drm_legacy.h (10349B)
1#ifndef __DRM_LEGACY_H__ 2#define __DRM_LEGACY_H__ 3 4/* 5 * Copyright (c) 2014 David Herrmann <dh.herrmann@gmail.com> 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included in 15 * all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 23 * OTHER DEALINGS IN THE SOFTWARE. 24 */ 25 26/* 27 * This file contains legacy interfaces that modern drm drivers 28 * should no longer be using. They cannot be removed as legacy 29 * drivers use them, and removing them are API breaks. 30 */ 31#include <linux/list.h> 32 33#include <drm/drm.h> 34#include <drm/drm_device.h> 35#include <drm/drm_legacy.h> 36 37struct agp_memory; 38struct drm_buf_desc; 39struct drm_device; 40struct drm_file; 41struct drm_hash_item; 42struct drm_open_hash; 43 44/* 45 * Hash-table Support 46 */ 47 48#define drm_hash_entry(_ptr, _type, _member) container_of(_ptr, _type, _member) 49 50/* drm_hashtab.c */ 51#if IS_ENABLED(CONFIG_DRM_LEGACY) 52int drm_ht_create(struct drm_open_hash *ht, unsigned int order); 53int drm_ht_insert_item(struct drm_open_hash *ht, struct drm_hash_item *item); 54int drm_ht_just_insert_please(struct drm_open_hash *ht, struct drm_hash_item *item, 55 unsigned long seed, int bits, int shift, 56 unsigned long add); 57int drm_ht_find_item(struct drm_open_hash *ht, unsigned long key, struct drm_hash_item **item); 58 59void drm_ht_verbose_list(struct drm_open_hash *ht, unsigned long key); 60int drm_ht_remove_key(struct drm_open_hash *ht, unsigned long key); 61int drm_ht_remove_item(struct drm_open_hash *ht, struct drm_hash_item *item); 62void drm_ht_remove(struct drm_open_hash *ht); 63#endif 64 65/* 66 * RCU-safe interface 67 * 68 * The user of this API needs to make sure that two or more instances of the 69 * hash table manipulation functions are never run simultaneously. 70 * The lookup function drm_ht_find_item_rcu may, however, run simultaneously 71 * with any of the manipulation functions as long as it's called from within 72 * an RCU read-locked section. 73 */ 74#define drm_ht_insert_item_rcu drm_ht_insert_item 75#define drm_ht_just_insert_please_rcu drm_ht_just_insert_please 76#define drm_ht_remove_key_rcu drm_ht_remove_key 77#define drm_ht_remove_item_rcu drm_ht_remove_item 78#define drm_ht_find_item_rcu drm_ht_find_item 79 80/* 81 * Generic DRM Contexts 82 */ 83 84#define DRM_KERNEL_CONTEXT 0 85#define DRM_RESERVED_CONTEXTS 1 86 87#if IS_ENABLED(CONFIG_DRM_LEGACY) 88void drm_legacy_ctxbitmap_init(struct drm_device *dev); 89void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev); 90void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file); 91#else 92static inline void drm_legacy_ctxbitmap_init(struct drm_device *dev) {} 93static inline void drm_legacy_ctxbitmap_cleanup(struct drm_device *dev) {} 94static inline void drm_legacy_ctxbitmap_flush(struct drm_device *dev, struct drm_file *file) {} 95#endif 96 97void drm_legacy_ctxbitmap_free(struct drm_device *dev, int ctx_handle); 98 99#if IS_ENABLED(CONFIG_DRM_LEGACY) 100int drm_legacy_resctx(struct drm_device *d, void *v, struct drm_file *f); 101int drm_legacy_addctx(struct drm_device *d, void *v, struct drm_file *f); 102int drm_legacy_getctx(struct drm_device *d, void *v, struct drm_file *f); 103int drm_legacy_switchctx(struct drm_device *d, void *v, struct drm_file *f); 104int drm_legacy_newctx(struct drm_device *d, void *v, struct drm_file *f); 105int drm_legacy_rmctx(struct drm_device *d, void *v, struct drm_file *f); 106 107int drm_legacy_setsareactx(struct drm_device *d, void *v, struct drm_file *f); 108int drm_legacy_getsareactx(struct drm_device *d, void *v, struct drm_file *f); 109#endif 110 111/* 112 * Generic Buffer Management 113 */ 114 115#define DRM_MAP_HASH_OFFSET 0x10000000 116 117#if IS_ENABLED(CONFIG_DRM_LEGACY) 118static inline int drm_legacy_create_map_hash(struct drm_device *dev) 119{ 120 return drm_ht_create(&dev->map_hash, 12); 121} 122 123static inline void drm_legacy_remove_map_hash(struct drm_device *dev) 124{ 125 drm_ht_remove(&dev->map_hash); 126} 127#else 128static inline int drm_legacy_create_map_hash(struct drm_device *dev) 129{ 130 return 0; 131} 132 133static inline void drm_legacy_remove_map_hash(struct drm_device *dev) {} 134#endif 135 136 137#if IS_ENABLED(CONFIG_DRM_LEGACY) 138int drm_legacy_getmap_ioctl(struct drm_device *dev, void *data, 139 struct drm_file *file_priv); 140int drm_legacy_addmap_ioctl(struct drm_device *d, void *v, struct drm_file *f); 141int drm_legacy_rmmap_ioctl(struct drm_device *d, void *v, struct drm_file *f); 142 143int drm_legacy_addbufs(struct drm_device *d, void *v, struct drm_file *f); 144int drm_legacy_infobufs(struct drm_device *d, void *v, struct drm_file *f); 145int drm_legacy_markbufs(struct drm_device *d, void *v, struct drm_file *f); 146int drm_legacy_freebufs(struct drm_device *d, void *v, struct drm_file *f); 147int drm_legacy_mapbufs(struct drm_device *d, void *v, struct drm_file *f); 148int drm_legacy_dma_ioctl(struct drm_device *d, void *v, struct drm_file *f); 149#endif 150 151int __drm_legacy_infobufs(struct drm_device *, void *, int *, 152 int (*)(void *, int, struct drm_buf_entry *)); 153int __drm_legacy_mapbufs(struct drm_device *, void *, int *, 154 void __user **, 155 int (*)(void *, int, unsigned long, struct drm_buf *), 156 struct drm_file *); 157 158#if IS_ENABLED(CONFIG_DRM_LEGACY) 159void drm_legacy_master_rmmaps(struct drm_device *dev, 160 struct drm_master *master); 161void drm_legacy_rmmaps(struct drm_device *dev); 162#else 163static inline void drm_legacy_master_rmmaps(struct drm_device *dev, 164 struct drm_master *master) {} 165static inline void drm_legacy_rmmaps(struct drm_device *dev) {} 166#endif 167 168#if IS_ENABLED(CONFIG_DRM_LEGACY) 169void drm_legacy_vma_flush(struct drm_device *d); 170#else 171static inline void drm_legacy_vma_flush(struct drm_device *d) 172{ 173 /* do nothing */ 174} 175#endif 176 177/* 178 * AGP Support 179 */ 180 181struct drm_agp_mem { 182 unsigned long handle; 183 struct agp_memory *memory; 184 unsigned long bound; 185 int pages; 186 struct list_head head; 187}; 188 189/* drm_agpsupport.c */ 190#if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP) 191void drm_legacy_agp_clear(struct drm_device *dev); 192 193int drm_legacy_agp_acquire_ioctl(struct drm_device *dev, void *data, 194 struct drm_file *file_priv); 195int drm_legacy_agp_release_ioctl(struct drm_device *dev, void *data, 196 struct drm_file *file_priv); 197int drm_legacy_agp_enable_ioctl(struct drm_device *dev, void *data, 198 struct drm_file *file_priv); 199int drm_legacy_agp_info_ioctl(struct drm_device *dev, void *data, 200 struct drm_file *file_priv); 201int drm_legacy_agp_alloc_ioctl(struct drm_device *dev, void *data, 202 struct drm_file *file_priv); 203int drm_legacy_agp_free_ioctl(struct drm_device *dev, void *data, 204 struct drm_file *file_priv); 205int drm_legacy_agp_unbind_ioctl(struct drm_device *dev, void *data, 206 struct drm_file *file_priv); 207int drm_legacy_agp_bind_ioctl(struct drm_device *dev, void *data, 208 struct drm_file *file_priv); 209#else 210static inline void drm_legacy_agp_clear(struct drm_device *dev) {} 211#endif 212 213/* drm_lock.c */ 214#if IS_ENABLED(CONFIG_DRM_LEGACY) 215int drm_legacy_lock(struct drm_device *d, void *v, struct drm_file *f); 216int drm_legacy_unlock(struct drm_device *d, void *v, struct drm_file *f); 217void drm_legacy_lock_release(struct drm_device *dev, struct file *filp); 218#else 219static inline void drm_legacy_lock_release(struct drm_device *dev, struct file *filp) {} 220#endif 221 222/* DMA support */ 223#if IS_ENABLED(CONFIG_DRM_LEGACY) 224int drm_legacy_dma_setup(struct drm_device *dev); 225void drm_legacy_dma_takedown(struct drm_device *dev); 226#else 227static inline int drm_legacy_dma_setup(struct drm_device *dev) 228{ 229 return 0; 230} 231#endif 232 233void drm_legacy_free_buffer(struct drm_device *dev, 234 struct drm_buf * buf); 235#if IS_ENABLED(CONFIG_DRM_LEGACY) 236void drm_legacy_reclaim_buffers(struct drm_device *dev, 237 struct drm_file *filp); 238#else 239static inline void drm_legacy_reclaim_buffers(struct drm_device *dev, 240 struct drm_file *filp) {} 241#endif 242 243/* Scatter Gather Support */ 244#if IS_ENABLED(CONFIG_DRM_LEGACY) 245void drm_legacy_sg_cleanup(struct drm_device *dev); 246int drm_legacy_sg_alloc(struct drm_device *dev, void *data, 247 struct drm_file *file_priv); 248int drm_legacy_sg_free(struct drm_device *dev, void *data, 249 struct drm_file *file_priv); 250#endif 251 252#if IS_ENABLED(CONFIG_DRM_LEGACY) 253void drm_legacy_init_members(struct drm_device *dev); 254void drm_legacy_destroy_members(struct drm_device *dev); 255void drm_legacy_dev_reinit(struct drm_device *dev); 256int drm_legacy_setup(struct drm_device * dev); 257#else 258static inline void drm_legacy_init_members(struct drm_device *dev) {} 259static inline void drm_legacy_destroy_members(struct drm_device *dev) {} 260static inline void drm_legacy_dev_reinit(struct drm_device *dev) {} 261static inline int drm_legacy_setup(struct drm_device * dev) { return 0; } 262#endif 263 264#if IS_ENABLED(CONFIG_DRM_LEGACY) 265void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master); 266#else 267static inline void drm_legacy_lock_master_cleanup(struct drm_device *dev, struct drm_master *master) {} 268#endif 269 270#if IS_ENABLED(CONFIG_DRM_LEGACY) 271void drm_master_legacy_init(struct drm_master *master); 272#else 273static inline void drm_master_legacy_init(struct drm_master *master) {} 274#endif 275 276/* drm_pci.c */ 277#if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_PCI) 278int drm_legacy_irq_by_busid(struct drm_device *dev, void *data, struct drm_file *file_priv); 279void drm_legacy_pci_agp_destroy(struct drm_device *dev); 280#else 281static inline int drm_legacy_irq_by_busid(struct drm_device *dev, void *data, 282 struct drm_file *file_priv) 283{ 284 return -EINVAL; 285} 286 287static inline void drm_legacy_pci_agp_destroy(struct drm_device *dev) {} 288#endif 289 290#endif /* __DRM_LEGACY_H__ */