Skip to contentSkip to conversation

drivers/qcom: add Command DB support

PATCH Superseded Lina Iyer 5 participants 16 messages Feb 26, 2018 – Mar 16, 2018

Subsystems (4)

v4 of 8 Superseded Latest is v8 →

lore
Share & tools
lore

Lina Iyer

author
#0 lore raw

v4 cover drivers/qcom: add Command DB support

Changes in v3:
- DT binding documentation fixes as suggested by Rob.

These patches add support for reading a shared memory database in the newer QCOM SoCs called Command DB. With the new architecture on SDM845, shared resources like clocks, regulators etc., have dynamic properties. These properties may change based on external components, board configurations or available feature set. A remote processor detects these parameters and fills up the database with the resource and available state information. Platform drivers that need these shared resources will need to query this database to get the address and properties and vote for the state.

The information in the database is static. The database is read-only memory location that is available for Linux. A pre-defined string is used as a key into an entry in the database. Generally, platform drivers query the database only at init to get the information they need.

[v1]: https://www.spinics.net/lists/linux-arm-msm/msg32462.html
[v2]: https://lkml.org/lkml/2018/2/8/588
[v3]: https://lkml.org/lkml/2018/2/16/842

Lina Iyer (2):
drivers: qcom: add command DB driver
dt-bindings: introduce Command DB for QCOM SoCs

 .../devicetree/bindings/arm/msm/cmd-db.txt         |  38 +++
 drivers/of/platform.c                              |   1 +
 drivers/soc/qcom/Kconfig                           |   9 +
 drivers/soc/qcom/Makefile                          |   1 +
 drivers/soc/qcom/cmd-db.c                          | 319 +++++++++++++++++++++
 include/soc/qcom/cmd-db.h                          |  50 ++++
 6 files changed, 418 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/cmd-db.txt
 create mode 100644 drivers/soc/qcom/cmd-db.c
 create mode 100644 include/soc/qcom/cmd-db.h

--
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project

author
#1 lore raw

PATCH v4 1/2 drivers: qcom: add command DB driver

From: Mahesh Sivasubramanian <[email protected]>

Command DB is a simple database in the shared memory of QCOM SoCs, that provides information regarding shared resources. Some shared resources in the SoC have properties that are probed dynamically at boot by the remote processor. The information pertaining to the SoC and the platform are made available in the shared memory. Drivers can query this information using predefined strings.

---
 drivers/of/platform.c     |   1 +
 drivers/soc/qcom/Kconfig  |   9 ++
 drivers/soc/qcom/Makefile |   1 +
 drivers/soc/qcom/cmd-db.c | 319 ++++++++++++++++++++++++++++++++++++++++++++++
 include/soc/qcom/cmd-db.h |  50 ++++++++
 5 files changed, 380 insertions(+)
 create mode 100644 drivers/soc/qcom/cmd-db.c
 create mode 100644 include/soc/qcom/cmd-db.h
drivers/of/platform.c +1 -0
index c00d81dfac0b..26fb43847f4b 100644
@@ -494,6 +494,7 @@ EXPORT_SYMBOL_GPL(of_platform_default_populate);
 #ifndef CONFIG_PPC
 static const struct of_device_id reserved_mem_matches[] = {
 	{ .compatible = "qcom,rmtfs-mem" },
+	{ .compatible = "qcom,cmd-db" },
 	{ .compatible = "ramoops" },
 	{}
 };
drivers/soc/qcom/Kconfig +9 -0
index e050eb83341d..b12868a2b92d 100644
@@ -3,6 +3,15 @@
 #
 menu "Qualcomm SoC drivers"
 
+config QCOM_COMMAND_DB
+	bool "Qualcomm Command DB"
+	depends on (ARCH_QCOM && OF) || COMPILE_TEST
+	help
+	  Command DB queries shared memory by key string for shared system
+	  resources. Platform drivers that require to set state of a shared
+	  resource on a RPM-hardened platform must use this database to get
+	  SoC specific identifier and information for the shared resources.
+
 config QCOM_GLINK_SSR
 	tristate "Qualcomm Glink SSR driver"
 	depends on RPMSG
drivers/soc/qcom/Makefile +1 -0
index dcebf2814e6d..bbd1230fc441 100644
@@ -1,4 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_QCOM_COMMAND_DB) += cmd-db.o
 obj-$(CONFIG_QCOM_GLINK_SSR) +=	glink_ssr.o
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
drivers/soc/qcom/cmd-db.c new file +319 -0

319 lines not on this page · raw message

include/soc/qcom/cmd-db.h new file +50 -0

50 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
#2 lore raw

Re: [PATCH v4 1/2] drivers: qcom: add command DB driver

Quoting Lina Iyer (2018-02-26 09:58:01)

Quoted 12 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
new file mode 100644
index 000000000000..0792a2a98fc9
@@ -0,0 +1,319 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. */
+
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_address.h>

drivers/soc/qcom/cmd-db.c line 16

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+#include <linux/of_platform.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
+
+#include <soc/qcom/cmd-db.h>
+
+#define NUM_PRIORITY           2
+#define MAX_SLV_ID             8
+#define CMD_DB_MAGIC           0x0C0330DBUL

Make this an array so it's endian safe.

drivers/soc/qcom/cmd-db.c line 29

