Bug Summary

File:dev/pci/drm/amd/amdgpu/hdp_v6_0.c
Warning:line 51, column 17
Although the value stored to 'hdp_clk_cntl1' is used in the enclosing expression, the value is never actually read from 'hdp_clk_cntl1'

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple amd64-unknown-openbsd7.4 -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name hdp_v6_0.c -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model static -mframe-pointer=all -relaxed-aliasing -ffp-contract=on -fno-rounding-math -mconstructor-aliases -ffreestanding -mcmodel=kernel -target-cpu x86-64 -target-feature +retpoline-indirect-calls -target-feature +retpoline-indirect-branches -target-feature -sse2 -target-feature -sse -target-feature -3dnow -target-feature -mmx -target-feature +save-args -target-feature +retpoline-external-thunk -disable-red-zone -no-implicit-float -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -nostdsysteminc -nobuiltininc -resource-dir /usr/local/llvm16/lib/clang/16 -I /usr/src/sys -I /usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -I /usr/src/sys/arch -I /usr/src/sys/dev/pci/drm/include -I /usr/src/sys/dev/pci/drm/include/uapi -I /usr/src/sys/dev/pci/drm/amd/include/asic_reg -I /usr/src/sys/dev/pci/drm/amd/include -I /usr/src/sys/dev/pci/drm/amd/amdgpu -I /usr/src/sys/dev/pci/drm/amd/display -I /usr/src/sys/dev/pci/drm/amd/display/include -I /usr/src/sys/dev/pci/drm/amd/display/dc -I /usr/src/sys/dev/pci/drm/amd/display/amdgpu_dm -I /usr/src/sys/dev/pci/drm/amd/pm/inc -I /usr/src/sys/dev/pci/drm/amd/pm/legacy-dpm -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu11 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu12 -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/smu13 -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/inc -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/hwmgr -I /usr/src/sys/dev/pci/drm/amd/pm/powerplay/smumgr -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc -I /usr/src/sys/dev/pci/drm/amd/pm/swsmu/inc/pmfw_if -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc -I /usr/src/sys/dev/pci/drm/amd/display/dc/inc/hw -I /usr/src/sys/dev/pci/drm/amd/display/dc/clk_mgr -I /usr/src/sys/dev/pci/drm/amd/display/modules/inc -I /usr/src/sys/dev/pci/drm/amd/display/modules/hdcp -I /usr/src/sys/dev/pci/drm/amd/display/dmub/inc -I /usr/src/sys/dev/pci/drm/i915 -D DDB -D DIAGNOSTIC -D KTRACE -D ACCOUNTING -D KMEMSTATS -D PTRACE -D POOL_DEBUG -D CRYPTO -D SYSVMSG -D SYSVSEM -D SYSVSHM -D UVM_SWAP_ENCRYPT -D FFS -D FFS2 -D FFS_SOFTUPDATES -D UFS_DIRHASH -D QUOTA -D EXT2FS -D MFS -D NFSCLIENT -D NFSSERVER -D CD9660 -D UDF -D MSDOSFS -D FIFO -D FUSE -D SOCKET_SPLICE -D TCP_ECN -D TCP_SIGNATURE -D INET6 -D IPSEC -D PPP_BSDCOMP -D PPP_DEFLATE -D PIPEX -D MROUTING -D MPLS -D BOOT_CONFIG -D USER_PCICONF -D APERTURE -D MTRR -D NTFS -D SUSPEND -D HIBERNATE -D PCIVERBOSE -D USBVERBOSE -D WSDISPLAY_COMPAT_USL -D WSDISPLAY_COMPAT_RAWKBD -D WSDISPLAY_DEFAULTSCREENS=6 -D X86EMU -D ONEWIREVERBOSE -D MULTIPROCESSOR -D MAXUSERS=80 -D _KERNEL -O2 -Wno-pointer-sign -Wno-address-of-packed-member -Wno-constant-conversion -Wno-unused-but-set-variable -Wno-gnu-folding-constant -fdebug-compilation-dir=/usr/src/sys/arch/amd64/compile/GENERIC.MP/obj -ferror-limit 19 -fwrapv -D_RET_PROTECTOR -ret-protector -fcf-protection=branch -fgnuc-version=4.2.1 -vectorize-loops -vectorize-slp -fno-builtin-malloc -fno-builtin-calloc -fno-builtin-realloc -fno-builtin-valloc -fno-builtin-free -fno-builtin-strdup -fno-builtin-strndup -analyzer-output=html -faddrsig -o /home/ben/Projects/scan/2024-01-11-110808-61670-1 -x c /usr/src/sys/dev/pci/drm/amd/amdgpu/hdp_v6_0.c
1/*
2 * Copyright 2020 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#include "amdgpu.h"
24#include "amdgpu_atombios.h"
25#include "hdp_v6_0.h"
26
27#include "hdp/hdp_6_0_0_offset.h"
28#include "hdp/hdp_6_0_0_sh_mask.h"
29#include <uapi/linux/kfd_ioctl.h>
30
31static void hdp_v6_0_flush_hdp(struct amdgpu_device *adev,
32 struct amdgpu_ring *ring)
33{
34 if (!ring || !ring->funcs->emit_wreg)
35 WREG32_NO_KIQ((adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL) >> 2, 0)amdgpu_device_wreg(adev, ((adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL
) >> 2), (0), (1<<1))
;
36 else
37 amdgpu_ring_emit_wreg(ring, (adev->rmmio_remap.reg_offset + KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL) >> 2, 0)(ring)->funcs->emit_wreg((ring), ((adev->rmmio_remap
.reg_offset + KFD_MMIO_REMAP_HDP_MEM_FLUSH_CNTL) >> 2),
(0))
;
38}
39
40static void hdp_v6_0_update_clock_gating(struct amdgpu_device *adev,
41 bool_Bool enable)
42{
43 uint32_t hdp_clk_cntl, hdp_clk_cntl1;
44 uint32_t hdp_mem_pwr_cntl;
45
46 if (!(adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS(1ULL << 15) |
47 AMD_CG_SUPPORT_HDP_DS(1ULL << 25) |
48 AMD_CG_SUPPORT_HDP_SD(1ULL << 26))))
49 return;
50
51 hdp_clk_cntl = hdp_clk_cntl1 = RREG32_SOC15(HDP, 0,regHDP_CLK_CNTL)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_rreg(adev, adev->reg_offset[HDP_HWIP][0][
0] + 0x00d8, 0, HDP_HWIP) : amdgpu_device_rreg(adev, (adev->
reg_offset[HDP_HWIP][0][0] + 0x00d8), 0))
;
Although the value stored to 'hdp_clk_cntl1' is used in the enclosing expression, the value is never actually read from 'hdp_clk_cntl1'
52 hdp_mem_pwr_cntl = RREG32_SOC15(HDP, 0, regHDP_MEM_POWER_CTRL)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_rreg(adev, adev->reg_offset[HDP_HWIP][0][
0] + 0x00d4, 0, HDP_HWIP) : amdgpu_device_rreg(adev, (adev->
reg_offset[HDP_HWIP][0][0] + 0x00d4), 0))
;
53
54 /* Before doing clock/power mode switch,
55 * forced on IPH & RC clock */
56 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,(((hdp_clk_cntl) & ~0x08000000L) | (0x08000000L & ((1
) << 0x1b)))
57 RC_MEM_CLK_SOFT_OVERRIDE, 1)(((hdp_clk_cntl) & ~0x08000000L) | (0x08000000L & ((1
) << 0x1b)))
;
58 WREG32_SOC15(HDP, 0, regHDP_CLK_CNTL, hdp_clk_cntl)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_wreg(adev, (adev->reg_offset[HDP_HWIP][0]
[0] + 0x00d8), hdp_clk_cntl, 0, HDP_HWIP) : amdgpu_device_wreg
(adev, ((adev->reg_offset[HDP_HWIP][0][0] + 0x00d8)), (hdp_clk_cntl
), 0))
;
59
60 /* disable clock and power gating before any changing */
61 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000001L) | (0x00000001L &
((0) << 0x0)))
62 ATOMIC_MEM_POWER_CTRL_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00000001L) | (0x00000001L &
((0) << 0x0)))
;
63 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000002L) | (0x00000002L &
((0) << 0x1)))
64 ATOMIC_MEM_POWER_LS_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00000002L) | (0x00000002L &
((0) << 0x1)))
;
65 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000004L) | (0x00000004L &
((0) << 0x2)))
66 ATOMIC_MEM_POWER_DS_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00000004L) | (0x00000004L &
((0) << 0x2)))
;
67 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000008L) | (0x00000008L &
((0) << 0x3)))
68 ATOMIC_MEM_POWER_SD_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00000008L) | (0x00000008L &
((0) << 0x3)))
;
69 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00010000L) | (0x00010000L &
((0) << 0x10)))
70 RC_MEM_POWER_CTRL_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00010000L) | (0x00010000L &
((0) << 0x10)))
;
71 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00020000L) | (0x00020000L &
((0) << 0x11)))
72 RC_MEM_POWER_LS_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00020000L) | (0x00020000L &
((0) << 0x11)))
;
73 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00040000L) | (0x00040000L &
((0) << 0x12)))
74 RC_MEM_POWER_DS_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00040000L) | (0x00040000L &
((0) << 0x12)))
;
75 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00080000L) | (0x00080000L &
((0) << 0x13)))
76 RC_MEM_POWER_SD_EN, 0)(((hdp_mem_pwr_cntl) & ~0x00080000L) | (0x00080000L &
((0) << 0x13)))
;
77 WREG32_SOC15(HDP, 0, regHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_wreg(adev, (adev->reg_offset[HDP_HWIP][0]
[0] + 0x00d4), hdp_mem_pwr_cntl, 0, HDP_HWIP) : amdgpu_device_wreg
(adev, ((adev->reg_offset[HDP_HWIP][0][0] + 0x00d4)), (hdp_mem_pwr_cntl
), 0))
;
78
79 /* Already disabled above. The actions below are for "enabled" only */
80 if (enable) {
81 /* only one clock gating mode (LS/DS/SD) can be enabled */
82 if (adev->cg_flags & AMD_CG_SUPPORT_HDP_SD(1ULL << 26)) {
83 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,(((hdp_mem_pwr_cntl) & ~0x00000008L) | (0x00000008L &
((1) << 0x3)))
84 HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000008L) | (0x00000008L &
((1) << 0x3)))
85 ATOMIC_MEM_POWER_SD_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00000008L) | (0x00000008L &
((1) << 0x3)))
;
86 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,(((hdp_mem_pwr_cntl) & ~0x00080000L) | (0x00080000L &
((1) << 0x13)))
87 HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00080000L) | (0x00080000L &
((1) << 0x13)))
88 RC_MEM_POWER_SD_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00080000L) | (0x00080000L &
((1) << 0x13)))
;
89 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_LS(1ULL << 15)) {
90 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,(((hdp_mem_pwr_cntl) & ~0x00000002L) | (0x00000002L &
((1) << 0x1)))
91 HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000002L) | (0x00000002L &
((1) << 0x1)))
92 ATOMIC_MEM_POWER_LS_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00000002L) | (0x00000002L &
((1) << 0x1)))
;
93 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,(((hdp_mem_pwr_cntl) & ~0x00020000L) | (0x00020000L &
((1) << 0x11)))
94 HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00020000L) | (0x00020000L &
((1) << 0x11)))
95 RC_MEM_POWER_LS_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00020000L) | (0x00020000L &
((1) << 0x11)))
;
96 } else if (adev->cg_flags & AMD_CG_SUPPORT_HDP_DS(1ULL << 25)) {
97 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,(((hdp_mem_pwr_cntl) & ~0x00000004L) | (0x00000004L &
((1) << 0x2)))
98 HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000004L) | (0x00000004L &
((1) << 0x2)))
99 ATOMIC_MEM_POWER_DS_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00000004L) | (0x00000004L &
((1) << 0x2)))
;
100 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl,(((hdp_mem_pwr_cntl) & ~0x00040000L) | (0x00040000L &
((1) << 0x12)))
101 HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00040000L) | (0x00040000L &
((1) << 0x12)))
102 RC_MEM_POWER_DS_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00040000L) | (0x00040000L &
((1) << 0x12)))
;
103 }
104
105 /* confirmed that IPH_MEM_POWER_CTRL_EN and RC_MEM_POWER_CTRL_EN have to
106 * be set for SRAM LS/DS/SD */
107 if (adev->cg_flags & (AMD_CG_SUPPORT_HDP_LS(1ULL << 15) | AMD_CG_SUPPORT_HDP_DS(1ULL << 25) |
108 AMD_CG_SUPPORT_HDP_SD(1ULL << 26))) {
109 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00000001L) | (0x00000001L &
((1) << 0x0)))
110 ATOMIC_MEM_POWER_CTRL_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00000001L) | (0x00000001L &
((1) << 0x0)))
;
111 hdp_mem_pwr_cntl = REG_SET_FIELD(hdp_mem_pwr_cntl, HDP_MEM_POWER_CTRL,(((hdp_mem_pwr_cntl) & ~0x00010000L) | (0x00010000L &
((1) << 0x10)))
112 RC_MEM_POWER_CTRL_EN, 1)(((hdp_mem_pwr_cntl) & ~0x00010000L) | (0x00010000L &
((1) << 0x10)))
;
113 WREG32_SOC15(HDP, 0, regHDP_MEM_POWER_CTRL, hdp_mem_pwr_cntl)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_wreg(adev, (adev->reg_offset[HDP_HWIP][0]
[0] + 0x00d4), hdp_mem_pwr_cntl, 0, HDP_HWIP) : amdgpu_device_wreg
(adev, ((adev->reg_offset[HDP_HWIP][0][0] + 0x00d4)), (hdp_mem_pwr_cntl
), 0))
;
114 }
115 }
116
117 /* disable IPH & RC clock override after clock/power mode changing */
118 hdp_clk_cntl = REG_SET_FIELD(hdp_clk_cntl, HDP_CLK_CNTL,(((hdp_clk_cntl) & ~0x08000000L) | (0x08000000L & ((0
) << 0x1b)))
119 RC_MEM_CLK_SOFT_OVERRIDE, 0)(((hdp_clk_cntl) & ~0x08000000L) | (0x08000000L & ((0
) << 0x1b)))
;
120 WREG32_SOC15(HDP, 0, regHDP_CLK_CNTL, hdp_clk_cntl)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_wreg(adev, (adev->reg_offset[HDP_HWIP][0]
[0] + 0x00d8), hdp_clk_cntl, 0, HDP_HWIP) : amdgpu_device_wreg
(adev, ((adev->reg_offset[HDP_HWIP][0][0] + 0x00d8)), (hdp_clk_cntl
), 0))
;
121}
122
123static void hdp_v6_0_get_clockgating_state(struct amdgpu_device *adev,
124 u64 *flags)
125{
126 uint32_t tmp;
127
128 /* AMD_CG_SUPPORT_HDP_LS/DS/SD */
129 tmp = RREG32_SOC15(HDP, 0, regHDP_MEM_POWER_CTRL)((((adev)->virt.caps & (1 << 2)) && adev
->gfx.rlc.funcs && adev->gfx.rlc.rlcg_reg_access_supported
) ? amdgpu_sriov_rreg(adev, adev->reg_offset[HDP_HWIP][0][
0] + 0x00d4, 0, HDP_HWIP) : amdgpu_device_rreg(adev, (adev->
reg_offset[HDP_HWIP][0][0] + 0x00d4), 0))
;
130 if (tmp & HDP_MEM_POWER_CTRL__ATOMIC_MEM_POWER_LS_EN_MASK0x00000002L)
131 *flags |= AMD_CG_SUPPORT_HDP_LS(1ULL << 15);
132 else if (tmp & HDP_MEM_POWER_CTRL__ATOMIC_MEM_POWER_DS_EN_MASK0x00000004L)
133 *flags |= AMD_CG_SUPPORT_HDP_DS(1ULL << 25);
134 else if (tmp & HDP_MEM_POWER_CTRL__ATOMIC_MEM_POWER_SD_EN_MASK0x00000008L)
135 *flags |= AMD_CG_SUPPORT_HDP_SD(1ULL << 26);
136}
137
138const struct amdgpu_hdp_funcs hdp_v6_0_funcs = {
139 .flush_hdp = hdp_v6_0_flush_hdp,
140 .update_clock_gating = hdp_v6_0_update_clock_gating,
141 .get_clock_gating_state = hdp_v6_0_get_clockgating_state,
142};