rpmsg_core.c 18 KB

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