1 /*
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * $FreeBSD$
5 */
6
7 #ifndef _RPMSG_INTERNAL_H_
8 #define _RPMSG_INTERNAL_H_
9
10 #include <stdint.h>
11 #include <openamp/rpmsg.h>
12
13 #if defined __cplusplus
14 extern "C" {
15 #endif
16
17 #ifdef RPMSG_DEBUG
18 #define RPMSG_ASSERT(_exp, _msg) do { \
19 if (!(_exp)) { \
20 openamp_print("FATAL: %s - _msg", __func__); \
21 while (1) { \
22 ; \
23 } \
24 } \
25 } while (0)
26 #else
27 #define RPMSG_ASSERT(_exp, _msg) do { \
28 if (!(_exp)) \
29 while (1) { \
30 ; \
31 } \
32 } while (0)
33 #endif
34
35 #define RPMSG_LOCATE_DATA(p) ((unsigned char *)(p) + sizeof(struct rpmsg_hdr))
36 /**
37 * enum rpmsg_ns_flags - dynamic name service announcement flags
38 *
39 * @RPMSG_NS_CREATE: a new remote service was just created
40 * @RPMSG_NS_DESTROY: a known remote service was just destroyed
41 * @RPMSG_NS_CREATE_WITH_ACK: a new remote service was just created waiting
42 * acknowledgment.
43 */
44 enum rpmsg_ns_flags {
45 RPMSG_NS_CREATE = 0,
46 RPMSG_NS_DESTROY = 1,
47 };
48
49 /**
50 * struct rpmsg_hdr - common header for all rpmsg messages
51 * @src: source address
52 * @dst: destination address
53 * @reserved: reserved for future use
54 * @len: length of payload (in bytes)
55 * @flags: message flags
56 *
57 * Every message sent(/received) on the rpmsg bus begins with this header.
58 */
59 OPENAMP_PACKED_BEGIN
60 struct rpmsg_hdr {
61 uint32_t src;
62 uint32_t dst;
63 uint32_t reserved;
64 uint16_t len;
65 uint16_t flags;
66 } OPENAMP_PACKED_END;
67
68 /**
69 * struct rpmsg_ns_msg - dynamic name service announcement message
70 * @name: name of remote service that is published
71 * @addr: address of remote service that is published
72 * @flags: indicates whether service is created or destroyed
73 *
74 * This message is sent across to publish a new service, or announce
75 * about its removal. When we receive these messages, an appropriate
76 * rpmsg channel (i.e device) is created/destroyed. In turn, the ->probe()
77 * or ->remove() handler of the appropriate rpmsg driver will be invoked
78 * (if/as-soon-as one is registered).
79 */
80 OPENAMP_PACKED_BEGIN
81 struct rpmsg_ns_msg {
82 char name[RPMSG_NAME_SIZE];
83 uint32_t addr;
84 uint32_t flags;
85 } OPENAMP_PACKED_END;
86
87 int rpmsg_send_ns_message(struct rpmsg_endpoint *ept, unsigned long flags);
88
89 struct rpmsg_endpoint *rpmsg_get_endpoint(struct rpmsg_device *rvdev,
90 const char *name, uint32_t addr,
91 uint32_t dest_addr);
92 int rpmsg_register_endpoint(struct rpmsg_device *rdev,
93 struct rpmsg_endpoint *ept);
94
95 static inline struct rpmsg_endpoint *
rpmsg_get_ept_from_addr(struct rpmsg_device * rdev,uint32_t addr)96 rpmsg_get_ept_from_addr(struct rpmsg_device *rdev, uint32_t addr)
97 {
98 return rpmsg_get_endpoint(rdev, NULL, addr, RPMSG_ADDR_ANY);
99 }
100
101 #if defined __cplusplus
102 }
103 #endif
104
105 #endif /* _RPMSG_INTERNAL_H_ */
106