drm_os_linux.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. #ifndef readq
  9. static inline u64 readq(void __iomem *reg)
  10. {
  11. return ((u64) readl(reg)) | (((u64) readl(reg + 4UL)) << 32);
  12. }
  13. static inline void writeq(u64 val, void __iomem *reg)
  14. {
  15. writel(val & 0xffffffff, reg);
  16. writel(val >> 32, reg + 0x4UL);
  17. }
  18. #endif
  19. /** Current process ID */
  20. #define DRM_CURRENTPID task_pid_nr(current)
  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 a qword from a MMIO region - be careful using these unless you really understand them */
  35. #define DRM_READ64(map, offset) readq(((void __iomem *)(map)->handle) + (offset))
  36. /** Write a qword into a MMIO region */
  37. #define DRM_WRITE64(map, offset, val) writeq(val, ((void __iomem *)(map)->handle) + (offset))
  38. #define DRM_WAIT_ON( ret, queue, timeout, condition ) \
  39. do { \
  40. DECLARE_WAITQUEUE(entry, current); \
  41. unsigned long end = jiffies + (timeout); \
  42. add_wait_queue(&(queue), &entry); \
  43. \
  44. for (;;) { \
  45. __set_current_state(TASK_INTERRUPTIBLE); \
  46. if (condition) \
  47. break; \
  48. if (time_after_eq(jiffies, end)) { \
  49. ret = -EBUSY; \
  50. break; \
  51. } \
  52. schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \
  53. if (signal_pending(current)) { \
  54. ret = -EINTR; \
  55. break; \
  56. } \
  57. } \
  58. __set_current_state(TASK_RUNNING); \
  59. remove_wait_queue(&(queue), &entry); \
  60. } while (0)