Skip to contentSkip to conversation

soc: qcom: Add SoC info driver

PATCH Superseded Imran Khan 3 participants 5 messages Oct 27, 2016 – Nov 2, 2016

Subsystems (2)

v2 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Imran Khan

author
#0 lore raw

PATCH v2 1/1 soc: qcom: Add SoC info driver

The SoC info driver provides information such as Chip ID, Chip family, serial number and other such details about Qualcomm SoCs.

---

Changes since v1:
- Removed inclusion of system_misc.h
- merged socinfo.h into socinfo.c
- made platform type and subtype arrays static
- replaced uint32_t with u32
- made functions static to avoid exposing vendor specific interface
- Replaced usage of IS_ERR_OR_NULL with IS_ERR.
- Remove raw-id attribute usage as human readable soc-id will suffice here
- Avoid using a separate platform driver for socinfo by rolling it into smem driver itself. The sysfs setup is being done in a separate file (socinfo.c)
- Replaced macro BUILD_ID_LENGTH with SMEM_SOCINFO_BUILD_ID_LENGTH.
- For failure cases where socinfo can not be read use a single dummy socinfo with error values.
- Removed usage of early_machine_is_xxx.

 drivers/soc/qcom/smem.c       |   18 +-
 drivers/soc/qcom/socinfo.c    | 1224 +++++++++++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/smem.h |    3 +-
 3 files changed, 1243 insertions(+), 2 deletions(-)
 create mode 100644 drivers/soc/qcom/socinfo.c
drivers/soc/qcom/smem.c +17 -1
index 18ec52f..c7244a0 100644
@@ -85,6 +85,12 @@
 /* Max number of processors/hosts in a system */
 #define SMEM_HOST_COUNT		9
 
