/** * Removes the given magic number from the hash table of used magic number * lists. */ static int drm_remove_magic(struct drm_device *dev, drm_magic_t magic) { drm_magic_entry_t *prev = NULL; drm_magic_entry_t *pt; int hash; DRM_LOCK_ASSERT(dev); DRM_DEBUG("%d\n", magic); hash = drm_hash_magic(magic); for (pt = dev->magiclist[hash].head; pt; prev = pt, pt = pt->next) { if (pt->magic == magic) { if (dev->magiclist[hash].head == pt) { dev->magiclist[hash].head = pt->next; } if (dev->magiclist[hash].tail == pt) { dev->magiclist[hash].tail = prev; } if (prev) { prev->next = pt->next; } drm_free(pt, DRM_MEM_MAGIC); return 0; } } return EINVAL; }
/** * Inserts the given magic number into the hash table of used magic number * lists. */ static int drm_add_magic(struct drm_device *dev, struct drm_file *priv, drm_magic_t magic) { int hash; drm_magic_entry_t *entry; DRM_DEBUG("%d\n", magic); DRM_LOCK_ASSERT(dev); hash = drm_hash_magic(magic); entry = kmalloc(sizeof(*entry), DRM_MEM_MAGIC, M_ZERO | M_NOWAIT); if (!entry) return ENOMEM; entry->magic = magic; entry->priv = priv; entry->next = NULL; if (dev->magiclist[hash].tail) { dev->magiclist[hash].tail->next = entry; dev->magiclist[hash].tail = entry; } else { dev->magiclist[hash].head = entry; dev->magiclist[hash].tail = entry; } return 0; }
/** * The default context needs to exist per ring that uses contexts. It stores the * context state of the GPU for applications that don't utilize HW contexts, as * well as an idle case. */ static int create_default_context(struct drm_i915_private *dev_priv) { struct i915_hw_context *ctx; int ret; DRM_LOCK_ASSERT(dev_priv->dev); ret = create_hw_context(dev_priv->dev, NULL, &ctx); if (ret != 0) return (ret); /* We may need to do things with the shrinker which require us to * immediately switch back to the default context. This can cause a * problem as pinning the default context also requires GTT space which * may not be available. To avoid this we always pin the * default context. */ dev_priv->rings[RCS].default_context = ctx; ret = i915_gem_object_pin(ctx->obj, CONTEXT_ALIGN, false); if (ret) goto err_destroy; ret = do_switch(ctx); if (ret) goto err_unpin; DRM_DEBUG_DRIVER("Default HW context loaded\n"); return 0; err_unpin: i915_gem_object_unpin(ctx->obj); err_destroy: do_destroy(ctx); return ret; }
void drm_gem_object_free(struct drm_gem_object *obj) { struct drm_device *dev = obj->dev; DRM_LOCK_ASSERT(dev); if (dev->driver->gem_free_object != NULL) dev->driver->gem_free_object(obj); }
/** * Returns the file private associated with the given magic number. */ static struct drm_file *drm_find_file(struct drm_device *dev, drm_magic_t magic) { drm_magic_entry_t *pt; int hash = drm_hash_magic(magic); DRM_LOCK_ASSERT(dev); for (pt = dev->magiclist[hash].head; pt; pt = pt->next) { if (pt->magic == magic) { return pt->priv; } } return NULL; }
static int drm_setup(struct drm_device *dev) { drm_local_map_t *map; int i; DRM_LOCK_ASSERT(dev); /* prebuild the SAREA */ i = drm_addmap(dev, 0, SAREA_MAX, _DRM_SHM, _DRM_CONTAINS_LOCK, &map); if (i != 0) return i; if (dev->driver->firstopen) dev->driver->firstopen(dev); dev->buf_use = 0; if (drm_core_check_feature(dev, DRIVER_HAVE_DMA)) { i = drm_dma_setup(dev); if (i != 0) return i; } for (i = 0; i < DRM_HASH_SIZE; i++) { dev->magiclist[i].head = NULL; dev->magiclist[i].tail = NULL; } init_waitqueue_head(&dev->lock.lock_queue); if (!drm_core_check_feature(dev, DRIVER_MODESET)) dev->irq_enabled = 0; dev->context_flag = 0; dev->last_context = 0; dev->if_version = 0; dev->buf_sigio = NULL; DRM_DEBUG("\n"); return 0; }