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
196
197#ifdef CONFIG_PCI
198
199int drm_legacy_pci_init(const struct drm_driver *driver,
200 struct pci_driver *pdriver);
201void drm_legacy_pci_exit(const struct drm_driver *driver,
202 struct pci_driver *pdriver);
203
204#else
205
206static inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
207 size_t size, size_t align)
208{
209 return NULL;
210}
211
212static inline void drm_pci_free(struct drm_device *dev,
213 struct drm_dma_handle *dmah)
214{
215}
216
217static inline int drm_legacy_pci_init(const struct drm_driver *driver,
218 struct pci_driver *pdriver)
219{
220 return -EINVAL;
221}
222
223static inline void drm_legacy_pci_exit(const struct drm_driver *driver,
224 struct pci_driver *pdriver)
225{
226}
227
228#endif
229
230
231
232
233
234struct drm_agp_head {
235 struct agp_kern_info agp_info;
236 struct list_head memory;
237 unsigned long mode;
238 struct agp_bridge_data *bridge;
239 int enabled;
240 int acquired;
241 unsigned long base;
242 int agp_mtrr;
243 int cant_use_aperture;
244 unsigned long page_mask;
245};
246
247#if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP)
248struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev);
249int drm_legacy_agp_acquire(struct drm_device *dev);
250int drm_legacy_agp_release(struct drm_device *dev);
251int drm_legacy_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
252int drm_legacy_agp_info(struct drm_device *dev, struct drm_agp_info *info);
253int drm_legacy_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
254int drm_legacy_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
255int drm_legacy_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
256int drm_legacy_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
257#else
258static inline struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev)
259{
260 return NULL;
261}
262
263static inline int drm_legacy_agp_acquire(struct drm_device *dev)
264{
265 return -ENODEV;
266}
267
268static inline int drm_legacy_agp_release(struct drm_device *dev)
269{
270 return -ENODEV;
271}
272
273static inline int drm_legacy_agp_enable(struct drm_device *dev,
274 struct drm_agp_mode mode)
275{
276 return -ENODEV;
277}
278
279static inline int drm_legacy_agp_info(struct drm_device *dev,
280 struct drm_agp_info *info)
281{
282 return -ENODEV;
283}
284
285static inline int drm_legacy_agp_alloc(struct drm_device *dev,
286 struct drm_agp_buffer *request)
287{
288 return -ENODEV;
289}
290
291static inline int drm_legacy_agp_free(struct drm_device *dev,
292 struct drm_agp_buffer *request)
293{
294 return -ENODEV;
295}
296
297static inline int drm_legacy_agp_unbind(struct drm_device *dev,
298 struct drm_agp_binding *request)
299{
300 return -ENODEV;
301}
302
303static inline int drm_legacy_agp_bind(struct drm_device *dev,
304 struct drm_agp_binding *request)
305{
306 return -ENODEV;
307}
308#endif
309
310
311void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
312void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
313void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
314
315#endif
316