1 #ifndef __DRM_DRM_LEGACY_H__
2 #define __DRM_DRM_LEGACY_H__
3 /*
4 * Legacy driver interfaces for the Direct Rendering Manager
5 *
6 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
7 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Copyright (c) 2009-2010, Code Aurora Forum.
9 * All rights reserved.
10 * Copyright © 2014 Intel Corporation
11 * Daniel Vetter <daniel.vetter@ffwll.ch>
12 *
13 * Author: Rickard E. (Rik) Faith <faith@valinux.com>
14 * Author: Gareth Hughes <gareth@valinux.com>
15 *
16 * Permission is hereby granted, free of charge, to any person obtaining a
17 * copy of this software and associated documentation files (the "Software"),
18 * to deal in the Software without restriction, including without limitation
19 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
20 * and/or sell copies of the Software, and to permit persons to whom the
21 * Software is furnished to do so, subject to the following conditions:
22 *
23 * The above copyright notice and this permission notice (including the next
24 * paragraph) shall be included in all copies or substantial portions of the
25 * Software.
26 *
27 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
28 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
29 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
30 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
31 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
32 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
33 * OTHER DEALINGS IN THE SOFTWARE.
34 */
35
36 #include <linux/agp_backend.h>
37
38 #include <drm/drm.h>
39 #include <drm/drm_auth.h>
40
41 struct drm_device;
42 struct drm_driver;
43 struct file;
44 struct pci_driver;
45
46 /*
47 * Legacy Support for palateontologic DRM drivers
48 *
49 * If you add a new driver and it uses any of these functions or structures,
50 * you're doing it terribly wrong.
51 */
52
53 /*
54 * Hash-table Support
55 */
56
57 struct drm_hash_item {
58 struct hlist_node head;
59 unsigned long key;
60 };
61
62 struct drm_open_hash {
63 struct hlist_head *table;
64 u8 order;
65 };
66
67 /**
68 * DMA buffer.
69 */
70 struct drm_buf {
71 int idx; /**< Index into master buflist */
72 int total; /**< Buffer size */
73 int order; /**< log-base-2(total) */
74 int used; /**< Amount of buffer in use (for DMA) */
75 unsigned long offset; /**< Byte offset (used internally) */
76 void *address; /**< Address of buffer */
77 unsigned long bus_address; /**< Bus address of buffer */
78 struct drm_buf *next; /**< Kernel-only: used for free list */
79 __volatile__ int waiting; /**< On kernel DMA queue */
80 __volatile__ int pending; /**< On hardware DMA queue */
81 struct drm_file *file_priv; /**< Private of holding file descr */
82 int context; /**< Kernel queue for this buffer */
83 int while_locked; /**< Dispatch this buffer while locked */
84 enum {
85 DRM_LIST_NONE = 0,
86 DRM_LIST_FREE = 1,
87 DRM_LIST_WAIT = 2,
88 DRM_LIST_PEND = 3,
89 DRM_LIST_PRIO = 4,
90 DRM_LIST_RECLAIM = 5
91 } list; /**< Which list we're on */
92
93 int dev_priv_size; /**< Size of buffer private storage */
94 void *dev_private; /**< Per-buffer private storage */
95 };
96
97 struct drm_dmamem {
98 bus_dmamap_t map;
99 caddr_t kva;
100 bus_size_t size;
101 int nsegs;
102 bus_dma_segment_t segs[1];
103 LIST_ENTRY(drm_dmamem) next;
104 };
105
106 typedef struct drm_dma_handle {
107 struct drm_dmamem *mem;
108 dma_addr_t busaddr;
109 void *vaddr;
110 size_t size;
111 } drm_dma_handle_t;
112
113 struct drm_dmamem *drm_dmamem_alloc(bus_dma_tag_t, bus_size_t, bus_size_t,
114 int, bus_size_t, int, int);
115 void drm_dmamem_free(bus_dma_tag_t, struct drm_dmamem *);
116
117 /**
118 * Buffer entry. There is one of this for each buffer size order.
119 */
120 struct drm_buf_entry {
121 int buf_size; /**< size */
122 int buf_count; /**< number of buffers */
123 struct drm_buf *buflist; /**< buffer list */
124 int seg_count;
125 int page_order;
126 struct drm_dma_handle **seglist;
127
128 int low_mark; /**< Low water mark */
129 int high_mark; /**< High water mark */
130 };
131
132 /**
133 * DMA data.
134 */
135 struct drm_device_dma {
136
137 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
138 int buf_count; /**< total number of buffers */
139 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
140 int seg_count;
141 int page_count; /**< number of pages */
142 unsigned long *pagelist; /**< page list */
143 unsigned long byte_count;
144 enum {
145 _DRM_DMA_USE_AGP = 0x01,
146 _DRM_DMA_USE_SG = 0x02,
147 _DRM_DMA_USE_FB = 0x04,
148 _DRM_DMA_USE_PCI_RO = 0x08
149 } flags;
150
151 };
152
153 /**
154 * Scatter-gather memory.
155 */
156 struct drm_sg_mem {
157 unsigned long handle;
158 void *virtual;
159 int pages;
160 struct vm_page **pagelist;
161 dma_addr_t *busaddr;
162 };
163
164 /**
165 * Kernel side of a mapping
166 */
167 struct drm_local_map {
168 dma_addr_t offset; /**< Requested physical address (0 for SAREA)*/
169 unsigned long size; /**< Requested physical size (bytes) */
170 enum drm_map_type type; /**< Type of memory to map */
171 enum drm_map_flags flags; /**< Flags */
172 void *handle; /**< User-space: "Handle" to pass to mmap() */
173 /**< Kernel-space: kernel-virtual address */
174 int mtrr; /**< MTRR slot used */
175 };
176
177 typedef struct drm_local_map drm_local_map_t;
178
179 /**
180 * Mappings list
181 */
182 struct drm_map_list {
183 struct list_head head; /**< list head */
184 struct drm_hash_item hash;
185 struct drm_local_map *map; /**< mapping */
186 uint64_t user_token;
187 struct drm_master *master;
188 };
189
190 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
191 unsigned int size, enum drm_map_type type,
192 enum drm_map_flags flags, struct drm_local_map **map_p);
193 struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
194 void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
195 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
196 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
197 #ifdef __linux__
198 int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
199 #endif
200
201 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
202 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
203
204 /**
205 * Test that the hardware lock is held by the caller, returning otherwise.
206 *
207 * \param dev DRM device.
208 * \param filp file pointer of the caller.
209 */
210 #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
211 do { \
212 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
213 _file_priv->master->lock.file_priv != _file_priv) { \
214 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
215 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
216 _file_priv->master->lock.file_priv, _file_priv); \
217 return -EINVAL; \
218 } \
219 } while (0)
220
221 void drm_legacy_idlelock_take(struct drm_lock_data *lock);
222 void drm_legacy_idlelock_release(struct drm_lock_data *lock);
223
224 /* drm_irq.c */
225 int drm_legacy_irq_uninstall(struct drm_device *dev);
226
227 /* drm_pci.c */
228
229 #ifdef CONFIG_PCI
230
231 int drm_legacy_pci_init(const struct drm_driver *driver,
232 struct pci_driver *pdriver);
233 void drm_legacy_pci_exit(const struct drm_driver *driver,
234 struct pci_driver *pdriver);
235
236 #else
237
drm_pci_alloc(struct drm_device * dev,size_t size,size_t align)238 static inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
239 size_t size, size_t align)
240 {
241 return NULL;
242 }
243
drm_pci_free(struct drm_device * dev,struct drm_dma_handle * dmah)244 static inline void drm_pci_free(struct drm_device *dev,
245 struct drm_dma_handle *dmah)
246 {
247 }
248
drm_legacy_pci_init(const struct drm_driver * driver,struct pci_driver * pdriver)249 static inline int drm_legacy_pci_init(const struct drm_driver *driver,
250 struct pci_driver *pdriver)
251 {
252 return -EINVAL;
253 }
254
drm_legacy_pci_exit(const struct drm_driver * driver,struct pci_driver * pdriver)255 static inline void drm_legacy_pci_exit(const struct drm_driver *driver,
256 struct pci_driver *pdriver)
257 {
258 }
259
260 #endif
261
262 /*
263 * AGP Support
264 */
265
266 #ifdef __linux__
267 struct drm_agp_head {
268 struct agp_kern_info agp_info;
269 struct list_head memory;
270 unsigned long mode;
271 struct agp_bridge_data *bridge;
272 int enabled;
273 int acquired;
274 unsigned long base;
275 int agp_mtrr;
276 int cant_use_aperture;
277 unsigned long page_mask;
278 };
279 #else
280
281 #include <dev/pci/pcivar.h>
282 #include <dev/pci/agpvar.h>
283
284 struct drm_agp_head {
285 struct agp_softc *agpdev;
286 const char *chipset;
287 TAILQ_HEAD(agp_memlist, drm_agp_mem) memory;
288 struct agp_info info;
289 unsigned long base;
290 unsigned long mode;
291 unsigned long page_mask;
292 int acquired;
293 int cant_use_aperture;
294 int enabled;
295 int mtrr;
296 };
297 #endif
298
299 /* #if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP) */
300 #if IS_ENABLED(CONFIG_AGP)
301 struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev);
302 int drm_legacy_agp_acquire(struct drm_device *dev);
303 int drm_legacy_agp_release(struct drm_device *dev);
304 int drm_legacy_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
305 int drm_legacy_agp_info(struct drm_device *dev, struct drm_agp_info *info);
306 int drm_legacy_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
307 int drm_legacy_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
308 int drm_legacy_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
309 int drm_legacy_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
310 #else
drm_legacy_agp_init(struct drm_device * dev)311 static inline struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev)
312 {
313 return NULL;
314 }
315
drm_legacy_agp_acquire(struct drm_device * dev)316 static inline int drm_legacy_agp_acquire(struct drm_device *dev)
317 {
318 return -ENODEV;
319 }
320
drm_legacy_agp_release(struct drm_device * dev)321 static inline int drm_legacy_agp_release(struct drm_device *dev)
322 {
323 return -ENODEV;
324 }
325
drm_legacy_agp_enable(struct drm_device * dev,struct drm_agp_mode mode)326 static inline int drm_legacy_agp_enable(struct drm_device *dev,
327 struct drm_agp_mode mode)
328 {
329 return -ENODEV;
330 }
331
drm_legacy_agp_info(struct drm_device * dev,struct drm_agp_info * info)332 static inline int drm_legacy_agp_info(struct drm_device *dev,
333 struct drm_agp_info *info)
334 {
335 return -ENODEV;
336 }
337
drm_legacy_agp_alloc(struct drm_device * dev,struct drm_agp_buffer * request)338 static inline int drm_legacy_agp_alloc(struct drm_device *dev,
339 struct drm_agp_buffer *request)
340 {
341 return -ENODEV;
342 }
343
drm_legacy_agp_free(struct drm_device * dev,struct drm_agp_buffer * request)344 static inline int drm_legacy_agp_free(struct drm_device *dev,
345 struct drm_agp_buffer *request)
346 {
347 return -ENODEV;
348 }
349
drm_legacy_agp_unbind(struct drm_device * dev,struct drm_agp_binding * request)350 static inline int drm_legacy_agp_unbind(struct drm_device *dev,
351 struct drm_agp_binding *request)
352 {
353 return -ENODEV;
354 }
355
drm_legacy_agp_bind(struct drm_device * dev,struct drm_agp_binding * request)356 static inline int drm_legacy_agp_bind(struct drm_device *dev,
357 struct drm_agp_binding *request)
358 {
359 return -ENODEV;
360 }
361 #endif
362
363 /* drm_memory.c */
364 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
365 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
366 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
367
368 #endif /* __DRM_DRM_LEGACY_H__ */
369