Skip to content

Commit 03c5aa4

Browse files
committed
gpu: add Exynos9820 GPU table update helper
Add build.sh --gpu-max to rebuild DVFS/PMQoS tables from forOC data. Make gpu_clock sysfs writable and restore the full OC table entries.
1 parent 0712603 commit 03c5aa4

4 files changed

Lines changed: 180 additions & 29 deletions

File tree

arch/arm64/boot/dts/exynos/exynos9820-mali_tables.dtsi

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
* This file is included inside the Mali node/overlay.
55
*/
66

7-
gpu_dvfs_table_size = <12 8>; /*<row col>*/
7+
gpu_dvfs_table_size = <16 8>; /*<row col>*/
88
/* 8 columns freq down up stay mif little middle big */
99
gpu_dvfs_table = <
10-
/* 910000 78 100 9 2093000 1456000 0 1820000 */
11-
/* 858000 78 100 9 2093000 1456000 0 1820000 */
12-
/* 806000 78 100 9 2093000 1456000 0 1820000 */
13-
/* 754000 70 90 9 2093000 1456000 0 1820000*/
14-
702000 72 90 9 2093000 1456000 0 1820000
15-
676000 74 92 5 2093000 1456000 0 2080000
16-
650000 74 92 5 2093000 1456000 0 2080000
17-
598000 75 92 5 2093000 1456000 0 2080000
18-
572000 75 92 5 1794000 0 0 0
19-
433000 76 90 2 1352000 0 0 0
20-
377000 78 90 2 1352000 0 0 0
21-
325000 80 88 2 1014000 0 0 0
22-
260000 80 88 2 676000 0 0 0
23-
200000 82 85 2 676000 0 0 0
24-
156000 82 85 2 676000 0 0 0
25-
100000 0 85 1 676000 0 0 0 >;
10+
910000 75 95 8 2093000 1456000 0 1820000
11+
858000 72 92 8 2093000 1456000 0 1820000
12+
806000 70 90 8 2093000 1456000 0 1820000
13+
754000 68 88 7 2093000 1456000 0 1820000
14+
702000 66 86 7 2093000 1456000 0 1820000
15+
676000 64 84 6 2093000 1456000 0 2080000
16+
650000 62 82 6 2093000 1456000 0 2080000
17+
598000 60 80 5 2093000 1456000 0 2080000
18+
572000 58 78 5 1794000 0 0 0
19+
433000 50 70 3 1352000 0 0 0
20+
377000 48 68 3 1352000 0 0 0
21+
325000 46 66 3 1014000 0 0 0
22+
260000 42 62 2 676000 0 0 0
23+
200000 38 58 2 676000 0 0 0
24+
156000 34 54 2 676000 0 0 0
25+
100000 30 50 1 676000 0 0 0 >;
2626

27-
gpu_cl_pmqos_table_size = <12 5>;
27+
gpu_cl_pmqos_table_size = <16 5>;
2828
gpu_cl_pmqos_table = <
29-
/* 910000 2093000 1456000 0 1820000 */
30-
/* 858000 2093000 1456000 0 1820000 */
31-
/* 806000 2093000 1456000 0 1820000 */
32-
/*754000 2093000 1456000 0 1820000*/
29+
910000 2093000 1456000 0 1820000
30+
858000 2093000 1456000 0 1820000
31+
806000 2093000 1456000 0 1820000
32+
754000 2093000 1456000 0 1820000
3333
702000 2093000 1456000 0 1820000
3434
676000 2093000 1456000 0 2080000
3535
650000 2093000 1456000 0 2080000
@@ -43,6 +43,6 @@ gpu_cl_pmqos_table = <
4343
156000 676000 0 0 0
4444
100000 676000 0 0 0 >;
4545

46-
gpu_max_clock = <702000>;
47-
gpu_max_clock_limit = <702000>;
46+
gpu_max_clock = <910000>;
47+
gpu_max_clock_limit = <910000>;
4848
gpu_min_clock = <100000>;

build.sh

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,146 @@ Options:
1717
-m, --model [value] Specify the model code of the phone
1818
-k, --ksu [Y/n] Include KernelSU
1919
-r, --recovery [y/N] Compile kernel for an Android Recovery
20+
-g, --gpu-max [value] Set GPU max MHz (ex: 806) using forOC tables
2021
EOF
2122
}
2223

