xref: /openbmc/linux/drivers/gpu/drm/drm_legacy.h (revision a10c9ede)
1 #ifndef __DRM_LEGACY_H__
2 #define __DRM_LEGACY_H__
3 
4 /*
5  * Copyright (c) 2014 David Herrmann <dh.herrmann@gmail.com>
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a
8  * copy of this software and associated documentation files (the "Software"),
9  * to deal in the Software without restriction, including without limitation
10  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11  * and/or sell copies of the Software, and to permit persons to whom the
12  * Software is furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
20  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
21  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23  * OTHER DEALINGS IN THE SOFTWARE.
24  */
25 
26 /*
27  * This file contains legacy interfaces that modern drm drivers
28  * should no longer be using. They cannot be removed as legacy
29  * drivers use them, and removing them are API breaks.
30  */
31 #include <linux/list.h>
32 
33 #include <drm/drm.h>
34 #include <drm/drm_device.h>
35 #include <drm/drm_legacy.h>
36 
37 struct agp_memory;
38 struct drm_buf_desc;
39 struct drm_device;
40 struct drm_file;
41 struct drm_hash_item;
42 struct drm_open_hash;
43 
44 /*
45  * Hash-table Support
46  */
47 
48 #define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member)
49 
50 /* drm_hashtab.c */
51 #if IS_ENABLED(CONFIG_DRM_LEGACY)
52 int drm_ht_create(struct drm_open_hash *ht, unsigned int order);
53 int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item);
54 int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item,
55 			      unsigned long seed, int bits, int shift,
56 			      unsigned long add);
57 int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item);
58 
59 void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key);
60 int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key);
61 int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item);
62 void drm_ht_remove(struct drm_open_hash *ht);
63 #endif
64 
65 /*
66  * RCU-safe interface
67  *
68  * The user of this API needs to make sure that two or more instances of the
69  * hash table manipulation functions are never run simultaneously.
70  * The lookup function drm_ht_find_item_rcu may, however, run simultaneously
71  * with any of the manipulation functions as long as it's called from within
72  * an RCU read-locked section.
73  */
74 #define drm_ht_insert_item_rcu drm_ht_insert_item
75 #define drm_ht_just_insert_please_rcu drm_ht_just_insert_please
76 #define drm_ht_remove_key_rcu drm_ht_remove_key
77 #define drm_ht_remove_item_rcu drm_ht_remove_item
78 #define drm_ht_find_item_rcu drm_ht_find_item
79 
80 /*
81  * Generic DRM Contexts
82  */
83 
84 #define DRM_KERNEL_CONTEXT		0
85 #define DRM_RESERVED_CONTEXTS		1
86 
87 #if IS_ENABLED(CONFIG_DRM_LEGACY)
88 void drm_legacy_ctxbitmap_init(struct drm_device *dev);
89 void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev);
90 void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file);
91 #else
92 static inline void drm_legacy_ctxbitmap_init(struct drm_device *dev) {}
93 static inline void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev) {}
94 static inline void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) {}
95 #endif
96 
97 void drm_legacy_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
98 
99 #if IS_ENABLED(CONFIG_DRM_LEGACY)
100 int drm_legacy_resctx(struct drm_device *d, void *v, struct drm_file *f);
101 int drm_legacy_addctx(struct drm_device *d, void *v, struct drm_file *f);
102 int drm_legacy_getctx(struct drm_device *d, void *v, struct drm_file *f);
103 int drm_legacy_switchctx(struct drm_device *d, void *v, struct drm_file *f);
104 int drm_legacy_newctx(struct drm_device *d, void *v, struct drm_file *f);
105 int drm_legacy_rmctx(struct drm_device *d, void *v, struct drm_file *f);
106 
107 int drm_legacy_setsareactx(struct drm_device *d, void *v, struct drm_file *f);
108 int drm_legacy_getsareactx(struct drm_device *d, void *v, struct drm_file *f);
109 #endif
110 
111 /*
112  * Generic Buffer Management
113  */
114 
115 #define DRM_MAP_HASH_OFFSET 0x10000000
116 
117 #if IS_ENABLED(CONFIG_DRM_LEGACY)
118 static inline int drm_legacy_create_map_hash(struct drm_device *dev)
119 {
120 	return drm_ht_create(&dev->map_hash, 12);
121 }
122 
123 static inline void drm_legacy_remove_map_hash(struct drm_device *dev)
124 {
125 	drm_ht_remove(&dev->map_hash);
126 }
127 #else
128 static inline int drm_legacy_create_map_hash(struct drm_device *dev)
129 {
130 	return 0;
131 }
132 
133 static inline void drm_legacy_remove_map_hash(struct drm_device *dev) {}
134 #endif
135 
136 
137 #if IS_ENABLED(CONFIG_DRM_LEGACY)
138 int drm_legacy_getmap_ioctl(struct drm_device *dev, void *data,
139 			    struct drm_file *file_priv);
140 int drm_legacy_addmap_ioctl(struct drm_device *d, void *v, struct drm_file *f);
141 int drm_legacy_rmmap_ioctl(struct drm_device *d, void *v, struct drm_file *f);
142 
143 int drm_legacy_addbufs(struct drm_device *d, void *v, struct drm_file *f);
144 int drm_legacy_infobufs(struct drm_device *d, void *v, struct drm_file *f);
145 int drm_legacy_markbufs(struct drm_device *d, void *v, struct drm_file *f);
146 int drm_legacy_freebufs(struct drm_device *d, void *v, struct drm_file *f);
147 int drm_legacy_mapbufs(struct drm_device *d, void *v, struct drm_file *f);
148 int drm_legacy_dma_ioctl(struct drm_device *d, void *v, struct drm_file *f);
149 #endif
150 
151 int __drm_legacy_infobufs(struct drm_device *, void *, int *,
152 			  int (*)(void *, int, struct drm_buf_entry *));
153 int __drm_legacy_mapbufs(struct drm_device *, void *, int *,
154 			  void __user **,
155 			  int (*)(void *, int, unsigned long, struct drm_buf *),
156 			  struct drm_file *);
157 
158 #if IS_ENABLED(CONFIG_DRM_LEGACY)
159 void drm_legacy_master_rmmaps(struct drm_device *dev,
160 			      struct drm_master *master);
161 void drm_legacy_rmmaps(struct drm_device *dev);
162 #else
163 static inline void drm_legacy_master_rmmaps(struct drm_device *dev,
164 					    struct drm_master *master) {}
165 static inline void drm_legacy_rmmaps(struct drm_device *dev) {}
166 #endif
167 
168 #if IS_ENABLED(CONFIG_DRM_LEGACY)
169 void drm_legacy_vma_flush(struct drm_device *d);
170 #else
171 static inline void drm_legacy_vma_flush(struct drm_device *d)
172 {
173 	/* do nothing */
174 }
175 #endif
176 
177 /*
178  * AGP Support
179  */
180 
181 struct drm_agp_mem {
182 	unsigned long handle;
183 	struct agp_memory *memory;
184 	unsigned long bound;
185 	int pages;
186 	struct list_head head;
187 };
188 
189 /* drm_agpsupport.c */
190 #if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP)
191 void drm_legacy_agp_clear(struct drm_device *dev);
192 
193 int drm_legacy_agp_acquire_ioctl(struct drm_device *dev, void *data,
194 				 struct drm_file *file_priv);
195 int drm_legacy_agp_release_ioctl(struct drm_device *dev, void *data,
196 				 struct drm_file *file_priv);
197 int drm_legacy_agp_enable_ioctl(struct drm_device *dev, void *data,
198 				struct drm_file *file_priv);
199 int drm_legacy_agp_info_ioctl(struct drm_device *dev, void *data,
200 			      struct drm_file *file_priv);
201 int drm_legacy_agp_alloc_ioctl(struct drm_device *dev, void *data,
202 			       struct drm_file *file_priv);
203 int drm_legacy_agp_free_ioctl(struct drm_device *dev, void *data,
204 			      struct drm_file *file_priv);
205 int drm_legacy_agp_unbind_ioctl(struct drm_device *dev, void *data,
206 				struct drm_file *file_priv);
207 int drm_legacy_agp_bind_ioctl(struct drm_device *dev, void *data,
208 			      struct drm_file *file_priv);
209 #else
210 static inline void drm_legacy_agp_clear(struct drm_device *dev) {}
211 #endif
212 
213 /* drm_lock.c */
214 #if IS_ENABLED(CONFIG_DRM_LEGACY)
215 int drm_legacy_lock(struct drm_device *d, void *v, struct drm_file *f);
216 int drm_legacy_unlock(struct drm_device *d, void *v, struct drm_file *f);
217 void drm_legacy_lock_release(struct drm_device *dev, struct file *filp);
218 #else
219 static inline void drm_legacy_lock_release(struct drm_device *dev, struct file *filp) {}
220 #endif
221 
222 /* DMA support */
223 #if IS_ENABLED(CONFIG_DRM_LEGACY)
224 int drm_legacy_dma_setup(struct drm_device *dev);
225 void drm_legacy_dma_takedown(struct drm_device *dev);
226 #else
227 static inline int drm_legacy_dma_setup(struct drm_device *dev)
228 {
229 	return 0;
230 }
231 #endif
232 
233 void drm_legacy_free_buffer(struct drm_device *dev,
234 			    struct drm_buf * buf);
235 #if IS_ENABLED(CONFIG_DRM_LEGACY)
236 void drm_legacy_reclaim_buffers(struct drm_device *dev,
237 				struct drm_file *filp);
238 #else
239 static inline void drm_legacy_reclaim_buffers(struct drm_device *dev,
240 					      struct drm_file *filp) {}
241 #endif
242 
243 /* Scatter Gather Support */
244 #if IS_ENABLED(CONFIG_DRM_LEGACY)
245 void drm_legacy_sg_cleanup(struct drm_device *dev);
246 int drm_legacy_sg_alloc(struct drm_device *dev, void *data,
247 			struct drm_file *file_priv);
248 int drm_legacy_sg_free(struct drm_device *dev, void *data,
249 		       struct drm_file *file_priv);
250 #endif
251 
252 #if IS_ENABLED(CONFIG_DRM_LEGACY)
253 void drm_legacy_init_members(struct drm_device *dev);
254 void drm_legacy_destroy_members(struct drm_device *dev);
255 void drm_legacy_dev_reinit(struct drm_device *dev);
256 int drm_legacy_setup(struct drm_device * dev);
257 #else
258 static inline void drm_legacy_init_members(struct drm_device *dev) {}
259 static inline void drm_legacy_destroy_members(struct drm_device *dev) {}
260 static inline void drm_legacy_dev_reinit(struct drm_device *dev) {}
261 static inline int drm_legacy_setup(struct drm_device * dev) { return 0; }
262 #endif
263 
264 #if IS_ENABLED(CONFIG_DRM_LEGACY)
265 void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master);
266 #else
267 static inline void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master) {}
268 #endif
269 
270 #if IS_ENABLED(CONFIG_DRM_LEGACY)
271 void drm_master_legacy_init(struct drm_master *master);
272 #else
273 static inline void drm_master_legacy_init(struct drm_master *master) {}
274 #endif
275 
276 /* drm_pci.c */
277 #if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_PCI)
278 int drm_legacy_irq_by_busid(struct drm_device *dev, void *data, struct drm_file *file_priv);
279 void drm_legacy_pci_agp_destroy(struct drm_device *dev);
280 #else
281 static inline int drm_legacy_irq_by_busid(struct drm_device *dev, void *data,
282 					  struct drm_file *file_priv)
283 {
284 	return -EINVAL;
285 }
286 
287 static inline void drm_legacy_pci_agp_destroy(struct drm_device *dev) {}
288 #endif
289 
290 #endif /* __DRM_LEGACY_H__ */
291