+/*
+ * Shared memory identifiers, used to acquire handles to respective memory
+ * region.
+ */
+#define SMEM_HW_SW_BUILD_ID		137
+
 /**
   * struct smem_proc_comm - proc_comm communication struct (legacy)
   * @command:	current command to be executed
@@ -695,7 +701,8 @@ static int qcom_smem_probe(struct platform_device *pdev)
 {
 	struct smem_header *header;
 	struct qcom_smem *smem;
-	size_t array_size;
+	void *socinfo;
+	size_t array_size, size;
 	int num_regions;
 	int hwlock_id;
 	u32 version;
@@ -751,6 +758,15 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
 	__smem = smem;
 
+	socinfo = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID,
+			&size);
+	if (IS_ERR(socinfo)) {
+		dev_warn(&pdev->dev,
+			"Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n");
+		socinfo = setup_dummy_socinfo();
+	}
+	qcom_socinfo_init(socinfo);
+
 	return 0;
 }
 
drivers/soc/qcom/socinfo.c new file +1224 -0

1,224 lines not on this page · raw message

include/linux/soc/qcom/smem.h +2 -1
index 785e196..d080500 100644
@@ -7,5 +7,6 @@
 void *qcom_smem_get(unsigned host, unsigned item, size_t *size);
 
 int qcom_smem_get_free_space(unsigned host);
-
+int qcom_socinfo_init(void *info);
+void *setup_dummy_socinfo(void);
 #endif
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw
url: https://github.com/0day-ci/linux/commits/Imran-Khan/soc-qcom-Add-SoC-info-driver/20161027-223213 config: arm64-defconfig (attached as .config) compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9)…

Hi Imran,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.9-rc2 next-20161027]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]

url: https://github.com/0day-ci/linux/commits/Imran-Khan/soc-qcom-Add-SoC-info-driver/20161027-223213
config: arm64-defconfig (attached as .config)
compiler: aarch64-linux-gnu-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm64

All errors (new ones prefixed by >>):

drivers/built-in.o: In function `qcom_smem_probe':

>> drivers/soc/qcom/smem.c:768: undefined reference to `qcom_socinfo_init'
   drivers/soc/qcom/smem.c:768:(.text+0xf2438): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `qcom_socinfo_init'
>> drivers/soc/qcom/smem.c:766: undefined reference to `setup_dummy_socinfo'
   drivers/soc/qcom/smem.c:766:(.text+0xf24d8): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `setup_dummy_socinfo'
>> drivers/soc/qcom/smem.c:768: undefined reference to `qcom_socinfo_init'

drivers/soc/qcom/smem.c:768:(.text+0xf24dc): relocation truncated to fit: R_AARCH64_CALL26 against undefined symbol `qcom_socinfo_init'

vim +768 drivers/soc/qcom/smem.c

760
761 socinfo = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID,
762 &size);
763 if (IS_ERR(socinfo)) {
764 dev_warn(&pdev->dev,
765 "Can't find SMEM_HW_SW_BUILD_ID; falling back on dummy values.\n");

 > 766			socinfo = setup_dummy_socinfo();
   767		}
 > 768		qcom_socinfo_init(socinfo);

769
770 return 0;
771 }

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#2 lore raw
In reply to Imran Khan
url: https://github.com/0day-ci/linux/commits/Imran-Khan/soc-qcom-Add-SoC-info-driver/20161027-223213 config: arm-multi_v7_defconfig (attached as .config) compiler: arm-linux-gnueabi-gcc (Debian…

Hi Imran,

[auto build test ERROR on linus/master]
[also build test ERROR on v4.9-rc2 next-20161027]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]
[Suggest to use git(>=2.9.0) format-patch --base=<commit> (or --base=auto for convenience) to record what (public, well-known) commit your patch series was built on] [Check https://git-scm.com/docs/git-format-patch for more information]

url: https://github.com/0day-ci/linux/commits/Imran-Khan/soc-qcom-Add-SoC-info-driver/20161027-223213
config: arm-multi_v7_defconfig (attached as .config)
compiler: arm-linux-gnueabi-gcc (Debian 6.1.1-9) 6.1.1 20160705
reproduce:
wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross chmod +x ~/bin/make.cross
# save the attached .config to linux build tree
make.cross ARCH=arm

All errors (new ones prefixed by >>):

drivers/built-in.o: In function `qcom_smem_probe':

>> sunxi_sid.c:(.text+0x113160): undefined reference to `qcom_socinfo_init'
>> sunxi_sid.c:(.text+0x1132d8): undefined reference to `setup_dummy_socinfo'

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#3 lore raw
In reply to Imran Khan
Quoted 5 lines · Imran Khan

The SoC info driver provides information such as Chip ID, Chip family, serial number and other such details about Qualcomm SoCs.

I like this patch. It is good to know stuff about the hardware.

(...)

Quoted 1 line

+++ b/drivers/soc/qcom/socinfo.c

(...)

drivers/soc/qcom/socinfo.c line 27

Quoted 6 lines
drivers/soc/qcom/socinfo.c new file +6 -0
+#include <linux/export.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/sys_soc.h>

Uses <linux/sys_soc.h> so you should definately get Lee Jones to review this.

Quoted 34 lines
drivers/soc/qcom/socinfo.c new file +34 -0
+/*
+ * Qcom SoC IDs
+ */
+enum qcom_cpu_id {
+       MSM_UNKNOWN_ID,
+       MSM_8960_ID = 87,
+       APQ_8064_ID = 109,
+       MSM_8660A_ID = 122,
+       MSM_8260A_ID,
+       APQ_8060A_ID,
+       MSM_8974_ID = 126,
+       MPQ_8064_ID = 130,
+       MSM_8960AB_ID = 138,
+       APQ_8060AB_ID,
+       MSM_8260AB_ID,
+       MSM_8660AB_ID,
+       APQ_8084_ID = 178,
+       APQ_8074_ID = 184,
+       MSM_8274_ID,
+       MSM_8674_ID,
+       MSM_8974PRO_ID = 194,
+       MSM_8916_ID = 206,
+       APQ_8074_AA_ID = 208,
+       APQ_8074_AB_ID,
+       APQ_8074PRO_ID,
+       MSM_8274_AA_ID,
+       MSM_8274_AB_ID,
+       MSM_8274PRO_ID,
+       MSM_8674_AA_ID,
+       MSM_8674_AB_ID,
+       MSM_8674PRO_ID,
+       MSM_8974_AA_ID,
+       MSM_8974_AB_ID,
+       MSM_8996_ID = 246,

drivers/soc/qcom/socinfo.c line 126

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+       APQ_8016_ID,
+       MSM_8216_ID,
+       MSM_8116_ID,
+       MSM_8616_ID,
+       APQ8096_ID = 291,
+       MSM_8996SG_ID = 305,
+       MSM_8996AU_ID = 310,
+       APQ_8096AU_ID,
+       APQ_8096SG_ID
+};

