Back to home page

OSCL-LXR

 
 

    


0001 #ifndef __DRM_DRM_LEGACY_H__
0002 #define __DRM_DRM_LEGACY_H__
0003 /*
0004  * Legacy driver interfaces for the Direct Rendering Manager
0005  *
0006  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
0007  * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
0008  * Copyright (c) 2009-2010, Code Aurora Forum.
0009  * All rights reserved.
0010  * Copyright © 2014 Intel Corporation
0011  *   Daniel Vetter <daniel.vetter@ffwll.ch>
0012  *
0013  * Author: Rickard E. (Rik) Faith <faith@valinux.com>
0014  * Author: Gareth Hughes <gareth@valinux.com>
0015  *
0016  * Permission is hereby granted, free of charge, to any person obtaining a
0017  * copy of this software and associated documentation files (the "Software"),
0018  * to deal in the Software without restriction, including without limitation
0019  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0020  * and/or sell copies of the Software, and to permit persons to whom the
0021  * Software is furnished to do so, subject to the following conditions:
0022  *
0023  * The above copyright notice and this permission notice (including the next
0024  * paragraph) shall be included in all copies or substantial portions of the
0025  * Software.
0026  *
0027  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0028  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0029  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0030  * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
0031  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0032  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0033  * OTHER DEALINGS IN THE SOFTWARE.
0034  */
0035 
0036 #include <linux/agp_backend.h>
0037 
0038 #include <drm/drm.h>
0039 #include <drm/drm_auth.h>
0040 
0041 struct drm_device;
0042 struct drm_driver;
0043 struct file;
0044 struct pci_driver;
0045 
0046 /*
0047  * Legacy Support for palateontologic DRM drivers
0048  *
0049  * If you add a new driver and it uses any of these functions or structures,
0050  * you're doing it terribly wrong.
0051  */
0052 
0053 /*
0054  * Hash-table Support
0055  */
0056 
0057 struct drm_hash_item {
0058     struct hlist_node head;
0059     unsigned long key;
0060 };
0061 
0062 struct drm_open_hash {
0063     struct hlist_head *table;
0064     u8 order;
0065 };
0066 
0067 /**
0068  * DMA buffer.
0069  */
0070 struct drm_buf {
0071     int idx;               /**< Index into master buflist */
0072     int total;             /**< Buffer size */
0073     int order;             /**< log-base-2(total) */
0074     int used;              /**< Amount of buffer in use (for DMA) */
0075     unsigned long offset;          /**< Byte offset (used internally) */
0076     void *address;             /**< Address of buffer */
0077     unsigned long bus_address;     /**< Bus address of buffer */
0078     struct drm_buf *next;          /**< Kernel-only: used for free list */
0079     __volatile__ int waiting;      /**< On kernel DMA queue */
0080     __volatile__ int pending;      /**< On hardware DMA queue */
0081     struct drm_file *file_priv;    /**< Private of holding file descr */
0082     int context;               /**< Kernel queue for this buffer */
0083     int while_locked;          /**< Dispatch this buffer while locked */
0084     enum {
0085         DRM_LIST_NONE = 0,
0086         DRM_LIST_FREE = 1,
0087         DRM_LIST_WAIT = 2,
0088         DRM_LIST_PEND = 3,
0089         DRM_LIST_PRIO = 4,
0090         DRM_LIST_RECLAIM = 5
0091     } list;                /**< Which list we're on */
0092 
0093     int dev_priv_size;       /**< Size of buffer private storage */
0094     void *dev_private;       /**< Per-buffer private storage */
0095 };
0096 
0097 typedef struct drm_dma_handle {
0098     dma_addr_t busaddr;
0099     void *vaddr;
0100     size_t size;
0101 } drm_dma_handle_t;
0102 
0103 /**
0104  * Buffer entry.  There is one of this for each buffer size order.
0105  */
0106 struct drm_buf_entry {
0107     int buf_size;           /**< size */
0108     int buf_count;          /**< number of buffers */
0109     struct drm_buf *buflist;        /**< buffer list */
0110     int seg_count;
0111     int page_order;
0112     struct drm_dma_handle **seglist;
0113 
0114     int low_mark;           /**< Low water mark */
0115     int high_mark;          /**< High water mark */
0116 };
0117 
0118 /**
0119  * DMA data.
0120  */
0121 struct drm_device_dma {
0122 
0123     struct drm_buf_entry bufs[DRM_MAX_ORDER + 1];   /**< buffers, grouped by their size order */
0124     int buf_count;          /**< total number of buffers */
0125     struct drm_buf **buflist;       /**< Vector of pointers into drm_device_dma::bufs */
0126     int seg_count;
0127     int page_count;         /**< number of pages */
0128     unsigned long *pagelist;    /**< page list */
0129     unsigned long byte_count;
0130     enum {
0131         _DRM_DMA_USE_AGP = 0x01,
0132         _DRM_DMA_USE_SG = 0x02,
0133         _DRM_DMA_USE_FB = 0x04,
0134         _DRM_DMA_USE_PCI_RO = 0x08
0135     } flags;
0136 
0137 };
0138 
0139 /**
0140  * Scatter-gather memory.
0141  */
0142 struct drm_sg_mem {
0143     unsigned long handle;
0144     void *virtual;
0145     int pages;
0146     struct page **pagelist;
0147     dma_addr_t *busaddr;
0148 };
0149 
0150 /**
0151  * Kernel side of a mapping
0152  */
0153 struct drm_local_map {
0154     dma_addr_t offset;   /**< Requested physical address (0 for SAREA)*/
0155     unsigned long size;  /**< Requested physical size (bytes) */
0156     enum drm_map_type type;  /**< Type of memory to map */
0157     enum drm_map_flags flags;    /**< Flags */
0158     void *handle;        /**< User-space: "Handle" to pass to mmap() */
0159                  /**< Kernel-space: kernel-virtual address */
0160     int mtrr;        /**< MTRR slot used */
0161 };
0162 
0163 typedef struct drm_local_map drm_local_map_t;
0164 
0165 /**
0166  * Mappings list
0167  */
0168 struct drm_map_list {
0169     struct list_head head;      /**< list head */
0170     struct drm_hash_item hash;
0171     struct drm_local_map *map;  /**< mapping */
0172     uint64_t user_token;
0173     struct drm_master *master;
0174 };
0175 
0176 int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
0177               unsigned int size, enum drm_map_type type,
0178               enum drm_map_flags flags, struct drm_local_map **map_p);
0179 struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
0180 void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
0181 int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
0182 struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
0183 int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
0184 
0185 int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
0186 int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
0187 
0188 /**
0189  * Test that the hardware lock is held by the caller, returning otherwise.
0190  *
0191  * \param dev DRM device.
0192  * \param filp file pointer of the caller.
0193  */
0194 #define LOCK_TEST_WITH_RETURN( dev, _file_priv )                \
0195 do {                                        \
0196     if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) ||   \
0197         _file_priv->master->lock.file_priv != _file_priv)   {       \
0198         DRM_ERROR( "%s called without lock held, held  %d owner %p %p\n",\
0199                __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
0200                _file_priv->master->lock.file_priv, _file_priv); \
0201         return -EINVAL;                         \
0202     }                                   \
0203 } while (0)
0204 
0205 void drm_legacy_idlelock_take(struct drm_lock_data *lock);
0206 void drm_legacy_idlelock_release(struct drm_lock_data *lock);
0207 
0208 /* drm_irq.c */
0209 int drm_legacy_irq_uninstall(struct drm_device *dev);
0210 
0211 /* drm_pci.c */
0212 
0213 #ifdef CONFIG_PCI
0214 
0215 int drm_legacy_pci_init(const struct drm_driver *driver,
0216             struct pci_driver *pdriver);
0217 void drm_legacy_pci_exit(const struct drm_driver *driver,
0218              struct pci_driver *pdriver);
0219 
0220 #else
0221 
0222 static inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
0223                            size_t size, size_t align)
0224 {
0225     return NULL;
0226 }
0227 
0228 static inline void drm_pci_free(struct drm_device *dev,
0229                 struct drm_dma_handle *dmah)
0230 {
0231 }
0232 
0233 static inline int drm_legacy_pci_init(const struct drm_driver *driver,
0234                       struct pci_driver *pdriver)
0235 {
0236     return -EINVAL;
0237 }
0238 
0239 static inline void drm_legacy_pci_exit(const struct drm_driver *driver,
0240                        struct pci_driver *pdriver)
0241 {
0242 }
0243 
0244 #endif
0245 
0246 /*
0247  * AGP Support
0248  */
0249 
0250 struct drm_agp_head {
0251     struct agp_kern_info agp_info;
0252     struct list_head memory;
0253     unsigned long mode;
0254     struct agp_bridge_data *bridge;
0255     int enabled;
0256     int acquired;
0257     unsigned long base;
0258     int agp_mtrr;
0259     int cant_use_aperture;
0260     unsigned long page_mask;
0261 };
0262 
0263 #if IS_ENABLED(CONFIG_DRM_LEGACY) && IS_ENABLED(CONFIG_AGP)
0264 struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev);
0265 int drm_legacy_agp_acquire(struct drm_device *dev);
0266 int drm_legacy_agp_release(struct drm_device *dev);
0267 int drm_legacy_agp_enable(struct drm_device *dev, struct drm_agp_mode mode);
0268 int drm_legacy_agp_info(struct drm_device *dev, struct drm_agp_info *info);
0269 int drm_legacy_agp_alloc(struct drm_device *dev, struct drm_agp_buffer *request);
0270 int drm_legacy_agp_free(struct drm_device *dev, struct drm_agp_buffer *request);
0271 int drm_legacy_agp_unbind(struct drm_device *dev, struct drm_agp_binding *request);
0272 int drm_legacy_agp_bind(struct drm_device *dev, struct drm_agp_binding *request);
0273 #else
0274 static inline struct drm_agp_head *drm_legacy_agp_init(struct drm_device *dev)
0275 {
0276     return NULL;
0277 }
0278 
0279 static inline int drm_legacy_agp_acquire(struct drm_device *dev)
0280 {
0281     return -ENODEV;
0282 }
0283 
0284 static inline int drm_legacy_agp_release(struct drm_device *dev)
0285 {
0286     return -ENODEV;
0287 }
0288 
0289 static inline int drm_legacy_agp_enable(struct drm_device *dev,
0290                     struct drm_agp_mode mode)
0291 {
0292     return -ENODEV;
0293 }
0294 
0295 static inline int drm_legacy_agp_info(struct drm_device *dev,
0296                       struct drm_agp_info *info)
0297 {
0298     return -ENODEV;
0299 }
0300 
0301 static inline int drm_legacy_agp_alloc(struct drm_device *dev,
0302                        struct drm_agp_buffer *request)
0303 {
0304     return -ENODEV;
0305 }
0306 
0307 static inline int drm_legacy_agp_free(struct drm_device *dev,
0308                       struct drm_agp_buffer *request)
0309 {
0310     return -ENODEV;
0311 }
0312 
0313 static inline int drm_legacy_agp_unbind(struct drm_device *dev,
0314                     struct drm_agp_binding *request)
0315 {
0316     return -ENODEV;
0317 }
0318 
0319 static inline int drm_legacy_agp_bind(struct drm_device *dev,
0320                       struct drm_agp_binding *request)
0321 {
0322     return -ENODEV;
0323 }
0324 #endif
0325 
0326 /* drm_memory.c */
0327 void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
0328 void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
0329 void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
0330 
0331 #endif /* __DRM_DRM_LEGACY_H__ */