Skip to contentSkip to conversation

soc: qcom: add in-kernel pd-mapper implementation

PATCH Superseded Dmitry Baryshkov 3 participants 18 messages Apr 19, 2024 – Apr 22, 2024

Subsystems (3)

v5 of 9 Superseded Latest is v9 →

lore
Share & tools
lore
#0 lore raw

v5 cover soc: qcom: add in-kernel pd-mapper implementation

Protection domain mapper is a QMI service providing mapping between 'protection domains' and services supported / allowed in these domains. For example such mapping is required for loading of the WiFi firmware or for properly starting up the UCSI / altmode / battery manager support.

The existing userspace implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread the JSON files if the firmware location is changed (or if the firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

However this configuration is largely static and common between different platforms. Provide in-kernel service implementing static per-platform data.

Unlike previous revisions of the patchset, this iteration uses static configuration per platform, rather than building it dynamically from the list of DSPs being started.

--
2.39.2

To: Bjorn Andersson <[email protected]>
To: Konrad Dybcio <[email protected]>
To: Mathieu Poirier <[email protected]>
To: Sibi Sankar <[email protected]>
Cc: [email protected]
Cc: [email protected]
Cc: Johan Hovold <[email protected]>
Cc: Xilin Wu <[email protected]>

Changes in v5:
- pdr: drop lock in pdr_register_listener, list_lock is already held (Chris Lew)
- pd_mapper: reworked to provide static configuration per platform
(Bjorn)
- Link to v4: https://lore.kernel.org/r/[email protected]

Changes in v4:
- Fixed missing chunk, reenabled kfree in qmi_del_server (Konrad)
- Added configuration for sm6350 (Thanks to Luca)
- Removed RFC tag (Konrad)
- Link to v3: https://lore.kernel.org/r/[email protected]

Changes in RFC v3:
- Send start / stop notifications when PD-mapper domain list is changed
- Reworked the way PD-mapper treats protection domains, register all of
them in a single batch
- Added SC7180 domains configuration based on TCL Book 14 GO
- Link to v2: https://lore.kernel.org/r/[email protected]

Changes in RFC v2:
- Swapped num_domains / domains (Konrad)
- Fixed an issue with battery not working on sc8280xp
- Added missing configuration for QCS404

---
Dmitry Baryshkov (6):
soc: qcom: pdr: protect locator_addr with the main mutex
soc: qcom: pdr: fix parsing of domains lists
soc: qcom: pdr: extract PDR message marshalling data
soc: qcom: qmi: add a way to remove running service
soc: qcom: add pd-mapper implementation
remoteproc: qcom: enable in-kernel PD mapper

 drivers/remoteproc/qcom_q6v5_adsp.c |  11 +-
 drivers/remoteproc/qcom_q6v5_mss.c  |  10 +-
 drivers/remoteproc/qcom_q6v5_pas.c  |  12 +-
 drivers/remoteproc/qcom_q6v5_wcss.c |  11 +-
 drivers/soc/qcom/Kconfig            |  15 +
 drivers/soc/qcom/Makefile           |   2 +
 drivers/soc/qcom/pdr_interface.c    |   6 +-
 drivers/soc/qcom/pdr_internal.h     | 318 ++----------------
 drivers/soc/qcom/qcom_pd_mapper.c   | 632 ++++++++++++++++++++++++++++++++++++
 drivers/soc/qcom/qcom_pdr_msg.c     | 349 ++++++++++++++++++++
 drivers/soc/qcom/qmi_interface.c    |  67 ++++
 include/linux/soc/qcom/pd_mapper.h  |  28 ++
 include/linux/soc/qcom/qmi.h        |   2 +
 13 files changed, 1161 insertions(+), 302 deletions(-)

---
base-commit: 7b4f2bc91c15fdcf948bb2d9741a9d7d54303f8d
change-id: 20240301-qcom-pd-mapper-e12d622d4ad0

Best regards,

Signature · 1 line
Dmitry Baryshkov <[email protected]>
#1 lore raw

PATCH v5 1/6 soc: qcom: pdr: protect locator_addr with the main mutex

If the service locator server is restarted fast enough, the PDR can rewrite locator_addr fields concurrently. Protect them by placing modification of those fields under the main pdr->lock.

Fixes fbe639b44a82 ("soc: qcom: Introduce Protection Domain Restart helpers")
---
 drivers/soc/qcom/pdr_interface.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/soc/qcom/pdr_interface.c +2 -2
index a1b6a4081dea..19cfe4b41235 100644
@@ -76,12 +76,12 @@ static int pdr_locator_new_server(struct qmi_handle *qmi,
 					      locator_hdl);
 	struct pdr_service *pds;
 
+	mutex_lock(&pdr->lock);
 	/* Create a local client port for QMI communication */
 	pdr->locator_addr.sq_family = AF_QIPCRTR;
 	pdr->locator_addr.sq_node = svc->node;
 	pdr->locator_addr.sq_port = svc->port;
 
-	mutex_lock(&pdr->lock);
 	pdr->locator_init_complete = true;
 	mutex_unlock(&pdr->lock);
 
@@ -104,10 +104,10 @@ static void pdr_locator_del_server(struct qmi_handle *qmi,
 
 	mutex_lock(&pdr->lock);
 	pdr->locator_init_complete = false;
-	mutex_unlock(&pdr->lock);
 
 	pdr->locator_addr.sq_node = 0;
 	pdr->locator_addr.sq_port = 0;
+	mutex_unlock(&pdr->lock);
 }
 
 static const struct qmi_ops pdr_locator_ops = {
Signature · 1 line
2.39.2
#2 lore raw

PATCH v5 2/6 soc: qcom: pdr: fix parsing of domains lists

In reply to Dmitry Baryshkov

While parsing the domains list, start offsets from 0 rather than from domains_read. The domains_read is equal to the total count of the domains we have seen, while the domains list in the message starts from offset 0.

Fixes fbe639b44a82 ("soc: qcom: Introduce Protection Domain Restart helpers")
---
 drivers/soc/qcom/pdr_interface.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/soc/qcom/pdr_interface.c +1 -1
index 19cfe4b41235..3c6f2d21e5e4 100644
@@ -415,7 +415,7 @@ static int pdr_locate_service(struct pdr_handle *pdr, struct pdr_service *pds)
 		if (ret < 0)
 			goto out;
 
-		for (i = domains_read; i < resp->domain_list_len; i++) {
+		for (i = 0; i < resp->domain_list_len; i++) {
 			entry = &resp->domain_list[i];
 
 			if (strnlen(entry->name, sizeof(entry->name)) == sizeof(entry->name))
Signature · 1 line
2.39.2
#3 lore raw

PATCH v5 3/6 soc: qcom: pdr: extract PDR message marshalling data

In reply to Dmitry Baryshkov

The in-kernel PD mapper is going to use same message structures as the QCOM_PDR_HELPERS module. Extract message marshalling data to separate module that can be used by both PDR helpers and by PD mapper.

---
 drivers/soc/qcom/Kconfig        |   4 +
 drivers/soc/qcom/Makefile       |   1 +
 drivers/soc/qcom/pdr_internal.h | 306 ++------------------------------------
 drivers/soc/qcom/qcom_pdr_msg.c | 315 ++++++++++++++++++++++++++++++++++++++++
 4 files changed, 330 insertions(+), 296 deletions(-)
drivers/soc/qcom/Kconfig +4 -0
index 5af33b0e3470..95973c6b828f 100644
@@ -75,8 +75,12 @@ config QCOM_OCMEM
 config QCOM_PDR_HELPERS
 	tristate
 	select QCOM_QMI_HELPERS
+	select QCOM_PDR_MSG
 	depends on NET
 
+config QCOM_PDR_MSG
+	tristate
+
 config QCOM_PMIC_PDCHARGER_ULOG
 	tristate "Qualcomm PMIC PDCharger ULOG driver"
 	depends on RPMSG
drivers/soc/qcom/Makefile +1 -0
index ca0bece0dfff..3110ac3288bc 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
 obj-$(CONFIG_QCOM_OCMEM)	+= ocmem.o
 obj-$(CONFIG_QCOM_PDR_HELPERS)	+= pdr_interface.o
+obj-$(CONFIG_QCOM_PDR_MSG)	+= qcom_pdr_msg.o
 obj-$(CONFIG_QCOM_PMIC_GLINK)	+= pmic_glink.o
 obj-$(CONFIG_QCOM_PMIC_GLINK)	+= pmic_glink_altmode.o
 obj-$(CONFIG_QCOM_PMIC_PDCHARGER_ULOG)	+= pmic_pdcharger_ulog.o
drivers/soc/qcom/pdr_internal.h +10 -296

357 lines not on this page · raw message

drivers/soc/qcom/qcom_pdr_msg.c new file +315 -0

315 lines not on this page · raw message

Signature · 1 line
2.39.2
Reviewed-by on v5 3/6
#4 lore raw

Re: [PATCH v5 3/6] soc: qcom: pdr: extract PDR message marshalling data

drivers/soc/qcom/qcom_pdr_msg.c line 4

Quoted 11 lines · Dmitry Baryshkov

The in-kernel PD mapper is going to use same message structures as the QCOM_PDR_HELPERS module. Extract message marshalling data to separate module that can be used by both PDR helpers and by PD mapper.

drivers/soc/qcom/qcom_pdr_msg.c new file +4 -0
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 The Linux Foundation. All rights reserved.
+ */

Is this the right org attributed ? Definitely not the right year/years.

Please fix, then.

#5 lore raw

Re: [PATCH v5 3/6] soc: qcom: pdr: extract PDR message marshalling data

Quoted 8 lines · Bryan O'Donoghue
Quoted 5 lines · Dmitry Baryshkov

The in-kernel PD mapper is going to use same message structures as the QCOM_PDR_HELPERS module. Extract message marshalling data to separate module that can be used by both PDR helpers and by PD mapper.

Quoted 7 lines

drivers/soc/qcom/qcom_pdr_msg.c line 4

Quoted 5 lines
drivers/soc/qcom/qcom_pdr_msg.c new file +4 -0
@@ -0,0 +1,315 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 The Linux Foundation. All rights reserved.
+ */

Is this the right org attributed ? Definitely not the right year/years.

Yes, it is the right org & year. While the pdr_internal.h header (from which these definitions were moved) didn't contain copyright, the pdr_interface.c file was a part of the commit that brought the header file in. The file contained this copyright header. Thus I assume the most correct action is to use it for the new source file.

Quoted 4 lines

Please fix, then.

Signature · 2 lines
With best wishes
Dmitry
#6 lore raw

PATCH v5 4/6 soc: qcom: qmi: add a way to remove running service

In reply to Dmitry Baryshkov

Add qmi_del_server(), a pair to qmi_add_server(), a way to remove running server from the QMI socket. This is e.g. necessary for pd-mapper, which needs to readd a server each time the DSP is started or stopped.

---
 drivers/soc/qcom/qmi_interface.c | 67 ++++++++++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/qmi.h     |  2 ++
 2 files changed, 69 insertions(+)
drivers/soc/qcom/qmi_interface.c +67 -0
index bb98b06e87f8..18ff2015c682 100644
@@ -289,6 +289,73 @@ int qmi_add_server(struct qmi_handle *qmi, unsigned int service,
 }
 EXPORT_SYMBOL_GPL(qmi_add_server);
 
+static void qmi_send_del_server(struct qmi_handle *qmi, struct qmi_service *svc)
+{
+	struct qrtr_ctrl_pkt pkt;
+	struct sockaddr_qrtr sq;
+	struct msghdr msg = { };
+	struct kvec iv = { &pkt, sizeof(pkt) };
+	int ret;
+
+	memset(&pkt, 0, sizeof(pkt));
+	pkt.cmd = cpu_to_le32(QRTR_TYPE_DEL_SERVER);
+	pkt.server.service = cpu_to_le32(svc->service);
+	pkt.server.instance = cpu_to_le32(svc->version | svc->instance << 8);
+	pkt.server.node = cpu_to_le32(qmi->sq.sq_node);
+	pkt.server.port = cpu_to_le32(qmi->sq.sq_port);
+
+	sq.sq_family = qmi->sq.sq_family;
+	sq.sq_node = qmi->sq.sq_node;
+	sq.sq_port = QRTR_PORT_CTRL;
+
+	msg.msg_name = &sq;
+	msg.msg_namelen = sizeof(sq);
+
+	mutex_lock(&qmi->sock_lock);
+	if (qmi->sock) {
+		ret = kernel_sendmsg(qmi->sock, &msg, &iv, 1, sizeof(pkt));
+		if (ret < 0)
+			pr_err("send service deregistration failed: %d\n", ret);
+	}
+	mutex_unlock(&qmi->sock_lock);
+}
+
+/**
+ * qmi_del_server() - register a service with the name service
+ * @qmi:	qmi handle
+ * @service:	type of the service
+ * @instance:	instance of the service
+ * @version:	version of the service
+ *
+ * Remove registration of the service with the name service. This notifies
+ * clients that they should no longer send messages to the client associated
+ * with @qmi.
+ *
+ * Return: 0 on success, negative errno on failure.
+ */
+int qmi_del_server(struct qmi_handle *qmi, unsigned int service,
+		   unsigned int version, unsigned int instance)
+{
+	struct qmi_service *svc;
+	struct qmi_service *tmp;
+
+	list_for_each_entry_safe(svc, tmp, &qmi->services, list_node) {
+		if (svc->service != service ||
+		    svc->version != version ||
+		    svc->instance != instance)
+			continue;
+
+		qmi_send_del_server(qmi, svc);
+		list_del(&svc->list_node);
+		kfree(svc);
+
+		return 0;
+	}
+
+	return -EINVAL;
+}
+EXPORT_SYMBOL_GPL(qmi_del_server);
+
 /**
  * qmi_txn_init() - allocate transaction id within the given QMI handle
  * @qmi:	QMI handle
include/linux/soc/qcom/qmi.h +2 -0
index 469e02d2aa0d..5039c30e4bdc 100644
@@ -241,6 +241,8 @@ int qmi_add_lookup(struct qmi_handle *qmi, unsigned int service,
 		   unsigned int version, unsigned int instance);
 int qmi_add_server(struct qmi_handle *qmi, unsigned int service,
 		   unsigned int version, unsigned int instance);
+int qmi_del_server(struct qmi_handle *qmi, unsigned int service,
+		   unsigned int version, unsigned int instance);
 
 int qmi_handle_init(struct qmi_handle *qmi, size_t max_msg_len,
 		    const struct qmi_ops *ops,
Signature · 1 line
2.39.2
#7 lore raw

PATCH v5 5/6 soc: qcom: add pd-mapper implementation

In reply to Dmitry Baryshkov

Existing userspace protection domain mapper implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread JSON files if firmware location is changed (or if firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Provide in-kernel service implementing protection domain mapping required to work with several services, which are provided by the DSP firmware.

---
 drivers/soc/qcom/Kconfig           |  11 +
 drivers/soc/qcom/Makefile          |   1 +
 drivers/soc/qcom/pdr_internal.h    |  14 +
 drivers/soc/qcom/qcom_pd_mapper.c  | 632 +++++++++++++++++++++++++++++++++++++
 drivers/soc/qcom/qcom_pdr_msg.c    |  34 ++
 include/linux/soc/qcom/pd_mapper.h |  28 ++
 6 files changed, 720 insertions(+)
drivers/soc/qcom/Kconfig +11 -0
index 95973c6b828f..0a2f2bfd7863 100644
@@ -72,6 +72,17 @@ config QCOM_OCMEM
 	  requirements. This is typically used by the GPU, camera/video, and
 	  audio components on some Snapdragon SoCs.
 
+config QCOM_PD_MAPPER
+	tristate "Qualcomm Protection Domain Mapper"
+	select QCOM_QMI_HELPERS
+	depends on NET && QRTR
+	default QCOM_RPROC_COMMON
+	help
+	  The Protection Domain Mapper maps registered services to the domains
+	  and instances handled by the remote DSPs. This is a kernel-space
+	  implementation of the service. It is a simpler alternative to the
+	  userspace daemon.
+
 config QCOM_PDR_HELPERS
 	tristate
 	select QCOM_QMI_HELPERS
drivers/soc/qcom/Makefile +1 -0
index 3110ac3288bc..d3560f861085 100644
@@ -7,6 +7,7 @@ obj-$(CONFIG_QCOM_COMMAND_DB) += cmd-db.o
 obj-$(CONFIG_QCOM_GSBI)	+=	qcom_gsbi.o
 obj-$(CONFIG_QCOM_MDT_LOADER)	+= mdt_loader.o
 obj-$(CONFIG_QCOM_OCMEM)	+= ocmem.o
+obj-$(CONFIG_QCOM_PD_MAPPER)	+= qcom_pd_mapper.o
 obj-$(CONFIG_QCOM_PDR_HELPERS)	+= pdr_interface.o
 obj-$(CONFIG_QCOM_PDR_MSG)	+= qcom_pdr_msg.o
 obj-$(CONFIG_QCOM_PMIC_GLINK)	+= pmic_glink.o
drivers/soc/qcom/pdr_internal.h +14 -0
index 7e5bb5a95275..8d17f7fb79e7 100644
@@ -13,6 +13,8 @@
 #define SERVREG_SET_ACK_REQ				0x23
 #define SERVREG_RESTART_PD_REQ				0x24
 
+#define SERVREG_LOC_PFR_REQ				0x24
+
 #define SERVREG_DOMAIN_LIST_LENGTH			32
 #define SERVREG_RESTART_PD_REQ_MAX_LEN			67
 #define SERVREG_REGISTER_LISTENER_REQ_LEN		71
@@ -20,6 +22,7 @@
 #define SERVREG_GET_DOMAIN_LIST_REQ_MAX_LEN		74
 #define SERVREG_STATE_UPDATED_IND_MAX_LEN		79
 #define SERVREG_GET_DOMAIN_LIST_RESP_MAX_LEN		2389
+#define SERVREG_LOC_PFR_RESP_MAX_LEN			10
 
 struct servreg_location_entry {
 	char name[SERVREG_NAME_LENGTH + 1];
@@ -79,6 +82,15 @@ struct servreg_set_ack_resp {
 	struct qmi_response_type_v01 resp;
 };
 
+struct servreg_loc_pfr_req {
+	char service[SERVREG_NAME_LENGTH + 1];
+	char reason[257];
+};
+
+struct servreg_loc_pfr_resp {
+	struct qmi_response_type_v01 rsp;
+};
+
 extern const struct qmi_elem_info servreg_location_entry_ei[];
 extern const struct qmi_elem_info servreg_get_domain_list_req_ei[];
 extern const struct qmi_elem_info servreg_get_domain_list_resp_ei[];
@@ -89,5 +101,7 @@ extern const struct qmi_elem_info servreg_restart_pd_resp_ei[];
 extern const struct qmi_elem_info servreg_state_updated_ind_ei[];
 extern const struct qmi_elem_info servreg_set_ack_req_ei[];
 extern const struct qmi_elem_info servreg_set_ack_resp_ei[];
+extern const struct qmi_elem_info servreg_loc_pfr_req_ei[];
+extern const struct qmi_elem_info servreg_loc_pfr_resp_ei[];
 
 #endif
drivers/soc/qcom/qcom_pd_mapper.c new file +632 -0

632 lines not on this page · raw message

drivers/soc/qcom/qcom_pdr_msg.c +34 -0
index a8867e8b1319..bdebbe929468 100644
@@ -313,3 +313,37 @@ const struct qmi_elem_info servreg_set_ack_resp_ei[] = {
 	{}
 };
 EXPORT_SYMBOL_GPL(servreg_set_ack_resp_ei);
+
+const struct qmi_elem_info servreg_loc_pfr_req_ei[] = {
+	{
+		.data_type = QMI_STRING,
+		.elem_len = SERVREG_NAME_LENGTH + 1,
+		.elem_size = sizeof(char),
+		.array_type = VAR_LEN_ARRAY,
+		.tlv_type = 0x01,
+		.offset = offsetof(struct servreg_loc_pfr_req, service)
+	},
+	{
+		.data_type = QMI_STRING,
+		.elem_len = SERVREG_NAME_LENGTH + 1,
+		.elem_size = sizeof(char),
+		.array_type = VAR_LEN_ARRAY,
+		.tlv_type = 0x02,
+		.offset = offsetof(struct servreg_loc_pfr_req, reason)
+	},
+	{}
+};
+EXPORT_SYMBOL_GPL(servreg_loc_pfr_req_ei);
+
+const struct qmi_elem_info servreg_loc_pfr_resp_ei[] = {
+	{
+		.data_type = QMI_STRUCT,
+		.elem_len = 1,
+		.elem_size = sizeof_field(struct servreg_loc_pfr_resp, rsp),
+		.tlv_type = 0x02,
+		.offset = offsetof(struct servreg_loc_pfr_resp, rsp),
+		.ei_array = qmi_response_type_v01_ei,
+	},
+	{}
+};
+EXPORT_SYMBOL_GPL(servreg_loc_pfr_resp_ei);
include/linux/soc/qcom/pd_mapper.h new file +28 -0
new file mode 100644
index 000000000000..d0dd3dfc8fea
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Qualcomm Protection Domain mapper
+ *
+ * Copyright (c) 2023 Linaro Ltd.
+ */
+#ifndef __QCOM_PD_MAPPER__
+#define __QCOM_PD_MAPPER__
+
+#if IS_ENABLED(CONFIG_QCOM_PD_MAPPER)
+
+int qcom_pdm_get(void);
+void qcom_pdm_release(void);
+
+#else
+
+static inline int qcom_pdm_get(void)
+{
+	return 0;
+}
+
+static inline void qcom_pdm_release(void)
+{
+}
+
+#endif
+
+#endif
Signature · 1 line
2.39.2
#8 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

Quoted 10 lines · Dmitry Baryshkov

Existing userspace protection domain mapper implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread JSON files if firmware location is changed (or if firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Provide in-kernel service implementing protection domain mapping required to work with several services, which are provided by the DSP firmware.

...

Quoted 15 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +15 -0
+
+static const struct of_device_id qcom_pdm_domains[] = {
+	{ .compatible = "qcom,apq8096", .data = msm8996_domains, },
+	{ .compatible = "qcom,msm8996", .data = msm8996_domains, },
+	{ .compatible = "qcom,msm8998", .data = msm8998_domains, },
+	{ .compatible = "qcom,qcm2290", .data = qcm2290_domains, },
+	{ .compatible = "qcom,qcs404", .data = qcs404_domains, },
+	{ .compatible = "qcom,sc7180", .data = sc7180_domains, },
+	{ .compatible = "qcom,sc7280", .data = sc7280_domains, },
+	{ .compatible = "qcom,sc8180x", .data = sc8180x_domains, },
+	{ .compatible = "qcom,sc8280xp", .data = sc8280xp_domains, },
+	{ .compatible = "qcom,sda660", .data = sdm660_domains, },
+	{ .compatible = "qcom,sdm660", .data = sdm660_domains, },
+	{ .compatible = "qcom,sdm670", .data = sdm670_domains, },
+	{ .compatible = "qcom,sdm845", .data = sdm845_domains, },

drivers/soc/qcom/qcom_pd_mapper.c line 524

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+	{ .compatible = "qcom,sm6115", .data = sm6115_domains, },
+	{ .compatible = "qcom,sm6350", .data = sm6350_domains, },
+	{ .compatible = "qcom,sm8150", .data = sm8150_domains, },
+	{ .compatible = "qcom,sm8250", .data = sm8250_domains, },
+	{ .compatible = "qcom,sm8350", .data = sm8350_domains, },
+	{ .compatible = "qcom,sm8450", .data = sm8350_domains, },
+	{ .compatible = "qcom,sm8550", .data = sm8550_domains, },
+	{ .compatible = "qcom,sm8650", .data = sm8550_domains, },
+	{},
+};

If this is supposed to be a module, then why no MODULE_DEVICE_TABLE?

drivers/soc/qcom/qcom_pd_mapper.c line 533

Quoted 9 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +9 -0
+
+static int qcom_pdm_start(void)
+{
+	const struct of_device_id *match;
+	const struct qcom_pdm_domain_data * const *domains;
+	struct device_node *root;
+	int ret, i;
+
+	pr_debug("PDM: starting service\n");

Drop simple entry/exit debug messages.

drivers/soc/qcom/qcom_pd_mapper.c line 546

Quoted 13 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +13 -0
+
+	root = of_find_node_by_path("/");
+	if (!root)
+		return -ENODEV;
+
+	match = of_match_node(qcom_pdm_domains, root);
+	of_node_put(root);
+	if (!match) {
+		pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
+		return 0;
+	}
+
+	domains = match->data;

All this is odd a bit. Why is this not a driver? You are open coding here of_device_get_match_data().

Quoted 34 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +34 -0
+	if (!domains) {
+		pr_debug("PDM: no domains\n");
+		return 0;
+	}
+
+	for (i = 0; domains[i]; i++) {
+		ret = qcom_pdm_add_domain(domains[i]);
+		if (ret)
+			goto free_domains;
+	}
+
+	ret = qmi_handle_init(&qcom_pdm_handle, 1024,
+			      NULL, qcom_pdm_msg_handlers);
+	if (ret)
+		goto free_domains;
+
+	ret = qmi_add_server(&qcom_pdm_handle, SERVREG_LOCATOR_SERVICE,
+			     SERVREG_QMI_VERSION, SERVREG_QMI_INSTANCE);
+	if (ret) {
+		pr_err("PDM: error adding server %d\n", ret);
+		goto release_handle;
+	}
+
+	return 0;
+
+release_handle:
+	qmi_handle_release(&qcom_pdm_handle);
+
+free_domains:
+	qcom_pdm_free_domains();
+
+	return ret;
+}
+

drivers/soc/qcom/qcom_pd_mapper.c line 590

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+static void qcom_pdm_stop(void)
+{
+	qmi_del_server(&qcom_pdm_handle, SERVREG_LOCATOR_SERVICE,
+		       SERVREG_QMI_VERSION, SERVREG_QMI_INSTANCE);
+
+	qmi_handle_release(&qcom_pdm_handle);
+
+	qcom_pdm_free_domains();
+
+	WARN_ON(!list_empty(&qcom_pdm_services));

This should be handled, not warned.

drivers/soc/qcom/qcom_pd_mapper.c line 592

Quoted 2 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +2 -0
+
+	pr_debug("PDM: stopped service\n");

Drop debug. Tracing gives you such information.

drivers/soc/qcom/qcom_pd_mapper.c line 597

Quoted 5 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +5 -0
+}
+
+/**
+ * qcom_pdm_get() - ensure that PD mapper is up and running
+ */

Please provide full kerneldoc, so also return and short description.

drivers/soc/qcom/qcom_pd_mapper.c line 610

Quoted 13 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +13 -0
+int qcom_pdm_get(void)
+{
+	int ret = 0;
+
+	mutex_lock(&qcom_pdm_mutex);
+
+	if (!qcom_pdm_count)
+		ret = qcom_pdm_start();
+
+	if (!ret)
+		++qcom_pdm_count;
+
+	mutex_unlock(&qcom_pdm_mutex);

Looks like you implement refcnt manually...

Also, what happens if this module gets unloaded? How do you handle module dependencies? I don't see any device links. Bartosz won't be happy... We really need to stop adding more of old-style-buggy-never-unload-logic. At least for new code.

drivers/soc/qcom/qcom_pd_mapper.c line 116

Quoted 3 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+	return ret;
+}

No export? Isn't this a module?

drivers/soc/qcom/qcom_pd_mapper.c line 619

Quoted 6 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +6 -0
+
+/**
+ * qcom_pdm_release() - possibly stop PD mapper service
+ */
+void qcom_pdm_release(void)
+{

Best regards,
Krzysztof

#9 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

Quoted 34 lines · Krzysztof Kozlowski
Quoted 10 lines · Dmitry Baryshkov

Existing userspace protection domain mapper implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread JSON files if firmware location is changed (or if firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Provide in-kernel service implementing protection domain mapping required to work with several services, which are provided by the DSP firmware.

...

Quoted 19 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +19 -0
+
+static const struct of_device_id qcom_pdm_domains[] = {
+     { .compatible = "qcom,apq8096", .data = msm8996_domains, },
+     { .compatible = "qcom,msm8996", .data = msm8996_domains, },
+     { .compatible = "qcom,msm8998", .data = msm8998_domains, },
+     { .compatible = "qcom,qcm2290", .data = qcm2290_domains, },
+     { .compatible = "qcom,qcs404", .data = qcs404_domains, },
+     { .compatible = "qcom,sc7180", .data = sc7180_domains, },
+     { .compatible = "qcom,sc7280", .data = sc7280_domains, },
+     { .compatible = "qcom,sc8180x", .data = sc8180x_domains, },
+     { .compatible = "qcom,sc8280xp", .data = sc8280xp_domains, },
+     { .compatible = "qcom,sda660", .data = sdm660_domains, },
+     { .compatible = "qcom,sdm660", .data = sdm660_domains, },
+     { .compatible = "qcom,sdm670", .data = sdm670_domains, },
+     { .compatible = "qcom,sdm845", .data = sdm845_domains, },
+     { .compatible = "qcom,sm6115", .data = sm6115_domains, },
+     { .compatible = "qcom,sm6350", .data = sm6350_domains, },
+     { .compatible = "qcom,sm8150", .data = sm8150_domains, },
+     { .compatible = "qcom,sm8250", .data = sm8250_domains, },
Quoted 8 lines

drivers/soc/qcom/qcom_pd_mapper.c line 524

Quoted 6 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +6 -0
+     { .compatible = "qcom,sm8350", .data = sm8350_domains, },
+     { .compatible = "qcom,sm8450", .data = sm8350_domains, },
+     { .compatible = "qcom,sm8550", .data = sm8550_domains, },
+     { .compatible = "qcom,sm8650", .data = sm8550_domains, },
+     {},
+};

If this is supposed to be a module, then why no MODULE_DEVICE_TABLE?

Ok, I should add this to the commit message.

For now:

This module is loaded automatically by the remoteproc drivers when necessary. It uses a root node to match a protection domains map for a particular device.

Quoted 12 lines

drivers/soc/qcom/qcom_pd_mapper.c line 533

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +9 -0
+
+static int qcom_pdm_start(void)
+{
+     const struct of_device_id *match;
+     const struct qcom_pdm_domain_data * const *domains;
+     struct device_node *root;
+     int ret, i;
+
+     pr_debug("PDM: starting service\n");

Drop simple entry/exit debug messages.

ack

Quoted 17 lines
Quoted 4 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+     root = of_find_node_by_path("/");
+     if (!root)

drivers/soc/qcom/qcom_pd_mapper.c line 546

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+             return -ENODEV;
+
+     match = of_match_node(qcom_pdm_domains, root);
+     of_node_put(root);
+     if (!match) {
+             pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
+             return 0;
+     }
+
+     domains = match->data;

All this is odd a bit. Why is this not a driver? You are open coding here of_device_get_match_data().

Except that it matches the root node instead of matching a device.

Quoted 40 lines
Quoted 40 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +38 -0
+     if (!domains) {
+             pr_debug("PDM: no domains\n");
+             return 0;
+     }
+
+     for (i = 0; domains[i]; i++) {
+             ret = qcom_pdm_add_domain(domains[i]);
+             if (ret)
+                     goto free_domains;
+     }
+
+     ret = qmi_handle_init(&qcom_pdm_handle, 1024,
+                           NULL, qcom_pdm_msg_handlers);
+     if (ret)
+             goto free_domains;
+
+     ret = qmi_add_server(&qcom_pdm_handle, SERVREG_LOCATOR_SERVICE,
+                          SERVREG_QMI_VERSION, SERVREG_QMI_INSTANCE);
+     if (ret) {
+             pr_err("PDM: error adding server %d\n", ret);
+             goto release_handle;
+     }
+
+     return 0;
+
+release_handle:
+     qmi_handle_release(&qcom_pdm_handle);
+
+free_domains:
+     qcom_pdm_free_domains();
+
+     return ret;
+}
+
+static void qcom_pdm_stop(void)
+{
+     qmi_del_server(&qcom_pdm_handle, SERVREG_LOCATOR_SERVICE,
+                    SERVREG_QMI_VERSION, SERVREG_QMI_INSTANCE);
Quoted 8 lines

drivers/soc/qcom/qcom_pd_mapper.c line 590

Quoted 6 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +6 -0
+
+     qmi_handle_release(&qcom_pdm_handle);
+
+     qcom_pdm_free_domains();
+
+     WARN_ON(!list_empty(&qcom_pdm_services));

This should be handled, not warned.

I'll just drop it, qcom_pdm_free_domains() should free them.

Quoted 14 lines

drivers/soc/qcom/qcom_pd_mapper.c line 592

Quoted 3 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +2 -0
+
+     pr_debug("PDM: stopped service\n");

Drop debug. Tracing gives you such information.

drivers/soc/qcom/qcom_pd_mapper.c line 597

Quoted 5 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +5 -0
+}
+
+/**
+ * qcom_pdm_get() - ensure that PD mapper is up and running
+ */

Please provide full kerneldoc, so also return and short description.

Quoted 15 lines

drivers/soc/qcom/qcom_pd_mapper.c line 610

Quoted 13 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +13 -0
+int qcom_pdm_get(void)
+{
+     int ret = 0;
+
+     mutex_lock(&qcom_pdm_mutex);
+
+     if (!qcom_pdm_count)
+             ret = qcom_pdm_start();
+
+     if (!ret)
+             ++qcom_pdm_count;
+
+     mutex_unlock(&qcom_pdm_mutex);

Looks like you implement refcnt manually...

Yes... There is refcount_dec_and_mutex_lock(), but I found no corresponding refcount_add_and_mutex_lock(). Maybe I'm misunderstanding that framework.
I need to have a mutex after incrementing the lock from 0, so that the driver can init QMI handlers.

Quoted 4 lines

Also, what happens if this module gets unloaded? How do you handle module dependencies? I don't see any device links. Bartosz won't be happy... We really need to stop adding more of old-style-buggy-never-unload-logic. At least for new code.

Module dependencies are handled by the symbol dependencies. Remoteproc module depends on this symbol. Once q6v5 remoteproc modules are unloaded this module can be unloaded too.
But I know what got missing. I should add 'depends on PD_MAPPER || !PD_MAPPER' to remoteproc Kconfig entries.

Quoted 6 lines

drivers/soc/qcom/qcom_pd_mapper.c line 116

Quoted 4 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+     return ret;
+}

No export? Isn't this a module?

Ack, missed them.

Quoted 11 lines

drivers/soc/qcom/qcom_pd_mapper.c line 619

Quoted 7 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +6 -0
+
+/**
+ * qcom_pdm_release() - possibly stop PD mapper service
+ */
+void qcom_pdm_release(void)
+{

Best regards,
Krzysztof

Signature · 2 lines
With best wishes
Dmitry
#10 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

Quoted 44 lines · Dmitry Baryshkov
Quoted 34 lines · Krzysztof Kozlowski
Quoted 10 lines · Dmitry Baryshkov

Existing userspace protection domain mapper implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread JSON files if firmware location is changed (or if firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Provide in-kernel service implementing protection domain mapping required to work with several services, which are provided by the DSP firmware.

...

Quoted 19 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +19 -0
+
+static const struct of_device_id qcom_pdm_domains[] = {
+     { .compatible = "qcom,apq8096", .data = msm8996_domains, },
+     { .compatible = "qcom,msm8996", .data = msm8996_domains, },
+     { .compatible = "qcom,msm8998", .data = msm8998_domains, },
+     { .compatible = "qcom,qcm2290", .data = qcm2290_domains, },
+     { .compatible = "qcom,qcs404", .data = qcs404_domains, },
+     { .compatible = "qcom,sc7180", .data = sc7180_domains, },
+     { .compatible = "qcom,sc7280", .data = sc7280_domains, },
+     { .compatible = "qcom,sc8180x", .data = sc8180x_domains, },
+     { .compatible = "qcom,sc8280xp", .data = sc8280xp_domains, },
+     { .compatible = "qcom,sda660", .data = sdm660_domains, },
+     { .compatible = "qcom,sdm660", .data = sdm660_domains, },
+     { .compatible = "qcom,sdm670", .data = sdm670_domains, },
+     { .compatible = "qcom,sdm845", .data = sdm845_domains, },
+     { .compatible = "qcom,sm6115", .data = sm6115_domains, },
+     { .compatible = "qcom,sm6350", .data = sm6350_domains, },
+     { .compatible = "qcom,sm8150", .data = sm8150_domains, },
+     { .compatible = "qcom,sm8250", .data = sm8250_domains, },
Quoted 8 lines

drivers/soc/qcom/qcom_pd_mapper.c line 524

Quoted 6 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +6 -0
+     { .compatible = "qcom,sm8350", .data = sm8350_domains, },
+     { .compatible = "qcom,sm8450", .data = sm8350_domains, },
+     { .compatible = "qcom,sm8550", .data = sm8550_domains, },
+     { .compatible = "qcom,sm8650", .data = sm8550_domains, },
+     {},
+};

If this is supposed to be a module, then why no MODULE_DEVICE_TABLE?

Quoted 5 lines

Ok, I should add this to the commit message.

For now:

This module is loaded automatically by the remoteproc drivers when

Hm? How remoteproc loads this module?

Quoted 36 lines

necessary. It uses a root node to match a protection domains map for a particular device.

Quoted 12 lines

drivers/soc/qcom/qcom_pd_mapper.c line 533

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +9 -0
+
+static int qcom_pdm_start(void)
+{
+     const struct of_device_id *match;
+     const struct qcom_pdm_domain_data * const *domains;
+     struct device_node *root;
+     int ret, i;
+
+     pr_debug("PDM: starting service\n");

Drop simple entry/exit debug messages.

ack

Quoted 17 lines
Quoted 4 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+     root = of_find_node_by_path("/");
+     if (!root)

drivers/soc/qcom/qcom_pd_mapper.c line 546

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+             return -ENODEV;
+
+     match = of_match_node(qcom_pdm_domains, root);
+     of_node_put(root);
+     if (!match) {
+             pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
+             return 0;
+     }
+
+     domains = match->data;

All this is odd a bit. Why is this not a driver? You are open coding here of_device_get_match_data().

Quoted 1 line

Except that it matches the root node instead of matching a device.

Yep, but if this was proper device then things get simpler, don't they?

...

Quoted 14 lines
Quoted 7 lines

drivers/soc/qcom/qcom_pd_mapper.c line 610

Quoted 5 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +5 -0
+
+     if (!ret)
+             ++qcom_pdm_count;
+
+     mutex_unlock(&qcom_pdm_mutex);

Looks like you implement refcnt manually...

Yes... There is refcount_dec_and_mutex_lock(), but I found no corresponding refcount_add_and_mutex_lock(). Maybe I'm misunderstanding that framework.
I need to have a mutex after incrementing the lock from 0, so that the driver can init QMI handlers.

Quoted 6 lines
Quoted 4 lines

Also, what happens if this module gets unloaded? How do you handle module dependencies? I don't see any device links. Bartosz won't be happy... We really need to stop adding more of old-style-buggy-never-unload-logic. At least for new code.

Module dependencies are handled by the symbol dependencies.

You mean build dependencies, not runtime load.

Quoted 2 lines

Remoteproc module depends on this symbol. Once q6v5 remoteproc modules are unloaded this module can be unloaded too.

I am pretty sure you can unload this and get crashes.

Best regards,
Krzysztof

#11 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

Quoted 46 lines · Krzysztof Kozlowski
Quoted 44 lines · Dmitry Baryshkov
Quoted 42 lines · Krzysztof Kozlowski
Quoted 10 lines · Dmitry Baryshkov

Existing userspace protection domain mapper implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread JSON files if firmware location is changed (or if firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Provide in-kernel service implementing protection domain mapping required to work with several services, which are provided by the DSP firmware.

...

Quoted 15 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +15 -0
+
+static const struct of_device_id qcom_pdm_domains[] = {
+     { .compatible = "qcom,apq8096", .data = msm8996_domains, },
+     { .compatible = "qcom,msm8996", .data = msm8996_domains, },
+     { .compatible = "qcom,msm8998", .data = msm8998_domains, },
+     { .compatible = "qcom,qcm2290", .data = qcm2290_domains, },
+     { .compatible = "qcom,qcs404", .data = qcs404_domains, },
+     { .compatible = "qcom,sc7180", .data = sc7180_domains, },
+     { .compatible = "qcom,sc7280", .data = sc7280_domains, },
+     { .compatible = "qcom,sc8180x", .data = sc8180x_domains, },
+     { .compatible = "qcom,sc8280xp", .data = sc8280xp_domains, },
+     { .compatible = "qcom,sda660", .data = sdm660_domains, },
+     { .compatible = "qcom,sdm660", .data = sdm660_domains, },
+     { .compatible = "qcom,sdm670", .data = sdm670_domains, },
+     { .compatible = "qcom,sdm845", .data = sdm845_domains, },

drivers/soc/qcom/qcom_pd_mapper.c line 524

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+     { .compatible = "qcom,sm6115", .data = sm6115_domains, },
+     { .compatible = "qcom,sm6350", .data = sm6350_domains, },
+     { .compatible = "qcom,sm8150", .data = sm8150_domains, },
+     { .compatible = "qcom,sm8250", .data = sm8250_domains, },
+     { .compatible = "qcom,sm8350", .data = sm8350_domains, },
+     { .compatible = "qcom,sm8450", .data = sm8350_domains, },
+     { .compatible = "qcom,sm8550", .data = sm8550_domains, },
+     { .compatible = "qcom,sm8650", .data = sm8550_domains, },
+     {},
+};

If this is supposed to be a module, then why no MODULE_DEVICE_TABLE?

Quoted 7 lines
Quoted 5 lines

Ok, I should add this to the commit message.

For now:

This module is loaded automatically by the remoteproc drivers when

Hm? How remoteproc loads this module?

remoteproc drivers call qcom_pdm_start(). This brings in this module via symbol deps.

Quoted 37 lines
Quoted 37 lines

necessary. It uses a root node to match a protection domains map for a particular device.

Quoted 12 lines

drivers/soc/qcom/qcom_pd_mapper.c line 533

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +9 -0
+
+static int qcom_pdm_start(void)
+{
+     const struct of_device_id *match;
+     const struct qcom_pdm_domain_data * const *domains;
+     struct device_node *root;
+     int ret, i;
+
+     pr_debug("PDM: starting service\n");

Drop simple entry/exit debug messages.

ack

Quoted 17 lines
Quoted 4 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+     root = of_find_node_by_path("/");
+     if (!root)

drivers/soc/qcom/qcom_pd_mapper.c line 546

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+             return -ENODEV;
+
+     match = of_match_node(qcom_pdm_domains, root);
+     of_node_put(root);
+     if (!match) {
+             pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
+             return 0;
+     }
+
+     domains = match->data;

All this is odd a bit. Why is this not a driver? You are open coding here of_device_get_match_data().

Quoted 3 lines
Quoted 1 line

Except that it matches the root node instead of matching a device.

Yep, but if this was proper device then things get simpler, don't they?

I don't think we are supposed to have devices for software things? This is purely a software construct. It replaces userspace daemon for the reason outlined in the cover letter, but other than that there is no hardware entity. Not even a firmware entity to drive this thing.

Quoted 14 lines
Quoted 14 lines
Quoted 7 lines

drivers/soc/qcom/qcom_pd_mapper.c line 610

Quoted 5 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +5 -0
+
+     if (!ret)
+             ++qcom_pdm_count;
+
+     mutex_unlock(&qcom_pdm_mutex);

Looks like you implement refcnt manually...

Yes... There is refcount_dec_and_mutex_lock(), but I found no corresponding refcount_add_and_mutex_lock(). Maybe I'm misunderstanding that framework.
I need to have a mutex after incrementing the lock from 0, so that the driver can init QMI handlers.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Also, what happens if this module gets unloaded? How do you handle module dependencies? I don't see any device links. Bartosz won't be happy... We really need to stop adding more of old-style-buggy-never-unload-logic. At least for new code.

Module dependencies are handled by the symbol dependencies.

You mean build dependencies, not runtime load.

No, I mean runtime load dependencies.

Quoted 5 lines
Quoted 3 lines

Remoteproc module depends on this symbol. Once q6v5 remoteproc modules are unloaded this module can be unloaded too.

I am pretty sure you can unload this and get crashes.

If for some reason somebody has called qcom_pdm_get() without qcom_pdm_release(), then yes. To make it 100% safe, I can cleanup actions to module_exit(), but for me it looks like an overkill.

Signature · 2 lines
With best wishes
Dmitry
#12 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

Quoted 6 lines · Dmitry Baryshkov
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+};

If this is supposed to be a module, then why no MODULE_DEVICE_TABLE?

Ok, I should add this to the commit message.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

For now:

This module is loaded automatically by the remoteproc drivers when

Hm? How remoteproc loads this module?

remoteproc drivers call qcom_pdm_start(). This brings in this module via symbol deps.

Ah, right, I understand now. So this should not be loaded on its own on the machine.

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines

necessary. It uses a root node to match a protection domains map for a particular device.

Quoted 12 lines

drivers/soc/qcom/qcom_pd_mapper.c line 533

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +9 -0
+
+static int qcom_pdm_start(void)
+{
+     const struct of_device_id *match;
+     const struct qcom_pdm_domain_data * const *domains;
+     struct device_node *root;
+     int ret, i;
+
+     pr_debug("PDM: starting service\n");

Drop simple entry/exit debug messages.

ack

Quoted 17 lines
Quoted 4 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+     root = of_find_node_by_path("/");
+     if (!root)

drivers/soc/qcom/qcom_pd_mapper.c line 546

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+             return -ENODEV;
+
+     match = of_match_node(qcom_pdm_domains, root);
+     of_node_put(root);
+     if (!match) {
+             pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
+             return 0;
+     }
+
+     domains = match->data;

All this is odd a bit. Why is this not a driver? You are open coding here of_device_get_match_data().

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Except that it matches the root node instead of matching a device.

Yep, but if this was proper device then things get simpler, don't they?

I don't think we are supposed to have devices for software things? This is purely a software construct. It replaces userspace daemon for the reason outlined in the cover letter, but other than that there is no hardware entity. Not even a firmware entity to drive this thing.

Firmware interfaces are also not "devices" but we create device drivers for them. The code lies in drivers, so it is a driver, even if somehow kernel software construct. fs/pstore/ram also has a driver, even though this is software device to handle ram dumps (it is not a driver for RAM). net/qrtr/smd.c is not even in the drivers and as well describes some sort of software daemon.

If this was not a driver, then it would be a subsystem... but it is not a subsystem, right?

Quoted 27 lines
Quoted 15 lines
Quoted 15 lines
Quoted 8 lines

drivers/soc/qcom/qcom_pd_mapper.c line 610

Quoted 6 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +5 -0
+
+     if (!ret)
+             ++qcom_pdm_count;
+
+     mutex_unlock(&qcom_pdm_mutex);

Looks like you implement refcnt manually...

Yes... There is refcount_dec_and_mutex_lock(), but I found no corresponding refcount_add_and_mutex_lock(). Maybe I'm misunderstanding that framework.
I need to have a mutex after incrementing the lock from 0, so that the driver can init QMI handlers.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Also, what happens if this module gets unloaded? How do you handle module dependencies? I don't see any device links. Bartosz won't be happy... We really need to stop adding more of old-style-buggy-never-unload-logic. At least for new code.

Module dependencies are handled by the symbol dependencies.

You mean build dependencies, not runtime load.

No, I mean runtime load dependencies.

Quoted 1 line
Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Remoteproc module depends on this symbol. Once q6v5 remoteproc modules are unloaded this module can be unloaded too.

I am pretty sure you can unload this and get crashes.

If for some reason somebody has called qcom_pdm_get() without qcom_pdm_release(), then yes. To make it 100% safe, I can cleanup actions to module_exit(), but for me it looks like an overkill.

I'll come with some more concrete example if you are not convinced.

Best regards,
Krzysztof

#13 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

Quoted 74 lines · Krzysztof Kozlowski
Quoted 6 lines · Dmitry Baryshkov
Quoted 6 lines
Quoted 6 lines
Quoted 3 lines
Quoted 1 line

+};

If this is supposed to be a module, then why no MODULE_DEVICE_TABLE?

Ok, I should add this to the commit message.

Quoted 8 lines
Quoted 5 lines
Quoted 3 lines

For now:

This module is loaded automatically by the remoteproc drivers when

Hm? How remoteproc loads this module?

remoteproc drivers call qcom_pdm_start(). This brings in this module via symbol deps.

Ah, right, I understand now. So this should not be loaded on its own on the machine.

Quoted 38 lines
Quoted 38 lines
Quoted 38 lines

necessary. It uses a root node to match a protection domains map for a particular device.

Quoted 12 lines

drivers/soc/qcom/qcom_pd_mapper.c line 533

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +9 -0
+
+static int qcom_pdm_start(void)
+{
+     const struct of_device_id *match;
+     const struct qcom_pdm_domain_data * const *domains;
+     struct device_node *root;
+     int ret, i;
+
+     pr_debug("PDM: starting service\n");

Drop simple entry/exit debug messages.

ack

Quoted 17 lines
Quoted 4 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +3 -0
+
+     root = of_find_node_by_path("/");
+     if (!root)

drivers/soc/qcom/qcom_pd_mapper.c line 546

Quoted 10 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +10 -0
+             return -ENODEV;
+
+     match = of_match_node(qcom_pdm_domains, root);
+     of_node_put(root);
+     if (!match) {
+             pr_notice("PDM: no support for the platform, userspace daemon might be required.\n");
+             return 0;
+     }
+
+     domains = match->data;

All this is odd a bit. Why is this not a driver? You are open coding here of_device_get_match_data().

Quoted 8 lines
Quoted 3 lines
Quoted 1 line

Except that it matches the root node instead of matching a device.

Yep, but if this was proper device then things get simpler, don't they?

I don't think we are supposed to have devices for software things? This is purely a software construct. It replaces userspace daemon for the reason outlined in the cover letter, but other than that there is no hardware entity. Not even a firmware entity to drive this thing.

Firmware interfaces are also not "devices" but we create device drivers for them. The code lies in drivers, so it is a driver, even if somehow kernel software construct. fs/pstore/ram also has a driver, even though this is software device to handle ram dumps (it is not a driver for RAM). net/qrtr/smd.c is not even in the drivers and as well describes some sort of software daemon.

Quoted 2 lines

If this was not a driver, then it would be a subsystem... but it is not a subsystem, right?

It is a server. Or a service. Compare this to nfs-kernel-server or historical things like khttpd.

Quoted 31 lines
Quoted 31 lines
Quoted 16 lines
Quoted 16 lines
Quoted 9 lines

drivers/soc/qcom/qcom_pd_mapper.c line 610

Quoted 7 lines
drivers/soc/qcom/qcom_pd_mapper.c new file +5 -0
+
+     if (!ret)
+             ++qcom_pdm_count;
+
+     mutex_unlock(&qcom_pdm_mutex);

Looks like you implement refcnt manually...

Yes... There is refcount_dec_and_mutex_lock(), but I found no corresponding refcount_add_and_mutex_lock(). Maybe I'm misunderstanding that framework.
I need to have a mutex after incrementing the lock from 0, so that the driver can init QMI handlers.

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Also, what happens if this module gets unloaded? How do you handle module dependencies? I don't see any device links. Bartosz won't be happy... We really need to stop adding more of old-style-buggy-never-unload-logic. At least for new code.

Module dependencies are handled by the symbol dependencies.

You mean build dependencies, not runtime load.

No, I mean runtime load dependencies.

Quoted 4 lines
Quoted 3 lines

Remoteproc module depends on this symbol. Once q6v5 remoteproc modules are unloaded this module can be unloaded too.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I am pretty sure you can unload this and get crashes.

If for some reason somebody has called qcom_pdm_get() without qcom_pdm_release(), then yes. To make it 100% safe, I can cleanup actions to module_exit(), but for me it looks like an overkill.

I'll come with some more concrete example if you are not convinced.

Sure, I might easily be missing something.

Signature · 2 lines
With best wishes
Dmitry
#14 lore raw

Re: [PATCH v5 5/6] soc: qcom: add pd-mapper implementation

In reply to Krzysztof Kozlowski
Quoted 5 lines · Krzysztof Kozlowski
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

Remoteproc module depends on this symbol. Once q6v5 remoteproc modules are unloaded this module can be unloaded too.

Quoted 7 lines
Quoted 5 lines
Quoted 1 line

I am pretty sure you can unload this and get crashes.

If for some reason somebody has called qcom_pdm_get() without qcom_pdm_release(), then yes. To make it 100% safe, I can cleanup actions to module_exit(), but for me it looks like an overkill.

I'll come with some more concrete example if you are not convinced.

It's not possible, this code does not compile. I fixed one thing but then it fails in other places. This was probably never built and for sure never really compile-tested in few more configurations.

Best regards,
Krzysztof

#15 lore raw

PATCH v5 6/6 remoteproc: qcom: enable in-kernel PD mapper

In reply to Dmitry Baryshkov

Request in-kernel protection domain mapper to be started before starting Qualcomm DSP and release it once DSP is stopped. Once all DSPs are stopped, the PD mapper will be stopped too.

---
 drivers/remoteproc/qcom_q6v5_adsp.c | 11 ++++++++++-
 drivers/remoteproc/qcom_q6v5_mss.c  | 10 +++++++++-
 drivers/remoteproc/qcom_q6v5_pas.c  | 12 +++++++++++-
 drivers/remoteproc/qcom_q6v5_wcss.c | 11 ++++++++++-
 4 files changed, 40 insertions(+), 4 deletions(-)
drivers/remoteproc/qcom_q6v5_adsp.c +10 -1
index 1d24c9b656a8..02d0c626b03b 100644
@@ -23,6 +23,7 @@
 #include <linux/remoteproc.h>
 #include <linux/reset.h>
 #include <linux/soc/qcom/mdt_loader.h>
+#include <linux/soc/qcom/pd_mapper.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
 
@@ -375,10 +376,14 @@ static int adsp_start(struct rproc *rproc)
 	int ret;
 	unsigned int val;
 
-	ret = qcom_q6v5_prepare(&adsp->q6v5);
+	ret = qcom_pdm_get();
 	if (ret)
 		return ret;
 
+	ret = qcom_q6v5_prepare(&adsp->q6v5);
+	if (ret)
+		goto put_pdm;
+
 	ret = adsp_map_carveout(rproc);
 	if (ret) {
 		dev_err(adsp->dev, "ADSP smmu mapping failed\n");
@@ -446,6 +451,8 @@ static int adsp_start(struct rproc *rproc)
 	adsp_unmap_carveout(rproc);
 disable_irqs:
 	qcom_q6v5_unprepare(&adsp->q6v5);
+put_pdm:
+	qcom_pdm_release();
 
 	return ret;
 }
@@ -478,6 +485,8 @@ static int adsp_stop(struct rproc *rproc)
 	if (handover)
 		qcom_adsp_pil_handover(&adsp->q6v5);
 
+	qcom_pdm_release();
+
 	return ret;
 }
 
drivers/remoteproc/qcom_q6v5_mss.c +9 -1
index 1779fc890e10..791f11e7adbf 100644
@@ -26,6 +26,7 @@
 #include <linux/remoteproc.h>
 #include <linux/reset.h>
 #include <linux/soc/qcom/mdt_loader.h>
+#include <linux/soc/qcom/pd_mapper.h>
 #include <linux/iopoll.h>
 #include <linux/slab.h>
 
@@ -1581,10 +1582,14 @@ static int q6v5_start(struct rproc *rproc)
 	int xfermemop_ret;
 	int ret;
 
-	ret = q6v5_mba_load(qproc);
+	ret = qcom_pdm_get();
 	if (ret)
 		return ret;
 
+	ret = q6v5_mba_load(qproc);
+	if (ret)
+		goto put_pdm;
+
 	dev_info(qproc->dev, "MBA booted with%s debug policy, loading mpss\n",
 		 qproc->dp_size ? "" : "out");
 
@@ -1613,6 +1618,8 @@ static int q6v5_start(struct rproc *rproc)
 reclaim_mpss:
 	q6v5_mba_reclaim(qproc);
 	q6v5_dump_mba_logs(qproc);
+put_pdm:
+	qcom_pdm_release();
 
 	return ret;
 }
@@ -1627,6 +1634,7 @@ static int q6v5_stop(struct rproc *rproc)
 		dev_err(qproc->dev, "timed out on wait\n");
 
 	q6v5_mba_reclaim(qproc);
+	qcom_pdm_release();
 
 	return 0;
 }
drivers/remoteproc/qcom_q6v5_pas.c +11 -1
index 54d8005d40a3..653e54f975fc 100644
@@ -23,6 +23,7 @@
 #include <linux/regulator/consumer.h>
 #include <linux/remoteproc.h>
 #include <linux/soc/qcom/mdt_loader.h>
+#include <linux/soc/qcom/pd_mapper.h>
 #include <linux/soc/qcom/smem.h>
 #include <linux/soc/qcom/smem_state.h>
 
@@ -261,10 +262,14 @@ static int adsp_start(struct rproc *rproc)
 	struct qcom_adsp *adsp = rproc->priv;
 	int ret;
 
-	ret = qcom_q6v5_prepare(&adsp->q6v5);
+	ret = qcom_pdm_get();
 	if (ret)
 		return ret;
 
+	ret = qcom_q6v5_prepare(&adsp->q6v5);
+	if (ret)
+		goto put_pdm;
+
 	ret = adsp_pds_enable(adsp, adsp->proxy_pds, adsp->proxy_pd_count);
 	if (ret < 0)
 		goto disable_irqs;
@@ -356,6 +361,9 @@ static int adsp_start(struct rproc *rproc)
 	/* Remove pointer to the loaded firmware, only valid in adsp_load() & adsp_start() */
 	adsp->firmware = NULL;
 
+put_pdm:
+	qcom_pdm_release();
+
 	return ret;
 }
 
@@ -399,6 +407,8 @@ static int adsp_stop(struct rproc *rproc)
 	if (handover)
 		qcom_pas_handover(&adsp->q6v5);
 
+	qcom_pdm_release();
+
 	return ret;
 }
 
drivers/remoteproc/qcom_q6v5_wcss.c +10 -1
index 94f68c919ee6..33bd30e07bf0 100644
@@ -240,13 +240,17 @@ static int q6v5_wcss_start(struct rproc *rproc)
 	struct q6v5_wcss *wcss = rproc->priv;
 	int ret;
 
+	ret = qcom_pdm_get();
+	if (ret)
+		return ret;
+
 	qcom_q6v5_prepare(&wcss->q6v5);
 
 	/* Release Q6 and WCSS reset */
 	ret = reset_control_deassert(wcss->wcss_reset);
 	if (ret) {
 		dev_err(wcss->dev, "wcss_reset failed\n");
-		return ret;
+		goto put_pdm;
 	}
 
 	ret = reset_control_deassert(wcss->wcss_q6_reset);
@@ -288,6 +292,9 @@ static int q6v5_wcss_start(struct rproc *rproc)
 wcss_reset:
 	reset_control_assert(wcss->wcss_reset);
 
+put_pdm:
+	qcom_pdm_release();
+
 	return ret;
 }
 
@@ -735,6 +742,8 @@ static int q6v5_wcss_stop(struct rproc *rproc)
 
 	qcom_q6v5_unprepare(&wcss->q6v5);
 
+	qcom_pdm_release();
+
 	return 0;
 }
 
Signature · 1 line
2.39.2
#16 lore raw
In reply to Dmitry Baryshkov
Quoted 11 lines · Dmitry Baryshkov

Protection domain mapper is a QMI service providing mapping between 'protection domains' and services supported / allowed in these domains. For example such mapping is required for loading of the WiFi firmware or for properly starting up the UCSI / altmode / battery manager support.

The existing userspace implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread the JSON files if the firmware location is changed (or if the firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Quoted 8 lines

However this configuration is largely static and common between different platforms. Provide in-kernel service implementing static per-platform data.

Unlike previous revisions of the patchset, this iteration uses static configuration per platform, rather than building it dynamically from the list of DSPs being started.

I applied this patchset and... it does not compile.

drivers/remoteproc/qcom_q6v5_wcss.c:243:15: error: implicit declaration of function ‘qcom_pdm_get’; did you mean ‘em_pd_get’? [-Werror=implicit-function-declaration]

That's just defconfig, so I have doubts this was tested.

Best regards,
Krzysztof

#17 lore raw
Quoted 22 lines · Krzysztof Kozlowski
Quoted 11 lines · Dmitry Baryshkov

Protection domain mapper is a QMI service providing mapping between 'protection domains' and services supported / allowed in these domains. For example such mapping is required for loading of the WiFi firmware or for properly starting up the UCSI / altmode / battery manager support.

The existing userspace implementation has several issue. It doesn't play well with CONFIG_EXTRA_FIRMWARE, it doesn't reread the JSON files if the firmware location is changed (or if the firmware was not available at the time pd-mapper was started but the corresponding directory is mounted later), etc.

Quoted 8 lines

However this configuration is largely static and common between different platforms. Provide in-kernel service implementing static per-platform data.

Unlike previous revisions of the patchset, this iteration uses static configuration per platform, rather than building it dynamically from the list of DSPs being started.

Quoted 8 lines

I applied this patchset and... it does not compile.

drivers/remoteproc/qcom_q6v5_wcss.c:243:15: error: implicit declaration of function ‘qcom_pdm_get’; did you mean ‘em_pd_get’? [-Werror=implicit-function-declaration]

That's just defconfig, so I have doubts this was tested.

I usually do not care about defconfig. This was tested as the built-in. I had the WCNSS driver disabled, never needed it. Enabled it now.

Signature · 2 lines
With best wishes
Dmitry