drm_legacy.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. /*
  36. * Legacy Support for palateontologic DRM drivers
  37. *
  38. * If you add a new driver and it uses any of these functions or structures,
  39. * you're doing it terribly wrong.
  40. */
  41. /**
  42. * DMA buffer.
  43. */
  44. struct drm_buf {
  45. int idx; /**< Index into master buflist */
  46. int total; /**< Buffer size */
  47. int order; /**< log-base-2(total) */
  48. int used; /**< Amount of buffer in use (for DMA) */
  49. unsigned long offset; /**< Byte offset (used internally) */
  50. void *address; /**< Address of buffer */
  51. unsigned long bus_address; /**< Bus address of buffer */
  52. struct drm_buf *next; /**< Kernel-only: used for free list */
  53. __volatile__ int waiting; /**< On kernel DMA queue */
  54. __volatile__ int pending; /**< On hardware DMA queue */
  55. struct drm_file *file_priv; /**< Private of holding file descr */
  56. int context; /**< Kernel queue for this buffer */
  57. int while_locked; /**< Dispatch this buffer while locked */
  58. enum {
  59. DRM_LIST_NONE = 0,
  60. DRM_LIST_FREE = 1,
  61. DRM_LIST_WAIT = 2,
  62. DRM_LIST_PEND = 3,
  63. DRM_LIST_PRIO = 4,
  64. DRM_LIST_RECLAIM = 5
  65. } list; /**< Which list we're on */
  66. int dev_priv_size; /**< Size of buffer private storage */
  67. void *dev_private; /**< Per-buffer private storage */
  68. };
  69. typedef struct drm_dma_handle {
  70. dma_addr_t busaddr;
  71. void *vaddr;
  72. size_t size;
  73. } drm_dma_handle_t;
  74. /**
  75. * Buffer entry. There is one of this for each buffer size order.
  76. */
  77. struct drm_buf_entry {
  78. int buf_size; /**< size */
  79. int buf_count; /**< number of buffers */
  80. struct drm_buf *buflist; /**< buffer list */
  81. int seg_count;
  82. int page_order;
  83. struct drm_dma_handle **seglist;
  84. int low_mark; /**< Low water mark */
  85. int high_mark; /**< High water mark */
  86. };
  87. /**
  88. * DMA data.
  89. */
  90. struct drm_device_dma {
  91. struct drm_buf_entry bufs[DRM_MAX_ORDER + 1]; /**< buffers, grouped by their size order */
  92. int buf_count; /**< total number of buffers */
  93. struct drm_buf **buflist; /**< Vector of pointers into drm_device_dma::bufs */
  94. int seg_count;
  95. int page_count; /**< number of pages */
  96. unsigned long *pagelist; /**< page list */
  97. unsigned long byte_count;
  98. enum {
  99. _DRM_DMA_USE_AGP = 0x01,
  100. _DRM_DMA_USE_SG = 0x02,
  101. _DRM_DMA_USE_FB = 0x04,
  102. _DRM_DMA_USE_PCI_RO = 0x08
  103. } flags;
  104. };
  105. /**
  106. * Scatter-gather memory.
  107. */
  108. struct drm_sg_mem {
  109. unsigned long handle;
  110. void *virtual;
  111. int pages;
  112. struct page **pagelist;
  113. dma_addr_t *busaddr;
  114. };
  115. /**
  116. * Kernel side of a mapping
  117. */
  118. struct drm_local_map {
  119. resource_size_t offset; /**< Requested physical address (0 for SAREA)*/
  120. unsigned long size; /**< Requested physical size (bytes) */
  121. enum drm_map_type type; /**< Type of memory to map */
  122. enum drm_map_flags flags; /**< Flags */
  123. void *handle; /**< User-space: "Handle" to pass to mmap() */
  124. /**< Kernel-space: kernel-virtual address */
  125. int mtrr; /**< MTRR slot used */
  126. };
  127. typedef struct drm_local_map drm_local_map_t;
  128. /**
  129. * Mappings list
  130. */
  131. struct drm_map_list {
  132. struct list_head head; /**< list head */
  133. struct drm_hash_item hash;
  134. struct drm_local_map *map; /**< mapping */
  135. uint64_t user_token;
  136. struct drm_master *master;
  137. };
  138. int drm_legacy_addmap(struct drm_device *d, resource_size_t offset,
  139. unsigned int size, enum drm_map_type type,
  140. enum drm_map_flags flags, struct drm_local_map **map_p);
  141. int drm_legacy_rmmap(struct drm_device *d, struct drm_local_map *map);
  142. int drm_legacy_rmmap_locked(struct drm_device *d, struct drm_local_map *map);
  143. struct drm_local_map *drm_legacy_getsarea(struct drm_device *dev);
  144. int drm_legacy_mmap(struct file *filp, struct vm_area_struct *vma);
  145. int drm_legacy_addbufs_agp(struct drm_device *d, struct drm_buf_desc *req);
  146. int drm_legacy_addbufs_pci(struct drm_device *d, struct drm_buf_desc *req);
  147. /**
  148. * Test that the hardware lock is held by the caller, returning otherwise.
  149. *
  150. * \param dev DRM device.
  151. * \param filp file pointer of the caller.
  152. */
  153. #define LOCK_TEST_WITH_RETURN( dev, _file_priv ) \
  154. do { \
  155. if (!_DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock) || \
  156. _file_priv->master->lock.file_priv != _file_priv) { \
  157. DRM_ERROR( "%s called without lock held, held %d owner %p %p\n",\
  158. __func__, _DRM_LOCK_IS_HELD(_file_priv->master->lock.hw_lock->lock),\
  159. _file_priv->master->lock.file_priv, _file_priv); \
  160. return -EINVAL; \
  161. } \
  162. } while (0)
  163. void drm_legacy_idlelock_take(struct drm_lock_data *lock);
  164. void drm_legacy_idlelock_release(struct drm_lock_data *lock);
  165. /* drm_pci.c dma alloc wrappers */
  166. void __drm_legacy_pci_free(struct drm_device *dev, drm_dma_handle_t * dmah);
  167. /* drm_memory.c */
  168. void drm_legacy_ioremap(struct drm_local_map *map, struct drm_device *dev);
  169. void drm_legacy_ioremap_wc(struct drm_local_map *map, struct drm_device *dev);
  170. void drm_legacy_ioremapfree(struct drm_local_map *map, struct drm_device *dev);
  171. static __inline__ struct drm_local_map *drm_legacy_findmap(struct drm_device *dev,
  172. unsigned int token)
  173. {
  174. struct drm_map_list *_entry;
  175. list_for_each_entry(_entry, &dev->maplist, head)
  176. if (_entry->user_token == token)
  177. return _entry->map;
  178. return NULL;
  179. }
  180. #endif /* __DRM_DRM_LEGACY_H__ */