1 1.1 riastrad /* $NetBSD: drm_legacy.h,v 1.8 2021/12/18 23:45:46 riastradh Exp $ */ 2 1.1 riastrad 3 1.1 riastrad #ifndef __DRM_DRM_LEGACY_H__ 4 1.1 riastrad #define __DRM_DRM_LEGACY_H__ 5 1.1 riastrad /* 6 1.1 riastrad * Legacy driver interfaces for the Direct Rendering Manager 7 1.1 riastrad * 8 1.1 riastrad * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas. 9 1.1 riastrad * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. 10 1.1 riastrad * Copyright (c) 2009-2010, Code Aurora Forum. 11 1.1 riastrad * All rights reserved. 12 1.1 riastrad * Copyright 2014 Intel Corporation 13 1.1 riastrad * Daniel Vetter <daniel.vetter (at) ffwll.ch> 14 1.1 riastrad * 15 1.1 riastrad * Author: Rickard E. (Rik) Faith <faith (at) valinux.com> 16 1.1 riastrad * Author: Gareth Hughes <gareth (at) valinux.com> 17 1.1 riastrad * 18 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 19 1.1 riastrad * copy of this software and associated documentation files (the "Software"), 20 1.1 riastrad * to deal in the Software without restriction, including without limitation 21 1.1 riastrad * the rights to use, copy, modify, merge, publish, distribute, sublicense, 22 1.1 riastrad * and/or sell copies of the Software, and to permit persons to whom the 23 1.1 riastrad * Software is furnished to do so, subject to the following conditions: 24 1.1 riastrad * 25 1.1 riastrad * The above copyright notice and this permission notice (including the next 26 1.1 riastrad * paragraph) shall be included in all copies or substantial portions of the 27 1.1 riastrad * Software. 28 1.1 riastrad * 29 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 30 1.1 riastrad * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 31 1.1 riastrad * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 32 1.1 riastrad * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 33 1.1 riastrad * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 34 1.1 riastrad * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 35 1.1 riastrad * OTHER DEALINGS IN THE SOFTWARE. 36 1.1 riastrad */ 37 1.1 riastrad 38 1.8 riastrad #include <drm/drm.h> 39 1.8 riastrad #include <drm/drm_auth.h> 40 1.3 riastrad #include <drm/drm_hashtab.h> 41 1.3 riastrad 42 1.8 riastrad struct drm_device; 43 1.8 riastrad struct drm_driver; 44 1.8 riastrad struct file; 45 1.8 riastrad struct pci_driver; 46 1.1 riastrad 47 1.1 riastrad /* 48 1.1 riastrad * Legacy Support for palateontologic DRM drivers 49 1.1 riastrad * 50 1.1 riastrad * If you add a new driver and it uses any of these functions or structures, 51 1.1 riastrad * you're doing it terribly wrong. 52 1.1 riastrad */ 53 1.1 riastrad 54 1.1 riastrad /** 55 1.1 riastrad * DMA buffer. 56 1.1 riastrad */ 57 1.1 riastrad struct drm_buf { 58 1.1 riastrad int idx; /**< Index into master buflist */ 59 1.1 riastrad int total; /**< Buffer size */ 60 1.1 riastrad int order; /**< log-base-2(total) */ 61 1.1 riastrad int used; /**< Amount of buffer in use (for DMA) */ 62 1.1 riastrad unsigned long offset; /**< Byte offset (used internally) */ 63 1.1 riastrad void *address; /**< Address of buffer */ 64 1.1 riastrad unsigned long bus_address; /**< Bus address of buffer */ 65 1.1 riastrad struct drm_buf *next; /**< Kernel-only: used for free list */ 66 1.1 riastrad __volatile__ int waiting; /**< On kernel DMA queue */ 67 1.1 riastrad __volatile__ int pending; /**< On hardware DMA queue */ 68 1.1 riastrad struct drm_file *file_priv; /**< Private of holding file descr */ 69 1.1 riastrad int context; /**< Kernel queue for this buffer */ 70 1.1 riastrad int while_locked; /**< Dispatch this buffer while locked */ 71 1.1 riastrad enum { 72 1.1 riastrad DRM_LIST_NONE = 0, 73 1.1 riastrad DRM_LIST_FREE = 1, 74 1.1 riastrad DRM_LIST_WAIT = 2, 75 1.1 riastrad DRM_LIST_PEND = 3, 76 1.1 riastrad DRM_LIST_PRIO = 4, 77 1.1 riastrad DRM_LIST_RECLAIM = 5 78 1.1 riastrad } list; /**< Which list we're on */ 79 1.1 riastrad 80 1.1 riastrad int dev_priv_size; /**< Size of buffer private storage */ 81 1.1 riastrad void *dev_private; /**< Per-buffer private storage */ 82 1.1 riastrad }; 83 1.1 riastrad 84 1.1 riastrad typedef struct drm_dma_handle { 85 1.1 riastrad dma_addr_t busaddr; 86 1.1 riastrad void *vaddr; 87 1.1 riastrad size_t size; 88 1.2 riastrad #ifdef __NetBSD__ 89 1.2 riastrad bus_dma_tag_t dmah_tag; 90 1.2 riastrad bus_dmamap_t dmah_map; 91 1.2 riastrad bus_dma_segment_t dmah_seg; 92 1.2 riastrad #endif 93 1.1 riastrad } drm_dma_handle_t; 94 1.1 riastrad 95 1.1 riastrad /** 96 1.1 riastrad * Buffer entry. There is one of this for each buffer size order. 97 1.1 riastrad */ 98 1.1 riastrad struct drm_buf_entry { 99 1.1 riastrad int buf_size; /**< size */ 100 1.1 riastrad int buf_count; /**< number of buffers */ 101 1.1 riastrad struct drm_buf *buflist; /**< buffer list */ 102 1.1 riastrad int seg_count; 103 1.1 riastrad int page_order; 104 1.1 riastrad struct drm_dma_handle **seglist; 105 1.1 riastrad 106 1.1 riastrad int low_mark; /**< Low water mark */ 107 1.1 riastrad int high_mark; /**< High water mark */ 108 1.1 riastrad }; 109 1.1 riastrad 110 1.1 riastrad /** 111 1.1 riastrad * DMA data. 112 1.1 riastrad */ 113 1.1 riastrad struct drm_device_dma { 114 1.1 riastrad 115 1.1 riastrad struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */ 116 1.1 riastrad int buf_count; /**< total number of buffers */ 117 1.1 riastrad struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */ 118 1.1 riastrad int seg_count; 119 1.1 riastrad int page_count; /**< number of pages */ 120 1.1 riastrad unsigned long *pagelist; /**< page list */ 121 1.1 riastrad unsigned long byte_count; 122 1.1 riastrad enum { 123 1.1 riastrad _DRM_DMA_USE_AGP = 0x01, 124 1.1 riastrad _DRM_DMA_USE_SG = 0x02, 125 1.1 riastrad _DRM_DMA_USE_FB = 0x04, 126 1.1 riastrad _DRM_DMA_USE_PCI_RO = 0x08 127 1.1 riastrad } flags; 128 1.1 riastrad 129 1.1 riastrad }; 130 1.1 riastrad 131 1.1 riastrad /** 132 1.1 riastrad * Scatter-gather memory. 133 1.1 riastrad */ 134 1.1 riastrad struct drm_sg_mem { 135 1.1 riastrad unsigned long handle; 136 1.1 riastrad void *virtual; 137 1.2 riastrad #ifdef __NetBSD__ 138 1.2 riastrad size_t sg_size; 139 1.2 riastrad bus_dma_tag_t sg_tag; 140 1.2 riastrad bus_dmamap_t sg_map; 141 1.2 riastrad unsigned int sg_nsegs; 142 1.2 riastrad unsigned int sg_nsegs_max; 143 1.2 riastrad bus_dma_segment_t sg_segs[]; 144 1.2 riastrad #else 145 1.1 riastrad int pages; 146 1.1 riastrad struct page **pagelist; 147 1.1 riastrad dma_addr_t *busaddr; 148 1.2 riastrad #endif 149 1.1 riastrad }; 150 1.1 riastrad 151 1.2 riastrad #ifdef __NetBSD__ 152 1.2 riastrad /* 153 1.2 riastrad * XXX Remember: memory mappings only. bm_flags must include 154 1.2 riastrad * BUS_SPACE_MAP_LINEAR. 155 1.2 riastrad */ 156 1.2 riastrad struct drm_bus_map { 157 1.2 riastrad bus_addr_t bm_base; 158 1.2 riastrad bus_size_t bm_size; 159 1.2 riastrad bus_space_handle_t bm_bsh; 160 1.2 riastrad int bm_flags; 161 1.2 riastrad }; 162 1.2 riastrad #endif 163 1.2 riastrad 164 1.1 riastrad /** 165 1.1 riastrad * Kernel side of a mapping 166 1.1 riastrad */ 167 1.1 riastrad struct drm_local_map { 168 1.1 riastrad resource_size_t offset; /**< Requested physical address (0 for SAREA)*/ 169 1.1 riastrad unsigned long size; /**< Requested physical size (bytes) */ 170 1.1 riastrad enum drm_map_type type; /**< Type of memory to map */ 171 1.1 riastrad enum drm_map_flags flags; /**< Flags */ 172 1.1 riastrad void *handle; /**< User-space: "Handle" to pass to mmap() */ 173 1.1 riastrad /**< Kernel-space: kernel-virtual address */ 174 1.1 riastrad int mtrr; /**< MTRR slot used */ 175 1.2 riastrad 176 1.2 riastrad #ifdef __NetBSD__ 177 1.2 riastrad union { 178 1.2 riastrad /* _DRM_FRAME_BUFFER, _DRM_AGP, _DRM_REGISTERS */ 179 1.2 riastrad /* XXX mtrr should be moved into this case too. */ 180 1.2 riastrad struct { 181 1.2 riastrad /* 182 1.2 riastrad * XXX bst seems like a waste of space, but not 183 1.2 riastrad * all accessors have the drm_device handy. 184 1.2 riastrad */ 185 1.2 riastrad bus_space_tag_t bst; 186 1.2 riastrad bus_space_handle_t bsh; 187 1.2 riastrad struct drm_bus_map *bus_map; 188 1.2 riastrad } bus_space; 189 1.2 riastrad 190 1.2 riastrad /* _DRM_CONSISTENT */ 191 1.2 riastrad struct drm_dma_handle *dmah; 192 1.2 riastrad 193 1.2 riastrad /* _DRM_SCATTER_GATHER */ 194 1.2 riastrad #if 0 /* XXX stored in dev->sg instead */ 195 1.2 riastrad struct drm_sg_mem *sg; 196 1.2 riastrad #endif 197 1.2 riastrad 198 1.2 riastrad /* _DRM_SHM */ 199 1.2 riastrad /* XXX Anything? uvm object? */ 200 1.2 riastrad } lm_data; 201 1.2 riastrad #endif 202 1.1 riastrad }; 203 1.1 riastrad 204 1.1 riastrad typedef struct drm_local_map drm_local_map_t; 205 1.1 riastrad 206 1.1 riastrad /** 207 1.1 riastrad * Mappings list 208 1.1 riastrad */ 209 1.1 riastrad struct drm_map_list { 210 1.1 riastrad struct list_head head; /**< list head */ 211 1.1 riastrad struct drm_hash_item hash; 212 1.1 riastrad struct drm_local_map *map; /**< mapping */ 213 1.1 riastrad uint64_t user_token; 214 1.1 riastrad struct drm_master *master; 215 1.1 riastrad }; 216 1.1 riastrad 217 1.1 riastrad int drm_legacy_addmap(struct drm_device *d, resource_size_t offset, 218 1.1 riastrad unsigned int size, enum drm_map_type type, 219 1.1 riastrad enum drm_map_flags flags, struct drm_local_map **map_p); 220 1.8 riastrad struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token); 221 1.8 riastrad void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map); 222 1.1 riastrad int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map); 223 1.1 riastrad struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev); 224 1.2 riastrad #ifdef __NetBSD__ 225 1.7 riastrad int drm_legacy_mmap_object(struct drm_device *, off_t, size_t, int, 226 1.2 riastrad struct uvm_object **, voff_t *, struct file *); 227 1.7 riastrad paddr_t drm_legacy_mmap_paddr(struct drm_device *, off_t, int); 228 1.2 riastrad #else 229 1.1 riastrad int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma); 230 1.2 riastrad #endif 231 1.1 riastrad 232 1.1 riastrad int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req); 233 1.1 riastrad int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req); 234 1.1 riastrad 235 1.1 riastrad /** 236 1.1 riastrad * Test that the hardware lock is held by the caller, returning otherwise. 237 1.1 riastrad * 238 1.1 riastrad * \param dev DRM device. 239 1.1 riastrad * \param filp file pointer of the caller. 240 1.1 riastrad */ 241 1.1 riastrad #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \ 242 1.1 riastrad do { \ 243 1.1 riastrad if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \ 244 1.1 riastrad _file_priv->master->lock.file_priv != _file_priv) { \ 245 1.1 riastrad DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\ 246 1.1 riastrad __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\ 247 1.1 riastrad _file_priv->master->lock.file_priv, _file_priv); \ 248 1.1 riastrad return -EINVAL; \ 249 1.1 riastrad } \ 250 1.1 riastrad } while (0) 251 1.1 riastrad 252 1.1 riastrad void drm_legacy_idlelock_take(struct drm_lock_data *lock); 253 1.1 riastrad void drm_legacy_idlelock_release(struct drm_lock_data *lock); 254 1.1 riastrad 255 1.8 riastrad /* drm_pci.c */ 256 1.8 riastrad 257 1.8 riastrad #ifdef CONFIG_PCI 258 1.8 riastrad 259 1.1 riastrad void __drm_legacy_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah); 260 1.8 riastrad int drm_legacy_pci_init(struct drm_driver *driver, struct pci_driver *pdriver); 261 1.8 riastrad void drm_legacy_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver); 262 1.8 riastrad 263 1.8 riastrad #else 264 1.8 riastrad 265 1.8 riastrad static inline void __drm_legacy_pci_free(struct drm_device *dev, 266 1.8 riastrad drm_dma_handle_t *dmah) 267 1.8 riastrad { 268 1.8 riastrad } 269 1.8 riastrad 270 1.8 riastrad static inline int drm_legacy_pci_init(struct drm_driver *driver, 271 1.8 riastrad struct pci_driver *pdriver) 272 1.8 riastrad { 273 1.8 riastrad return -EINVAL; 274 1.8 riastrad } 275 1.8 riastrad 276 1.8 riastrad static inline void drm_legacy_pci_exit(struct drm_driver *driver, 277 1.8 riastrad struct pci_driver *pdriver) 278 1.8 riastrad { 279 1.8 riastrad } 280 1.8 riastrad 281 1.8 riastrad #endif 282 1.1 riastrad 283 1.1 riastrad /* drm_memory.c */ 284 1.1 riastrad void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev); 285 1.1 riastrad void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev); 286 1.1 riastrad void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev); 287 1.1 riastrad 288 1.5 riastrad #ifdef __NetBSD__ 289 1.5 riastrad #include <drm/drm_iomap_netbsd.h> 290 1.5 riastrad #endif 291 1.5 riastrad 292 1.1 riastrad #endif /* __DRM_DRM_LEGACY_H__ */ 293