1 | /* |
2 | Copyright (c) 2012, Broadcom Europe Ltd |
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 | * Redistributions of source code must retain the above copyright |
8 | notice, this list of conditions and the following disclaimer. |
9 | * Redistributions in binary form must reproduce the above copyright |
10 | notice, this list of conditions and the following disclaimer in the |
11 | documentation and/or other materials provided with the distribution. |
12 | * Neither the name of the copyright holder nor the |
13 | names of its contributors may be used to endorse or promote products |
14 | derived from this software without specific prior written permission. |
15 | |
16 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
17 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY |
20 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | */ |
27 | |
28 | #ifndef VCHIQ_IF_H |
29 | #define VCHIQ_IF_H |
30 | |
31 | #include "interface/vchi/vchi_mh.h" |
32 | |
33 | #ifdef __cplusplus |
34 | extern "C" { |
35 | #endif |
36 | |
37 | #define VCHIQ_SERVICE_HANDLE_INVALID 0 |
38 | |
39 | #define VCHIQ_SLOT_SIZE 4096 |
40 | #define VCHIQ_MAX_MSG_SIZE (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T)) |
41 | #define VCHIQ_CHANNEL_SIZE VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */ |
42 | |
43 | #define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) (((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3)) |
44 | #define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service) |
45 | #define VCHIQ_GET_SERVICE_FOURCC(service) vchiq_get_service_fourcc(service) |
46 | |
47 | typedef enum { |
48 | VCHIQ_SERVICE_OPENED, // service, -, - |
49 | VCHIQ_SERVICE_CLOSED, // service, -, - |
50 | VCHIQ_MESSAGE_AVAILABLE, // service, header, - |
51 | VCHIQ_BULK_TRANSMIT_DONE, // service, -, bulk_userdata |
52 | VCHIQ_BULK_RECEIVE_DONE, // service, -, bulk_userdata |
53 | VCHIQ_BULK_TRANSMIT_ABORTED, // service, -, bulk_userdata |
54 | VCHIQ_BULK_RECEIVE_ABORTED // service, -, bulk_userdata |
55 | } VCHIQ_REASON_T; |
56 | |
57 | typedef enum |
58 | { |
59 | VCHIQ_ERROR = -1, |
60 | VCHIQ_SUCCESS = 0, |
61 | VCHIQ_RETRY = 1 |
62 | } VCHIQ_STATUS_T; |
63 | |
64 | typedef enum |
65 | { |
66 | VCHIQ_BULK_MODE_CALLBACK, |
67 | VCHIQ_BULK_MODE_BLOCKING, |
68 | VCHIQ_BULK_MODE_NOCALLBACK |
69 | } VCHIQ_BULK_MODE_T; |
70 | |
71 | typedef enum |
72 | { |
73 | VCHIQ_SERVICE_OPTION_AUTOCLOSE, |
74 | VCHIQ_SERVICE_OPTION_SLOT_QUOTA, |
75 | VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA, |
76 | VCHIQ_SERVICE_OPTION_SYNCHRONOUS, |
77 | VCHIQ_SERVICE_OPTION_TRACE |
78 | } VCHIQ_SERVICE_OPTION_T; |
79 | |
80 | #ifdef __HIGHC__ |
81 | /* Allow zero-sized arrays without warnings */ |
82 | #pragma warning (push) |
83 | #pragma warning (disable : 4200) |
84 | #endif |
85 | |
86 | typedef struct { |
87 | /* The message identifier - opaque to applications. */ |
88 | int ; |
89 | |
90 | /* Size of message data. */ |
91 | unsigned int ; |
92 | |
93 | char [0]; /* message */ |
94 | } ; |
95 | |
96 | #ifdef __HIGHC__ |
97 | #pragma warning (pop) |
98 | #endif |
99 | |
100 | typedef struct { |
101 | const void *data; |
102 | int size; |
103 | } VCHIQ_ELEMENT_T; |
104 | |
105 | typedef unsigned int VCHIQ_SERVICE_HANDLE_T; |
106 | |
107 | typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *, |
108 | VCHIQ_SERVICE_HANDLE_T, void *); |
109 | |
110 | typedef struct vchiq_service_base_struct { |
111 | int fourcc; |
112 | VCHIQ_CALLBACK_T callback; |
113 | void *userdata; |
114 | } VCHIQ_SERVICE_BASE_T; |
115 | |
116 | typedef struct vchiq_service_params_struct { |
117 | int fourcc; |
118 | VCHIQ_CALLBACK_T callback; |
119 | void *userdata; |
120 | short version; /* Increment for non-trivial changes */ |
121 | short version_min; /* Update for incompatible changes */ |
122 | } VCHIQ_SERVICE_PARAMS_T; |
123 | |
124 | typedef struct vchiq_config_struct { |
125 | int max_msg_size; |
126 | int bulk_threshold; /* The message size aboce which it is better to use |
127 | a bulk transfer (<= max_msg_size) */ |
128 | int max_outstanding_bulks; |
129 | int max_services; |
130 | short version; /* The version of VCHIQ */ |
131 | short version_min; /* The minimum compatible version of VCHIQ */ |
132 | } VCHIQ_CONFIG_T; |
133 | |
134 | typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T; |
135 | typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void* cb_arg); |
136 | struct pagelist_struct; |
137 | |
138 | extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance); |
139 | extern VCHIQ_STATUS_T vchiq_initialise_fd(VCHIQ_INSTANCE_T *pinstance, int dev_vchiq_fd); |
140 | extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance); |
141 | extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance); |
142 | extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance, |
143 | const VCHIQ_SERVICE_PARAMS_T *params, |
144 | VCHIQ_SERVICE_HANDLE_T *pservice); |
145 | extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance, |
146 | const VCHIQ_SERVICE_PARAMS_T *params, |
147 | VCHIQ_SERVICE_HANDLE_T *pservice); |
148 | extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service); |
149 | extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service); |
150 | extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service); |
151 | extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service); |
152 | |
153 | extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service, |
154 | const VCHIQ_ELEMENT_T *elements, int count); |
155 | extern void vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service, |
156 | VCHIQ_HEADER_T *); |
157 | extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service, |
158 | const void *data, int size, void *userdata); |
159 | extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service, |
160 | void *data, int size, void *userdata); |
161 | extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle( |
162 | VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle, |
163 | const void *offset, int size, void *userdata); |
164 | extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle( |
165 | VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle, |
166 | void *offset, int size, void *userdata); |
167 | extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service, |
168 | const void *data, int size, void *userdata, VCHIQ_BULK_MODE_T mode); |
169 | extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service, |
170 | void *data, int size, void *userdata, VCHIQ_BULK_MODE_T mode); |
171 | extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service, |
172 | VCHI_MEM_HANDLE_T handle, const void *offset, int size, void *userdata, |
173 | VCHIQ_BULK_MODE_T mode); |
174 | extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service, |
175 | VCHI_MEM_HANDLE_T handle, void *offset, int size, void *userdata, |
176 | VCHIQ_BULK_MODE_T mode, |
177 | int copy_pagelist(char *vcptr, const struct pagelist_struct *pagelist)); |
178 | extern int vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service); |
179 | extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service); |
180 | extern int vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service); |
181 | extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance, |
182 | int config_size, VCHIQ_CONFIG_T *pconfig); |
183 | extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service, |
184 | VCHIQ_SERVICE_OPTION_T option, int value); |
185 | |
186 | extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance, |
187 | VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg); |
188 | extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance); |
189 | |
190 | extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service, |
191 | void *ptr, size_t num_bytes); |
192 | |
193 | extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle, |
194 | short *peer_version); |
195 | |
196 | #ifdef __cplusplus |
197 | } |
198 | #endif |
199 | |
200 | #endif /* VCHIQ_IF_H */ |
201 | |