drm_os_linux.h 2.0 KB

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