Skip to content

Commit c928a05

Browse files
committed
drm/msm/adreno: Move speedbin mapping to device table
This simplifies the code. v2: Use a table of structs instead of flat uint32_t[] Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Dmitry Baryshkov <[email protected]> Patchwork: https://patchwork.freedesktop.org/patch/549769/
1 parent f30a648 commit c928a05

File tree

3 files changed

+97
-155
lines changed

3 files changed

+97
-155
lines changed

drivers/gpu/drm/msm/adreno/a6xx_gpu.c

Lines changed: 16 additions & 155 deletions
Original file line numberDiff line numberDiff line change
@@ -2204,159 +2204,19 @@ static bool a6xx_progress(struct msm_gpu *gpu, struct msm_ringbuffer *ring)
22042204
return progress;
22052205
}
22062206

2207-
static u32 a610_get_speed_bin(u32 fuse)
2207+
static u32 fuse_to_supp_hw(const struct adreno_info *info, u32 fuse)
22082208
{
2209-
/*
2210-
* There are (at least) three SoCs implementing A610: SM6125 (trinket),
2211-
* SM6115 (bengal) and SM6225 (khaje). Trinket does not have speedbinning,
2212-
* as only a single SKU exists and we don't support khaje upstream yet.
2213-
* Hence, this matching table is only valid for bengal and can be easily
2214-
* expanded if need be.
2215-
*/
2216-
2217-
if (fuse == 0)
2218-
return 0;
2219-
else if (fuse == 206)
2220-
return 1;
2221-
else if (fuse == 200)
2222-
return 2;
2223-
else if (fuse == 157)
2224-
return 3;
2225-
else if (fuse == 127)
2226-
return 4;
2227-
2228-
return UINT_MAX;
2229-
}
2230-
2231-
static u32 a618_get_speed_bin(u32 fuse)
2232-
{
2233-
if (fuse == 0)
2234-
return 0;
2235-
else if (fuse == 169)
2236-
return 1;
2237-
else if (fuse == 174)
2238-
return 2;
2239-
2240-
return UINT_MAX;
2241-
}
2242-
2243-
static u32 a619_holi_get_speed_bin(u32 fuse)
2244-
{
2245-
/*
2246-
* There are (at least) two SoCs implementing A619_holi: SM4350 (holi)
2247-
* and SM6375 (blair). Limit the fuse matching to the corresponding
2248-
* SoC to prevent bogus frequency setting (as improbable as it may be,
2249-
* given unexpected fuse values are.. unexpected! But still possible.)
2250-
*/
2251-
2252-
if (fuse == 0)
2253-
return 0;
2254-
2255-
if (of_machine_is_compatible("qcom,sm4350")) {
2256-
if (fuse == 138)
2257-
return 1;
2258-
else if (fuse == 92)
2259-
return 2;
2260-
} else if (of_machine_is_compatible("qcom,sm6375")) {
2261-
if (fuse == 190)
2262-
return 1;
2263-
else if (fuse == 177)
2264-
return 2;
2265-
} else
2266-
pr_warn("Unknown SoC implementing A619_holi!\n");
2267-
2268-
return UINT_MAX;
2269-
}
2270-
2271-
static u32 a619_get_speed_bin(u32 fuse)
2272-
{
2273-
if (fuse == 0)
2274-
return 0;
2275-
else if (fuse == 120)
2276-
return 4;
2277-
else if (fuse == 138)
2278-
return 3;
2279-
else if (fuse == 169)
2280-
return 2;
2281-
else if (fuse == 180)
2282-
return 1;
2283-
2284-
return UINT_MAX;
2285-
}
2286-
2287-
static u32 a640_get_speed_bin(u32 fuse)
2288-
{
2289-
if (fuse == 0)
2290-
return 0;
2291-
else if (fuse == 1)
2292-
return 1;
2293-
2294-
return UINT_MAX;
2295-
}
2296-
2297-
static u32 a650_get_speed_bin(u32 fuse)
2298-
{
2299-
if (fuse == 0)
2300-
return 0;
2301-
else if (fuse == 1)
2302-
return 1;
2303-
/* Yep, 2 and 3 are swapped! :/ */
2304-
else if (fuse == 2)
2305-
return 3;
2306-
else if (fuse == 3)
2307-
return 2;
2308-
2309-
return UINT_MAX;
2310-
}
2209+
if (!info->speedbins)
2210+
return UINT_MAX;
23112211

2312-
static u32 adreno_7c3_get_speed_bin(u32 fuse)
2313-
{
2314-
if (fuse == 0)
2315-
return 0;
2316-
else if (fuse == 117)
2317-
return 0;
2318-
else if (fuse == 190)
2319-
return 1;
2212+
for (int i = 0; info->speedbins[i].fuse != SHRT_MAX; i++)
2213+
if (info->speedbins[i].fuse == fuse)
2214+
return BIT(info->speedbins[i].speedbin);
23202215

23212216
return UINT_MAX;
23222217
}
23232218

