Skip to contentSkip to conversation

soc: qcom: Add SoC info driver

PATCH Superseded Imran Khan 2 participants 4 messages Jan 10, 2017 – Feb 16, 2017

Subsystems (2)

v8 of 10 Superseded Latest is v10 →

lore
Share & tools
lore

Imran Khan

author
#0 lore raw

PATCH v8 1/2 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 to user space, so that if needed some user space utility(like antutu) can query such information using sysfs interface.

---

v7 --> v8:
- Fixed compilation warning detected in v7
v6 --> v7:
- Some minor style changes
- Rather than showing string for h/w types, just show the number obtained from SMEM. The reader of this number is supposed to parse this into a human readable string as this information may be different for different ODMs
- Create an attribute 'qcom_odm' depending on the presence of corresponding property in SMEM DT entry. This information can be used for ODM specific interpretation of SMEM socinfo content
- Read machine value from DT, rather than using soc-id as index in an ever increasing array of machine names

v5 --> v6:
- use dev_ext_attribute to represent SMEM image items
- Avoid redundant function calls
- Avoid use of unnecessary global variables
- Remove redundant enums
- Avoid redundant checking of socinfo being NULL or not
- Avoid redundant checking of socinfo format version
- Rename show/store function of attributes as _show/_store rather than _get/_set
- Use an array to represent socinfo attributes and create attribute files in a loop depending on the minimum socinfo format version for which these attributes are supported
- if obtained socinfo format version is greater than the maximum known version return an error rather than falling back to maximum known version

v4 --> v5:
- Removed redundant function socinfo_print

v3 --> v4:
- Corrected makefile so that smem and socinfo are treated as one module
- Moved the code snippet to get socinfo smem item into socinfo.c
- Removed redundant use of socinfo major version as it is always zero
- Removed unused enums
- Removed redundant indirections
- Use image_version object to store information about each entry in the smem image table
- Replaced usage of snprintf with sprintf and scnprintf
- Get the address of image version table at the beginning and setup image version attributes only if image version table is available
- Do the same for platform_subtype
- Make different type of image version objects read only or readable/ writable depending on their types. For example apps image attributes can be modified via sysfs but the same can't be done for modem image
- Show PMIC model in a human readable form rather than a numeric number
- Avoid using table in single sysfs entry
- Removed checkpatch warnings about S_IRUGO

v2 --> v3:
- Add support to toss soc information data into entropy pool
- Since socinfo is rolled into smem driver, compile the relevant portion of socinfo driver with smem driver

v1 --> v2:
- 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/Kconfig   |   1 +
 drivers/soc/qcom/Makefile  |   3 +-
 drivers/soc/qcom/smem.c    |   5 +
 drivers/soc/qcom/socinfo.c | 516 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 524 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soc/qcom/socinfo.c
drivers/soc/qcom/Kconfig +1 -0
index 461b387..f89d34d 100644
@@ -24,6 +24,7 @@ config QCOM_SMEM
 	tristate "Qualcomm Shared Memory Manager (SMEM)"
 	depends on ARCH_QCOM
 	depends on HWSPINLOCK
+	select SOC_BUS
 	help
 	  Say y here to enable support for the Qualcomm Shared Memory Manager.
 	  The driver provides an interface to items in a heap shared among all
drivers/soc/qcom/Makefile +2 -1
index fdd664e..438efec 100644
@@ -2,7 +2,8 @@ obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_PM)	+=	spm.o
 obj-$(CONFIG_QCOM_SMD) +=	smd.o
 obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
-obj-$(CONFIG_QCOM_SMEM) +=	smem.o
+obj-$(CONFIG_QCOM_SMEM) +=	qcom_smem.o
+qcom_smem-y := smem.o socinfo.o
 obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
 obj-$(CONFIG_QCOM_SMP2P)	+= smp2p.o
 obj-$(CONFIG_QCOM_SMSM)	+= smsm.o
drivers/soc/qcom/smem.c +5 -0
index 18ec52f..4f0ccf8 100644
@@ -85,6 +85,9 @@
 /* Max number of processors/hosts in a system */
 #define SMEM_HOST_COUNT		9
 
