aboutsummaryrefslogtreecommitdiffstats
path: root/include/drm
diff options
context:
space:
mode:
authorDaniel Vetter <daniel.vetter@ffwll.ch>2014-09-23 09:46:53 -0400
committerDave Airlie <airlied@redhat.com>2014-09-23 21:43:41 -0400
commitd9fc9413f97f5c615256a5657ec667c064c07a70 (patch)
tree42f6e33995c93f08e96dcfc886c2aaa1e45d2c72 /include/drm
parentc2611031b49e9ccd571a3737845af3fca2a2090f (diff)
drm: Extract <drm/drm_gem.h>
v2: Don't forget git add, noticed by David. Cc: David Herrmann <dh.herrmann@gmail.com> Signed-off-by: Daniel Vetter <daniel.vetter@intel.com> Acked-by: David Herrmann <dh.herrmann@gmail.com> Acked-by: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Dave Airlie <airlied@redhat.com>
Diffstat (limited to 'include/drm')
-rw-r--r--include/drm/drmP.h148
-rw-r--r--include/drm/drm_gem.h183
-rw-r--r--include/drm/drm_gem_cma_helper.h1
3 files changed, 185 insertions, 147 deletions
diff --git a/include/drm/drmP.h b/include/drm/drmP.h
index 6656fd7d64d4..d2c2b7f3a4e2 100644
--- a/include/drm/drmP.h
+++ b/include/drm/drmP.h
@@ -82,6 +82,7 @@ struct drm_agp_head;
82struct drm_local_map; 82struct drm_local_map;
83struct drm_device_dma; 83struct drm_device_dma;
84struct drm_dma_handle; 84struct drm_dma_handle;
85struct drm_gem_object;
85 86
86struct device_node; 87struct device_node;
87struct videomode; 88struct videomode;
@@ -331,93 +332,6 @@ struct drm_lock_data {
331}; 332};
332 333
333/** 334/**
334 * This structure defines the drm_mm memory object, which will be used by the
335 * DRM for its buffer objects.
336 */
337struct drm_gem_object {
338 /** Reference count of this object */
339 struct kref refcount;
340
341 /**
342 * handle_count - gem file_priv handle count of this object
343 *
344 * Each handle also holds a reference. Note that when the handle_count
345 * drops to 0 any global names (e.g. the id in the flink namespace) will
346 * be cleared.
347 *
348 * Protected by dev->object_name_lock.
349 * */
350 unsigned handle_count;
351
352 /** Related drm device */
353 struct drm_device *dev;
354
355 /** File representing the shmem storage */
356 struct file *filp;
357
358 /* Mapping info for this object */
359 struct drm_vma_offset_node vma_node;
360
361 /**
362 * Size of the object, in bytes. Immutable over the object's
363 * lifetime.
364 */
365 size_t size;
366
367 /**
368 * Global name for this object, starts at 1. 0 means unnamed.
369 * Access is covered by the object_name_lock in the related drm_device
370 */
371 int name;
372
373 /**
374 * Memory domains. These monitor which caches contain read/write data
375 * related to the object. When transitioning from one set of domains
376 * to another, the driver is called to ensure that caches are suitably
377 * flushed and invalidated
378 */
379 uint32_t read_domains;
380 uint32_t write_domain;
381
382 /**
383 * While validating an exec operation, the
384 * new read/write domain values are computed here.
385 * They will be transferred to the above values
386 * at the point that any cache flushing occurs
387 */
388 uint32_t pending_read_domains;
389 uint32_t pending_write_domain;
390
391 /**
392 * dma_buf - dma buf associated with this GEM object
393 *
394 * Pointer to the dma-buf associated with this gem object (either
395 * through importing or exporting). We break the resulting reference
396 * loop when the last gem handle for this object is released.
397 *
398 * Protected by obj->object_name_lock
399 */
400 struct dma_buf *dma_buf;
401
402 /**
403 * import_attach - dma buf attachment backing this object
404 *
405 * Any foreign dma_buf imported as a gem object has this set to the
406 * attachment point for the device. This is invariant over the lifetime
407 * of a gem object.
408 *
409 * The driver's ->gem_free_object callback is responsible for cleaning
410 * up the dma_buf attachment and references acquired at import time.
411 *
412 * Note that the drm gem/prime core does not depend upon drivers setting
413 * this field any more. So for drivers where this doesn't make sense
414 * (e.g. virtual devices or a displaylink behind an usb bus) they can
415 * simply leave it as NULL.
416 */
417 struct dma_buf_attachment *import_attach;
418};
419
420/**
421 * struct drm_master - drm master structure 335 * struct drm_master - drm master structure
422 * 336 *
423 * @refcount: Refcount for this master object. 337 * @refcount: Refcount for this master object.
@@ -1073,10 +987,6 @@ extern int drm_prime_sg_to_page_addr_arrays(struct sg_table *sgt, struct page **
1073extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages); 987extern struct sg_table *drm_prime_pages_to_sg(struct page **pages, int nr_pages);
1074extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg); 988extern void drm_prime_gem_destroy(struct drm_gem_object *obj, struct sg_table *sg);
1075 989
1076int drm_gem_dumb_destroy(struct drm_file *file,
1077 struct drm_device *dev,
1078 uint32_t handle);
1079
1080 990
1081extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size, 991extern struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
1082 size_t align); 992 size_t align);
@@ -1085,62 +995,6 @@ extern void drm_pci_free(struct drm_device *dev, struct drm_dma_handle * dmah);
1085 /* sysfs support (drm_sysfs.c) */ 995 /* sysfs support (drm_sysfs.c) */
1086extern void drm_sysfs_hotplug_event(struct drm_device *dev); 996extern void drm_sysfs_hotplug_event(struct drm_device *dev);
1087 997
1088/* Graphics Execution Manager library functions (drm_gem.c) */
1089void drm_gem_object_release(struct drm_gem_object *obj);
1090void drm_gem_object_free(struct kref *kref);
1091int drm_gem_object_init(struct drm_device *dev,
1092 struct drm_gem_object *obj, size_t size);
1093void drm_gem_private_object_init(struct drm_device *dev,
1094 struct drm_gem_object *obj, size_t size);
1095void drm_gem_vm_open(struct vm_area_struct *vma);
1096void drm_gem_vm_close(struct vm_area_struct *vma);
1097int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
1098 struct vm_area_struct *vma);
1099int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
1100
1101static inline void
1102drm_gem_object_reference(struct drm_gem_object *obj)
1103{
1104 kref_get(&obj->refcount);
1105}
1106
1107static inline void
1108drm_gem_object_unreference(struct drm_gem_object *obj)
1109{
1110 if (obj != NULL)
1111 kref_put(&obj->refcount, drm_gem_object_free);
1112}
1113
1114static inline void
1115drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
1116{
1117 if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
1118 struct drm_device *dev = obj->dev;
1119
1120 mutex_lock(&dev->struct_mutex);
1121 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
1122 drm_gem_object_free(&obj->refcount);
1123 mutex_unlock(&dev->struct_mutex);
1124 }
1125}
1126
1127int drm_gem_handle_create(struct drm_file *file_priv,
1128 struct drm_gem_object *obj,
1129 u32 *handlep);
1130int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
1131
1132
1133void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
1134int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
1135int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
1136
1137struct page **drm_gem_get_pages(struct drm_gem_object *obj);
1138void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
1139 bool dirty, bool accessed);
1140
1141struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
1142 struct drm_file *filp,
1143 u32 handle);
1144 998
1145struct drm_device *drm_dev_alloc(struct drm_driver *driver, 999struct drm_device *drm_dev_alloc(struct drm_driver *driver,
1146 struct device *parent); 1000 struct device *parent);
diff --git a/include/drm/drm_gem.h b/include/drm/drm_gem.h
new file mode 100644
index 000000000000..1e6ae1458f7a
--- /dev/null
+++ b/include/drm/drm_gem.h
@@ -0,0 +1,183 @@
1#ifndef __DRM_GEM_H__
2#define __DRM_GEM_H__
3
4/*
5 * GEM Graphics Execution Manager Driver Interfaces
6 *
7 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
8 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
9 * Copyright (c) 2009-2010, Code Aurora Forum.
10 * All rights reserved.
11 * Copyright © 2014 Intel Corporation
12 * Daniel Vetter <daniel.vetter@ffwll.ch>
13 *
14 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
15 * Author: Gareth Hughes <gareth@valinux.com>
16 *
17 * Permission is hereby granted, free of charge, to any person obtaining a
18 * copy of this software and associated documentation files (the "Software"),
19 * to deal in the Software without restriction, including without limitation
20 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
21 * and/or sell copies of the Software, and to permit persons to whom the
22 * Software is furnished to do so, subject to the following conditions:
23 *
24 * The above copyright notice and this permission notice (including the next
25 * paragraph) shall be included in all copies or substantial portions of the
26 * Software.
27 *
28 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
29 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
30 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
31 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
32 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
33 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
34 * OTHER DEALINGS IN THE SOFTWARE.
35 */
36
37/**
38 * This structure defines the drm_mm memory object, which will be used by the
39 * DRM for its buffer objects.
40 */
41struct drm_gem_object {
42 /** Reference count of this object */
43 struct kref refcount;
44
45 /**
46 * handle_count - gem file_priv handle count of this object
47 *
48 * Each handle also holds a reference. Note that when the handle_count
49 * drops to 0 any global names (e.g. the id in the flink namespace) will
50 * be cleared.
51 *
52 * Protected by dev->object_name_lock.
53 * */
54 unsigned handle_count;
55
56 /** Related drm device */
57 struct drm_device *dev;
58
59 /** File representing the shmem storage */
60 struct file *filp;
61
62 /* Mapping info for this object */
63 struct drm_vma_offset_node vma_node;
64
65 /**
66 * Size of the object, in bytes. Immutable over the object's
67 * lifetime.
68 */
69 size_t size;
70
71 /**
72 * Global name for this object, starts at 1. 0 means unnamed.
73 * Access is covered by the object_name_lock in the related drm_device
74 */
75 int name;
76
77 /**
78 * Memory domains. These monitor which caches contain read/write data
79 * related to the object. When transitioning from one set of domains
80 * to another, the driver is called to ensure that caches are suitably
81 * flushed and invalidated
82 */
83 uint32_t read_domains;
84 uint32_t write_domain;
85
86 /**
87 * While validating an exec operation, the
88 * new read/write domain values are computed here.
89 * They will be transferred to the above values
90 * at the point that any cache flushing occurs
91 */
92 uint32_t pending_read_domains;
93 uint32_t pending_write_domain;
94
95 /**
96 * dma_buf - dma buf associated with this GEM object
97 *
98 * Pointer to the dma-buf associated with this gem object (either
99 * through importing or exporting). We break the resulting reference
100 * loop when the last gem handle for this object is released.
101 *
102 * Protected by obj->object_name_lock
103 */
104 struct dma_buf *dma_buf;
105
106 /**
107 * import_attach - dma buf attachment backing this object
108 *
109 * Any foreign dma_buf imported as a gem object has this set to the
110 * attachment point for the device. This is invariant over the lifetime
111 * of a gem object.
112 *
113 * The driver's ->gem_free_object callback is responsible for cleaning
114 * up the dma_buf attachment and references acquired at import time.
115 *
116 * Note that the drm gem/prime core does not depend upon drivers setting
117 * this field any more. So for drivers where this doesn't make sense
118 * (e.g. virtual devices or a displaylink behind an usb bus) they can
119 * simply leave it as NULL.
120 */
121 struct dma_buf_attachment *import_attach;
122};
123
124void drm_gem_object_release(struct drm_gem_object *obj);
125void drm_gem_object_free(struct kref *kref);
126int drm_gem_object_init(struct drm_device *dev,
127 struct drm_gem_object *obj, size_t size);
128void drm_gem_private_object_init(struct drm_device *dev,
129 struct drm_gem_object *obj, size_t size);
130void drm_gem_vm_open(struct vm_area_struct *vma);
131void drm_gem_vm_close(struct vm_area_struct *vma);
132int drm_gem_mmap_obj(struct drm_gem_object *obj, unsigned long obj_size,
133 struct vm_area_struct *vma);
134int drm_gem_mmap(struct file *filp, struct vm_area_struct *vma);
135
136static inline void
137drm_gem_object_reference(struct drm_gem_object *obj)
138{
139 kref_get(&obj->refcount);
140}
141
142static inline void
143drm_gem_object_unreference(struct drm_gem_object *obj)
144{
145 if (obj != NULL)
146 kref_put(&obj->refcount, drm_gem_object_free);
147}
148
149static inline void
150drm_gem_object_unreference_unlocked(struct drm_gem_object *obj)
151{
152 if (obj && !atomic_add_unless(&obj->refcount.refcount, -1, 1)) {
153 struct drm_device *dev = obj->dev;
154
155 mutex_lock(&dev->struct_mutex);
156 if (likely(atomic_dec_and_test(&obj->refcount.refcount)))
157 drm_gem_object_free(&obj->refcount);
158 mutex_unlock(&dev->struct_mutex);
159 }
160}
161
162int drm_gem_handle_create(struct drm_file *file_priv,
163 struct drm_gem_object *obj,
164 u32 *handlep);
165int drm_gem_handle_delete(struct drm_file *filp, u32 handle);
166
167
168void drm_gem_free_mmap_offset(struct drm_gem_object *obj);
169int drm_gem_create_mmap_offset(struct drm_gem_object *obj);
170int drm_gem_create_mmap_offset_size(struct drm_gem_object *obj, size_t size);
171
172struct page **drm_gem_get_pages(struct drm_gem_object *obj);
173void drm_gem_put_pages(struct drm_gem_object *obj, struct page **pages,
174 bool dirty, bool accessed);
175
176struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev,
177 struct drm_file *filp,
178 u32 handle);
179int drm_gem_dumb_destroy(struct drm_file *file,
180 struct drm_device *dev,
181 uint32_t handle);
182
183#endif /* __DRM_GEM_H__ */
diff --git a/include/drm/drm_gem_cma_helper.h b/include/drm/drm_gem_cma_helper.h
index 2a3cea91606d..42f11f3a8d39 100644
--- a/include/drm/drm_gem_cma_helper.h
+++ b/include/drm/drm_gem_cma_helper.h
@@ -2,6 +2,7 @@
2#define __DRM_GEM_CMA_HELPER_H__ 2#define __DRM_GEM_CMA_HELPER_H__
3 3
4#include <drm/drmP.h> 4#include <drm/drmP.h>
5#include <drm/drm_gem.h>
5 6
6struct drm_gem_cma_object { 7struct drm_gem_cma_object {
7 struct drm_gem_object base; 8 struct drm_gem_object base;