Message ID | 20230525120956.3095317-1-robimarko@gmail.com |
---|---|
State | Superseded |
Headers | show |
Series | [v3,1/5] soc: qcom: socinfo: move SMEM item struct and defines to a header | expand |
On 5/25/2023 5:39 PM, 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 <robimarko@gmail.com> > --- > Changes in v3: > * Change export to EXPORT_SYMBOL_GPL > * Use an argument for returning SoC ID > * Update kerneldoc > --- > drivers/soc/qcom/smem.c | 24 ++++++++++++++++++++++++ > include/linux/soc/qcom/smem.h | 2 ++ > 2 files changed, 26 insertions(+) > > diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c > index bc98520c4969..185ed0da11a1 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,29 @@ phys_addr_t qcom_smem_virt_to_phys(void *p) > } > EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys); > > +/** > + * qcom_smem_get_msm_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_msm_id(u32 *id) I think, MSMĀ is not the only platform which will leverage this API. qcom_smem_get_soc_id() / qcom_smem_get_cpu_id() would make more sense than qcom_smem_get_msm_id() ? > +{ > + size_t len; > + struct socinfo *info; > + > + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, &len); len is unused after this, can we just pass NULL? Did a quick check on the code, if we pass the address, size of the item will be updated, else no. > + if (IS_ERR(info)) > + return PTR_ERR(info); > + > + *id = info->id; > + > + return 0; > +} > +EXPORT_SYMBOL_GPL(qcom_smem_get_msm_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..cb204ad6373c 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_msm_id(u32 *id); > + > #endif
On 25.05.2023 23:21, Konrad Dybcio wrote: > > > On 25.05.2023 17:03, Robert Marko wrote: >> On Thu, 25 May 2023 at 14:59, Kathiravan T <quic_kathirav@quicinc.com> wrote: >>> >>> >>> On 5/25/2023 5:39 PM, 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 <robimarko@gmail.com> >>>> --- >>>> Changes in v3: >>>> * Change export to EXPORT_SYMBOL_GPL >>>> * Use an argument for returning SoC ID >>>> * Update kerneldoc >>>> --- >>>> drivers/soc/qcom/smem.c | 24 ++++++++++++++++++++++++ >>>> include/linux/soc/qcom/smem.h | 2 ++ >>>> 2 files changed, 26 insertions(+) >>>> >>>> diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c >>>> index bc98520c4969..185ed0da11a1 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,29 @@ phys_addr_t qcom_smem_virt_to_phys(void *p) >>>> } >>>> EXPORT_SYMBOL_GPL(qcom_smem_virt_to_phys); >>>> >>>> +/** >>>> + * qcom_smem_get_msm_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_msm_id(u32 *id) >>> >>> >>> I think, MSM is not the only platform which will leverage this API. >>> qcom_smem_get_soc_id() / qcom_smem_get_cpu_id() would make more sense >>> than qcom_smem_get_msm_id() ? >> >> I agree, qcom_smem_get_soc_id() sounds better to me as its not just MSM parts. >>> >>> >>>> +{ >>>> + size_t len; >>>> + struct socinfo *info; >>>> + >>>> + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, &len); >>> >>> >>> len is unused after this, can we just pass NULL? Did a quick check on >>> the code, if we pass the address, size of the item will be updated, else no. >> >> Yes, indeed passing NULL works here for the simple case this helper is handling. >> Will address in v4. > Please also consider Bjorn's suggestion of using PTR_ERR Nevermind, brain too laggy ;) Konrad > > Konrad >> >> Regards, >> Robert >>> >>> >>>> + if (IS_ERR(info)) >>>> + return PTR_ERR(info); >>>> + >>>> + *id = info->id; >>>> + >>>> + return 0; >>>> +} >>>> +EXPORT_SYMBOL_GPL(qcom_smem_get_msm_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..cb204ad6373c 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_msm_id(u32 *id); >>>> + >>>> #endif
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
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 <robimarko@gmail.com> --- 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