drm_os_linux.h 4.7 KB

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