| .. | .. |
|---|
| 24 | 24 | #ifndef _VIA_DRV_H_ |
|---|
| 25 | 25 | #define _VIA_DRV_H_ |
|---|
| 26 | 26 | |
|---|
| 27 | | -#include <drm/drm_mm.h> |
|---|
| 27 | +#include <linux/irqreturn.h> |
|---|
| 28 | +#include <linux/jiffies.h> |
|---|
| 29 | +#include <linux/sched.h> |
|---|
| 30 | +#include <linux/sched/signal.h> |
|---|
| 31 | +#include <linux/wait.h> |
|---|
| 32 | + |
|---|
| 33 | +#include <drm/drm_ioctl.h> |
|---|
| 28 | 34 | #include <drm/drm_legacy.h> |
|---|
| 35 | +#include <drm/drm_mm.h> |
|---|
| 36 | +#include <drm/via_drm.h> |
|---|
| 29 | 37 | |
|---|
| 30 | 38 | #define DRIVER_AUTHOR "Various" |
|---|
| 31 | 39 | |
|---|
| .. | .. |
|---|
| 113 | 121 | }; |
|---|
| 114 | 122 | |
|---|
| 115 | 123 | /* VIA MMIO register access */ |
|---|
| 116 | | -#define VIA_BASE ((dev_priv->mmio)) |
|---|
| 124 | +static inline u32 via_read(struct drm_via_private *dev_priv, u32 reg) |
|---|
| 125 | +{ |
|---|
| 126 | + return readl((void __iomem *)(dev_priv->mmio->handle + reg)); |
|---|
| 127 | +} |
|---|
| 117 | 128 | |
|---|
| 118 | | -#define VIA_READ(reg) DRM_READ32(VIA_BASE, reg) |
|---|
| 119 | | -#define VIA_WRITE(reg, val) DRM_WRITE32(VIA_BASE, reg, val) |
|---|
| 120 | | -#define VIA_READ8(reg) DRM_READ8(VIA_BASE, reg) |
|---|
| 121 | | -#define VIA_WRITE8(reg, val) DRM_WRITE8(VIA_BASE, reg, val) |
|---|
| 129 | +static inline void via_write(struct drm_via_private *dev_priv, u32 reg, |
|---|
| 130 | + u32 val) |
|---|
| 131 | +{ |
|---|
| 132 | + writel(val, (void __iomem *)(dev_priv->mmio->handle + reg)); |
|---|
| 133 | +} |
|---|
| 134 | + |
|---|
| 135 | +static inline void via_write8(struct drm_via_private *dev_priv, u32 reg, |
|---|
| 136 | + u32 val) |
|---|
| 137 | +{ |
|---|
| 138 | + writeb(val, (void __iomem *)(dev_priv->mmio->handle + reg)); |
|---|
| 139 | +} |
|---|
| 140 | + |
|---|
| 141 | +static inline void via_write8_mask(struct drm_via_private *dev_priv, |
|---|
| 142 | + u32 reg, u32 mask, u32 val) |
|---|
| 143 | +{ |
|---|
| 144 | + u32 tmp; |
|---|
| 145 | + |
|---|
| 146 | + tmp = readb((void __iomem *)(dev_priv->mmio->handle + reg)); |
|---|
| 147 | + tmp = (tmp & ~mask) | (val & mask); |
|---|
| 148 | + writeb(tmp, (void __iomem *)(dev_priv->mmio->handle + reg)); |
|---|
| 149 | +} |
|---|
| 150 | + |
|---|
| 151 | +/* |
|---|
| 152 | + * Poll in a loop waiting for 'contidition' to be true. |
|---|
| 153 | + * Note: A direct replacement with wait_event_interruptible_timeout() |
|---|
| 154 | + * will not work unless driver is updated to emit wake_up() |
|---|
| 155 | + * in relevant places that can impact the 'condition' |
|---|
| 156 | + * |
|---|
| 157 | + * Returns: |
|---|
| 158 | + * ret keeps current value if 'condition' becomes true |
|---|
| 159 | + * ret = -BUSY if timeout happens |
|---|
| 160 | + * ret = -EINTR if a signal interrupted the waiting period |
|---|
| 161 | + */ |
|---|
| 162 | +#define VIA_WAIT_ON( ret, queue, timeout, condition ) \ |
|---|
| 163 | +do { \ |
|---|
| 164 | + DECLARE_WAITQUEUE(entry, current); \ |
|---|
| 165 | + unsigned long end = jiffies + (timeout); \ |
|---|
| 166 | + add_wait_queue(&(queue), &entry); \ |
|---|
| 167 | + \ |
|---|
| 168 | + for (;;) { \ |
|---|
| 169 | + __set_current_state(TASK_INTERRUPTIBLE); \ |
|---|
| 170 | + if (condition) \ |
|---|
| 171 | + break; \ |
|---|
| 172 | + if (time_after_eq(jiffies, end)) { \ |
|---|
| 173 | + ret = -EBUSY; \ |
|---|
| 174 | + break; \ |
|---|
| 175 | + } \ |
|---|
| 176 | + schedule_timeout((HZ/100 > 1) ? HZ/100 : 1); \ |
|---|
| 177 | + if (signal_pending(current)) { \ |
|---|
| 178 | + ret = -EINTR; \ |
|---|
| 179 | + break; \ |
|---|
| 180 | + } \ |
|---|
| 181 | + } \ |
|---|
| 182 | + __set_current_state(TASK_RUNNING); \ |
|---|
| 183 | + remove_wait_queue(&(queue), &entry); \ |
|---|
| 184 | +} while (0) |
|---|
| 122 | 185 | |
|---|
| 123 | 186 | extern const struct drm_ioctl_desc via_ioctls[]; |
|---|
| 124 | 187 | extern int via_max_ioctl; |
|---|