+
+extern void qcom_socinfo_init(struct device *device);
+
 /**
   * struct smem_proc_comm - proc_comm communication struct (legacy)
   * @command:	current command to be executed
@@ -751,6 +754,8 @@ static int qcom_smem_probe(struct platform_device *pdev)
 
 	__smem = smem;
 
+	qcom_socinfo_init(&pdev->dev);
+
 	return 0;
 }
 
drivers/soc/qcom/socinfo.c new file +516 -0

516 lines not on this page · raw message

Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
#1 lore raw

drivers/soc/qcom/socinfo.c line 2

Quoted 8 lines · Imran Khan
drivers/soc/qcom/socinfo.c new file +2 -0
new file mode 100644
index 0000000..40c180d
@@ -0,0 +1,516 @@
+/*
+ * Copyright (c) 2009-2016, The Linux Foundation. All rights reserved.

Sorry for the slow progress, please bump the year now.

[..]

Quoted 7 lines
drivers/soc/qcom/socinfo.c new file +7 -0
+
+static const char *const pmic_model[] = {
+	[0]  = "Unknown PMIC model",
+	[13] = "PM8058",
+	[14] = "PM8028",
+	[15] = "PM8901",
+	[16] = "PM8027",

drivers/soc/qcom/socinfo.c line 117

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+	[17] = "ISL9519",
+	[18] = "PM8921",
+	[19] = "PM8018",
+	[20] = "PM8015",
+	[21] = "PM8014",
+	[22] = "PM8821",
+	[23] = "PM8038",
+	[24] = "PM8922",
+	[25] = "PM8917",
+};

I thought the conclusion was to drop the "hw_platform", "qrd_hw_platform_subtype" and hw_platform_subtype" lists, but to keep the cpu_of_id (although named soc_of_id).

The hw_platform ids are re-used by ODMs and might have different meaning, but the SoC name is quite useful. So please put the soc_of_id back in here.

[..]

drivers/soc/qcom/socinfo.c line 223

Quoted 7 lines
drivers/soc/qcom/socinfo.c new file +7 -0
+
+static ssize_t
+qcom_odm_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "%s\n", odm_name);
+}
+DEVICE_ATTR_RO(qcom_odm);

In the case that ODMs will start using this implementation for communicating information to user-space I believe a name will not be enough - most likely there would be some product name and some revision/build information.

My suggestion is that you just skip the "odm" attribute in your patch, this gives a good opportunity for the ODMs to make a simple contribution of what they actually want here.

[..]

Quoted 11 lines
drivers/soc/qcom/socinfo.c new file +11 -0
+
+void qcom_socinfo_init(struct device *device)
+{
+	struct soc_device_attribute *attr;
+	const struct fdt_property *prop;
+	struct soc_device *soc_dev;
+	struct device *dev;
+	size_t item_size;
+	size_t size;
+	int i;
+

drivers/soc/qcom/socinfo.c line 450

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+	socinfo = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID,
+			&item_size);
+	if (IS_ERR(socinfo)) {
+		dev_err(device, "Coudn't find socinfo\n");
+		return;
+	}
+
+	if ((SOCINFO_VERSION_MAJOR(le32_to_cpu(socinfo->v0_1.fmt)) != 0) ||
+	(SOCINFO_VERSION_MINOR(le32_to_cpu(socinfo->v0_1.fmt)) < 0) ||
+	(le32_to_cpu(socinfo->v0_1.fmt) > MAX_SOCINFO_FORMAT)) {

Indent wrapped lines by the start parenthesis and skip the extra parenthesis please.

I.e.

if (... ||
    ... ||
    ...) {
Quoted 4 lines
drivers/soc/qcom/socinfo.c new file +4 -0
+		dev_err(device, "Wrong socinfo format\n");
+		return;
+	}
+

[..]

drivers/soc/qcom/socinfo.c line 511

Quoted 4 lines
drivers/soc/qcom/socinfo.c new file +4 -0
+
+	odm_name = of_get_property(device->of_node, "qcom,odm", NULL);
+	if (odm_name)
+		device_create_file(dev, &dev_attr_qcom_odm);

Skip this for now.

drivers/soc/qcom/socinfo.c line 516

Quoted 5 lines
drivers/soc/qcom/socinfo.c new file +5 -0
+
+	/* Feed the soc specific unique data into entropy pool */
+	add_device_randomness(socinfo, item_size);
+}
+EXPORT_SYMBOL(qcom_socinfo_init);