Quoted 13 lines
drivers/soc/qcom/cmd-db.c new file +13 -0
+#define SLAVE_ID_MASK          0x7
+#define SLAVE_ID_SHIFT         16
+
+#define ENTRY_HEADER(hdr)      ((void *)cmd_db_header +        \
+                               sizeof(*cmd_db_header) +        \
+                               hdr->header_offset)
+
+#define RSC_OFFSET(hdr, ent)   ((void *)cmd_db_header +        \
+                               sizeof(*cmd_db_header) +        \
+                               hdr.data_offset + ent.offset)
+
+/**
+ * entry_header: header for each entry in cmddb

struct entry_header - header for each...

drivers/soc/qcom/cmd-db.c line 35

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+ *
+ * @id: resource's identifier
+ * @priority: unused
+ * @addr: the address of the resource
+ * @len: length of the data
+ * @offset: offset at which data starts

offset from this entry header at which data starts? Or offset from where?

drivers/soc/qcom/cmd-db.c line 46

Quoted 11 lines
drivers/soc/qcom/cmd-db.c new file +11 -0
+ */
+struct entry_header {
+       u64 id;
+       u32 priority[NUM_PRIORITY];
+       u32 addr;
+       u16 len;
+       u16 offset;
+};
+
+/**
+ * rsc_hdr: resource header information

ditto.

drivers/soc/qcom/cmd-db.c line 50

Quoted 4 lines
drivers/soc/qcom/cmd-db.c new file +4 -0
+ *
+ * @slv_id: id for the resource
+ * @header_offset: Entry header offset from data
+ * @data_offset: Entry offset for data location

Same question: offset from where?

drivers/soc/qcom/cmd-db.c line 52

Quoted 2 lines
drivers/soc/qcom/cmd-db.c new file +2 -0
+ * @cnt: number of entries for HW type
+ * @version: MSB is major, LSB is minor

@reserved: reserved for future use

Quoted 15 lines
drivers/soc/qcom/cmd-db.c new file +15 -0
+ */
+struct rsc_hdr {
+       u16 slv_id;
+       u16 header_offset;
+       u16 data_offset;
+       u16 cnt;
+       u16 version;
+       u16 reserved[3];
+};
+
+/**
+ * cmd_db_header: The DB header information
+ *
+ * @version: The cmd db version
+ * @magic_number: constant expected in the database

drivers/soc/qcom/cmd-db.c line 77

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+ * @header: array of resources
+ * @check_sum: check sum for the header. Unused.
+ * @reserved: reserved memory
+ * @data: driver specific data
+ */
+struct cmd_db_header {
+       u32 version;
+       u32 magic_num;
+       struct rsc_hdr header[MAX_SLV_ID];
+       u32 check_sum;

Drop underscore? 'checksum' is usually one word.

Quoted 28 lines
drivers/soc/qcom/cmd-db.c new file +28 -0
+       u32 reserved;
+       u8 data[];
+};
+
+/**
+ * DOC: Description of the Command DB database.
+ *
+ * At the start of the command DB memory is the cmd_db_header structure.
+ * The cmd_db_header holds the version, checksum, magic key as well as an
+ * array for header for each slave (depicted by the rsc_header). Each h/w
+ * based accelerator is a 'slave' (shared resource) and has slave id indicating
+ * the type of accelerator. The rsc_header is the header for such individual
+ * slaves of a given type. The entries for each of these slaves begin at the
+ * rsc_hdr.header_offset. In addition each slave could have auxiliary data
+ * that may be needed by the driver. The data for the slave starts at the
+ * entry_header.offset to the location pointed to by the rsc_hdr.data_offset.
+ *
+ * Drivers have a stringified key to a slave/resource. They can query the slave
+ * information and get the slave id and the auxiliary data and the length of the
+ * data. Using this information, they can format the request to be sent to the
+ * h/w accelerator and request a resource state.
+ */
+
+static struct cmd_db_header *cmd_db_header;
+
+/**
+ * cmd_db_ready - Indicates if command DB is available
+ *

drivers/soc/qcom/cmd-db.c line 115

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+ * Return: 0 on success, errno otherwise
+ */
+int cmd_db_ready(void)
+{
+       if (cmd_db_header == NULL)
+               return -EPROBE_DEFER;
+       else if (cmd_db_header->magic_num != CMD_DB_MAGIC)
+               return -EINVAL;
+       else
+               return 0;

Drop else and just return 0.

drivers/soc/qcom/cmd-db.c line 126

Quoted 11 lines
drivers/soc/qcom/cmd-db.c new file +11 -0
+}
+EXPORT_SYMBOL(cmd_db_ready);
+
+static u64 cmd_db_get_u64_id(const char *id)
+{
+       u64 rsc_id = 0;
+       u8 *ch = (u8 *)&rsc_id;
+       int i;
+
+       for (i = 0; i < sizeof(rsc_id) && id[i]; i++)
+               ch[i] = id[i];

This could be a strncpy now? Didn't I already ask this? I'll have to look back at the other emails it seems. Actually, it looks like a cast of a string to an integer, which is then reversed to look up the same string. Not sure what the use is for this.

Quoted 22 lines
drivers/soc/qcom/cmd-db.c new file +22 -0
+
+       return rsc_id;
+}
+
+static int cmd_db_get_header(u64 query, struct entry_header *eh,
+                           struct rsc_hdr *rh)
+{
+       struct rsc_hdr *rsc_hdr;
+       struct entry_header *ent;
+       int ret, i, j;
+
+       ret = cmd_db_ready();
+       if (ret)
+               return ret;
+
+       if (!eh || !rh)
+               return -EINVAL;
+
+       for (i = 0; i < MAX_SLV_ID; i++) {
+               rsc_hdr = &cmd_db_header->header[i];
+               if (!rsc_hdr->slv_id)
+                       break;

drivers/soc/qcom/cmd-db.c line 158

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+
+               ent = ENTRY_HEADER(rsc_hdr);
+               for (j = 0; j < rsc_hdr->cnt; j++, ent++) {
+                       if (ent->id == query)
+                               break;
+               }
+
+               if (j < rsc_hdr->cnt) {
+                       memcpy(eh, ent, sizeof(*ent));
+                       memcpy(rh, rsc_hdr, sizeof(*rh));

I suppose it's OK to punt on the endian issues for now if it's too hard. Eventually we'll want to handle it though and it shouldn't make the code any worse when endianness is the same. Can it be done now?

Quoted 14 lines
drivers/soc/qcom/cmd-db.c new file +14 -0
+                       return 0;
+               }
+       }
+
+       return -ENODEV;
+}
+
+static int cmd_db_get_header_by_rsc_id(const char *id,
+                                     struct entry_header *ent_hdr,
+                                     struct rsc_hdr *rsc_hdr)
+{
+       u64 rsc_id = cmd_db_get_u64_id(id);
+
+       return cmd_db_get_header(rsc_id, ent_hdr, rsc_hdr);

drivers/soc/qcom/cmd-db.c line 182

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+}
+
+/**
+ * cmd_db_read_addr() - Query command db for resource id address.
+ *
+ *  @id: resource id to query for address
+ *
+ * This is used to retrieve resource address based on resource
+ * id.
+ *  Return: resource address on success, 0 on error

Weird spaces here. Mix of tabs and spaces perhaps?

Quoted 9 lines
drivers/soc/qcom/cmd-db.c new file +9 -0
+ */
+u32 cmd_db_read_addr(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);
+

drivers/soc/qcom/cmd-db.c line 201

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+       return ret < 0 ? 0 : ent.addr;
+}
+EXPORT_SYMBOL(cmd_db_read_addr);
+
+/**
+ * cmd_db_read_aux_data() - Query command db for aux data.
+ *
+ *  @id : Resource to retrieve AUX Data on.
+ *  @data : Data buffer to copy returned aux data to. Returns size on NULL
+ *  @len : Caller provides size of data buffer passed in.

Attach the ':' to the variable please.

drivers/soc/qcom/cmd-db.c line 203

Quoted 2 lines
drivers/soc/qcom/cmd-db.c new file +2 -0
+ *
+ *  Return: size of data on success, errno on error

success, -EINVAL on error

Quoted 28 lines
drivers/soc/qcom/cmd-db.c new file +28 -0
+ */
+int cmd_db_read_aux_data(const char *id, u8 *data, int len)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       if (!data)
+               return -EINVAL;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);
+       if (ret)
+               return ret;
+
+       if (len < ent.len)
+               return -EINVAL;
+
+       len = min_t(u16, ent.len, len);
+       memcpy(data, RSC_OFFSET(rsc_hdr, ent), len);
+
+       return len;
+}
+EXPORT_SYMBOL(cmd_db_read_aux_data);
+
+/**
+ * cmd_db_read_aux_data_len - Get the length of the auxllary data stored in DB.
+ *
+ * @id: Resource to retrieve AUX Data.

drivers/soc/qcom/cmd-db.c line 241

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+ *
+ * Return: size on success, 0 on error
+ */
+size_t cmd_db_read_aux_data_len(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);

