Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Documentation/devicetree/bindings/misc/qcom,fastrpc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,10 @@ patternProperties:
qcom,nsessions:
$ref: /schemas/types.yaml#/definitions/uint32
default: 1
deprecated: true
description: >
A value indicating how many sessions can share this context bank.
Session duplication is now handled by the driver.

required:
- compatible
Expand Down
142 changes: 74 additions & 68 deletions drivers/misc/fastrpc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
#define CDSP_DOMAIN_ID (3)
#define GDSP_DOMAIN_ID (4)
#define FASTRPC_MAX_SESSIONS 14
#define FASTRPC_DUP_SESSIONS 4
#define FASTRPC_MAX_VMIDS 16
#define FASTRPC_ALIGN 128
#define FASTRPC_MAX_FDLIST 16
Expand Down Expand Up @@ -2395,48 +2396,37 @@ static const struct file_operations fastrpc_fops = {
.compat_ioctl = fastrpc_device_ioctl,
};

static int fastrpc_cb_probe(struct platform_device *pdev)
static int fastrpc_cb_init(struct platform_device *pdev)
{
struct fastrpc_channel_ctx *cctx;
struct fastrpc_session_ctx *sess;
struct device *dev = &pdev->dev;
int i, sessions = 0;
unsigned long flags;
u32 sid = 0;
int rc;

cctx = dev_get_drvdata(dev->parent);
if (!cctx)
return -EINVAL;

of_property_read_u32(dev->of_node, "qcom,nsessions", &sessions);
if (of_property_read_u32(dev->of_node, "reg", &sid))
dev_info(dev, "FastRPC Session ID not specified in DT\n");

spin_lock_irqsave(&cctx->lock, flags);
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS) {
dev_err(&pdev->dev, "too many sessions\n");
spin_unlock_irqrestore(&cctx->lock, flags);
dev_err(dev, "too many sessions\n");
return -ENOSPC;
}
sess = &cctx->session[cctx->sesscount++];
sess->used = false;
sess->valid = true;
sess->dev = dev;
sess->sid = sid;
sess->coherent = of_property_read_bool(dev->of_node, "dma-coherent");
dev_set_drvdata(dev, sess);

if (of_property_read_u32(dev->of_node, "reg", &sess->sid))
dev_info(dev, "FastRPC Session ID not specified in DT\n");

if (sessions > 0) {
struct fastrpc_session_ctx *dup_sess;

for (i = 1; i < sessions; i++) {
if (cctx->sesscount >= FASTRPC_MAX_SESSIONS)
break;
dup_sess = &cctx->session[cctx->sesscount++];
memcpy(dup_sess, sess, sizeof(*dup_sess));
}
}
spin_unlock_irqrestore(&cctx->lock, flags);

rc = dma_set_mask(dev, DMA_BIT_MASK(32));
if (rc) {
dev_err(dev, "32-bit DMA enable failed\n");
Expand All @@ -2446,37 +2436,63 @@ static int fastrpc_cb_probe(struct platform_device *pdev)
return 0;
}

