misc: fastrpc: FastRPC reserved memory assignment for SDM845 SLPI
v3 cover misc: fastrpc: FastRPC reserved memory assignment for SDM845 SLPI
* About *
The Qualcomm SDM845 SoC has a separate SLPI (Sensor Low Power Island) DSP for sensors connected to the SoC which is responsible for exposing sensors to userspace, power saving, and other features.
While sensors are connected to GPIOs of the SoC, they cannot be used because the hypervisor blocks direct access to the sensors, thus the DSP must be used to access any sensor on this SoC. The SLPI DSP uses a GLink edge (dsps) to communicate with the host and has a FastRPC interface to load files from the host filesystem such as sensor configuration files. The FastRPC interface does not use regular FastRPC Compute Banks but instead uses an allocated CMA region through which communication happens.
* Changes *
This patchseries add support to the FastRPC for assigning a coherent memory region to a DSP via the hypervisor with the correct permissions. This is necessary to support the SLPI found in the Qualcomm SDM845 SoC which does not have dedicated FastRPC Compute Banks, in contrast to newer SoCs, but uses a memory region instead when allocating buffers.
* Related patches *
1. Remoteproc changes to support the SLPI DSP in SDM845 (v3), needs to be applied:
https://lore.kernel.org/linux-remoteproc/[email protected]
2. DTS changes (v5), already applied:
https://lore.kernel.org/linux-devicetree/[email protected]
This serie does not depend on any serie, but all of them are necessary to enable the feature in the end.
* Changelog *
Changes in v3:
- Dropped debug prints.
- Added Reviewed-By tags from v2.
Changes in v2:
- Removed double blank lines
- Dropped dt-bindings property as it is not needed for driver behavior
- Add additional patch to allocate buffers via CMA memory for DSPs without dedicated FastRPC Compute Banks.
Kind regards,
Dylan Van Assche
Dylan Van Assche (2):
misc: fastrpc: support complete DMA pool access to the DSP
misc: fastrpc: use coherent pool for untranslated Compute Banks
drivers/misc/fastrpc.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-)
Signature · 1 line
2.40.1
PATCH v3 1/2 misc: fastrpc: support complete DMA pool access to the DSP
To support FastRPC Context Banks which aren't mapped via the SMMU, make the whole reserved memory region available to the DSP to allow access to coherent buffers.
This is performed by assigning the memory to the DSP via a hypervisor call to set the correct permissions for the Virtual Machines on the DSP. This is only necessary when a memory region is provided for SLPI DSPs so guard this with a domain ID check.
--- drivers/misc/fastrpc.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/misc/fastrpc.c +13 -0
@@ -2231,6 +2231,8 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)int i, err, domain_id =-1 , vmcount;const char *domain;bool secure_dsp; +struct device_node *rmem_node; +struct reserved_mem *rmem;unsigned int vmids[FASTRPC_MAX_VMIDS ]; err =of_property_read_string (rdev->of_node,"label" , &domain);
@@ -2274,6 +2276,17 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev) } } + rmem_node =of_parse_phandle (rdev->of_node,"memory-region" ,0 ); +if (domain_id ==SDSP_DOMAIN_ID && rmem_node) { + rmem =of_reserved_mem_lookup (rmem_node); +if (!rmem) +return -EINVAL ; + +qcom_scm_assign_mem (rmem->base, rmem->size, &data->perms, + data->vmperms, data->vmcount); + + } + secure_dsp = !(of_property_read_bool (rdev->of_node,"qcom,non-secure-domain" )); data->secure = secure_dsp;
Signature · 1 line
2.40.1
Re: [PATCH v3 1/2] misc: fastrpc: support complete DMA pool access to the DSP
Hi Dylan,
kernel test robot noticed the following build warnings:
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/Dylan-Van-Assche/misc-fastrpc-support-complete-DMA-pool-access-to-the-DSP/20230507-161214 base: char-misc/char-misc-testing patch link: https://lore.kernel.org/r/20230507080839.37578-2-me%40dylanvanassche.be patch subject: [PATCH v3 1/2] misc: fastrpc: support complete DMA pool access to the DSP config: mips-randconfig-m041-20230509 (https://download.01.org/0day-ci/archive/20230511/[email protected]/config) compiler: mips-linux-gcc (GCC) 12.1.0
If you fix the issue, kindly add following tag where applicable
| Reported-by: kernel test robot <[email protected]> | Reported-by: Dan Carpenter <[email protected]> | Link: https://lore.kernel.org/r/[email protected]/
New smatch warnings:drivers/misc/fastrpc.c:2283 fastrpc_rpmsg_probe() warn: possible memory leak of 'data'
Old smatch warnings:drivers/misc/fastrpc.c:1269 fastrpc_init_create_static_process() error: we previously assumed 'fl->cctx->remote_heap' could be null (see line 1261)
vim +/data +2283 drivers/misc/fastrpc.c
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2227 static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2228 {
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2229 struct device *rdev = &rpdev->dev;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2230 struct fastrpc_channel_ctx *data;
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2231 int i, err, domain_id = -1, vmcount;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2232 const char *domain;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2233 bool secure_dsp;
8bebea279f7a60 Dylan Van Assche 2023-05-07 2234 struct device_node *rmem_node;
8bebea279f7a60 Dylan Van Assche 2023-05-07 2235 struct reserved_mem *rmem;
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2236 unsigned int vmids[FASTRPC_MAX_VMIDS];
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2237
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2238 err = of_property_read_string(rdev->of_node, "label", &domain);
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2239 if (err) {
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2240 dev_info(rdev, "FastRPC Domain not specified in DT\n");
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2241 return err;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2242 }
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2243
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2244 for (i = 0; i <= CDSP_DOMAIN_ID; i++) {
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2245 if (!strcmp(domains[i], domain)) {
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2246 domain_id = i;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2247 break;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2248 }
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2249 }
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2250
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2251 if (domain_id < 0) {
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2252 dev_info(rdev, "FastRPC Invalid Domain ID %d\n", domain_id);
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2253 return -EINVAL;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2254 }
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2255
1ce91d45ba77a4 Abel Vesa 2022-11-25 2256 if (of_reserved_mem_device_init_by_idx(rdev, rdev->of_node, 0))
1ce91d45ba77a4 Abel Vesa 2022-11-25 2257 dev_info(rdev, "no reserved DMA memory for FASTRPC\n");
1ce91d45ba77a4 Abel Vesa 2022-11-25 2258
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2259 vmcount = of_property_read_variable_u32_array(rdev->of_node,
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2260 "qcom,vmids", &vmids[0], 0, FASTRPC_MAX_VMIDS);
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2261 if (vmcount < 0)
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2262 vmcount = 0;
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2263 else if (!qcom_scm_is_available())
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2264 return -EPROBE_DEFER;
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2265
278d56f970ae6e Bjorn Andersson 2019-08-29 2266 data = kzalloc(sizeof(*data), GFP_KERNEL);Allocated here.
278d56f970ae6e Bjorn Andersson 2019-08-29 2267 if (!data)
278d56f970ae6e Bjorn Andersson 2019-08-29 2268 return -ENOMEM;
278d56f970ae6e Bjorn Andersson 2019-08-29 2269
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2270 if (vmcount) {
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2271 data->vmcount = vmcount;
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2272 data->perms = BIT(QCOM_SCM_VMID_HLOS);
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2273 for (i = 0; i < data->vmcount; i++) {
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2274 data->vmperms[i].vmid = vmids[i];
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2275 data->vmperms[i].perm = QCOM_SCM_PERM_RWX;
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2276 }
e90d911906196b Vamsi Krishna Gattupalli 2022-02-14 2277 }
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2278
8bebea279f7a60 Dylan Van Assche 2023-05-07 2279 rmem_node = of_parse_phandle(rdev->of_node, "memory-region", 0);
8bebea279f7a60 Dylan Van Assche 2023-05-07 2280 if (domain_id == SDSP_DOMAIN_ID && rmem_node) {
8bebea279f7a60 Dylan Van Assche 2023-05-07 2281 rmem = of_reserved_mem_lookup(rmem_node);
8bebea279f7a60 Dylan Van Assche 2023-05-07 2282 if (!rmem)8bebea279f7a60 Dylan Van Assche 2023-05-07 @2283 return -EINVAL;
Needs goto fdev_error;
8bebea279f7a60 Dylan Van Assche 2023-05-07 2284
8bebea279f7a60 Dylan Van Assche 2023-05-07 2285 qcom_scm_assign_mem(rmem->base, rmem->size, &data->perms,
8bebea279f7a60 Dylan Van Assche 2023-05-07 2286 data->vmperms, data->vmcount);
8bebea279f7a60 Dylan Van Assche 2023-05-07 2287
8bebea279f7a60 Dylan Van Assche 2023-05-07 2288 }
8bebea279f7a60 Dylan Van Assche 2023-05-07 2289
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2290 secure_dsp = !(of_property_read_bool(rdev->of_node, "qcom,non-secure-domain"));
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2291 data->secure = secure_dsp;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2292
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2293 switch (domain_id) {
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2294 case ADSP_DOMAIN_ID:
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2295 case MDSP_DOMAIN_ID:
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2296 case SDSP_DOMAIN_ID:
7f1f481263c3ce Jeya R 2022-02-14 2297 /* Unsigned PD offloading is only supported on CDSP*/
7f1f481263c3ce Jeya R 2022-02-14 2298 data->unsigned_support = false;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2299 err = fastrpc_device_register(rdev, data, secure_dsp, domains[domain_id]);
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2300 if (err)
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2301 goto fdev_error;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2302 break;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2303 case CDSP_DOMAIN_ID:
7f1f481263c3ce Jeya R 2022-02-14 2304 data->unsigned_support = true;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2305 /* Create both device nodes so that we can allow both Signed and Unsigned PD */
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2306 err = fastrpc_device_register(rdev, data, true, domains[domain_id]);
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2307 if (err)
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2308 goto fdev_error;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2309
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2310 err = fastrpc_device_register(rdev, data, false, domains[domain_id]);
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2311 if (err)
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2312 goto fdev_error;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2313 break;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2314 default:
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2315 err = -EINVAL;
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2316 goto fdev_error;
0978de9fc7335c Srinivas Kandagatla 2020-05-11 2317 }
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2318
278d56f970ae6e Bjorn Andersson 2019-08-29 2319 kref_init(&data->refcount);
278d56f970ae6e Bjorn Andersson 2019-08-29 2320
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2321 dev_set_drvdata(&rpdev->dev, data);
9bde43a0e2f469 Abel Vesa 2022-11-25 2322 rdev->dma_mask = &data->dma_mask;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2323 dma_set_mask_and_coherent(rdev, DMA_BIT_MASK(32));
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2324 INIT_LIST_HEAD(&data->users);
76e8e4ace1ed2c Abel Vesa 2022-11-25 2325 INIT_LIST_HEAD(&data->invoke_interrupted_mmaps);
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2326 spin_lock_init(&data->lock);
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2327 idr_init(&data->ctx_idr);
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2328 data->domain_id = domain_id;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2329 data->rpdev = rpdev;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2330
11819ed2b70da9 Christophe JAILLET 2022-11-25 2331 err = of_platform_populate(rdev->of_node, NULL, NULL, rdev);
11819ed2b70da9 Christophe JAILLET 2022-11-25 2332 if (err)
11819ed2b70da9 Christophe JAILLET 2022-11-25 2333 goto populate_error;
11819ed2b70da9 Christophe JAILLET 2022-11-25 2334
11819ed2b70da9 Christophe JAILLET 2022-11-25 2335 return 0;
11819ed2b70da9 Christophe JAILLET 2022-11-25 2336
11819ed2b70da9 Christophe JAILLET 2022-11-25 2337 populate_error:
11819ed2b70da9 Christophe JAILLET 2022-11-25 2338 if (data->fdevice)
11819ed2b70da9 Christophe JAILLET 2022-11-25 2339 misc_deregister(&data->fdevice->miscdev);
11819ed2b70da9 Christophe JAILLET 2022-11-25 2340 if (data->secure_fdevice)
11819ed2b70da9 Christophe JAILLET 2022-11-25 2341 misc_deregister(&data->secure_fdevice->miscdev);
11819ed2b70da9 Christophe JAILLET 2022-11-25 2342
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2343 fdev_error:
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2344 kfree(data);
3abe3ab3cdab71 Srinivas Kandagatla 2022-02-14 2345 return err;
f6f9279f2bf0e3 Srinivas Kandagatla 2019-02-08 2346 }Signature · 2 lines
0-DAY CI Kernel Test Service https://github.com/intel/lkp-tests
PATCH v3 2/2 misc: fastrpc: use coherent pool for untranslated Compute Banks
In reply to Dylan Van AsscheUse fastrpc_remote_heap_alloc to allocate from the FastRPC device instead of the Compute Bank when the session ID is 0. This ensures that the allocation is inside the coherent DMA pool which is already accessible to the DSP. This is necessary to support FastRPC devices which do not have dedicated Compute Banks such as the SLPI on the SDM845. The latter uses an allocated CMA region instead of FastRPC Compute Banks.
--- drivers/misc/fastrpc.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/misc/fastrpc.c +4 -1
@@ -939,7 +939,10 @@ static int fastrpc_get_args(u32 kernel, struct fastrpc_invoke_ctx *ctx) ctx->msg_sz = pkt_size; - err =fastrpc_buf_alloc (ctx->fl, dev, pkt_size, &ctx->buf); +if (ctx->fl->sctx->sid) + err =fastrpc_buf_alloc (ctx->fl, dev, pkt_size, &ctx->buf); +else + err =fastrpc_remote_heap_alloc (ctx->fl, dev, pkt_size, &ctx->buf);if (err)return err;
Signature · 1 line
2.40.1