drm_os_linux.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /**
  2. * \file drm_os_linux.h
  3. * OS abstraction macros.
  4. */
  5. #include <linux/interrupt.h> /* For task queue support */
  6. #include <linux/delay.h>
  7. /** File pointer type */
  8. #define DRMFILE struct file *
  9. /** Ioctl arguments */
  10. #define DRM_IOCTL_ARGS struct inode *inode, struct file *filp, unsigned int cmd, unsigned long data
  11. #define DRM_ERR(d) -(d)
  12. /** Current process ID */
  13. #define DRM_CURRENTPID current->pid
  14. #define DRM_UDELAY(d) udelay(d)
  15. /** Read a byte from a MMIO region */
  16. #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
  17. /** Read a word from a MMIO region */
  18. #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
  19. /** Read a dword from a MMIO region */
  20. #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
  21. /** Write a byte into a MMIO region */
  22. #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
  23. /** Write a word into a MMIO region */
  24. #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
  25. /** Write a dword into a MMIO region */
  26. #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
  27. /** Read memory barrier */
  28. #define DRM_READMEMORYBARRIER() rmb()
  29. /** Write memory barrier */
  30. #define DRM_WRITEMEMORYBARRIER() wmb()
  31. /** Read/write memory barrier */
  32. #define DRM_MEMORYBARRIER() mb()
  33. /** DRM device local declaration */
  34. #define DRM_DEVICE drm_file_t *priv = filp->private_data; \
  35. drm_device_t *dev = priv->head->dev
  36. /** IRQ handler arguments and return type and values */
  37. #define DRM_IRQ_ARGS int irq, void *arg, struct pt_regs *regs
  38. /** AGP types */
  39. #if __OS_HAS_AGP
  40. #define DRM_AGP_MEM struct agp_memory
  41. #define DRM_AGP_KERN struct agp_kern_info
  42. #else
  43. /* define some dummy types for non AGP supporting kernels */
  44. struct no_agp_kern {
  45. unsigned long aper_base;
  46. unsigned long aper_size;
  47. };
  48. #define DRM_AGP_MEM int
  49. #define DRM_AGP_KERN struct no_agp_kern
  50. #endif
  51. #if !(__OS_HAS_MTRR)
  52. static __inline__ int mtrr_add(unsigned long base, unsigned long size,
  53. unsigned int type, char increment)
  54. {
  55. return -ENODEV;
  56. }
  57. static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
  58. {
  59. return -ENODEV;
  60. }
  61. #define MTRR_TYPE_WRCOMB 1
  62. #endif
  63. /** Task queue handler arguments */
  64. #define DRM_TASKQUEUE_ARGS void *arg
  65. /** For data going into the kernel through the ioctl argument */
  66. #define DRM_COPY_FROM_USER_IOCTL(arg1, arg2, arg3) \
  67. if ( copy_from_user(&arg1, arg2, arg3) ) \
  68. return -EFAULT
  69. /** For data going from the kernel through the ioctl argument */
  70. #define DRM_COPY_TO_USER_IOCTL(arg1, arg2, arg3) \
  71. if ( copy_to_user(arg1, &arg2, arg3) ) \
  72. return -EFAULT
  73. /** Other copying of data to kernel space */
  74. #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
  75. copy_from_user(arg1, arg2, arg3)
  76. /** Other copying of data from kernel space */
  77. #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
  78. copy_to_user(arg1, arg2, arg3)
  79. /* Macros for copyfrom user, but checking readability only once */
  80. #define DRM_VERIFYAREA_READ( uaddr, size ) \
  81. (access_ok( VERIFY_READ, uaddr, size ) ? 0 : -EFAULT)
  82. #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
  83. __copy_from_user(arg1, arg2, arg3)
  84. #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
  85. __copy_to_user(arg1, arg2, arg3)
  86. #define DRM_GET_USER_UNCHECKED(val, uaddr) \
  87. __get_user(val, uaddr)
  88. #define DRM_GET_PRIV_WITH_RETURN(_priv, _filp) _priv = _filp->private_data
  89. /**
  90. * Get the pointer to the SAREA.
  91. *
  92. * Searches the SAREA on the mapping lists and points drm_device::sarea to it.
  93. */
  94. #define DRM_GETSAREA() \
  95. do { \
  96. drm_map_list_t *entry; \
  97. list_for_each_entry( entry, &dev->maplist->head, head ) { \
  98. if ( entry->map && \
  99. entry->map->type == _DRM_SHM && \
  100. (entry->map->flags & _DRM_CONTAINS_LOCK) ) { \
  101. dev_priv->sarea = entry->map; \
  102. break; \
  103. } \
  104. } \
  105. } while (0)
  106. #define DRM_HZ HZ
  107. #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
  108. do { \
  109. DECLARE_WAITQUEUE(entry, current); \
  110. unsigned long end = jiffies + (timeout); \
  111. add_wait_queue(&(queue), &entry); \
  112. \
  113. for (;;) { \
  114. __set_current_state(TASK_INTERRUPTIBLE); \
  115. if (condition) \
  116. break; \
  117. if (time_after_eq(jiffies, end)) { \
  118. ret = -EBUSY; \
  119. break; \
  120. } \
  121. schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
  122. if (signal_pending(current)) { \
  123. ret = -EINTR; \
  124. break; \
  125. } \
  126. } \
  127. __set_current_state(TASK_RUNNING); \
  128. remove_wait_queue(&(queue), &entry); \
  129. } while (0)
  130. #define DRM_WAKEUP( queue ) wake_up_interruptible( queue )
  131. #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )