Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Macros | Functions
drm_gem.c File Reference
#include <linux/types.h>
#include <linux/slab.h>
#include <linux/mm.h>
#include <linux/uaccess.h>
#include <linux/fs.h>
#include <linux/file.h>
#include <linux/module.h>
#include <linux/mman.h>
#include <linux/pagemap.h>
#include <linux/shmem_fs.h>
#include <linux/dma-buf.h>
#include <drm/drmP.h>

Go to the source code of this file.




int drm_gem_init (struct drm_device *dev)
void drm_gem_destroy (struct drm_device *dev)
int drm_gem_object_init (struct drm_device *dev, struct drm_gem_object *obj, size_t size)
 EXPORT_SYMBOL (drm_gem_object_init)
int drm_gem_private_object_init (struct drm_device *dev, struct drm_gem_object *obj, size_t size)
 EXPORT_SYMBOL (drm_gem_private_object_init)
struct drm_gem_object * drm_gem_object_alloc (struct drm_device *dev, size_t size)
 EXPORT_SYMBOL (drm_gem_object_alloc)
int drm_gem_handle_delete (struct drm_file *filp, u32 handle)
 EXPORT_SYMBOL (drm_gem_handle_delete)
int drm_gem_handle_create (struct drm_file *file_priv, struct drm_gem_object *obj, u32 *handlep)
 EXPORT_SYMBOL (drm_gem_handle_create)
void drm_gem_free_mmap_offset (struct drm_gem_object *obj)
 EXPORT_SYMBOL (drm_gem_free_mmap_offset)
int drm_gem_create_mmap_offset (struct drm_gem_object *obj)
 EXPORT_SYMBOL (drm_gem_create_mmap_offset)
struct drm_gem_object * drm_gem_object_lookup (struct drm_device *dev, struct drm_file *filp, u32 handle)
 EXPORT_SYMBOL (drm_gem_object_lookup)
int drm_gem_close_ioctl (struct drm_device *dev, void *data, struct drm_file *file_priv)
int drm_gem_flink_ioctl (struct drm_device *dev, void *data, struct drm_file *file_priv)
int drm_gem_open_ioctl (struct drm_device *dev, void *data, struct drm_file *file_priv)
void drm_gem_open (struct drm_device *dev, struct drm_file *file_private)
void drm_gem_release (struct drm_device *dev, struct drm_file *file_private)
void drm_gem_object_release (struct drm_gem_object *obj)
 EXPORT_SYMBOL (drm_gem_object_release)
void drm_gem_object_free (struct kref *kref)
 EXPORT_SYMBOL (drm_gem_object_free)
void drm_gem_object_handle_free (struct drm_gem_object *obj)
 EXPORT_SYMBOL (drm_gem_object_handle_free)
void drm_gem_vm_open (struct vm_area_struct *vma)
 EXPORT_SYMBOL (drm_gem_vm_open)
void drm_gem_vm_close (struct vm_area_struct *vma)
 EXPORT_SYMBOL (drm_gem_vm_close)
int drm_gem_mmap (struct file *filp, struct vm_area_struct *vma)
 EXPORT_SYMBOL (drm_gem_mmap)

Detailed Description

This file provides some of the base ioctls and library routines for the graphics memory manager implemented by each device driver.

Because various devices have different requirements in terms of synchronization and migration strategies, implementing that is left up to the driver, and all that the general API provides should be generic – allocating objects, reading/writing data with the cpu, freeing objects. Even there, platform-dependent optimizations for reading/writing data with the CPU mean we'll likely hook those out to driver-specific calls. However, the DRI2 implementation wants to have at least allocate/mmap be generic.

The goal was to have swap-backed object allocation managed through struct file. However, file descriptors as handles to a struct file have two major failings:

This led to a plan of using our own integer IDs (called handles, following DRM terminology) to mimic fds, and implement the fd syscalls we need as ioctls. The objects themselves will still include the struct file so that we can transition to fds if the required kernel infrastructure shows up at a later date, and as our interface with shmfs for memory allocation.

Definition in file drm_gem.c.

Macro Definition Documentation


Definition at line 83 of file drm_gem.c.


Definition at line 82 of file drm_gem.c.

Function Documentation

