Lines Matching refs:dev
32 __FBSDID("$FreeBSD: releng/11.0/sys/dev/drm/drm_drv.c 283999 2015-06-04 20:36:16Z jhb $");
41 #include "dev/drm/drmP.h"
42 #include "dev/drm/drm.h"
43 #include "dev/drm/drm_sarea.h"
51 static int drm_load(struct drm_device *dev);
52 static void drm_unload(struct drm_device *dev);
185 struct drm_device *dev;
190 dev = device_get_softc(kdev);
192 dev->device = kdev;
193 dev->devnode = make_dev(&drm_cdevsw,
199 dev->devnode->si_drv1 = dev;
201 dev->pci_domain = pci_get_domain(dev->device);
202 dev->pci_bus = pci_get_bus(dev->device);
203 dev->pci_slot = pci_get_slot(dev->device);
204 dev->pci_func = pci_get_function(dev->device);
206 dev->pci_vendor = pci_get_vendor(dev->device);
207 dev->pci_device = pci_get_device(dev->device);
209 if (drm_core_check_feature(dev, DRIVER_HAVE_IRQ)) {
211 !drm_msi_is_blacklisted(dev->pci_vendor, dev->pci_device)) {
212 msicount = pci_msi_count(dev->device);
217 if (pci_alloc_msi(dev->device, &msicount) == 0) {
220 dev->msi_enabled = 1;
221 dev->irqrid = 1;
225 dev->irqr = bus_alloc_resource_any(dev->device, SYS_RES_IRQ,
226 &dev->irqrid, RF_SHAREABLE);
227 if (!dev->irqr) {
231 dev->irq = (int) rman_get_start(dev->irqr);
234 mtx_init(&dev->dev_lock, "drmdev", NULL, MTX_DEF);
235 mtx_init(&dev->irq_lock, "drmirq", NULL, MTX_DEF);
236 mtx_init(&dev->vbl_lock, "drmvbl", NULL, MTX_DEF);
237 mtx_init(&dev->drw_lock, "drmdrw", NULL, MTX_DEF);
239 id_entry = drm_find_description(dev->pci_vendor,
240 dev->pci_device, idlist);
241 dev->id_entry = id_entry;
243 return drm_load(dev);
248 struct drm_device *dev;
250 dev = device_get_softc(kdev);
252 drm_unload(dev);
254 if (dev->irqr) {
255 bus_release_resource(dev->device, SYS_RES_IRQ, dev->irqrid,
256 dev->irqr);
258 if (dev->msi_enabled) {
259 pci_release_msi(dev->device);
288 static int drm_firstopen(struct drm_device *dev)
293 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
296 i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM,
301 if (dev->driver->firstopen)
302 dev->driver->firstopen(dev);
304 dev->buf_use = 0;
306 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) {
307 i = drm_dma_setup(dev);
313 dev->magiclist[i].head = NULL;
314 dev->magiclist[i].tail = NULL;
317 dev->lock.lock_queue = 0;
318 dev->irq_enabled = 0;
319 dev->context_flag = 0;
320 dev->last_context = 0;
321 dev->if_version = 0;
323 dev->buf_sigio = NULL;
330 static int drm_lastclose(struct drm_device *dev)
336 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
340 if (dev->driver->lastclose != NULL)
341 dev->driver->lastclose(dev);
343 if (dev->irq_enabled)
344 drm_irq_uninstall(dev);
346 if (dev->unique) {
347 free(dev->unique, DRM_MEM_DRIVER);
348 dev->unique = NULL;
349 dev->unique_len = 0;
353 for (pt = dev->magiclist[i].head; pt; pt = next) {
357 dev->magiclist[i].head = dev->magiclist[i].tail = NULL;
361 drm_drawable_free_all(dev);
365 if (dev->agp) {
369 /* Remove AGP resources, but leave dev->agp intact until
372 for (entry = dev->agp->memory; entry; entry = nexte) {
379 dev->agp->memory = NULL;
381 if (dev->agp->acquired)
382 drm_agp_release(dev);
384 dev->agp->acquired = 0;
385 dev->agp->enabled = 0;
387 if (dev->sg != NULL) {
388 drm_sg_cleanup(dev->sg);
389 dev->sg = NULL;
392 TAILQ_FOREACH_SAFE(map, &dev->maplist, link, mapsave) {
394 drm_rmmap(dev, map);
397 drm_dma_takedown(dev);
398 if (dev->lock.hw_lock) {
399 dev->lock.hw_lock = NULL; /* SHM removed */
400 dev->lock.file_priv = NULL;
401 DRM_WAKEUP_INT((void *)&dev->lock.lock_queue);
407 static int drm_load(struct drm_device *dev)
413 TAILQ_INIT(&dev->maplist);
414 dev->map_unrhdr = new_unrhdr(1, ((1 << DRM_MAP_HANDLE_BITS) - 1), NULL);
415 if (dev->map_unrhdr == NULL) {
422 drm_sysctl_init(dev);
423 TAILQ_INIT(&dev->files);
425 dev->counters = 6;
426 dev->types[0] = _DRM_STAT_LOCK;
427 dev->types[1] = _DRM_STAT_OPENS;
428 dev->types[2] = _DRM_STAT_CLOSES;
429 dev->types[3] = _DRM_STAT_IOCTLS;
430 dev->types[4] = _DRM_STAT_LOCKS;
431 dev->types[5] = _DRM_STAT_UNLOCKS;
433 for (i = 0; i < DRM_ARRAY_SIZE(dev->counts); i++)
434 atomic_set(&dev->counts[i], 0);
436 if (dev->driver->load != NULL) {
439 retcode = -dev->driver->load(dev,
440 dev->id_entry->driver_private);
441 if (pci_enable_busmaster(dev->device))
448 if (drm_core_has_AGP(dev)) {
449 if (drm_device_is_agp(dev))
450 dev->agp = drm_agp_init();
451 if (drm_core_check_feature(dev, DRIVER_REQUIRE_AGP) &&
452 dev->agp == NULL) {
458 if (dev->agp != NULL && dev->agp->info.ai_aperture_base != 0) {
459 if (drm_mtrr_add(dev->agp->info.ai_aperture_base,
460 dev->agp->info.ai_aperture_size, DRM_MTRR_WC) == 0)
461 dev->agp->mtrr = 1;
465 retcode = drm_ctxbitmap_init(dev);
471 dev->drw_unrhdr = new_unrhdr(1, INT_MAX, NULL);
472 if (dev->drw_unrhdr == NULL) {
478 dev->driver->name,
479 dev->driver->major,
480 dev->driver->minor,
481 dev->driver->patchlevel,
482 dev->driver->date);
487 drm_sysctl_cleanup(dev);
489 drm_lastclose(dev);
491 destroy_dev(dev->devnode);
493 mtx_destroy(&dev->drw_lock);
494 mtx_destroy(&dev->vbl_lock);
495 mtx_destroy(&dev->irq_lock);
496 mtx_destroy(&dev->dev_lock);
501 static void drm_unload(struct drm_device *dev)
507 drm_sysctl_cleanup(dev);
508 destroy_dev(dev->devnode);
510 drm_ctxbitmap_cleanup(dev);
512 if (dev->agp && dev->agp->mtrr) {
515 retcode = drm_mtrr_del(0, dev->agp->info.ai_aperture_base,
516 dev->agp->info.ai_aperture_size, DRM_MTRR_WC);
520 drm_vblank_cleanup(dev);
523 drm_lastclose(dev);
532 if (dev->pcir[i] == NULL)
534 bus_release_resource(dev->device, SYS_RES_MEMORY,
535 dev->pcirid[i], dev->pcir[i]);
536 dev->pcir[i] = NULL;
539 if (dev->agp) {
540 free(dev->agp, DRM_MEM_AGPLISTS);
541 dev->agp = NULL;
544 if (dev->driver->unload != NULL) {
546 dev->driver->unload(dev);
550 delete_unrhdr(dev->drw_unrhdr);
551 delete_unrhdr(dev->map_unrhdr);
555 if (pci_disable_busmaster(dev->device))
558 mtx_destroy(&dev->drw_lock);
559 mtx_destroy(&dev->vbl_lock);
560 mtx_destroy(&dev->irq_lock);
561 mtx_destroy(&dev->dev_lock);
564 int drm_version(struct drm_device *dev, void *data, struct drm_file *file_priv)
578 version->version_major = dev->driver->major;
579 version->version_minor = dev->driver->minor;
580 version->version_patchlevel = dev->driver->patchlevel;
582 DRM_COPY(version->name, dev->driver->name);
583 DRM_COPY(version->date, dev->driver->date);
584 DRM_COPY(version->desc, dev->driver->desc);
591 struct drm_device *dev = NULL;
594 dev = kdev->si_drv1;
596 DRM_DEBUG("open_count = %d\n", dev->open_count);
598 retcode = drm_open_helper(kdev, flags, fmt, p, dev);
601 atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
603 device_busy(dev->device);
604 if (!dev->open_count++)
605 retcode = drm_firstopen(dev);
615 struct drm_device *dev = file_priv->dev;
618 DRM_DEBUG("open_count = %d\n", dev->open_count);
622 if (dev->driver->preclose != NULL)
623 dev->driver->preclose(dev, file_priv);
630 DRM_CURRENTPID, (long)dev->device, dev->open_count);
632 if (dev->lock.hw_lock && _DRM_LOCK_IS_HELD(dev->lock.hw_lock->lock)
633 && dev->lock.file_priv == file_priv) {
636 _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
637 if (dev->driver->reclaim_buffers_locked != NULL)
638 dev->driver->reclaim_buffers_locked(dev, file_priv);
640 drm_lock_free(&dev->lock,
641 _DRM_LOCKING_CONTEXT(dev->lock.hw_lock->lock));
647 } else if (dev->driver->reclaim_buffers_locked != NULL &&
648 dev->lock.hw_lock != NULL) {
651 if (!dev->lock.hw_lock) {
656 if (drm_lock_take(&dev->lock, DRM_KERNEL_CONTEXT)) {
657 dev->lock.file_priv = file_priv;
658 dev->lock.lock_time = jiffies;
659 atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
663 retcode = mtx_sleep((void *)&dev->lock.lock_queue,
664 &dev->dev_lock, PCATCH, "drmlk2", 0);
669 dev->driver->reclaim_buffers_locked(dev, file_priv);
670 drm_lock_free(&dev->lock, DRM_KERNEL_CONTEXT);
674 if (drm_core_check_feature(dev, DRIVER_HAVE_DMA) &&
675 !dev->driver->reclaim_buffers_locked)
676 drm_reclaim_buffers(dev, file_priv);
678 funsetown(&dev->buf_sigio);
680 if (dev->driver->postclose != NULL)
681 dev->driver->postclose(dev, file_priv);
682 TAILQ_REMOVE(&dev->files, file_priv, link);
689 atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
690 device_unbusy(dev->device);
691 if (--dev->open_count == 0) {
692 retcode = drm_lastclose(dev);
698 /* drm_ioctl is called whenever a process performs an ioctl on /dev/drm.
703 struct drm_device *dev = drm_get_device_from_kdev(kdev);
706 int (*func)(struct drm_device *dev, void *data, struct drm_file *file_priv);
717 atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
720 DRM_DEBUG("pid=%d, cmd=0x%02lx, nr=0x%02x, dev 0x%lx, auth=%d\n",
721 DRM_CURRENTPID, cmd, nr, (long)dev->device,
730 return fsetown(*(int *)data, &dev->buf_sigio);
733 *(int *) data = fgetown(&dev->buf_sigio);
747 if (nr > dev->driver->max_ioctl) {
749 nr, dev->driver->max_ioctl);
752 ioctl = &dev->driver->ioctls[nr];
770 retcode = -func(dev, data, file_priv);
773 retcode = func(dev, data, file_priv);
782 drm_local_map_t *drm_getsarea(struct drm_device *dev)
786 DRM_SPINLOCK_ASSERT(&dev->dev_lock);
787 TAILQ_FOREACH(map, &dev->maplist, link) {