xref: /openbmc/linux/include/drm/drm_legacy.h (revision 87875c10)
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 #include <drm/drm_hashtab.h>
41 
42 struct drm_device;
43 struct drm_driver;
44 struct file;
45 struct pci_driver;
46 
47 /*
48  * Legacy Support for palateontologic DRM drivers
49  *
50  * If you add a new driver and it uses any of these functions or structures,
51  * you're doing it terribly wrong.
52  */
53 
54 /**
55  * DMA buffer.
56  */
57 struct drm_buf {
58 	int idx;		       /**< Index into master buflist */
59 	int total;		       /**< Buffer size */
60 	int order;		       /**< log-base-2(total) */
61 	int used;		       /**< Amount of buffer in use (for DMA) */
62 	unsigned long offset;	       /**< Byte offset (used internally) */
63 	void *address;		       /**< Address of buffer */
64 	unsigned long bus_address;     /**< Bus address of buffer */
65 	struct drm_buf *next;	       /**< Kernel-only: used for free list */
66 	__volatile__ int waiting;      /**< On kernel DMA queue */
67 	__volatile__ int pending;      /**< On hardware DMA queue */
68 	struct drm_file *file_priv;    /**< Private of holding file descr */
69 	int context;		       /**< Kernel queue for this buffer */
70 	int while_locked;	       /**< Dispatch this buffer 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;			       /**< Which list we're on */
79 
80 	int dev_priv_size;		 /**< Size of buffer private storage */
81 	void *dev_private;		 /**< Per-buffer private storage */
82 };
83 
84 typedef struct drm_dma_handle {
85 	dma_addr_t busaddr;
86 	void *vaddr;
87 	size_t size;
88 } drm_dma_handle_t;
89 
90 /**
91  * Buffer entry.  There is one of this for each buffer size order.
92  */
93 struct drm_buf_entry {
94 	int buf_size;			/**< size */
95 	int buf_count;			/**< number of buffers */
96 	struct drm_buf *buflist;		/**< buffer list */
97 	int seg_count;
98 	int page_order;
99 	struct drm_dma_handle **seglist;
100 
101 	int low_mark;			/**< Low water mark */
102 	int high_mark;			/**< High water mark */
103 };
104 
105 /**
106  * DMA data.
107  */
108 struct drm_device_dma {
109 
110 	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
111 	int buf_count;			/**< total number of buffers */
112 	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
113 	int seg_count;
114 	int page_count;			/**< number of pages */
115 	unsigned long *pagelist;	/**< page list */
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  * Scatter-gather memory.
128  */
129 struct 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  * Kernel side of a mapping
139  */
140 struct drm_local_map {
141 	dma_addr_t offset;	 /**< Requested physical address (0 for SAREA)*/
142 	unsigned long size;	 /**< Requested physical size (bytes) */
143 	enum drm_map_type type;	 /**< Type of memory to map */
144 	enum drm_map_flags flags;	 /**< Flags */
145 	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
146 				 /**< Kernel-space: kernel-virtual address */
147 	int mtrr;		 /**< MTRR slot used */
148 };
149 
150 typedef struct drm_local_map drm_local_map_t;
151 
152 /**
153  * Mappings list
154  */
155 struct drm_map_list {
156 	struct list_head head;		/**< list head */
157 	struct drm_hash_item hash;
158 	struct drm_local_map *map;	/**< mapping */
159 	uint64_t user_token;
160 	struct drm_master *master;
161 };
162 
163 int 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);
166 struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
167 void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
168 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
169 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
170 int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
171 
172 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
173 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
174 
175 /**
176  * Test that the hardware lock is held by the caller, returning otherwise.
177  *
178  * \param dev DRM device.
179  * \param filp file pointer of the caller.
180  */
181 #define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
182 do {										\
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 
192 void drm_legacy_idlelock_take(struct drm_lock_data *lock);
193 void drm_legacy_idlelock_release(struct drm_lock_data *lock);
194 
195 /* drm_pci.c */
196 
197 #ifdef CONFIG_PCI
198 
199 int drm_legacy_pci_init(const struct drm_driver *driver,
200 			struct pci_driver *pdriver);
201 void drm_legacy_pci_exit(const struct drm_driver *driver,
202 			 struct pci_driver *pdriver);
203 
204 #else
205 
206 static 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 
212 static inline void drm_pci_free(struct drm_device *dev,
213 				struct drm_dma_handle *dmah)
214 {
215 }
216 
217 static inline int drm_legacy_pci_init(const struct drm_driver *driver,
218 				      struct pci_driver *pdriver)
219 {
220 	return -EINVAL;
221 }
222 
223 static inline void drm_legacy_pci_exit(const struct drm_driver *driver,
224 				       struct pci_driver *pdriver)
225 {
226 }
227 
228 #endif
229 
230 /*
231  * AGP Support
232  */
233 
234 struct 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)
248 struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev);
249 int drm_legacy_agp_acquire(struct drm_device *dev);
250 int drm_legacy_agp_release(struct drm_device *dev);
251 int drm_legacy_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
252 int drm_legacy_agp_info(struct drm_device *dev, struct drm_agp_info *info);
253 int drm_legacy_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
254 int drm_legacy_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
255 int drm_legacy_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
256 int drm_legacy_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
257 #else
258 static inline struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev)
259 {
260 	return NULL;
261 }
262 
263 static inline int drm_legacy_agp_acquire(struct drm_device *dev)
264 {
265 	return -ENODEV;
266 }
267 
268 static inline int drm_legacy_agp_release(struct drm_device *dev)
269 {
270 	return -ENODEV;
271 }
272 
273 static inline int drm_legacy_agp_enable(struct drm_device *dev,
274 					struct drm_agp_mode mode)
275 {
276 	return -ENODEV;
277 }
278 
279 static inline int drm_legacy_agp_info(struct drm_device *dev,
280 				      struct drm_agp_info *info)
281 {
282 	return -ENODEV;
283 }
284 
285 static inline int drm_legacy_agp_alloc(struct drm_device *dev,
286 				       struct drm_agp_buffer *request)
287 {
288 	return -ENODEV;
289 }
290 
291 static inline int drm_legacy_agp_free(struct drm_device *dev,
292 				      struct drm_agp_buffer *request)
293 {
294 	return -ENODEV;
295 }
296 
297 static inline int drm_legacy_agp_unbind(struct drm_device *dev,
298 					struct drm_agp_binding *request)
299 {
300 	return -ENODEV;
301 }
302 
303 static 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 /* drm_memory.c */
311 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
312 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
313 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
314 
315 #endif /* __DRM_DRM_LEGACY_H__ */
316