soc: qcom: add in-kernel pd-mapper implementation
v3 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.
NOTE: this is an RFC / RFT, the domain mapping data might be inaccurate (especially for SM6xxx and SC7xxx platforms), which is reflected by several TODO and FIXME comments in the code.
--
2.39.2
---
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 (7):
soc: qcom: pdr: protect locator_addr with the main mutex
soc: qcom: qmi: add a way to remove running service
soc: qcom: add pd-mapper implementation
remoteproc: qcom: pas: correct data indentation
remoteproc: qcom: adsp: add configuration for in-kernel pdm
remoteproc: qcom: mss: add configuration for in-kernel pdm
remoteproc: qcom: pas: add configuration for in-kernel pdm
drivers/remoteproc/Kconfig | 3 + drivers/remoteproc/qcom_q6v5_adsp.c | 82 +++++- drivers/remoteproc/qcom_q6v5_mss.c | 80 +++++- drivers/remoteproc/qcom_q6v5_pas.c | 546 ++++++++++++++++++++++++++++++------ drivers/soc/qcom/Kconfig | 10 + drivers/soc/qcom/Makefile | 2 + drivers/soc/qcom/pdr_interface.c | 6 +- drivers/soc/qcom/qcom_pdm.c | 346 +++++++++++++++++++++++ drivers/soc/qcom/qcom_pdm_msg.c | 188 +++++++++++++ drivers/soc/qcom/qcom_pdm_msg.h | 66 +++++ drivers/soc/qcom/qmi_interface.c | 67 +++++ include/linux/soc/qcom/pd_mapper.h | 39 +++ include/linux/soc/qcom/qmi.h | 2 + 13 files changed, 1348 insertions(+), 89 deletions(-)
---
base-commit: 67908bf6954b7635d33760ff6dfc189fc26ccc89
change-id: 20240301-qcom-pd-mapper-e12d622d4ad0
Best regards,
Signature · 1 line
Dmitry Baryshkov <[email protected]>
RFC PATCH v3 1/7 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.
--- drivers/soc/qcom/pdr_interface.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/soc/qcom/pdr_interface.c +4 -2
@@ -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 = {
@@ -133,11 +133,13 @@ static int pdr_register_listener(struct pdr_handle *pdr, req.enable = enable;strscpy (req.service_path, pds->service_path,sizeof (req.service_path)); +mutex_lock (&pdr->lock); ret =qmi_send_request (&pdr->notifier_hdl, &pds->addr, &txn,SERVREG_REGISTER_LISTENER_REQ ,SERVREG_REGISTER_LISTENER_REQ_LEN , servreg_register_listener_req_ei, &req); +mutex_unlock (&pdr->lock);if (ret <0 ) {qmi_txn_cancel (&txn);return ret;
Signature · 1 line
2.39.2
RFC PATCH v3 2/7 soc: qcom: qmi: add a way to remove running service
In reply to Dmitry BaryshkovAdd 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
@@ -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(&vc->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
@@ -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
Re: [PATCH RFC v3 2/7] soc: qcom: qmi: add a way to remove running service
Quoted 7 lines · Dmitry Baryshkov
Add
qmi_del_server(), a pair toqmi_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.Signed-off-by Dmitry Baryshkov <[email protected]>---
[...]
drivers/soc/qcom/qmi_interface.c int qmi_add_server(struct qmi_handle *qmi, unsigned int service, · line 350
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c +10
-0+ +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(&vc->list_node); +//kfree(svc);
foo
Konrad
Re: [PATCH RFC v3 2/7] soc: qcom: qmi: add a way to remove running service
Quoted 14 lines · Konrad Dybcio
Quoted 7 lines · Dmitry Baryshkov
Add
qmi_del_server(), a pair toqmi_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.Signed-off-by Dmitry Baryshkov <[email protected]>---
[...]
Quoted 12 lines
drivers/soc/qcom/qmi_interface.c int qmi_add_server(struct qmi_handle *qmi, unsigned int service, · line 350
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c +10
-0+ +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(&vc->list_node); +//kfree(svc); foo
Ugh, I had that disabled at some point and forgot to re-enable.
Signature · 2 lines
With best wishes Dmitry
RFC PATCH v3 3/7 soc: qcom: add pd-mapper implementation
In reply to Dmitry BaryshkovExisting 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 | 10 ++ drivers/soc/qcom/Makefile | 2 + drivers/soc/qcom/qcom_pdm.c | 346 +++++++++++++++++++++++++++++++++++++ drivers/soc/qcom/qcom_pdm_msg.c | 188 ++++++++++++++++++++ drivers/soc/qcom/qcom_pdm_msg.h | 66 +++++++ include/linux/soc/qcom/pd_mapper.h | 39 +++++ 6 files changed, 651 insertions(+)
drivers/soc/qcom/Kconfig +10 -0
@@ -72,6 +72,16 @@ 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 + 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 +2 -0
@@ -7,6 +7,8 @@ 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 +qcom_pd_mapper-y += qcom_pdm.o qcom_pdm_msg.o obj-$(CONFIG_QCOM_PDR_HELPERS) += pdr_interface.o obj-$(CONFIG_QCOM_PMIC_GLINK) += pmic_glink.o obj-$(CONFIG_QCOM_PMIC_GLINK) += pmic_glink_altmode.o
drivers/soc/qcom/qcom_pdm.c new file +346 -0
346 lines not on this page · raw message
drivers/soc/qcom/qcom_pdm_msg.c new file +188 -0
188 lines not on this page · raw message
drivers/soc/qcom/qcom_pdm_msg.h new file +66 -0
66 lines not on this page · raw message
include/linux/soc/qcom/pd_mapper.h new file +39 -0
@@ -0,0 +1,39 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Qualcomm Protection Domain mapper +* +* Copyright (c) 2023 Linaro Ltd. +*/ +#ifndef __QCOM_PD_MAPPER__ +#define __QCOM_PD_MAPPER__ + +struct qcom_pdm_domain_data { +const char *domain; +u32 instance_id; +/* NULL-terminated array */ +const char * services[]; +}; + +#if IS_ENABLED (CONFIG_QCOM_PD_MAPPER ) + +int qcom_pdm_add_domains (const struct qcom_pdm_domain_data *const *data, +size_t num_data); +void qcom_pdm_del_domains (const struct qcom_pdm_domain_data *const *data, +size_t num_data); + +#else + +static inline int qcom_pdm_add_domains (const struct qcom_pdm_domain_data *const *data, +size_t num_data) +{ +return 0 ; +} + +static inline void qcom_pdm_del_domains (const struct qcom_pdm_domain_data *const *data, +size_t num_data) +{ +} + +#endif + +#endif
Signature · 1 line
2.39.2
RFC PATCH v3 4/7 remoteproc: qcom: pas: correct data indentation
In reply to Dmitry BaryshkovCorrect indentation of several struct adsp_data instances to always use a single TAB character instead of two.
--- drivers/remoteproc/qcom_q6v5_pas.c | 124 ++++++++++++++++++------------------- 1 file changed, 62 insertions(+), 62 deletions(-)
drivers/remoteproc/qcom_q6v5_pas.c +62 -62
@@ -807,24 +807,24 @@ static void adsp_remove(struct platform_device *pdev) }static const struct adsp_data adsp_resource_init = { - .crash_reason_smem =423 , - .firmware_name ="adsp.mdt" , - .pas_id =1 , - .auto_boot = true, - .ssr_name ="lpass" , - .sysmon_name ="adsp" , - .ssctl_id =0x14 , + .crash_reason_smem =423 , + .firmware_name ="adsp.mdt" , + .pas_id =1 , + .auto_boot = true, + .ssr_name ="lpass" , + .sysmon_name ="adsp" , + .ssctl_id =0x14 , };static const struct adsp_data sdm845_adsp_resource_init = { - .crash_reason_smem =423 , - .firmware_name ="adsp.mdt" , - .pas_id =1 , - .auto_boot = true, - .load_state ="adsp" , - .ssr_name ="lpass" , - .sysmon_name ="adsp" , - .ssctl_id =0x14 , + .crash_reason_smem =423 , + .firmware_name ="adsp.mdt" , + .pas_id =1 , + .auto_boot = true, + .load_state ="adsp" , + .ssr_name ="lpass" , + .sysmon_name ="adsp" , + .ssctl_id =0x14 , };static const struct adsp_data sm6350_adsp_resource = {
@@ -859,18 +859,18 @@ static const struct adsp_data sm6375_mpss_resource = { };static const struct adsp_data sm8150_adsp_resource = { - .crash_reason_smem =423 , - .firmware_name ="adsp.mdt" , - .pas_id =1 , - .auto_boot = true, - .proxy_pd_names = (char *[]){ -"cx" , -NULL - }, - .load_state ="adsp" , - .ssr_name ="lpass" , - .sysmon_name ="adsp" , - .ssctl_id =0x14 , + .crash_reason_smem =423 , + .firmware_name ="adsp.mdt" , + .pas_id =1 , + .auto_boot = true, + .proxy_pd_names = (char *[]){ +"cx" , +NULL + }, + .load_state ="adsp" , + .ssr_name ="lpass" , + .sysmon_name ="adsp" , + .ssctl_id =0x14 , };static const struct adsp_data sm8250_adsp_resource = {
@@ -906,17 +906,17 @@ static const struct adsp_data sm8350_adsp_resource = { };static const struct adsp_data msm8996_adsp_resource = { - .crash_reason_smem =423 , - .firmware_name ="adsp.mdt" , - .pas_id =1 , - .auto_boot = true, - .proxy_pd_names = (char *[]){ -"cx" , -NULL - }, - .ssr_name ="lpass" , - .sysmon_name ="adsp" , - .ssctl_id =0x14 , + .crash_reason_smem =423 , + .firmware_name ="adsp.mdt" , + .pas_id =1 , + .auto_boot = true, + .proxy_pd_names = (char *[]){ +"cx" , +NULL + }, + .ssr_name ="lpass" , + .sysmon_name ="adsp" , + .ssctl_id =0x14 , };static const struct adsp_data cdsp_resource_init = {
@@ -1063,33 +1063,33 @@ static const struct adsp_data sc8180x_mpss_resource = { };static const struct adsp_data msm8996_slpi_resource_init = { - .crash_reason_smem =424 , - .firmware_name ="slpi.mdt" , - .pas_id =12 , - .auto_boot = true, - .proxy_pd_names = (char *[]){ -"ssc_cx" , -NULL - }, - .ssr_name ="dsps" , - .sysmon_name ="slpi" , - .ssctl_id =0x16 , + .crash_reason_smem =424 , + .firmware_name ="slpi.mdt" , + .pas_id =12 , + .auto_boot = true, + .proxy_pd_names = (char *[]){ +"ssc_cx" , +NULL + }, + .ssr_name ="dsps" , + .sysmon_name ="slpi" , + .ssctl_id =0x16 , };static const struct adsp_data sdm845_slpi_resource_init = { - .crash_reason_smem =424 , - .firmware_name ="slpi.mdt" , - .pas_id =12 , - .auto_boot = true, - .proxy_pd_names = (char *[]){ -"lcx" , -"lmx" , -NULL - }, - .load_state ="slpi" , - .ssr_name ="dsps" , - .sysmon_name ="slpi" , - .ssctl_id =0x16 , + .crash_reason_smem =424 , + .firmware_name ="slpi.mdt" , + .pas_id =12 , + .auto_boot = true, + .proxy_pd_names = (char *[]){ +"lcx" , +"lmx" , +NULL + }, + .load_state ="slpi" , + .ssr_name ="dsps" , + .sysmon_name ="slpi" , + .ssctl_id =0x16 , };static const struct adsp_data wcss_resource_init = {
Signature · 1 line
2.39.2
Re: [PATCH RFC v3 4/7] remoteproc: qcom: pas: correct data indentation
Quoted 5 lines · Dmitry Baryshkov
Correct indentation of several struct
adsp_datainstances to always use a single TAB character instead of two.Signed-off-by Dmitry Baryshkov <[email protected]>---
Konrad
RFC PATCH v3 5/7 remoteproc: qcom: adsp: add configuration for in-kernel pdm
In reply to Dmitry BaryshkovAdd domain / service configuration for the in-kernel protection domain mapper service.
--- drivers/remoteproc/Kconfig | 1 + drivers/remoteproc/qcom_q6v5_adsp.c | 82 ++++++++++++++++++++++++++++++++++--- 2 files changed, 78 insertions(+), 5 deletions(-)
drivers/remoteproc/Kconfig +1 -0
@@ -181,6 +181,7 @@ config QCOM_Q6V5_ADSP depends on QCOM_SYSMON || QCOM_SYSMON=n depends on RPMSG_QCOM_GLINK || RPMSG_QCOM_GLINK=n depends on QCOM_AOSS_QMP || QCOM_AOSS_QMP=n + depends on QCOM_PD_MAPPER || QCOM_PD_MAPPER=n select MFD_SYSCON select QCOM_PIL_INFO select QCOM_MDT_LOADER
drivers/remoteproc/qcom_q6v5_adsp.c +77 -5
161 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH v3 6/7 remoteproc: qcom: mss: add configuration for in-kernel pdm
In reply to Dmitry BaryshkovAdd domain / service configuration for the in-kernel protection domain mapper service.
--- drivers/remoteproc/Kconfig | 1 + drivers/remoteproc/qcom_q6v5_mss.c | 80 +++++++++++++++++++++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-)
drivers/remoteproc/Kconfig +1 -0
@@ -202,6 +202,7 @@ config QCOM_Q6V5_MSS depends on QCOM_SYSMON || QCOM_SYSMON=n depends on RPMSG_QCOM_GLINK || RPMSG_QCOM_GLINK=n depends on QCOM_AOSS_QMP || QCOM_AOSS_QMP=n + depends on QCOM_PD_MAPPER || QCOM_PD_MAPPER=n select MFD_SYSCON select QCOM_MDT_LOADER select QCOM_PIL_INFO
drivers/remoteproc/qcom_q6v5_mss.c +79 -1
167 lines not on this page · raw message
Signature · 1 line
2.39.2
RFC PATCH v3 7/7 remoteproc: qcom: pas: add configuration for in-kernel pdm
In reply to Dmitry BaryshkovAdd domain / service configuration for the in-kernel protection domain mapper service.
--- drivers/remoteproc/Kconfig | 1 + drivers/remoteproc/qcom_q6v5_pas.c | 414 +++++++++++++++++++++++++++++++++++-- 2 files changed, 400 insertions(+), 15 deletions(-)
drivers/remoteproc/Kconfig +1 -0
@@ -223,6 +223,7 @@ config QCOM_Q6V5_PAS depends on QCOM_SYSMON || QCOM_SYSMON=n depends on RPMSG_QCOM_GLINK || RPMSG_QCOM_GLINK=n depends on QCOM_AOSS_QMP || QCOM_AOSS_QMP=n + depends on QCOM_PD_MAPPER || QCOM_PD_MAPPER=n select MFD_SYSCON select QCOM_PIL_INFO select QCOM_MDT_LOADER
drivers/remoteproc/qcom_q6v5_pas.c +399 -15
673 lines not on this page · raw message
Signature · 1 line
2.39.2