8
8
9
9
#include <linux/debugfs.h>
10
10
#include <linux/device.h>
11
- #include <linux/idr .h>
11
+ #include <linux/xarray .h>
12
12
13
13
#include <drm/drm_accel.h>
14
14
#include <drm/drm_debugfs.h>
17
17
#include <drm/drm_ioctl.h>
18
18
#include <drm/drm_print.h>
19
19
20
- static DEFINE_SPINLOCK (accel_minor_lock );
21
- static struct idr accel_minors_idr ;
20
+ DEFINE_XARRAY_ALLOC (accel_minors_xa );
22
21
23
22
static struct dentry * accel_debugfs_root ;
24
23
static struct class * accel_class ;
@@ -120,99 +119,6 @@ void accel_set_device_instance_params(struct device *kdev, int index)
120
119
kdev -> type = & accel_sysfs_device_minor ;
121
120
}
122
121
123
- /**
124
- * accel_minor_alloc() - Allocates a new accel minor
125
- *
126
- * This function access the accel minors idr and allocates from it
127
- * a new id to represent a new accel minor
128
- *
129
- * Return: A new id on success or error code in case idr_alloc failed
130
- */
131
- int accel_minor_alloc (void )
132
- {
133
- unsigned long flags ;
134
- int r ;
135
-
136
- spin_lock_irqsave (& accel_minor_lock , flags );
137
- r = idr_alloc (& accel_minors_idr , NULL , 0 , ACCEL_MAX_MINORS , GFP_NOWAIT );
138
- spin_unlock_irqrestore (& accel_minor_lock , flags );
139
-
140
- return r ;
141
- }
142
-
143
- /**
144
- * accel_minor_remove() - Remove an accel minor
145
- * @index: The minor id to remove.
146
- *
147
- * This function access the accel minors idr and removes from
148
- * it the member with the id that is passed to this function.
149
- */
150
- void accel_minor_remove (int index )
151
- {
152
- unsigned long flags ;
153
-
154
- spin_lock_irqsave (& accel_minor_lock , flags );
155
- idr_remove (& accel_minors_idr , index );
156
- spin_unlock_irqrestore (& accel_minor_lock , flags );
157
- }
158
-
159
- /**
160
- * accel_minor_replace() - Replace minor pointer in accel minors idr.
161
- * @minor: Pointer to the new minor.
162
- * @index: The minor id to replace.
163
- *
164
- * This function access the accel minors idr structure and replaces the pointer
165
- * that is associated with an existing id. Because the minor pointer can be
166
- * NULL, we need to explicitly pass the index.
167
- *
168
- * Return: 0 for success, negative value for error
169
- */
170
- void accel_minor_replace (struct drm_minor * minor , int index )
171
- {
172
- unsigned long flags ;
173
-
174
- spin_lock_irqsave (& accel_minor_lock , flags );
175
- idr_replace (& accel_minors_idr , minor , index );
176
- spin_unlock_irqrestore (& accel_minor_lock , flags );
177
- }
178
-
179
- /*
180
- * Looks up the given minor-ID and returns the respective DRM-minor object. The
181
- * refence-count of the underlying device is increased so you must release this
182
- * object with accel_minor_release().
183
- *
184
- * The object can be only a drm_minor that represents an accel device.
185
- *
186
- * As long as you hold this minor, it is guaranteed that the object and the
187
- * minor->dev pointer will stay valid! However, the device may get unplugged and
188
- * unregistered while you hold the minor.
189
- */
190
- static struct drm_minor * accel_minor_acquire (unsigned int minor_id )
191
- {
192
- struct drm_minor * minor ;
193
- unsigned long flags ;
194
-
195
- spin_lock_irqsave (& accel_minor_lock , flags );
196
- minor = idr_find (& accel_minors_idr , minor_id );
197
- if (minor )
198
- drm_dev_get (minor -> dev );
199
- spin_unlock_irqrestore (& accel_minor_lock , flags );
200
-
201
- if (!minor ) {
202
- return ERR_PTR (- ENODEV );
203
- } else if (drm_dev_is_unplugged (minor -> dev )) {
204
- drm_dev_put (minor -> dev );
205
- return ERR_PTR (- ENODEV );
206
- }
207
-
208
- return minor ;
209
- }
210
-
211
- static void accel_minor_release (struct drm_minor * minor )
212
- {
213
- drm_dev_put (minor -> dev );
214
- }
215
-
216
122
/**
217
123
* accel_open - open method for ACCEL file
218
124
* @inode: device inode
@@ -230,7 +136,7 @@ int accel_open(struct inode *inode, struct file *filp)
230
136
struct drm_minor * minor ;
231
137
int retcode ;
232
138
233
- minor = accel_minor_acquire ( iminor (inode ));
139
+ minor = drm_minor_acquire ( & accel_minors_xa , iminor (inode ));
234
140
if (IS_ERR (minor ))
235
141
return PTR_ERR (minor );
236
142
@@ -249,7 +155,7 @@ int accel_open(struct inode *inode, struct file *filp)
249
155
250
156
err_undo :
251
157
atomic_dec (& dev -> open_count );
252
- accel_minor_release (minor );
158
+ drm_minor_release (minor );
253
159
return retcode ;
254
160
}
255
161
EXPORT_SYMBOL_GPL (accel_open );
@@ -260,7 +166,7 @@ static int accel_stub_open(struct inode *inode, struct file *filp)
260
166
struct drm_minor * minor ;
261
167
int err ;
262
168
263
- minor = accel_minor_acquire ( iminor (inode ));
169
+ minor = drm_minor_acquire ( & accel_minors_xa , iminor (inode ));
264
170
if (IS_ERR (minor ))
265
171
return PTR_ERR (minor );
266
172
@@ -277,7 +183,7 @@ static int accel_stub_open(struct inode *inode, struct file *filp)
277
183
err = 0 ;
278
184
279
185
out :
280
- accel_minor_release (minor );
186
+ drm_minor_release (minor );
281
187
282
188
return err ;
283
189
}
@@ -293,15 +199,13 @@ void accel_core_exit(void)
293
199
unregister_chrdev (ACCEL_MAJOR , "accel" );
294
200
debugfs_remove (accel_debugfs_root );
295
201
accel_sysfs_destroy ();
296
- idr_destroy ( & accel_minors_idr );
202
+ WARN_ON (! xa_empty ( & accel_minors_xa ) );
297
203
}
298
204
299
205
int __init accel_core_init (void )
300
206
{
301
207
int ret ;
302
208
303
- idr_init (& accel_minors_idr );
304
-
305
209
ret = accel_sysfs_init ();
306
210
if (ret < 0 ) {
307
211
DRM_ERROR ("Cannot create ACCEL class: %d\n" , ret );
0 commit comments