drm_os_linux.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /**
  2. * \file drm_os_linux.h
  3. * OS abstraction macros.
  4. */
  5. #include <linux/interrupt.h> /* For task queue support */
  6. #include <linux/sched/signal.h>
  7. #include <linux/delay.h>
  8. #include <linux/io-64-nonatomic-lo-hi.h>
  9. /** Current process ID */
  10. #define DRM_CURRENTPID task_pid_nr(current)
  11. #define DRM_UDELAY(d) udelay(d)
  12. /** Read a byte from a MMIO region */
  13. #define DRM_READ8(map, offset) readb(((void __iomem *)(map)->handle) + (offset))
  14. /** Read a word from a MMIO region */
  15. #define DRM_READ16(map, offset) readw(((void __iomem *)(map)->handle) + (offset))
  16. /** Read a dword from a MMIO region */
  17. #define DRM_READ32(map, offset) readl(((void __iomem *)(map)->handle) + (offset))
  18. /** Write a byte into a MMIO region */
  19. #define DRM_WRITE8(map, offset, val) writeb(val, ((void __iomem *)(map)->handle) + (offset))
  20. /** Write a word into a MMIO region */
  21. #define DRM_WRITE16(map, offset, val) writew(val, ((void __iomem *)(map)->handle) + (offset))
  22. /** Write a dword into a MMIO region */
  23. #define DRM_WRITE32(map, offset, val) writel(val, ((void __iomem *)(map)->handle) + (offset))
  24. /** Read a qword from a MMIO region - be careful using these unless you really understand them */
  25. #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset))
  26. /** Write a qword into a MMIO region */
  27. #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset))
  28. #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
  29. do { \
  30. DECLARE_WAITQUEUE(entry, current); \
  31. unsigned long end = jiffies + (timeout); \
  32. add_wait_queue(&(queue), &entry); \
  33. \
  34. for (;;) { \
  35. __set_current_state(TASK_INTERRUPTIBLE); \
  36. if (condition) \
  37. break; \
  38. if (time_after_eq(jiffies, end)) { \
  39. ret = -EBUSY; \
  40. break; \
  41. } \
  42. schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
  43. if (signal_pending(current)) { \
  44. ret = -EINTR; \
  45. break; \
  46. } \
  47. } \
  48. __set_current_state(TASK_RUNNING); \
  49. remove_wait_queue(&(queue), &entry); \
  50. } while (0)