Lines Matching +full:rpmsg +full:- +full:name

1 // SPDX-License-Identifier: GPL-2.0
10 #include <linux/rpmsg/mtk_rpmsg.h>
36 * struct rpmsg_ns_msg - dynamic name service announcement message
37 * @name: name of remote service that is published
41 * messages, an appropriate rpmsg channel (i.e device) is created. In turn, the
42 * ->probe() handler of the appropriate rpmsg driver will be invoked
43 * (if/as-soon-as one is registered).
46 char name[RPMSG_NAME_SIZE]; member
75 struct rpmsg_endpoint *ept = &mept->ept; in mtk_rpmsg_ipi_handler()
78 ret = (*ept->cb)(ept->rpdev, data, len, ept->priv, ept->addr); in mtk_rpmsg_ipi_handler()
80 dev_warn(&ept->rpdev->dev, "rpmsg handler return error = %d", in mtk_rpmsg_ipi_handler()
91 struct platform_device *pdev = mtk_subdev->pdev; in __mtk_create_ept()
97 mept->mtk_subdev = mtk_subdev; in __mtk_create_ept()
99 ept = &mept->ept; in __mtk_create_ept()
100 kref_init(&ept->refcount); in __mtk_create_ept()
102 ept->rpdev = rpdev; in __mtk_create_ept()
103 ept->cb = cb; in __mtk_create_ept()
104 ept->priv = priv; in __mtk_create_ept()
105 ept->ops = &mtk_rpmsg_endpoint_ops; in __mtk_create_ept()
106 ept->addr = id; in __mtk_create_ept()
108 ret = mtk_subdev->info->register_ipi(pdev, id, mtk_rpmsg_ipi_handler, in __mtk_create_ept()
111 dev_err(&pdev->dev, "IPI register failed, id = %d", id); in __mtk_create_ept()
112 kref_put(&ept->refcount, __mtk_ept_release); in __mtk_create_ept()
124 to_mtk_rpmsg_device(rpdev)->mtk_subdev; in mtk_rpmsg_create_ept()
132 to_mtk_rpmsg_endpoint(ept)->mtk_subdev; in mtk_rpmsg_destroy_ept()
134 mtk_subdev->info->unregister_ipi(mtk_subdev->pdev, ept->addr); in mtk_rpmsg_destroy_ept()
135 kref_put(&ept->refcount, __mtk_ept_release); in mtk_rpmsg_destroy_ept()
141 to_mtk_rpmsg_endpoint(ept)->mtk_subdev; in mtk_rpmsg_send()
143 return mtk_subdev->info->send_ipi(mtk_subdev->pdev, ept->addr, data, in mtk_rpmsg_send()
150 to_mtk_rpmsg_endpoint(ept)->mtk_subdev; in mtk_rpmsg_trysend()
156 return mtk_subdev->info->send_ipi(mtk_subdev->pdev, ept->addr, data, in mtk_rpmsg_trysend()
182 const char *name; in mtk_rpmsg_match_device_subnode() local
186 ret = of_property_read_string(child, "mediatek,rpmsg-name", &name); in mtk_rpmsg_match_device_subnode()
190 if (strcmp(name, channel) == 0) in mtk_rpmsg_match_device_subnode()
202 struct platform_device *pdev = mtk_subdev->pdev; in mtk_rpmsg_register_device()
206 return -ENOMEM; in mtk_rpmsg_register_device()
208 mdev->mtk_subdev = mtk_subdev; in mtk_rpmsg_register_device()
210 rpdev = &mdev->rpdev; in mtk_rpmsg_register_device()
211 rpdev->ops = &mtk_rpmsg_device_ops; in mtk_rpmsg_register_device()
212 rpdev->src = info->src; in mtk_rpmsg_register_device()
213 rpdev->dst = info->dst; in mtk_rpmsg_register_device()
214 strscpy(rpdev->id.name, info->name, RPMSG_NAME_SIZE); in mtk_rpmsg_register_device()
216 rpdev->dev.of_node = in mtk_rpmsg_register_device()
217 mtk_rpmsg_match_device_subnode(pdev->dev.of_node, info->name); in mtk_rpmsg_register_device()
218 rpdev->dev.parent = &pdev->dev; in mtk_rpmsg_register_device()
219 rpdev->dev.release = mtk_rpmsg_release_device; in mtk_rpmsg_register_device()
228 struct platform_device *pdev = subdev->pdev; in mtk_register_device_work_function()
232 mutex_lock(&subdev->channels_lock); in mtk_register_device_work_function()
233 list_for_each_entry(info, &subdev->channels, list) { in mtk_register_device_work_function()
234 if (info->registered) in mtk_register_device_work_function()
237 mutex_unlock(&subdev->channels_lock); in mtk_register_device_work_function()
238 ret = mtk_rpmsg_register_device(subdev, &info->info); in mtk_register_device_work_function()
239 mutex_lock(&subdev->channels_lock); in mtk_register_device_work_function()
241 dev_err(&pdev->dev, "Can't create rpmsg_device\n"); in mtk_register_device_work_function()
245 info->registered = true; in mtk_register_device_work_function()
247 mutex_unlock(&subdev->channels_lock); in mtk_register_device_work_function()
251 char *name, u32 addr) in mtk_rpmsg_create_device() argument
257 return -ENOMEM; in mtk_rpmsg_create_device()
259 strscpy(info->info.name, name, RPMSG_NAME_SIZE); in mtk_rpmsg_create_device()
260 info->info.src = addr; in mtk_rpmsg_create_device()
261 info->info.dst = RPMSG_ADDR_ANY; in mtk_rpmsg_create_device()
262 mutex_lock(&mtk_subdev->channels_lock); in mtk_rpmsg_create_device()
263 list_add(&info->list, &mtk_subdev->channels); in mtk_rpmsg_create_device()
264 mutex_unlock(&mtk_subdev->channels_lock); in mtk_rpmsg_create_device()
266 schedule_work(&mtk_subdev->register_work); in mtk_rpmsg_create_device()
275 struct device *dev = &mtk_subdev->pdev->dev; in mtk_rpmsg_ns_cb()
281 return -EINVAL; in mtk_rpmsg_ns_cb()
285 * the name service ept does _not_ belong to a real rpmsg channel, in mtk_rpmsg_ns_cb()
286 * and is handled by the rpmsg bus itself. in mtk_rpmsg_ns_cb()
292 return -EINVAL; in mtk_rpmsg_ns_cb()
295 /* don't trust the remote processor for null terminating the name */ in mtk_rpmsg_ns_cb()
296 msg->name[RPMSG_NAME_SIZE - 1] = '\0'; in mtk_rpmsg_ns_cb()
298 dev_info(dev, "creating channel %s addr 0x%x\n", msg->name, msg->addr); in mtk_rpmsg_ns_cb()
300 ret = mtk_rpmsg_create_device(mtk_subdev, msg->name, msg->addr); in mtk_rpmsg_ns_cb()
302 dev_err(dev, "create rpmsg device failed\n"); in mtk_rpmsg_ns_cb()
313 /* a dedicated endpoint handles the name service msgs */ in mtk_rpmsg_prepare()
314 if (mtk_subdev->info->ns_ipi_id >= 0) { in mtk_rpmsg_prepare()
315 mtk_subdev->ns_ept = in mtk_rpmsg_prepare()
318 mtk_subdev->info->ns_ipi_id); in mtk_rpmsg_prepare()
319 if (!mtk_subdev->ns_ept) { in mtk_rpmsg_prepare()
320 dev_err(&mtk_subdev->pdev->dev, in mtk_rpmsg_prepare()
321 "failed to create name service endpoint\n"); in mtk_rpmsg_prepare()
322 return -ENOMEM; in mtk_rpmsg_prepare()
333 if (mtk_subdev->ns_ept) { in mtk_rpmsg_unprepare()
334 mtk_rpmsg_destroy_ept(mtk_subdev->ns_ept); in mtk_rpmsg_unprepare()
335 mtk_subdev->ns_ept = NULL; in mtk_rpmsg_unprepare()
343 struct device *dev = &mtk_subdev->pdev->dev; in mtk_rpmsg_stop()
346 * Destroy the name service endpoint here, to avoid new channel being in mtk_rpmsg_stop()
349 if (mtk_subdev->ns_ept) { in mtk_rpmsg_stop()
350 mtk_rpmsg_destroy_ept(mtk_subdev->ns_ept); in mtk_rpmsg_stop()
351 mtk_subdev->ns_ept = NULL; in mtk_rpmsg_stop()
354 cancel_work_sync(&mtk_subdev->register_work); in mtk_rpmsg_stop()
356 mutex_lock(&mtk_subdev->channels_lock); in mtk_rpmsg_stop()
357 list_for_each_entry(info, &mtk_subdev->channels, list) { in mtk_rpmsg_stop()
358 if (!info->registered) in mtk_rpmsg_stop()
360 if (rpmsg_unregister_device(dev, &info->info)) { in mtk_rpmsg_stop()
364 info->info.name, info->info.src, in mtk_rpmsg_stop()
365 info->info.dst); in mtk_rpmsg_stop()
370 &mtk_subdev->channels, list) { in mtk_rpmsg_stop()
371 list_del(&info->list); in mtk_rpmsg_stop()
374 mutex_unlock(&mtk_subdev->channels_lock); in mtk_rpmsg_stop()
387 mtk_subdev->pdev = pdev; in mtk_rpmsg_create_rproc_subdev()
388 mtk_subdev->subdev.prepare = mtk_rpmsg_prepare; in mtk_rpmsg_create_rproc_subdev()
389 mtk_subdev->subdev.stop = mtk_rpmsg_stop; in mtk_rpmsg_create_rproc_subdev()
390 mtk_subdev->subdev.unprepare = mtk_rpmsg_unprepare; in mtk_rpmsg_create_rproc_subdev()
391 mtk_subdev->info = info; in mtk_rpmsg_create_rproc_subdev()
392 INIT_LIST_HEAD(&mtk_subdev->channels); in mtk_rpmsg_create_rproc_subdev()
393 INIT_WORK(&mtk_subdev->register_work, in mtk_rpmsg_create_rproc_subdev()
395 mutex_init(&mtk_subdev->channels_lock); in mtk_rpmsg_create_rproc_subdev()
397 return &mtk_subdev->subdev; in mtk_rpmsg_create_rproc_subdev()
410 MODULE_DESCRIPTION("MediaTek scp rpmsg driver");