Bjorn Andersson | 026dad4 | 2016-09-01 15:27:59 -0700 | [diff] [blame^] | 1 | /* |
| 2 | * remote processor messaging bus |
| 3 | * |
| 4 | * Copyright (C) 2011 Texas Instruments, Inc. |
| 5 | * Copyright (C) 2011 Google, Inc. |
| 6 | * |
| 7 | * Ohad Ben-Cohen <ohad@wizery.com> |
| 8 | * Brian Swetland <swetland@google.com> |
| 9 | * |
| 10 | * This software is licensed under the terms of the GNU General Public |
| 11 | * License version 2, as published by the Free Software Foundation, and |
| 12 | * may be copied, distributed, and modified under those terms. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | */ |
| 19 | |
| 20 | #define pr_fmt(fmt) "%s: " fmt, __func__ |
| 21 | |
| 22 | #include <linux/kernel.h> |
| 23 | #include <linux/rpmsg.h> |
| 24 | |
| 25 | /** |
| 26 | * rpmsg_create_ept() - create a new rpmsg_endpoint |
| 27 | * @rpdev: rpmsg channel device |
| 28 | * @cb: rx callback handler |
| 29 | * @priv: private data for the driver's use |
| 30 | * @chinfo: channel_info with the local rpmsg address to bind with @cb |
| 31 | * |
| 32 | * Every rpmsg address in the system is bound to an rx callback (so when |
| 33 | * inbound messages arrive, they are dispatched by the rpmsg bus using the |
| 34 | * appropriate callback handler) by means of an rpmsg_endpoint struct. |
| 35 | * |
| 36 | * This function allows drivers to create such an endpoint, and by that, |
| 37 | * bind a callback, and possibly some private data too, to an rpmsg address |
| 38 | * (either one that is known in advance, or one that will be dynamically |
| 39 | * assigned for them). |
| 40 | * |
| 41 | * Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint |
| 42 | * is already created for them when they are probed by the rpmsg bus |
| 43 | * (using the rx callback provided when they registered to the rpmsg bus). |
| 44 | * |
| 45 | * So things should just work for simple drivers: they already have an |
| 46 | * endpoint, their rx callback is bound to their rpmsg address, and when |
| 47 | * relevant inbound messages arrive (i.e. messages which their dst address |
| 48 | * equals to the src address of their rpmsg channel), the driver's handler |
| 49 | * is invoked to process it. |
| 50 | * |
| 51 | * That said, more complicated drivers might do need to allocate |
| 52 | * additional rpmsg addresses, and bind them to different rx callbacks. |
| 53 | * To accomplish that, those drivers need to call this function. |
| 54 | * |
| 55 | * Drivers should provide their @rpdev channel (so the new endpoint would belong |
| 56 | * to the same remote processor their channel belongs to), an rx callback |
| 57 | * function, an optional private data (which is provided back when the |
| 58 | * rx callback is invoked), and an address they want to bind with the |
| 59 | * callback. If @addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will |
| 60 | * dynamically assign them an available rpmsg address (drivers should have |
| 61 | * a very good reason why not to always use RPMSG_ADDR_ANY here). |
| 62 | * |
| 63 | * Returns a pointer to the endpoint on success, or NULL on error. |
| 64 | */ |
| 65 | struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev, |
| 66 | rpmsg_rx_cb_t cb, void *priv, |
| 67 | struct rpmsg_channel_info chinfo) |
| 68 | { |
| 69 | return rpdev->ops->create_ept(rpdev, cb, priv, chinfo); |
| 70 | } |
| 71 | EXPORT_SYMBOL(rpmsg_create_ept); |