Message ID | 20241124-b4-modernise-smem-v1-8-b7852c11b67c@linaro.org |
---|---|
State | New |
Headers | show |
Series | qcom: smem: modernize SMEM in U-Boot | expand |
Hi Caleb, On Sun, 24 Nov 2024 at 12:17, Caleb Connolly <caleb.connolly@linaro.org> wrote: > > Implement socinfo support to fetch the serial number if available. > > Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org> > --- > drivers/soc/qcom/smem.c | 25 +++++++++++++++++++++++++ > include/soc/qcom/smem.h | 1 + > 2 files changed, 26 insertions(+) > Reviewed-by: Simon Glass <sjg@chromium.org> nit below > diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c > index 5166f289dfb6..5570c5c907ad 100644 > --- a/drivers/soc/qcom/smem.c > +++ b/drivers/soc/qcom/smem.c > @@ -13,8 +13,10 @@ > #include <linux/io.h> > #include <linux/ioport.h> > #include <linux/sizes.h> > #include <soc/qcom/smem.h> > +#include <soc/qcom/socinfo.h> > +#include <env.h> > > /* > * The Qualcomm shared memory system is a allocate only heap structure that > * consists of one of more memory areas that can be accessed by the processors > @@ -982,8 +984,31 @@ static int qcom_smem_map_global(struct qcom_smem *smem, u32 size) > > return 0; > } > > +int qcom_socinfo_init(void) > +{ > + struct socinfo *info; > + size_t item_size; > + char buf[32] = { 0 }; > + > + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, > + &item_size); > + if (IS_ERR(info)) { > + log_err("Couldn't find socinfo: %ld\n", PTR_ERR(info)); > + return PTR_ERR(info); > + } > + > + if (offsetof(struct socinfo, serial_num) <= item_size) { > + snprintf(buf, sizeof(buf), "%u", le32_to_cpu(info->serial_num)); > + env_set("serial#", buf); > + } else { > + return -ENOENT; > + } > + > + return 0; > +} > + > int qcom_smem_init(void) > { > struct smem_header *header; > struct qcom_smem *smem; > diff --git a/include/soc/qcom/smem.h b/include/soc/qcom/smem.h > index a955db08c0f0..755003807dba 100644 > --- a/include/soc/qcom/smem.h > +++ b/include/soc/qcom/smem.h > @@ -4,8 +4,9 @@ > > #define QCOM_SMEM_HOST_ANY -1 > > int qcom_smem_init(void); > +int qcom_socinfo_init(void); Comment please! > > bool qcom_smem_is_available(void); > int qcom_smem_alloc(unsigned host, unsigned item, size_t size); > void *qcom_smem_get(unsigned host, unsigned item, size_t *size); > > -- > 2.47.0 >
On Sun, Nov 24, 2024 at 08:17:50PM +0100, Caleb Connolly wrote: > Implement socinfo support to fetch the serial number if available. > > Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org> > --- > drivers/soc/qcom/smem.c | 25 +++++++++++++++++++++++++ > include/soc/qcom/smem.h | 1 + > 2 files changed, 26 insertions(+) > > diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c > index 5166f289dfb6..5570c5c907ad 100644 > --- a/drivers/soc/qcom/smem.c > +++ b/drivers/soc/qcom/smem.c > @@ -13,8 +13,10 @@ > #include <linux/io.h> > #include <linux/ioport.h> > #include <linux/sizes.h> > #include <soc/qcom/smem.h> > +#include <soc/qcom/socinfo.h> > +#include <env.h> > > /* > * The Qualcomm shared memory system is a allocate only heap structure that > * consists of one of more memory areas that can be accessed by the processors > @@ -982,8 +984,31 @@ static int qcom_smem_map_global(struct qcom_smem *smem, u32 size) > > return 0; > } > > +int qcom_socinfo_init(void) > +{ > + struct socinfo *info; > + size_t item_size; > + char buf[32] = { 0 }; > + > + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, > + &item_size); > + if (IS_ERR(info)) { > + log_err("Couldn't find socinfo: %ld\n", PTR_ERR(info)); > + return PTR_ERR(info); > + } > + > + if (offsetof(struct socinfo, serial_num) <= item_size) { > + snprintf(buf, sizeof(buf), "%u", le32_to_cpu(info->serial_num)); > + env_set("serial#", buf); Hm, this conflicts with qcom_late_init() setting the serial# in board/qualcomm/dragonboard410c/dragonboard410c.c: ## Error: Can't overwrite "serial#" ## Error inserting "serial#" variable, errno=1 DB410c doesn't have a proper serial number in socinfo. Turns out using offsetof() in this check is wrong, I sent a patch for this on Linux that was applied upstream: https://git.kernel.org/pub/scm/linux/kernel/git/qcom/linux.git/commit/?h=for-next&id=22cf4fae6660b6e1a583a41cbf84e3046ca9ccd0 Can you add that fix here? offsetofend() doesn't exist in U-Boot. Might be cleanest to just copy that over to U-Boot's linux/stddef.h. Thanks, Stephan
diff --git a/drivers/soc/qcom/smem.c b/drivers/soc/qcom/smem.c index 5166f289dfb6..5570c5c907ad 100644 --- a/drivers/soc/qcom/smem.c +++ b/drivers/soc/qcom/smem.c @@ -13,8 +13,10 @@ #include <linux/io.h> #include <linux/ioport.h> #include <linux/sizes.h> #include <soc/qcom/smem.h> +#include <soc/qcom/socinfo.h> +#include <env.h> /* * The Qualcomm shared memory system is a allocate only heap structure that * consists of one of more memory areas that can be accessed by the processors @@ -982,8 +984,31 @@ static int qcom_smem_map_global(struct qcom_smem *smem, u32 size) return 0; } +int qcom_socinfo_init(void) +{ + struct socinfo *info; + size_t item_size; + char buf[32] = { 0 }; + + info = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID, + &item_size); + if (IS_ERR(info)) { + log_err("Couldn't find socinfo: %ld\n", PTR_ERR(info)); + return PTR_ERR(info); + } + + if (offsetof(struct socinfo, serial_num) <= item_size) { + snprintf(buf, sizeof(buf), "%u", le32_to_cpu(info->serial_num)); + env_set("serial#", buf); + } else { + return -ENOENT; + } + + return 0; +} + int qcom_smem_init(void) { struct smem_header *header; struct qcom_smem *smem; diff --git a/include/soc/qcom/smem.h b/include/soc/qcom/smem.h index a955db08c0f0..755003807dba 100644 --- a/include/soc/qcom/smem.h +++ b/include/soc/qcom/smem.h @@ -4,8 +4,9 @@ #define QCOM_SMEM_HOST_ANY -1 int qcom_smem_init(void); +int qcom_socinfo_init(void); bool qcom_smem_is_available(void); int qcom_smem_alloc(unsigned host, unsigned item, size_t size); void *qcom_smem_get(unsigned host, unsigned item, size_t *size);
Implement socinfo support to fetch the serial number if available. Signed-off-by: Caleb Connolly <caleb.connolly@linaro.org> --- drivers/soc/qcom/smem.c | 25 +++++++++++++++++++++++++ include/soc/qcom/smem.h | 1 + 2 files changed, 26 insertions(+)