xref: /openbmc/linux/include/drm/drm_legacy.h (revision 73c9a3f3)
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 <drm/drm.h>
37 #include <drm/drm_auth.h>
38 #include <drm/drm_hashtab.h>
39 
40 struct drm_device;
41 struct drm_driver;
42 struct file;
43 struct pci_driver;
44 
45 /*
46  * Legacy Support for palateontologic DRM drivers
47  *
48  * If you add a new driver and it uses any of these functions or structures,
49  * you're doing it terribly wrong.
50  */
51 
52 /**
53  * DMA buffer.
54  */
55 struct drm_buf {
56 	int idx;		       /**< Index into master buflist */
57 	int total;		       /**< Buffer size */
58 	int order;		       /**< log-base-2(total) */
59 	int used;		       /**< Amount of buffer in use (for DMA) */
60 	unsigned long offset;	       /**< Byte offset (used internally) */
61 	void *address;		       /**< Address of buffer */
62 	unsigned long bus_address;     /**< Bus address of buffer */
63 	struct drm_buf *next;	       /**< Kernel-only: used for free list */
64 	__volatile__ int waiting;      /**< On kernel DMA queue */
65 	__volatile__ int pending;      /**< On hardware DMA queue */
66 	struct drm_file *file_priv;    /**< Private of holding file descr */
67 	int context;		       /**< Kernel queue for this buffer */
68 	int while_locked;	       /**< Dispatch this buffer while locked */
69 	enum {
70 		DRM_LIST_NONE = 0,
71 		DRM_LIST_FREE = 1,
72 		DRM_LIST_WAIT = 2,
73 		DRM_LIST_PEND = 3,
74 		DRM_LIST_PRIO = 4,
75 		DRM_LIST_RECLAIM = 5
76 	} list;			       /**< Which list we're on */
77 
78 	int dev_priv_size;		 /**< Size of buffer private storage */
79 	void *dev_private;		 /**< Per-buffer private storage */
80 };
81 
82 typedef struct drm_dma_handle {
83 	dma_addr_t busaddr;
84 	void *vaddr;
85 	size_t size;
86 } drm_dma_handle_t;
87 
88 /**
89  * Buffer entry.  There is one of this for each buffer size order.
90  */
91 struct drm_buf_entry {
92 	int buf_size;			/**< size */
93 	int buf_count;			/**< number of buffers */
94 	struct drm_buf *buflist;		/**< buffer list */
95 	int seg_count;
96 	int page_order;
97 	struct drm_dma_handle **seglist;
98 
99 	int low_mark;			/**< Low water mark */
100 	int high_mark;			/**< High water mark */
101 };
102 
103 /**
104  * DMA data.
105  */
106 struct drm_device_dma {
107 
108 	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
109 	int buf_count;			/**< total number of buffers */
110 	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
111 	int seg_count;
112 	int page_count;			/**< number of pages */
113 	unsigned long *pagelist;	/**< page list */
114 	unsigned long byte_count;
115 	enum {
116 		_DRM_DMA_USE_AGP = 0x01,
117 		_DRM_DMA_USE_SG = 0x02,
118 		_DRM_DMA_USE_FB = 0x04,
119 		_DRM_DMA_USE_PCI_RO = 0x08
120 	} flags;
121 
122 };
123 
124 /**
125  * Scatter-gather memory.
126  */
127 struct drm_sg_mem {
128 	unsigned long handle;
129 	void *virtual;
130 	int pages;
131 	struct page **pagelist;
132 	dma_addr_t *busaddr;
133 };
134 
135 /**
136  * Kernel side of a mapping
137  */
138 struct drm_local_map {
139 	dma_addr_t offset;	 /**< Requested physical address (0 for SAREA)*/
140 	unsigned long size;	 /**< Requested physical size (bytes) */
141 	enum drm_map_type type;	 /**< Type of memory to map */
142 	enum drm_map_flags flags;	 /**< Flags */
143 	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
144 				 /**< Kernel-space: kernel-virtual address */
145 	int mtrr;		 /**< MTRR slot used */
146 };
147 
148 typedef struct drm_local_map drm_local_map_t;
149 
150 /**
151  * Mappings list
152  */
153 struct drm_map_list {
154 	struct list_head head;		/**< list head */
155 	struct drm_hash_item hash;
156 	struct drm_local_map *map;	/**< mapping */
157 	uint64_t user_token;
158 	struct drm_master *master;
159 };
160 
161 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
162 		      unsigned int size, enum drm_map_type type,
163 		      enum drm_map_flags flags, struct drm_local_map **map_p);
164 struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
165 void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
166 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
167 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
168 int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
169 
170 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
171 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
172 
173 /**
174  * Test that the hardware lock is held by the caller, returning otherwise.
175  *
176  * \param dev DRM device.
177  * \param filp file pointer of the caller.
178  */
179 #define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
180 do {										\
181 	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
182 	    _file_priv->master->lock.file_priv != _file_priv)	{		\
183 		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
184 			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
185 			   _file_priv->master->lock.file_priv, _file_priv);	\
186 		return -EINVAL;							\
187 	}									\
188 } while (0)
189 
190 void drm_legacy_idlelock_take(struct drm_lock_data *lock);
191 void drm_legacy_idlelock_release(struct drm_lock_data *lock);
192 
193 /* drm_pci.c */
194 
195 #ifdef CONFIG_PCI
196 
197 struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
198 				     size_t align);
199 void drm_pci_free(struct drm_device *dev, struct drm_dma_handle *dmah);
200 
201 int drm_legacy_pci_init(const struct drm_driver *driver,
202 			struct pci_driver *pdriver);
203 void drm_legacy_pci_exit(const struct drm_driver *driver,
204 			 struct pci_driver *pdriver);
205 
206 #else
207 
208 static inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
209 						   size_t size, size_t align)
210 {
211 	return NULL;
212 }
213 
214 static inline void drm_pci_free(struct drm_device *dev,
215 				struct drm_dma_handle *dmah)
216 {
217 }
218 
219 static inline int drm_legacy_pci_init(const struct drm_driver *driver,
220 				      struct pci_driver *pdriver)
221 {
222 	return -EINVAL;
223 }
224 
225 static inline void drm_legacy_pci_exit(const struct drm_driver *driver,
226 				       struct pci_driver *pdriver)
227 {
228 }
229 
230 #endif
231 
232 /* drm_memory.c */
233 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
234 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
235 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
236 
237 #endif /* __DRM_DRM_LEGACY_H__ */
238