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