drm_legacy.h revision 1.7.6.2 1 /* $NetBSD: drm_legacy.h,v 1.7.6.2 2019/06/10 22:08:29 christos Exp $ */
2
3 #ifndef __DRM_DRM_LEGACY_H__
4 #define __DRM_DRM_LEGACY_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 (at) ffwll.ch>
15 *
16 * Author: Rickard E. (Rik) Faith <faith (at) valinux.com>
17 * Author: Gareth Hughes <gareth (at) 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 #include <drm/drmP.h>
40 #include <drm/drm_hashtab.h>
41
42 struct drm_lock_data;
43
44 /*
45 * Legacy Support for palateontologic DRM drivers
46 *
47 * If you add a new driver and it uses any of these functions or structures,
48 * you're doing it terribly wrong.
49 */
50
51 /**
52 * DMA buffer.
53 */
54 struct drm_buf {
55 int idx; /**< Index into master buflist */
56 int total; /**< Buffer size */
57 int order; /**< log-base-2(total) */
58 int used; /**< Amount of buffer in use (for DMA) */
59 unsigned long offset; /**< Byte offset (used internally) */
60 void *address; /**< Address of buffer */
61 unsigned long bus_address; /**< Bus address of buffer */
62 struct drm_buf *next; /**< Kernel-only: used for free list */
63 __volatile__ int waiting; /**< On kernel DMA queue */
64 __volatile__ int pending; /**< On hardware DMA queue */
65 struct drm_file *file_priv; /**< Private of holding file descr */
66 int context; /**< Kernel queue for this buffer */
67 int while_locked; /**< Dispatch this buffer while locked */
68 enum {
69 DRM_LIST_NONE = 0,
70 DRM_LIST_FREE = 1,
71 DRM_LIST_WAIT = 2,
72 DRM_LIST_PEND = 3,
73 DRM_LIST_PRIO = 4,
74 DRM_LIST_RECLAIM = 5
75 } list; /**< Which list we're on */
76
77 int dev_priv_size; /**< Size of buffer private storage */
78 void *dev_private; /**< Per-buffer private storage */
79 };
80
81 typedef struct drm_dma_handle {
82 dma_addr_t busaddr;
83 void *vaddr;
84 size_t size;
85 #ifdef __NetBSD__
86 bus_dma_tag_t dmah_tag;
87 bus_dmamap_t dmah_map;
88 bus_dma_segment_t dmah_seg;
89 #endif
90 } drm_dma_handle_t;
91
92 /**
93 * Buffer entry. There is one of this for each buffer size order.
94 */
95 struct drm_buf_entry {
96 int buf_size; /**< size */
97 int buf_count; /**< number of buffers */
98 struct drm_buf *buflist; /**< buffer list */
99 int seg_count;
100 int page_order;
101 struct drm_dma_handle **seglist;
102
103 int low_mark; /**< Low water mark */
104 int high_mark; /**< High water mark */
105 };
106
107 /**
108 * DMA data.
109 */
110 struct drm_device_dma {
111
112 struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
113 int buf_count; /**< total number of buffers */
114 struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
115 int seg_count;
116 int page_count; /**< number of pages */
117 unsigned long *pagelist; /**< page list */
118 unsigned long byte_count;
119 enum {
120 _DRM_DMA_USE_AGP = 0x01,
121 _DRM_DMA_USE_SG = 0x02,
122 _DRM_DMA_USE_FB = 0x04,
123 _DRM_DMA_USE_PCI_RO = 0x08
124 } flags;
125
126 };
127
128 /**
129 * Scatter-gather memory.
130 */
131 struct drm_sg_mem {
132 unsigned long handle;
133 void *virtual;
134 #ifdef __NetBSD__
135 size_t sg_size;
136 bus_dma_tag_t sg_tag;
137 bus_dmamap_t sg_map;
138 unsigned int sg_nsegs;
139 unsigned int sg_nsegs_max;
140 bus_dma_segment_t sg_segs[];
141 #else
142 int pages;
143 struct page **pagelist;
144 dma_addr_t *busaddr;
145 #endif
146 };
147
148 #ifdef __NetBSD__
149 /*
150 * XXX Remember: memory mappings only. bm_flags must include
151 * BUS_SPACE_MAP_LINEAR.
152 */
153 struct drm_bus_map {
154 bus_addr_t bm_base;
155 bus_size_t bm_size;
156 bus_space_handle_t bm_bsh;
157 int bm_flags;
158 };
159 #endif
160
161 /**
162 * Kernel side of a mapping
163 */
164 struct drm_local_map {
165 resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
166 unsigned long size; /**< Requested physical size (bytes) */
167 enum drm_map_type type; /**< Type of memory to map */
168 enum drm_map_flags flags; /**< Flags */
169 void *handle; /**< User-space: "Handle" to pass to mmap() */
170 /**< Kernel-space: kernel-virtual address */
171 int mtrr; /**< MTRR slot used */
172
173 #ifdef __NetBSD__
174 union {
175 /* _DRM_FRAME_BUFFER, _DRM_AGP, _DRM_REGISTERS */
176 /* XXX mtrr should be moved into this case too. */
177 struct {
178 /*
179 * XXX bst seems like a waste of space, but not
180 * all accessors have the drm_device handy.
181 */
182 bus_space_tag_t bst;
183 bus_space_handle_t bsh;
184 struct drm_bus_map *bus_map;
185 } bus_space;
186
187 /* _DRM_CONSISTENT */
188 struct drm_dma_handle *dmah;
189
190 /* _DRM_SCATTER_GATHER */
191 #if 0 /* XXX stored in dev->sg instead */
192 struct drm_sg_mem *sg;
193 #endif
194
195 /* _DRM_SHM */
196 /* XXX Anything? uvm object? */
197 } lm_data;
198 #endif
199 };
200
201 typedef struct drm_local_map drm_local_map_t;
202
203 /**
204 * Mappings list
205 */
206 struct drm_map_list {
207 struct list_head head; /**< list head */
208 struct drm_hash_item hash;
209 struct drm_local_map *map; /**< mapping */
210 uint64_t user_token;
211 struct drm_master *master;
212 };
213
214 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
215 unsigned int size, enum drm_map_type type,
216 enum drm_map_flags flags, struct drm_local_map **map_p);
217 int drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
218 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
219 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
220 #ifdef __NetBSD__
221 int drm_legacy_mmap_object(struct drm_device *, off_t, size_t, int,
222 struct uvm_object **, voff_t *, struct file *);
223 paddr_t drm_legacy_mmap_paddr(struct drm_device *, off_t, int);
224 #else
225 int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
226 #endif
227
228 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
229 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
230
231 /**
232 * Test that the hardware lock is held by the caller, returning otherwise.
233 *
234 * \param dev DRM device.
235 * \param filp file pointer of the caller.
236 */
237 #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
238 do { \
239 if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
240 _file_priv->master->lock.file_priv != _file_priv) { \
241 DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
242 __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
243 _file_priv->master->lock.file_priv, _file_priv); \
244 return -EINVAL; \
245 } \
246 } while (0)
247
248 void drm_legacy_idlelock_take(struct drm_lock_data *lock);
249 void drm_legacy_idlelock_release(struct drm_lock_data *lock);
250
251 /* drm_pci.c dma alloc wrappers */
252 void __drm_legacy_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
253
254 /* drm_memory.c */
255 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
256 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
257 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
258
259 static __inline__ struct drm_local_map *drm_legacy_findmap(struct drm_device *dev,
260 unsigned int token)
261 {
262 struct drm_map_list *_entry;
263 list_for_each_entry(_entry, &dev->maplist, head)
264 if (_entry->user_token == token)
265 return _entry->map;
266 return NULL;
267 }
268
269 #ifdef __NetBSD__
270 #include <drm/drm_iomap_netbsd.h>
271 #endif
272
273 #endif /* __DRM_DRM_LEGACY_H__ */
274