Please add me as To: on the next spin of your patch so I don't miss it on the mailing list. I do expect to be able to recommend Andy to merge that version.

Regards,
Bjorn

author
#2 lore raw
Quoted 13 lines · Bjorn Andersson

drivers/soc/qcom/socinfo.c line 2

Quoted 8 lines · Imran Khan
drivers/soc/qcom/socinfo.c new file +2 -0
new file mode 100644
index 0000000..40c180d
@@ -0,0 +1,516 @@
+/*
+ * Copyright (c) 2009-2016, The Linux Foundation. All rights reserved.

Sorry for the slow progress, please bump the year now.

Sure, Will update the year.

Quoted 23 lines

[..]

Quoted 7 lines
drivers/soc/qcom/socinfo.c new file +7 -0
+
+static const char *const pmic_model[] = {
+	[0]  = "Unknown PMIC model",
+	[13] = "PM8058",
+	[14] = "PM8028",
+	[15] = "PM8901",
+	[16] = "PM8027",

drivers/soc/qcom/socinfo.c line 117

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+	[17] = "ISL9519",
+	[18] = "PM8921",
+	[19] = "PM8018",
+	[20] = "PM8015",
+	[21] = "PM8014",
+	[22] = "PM8821",
+	[23] = "PM8038",
+	[24] = "PM8922",
+	[25] = "PM8917",
+};

I thought the conclusion was to drop the "hw_platform", "qrd_hw_platform_subtype" and hw_platform_subtype" lists, but to keep the cpu_of_id (although named soc_of_id).

Quoted 4 lines

The hw_platform ids are re-used by ODMs and might have different meaning, but the SoC name is quite useful. So please put the soc_of_id back in here.

cpu_of_id was mapping soc-id read from SMEM into SoC name, which in turn was being used as machine name in soc_device_attribute. But we can also read machine name from DT. Reading the machine name from DT would make the solution more flexible as we don't have to make an entry in soc_of_id every time we get a new SoC.
Also as soc_of_id uses soc-id as index, there is theoretically no limit on how many elements it may end up having.
Because of the above reasons, I wanted to get rid off soc_of_id (or cpu_of_id) array and use DT to get machine name as shown in the following snippet:

+ attr->family = "Snapdragon";
+ prop = fdt_get_property(initial_boot_params, 0, "model", NULL);
+ if (prop)
+ attr->machine = kasprintf(GFP_KERNEL, "%s", prop->data);

Could you please let me know if this approach looks fine to you?

Quoted 14 lines

[..]

drivers/soc/qcom/socinfo.c line 223

Quoted 7 lines
drivers/soc/qcom/socinfo.c new file +7 -0
+
+static ssize_t
+qcom_odm_show(struct device *dev, struct device_attribute *attr, char *buf)
+{
+	return scnprintf(buf, PAGE_SIZE, "%s\n", odm_name);
+}
+DEVICE_ATTR_RO(qcom_odm);

In the case that ODMs will start using this implementation for communicating information to user-space I believe a name will not be enough - most likely there would be some product name and some revision/build information.

Quoted 5 lines

My suggestion is that you just skip the "odm" attribute in your patch, this gives a good opportunity for the ODMs to make a simple contribution of what they actually want here.

[..]

Okay, will skip the odm attribute.

Quoted 38 lines
Quoted 11 lines
drivers/soc/qcom/socinfo.c new file +11 -0
+
+void qcom_socinfo_init(struct device *device)
+{
+	struct soc_device_attribute *attr;
+	const struct fdt_property *prop;
+	struct soc_device *soc_dev;
+	struct device *dev;
+	size_t item_size;
+	size_t size;
+	int i;
+

drivers/soc/qcom/socinfo.c line 450

Quoted 10 lines
drivers/soc/qcom/socinfo.c new file +10 -0
+	socinfo = qcom_smem_get(QCOM_SMEM_HOST_ANY, SMEM_HW_SW_BUILD_ID,
+			&item_size);
+	if (IS_ERR(socinfo)) {
+		dev_err(device, "Coudn't find socinfo\n");
+		return;
+	}
+
+	if ((SOCINFO_VERSION_MAJOR(le32_to_cpu(socinfo->v0_1.fmt)) != 0) ||
+	(SOCINFO_VERSION_MINOR(le32_to_cpu(socinfo->v0_1.fmt)) < 0) ||
+	(le32_to_cpu(socinfo->v0_1.fmt) > MAX_SOCINFO_FORMAT)) {

Indent wrapped lines by the start parenthesis and skip the extra parenthesis please.

I.e.

if (... ||
    ... ||
    ...) {
Quoted 4 lines
drivers/soc/qcom/socinfo.c new file +4 -0
+		dev_err(device, "Wrong socinfo format\n");
+		return;
+	}
+

[..]

Quoted 7 lines

drivers/soc/qcom/socinfo.c line 511

Quoted 4 lines
drivers/soc/qcom/socinfo.c new file +4 -0
+
+	odm_name = of_get_property(device->of_node, "qcom,odm", NULL);
+	if (odm_name)
+		device_create_file(dev, &dev_attr_qcom_odm);

Skip this for now.

Okay.

Quoted 10 lines

drivers/soc/qcom/socinfo.c line 516

Quoted 5 lines
drivers/soc/qcom/socinfo.c new file +5 -0
+
+	/* Feed the soc specific unique data into entropy pool */
+	add_device_randomness(socinfo, item_size);
+}
+EXPORT_SYMBOL(qcom_socinfo_init);

