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