2023-05-25 21:04:31

by Robert Marko

[permalink] [raw]
Subject: [PATCH v4 1/5] soc: qcom: socinfo: move SMEM item struct and defines to a header

Move SMEM item struct and related defines to a header in order to be able
to reuse them in the SMEM driver instead of duplicating them.

Signed-off-by: Robert Marko <[email protected]>
---
drivers/soc/qcom/socinfo.c | 67 +-----------------------------
include/linux/soc/qcom/socinfo.h | 70 ++++++++++++++++++++++++++++++++
2 files changed, 71 insertions(+), 66 deletions(-)
create mode 100644 include/linux/soc/qcom/socinfo.h

diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
index c2e4a57dd666..ee6bbf76d941 100644
--- a/drivers/soc/qcom/socinfo.c
+++ b/drivers/soc/qcom/socinfo.c
@@ -11,6 +11,7 @@
#include <linux/random.h>
#include <linux/slab.h>
#include <linux/soc/qcom/smem.h>
+#include <linux/soc/qcom/socinfo.h>
#include <linux/string.h>
#include <linux/stringify.h>
#include <linux/sys_soc.h>
@@ -32,15 +33,6 @@
#define qcom_board_id(id) QCOM_ID_ ## id, __stringify(id)
#define qcom_board_id_named(id, name) QCOM_ID_ ## id, (name)

-#define SMEM_SOCINFO_BUILD_ID_LENGTH 32
-#define SMEM_SOCINFO_CHIP_ID_LENGTH 32
-
-/*
- * SMEM item id, used to acquire handles to respective
- * SMEM region.
- */
-#define SMEM_HW_SW_BUILD_ID 137
-
#ifdef CONFIG_DEBUG_FS
#define SMEM_IMAGE_VERSION_BLOCKS_COUNT 32
#define SMEM_IMAGE_VERSION_SIZE 4096
@@ -126,64 +118,7 @@ static const char *const pmic_models[] = {
[58] = "PM8450",
[65] = "PM8010",
};
-#endif /* CONFIG_DEBUG_FS */
-
-/* Socinfo SMEM item structure */
-struct socinfo {
- __le32 fmt;
- __le32 id;
- __le32 ver;
- char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
- /* Version 2 */
- __le32 raw_id;
- __le32 raw_ver;
- /* Version 3 */
- __le32 hw_plat;
- /* Version 4 */
- __le32 plat_ver;
- /* Version 5 */
- __le32 accessory_chip;
- /* Version 6 */
- __le32 hw_plat_subtype;
- /* Version 7 */
- __le32 pmic_model;
- __le32 pmic_die_rev;
- /* Version 8 */
- __le32 pmic_model_1;
- __le32 pmic_die_rev_1;
- __le32 pmic_model_2;
- __le32 pmic_die_rev_2;
- /* Version 9 */
- __le32 foundry_id;
- /* Version 10 */
- __le32 serial_num;
- /* Version 11 */
- __le32 num_pmics;
- __le32 pmic_array_offset;
- /* Version 12 */
- __le32 chip_family;
- __le32 raw_device_family;
- __le32 raw_device_num;
- /* Version 13 */
- __le32 nproduct_id;
- char chip_id[SMEM_SOCINFO_CHIP_ID_LENGTH];
- /* Version 14 */
- __le32 num_clusters;
- __le32 ncluster_array_offset;
- __le32 num_defective_parts;
- __le32 ndefective_parts_array_offset;
- /* Version 15 */
- __le32 nmodem_supported;
- /* Version 16 */
- __le32 feature_code;
- __le32 pcode;
- __le32 npartnamemap_offset;
- __le32 nnum_partname_mapping;
- /* Version 17 */
- __le32 oem_variant;
-};

-#ifdef CONFIG_DEBUG_FS
struct socinfo_params {
u32 raw_device_family;
u32 hw_plat_subtype;
diff --git a/include/linux/soc/qcom/socinfo.h b/include/linux/soc/qcom/socinfo.h
new file mode 100644
index 000000000000..d1cbc49a2a2d
--- /dev/null
+++ b/include/linux/soc/qcom/socinfo.h
@@ -0,0 +1,70 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+
+#ifndef __QCOM_SOCINFO_H__
+#define __QCOM_SOCINFO_H__
+
+/*
+ * SMEM item id, used to acquire handles to respective
+ * SMEM region.
+ */
+#define SMEM_HW_SW_BUILD_ID 137
+
+#define SMEM_SOCINFO_BUILD_ID_LENGTH 32
+#define SMEM_SOCINFO_CHIP_ID_LENGTH 32
+
+/* Socinfo SMEM item structure */
+struct socinfo {
+ __le32 fmt;
+ __le32 id;
+ __le32 ver;
+ char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
+ /* Version 2 */
+ __le32 raw_id;
+ __le32 raw_ver;
+ /* Version 3 */
+ __le32 hw_plat;
+ /* Version 4 */
+ __le32 plat_ver;
+ /* Version 5 */
+ __le32 accessory_chip;
+ /* Version 6 */
+ __le32 hw_plat_subtype;
+ /* Version 7 */
+ __le32 pmic_model;
+ __le32 pmic_die_rev;
+ /* Version 8 */
+ __le32 pmic_model_1;
+ __le32 pmic_die_rev_1;
+ __le32 pmic_model_2;
+ __le32 pmic_die_rev_2;
+ /* Version 9 */
+ __le32 foundry_id;
+ /* Version 10 */
+ __le32 serial_num;
+ /* Version 11 */
+ __le32 num_pmics;
+ __le32 pmic_array_offset;
+ /* Version 12 */
+ __le32 chip_family;
+ __le32 raw_device_family;
+ __le32 raw_device_num;
+ /* Version 13 */
+ __le32 nproduct_id;
+ char chip_id[SMEM_SOCINFO_CHIP_ID_LENGTH];
+ /* Version 14 */
+ __le32 num_clusters;
+ __le32 ncluster_array_offset;
+ __le32 num_defective_parts;
+ __le32 ndefective_parts_array_offset;
+ /* Version 15 */
+ __le32 nmodem_supported;
+ /* Version 16 */
+ __le32 feature_code;
+ __le32 pcode;
+ __le32 npartnamemap_offset;
+ __le32 nnum_partname_mapping;
+ /* Version 17 */
+ __le32 oem_variant;
+};
+
+#endif
--
2.40.1



2023-05-25 21:04:46

by Robert Marko

[permalink] [raw]
Subject: [PATCH v4 2/5] soc: qcom: smem: Switch to EXPORT_SYMBOL_GPL()

SMEM has been GPL licensed from the start, and there is no reason to use
EXPORT_SYMBOL() so switch to the GPL version.

Signed-off-by: Robert Marko <[email protected]>
Reviewed-by: Konrad Dybcio <[email protected]>
Reviewed-by: Trilok Soni <[email protected]>
---
drivers/soc/qcom/smem.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index 6be7ea93c78c..bc98520c4969 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -500,7 +500,7 @@ int qcom_smem_alloc(unsigned host, unsigned item, size_t size)

return ret;
}
-EXPORT_SYMBOL(qcom_smem_alloc);
+EXPORT_SYMBOL_GPL(qcom_smem_alloc);

