]>
Commit | Line | Data |
---|---|---|
bcabbcca OBC |
1 | /* |
2 | * Remote processor messaging | |
3 | * | |
4 | * Copyright (C) 2011 Texas Instruments, Inc. | |
5 | * Copyright (C) 2011 Google, Inc. | |
6 | * All rights reserved. | |
7 | * | |
8 | * Redistribution and use in source and binary forms, with or without | |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * | |
12 | * * Redistributions of source code must retain the above copyright | |
13 | * notice, this list of conditions and the following disclaimer. | |
14 | * * Redistributions in binary form must reproduce the above copyright | |
15 | * notice, this list of conditions and the following disclaimer in | |
16 | * the documentation and/or other materials provided with the | |
17 | * distribution. | |
18 | * * Neither the name Texas Instruments nor the names of its | |
19 | * contributors may be used to endorse or promote products derived | |
20 | * from this software without specific prior written permission. | |
21 | * | |
22 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
23 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
24 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
25 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
26 | * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
27 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
28 | * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
29 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
30 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
31 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
32 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
33 | */ | |
34 | ||
35 | #ifndef _LINUX_RPMSG_H | |
36 | #define _LINUX_RPMSG_H | |
37 | ||
38 | #include <linux/types.h> | |
39 | #include <linux/device.h> | |
40 | #include <linux/mod_devicetable.h> | |
5a081caa | 41 | #include <linux/kref.h> |
15fd943a | 42 | #include <linux/mutex.h> |
bcabbcca | 43 | |
bcabbcca OBC |
44 | #define RPMSG_ADDR_ANY 0xFFFFFFFF |
45 | ||
8a228ecf | 46 | struct rpmsg_device; |
36b72c7d BA |
47 | struct rpmsg_endpoint; |
48 | struct rpmsg_device_ops; | |
8a228ecf | 49 | struct rpmsg_endpoint_ops; |
bcabbcca | 50 | |
2b263d24 BA |
51 | /** |
52 | * struct rpmsg_channel_info - channel info representation | |
53 | * @name: name of service | |
54 | * @src: local address | |
55 | * @dst: destination address | |
56 | */ | |
57 | struct rpmsg_channel_info { | |
58 | char name[RPMSG_NAME_SIZE]; | |
59 | u32 src; | |
60 | u32 dst; | |
61 | }; | |
62 | ||
bcabbcca | 63 | /** |
92e1de51 | 64 | * rpmsg_device - device that belong to the rpmsg bus |
bcabbcca OBC |
65 | * @dev: the device struct |
66 | * @id: device id (used to match between rpmsg drivers and devices) | |
67 | * @src: local address | |
68 | * @dst: destination address | |
69 | * @ept: the rpmsg endpoint of this channel | |
70 | * @announce: if set, rpmsg will announce the creation/removal of this channel | |
71 | */ | |
92e1de51 | 72 | struct rpmsg_device { |
bcabbcca OBC |
73 | struct device dev; |
74 | struct rpmsg_device_id id; | |
75 | u32 src; | |
76 | u32 dst; | |
77 | struct rpmsg_endpoint *ept; | |
78 | bool announce; | |
36b72c7d BA |
79 | |
80 | const struct rpmsg_device_ops *ops; | |
bcabbcca OBC |
81 | }; |
82 | ||
4b83c52a | 83 | typedef int (*rpmsg_rx_cb_t)(struct rpmsg_device *, void *, int, void *, u32); |
bcabbcca OBC |
84 | |
85 | /** | |
86 | * struct rpmsg_endpoint - binds a local rpmsg address to its user | |
87 | * @rpdev: rpmsg channel device | |
5a081caa | 88 | * @refcount: when this drops to zero, the ept is deallocated |
bcabbcca | 89 | * @cb: rx callback handler |
15fd943a | 90 | * @cb_lock: must be taken before accessing/changing @cb |
bcabbcca OBC |
91 | * @addr: local rpmsg address |
92 | * @priv: private data for the driver's use | |
93 | * | |
94 | * In essence, an rpmsg endpoint represents a listener on the rpmsg bus, as | |
95 | * it binds an rpmsg address with an rx callback handler. | |
96 | * | |
97 | * Simple rpmsg drivers shouldn't use this struct directly, because | |
98 | * things just work: every rpmsg driver provides an rx callback upon | |
99 | * registering to the bus, and that callback is then bound to its rpmsg | |
100 | * address when the driver is probed. When relevant inbound messages arrive | |
101 | * (i.e. messages which their dst address equals to the src address of | |
102 | * the rpmsg channel), the driver's handler is invoked to process it. | |
103 | * | |
104 | * More complicated drivers though, that do need to allocate additional rpmsg | |
105 | * addresses, and bind them to different rx callbacks, must explicitly | |
106 | * create additional endpoints by themselves (see rpmsg_create_ept()). | |
107 | */ | |
108 | struct rpmsg_endpoint { | |
92e1de51 | 109 | struct rpmsg_device *rpdev; |
5a081caa | 110 | struct kref refcount; |
bcabbcca | 111 | rpmsg_rx_cb_t cb; |
15fd943a | 112 | struct mutex cb_lock; |
bcabbcca OBC |
113 | u32 addr; |
114 | void *priv; | |
8a228ecf BA |
115 | |
116 | const struct rpmsg_endpoint_ops *ops; | |
117 | }; | |
118 | ||
bcabbcca OBC |
119 | /** |
120 | * struct rpmsg_driver - rpmsg driver struct | |
121 | * @drv: underlying device driver | |
122 | * @id_table: rpmsg ids serviced by this driver | |
123 | * @probe: invoked when a matching rpmsg channel (i.e. device) is found | |
124 | * @remove: invoked when the rpmsg channel is removed | |
125 | * @callback: invoked when an inbound message is received on the channel | |
126 | */ | |
127 | struct rpmsg_driver { | |
128 | struct device_driver drv; | |
129 | const struct rpmsg_device_id *id_table; | |
92e1de51 BA |
130 | int (*probe)(struct rpmsg_device *dev); |
131 | void (*remove)(struct rpmsg_device *dev); | |
4b83c52a | 132 | int (*callback)(struct rpmsg_device *, void *, int, void *, u32); |
bcabbcca OBC |
133 | }; |
134 | ||
92e1de51 BA |
135 | int register_rpmsg_device(struct rpmsg_device *dev); |
136 | void unregister_rpmsg_device(struct rpmsg_device *dev); | |
bc3c57c1 | 137 | int __register_rpmsg_driver(struct rpmsg_driver *drv, struct module *owner); |
bcabbcca OBC |
138 | void unregister_rpmsg_driver(struct rpmsg_driver *drv); |
139 | void rpmsg_destroy_ept(struct rpmsg_endpoint *); | |
92e1de51 | 140 | struct rpmsg_endpoint *rpmsg_create_ept(struct rpmsg_device *, |
2b263d24 BA |
141 | rpmsg_rx_cb_t cb, void *priv, |
142 | struct rpmsg_channel_info chinfo); | |
bcabbcca | 143 | |
bc3c57c1 AD |
144 | /* use a macro to avoid include chaining to get THIS_MODULE */ |
145 | #define register_rpmsg_driver(drv) \ | |
146 | __register_rpmsg_driver(drv, THIS_MODULE) | |
147 | ||
f3d9f1ce AD |
148 | /** |
149 | * module_rpmsg_driver() - Helper macro for registering an rpmsg driver | |
150 | * @__rpmsg_driver: rpmsg_driver struct | |
151 | * | |
152 | * Helper macro for rpmsg drivers which do not do anything special in module | |
153 | * init/exit. This eliminates a lot of boilerplate. Each module may only | |
154 | * use this macro once, and calling it replaces module_init() and module_exit() | |
155 | */ | |
156 | #define module_rpmsg_driver(__rpmsg_driver) \ | |
157 | module_driver(__rpmsg_driver, register_rpmsg_driver, \ | |
158 | unregister_rpmsg_driver) | |
159 | ||
c9bd6f42 BA |
160 | int rpmsg_send(struct rpmsg_endpoint *ept, void *data, int len); |
161 | int rpmsg_sendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); | |
2a48d732 | 162 | int rpmsg_send_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, |
c9bd6f42 | 163 | void *data, int len); |
bcabbcca | 164 | |
c9bd6f42 BA |
165 | int rpmsg_trysend(struct rpmsg_endpoint *ept, void *data, int len); |
166 | int rpmsg_trysendto(struct rpmsg_endpoint *ept, void *data, int len, u32 dst); | |
2a48d732 | 167 | int rpmsg_trysend_offchannel(struct rpmsg_endpoint *ept, u32 src, u32 dst, |
c9bd6f42 | 168 | void *data, int len); |
bcabbcca OBC |
169 | |
170 | #endif /* _LINUX_RPMSG_H */ |