24+
apply_gpu_tables()
25+
{
26+
local max_khz="$1"
27+
local src_dtsi="$PWD/forOC/exynos9820-mali_tables.dtsi"
28+
local dst_dtsi="$PWD/arch/arm64/boot/dts/exynos/exynos9820-mali_tables.dtsi"
29+
local src_cal="$PWD/forOC/g3d_dvfs_table.h"
30+
local dst_cal="$PWD/drivers/soc/samsung/cal-if/g3d_dvfs_table.h"
31+
32+
if [ ! -f "$src_dtsi" ] || [ ! -f "$src_cal" ]; then
33+
echo "GPU table sources not found under forOC; skipping GPU table update."
34+
return 1
35+
fi
36+
37+
if ! command -v python3 >/dev/null 2>&1; then
38+
echo "python3 not found; cannot update GPU tables."
39+
return 1
40+
fi
41+
42+
python3 - "$max_khz" "$src_dtsi" "$dst_dtsi" "$src_cal" "$dst_cal" << 'PY'
43+
import re
44+
import sys
45+
from pathlib import Path
46+
47+
max_khz = int(sys.argv[1])
48+
src_dtsi = Path(sys.argv[2])
49+
dst_dtsi = Path(sys.argv[3])
50+
src_cal = Path(sys.argv[4])
51+
dst_cal = Path(sys.argv[5])
52+
53+
def parse_table(lines, key):
54+
start = next(i for i, l in enumerate(lines) if key in l)
55+
end = next(i for i in range(start + 1, len(lines)) if ">;" in lines[i])
56+
entries = []
57+
indent = None
58+
for line in lines[start + 1:end + 1]:
59+
stripped = line.strip()
60+
if not stripped or stripped.startswith("/*"):
61+
continue
62+
cleaned = re.sub(r">;\s*$", "", stripped)
63+
cleaned = re.sub(r">\s*$", "", cleaned)
64+
parts = cleaned.split()
65+
if not parts or not parts[0].isdigit():
66+
continue
67+
freq = int(parts[0])
68+
if indent is None:
69+
indent = line[:len(line) - len(line.lstrip())]
70+
entries.append((freq, cleaned))
71+
if indent is None:
72+
indent = "\t"
73+
return start, end, entries, indent
74+
75+
def update_size_line(line, row, cols):
76+
return re.sub(r"<\s*\d+\s+%d\s*>" % cols, f"<{row} {cols}>", line)
77+
78+
def update_clock_line(line, value):
79+
return re.sub(r"<\s*\d+\s*>", f"<{value}>", line)
80+
81+
def write_dtsi():
82+
lines = src_dtsi.read_text().splitlines(True)
83+
start, end, entries, indent = parse_table(lines, "gpu_dvfs_table = <")
84+
filtered = [e for e in entries if e[0] <= max_khz]
85+
if not any(e[0] == max_khz for e in filtered):
86+
raise SystemExit(f"GPU max {max_khz} not found in DVFS table")
87+
dvfs_block = []
88+
for idx, (_, cleaned) in enumerate(filtered):
89+
suffix = " >;\n" if idx == len(filtered) - 1 else "\n"
90+
dvfs_block.append(f"{indent}{cleaned}{suffix}")
91+
lines[start + 1:end + 1] = dvfs_block
92+
93+
start, end, entries, indent = parse_table(lines, "gpu_cl_pmqos_table = <")
94+
filtered_cl = [e for e in entries if e[0] <= max_khz]
95+
if not any(e[0] == max_khz for e in filtered_cl):
96+
raise SystemExit(f"GPU max {max_khz} not found in PMQoS table")
97+
cl_block = []
98+
for idx, (_, cleaned) in enumerate(filtered_cl):
99+
suffix = " >;\n" if idx == len(filtered_cl) - 1 else "\n"
100+
cl_block.append(f"{indent}{cleaned}{suffix}")
101+
lines[start + 1:end + 1] = cl_block
102+
103+
for i, line in enumerate(lines):
104+
if line.strip().startswith("gpu_dvfs_table_size"):
105+
lines[i] = update_size_line(line, len(filtered), 8)
106+
elif line.strip().startswith("gpu_cl_pmqos_table_size"):
107+
lines[i] = update_size_line(line, len(filtered_cl), 5)
108+
elif line.strip().startswith("gpu_max_clock_limit"):
109+
lines[i] = update_clock_line(line, max_khz)
110+
elif line.strip().startswith("gpu_max_clock"):
111+
lines[i] = update_clock_line(line, max_khz)
112+
113+
dst_dtsi.write_text("".join(lines))
114+
115+
def write_cal():
116+
lines = src_cal.read_text().splitlines(True)
117+
start = next(i for i, l in enumerate(lines)
118+
if "G3D_DVFS_TABLE_ENTRY_LIST" in l)
119+
i = start + 1
120+
entries = []
121+
indent = None
122+
while i < len(lines):
123+
line = lines[i]
124+
if line.strip().startswith("#endif") or not line.strip():
125+
break
126+
m = re.search(r"\bX\((\d+),", line)
127+
if m:
128+
if indent is None:
129+
indent = line[:len(line) - len(line.lstrip())]
130+
entries.append((int(m.group(1)), line))
131+
i += 1
132+
if indent is None:
133+
indent = "\t"
134+
filtered = [(f, l) for (f, l) in entries if f <= max_khz]
135+
if not any(f == max_khz for f, _ in filtered):
136+
raise SystemExit(f"GPU max {max_khz} not found in CAL table")
137+
new_list = []
138+
for idx, (_, line) in enumerate(filtered):
139+
core = line.rstrip().rstrip("\\").rstrip()
140+
suffix = "\n" if idx == len(filtered) - 1 else " \\\n"
141+
new_list.append(f"{indent}{core}{suffix}")
142+
lines[start + 1:i] = new_list
143+
dst_cal.write_text("".join(lines))
144+
145+
write_dtsi()
146+
write_cal()
147+
PY
148+
}
149+
23150
while [[ $# -gt 0 ]]; do
24151
case "$1" in
25152
--model|-m)
26153
MODEL="$2"
27154
shift 2
28155
;;
156+
--gpu-max|-g)
157+
GPU_MAX="$2"
158+
shift 2
159+
;;
29160
--ksu|-k)
30161
KSU_OPTION="$2"
31162
shift 2
@@ -148,6 +279,25 @@ if [[ "$KSU_OPTION" == "y" ]]; then
148279
KSU=ksu.config
149280
fi
150281

