diff options
author | Dave Airlie <airlied@starflyer.(none)> | 2005-09-25 00:28:13 -0400 |
---|---|---|
committer | Dave Airlie <airlied@linux.ie> | 2005-09-25 00:28:13 -0400 |
commit | b5e89ed53ed8d24f83ba1941c07382af00ed238e (patch) | |
tree | 747bae7a565f88a2e1d5974776eeb054a932c505 /drivers/char/drm/drm_drv.c | |
parent | 99a2657a29e2d623c3568cd86b27cac13fb63140 (diff) |
drm: lindent the drm directory.
I've been threatening this for a while, so no point hanging around.
This lindents the DRM code which was always really bad in tabbing department.
I've also fixed some misnamed files in comments and removed some trailing
whitespace.
Signed-off-by: Dave Airlie <airlied@linux.ie>
Diffstat (limited to 'drivers/char/drm/drm_drv.c')
-rw-r--r-- | drivers/char/drm/drm_drv.c | 361 |
1 files changed, 182 insertions, 179 deletions
diff --git a/drivers/char/drm/drm_drv.c b/drivers/char/drm/drm_drv.c index 6ba48f346fcf..26733248ff4a 100644 --- a/drivers/char/drm/drm_drv.c +++ b/drivers/char/drm/drm_drv.c | |||
@@ -1,5 +1,5 @@ | |||
1 | /** | 1 | /** |
2 | * \file drm_drv.h | 2 | * \file drm_drv.c |
3 | * Generic driver template | 3 | * Generic driver template |
4 | * | 4 | * |
5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> | 5 | * \author Rickard E. (Rik) Faith <faith@valinux.com> |
@@ -55,67 +55,67 @@ static int drm_version(struct inode *inode, struct file *filp, | |||
55 | unsigned int cmd, unsigned long arg); | 55 | unsigned int cmd, unsigned long arg); |
56 | 56 | ||
57 | /** Ioctl table */ | 57 | /** Ioctl table */ |
58 | static drm_ioctl_desc_t drm_ioctls[] = { | 58 | static drm_ioctl_desc_t drm_ioctls[] = { |
59 | [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = { drm_version, 0, 0 }, | 59 | [DRM_IOCTL_NR(DRM_IOCTL_VERSION)] = {drm_version, 0, 0}, |
60 | [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = { drm_getunique, 0, 0 }, | 60 | [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE)] = {drm_getunique, 0, 0}, |
61 | [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = { drm_getmagic, 0, 0 }, | 61 | [DRM_IOCTL_NR(DRM_IOCTL_GET_MAGIC)] = {drm_getmagic, 0, 0}, |
62 | [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = { drm_irq_by_busid, 0, 1 }, | 62 | [DRM_IOCTL_NR(DRM_IOCTL_IRQ_BUSID)] = {drm_irq_by_busid, 0, 1}, |
63 | [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = { drm_getmap, 0, 0 }, | 63 | [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP)] = {drm_getmap, 0, 0}, |
64 | [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = { drm_getclient, 0, 0 }, | 64 | [DRM_IOCTL_NR(DRM_IOCTL_GET_CLIENT)] = {drm_getclient, 0, 0}, |
65 | [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = { drm_getstats, 0, 0 }, | 65 | [DRM_IOCTL_NR(DRM_IOCTL_GET_STATS)] = {drm_getstats, 0, 0}, |
66 | [DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)] = { drm_setversion, 0, 1 }, | 66 | [DRM_IOCTL_NR(DRM_IOCTL_SET_VERSION)] = {drm_setversion, 0, 1}, |
67 | 67 | ||
68 | [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = { drm_setunique, 1, 1 }, | 68 | [DRM_IOCTL_NR(DRM_IOCTL_SET_UNIQUE)] = {drm_setunique, 1, 1}, |
69 | [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = { drm_noop, 1, 1 }, | 69 | [DRM_IOCTL_NR(DRM_IOCTL_BLOCK)] = {drm_noop, 1, 1}, |
70 | [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = { drm_noop, 1, 1 }, | 70 | [DRM_IOCTL_NR(DRM_IOCTL_UNBLOCK)] = {drm_noop, 1, 1}, |
71 | [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = { drm_authmagic, 1, 1 }, | 71 | [DRM_IOCTL_NR(DRM_IOCTL_AUTH_MAGIC)] = {drm_authmagic, 1, 1}, |
72 | 72 | ||
73 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = { drm_addmap_ioctl,1, 1 }, | 73 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_MAP)] = {drm_addmap_ioctl, 1, 1}, |
74 | [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)] = { drm_rmmap_ioctl, 1, 0 }, | 74 | [DRM_IOCTL_NR(DRM_IOCTL_RM_MAP)] = {drm_rmmap_ioctl, 1, 0}, |
75 | 75 | ||
76 | [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = { drm_setsareactx, 1, 1 }, | 76 | [DRM_IOCTL_NR(DRM_IOCTL_SET_SAREA_CTX)] = {drm_setsareactx, 1, 1}, |
77 | [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = { drm_getsareactx, 1, 0 }, | 77 | [DRM_IOCTL_NR(DRM_IOCTL_GET_SAREA_CTX)] = {drm_getsareactx, 1, 0}, |
78 | 78 | ||
79 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = { drm_addctx, 1, 1 }, | 79 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_CTX)] = {drm_addctx, 1, 1}, |
80 | [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = { drm_rmctx, 1, 1 }, | 80 | [DRM_IOCTL_NR(DRM_IOCTL_RM_CTX)] = {drm_rmctx, 1, 1}, |
81 | [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = { drm_modctx, 1, 1 }, | 81 | [DRM_IOCTL_NR(DRM_IOCTL_MOD_CTX)] = {drm_modctx, 1, 1}, |
82 | [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = { drm_getctx, 1, 0 }, | 82 | [DRM_IOCTL_NR(DRM_IOCTL_GET_CTX)] = {drm_getctx, 1, 0}, |
83 | [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = { drm_switchctx, 1, 1 }, | 83 | [DRM_IOCTL_NR(DRM_IOCTL_SWITCH_CTX)] = {drm_switchctx, 1, 1}, |
84 | [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = { drm_newctx, 1, 1 }, | 84 | [DRM_IOCTL_NR(DRM_IOCTL_NEW_CTX)] = {drm_newctx, 1, 1}, |
85 | [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = { drm_resctx, 1, 0 }, | 85 | [DRM_IOCTL_NR(DRM_IOCTL_RES_CTX)] = {drm_resctx, 1, 0}, |
86 | 86 | ||
87 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = { drm_adddraw, 1, 1 }, | 87 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_DRAW)] = {drm_adddraw, 1, 1}, |
88 | [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = { drm_rmdraw, 1, 1 }, | 88 | [DRM_IOCTL_NR(DRM_IOCTL_RM_DRAW)] = {drm_rmdraw, 1, 1}, |
89 | 89 | ||
90 | [DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = { drm_lock, 1, 0 }, | 90 | [DRM_IOCTL_NR(DRM_IOCTL_LOCK)] = {drm_lock, 1, 0}, |
91 | [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = { drm_unlock, 1, 0 }, | 91 | [DRM_IOCTL_NR(DRM_IOCTL_UNLOCK)] = {drm_unlock, 1, 0}, |
92 | 92 | ||
93 | [DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = { drm_noop, 1, 0 }, | 93 | [DRM_IOCTL_NR(DRM_IOCTL_FINISH)] = {drm_noop, 1, 0}, |
94 | 94 | ||
95 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = { drm_addbufs, 1, 1 }, | 95 | [DRM_IOCTL_NR(DRM_IOCTL_ADD_BUFS)] = {drm_addbufs, 1, 1}, |
96 | [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = { drm_markbufs, 1, 1 }, | 96 | [DRM_IOCTL_NR(DRM_IOCTL_MARK_BUFS)] = {drm_markbufs, 1, 1}, |
97 | [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = { drm_infobufs, 1, 0 }, | 97 | [DRM_IOCTL_NR(DRM_IOCTL_INFO_BUFS)] = {drm_infobufs, 1, 0}, |
98 | [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = { drm_mapbufs, 1, 0 }, | 98 | [DRM_IOCTL_NR(DRM_IOCTL_MAP_BUFS)] = {drm_mapbufs, 1, 0}, |
99 | [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = { drm_freebufs, 1, 0 }, | 99 | [DRM_IOCTL_NR(DRM_IOCTL_FREE_BUFS)] = {drm_freebufs, 1, 0}, |
100 | /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */ | 100 | /* The DRM_IOCTL_DMA ioctl should be defined by the driver. */ |
101 | 101 | ||
102 | [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = { drm_control, 1, 1 }, | 102 | [DRM_IOCTL_NR(DRM_IOCTL_CONTROL)] = {drm_control, 1, 1}, |
103 | 103 | ||
104 | #if __OS_HAS_AGP | 104 | #if __OS_HAS_AGP |
105 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = { drm_agp_acquire_ioctl, 1, 1 }, | 105 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ACQUIRE)] = {drm_agp_acquire_ioctl, 1, 1}, |
106 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = { drm_agp_release_ioctl, 1, 1 }, | 106 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_RELEASE)] = {drm_agp_release_ioctl, 1, 1}, |
107 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = { drm_agp_enable_ioctl, 1, 1 }, | 107 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ENABLE)] = {drm_agp_enable_ioctl, 1, 1}, |
108 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = { drm_agp_info_ioctl, 1, 0 }, | 108 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_INFO)] = {drm_agp_info_ioctl, 1, 0}, |
109 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = { drm_agp_alloc, 1, 1 }, | 109 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_ALLOC)] = {drm_agp_alloc, 1, 1}, |
110 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = { drm_agp_free, 1, 1 }, | 110 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_FREE)] = {drm_agp_free, 1, 1}, |
111 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = { drm_agp_bind, 1, 1 }, | 111 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_BIND)] = {drm_agp_bind, 1, 1}, |
112 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = { drm_agp_unbind, 1, 1 }, | 112 | [DRM_IOCTL_NR(DRM_IOCTL_AGP_UNBIND)] = {drm_agp_unbind, 1, 1}, |
113 | #endif | 113 | #endif |
114 | 114 | ||
115 | [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)] = { drm_sg_alloc, 1, 1 }, | 115 | [DRM_IOCTL_NR(DRM_IOCTL_SG_ALLOC)] = {drm_sg_alloc, 1, 1}, |
116 | [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = { drm_sg_free, 1, 1 }, | 116 | [DRM_IOCTL_NR(DRM_IOCTL_SG_FREE)] = {drm_sg_free, 1, 1}, |
117 | 117 | ||
118 | [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = { drm_wait_vblank, 0, 0 }, | 118 | [DRM_IOCTL_NR(DRM_IOCTL_WAIT_VBLANK)] = {drm_wait_vblank, 0, 0}, |
119 | }; | 119 | }; |
120 | 120 | ||
121 | #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( drm_ioctls ) | 121 | #define DRIVER_IOCTL_COUNT DRM_ARRAY_SIZE( drm_ioctls ) |
@@ -129,17 +129,17 @@ static drm_ioctl_desc_t drm_ioctls[] = { | |||
129 | * | 129 | * |
130 | * \sa drm_device | 130 | * \sa drm_device |
131 | */ | 131 | */ |
132 | int drm_takedown( drm_device_t *dev ) | 132 | int drm_takedown(drm_device_t * dev) |
133 | { | 133 | { |
134 | drm_magic_entry_t *pt, *next; | 134 | drm_magic_entry_t *pt, *next; |
135 | drm_map_list_t *r_list; | 135 | drm_map_list_t *r_list; |
136 | drm_vma_entry_t *vma, *vma_next; | 136 | drm_vma_entry_t *vma, *vma_next; |
137 | int i; | 137 | int i; |
138 | 138 | ||
139 | DRM_DEBUG( "\n" ); | 139 | DRM_DEBUG("\n"); |
140 | 140 | ||
141 | if (dev->driver->pretakedown) | 141 | if (dev->driver->pretakedown) |
142 | dev->driver->pretakedown(dev); | 142 | dev->driver->pretakedown(dev); |
143 | DRM_DEBUG("driver pretakedown completed\n"); | 143 | DRM_DEBUG("driver pretakedown completed\n"); |
144 | 144 | ||
145 | if (dev->unique) { | 145 | if (dev->unique) { |
@@ -148,95 +148,95 @@ int drm_takedown( drm_device_t *dev ) | |||
148 | dev->unique_len = 0; | 148 | dev->unique_len = 0; |
149 | } | 149 | } |
150 | 150 | ||
151 | if ( dev->irq_enabled ) drm_irq_uninstall( dev ); | 151 | if (dev->irq_enabled) |
152 | drm_irq_uninstall(dev); | ||
152 | 153 | ||
153 | down( &dev->struct_sem ); | 154 | down(&dev->struct_sem); |
154 | del_timer( &dev->timer ); | 155 | del_timer(&dev->timer); |
155 | 156 | ||
156 | /* Clear pid list */ | 157 | /* Clear pid list */ |
157 | for ( i = 0 ; i < DRM_HASH_SIZE ; i++ ) { | 158 | for (i = 0; i < DRM_HASH_SIZE; i++) { |
158 | for ( pt = dev->magiclist[i].head ; pt ; pt = next ) { | 159 | for (pt = dev->magiclist[i].head; pt; pt = next) { |
159 | next = pt->next; | 160 | next = pt->next; |
160 | drm_free( pt, sizeof(*pt), DRM_MEM_MAGIC ); | 161 | drm_free(pt, sizeof(*pt), DRM_MEM_MAGIC); |
161 | } | 162 | } |
162 | dev->magiclist[i].head = dev->magiclist[i].tail = NULL; | 163 | dev->magiclist[i].head = dev->magiclist[i].tail = NULL; |
163 | } | 164 | } |
164 | 165 | ||
165 | /* Clear AGP information */ | 166 | /* Clear AGP information */ |
166 | if (drm_core_has_AGP(dev) && dev->agp) { | 167 | if (drm_core_has_AGP(dev) && dev->agp) { |
167 | drm_agp_mem_t *entry; | 168 | drm_agp_mem_t *entry; |
168 | drm_agp_mem_t *nexte; | 169 | drm_agp_mem_t *nexte; |
169 | 170 | ||
170 | /* Remove AGP resources, but leave dev->agp | 171 | /* Remove AGP resources, but leave dev->agp |
171 | intact until drv_cleanup is called. */ | 172 | intact until drv_cleanup is called. */ |
172 | for ( entry = dev->agp->memory ; entry ; entry = nexte ) { | 173 | for (entry = dev->agp->memory; entry; entry = nexte) { |
173 | nexte = entry->next; | 174 | nexte = entry->next; |
174 | if ( entry->bound ) drm_unbind_agp( entry->memory ); | 175 | if (entry->bound) |
175 | drm_free_agp( entry->memory, entry->pages ); | 176 | drm_unbind_agp(entry->memory); |
176 | drm_free( entry, sizeof(*entry), DRM_MEM_AGPLISTS ); | 177 | drm_free_agp(entry->memory, entry->pages); |
178 | drm_free(entry, sizeof(*entry), DRM_MEM_AGPLISTS); | ||
177 | } | 179 | } |
178 | dev->agp->memory = NULL; | 180 | dev->agp->memory = NULL; |
179 | 181 | ||
180 | if (dev->agp->acquired) | 182 | if (dev->agp->acquired) |
181 | drm_agp_release(dev); | 183 | drm_agp_release(dev); |
182 | 184 | ||
183 | dev->agp->acquired = 0; | 185 | dev->agp->acquired = 0; |
184 | dev->agp->enabled = 0; | 186 | dev->agp->enabled = 0; |
185 | } | 187 | } |
186 | if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) { | 188 | if (drm_core_check_feature(dev, DRIVER_SG) && dev->sg) { |
187 | drm_sg_cleanup(dev->sg); | 189 | drm_sg_cleanup(dev->sg); |
188 | dev->sg = NULL; | 190 | dev->sg = NULL; |
189 | } | 191 | } |
190 | 192 | ||
191 | /* Clear vma list (only built for debugging) */ | 193 | /* Clear vma list (only built for debugging) */ |
192 | if ( dev->vmalist ) { | 194 | if (dev->vmalist) { |
193 | for ( vma = dev->vmalist ; vma ; vma = vma_next ) { | 195 | for (vma = dev->vmalist; vma; vma = vma_next) { |
194 | vma_next = vma->next; | 196 | vma_next = vma->next; |
195 | drm_free( vma, sizeof(*vma), DRM_MEM_VMAS ); | 197 | drm_free(vma, sizeof(*vma), DRM_MEM_VMAS); |
196 | } | 198 | } |
197 | dev->vmalist = NULL; | 199 | dev->vmalist = NULL; |
198 | } | 200 | } |
199 | 201 | ||
200 | if( dev->maplist ) { | 202 | if (dev->maplist) { |
201 | while (!list_empty(&dev->maplist->head)) { | 203 | while (!list_empty(&dev->maplist->head)) { |
202 | struct list_head *list = dev->maplist->head.next; | 204 | struct list_head *list = dev->maplist->head.next; |
203 | r_list = list_entry(list, drm_map_list_t, head); | 205 | r_list = list_entry(list, drm_map_list_t, head); |
204 | drm_rmmap_locked(dev, r_list->map); | 206 | drm_rmmap_locked(dev, r_list->map); |
205 | } | 207 | } |
206 | } | 208 | } |
207 | 209 | ||
208 | if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist ) { | 210 | if (drm_core_check_feature(dev, DRIVER_DMA_QUEUE) && dev->queuelist) { |
209 | for ( i = 0 ; i < dev->queue_count ; i++ ) { | 211 | for (i = 0; i < dev->queue_count; i++) { |
210 | if ( dev->queuelist[i] ) { | 212 | if (dev->queuelist[i]) { |
211 | drm_free( dev->queuelist[i], | 213 | drm_free(dev->queuelist[i], |
212 | sizeof(*dev->queuelist[0]), | 214 | sizeof(*dev->queuelist[0]), |
213 | DRM_MEM_QUEUES ); | 215 | DRM_MEM_QUEUES); |
214 | dev->queuelist[i] = NULL; | 216 | dev->queuelist[i] = NULL; |
215 | } | 217 | } |
216 | } | 218 | } |
217 | drm_free( dev->queuelist, | 219 | drm_free(dev->queuelist, |
218 | dev->queue_slots * sizeof(*dev->queuelist), | 220 | dev->queue_slots * sizeof(*dev->queuelist), |
219 | DRM_MEM_QUEUES ); | 221 | DRM_MEM_QUEUES); |
220 | dev->queuelist = NULL; | 222 | dev->queuelist = NULL; |
221 | } | 223 | } |
222 | dev->queue_count = 0; | 224 | dev->queue_count = 0; |
223 | 225 | ||
224 | if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) | 226 | if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) |
225 | drm_dma_takedown( dev ); | 227 | drm_dma_takedown(dev); |
226 | 228 | ||
227 | if ( dev->lock.hw_lock ) { | 229 | if (dev->lock.hw_lock) { |
228 | dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */ | 230 | dev->sigdata.lock = dev->lock.hw_lock = NULL; /* SHM removed */ |
229 | dev->lock.filp = NULL; | 231 | dev->lock.filp = NULL; |
230 | wake_up_interruptible( &dev->lock.lock_queue ); | 232 | wake_up_interruptible(&dev->lock.lock_queue); |
231 | } | 233 | } |
232 | up( &dev->struct_sem ); | 234 | up(&dev->struct_sem); |
233 | 235 | ||
234 | DRM_DEBUG("takedown completed\n"); | 236 | DRM_DEBUG("takedown completed\n"); |
235 | return 0; | 237 | return 0; |
236 | } | 238 | } |
237 | 239 | ||
238 | |||
239 | |||
240 | /** | 240 | /** |
241 | * Module initialization. Called via init_module at module load time, or via | 241 | * Module initialization. Called via init_module at module load time, or via |
242 | * linux/init/main.c (this is not currently supported). | 242 | * linux/init/main.c (this is not currently supported). |
@@ -246,26 +246,28 @@ int drm_takedown( drm_device_t *dev ) | |||
246 | * Initializes an array of drm_device structures, and attempts to | 246 | * Initializes an array of drm_device structures, and attempts to |
247 | * initialize all available devices, using consecutive minors, registering the | 247 | * initialize all available devices, using consecutive minors, registering the |
248 | * stubs and initializing the AGP device. | 248 | * stubs and initializing the AGP device. |
249 | * | 249 | * |
250 | * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and | 250 | * Expands the \c DRIVER_PREINIT and \c DRIVER_POST_INIT macros before and |
251 | * after the initialization for driver customization. | 251 | * after the initialization for driver customization. |
252 | */ | 252 | */ |
253 | int drm_init( struct drm_driver *driver ) | 253 | int drm_init(struct drm_driver *driver) |
254 | { | 254 | { |
255 | struct pci_dev *pdev = NULL; | 255 | struct pci_dev *pdev = NULL; |
256 | struct pci_device_id *pid; | 256 | struct pci_device_id *pid; |
257 | int i; | 257 | int i; |
258 | 258 | ||
259 | DRM_DEBUG( "\n" ); | 259 | DRM_DEBUG("\n"); |
260 | 260 | ||
261 | drm_mem_init(); | 261 | drm_mem_init(); |
262 | 262 | ||
263 | for (i=0; driver->pci_driver.id_table[i].vendor != 0; i++) { | 263 | for (i = 0; driver->pci_driver.id_table[i].vendor != 0; i++) { |
264 | pid = (struct pci_device_id *)&driver->pci_driver.id_table[i]; | 264 | pid = (struct pci_device_id *)&driver->pci_driver.id_table[i]; |
265 | 265 | ||
266 | pdev=NULL; | 266 | pdev = NULL; |
267 | /* pass back in pdev to account for multiple identical cards */ | 267 | /* pass back in pdev to account for multiple identical cards */ |
268 | while ((pdev = pci_get_subsys(pid->vendor, pid->device, pid->subvendor, pid->subdevice, pdev)) != NULL) { | 268 | while ((pdev = |
269 | pci_get_subsys(pid->vendor, pid->device, pid->subvendor, | ||
270 | pid->subdevice, pdev)) != NULL) { | ||
269 | /* stealth mode requires a manual probe */ | 271 | /* stealth mode requires a manual probe */ |
270 | pci_dev_get(pdev); | 272 | pci_dev_get(pdev); |
271 | drm_get_dev(pdev, pid, driver); | 273 | drm_get_dev(pdev, pid, driver); |
@@ -273,62 +275,63 @@ int drm_init( struct drm_driver *driver ) | |||
273 | } | 275 | } |
274 | return 0; | 276 | return 0; |
275 | } | 277 | } |
278 | |||
276 | EXPORT_SYMBOL(drm_init); | 279 | EXPORT_SYMBOL(drm_init); |
277 | 280 | ||
278 | /** | 281 | /** |
279 | * Called via cleanup_module() at module unload time. | 282 | * Called via cleanup_module() at module unload time. |
280 | * | 283 | * |
281 | * Cleans up all DRM device, calling takedown(). | 284 | * Cleans up all DRM device, calling takedown(). |
282 | * | 285 | * |
283 | * \sa drm_init | 286 | * \sa drm_init |
284 | */ | 287 | */ |
285 | static void drm_cleanup( drm_device_t *dev ) | 288 | static void drm_cleanup(drm_device_t * dev) |
286 | { | 289 | { |
287 | DRM_DEBUG( "\n" ); | 290 | DRM_DEBUG("\n"); |
288 | 291 | ||
289 | if (!dev) { | 292 | if (!dev) { |
290 | DRM_ERROR("cleanup called no dev\n"); | 293 | DRM_ERROR("cleanup called no dev\n"); |
291 | return; | 294 | return; |
292 | } | 295 | } |
293 | 296 | ||
294 | drm_takedown( dev ); | 297 | drm_takedown(dev); |
295 | 298 | ||
296 | if (dev->maplist) { | 299 | if (dev->maplist) { |
297 | drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS); | 300 | drm_free(dev->maplist, sizeof(*dev->maplist), DRM_MEM_MAPS); |
298 | dev->maplist = NULL; | 301 | dev->maplist = NULL; |
299 | } | 302 | } |
300 | 303 | ||
301 | drm_ctxbitmap_cleanup( dev ); | 304 | drm_ctxbitmap_cleanup(dev); |
302 | 305 | ||
303 | if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && | 306 | if (drm_core_has_MTRR(dev) && drm_core_has_AGP(dev) && |
304 | dev->agp && dev->agp->agp_mtrr >= 0) { | 307 | dev->agp && dev->agp->agp_mtrr >= 0) { |
305 | int retval; | 308 | int retval; |
306 | retval = mtrr_del( dev->agp->agp_mtrr, | 309 | retval = mtrr_del(dev->agp->agp_mtrr, |
307 | dev->agp->agp_info.aper_base, | 310 | dev->agp->agp_info.aper_base, |
308 | dev->agp->agp_info.aper_size*1024*1024 ); | 311 | dev->agp->agp_info.aper_size * 1024 * 1024); |
309 | DRM_DEBUG( "mtrr_del=%d\n", retval ); | 312 | DRM_DEBUG("mtrr_del=%d\n", retval); |
310 | } | 313 | } |
311 | 314 | ||
312 | if (drm_core_has_AGP(dev) && dev->agp ) { | 315 | if (drm_core_has_AGP(dev) && dev->agp) { |
313 | drm_free( dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS ); | 316 | drm_free(dev->agp, sizeof(*dev->agp), DRM_MEM_AGPLISTS); |
314 | dev->agp = NULL; | 317 | dev->agp = NULL; |
315 | } | 318 | } |
316 | 319 | ||
317 | if (dev->driver->postcleanup) | 320 | if (dev->driver->postcleanup) |
318 | dev->driver->postcleanup(dev); | 321 | dev->driver->postcleanup(dev); |
319 | 322 | ||
320 | drm_put_head(&dev->primary); | 323 | drm_put_head(&dev->primary); |
321 | if ( drm_put_dev(dev) ) | 324 | if (drm_put_dev(dev)) |
322 | DRM_ERROR( "Cannot unload module\n" ); | 325 | DRM_ERROR("Cannot unload module\n"); |
323 | } | 326 | } |
324 | 327 | ||
325 | void drm_exit (struct drm_driver *driver) | 328 | void drm_exit(struct drm_driver *driver) |
326 | { | 329 | { |
327 | int i; | 330 | int i; |
328 | drm_device_t *dev = NULL; | 331 | drm_device_t *dev = NULL; |
329 | drm_head_t *head; | 332 | drm_head_t *head; |
330 | 333 | ||
331 | DRM_DEBUG( "\n" ); | 334 | DRM_DEBUG("\n"); |
332 | 335 | ||
333 | for (i = 0; i < drm_cards_limit; i++) { | 336 | for (i = 0; i < drm_cards_limit; i++) { |
334 | head = drm_heads[i]; | 337 | head = drm_heads[i]; |
@@ -336,9 +339,9 @@ void drm_exit (struct drm_driver *driver) | |||
336 | continue; | 339 | continue; |
337 | if (!head->dev) | 340 | if (!head->dev) |
338 | continue; | 341 | continue; |
339 | if (head->dev->driver!=driver) | 342 | if (head->dev->driver != driver) |
340 | continue; | 343 | continue; |
341 | dev=head->dev; | 344 | dev = head->dev; |
342 | } | 345 | } |
343 | if (dev) { | 346 | if (dev) { |
344 | /* release the pci driver */ | 347 | /* release the pci driver */ |
@@ -346,32 +349,35 @@ void drm_exit (struct drm_driver *driver) | |||
346 | pci_dev_put(dev->pdev); | 349 | pci_dev_put(dev->pdev); |
347 | drm_cleanup(dev); | 350 | drm_cleanup(dev); |
348 | } | 351 | } |
349 | DRM_INFO( "Module unloaded\n" ); | 352 | DRM_INFO("Module unloaded\n"); |
350 | } | 353 | } |
354 | |||
351 | EXPORT_SYMBOL(drm_exit); | 355 | EXPORT_SYMBOL(drm_exit); |
352 | 356 | ||
353 | /** File operations structure */ | 357 | /** File operations structure */ |
354 | static struct file_operations drm_stub_fops = { | 358 | static struct file_operations drm_stub_fops = { |
355 | .owner = THIS_MODULE, | 359 | .owner = THIS_MODULE, |
356 | .open = drm_stub_open | 360 | .open = drm_stub_open |
357 | }; | 361 | }; |
358 | 362 | ||
359 | static int __init drm_core_init(void) | 363 | static int __init drm_core_init(void) |
360 | { | 364 | { |
361 | int ret = -ENOMEM; | 365 | int ret = -ENOMEM; |
362 | 366 | ||
363 | drm_cards_limit = (drm_cards_limit < DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1); | 367 | drm_cards_limit = |
364 | drm_heads = drm_calloc(drm_cards_limit, | 368 | (drm_cards_limit < |
365 | sizeof(*drm_heads), DRM_MEM_STUB); | 369 | DRM_MAX_MINOR + 1 ? drm_cards_limit : DRM_MAX_MINOR + 1); |
366 | if(!drm_heads) | 370 | drm_heads = |
371 | drm_calloc(drm_cards_limit, sizeof(*drm_heads), DRM_MEM_STUB); | ||
372 | if (!drm_heads) | ||
367 | goto err_p1; | 373 | goto err_p1; |
368 | 374 | ||
369 | if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) | 375 | if (register_chrdev(DRM_MAJOR, "drm", &drm_stub_fops)) |
370 | goto err_p1; | 376 | goto err_p1; |
371 | 377 | ||
372 | drm_class = drm_sysfs_create(THIS_MODULE, "drm"); | 378 | drm_class = drm_sysfs_create(THIS_MODULE, "drm"); |
373 | if (IS_ERR(drm_class)) { | 379 | if (IS_ERR(drm_class)) { |
374 | printk (KERN_ERR "DRM: Error creating drm class.\n"); | 380 | printk(KERN_ERR "DRM: Error creating drm class.\n"); |
375 | ret = PTR_ERR(drm_class); | 381 | ret = PTR_ERR(drm_class); |
376 | goto err_p2; | 382 | goto err_p2; |
377 | } | 383 | } |
@@ -382,35 +388,31 @@ static int __init drm_core_init(void) | |||
382 | ret = -1; | 388 | ret = -1; |
383 | goto err_p3; | 389 | goto err_p3; |
384 | } | 390 | } |
385 | 391 | ||
386 | DRM_INFO( "Initialized %s %d.%d.%d %s\n", | 392 | DRM_INFO("Initialized %s %d.%d.%d %s\n", |
387 | CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, | 393 | CORE_NAME, CORE_MAJOR, CORE_MINOR, CORE_PATCHLEVEL, CORE_DATE); |
388 | CORE_DATE); | ||
389 | return 0; | 394 | return 0; |
390 | err_p3: | 395 | err_p3: |
391 | drm_sysfs_destroy(drm_class); | 396 | drm_sysfs_destroy(drm_class); |
392 | err_p2: | 397 | err_p2: |
393 | unregister_chrdev(DRM_MAJOR, "drm"); | 398 | unregister_chrdev(DRM_MAJOR, "drm"); |
394 | drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB); | 399 | drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB); |
395 | err_p1: | 400 | err_p1: |
396 | return ret; | 401 | return ret; |
397 | } | 402 | } |
398 | 403 | ||
399 | static void __exit drm_core_exit (void) | 404 | static void __exit drm_core_exit(void) |
400 | { | 405 | { |
401 | remove_proc_entry("dri", NULL); | 406 | remove_proc_entry("dri", NULL); |
402 | drm_sysfs_destroy(drm_class); | 407 | drm_sysfs_destroy(drm_class); |
403 | 408 | ||
404 | unregister_chrdev(DRM_MAJOR, "drm"); | 409 | unregister_chrdev(DRM_MAJOR, "drm"); |
405 | 410 | ||
406 | drm_free(drm_heads, sizeof(*drm_heads) * | 411 | drm_free(drm_heads, sizeof(*drm_heads) * drm_cards_limit, DRM_MEM_STUB); |
407 | drm_cards_limit, DRM_MEM_STUB); | ||
408 | } | 412 | } |
409 | 413 | ||
410 | 414 | module_init(drm_core_init); | |
411 | module_init( drm_core_init ); | 415 | module_exit(drm_core_exit); |
412 | module_exit( drm_core_exit ); | ||
413 | |||
414 | 416 | ||
415 | /** | 417 | /** |
416 | * Get version information | 418 | * Get version information |
@@ -423,8 +425,8 @@ module_exit( drm_core_exit ); | |||
423 | * | 425 | * |
424 | * Fills in the version information in \p arg. | 426 | * Fills in the version information in \p arg. |
425 | */ | 427 | */ |
426 | static int drm_version( struct inode *inode, struct file *filp, | 428 | static int drm_version(struct inode *inode, struct file *filp, |
427 | unsigned int cmd, unsigned long arg ) | 429 | unsigned int cmd, unsigned long arg) |
428 | { | 430 | { |
429 | drm_file_t *priv = filp->private_data; | 431 | drm_file_t *priv = filp->private_data; |
430 | drm_device_t *dev = priv->head->dev; | 432 | drm_device_t *dev = priv->head->dev; |
@@ -432,21 +434,19 @@ static int drm_version( struct inode *inode, struct file *filp, | |||
432 | drm_version_t version; | 434 | drm_version_t version; |
433 | int ret; | 435 | int ret; |
434 | 436 | ||
435 | if ( copy_from_user( &version, argp, sizeof(version) ) ) | 437 | if (copy_from_user(&version, argp, sizeof(version))) |
436 | return -EFAULT; | 438 | return -EFAULT; |
437 | 439 | ||
438 | /* version is a required function to return the personality module version */ | 440 | /* version is a required function to return the personality module version */ |
439 | if ((ret = dev->driver->version(&version))) | 441 | if ((ret = dev->driver->version(&version))) |
440 | return ret; | 442 | return ret; |
441 | 443 | ||
442 | if ( copy_to_user( argp, &version, sizeof(version) ) ) | 444 | if (copy_to_user(argp, &version, sizeof(version))) |
443 | return -EFAULT; | 445 | return -EFAULT; |
444 | return 0; | 446 | return 0; |
445 | } | 447 | } |
446 | 448 | ||
447 | 449 | /** | |
448 | |||
449 | /** | ||
450 | * Called whenever a process performs an ioctl on /dev/drm. | 450 | * Called whenever a process performs an ioctl on /dev/drm. |
451 | * | 451 | * |
452 | * \param inode device inode. | 452 | * \param inode device inode. |
@@ -458,8 +458,8 @@ static int drm_version( struct inode *inode, struct file *filp, | |||
458 | * Looks up the ioctl function in the ::ioctls table, checking for root | 458 | * Looks up the ioctl function in the ::ioctls table, checking for root |
459 | * previleges if so required, and dispatches to the respective function. | 459 | * previleges if so required, and dispatches to the respective function. |
460 | */ | 460 | */ |
461 | int drm_ioctl( struct inode *inode, struct file *filp, | 461 | int drm_ioctl(struct inode *inode, struct file *filp, |
462 | unsigned int cmd, unsigned long arg ) | 462 | unsigned int cmd, unsigned long arg) |
463 | { | 463 | { |
464 | drm_file_t *priv = filp->private_data; | 464 | drm_file_t *priv = filp->private_data; |
465 | drm_device_t *dev = priv->head->dev; | 465 | drm_device_t *dev = priv->head->dev; |
@@ -468,40 +468,43 @@ int drm_ioctl( struct inode *inode, struct file *filp, | |||
468 | unsigned int nr = DRM_IOCTL_NR(cmd); | 468 | unsigned int nr = DRM_IOCTL_NR(cmd); |
469 | int retcode = -EINVAL; | 469 | int retcode = -EINVAL; |
470 | 470 | ||
471 | atomic_inc( &dev->ioctl_count ); | 471 | atomic_inc(&dev->ioctl_count); |
472 | atomic_inc( &dev->counts[_DRM_STAT_IOCTLS] ); | 472 | atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]); |
473 | ++priv->ioctl_count; | 473 | ++priv->ioctl_count; |
474 | 474 | ||
475 | DRM_DEBUG( "pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n", | 475 | DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n", |
476 | current->pid, cmd, nr, (long)old_encode_dev(priv->head->device), | 476 | current->pid, cmd, nr, |
477 | priv->authenticated ); | 477 | (long)old_encode_dev(priv->head->device), |
478 | 478 | priv->authenticated); | |
479 | |||
479 | if (nr < DRIVER_IOCTL_COUNT) | 480 | if (nr < DRIVER_IOCTL_COUNT) |
480 | ioctl = &drm_ioctls[nr]; | 481 | ioctl = &drm_ioctls[nr]; |
481 | else if ((nr >= DRM_COMMAND_BASE) && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) | 482 | else if ((nr >= DRM_COMMAND_BASE) |
483 | && (nr < DRM_COMMAND_BASE + dev->driver->num_ioctls)) | ||
482 | ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE]; | 484 | ioctl = &dev->driver->ioctls[nr - DRM_COMMAND_BASE]; |
483 | else | 485 | else |
484 | goto err_i1; | 486 | goto err_i1; |
485 | 487 | ||
486 | func = ioctl->func; | 488 | func = ioctl->func; |
487 | /* is there a local override? */ | 489 | /* is there a local override? */ |
488 | if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl) | 490 | if ((nr == DRM_IOCTL_NR(DRM_IOCTL_DMA)) && dev->driver->dma_ioctl) |
489 | func = dev->driver->dma_ioctl; | 491 | func = dev->driver->dma_ioctl; |
490 | 492 | ||
491 | if ( !func ) { | 493 | if (!func) { |
492 | DRM_DEBUG( "no function\n" ); | 494 | DRM_DEBUG("no function\n"); |
493 | retcode = -EINVAL; | 495 | retcode = -EINVAL; |
494 | } else if ( ( ioctl->root_only && !capable( CAP_SYS_ADMIN ) )|| | 496 | } else if ((ioctl->root_only && !capable(CAP_SYS_ADMIN)) || |
495 | ( ioctl->auth_needed && !priv->authenticated ) ) { | 497 | (ioctl->auth_needed && !priv->authenticated)) { |
496 | retcode = -EACCES; | 498 | retcode = -EACCES; |
497 | } else { | 499 | } else { |
498 | retcode = func( inode, filp, cmd, arg ); | 500 | retcode = func(inode, filp, cmd, arg); |
499 | } | 501 | } |
500 | 502 | ||
501 | err_i1: | 503 | err_i1: |
502 | atomic_dec( &dev->ioctl_count ); | 504 | atomic_dec(&dev->ioctl_count); |
503 | if (retcode) DRM_DEBUG( "ret = %x\n", retcode); | 505 | if (retcode) |
506 | DRM_DEBUG("ret = %x\n", retcode); | ||
504 | return retcode; | 507 | return retcode; |
505 | } | 508 | } |
506 | EXPORT_SYMBOL(drm_ioctl); | ||
507 | 509 | ||
510 | EXPORT_SYMBOL(drm_ioctl); | ||