Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Virtio-based 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/module.h> |
| 24 | #include <linux/virtio.h> |
| 25 | #include <linux/virtio_ids.h> |
| 26 | #include <linux/virtio_config.h> |
| 27 | #include <linux/scatterlist.h> |
| 28 | #include <linux/dma-mapping.h> |
| 29 | #include <linux/slab.h> |
| 30 | #include <linux/idr.h> |
| 31 | #include <linux/jiffies.h> |
| 32 | #include <linux/sched.h> |
| 33 | #include <linux/wait.h> |
| 34 | #include <linux/rpmsg.h> |
| 35 | #include <linux/mutex.h> |
Bjorn Andersson | a16644c | 2016-09-01 15:27:53 -0700 | [diff] [blame] | 36 | #include <linux/of_device.h> |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 37 | |
Bjorn Andersson | 8b881c0 | 2016-09-01 15:28:02 -0700 | [diff] [blame] | 38 | #include "rpmsg_internal.h" |
| 39 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 40 | /** |
| 41 | * struct virtproc_info - virtual remote processor state |
| 42 | * @vdev: the virtio device |
| 43 | * @rvq: rx virtqueue |
| 44 | * @svq: tx virtqueue |
| 45 | * @rbufs: kernel address of rx buffers |
| 46 | * @sbufs: kernel address of tx buffers |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 47 | * @num_bufs: total number of buffers for rx and tx |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 48 | * @last_sbuf: index of last tx buffer used |
| 49 | * @bufs_dma: dma base addr of the buffers |
| 50 | * @tx_lock: protects svq, sbufs and sleepers, to allow concurrent senders. |
| 51 | * sending a message might require waking up a dozing remote |
| 52 | * processor, which involves sleeping, hence the mutex. |
| 53 | * @endpoints: idr of local endpoints, allows fast retrieval |
| 54 | * @endpoints_lock: lock of the endpoints set |
| 55 | * @sendq: wait queue of sending contexts waiting for a tx buffers |
| 56 | * @sleepers: number of senders that are waiting for a tx buffer |
| 57 | * @ns_ept: the bus's name service endpoint |
| 58 | * |
| 59 | * This structure stores the rpmsg state of a given virtio remote processor |
| 60 | * device (there might be several virtio proc devices for each physical |
| 61 | * remote processor). |
| 62 | */ |
| 63 | struct virtproc_info { |
| 64 | struct virtio_device *vdev; |
| 65 | struct virtqueue *rvq, *svq; |
| 66 | void *rbufs, *sbufs; |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 67 | unsigned int num_bufs; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 68 | int last_sbuf; |
| 69 | dma_addr_t bufs_dma; |
| 70 | struct mutex tx_lock; |
| 71 | struct idr endpoints; |
| 72 | struct mutex endpoints_lock; |
| 73 | wait_queue_head_t sendq; |
| 74 | atomic_t sleepers; |
| 75 | struct rpmsg_endpoint *ns_ept; |
| 76 | }; |
| 77 | |
Bjorn Andersson | e88dae5 | 2016-09-01 15:28:07 -0700 | [diff] [blame] | 78 | /* The feature bitmap for virtio rpmsg */ |
| 79 | #define VIRTIO_RPMSG_F_NS 0 /* RP supports name service notifications */ |
| 80 | |
| 81 | /** |
| 82 | * struct rpmsg_hdr - common header for all rpmsg messages |
| 83 | * @src: source address |
| 84 | * @dst: destination address |
| 85 | * @reserved: reserved for future use |
| 86 | * @len: length of payload (in bytes) |
| 87 | * @flags: message flags |
| 88 | * @data: @len bytes of message payload data |
| 89 | * |
| 90 | * Every message sent(/received) on the rpmsg bus begins with this header. |
| 91 | */ |
| 92 | struct rpmsg_hdr { |
| 93 | u32 src; |
| 94 | u32 dst; |
| 95 | u32 reserved; |
| 96 | u16 len; |
| 97 | u16 flags; |
| 98 | u8 data[0]; |
| 99 | } __packed; |
| 100 | |
| 101 | /** |
| 102 | * struct rpmsg_ns_msg - dynamic name service announcement message |
| 103 | * @name: name of remote service that is published |
| 104 | * @addr: address of remote service that is published |
| 105 | * @flags: indicates whether service is created or destroyed |
| 106 | * |
| 107 | * This message is sent across to publish a new service, or announce |
| 108 | * about its removal. When we receive these messages, an appropriate |
| 109 | * rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe() |
| 110 | * or ->remove() handler of the appropriate rpmsg driver will be invoked |
| 111 | * (if/as-soon-as one is registered). |
| 112 | */ |
| 113 | struct rpmsg_ns_msg { |
| 114 | char name[RPMSG_NAME_SIZE]; |
| 115 | u32 addr; |
| 116 | u32 flags; |
| 117 | } __packed; |
| 118 | |
| 119 | /** |
| 120 | * enum rpmsg_ns_flags - dynamic name service announcement flags |
| 121 | * |
| 122 | * @RPMSG_NS_CREATE: a new remote service was just created |
| 123 | * @RPMSG_NS_DESTROY: a known remote service was just destroyed |
| 124 | */ |
| 125 | enum rpmsg_ns_flags { |
| 126 | RPMSG_NS_CREATE = 0, |
| 127 | RPMSG_NS_DESTROY = 1, |
| 128 | }; |
| 129 | |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 130 | /** |
| 131 | * @vrp: the remote processor this channel belongs to |
| 132 | */ |
| 133 | struct virtio_rpmsg_channel { |
| 134 | struct rpmsg_device rpdev; |
| 135 | |
| 136 | struct virtproc_info *vrp; |
| 137 | }; |
| 138 | |
| 139 | #define to_virtio_rpmsg_channel(_rpdev) \ |
| 140 | container_of(_rpdev, struct virtio_rpmsg_channel, rpdev) |
| 141 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 142 | /* |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 143 | * We're allocating buffers of 512 bytes each for communications. The |
| 144 | * number of buffers will be computed from the number of buffers supported |
| 145 | * by the vring, upto a maximum of 512 buffers (256 in each direction). |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 146 | * |
| 147 | * Each buffer will have 16 bytes for the msg header and 496 bytes for |
| 148 | * the payload. |
| 149 | * |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 150 | * This will utilize a maximum total space of 256KB for the buffers. |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 151 | * |
| 152 | * We might also want to add support for user-provided buffers in time. |
| 153 | * This will allow bigger buffer size flexibility, and can also be used |
| 154 | * to achieve zero-copy messaging. |
| 155 | * |
| 156 | * Note that these numbers are purely a decision of this driver - we |
| 157 | * can change this without changing anything in the firmware of the remote |
| 158 | * processor. |
| 159 | */ |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 160 | #define MAX_RPMSG_NUM_BUFS (512) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 161 | #define RPMSG_BUF_SIZE (512) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 162 | |
| 163 | /* |
| 164 | * Local addresses are dynamically allocated on-demand. |
| 165 | * We do not dynamically assign addresses from the low 1024 range, |
| 166 | * in order to reserve that address range for predefined services. |
| 167 | */ |
| 168 | #define RPMSG_RESERVED_ADDRESSES (1024) |
| 169 | |
| 170 | /* Address 53 is reserved for advertising remote services */ |
| 171 | #define RPMSG_NS_ADDR (53) |
| 172 | |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 173 | static void virtio_rpmsg_destroy_ept(struct rpmsg_endpoint *ept); |
| 174 | static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len); |
| 175 | static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, |
| 176 | u32 dst); |
| 177 | static int virtio_rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, |
| 178 | u32 dst, void *data, int len); |
| 179 | static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len); |
| 180 | static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, |
| 181 | int len, u32 dst); |
| 182 | static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, |
| 183 | u32 dst, void *data, int len); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 184 | |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 185 | static const struct rpmsg_endpoint_ops virtio_endpoint_ops = { |
| 186 | .destroy_ept = virtio_rpmsg_destroy_ept, |
| 187 | .send = virtio_rpmsg_send, |
| 188 | .sendto = virtio_rpmsg_sendto, |
| 189 | .send_offchannel = virtio_rpmsg_send_offchannel, |
| 190 | .trysend = virtio_rpmsg_trysend, |
| 191 | .trysendto = virtio_rpmsg_trysendto, |
| 192 | .trysend_offchannel = virtio_rpmsg_trysend_offchannel, |
| 193 | }; |
| 194 | |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 195 | /** |
| 196 | * __ept_release() - deallocate an rpmsg endpoint |
| 197 | * @kref: the ept's reference count |
| 198 | * |
| 199 | * This function deallocates an ept, and is invoked when its @kref refcount |
| 200 | * drops to zero. |
| 201 | * |
| 202 | * Never invoke this function directly! |
| 203 | */ |
| 204 | static void __ept_release(struct kref *kref) |
| 205 | { |
| 206 | struct rpmsg_endpoint *ept = container_of(kref, struct rpmsg_endpoint, |
| 207 | refcount); |
| 208 | /* |
| 209 | * At this point no one holds a reference to ept anymore, |
| 210 | * so we can directly free it |
| 211 | */ |
| 212 | kfree(ept); |
| 213 | } |
| 214 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 215 | /* for more info, see below documentation of rpmsg_create_ept() */ |
| 216 | static struct rpmsg_endpoint *__rpmsg_create_ept(struct virtproc_info *vrp, |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 217 | struct rpmsg_device *rpdev, |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 218 | rpmsg_rx_cb_t cb, |
| 219 | void *priv, u32 addr) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 220 | { |
Tejun Heo | d0ffce7 | 2013-02-27 17:04:40 -0800 | [diff] [blame] | 221 | int id_min, id_max, id; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 222 | struct rpmsg_endpoint *ept; |
| 223 | struct device *dev = rpdev ? &rpdev->dev : &vrp->vdev->dev; |
| 224 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 225 | ept = kzalloc(sizeof(*ept), GFP_KERNEL); |
Anna, Suman | a8bb3fd | 2016-08-12 18:42:24 -0500 | [diff] [blame] | 226 | if (!ept) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 227 | return NULL; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 228 | |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 229 | kref_init(&ept->refcount); |
Ohad Ben-Cohen | 15fd943 | 2012-06-07 15:39:35 +0300 | [diff] [blame] | 230 | mutex_init(&ept->cb_lock); |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 231 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 232 | ept->rpdev = rpdev; |
| 233 | ept->cb = cb; |
| 234 | ept->priv = priv; |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 235 | ept->ops = &virtio_endpoint_ops; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 236 | |
| 237 | /* do we need to allocate a local address ? */ |
Tejun Heo | d0ffce7 | 2013-02-27 17:04:40 -0800 | [diff] [blame] | 238 | if (addr == RPMSG_ADDR_ANY) { |
| 239 | id_min = RPMSG_RESERVED_ADDRESSES; |
| 240 | id_max = 0; |
| 241 | } else { |
| 242 | id_min = addr; |
| 243 | id_max = addr + 1; |
| 244 | } |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 245 | |
| 246 | mutex_lock(&vrp->endpoints_lock); |
| 247 | |
| 248 | /* bind the endpoint to an rpmsg address (and allocate one if needed) */ |
Tejun Heo | d0ffce7 | 2013-02-27 17:04:40 -0800 | [diff] [blame] | 249 | id = idr_alloc(&vrp->endpoints, ept, id_min, id_max, GFP_KERNEL); |
| 250 | if (id < 0) { |
| 251 | dev_err(dev, "idr_alloc failed: %d\n", id); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 252 | goto free_ept; |
| 253 | } |
Tejun Heo | d0ffce7 | 2013-02-27 17:04:40 -0800 | [diff] [blame] | 254 | ept->addr = id; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 255 | |
| 256 | mutex_unlock(&vrp->endpoints_lock); |
| 257 | |
| 258 | return ept; |
| 259 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 260 | free_ept: |
| 261 | mutex_unlock(&vrp->endpoints_lock); |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 262 | kref_put(&ept->refcount, __ept_release); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 263 | return NULL; |
| 264 | } |
| 265 | |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 266 | static struct rpmsg_endpoint *virtio_rpmsg_create_ept(struct rpmsg_device *rpdev, |
| 267 | rpmsg_rx_cb_t cb, |
| 268 | void *priv, |
| 269 | struct rpmsg_channel_info chinfo) |
| 270 | { |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 271 | struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); |
| 272 | |
| 273 | return __rpmsg_create_ept(vch->vrp, rpdev, cb, priv, chinfo.src); |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 274 | } |
| 275 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 276 | /** |
Ohad Ben-Cohen | fa2d779 | 2012-02-09 15:16:41 +0200 | [diff] [blame] | 277 | * __rpmsg_destroy_ept() - destroy an existing rpmsg endpoint |
| 278 | * @vrp: virtproc which owns this ept |
| 279 | * @ept: endpoing to destroy |
| 280 | * |
| 281 | * An internal function which destroy an ept without assuming it is |
| 282 | * bound to an rpmsg channel. This is needed for handling the internal |
| 283 | * name service endpoint, which isn't bound to an rpmsg channel. |
| 284 | * See also __rpmsg_create_ept(). |
| 285 | */ |
| 286 | static void |
| 287 | __rpmsg_destroy_ept(struct virtproc_info *vrp, struct rpmsg_endpoint *ept) |
| 288 | { |
Ohad Ben-Cohen | 15fd943 | 2012-06-07 15:39:35 +0300 | [diff] [blame] | 289 | /* make sure new inbound messages can't find this ept anymore */ |
Ohad Ben-Cohen | fa2d779 | 2012-02-09 15:16:41 +0200 | [diff] [blame] | 290 | mutex_lock(&vrp->endpoints_lock); |
| 291 | idr_remove(&vrp->endpoints, ept->addr); |
| 292 | mutex_unlock(&vrp->endpoints_lock); |
| 293 | |
Ohad Ben-Cohen | 15fd943 | 2012-06-07 15:39:35 +0300 | [diff] [blame] | 294 | /* make sure in-flight inbound messages won't invoke cb anymore */ |
| 295 | mutex_lock(&ept->cb_lock); |
| 296 | ept->cb = NULL; |
| 297 | mutex_unlock(&ept->cb_lock); |
| 298 | |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 299 | kref_put(&ept->refcount, __ept_release); |
Ohad Ben-Cohen | fa2d779 | 2012-02-09 15:16:41 +0200 | [diff] [blame] | 300 | } |
| 301 | |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 302 | static void virtio_rpmsg_destroy_ept(struct rpmsg_endpoint *ept) |
| 303 | { |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 304 | struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(ept->rpdev); |
| 305 | |
| 306 | __rpmsg_destroy_ept(vch->vrp, ept); |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 307 | } |
| 308 | |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 309 | static int virtio_rpmsg_announce_create(struct rpmsg_device *rpdev) |
| 310 | { |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 311 | struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); |
| 312 | struct virtproc_info *vrp = vch->vrp; |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 313 | struct device *dev = &rpdev->dev; |
| 314 | int err = 0; |
| 315 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 316 | /* need to tell remote processor's name service about this channel ? */ |
Henri Roosen | b2599eb | 2017-06-02 13:35:51 +0200 | [diff] [blame] | 317 | if (rpdev->announce && rpdev->ept && |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 318 | virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) { |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 319 | struct rpmsg_ns_msg nsm; |
| 320 | |
| 321 | strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 322 | nsm.addr = rpdev->ept->addr; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 323 | nsm.flags = RPMSG_NS_CREATE; |
| 324 | |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 325 | err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 326 | if (err) |
| 327 | dev_err(dev, "failed to announce service %d\n", err); |
| 328 | } |
| 329 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 330 | return err; |
| 331 | } |
| 332 | |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 333 | static int virtio_rpmsg_announce_destroy(struct rpmsg_device *rpdev) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 334 | { |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 335 | struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); |
| 336 | struct virtproc_info *vrp = vch->vrp; |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 337 | struct device *dev = &rpdev->dev; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 338 | int err = 0; |
| 339 | |
| 340 | /* tell remote processor's name service we're removing this channel */ |
Henri Roosen | b2599eb | 2017-06-02 13:35:51 +0200 | [diff] [blame] | 341 | if (rpdev->announce && rpdev->ept && |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 342 | virtio_has_feature(vrp->vdev, VIRTIO_RPMSG_F_NS)) { |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 343 | struct rpmsg_ns_msg nsm; |
| 344 | |
| 345 | strncpy(nsm.name, rpdev->id.name, RPMSG_NAME_SIZE); |
Henri Roosen | 8578672 | 2017-06-02 13:36:42 +0200 | [diff] [blame^] | 346 | nsm.addr = rpdev->ept->addr; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 347 | nsm.flags = RPMSG_NS_DESTROY; |
| 348 | |
Bjorn Andersson | 2a48d73 | 2016-09-01 15:27:55 -0700 | [diff] [blame] | 349 | err = rpmsg_sendto(rpdev->ept, &nsm, sizeof(nsm), RPMSG_NS_ADDR); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 350 | if (err) |
| 351 | dev_err(dev, "failed to announce service %d\n", err); |
| 352 | } |
| 353 | |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 354 | return err; |
| 355 | } |
| 356 | |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 357 | static const struct rpmsg_device_ops virtio_rpmsg_ops = { |
| 358 | .create_ept = virtio_rpmsg_create_ept, |
| 359 | .announce_create = virtio_rpmsg_announce_create, |
| 360 | .announce_destroy = virtio_rpmsg_announce_destroy, |
| 361 | }; |
| 362 | |
Bjorn Andersson | b0b03b8 | 2017-03-15 22:18:35 -0700 | [diff] [blame] | 363 | static void virtio_rpmsg_release_device(struct device *dev) |
| 364 | { |
| 365 | struct rpmsg_device *rpdev = to_rpmsg_device(dev); |
| 366 | struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); |
| 367 | |
| 368 | kfree(vch); |
| 369 | } |
| 370 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 371 | /* |
| 372 | * create an rpmsg channel using its name and address info. |
| 373 | * this function will be used to create both static and dynamic |
| 374 | * channels. |
| 375 | */ |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 376 | static struct rpmsg_device *rpmsg_create_channel(struct virtproc_info *vrp, |
| 377 | struct rpmsg_channel_info *chinfo) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 378 | { |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 379 | struct virtio_rpmsg_channel *vch; |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 380 | struct rpmsg_device *rpdev; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 381 | struct device *tmp, *dev = &vrp->vdev->dev; |
| 382 | int ret; |
| 383 | |
| 384 | /* make sure a similar channel doesn't already exist */ |
Bjorn Andersson | 8b881c0 | 2016-09-01 15:28:02 -0700 | [diff] [blame] | 385 | tmp = rpmsg_find_device(dev, chinfo); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 386 | if (tmp) { |
| 387 | /* decrement the matched device's refcount back */ |
| 388 | put_device(tmp); |
| 389 | dev_err(dev, "channel %s:%x:%x already exist\n", |
| 390 | chinfo->name, chinfo->src, chinfo->dst); |
| 391 | return NULL; |
| 392 | } |
| 393 | |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 394 | vch = kzalloc(sizeof(*vch), GFP_KERNEL); |
| 395 | if (!vch) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 396 | return NULL; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 397 | |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 398 | /* Link the channel to our vrp */ |
| 399 | vch->vrp = vrp; |
| 400 | |
| 401 | /* Assign callbacks for rpmsg_channel */ |
| 402 | vch->rpdev.ops = &virtio_rpmsg_ops; |
| 403 | |
| 404 | /* Assign public information to the rpmsg_device */ |
| 405 | rpdev = &vch->rpdev; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 406 | rpdev->src = chinfo->src; |
| 407 | rpdev->dst = chinfo->dst; |
Bjorn Andersson | 36b72c7 | 2016-09-01 15:27:58 -0700 | [diff] [blame] | 408 | rpdev->ops = &virtio_rpmsg_ops; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 409 | |
| 410 | /* |
| 411 | * rpmsg server channels has predefined local address (for now), |
| 412 | * and their existence needs to be announced remotely |
| 413 | */ |
Andrew F. Davis | c8ced11 | 2016-07-01 09:24:58 -0500 | [diff] [blame] | 414 | rpdev->announce = rpdev->src != RPMSG_ADDR_ANY; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 415 | |
| 416 | strncpy(rpdev->id.name, chinfo->name, RPMSG_NAME_SIZE); |
| 417 | |
Bjorn Andersson | 6eed598 | 2016-09-01 15:28:03 -0700 | [diff] [blame] | 418 | rpdev->dev.parent = &vrp->vdev->dev; |
Bjorn Andersson | b0b03b8 | 2017-03-15 22:18:35 -0700 | [diff] [blame] | 419 | rpdev->dev.release = virtio_rpmsg_release_device; |
Bjorn Andersson | 6eed598 | 2016-09-01 15:28:03 -0700 | [diff] [blame] | 420 | ret = rpmsg_register_device(rpdev); |
| 421 | if (ret) |
| 422 | return NULL; |
| 423 | |
| 424 | return rpdev; |
| 425 | } |
| 426 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 427 | /* super simple buffer "allocator" that is just enough for now */ |
| 428 | static void *get_a_tx_buf(struct virtproc_info *vrp) |
| 429 | { |
| 430 | unsigned int len; |
| 431 | void *ret; |
| 432 | |
| 433 | /* support multiple concurrent senders */ |
| 434 | mutex_lock(&vrp->tx_lock); |
| 435 | |
| 436 | /* |
| 437 | * either pick the next unused tx buffer |
| 438 | * (half of our buffers are used for sending messages) |
| 439 | */ |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 440 | if (vrp->last_sbuf < vrp->num_bufs / 2) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 441 | ret = vrp->sbufs + RPMSG_BUF_SIZE * vrp->last_sbuf++; |
| 442 | /* or recycle a used one */ |
| 443 | else |
| 444 | ret = virtqueue_get_buf(vrp->svq, &len); |
| 445 | |
| 446 | mutex_unlock(&vrp->tx_lock); |
| 447 | |
| 448 | return ret; |
| 449 | } |
| 450 | |
| 451 | /** |
| 452 | * rpmsg_upref_sleepers() - enable "tx-complete" interrupts, if needed |
| 453 | * @vrp: virtual remote processor state |
| 454 | * |
| 455 | * This function is called before a sender is blocked, waiting for |
| 456 | * a tx buffer to become available. |
| 457 | * |
| 458 | * If we already have blocking senders, this function merely increases |
| 459 | * the "sleepers" reference count, and exits. |
| 460 | * |
| 461 | * Otherwise, if this is the first sender to block, we also enable |
| 462 | * virtio's tx callbacks, so we'd be immediately notified when a tx |
| 463 | * buffer is consumed (we rely on virtio's tx callback in order |
| 464 | * to wake up sleeping senders as soon as a tx buffer is used by the |
| 465 | * remote processor). |
| 466 | */ |
| 467 | static void rpmsg_upref_sleepers(struct virtproc_info *vrp) |
| 468 | { |
| 469 | /* support multiple concurrent senders */ |
| 470 | mutex_lock(&vrp->tx_lock); |
| 471 | |
| 472 | /* are we the first sleeping context waiting for tx buffers ? */ |
| 473 | if (atomic_inc_return(&vrp->sleepers) == 1) |
| 474 | /* enable "tx-complete" interrupts before dozing off */ |
| 475 | virtqueue_enable_cb(vrp->svq); |
| 476 | |
| 477 | mutex_unlock(&vrp->tx_lock); |
| 478 | } |
| 479 | |
| 480 | /** |
| 481 | * rpmsg_downref_sleepers() - disable "tx-complete" interrupts, if needed |
| 482 | * @vrp: virtual remote processor state |
| 483 | * |
| 484 | * This function is called after a sender, that waited for a tx buffer |
| 485 | * to become available, is unblocked. |
| 486 | * |
| 487 | * If we still have blocking senders, this function merely decreases |
| 488 | * the "sleepers" reference count, and exits. |
| 489 | * |
| 490 | * Otherwise, if there are no more blocking senders, we also disable |
| 491 | * virtio's tx callbacks, to avoid the overhead incurred with handling |
| 492 | * those (now redundant) interrupts. |
| 493 | */ |
| 494 | static void rpmsg_downref_sleepers(struct virtproc_info *vrp) |
| 495 | { |
| 496 | /* support multiple concurrent senders */ |
| 497 | mutex_lock(&vrp->tx_lock); |
| 498 | |
| 499 | /* are we the last sleeping context waiting for tx buffers ? */ |
| 500 | if (atomic_dec_and_test(&vrp->sleepers)) |
| 501 | /* disable "tx-complete" interrupts */ |
| 502 | virtqueue_disable_cb(vrp->svq); |
| 503 | |
| 504 | mutex_unlock(&vrp->tx_lock); |
| 505 | } |
| 506 | |
| 507 | /** |
| 508 | * rpmsg_send_offchannel_raw() - send a message across to the remote processor |
| 509 | * @rpdev: the rpmsg channel |
| 510 | * @src: source address |
| 511 | * @dst: destination address |
| 512 | * @data: payload of message |
| 513 | * @len: length of payload |
| 514 | * @wait: indicates whether caller should block in case no TX buffers available |
| 515 | * |
| 516 | * This function is the base implementation for all of the rpmsg sending API. |
| 517 | * |
| 518 | * It will send @data of length @len to @dst, and say it's from @src. The |
| 519 | * message will be sent to the remote processor which the @rpdev channel |
| 520 | * belongs to. |
| 521 | * |
| 522 | * The message is sent using one of the TX buffers that are available for |
| 523 | * communication with this remote processor. |
| 524 | * |
| 525 | * If @wait is true, the caller will be blocked until either a TX buffer is |
| 526 | * available, or 15 seconds elapses (we don't want callers to |
| 527 | * sleep indefinitely due to misbehaving remote processors), and in that |
| 528 | * case -ERESTARTSYS is returned. The number '15' itself was picked |
| 529 | * arbitrarily; there's little point in asking drivers to provide a timeout |
| 530 | * value themselves. |
| 531 | * |
| 532 | * Otherwise, if @wait is false, and there are no TX buffers available, |
| 533 | * the function will immediately fail, and -ENOMEM will be returned. |
| 534 | * |
| 535 | * Normally drivers shouldn't use this function directly; instead, drivers |
| 536 | * should use the appropriate rpmsg_{try}send{to, _offchannel} API |
| 537 | * (see include/linux/rpmsg.h). |
| 538 | * |
| 539 | * Returns 0 on success and an appropriate error value on failure. |
| 540 | */ |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 541 | static int rpmsg_send_offchannel_raw(struct rpmsg_device *rpdev, |
| 542 | u32 src, u32 dst, |
| 543 | void *data, int len, bool wait) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 544 | { |
Bjorn Andersson | 3bf950f | 2016-09-01 15:28:06 -0700 | [diff] [blame] | 545 | struct virtio_rpmsg_channel *vch = to_virtio_rpmsg_channel(rpdev); |
| 546 | struct virtproc_info *vrp = vch->vrp; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 547 | struct device *dev = &rpdev->dev; |
| 548 | struct scatterlist sg; |
| 549 | struct rpmsg_hdr *msg; |
| 550 | int err; |
| 551 | |
| 552 | /* bcasting isn't allowed */ |
| 553 | if (src == RPMSG_ADDR_ANY || dst == RPMSG_ADDR_ANY) { |
| 554 | dev_err(dev, "invalid addr (src 0x%x, dst 0x%x)\n", src, dst); |
| 555 | return -EINVAL; |
| 556 | } |
| 557 | |
| 558 | /* |
| 559 | * We currently use fixed-sized buffers, and therefore the payload |
| 560 | * length is limited. |
| 561 | * |
| 562 | * One of the possible improvements here is either to support |
| 563 | * user-provided buffers (and then we can also support zero-copy |
| 564 | * messaging), or to improve the buffer allocator, to support |
| 565 | * variable-length buffer sizes. |
| 566 | */ |
| 567 | if (len > RPMSG_BUF_SIZE - sizeof(struct rpmsg_hdr)) { |
| 568 | dev_err(dev, "message is too big (%d)\n", len); |
| 569 | return -EMSGSIZE; |
| 570 | } |
| 571 | |
| 572 | /* grab a buffer */ |
| 573 | msg = get_a_tx_buf(vrp); |
| 574 | if (!msg && !wait) |
| 575 | return -ENOMEM; |
| 576 | |
| 577 | /* no free buffer ? wait for one (but bail after 15 seconds) */ |
| 578 | while (!msg) { |
| 579 | /* enable "tx-complete" interrupts, if not already enabled */ |
| 580 | rpmsg_upref_sleepers(vrp); |
| 581 | |
| 582 | /* |
| 583 | * sleep until a free buffer is available or 15 secs elapse. |
| 584 | * the timeout period is not configurable because there's |
| 585 | * little point in asking drivers to specify that. |
| 586 | * if later this happens to be required, it'd be easy to add. |
| 587 | */ |
| 588 | err = wait_event_interruptible_timeout(vrp->sendq, |
| 589 | (msg = get_a_tx_buf(vrp)), |
| 590 | msecs_to_jiffies(15000)); |
| 591 | |
| 592 | /* disable "tx-complete" interrupts if we're the last sleeper */ |
| 593 | rpmsg_downref_sleepers(vrp); |
| 594 | |
| 595 | /* timeout ? */ |
| 596 | if (!err) { |
| 597 | dev_err(dev, "timeout waiting for a tx buffer\n"); |
| 598 | return -ERESTARTSYS; |
| 599 | } |
| 600 | } |
| 601 | |
| 602 | msg->len = len; |
| 603 | msg->flags = 0; |
| 604 | msg->src = src; |
| 605 | msg->dst = dst; |
| 606 | msg->reserved = 0; |
| 607 | memcpy(msg->data, data, len); |
| 608 | |
| 609 | dev_dbg(dev, "TX From 0x%x, To 0x%x, Len %d, Flags %d, Reserved %d\n", |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 610 | msg->src, msg->dst, msg->len, msg->flags, msg->reserved); |
Anna, Suman | 211e3a9 | 2016-08-12 18:42:27 -0500 | [diff] [blame] | 611 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 612 | dynamic_hex_dump("rpmsg_virtio TX: ", DUMP_PREFIX_NONE, 16, 1, |
| 613 | msg, sizeof(*msg) + msg->len, true); |
| 614 | #endif |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 615 | |
| 616 | sg_init_one(&sg, msg, sizeof(*msg) + len); |
| 617 | |
| 618 | mutex_lock(&vrp->tx_lock); |
| 619 | |
| 620 | /* add message to the remote processor's virtqueue */ |
Rusty Russell | cee51d6 | 2013-03-20 15:44:29 +1030 | [diff] [blame] | 621 | err = virtqueue_add_outbuf(vrp->svq, &sg, 1, msg, GFP_KERNEL); |
Rusty Russell | 57e1a37 | 2012-10-16 23:56:15 +1030 | [diff] [blame] | 622 | if (err) { |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 623 | /* |
| 624 | * need to reclaim the buffer here, otherwise it's lost |
| 625 | * (memory won't leak, but rpmsg won't use it again for TX). |
| 626 | * this will wait for a buffer management overhaul. |
| 627 | */ |
Rusty Russell | cee51d6 | 2013-03-20 15:44:29 +1030 | [diff] [blame] | 628 | dev_err(dev, "virtqueue_add_outbuf failed: %d\n", err); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 629 | goto out; |
| 630 | } |
| 631 | |
| 632 | /* tell the remote processor it has a pending message to read */ |
| 633 | virtqueue_kick(vrp->svq); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 634 | out: |
| 635 | mutex_unlock(&vrp->tx_lock); |
| 636 | return err; |
| 637 | } |
| 638 | EXPORT_SYMBOL(rpmsg_send_offchannel_raw); |
| 639 | |
Bjorn Andersson | 8a228ec | 2016-09-01 15:28:00 -0700 | [diff] [blame] | 640 | static int virtio_rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len) |
| 641 | { |
| 642 | struct rpmsg_device *rpdev = ept->rpdev; |
| 643 | u32 src = ept->addr, dst = rpdev->dst; |
| 644 | |
| 645 | return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); |
| 646 | } |
| 647 | |
| 648 | static int virtio_rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, |
| 649 | u32 dst) |
| 650 | { |
| 651 | struct rpmsg_device *rpdev = ept->rpdev; |
| 652 | u32 src = ept->addr; |
| 653 | |
| 654 | return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); |
| 655 | } |
| 656 | |
| 657 | static int virtio_rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, |
| 658 | u32 dst, void *data, int len) |
| 659 | { |
| 660 | struct rpmsg_device *rpdev = ept->rpdev; |
| 661 | |
| 662 | return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, true); |
| 663 | } |
| 664 | |
| 665 | static int virtio_rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len) |
| 666 | { |
| 667 | struct rpmsg_device *rpdev = ept->rpdev; |
| 668 | u32 src = ept->addr, dst = rpdev->dst; |
| 669 | |
| 670 | return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); |
| 671 | } |
| 672 | |
| 673 | static int virtio_rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, |
| 674 | int len, u32 dst) |
| 675 | { |
| 676 | struct rpmsg_device *rpdev = ept->rpdev; |
| 677 | u32 src = ept->addr; |
| 678 | |
| 679 | return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); |
| 680 | } |
| 681 | |
| 682 | static int virtio_rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, |
| 683 | u32 dst, void *data, int len) |
| 684 | { |
| 685 | struct rpmsg_device *rpdev = ept->rpdev; |
| 686 | |
| 687 | return rpmsg_send_offchannel_raw(rpdev, src, dst, data, len, false); |
| 688 | } |
| 689 | |
Robert Tivy | 1aa7d6a | 2013-04-05 17:38:52 +0300 | [diff] [blame] | 690 | static int rpmsg_recv_single(struct virtproc_info *vrp, struct device *dev, |
| 691 | struct rpmsg_hdr *msg, unsigned int len) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 692 | { |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 693 | struct rpmsg_endpoint *ept; |
| 694 | struct scatterlist sg; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 695 | int err; |
| 696 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 697 | dev_dbg(dev, "From: 0x%x, To: 0x%x, Len: %d, Flags: %d, Reserved: %d\n", |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 698 | msg->src, msg->dst, msg->len, msg->flags, msg->reserved); |
Anna, Suman | 211e3a9 | 2016-08-12 18:42:27 -0500 | [diff] [blame] | 699 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 700 | dynamic_hex_dump("rpmsg_virtio RX: ", DUMP_PREFIX_NONE, 16, 1, |
| 701 | msg, sizeof(*msg) + msg->len, true); |
| 702 | #endif |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 703 | |
Ohad Ben-Cohen | 9648224 | 2012-02-28 16:16:48 +0200 | [diff] [blame] | 704 | /* |
| 705 | * We currently use fixed-sized buffers, so trivially sanitize |
| 706 | * the reported payload length. |
| 707 | */ |
| 708 | if (len > RPMSG_BUF_SIZE || |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 709 | msg->len > (len - sizeof(struct rpmsg_hdr))) { |
Ohad Ben-Cohen | 9648224 | 2012-02-28 16:16:48 +0200 | [diff] [blame] | 710 | dev_warn(dev, "inbound msg too big: (%d, %d)\n", len, msg->len); |
Robert Tivy | 1aa7d6a | 2013-04-05 17:38:52 +0300 | [diff] [blame] | 711 | return -EINVAL; |
Ohad Ben-Cohen | 9648224 | 2012-02-28 16:16:48 +0200 | [diff] [blame] | 712 | } |
| 713 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 714 | /* use the dst addr to fetch the callback of the appropriate user */ |
| 715 | mutex_lock(&vrp->endpoints_lock); |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 716 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 717 | ept = idr_find(&vrp->endpoints, msg->dst); |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 718 | |
| 719 | /* let's make sure no one deallocates ept while we use it */ |
| 720 | if (ept) |
| 721 | kref_get(&ept->refcount); |
| 722 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 723 | mutex_unlock(&vrp->endpoints_lock); |
| 724 | |
Ohad Ben-Cohen | 15fd943 | 2012-06-07 15:39:35 +0300 | [diff] [blame] | 725 | if (ept) { |
| 726 | /* make sure ept->cb doesn't go away while we use it */ |
| 727 | mutex_lock(&ept->cb_lock); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 728 | |
Ohad Ben-Cohen | 15fd943 | 2012-06-07 15:39:35 +0300 | [diff] [blame] | 729 | if (ept->cb) |
| 730 | ept->cb(ept->rpdev, msg->data, msg->len, ept->priv, |
| 731 | msg->src); |
| 732 | |
| 733 | mutex_unlock(&ept->cb_lock); |
| 734 | |
| 735 | /* farewell, ept, we don't need you anymore */ |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 736 | kref_put(&ept->refcount, __ept_release); |
Ohad Ben-Cohen | 15fd943 | 2012-06-07 15:39:35 +0300 | [diff] [blame] | 737 | } else |
Masanari Iida | 8a168ca | 2012-12-29 02:00:09 +0900 | [diff] [blame] | 738 | dev_warn(dev, "msg received with no recipient\n"); |
Ohad Ben-Cohen | 5a081ca | 2012-06-06 10:09:25 +0300 | [diff] [blame] | 739 | |
Ohad Ben-Cohen | f1d9e9c | 2012-02-28 16:11:28 +0200 | [diff] [blame] | 740 | /* publish the real size of the buffer */ |
| 741 | sg_init_one(&sg, msg, RPMSG_BUF_SIZE); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 742 | |
| 743 | /* add the buffer back to the remote processor's virtqueue */ |
Rusty Russell | cee51d6 | 2013-03-20 15:44:29 +1030 | [diff] [blame] | 744 | err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, msg, GFP_KERNEL); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 745 | if (err < 0) { |
| 746 | dev_err(dev, "failed to add a virtqueue buffer: %d\n", err); |
Robert Tivy | 1aa7d6a | 2013-04-05 17:38:52 +0300 | [diff] [blame] | 747 | return err; |
| 748 | } |
| 749 | |
| 750 | return 0; |
| 751 | } |
| 752 | |
| 753 | /* called when an rx buffer is used, and it's time to digest a message */ |
| 754 | static void rpmsg_recv_done(struct virtqueue *rvq) |
| 755 | { |
| 756 | struct virtproc_info *vrp = rvq->vdev->priv; |
| 757 | struct device *dev = &rvq->vdev->dev; |
| 758 | struct rpmsg_hdr *msg; |
| 759 | unsigned int len, msgs_received = 0; |
| 760 | int err; |
| 761 | |
| 762 | msg = virtqueue_get_buf(rvq, &len); |
| 763 | if (!msg) { |
| 764 | dev_err(dev, "uhm, incoming signal, but no used buffer ?\n"); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 765 | return; |
| 766 | } |
| 767 | |
Robert Tivy | 1aa7d6a | 2013-04-05 17:38:52 +0300 | [diff] [blame] | 768 | while (msg) { |
| 769 | err = rpmsg_recv_single(vrp, dev, msg, len); |
| 770 | if (err) |
| 771 | break; |
| 772 | |
| 773 | msgs_received++; |
| 774 | |
| 775 | msg = virtqueue_get_buf(rvq, &len); |
Lee Jones | 6c49fbe | 2016-07-20 10:29:35 +0100 | [diff] [blame] | 776 | } |
Robert Tivy | 1aa7d6a | 2013-04-05 17:38:52 +0300 | [diff] [blame] | 777 | |
| 778 | dev_dbg(dev, "Received %u messages\n", msgs_received); |
| 779 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 780 | /* tell the remote processor we added another available rx buffer */ |
Robert Tivy | 1aa7d6a | 2013-04-05 17:38:52 +0300 | [diff] [blame] | 781 | if (msgs_received) |
| 782 | virtqueue_kick(vrp->rvq); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 783 | } |
| 784 | |
| 785 | /* |
| 786 | * This is invoked whenever the remote processor completed processing |
| 787 | * a TX msg we just sent it, and the buffer is put back to the used ring. |
| 788 | * |
| 789 | * Normally, though, we suppress this "tx complete" interrupt in order to |
| 790 | * avoid the incurred overhead. |
| 791 | */ |
| 792 | static void rpmsg_xmit_done(struct virtqueue *svq) |
| 793 | { |
| 794 | struct virtproc_info *vrp = svq->vdev->priv; |
| 795 | |
| 796 | dev_dbg(&svq->vdev->dev, "%s\n", __func__); |
| 797 | |
| 798 | /* wake up potential senders that are waiting for a tx buffer */ |
| 799 | wake_up_interruptible(&vrp->sendq); |
| 800 | } |
| 801 | |
| 802 | /* invoked when a name service announcement arrives */ |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 803 | static int rpmsg_ns_cb(struct rpmsg_device *rpdev, void *data, int len, |
| 804 | void *priv, u32 src) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 805 | { |
| 806 | struct rpmsg_ns_msg *msg = data; |
Bjorn Andersson | 92e1de5 | 2016-09-01 15:27:57 -0700 | [diff] [blame] | 807 | struct rpmsg_device *newch; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 808 | struct rpmsg_channel_info chinfo; |
| 809 | struct virtproc_info *vrp = priv; |
| 810 | struct device *dev = &vrp->vdev->dev; |
| 811 | int ret; |
| 812 | |
Anna, Suman | 211e3a9 | 2016-08-12 18:42:27 -0500 | [diff] [blame] | 813 | #if defined(CONFIG_DYNAMIC_DEBUG) |
| 814 | dynamic_hex_dump("NS announcement: ", DUMP_PREFIX_NONE, 16, 1, |
| 815 | data, len, true); |
| 816 | #endif |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 817 | |
| 818 | if (len != sizeof(*msg)) { |
| 819 | dev_err(dev, "malformed ns msg (%d)\n", len); |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 820 | return -EINVAL; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 821 | } |
| 822 | |
| 823 | /* |
| 824 | * the name service ept does _not_ belong to a real rpmsg channel, |
| 825 | * and is handled by the rpmsg bus itself. |
| 826 | * for sanity reasons, make sure a valid rpdev has _not_ sneaked |
| 827 | * in somehow. |
| 828 | */ |
| 829 | if (rpdev) { |
| 830 | dev_err(dev, "anomaly: ns ept has an rpdev handle\n"); |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 831 | return -EINVAL; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 832 | } |
| 833 | |
| 834 | /* don't trust the remote processor for null terminating the name */ |
| 835 | msg->name[RPMSG_NAME_SIZE - 1] = '\0'; |
| 836 | |
| 837 | dev_info(dev, "%sing channel %s addr 0x%x\n", |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 838 | msg->flags & RPMSG_NS_DESTROY ? "destroy" : "creat", |
| 839 | msg->name, msg->addr); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 840 | |
| 841 | strncpy(chinfo.name, msg->name, sizeof(chinfo.name)); |
| 842 | chinfo.src = RPMSG_ADDR_ANY; |
| 843 | chinfo.dst = msg->addr; |
| 844 | |
| 845 | if (msg->flags & RPMSG_NS_DESTROY) { |
Bjorn Andersson | 5e619b4 | 2016-09-01 15:28:04 -0700 | [diff] [blame] | 846 | ret = rpmsg_unregister_device(&vrp->vdev->dev, &chinfo); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 847 | if (ret) |
| 848 | dev_err(dev, "rpmsg_destroy_channel failed: %d\n", ret); |
| 849 | } else { |
| 850 | newch = rpmsg_create_channel(vrp, &chinfo); |
| 851 | if (!newch) |
| 852 | dev_err(dev, "rpmsg_create_channel failed\n"); |
| 853 | } |
Bjorn Andersson | 4b83c52 | 2016-09-01 15:28:08 -0700 | [diff] [blame] | 854 | |
| 855 | return 0; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 856 | } |
| 857 | |
| 858 | static int rpmsg_probe(struct virtio_device *vdev) |
| 859 | { |
| 860 | vq_callback_t *vq_cbs[] = { rpmsg_recv_done, rpmsg_xmit_done }; |
Stefan Hajnoczi | f7ad26f | 2015-12-17 16:53:43 +0800 | [diff] [blame] | 861 | static const char * const names[] = { "input", "output" }; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 862 | struct virtqueue *vqs[2]; |
| 863 | struct virtproc_info *vrp; |
| 864 | void *bufs_va; |
| 865 | int err = 0, i; |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 866 | size_t total_buf_space; |
Michael S. Tsirkin | 71e4b8b | 2015-03-12 11:54:41 +1030 | [diff] [blame] | 867 | bool notify; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 868 | |
| 869 | vrp = kzalloc(sizeof(*vrp), GFP_KERNEL); |
| 870 | if (!vrp) |
| 871 | return -ENOMEM; |
| 872 | |
| 873 | vrp->vdev = vdev; |
| 874 | |
| 875 | idr_init(&vrp->endpoints); |
| 876 | mutex_init(&vrp->endpoints_lock); |
| 877 | mutex_init(&vrp->tx_lock); |
| 878 | init_waitqueue_head(&vrp->sendq); |
| 879 | |
| 880 | /* We expect two virtqueues, rx and tx (and in this order) */ |
Michael S. Tsirkin | 9b2bbdb | 2017-03-06 18:19:39 +0200 | [diff] [blame] | 881 | err = virtio_find_vqs(vdev, 2, vqs, vq_cbs, names, NULL); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 882 | if (err) |
| 883 | goto free_vrp; |
| 884 | |
| 885 | vrp->rvq = vqs[0]; |
| 886 | vrp->svq = vqs[1]; |
| 887 | |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 888 | /* we expect symmetric tx/rx vrings */ |
| 889 | WARN_ON(virtqueue_get_vring_size(vrp->rvq) != |
| 890 | virtqueue_get_vring_size(vrp->svq)); |
| 891 | |
| 892 | /* we need less buffers if vrings are small */ |
| 893 | if (virtqueue_get_vring_size(vrp->rvq) < MAX_RPMSG_NUM_BUFS / 2) |
| 894 | vrp->num_bufs = virtqueue_get_vring_size(vrp->rvq) * 2; |
| 895 | else |
| 896 | vrp->num_bufs = MAX_RPMSG_NUM_BUFS; |
| 897 | |
| 898 | total_buf_space = vrp->num_bufs * RPMSG_BUF_SIZE; |
| 899 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 900 | /* allocate coherent memory for the buffers */ |
Ohad Ben-Cohen | b5ab5e2 | 2012-05-30 22:01:25 +0300 | [diff] [blame] | 901 | bufs_va = dma_alloc_coherent(vdev->dev.parent->parent, |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 902 | total_buf_space, &vrp->bufs_dma, |
| 903 | GFP_KERNEL); |
Wei Yongjun | 3119b48 | 2013-04-29 16:17:09 -0700 | [diff] [blame] | 904 | if (!bufs_va) { |
| 905 | err = -ENOMEM; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 906 | goto vqs_del; |
Wei Yongjun | 3119b48 | 2013-04-29 16:17:09 -0700 | [diff] [blame] | 907 | } |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 908 | |
Anna, Suman | 8d95b32 | 2016-08-12 18:42:25 -0500 | [diff] [blame] | 909 | dev_dbg(&vdev->dev, "buffers: va %p, dma %pad\n", |
| 910 | bufs_va, &vrp->bufs_dma); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 911 | |
| 912 | /* half of the buffers is dedicated for RX */ |
| 913 | vrp->rbufs = bufs_va; |
| 914 | |
| 915 | /* and half is dedicated for TX */ |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 916 | vrp->sbufs = bufs_va + total_buf_space / 2; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 917 | |
| 918 | /* set up the receive buffers */ |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 919 | for (i = 0; i < vrp->num_bufs / 2; i++) { |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 920 | struct scatterlist sg; |
| 921 | void *cpu_addr = vrp->rbufs + i * RPMSG_BUF_SIZE; |
| 922 | |
| 923 | sg_init_one(&sg, cpu_addr, RPMSG_BUF_SIZE); |
| 924 | |
Rusty Russell | cee51d6 | 2013-03-20 15:44:29 +1030 | [diff] [blame] | 925 | err = virtqueue_add_inbuf(vrp->rvq, &sg, 1, cpu_addr, |
Anna, Suman | 0963679 | 2016-08-12 18:42:26 -0500 | [diff] [blame] | 926 | GFP_KERNEL); |
Rusty Russell | 57e1a37 | 2012-10-16 23:56:15 +1030 | [diff] [blame] | 927 | WARN_ON(err); /* sanity check; this can't really happen */ |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | /* suppress "tx-complete" interrupts */ |
| 931 | virtqueue_disable_cb(vrp->svq); |
| 932 | |
| 933 | vdev->priv = vrp; |
| 934 | |
| 935 | /* if supported by the remote processor, enable the name service */ |
| 936 | if (virtio_has_feature(vdev, VIRTIO_RPMSG_F_NS)) { |
| 937 | /* a dedicated endpoint handles the name service msgs */ |
| 938 | vrp->ns_ept = __rpmsg_create_ept(vrp, NULL, rpmsg_ns_cb, |
| 939 | vrp, RPMSG_NS_ADDR); |
| 940 | if (!vrp->ns_ept) { |
| 941 | dev_err(&vdev->dev, "failed to create the ns ept\n"); |
| 942 | err = -ENOMEM; |
| 943 | goto free_coherent; |
| 944 | } |
| 945 | } |
| 946 | |
Michael S. Tsirkin | 71e4b8b | 2015-03-12 11:54:41 +1030 | [diff] [blame] | 947 | /* |
| 948 | * Prepare to kick but don't notify yet - we can't do this before |
| 949 | * device is ready. |
| 950 | */ |
| 951 | notify = virtqueue_kick_prepare(vrp->rvq); |
| 952 | |
| 953 | /* From this point on, we can notify and get callbacks. */ |
| 954 | virtio_device_ready(vdev); |
| 955 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 956 | /* tell the remote processor it can start sending messages */ |
Michael S. Tsirkin | 71e4b8b | 2015-03-12 11:54:41 +1030 | [diff] [blame] | 957 | /* |
| 958 | * this might be concurrent with callbacks, but we are only |
| 959 | * doing notify, not a full kick here, so that's ok. |
| 960 | */ |
| 961 | if (notify) |
| 962 | virtqueue_notify(vrp->rvq); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 963 | |
| 964 | dev_info(&vdev->dev, "rpmsg host is online\n"); |
| 965 | |
| 966 | return 0; |
| 967 | |
| 968 | free_coherent: |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 969 | dma_free_coherent(vdev->dev.parent->parent, total_buf_space, |
| 970 | bufs_va, vrp->bufs_dma); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 971 | vqs_del: |
| 972 | vdev->config->del_vqs(vrp->vdev); |
| 973 | free_vrp: |
| 974 | kfree(vrp); |
| 975 | return err; |
| 976 | } |
| 977 | |
| 978 | static int rpmsg_remove_device(struct device *dev, void *data) |
| 979 | { |
| 980 | device_unregister(dev); |
| 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 985 | static void rpmsg_remove(struct virtio_device *vdev) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 986 | { |
| 987 | struct virtproc_info *vrp = vdev->priv; |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 988 | size_t total_buf_space = vrp->num_bufs * RPMSG_BUF_SIZE; |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 989 | int ret; |
| 990 | |
| 991 | vdev->config->reset(vdev); |
| 992 | |
| 993 | ret = device_for_each_child(&vdev->dev, NULL, rpmsg_remove_device); |
| 994 | if (ret) |
| 995 | dev_warn(&vdev->dev, "can't remove rpmsg device: %d\n", ret); |
| 996 | |
Ohad Ben-Cohen | fa2d779 | 2012-02-09 15:16:41 +0200 | [diff] [blame] | 997 | if (vrp->ns_ept) |
| 998 | __rpmsg_destroy_ept(vrp, vrp->ns_ept); |
| 999 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1000 | idr_destroy(&vrp->endpoints); |
| 1001 | |
| 1002 | vdev->config->del_vqs(vrp->vdev); |
| 1003 | |
Suman Anna | b1b9891 | 2014-09-16 13:33:07 -0500 | [diff] [blame] | 1004 | dma_free_coherent(vdev->dev.parent->parent, total_buf_space, |
| 1005 | vrp->rbufs, vrp->bufs_dma); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1006 | |
| 1007 | kfree(vrp); |
| 1008 | } |
| 1009 | |
| 1010 | static struct virtio_device_id id_table[] = { |
| 1011 | { VIRTIO_ID_RPMSG, VIRTIO_DEV_ANY_ID }, |
| 1012 | { 0 }, |
| 1013 | }; |
| 1014 | |
| 1015 | static unsigned int features[] = { |
| 1016 | VIRTIO_RPMSG_F_NS, |
| 1017 | }; |
| 1018 | |
| 1019 | static struct virtio_driver virtio_ipc_driver = { |
| 1020 | .feature_table = features, |
| 1021 | .feature_table_size = ARRAY_SIZE(features), |
| 1022 | .driver.name = KBUILD_MODNAME, |
| 1023 | .driver.owner = THIS_MODULE, |
| 1024 | .id_table = id_table, |
| 1025 | .probe = rpmsg_probe, |
Greg Kroah-Hartman | 0fe763c | 2012-12-21 15:14:44 -0800 | [diff] [blame] | 1026 | .remove = rpmsg_remove, |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1027 | }; |
| 1028 | |
| 1029 | static int __init rpmsg_init(void) |
| 1030 | { |
| 1031 | int ret; |
| 1032 | |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1033 | ret = register_virtio_driver(&virtio_ipc_driver); |
Bjorn Andersson | 5e619b4 | 2016-09-01 15:28:04 -0700 | [diff] [blame] | 1034 | if (ret) |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1035 | pr_err("failed to register virtio driver: %d\n", ret); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1036 | |
| 1037 | return ret; |
| 1038 | } |
Federico Fuga | 9634252 | 2012-07-16 10:36:51 +0300 | [diff] [blame] | 1039 | subsys_initcall(rpmsg_init); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1040 | |
| 1041 | static void __exit rpmsg_fini(void) |
| 1042 | { |
| 1043 | unregister_virtio_driver(&virtio_ipc_driver); |
Ohad Ben-Cohen | bcabbcc | 2011-10-20 21:10:55 +0200 | [diff] [blame] | 1044 | } |
| 1045 | module_exit(rpmsg_fini); |
| 1046 | |
| 1047 | MODULE_DEVICE_TABLE(virtio, id_table); |
| 1048 | MODULE_DESCRIPTION("Virtio-based remote processor messaging bus"); |
| 1049 | MODULE_LICENSE("GPL v2"); |