Message ID | 20231102074916.3280809-3-adeep@lexina.in (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | RFC: firmware: meson-sm: add chipid sysfs export | expand |
Hi Viacheslav, kernel test robot noticed the following build errors: [auto build test ERROR on soc/for-next] [also build test ERROR on linus/master v6.6 next-20231102] [If your patch is applied to the wrong git tree, kindly drop us a note. And when submitting patch, we suggest to use '--base' as documented in https://git-scm.com/docs/git-format-patch#_base_tree_information] url: https://github.com/intel-lab-lkp/linux/commits/Viacheslav-Bocharov/firmware-meson-sm-change-sprintf-to-scnprintf/20231102-172556 base: https://git.kernel.org/pub/scm/linux/kernel/git/soc/soc.git for-next patch link: https://lore.kernel.org/r/20231102074916.3280809-3-adeep%40lexina.in patch subject: [PATCH 2/4] firmware: meson_sm: Add chipid number sysfs entry config: arm64-randconfig-003-20231103 (https://download.01.org/0day-ci/archive/20231103/202311030513.HxyDUCuc-lkp@intel.com/config) compiler: aarch64-linux-gcc (GCC) 13.2.0 reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20231103/202311030513.HxyDUCuc-lkp@intel.com/reproduce) If you fix the issue in a separate patch/commit (i.e. not just a new version of the same patch/commit), kindly add following tags | Reported-by: kernel test robot <lkp@intel.com> | Closes: https://lore.kernel.org/oe-kbuild-all/202311030513.HxyDUCuc-lkp@intel.com/ All errors (new ones prefixed by >>): drivers/firmware/meson/meson_sm.c: In function 'chipid_show': >> drivers/firmware/meson/meson_sm.c:315:17: error: 'ch' undeclared (first use in this function) 315 | ch = (uint8_t *)(id_buf + 4); | ^~ drivers/firmware/meson/meson_sm.c:315:17: note: each undeclared identifier is reported only once for each function it appears in >> drivers/firmware/meson/meson_sm.c:316:22: error: 'i' undeclared (first use in this function) 316 | for (i = 0; i < 12; i++) | ^ vim +/ch +315 drivers/firmware/meson/meson_sm.c 277 278 static ssize_t chipid_show(struct device *dev, struct device_attribute *attr, 279 char *buf) 280 { 281 struct platform_device *pdev = to_platform_device(dev); 282 struct meson_sm_firmware *fw; 283 uint8_t *id_buf; 284 int ret; 285 286 fw = platform_get_drvdata(pdev); 287 288 id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); 289 if (!id_buf) 290 return -ENOMEM; 291 292 ret = meson_sm_call_read(fw, id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID, 293 2, 0, 0, 0, 0); 294 if (ret < 0) { 295 kfree(id_buf); 296 return ret; 297 } 298 299 int version = *((unsigned int *)id_buf); 300 301 if (version == 2) 302 ret = scnprintf(buf, PAGE_SIZE, "%16phN\n", &id_buf[SM_CHIP_ID_OFFSET]); 303 else { 304 /** 305 * Legacy 12-byte chip ID read out, transform data 306 * to expected order format. 307 */ 308 uint8_t *buff; 309 310 buff = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); 311 if (!buff) 312 return -ENOMEM; 313 ((uint32_t *)buff)[0] = 0; // CPU_ID is empty 314 /* Transform into expected order for display */ > 315 ch = (uint8_t *)(id_buf + 4); > 316 for (i = 0; i < 12; i++) 317 buff[i + 4] = ch[11 - i]; 318 ret = scnprintf(buf, PAGE_SIZE, "%16phN\n", &buff); 319 kfree(buff); 320 } 321 322 kfree(id_buf); 323 return ret; 324 } 325
diff --git a/drivers/firmware/meson/meson_sm.c b/drivers/firmware/meson/meson_sm.c index c1c694b485ee..2820f4ac871b 100644 --- a/drivers/firmware/meson/meson_sm.c +++ b/drivers/firmware/meson/meson_sm.c @@ -240,9 +240,10 @@ struct meson_sm_firmware *meson_sm_get(struct device_node *sm_node) } EXPORT_SYMBOL_GPL(meson_sm_get); -#define SM_CHIP_ID_LENGTH 119 +#define SM_CHIP_ID_LENGTH 128 #define SM_CHIP_ID_OFFSET 4 #define SM_CHIP_ID_SIZE 12 +#define SM_CHIP_IDv2_SIZE 16 static ssize_t serial_show(struct device *dev, struct device_attribute *attr, char *buf) @@ -274,8 +275,59 @@ static ssize_t serial_show(struct device *dev, struct device_attribute *attr, static DEVICE_ATTR_RO(serial); +static ssize_t chipid_show(struct device *dev, struct device_attribute *attr, + char *buf) +{ + struct platform_device *pdev = to_platform_device(dev); + struct meson_sm_firmware *fw; + uint8_t *id_buf; + int ret; + + fw = platform_get_drvdata(pdev); + + id_buf = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); + if (!id_buf) + return -ENOMEM; + + ret = meson_sm_call_read(fw, id_buf, SM_CHIP_ID_LENGTH, SM_GET_CHIP_ID, + 2, 0, 0, 0, 0); + if (ret < 0) { + kfree(id_buf); + return ret; + } + + int version = *((unsigned int *)id_buf); + + if (version == 2) + ret = scnprintf(buf, PAGE_SIZE, "%16phN\n", &id_buf[SM_CHIP_ID_OFFSET]); + else { + /** + * Legacy 12-byte chip ID read out, transform data + * to expected order format. + */ + uint8_t *buff; + + buff = kmalloc(SM_CHIP_ID_LENGTH, GFP_KERNEL); + if (!buff) + return -ENOMEM; + ((uint32_t *)buff)[0] = 0; // CPU_ID is empty + /* Transform into expected order for display */ + ch = (uint8_t *)(id_buf + 4); + for (i = 0; i < 12; i++) + buff[i + 4] = ch[11 - i]; + ret = scnprintf(buf, PAGE_SIZE, "%16phN\n", &buff); + kfree(buff); + } + + kfree(id_buf); + return ret; +} + +static DEVICE_ATTR_RO(chipid); + static struct attribute *meson_sm_sysfs_attributes[] = { &dev_attr_serial.attr, + &dev_attr_chipid.attr, NULL, };
The Amlogic Meson SoC Secure Monitor implements a call to retrieve an unique CHIP ID with CPU ID (128 bits length) starting from the GX Family and all new families. The chipid string is simply exposed as a sysfs entry under the firmware sysfs directory. Signed-off-by: Viacheslav Bocharov <adeep@lexina.in> --- drivers/firmware/meson/meson_sm.c | 54 ++++++++++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-)