• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * remote processor messaging bus
4  *
5  * Copyright (C) 2011 Texas Instruments, Inc.
6  * Copyright (C) 2011 Google, Inc.
7  *
8  * Ohad Ben-Cohen <ohad@wizery.com>
9  * Brian Swetland <swetland@google.com>
10  */
11 
12 #define pr_fmt(fmt) "%s: " fmt, __func__
13 
14 #include <linux/kernel.h>
15 #include <linux/module.h>
16 #include <linux/rpmsg.h>
17 #include <linux/of_device.h>
18 #include <linux/pm_domain.h>
19 #include <linux/slab.h>
20 
21 #include "rpmsg_internal.h"
22 
23 /**
24  * rpmsg_create_ept() - create a new rpmsg_endpoint
25  * @rpdev: rpmsg channel device
26  * @cb: rx callback handler
27  * @priv: private data for the driver's use
28  * @chinfo: channel_info with the local rpmsg address to bind with @cb
29  *
30  * Every rpmsg address in the system is bound to an rx callback (so when
31  * inbound messages arrive, they are dispatched by the rpmsg bus using the
32  * appropriate callback handler) by means of an rpmsg_endpoint struct.
33  *
34  * This function allows drivers to create such an endpoint, and by that,
35  * bind a callback, and possibly some private data too, to an rpmsg address
36  * (either one that is known in advance, or one that will be dynamically
37  * assigned for them).
38  *
39  * Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint
40  * is already created for them when they are probed by the rpmsg bus
41  * (using the rx callback provided when they registered to the rpmsg bus).
42  *
43  * So things should just work for simple drivers: they already have an
44  * endpoint, their rx callback is bound to their rpmsg address, and when
45  * relevant inbound messages arrive (i.e. messages which their dst address
46  * equals to the src address of their rpmsg channel), the driver's handler
47  * is invoked to process it.
48  *
49  * That said, more complicated drivers might need to allocate
50  * additional rpmsg addresses, and bind them to different rx callbacks.
51  * To accomplish that, those drivers need to call this function.
52  *
53  * Drivers should provide their @rpdev channel (so the new endpoint would belong
54  * to the same remote processor their channel belongs to), an rx callback
55  * function, an optional private data (which is provided back when the
56  * rx callback is invoked), and an address they want to bind with the
57  * callback. If @addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will
58  * dynamically assign them an available rpmsg address (drivers should have
59  * a very good reason why not to always use RPMSG_ADDR_ANY here).
60  *
61  * Returns a pointer to the endpoint on success, or NULL on error.
62  */
rpmsg_create_ept(struct rpmsg_device * rpdev,rpmsg_rx_cb_t cb,void * priv,struct rpmsg_channel_info chinfo)63 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
64 					rpmsg_rx_cb_t cb, void *priv,
65 					struct rpmsg_channel_info chinfo)
66 {
67 	if (WARN_ON(!rpdev))
68 		return NULL;
69 
70 	return rpdev->ops->create_ept(rpdev, cb, priv, chinfo);
71 }
72 EXPORT_SYMBOL(rpmsg_create_ept);
73 
74 /**
75  * rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
76  * @ept: endpoing to destroy
77  *
78  * Should be used by drivers to destroy an rpmsg endpoint previously
79  * created with rpmsg_create_ept(). As with other types of "free" NULL
80  * is a valid parameter.
81  */
rpmsg_destroy_ept(struct rpmsg_endpoint * ept)82 void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
83 {
84 	if (ept && ept->ops)
85 		ept->ops->destroy_ept(ept);
86 }
87 EXPORT_SYMBOL(rpmsg_destroy_ept);
88 
89 /**
90  * rpmsg_send() - send a message across to the remote processor
91  * @ept: the rpmsg endpoint
92  * @data: payload of message
93  * @len: length of payload
94  *
95  * This function sends @data of length @len on the @ept endpoint.
96  * The message will be sent to the remote processor which the @ept
97  * endpoint belongs to, using @ept's address and its associated rpmsg
98  * device destination addresses.
99  * In case there are no TX buffers available, the function will block until
100  * one becomes available, or a timeout of 15 seconds elapses. When the latter
101  * happens, -ERESTARTSYS is returned.
102  *
103  * Can only be called from process context (for now).
104  *
105  * Returns 0 on success and an appropriate error value on failure.
106  */
rpmsg_send(struct rpmsg_endpoint * ept,void * data,int len)107 int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
108 {
109 	if (WARN_ON(!ept))
110 		return -EINVAL;
111 	if (!ept->ops->send)
112 		return -ENXIO;
113 
114 	return ept->ops->send(ept, data, len);
115 }
116 EXPORT_SYMBOL(rpmsg_send);
117 
118 /**
119  * rpmsg_sendto() - send a message across to the remote processor, specify dst
120  * @ept: the rpmsg endpoint
121  * @data: payload of message
122  * @len: length of payload
123  * @dst: destination address
124  *
125  * This function sends @data of length @len to the remote @dst address.
126  * The message will be sent to the remote processor which the @ept
127  * endpoint belongs to, using @ept's address as source.
128  * In case there are no TX buffers available, the function will block until
129  * one becomes available, or a timeout of 15 seconds elapses. When the latter
130  * happens, -ERESTARTSYS is returned.
131  *
132  * Can only be called from process context (for now).
133  *
134  * Returns 0 on success and an appropriate error value on failure.
135  */
rpmsg_sendto(struct rpmsg_endpoint * ept,void * data,int len,u32 dst)136 int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
137 {
138 	if (WARN_ON(!ept))
139 		return -EINVAL;
140 	if (!ept->ops->sendto)
141 		return -ENXIO;
142 
143 	return ept->ops->sendto(ept, data, len, dst);
144 }
145 EXPORT_SYMBOL(rpmsg_sendto);
146 
147 /**
148  * rpmsg_send_offchannel() - send a message using explicit src/dst addresses
149  * @ept: the rpmsg endpoint
150  * @src: source address
151  * @dst: destination address
152  * @data: payload of message
153  * @len: length of payload
154  *
155  * This function sends @data of length @len to the remote @dst address,
156  * and uses @src as the source address.
157  * The message will be sent to the remote processor which the @ept
158  * endpoint belongs to.
159  * In case there are no TX buffers available, the function will block until
160  * one becomes available, or a timeout of 15 seconds elapses. When the latter
161  * happens, -ERESTARTSYS is returned.
162  *
163  * Can only be called from process context (for now).
164  *
165  * Returns 0 on success and an appropriate error value on failure.
166  */
rpmsg_send_offchannel(struct rpmsg_endpoint * ept,u32 src,u32 dst,void * data,int len)167 int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
168 			  void *data, int len)
169 {
170 	if (WARN_ON(!ept))
171 		return -EINVAL;
172 	if (!ept->ops->send_offchannel)
173 		return -ENXIO;
174 
175 	return ept->ops->send_offchannel(ept, src, dst, data, len);
176 }
177 EXPORT_SYMBOL(rpmsg_send_offchannel);
178 
179 /**
180  * rpmsg_trysend() - send a message across to the remote processor
181  * @ept: the rpmsg endpoint
182  * @data: payload of message
183  * @len: length of payload
184  *
185  * This function sends @data of length @len on the @ept endpoint.
186  * The message will be sent to the remote processor which the @ept
187  * endpoint belongs to, using @ept's address as source and its associated
188  * rpdev's address as destination.
189  * In case there are no TX buffers available, the function will immediately
190  * return -ENOMEM without waiting until one becomes available.
191  *
192  * Can only be called from process context (for now).
193  *
194  * Returns 0 on success and an appropriate error value on failure.
195  */
rpmsg_trysend(struct rpmsg_endpoint * ept,void * data,int len)196 int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
197 {
198 	if (WARN_ON(!ept))
199 		return -EINVAL;
200 	if (!ept->ops->trysend)
201 		return -ENXIO;
202 
203 	return ept->ops->trysend(ept, data, len);
204 }
205 EXPORT_SYMBOL(rpmsg_trysend);
206 
207 /**
208  * rpmsg_trysendto() - send a message across to the remote processor, specify dst
209  * @ept: the rpmsg endpoint
210  * @data: payload of message
211  * @len: length of payload
212  * @dst: destination address
213  *
214  * This function sends @data of length @len to the remote @dst address.
215  * The message will be sent to the remote processor which the @ept
216  * endpoint belongs to, using @ept's address as source.
217  * In case there are no TX buffers available, the function will immediately
218  * return -ENOMEM without waiting until one becomes available.
219  *
220  * Can only be called from process context (for now).
221  *
222  * Returns 0 on success and an appropriate error value on failure.
223  */
rpmsg_trysendto(struct rpmsg_endpoint * ept,void * data,int len,u32 dst)224 int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
225 {
226 	if (WARN_ON(!ept))
227 		return -EINVAL;
228 	if (!ept->ops->trysendto)
229 		return -ENXIO;
230 
231 	return ept->ops->trysendto(ept, data, len, dst);
232 }
233 EXPORT_SYMBOL(rpmsg_trysendto);
234 
235 /**
236  * rpmsg_poll() - poll the endpoint's send buffers
237  * @ept:	the rpmsg endpoint
238  * @filp:	file for poll_wait()
239  * @wait:	poll_table for poll_wait()
240  *
241  * Returns mask representing the current state of the endpoint's send buffers
242  */
rpmsg_poll(struct rpmsg_endpoint * ept,struct file * filp,poll_table * wait)243 __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
244 			poll_table *wait)
245 {
246 	if (WARN_ON(!ept))
247 		return 0;
248 	if (!ept->ops->poll)
249 		return 0;
250 
251 	return ept->ops->poll(ept, filp, wait);
252 }
253 EXPORT_SYMBOL(rpmsg_poll);
254 
255 /**
256  * rpmsg_trysend_offchannel() - send a message using explicit src/dst addresses
257  * @ept: the rpmsg endpoint
258  * @src: source address
259  * @dst: destination address
260  * @data: payload of message
261  * @len: length of payload
262  *
263  * This function sends @data of length @len to the remote @dst address,
264  * and uses @src as the source address.
265  * The message will be sent to the remote processor which the @ept
266  * endpoint belongs to.
267  * In case there are no TX buffers available, the function will immediately
268  * return -ENOMEM without waiting until one becomes available.
269  *
270  * Can only be called from process context (for now).
271  *
272  * Returns 0 on success and an appropriate error value on failure.
273  */
rpmsg_trysend_offchannel(struct rpmsg_endpoint * ept,u32 src,u32 dst,void * data,int len)274 int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
275 			     void *data, int len)
276 {
277 	if (WARN_ON(!ept))
278 		return -EINVAL;
279 	if (!ept->ops->trysend_offchannel)
280 		return -ENXIO;
281 
282 	return ept->ops->trysend_offchannel(ept, src, dst, data, len);
283 }
284 EXPORT_SYMBOL(rpmsg_trysend_offchannel);
285 
286 /**
287  * rpmsg_get_signals() - get the signals for this endpoint
288  * @ept:	the rpmsg endpoint
289  *
290  * Returns signal bits on success and an appropriate error value on failure.
291  */
rpmsg_get_signals(struct rpmsg_endpoint * ept)292 int rpmsg_get_signals(struct rpmsg_endpoint *ept)
293 {
294 	if (WARN_ON(!ept))
295 		return -EINVAL;
296 	if (!ept->ops->get_signals)
297 		return -ENXIO;
298 
299 	return ept->ops->get_signals(ept);
300 }
301 EXPORT_SYMBOL(rpmsg_get_signals);
302 
303 /**
304  * rpmsg_set_signals() - set the remote signals for this endpoint
305  * @ept:	the rpmsg endpoint
306  * @set:	set mask for signals
307  * @clear:	clear mask for signals
308  *
309  * Returns 0 on success and an appropriate error value on failure.
310  */
rpmsg_set_signals(struct rpmsg_endpoint * ept,u32 set,u32 clear)311 int rpmsg_set_signals(struct rpmsg_endpoint *ept, u32 set, u32 clear)
312 {
313 	if (WARN_ON(!ept))
314 		return -EINVAL;
315 	if (!ept->ops->set_signals)
316 		return -ENXIO;
317 
318 	return ept->ops->set_signals(ept, set, clear);
319 }
320 EXPORT_SYMBOL(rpmsg_set_signals);
321 
322 /*
323  * match a rpmsg channel with a channel info struct.
324  * this is used to make sure we're not creating rpmsg devices for channels
325  * that already exist.
326  */
rpmsg_device_match(struct device * dev,void * data)327 static int rpmsg_device_match(struct device *dev, void *data)
328 {
329 	struct rpmsg_channel_info *chinfo = data;
330 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
331 
332 	if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
333 		return 0;
334 
335 	if (chinfo->dst != RPMSG_ADDR_ANY && chinfo->dst != rpdev->dst)
336 		return 0;
337 
338 	if (strncmp(chinfo->name, rpdev->id.name, RPMSG_NAME_SIZE))
339 		return 0;
340 
341 	/* found a match ! */
342 	return 1;
343 }
344 
rpmsg_find_device(struct device * parent,struct rpmsg_channel_info * chinfo)345 struct device *rpmsg_find_device(struct device *parent,
346 				 struct rpmsg_channel_info *chinfo)
347 {
348 	return device_find_child(parent, chinfo, rpmsg_device_match);
349 
350 }
351 EXPORT_SYMBOL(rpmsg_find_device);
352 
353 /* sysfs show configuration fields */
354 #define rpmsg_show_attr(field, path, format_string)			\
355 static ssize_t								\
356 field##_show(struct device *dev,					\
357 			struct device_attribute *attr, char *buf)	\
358 {									\
359 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);		\
360 									\
361 	return sprintf(buf, format_string, rpdev->path);		\
362 }									\
363 static DEVICE_ATTR_RO(field);
364 
365 #define rpmsg_string_attr(field, member)				\
366 static ssize_t								\
367 field##_store(struct device *dev, struct device_attribute *attr,	\
368 	      const char *buf, size_t sz)				\
369 {									\
370 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);		\
371 	const char *old;						\
372 	char *new;							\
373 									\
374 	new = kstrndup(buf, sz, GFP_KERNEL);				\
375 	if (!new)							\
376 		return -ENOMEM;						\
377 	new[strcspn(new, "\n")] = '\0';					\
378 									\
379 	device_lock(dev);						\
380 	old = rpdev->member;						\
381 	if (strlen(new)) {						\
382 		rpdev->member = new;					\
383 	} else {							\
384 		kfree(new);						\
385 		rpdev->member = NULL;					\
386 	}								\
387 	device_unlock(dev);						\
388 									\
389 	kfree(old);							\
390 									\
391 	return sz;							\
392 }									\
393 static ssize_t								\
394 field##_show(struct device *dev,					\
395 	     struct device_attribute *attr, char *buf)			\
396 {									\
397 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);		\
398 									\
399 	return sprintf(buf, "%s\n", rpdev->member);			\
400 }									\
401 static DEVICE_ATTR_RW(field)
402 
403 /* for more info, see Documentation/ABI/testing/sysfs-bus-rpmsg */
404 rpmsg_show_attr(name, id.name, "%s\n");
405 rpmsg_show_attr(src, src, "0x%x\n");
406 rpmsg_show_attr(dst, dst, "0x%x\n");
407 rpmsg_show_attr(announce, announce ? "true" : "false", "%s\n");
408 rpmsg_string_attr(driver_override, driver_override);
409 
modalias_show(struct device * dev,struct device_attribute * attr,char * buf)410 static ssize_t modalias_show(struct device *dev,
411 			     struct device_attribute *attr, char *buf)
412 {
413 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
414 	ssize_t len;
415 
416 	len = of_device_modalias(dev, buf, PAGE_SIZE);
417 	if (len != -ENODEV)
418 		return len;
419 
420 	return sprintf(buf, RPMSG_DEVICE_MODALIAS_FMT "\n", rpdev->id.name);
421 }
422 static DEVICE_ATTR_RO(modalias);
423 
424 static struct attribute *rpmsg_dev_attrs[] = {
425 	&dev_attr_name.attr,
426 	&dev_attr_modalias.attr,
427 	&dev_attr_dst.attr,
428 	&dev_attr_src.attr,
429 	&dev_attr_announce.attr,
430 	&dev_attr_driver_override.attr,
431 	NULL,
432 };
433 ATTRIBUTE_GROUPS(rpmsg_dev);
434 
435 /* rpmsg devices and drivers are matched using the service name */
rpmsg_id_match(const struct rpmsg_device * rpdev,const struct rpmsg_device_id * id)436 static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
437 				  const struct rpmsg_device_id *id)
438 {
439 	return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
440 }
441 
442 /* match rpmsg channel and rpmsg driver */
rpmsg_dev_match(struct device * dev,struct device_driver * drv)443 static int rpmsg_dev_match(struct device *dev, struct device_driver *drv)
444 {
445 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
446 	struct rpmsg_driver *rpdrv = to_rpmsg_driver(drv);
447 	const struct rpmsg_device_id *ids = rpdrv->id_table;
448 	unsigned int i;
449 
450 	if (rpdev->driver_override)
451 		return !strcmp(rpdev->driver_override, drv->name);
452 
453 	if (ids)
454 		for (i = 0; ids[i].name[0]; i++)
455 			if (rpmsg_id_match(rpdev, &ids[i]))
456 				return 1;
457 
458 	return of_driver_match_device(dev, drv);
459 }
460 
rpmsg_uevent(struct device * dev,struct kobj_uevent_env * env)461 static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env)
462 {
463 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
464 	int ret;
465 
466 	ret = of_device_uevent_modalias(dev, env);
467 	if (ret != -ENODEV)
468 		return ret;
469 
470 	return add_uevent_var(env, "MODALIAS=" RPMSG_DEVICE_MODALIAS_FMT,
471 					rpdev->id.name);
472 }
473 
474 /*
475  * when an rpmsg driver is probed with a channel, we seamlessly create
476  * it an endpoint, binding its rx callback to a unique local rpmsg
477  * address.
478  *
479  * if we need to, we also announce about this channel to the remote
480  * processor (needed in case the driver is exposing an rpmsg service).
481  */
rpmsg_dev_probe(struct device * dev)482 static int rpmsg_dev_probe(struct device *dev)
483 {
484 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
485 	struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
486 	struct rpmsg_channel_info chinfo = {};
487 	struct rpmsg_endpoint *ept = NULL;
488 	int err;
489 
490 	err = dev_pm_domain_attach(dev, true);
491 	if (err)
492 		goto out;
493 
494 	if (rpdrv->callback) {
495 		strncpy(chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE);
496 		chinfo.src = rpdev->src;
497 		chinfo.dst = RPMSG_ADDR_ANY;
498 
499 		ept = rpmsg_create_ept(rpdev, rpdrv->callback, NULL, chinfo);
500 		if (!ept) {
501 			dev_err(dev, "failed to create endpoint\n");
502 			err = -ENOMEM;
503 			goto out;
504 		}
505 
506 		rpdev->ept = ept;
507 		rpdev->src = ept->addr;
508 
509 		if (rpdrv->signals)
510 			ept->sig_cb = rpdrv->signals;
511 
512 	}
513 
514 	err = rpdrv->probe(rpdev);
515 	if (err) {
516 		dev_err(dev, "%s: failed: %d\n", __func__, err);
517 		goto destroy_ept;
518 	}
519 
520 	if (ept && rpdev->ops->announce_create) {
521 		err = rpdev->ops->announce_create(rpdev);
522 		if (err) {
523 			dev_err(dev, "failed to announce creation\n");
524 			goto remove_rpdev;
525 		}
526 	}
527 
528 	return 0;
529 
530 remove_rpdev:
531 	if (rpdrv->remove)
532 		rpdrv->remove(rpdev);
533 destroy_ept:
534 	if (ept)
535 		rpmsg_destroy_ept(ept);
536 out:
537 	return err;
538 }
539 
rpmsg_dev_remove(struct device * dev)540 static int rpmsg_dev_remove(struct device *dev)
541 {
542 	struct rpmsg_device *rpdev = to_rpmsg_device(dev);
543 	struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
544 	int err = 0;
545 
546 	if (rpdev->ops->announce_destroy)
547 		err = rpdev->ops->announce_destroy(rpdev);
548 
549 	if (rpdrv->remove)
550 		rpdrv->remove(rpdev);
551 
552 	dev_pm_domain_detach(dev, true);
553 
554 	if (rpdev->ept)
555 		rpmsg_destroy_ept(rpdev->ept);
556 
557 	return err;
558 }
559 
560 static struct bus_type rpmsg_bus = {
561 	.name		= "rpmsg",
562 	.match		= rpmsg_dev_match,
563 	.dev_groups	= rpmsg_dev_groups,
564 	.uevent		= rpmsg_uevent,
565 	.probe		= rpmsg_dev_probe,
566 	.remove		= rpmsg_dev_remove,
567 };
568 
569 /*
570  * A helper for registering rpmsg device with driver override and name.
571  * Drivers should not be using it, but instead rpmsg_register_device().
572  */
rpmsg_register_device_override(struct rpmsg_device * rpdev,const char * driver_override)573 int rpmsg_register_device_override(struct rpmsg_device *rpdev,
574 				   const char *driver_override)
575 {
576 	struct device *dev = &rpdev->dev;
577 	int ret;
578 
579 	if (driver_override)
580 		strcpy(rpdev->id.name, driver_override);
581 
582 	dev_set_name(&rpdev->dev, "%s.%s.%d.%d", dev_name(dev->parent),
583 		     rpdev->id.name, rpdev->src, rpdev->dst);
584 
585 	rpdev->dev.bus = &rpmsg_bus;
586 
587 	device_initialize(dev);
588 	if (driver_override) {
589 		ret = driver_set_override(dev, (const char **)&rpdev->driver_override,
590 					  driver_override,
591 					  strlen(driver_override));
592 		if (ret) {
593 			dev_err(dev, "device_set_override failed: %d\n", ret);
594 			put_device(dev);
595 			return ret;
596 		}
597 	}
598 
599 	ret = device_add(dev);
600 	if (ret) {
601 		dev_err(dev, "device_add failed: %d\n", ret);
602 		kfree(rpdev->driver_override);
603 		rpdev->driver_override = NULL;
604 		put_device(&rpdev->dev);
605 	}
606 
607 	return ret;
608 }
609 EXPORT_SYMBOL(rpmsg_register_device_override);
610 
rpmsg_register_device(struct rpmsg_device * rpdev)611 int rpmsg_register_device(struct rpmsg_device *rpdev)
612 {
613 	return rpmsg_register_device_override(rpdev, NULL);
614 }
615 EXPORT_SYMBOL(rpmsg_register_device);
616 
617 /*
618  * find an existing channel using its name + address properties,
619  * and destroy it
620  */
rpmsg_unregister_device(struct device * parent,struct rpmsg_channel_info * chinfo)621 int rpmsg_unregister_device(struct device *parent,
622 			    struct rpmsg_channel_info *chinfo)
623 {
624 	struct device *dev;
625 
626 	dev = rpmsg_find_device(parent, chinfo);
627 	if (!dev)
628 		return -EINVAL;
629 
630 	device_unregister(dev);
631 
632 	put_device(dev);
633 
634 	return 0;
635 }
636 EXPORT_SYMBOL(rpmsg_unregister_device);
637 
638 /**
639  * __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
640  * @rpdrv: pointer to a struct rpmsg_driver
641  * @owner: owning module/driver
642  *
643  * Returns 0 on success, and an appropriate error value on failure.
644  */
__register_rpmsg_driver(struct rpmsg_driver * rpdrv,struct module * owner)645 int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner)
646 {
647 	rpdrv->drv.bus = &rpmsg_bus;
648 	rpdrv->drv.owner = owner;
649 	return driver_register(&rpdrv->drv);
650 }
651 EXPORT_SYMBOL(__register_rpmsg_driver);
652 
653 /**
654  * unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus
655  * @rpdrv: pointer to a struct rpmsg_driver
656  *
657  * Returns 0 on success, and an appropriate error value on failure.
658  */
unregister_rpmsg_driver(struct rpmsg_driver * rpdrv)659 void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv)
660 {
661 	driver_unregister(&rpdrv->drv);
662 }
663 EXPORT_SYMBOL(unregister_rpmsg_driver);
664 
665 
rpmsg_init(void)666 static int __init rpmsg_init(void)
667 {
668 	int ret;
669 
670 	ret = bus_register(&rpmsg_bus);
671 	if (ret)
672 		pr_err("failed to register rpmsg bus: %d\n", ret);
673 
674 	return ret;
675 }
676 postcore_initcall(rpmsg_init);
677 
rpmsg_fini(void)678 static void __exit rpmsg_fini(void)
679 {
680 	bus_unregister(&rpmsg_bus);
681 }
682 module_exit(rpmsg_fini);
683 
684 MODULE_DESCRIPTION("remote processor messaging bus");
685 MODULE_LICENSE("GPL v2");
686