Seems to support everything and its dog. Good job!

Now I guess I first have to support smem on my pet peeves (MSM8660 and APQ8060) for this to work.

drivers/soc/qcom/socinfo.c line 161

Quoted 12 lines
drivers/soc/qcom/socinfo.c new file +12 -0
+enum hw_platform_type {
+       HW_PLATFORM_UNKNOWN,
+       HW_PLATFORM_SURF,
+       HW_PLATFORM_FFA,
+       HW_PLATFORM_FLUID,
+       HW_PLATFORM_SVLTE_FFA,
+       HW_PLATFORM_SVLTE_SURF,
+       HW_PLATFORM_MTP_MDM = 7,
+       HW_PLATFORM_MTP,
+       HW_PLATFORM_LIQUID,
+       /* Dragonboard platform id is assigned as 10 in CDT */
+       HW_PLATFORM_DRAGON,

I guess that is not "my" dragonboard generation 1 with the APQ8060 but rather the APQ8074 Dragonboard?

Is mine just a variant of SURF then... I dunno. Will be interesting to see what number it has in its hardware.

Quoted 1 line

+#ifdef CONFIG_SOC_BUS

Why not just select that in Kconfig and get rid of this #ifdef?

Quoted 8 lines
drivers/soc/qcom/socinfo.c new file +8 -0
+int qcom_socinfo_init(void *info)
+{
+       socinfo = info;
+
+       socinfo_select_format();
+
+       WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
+

drivers/soc/qcom/socinfo.c line 1223

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+       WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
+               "New IDs added! ID => CPU mapping needs an update.\n");
+
+       socinfo_print();
+
+       socinfo_init_sysfs();
+
+       return 0;
+}
+EXPORT_SYMBOL(qcom_socinfo_init);

So something I've been adding to drivers that handle any kind of device-unique numbers is:

#include <linux/random.h>

/* Toss the unique data into the entropy pool */
add_device_randomness(buf, sizeof(buf));

Can you do this here in init() with the register that are *device unique* because I guess not all of them are?

Yours,
Linus Walleij

author
#4 lore raw
Quoted 10 lines · Linus Walleij
Quoted 5 lines · Imran Khan

The SoC info driver provides information such as Chip ID, Chip family, serial number and other such details about Qualcomm SoCs.

I like this patch. It is good to know stuff about the hardware.

Thanks Linus for the review comments.

Quoted 13 lines

(...)

Quoted 1 line

+++ b/drivers/soc/qcom/socinfo.c

(...)

drivers/soc/qcom/socinfo.c line 27

Quoted 6 lines
drivers/soc/qcom/socinfo.c new file +6 -0
+#include <linux/export.h>
+#include <linux/module.h>
+#include <linux/err.h>
+#include <linux/of.h>
+#include <linux/platform_device.h>
+#include <linux/sys_soc.h>

Uses <linux/sys_soc.h> so you should definately get Lee Jones to review this.

Okay. Will add Lee Jones while sending future patch sets.

Quoted 47 lines
Quoted 34 lines
drivers/soc/qcom/socinfo.c new file +34 -0
+/*
+ * Qcom SoC IDs
+ */
+enum qcom_cpu_id {
+       MSM_UNKNOWN_ID,
+       MSM_8960_ID = 87,
+       APQ_8064_ID = 109,
+       MSM_8660A_ID = 122,
+       MSM_8260A_ID,
+       APQ_8060A_ID,
+       MSM_8974_ID = 126,
+       MPQ_8064_ID = 130,
+       MSM_8960AB_ID = 138,
+       APQ_8060AB_ID,
+       MSM_8260AB_ID,
+       MSM_8660AB_ID,
+       APQ_8084_ID = 178,
+       APQ_8074_ID = 184,
+       MSM_8274_ID,
+       MSM_8674_ID,
+       MSM_8974PRO_ID = 194,
+       MSM_8916_ID = 206,
+       APQ_8074_AA_ID = 208,
+       APQ_8074_AB_ID,
+       APQ_8074PRO_ID,
+       MSM_8274_AA_ID,
+       MSM_8274_AB_ID,
+       MSM_8274PRO_ID,
+       MSM_8674_AA_ID,
+       MSM_8674_AB_ID,
+       MSM_8674PRO_ID,
+       MSM_8974_AA_ID,
+       MSM_8974_AB_ID,
+       MSM_8996_ID = 246,

drivers/soc/qcom/socinfo.c line 126

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+       APQ_8016_ID,
+       MSM_8216_ID,
+       MSM_8116_ID,
+       MSM_8616_ID,
+       APQ8096_ID = 291,
+       MSM_8996SG_ID = 305,
+       MSM_8996AU_ID = 310,
+       APQ_8096AU_ID,
+       APQ_8096SG_ID
+};

