drm/amdgpu: Add SOC15_WAIT_ON_RREG macro define
authorRex Zhu <Rex.Zhu@amd.com>
Thu, 17 May 2018 07:58:53 +0000 (15:58 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Thu, 24 May 2018 05:18:02 +0000 (00:18 -0500)
Add new macro to wait on a register field to be a specific
value.

Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Rex Zhu <Rex.Zhu@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/soc15_common.h

index def8650..0942f49 100644 (file)
 #define WREG32_SOC15_OFFSET(ip, inst, reg, offset, value) \
        WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value)
 
+#define SOC15_WAIT_ON_RREG(ip, inst, reg, expected_value, mask, ret) \
+       do {                                                    \
+               uint32_t tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \
+               uint32_t loop = adev->usec_timeout;             \
+               while ((tmp_ & (mask)) != (expected_value)) {   \
+                       udelay(2);                              \
+                       tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \
+                       loop--;                                 \
+                       if (!loop) {                            \
+                               ret = -ETIMEDOUT;               \
+                               break;                          \
+                       }                                       \
+               }                                               \
+       } while (0)
+
 #endif