A bunch of code is calling this function. Why not change the user interface to use an opaque 'resource' cookie that we can 'get' or 'find' and then use that cookie in the rest of the API to pull out the data that's desired?

Quoted 34 lines
drivers/soc/qcom/cmd-db.c new file +34 -0
+
+       return ret < 0 ? 0 : ent.len;
+}
+EXPORT_SYMBOL(cmd_db_read_aux_data_len);
+
+/**
+ * cmd_db_read_slave_id - Get the slave ID for a given resource address
+ *
+ * @id: Resource id to query the DB for version
+ *
+ * Return: cmd_db_hw_type enum on success, CMD_DB_HW_INVALID on error
+ */
+enum cmd_db_hw_type cmd_db_read_slave_id(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);
+
+       return ret < 0 ? CMD_DB_HW_INVALID :
+                      (ent.addr >> SLAVE_ID_SHIFT) & SLAVE_ID_MASK;
+}
+EXPORT_SYMBOL(cmd_db_read_slave_id);
+
+static int cmd_db_dev_probe(struct platform_device *pdev)
+{
+       struct reserved_mem *rmem;
+       void *dict, *start_addr;
+       int ret = 0;
+
+       rmem = of_reserved_mem_lookup(pdev->dev.of_node);
+       if (!rmem) {
+               dev_err(&pdev->dev, "failed to acquire memory region\n");

drivers/soc/qcom/cmd-db.c line 285

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+               return -EINVAL;
+       }
+
+       dict = devm_memremap(&pdev->dev, rmem->base, rmem->size, MEMREMAP_WB);
+       if (IS_ERR(dict))
+               return -ENOMEM;
+
+       start_addr = memremap(readl_relaxed(dict), readl_relaxed(dict + 0x4),
+                            MEMREMAP_WB);
+       if (IS_ERR_OR_NULL(start_addr)) {

Should just be !start_addr? I don't see where memremap() returns an error pointer.

drivers/soc/qcom/cmd-db.c line 291

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+               ret = PTR_ERR(start_addr);
+               goto done;
+       }
+
+       cmd_db_header = start_addr;
+       if (cmd_db_header->magic_num != CMD_DB_MAGIC) {

memcmp?

drivers/soc/qcom/cmd-db.c line 298

Quoted 7 lines
drivers/soc/qcom/cmd-db.c new file +7 -0
+               ret = -EINVAL;
+               dev_err(&pdev->dev, "Invalid Command DB Magic\n");
+               goto done;
+       }
+
+done:
+       devm_memunmap(&pdev->dev, dict);

I'm lost why we use devm_*() for this mapping.

drivers/soc/qcom/cmd-db.c line 311

Quoted 13 lines
drivers/soc/qcom/cmd-db.c new file +13 -0
+       return ret;
+}
+
+static const struct of_device_id cmd_db_match_table[] = {
+       { .compatible = "qcom,cmd-db" },
+       { },
+};
+
+static struct platform_driver cmd_db_dev_driver = {
+       .probe  = cmd_db_dev_probe,
+       .driver = {
+                 .name = "cmd-db",
+                 .of_match_table = cmd_db_match_table,

Add suppress_bind_attrs here to make sure we can't remove this device later? That also allows us to ignore unmapping the start_addr pointer in any sort of 'remove' function.

Quoted 3 lines
drivers/soc/qcom/cmd-db.c new file +3 -0
+       },
+};
+
author
#3 lore raw

Re: [PATCH v4 1/2] drivers: qcom: add command DB driver

Quoted 26 lines · Stephen Boyd

Quoting Lina Iyer (2018-02-26 09:58:01)

Quoted 12 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
new file mode 100644
index 000000000000..0792a2a98fc9
@@ -0,0 +1,319 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/* Copyright (c) 2016-2018, The Linux Foundation. All rights reserved. */
+
+#include <linux/kernel.h>
+#include <linux/of.h>
+#include <linux/of_address.h>

drivers/soc/qcom/cmd-db.c line 16

Quoted 10 lines
drivers/soc/qcom/cmd-db.c new file +10 -0
+#include <linux/of_platform.h>
+#include <linux/of_reserved_mem.h>
+#include <linux/platform_device.h>
+#include <linux/types.h>
+
+#include <soc/qcom/cmd-db.h>
+
+#define NUM_PRIORITY           2
+#define MAX_SLV_ID             8
+#define CMD_DB_MAGIC           0x0C0330DBUL

Make this an array so it's endian safe.

Quoted 16 lines

drivers/soc/qcom/cmd-db.c line 29

