Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * remote processor messaging bus
0004  *
0005  * Copyright (C) 2011 Texas Instruments, Inc.
0006  * Copyright (C) 2011 Google, Inc.
0007  *
0008  * Ohad Ben-Cohen <ohad@wizery.com>
0009  * Brian Swetland <swetland@google.com>
0010  */
0011 
0012 #define pr_fmt(fmt) "%s: " fmt, __func__
0013 
0014 #include <linux/kernel.h>
0015 #include <linux/module.h>
0016 #include <linux/rpmsg.h>
0017 #include <linux/of_device.h>
0018 #include <linux/pm_domain.h>
0019 #include <linux/slab.h>
0020 
0021 #include "rpmsg_internal.h"
0022 
0023 struct class *rpmsg_class;
0024 EXPORT_SYMBOL(rpmsg_class);
0025 
0026 /**
0027  * rpmsg_create_channel() - create a new rpmsg channel
0028  * using its name and address info.
0029  * @rpdev: rpmsg device
0030  * @chinfo: channel_info to bind
0031  *
0032  * Return: a pointer to the new rpmsg device on success, or NULL on error.
0033  */
0034 struct rpmsg_device *rpmsg_create_channel(struct rpmsg_device *rpdev,
0035                       struct rpmsg_channel_info *chinfo)
0036 {
0037     if (WARN_ON(!rpdev))
0038         return NULL;
0039     if (!rpdev->ops || !rpdev->ops->create_channel) {
0040         dev_err(&rpdev->dev, "no create_channel ops found\n");
0041         return NULL;
0042     }
0043 
0044     return rpdev->ops->create_channel(rpdev, chinfo);
0045 }
0046 EXPORT_SYMBOL(rpmsg_create_channel);
0047 
0048 /**
0049  * rpmsg_release_channel() - release a rpmsg channel
0050  * using its name and address info.
0051  * @rpdev: rpmsg device
0052  * @chinfo: channel_info to bind
0053  *
0054  * Return: 0 on success or an appropriate error value.
0055  */
0056 int rpmsg_release_channel(struct rpmsg_device *rpdev,
0057               struct rpmsg_channel_info *chinfo)
0058 {
0059     if (WARN_ON(!rpdev))
0060         return -EINVAL;
0061     if (!rpdev->ops || !rpdev->ops->release_channel) {
0062         dev_err(&rpdev->dev, "no release_channel ops found\n");
0063         return -ENXIO;
0064     }
0065 
0066     return rpdev->ops->release_channel(rpdev, chinfo);
0067 }
0068 EXPORT_SYMBOL(rpmsg_release_channel);
0069 
0070 /**
0071  * rpmsg_create_ept() - create a new rpmsg_endpoint
0072  * @rpdev: rpmsg channel device
0073  * @cb: rx callback handler
0074  * @priv: private data for the driver's use
0075  * @chinfo: channel_info with the local rpmsg address to bind with @cb
0076  *
0077  * Every rpmsg address in the system is bound to an rx callback (so when
0078  * inbound messages arrive, they are dispatched by the rpmsg bus using the
0079  * appropriate callback handler) by means of an rpmsg_endpoint struct.
0080  *
0081  * This function allows drivers to create such an endpoint, and by that,
0082  * bind a callback, and possibly some private data too, to an rpmsg address
0083  * (either one that is known in advance, or one that will be dynamically
0084  * assigned for them).
0085  *
0086  * Simple rpmsg drivers need not call rpmsg_create_ept, because an endpoint
0087  * is already created for them when they are probed by the rpmsg bus
0088  * (using the rx callback provided when they registered to the rpmsg bus).
0089  *
0090  * So things should just work for simple drivers: they already have an
0091  * endpoint, their rx callback is bound to their rpmsg address, and when
0092  * relevant inbound messages arrive (i.e. messages which their dst address
0093  * equals to the src address of their rpmsg channel), the driver's handler
0094  * is invoked to process it.
0095  *
0096  * That said, more complicated drivers might need to allocate
0097  * additional rpmsg addresses, and bind them to different rx callbacks.
0098  * To accomplish that, those drivers need to call this function.
0099  *
0100  * Drivers should provide their @rpdev channel (so the new endpoint would belong
0101  * to the same remote processor their channel belongs to), an rx callback
0102  * function, an optional private data (which is provided back when the
0103  * rx callback is invoked), and an address they want to bind with the
0104  * callback. If @addr is RPMSG_ADDR_ANY, then rpmsg_create_ept will
0105  * dynamically assign them an available rpmsg address (drivers should have
0106  * a very good reason why not to always use RPMSG_ADDR_ANY here).
0107  *
0108  * Return: a pointer to the endpoint on success, or NULL on error.
0109  */
0110 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
0111                     rpmsg_rx_cb_t cb, void *priv,
0112                     struct rpmsg_channel_info chinfo)
0113 {
0114     if (WARN_ON(!rpdev))
0115         return NULL;
0116 
0117     return rpdev->ops->create_ept(rpdev, cb, priv, chinfo);
0118 }
0119 EXPORT_SYMBOL(rpmsg_create_ept);
0120 
0121 /**
0122  * rpmsg_destroy_ept() - destroy an existing rpmsg endpoint
0123  * @ept: endpoing to destroy
0124  *
0125  * Should be used by drivers to destroy an rpmsg endpoint previously
0126  * created with rpmsg_create_ept(). As with other types of "free" NULL
0127  * is a valid parameter.
0128  */
0129 void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
0130 {
0131     if (ept && ept->ops)
0132         ept->ops->destroy_ept(ept);
0133 }
0134 EXPORT_SYMBOL(rpmsg_destroy_ept);
0135 
0136 /**
0137  * rpmsg_send() - send a message across to the remote processor
0138  * @ept: the rpmsg endpoint
0139  * @data: payload of message
0140  * @len: length of payload
0141  *
0142  * This function sends @data of length @len on the @ept endpoint.
0143  * The message will be sent to the remote processor which the @ept
0144  * endpoint belongs to, using @ept's address and its associated rpmsg
0145  * device destination addresses.
0146  * In case there are no TX buffers available, the function will block until
0147  * one becomes available, or a timeout of 15 seconds elapses. When the latter
0148  * happens, -ERESTARTSYS is returned.
0149  *
0150  * Can only be called from process context (for now).
0151  *
0152  * Return: 0 on success and an appropriate error value on failure.
0153  */
0154 int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
0155 {
0156     if (WARN_ON(!ept))
0157         return -EINVAL;
0158     if (!ept->ops->send)
0159         return -ENXIO;
0160 
0161     return ept->ops->send(ept, data, len);
0162 }
0163 EXPORT_SYMBOL(rpmsg_send);
0164 
0165 /**
0166  * rpmsg_sendto() - send a message across to the remote processor, specify dst
0167  * @ept: the rpmsg endpoint
0168  * @data: payload of message
0169  * @len: length of payload
0170  * @dst: destination address
0171  *
0172  * This function sends @data of length @len to the remote @dst address.
0173  * The message will be sent to the remote processor which the @ept
0174  * endpoint belongs to, using @ept's address as source.
0175  * In case there are no TX buffers available, the function will block until
0176  * one becomes available, or a timeout of 15 seconds elapses. When the latter
0177  * happens, -ERESTARTSYS is returned.
0178  *
0179  * Can only be called from process context (for now).
0180  *
0181  * Return: 0 on success and an appropriate error value on failure.
0182  */
0183 int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
0184 {
0185     if (WARN_ON(!ept))
0186         return -EINVAL;
0187     if (!ept->ops->sendto)
0188         return -ENXIO;
0189 
0190     return ept->ops->sendto(ept, data, len, dst);
0191 }
0192 EXPORT_SYMBOL(rpmsg_sendto);
0193 
0194 /**
0195  * rpmsg_send_offchannel() - send a message using explicit src/dst addresses
0196  * @ept: the rpmsg endpoint
0197  * @src: source address
0198  * @dst: destination address
0199  * @data: payload of message
0200  * @len: length of payload
0201  *
0202  * This function sends @data of length @len to the remote @dst address,
0203  * and uses @src as the source address.
0204  * The message will be sent to the remote processor which the @ept
0205  * endpoint belongs to.
0206  * In case there are no TX buffers available, the function will block until
0207  * one becomes available, or a timeout of 15 seconds elapses. When the latter
0208  * happens, -ERESTARTSYS is returned.
0209  *
0210  * Can only be called from process context (for now).
0211  *
0212  * Return: 0 on success and an appropriate error value on failure.
0213  */
0214 int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
0215               void *data, int len)
0216 {
0217     if (WARN_ON(!ept))
0218         return -EINVAL;
0219     if (!ept->ops->send_offchannel)
0220         return -ENXIO;
0221 
0222     return ept->ops->send_offchannel(ept, src, dst, data, len);
0223 }
0224 EXPORT_SYMBOL(rpmsg_send_offchannel);
0225 
0226 /**
0227  * rpmsg_trysend() - send a message across to the remote processor
0228  * @ept: the rpmsg endpoint
0229  * @data: payload of message
0230  * @len: length of payload
0231  *
0232  * This function sends @data of length @len on the @ept endpoint.
0233  * The message will be sent to the remote processor which the @ept
0234  * endpoint belongs to, using @ept's address as source and its associated
0235  * rpdev's address as destination.
0236  * In case there are no TX buffers available, the function will immediately
0237  * return -ENOMEM without waiting until one becomes available.
0238  *
0239  * Can only be called from process context (for now).
0240  *
0241  * Return: 0 on success and an appropriate error value on failure.
0242  */
0243 int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
0244 {
0245     if (WARN_ON(!ept))
0246         return -EINVAL;
0247     if (!ept->ops->trysend)
0248         return -ENXIO;
0249 
0250     return ept->ops->trysend(ept, data, len);
0251 }
0252 EXPORT_SYMBOL(rpmsg_trysend);
0253 
0254 /**
0255  * rpmsg_trysendto() - send a message across to the remote processor, specify dst
0256  * @ept: the rpmsg endpoint
0257  * @data: payload of message
0258  * @len: length of payload
0259  * @dst: destination address
0260  *
0261  * This function sends @data of length @len to the remote @dst address.
0262  * The message will be sent to the remote processor which the @ept
0263  * endpoint belongs to, using @ept's address as source.
0264  * In case there are no TX buffers available, the function will immediately
0265  * return -ENOMEM without waiting until one becomes available.
0266  *
0267  * Can only be called from process context (for now).
0268  *
0269  * Return: 0 on success and an appropriate error value on failure.
0270  */
0271 int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst)
0272 {
0273     if (WARN_ON(!ept))
0274         return -EINVAL;
0275     if (!ept->ops->trysendto)
0276         return -ENXIO;
0277 
0278     return ept->ops->trysendto(ept, data, len, dst);
0279 }
0280 EXPORT_SYMBOL(rpmsg_trysendto);
0281 
0282 /**
0283  * rpmsg_poll() - poll the endpoint's send buffers
0284  * @ept:    the rpmsg endpoint
0285  * @filp:   file for poll_wait()
0286  * @wait:   poll_table for poll_wait()
0287  *
0288  * Return: mask representing the current state of the endpoint's send buffers
0289  */
0290 __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
0291             poll_table *wait)
0292 {
0293     if (WARN_ON(!ept))
0294         return 0;
0295     if (!ept->ops->poll)
0296         return 0;
0297 
0298     return ept->ops->poll(ept, filp, wait);
0299 }
0300 EXPORT_SYMBOL(rpmsg_poll);
0301 
0302 /**
0303  * rpmsg_trysend_offchannel() - send a message using explicit src/dst addresses
0304  * @ept: the rpmsg endpoint
0305  * @src: source address
0306  * @dst: destination address
0307  * @data: payload of message
0308  * @len: length of payload
0309  *
0310  * This function sends @data of length @len to the remote @dst address,
0311  * and uses @src as the source address.
0312  * The message will be sent to the remote processor which the @ept
0313  * endpoint belongs to.
0314  * In case there are no TX buffers available, the function will immediately
0315  * return -ENOMEM without waiting until one becomes available.
0316  *
0317  * Can only be called from process context (for now).
0318  *
0319  * Return: 0 on success and an appropriate error value on failure.
0320  */
0321 int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
0322                  void *data, int len)
0323 {
0324     if (WARN_ON(!ept))
0325         return -EINVAL;
0326     if (!ept->ops->trysend_offchannel)
0327         return -ENXIO;
0328 
0329     return ept->ops->trysend_offchannel(ept, src, dst, data, len);
0330 }
0331 EXPORT_SYMBOL(rpmsg_trysend_offchannel);
0332 
0333 /**
0334  * rpmsg_get_mtu() - get maximum transmission buffer size for sending message.
0335  * @ept: the rpmsg endpoint
0336  *
0337  * This function returns maximum buffer size available for a single outgoing message.
0338  *
0339  * Return: the maximum transmission size on success and an appropriate error
0340  * value on failure.
0341  */
0342 
0343 ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept)
0344 {
0345     if (WARN_ON(!ept))
0346         return -EINVAL;
0347     if (!ept->ops->get_mtu)
0348         return -ENOTSUPP;
0349 
0350     return ept->ops->get_mtu(ept);
0351 }
0352 EXPORT_SYMBOL(rpmsg_get_mtu);
0353 
0354 /*
0355  * match a rpmsg channel with a channel info struct.
0356  * this is used to make sure we're not creating rpmsg devices for channels
0357  * that already exist.
0358  */
0359 static int rpmsg_device_match(struct device *dev, void *data)
0360 {
0361     struct rpmsg_channel_info *chinfo = data;
0362     struct rpmsg_device *rpdev = to_rpmsg_device(dev);
0363 
0364     if (chinfo->src != RPMSG_ADDR_ANY && chinfo->src != rpdev->src)
0365         return 0;
0366 
0367     if (chinfo->dst != RPMSG_ADDR_ANY && chinfo->dst != rpdev->dst)
0368         return 0;
0369 
0370     if (strncmp(chinfo->name, rpdev->id.name, RPMSG_NAME_SIZE))
0371         return 0;
0372 
0373     /* found a match ! */
0374     return 1;
0375 }
0376 
0377 struct device *rpmsg_find_device(struct device *parent,
0378                  struct rpmsg_channel_info *chinfo)
0379 {
0380     return device_find_child(parent, chinfo, rpmsg_device_match);
0381 
0382 }
0383 EXPORT_SYMBOL(rpmsg_find_device);
0384 
0385 /* sysfs show configuration fields */
0386 #define rpmsg_show_attr(field, path, format_string)         \
0387 static ssize_t                              \
0388 field##_show(struct device *dev,                    \
0389             struct device_attribute *attr, char *buf)   \
0390 {                                   \
0391     struct rpmsg_device *rpdev = to_rpmsg_device(dev);      \
0392                                     \
0393     return sprintf(buf, format_string, rpdev->path);        \
0394 }                                   \
0395 static DEVICE_ATTR_RO(field);
0396 
0397 #define rpmsg_string_attr(field, member)                \
0398 static ssize_t                              \
0399 field##_store(struct device *dev, struct device_attribute *attr,    \
0400           const char *buf, size_t sz)               \
0401 {                                   \
0402     struct rpmsg_device *rpdev = to_rpmsg_device(dev);      \
0403     const char *old;                        \
0404     char *new;                          \
0405                                     \
0406     new = kstrndup(buf, sz, GFP_KERNEL);                \
0407     if (!new)                           \
0408         return -ENOMEM;                     \
0409     new[strcspn(new, "\n")] = '\0';                 \
0410                                     \
0411     device_lock(dev);                       \
0412     old = rpdev->member;                        \
0413     if (strlen(new)) {                      \
0414         rpdev->member = new;                    \
0415     } else {                            \
0416         kfree(new);                     \
0417         rpdev->member = NULL;                   \
0418     }                               \
0419     device_unlock(dev);                     \
0420                                     \
0421     kfree(old);                         \
0422                                     \
0423     return sz;                          \
0424 }                                   \
0425 static ssize_t                              \
0426 field##_show(struct device *dev,                    \
0427          struct device_attribute *attr, char *buf)          \
0428 {                                   \
0429     struct rpmsg_device *rpdev = to_rpmsg_device(dev);      \
0430                                     \
0431     return sprintf(buf, "%s\n", rpdev->member);         \
0432 }                                   \
0433 static DEVICE_ATTR_RW(field)
0434 
0435 /* for more info, see Documentation/ABI/testing/sysfs-bus-rpmsg */
0436 rpmsg_show_attr(name, id.name, "%s\n");
0437 rpmsg_show_attr(src, src, "0x%x\n");
0438 rpmsg_show_attr(dst, dst, "0x%x\n");
0439 rpmsg_show_attr(announce, announce ? "true" : "false", "%s\n");
0440 rpmsg_string_attr(driver_override, driver_override);
0441 
0442 static ssize_t modalias_show(struct device *dev,
0443                  struct device_attribute *attr, char *buf)
0444 {
0445     struct rpmsg_device *rpdev = to_rpmsg_device(dev);
0446     ssize_t len;
0447 
0448     len = of_device_modalias(dev, buf, PAGE_SIZE);
0449     if (len != -ENODEV)
0450         return len;
0451 
0452     return sprintf(buf, RPMSG_DEVICE_MODALIAS_FMT "\n", rpdev->id.name);
0453 }
0454 static DEVICE_ATTR_RO(modalias);
0455 
0456 static struct attribute *rpmsg_dev_attrs[] = {
0457     &dev_attr_name.attr,
0458     &dev_attr_modalias.attr,
0459     &dev_attr_dst.attr,
0460     &dev_attr_src.attr,
0461     &dev_attr_announce.attr,
0462     &dev_attr_driver_override.attr,
0463     NULL,
0464 };
0465 ATTRIBUTE_GROUPS(rpmsg_dev);
0466 
0467 /* rpmsg devices and drivers are matched using the service name */
0468 static inline int rpmsg_id_match(const struct rpmsg_device *rpdev,
0469                   const struct rpmsg_device_id *id)
0470 {
0471     return strncmp(id->name, rpdev->id.name, RPMSG_NAME_SIZE) == 0;
0472 }
0473 
0474 /* match rpmsg channel and rpmsg driver */
0475 static int rpmsg_dev_match(struct device *dev, struct device_driver *drv)
0476 {
0477     struct rpmsg_device *rpdev = to_rpmsg_device(dev);
0478     struct rpmsg_driver *rpdrv = to_rpmsg_driver(drv);
0479     const struct rpmsg_device_id *ids = rpdrv->id_table;
0480     unsigned int i;
0481 
0482     if (rpdev->driver_override)
0483         return !strcmp(rpdev->driver_override, drv->name);
0484 
0485     if (ids)
0486         for (i = 0; ids[i].name[0]; i++)
0487             if (rpmsg_id_match(rpdev, &ids[i])) {
0488                 rpdev->id.driver_data = ids[i].driver_data;
0489                 return 1;
0490             }
0491 
0492     return of_driver_match_device(dev, drv);
0493 }
0494 
0495 static int rpmsg_uevent(struct device *dev, struct kobj_uevent_env *env)
0496 {
0497     struct rpmsg_device *rpdev = to_rpmsg_device(dev);
0498     int ret;
0499 
0500     ret = of_device_uevent_modalias(dev, env);
0501     if (ret != -ENODEV)
0502         return ret;
0503 
0504     return add_uevent_var(env, "MODALIAS=" RPMSG_DEVICE_MODALIAS_FMT,
0505                     rpdev->id.name);
0506 }
0507 
0508 /*
0509  * when an rpmsg driver is probed with a channel, we seamlessly create
0510  * it an endpoint, binding its rx callback to a unique local rpmsg
0511  * address.
0512  *
0513  * if we need to, we also announce about this channel to the remote
0514  * processor (needed in case the driver is exposing an rpmsg service).
0515  */
0516 static int rpmsg_dev_probe(struct device *dev)
0517 {
0518     struct rpmsg_device *rpdev = to_rpmsg_device(dev);
0519     struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
0520     struct rpmsg_channel_info chinfo = {};
0521     struct rpmsg_endpoint *ept = NULL;
0522     int err;
0523 
0524     err = dev_pm_domain_attach(dev, true);
0525     if (err)
0526         goto out;
0527 
0528     if (rpdrv->callback) {
0529         strncpy(chinfo.name, rpdev->id.name, RPMSG_NAME_SIZE);
0530         chinfo.src = rpdev->src;
0531         chinfo.dst = RPMSG_ADDR_ANY;
0532 
0533         ept = rpmsg_create_ept(rpdev, rpdrv->callback, NULL, chinfo);
0534         if (!ept) {
0535             dev_err(dev, "failed to create endpoint\n");
0536             err = -ENOMEM;
0537             goto out;
0538         }
0539 
0540         rpdev->ept = ept;
0541         rpdev->src = ept->addr;
0542     }
0543 
0544     err = rpdrv->probe(rpdev);
0545     if (err) {
0546         dev_err(dev, "%s: failed: %d\n", __func__, err);
0547         goto destroy_ept;
0548     }
0549 
0550     if (ept && rpdev->ops->announce_create) {
0551         err = rpdev->ops->announce_create(rpdev);
0552         if (err) {
0553             dev_err(dev, "failed to announce creation\n");
0554             goto remove_rpdev;
0555         }
0556     }
0557 
0558     return 0;
0559 
0560 remove_rpdev:
0561     if (rpdrv->remove)
0562         rpdrv->remove(rpdev);
0563 destroy_ept:
0564     if (ept)
0565         rpmsg_destroy_ept(ept);
0566 out:
0567     return err;
0568 }
0569 
0570 static void rpmsg_dev_remove(struct device *dev)
0571 {
0572     struct rpmsg_device *rpdev = to_rpmsg_device(dev);
0573     struct rpmsg_driver *rpdrv = to_rpmsg_driver(rpdev->dev.driver);
0574 
0575     if (rpdev->ops->announce_destroy)
0576         rpdev->ops->announce_destroy(rpdev);
0577 
0578     if (rpdrv->remove)
0579         rpdrv->remove(rpdev);
0580 
0581     dev_pm_domain_detach(dev, true);
0582 
0583     if (rpdev->ept)
0584         rpmsg_destroy_ept(rpdev->ept);
0585 }
0586 
0587 static struct bus_type rpmsg_bus = {
0588     .name       = "rpmsg",
0589     .match      = rpmsg_dev_match,
0590     .dev_groups = rpmsg_dev_groups,
0591     .uevent     = rpmsg_uevent,
0592     .probe      = rpmsg_dev_probe,
0593     .remove     = rpmsg_dev_remove,
0594 };
0595 
0596 /*
0597  * A helper for registering rpmsg device with driver override and name.
0598  * Drivers should not be using it, but instead rpmsg_register_device().
0599  */
0600 int rpmsg_register_device_override(struct rpmsg_device *rpdev,
0601                    const char *driver_override)
0602 {
0603     struct device *dev = &rpdev->dev;
0604     int ret;
0605 
0606     if (driver_override)
0607         strscpy_pad(rpdev->id.name, driver_override, RPMSG_NAME_SIZE);
0608 
0609     dev_set_name(dev, "%s.%s.%d.%d", dev_name(dev->parent),
0610              rpdev->id.name, rpdev->src, rpdev->dst);
0611 
0612     dev->bus = &rpmsg_bus;
0613 
0614     device_initialize(dev);
0615     if (driver_override) {
0616         ret = driver_set_override(dev, &rpdev->driver_override,
0617                       driver_override,
0618                       strlen(driver_override));
0619         if (ret) {
0620             dev_err(dev, "device_set_override failed: %d\n", ret);
0621             put_device(dev);
0622             return ret;
0623         }
0624     }
0625 
0626     ret = device_add(dev);
0627     if (ret) {
0628         dev_err(dev, "device_add failed: %d\n", ret);
0629         kfree(rpdev->driver_override);
0630         rpdev->driver_override = NULL;
0631         put_device(dev);
0632     }
0633 
0634     return ret;
0635 }
0636 EXPORT_SYMBOL(rpmsg_register_device_override);
0637 
0638 int rpmsg_register_device(struct rpmsg_device *rpdev)
0639 {
0640     return rpmsg_register_device_override(rpdev, NULL);
0641 }
0642 EXPORT_SYMBOL(rpmsg_register_device);
0643 
0644 /*
0645  * find an existing channel using its name + address properties,
0646  * and destroy it
0647  */
0648 int rpmsg_unregister_device(struct device *parent,
0649                 struct rpmsg_channel_info *chinfo)
0650 {
0651     struct device *dev;
0652 
0653     dev = rpmsg_find_device(parent, chinfo);
0654     if (!dev)
0655         return -EINVAL;
0656 
0657     device_unregister(dev);
0658 
0659     put_device(dev);
0660 
0661     return 0;
0662 }
0663 EXPORT_SYMBOL(rpmsg_unregister_device);
0664 
0665 /**
0666  * __register_rpmsg_driver() - register an rpmsg driver with the rpmsg bus
0667  * @rpdrv: pointer to a struct rpmsg_driver
0668  * @owner: owning module/driver
0669  *
0670  * Return: 0 on success, and an appropriate error value on failure.
0671  */
0672 int __register_rpmsg_driver(struct rpmsg_driver *rpdrv, struct module *owner)
0673 {
0674     rpdrv->drv.bus = &rpmsg_bus;
0675     rpdrv->drv.owner = owner;
0676     return driver_register(&rpdrv->drv);
0677 }
0678 EXPORT_SYMBOL(__register_rpmsg_driver);
0679 
0680 /**
0681  * unregister_rpmsg_driver() - unregister an rpmsg driver from the rpmsg bus
0682  * @rpdrv: pointer to a struct rpmsg_driver
0683  *
0684  * Return: 0 on success, and an appropriate error value on failure.
0685  */
0686 void unregister_rpmsg_driver(struct rpmsg_driver *rpdrv)
0687 {
0688     driver_unregister(&rpdrv->drv);
0689 }
0690 EXPORT_SYMBOL(unregister_rpmsg_driver);
0691 
0692 
0693 static int __init rpmsg_init(void)
0694 {
0695     int ret;
0696 
0697     rpmsg_class = class_create(THIS_MODULE, "rpmsg");
0698     if (IS_ERR(rpmsg_class)) {
0699         pr_err("failed to create rpmsg class\n");
0700         return PTR_ERR(rpmsg_class);
0701     }
0702 
0703     ret = bus_register(&rpmsg_bus);
0704     if (ret) {
0705         pr_err("failed to register rpmsg bus: %d\n", ret);
0706         class_destroy(rpmsg_class);
0707     }
0708     return ret;
0709 }
0710 postcore_initcall(rpmsg_init);
0711 
0712 static void __exit rpmsg_fini(void)
0713 {
0714     bus_unregister(&rpmsg_bus);
0715     class_destroy(rpmsg_class);
0716 }
0717 module_exit(rpmsg_fini);
0718 
0719 MODULE_DESCRIPTION("remote processor messaging bus");
0720 MODULE_LICENSE("GPL v2");