static void *qcom_smem_get_global(struct qcom_smem *smem,
unsigned item,
@@ -674,7 +674,7 @@ void *qcom_smem_get(unsigned host, unsigned item, size_t *size)
return ptr;

}
-EXPORT_SYMBOL(qcom_smem_get);
+EXPORT_SYMBOL_GPL(qcom_smem_get);

/**
* qcom_smem_get_free_space() - retrieve amount of free space in a partition
@@ -719,7 +719,7 @@ int qcom_smem_get_free_space(unsigned host)

return ret;
}
-EXPORT_SYMBOL(qcom_smem_get_free_space);
+EXPORT_SYMBOL_GPL(qcom_smem_get_free_space);

static bool addr_in_range(void __iomem *base, size_t size, void *addr)
{
@@ -770,7 +770,7 @@ phys_addr_t qcom_smem_virt_to_phys(void *p)

return 0;
}
-EXPORT_SYMBOL(qcom_smem_virt_to_phys);
+EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);

static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
{
--
2.40.1


2023-05-25 21:05:14

by Robert Marko

[permalink] [raw]
Subject: [PATCH v4 4/5] cpufreq: qcom-nvmem: use SoC ID-s from bindings

SMEM SoC ID-s are now stored in DT bindings so lets use those instead of
defining them in the driver again.

Signed-off-by: Robert Marko <[email protected]>
Reviewed-by: Konrad Dybcio <[email protected]>
Reviewed-by: Bjorn Andersson <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
---
drivers/cpufreq/qcom-cpufreq-nvmem.c | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c
index a577586b23be..60e99be2d3db 100644
--- a/drivers/cpufreq/qcom-cpufreq-nvmem.c
+++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c
@@ -31,12 +31,7 @@

#define MSM_ID_SMEM 137

-enum _msm_id {
- MSM8996V3 = 0xF6ul,
- APQ8096V3 = 0x123ul,
- MSM8996SG = 0x131ul,
- APQ8096SG = 0x138ul,
-};
+#include <dt-bindings/arm/qcom,ids.h>

enum _msm8996_version {
MSM8996_V3,
@@ -154,12 +149,12 @@ static enum _msm8996_version qcom_cpufreq_get_msm_id(void)
msm_id++;

switch ((enum _msm_id)*msm_id) {
- case MSM8996V3:
- case APQ8096V3:
+ case QCOM_ID_MSM8996:
+ case QCOM_ID_APQ8096:
version = MSM8996_V3;
break;
- case MSM8996SG:
- case APQ8096SG:
+ case QCOM_ID_MSM8996SG:
+ case QCOM_ID_APQ8096SG:
version = MSM8996_SG;
break;
default:
--
2.40.1


2023-05-25 21:05:49

by Robert Marko

[permalink] [raw]
Subject: [PATCH v4 3/5] soc: qcom: smem: introduce qcom_smem_get_soc_id()

Introduce a helper to return the SoC SMEM ID, which is used to identify the
exact SoC model as there may be differences in the same SoC family.

Currently, cpufreq-nvmem does this completely in the driver and there has
been more interest expresed for other drivers to use this information so
lets expose a common helper to prevent redoing it in individual drivers
since this field is present on every SMEM table version.

Signed-off-by: Robert Marko <[email protected]>
---
Changes in v4:
* Change helper name to qcom_smem_get_soc_id()
* Remove len and just pass NULL, that is sufficient here

Changes in v3:
* Change export to EXPORT_SYMBOL_GPL
* Use an argument for returning SoC ID
* Update kerneldoc
---
drivers/soc/qcom/smem.c | 23 +++++++++++++++++++++++
include/linux/soc/qcom/smem.h | 2 ++
2 files changed, 25 insertions(+)

diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
index bc98520c4969..78cf79ea4924 100644
--- a/drivers/soc/qcom/smem.c
+++ b/drivers/soc/qcom/smem.c
@@ -14,6 +14,7 @@
#include <linux/sizes.h>
#include <linux/slab.h>
#include <linux/soc/qcom/smem.h>
+#include <linux/soc/qcom/socinfo.h>

/*
* The Qualcomm shared memory system is a allocate only heap structure that
@@ -772,6 +773,28 @@ phys_addr_t qcom_smem_virt_to_phys(void *p)
}
EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);

+/**
+ * qcom_smem_get_soc_id() - return the SoC ID
+ * @id: On success, we return the SoC ID here.
+ *
+ * Look up SoC ID from HW/SW build ID and return it.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int qcom_smem_get_soc_id(u32 *id)
+{
+ struct socinfo *info;
+
+ info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
+ if (IS_ERR(info))
+ return PTR_ERR(info);
+
+ *id = info->id;
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id);
+
static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
{
struct smem_header *header;
diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
index 86e1b358688a..223db6a9c733 100644
--- a/include/linux/soc/qcom/smem.h
+++ b/include/linux/soc/qcom/smem.h
@@ -11,4 +11,6 @@ int qcom_smem_get_free_space(unsigned host);

phys_addr_t qcom_smem_virt_to_phys(void *p);

+int qcom_smem_get_soc_id(u32 *id);
+
#endif
--
2.40.1


2023-05-25 21:10:34

by Robert Marko

[permalink] [raw]
Subject: [PATCH v4 5/5] cpufreq: qcom-nvmem: use helper to get SMEM SoC ID

Now that SMEM exports a helper to get the SMEM SoC ID lets utilize it.
Currently qcom_cpufreq_get_msm_id() is encoding the returned SMEM SoC ID
into an enum, however there is no reason to do so and we can just match
directly on the SMEM SoC ID as returned by qcom_smem_get_soc_id().

Signed-off-by: Robert Marko <[email protected]>
Acked-by: Viresh Kumar <[email protected]>
---
Changes in v4:
* Adapt to name change to qcom_smem_get_soc_id()

Changes in v3:
* Adapt to helper using argument now

Changes in v2:
* Utilize helper exported by SMEM instead of refactoring
qcom_cpufreq_get_msm_id()
---
drivers/cpufreq/qcom-cpufreq-nvmem.c | 56 +++++-----------------------
1 file changed, 10 insertions(+), 46 deletions(-)

diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c
index 60e99be2d3db..a88b6fe5db50 100644
--- a/drivers/cpufreq/qcom-cpufreq-nvmem.c
+++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c
@@ -29,16 +29,8 @@
#include <linux/slab.h>
#include <linux/soc/qcom/smem.h>

-#define MSM_ID_SMEM 137
-
#include <dt-bindings/arm/qcom,ids.h>

-enum _msm8996_version {
- MSM8996_V3,
- MSM8996_SG,
- NUM_OF_MSM8996_VERSIONS,
-};
-
struct qcom_cpufreq_drv;

struct qcom_cpufreq_match_data {
@@ -135,60 +127,32 @@ static void get_krait_bin_format_b(struct device *cpu_dev,
dev_dbg(cpu_dev, "PVS version: %d\n", *pvs_ver);
}

-static enum _msm8996_version qcom_cpufreq_get_msm_id(void)
-{
- size_t len;
- u32 *msm_id;
- enum _msm8996_version version;
-
- msm_id = qcom_smem_get(QCOM_SMEM_HOST_ANY, MSM_ID_SMEM, &len);
- if (IS_ERR(msm_id))
- return NUM_OF_MSM8996_VERSIONS;
-
- /* The first 4 bytes are format, next to them is the actual msm-id */
- msm_id++;
-
- switch ((enum _msm_id)*msm_id) {
- case QCOM_ID_MSM8996:
- case QCOM_ID_APQ8096:
- version = MSM8996_V3;
- break;
- case QCOM_ID_MSM8996SG:
- case QCOM_ID_APQ8096SG:
- version = MSM8996_SG;
- break;
- default:
- version = NUM_OF_MSM8996_VERSIONS;
- }
-
- return version;
-}
-
static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev,
struct nvmem_cell *speedbin_nvmem,
char **pvs_name,
struct qcom_cpufreq_drv *drv)
{
size_t len;
+ u32 msm_id;
u8 *speedbin;
- enum _msm8996_version msm8996_version;
+ int ret;
*pvs_name = NULL;

- msm8996_version = qcom_cpufreq_get_msm_id();
- if (NUM_OF_MSM8996_VERSIONS == msm8996_version) {
- dev_err(cpu_dev, "Not Snapdragon 820/821!");
- return -ENODEV;
- }
+ ret = qcom_smem_get_soc_id(&msm_id);
+ if (ret)
+ return ret;

speedbin = nvmem_cell_read(speedbin_nvmem, &len);
if (IS_ERR(speedbin))
return PTR_ERR(speedbin);

- switch (msm8996_version) {
- case MSM8996_V3:
+ switch (msm_id) {
+ case QCOM_ID_MSM8996:
+ case QCOM_ID_APQ8096:
drv->versions = 1 << (unsigned int)(*speedbin);
break;
- case MSM8996_SG:
+ case QCOM_ID_MSM8996SG:
+ case QCOM_ID_APQ8096SG:
drv->versions = 1 << ((unsigned int)(*speedbin) + 4);
break;
default:
--
2.40.1


2023-05-25 23:22:06

by Konrad Dybcio

[permalink] [raw]
Subject: Re: [PATCH v4 1/5] soc: qcom: socinfo: move SMEM item struct and defines to a header



On 25.05.2023 23:02, Robert Marko wrote:
> Move SMEM item struct and related defines to a header in order to be able
> to reuse them in the SMEM driver instead of duplicating them.
>
> Signed-off-by: Robert Marko <[email protected]>
> ---
Reviewed-by: Konrad Dybcio <[email protected]>

Konrad
> drivers/soc/qcom/socinfo.c | 67 +-----------------------------
> include/linux/soc/qcom/socinfo.h | 70 ++++++++++++++++++++++++++++++++
> 2 files changed, 71 insertions(+), 66 deletions(-)
> create mode 100644 include/linux/soc/qcom/socinfo.h
>
> diff --git a/drivers/soc/qcom/socinfo.c b/drivers/soc/qcom/socinfo.c
> index c2e4a57dd666..ee6bbf76d941 100644
> --- a/drivers/soc/qcom/socinfo.c
> +++ b/drivers/soc/qcom/socinfo.c
> @@ -11,6 +11,7 @@
> #include <linux/random.h>
> #include <linux/slab.h>
> #include <linux/soc/qcom/smem.h>
> +#include <linux/soc/qcom/socinfo.h>
> #include <linux/string.h>
> #include <linux/stringify.h>
> #include <linux/sys_soc.h>
> @@ -32,15 +33,6 @@
> #define qcom_board_id(id) QCOM_ID_ ## id, __stringify(id)
> #define qcom_board_id_named(id, name) QCOM_ID_ ## id, (name)
>
> -#define SMEM_SOCINFO_BUILD_ID_LENGTH 32
> -#define SMEM_SOCINFO_CHIP_ID_LENGTH 32
> -
> -/*
> - * SMEM item id, used to acquire handles to respective
> - * SMEM region.
> - */
> -#define SMEM_HW_SW_BUILD_ID 137
> -
> #ifdef CONFIG_DEBUG_FS
> #define SMEM_IMAGE_VERSION_BLOCKS_COUNT 32
> #define SMEM_IMAGE_VERSION_SIZE 4096
> @@ -126,64 +118,7 @@ static const char *const pmic_models[] = {
> [58] = "PM8450",
> [65] = "PM8010",
> };
> -#endif /* CONFIG_DEBUG_FS */
> -
> -/* Socinfo SMEM item structure */
> -struct socinfo {
> - __le32 fmt;
> - __le32 id;
> - __le32 ver;
> - char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
> - /* Version 2 */
> - __le32 raw_id;
> - __le32 raw_ver;
> - /* Version 3 */
> - __le32 hw_plat;
> - /* Version 4 */
> - __le32 plat_ver;
> - /* Version 5 */
> - __le32 accessory_chip;
> - /* Version 6 */
> - __le32 hw_plat_subtype;
> - /* Version 7 */
> - __le32 pmic_model;
> - __le32 pmic_die_rev;
> - /* Version 8 */
> - __le32 pmic_model_1;
> - __le32 pmic_die_rev_1;
> - __le32 pmic_model_2;
> - __le32 pmic_die_rev_2;
> - /* Version 9 */
> - __le32 foundry_id;
> - /* Version 10 */
> - __le32 serial_num;
> - /* Version 11 */
> - __le32 num_pmics;
> - __le32 pmic_array_offset;
> - /* Version 12 */
> - __le32 chip_family;
> - __le32 raw_device_family;
> - __le32 raw_device_num;
> - /* Version 13 */
> - __le32 nproduct_id;
> - char chip_id[SMEM_SOCINFO_CHIP_ID_LENGTH];
> - /* Version 14 */
> - __le32 num_clusters;
> - __le32 ncluster_array_offset;
> - __le32 num_defective_parts;
> - __le32 ndefective_parts_array_offset;
> - /* Version 15 */
> - __le32 nmodem_supported;
> - /* Version 16 */
> - __le32 feature_code;
> - __le32 pcode;
> - __le32 npartnamemap_offset;
> - __le32 nnum_partname_mapping;
> - /* Version 17 */
> - __le32 oem_variant;
> -};
>
> -#ifdef CONFIG_DEBUG_FS
> struct socinfo_params {
> u32 raw_device_family;
> u32 hw_plat_subtype;
> diff --git a/include/linux/soc/qcom/socinfo.h b/include/linux/soc/qcom/socinfo.h
> new file mode 100644
> index 000000000000..d1cbc49a2a2d
> --- /dev/null
> +++ b/include/linux/soc/qcom/socinfo.h
> @@ -0,0 +1,70 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +
> +#ifndef __QCOM_SOCINFO_H__
> +#define __QCOM_SOCINFO_H__
> +
> +/*
> + * SMEM item id, used to acquire handles to respective
> + * SMEM region.
> + */
> +#define SMEM_HW_SW_BUILD_ID 137
> +
> +#define SMEM_SOCINFO_BUILD_ID_LENGTH 32
> +#define SMEM_SOCINFO_CHIP_ID_LENGTH 32
> +
> +/* Socinfo SMEM item structure */
> +struct socinfo {
> + __le32 fmt;
> + __le32 id;
> + __le32 ver;
> + char build_id[SMEM_SOCINFO_BUILD_ID_LENGTH];
> + /* Version 2 */
> + __le32 raw_id;
> + __le32 raw_ver;
> + /* Version 3 */
> + __le32 hw_plat;
> + /* Version 4 */
> + __le32 plat_ver;
> + /* Version 5 */
> + __le32 accessory_chip;
> + /* Version 6 */
> + __le32 hw_plat_subtype;
> + /* Version 7 */
> + __le32 pmic_model;
> + __le32 pmic_die_rev;
> + /* Version 8 */
> + __le32 pmic_model_1;
> + __le32 pmic_die_rev_1;
> + __le32 pmic_model_2;
> + __le32 pmic_die_rev_2;
> + /* Version 9 */
> + __le32 foundry_id;
> + /* Version 10 */
> + __le32 serial_num;
> + /* Version 11 */
> + __le32 num_pmics;
> + __le32 pmic_array_offset;
> + /* Version 12 */
> + __le32 chip_family;
> + __le32 raw_device_family;
> + __le32 raw_device_num;
> + /* Version 13 */
> + __le32 nproduct_id;
> + char chip_id[SMEM_SOCINFO_CHIP_ID_LENGTH];
> + /* Version 14 */
> + __le32 num_clusters;
> + __le32 ncluster_array_offset;
> + __le32 num_defective_parts;
> + __le32 ndefective_parts_array_offset;
> + /* Version 15 */
> + __le32 nmodem_supported;
> + /* Version 16 */
> + __le32 feature_code;
> + __le32 pcode;
> + __le32 npartnamemap_offset;
> + __le32 nnum_partname_mapping;
> + /* Version 17 */
> + __le32 oem_variant;
> +};
> +
> +#endif

2023-05-25 23:25:49

by Konrad Dybcio

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] soc: qcom: smem: introduce qcom_smem_get_soc_id()



On 25.05.2023 23:02, Robert Marko wrote:
> Introduce a helper to return the SoC SMEM ID, which is used to identify the
> exact SoC model as there may be differences in the same SoC family.
>
> Currently, cpufreq-nvmem does this completely in the driver and there has
> been more interest expresed for other drivers to use this information so
> lets expose a common helper to prevent redoing it in individual drivers
> since this field is present on every SMEM table version.
>
> Signed-off-by: Robert Marko <[email protected]>
> ---
> Changes in v4:
> * Change helper name to qcom_smem_get_soc_id()
> * Remove len and just pass NULL, that is sufficient here
>
> Changes in v3:
> * Change export to EXPORT_SYMBOL_GPL
> * Use an argument for returning SoC ID
> * Update kerneldoc
> ---
> drivers/soc/qcom/smem.c | 23 +++++++++++++++++++++++
> include/linux/soc/qcom/smem.h | 2 ++
> 2 files changed, 25 insertions(+)
>
> diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
> index bc98520c4969..78cf79ea4924 100644
> --- a/drivers/soc/qcom/smem.c
> +++ b/drivers/soc/qcom/smem.c
> @@ -14,6 +14,7 @@
> #include <linux/sizes.h>
> #include <linux/slab.h>
> #include <linux/soc/qcom/smem.h>
> +#include <linux/soc/qcom/socinfo.h>
>
> /*
> * The Qualcomm shared memory system is a allocate only heap structure that
> @@ -772,6 +773,28 @@ phys_addr_t qcom_smem_virt_to_phys(void *p)
> }
> EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);
>
> +/**
> + * qcom_smem_get_soc_id() - return the SoC ID
> + * @id: On success, we return the SoC ID here.
> + *
> + * Look up SoC ID from HW/SW build ID and return it.
> + *
> + * Return: 0 on success, negative errno on failure.
> + */
> +int qcom_smem_get_soc_id(u32 *id)
__le32 *id

LGTM otherwise!

Konrad
> +{
> + struct socinfo *info;
> +
> + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
> + if (IS_ERR(info))
> + return PTR_ERR(info);
> +
> + *id = info->id;
> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id);
> +
> static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
> {
> struct smem_header *header;
> diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
> index 86e1b358688a..223db6a9c733 100644
> --- a/include/linux/soc/qcom/smem.h
> +++ b/include/linux/soc/qcom/smem.h
> @@ -11,4 +11,6 @@ int qcom_smem_get_free_space(unsigned host);
>
> phys_addr_t qcom_smem_virt_to_phys(void *p);
>
> +int qcom_smem_get_soc_id(u32 *id);
> +
> #endif

2023-05-25 23:33:29

by Konrad Dybcio

[permalink] [raw]
Subject: Re: [PATCH v4 5/5] cpufreq: qcom-nvmem: use helper to get SMEM SoC ID



On 25.05.2023 23:02, Robert Marko wrote:
> Now that SMEM exports a helper to get the SMEM SoC ID lets utilize it.
> Currently qcom_cpufreq_get_msm_id() is encoding the returned SMEM SoC ID
> into an enum, however there is no reason to do so and we can just match
> directly on the SMEM SoC ID as returned by qcom_smem_get_soc_id().
>
> Signed-off-by: Robert Marko <[email protected]>
> Acked-by: Viresh Kumar <[email protected]>
> ---
> Changes in v4:
> * Adapt to name change to qcom_smem_get_soc_id()
>
> Changes in v3:
> * Adapt to helper using argument now
>
> Changes in v2:
> * Utilize helper exported by SMEM instead of refactoring
> qcom_cpufreq_get_msm_id()
> ---
> drivers/cpufreq/qcom-cpufreq-nvmem.c | 56 +++++-----------------------
> 1 file changed, 10 insertions(+), 46 deletions(-)
>
> diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c
> index 60e99be2d3db..a88b6fe5db50 100644
> --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c
> +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c
> @@ -29,16 +29,8 @@
> #include <linux/slab.h>
> #include <linux/soc/qcom/smem.h>
>
> -#define MSM_ID_SMEM 137
> -
> #include <dt-bindings/arm/qcom,ids.h>
>
> -enum _msm8996_version {
> - MSM8996_V3,
> - MSM8996_SG,
> - NUM_OF_MSM8996_VERSIONS,
> -};
> -
> struct qcom_cpufreq_drv;
>
> struct qcom_cpufreq_match_data {
> @@ -135,60 +127,32 @@ static void get_krait_bin_format_b(struct device *cpu_dev,
> dev_dbg(cpu_dev, "PVS version: %d\n", *pvs_ver);
> }
>
> -static enum _msm8996_version qcom_cpufreq_get_msm_id(void)
> -{
> - size_t len;
> - u32 *msm_id;
> - enum _msm8996_version version;
> -
> - msm_id = qcom_smem_get(QCOM_SMEM_HOST_ANY, MSM_ID_SMEM, &len);
> - if (IS_ERR(msm_id))
> - return NUM_OF_MSM8996_VERSIONS;
> -
> - /* The first 4 bytes are format, next to them is the actual msm-id */
> - msm_id++;
> -
> - switch ((enum _msm_id)*msm_id) {
> - case QCOM_ID_MSM8996:
> - case QCOM_ID_APQ8096:
> - version = MSM8996_V3;
> - break;
> - case QCOM_ID_MSM8996SG:
> - case QCOM_ID_APQ8096SG:
> - version = MSM8996_SG;
> - break;
> - default:
> - version = NUM_OF_MSM8996_VERSIONS;
> - }
> -
> - return version;
> -}
> -
> static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev,
> struct nvmem_cell *speedbin_nvmem,
> char **pvs_name,
> struct qcom_cpufreq_drv *drv)
> {
> size_t len;
> + u32 msm_id;
__le32

> u8 *speedbin;
> - enum _msm8996_version msm8996_version;
> + int ret;
> *pvs_name = NULL;
>
> - msm8996_version = qcom_cpufreq_get_msm_id();
> - if (NUM_OF_MSM8996_VERSIONS == msm8996_version) {
> - dev_err(cpu_dev, "Not Snapdragon 820/821!");
> - return -ENODEV;
> - }
> + ret = qcom_smem_get_soc_id(&msm_id);
> + if (ret)
> + return ret;
Now since it can return a PTR_ERR, you should check for IS_ERR
and return ERR_PTR if that happens

LGTM otherwise!

Konrad
>
> speedbin = nvmem_cell_read(speedbin_nvmem, &len);
> if (IS_ERR(speedbin))
> return PTR_ERR(speedbin);
>
> - switch (msm8996_version) {
> - case MSM8996_V3:
> + switch (msm_id) {
> + case QCOM_ID_MSM8996:
> + case QCOM_ID_APQ8096:
> drv->versions = 1 << (unsigned int)(*speedbin);
> break;
> - case MSM8996_SG:
> + case QCOM_ID_MSM8996SG:
> + case QCOM_ID_APQ8096SG:
> drv->versions = 1 << ((unsigned int)(*speedbin) + 4);
> break;
> default:

2023-05-26 02:35:25

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] soc: qcom: smem: introduce qcom_smem_get_soc_id()

On Fri, May 26, 2023 at 01:18:17AM +0200, Konrad Dybcio wrote:
>
>
> On 25.05.2023 23:02, Robert Marko wrote:
> > Introduce a helper to return the SoC SMEM ID, which is used to identify the
> > exact SoC model as there may be differences in the same SoC family.
> >
> > Currently, cpufreq-nvmem does this completely in the driver and there has
> > been more interest expresed for other drivers to use this information so
> > lets expose a common helper to prevent redoing it in individual drivers
> > since this field is present on every SMEM table version.
> >
> > Signed-off-by: Robert Marko <[email protected]>
> > ---
> > Changes in v4:
> > * Change helper name to qcom_smem_get_soc_id()
> > * Remove len and just pass NULL, that is sufficient here
> >
> > Changes in v3:
> > * Change export to EXPORT_SYMBOL_GPL
> > * Use an argument for returning SoC ID
> > * Update kerneldoc
> > ---
> > drivers/soc/qcom/smem.c | 23 +++++++++++++++++++++++
> > include/linux/soc/qcom/smem.h | 2 ++
> > 2 files changed, 25 insertions(+)
> >
> > diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
> > index bc98520c4969..78cf79ea4924 100644
> > --- a/drivers/soc/qcom/smem.c
> > +++ b/drivers/soc/qcom/smem.c
> > @@ -14,6 +14,7 @@
> > #include <linux/sizes.h>
> > #include <linux/slab.h>
> > #include <linux/soc/qcom/smem.h>
> > +#include <linux/soc/qcom/socinfo.h>
> >
> > /*
> > * The Qualcomm shared memory system is a allocate only heap structure that
> > @@ -772,6 +773,28 @@ phys_addr_t qcom_smem_virt_to_phys(void *p)
> > }
> > EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);
> >
> > +/**
> > + * qcom_smem_get_soc_id() - return the SoC ID
> > + * @id: On success, we return the SoC ID here.
> > + *
> > + * Look up SoC ID from HW/SW build ID and return it.
> > + *
> > + * Return: 0 on success, negative errno on failure.
> > + */
> > +int qcom_smem_get_soc_id(u32 *id)
> __le32 *id
>

Why do you want this passed back to the user in little endian? When is
it not going to be compared to a cpu-endian constant?

> LGTM otherwise!
>
> Konrad
> > +{
> > + struct socinfo *info;
> > +
> > + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
> > + if (IS_ERR(info))
> > + return PTR_ERR(info);
> > +
> > + *id = info->id;

This should be __le32_to_cpu() though...

Regards,
Bjorn

> > +
> > + return 0;
> > +}
> > +EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id);
> > +
> > static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
> > {
> > struct smem_header *header;
> > diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
> > index 86e1b358688a..223db6a9c733 100644
> > --- a/include/linux/soc/qcom/smem.h
> > +++ b/include/linux/soc/qcom/smem.h
> > @@ -11,4 +11,6 @@ int qcom_smem_get_free_space(unsigned host);
> >
> > phys_addr_t qcom_smem_virt_to_phys(void *p);
> >
> > +int qcom_smem_get_soc_id(u32 *id);
> > +
> > #endif

2023-05-26 02:52:08

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH v4 5/5] cpufreq: qcom-nvmem: use helper to get SMEM SoC ID

On Fri, May 26, 2023 at 01:18:02AM +0200, Konrad Dybcio wrote:
>
>
> On 25.05.2023 23:02, Robert Marko wrote:
> > Now that SMEM exports a helper to get the SMEM SoC ID lets utilize it.
> > Currently qcom_cpufreq_get_msm_id() is encoding the returned SMEM SoC ID
> > into an enum, however there is no reason to do so and we can just match
> > directly on the SMEM SoC ID as returned by qcom_smem_get_soc_id().
> >
> > Signed-off-by: Robert Marko <[email protected]>
> > Acked-by: Viresh Kumar <[email protected]>
> > ---
> > Changes in v4:
> > * Adapt to name change to qcom_smem_get_soc_id()
> >
> > Changes in v3:
> > * Adapt to helper using argument now
> >
> > Changes in v2:
> > * Utilize helper exported by SMEM instead of refactoring
> > qcom_cpufreq_get_msm_id()
> > ---
> > drivers/cpufreq/qcom-cpufreq-nvmem.c | 56 +++++-----------------------
> > 1 file changed, 10 insertions(+), 46 deletions(-)
> >
> > diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c
> > index 60e99be2d3db..a88b6fe5db50 100644
> > --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c
> > +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c
> > @@ -29,16 +29,8 @@
> > #include <linux/slab.h>
> > #include <linux/soc/qcom/smem.h>
> >
> > -#define MSM_ID_SMEM 137
> > -
> > #include <dt-bindings/arm/qcom,ids.h>
> >
> > -enum _msm8996_version {
> > - MSM8996_V3,
> > - MSM8996_SG,
> > - NUM_OF_MSM8996_VERSIONS,
> > -};
> > -
> > struct qcom_cpufreq_drv;
> >
> > struct qcom_cpufreq_match_data {
> > @@ -135,60 +127,32 @@ static void get_krait_bin_format_b(struct device *cpu_dev,
> > dev_dbg(cpu_dev, "PVS version: %d\n", *pvs_ver);
> > }
> >
> > -static enum _msm8996_version qcom_cpufreq_get_msm_id(void)
> > -{
> > - size_t len;
> > - u32 *msm_id;
> > - enum _msm8996_version version;
> > -
> > - msm_id = qcom_smem_get(QCOM_SMEM_HOST_ANY, MSM_ID_SMEM, &len);
> > - if (IS_ERR(msm_id))
> > - return NUM_OF_MSM8996_VERSIONS;
> > -
> > - /* The first 4 bytes are format, next to them is the actual msm-id */
> > - msm_id++;
> > -
> > - switch ((enum _msm_id)*msm_id) {
> > - case QCOM_ID_MSM8996:
> > - case QCOM_ID_APQ8096:
> > - version = MSM8996_V3;
> > - break;
> > - case QCOM_ID_MSM8996SG:
> > - case QCOM_ID_APQ8096SG:
> > - version = MSM8996_SG;
> > - break;
> > - default:
> > - version = NUM_OF_MSM8996_VERSIONS;
> > - }
> > -
> > - return version;
> > -}
> > -
> > static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev,
> > struct nvmem_cell *speedbin_nvmem,
> > char **pvs_name,
> > struct qcom_cpufreq_drv *drv)
> > {
> > size_t len;
> > + u32 msm_id;
> __le32
>
> > u8 *speedbin;
> > - enum _msm8996_version msm8996_version;
> > + int ret;
> > *pvs_name = NULL;
> >
> > - msm8996_version = qcom_cpufreq_get_msm_id();
> > - if (NUM_OF_MSM8996_VERSIONS == msm8996_version) {
> > - dev_err(cpu_dev, "Not Snapdragon 820/821!");
> > - return -ENODEV;
> > - }
> > + ret = qcom_smem_get_soc_id(&msm_id);
> > + if (ret)
> > + return ret;
> Now since it can return a PTR_ERR, you should check for IS_ERR
> and return ERR_PTR if that happens

No, the PTR_ERR() extracted the error value out of the pointer, so it's
just an integer now (or zero on success). So this is looking correct to
me.

>
> LGTM otherwise!
>
> Konrad
> >
> > speedbin = nvmem_cell_read(speedbin_nvmem, &len);
> > if (IS_ERR(speedbin))
> > return PTR_ERR(speedbin);
> >
> > - switch (msm8996_version) {
> > - case MSM8996_V3:
> > + switch (msm_id) {
> > + case QCOM_ID_MSM8996:

And here are those cpu-endian constants... If msm_id is a __le32 then
all these constants needs to be cpu_to_le32().

Regards,
Bjorn

> > + case QCOM_ID_APQ8096:
> > drv->versions = 1 << (unsigned int)(*speedbin);
> > break;
> > - case MSM8996_SG:
> > + case QCOM_ID_MSM8996SG:
> > + case QCOM_ID_APQ8096SG:
> > drv->versions = 1 << ((unsigned int)(*speedbin) + 4);
> > break;
> > default:

2023-05-26 09:19:03

by Konrad Dybcio

[permalink] [raw]
Subject: Re: [PATCH v4 5/5] cpufreq: qcom-nvmem: use helper to get SMEM SoC ID



On 26.05.2023 04:43, Bjorn Andersson wrote:
> On Fri, May 26, 2023 at 01:18:02AM +0200, Konrad Dybcio wrote:
>>
>>
>> On 25.05.2023 23:02, Robert Marko wrote:
>>> Now that SMEM exports a helper to get the SMEM SoC ID lets utilize it.
>>> Currently qcom_cpufreq_get_msm_id() is encoding the returned SMEM SoC ID
>>> into an enum, however there is no reason to do so and we can just match
>>> directly on the SMEM SoC ID as returned by qcom_smem_get_soc_id().
>>>
>>> Signed-off-by: Robert Marko <[email protected]>
>>> Acked-by: Viresh Kumar <[email protected]>
>>> ---
>>> Changes in v4:
>>> * Adapt to name change to qcom_smem_get_soc_id()
>>>
>>> Changes in v3:
>>> * Adapt to helper using argument now
>>>
>>> Changes in v2:
>>> * Utilize helper exported by SMEM instead of refactoring
>>> qcom_cpufreq_get_msm_id()
>>> ---
>>> drivers/cpufreq/qcom-cpufreq-nvmem.c | 56 +++++-----------------------
>>> 1 file changed, 10 insertions(+), 46 deletions(-)
>>>
>>> diff --git a/drivers/cpufreq/qcom-cpufreq-nvmem.c b/drivers/cpufreq/qcom-cpufreq-nvmem.c
>>> index 60e99be2d3db..a88b6fe5db50 100644
>>> --- a/drivers/cpufreq/qcom-cpufreq-nvmem.c
>>> +++ b/drivers/cpufreq/qcom-cpufreq-nvmem.c
>>> @@ -29,16 +29,8 @@
>>> #include <linux/slab.h>
>>> #include <linux/soc/qcom/smem.h>
>>>
>>> -#define MSM_ID_SMEM 137
>>> -
>>> #include <dt-bindings/arm/qcom,ids.h>
>>>
>>> -enum _msm8996_version {
>>> - MSM8996_V3,
>>> - MSM8996_SG,
>>> - NUM_OF_MSM8996_VERSIONS,
>>> -};
>>> -
>>> struct qcom_cpufreq_drv;
>>>
>>> struct qcom_cpufreq_match_data {
>>> @@ -135,60 +127,32 @@ static void get_krait_bin_format_b(struct device *cpu_dev,
>>> dev_dbg(cpu_dev, "PVS version: %d\n", *pvs_ver);
>>> }
>>>
>>> -static enum _msm8996_version qcom_cpufreq_get_msm_id(void)
>>> -{
>>> - size_t len;
>>> - u32 *msm_id;
>>> - enum _msm8996_version version;
>>> -
>>> - msm_id = qcom_smem_get(QCOM_SMEM_HOST_ANY, MSM_ID_SMEM, &len);
>>> - if (IS_ERR(msm_id))
>>> - return NUM_OF_MSM8996_VERSIONS;
>>> -
>>> - /* The first 4 bytes are format, next to them is the actual msm-id */
>>> - msm_id++;
>>> -
>>> - switch ((enum _msm_id)*msm_id) {
>>> - case QCOM_ID_MSM8996:
>>> - case QCOM_ID_APQ8096:
>>> - version = MSM8996_V3;
>>> - break;
>>> - case QCOM_ID_MSM8996SG:
>>> - case QCOM_ID_APQ8096SG:
>>> - version = MSM8996_SG;
>>> - break;
>>> - default:
>>> - version = NUM_OF_MSM8996_VERSIONS;
>>> - }
>>> -
>>> - return version;
>>> -}
>>> -
>>> static int qcom_cpufreq_kryo_name_version(struct device *cpu_dev,
>>> struct nvmem_cell *speedbin_nvmem,
>>> char **pvs_name,
>>> struct qcom_cpufreq_drv *drv)
>>> {
>>> size_t len;
>>> + u32 msm_id;
>> __le32
>>
>>> u8 *speedbin;
>>> - enum _msm8996_version msm8996_version;
>>> + int ret;
>>> *pvs_name = NULL;
>>>
>>> - msm8996_version = qcom_cpufreq_get_msm_id();
>>> - if (NUM_OF_MSM8996_VERSIONS == msm8996_version) {
>>> - dev_err(cpu_dev, "Not Snapdragon 820/821!");
>>> - return -ENODEV;
>>> - }
>>> + ret = qcom_smem_get_soc_id(&msm_id);
>>> + if (ret)
>>> + return ret;
>> Now since it can return a PTR_ERR, you should check for IS_ERR
>> and return ERR_PTR if that happens
>
> No, the PTR_ERR() extracted the error value out of the pointer, so it's
> just an integer now (or zero on success). So this is looking correct to
> me.
Riiight the function that returns a pointer to an error is *within*
the one we're calling.. So much so for me reviewing late at night..

Konrad
>
>>
>> LGTM otherwise!
>>
>> Konrad
>>>
>>> speedbin = nvmem_cell_read(speedbin_nvmem, &len);
>>> if (IS_ERR(speedbin))
>>> return PTR_ERR(speedbin);
>>>
>>> - switch (msm8996_version) {
>>> - case MSM8996_V3:
>>> + switch (msm_id) {
>>> + case QCOM_ID_MSM8996:
>
> And here are those cpu-endian constants... If msm_id is a __le32 then
> all these constants needs to be cpu_to_le32().
>
> Regards,
> Bjorn
>
>>> + case QCOM_ID_APQ8096:
>>> drv->versions = 1 << (unsigned int)(*speedbin);
>>> break;
>>> - case MSM8996_SG:
>>> + case QCOM_ID_MSM8996SG:
>>> + case QCOM_ID_APQ8096SG:
>>> drv->versions = 1 << ((unsigned int)(*speedbin) + 4);
>>> break;
>>> default:

2023-05-26 09:21:06

by Konrad Dybcio

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] soc: qcom: smem: introduce qcom_smem_get_soc_id()



On 26.05.2023 04:33, Bjorn Andersson wrote:
> On Fri, May 26, 2023 at 01:18:17AM +0200, Konrad Dybcio wrote:
>>
>>
>> On 25.05.2023 23:02, Robert Marko wrote:
>>> Introduce a helper to return the SoC SMEM ID, which is used to identify the
>>> exact SoC model as there may be differences in the same SoC family.
>>>
>>> Currently, cpufreq-nvmem does this completely in the driver and there has
>>> been more interest expresed for other drivers to use this information so
>>> lets expose a common helper to prevent redoing it in individual drivers
>>> since this field is present on every SMEM table version.
>>>
>>> Signed-off-by: Robert Marko <[email protected]>
>>> ---
>>> Changes in v4:
>>> * Change helper name to qcom_smem_get_soc_id()
>>> * Remove len and just pass NULL, that is sufficient here
>>>
>>> Changes in v3:
>>> * Change export to EXPORT_SYMBOL_GPL
>>> * Use an argument for returning SoC ID
>>> * Update kerneldoc
>>> ---
>>> drivers/soc/qcom/smem.c | 23 +++++++++++++++++++++++
>>> include/linux/soc/qcom/smem.h | 2 ++
>>> 2 files changed, 25 insertions(+)
>>>
>>> diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
>>> index bc98520c4969..78cf79ea4924 100644
>>> --- a/drivers/soc/qcom/smem.c
>>> +++ b/drivers/soc/qcom/smem.c
>>> @@ -14,6 +14,7 @@
>>> #include <linux/sizes.h>
>>> #include <linux/slab.h>
>>> #include <linux/soc/qcom/smem.h>
>>> +#include <linux/soc/qcom/socinfo.h>
>>>
>>> /*
>>> * The Qualcomm shared memory system is a allocate only heap structure that
>>> @@ -772,6 +773,28 @@ phys_addr_t qcom_smem_virt_to_phys(void *p)
>>> }
>>> EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);
>>>
>>> +/**
>>> + * qcom_smem_get_soc_id() - return the SoC ID
>>> + * @id: On success, we return the SoC ID here.
>>> + *
>>> + * Look up SoC ID from HW/SW build ID and return it.
>>> + *
>>> + * Return: 0 on success, negative errno on failure.
>>> + */
>>> +int qcom_smem_get_soc_id(u32 *id)
>> __le32 *id
>>
>
> Why do you want this passed back to the user in little endian? When is
> it not going to be compared to a cpu-endian constant?
Ugh. You're right. This makes no sense.

Konrad
>
>> LGTM otherwise!
>>
>> Konrad
>>> +{
>>> + struct socinfo *info;
>>> +
>>> + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
>>> + if (IS_ERR(info))
>>> + return PTR_ERR(info);
>>> +
>>> + *id = info->id;
>
> This should be __le32_to_cpu() though...
>
> Regards,
> Bjorn
>
>>> +
>>> + return 0;
>>> +}
>>> +EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id);
>>> +
>>> static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
>>> {
>>> struct smem_header *header;
>>> diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
>>> index 86e1b358688a..223db6a9c733 100644
>>> --- a/include/linux/soc/qcom/smem.h
>>> +++ b/include/linux/soc/qcom/smem.h
>>> @@ -11,4 +11,6 @@ int qcom_smem_get_free_space(unsigned host);
>>>
>>> phys_addr_t qcom_smem_virt_to_phys(void *p);
>>>
>>> +int qcom_smem_get_soc_id(u32 *id);
>>> +
>>> #endif

2023-05-26 19:23:08

by Bjorn Andersson

[permalink] [raw]
Subject: Re: [PATCH v4 3/5] soc: qcom: smem: introduce qcom_smem_get_soc_id()

On Thu, May 25, 2023 at 11:02:12PM +0200, Robert Marko wrote:
> Introduce a helper to return the SoC SMEM ID, which is used to identify the
> exact SoC model as there may be differences in the same SoC family.
>
> Currently, cpufreq-nvmem does this completely in the driver and there has
> been more interest expresed for other drivers to use this information so
> lets expose a common helper to prevent redoing it in individual drivers
> since this field is present on every SMEM table version.
>
> Signed-off-by: Robert Marko <[email protected]>
> ---
> Changes in v4:
> * Change helper name to qcom_smem_get_soc_id()
> * Remove len and just pass NULL, that is sufficient here
>
> Changes in v3:
> * Change export to EXPORT_SYMBOL_GPL
> * Use an argument for returning SoC ID
> * Update kerneldoc
> ---
> drivers/soc/qcom/smem.c | 23 +++++++++++++++++++++++
> include/linux/soc/qcom/smem.h | 2 ++
> 2 files changed, 25 insertions(+)
>
> diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c
> index bc98520c4969..78cf79ea4924 100644
> --- a/drivers/soc/qcom/smem.c
> +++ b/drivers/soc/qcom/smem.c
> @@ -14,6 +14,7 @@
> #include <linux/sizes.h>
> #include <linux/slab.h>
> #include <linux/soc/qcom/smem.h>
> +#include <linux/soc/qcom/socinfo.h>
>
> /*
> * The Qualcomm shared memory system is a allocate only heap structure that
> @@ -772,6 +773,28 @@ phys_addr_t qcom_smem_virt_to_phys(void *p)
> }
> EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys);
>
> +/**
> + * qcom_smem_get_soc_id() - return the SoC ID
> + * @id: On success, we return the SoC ID here.
> + *
> + * Look up SoC ID from HW/SW build ID and return it.
> + *
> + * Return: 0 on success, negative errno on failure.
> + */
> +int qcom_smem_get_soc_id(u32 *id)
> +{
> + struct socinfo *info;
> +
> + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, NULL);
> + if (IS_ERR(info))
> + return PTR_ERR(info);
> +
> + *id = info->id;

So just to make the discussion between Konrad and me clear, please wrap
the info->id access in __le32_to_cpu() and the series is ready to go.

Thanks,
Bjorn

> +
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(qcom_smem_get_soc_id);
> +
> static int qcom_smem_get_sbl_version(struct qcom_smem *smem)
> {
> struct smem_header *header;
> diff --git a/include/linux/soc/qcom/smem.h b/include/linux/soc/qcom/smem.h
> index 86e1b358688a..223db6a9c733 100644
> --- a/include/linux/soc/qcom/smem.h
> +++ b/include/linux/soc/qcom/smem.h
> @@ -11,4 +11,6 @@ int qcom_smem_get_free_space(unsigned host);
>
> phys_addr_t qcom_smem_virt_to_phys(void *p);
>
> +int qcom_smem_get_soc_id(u32 *id);
> +
> #endif
> --
> 2.40.1
>