drm_legacy.h 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. #ifndef __DRM_DRM_LEGACY_H__
  2. #define __DRM_DRM_LEGACY_H__
  3. /*
  4. * Legacy driver interfaces for the Direct Rendering Manager
  5. *
  6. * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
  7. * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
  8. * Copyright (c) 2009-2010, Code Aurora Forum.
  9. * All rights reserved.
  10. * Copyright © 2014 Intel Corporation
  11. * Daniel Vetter <daniel.vetter@ffwll.ch>
  12. *
  13. * Author: Rickard E. (Rik) Faith <faith@valinux.com>
  14. * Author: Gareth Hughes <gareth@valinux.com>
  15. *
  16. * Permission is hereby granted, free of charge, to any person obtaining a
  17. * copy of this software and associated documentation files (the "Software"),
  18. * to deal in the Software without restriction, including without limitation
  19. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  20. * and/or sell copies of the Software, and to permit persons to whom the
  21. * Software is furnished to do so, subject to the following conditions:
  22. *
  23. * The above copyright notice and this permission notice (including the next
  24. * paragraph) shall be included in all copies or substantial portions of the
  25. * Software.
  26. *
  27. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  28. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  29. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  30. * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
  31. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  32. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  33. * OTHER DEALINGS IN THE SOFTWARE.
  34. */
  35. #include <drm/drm.h>
  36. #include <drm/drm_auth.h>
  37. #include <drm/drm_hashtab.h>
  38. struct drm_device;
  39. struct drm_driver;
  40. struct file;
  41. struct pci_driver;
  42. /*
  43. * Legacy Support for palateontologic DRM drivers
  44. *
  45. * If you add a new driver and it uses any of these functions or structures,
  46. * you're doing it terribly wrong.
  47. */
  48. /**
  49. * DMA buffer.
  50. */
  51. struct drm_buf {
  52. int idx; /**< Index into master buflist */
  53. int total; /**< Buffer size */
  54. int order; /**< log-base-2(total) */
  55. int used; /**< Amount of buffer in use (for DMA) */
  56. unsigned long offset; /**< Byte offset (used internally) */
  57. void *address; /**< Address of buffer */
  58. unsigned long bus_address; /**< Bus address of buffer */
  59. struct drm_buf *next; /**< Kernel-only: used for free list */
  60. __volatile__ int waiting; /**< On kernel DMA queue */
  61. __volatile__ int pending; /**< On hardware DMA queue */
  62. struct drm_file *file_priv; /**< Private of holding file descr */
  63. int context; /**< Kernel queue for this buffer */
  64. int while_locked; /**< Dispatch this buffer while locked */
  65. enum {
  66. DRM_LIST_NONE = 0,
  67. DRM_LIST_FREE = 1,
  68. DRM_LIST_WAIT = 2,
  69. DRM_LIST_PEND = 3,
  70. DRM_LIST_PRIO = 4,
  71. DRM_LIST_RECLAIM = 5
  72. } list; /**< Which list we're on */
  73. int dev_priv_size; /**< Size of buffer private storage */
  74. void *dev_private; /**< Per-buffer private storage */
  75. };
  76. typedef struct drm_dma_handle {
  77. dma_addr_t busaddr;
  78. void *vaddr;
  79. size_t size;
  80. } drm_dma_handle_t;
  81. /**
  82. * Buffer entry. There is one of this for each buffer size order.
  83. */
  84. struct drm_buf_entry {
  85. int buf_size; /**< size */
  86. int buf_count; /**< number of buffers */
  87. struct drm_buf *buflist; /**< buffer list */
  88. int seg_count;
  89. int page_order;
  90. struct drm_dma_handle **seglist;
  91. int low_mark; /**< Low water mark */
  92. int high_mark; /**< High water mark */
  93. };
  94. /**
  95. * DMA data.
  96. */
  97. struct drm_device_dma {
  98. struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  99. int buf_count; /**< total number of buffers */
  100. struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  101. int seg_count;
  102. int page_count; /**< number of pages */
  103. unsigned long *pagelist; /**< page list */
  104. unsigned long byte_count;
  105. enum {
  106. _DRM_DMA_USE_AGP = 0x01,
  107. _DRM_DMA_USE_SG = 0x02,
  108. _DRM_DMA_USE_FB = 0x04,
  109. _DRM_DMA_USE_PCI_RO = 0x08
  110. } flags;
  111. };
  112. /**
  113. * Scatter-gather memory.
  114. */
  115. struct drm_sg_mem {
  116. unsigned long handle;
  117. void *virtual;
  118. int pages;
  119. struct page **pagelist;
  120. dma_addr_t *busaddr;
  121. };
  122. /**
  123. * Kernel side of a mapping
  124. */
  125. struct drm_local_map {
  126. dma_addr_t offset; /**< Requested physical address (0 for SAREA)*/
  127. unsigned long size; /**< Requested physical size (bytes) */
  128. enum drm_map_type type; /**< Type of memory to map */
  129. enum drm_map_flags flags; /**< Flags */
  130. void *handle; /**< User-space: "Handle" to pass to mmap() */
  131. /**< Kernel-space: kernel-virtual address */
  132. int mtrr; /**< MTRR slot used */
  133. };
  134. typedef struct drm_local_map drm_local_map_t;
  135. /**
  136. * Mappings list
  137. */
  138. struct drm_map_list {
  139. struct list_head head; /**< list head */
  140. struct drm_hash_item hash;
  141. struct drm_local_map *map; /**< mapping */
  142. uint64_t user_token;
  143. struct drm_master *master;
  144. };
  145. int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
  146. unsigned int size, enum drm_map_type type,
  147. enum drm_map_flags flags, struct drm_local_map **map_p);
  148. struct drm_local_map *drm_legacy_findmap(struct drm_device *dev, unsigned int token);
  149. void drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
  150. int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
  151. struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
  152. int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
  153. int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
  154. int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
  155. /**
  156. * Test that the hardware lock is held by the caller, returning otherwise.
  157. *
  158. * \param dev DRM device.
  159. * \param filp file pointer of the caller.
  160. */
  161. #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
  162. do { \
  163. if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
  164. _file_priv->master->lock.file_priv != _file_priv) { \
  165. DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
  166. __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  167. _file_priv->master->lock.file_priv, _file_priv); \
  168. return -EINVAL; \
  169. } \
  170. } while (0)
  171. void drm_legacy_idlelock_take(struct drm_lock_data *lock);
  172. void drm_legacy_idlelock_release(struct drm_lock_data *lock);
  173. /* drm_pci.c */
  174. #ifdef CONFIG_PCI
  175. struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev, size_t size,
  176. size_t align);
  177. void drm_pci_free(struct drm_device *dev, struct drm_dma_handle *dmah);
  178. int drm_legacy_pci_init(struct drm_driver *driver, struct pci_driver *pdriver);
  179. void drm_legacy_pci_exit(struct drm_driver *driver, struct pci_driver *pdriver);
  180. #else
  181. static inline struct drm_dma_handle *drm_pci_alloc(struct drm_device *dev,
  182. size_t size, size_t align)
  183. {
  184. return NULL;
  185. }
  186. static inline void drm_pci_free(struct drm_device *dev,
  187. struct drm_dma_handle *dmah)
  188. {
  189. }
  190. static inline int drm_legacy_pci_init(struct drm_driver *driver,
  191. struct pci_driver *pdriver)
  192. {
  193. return -EINVAL;
  194. }
  195. static inline void drm_legacy_pci_exit(struct drm_driver *driver,
  196. struct pci_driver *pdriver)
  197. {
  198. }
  199. #endif
  200. /* drm_memory.c */
  201. void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
  202. void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  203. void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  204. #endif /* __DRM_DRM_LEGACY_H__ */