From d21ee3b3a84eeeac108c667f358aa9bcfbc963aa Mon Sep 17 00:00:00 2001 From: Johnny Liu Date: Tue, 15 Oct 2024 02:29:15 +0000 Subject: [PATCH] devfreq: nvhost_podgov: fix build issue for K519+ Since K519+, frequency table and max_state information is stored in the devfreq struct directly, not in the devfreq_dev_profile struct. Use nvidia conftest to conditionally build the governor and choose the correct data structure for accessing the information. Kernel build won't complain anything when build the governor, but when the devfreq driver (e.g. nvgpu) trying to add the devfreq device with the nvhost_pogdov governor, it will fail to add the devfreq device since the frequency table information is NULL in the devfreq_dev_profile and the governor use the wrong information. Bug 4883576 Change-Id: I885bc4ceac885eea5644416b6eacefbbea523a2b Signed-off-by: Johnny Liu Reviewed-on: https://git-master.nvidia.com/r/c/linux-nv-oot/+/3229870 GVS: buildbot_gerritrpt Reviewed-by: svcacv Reviewed-by: Jon Hunter --- drivers/devfreq/governor_pod_scaling.c | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/drivers/devfreq/governor_pod_scaling.c b/drivers/devfreq/governor_pod_scaling.c index ed7b6533..077c8b95 100644 --- a/drivers/devfreq/governor_pod_scaling.c +++ b/drivers/devfreq/governor_pod_scaling.c @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-only /* - * Copyright (c) 2012-2023, NVIDIA CORPORATION. All rights reserved. + * SPDX-FileCopyrightText: Copyright (c) 2012-2024 NVIDIA CORPORATION & AFFILIATES. All rights reserved. */ /* @@ -13,6 +13,8 @@ * */ +#include + #include #include #include @@ -113,15 +115,21 @@ static void get_freq_range(struct devfreq *devfreq, unsigned long *min_freq, unsigned long *max_freq) { +#if defined(NV_DEVFREQ_HAS_FREQ_TABLE) + unsigned long *freq_table = devfreq->freq_table; + unsigned int max_state = devfreq->max_state; +#else unsigned long *freq_table = devfreq->profile->freq_table; + unsigned int max_state = devfreq->profile->max_state; +#endif lockdep_assert_held(&devfreq->lock); - if (freq_table[0] < freq_table[devfreq->profile->max_state - 1]) { + if (freq_table[0] < freq_table[max_state - 1]) { *min_freq = freq_table[0]; - *max_freq = freq_table[devfreq->profile->max_state - 1]; + *max_freq = freq_table[max_state - 1]; } else { - *min_freq = freq_table[devfreq->profile->max_state - 1]; + *min_freq = freq_table[max_state - 1]; *max_freq = freq_table[0]; } @@ -767,8 +775,13 @@ static int nvhost_pod_init(struct devfreq *df) if (sysfs_create_file(&df->dev.parent->kobj, &attr->attr)) goto err_create_user_sysfs_entry; +#if defined(NV_DEVFREQ_HAS_FREQ_TABLE) + podgov->freq_count = df->max_state; + podgov->freqlist = df->freq_table; +#else podgov->freq_count = df->profile->max_state; podgov->freqlist = df->profile->freq_table; +#endif if (!podgov->freq_count || !podgov->freqlist) goto err_get_freqs;