282+
if [ -n "$GPU_MAX" ]; then
283+
if ! [[ "$GPU_MAX" =~ ^[0-9]+$ ]]; then
284+
echo "Invalid GPU max value: $GPU_MAX"
285+
exit 1
286+
fi
287+
288+
if [ "$SOC" != "exynos9820" ]; then
289+
echo "GPU max override is only supported on exynos9820; skipping."
290+
else
291+
if [ "$GPU_MAX" -lt 10000 ]; then
292+
GPU_MAX_KHZ=$((GPU_MAX * 1000))
293+
else
294+
GPU_MAX_KHZ=$GPU_MAX
295+
fi
296+
echo "Applying GPU max: ${GPU_MAX_KHZ} kHz (from forOC tables)"
297+
apply_gpu_tables "$GPU_MAX_KHZ" || abort
298+
fi
299+
fi
300+
151301
rm -rf build/out/$MODEL
152302
mkdir -p build/out/$MODEL/zip/files
153303
mkdir -p build/out/$MODEL/zip/META-INF/com/google/android

drivers/gpu/arm/exynos/frontend/gpex_clock_sysfs.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ GPEX_STATIC ssize_t set_clock(const char *buf, size_t count)
6969
return count;
7070
}
7171
CREATE_SYSFS_DEVICE_WRITE_FUNCTION(set_clock)
72+
CREATE_SYSFS_KOBJECT_WRITE_FUNCTION(set_clock)
7273

7374
GPEX_STATIC int gpu_get_asv_table(char *buf, size_t buf_size)
7475
{
@@ -497,7 +498,7 @@ int gpex_clock_sysfs_init(struct _clock_info *_clk_info)
497498
set_min_lock_dvfs);
498499
GPEX_UTILS_SYSFS_KOBJECT_FILE_ADD(gpu_mm_min_clock, show_mm_min_lock_dvfs,
499500
set_mm_min_lock_dvfs);
500-
GPEX_UTILS_SYSFS_KOBJECT_FILE_ADD_RO(gpu_clock, show_clock);
501+
GPEX_UTILS_SYSFS_KOBJECT_FILE_ADD(gpu_clock, show_clock, set_clock);
501502
GPEX_UTILS_SYSFS_KOBJECT_FILE_ADD_RO(gpu_freq_table, show_gpu_freq_table);
502503

503504
return 0;

drivers/soc/samsung/cal-if/g3d_dvfs_table.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
#define __G3D_DVFS_TABLE_H__
1010

1111
#define G3D_DVFS_TABLE_ENTRY_LIST(X) \
12-
/* X(910000, 837500, 910000000, 4, 140, 0, 0, 1) */ \
13-
/* X(858000, 812500, 858000000, 4, 132, 0, 0, 1) */ \
14-
/* X(806000, 787500, 806000000, 4, 124, 0, 0, 1) */ \
15-
/*X(754000, 768750, 754000000, 4, 116, 0, 0, 1) */ \
12+
X(910000, 837500, 910000000, 4, 140, 0, 0, 1) \
13+
X(858000, 812500, 858000000, 4, 132, 0, 0, 1) \
14+
X(806000, 787500, 806000000, 4, 124, 0, 0, 1) \
15+
X(754000, 768750, 754000000, 4, 116, 0, 0, 1) \
1616
X(702000, 750000, 702000000, 4, 108, 0, 0, 0) \
1717
X(676000, 706250, 676000000, 4, 104, 0, 0, 0) \
1818
X(650000, 700000, 650000000, 4, 100, 0, 0, 0) \

0 commit comments

Comments
 (0)