Home | History | Annotate | Line # | Download | only in drm
      1 /*	$NetBSD: drm_legacy.h,v 1.3 2021/12/18 23:44:57 riastradh Exp $	*/
      2 
      3 #ifndef __DRM_LEGACY_H__
      4 #define __DRM_LEGACY_H__
      5 
      6 /*
      7  * Copyright (c) 2014 David Herrmann <dh.herrmann (at) gmail.com>
      8  *
      9  * Permission is hereby granted, free of charge, to any person obtaining a
     10  * copy of this software and associated documentation files (the "Software"),
     11  * to deal in the Software without restriction, including without limitation
     12  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
     13  * and/or sell copies of the Software, and to permit persons to whom the
     14  * Software is furnished to do so, subject to the following conditions:
     15  *
     16  * The above copyright notice and this permission notice shall be included in
     17  * all copies or substantial portions of the Software.
     18  *
     19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
     22  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
     23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
     24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
     25  * OTHER DEALINGS IN THE SOFTWARE.
     26  */
     27 
     28 /*
     29  * This file contains legacy interfaces that modern drm drivers
     30  * should no longer be using. They cannot be removed as legacy
     31  * drivers use them, and removing them are API breaks.
     32  */
     33 #include <linux/list.h>
     34 
     35 #include <drm/drm.h>
     36 #include <drm/drm_device.h>
     37 #include <drm/drm_legacy.h>
     38 
     39 struct agp_memory;
     40 struct drm_device;
     41 struct drm_file;
     42 struct drm_buf_desc;
     43 
     44 /*
     45  * Generic DRM Contexts
     46  */
     47 
     48 #define DRM_KERNEL_CONTEXT		0
     49 #define DRM_RESERVED_CONTEXTS		1
     50 
     51 #if IS_ENABLED(CONFIG_DRM_LEGACY)
     52 void drm_legacy_ctxbitmap_init(struct drm_device *dev);
     53 void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev);
     54 void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file);
     55 #else
     56 static inline void drm_legacy_ctxbitmap_init(struct drm_device *dev) {}
     57 static inline void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev) {}
     58 static inline void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) {}
     59 #endif
     60 
     61 void drm_legacy_ctxbitmap_free(struct drm_device *dev, int ctx_handle);
     62 
     63 #if IS_ENABLED(CONFIG_DRM_LEGACY)
     64 int drm_legacy_resctx(struct drm_device *d, void *v, struct drm_file *f);
     65 int drm_legacy_addctx(struct drm_device *d, void *v, struct drm_file *f);
     66 int drm_legacy_getctx(struct drm_device *d, void *v, struct drm_file *f);
     67 int drm_legacy_switchctx(struct drm_device *d, void *v, struct drm_file *f);
     68 int drm_legacy_newctx(struct drm_device *d, void *v, struct drm_file *f);
     69 int drm_legacy_rmctx(struct drm_device *d, void *v, struct drm_file *f);
     70 
     71 int drm_legacy_setsareactx(struct drm_device *d, void *v, struct drm_file *f);
     72 int drm_legacy_getsareactx(struct drm_device *d, void *v, struct drm_file *f);
     73 #endif
     74 
     75 /*
     76  * Generic Buffer Management
     77  */
     78 
     79 #define DRM_MAP_HASH_OFFSET 0x10000000
     80 
     81 #if IS_ENABLED(CONFIG_DRM_LEGACY)
     82 static inline int drm_legacy_create_map_hash(struct drm_device *dev)
     83 {
     84 	return drm_ht_create(&dev->map_hash, 12);
     85 }
     86 
     87 static inline void drm_legacy_remove_map_hash(struct drm_device *dev)
     88 {
     89 	drm_ht_remove(&dev->map_hash);
     90 }
     91 #else
     92 static inline int drm_legacy_create_map_hash(struct drm_device *dev)
     93 {
     94 	return 0;
     95 }
     96 
     97 static inline void drm_legacy_remove_map_hash(struct drm_device *dev) {}
     98 #endif
     99 
    100 
    101 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    102 int drm_legacy_getmap_ioctl(struct drm_device *dev, void *data,
    103 			    struct drm_file *file_priv);
    104 int drm_legacy_addmap_ioctl(struct drm_device *d, void *v, struct drm_file *f);
    105 int drm_legacy_rmmap_ioctl(struct drm_device *d, void *v, struct drm_file *f);
    106 
    107 int drm_legacy_addbufs(struct drm_device *d, void *v, struct drm_file *f);
    108 int drm_legacy_infobufs(struct drm_device *d, void *v, struct drm_file *f);
    109 int drm_legacy_markbufs(struct drm_device *d, void *v, struct drm_file *f);
    110 int drm_legacy_freebufs(struct drm_device *d, void *v, struct drm_file *f);
    111 int drm_legacy_mapbufs(struct drm_device *d, void *v, struct drm_file *f);
    112 int drm_legacy_dma_ioctl(struct drm_device *d, void *v, struct drm_file *f);
    113 #endif
    114 
    115 int __drm_legacy_infobufs(struct drm_device *, void *, int *,
    116 			  int (*)(void *, int, struct drm_buf_entry *));
    117 int __drm_legacy_mapbufs(struct drm_device *, void *, int *,
    118 			  void __user **,
    119 			  int (*)(void *, int, unsigned long, struct drm_buf *),
    120 			  struct drm_file *);
    121 
    122 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    123 void drm_legacy_master_rmmaps(struct drm_device *dev,
    124 			      struct drm_master *master);
    125 void drm_legacy_rmmaps(struct drm_device *dev);
    126 #else
    127 static inline void drm_legacy_master_rmmaps(struct drm_device *dev,
    128 					    struct drm_master *master) {}
    129 static inline void drm_legacy_rmmaps(struct drm_device *dev) {}
    130 #endif
    131 
    132 #if IS_ENABLED(CONFIG_DRM_VM) && IS_ENABLED(CONFIG_DRM_LEGACY)
    133 void drm_legacy_vma_flush(struct drm_device *d);
    134 #else
    135 static inline void drm_legacy_vma_flush(struct drm_device *d)
    136 {
    137 	/* do nothing */
    138 }
    139 #endif
    140 
    141 /*
    142  * AGP Support
    143  */
    144 
    145 struct drm_agp_mem {
    146 	unsigned long handle;
    147 	struct agp_memory *memory;
    148 	unsigned long bound;
    149 	int pages;
    150 	struct list_head head;
    151 };
    152 
    153 /* drm_lock.c */
    154 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    155 int drm_legacy_lock(struct drm_device *d, void *v, struct drm_file *f);
    156 int drm_legacy_unlock(struct drm_device *d, void *v, struct drm_file *f);
    157 void drm_legacy_lock_release(struct drm_device *dev, struct file *filp);
    158 #else
    159 static inline void drm_legacy_lock_release(struct drm_device *dev, struct file *filp) {}
    160 #endif
    161 
    162 /* DMA support */
    163 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    164 int drm_legacy_dma_setup(struct drm_device *dev);
    165 void drm_legacy_dma_takedown(struct drm_device *dev);
    166 #else
    167 static inline int drm_legacy_dma_setup(struct drm_device *dev)
    168 {
    169 	return 0;
    170 }
    171 #endif
    172 
    173 void drm_legacy_free_buffer(struct drm_device *dev,
    174 			    struct drm_buf * buf);
    175 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    176 void drm_legacy_reclaim_buffers(struct drm_device *dev,
    177 				struct drm_file *filp);
    178 #else
    179 static inline void drm_legacy_reclaim_buffers(struct drm_device *dev,
    180 					      struct drm_file *filp) {}
    181 #endif
    182 
    183 /* Scatter Gather Support */
    184 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    185 void drm_legacy_sg_cleanup(struct drm_device *dev);
    186 int drm_legacy_sg_alloc(struct drm_device *dev, void *data,
    187 			struct drm_file *file_priv);
    188 int drm_legacy_sg_free(struct drm_device *dev, void *data,
    189 		       struct drm_file *file_priv);
    190 #endif
    191 
    192 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    193 void drm_legacy_init_members(struct drm_device *dev);
    194 void drm_legacy_destroy_members(struct drm_device *dev);
    195 void drm_legacy_dev_reinit(struct drm_device *dev);
    196 int drm_legacy_setup(struct drm_device * dev);
    197 #else
    198 static inline void drm_legacy_init_members(struct drm_device *dev) {}
    199 static inline void drm_legacy_destroy_members(struct drm_device *dev) {}
    200 static inline void drm_legacy_dev_reinit(struct drm_device *dev) {}
    201 static inline int drm_legacy_setup(struct drm_device * dev) { return 0; }
    202 #endif
    203 
    204 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    205 void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master);
    206 #else
    207 static inline void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master) {}
    208 #endif
    209 
    210 #if IS_ENABLED(CONFIG_DRM_LEGACY)
    211 void drm_master_legacy_init(struct drm_master *master);
    212 #else
    213 static inline void drm_master_legacy_init(struct drm_master *master) {}
    214 #endif
    215 
    216 #endif /* __DRM_LEGACY_H__ */
    217