2018-05-31 17:10:59 +00:00
|
|
|
/* SPDX-License-Identifier: BSD-3-Clause */
|
2011-10-20 19:10:55 +00:00
|
|
|
/*
|
|
|
|
* Remote processor messaging
|
|
|
|
*
|
|
|
|
* Copyright (C) 2011 Texas Instruments, Inc.
|
|
|
|
* Copyright (C) 2011 Google, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _LINUX_RPMSG_H
|
|
|
|
#define _LINUX_RPMSG_H
|
|
|
|
|
|
|
|
#include <linux/types.h>
|
|
|
|
#include <linux/device.h>
|
2016-10-21 17:25:37 +00:00
|
|
|
#include <linux/err.h>
|
2011-10-20 19:10:55 +00:00
|
|
|
#include <linux/mod_devicetable.h>
|
2012-06-06 07:09:25 +00:00
|
|
|
#include <linux/kref.h>
|
2012-06-07 12:39:35 +00:00
|
|
|
#include <linux/mutex.h>
|
2017-01-11 14:35:10 +00:00
|
|
|
#include <linux/poll.h>
|
2011-10-20 19:10:55 +00:00
|
|
|
|
|
|
|
#define RPMSG_ADDR_ANY 0xFFFFFFFF
|
|
|
|
|
2016-09-01 22:28:00 +00:00
|
|
|
struct rpmsg_device;
|
2016-09-01 22:27:58 +00:00
|
|
|
struct rpmsg_endpoint;
|
|
|
|
struct rpmsg_device_ops;
|
2016-09-01 22:28:00 +00:00
|
|
|
struct rpmsg_endpoint_ops;
|
2011-10-20 19:10:55 +00:00
|
|
|
|
2016-09-01 22:27:56 +00:00
|
|
|
/**
|
|
|
|
* struct rpmsg_channel_info - channel info representation
|
|
|
|
* @name: name of service
|
|
|
|
* @src: local address
|
|
|
|
* @dst: destination address
|
|
|
|
*/
|
|
|
|
struct rpmsg_channel_info {
|
|
|
|
char name[RPMSG_NAME_SIZE];
|
|
|
|
u32 src;
|
|
|
|
u32 dst;
|
|
|
|
};
|
|
|
|
|
2011-10-20 19:10:55 +00:00
|
|
|
/**
|
2016-09-01 22:27:57 +00:00
|
|
|
* rpmsg_device - device that belong to the rpmsg bus
|
2011-10-20 19:10:55 +00:00
|
|
|
* @dev: the device struct
|
|
|
|
* @id: device id (used to match between rpmsg drivers and devices)
|
2016-10-08 04:23:12 +00:00
|
|
|
* @driver_override: driver name to force a match
|
2011-10-20 19:10:55 +00:00
|
|
|
* @src: local address
|
|
|
|
* @dst: destination address
|
|
|
|
* @ept: the rpmsg endpoint of this channel
|
|
|
|
* @announce: if set, rpmsg will announce the creation/removal of this channel
|
|
|
|
*/
|
2016-09-01 22:27:57 +00:00
|
|
|
struct rpmsg_device {
|
2011-10-20 19:10:55 +00:00
|
|
|
struct device dev;
|
|
|
|
struct rpmsg_device_id id;
|
2016-10-08 04:23:12 +00:00
|
|
|
char *driver_override;
|
2011-10-20 19:10:55 +00:00
|
|
|
u32 src;
|
|
|
|
u32 dst;
|
|
|
|
struct rpmsg_endpoint *ept;
|
|
|
|
bool announce;
|
2016-09-01 22:27:58 +00:00
|
|
|
|
|
|
|
const struct rpmsg_device_ops *ops;
|
2011-10-20 19:10:55 +00:00
|
|
|
};
|
|
|
|
|
2016-09-01 22:28:08 +00:00
|
|
|
typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
|
2011-10-20 19:10:55 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* struct rpmsg_endpoint - binds a local rpmsg address to its user
|
|
|
|
* @rpdev: rpmsg channel device
|
2012-06-06 07:09:25 +00:00
|
|
|
* @refcount: when this drops to zero, the ept is deallocated
|
2011-10-20 19:10:55 +00:00
|
|
|
* @cb: rx callback handler
|
2012-06-07 12:39:35 +00:00
|
|
|
* @cb_lock: must be taken before accessing/changing @cb
|
2011-10-20 19:10:55 +00:00
|
|
|
* @addr: local rpmsg address
|
|
|
|
* @priv: private data for the driver's use
|
|
|
|
*
|
|
|
|
* In essence, an rpmsg endpoint represents a listener on the rpmsg bus, as
|
|
|
|
* it binds an rpmsg address with an rx callback handler.
|
|
|
|
*
|
|
|
|
* Simple rpmsg drivers shouldn't use this struct directly, because
|
|
|
|
* things just work: every rpmsg driver provides an rx callback upon
|
|
|
|
* registering to the bus, and that callback is then bound to its rpmsg
|
|
|
|
* address when the driver is probed. When relevant inbound messages arrive
|
|
|
|
* (i.e. messages which their dst address equals to the src address of
|
|
|
|
* the rpmsg channel), the driver's handler is invoked to process it.
|
|
|
|
*
|
|
|
|
* More complicated drivers though, that do need to allocate additional rpmsg
|
|
|
|
* addresses, and bind them to different rx callbacks, must explicitly
|
|
|
|
* create additional endpoints by themselves (see rpmsg_create_ept()).
|
|
|
|
*/
|
|
|
|
struct rpmsg_endpoint {
|
2016-09-01 22:27:57 +00:00
|
|
|
struct rpmsg_device *rpdev;
|
2012-06-06 07:09:25 +00:00
|
|
|
struct kref refcount;
|
2011-10-20 19:10:55 +00:00
|
|
|
rpmsg_rx_cb_t cb;
|
2012-06-07 12:39:35 +00:00
|
|
|
struct mutex cb_lock;
|
2011-10-20 19:10:55 +00:00
|
|
|
u32 addr;
|
|
|
|
void *priv;
|
2016-09-01 22:28:00 +00:00
|
|
|
|
|
|
|
const struct rpmsg_endpoint_ops *ops;
|
|
|
|
};
|
|
|
|
|
2011-10-20 19:10:55 +00:00
|
|
|
/**
|
|
|
|
* struct rpmsg_driver - rpmsg driver struct
|
|
|
|
* @drv: underlying device driver
|
|
|
|
* @id_table: rpmsg ids serviced by this driver
|
|
|
|
* @probe: invoked when a matching rpmsg channel (i.e. device) is found
|
|
|
|
* @remove: invoked when the rpmsg channel is removed
|
|
|
|
* @callback: invoked when an inbound message is received on the channel
|
|
|
|
*/
|
|
|
|
struct rpmsg_driver {
|
|
|
|
struct device_driver drv;
|
|
|
|
const struct rpmsg_device_id *id_table;
|
2016-09-01 22:27:57 +00:00
|
|
|
int (*probe)(struct rpmsg_device *dev);
|
|
|
|
void (*remove)(struct rpmsg_device *dev);
|
2016-09-01 22:28:08 +00:00
|
|
|
int (*callback)(struct rpmsg_device *, void *, int, void *, u32);
|
2011-10-20 19:10:55 +00:00
|
|
|
};
|
|
|
|
|
2016-10-21 17:25:37 +00:00
|
|
|
#if IS_ENABLED(CONFIG_RPMSG)
|
|
|
|
|
2016-09-01 22:27:57 +00:00
|
|
|
int register_rpmsg_device(struct rpmsg_device *dev);
|
|
|
|
void unregister_rpmsg_device(struct rpmsg_device *dev);
|
2016-05-04 22:01:36 +00:00
|
|
|
int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
|
2011-10-20 19:10:55 +00:00
|
|
|
void unregister_rpmsg_driver(struct rpmsg_driver *drv);
|
|
|
|
void rpmsg_destroy_ept(struct rpmsg_endpoint *);
|
2016-09-01 22:27:57 +00:00
|
|
|
struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *,
|
2016-09-01 22:27:56 +00:00
|
|
|
rpmsg_rx_cb_t cb, void *priv,
|
|
|
|
struct rpmsg_channel_info chinfo);
|
2011-10-20 19:10:55 +00:00
|
|
|
|
2016-10-21 17:25:37 +00:00
|
|
|
int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
|
|
|
|
int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
|
|
|
|
int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
|
|
|
void *data, int len);
|
|
|
|
|
|
|
|
int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
|
|
|
|
int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
|
|
|
|
int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
|
|
|
|
void *data, int len);
|
|
|
|
|
2017-07-03 10:39:46 +00:00
|
|
|
__poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
|
2017-01-11 14:35:10 +00:00
|
|
|
poll_table *wait);
|
|
|
|
|
2016-10-21 17:25:37 +00:00
|
|
|
#else
|
|
|
|
|
|
|
|
static inline int register_rpmsg_device(struct rpmsg_device *dev)
|
|
|
|
{
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unregister_rpmsg_device(struct rpmsg_device *dev)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int __register_rpmsg_driver(struct rpmsg_driver *drv,
|
|
|
|
struct module *owner)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void unregister_rpmsg_driver(struct rpmsg_driver *drv)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
|
|
|
|
rpmsg_rx_cb_t cb,
|
|
|
|
void *priv,
|
|
|
|
struct rpmsg_channel_info chinfo)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return ERR_PTR(-ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
|
|
|
|
u32 dst)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src,
|
|
|
|
u32 dst, void *data, int len)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
|
|
|
|
int len, u32 dst)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
|
|
|
|
u32 dst, void *data, int len)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
2017-07-03 10:39:46 +00:00
|
|
|
static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept,
|
2017-01-11 14:35:10 +00:00
|
|
|
struct file *filp, poll_table *wait)
|
|
|
|
{
|
|
|
|
/* This shouldn't be possible */
|
|
|
|
WARN_ON(1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-10-21 17:25:37 +00:00
|
|
|
#endif /* IS_ENABLED(CONFIG_RPMSG) */
|
|
|
|
|
2016-05-04 22:01:36 +00:00
|
|
|
/* use a macro to avoid include chaining to get THIS_MODULE */
|
|
|
|
#define register_rpmsg_driver(drv) \
|
|
|
|
__register_rpmsg_driver(drv, THIS_MODULE)
|
|
|
|
|
2016-05-04 22:01:38 +00:00
|
|
|
/**
|
|
|
|
* module_rpmsg_driver() - Helper macro for registering an rpmsg driver
|
|
|
|
* @__rpmsg_driver: rpmsg_driver struct
|
|
|
|
*
|
|
|
|
* Helper macro for rpmsg drivers which do not do anything special in module
|
|
|
|
* init/exit. This eliminates a lot of boilerplate. Each module may only
|
|
|
|
* use this macro once, and calling it replaces module_init() and module_exit()
|
|
|
|
*/
|
|
|
|
#define module_rpmsg_driver(__rpmsg_driver) \
|
|
|
|
module_driver(__rpmsg_driver, register_rpmsg_driver, \
|
|
|
|
unregister_rpmsg_driver)
|
|
|
|
|
2011-10-20 19:10:55 +00:00
|
|
|
#endif /* _LINUX_RPMSG_H */
|