static void fastrpc_cb_remove(struct platform_device *pdev)
static void fastrpc_cb_devices_destroy(struct rpmsg_device *rpdev)
{
struct fastrpc_channel_ctx *cctx = dev_get_drvdata(pdev->dev.parent);
struct fastrpc_session_ctx *sess = dev_get_drvdata(&pdev->dev);
struct fastrpc_channel_ctx *cctx = dev_get_drvdata(&rpdev->dev);
struct device *rdev = &rpdev->dev;
struct platform_device *pdev;
struct device_node *np;
unsigned long flags;
int i;

spin_lock_irqsave(&cctx->lock, flags);
for (i = 0; i < FASTRPC_MAX_SESSIONS; i++) {
if (cctx->session[i].sid == sess->sid) {
cctx->session[i].valid = false;
cctx->sesscount--;
for (i = 0; i < cctx->sesscount; i++)
cctx->session[i].valid = false;
spin_unlock_irqrestore(&cctx->lock, flags);

for_each_available_child_of_node(rdev->of_node, np) {
if (!of_device_is_compatible(np, "qcom,fastrpc-compute-cb")) {
of_node_put(np);
continue;
}

pdev = of_find_device_by_node(np);
of_node_put(np);
if (pdev)
of_platform_device_destroy(&pdev->dev, NULL);
}
spin_unlock_irqrestore(&cctx->lock, flags);
}

static const struct of_device_id fastrpc_match_table[] = {
{ .compatible = "qcom,fastrpc-compute-cb", },
{}
};
static int fastrpc_cb_devices_create(struct rpmsg_device *rpdev)
{
struct device *rdev = &rpdev->dev;
struct platform_device *pdev;
struct device_node *np;
int err;

static struct platform_driver fastrpc_cb_driver = {
.probe = fastrpc_cb_probe,
.remove = fastrpc_cb_remove,
.driver = {
.name = "qcom,fastrpc-cb",
.of_match_table = fastrpc_match_table,
.suppress_bind_attrs = true,
},
};
for_each_available_child_of_node(rdev->of_node, np) {
if (!of_device_is_compatible(np, "qcom,fastrpc-compute-cb")) {
of_node_put(np);
continue;
}

pdev = of_platform_device_create(np, NULL, rdev);
if (!pdev) {
of_node_put(np);
fastrpc_cb_devices_destroy(rpdev);
return -EINVAL;
}

err = fastrpc_cb_init(pdev);
if (err) {
of_node_put(np);
fastrpc_cb_devices_destroy(rpdev);
return err;
}
}

return 0;
}

static int fastrpc_device_register(struct device *dev, struct fastrpc_channel_ctx *cctx,
bool is_secured, const char *domain)
Expand Down Expand Up @@ -2731,10 +2747,26 @@ static int fastrpc_rpmsg_probe(struct rpmsg_device *rpdev)
data->rpdev = rpdev;
dev_set_drvdata(&rpdev->dev, data);

err = of_platform_populate(rdev->of_node, NULL, NULL, rdev);
err = fastrpc_cb_devices_create(rpdev);
if (err)
goto err_deregister_fdev;

if (data->domain_id == ADSP_DOMAIN_ID && data->sesscount > 0) {
struct fastrpc_session_ctx *last_sess;
struct fastrpc_session_ctx *dup_sess;
unsigned long flags;

spin_lock_irqsave(&data->lock, flags);
last_sess = &data->session[data->sesscount - 1];
for (i = 0; i < FASTRPC_DUP_SESSIONS; i++) {
if (data->sesscount >= FASTRPC_MAX_SESSIONS)
break;
dup_sess = &data->session[data->sesscount++];
memcpy(dup_sess, last_sess, sizeof(*dup_sess));
}
spin_unlock_irqrestore(&data->lock, flags);
}

return 0;

err_deregister_fdev:
Expand Down Expand Up @@ -2810,7 +2842,7 @@ static void fastrpc_rpmsg_remove(struct rpmsg_device *rpdev)
}
}

of_platform_depopulate(&rpdev->dev);
fastrpc_cb_devices_destroy(rpdev);

fastrpc_channel_ctx_put(cctx);
}
Expand Down Expand Up @@ -2871,33 +2903,7 @@ static struct rpmsg_driver fastrpc_driver = {
},
};

static int fastrpc_init(void)
{
int ret;

ret = platform_driver_register(&fastrpc_cb_driver);
if (ret < 0) {
pr_err("fastrpc: failed to register cb driver\n");
return ret;
}

ret = register_rpmsg_driver(&fastrpc_driver);
if (ret < 0) {
pr_err("fastrpc: failed to register rpmsg driver\n");
platform_driver_unregister(&fastrpc_cb_driver);
return ret;
}

return 0;
}
module_init(fastrpc_init);

static void fastrpc_exit(void)
{
platform_driver_unregister(&fastrpc_cb_driver);
unregister_rpmsg_driver(&fastrpc_driver);
}
module_exit(fastrpc_exit);
module_rpmsg_driver(fastrpc_driver);

MODULE_DESCRIPTION("Qualcomm FastRPC");
MODULE_LICENSE("GPL v2");
Expand Down