xref: /freebsd/sys/contrib/vchiq/interface/vchiq_arm/vchiq_if.h (revision b626f5a73a48f44a31a200291b141e1da408a2ff)
1262f27b2SOleksandr Tymoshenko /**
2262f27b2SOleksandr Tymoshenko  * Copyright (c) 2010-2012 Broadcom. All rights reserved.
3262f27b2SOleksandr Tymoshenko  *
4262f27b2SOleksandr Tymoshenko  * Redistribution and use in source and binary forms, with or without
5262f27b2SOleksandr Tymoshenko  * modification, are permitted provided that the following conditions
6262f27b2SOleksandr Tymoshenko  * are met:
7262f27b2SOleksandr Tymoshenko  * 1. Redistributions of source code must retain the above copyright
8262f27b2SOleksandr Tymoshenko  *    notice, this list of conditions, and the following disclaimer,
9262f27b2SOleksandr Tymoshenko  *    without modification.
10262f27b2SOleksandr Tymoshenko  * 2. Redistributions in binary form must reproduce the above copyright
11262f27b2SOleksandr Tymoshenko  *    notice, this list of conditions and the following disclaimer in the
12262f27b2SOleksandr Tymoshenko  *    documentation and/or other materials provided with the distribution.
13262f27b2SOleksandr Tymoshenko  * 3. The names of the above-listed copyright holders may not be used
14262f27b2SOleksandr Tymoshenko  *    to endorse or promote products derived from this software without
15262f27b2SOleksandr Tymoshenko  *    specific prior written permission.
16262f27b2SOleksandr Tymoshenko  *
17262f27b2SOleksandr Tymoshenko  * ALTERNATIVELY, this software may be distributed under the terms of the
18262f27b2SOleksandr Tymoshenko  * GNU General Public License ("GPL") version 2, as published by the Free
19262f27b2SOleksandr Tymoshenko  * Software Foundation.
20262f27b2SOleksandr Tymoshenko  *
21262f27b2SOleksandr Tymoshenko  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
22262f27b2SOleksandr Tymoshenko  * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
23262f27b2SOleksandr Tymoshenko  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24262f27b2SOleksandr Tymoshenko  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
25262f27b2SOleksandr Tymoshenko  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26262f27b2SOleksandr Tymoshenko  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27262f27b2SOleksandr Tymoshenko  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
28262f27b2SOleksandr Tymoshenko  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
29262f27b2SOleksandr Tymoshenko  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
30262f27b2SOleksandr Tymoshenko  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
31262f27b2SOleksandr Tymoshenko  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32262f27b2SOleksandr Tymoshenko  */
33262f27b2SOleksandr Tymoshenko 
34262f27b2SOleksandr Tymoshenko #ifndef VCHIQ_IF_H
35262f27b2SOleksandr Tymoshenko #define VCHIQ_IF_H
36262f27b2SOleksandr Tymoshenko 
37262f27b2SOleksandr Tymoshenko #include "interface/vchi/vchi_mh.h"
38262f27b2SOleksandr Tymoshenko 
39262f27b2SOleksandr Tymoshenko #define VCHIQ_SERVICE_HANDLE_INVALID 0
40262f27b2SOleksandr Tymoshenko 
41262f27b2SOleksandr Tymoshenko #define VCHIQ_SLOT_SIZE     4096
42262f27b2SOleksandr Tymoshenko #define VCHIQ_MAX_MSG_SIZE  (VCHIQ_SLOT_SIZE - sizeof(VCHIQ_HEADER_T))
43262f27b2SOleksandr Tymoshenko #define VCHIQ_CHANNEL_SIZE  VCHIQ_MAX_MSG_SIZE /* For backwards compatibility */
44262f27b2SOleksandr Tymoshenko 
45262f27b2SOleksandr Tymoshenko #define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
46262f27b2SOleksandr Tymoshenko 			(((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
47262f27b2SOleksandr Tymoshenko #define VCHIQ_GET_SERVICE_USERDATA(service) vchiq_get_service_userdata(service)
48262f27b2SOleksandr Tymoshenko #define VCHIQ_GET_SERVICE_FOURCC(service)   vchiq_get_service_fourcc(service)
49262f27b2SOleksandr Tymoshenko 
50262f27b2SOleksandr Tymoshenko typedef enum {
51262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPENED,         /* service, -, -             */
52262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_CLOSED,         /* service, -, -             */
53262f27b2SOleksandr Tymoshenko 	VCHIQ_MESSAGE_AVAILABLE,      /* service, header, -        */
54262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_TRANSMIT_DONE,     /* service, -, bulk_userdata */
55262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_RECEIVE_DONE,      /* service, -, bulk_userdata */
56262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_TRANSMIT_ABORTED,  /* service, -, bulk_userdata */
57262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_RECEIVE_ABORTED    /* service, -, bulk_userdata */
58262f27b2SOleksandr Tymoshenko } VCHIQ_REASON_T;
59262f27b2SOleksandr Tymoshenko 
60262f27b2SOleksandr Tymoshenko typedef enum {
61262f27b2SOleksandr Tymoshenko 	VCHIQ_ERROR   = -1,
62262f27b2SOleksandr Tymoshenko 	VCHIQ_SUCCESS = 0,
63262f27b2SOleksandr Tymoshenko 	VCHIQ_RETRY   = 1
64262f27b2SOleksandr Tymoshenko } VCHIQ_STATUS_T;
65262f27b2SOleksandr Tymoshenko 
66262f27b2SOleksandr Tymoshenko typedef enum {
67262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_MODE_CALLBACK,
68262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_MODE_BLOCKING,
69262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_MODE_NOCALLBACK,
70262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_MODE_WAITING		/* Reserved for internal use */
71262f27b2SOleksandr Tymoshenko } VCHIQ_BULK_MODE_T;
72262f27b2SOleksandr Tymoshenko 
73262f27b2SOleksandr Tymoshenko typedef enum {
74262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPTION_AUTOCLOSE,
75262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
76262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
77*a0b87461SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPTION_SYNCHRONOUS,
78*a0b87461SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPTION_TRACE
79262f27b2SOleksandr Tymoshenko } VCHIQ_SERVICE_OPTION_T;
80262f27b2SOleksandr Tymoshenko 
81262f27b2SOleksandr Tymoshenko typedef struct vchiq_header_struct {
82262f27b2SOleksandr Tymoshenko 	/* The message identifier - opaque to applications. */
83262f27b2SOleksandr Tymoshenko 	int msgid;
84262f27b2SOleksandr Tymoshenko 
85262f27b2SOleksandr Tymoshenko 	/* Size of message data. */
86262f27b2SOleksandr Tymoshenko 	unsigned int size;
87262f27b2SOleksandr Tymoshenko 
88262f27b2SOleksandr Tymoshenko 	char data[0];           /* message */
89262f27b2SOleksandr Tymoshenko } VCHIQ_HEADER_T;
90262f27b2SOleksandr Tymoshenko 
91262f27b2SOleksandr Tymoshenko typedef struct {
92262f27b2SOleksandr Tymoshenko 	const void *data;
93262f27b2SOleksandr Tymoshenko 	unsigned int size;
94262f27b2SOleksandr Tymoshenko } VCHIQ_ELEMENT_T;
95262f27b2SOleksandr Tymoshenko 
96262f27b2SOleksandr Tymoshenko typedef unsigned int VCHIQ_SERVICE_HANDLE_T;
97262f27b2SOleksandr Tymoshenko 
98262f27b2SOleksandr Tymoshenko typedef VCHIQ_STATUS_T (*VCHIQ_CALLBACK_T)(VCHIQ_REASON_T, VCHIQ_HEADER_T *,
99262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_HANDLE_T, void *);
100262f27b2SOleksandr Tymoshenko 
101262f27b2SOleksandr Tymoshenko typedef struct vchiq_service_base_struct {
102262f27b2SOleksandr Tymoshenko 	int fourcc;
103262f27b2SOleksandr Tymoshenko 	VCHIQ_CALLBACK_T callback;
104262f27b2SOleksandr Tymoshenko 	void *userdata;
105262f27b2SOleksandr Tymoshenko } VCHIQ_SERVICE_BASE_T;
106262f27b2SOleksandr Tymoshenko 
107262f27b2SOleksandr Tymoshenko typedef struct vchiq_service_params_struct {
108262f27b2SOleksandr Tymoshenko 	int fourcc;
109262f27b2SOleksandr Tymoshenko 	VCHIQ_CALLBACK_T callback;
110262f27b2SOleksandr Tymoshenko 	void *userdata;
111262f27b2SOleksandr Tymoshenko 	short version;       /* Increment for non-trivial changes */
112262f27b2SOleksandr Tymoshenko 	short version_min;   /* Update for incompatible changes */
113262f27b2SOleksandr Tymoshenko } VCHIQ_SERVICE_PARAMS_T;
114262f27b2SOleksandr Tymoshenko 
115262f27b2SOleksandr Tymoshenko typedef struct vchiq_config_struct {
116262f27b2SOleksandr Tymoshenko 	unsigned int max_msg_size;
117262f27b2SOleksandr Tymoshenko 	unsigned int bulk_threshold; /* The message size above which it
118262f27b2SOleksandr Tymoshenko 					is better to use a bulk transfer
119262f27b2SOleksandr Tymoshenko 					(<= max_msg_size) */
120262f27b2SOleksandr Tymoshenko 	unsigned int max_outstanding_bulks;
121262f27b2SOleksandr Tymoshenko 	unsigned int max_services;
122262f27b2SOleksandr Tymoshenko 	short version;      /* The version of VCHIQ */
123262f27b2SOleksandr Tymoshenko 	short version_min;  /* The minimum compatible version of VCHIQ */
124262f27b2SOleksandr Tymoshenko } VCHIQ_CONFIG_T;
125262f27b2SOleksandr Tymoshenko 
126262f27b2SOleksandr Tymoshenko typedef struct vchiq_instance_struct *VCHIQ_INSTANCE_T;
127262f27b2SOleksandr Tymoshenko typedef void (*VCHIQ_REMOTE_USE_CALLBACK_T)(void *cb_arg);
128262f27b2SOleksandr Tymoshenko 
129262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_initialise(VCHIQ_INSTANCE_T *pinstance);
130262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T instance);
131262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_connect(VCHIQ_INSTANCE_T instance);
132262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_add_service(VCHIQ_INSTANCE_T instance,
133262f27b2SOleksandr Tymoshenko 	const VCHIQ_SERVICE_PARAMS_T *params,
134262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_HANDLE_T *pservice);
135262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_open_service(VCHIQ_INSTANCE_T instance,
136262f27b2SOleksandr Tymoshenko 	const VCHIQ_SERVICE_PARAMS_T *params,
137262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_HANDLE_T *pservice);
138262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_close_service(VCHIQ_SERVICE_HANDLE_T service);
139262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_remove_service(VCHIQ_SERVICE_HANDLE_T service);
140262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_use_service(VCHIQ_SERVICE_HANDLE_T service);
141262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_use_service_no_resume(
142262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_HANDLE_T service);
143262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_release_service(VCHIQ_SERVICE_HANDLE_T service);
144262f27b2SOleksandr Tymoshenko 
145262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_queue_message(VCHIQ_SERVICE_HANDLE_T service,
146262f27b2SOleksandr Tymoshenko 	const VCHIQ_ELEMENT_T *elements, unsigned int count);
147262f27b2SOleksandr Tymoshenko extern void           vchiq_release_message(VCHIQ_SERVICE_HANDLE_T service,
148262f27b2SOleksandr Tymoshenko 	VCHIQ_HEADER_T *header);
149262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
150262f27b2SOleksandr Tymoshenko 	void *data, unsigned int size, void *userdata);
151262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_queue_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
152262f27b2SOleksandr Tymoshenko 	void *data, unsigned int size, void *userdata);
153262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_queue_bulk_transmit_handle(
154262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
155262f27b2SOleksandr Tymoshenko 	const void *offset, unsigned int size, void *userdata);
156262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_queue_bulk_receive_handle(
157262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_HANDLE_T service, VCHI_MEM_HANDLE_T handle,
158262f27b2SOleksandr Tymoshenko 	void *offset, unsigned int size, void *userdata);
159262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_bulk_transmit(VCHIQ_SERVICE_HANDLE_T service,
160262f27b2SOleksandr Tymoshenko 	void *data, unsigned int size, void *userdata,
161262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_MODE_T mode);
162262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_bulk_receive(VCHIQ_SERVICE_HANDLE_T service,
163262f27b2SOleksandr Tymoshenko 	void *data, unsigned int size, void *userdata,
164262f27b2SOleksandr Tymoshenko 	VCHIQ_BULK_MODE_T mode);
165262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_bulk_transmit_handle(VCHIQ_SERVICE_HANDLE_T service,
166262f27b2SOleksandr Tymoshenko 	VCHI_MEM_HANDLE_T handle, const void *offset, unsigned int size,
167262f27b2SOleksandr Tymoshenko 	void *userdata,	VCHIQ_BULK_MODE_T mode);
168262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_bulk_receive_handle(VCHIQ_SERVICE_HANDLE_T service,
169262f27b2SOleksandr Tymoshenko 	VCHI_MEM_HANDLE_T handle, void *offset, unsigned int size,
170262f27b2SOleksandr Tymoshenko 	void *userdata, VCHIQ_BULK_MODE_T mode);
171262f27b2SOleksandr Tymoshenko extern int   vchiq_get_client_id(VCHIQ_SERVICE_HANDLE_T service);
172262f27b2SOleksandr Tymoshenko extern void *vchiq_get_service_userdata(VCHIQ_SERVICE_HANDLE_T service);
173262f27b2SOleksandr Tymoshenko extern int   vchiq_get_service_fourcc(VCHIQ_SERVICE_HANDLE_T service);
174262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_get_config(VCHIQ_INSTANCE_T instance,
175262f27b2SOleksandr Tymoshenko 	int config_size, VCHIQ_CONFIG_T *pconfig);
176262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_set_service_option(VCHIQ_SERVICE_HANDLE_T service,
177262f27b2SOleksandr Tymoshenko 	VCHIQ_SERVICE_OPTION_T option, int value);
178262f27b2SOleksandr Tymoshenko 
179262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_remote_use(VCHIQ_INSTANCE_T instance,
180262f27b2SOleksandr Tymoshenko 	VCHIQ_REMOTE_USE_CALLBACK_T callback, void *cb_arg);
181262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_remote_release(VCHIQ_INSTANCE_T instance);
182262f27b2SOleksandr Tymoshenko 
183262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_dump_phys_mem(VCHIQ_SERVICE_HANDLE_T service,
184262f27b2SOleksandr Tymoshenko 	void *ptr, size_t num_bytes);
185262f27b2SOleksandr Tymoshenko 
186262f27b2SOleksandr Tymoshenko extern VCHIQ_STATUS_T vchiq_get_peer_version(VCHIQ_SERVICE_HANDLE_T handle,
187262f27b2SOleksandr Tymoshenko       short *peer_version);
188262f27b2SOleksandr Tymoshenko 
189262f27b2SOleksandr Tymoshenko #endif /* VCHIQ_IF_H */
190