drm_os_linux.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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_UDELAY(d) udelay(d)
  21. /** Read a byte from a MMIO region */
  22. #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
  23. /** Read a word from a MMIO region */
  24. #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
  25. /** Read a dword from a MMIO region */
  26. #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
  27. /** Write a byte into a MMIO region */
  28. #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
  29. /** Write a word into a MMIO region */
  30. #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
  31. /** Write a dword into a MMIO region */
  32. #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
  33. /** Read a qword from a MMIO region - be careful using these unless you really understand them */
  34. #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset))
  35. /** Write a qword into a MMIO region */
  36. #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset))
  37. #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
  38. do { \
  39. DECLARE_WAITQUEUE(entry, current); \
  40. unsigned long end = jiffies + (timeout); \
  41. add_wait_queue(&(queue), &entry); \
  42. \
  43. for (;;) { \
  44. __set_current_state(TASK_INTERRUPTIBLE); \
  45. if (condition) \
  46. break; \
  47. if (time_after_eq(jiffies, end)) { \
  48. ret = -EBUSY; \
  49. break; \
  50. } \
  51. schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
  52. if (signal_pending(current)) { \
  53. ret = -EINTR; \
  54. break; \
  55. } \
  56. } \
  57. __set_current_state(TASK_RUNNING); \
  58. remove_wait_queue(&(queue), &entry); \
  59. } while (0)