1#ifndef __DRM_DRM_LEGACY_H__
2#define __DRM_DRM_LEGACY_H__
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36#include <linux/agp_backend.h>
37
38#include <drm/drm.h>
39#include <drm/drm_auth.h>
40#include <drm/drm_hashtab.h>
41
42struct drm_device;
43struct drm_driver;
44struct file;
45struct pci_driver;
46
47
48
49
50
51
52
53
54
55
56
57struct drm_buf {
58 int idx;
59 int total;
60 int order;
61 int used;
62 unsigned long offset;
63 void *address;
64 unsigned long bus_address;
65 struct drm_buf *next;
66 __volatile__ int waiting;
67 __volatile__ int pending;
68 struct drm_file *file_priv;
69 int context;
70 int while_locked;
71 enum {
72 DRM_LIST_NONE = 0,
73 DRM_LIST_FREE = 1,
74 DRM_LIST_WAIT = 2,
75 DRM_LIST_PEND = 3,
76 DRM_LIST_PRIO = 4,
77 DRM_LIST_RECLAIM = 5
78 } list;
79
80 int dev_priv_size;
81 void *dev_private;
82};
83
84typedef struct drm_dma_handle {
85 dma_addr_t busaddr;
86 void *vaddr;
87 size_t size;
88} drm_dma_handle_t;
89
90
91
92
93struct drm_buf_entry {
94 int buf_size;
95 int buf_count;
96 struct drm_buf *buflist;
97 int seg_count;
98 int page_order;
99 struct drm_dma_handle **seglist;
100
101 int low_mark;
102 int high_mark;
103};
104
105
106
107
108struct drm_device_dma {
109
110 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];
111 int buf_count;
112 struct drm_buf **buflist;
113 int seg_count;
114 int page_count;
115 unsigned long *pagelist;
116 unsigned long byte_count;
117 enum {
118 _DRM_DMA_USE_AGP = 0x01,
119 _DRM_DMA_USE_SG = 0x02,
120 _DRM_DMA_USE_FB = 0x04,
121 _DRM_DMA_USE_PCI_RO = 0x08
122 } flags;
123
124};
125
126
127
128
129struct drm_sg_mem {
130 unsigned long handle;
131 void *virtual;
132 int pages;
133 struct page **pagelist;
134 dma_addr_t *busaddr;
135};
136
137
138
139
140struct drm_local_map {
141 dma_addr_t offset;
142 unsigned long size;
143 enum drm_map_type type;
144 enum drm_map_flags flags;
145 void *handle;
146
147 int mtrr;
148};
149
150typedef struct drm_local_map drm_local_map_t;
151
152
153
154
155struct drm_map_list {
156 struct list_head head;
157 struct drm_hash_item hash;
158 struct drm_local_map *map;
159 uint64_t user_token;
160 struct drm_master *master;
161};
162
163int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
164 unsigned int size, enum drm_map_type type,
165 enum drm_map_flags flags, struct drm_local_map **map_p);
166struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
167void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
168int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
169struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
170int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
171
172int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
173int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
174
175
176
177
178
179
180
181#define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
182do { \
183 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
184 _file_priv->master->lock.file_priv != _file_priv) { \
185 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
186 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
187 _file_priv->master->lock.file_priv, _file_priv); \
188 return -EINVAL; \
189 } \
190} while (0)
191
192void drm_legacy_idlelock_take(struct drm_lock_data *lock);
193void drm_legacy_idlelock_release(struct drm_lock_data *lock);
194
195
196int drm_legacy_irq_uninstall(struct drm_device *dev);
197
198
199
200#ifdef CONFIG_PCI
201
202int drm_legacy_pci_init(const struct drm_driver *driver,
203 struct pci_driver *pdriver);
204void drm_legacy_pci_exit(const struct drm_driver *driver,
205 struct pci_driver *pdriver);
206
207#else
208
209static inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
210 size_t size, size_t align)
211{
212 return NULL;
213}
214
215static inline void drm_pci_free(struct drm_device *dev,
216 struct drm_dma_handle *dmah)
217{
218}
219
220static inline int drm_legacy_pci_init(const struct drm_driver *driver,
221 struct pci_driver *pdriver)
222{
223 return -EINVAL;
224}
225
226static inline void drm_legacy_pci_exit(const struct drm_driver *driver,
227 struct pci_driver *pdriver)
228{
229}
230
231#endif
232
233
234
235
236
237struct drm_agp_head {
238 struct agp_kern_info agp_info;
239 struct list_head memory;
240 unsigned long mode;
241 struct agp_bridge_data *bridge;
242 int enabled;
243 int acquired;
244 unsigned long base;
245 int agp_mtrr;
246 int cant_use_aperture;
247 unsigned long page_mask;
248};
249
250#if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP)
251struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev);
252int drm_legacy_agp_acquire(struct drm_device *dev);
253int drm_legacy_agp_release(struct drm_device *dev);
254int drm_legacy_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
255int drm_legacy_agp_info(struct drm_device *dev, struct drm_agp_info *info);
256int drm_legacy_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
257int drm_legacy_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
258int drm_legacy_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
259int drm_legacy_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
260#else
261static inline struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev)
262{
263 return NULL;
264}
265
266static inline int drm_legacy_agp_acquire(struct drm_device *dev)
267{
268 return -ENODEV;
269}
270
271static inline int drm_legacy_agp_release(struct drm_device *dev)
272{
273 return -ENODEV;
274}
275
276static inline int drm_legacy_agp_enable(struct drm_device *dev,
277 struct drm_agp_mode mode)
278{
279 return -ENODEV;
280}
281
282static inline int drm_legacy_agp_info(struct drm_device *dev,
283 struct drm_agp_info *info)
284{
285 return -ENODEV;
286}
287
288static inline int drm_legacy_agp_alloc(struct drm_device *dev,
289 struct drm_agp_buffer *request)
290{
291 return -ENODEV;
292}
293
294static inline int drm_legacy_agp_free(struct drm_device *dev,
295 struct drm_agp_buffer *request)
296{
297 return -ENODEV;
298}
299
300static inline int drm_legacy_agp_unbind(struct drm_device *dev,
301 struct drm_agp_binding *request)
302{
303 return -ENODEV;
304}
305
306static inline int drm_legacy_agp_bind(struct drm_device *dev,
307 struct drm_agp_binding *request)
308{
309 return -ENODEV;
310}
311#endif
312
313
314void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
315void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
316void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
317
318#endif
319