rpmsg_core.c 18 KB

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