drm_os_linux.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. #ifndef readq
  8. static inline u64 readq(void __iomem *reg)
  9. {
  10. return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32);
  11. }
  12. static inline void writeq(u64 val, void __iomem *reg)
  13. {
  14. writel(val & 0xffffffff, reg);
  15. writel(val >> 32, reg + 0x4UL);
  16. }
  17. #endif
  18. /** Current process ID */
  19. #define DRM_CURRENTPID task_pid_nr(current)
  20. #define DRM_SUSER(p) capable(CAP_SYS_ADMIN)
  21. #define DRM_UDELAY(d) udelay(d)
  22. /** Read a byte from a MMIO region */
  23. #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
  24. /** Read a word from a MMIO region */
  25. #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
  26. /** Read a dword from a MMIO region */
  27. #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
  28. /** Write a byte into a MMIO region */
  29. #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
  30. /** Write a word into a MMIO region */
  31. #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
  32. /** Write a dword into a MMIO region */
  33. #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
  34. /** Read memory barrier */
  35. /** Read a qword from a MMIO region - be careful using these unless you really understand them */
  36. #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset))
  37. /** Write a qword into a MMIO region */
  38. #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset))
  39. #define DRM_READMEMORYBARRIER() rmb()
  40. /** Write memory barrier */
  41. #define DRM_WRITEMEMORYBARRIER() wmb()
  42. /** Read/write memory barrier */
  43. #define DRM_MEMORYBARRIER() mb()
  44. /** IRQ handler arguments and return type and values */
  45. #define DRM_IRQ_ARGS int irq, void *arg
  46. /** AGP types */
  47. #if __OS_HAS_AGP
  48. #define DRM_AGP_MEM struct agp_memory
  49. #define DRM_AGP_KERN struct agp_kern_info
  50. #else
  51. /* define some dummy types for non AGP supporting kernels */
  52. struct no_agp_kern {
  53. unsigned long aper_base;
  54. unsigned long aper_size;
  55. };
  56. #define DRM_AGP_MEM int
  57. #define DRM_AGP_KERN struct no_agp_kern
  58. #endif
  59. #if !(__OS_HAS_MTRR)
  60. static __inline__ int mtrr_add(unsigned long base, unsigned long size,
  61. unsigned int type, char increment)
  62. {
  63. return -ENODEV;
  64. }
  65. static __inline__ int mtrr_del(int reg, unsigned long base, unsigned long size)
  66. {
  67. return -ENODEV;
  68. }
  69. #define MTRR_TYPE_WRCOMB 1
  70. #endif
  71. /** Other copying of data to kernel space */
  72. #define DRM_COPY_FROM_USER(arg1, arg2, arg3) \
  73. copy_from_user(arg1, arg2, arg3)
  74. /** Other copying of data from kernel space */
  75. #define DRM_COPY_TO_USER(arg1, arg2, arg3) \
  76. copy_to_user(arg1, arg2, arg3)
  77. /* Macros for copyfrom user, but checking readability only once */
  78. #define DRM_VERIFYAREA_READ( uaddr, size ) \
  79. (access_ok( VERIFY_READ, uaddr, size ) ? 0 : -EFAULT)
  80. #define DRM_COPY_FROM_USER_UNCHECKED(arg1, arg2, arg3) \
  81. __copy_from_user(arg1, arg2, arg3)
  82. #define DRM_COPY_TO_USER_UNCHECKED(arg1, arg2, arg3) \
  83. __copy_to_user(arg1, arg2, arg3)
  84. #define DRM_GET_USER_UNCHECKED(val, uaddr) \
  85. __get_user(val, uaddr)
  86. #define DRM_HZ HZ
  87. #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
  88. do { \
  89. DECLARE_WAITQUEUE(entry, current); \
  90. unsigned long end = jiffies + (timeout); \
  91. add_wait_queue(&(queue), &entry); \
  92. \
  93. for (;;) { \
  94. __set_current_state(TASK_INTERRUPTIBLE); \
  95. if (condition) \
  96. break; \
  97. if (time_after_eq(jiffies, end)) { \
  98. ret = -EBUSY; \
  99. break; \
  100. } \
  101. schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
  102. if (signal_pending(current)) { \
  103. ret = -EINTR; \
  104. break; \
  105. } \
  106. } \
  107. __set_current_state(TASK_RUNNING); \
  108. remove_wait_queue(&(queue), &entry); \
  109. } while (0)
  110. #define DRM_WAKEUP( queue ) wake_up( queue )
  111. #define DRM_INIT_WAITQUEUE( queue ) init_waitqueue_head( queue )