Please add me as To: on the next spin of your patch so I don't miss it on the mailing list. I do expect to be able to recommend Andy to merge that version.

Quoted 2 lines

Regards,
Bjorn

Sure. Will send the next patch set once I have confirmation of the above query.

Thanks and Regards,
Imran

Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

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
#3 lore raw
Quoted 1 line · Imran Khan

On 2/15/2017 5:54 AM, Bjorn Andersson wrote:

[..]

Quoted 10 lines
Quoted 9 lines

I thought the conclusion was to drop the "hw_platform", "qrd_hw_platform_subtype" and hw_platform_subtype" lists, but to keep the cpu_of_id (although named soc_of_id).

The hw_platform ids are re-used by ODMs and might have different meaning, but the SoC name is quite useful. So please put the soc_of_id back in here.

Quoted 5 lines

cpu_of_id was mapping soc-id read from SMEM into SoC name, which in turn was being used as machine name in soc_device_attribute. But we can also read machine name from DT. Reading the machine name from DT would make the solution more flexible as we don't have to make an entry in soc_of_id every time we get a new SoC.

I don't think we need a more flexible solution, as the purpose of this driver is to expose the socinfo information to user space; i.e. there's nothing flexible about that.

If we just expose this information as a proprietary magic number, then it will be up to each consumer to keep some mapping table. So you will not get rid of the work of keeping things updated, you will just push the problem to somewhere else.

Quoted 2 lines

Also as soc_of_id uses soc-id as index, there is theoretically no limit on how many elements it may end up having.

There's a practical - and reasonable - limit on how much space this data will take, one could however argue that it's unwise to keep the sparse data in a simple array. A better solution would be to maintain an array of id,soc pairs and loop through that on lookup.

drivers/soc/qcom/socinfo.c line 475

Quoted 7 lines

Because of the above reasons, I wanted to get rid off soc_of_id (or cpu_of_id) array and use DT to get machine name as shown in the following snippet:

drivers/soc/qcom/socinfo.c new file +4 -0
+	attr->family = "Snapdragon";
+	prop = fdt_get_property(initial_boot_params, 0, "model", NULL);
+	if (prop)
+		attr->machine = kasprintf(GFP_KERNEL, "%s", prop->data);

The data is already in socinfo, we should not manually duplicate it in DT.

Quoted 3 lines

Could you please let me know if this approach looks fine to you?

I would prefer that the socinfo doesn't expose magic numbers without a publicly available lookup table. And I don't see a need for the added flexibility.

Regards,
Bjorn