Quoted 13 lines
drivers/soc/qcom/cmd-db.c new file +13 -0
+#define SLAVE_ID_MASK          0x7
+#define SLAVE_ID_SHIFT         16
+
+#define ENTRY_HEADER(hdr)      ((void *)cmd_db_header +        \
+                               sizeof(*cmd_db_header) +        \
+                               hdr->header_offset)
+
+#define RSC_OFFSET(hdr, ent)   ((void *)cmd_db_header +        \
+                               sizeof(*cmd_db_header) +        \
+                               hdr.data_offset + ent.offset)
+
+/**
+ * entry_header: header for each entry in cmddb

struct entry_header - header for each...

Ok

Quoted 10 lines

drivers/soc/qcom/cmd-db.c line 35

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+ *
+ * @id: resource's identifier
+ * @priority: unused
+ * @addr: the address of the resource
+ * @len: length of the data
+ * @offset: offset at which data starts

offset from this entry header at which data starts? Or offset from where?

Offset from @data_offset of the rsc_header.

Quoted 5 lines
Quoted 5 lines
drivers/soc/qcom/cmd-db.c new file +5 -0
+ */
+struct entry_header {
+       u64 id;
+       u32 priority[NUM_PRIORITY];
+       u32 addr;
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 46

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+       u16 len;
+       u16 offset;
+};
+
+/**
+ * rsc_hdr: resource header information

ditto.

Will do.

Quoted 7 lines

drivers/soc/qcom/cmd-db.c line 50

Quoted 4 lines
drivers/soc/qcom/cmd-db.c new file +4 -0
+ *
+ * @slv_id: id for the resource
+ * @header_offset: Entry header offset from data
+ * @data_offset: Entry offset for data location

Same question: offset from where?

Ok

Quoted 5 lines

drivers/soc/qcom/cmd-db.c line 52

Quoted 2 lines
drivers/soc/qcom/cmd-db.c new file +2 -0
+ * @cnt: number of entries for HW type
+ * @version: MSB is major, LSB is minor

@reserved: reserved for future use

Ok.

Quoted 19 lines
Quoted 19 lines
drivers/soc/qcom/cmd-db.c new file +19 -0
+ */
+struct rsc_hdr {
+       u16 slv_id;
+       u16 header_offset;
+       u16 data_offset;
+       u16 cnt;
+       u16 version;
+       u16 reserved[3];
+};
+
+/**
+ * cmd_db_header: The DB header information
+ *
+ * @version: The cmd db version
+ * @magic_number: constant expected in the database
+ * @header: array of resources
+ * @check_sum: check sum for the header. Unused.
+ * @reserved: reserved memory
+ * @data: driver specific data
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 77

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+ */
+struct cmd_db_header {
+       u32 version;
+       u32 magic_num;
+       struct rsc_hdr header[MAX_SLV_ID];
+       u32 check_sum;

Drop underscore? 'checksum' is usually one word.

Sure.

Quoted 32 lines
Quoted 32 lines
drivers/soc/qcom/cmd-db.c new file +32 -0
+       u32 reserved;
+       u8 data[];
+};
+
+/**
+ * DOC: Description of the Command DB database.
+ *
+ * At the start of the command DB memory is the cmd_db_header structure.
+ * The cmd_db_header holds the version, checksum, magic key as well as an
+ * array for header for each slave (depicted by the rsc_header). Each h/w
+ * based accelerator is a 'slave' (shared resource) and has slave id indicating
+ * the type of accelerator. The rsc_header is the header for such individual
+ * slaves of a given type. The entries for each of these slaves begin at the
+ * rsc_hdr.header_offset. In addition each slave could have auxiliary data
+ * that may be needed by the driver. The data for the slave starts at the
+ * entry_header.offset to the location pointed to by the rsc_hdr.data_offset.
+ *
+ * Drivers have a stringified key to a slave/resource. They can query the slave
+ * information and get the slave id and the auxiliary data and the length of the
+ * data. Using this information, they can format the request to be sent to the
+ * h/w accelerator and request a resource state.
+ */
+
+static struct cmd_db_header *cmd_db_header;
+
+/**
+ * cmd_db_ready - Indicates if command DB is available
+ *
+ * Return: 0 on success, errno otherwise
+ */
+int cmd_db_ready(void)
+{
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 115

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+       if (cmd_db_header == NULL)
+               return -EPROBE_DEFER;
+       else if (cmd_db_header->magic_num != CMD_DB_MAGIC)
+               return -EINVAL;
+       else
+               return 0;

Drop else and just return 0.

Ok.

Quoted 7 lines
Quoted 7 lines
drivers/soc/qcom/cmd-db.c new file +7 -0
+}
+EXPORT_SYMBOL(cmd_db_ready);
+
+static u64 cmd_db_get_u64_id(const char *id)
+{
+       u64 rsc_id = 0;
+       u8 *ch = (u8 *)&rsc_id;
Quoted 8 lines

drivers/soc/qcom/cmd-db.c line 126

Quoted 4 lines
drivers/soc/qcom/cmd-db.c new file +4 -0
+       int i;
+
+       for (i = 0; i < sizeof(rsc_id) && id[i]; i++)
+               ch[i] = id[i];

This could be a strncpy now? Didn't I already ask this? I'll have to look back at the other emails it seems. Actually, it looks like a cast of a string to an integer,

Yes, you did ask. The cast helps do an integer comparison as opposed to string comparision on the database.

Quoted 3 lines

which is then reversed to look up the same
string. Not sure what the use is for this.

Where do you see that?

Quoted 28 lines
Quoted 28 lines
drivers/soc/qcom/cmd-db.c new file +28 -0
+
+       return rsc_id;
+}
+
+static int cmd_db_get_header(u64 query, struct entry_header *eh,
+                           struct rsc_hdr *rh)
+{
+       struct rsc_hdr *rsc_hdr;
+       struct entry_header *ent;
+       int ret, i, j;
+
+       ret = cmd_db_ready();
+       if (ret)
+               return ret;
+
+       if (!eh || !rh)
+               return -EINVAL;
+
+       for (i = 0; i < MAX_SLV_ID; i++) {
+               rsc_hdr = &cmd_db_header->header[i];
+               if (!rsc_hdr->slv_id)
+                       break;
+
+               ent = ENTRY_HEADER(rsc_hdr);
+               for (j = 0; j < rsc_hdr->cnt; j++, ent++) {
+                       if (ent->id == query)
+                               break;
+               }
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 158

Quoted 4 lines
drivers/soc/qcom/cmd-db.c new file +4 -0
+
+               if (j < rsc_hdr->cnt) {
+                       memcpy(eh, ent, sizeof(*ent));
+                       memcpy(rh, rsc_hdr, sizeof(*rh));

I suppose it's OK to punt on the endian issues for now if it's too hard. Eventually we'll want to handle it though and it shouldn't make the code any worse when endianness is the same. Can it be done now?

Why is the change in endian needed? We can always add that in later if we decide to change the default endian. I would prefer that we punt it for now.

Quoted 18 lines
Quoted 18 lines
drivers/soc/qcom/cmd-db.c new file +18 -0
+                       return 0;
+               }
+       }
+
+       return -ENODEV;
+}
+
+static int cmd_db_get_header_by_rsc_id(const char *id,
+                                     struct entry_header *ent_hdr,
+                                     struct rsc_hdr *rsc_hdr)
+{
+       u64 rsc_id = cmd_db_get_u64_id(id);
+
+       return cmd_db_get_header(rsc_id, ent_hdr, rsc_hdr);
+}
+
+/**
+ * cmd_db_read_addr() - Query command db for resource id address.
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 182

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+ *
+ *  @id: resource id to query for address
+ *
+ * This is used to retrieve resource address based on resource
+ * id.
+ *  Return: resource address on success, 0 on error

Weird spaces here. Mix of tabs and spaces perhaps?

Hmm. Not sure, didn't see checkpatch complain. Will check.

Quoted 13 lines
Quoted 13 lines
drivers/soc/qcom/cmd-db.c new file +13 -0
+ */
+u32 cmd_db_read_addr(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);
+
+       return ret < 0 ? 0 : ent.addr;
+}
+EXPORT_SYMBOL(cmd_db_read_addr);
+
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 201

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+/**
+ * cmd_db_read_aux_data() - Query command db for aux data.
+ *
+ *  @id : Resource to retrieve AUX Data on.
+ *  @data : Data buffer to copy returned aux data to. Returns size on NULL
+ *  @len : Caller provides size of data buffer passed in.

Attach the ':' to the variable please.

Ok

Quoted 5 lines

drivers/soc/qcom/cmd-db.c line 203

Quoted 2 lines
drivers/soc/qcom/cmd-db.c new file +2 -0
+ *
+ *  Return: size of data on success, errno on error

success, -EINVAL on error

Ok

Quoted 35 lines
Quoted 35 lines
drivers/soc/qcom/cmd-db.c new file +35 -0
+ */
+int cmd_db_read_aux_data(const char *id, u8 *data, int len)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       if (!data)
+               return -EINVAL;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);
+       if (ret)
+               return ret;
+
+       if (len < ent.len)
+               return -EINVAL;
+
+       len = min_t(u16, ent.len, len);
+       memcpy(data, RSC_OFFSET(rsc_hdr, ent), len);
+
+       return len;
+}
+EXPORT_SYMBOL(cmd_db_read_aux_data);
+
+/**
+ * cmd_db_read_aux_data_len - Get the length of the auxllary data stored in DB.
+ *
+ * @id: Resource to retrieve AUX Data.
+ *
+ * Return: size on success, 0 on error
+ */
+size_t cmd_db_read_aux_data_len(const char *id)
+{
+       int ret;
+       struct entry_header ent;
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 190

Quoted 3 lines
drivers/soc/qcom/cmd-db.c new file +3 -0
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);

