drm_cdevsw.c revision 1.5 1 1.2 riastrad /* $NetBSD: drm_cdevsw.c,v 1.5 2018/08/27 06:51:17 riastradh Exp $ */
2 1.1 riastrad
3 1.1 riastrad /*-
4 1.1 riastrad * Copyright (c) 2013 The NetBSD Foundation, Inc.
5 1.1 riastrad * All rights reserved.
6 1.1 riastrad *
7 1.1 riastrad * This code is derived from software contributed to The NetBSD Foundation
8 1.1 riastrad * by Taylor R. Campbell.
9 1.1 riastrad *
10 1.1 riastrad * Redistribution and use in source and binary forms, with or without
11 1.1 riastrad * modification, are permitted provided that the following conditions
12 1.1 riastrad * are met:
13 1.1 riastrad * 1. Redistributions of source code must retain the above copyright
14 1.1 riastrad * notice, this list of conditions and the following disclaimer.
15 1.1 riastrad * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 riastrad * notice, this list of conditions and the following disclaimer in the
17 1.1 riastrad * documentation and/or other materials provided with the distribution.
18 1.1 riastrad *
19 1.1 riastrad * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 riastrad * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 riastrad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 riastrad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 riastrad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 riastrad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 riastrad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 riastrad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 riastrad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 riastrad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 riastrad * POSSIBILITY OF SUCH DAMAGE.
30 1.1 riastrad */
31 1.1 riastrad
32 1.1 riastrad #include <sys/cdefs.h>
33 1.2 riastrad __KERNEL_RCSID(0, "$NetBSD: drm_cdevsw.c,v 1.5 2018/08/27 06:51:17 riastradh Exp $");
34 1.1 riastrad
35 1.1 riastrad #include <sys/param.h>
36 1.1 riastrad #include <sys/types.h>
37 1.1 riastrad #include <sys/conf.h>
38 1.1 riastrad #include <sys/device.h>
39 1.1 riastrad #include <sys/file.h>
40 1.1 riastrad #include <sys/filedesc.h>
41 1.1 riastrad #include <sys/ioccom.h>
42 1.1 riastrad #include <sys/kauth.h>
43 1.1 riastrad #ifndef _MODULE
44 1.1 riastrad /* XXX Mega-kludge because modules are broken. */
45 1.1 riastrad #include <sys/once.h>
46 1.1 riastrad #endif
47 1.1 riastrad #include <sys/pmf.h>
48 1.1 riastrad #include <sys/poll.h>
49 1.1 riastrad #ifndef _MODULE
50 1.1 riastrad #include <sys/reboot.h> /* XXX drm_init kludge */
51 1.1 riastrad #endif
52 1.1 riastrad #include <sys/select.h>
53 1.1 riastrad
54 1.1 riastrad #include <uvm/uvm_extern.h>
55 1.1 riastrad
56 1.1 riastrad #include <linux/err.h>
57 1.1 riastrad
58 1.1 riastrad #include <linux/pm.h>
59 1.1 riastrad
60 1.1 riastrad #include <drm/drmP.h>
61 1.1 riastrad #include "../dist/drm/drm_legacy.h"
62 1.1 riastrad
63 1.1 riastrad static dev_type_open(drm_open);
64 1.1 riastrad
65 1.1 riastrad static int drm_firstopen(struct drm_device *);
66 1.1 riastrad
67 1.1 riastrad static int drm_close(struct file *);
68 1.1 riastrad static int drm_read(struct file *, off_t *, struct uio *, kauth_cred_t,
69 1.1 riastrad int);
70 1.1 riastrad static int drm_dequeue_event(struct drm_file *, size_t,
71 1.1 riastrad struct drm_pending_event **, int);
72 1.1 riastrad static int drm_poll(struct file *, int);
73 1.1 riastrad static int drm_kqfilter(struct file *, struct knote *);
74 1.1 riastrad static int drm_stat(struct file *, struct stat *);
75 1.1 riastrad static int drm_fop_mmap(struct file *, off_t *, size_t, int, int *, int *,
76 1.1 riastrad struct uvm_object **, int *);
77 1.1 riastrad static paddr_t drm_mmap(dev_t, off_t, int);
78 1.1 riastrad
79 1.1 riastrad const struct cdevsw drm_cdevsw = {
80 1.1 riastrad .d_open = drm_open,
81 1.1 riastrad .d_close = noclose,
82 1.1 riastrad .d_read = noread,
83 1.1 riastrad .d_write = nowrite,
84 1.1 riastrad .d_ioctl = noioctl,
85 1.1 riastrad .d_stop = nostop,
86 1.1 riastrad .d_tty = notty,
87 1.1 riastrad .d_poll = nopoll,
88 1.1 riastrad .d_mmap = drm_mmap,
89 1.1 riastrad .d_kqfilter = nokqfilter,
90 1.1 riastrad .d_discard = nodiscard,
91 1.1 riastrad /* XXX was D_TTY | D_NEGOFFSAFE */
92 1.1 riastrad /* XXX Add D_MPSAFE some day... */
93 1.1 riastrad .d_flag = D_NEGOFFSAFE,
94 1.1 riastrad };
95 1.1 riastrad
96 1.1 riastrad static const struct fileops drm_fileops = {
97 1.1 riastrad .fo_name = "drm",
98 1.1 riastrad .fo_read = drm_read,
99 1.1 riastrad .fo_write = fbadop_write,
100 1.1 riastrad .fo_ioctl = drm_ioctl,
101 1.1 riastrad .fo_fcntl = fnullop_fcntl,
102 1.1 riastrad .fo_poll = drm_poll,
103 1.1 riastrad .fo_stat = drm_stat,
104 1.1 riastrad .fo_close = drm_close,
105 1.1 riastrad .fo_kqfilter = drm_kqfilter,
106 1.1 riastrad .fo_restart = fnullop_restart,
107 1.1 riastrad .fo_mmap = drm_fop_mmap,
108 1.1 riastrad };
109 1.1 riastrad
110 1.1 riastrad static int
111 1.1 riastrad drm_open(dev_t d, int flags, int fmt, struct lwp *l)
112 1.1 riastrad {
113 1.1 riastrad struct drm_minor *dminor;
114 1.1 riastrad struct drm_device *dev;
115 1.1 riastrad bool firstopen, lastclose;
116 1.1 riastrad int fd;
117 1.1 riastrad struct file *fp;
118 1.1 riastrad int error;
119 1.1 riastrad extern int drm_guarantee_initialized(void);
120 1.1 riastrad
121 1.1 riastrad error = drm_guarantee_initialized();
122 1.1 riastrad if (error)
123 1.1 riastrad goto fail0;
124 1.1 riastrad
125 1.1 riastrad if (flags & O_EXCL) {
126 1.1 riastrad error = EBUSY;
127 1.1 riastrad goto fail0;
128 1.1 riastrad }
129 1.1 riastrad
130 1.1 riastrad dminor = drm_minor_acquire(minor(d));
131 1.1 riastrad if (IS_ERR(dminor)) {
132 1.1 riastrad /* XXX errno Linux->NetBSD */
133 1.1 riastrad error = -PTR_ERR(dminor);
134 1.1 riastrad goto fail0;
135 1.1 riastrad }
136 1.1 riastrad dev = dminor->dev;
137 1.1 riastrad if (dev->switch_power_state != DRM_SWITCH_POWER_ON) {
138 1.1 riastrad error = EINVAL;
139 1.1 riastrad goto fail1;
140 1.1 riastrad }
141 1.1 riastrad
142 1.1 riastrad spin_lock(&dev->count_lock);
143 1.1 riastrad if (dev->open_count == INT_MAX) {
144 1.1 riastrad spin_unlock(&dev->count_lock);
145 1.1 riastrad error = EBUSY;
146 1.1 riastrad goto fail1;
147 1.1 riastrad }
148 1.1 riastrad firstopen = (dev->open_count == 0);
149 1.1 riastrad dev->open_count++;
150 1.1 riastrad spin_unlock(&dev->count_lock);
151 1.1 riastrad
152 1.1 riastrad if (firstopen) {
153 1.1 riastrad /* XXX errno Linux->NetBSD */
154 1.5 riastrad error = -drm_firstopen(dev);
155 1.1 riastrad if (error)
156 1.1 riastrad goto fail2;
157 1.1 riastrad }
158 1.1 riastrad
159 1.1 riastrad error = fd_allocfile(&fp, &fd);
160 1.1 riastrad if (error)
161 1.1 riastrad goto fail2;
162 1.1 riastrad
163 1.1 riastrad struct drm_file *const file = kmem_zalloc(sizeof(*file), KM_SLEEP);
164 1.1 riastrad /* XXX errno Linux->NetBSD */
165 1.1 riastrad error = -drm_open_file(file, fp, dminor);
166 1.1 riastrad if (error)
167 1.1 riastrad goto fail3;
168 1.1 riastrad
169 1.1 riastrad error = fd_clone(fp, fd, flags, &drm_fileops, file);
170 1.1 riastrad KASSERT(error == EMOVEFD); /* XXX */
171 1.1 riastrad
172 1.1 riastrad /* Success! (But error has to be EMOVEFD, not 0.) */
173 1.1 riastrad return error;
174 1.1 riastrad
175 1.1 riastrad fail3: kmem_free(file, sizeof(*file));
176 1.1 riastrad fd_abort(curproc, fp, fd);
177 1.1 riastrad fail2: spin_lock(&dev->count_lock);
178 1.1 riastrad KASSERT(0 < dev->open_count);
179 1.1 riastrad --dev->open_count;
180 1.1 riastrad lastclose = (dev->open_count == 0);
181 1.1 riastrad spin_unlock(&dev->count_lock);
182 1.1 riastrad if (lastclose)
183 1.1 riastrad (void)drm_lastclose(dev);
184 1.1 riastrad fail1: drm_minor_release(dminor);
185 1.1 riastrad fail0: KASSERT(error);
186 1.1 riastrad return error;
187 1.1 riastrad }
188 1.1 riastrad
189 1.1 riastrad static int
190 1.1 riastrad drm_close(struct file *fp)
191 1.1 riastrad {
192 1.1 riastrad struct drm_file *const file = fp->f_data;
193 1.1 riastrad struct drm_minor *const dminor = file->minor;
194 1.1 riastrad struct drm_device *const dev = dminor->dev;
195 1.1 riastrad bool lastclose;
196 1.1 riastrad
197 1.1 riastrad drm_close_file(file);
198 1.1 riastrad kmem_free(file, sizeof(*file));
199 1.1 riastrad
200 1.1 riastrad spin_lock(&dev->count_lock);
201 1.1 riastrad KASSERT(0 < dev->open_count);
202 1.1 riastrad --dev->open_count;
203 1.1 riastrad lastclose = (dev->open_count == 0);
204 1.1 riastrad spin_unlock(&dev->count_lock);
205 1.1 riastrad
206 1.1 riastrad if (lastclose)
207 1.1 riastrad (void)drm_lastclose(dev);
208 1.1 riastrad
209 1.1 riastrad drm_minor_release(dminor);
210 1.1 riastrad
211 1.1 riastrad return 0;
212 1.1 riastrad }
213 1.1 riastrad
214 1.1 riastrad static int
215 1.1 riastrad drm_firstopen(struct drm_device *dev)
216 1.1 riastrad {
217 1.1 riastrad int ret;
218 1.1 riastrad
219 1.1 riastrad if (drm_core_check_feature(dev, DRIVER_MODESET))
220 1.1 riastrad return 0;
221 1.1 riastrad
222 1.1 riastrad if (dev->driver->firstopen) {
223 1.1 riastrad ret = (*dev->driver->firstopen)(dev);
224 1.1 riastrad if (ret)
225 1.1 riastrad goto fail0;
226 1.1 riastrad }
227 1.1 riastrad
228 1.1 riastrad ret = drm_legacy_dma_setup(dev);
229 1.1 riastrad if (ret)
230 1.1 riastrad goto fail1;
231 1.1 riastrad
232 1.1 riastrad return 0;
233 1.1 riastrad
234 1.1 riastrad fail2: __unused
235 1.1 riastrad drm_legacy_dma_takedown(dev);
236 1.1 riastrad fail1: if (dev->driver->lastclose)
237 1.1 riastrad (*dev->driver->lastclose)(dev);
238 1.1 riastrad fail0: KASSERT(ret);
239 1.1 riastrad return ret;
240 1.1 riastrad }
241 1.1 riastrad
242 1.1 riastrad int
243 1.1 riastrad drm_lastclose(struct drm_device *dev)
244 1.1 riastrad {
245 1.1 riastrad
246 1.1 riastrad /* XXX Order is sketchy here... */
247 1.1 riastrad if (dev->driver->lastclose)
248 1.1 riastrad (*dev->driver->lastclose)(dev);
249 1.1 riastrad if (dev->irq_enabled && !drm_core_check_feature(dev, DRIVER_MODESET))
250 1.1 riastrad drm_irq_uninstall(dev);
251 1.1 riastrad
252 1.1 riastrad mutex_lock(&dev->struct_mutex);
253 1.1 riastrad if (dev->agp)
254 1.1 riastrad drm_agp_clear_hook(dev);
255 1.1 riastrad drm_legacy_sg_cleanup(dev);
256 1.2 riastrad drm_legacy_vma_flush(dev);
257 1.1 riastrad drm_legacy_dma_takedown(dev);
258 1.2 riastrad
259 1.1 riastrad mutex_unlock(&dev->struct_mutex);
260 1.1 riastrad
261 1.2 riastrad drm_legacy_dev_reinit(dev);
262 1.1 riastrad
263 1.1 riastrad return 0;
264 1.1 riastrad }
265 1.1 riastrad
266 1.1 riastrad static int
267 1.1 riastrad drm_read(struct file *fp, off_t *off, struct uio *uio, kauth_cred_t cred,
268 1.1 riastrad int flags)
269 1.1 riastrad {
270 1.1 riastrad struct drm_file *const file = fp->f_data;
271 1.1 riastrad struct drm_pending_event *event;
272 1.1 riastrad bool first;
273 1.1 riastrad int error = 0;
274 1.1 riastrad
275 1.1 riastrad for (first = true; ; first = false) {
276 1.1 riastrad int f = 0;
277 1.1 riastrad
278 1.1 riastrad if (!first || ISSET(fp->f_flag, FNONBLOCK))
279 1.1 riastrad f |= FNONBLOCK;
280 1.1 riastrad
281 1.1 riastrad /* XXX errno Linux->NetBSD */
282 1.1 riastrad error = -drm_dequeue_event(file, uio->uio_resid, &event, f);
283 1.1 riastrad if (error) {
284 1.1 riastrad if ((error == EWOULDBLOCK) && !first)
285 1.1 riastrad error = 0;
286 1.1 riastrad break;
287 1.1 riastrad }
288 1.1 riastrad if (event == NULL)
289 1.1 riastrad break;
290 1.1 riastrad error = uiomove(event->event, event->event->length, uio);
291 1.1 riastrad if (error) /* XXX Requeue the event? */
292 1.1 riastrad break;
293 1.1 riastrad (*event->destroy)(event);
294 1.1 riastrad }
295 1.1 riastrad
296 1.1 riastrad /* Success! */
297 1.1 riastrad return error;
298 1.1 riastrad }
299 1.1 riastrad
300 1.1 riastrad static int
301 1.1 riastrad drm_dequeue_event(struct drm_file *file, size_t max_length,
302 1.1 riastrad struct drm_pending_event **eventp, int flags)
303 1.1 riastrad {
304 1.1 riastrad struct drm_device *const dev = file->minor->dev;
305 1.1 riastrad struct drm_pending_event *event = NULL;
306 1.1 riastrad unsigned long irqflags;
307 1.1 riastrad int ret = 0;
308 1.1 riastrad
309 1.1 riastrad spin_lock_irqsave(&dev->event_lock, irqflags);
310 1.1 riastrad
311 1.1 riastrad if (ISSET(flags, FNONBLOCK)) {
312 1.1 riastrad if (list_empty(&file->event_list))
313 1.1 riastrad ret = -EWOULDBLOCK;
314 1.1 riastrad } else {
315 1.1 riastrad DRM_SPIN_WAIT_UNTIL(ret, &file->event_wait, &dev->event_lock,
316 1.1 riastrad !list_empty(&file->event_list));
317 1.1 riastrad }
318 1.1 riastrad if (ret)
319 1.1 riastrad goto out;
320 1.1 riastrad
321 1.1 riastrad event = list_first_entry(&file->event_list, struct drm_pending_event,
322 1.1 riastrad link);
323 1.1 riastrad if (event->event->length > max_length) {
324 1.1 riastrad /* Event is too large, can't return it. */
325 1.1 riastrad event = NULL;
326 1.1 riastrad ret = 0;
327 1.1 riastrad goto out;
328 1.1 riastrad }
329 1.1 riastrad
330 1.1 riastrad file->event_space += event->event->length;
331 1.1 riastrad list_del(&event->link);
332 1.1 riastrad
333 1.1 riastrad out: spin_unlock_irqrestore(&dev->event_lock, irqflags);
334 1.1 riastrad *eventp = event;
335 1.1 riastrad return ret;
336 1.1 riastrad }
337 1.1 riastrad
338 1.1 riastrad static int
339 1.1 riastrad drm_poll(struct file *fp __unused, int events __unused)
340 1.1 riastrad {
341 1.1 riastrad struct drm_file *const file = fp->f_data;
342 1.1 riastrad struct drm_device *const dev = file->minor->dev;
343 1.1 riastrad int revents = 0;
344 1.1 riastrad unsigned long irqflags;
345 1.1 riastrad
346 1.1 riastrad if (!ISSET(events, (POLLIN | POLLRDNORM)))
347 1.1 riastrad return 0;
348 1.1 riastrad
349 1.1 riastrad spin_lock_irqsave(&dev->event_lock, irqflags);
350 1.1 riastrad if (list_empty(&file->event_list))
351 1.1 riastrad selrecord(curlwp, &file->event_selq);
352 1.1 riastrad else
353 1.1 riastrad revents |= (events & (POLLIN | POLLRDNORM));
354 1.1 riastrad spin_unlock_irqrestore(&dev->event_lock, irqflags);
355 1.1 riastrad
356 1.1 riastrad return revents;
357 1.1 riastrad }
358 1.1 riastrad
359 1.1 riastrad static void filt_drm_detach(struct knote *);
360 1.1 riastrad static int filt_drm_event(struct knote *, long);
361 1.1 riastrad
362 1.1 riastrad static const struct filterops drm_filtops = {
363 1.1 riastrad .f_isfd = 1,
364 1.1 riastrad .f_attach = NULL,
365 1.1 riastrad .f_detach = filt_drm_detach,
366 1.1 riastrad .f_event = filt_drm_event,
367 1.1 riastrad };
368 1.1 riastrad
369 1.1 riastrad static int
370 1.1 riastrad drm_kqfilter(struct file *fp, struct knote *kn)
371 1.1 riastrad {
372 1.1 riastrad struct drm_file *const file = fp->f_data;
373 1.1 riastrad struct drm_device *const dev = file->minor->dev;
374 1.1 riastrad unsigned long irqflags;
375 1.1 riastrad
376 1.1 riastrad switch (kn->kn_filter) {
377 1.1 riastrad case EVFILT_READ:
378 1.1 riastrad kn->kn_fop = &drm_filtops;
379 1.1 riastrad kn->kn_hook = file;
380 1.1 riastrad spin_lock_irqsave(&dev->event_lock, irqflags);
381 1.1 riastrad SLIST_INSERT_HEAD(&file->event_selq.sel_klist, kn, kn_selnext);
382 1.1 riastrad spin_unlock_irqrestore(&dev->event_lock, irqflags);
383 1.1 riastrad return 0;
384 1.1 riastrad case EVFILT_WRITE:
385 1.1 riastrad default:
386 1.1 riastrad return EINVAL;
387 1.1 riastrad }
388 1.1 riastrad }
389 1.1 riastrad
390 1.1 riastrad static void
391 1.1 riastrad filt_drm_detach(struct knote *kn)
392 1.1 riastrad {
393 1.1 riastrad struct drm_file *const file = kn->kn_hook;
394 1.1 riastrad struct drm_device *const dev = file->minor->dev;
395 1.1 riastrad unsigned long irqflags;
396 1.1 riastrad
397 1.1 riastrad spin_lock_irqsave(&dev->event_lock, irqflags);
398 1.1 riastrad SLIST_REMOVE(&file->event_selq.sel_klist, kn, knote, kn_selnext);
399 1.1 riastrad spin_unlock_irqrestore(&dev->event_lock, irqflags);
400 1.1 riastrad }
401 1.1 riastrad
402 1.1 riastrad static int
403 1.1 riastrad filt_drm_event(struct knote *kn, long hint)
404 1.1 riastrad {
405 1.1 riastrad struct drm_file *const file = kn->kn_hook;
406 1.1 riastrad struct drm_device *const dev = file->minor->dev;
407 1.1 riastrad unsigned long irqflags;
408 1.1 riastrad int ret;
409 1.1 riastrad
410 1.1 riastrad if (hint == NOTE_SUBMIT)
411 1.1 riastrad KASSERT(spin_is_locked(&dev->event_lock));
412 1.1 riastrad else
413 1.1 riastrad spin_lock_irqsave(&dev->event_lock, irqflags);
414 1.1 riastrad if (list_empty(&file->event_list)) {
415 1.1 riastrad ret = 0;
416 1.1 riastrad } else {
417 1.1 riastrad struct drm_pending_event *const event =
418 1.1 riastrad list_first_entry(&file->event_list,
419 1.1 riastrad struct drm_pending_event, link);
420 1.1 riastrad kn->kn_data = event->event->length;
421 1.1 riastrad ret = 1;
422 1.1 riastrad }
423 1.1 riastrad if (hint == NOTE_SUBMIT)
424 1.1 riastrad KASSERT(spin_is_locked(&dev->event_lock));
425 1.1 riastrad else
426 1.1 riastrad spin_unlock_irqrestore(&dev->event_lock, irqflags);
427 1.1 riastrad
428 1.1 riastrad return ret;
429 1.1 riastrad }
430 1.1 riastrad
431 1.1 riastrad static int
432 1.1 riastrad drm_stat(struct file *fp, struct stat *st)
433 1.1 riastrad {
434 1.1 riastrad struct drm_file *const file = fp->f_data;
435 1.1 riastrad struct drm_minor *const dminor = file->minor;
436 1.1 riastrad const dev_t devno = makedev(cdevsw_lookup_major(&drm_cdevsw),
437 1.1 riastrad 64*dminor->type + dminor->index);
438 1.1 riastrad
439 1.1 riastrad (void)memset(st, 0, sizeof(*st));
440 1.1 riastrad
441 1.1 riastrad st->st_dev = devno;
442 1.1 riastrad st->st_ino = 0; /* XXX (dev,ino) uniqueness bleh */
443 1.1 riastrad st->st_uid = kauth_cred_geteuid(fp->f_cred);
444 1.1 riastrad st->st_gid = kauth_cred_getegid(fp->f_cred);
445 1.1 riastrad st->st_mode = S_IFCHR; /* XXX what? */
446 1.1 riastrad st->st_rdev = devno;
447 1.1 riastrad /* XXX what else? */
448 1.1 riastrad
449 1.1 riastrad return 0;
450 1.1 riastrad }
451 1.1 riastrad
452 1.1 riastrad static int
453 1.1 riastrad drm_fop_mmap(struct file *fp, off_t *offp, size_t len, int prot, int *flagsp,
454 1.1 riastrad int *advicep, struct uvm_object **uobjp, int *maxprotp)
455 1.1 riastrad {
456 1.1 riastrad struct drm_file *const file = fp->f_data;
457 1.1 riastrad struct drm_device *const dev = file->minor->dev;
458 1.1 riastrad int error;
459 1.1 riastrad
460 1.1 riastrad KASSERT(fp == file->filp);
461 1.1 riastrad error = (*dev->driver->mmap_object)(dev, *offp, len, prot, uobjp,
462 1.1 riastrad offp, file->filp);
463 1.1 riastrad *maxprotp = prot;
464 1.1 riastrad *advicep = UVM_ADV_RANDOM;
465 1.1 riastrad return -error;
466 1.1 riastrad }
467 1.1 riastrad
468 1.1 riastrad static paddr_t
469 1.1 riastrad drm_mmap(dev_t d, off_t offset, int prot)
470 1.1 riastrad {
471 1.1 riastrad struct drm_minor *dminor;
472 1.1 riastrad paddr_t paddr;
473 1.1 riastrad
474 1.1 riastrad dminor = drm_minor_acquire(minor(d));
475 1.1 riastrad if (IS_ERR(dminor))
476 1.1 riastrad return (paddr_t)-1;
477 1.1 riastrad
478 1.1 riastrad paddr = drm_mmap_paddr(dminor->dev, offset, prot);
479 1.1 riastrad
480 1.1 riastrad drm_minor_release(dminor);
481 1.1 riastrad return paddr;
482 1.1 riastrad }
483