drm_legacy.h 6.8 KB

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