A bunch of code is calling this function. Why not change the user interface to use an opaque 'resource' cookie that we can 'get' or 'find' and then use that cookie in the rest of the API to pull out the data that's desired?

Fair point. Let me find out. I suspect this was done to keep the API similar to other non-Linux interfaces. I am not sure why they all didn't use a handle instead of char *.

Quoted 39 lines
Quoted 39 lines
drivers/soc/qcom/cmd-db.c new file +39 -0
+
+       return ret < 0 ? 0 : ent.len;
+}
+EXPORT_SYMBOL(cmd_db_read_aux_data_len);
+
+/**
+ * cmd_db_read_slave_id - Get the slave ID for a given resource address
+ *
+ * @id: Resource id to query the DB for version
+ *
+ * Return: cmd_db_hw_type enum on success, CMD_DB_HW_INVALID on error
+ */
+enum cmd_db_hw_type cmd_db_read_slave_id(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);
+
+       return ret < 0 ? CMD_DB_HW_INVALID :
+                      (ent.addr >> SLAVE_ID_SHIFT) & SLAVE_ID_MASK;
+}
+EXPORT_SYMBOL(cmd_db_read_slave_id);
+
+static int cmd_db_dev_probe(struct platform_device *pdev)
+{
+       struct reserved_mem *rmem;
+       void *dict, *start_addr;
+       int ret = 0;
+
+       rmem = of_reserved_mem_lookup(pdev->dev.of_node);
+       if (!rmem) {
+               dev_err(&pdev->dev, "failed to acquire memory region\n");
+               return -EINVAL;
+       }
+
+       dict = devm_memremap(&pdev->dev, rmem->base, rmem->size, MEMREMAP_WB);
+       if (IS_ERR(dict))
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 285

Quoted 5 lines
drivers/soc/qcom/cmd-db.c new file +5 -0
+               return -ENOMEM;
+
+       start_addr = memremap(readl_relaxed(dict), readl_relaxed(dict + 0x4),
+                            MEMREMAP_WB);
+       if (IS_ERR_OR_NULL(start_addr)) {

Should just be !start_addr? I don't see where memremap() returns an error pointer.

Sure.

Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 291

Quoted 6 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+               ret = PTR_ERR(start_addr);
+               goto done;
+       }
+
+       cmd_db_header = start_addr;
+       if (cmd_db_header->magic_num != CMD_DB_MAGIC) {

memcmp?

Why? It could be a simple comparison.

Quoted 10 lines

drivers/soc/qcom/cmd-db.c line 298

Quoted 7 lines
drivers/soc/qcom/cmd-db.c new file +7 -0
+               ret = -EINVAL;
+               dev_err(&pdev->dev, "Invalid Command DB Magic\n");
+               goto done;
+       }
+
+done:
+       devm_memunmap(&pdev->dev, dict);

I'm lost why we use devm_*() for this mapping.

Must have picked it up from an example. Curious, why not though?

Quoted 9 lines
Quoted 9 lines
drivers/soc/qcom/cmd-db.c new file +9 -0
+       return ret;
+}
+
+static const struct of_device_id cmd_db_match_table[] = {
+       { .compatible = "qcom,cmd-db" },
+       { },
+};
+
+static struct platform_driver cmd_db_dev_driver = {
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 311

Quoted 4 lines
drivers/soc/qcom/cmd-db.c new file +4 -0
+       .probe  = cmd_db_dev_probe,
+       .driver = {
+                 .name = "cmd-db",
+                 .of_match_table = cmd_db_match_table,

Add suppress_bind_attrs here to make sure we can't remove this device later? That also allows us to ignore unmapping the start_addr pointer in any sort of 'remove' function.

Ok..

Thanks Stephen.

-- Lina

author
#4 lore raw

Re: [PATCH v4 1/2] drivers: qcom: add command DB driver

Quoted 15 lines · Lina Iyer
Quoted 14 lines · Stephen Boyd

Quoting Lina Iyer (2018-02-26 09:58:01)

drivers/soc/qcom/cmd-db.c line 241

Quoted 7 lines
drivers/soc/qcom/cmd-db.c new file +7 -0
+size_t cmd_db_read_aux_data_len(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);

A bunch of code is calling this function. Why not change the user interface to use an opaque 'resource' cookie that we can 'get' or 'find' and then use that cookie in the rest of the API to pull out the data that's desired?

Quoted 4 lines

Fair point. Let me find out. I suspect this was done to keep the API similar to other non-Linux interfaces. I am not sure why they all didn't use a handle instead of char *.

I was reminded that the APIs are generally used once for each resource and are used for multiple resources and usually only at init. The handle method doesn't buy much in benefits.

-- Lina

#5 lore raw

Re: [PATCH v4 1/2] drivers: qcom: add command DB driver

Quoting Lina Iyer (2018-03-06 08:56:19)

Quoted 16 lines · Lina Iyer
Quoted 15 lines · Stephen Boyd
Quoted 14 lines

Quoting Lina Iyer (2018-02-26 09:58:01)

drivers/soc/qcom/cmd-db.c line 241

Quoted 7 lines
drivers/soc/qcom/cmd-db.c new file +7 -0
+size_t cmd_db_read_aux_data_len(const char *id)
+{
+       int ret;
+       struct entry_header ent;
+       struct rsc_hdr rsc_hdr;
+
+       ret = cmd_db_get_header_by_rsc_id(id, &ent, &rsc_hdr);

A bunch of code is calling this function. Why not change the user interface to use an opaque 'resource' cookie that we can 'get' or 'find' and then use that cookie in the rest of the API to pull out the data that's desired?

Quoted 8 lines
Quoted 4 lines

Fair point. Let me find out. I suspect this was done to keep the API similar to other non-Linux interfaces. I am not sure why they all didn't use a handle instead of char *.

I was reminded that the APIs are generally used once for each resource and are used for multiple resources and usually only at init. The handle method doesn't buy much in benefits.

Ok. Let's take the wait and see approach then.

#6 lore raw

Re: [PATCH v4 1/2] drivers: qcom: add command DB driver

In reply to Lina Iyer

Quoting Lina Iyer (2018-03-06 08:21:40)

Quoted 18 lines · Stephen Boyd
Quoted 17 lines

Quoting Lina Iyer (2018-02-26 09:58:01)

drivers/soc/qcom/cmd-db.c line 126

Quoted 11 lines
drivers/soc/qcom/cmd-db.c new file +11 -0
+}
+EXPORT_SYMBOL(cmd_db_ready);
+
+static u64 cmd_db_get_u64_id(const char *id)
+{
+       u64 rsc_id = 0;
+       u8 *ch = (u8 *)&rsc_id;
+       int i;
+
+       for (i = 0; i < sizeof(rsc_id) && id[i]; i++)
+               ch[i] = id[i];

This could be a strncpy now? Didn't I already ask this? I'll have to look back at the other emails it seems. Actually, it looks like a cast of a string to an integer,

Quoted 7 lines

Yes, you did ask. The cast helps do an integer comparison as opposed to string comparision on the database.

Quoted 3 lines

which is then reversed to look up the same
string. Not sure what the use is for this.

Where do you see that?

Hmm no idea. I must have seen something wrong. Ignore this one.

Quoted 38 lines
Quoted 29 lines
Quoted 29 lines
drivers/soc/qcom/cmd-db.c new file +28 -0
+
+       return rsc_id;
+}
+
+static int cmd_db_get_header(u64 query, struct entry_header *eh,
+                           struct rsc_hdr *rh)
+{
+       struct rsc_hdr *rsc_hdr;
+       struct entry_header *ent;
+       int ret, i, j;
+
+       ret = cmd_db_ready();
+       if (ret)
+               return ret;
+
+       if (!eh || !rh)
+               return -EINVAL;
+
+       for (i = 0; i < MAX_SLV_ID; i++) {
+               rsc_hdr = &cmd_db_header->header[i];
+               if (!rsc_hdr->slv_id)
+                       break;
+
+               ent = ENTRY_HEADER(rsc_hdr);
+               for (j = 0; j < rsc_hdr->cnt; j++, ent++) {
+                       if (ent->id == query)
+                               break;
+               }
Quoted 9 lines

drivers/soc/qcom/cmd-db.c line 158

Quoted 4 lines
drivers/soc/qcom/cmd-db.c new file +4 -0
+
+               if (j < rsc_hdr->cnt) {
+                       memcpy(eh, ent, sizeof(*ent));
+                       memcpy(rh, rsc_hdr, sizeof(*rh));

I suppose it's OK to punt on the endian issues for now if it's too hard. Eventually we'll want to handle it though and it shouldn't make the code any worse when endianness is the same. Can it be done now?

Quoted 3 lines

Why is the change in endian needed? We can always add that in later if we decide to change the default endian. I would prefer that we punt it for now.

Ok!

Quoted 11 lines
Quoted 10 lines

drivers/soc/qcom/cmd-db.c line 291

Quoted 7 lines
drivers/soc/qcom/cmd-db.c new file +6 -0
+               ret = PTR_ERR(start_addr);
+               goto done;
+       }
+
+       cmd_db_header = start_addr;
+       if (cmd_db_header->magic_num != CMD_DB_MAGIC) {

memcmp?

Why? It could be a simple comparison.

Endian stuff again

Quoted 11 lines
Quoted 11 lines

drivers/soc/qcom/cmd-db.c line 298

Quoted 8 lines
drivers/soc/qcom/cmd-db.c new file +7 -0
+               ret = -EINVAL;
+               dev_err(&pdev->dev, "Invalid Command DB Magic\n");
+               goto done;
+       }
+
+done:
+       devm_memunmap(&pdev->dev, dict);

I'm lost why we use devm_*() for this mapping.

Quoted 1 line

Must have picked it up from an example. Curious, why not though?

devm is usually used for long lived things that need to be released on driver removal. At least that's the way I view it. For short lived things that are created and then freed in the same scope I usually avoid devm.

author
#7 lore raw

PATCH v4 2/2 dt-bindings: introduce Command DB for QCOM SoCs

In reply to Lina Iyer

From: Mahesh Sivasubramanian <[email protected]>

Command DB provides information on shared resources like clocks, regulators etc., probed at boot by the remote subsytem and made available in shared memory.

---

Changes in v4:
- Fix unwanted capitalization
- Add reg property

---
 .../devicetree/bindings/arm/msm/cmd-db.txt         | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/cmd-db.txt
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +38 -0
new file mode 100644
index 000000000000..5737ed2ac6e8
@@ -0,0 +1,38 @@
+Command DB
+---------
+
+Command DB is a database that provides a mapping between resource key and the
+resource address for a system resource managed by a remote processor. The data
+is stored in a shared memory region and is loaded by the remote processor.
+
+Some of the Qualcomm Technologies Inc SoC's have hardware accelerators for
+controlling shared resources. Depending on the board configuration the shared
+resource properties may change. These properties are dynamically probed by the
+remote processor and made available in the shared memory.
+
+The bindings for Command DB is specified in the reserved-memory section in
+devicetree. The devicetree representation of the command DB driver should be:
+
+Properties:
+- compatible:
+	Usage: required
+	Value type: <string>
+	Definition: Should be "qcom,cmd-db"
+
+- reg:
+	Usage: required
+	Value type: <prop encoded array>
+	Definition: The register address that points to the location of the
+		    Command DB in memory. Additionally, specify the address
+		    and size of the actual lacation in memory.
+
+Example:
+
+	reserved-memory {
+		[...]
+		qcom,cmd-db@c3f000c {
+			reg = <0x0 0xc3f000c 0x0 0x8>,
+			      <0x0 0x85fe0000 0x0 0x20000>;
+			compatible = "qcom,cmd-db";
+		};
+	};
Signature · 2 lines
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum,
a Linux Foundation Collaborative Project
maintainer Reviewed-by on v4 2/2
#8 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

Quoted 11 lines · Lina Iyer

From: Mahesh Sivasubramanian <[email protected]>

Command DB provides information on shared resources like clocks, regulators etc., probed at boot by the remote subsytem and made available in shared memory.

---

Quoted 7 lines

Changes in v4:
- Fix unwanted capitalization
- Add reg property

---
 .../devicetree/bindings/arm/msm/cmd-db.txt         | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/cmd-db.txt
#9 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

In reply to Lina Iyer
Quoted 20 lines · Lina Iyer

From: Mahesh Sivasubramanian <[email protected]>

Command DB provides information on shared resources like clocks, regulators etc., probed at boot by the remote subsytem and made available in shared memory.

---

Changes in v4:
- Fix unwanted capitalization
- Add reg property

---
 .../devicetree/bindings/arm/msm/cmd-db.txt         | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/cmd-db.txt
Documentation/devicetree/bindings/arm/msm/cmd-db.txt +0 -0

[..]

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 35

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt +5 -0
+	reserved-memory {
+		[...]
+		qcom,cmd-db@c3f000c {
+			reg = <0x0 0xc3f000c 0x0 0x8>,
+			      <0x0 0x85fe0000 0x0 0x20000>;

I'm still concerned about the use of the redirection mapping here, the relocation at 0xc3f000c is used a convenience thing so that the command db can be relocated, but because of how Linux will consume any non-reserved memory the dts would still need to be manually updated.

As such I think you should just describe only the 0x85fe0000 + 0x20000 region here and to support the dynamic aspect of this from a system point of view you can have the boot loader read the information at 0xc3f000c and adjust the reserved memory. (Or just keep the step of manually update the dts without caring about the indirection)

Regards,
Bjorn

author
#10 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

Quoted 23 lines · Bjorn Andersson
Quoted 20 lines · Lina Iyer

From: Mahesh Sivasubramanian <[email protected]>

Command DB provides information on shared resources like clocks, regulators etc., probed at boot by the remote subsytem and made available in shared memory.

---

Changes in v4:
- Fix unwanted capitalization
- Add reg property

---
 .../devicetree/bindings/arm/msm/cmd-db.txt         | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/cmd-db.txt
Documentation/devicetree/bindings/arm/msm/cmd-db.txt +0 -0

[..]

Quoted 11 lines

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 35

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt +5 -0
+	reserved-memory {
+		[...]
+		qcom,cmd-db@c3f000c {
+			reg = <0x0 0xc3f000c 0x0 0x8>,
+			      <0x0 0x85fe0000 0x0 0x20000>;

I'm still concerned about the use of the redirection mapping here, the relocation at 0xc3f000c is used a convenience thing so that the command db can be relocated, but because of how Linux will consume any non-reserved memory the dts would still need to be manually updated.

This location is fixed and it is not expected to change between different boards. OEMs may change the actual address of the command db location, but would not change the dictionary location.

Quoted 6 lines

As such I think you should just describe only the 0x85fe0000 + 0x20000 region here and to support the dynamic aspect of this from a system point of view you can have the boot loader read the information at 0xc3f000c and adjust the reserved memory. (Or just keep the step of manually update the dts without caring about the indirection)

It would be incorrect and very board specific to just use the 0x85fe000 as the address. It is not how the SoC defines the location. Upon request earlier, this memory location was added in DT and the location is typical reference platform usage only.

Thanks,
Lina

#11 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

Quoted 35 lines · Lina Iyer
Quoted 23 lines · Bjorn Andersson
Quoted 20 lines · Lina Iyer

From: Mahesh Sivasubramanian <[email protected]>

Command DB provides information on shared resources like clocks, regulators etc., probed at boot by the remote subsytem and made available in shared memory.

---

Changes in v4:
- Fix unwanted capitalization
- Add reg property

---
 .../devicetree/bindings/arm/msm/cmd-db.txt         | 38 ++++++++++++++++++++++
 1 file changed, 38 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/arm/msm/cmd-db.txt
Documentation/devicetree/bindings/arm/msm/cmd-db.txt +0 -0

[..]

Quoted 11 lines

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 35

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt +5 -0
+	reserved-memory {
+		[...]
+		qcom,cmd-db@c3f000c {
+			reg = <0x0 0xc3f000c 0x0 0x8>,
+			      <0x0 0x85fe0000 0x0 0x20000>;

I'm still concerned about the use of the redirection mapping here, the relocation at 0xc3f000c is used a convenience thing so that the command db can be relocated, but because of how Linux will consume any non-reserved memory the dts would still need to be manually updated.

Quoted 4 lines

This location is fixed and it is not expected to change between different boards. OEMs may change the actual address of the command db location, but would not change the dictionary location.

Right, dictionary location is fixed. So to pick another range for command db one would update the numbers that goes into the dictionary and expect all software in the system to use this new range.

Quoted 11 lines
Quoted 6 lines

As such I think you should just describe only the 0x85fe0000 + 0x20000 region here and to support the dynamic aspect of this from a system point of view you can have the boot loader read the information at 0xc3f000c and adjust the reserved memory. (Or just keep the step of manually update the dts without caring about the indirection)

It would be incorrect and very board specific to just use the 0x85fe000 as the address. It is not how the SoC defines the location. Upon request earlier, this memory location was added in DT and the location is typical reference platform usage only.

The problem is that as the db resides in a chunk of memory in the middle of what Linux considers System RAM the DTS must specify this region as reserved. Which means that as you, like described above, update the dictionary something (in your scheme a person) has to update the reserved-memory region as well.

That's why I'm proposing that the appropriate implementation for this is to have the boot loader to the dictionary part of this and Linux only care about the actual reserved-memory region. This way you would still implement the dictionary lookup on a system level, but the Linux part no longer depend on a human updating the DTS to match the values of the dictionary.

But if we stick with the approach of describing both these and hoping that the values in the first region matches the second (or should we add a sanity check in probe?). The memory reserve defined as 0xc3f000c + 8 looks strange, is this system ram as well and what other things resides in that same page?

Regards,
Bjorn

#12 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

Quoting Bjorn Andersson (2018-03-07 11:02:49)

Quoted 23 lines · Lina Iyer
Quoted 10 lines · Bjorn Andersson
Quoted 8 lines · Lina Iyer

As such I think you should just describe only the 0x85fe0000 + 0x20000 region here and to support the dynamic aspect of this from a system point of view you can have the boot loader read the information at 0xc3f000c and adjust the reserved memory. (Or just keep the step of manually update the dts without caring about the indirection)

Quoted 5 lines

It would be incorrect and very board specific to just use the 0x85fe000 as the address. It is not how the SoC defines the location. Upon request earlier, this memory location was added in DT and the location is typical reference platform usage only.

The problem is that as the db resides in a chunk of memory in the middle of what Linux considers System RAM the DTS must specify this region as reserved. Which means that as you, like described above, update the dictionary something (in your scheme a person) has to update the reserved-memory region as well.

Quoted 6 lines

That's why I'm proposing that the appropriate implementation for this is to have the boot loader to the dictionary part of this and Linux only care about the actual reserved-memory region. This way you would still implement the dictionary lookup on a system level, but the Linux part no longer depend on a human updating the DTS to match the values of the dictionary.

Agreed. I thought SMEM had a similar design of a cookie in IMEM to indicate location and size because coordinating changes across all the various software images is a hard problem. But coordinating between linux and the linux bootloader shouldn't be as hard.

Quoted 8 lines

But if we stick with the approach of describing both these and hoping that the values in the first region matches the second (or should we add a sanity check in probe?). The memory reserve defined as 0xc3f000c + 8 looks strange, is this system ram as well and what other things resides in that same page?

Doesn't look like it could be RAM, the address is not very close to the other one so I would guess it's something like IMEM. And there are two 32-bit numbers to describe address and size?

#13 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

Quoted 31 lines · Stephen Boyd

Quoting Bjorn Andersson (2018-03-07 11:02:49)

Quoted 23 lines · Lina Iyer
Quoted 10 lines · Bjorn Andersson
Quoted 8 lines · Lina Iyer

As such I think you should just describe only the 0x85fe0000 + 0x20000 region here and to support the dynamic aspect of this from a system point of view you can have the boot loader read the information at 0xc3f000c and adjust the reserved memory. (Or just keep the step of manually update the dts without caring about the indirection)

Quoted 5 lines

It would be incorrect and very board specific to just use the 0x85fe000 as the address. It is not how the SoC defines the location. Upon request earlier, this memory location was added in DT and the location is typical reference platform usage only.

The problem is that as the db resides in a chunk of memory in the middle of what Linux considers System RAM the DTS must specify this region as reserved. Which means that as you, like described above, update the dictionary something (in your scheme a person) has to update the reserved-memory region as well.

Quoted 6 lines

That's why I'm proposing that the appropriate implementation for this is to have the boot loader to the dictionary part of this and Linux only care about the actual reserved-memory region. This way you would still implement the dictionary lookup on a system level, but the Linux part no longer depend on a human updating the DTS to match the values of the dictionary.

Quoted 5 lines

Agreed. I thought SMEM had a similar design of a cookie in IMEM to indicate location and size because coordinating changes across all the various software images is a hard problem. But coordinating between linux and the linux bootloader shouldn't be as hard.

Correct, SMEM has exactly the same mechanism.

I get that the coordinating of these addresses between all involved images can be a tricky thing, but the only way to make this automatic on the application CPU is to split this between boot and Linux; as any all-Linux solution requires a human to update the reserved-memory node to match the values in the indirection.

So for SMEM we agreed that we implement this as "someone needs to tell Linux where SMEM is" and that can be a human or the boot loader.

Regards,
Bjorn

#14 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

In reply to Lina Iyer

Quoting Lina Iyer (2018-02-26 09:58:02)

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +4 -0
new file mode 100644
index 000000000000..5737ed2ac6e8
@@ -0,0 +1,38 @@
+Command DB
+---------
+
+Command DB is a database that provides a mapping between resource key and the

s/between/between the/

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 8

Quoted 4 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +4 -0
+resource address for a system resource managed by a remote processor. The data
+is stored in a shared memory region and is loaded by the remote processor.
+
+Some of the Qualcomm Technologies Inc SoC's have hardware accelerators for

s/SoC's/SoCs/

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 13

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +5 -0
+controlling shared resources. Depending on the board configuration the shared
+resource properties may change. These properties are dynamically probed by the
+remote processor and made available in the shared memory.
+
+The bindings for Command DB is specified in the reserved-memory section in

s/bindings/node/

maybe?

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +1 -0
+devicetree. The devicetree representation of the command DB driver should be:

Maybe drop this last sentence entirely.

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 27

Quoted 13 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +13 -0
+
+Properties:
+- compatible:
+       Usage: required
+       Value type: <string>
+       Definition: Should be "qcom,cmd-db"
+
+- reg:
+       Usage: required
+       Value type: <prop encoded array>
+       Definition: The register address that points to the location of the
+                   Command DB in memory. Additionally, specify the address
+                   and size of the actual lacation in memory.

s/lacation/location/

Quoted 11 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +11 -0
+
+Example:
+
+       reserved-memory {
+               [...]
+               qcom,cmd-db@c3f000c {
+                       reg = <0x0 0xc3f000c 0x0 0x8>,
+                             <0x0 0x85fe0000 0x0 0x20000>;
+                       compatible = "qcom,cmd-db";
+               };
+       };
author
#15 lore raw

Re: [PATCH v4 2/2] dt-bindings: introduce Command DB for QCOM SoCs

Quoted 35 lines · Stephen Boyd

Quoting Lina Iyer (2018-02-26 09:58:02)

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 4

Quoted 10 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +4 -0
new file mode 100644
index 000000000000..5737ed2ac6e8
@@ -0,0 +1,38 @@
+Command DB
+---------
+
+Command DB is a database that provides a mapping between resource key and the

s/between/between the/

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 8

Quoted 4 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +4 -0
+resource address for a system resource managed by a remote processor. The data
+is stored in a shared memory region and is loaded by the remote processor.
+
+Some of the Qualcomm Technologies Inc SoC's have hardware accelerators for

s/SoC's/SoCs/

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 13

Quoted 5 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +5 -0
+controlling shared resources. Depending on the board configuration the shared
+resource properties may change. These properties are dynamically probed by the
+remote processor and made available in the shared memory.
+
+The bindings for Command DB is specified in the reserved-memory section in

s/bindings/node/

maybe?

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 14

Quoted 1 line
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +1 -0
+devicetree. The devicetree representation of the command DB driver should be:

Maybe drop this last sentence entirely.

Quoted 16 lines

Documentation/devicetree/bindings/arm/msm/cmd-db.txt line 27

Quoted 13 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +13 -0
+
+Properties:
+- compatible:
+       Usage: required
+       Value type: <string>
+       Definition: Should be "qcom,cmd-db"
+
+- reg:
+       Usage: required
+       Value type: <prop encoded array>
+       Definition: The register address that points to the location of the
+                   Command DB in memory. Additionally, specify the address
+                   and size of the actual lacation in memory.

s/lacation/location/

Will take care of these in the next spin.

Quoted 11 lines
Quoted 11 lines
Documentation/devicetree/bindings/arm/msm/cmd-db.txt new file +11 -0
+
+Example:
+
+       reserved-memory {
+               [...]
+               qcom,cmd-db@c3f000c {
+                       reg = <0x0 0xc3f000c 0x0 0x8>,
+                             <0x0 0x85fe0000 0x0 0x20000>;
+                       compatible = "qcom,cmd-db";
+               };
+       };