0001
0002
0003
0004
0005
0006
0007
0008
0009
0010 #ifndef _LINUX_RPMSG_H
0011 #define _LINUX_RPMSG_H
0012
0013 #include <linux/types.h>
0014 #include <linux/device.h>
0015 #include <linux/err.h>
0016 #include <linux/mod_devicetable.h>
0017 #include <linux/kref.h>
0018 #include <linux/mutex.h>
0019 #include <linux/poll.h>
0020 #include <linux/rpmsg/byteorder.h>
0021 #include <uapi/linux/rpmsg.h>
0022
0023 struct rpmsg_device;
0024 struct rpmsg_endpoint;
0025 struct rpmsg_device_ops;
0026 struct rpmsg_endpoint_ops;
0027
0028
0029
0030
0031
0032
0033
0034 struct rpmsg_channel_info {
0035 char name[RPMSG_NAME_SIZE];
0036 u32 src;
0037 u32 dst;
0038 };
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053 struct rpmsg_device {
0054 struct device dev;
0055 struct rpmsg_device_id id;
0056 const char *driver_override;
0057 u32 src;
0058 u32 dst;
0059 struct rpmsg_endpoint *ept;
0060 bool announce;
0061 bool little_endian;
0062
0063 const struct rpmsg_device_ops *ops;
0064 };
0065
0066 typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32);
0067
0068
0069
0070
0071
0072
0073
0074
0075
0076
0077
0078
0079
0080
0081
0082
0083
0084
0085
0086
0087
0088
0089
0090
0091 struct rpmsg_endpoint {
0092 struct rpmsg_device *rpdev;
0093 struct kref refcount;
0094 rpmsg_rx_cb_t cb;
0095 struct mutex cb_lock;
0096 u32 addr;
0097 void *priv;
0098
0099 const struct rpmsg_endpoint_ops *ops;
0100 };
0101
0102
0103
0104
0105
0106
0107
0108
0109
0110 struct rpmsg_driver {
0111 struct device_driver drv;
0112 const struct rpmsg_device_id *id_table;
0113 int (*probe)(struct rpmsg_device *dev);
0114 void (*remove)(struct rpmsg_device *dev);
0115 int (*callback)(struct rpmsg_device *, void *, int, void *, u32);
0116 };
0117
0118 static inline u16 rpmsg16_to_cpu(struct rpmsg_device *rpdev, __rpmsg16 val)
0119 {
0120 if (!rpdev)
0121 return __rpmsg16_to_cpu(rpmsg_is_little_endian(), val);
0122 else
0123 return __rpmsg16_to_cpu(rpdev->little_endian, val);
0124 }
0125
0126 static inline __rpmsg16 cpu_to_rpmsg16(struct rpmsg_device *rpdev, u16 val)
0127 {
0128 if (!rpdev)
0129 return __cpu_to_rpmsg16(rpmsg_is_little_endian(), val);
0130 else
0131 return __cpu_to_rpmsg16(rpdev->little_endian, val);
0132 }
0133
0134 static inline u32 rpmsg32_to_cpu(struct rpmsg_device *rpdev, __rpmsg32 val)
0135 {
0136 if (!rpdev)
0137 return __rpmsg32_to_cpu(rpmsg_is_little_endian(), val);
0138 else
0139 return __rpmsg32_to_cpu(rpdev->little_endian, val);
0140 }
0141
0142 static inline __rpmsg32 cpu_to_rpmsg32(struct rpmsg_device *rpdev, u32 val)
0143 {
0144 if (!rpdev)
0145 return __cpu_to_rpmsg32(rpmsg_is_little_endian(), val);
0146 else
0147 return __cpu_to_rpmsg32(rpdev->little_endian, val);
0148 }
0149
0150 static inline u64 rpmsg64_to_cpu(struct rpmsg_device *rpdev, __rpmsg64 val)
0151 {
0152 if (!rpdev)
0153 return __rpmsg64_to_cpu(rpmsg_is_little_endian(), val);
0154 else
0155 return __rpmsg64_to_cpu(rpdev->little_endian, val);
0156 }
0157
0158 static inline __rpmsg64 cpu_to_rpmsg64(struct rpmsg_device *rpdev, u64 val)
0159 {
0160 if (!rpdev)
0161 return __cpu_to_rpmsg64(rpmsg_is_little_endian(), val);
0162 else
0163 return __cpu_to_rpmsg64(rpdev->little_endian, val);
0164 }
0165
0166 #if IS_ENABLED(CONFIG_RPMSG)
0167
0168 int rpmsg_register_device_override(struct rpmsg_device *rpdev,
0169 const char *driver_override);
0170 int rpmsg_register_device(struct rpmsg_device *rpdev);
0171 int rpmsg_unregister_device(struct device *parent,
0172 struct rpmsg_channel_info *chinfo);
0173 int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner);
0174 void unregister_rpmsg_driver(struct rpmsg_driver *drv);
0175 void rpmsg_destroy_ept(struct rpmsg_endpoint *);
0176 struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *,
0177 rpmsg_rx_cb_t cb, void *priv,
0178 struct rpmsg_channel_info chinfo);
0179
0180 int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len);
0181 int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
0182 int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
0183 void *data, int len);
0184
0185 int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len);
0186 int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst);
0187 int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst,
0188 void *data, int len);
0189
0190 __poll_t rpmsg_poll(struct rpmsg_endpoint *ept, struct file *filp,
0191 poll_table *wait);
0192
0193 ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept);
0194
0195 #else
0196
0197 static inline int rpmsg_register_device_override(struct rpmsg_device *rpdev,
0198 const char *driver_override)
0199 {
0200 return -ENXIO;
0201 }
0202
0203 static inline int rpmsg_register_device(struct rpmsg_device *rpdev)
0204 {
0205 return -ENXIO;
0206 }
0207
0208 static inline int rpmsg_unregister_device(struct device *parent,
0209 struct rpmsg_channel_info *chinfo)
0210 {
0211
0212 WARN_ON(1);
0213
0214 return -ENXIO;
0215 }
0216
0217 static inline int __register_rpmsg_driver(struct rpmsg_driver *drv,
0218 struct module *owner)
0219 {
0220
0221 WARN_ON(1);
0222
0223 return -ENXIO;
0224 }
0225
0226 static inline void unregister_rpmsg_driver(struct rpmsg_driver *drv)
0227 {
0228
0229 WARN_ON(1);
0230 }
0231
0232 static inline void rpmsg_destroy_ept(struct rpmsg_endpoint *ept)
0233 {
0234
0235 WARN_ON(1);
0236 }
0237
0238 static inline struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *rpdev,
0239 rpmsg_rx_cb_t cb,
0240 void *priv,
0241 struct rpmsg_channel_info chinfo)
0242 {
0243
0244 WARN_ON(1);
0245
0246 return NULL;
0247 }
0248
0249 static inline int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len)
0250 {
0251
0252 WARN_ON(1);
0253
0254 return -ENXIO;
0255 }
0256
0257 static inline int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len,
0258 u32 dst)
0259 {
0260
0261 WARN_ON(1);
0262
0263 return -ENXIO;
0264
0265 }
0266
0267 static inline int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src,
0268 u32 dst, void *data, int len)
0269 {
0270
0271 WARN_ON(1);
0272
0273 return -ENXIO;
0274 }
0275
0276 static inline int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len)
0277 {
0278
0279 WARN_ON(1);
0280
0281 return -ENXIO;
0282 }
0283
0284 static inline int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data,
0285 int len, u32 dst)
0286 {
0287
0288 WARN_ON(1);
0289
0290 return -ENXIO;
0291 }
0292
0293 static inline int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src,
0294 u32 dst, void *data, int len)
0295 {
0296
0297 WARN_ON(1);
0298
0299 return -ENXIO;
0300 }
0301
0302 static inline __poll_t rpmsg_poll(struct rpmsg_endpoint *ept,
0303 struct file *filp, poll_table *wait)
0304 {
0305
0306 WARN_ON(1);
0307
0308 return 0;
0309 }
0310
0311 static inline ssize_t rpmsg_get_mtu(struct rpmsg_endpoint *ept)
0312 {
0313
0314 WARN_ON(1);
0315
0316 return -ENXIO;
0317 }
0318
0319 #endif
0320
0321
0322 #define register_rpmsg_driver(drv) \
0323 __register_rpmsg_driver(drv, THIS_MODULE)
0324
0325
0326
0327
0328
0329
0330
0331
0332
0333 #define module_rpmsg_driver(__rpmsg_driver) \
0334 module_driver(__rpmsg_driver, register_rpmsg_driver, \
0335 unregister_rpmsg_driver)
0336
0337 #endif