]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blame - drivers/gpu/drm/amd/amdgpu/soc15_common.h
drm/scheduler: fix inconsistent locking of job_list_lock
[mirror_ubuntu-jammy-kernel.git] / drivers / gpu / drm / amd / amdgpu / soc15_common.h
CommitLineData
8e3153ba
KW
1/*
2 * Copyright 2016 Advanced Micro Devices, Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 */
23
24#ifndef __SOC15_COMMON_H__
25#define __SOC15_COMMON_H__
26
b1bb8c01 27/* Register Access Macros */
cd29253f 28#define SOC15_REG_OFFSET(ip, inst, reg) (adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg)
8e3153ba 29
b1bb8c01 30#define WREG32_FIELD15(ip, idx, reg, field, val) \
b466107e
SL
31 WREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg, \
32 (RREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg) \
33 & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
b1bb8c01
TSD
34
35#define RREG32_SOC15(ip, inst, reg) \
b466107e 36 RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg)
b1bb8c01 37
496828e7 38#define RREG32_SOC15_OFFSET(ip, inst, reg, offset) \
b466107e 39 RREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset)
496828e7 40
b1bb8c01 41#define WREG32_SOC15(ip, inst, reg, value) \
b466107e 42 WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value)
b1bb8c01 43
c708535e 44#define WREG32_SOC15_NO_KIQ(ip, inst, reg, value) \
b466107e 45 WREG32_NO_KIQ((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg), value)
c708535e 46
496828e7 47#define WREG32_SOC15_OFFSET(ip, inst, reg, offset, value) \
b466107e 48 WREG32((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset, value)
496828e7 49
ac06b4cf
RZ
50#define SOC15_WAIT_ON_RREG(ip, inst, reg, expected_value, mask, ret) \
51 do { \
7ab3f021 52 uint32_t old_ = 0; \
ac06b4cf
RZ
53 uint32_t tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \
54 uint32_t loop = adev->usec_timeout; \
a63141e3 55 ret = 0; \
ac06b4cf 56 while ((tmp_ & (mask)) != (expected_value)) { \
7ab3f021
JZ
57 if (old_ != tmp_) { \
58 loop = adev->usec_timeout; \
59 old_ = tmp_; \
60 } else \
61 udelay(1); \
ac06b4cf
RZ
62 tmp_ = RREG32(adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg); \
63 loop--; \
64 if (!loop) { \
7ab3f021 65 DRM_WARN("Register(%d) [%s] failed to reach value 0x%08x != 0x%08x\n", \
81bb773f 66 inst, #reg, (unsigned)expected_value, (unsigned)(tmp_ & (mask))); \
ac06b4cf
RZ
67 ret = -ETIMEDOUT; \
68 break; \
69 } \
70 } \
71 } while (0)
72
4cd4c5c0 73#define AMDGPU_VIRT_SUPPORT_RLC_PRG_REG(a) (amdgpu_sriov_vf((a)) && !amdgpu_sriov_runtime((a)))
6b1ff3dd
TH
74#define WREG32_RLC(reg, value) \
75 do { \
4cd4c5c0 76 if (AMDGPU_VIRT_SUPPORT_RLC_PRG_REG(adev)) { \
6b1ff3dd
TH
77 uint32_t i = 0; \
78 uint32_t retries = 50000; \
79 uint32_t r0 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG0_BASE_IDX] + mmSCRATCH_REG0; \
80 uint32_t r1 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG1; \
81 uint32_t spare_int = adev->reg_offset[GC_HWIP][0][mmRLC_SPARE_INT_BASE_IDX] + mmRLC_SPARE_INT; \
82 WREG32(r0, value); \
83 WREG32(r1, (reg | 0x80000000)); \
84 WREG32(spare_int, 0x1); \
85 for (i = 0; i < retries; i++) { \
86 u32 tmp = RREG32(r1); \
87 if (!(tmp & 0x80000000)) \
88 break; \
89 udelay(10); \
90 } \
91 if (i >= retries) \
92 pr_err("timeout: rlcg program reg:0x%05x failed !\n", reg); \
93 } else { \
94 WREG32(reg, value); \
95 } \
96 } while (0)
97
98#define WREG32_SOC15_RLC_SHADOW(ip, inst, reg, value) \
99 do { \
100 uint32_t target_reg = adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg;\
4cd4c5c0 101 if (AMDGPU_VIRT_SUPPORT_RLC_PRG_REG(adev)) { \
6b1ff3dd
TH
102 uint32_t r2 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG2; \
103 uint32_t r3 = adev->reg_offset[GC_HWIP][0][mmSCRATCH_REG1_BASE_IDX] + mmSCRATCH_REG3; \
104 uint32_t grbm_cntl = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_CNTL_BASE_IDX] + mmGRBM_GFX_CNTL; \
105 uint32_t grbm_idx = adev->reg_offset[GC_HWIP][0][mmGRBM_GFX_INDEX_BASE_IDX] + mmGRBM_GFX_INDEX; \
106 if (target_reg == grbm_cntl) \
107 WREG32(r2, value); \
108 else if (target_reg == grbm_idx) \
109 WREG32(r3, value); \
110 WREG32(target_reg, value); \
111 } else { \
112 WREG32(target_reg, value); \
113 } \
114 } while (0)
115
116#define WREG32_SOC15_RLC(ip, inst, reg, value) \
117 do { \
118 uint32_t target_reg = adev->reg_offset[GC_HWIP][0][reg##_BASE_IDX] + reg;\
119 WREG32_RLC(target_reg, value); \
120 } while (0)
121
122#define WREG32_FIELD15_RLC(ip, idx, reg, field, val) \
123 WREG32_RLC((adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg), \
124 (RREG32(adev->reg_offset[ip##_HWIP][idx][mm##reg##_BASE_IDX] + mm##reg) \
125 & ~REG_FIELD_MASK(reg, field)) | (val) << REG_FIELD_SHIFT(reg, field))
126
127#define WREG32_SOC15_OFFSET_RLC(ip, inst, reg, offset, value) \
128 WREG32_RLC(((adev->reg_offset[ip##_HWIP][inst][reg##_BASE_IDX] + reg) + offset), value)
8e3153ba 129
6b1ff3dd 130#endif