]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - processor-sdk/open-amp.git/blob - lib/include/openamp/rpmsg_core.h
60d7fdb78c16051f7be49c447ce1a77788865375
[processor-sdk/open-amp.git] / lib / include / openamp / rpmsg_core.h
1 /*
2  * Copyright (c) 2014, Mentor Graphics Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * 1. Redistributions of source code must retain the above copyright notice,
9  *    this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright notice,
11  *    this list of conditions and the following disclaimer in the documentation
12  *    and/or other materials provided with the distribution.
13  * 3. Neither the name of Mentor Graphics Corporation nor the names of its
14  *    contributors may be used to endorse or promote products derived from this
15  *    software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
30 #ifndef _RPMSG_CORE_H_
31 #define _RPMSG_CORE_H_
33 #include "openamp/compiler.h"
34 #include "openamp/env.h"
35 #include "openamp/virtio.h"
36 #include "openamp/hil.h"
37 #include "openamp/sh_mem.h"
38 #include "openamp/llist.h"
39 #include "openamp/rpmsg.h"
41 /* Configurable parameters */
42 #define RPMSG_BUFFER_SIZE                       512
43 #define RPMSG_MAX_VQ_PER_RDEV                   2
44 #define RPMSG_NS_EPT_ADDR                       0x35
45 #define RPMSG_ADDR_BMP_SIZE                     4
47 /* Definitions for device types , null pointer, etc.*/
48 #define RPMSG_SUCCESS                           0
49 #define RPMSG_NULL                              (void *)0
50 #define RPMSG_REMOTE                            0
51 #define RPMSG_MASTER                            1
52 #define RPMSG_TRUE                              1
53 #define RPMSG_FALSE                             0
55 /* RPMSG channel states. */
56 #define RPMSG_CHNL_STATE_IDLE                   0
57 #define RPMSG_CHNL_STATE_NS                     1
58 #define RPMSG_CHNL_STATE_ACTIVE                 2
60 /* Remote processor/device states. */
61 #define RPMSG_DEV_STATE_IDLE                    0
62 #define RPMSG_DEV_STATE_ACTIVE                  1
64 /* Total tick count for 15secs - 1msec tick. */
65 #define RPMSG_TICK_COUNT                        15000
67 /* Time to wait - In multiple of 10 msecs. */
68 #define RPMSG_TICKS_PER_INTERVAL                10
70 /* Error macros. */
71 #define RPMSG_ERROR_BASE                        -2000
72 #define RPMSG_ERR_NO_MEM                        (RPMSG_ERROR_BASE - 1)
73 #define RPMSG_ERR_NO_BUFF                       (RPMSG_ERROR_BASE - 2)
74 #define RPMSG_ERR_MAX_VQ                        (RPMSG_ERROR_BASE - 3)
75 #define RPMSG_ERR_PARAM                         (RPMSG_ERROR_BASE - 4)
76 #define RPMSG_ERR_DEV_STATE                     (RPMSG_ERROR_BASE - 5)
77 #define RPMSG_ERR_BUFF_SIZE                     (RPMSG_ERROR_BASE - 6)
78 #define RPMSG_ERR_DEV_ID                        (RPMSG_ERROR_BASE - 7)
79 #define RPMSG_ERR_DEV_ADDR                      (RPMSG_ERROR_BASE - 8)
81 struct rpmsg_channel;
82 typedef void (*rpmsg_rx_cb_t) (struct rpmsg_channel *, void *, int, void *,
83                                unsigned long);
84 typedef void (*rpmsg_chnl_cb_t) (struct rpmsg_channel * rp_chl);
85 /**
86  * remote_device
87  *
88  * This structure is maintained by RPMSG driver to represent remote device/core.
89  *
90  * @virtd_dev           - virtio device for remote core
91  * @rvq                 - Rx virtqueue for virtio device
92  * @tvq                 - Tx virtqueue for virtio device
93  * @proc                - reference to remote processor
94  * @rp_channels         - rpmsg channels list for the device
95  * @rp_endpoints        - rpmsg endpoints list for the device
96  * @mem_pool            - shared memory pool
97  * @bitmap              - bitmap for channels addresses
98  * @channel_created     - create channel callback
99  * @channel_destroyed   - delete channel callback
100  * @default_cb          - default callback handler for RX data on channel
101  * @lock                - remote device mutex
102  * @role                - role of the remote device, RPMSG_MASTER/RPMSG_REMOTE
103  * @state               - remote device state, IDLE/ACTIVE
104  * @support_ns          - if device supports name service announcement
105  *
106  */
107 struct remote_device {
108         struct virtio_device virt_dev;
109         struct virtqueue *rvq;
110         struct virtqueue *tvq;
111         struct hil_proc *proc;
112         struct llist *rp_channels;
113         struct llist *rp_endpoints;
114         struct sh_mem_pool *mem_pool;
115         unsigned long bitmap[RPMSG_ADDR_BMP_SIZE];
116         rpmsg_chnl_cb_t channel_created;
117         rpmsg_chnl_cb_t channel_destroyed;
118         rpmsg_rx_cb_t default_cb;
119         LOCK *lock;
120         unsigned int role;
121         unsigned int state;
122         int support_ns;
123 };
125 /* Core functions */
126 int rpmsg_start_ipc(struct remote_device *rdev);
127 struct rpmsg_channel *_rpmsg_create_channel(struct remote_device *rdev,
128                                             char *name, unsigned long src,
129                                             unsigned long dst);
130 void _rpmsg_delete_channel(struct rpmsg_channel *rp_chnl);
131 struct rpmsg_endpoint *_create_endpoint(struct remote_device *rdev,
132                                         rpmsg_rx_cb_t cb, void *priv,
133                                         unsigned long addr);
134 void _destroy_endpoint(struct remote_device *rdev,
135                        struct rpmsg_endpoint *rp_ept);
136 void rpmsg_send_ns_message(struct remote_device *rdev,
137                            struct rpmsg_channel *rp_chnl, unsigned long flags);
138 int rpmsg_enqueue_buffer(struct remote_device *rdev, void *buffer,
139                          unsigned long len, unsigned short idx);
140 void rpmsg_return_buffer(struct remote_device *rdev, void *buffer,
141                          unsigned long len, unsigned short idx);
142 void *rpmsg_get_tx_buffer(struct remote_device *rdev, unsigned long *len,
143                           unsigned short *idx);
144 void rpmsg_free_buffer(struct remote_device *rdev, void *buffer);
145 void rpmsg_free_channel(struct rpmsg_channel *rp_chnl);
146 void *rpmsg_get_rx_buffer(struct remote_device *rdev, unsigned long *len,
147                           unsigned short *idx);
148 int rpmsg_get_address(unsigned long *bitmap, int size);
149 int rpmsg_release_address(unsigned long *bitmap, int size, int addr);
150 int rpmsg_is_address_set(unsigned long *bitmap, int size, int addr);
151 int rpmsg_set_address(unsigned long *bitmap, int size, int addr);
152 void rpmsg_ns_callback(struct rpmsg_channel *server_chnl,
153                        void *data, int len, void *priv, unsigned long src);
155 /* Remote device functions */
156 int rpmsg_rdev_init(struct remote_device **rdev, int dev_id, int role,
157                     rpmsg_chnl_cb_t channel_created,
158                     rpmsg_chnl_cb_t channel_destroyed,
159                     rpmsg_rx_cb_t default_cb);
160 void rpmsg_rdev_deinit(struct remote_device *rdev);
161 struct llist *rpmsg_rdev_get_chnl_node_from_id(struct remote_device *rdev,
162                                                char *rp_chnl_id);
163 struct llist *rpmsg_rdev_get_endpoint_from_addr(struct remote_device *rdev,
164                                                 unsigned long addr);
165 int rpmsg_rdev_notify(struct remote_device *rdev);
166 int rpmsg_rdev_create_virtqueues(struct virtio_device *dev, int flags, int nvqs,
167                                  const char *names[], vq_callback * callbacks[],
168                                  struct virtqueue *vqs[]);
169 unsigned char rpmsg_rdev_get_status(struct virtio_device *dev);
171 void rpmsg_rdev_set_status(struct virtio_device *dev, unsigned char status);
173 uint32_t rpmsg_rdev_get_feature(struct virtio_device *dev);
175 void rpmsg_rdev_set_feature(struct virtio_device *dev, uint32_t feature);
177 uint32_t rpmsg_rdev_negotiate_feature(struct virtio_device *dev,
178                                       uint32_t features);
179 /*
180  * Read/write a variable amount from the device specific (ie, network)
181  * configuration region. This region is encoded in the same endian as
182  * the guest.
183  */
184 void rpmsg_rdev_read_config(struct virtio_device *dev, uint32_t offset,
185                             void *dst, int length);
186 void rpmsg_rdev_write_config(struct virtio_device *dev, uint32_t offset,
187                              void *src, int length);
188 void rpmsg_rdev_reset(struct virtio_device *dev);
190 #endif                          /* _RPMSG_CORE_H_ */