2324-
static u32 fuse_to_supp_hw(struct device *dev, struct adreno_gpu *adreno_gpu, u32 fuse)
2325-
{
2326-
u32 val = UINT_MAX;
2327-
2328-
if (adreno_is_a610(adreno_gpu))
2329-
val = a610_get_speed_bin(fuse);
2330-
2331-
if (adreno_is_a618(adreno_gpu))
2332-
val = a618_get_speed_bin(fuse);
2333-
2334-
else if (adreno_is_a619_holi(adreno_gpu))
2335-
val = a619_holi_get_speed_bin(fuse);
2336-
2337-
else if (adreno_is_a619(adreno_gpu))
2338-
val = a619_get_speed_bin(fuse);
2339-
2340-
else if (adreno_is_7c3(adreno_gpu))
2341-
val = adreno_7c3_get_speed_bin(fuse);
2342-
2343-
else if (adreno_is_a640(adreno_gpu))
2344-
val = a640_get_speed_bin(fuse);
2345-
2346-
else if (adreno_is_a650(adreno_gpu))
2347-
val = a650_get_speed_bin(fuse);
2348-
2349-
if (val == UINT_MAX) {
2350-
DRM_DEV_ERROR(dev,
2351-
"missing support for speed-bin: %u. Some OPPs may not be supported by hardware\n",
2352-
fuse);
2353-
return UINT_MAX;
2354-
}
2355-
2356-
return (1 << val);
2357-
}
2358-
2359-
static int a6xx_set_supported_hw(struct device *dev, struct adreno_gpu *adreno_gpu)
2219+
static int a6xx_set_supported_hw(struct device *dev, const struct adreno_info *info)
23602220
{
23612221
u32 supp_hw;
23622222
u32 speedbin;
@@ -2375,7 +2235,14 @@ static int a6xx_set_supported_hw(struct device *dev, struct adreno_gpu *adreno_g
23752235
return ret;
23762236
}
23772237

2378-
supp_hw = fuse_to_supp_hw(dev, adreno_gpu, speedbin);
2238+
supp_hw = fuse_to_supp_hw(info, speedbin);
2239+
2240+
if (supp_hw == UINT_MAX) {
2241+
DRM_DEV_ERROR(dev,
2242+
"missing support for speed-bin: %u. Some OPPs may not be supported by hardware\n",
2243+
speedbin);
2244+
return UINT_MAX;
2245+
}
23792246

23802247
ret = devm_pm_opp_set_supported_hw(dev, &supp_hw, 1);
23812248
if (ret)
@@ -2483,17 +2350,11 @@ struct msm_gpu *a6xx_gpu_init(struct drm_device *dev)
24832350
if (!info)
24842351
return ERR_PTR(-EINVAL);
24852352

2486-
/* Assign these early so that we can use the is_aXYZ helpers */
2487-
/* New-style ADRENO_REV()-only */
2488-
adreno_gpu->rev = info->rev;
2489-
/* Quirk data */
2490-
adreno_gpu->info = info;
2491-
24922353
adreno_gpu->base.hw_apriv = !!(info->quirks & ADRENO_QUIRK_HAS_HW_APRIV);
24932354

24942355
a6xx_llc_slices_init(pdev, a6xx_gpu);
24952356

2496-
ret = a6xx_set_supported_hw(&pdev->dev, adreno_gpu);
2357+
ret = a6xx_set_supported_hw(&pdev->dev, info);
24972358
if (ret) {
24982359
a6xx_destroy(&(a6xx_gpu->base.base));
24992360
return ERR_PTR(ret);

drivers/gpu/drm/msm/adreno/adreno_device.c

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,20 @@ static const struct adreno_info gpulist[] = {
247247
.init = a6xx_gpu_init,
248248
.zapfw = "a610_zap.mdt",
249249
.hwcg = a612_hwcg,
250+
/*
251+
* There are (at least) three SoCs implementing A610: SM6125
252+
* (trinket), SM6115 (bengal) and SM6225 (khaje). Trinket does
253+
* not have speedbinning, as only a single SKU exists and we
254+
* don't support khaje upstream yet. Hence, this matching
255+
* table is only valid for bengal.
256+
*/
257+
.speedbins = ADRENO_SPEEDBINS(
258+
{ 0, 0 },
259+
{ 206, 1 },
260+
{ 200, 2 },
261+
{ 157, 3 },
262+
{ 127, 4 },
263+
),
250264
}, {
251265
.rev = ADRENO_REV(6, 1, 8, ANY_ID),
252266
.revn = 618,
@@ -258,6 +272,11 @@ static const struct adreno_info gpulist[] = {
258272
.inactive_period = DRM_MSM_INACTIVE_PERIOD,
259273
.quirks = ADRENO_QUIRK_HAS_CACHED_COHERENT,
260274
.init = a6xx_gpu_init,
275+
.speedbins = ADRENO_SPEEDBINS(
276+
{ 0, 0 },
277+
{ 169, 1 },
278+
{ 174, 2 },
279+
),
261280
}, {
262281
.machine = "qcom,sm4350",
263282
.rev = ADRENO_REV(6, 1, 9, ANY_ID),
@@ -271,6 +290,11 @@ static const struct adreno_info gpulist[] = {
271290
.init = a6xx_gpu_init,
272291
.zapfw = "a615_zap.mdt",
273292
.hwcg = a615_hwcg,
293+
.speedbins = ADRENO_SPEEDBINS(
294+
{ 0, 0 },
295+
{ 138, 1 },
296+
{ 92, 2 },
297+
),
274298
}, {
275299
.machine = "qcom,sm6375",
276300
.rev = ADRENO_REV(6, 1, 9, ANY_ID),
@@ -284,6 +308,11 @@ static const struct adreno_info gpulist[] = {
284308
.init = a6xx_gpu_init,
285309
.zapfw = "a615_zap.mdt",
286310
.hwcg = a615_hwcg,
311+
.speedbins = ADRENO_SPEEDBINS(
312+
{ 0, 0 },
313+
{ 190, 1 },
314+
{ 177, 2 },
315+
),
287316
}, {
288317
.rev = ADRENO_REV(6, 1, 9, ANY_ID),
289318
.revn = 619,
@@ -297,6 +326,13 @@ static const struct adreno_info gpulist[] = {
297326
.init = a6xx_gpu_init,
298327
.zapfw = "a615_zap.mdt",
299328
.hwcg = a615_hwcg,
329+
.speedbins = ADRENO_SPEEDBINS(
330+
{ 0, 0 },
331+
{ 120, 4 },
332+
{ 138, 3 },
333+
{ 169, 2 },
334+
{ 180, 1 },
335+
),
300336
}, {
301337
.rev = ADRENO_REV(6, 3, 0, ANY_ID),
302338
.revn = 630,
@@ -323,6 +359,10 @@ static const struct adreno_info gpulist[] = {
323359
.init = a6xx_gpu_init,
324360
.zapfw = "a640_zap.mdt",
325361
.hwcg = a640_hwcg,
362+
.speedbins = ADRENO_SPEEDBINS(
363+
{ 0, 0 },
364+
{ 1, 1 },
365+
),
326366
}, {
327367
.rev = ADRENO_REV(6, 5, 0, ANY_ID),
328368
.revn = 650,
@@ -338,6 +378,12 @@ static const struct adreno_info gpulist[] = {
338378
.zapfw = "a650_zap.mdt",
339379
.hwcg = a650_hwcg,
340380
.address_space_size = SZ_16G,
381+
.speedbins = ADRENO_SPEEDBINS(
382+
{ 0, 0 },
383+
{ 1, 1 },
384+
{ 2, 3 }, /* Yep, 2 and 3 are swapped! :/ */
385+
{ 3, 2 },
386+
),
341387
}, {
342388
.rev = ADRENO_REV(6, 6, 0, ANY_ID),
343389
.revn = 660,
@@ -366,6 +412,11 @@ static const struct adreno_info gpulist[] = {
366412
.init = a6xx_gpu_init,
367413
.hwcg = a660_hwcg,
368414
.address_space_size = SZ_16G,
415+
.speedbins = ADRENO_SPEEDBINS(
416+
{ 0, 0 },
417+
{ 117, 0 },
418+
{ 190, 1 },
419+
),
369420
}, {
370421
.rev = ADRENO_REV(6, 8, 0, ANY_ID),
371422
.revn = 680,

drivers/gpu/drm/msm/adreno/adreno_gpu.h

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,11 @@ struct adreno_reglist {
6060
extern const struct adreno_reglist a612_hwcg[], a615_hwcg[], a630_hwcg[], a640_hwcg[], a650_hwcg[];
6161
extern const struct adreno_reglist a660_hwcg[], a690_hwcg[];
6262

63+
struct adreno_speedbin {
64+
uint16_t fuse;
65+
uint16_t speedbin;
66+
};
67+
6368
struct adreno_info {
6469
const char *machine;
6570
struct adreno_rev rev;
@@ -72,8 +77,33 @@ struct adreno_info {
7277
u32 inactive_period;
7378
const struct adreno_reglist *hwcg;
7479
u64 address_space_size;
80+
/**
81+
* @speedbins: Optional table of fuse to speedbin mappings
82+
*
83+
* Consists of pairs of fuse, index mappings, terminated with
84+
* {SHRT_MAX, 0} sentinal.
85+
*/
86+
struct adreno_speedbin *speedbins;
7587
};
7688

89+
/*
90+
* Helper to build a speedbin table, ie. the table:
91+
* fuse | speedbin
92+
* -----+---------
93+
* 0 | 0
94+
* 169 | 1
95+
* 174 | 2
96+
*
97+
* would be declared as:
98+
*
99+
* .speedbins = ADRENO_SPEEDBINS(
100+
* { 0, 0 },
101+
* { 169, 1 },
102+
* { 174, 2 },
103+
* ),
104+
*/
105+
#define ADRENO_SPEEDBINS(tbl...) (struct adreno_speedbin[]) { tbl {SHRT_MAX, 0} }
106+
77107
const struct adreno_info *adreno_info(struct adreno_rev rev);
78108

79109
struct adreno_gpu {

0 commit comments

Comments
 (0)