int drm_gem_close_ioctl ( struct drm_device dev,
void data,
struct drm_file *  file_priv 

Releases the handle to an mm object.

Definition at line 419 of file drm_gem.c.

int drm_gem_create_mmap_offset ( struct drm_gem_object *  obj)

drm_gem_create_mmap_offset - create a fake mmap offset for an object : obj in question

GEM memory mapping works by handing back to userspace a fake mmap offset it can use in a subsequent mmap(2) call. The DRM core code then looks up the object based on the offset and sets up the various memory mapping structures.

This routine allocates and attaches a fake offset for .

Definition at line 336 of file drm_gem.c.

void drm_gem_destroy ( struct drm_device dev)

Definition at line 122 of file drm_gem.c.

int drm_gem_flink_ioctl ( struct drm_device dev,
void data,
struct drm_file *  file_priv 

Create a global name for an object, returning the name.

Note that the name does not hold a reference; when the object is freed, the name goes away.

Definition at line 440 of file drm_gem.c.

void drm_gem_free_mmap_offset ( struct drm_gem_object *  obj)

drm_gem_free_mmap_offset - release a fake mmap offset for an object : obj in question

This routine frees fake offsets allocated by drm_gem_create_mmap_offset().

Definition at line 311 of file drm_gem.c.

int drm_gem_handle_create ( struct drm_file *  file_priv,
struct drm_gem_object *  obj,
u32 handlep 

Create a handle for this object. This adds a handle reference to the object, which includes a regular reference count. Callers will likely want to dereference the object afterwards.

Definition at line 265 of file drm_gem.c.

int drm_gem_handle_delete ( struct drm_file *  filp,
u32  handle 

Removes the mapping from handle to filp for this object.

Definition at line 221 of file drm_gem.c.

int drm_gem_init ( struct drm_device dev)

Initialize the GEM device fields

Definition at line 91 of file drm_gem.c.

int drm_gem_mmap ( struct file filp,
struct vm_area_struct vma 

drm_gem_mmap - memory map routine for GEM objects : DRM file pointer : VMA for the area to be mapped

If a driver supports GEM object mapping, mmap calls on the DRM file descriptor will end up here.

If we find the object based on the offset passed in (vma->vm_pgoff will contain the fake offset we created when the GTT map ioctl was called on the object), we set up the driver fault handler so that any accesses to the object can be trapped, to perform migration, GTT binding, surface register allocation, or performance monitoring.

Definition at line 670 of file drm_gem.c.

struct drm_gem_object* drm_gem_object_alloc ( struct drm_device dev,
size_t  size 

Allocate a GEM object of the specified size with shmfs backing store

Definition at line 179 of file drm_gem.c.

void drm_gem_object_free ( struct kref kref)

Called after the last reference to the object has been lost. Must be called holding struct_ mutex

Frees the object

Definition at line 584 of file drm_gem.c.

void drm_gem_object_handle_free ( struct drm_gem_object *  obj)

Called after the last handle to the object has been closed

Removes any name for the object. Note that this must be called before drm_gem_object_free or we'll be touching freed memory

Definition at line 608 of file drm_gem.c.

int drm_gem_object_init ( struct drm_device dev,
struct drm_gem_object *  obj,
size_t  size 

Initialize an already allocated GEM object of the specified size with shmfs backing store.

Definition at line 136 of file drm_gem.c.

struct drm_gem_object* drm_gem_object_lookup ( struct drm_device dev,
struct drm_file *  filp,
u32  handle 

Returns a reference to the object named by the handle.

Definition at line 393 of file drm_gem.c.

void drm_gem_object_release ( struct drm_gem_object *  obj)

Definition at line 570 of file drm_gem.c.

void drm_gem_open ( struct drm_device dev,
struct drm_file *  file_private 

Called at device open time, sets up the structure for handling refcounting of mm objects.

Definition at line 527 of file drm_gem.c.

int drm_gem_open_ioctl ( struct drm_device dev,
void data,
struct drm_file *  file_priv 

Open an object using the global name, returning a handle and the size.

This handle (of course) holds a reference to the object, so the object will not go away until the handle is deleted.

Definition at line 492 of file drm_gem.c.

int drm_gem_private_object_init ( struct drm_device dev,
struct drm_gem_object *  obj,
size_t  size 

Initialize an already allocated GEM object of the specified size with no GEM provided backing store. Instead the caller is responsible for backing the object and handling it.

Definition at line 159 of file drm_gem.c.

void drm_gem_release ( struct drm_device dev,
struct drm_file *  file_private 

Called at close time when the filp is going away.

Releases any remaining references on objects by this filp.

Definition at line 560 of file drm_gem.c.

void drm_gem_vm_close ( struct vm_area_struct vma)

Definition at line 643 of file drm_gem.c.

void drm_gem_vm_open ( struct vm_area_struct vma)

Definition at line 631 of file drm_gem.c.

EXPORT_SYMBOL ( drm_gem_object_init  )
EXPORT_SYMBOL ( drm_gem_private_object_init  )
EXPORT_SYMBOL ( drm_gem_object_alloc  )
EXPORT_SYMBOL ( drm_gem_handle_delete  )
EXPORT_SYMBOL ( drm_gem_handle_create  )
EXPORT_SYMBOL ( drm_gem_free_mmap_offset  )
EXPORT_SYMBOL ( drm_gem_create_mmap_offset  )
EXPORT_SYMBOL ( drm_gem_object_lookup  )
EXPORT_SYMBOL ( drm_gem_object_release  )
EXPORT_SYMBOL ( drm_gem_object_free  )
EXPORT_SYMBOL ( drm_gem_object_handle_free  )
EXPORT_SYMBOL ( drm_gem_vm_open  )
EXPORT_SYMBOL ( drm_gem_vm_close  )
EXPORT_SYMBOL ( drm_gem_mmap  )