Seems to support everything and its dog. Good job!

Quoted 3 lines

Now I guess I first have to support smem on my pet peeves (MSM8660 and APQ8060) for this to work.

Yes. Actually socinfo is one of the smem items and can be accessed only via smem interface.

Quoted 13 lines

drivers/soc/qcom/socinfo.c line 161

Quoted 12 lines
drivers/soc/qcom/socinfo.c new file +12 -0
+enum hw_platform_type {
+       HW_PLATFORM_UNKNOWN,
+       HW_PLATFORM_SURF,
+       HW_PLATFORM_FFA,
+       HW_PLATFORM_FLUID,
+       HW_PLATFORM_SVLTE_FFA,
+       HW_PLATFORM_SVLTE_SURF,
+       HW_PLATFORM_MTP_MDM = 7,
+       HW_PLATFORM_MTP,
+       HW_PLATFORM_LIQUID,
+       /* Dragonboard platform id is assigned as 10 in CDT */
+       HW_PLATFORM_DRAGON,
Quoted 3 lines

I guess that is not "my" dragonboard generation 1 with the APQ8060 but rather the APQ8074 Dragonboard?

Let me check this and get back to you.

Quoted 7 lines

Is mine just a variant of SURF then... I dunno. Will be interesting to see what number it has in its hardware.

Quoted 1 line

+#ifdef CONFIG_SOC_BUS

Why not just select that in Kconfig and get rid of this #ifdef?

As far as socinfo driver is concerned, it's main purpose is to read some information already latched in smem. So instead of having a separate platform driver, we have just rolled this into smem driver itself. On the other hand it may not be necessary to expose the socinfo to user space via sysfs so we may have a kernel config with QCOM_SMEM enabled while SOC_BUS not enabled at the same time and in such cases this #ifdef becomes useful. That's why instead of making entire socinfo.c dependent on CONFIG_SOC_BUS, we are just making a part of this file dependent on this flag.
Please let me know if you have some suggestion to improve on this.

Quoted 22 lines
Quoted 8 lines
drivers/soc/qcom/socinfo.c new file +8 -0
+int qcom_socinfo_init(void *info)
+{
+       socinfo = info;
+
+       socinfo_select_format();
+
+       WARN(!socinfo_get_id(), "Unknown SOC ID!\n");
+

drivers/soc/qcom/socinfo.c line 1223

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+       WARN(socinfo_get_id() >= ARRAY_SIZE(cpu_of_id),
+               "New IDs added! ID => CPU mapping needs an update.\n");
+
+       socinfo_print();
+
+       socinfo_init_sysfs();
+
+       return 0;
+}
+EXPORT_SYMBOL(qcom_socinfo_init);

So something I've been adding to drivers that handle any kind of device-unique numbers is:

Quoted 8 lines

#include <linux/random.h>

/* Toss the unique data into the entropy pool */
add_device_randomness(buf, sizeof(buf));

Can you do this here in init() with the register that are *device unique* because I guess not all of them are?

The socinfo item that we obtain from smem here will be unique to each soc and I have added support to feed this data into entropy pool. This change will be available in next patch set.

--Imran

Quoted 3 lines

Yours,
Linus Walleij

Signature · 1 line
QUALCOMM INDIA, on behalf of Qualcomm Innovation Center, Inc. is a\nmember of the Code Aurora Forum, hosted by The Linux Foundation