xref: /openbmc/linux/include/drm/drm_legacy.h (revision d2ba09c1)
1 #ifndef __DRM_DRM_LEGACY_H__
2 #define __DRM_DRM_LEGACY_H__
3 
4 #include <drm/drm_auth.h>
5 
6 /*
7  * Legacy driver interfaces for the Direct Rendering Manager
8  *
9  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
10  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
11  * Copyright (c) 2009-2010, Code Aurora Forum.
12  * All rights reserved.
13  * Copyright © 2014 Intel Corporation
14  *   Daniel Vetter <daniel.vetter@ffwll.ch>
15  *
16  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
17  * Author: Gareth Hughes <gareth@valinux.com>
18  *
19  * Permission is hereby granted, free of charge, to any person obtaining a
20  * copy of this software and associated documentation files (the "Software"),
21  * to deal in the Software without restriction, including without limitation
22  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
23  * and/or sell copies of the Software, and to permit persons to whom the
24  * Software is furnished to do so, subject to the following conditions:
25  *
26  * The above copyright notice and this permission notice (including the next
27  * paragraph) shall be included in all copies or substantial portions of the
28  * Software.
29  *
30  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
33  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
34  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
35  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
36  * OTHER DEALINGS IN THE SOFTWARE.
37  */
38 
39 
40 /*
41  * Legacy Support for palateontologic DRM drivers
42  *
43  * If you add a new driver and it uses any of these functions or structures,
44  * you're doing it terribly wrong.
45  */
46 
47 /**
48  * DMA buffer.
49  */
50 struct drm_buf {
51 	int idx;		       /**< Index into master buflist */
52 	int total;		       /**< Buffer size */
53 	int order;		       /**< log-base-2(total) */
54 	int used;		       /**< Amount of buffer in use (for DMA) */
55 	unsigned long offset;	       /**< Byte offset (used internally) */
56 	void *address;		       /**< Address of buffer */
57 	unsigned long bus_address;     /**< Bus address of buffer */
58 	struct drm_buf *next;	       /**< Kernel-only: used for free list */
59 	__volatile__ int waiting;      /**< On kernel DMA queue */
60 	__volatile__ int pending;      /**< On hardware DMA queue */
61 	struct drm_file *file_priv;    /**< Private of holding file descr */
62 	int context;		       /**< Kernel queue for this buffer */
63 	int while_locked;	       /**< Dispatch this buffer while locked */
64 	enum {
65 		DRM_LIST_NONE = 0,
66 		DRM_LIST_FREE = 1,
67 		DRM_LIST_WAIT = 2,
68 		DRM_LIST_PEND = 3,
69 		DRM_LIST_PRIO = 4,
70 		DRM_LIST_RECLAIM = 5
71 	} list;			       /**< Which list we're on */
72 
73 	int dev_priv_size;		 /**< Size of buffer private storage */
74 	void *dev_private;		 /**< Per-buffer private storage */
75 };
76 
77 typedef struct drm_dma_handle {
78 	dma_addr_t busaddr;
79 	void *vaddr;
80 	size_t size;
81 } drm_dma_handle_t;
82 
83 /**
84  * Buffer entry.  There is one of this for each buffer size order.
85  */
86 struct drm_buf_entry {
87 	int buf_size;			/**< size */
88 	int buf_count;			/**< number of buffers */
89 	struct drm_buf *buflist;		/**< buffer list */
90 	int seg_count;
91 	int page_order;
92 	struct drm_dma_handle **seglist;
93 
94 	int low_mark;			/**< Low water mark */
95 	int high_mark;			/**< High water mark */
96 };
97 
98 /**
99  * DMA data.
100  */
101 struct drm_device_dma {
102 
103 	struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];	/**< buffers, grouped by their size order */
104 	int buf_count;			/**< total number of buffers */
105 	struct drm_buf **buflist;		/**< Vector of pointers into drm_device_dma::bufs */
106 	int seg_count;
107 	int page_count;			/**< number of pages */
108 	unsigned long *pagelist;	/**< page list */
109 	unsigned long byte_count;
110 	enum {
111 		_DRM_DMA_USE_AGP = 0x01,
112 		_DRM_DMA_USE_SG = 0x02,
113 		_DRM_DMA_USE_FB = 0x04,
114 		_DRM_DMA_USE_PCI_RO = 0x08
115 	} flags;
116 
117 };
118 
119 /**
120  * Scatter-gather memory.
121  */
122 struct drm_sg_mem {
123 	unsigned long handle;
124 	void *virtual;
125 	int pages;
126 	struct page **pagelist;
127 	dma_addr_t *busaddr;
128 };
129 
130 /**
131  * Kernel side of a mapping
132  */
133 struct drm_local_map {
134 	resource_size_t offset;	 /**< Requested physical address (0 for SAREA)*/
135 	unsigned long size;	 /**< Requested physical size (bytes) */
136 	enum drm_map_type type;	 /**< Type of memory to map */
137 	enum drm_map_flags flags;	 /**< Flags */
138 	void *handle;		 /**< User-space: "Handle" to pass to mmap() */
139 				 /**< Kernel-space: kernel-virtual address */
140 	int mtrr;		 /**< MTRR slot used */
141 };
142 
143 typedef struct drm_local_map drm_local_map_t;
144 
145 /**
146  * Mappings list
147  */
148 struct drm_map_list {
149 	struct list_head head;		/**< list head */
150 	struct drm_hash_item hash;
151 	struct drm_local_map *map;	/**< mapping */
152 	uint64_t user_token;
153 	struct drm_master *master;
154 };
155 
156 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
157 		      unsigned int size, enum drm_map_type type,
158 		      enum drm_map_flags flags, struct drm_local_map **map_p);
159 void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
160 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
161 void drm_legacy_master_rmmaps(struct drm_device *dev,
162 			      struct drm_master *master);
163 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
164 int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
165 
166 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
167 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
168 
169 /**
170  * Test that the hardware lock is held by the caller, returning otherwise.
171  *
172  * \param dev DRM device.
173  * \param filp file pointer of the caller.
174  */
175 #define LOCK_TEST_WITH_RETURN( dev, _file_priv )				\
176 do {										\
177 	if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||	\
178 	    _file_priv->master->lock.file_priv != _file_priv)	{		\
179 		DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
180 			   __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
181 			   _file_priv->master->lock.file_priv, _file_priv);	\
182 		return -EINVAL;							\
183 	}									\
184 } while (0)
185 
186 void drm_legacy_idlelock_take(struct drm_lock_data *lock);
187 void drm_legacy_idlelock_release(struct drm_lock_data *lock);
188 
189 /* drm_pci.c dma alloc wrappers */
190 void __drm_legacy_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
191 
192 /* drm_memory.c */
193 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
194 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
195 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
196 
197 static __inline__ struct drm_local_map *drm_legacy_findmap(struct drm_device *dev,
198 							   unsigned int token)
199 {
200 	struct drm_map_list *_entry;
201 	list_for_each_entry(_entry, &dev->maplist, head)
202 	    if (_entry->user_token == token)
203 		return _entry->map;
204 	return NULL;
205 }
206 
207 #endif /* __DRM_DRM_LEGACY_H__ */
208