| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: drm_memory.c,v 1.1.2.2 2013/07/24 02:39:25 riastradh Exp $ */ | | 1 | /* $NetBSD: drm_memory.c,v 1.1.2.3 2013/07/24 02:47:19 riastradh Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. | | 4 | * Copyright (c) 2013 The NetBSD Foundation, Inc. |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * This code is derived from software contributed to The NetBSD Foundation | | 7 | * This code is derived from software contributed to The NetBSD Foundation |
8 | * by Taylor R. Campbell. | | 8 | * by Taylor R. Campbell. |
9 | * | | 9 | * |
10 | * Redistribution and use in source and binary forms, with or without | | 10 | * Redistribution and use in source and binary forms, with or without |
11 | * modification, are permitted provided that the following conditions | | 11 | * modification, are permitted provided that the following conditions |
12 | * are met: | | 12 | * are met: |
13 | * 1. Redistributions of source code must retain the above copyright | | 13 | * 1. Redistributions of source code must retain the above copyright |
14 | * notice, this list of conditions and the following disclaimer. | | 14 | * notice, this list of conditions and the following disclaimer. |
| @@ -20,27 +20,27 @@ | | | @@ -20,27 +20,27 @@ |
20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | | 20 | * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED |
21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | | 21 | * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR |
22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS | | 22 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS |
23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | | 23 | * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | | 24 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | | 25 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | | 26 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | | 27 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | | 28 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
29 | * POSSIBILITY OF SUCH DAMAGE. | | 29 | * POSSIBILITY OF SUCH DAMAGE. |
30 | */ | | 30 | */ |
31 | | | 31 | |
32 | #include <sys/cdefs.h> | | 32 | #include <sys/cdefs.h> |
33 | __KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.1.2.2 2013/07/24 02:39:25 riastradh Exp $"); | | 33 | __KERNEL_RCSID(0, "$NetBSD: drm_memory.c,v 1.1.2.3 2013/07/24 02:47:19 riastradh Exp $"); |
34 | | | 34 | |
35 | /* XXX Cargo-culted from the old drm_memory.c. */ | | 35 | /* XXX Cargo-culted from the old drm_memory.c. */ |
36 | | | 36 | |
37 | #ifdef _KERNEL_OPT | | 37 | #ifdef _KERNEL_OPT |
38 | #include "agp_i810.h" | | 38 | #include "agp_i810.h" |
39 | #include "genfb.h" | | 39 | #include "genfb.h" |
40 | #else | | 40 | #else |
41 | #define NAGP_I810 1 /* XXX WTF? */ | | 41 | #define NAGP_I810 1 /* XXX WTF? */ |
42 | #define NGENFB 0 /* XXX WTF? */ | | 42 | #define NGENFB 0 /* XXX WTF? */ |
43 | #endif | | 43 | #endif |
44 | | | 44 | |
45 | #include <sys/bus.h> | | 45 | #include <sys/bus.h> |
46 | | | 46 | |
| @@ -101,51 +101,53 @@ drm_ioremap(struct drm_device *dev, stru | | | @@ -101,51 +101,53 @@ drm_ioremap(struct drm_device *dev, stru |
101 | * Reject maps that the request doesn't fit in. (Make | | 101 | * Reject maps that the request doesn't fit in. (Make |
102 | * sure to avoid integer overflow.) | | 102 | * sure to avoid integer overflow.) |
103 | */ | | 103 | */ |
104 | if ((bm->bm_size - map->size) < | | 104 | if ((bm->bm_size - map->size) < |
105 | (map->offset - bm->bm_base)) | | 105 | (map->offset - bm->bm_base)) |
106 | continue; | | 106 | continue; |
107 | | | 107 | |
108 | /* Has it been mapped yet? If not, map it. */ | | 108 | /* Has it been mapped yet? If not, map it. */ |
109 | if (bm->bm_mapped == 0) { | | 109 | if (bm->bm_mapped == 0) { |
110 | KASSERT(ISSET(bm->bm_flags, BUS_SPACE_MAP_LINEAR)); | | 110 | KASSERT(ISSET(bm->bm_flags, BUS_SPACE_MAP_LINEAR)); |
111 | error = bus_space_map(bst, bm->bm_base, | | 111 | error = bus_space_map(bst, bm->bm_base, |
112 | bm->bm_size, bm->bm_flags, &bm->bm_bsh); | | 112 | bm->bm_size, bm->bm_flags, &bm->bm_bsh); |
113 | if (error) { | | 113 | if (error) { |
114 | if (drm_bus_borrow(map->offset, &map->bsh)) { | | 114 | if (drm_bus_borrow(map->offset, |
115 | map->bus_map = NULL; | | 115 | &map->lm_data.bus_space.bsh)) { |
| | | 116 | map->lm_data.bus_space.bus_map = NULL; |
116 | goto win; | | 117 | goto win; |
117 | } | | 118 | } |
118 | return NULL; | | 119 | return NULL; |
119 | } | | 120 | } |
120 | } | | 121 | } |
121 | | | 122 | |
122 | /* Mark it used and make a subregion just for the request. */ | | 123 | /* Mark it used and make a subregion just for the request. */ |
123 | bm->bm_mapped++; | | 124 | bm->bm_mapped++; |
124 | error = bus_space_subregion(bst, bm->bm_bsh, | | 125 | error = bus_space_subregion(bst, bm->bm_bsh, |
125 | map->offset - bm->bm_base, map->size, &map->bsh); | | 126 | map->offset - bm->bm_base, map->size, |
| | | 127 | &map->lm_data.bus_space.bsh); |
126 | if (error) { | | 128 | if (error) { |
127 | /* | | 129 | /* |
128 | * Back out: unmark it and, if nobody else was | | 130 | * Back out: unmark it and, if nobody else was |
129 | * using it, unmap it. | | 131 | * using it, unmap it. |
130 | */ | | 132 | */ |
131 | if (--bm->bm_mapped == 0) | | 133 | if (--bm->bm_mapped == 0) |
132 | bus_space_unmap(bst, bm->bm_bsh, | | 134 | bus_space_unmap(bst, bm->bm_bsh, |
133 | bm->bm_size); | | 135 | bm->bm_size); |
134 | return NULL; | | 136 | return NULL; |
135 | } | | 137 | } |
136 | | | 138 | |
137 | /* Got it! */ | | 139 | /* Got it! */ |
138 | map->bus_map = bm; | | 140 | map->lm_data.bus_space.bus_map = bm; |
139 | goto win; | | 141 | goto win; |
140 | } | | 142 | } |
141 | | | 143 | |
142 | /* | | 144 | /* |
143 | * No dice. Try mapping it directly ourselves. | | 145 | * No dice. Try mapping it directly ourselves. |
144 | * | | 146 | * |
145 | * XXX Is this sensible? What prevents us from clobbering some | | 147 | * XXX Is this sensible? What prevents us from clobbering some |
146 | * existing map? And what does this have to do with agp? | | 148 | * existing map? And what does this have to do with agp? |
147 | */ | | 149 | */ |
148 | for (unit = 0; unit < dev->agp_nmaps; unit++) { | | 150 | for (unit = 0; unit < dev->agp_nmaps; unit++) { |
149 | struct drm_bus_map *const bm = &dev->agp_maps[unit]; | | 151 | struct drm_bus_map *const bm = &dev->agp_maps[unit]; |
150 | | | 152 | |
151 | /* Is this one allocated? */ | | 153 | /* Is this one allocated? */ |
| @@ -159,62 +161,63 @@ drm_ioremap(struct drm_device *dev, stru | | | @@ -159,62 +161,63 @@ drm_ioremap(struct drm_device *dev, stru |
159 | if (bm->bm_base != map->offset) | | 161 | if (bm->bm_base != map->offset) |
160 | continue; | | 162 | continue; |
161 | | | 163 | |
162 | /* Make sure it's big enough. */ | | 164 | /* Make sure it's big enough. */ |
163 | if (bm->bm_size < map->size) | | 165 | if (bm->bm_size < map->size) |
164 | continue; | | 166 | continue; |
165 | | | 167 | |
166 | /* Mark it used and return it. */ | | 168 | /* Mark it used and return it. */ |
167 | bm->bm_mapped++; | | 169 | bm->bm_mapped++; |
168 | | | 170 | |
169 | /* XXX size is an input/output parameter too...? */ | | 171 | /* XXX size is an input/output parameter too...? */ |
170 | map->size = bm->bm_size; | | 172 | map->size = bm->bm_size; |
171 | | | 173 | |
172 | map->bsh = bm->bm_bsh; | | 174 | map->lm_data.bus_space.bsh = bm->bm_bsh; |
173 | map->bus_map = bm; | | 175 | map->lm_data.bus_space.bus_map = bm; |
174 | goto win; | | 176 | goto win; |
175 | } else { | | 177 | } else { |
176 | const int flags = BUS_SPACE_MAP_PREFETCHABLE | | | 178 | const int flags = BUS_SPACE_MAP_PREFETCHABLE | |
177 | BUS_SPACE_MAP_LINEAR; | | 179 | BUS_SPACE_MAP_LINEAR; |
178 | | | 180 | |
179 | /* Try mapping the request. */ | | 181 | /* Try mapping the request. */ |
180 | error = bus_space_map(bst, map->offset, map->size, | | 182 | error = bus_space_map(bst, map->offset, map->size, |
181 | flags, &bm->bm_bsh); | | 183 | flags, &bm->bm_bsh); |
182 | if (error) | | 184 | if (error) |
183 | return NULL; /* XXX Why not continue? */ | | 185 | return NULL; /* XXX Why not continue? */ |
184 | | | 186 | |
185 | /* Got it. Allocate this bus map. */ | | 187 | /* Got it. Allocate this bus map. */ |
186 | bm->bm_mapped++; | | 188 | bm->bm_mapped++; |
187 | bm->bm_base = map->offset; | | 189 | bm->bm_base = map->offset; |
188 | bm->bm_size = map->size; | | 190 | bm->bm_size = map->size; |
189 | bm->bm_flags = flags; /* XXX What for? */ | | 191 | bm->bm_flags = flags; /* XXX What for? */ |
190 | | | 192 | |
191 | map->bsh = bm->bm_bsh; | | 193 | map->lm_data.bus_space.bsh = bm->bm_bsh; |
192 | map->bus_map = bm; | | 194 | map->lm_data.bus_space.bus_map = bm; |
193 | goto win; | | 195 | goto win; |
194 | } | | 196 | } |
195 | } | | 197 | } |
196 | | | 198 | |
197 | return NULL; | | 199 | return NULL; |
198 | | | 200 | |
199 | win: | | 201 | win: |
200 | return bus_space_vaddr(bst, map->bsh); | | 202 | map->lm_data.bus_space.bst = bst; |
| | | 203 | return bus_space_vaddr(bst, map->lm_data.bus_space.bsh); |
201 | } | | 204 | } |
202 | | | 205 | |
203 | void | | 206 | void |
204 | drm_iounmap(struct drm_device *dev, struct drm_local_map *map) | | 207 | drm_iounmap(struct drm_device *dev, struct drm_local_map *map) |
205 | { | | 208 | { |
206 | const bus_space_tag_t bst = dev->bst; | | 209 | const bus_space_tag_t bst = dev->bst; |
207 | struct drm_bus_map *const bm = map->bus_map; | | 210 | struct drm_bus_map *const bm = map->lm_data.bus_space.bus_map; |
208 | | | 211 | |
209 | /* | | 212 | /* |
210 | * bm may be null if we have committed the horrible deed of | | 213 | * bm may be null if we have committed the horrible deed of |
211 | * borrowing from agp_i810 or genfb. | | 214 | * borrowing from agp_i810 or genfb. |
212 | */ | | 215 | */ |
213 | if (bm != NULL) { | | 216 | if (bm != NULL) { |
214 | KASSERT(bm->bm_mapped > 0); | | 217 | KASSERT(bm->bm_mapped > 0); |
215 | if (--bm->bm_mapped) | | 218 | if (--bm->bm_mapped) |
216 | bus_space_unmap(bst, bm->bm_bsh, bm->bm_size); | | 219 | bus_space_unmap(bst, bm->bm_bsh, bm->bm_size); |
217 | } | | 220 | } |
218 | } | | 221 | } |
219 | | | 222 | |
220 | /* | | 223 | /* |