// SPDX-License-Identifier: GPL-2.0 /* * remote processor messaging bus * * Copyright (C) 2011 Texas Instruments, Inc. * Copyright (C) 2011 Google, Inc. * * Ohad Ben-Cohen <[email protected]> * Brian Swetland <[email protected]> */ #define pr_fmt(fmt) … #include <linux/kernel.h> #include <linux/module.h> #include <linux/rpmsg.h> #include <linux/of_device.h> #include <linux/pm_domain.h> #include <linux/slab.h> #include "rpmsg_internal.h" const struct class rpmsg_class = …; EXPORT_SYMBOL(…); /** * rpmsg_create_channel() - create a new rpmsg channel * using its name and address info. * @rpdev: rpmsg device * @chinfo: channel_info to bind * * Return: a pointer to the new rpmsg device on success, or NULL on error. */ struct rpmsg_device *rpmsg_create_channel(struct rpmsg_device *rpdev, struct rpmsg_channel_info *chinfo) { … } EXPORT_SYMBOL(…); /** * rpmsg_release_channel() - release a rpmsg channel * using its name and address info. * @rpdev: rpmsg device * @chinfo: channel_info to bind * * Return: 0 on success or an appropriate error value. */ int rpmsg_release_channel(struct rpmsg_device *rpdev, struct rpmsg_channel_info *chinfo) { … } EXPORT_SYMBOL(…); /** * rpmsg_create_ept() - create a new rpmsg_endpoint * @rpdev: rpmsg channel device * @cb: rx callback handler * @priv: private data for the driver's use * @chinfo: channel_info with the local rpmsg address to bind with @cb * * Every rpmsg address in the system is bound to an rx callback (so when * inbound messages arrive, they are dispatched by the rpmsg bus using the * appropriate callback handler) by means of an rpmsg_endpoint struct. * * This function allows drivers to create such an endpoint, and by that, * bind a callback, and possibly some private data too, to an rpmsg address * (either one that is known in advance, or one that will be dynamically * assigned for them). * * Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint * is already created for them when they are probed by the rpmsg bus * (using the rx callback provided when they registered to the rpmsg bus). * * So things should just work for simple drivers: they already have an * endpoint, their rx callback is bound to their rpmsg address, and when * relevant inbound messages arrive (i.e. messages which their dst address * equals to the src address of their rpmsg channel), the driver's handler * is invoked to process it. * * That said, more complicated drivers might need to allocate * additional rpmsg addresses, and bind them to different rx callbacks. * To accomplish that, those drivers need to call this function. * * Drivers should provide their @rpdev channel (so the new endpoint would belong * to the same remote processor their channel belongs to), an rx callback * function, an optional private data (which is provided back when the * rx callback is invoked), and an address they want to bind with the * callback. If @addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will * dynamically assign them an available rpmsg address (drivers should have * a very good reason why not to always use RPMSG_ADDR_ANY here). * * Return: a pointer to the endpoint on success, or NULL on error. */ struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, rpmsg_rx_cb_t cb, void *priv, struct rpmsg_channel_info chinfo) { … } EXPORT_SYMBOL(…); /** * rpmsg_destroy_ept() - destroy an existing rpmsg endpoint * @ept: endpoing to destroy * * Should be used by drivers to destroy an rpmsg endpoint previously * created with rpmsg_create_ept(). As with other types of "free" NULL * is a valid parameter. */ void rpmsg_destroy_ept(struct rpmsg_endpoint *ept) { … } EXPORT_SYMBOL(…); /** * rpmsg_send() - send a message across to the remote processor * @ept: the rpmsg endpoint * @data: payload of message * @len: length of payload * * This function sends @data of length @len on the @ept endpoint. * The message will be sent to the remote processor which the @ept * endpoint belongs to, using @ept's address and its associated rpmsg * device destination addresses. * In case there are no TX buffers available, the function will block until * one becomes available, or a timeout of 15 seconds elapses. When the latter * happens, -ERESTARTSYS is returned. * * Can only be called from process context (for now). * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) { … } EXPORT_SYMBOL(…); /** * rpmsg_sendto() - send a message across to the remote processor, specify dst * @ept: the rpmsg endpoint * @data: payload of message * @len: length of payload * @dst: destination address * * This function sends @data of length @len to the remote @dst address. * The message will be sent to the remote processor which the @ept * endpoint belongs to, using @ept's address as source. * In case there are no TX buffers available, the function will block until * one becomes available, or a timeout of 15 seconds elapses. When the latter * happens, -ERESTARTSYS is returned. * * Can only be called from process context (for now). * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { … } EXPORT_SYMBOL(…); /** * rpmsg_send_offchannel() - send a message using explicit src/dst addresses * @ept: the rpmsg endpoint * @src: source address * @dst: destination address * @data: payload of message * @len: length of payload * * This function sends @data of length @len to the remote @dst address, * and uses @src as the source address. * The message will be sent to the remote processor which the @ept * endpoint belongs to. * In case there are no TX buffers available, the function will block until * one becomes available, or a timeout of 15 seconds elapses. When the latter * happens, -ERESTARTSYS is returned. * * Can only be called from process context (for now). * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len) { … } EXPORT_SYMBOL(…); /** * rpmsg_trysend() - send a message across to the remote processor * @ept: the rpmsg endpoint * @data: payload of message * @len: length of payload * * This function sends @data of length @len on the @ept endpoint. * The message will be sent to the remote processor which the @ept * endpoint belongs to, using @ept's address as source and its associated * rpdev's address as destination. * In case there are no TX buffers available, the function will immediately * return -ENOMEM without waiting until one becomes available. * * Can only be called from process context (for now). * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) { … } EXPORT_SYMBOL(…); /** * rpmsg_trysendto() - send a message across to the remote processor, specify dst * @ept: the rpmsg endpoint * @data: payload of message * @len: length of payload * @dst: destination address * * This function sends @data of length @len to the remote @dst address. * The message will be sent to the remote processor which the @ept * endpoint belongs to, using @ept's address as source. * In case there are no TX buffers available, the function will immediately * return -ENOMEM without waiting until one becomes available. * * Can only be called from process context (for now). * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst) { … } EXPORT_SYMBOL(…); /** * rpmsg_poll() - poll the endpoint's send buffers * @ept: the rpmsg endpoint * @filp: file for poll_wait() * @wait: poll_table for poll_wait() * * Return: mask representing the current state of the endpoint's send buffers */ __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp, poll_table *wait) { … } EXPORT_SYMBOL(…); /** * rpmsg_trysend_offchannel() - send a message using explicit src/dst addresses * @ept: the rpmsg endpoint * @src: source address * @dst: destination address * @data: payload of message * @len: length of payload * * This function sends @data of length @len to the remote @dst address, * and uses @src as the source address. * The message will be sent to the remote processor which the @ept * endpoint belongs to. * In case there are no TX buffers available, the function will immediately * return -ENOMEM without waiting until one becomes available. * * Can only be called from process context (for now). * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, void *data, int len) { … } EXPORT_SYMBOL(…); /** * rpmsg_set_flow_control() - request remote to pause/resume transmission * @ept: the rpmsg endpoint * @pause: pause transmission * @dst: destination address of the endpoint * * Return: 0 on success and an appropriate error value on failure. */ int rpmsg_set_flow_control(struct rpmsg_endpoint *ept, bool pause, u32 dst) { … } EXPORT_SYMBOL_GPL(…); /** * rpmsg_get_mtu() - get maximum transmission buffer size for sending message. * @ept: the rpmsg endpoint * * This function returns maximum buffer size available for a single outgoing message. * * Return: the maximum transmission size on success and an appropriate error * value on failure. */ ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept) { … } EXPORT_SYMBOL(…); /* * match a rpmsg channel with a channel info struct. * this is used to make sure we're not creating rpmsg devices for channels * that already exist. */ static int rpmsg_device_match(struct device *dev, void *data) { … } struct device *rpmsg_find_device(struct device *parent, struct rpmsg_channel_info *chinfo) { … } EXPORT_SYMBOL(…); /* sysfs show configuration fields */ #define rpmsg_show_attr(field, path, format_string) … #define rpmsg_string_attr(field, member) … /* for more info, see Documentation/ABI/testing/sysfs-bus-rpmsg */ rpmsg_show_attr(name, id.name, "%s\n"); rpmsg_show_attr(src, src, "0x%x\n"); rpmsg_show_attr(dst, dst, "0x%x\n"); rpmsg_show_attr(announce, announce ? "true" : "false", "%s\n"); rpmsg_string_attr(…) …; static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, char *buf) { … } static DEVICE_ATTR_RO(modalias); static struct attribute *rpmsg_dev_attrs[] = …; ATTRIBUTE_GROUPS(…); /* rpmsg devices and drivers are matched using the service name */ static inline int rpmsg_id_match(const struct rpmsg_device *rpdev, const struct rpmsg_device_id *id) { … } /* match rpmsg channel and rpmsg driver */ static int rpmsg_dev_match(struct device *dev, const struct device_driver *drv) { … } static int rpmsg_uevent(const struct device *dev, struct kobj_uevent_env *env) { … } /* * when an rpmsg driver is probed with a channel, we seamlessly create * it an endpoint, binding its rx callback to a unique local rpmsg * address. * * if we need to, we also announce about this channel to the remote * processor (needed in case the driver is exposing an rpmsg service). */ static int rpmsg_dev_probe(struct device *dev) { … } static void rpmsg_dev_remove(struct device *dev) { … } static const struct bus_type rpmsg_bus = …; /* * A helper for registering rpmsg device with driver override and name. * Drivers should not be using it, but instead rpmsg_register_device(). */ int rpmsg_register_device_override(struct rpmsg_device *rpdev, const char *driver_override) { … } EXPORT_SYMBOL(…); int rpmsg_register_device(struct rpmsg_device *rpdev) { … } EXPORT_SYMBOL(…); /* * find an existing channel using its name + address properties, * and destroy it */ int rpmsg_unregister_device(struct device *parent, struct rpmsg_channel_info *chinfo) { … } EXPORT_SYMBOL(…); /** * __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus * @rpdrv: pointer to a struct rpmsg_driver * @owner: owning module/driver * * Return: 0 on success, and an appropriate error value on failure. */ int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner) { … } EXPORT_SYMBOL(…); /** * unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus * @rpdrv: pointer to a struct rpmsg_driver * * Return: 0 on success, and an appropriate error value on failure. */ void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv) { … } EXPORT_SYMBOL(…); static int __init rpmsg_init(void) { … } postcore_initcall(rpmsg_init); static void __exit rpmsg_fini(void) { … } module_exit(rpmsg_fini); MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;