1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
3 
4 #ifndef VCHIQ_H
5 #define VCHIQ_H
6 
7 #define VCHIQ_MAKE_FOURCC(x0, x1, x2, x3) \
8 			(((x0) << 24) | ((x1) << 16) | ((x2) << 8) | (x3))
9 
10 enum vchiq_reason {
11 	VCHIQ_SERVICE_OPENED,         /* service, -, -             */
12 	VCHIQ_SERVICE_CLOSED,         /* service, -, -             */
13 	VCHIQ_MESSAGE_AVAILABLE,      /* service, header, -        */
14 	VCHIQ_BULK_TRANSMIT_DONE,     /* service, -, bulk_userdata */
15 	VCHIQ_BULK_RECEIVE_DONE,      /* service, -, bulk_userdata */
16 	VCHIQ_BULK_TRANSMIT_ABORTED,  /* service, -, bulk_userdata */
17 	VCHIQ_BULK_RECEIVE_ABORTED    /* service, -, bulk_userdata */
18 };
19 
20 enum vchiq_status {
21 	VCHIQ_ERROR   = -1,
22 	VCHIQ_SUCCESS = 0,
23 	VCHIQ_RETRY   = 1
24 };
25 
26 enum vchiq_bulk_mode {
27 	VCHIQ_BULK_MODE_CALLBACK,
28 	VCHIQ_BULK_MODE_BLOCKING,
29 	VCHIQ_BULK_MODE_NOCALLBACK,
30 	VCHIQ_BULK_MODE_WAITING		/* Reserved for internal use */
31 };
32 
33 enum vchiq_service_option {
34 	VCHIQ_SERVICE_OPTION_AUTOCLOSE,
35 	VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
36 	VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
37 	VCHIQ_SERVICE_OPTION_SYNCHRONOUS,
38 	VCHIQ_SERVICE_OPTION_TRACE
39 };
40 
41 struct vchiq_header {
42 	/* The message identifier - opaque to applications. */
43 	int msgid;
44 
45 	/* Size of message data. */
46 	unsigned int size;
47 
48 	char data[];           /* message */
49 };
50 
51 struct vchiq_element {
52 	const void __user *data;
53 	unsigned int size;
54 };
55 
56 struct vchiq_service_base {
57 	int fourcc;
58 	enum vchiq_status (*callback)(enum vchiq_reason reason,
59 				      struct vchiq_header *header,
60 				      unsigned int handle,
61 				      void *bulk_userdata);
62 	void *userdata;
63 };
64 
65 struct vchiq_completion_data_kernel {
66 	enum vchiq_reason reason;
67 	struct vchiq_header *header;
68 	void *service_userdata;
69 	void *bulk_userdata;
70 };
71 
72 struct vchiq_service_params_kernel {
73 	int fourcc;
74 	enum vchiq_status (*callback)(enum vchiq_reason reason,
75 				      struct vchiq_header *header,
76 				      unsigned int handle,
77 				      void *bulk_userdata);
78 	void *userdata;
79 	short version;       /* Increment for non-trivial changes */
80 	short version_min;   /* Update for incompatible changes */
81 };
82 
83 struct vchiq_instance;
84 
85 extern enum vchiq_status vchiq_initialise(struct vchiq_instance **pinstance);
86 extern enum vchiq_status vchiq_shutdown(struct vchiq_instance *instance);
87 extern enum vchiq_status vchiq_connect(struct vchiq_instance *instance);
88 extern enum vchiq_status vchiq_open_service(struct vchiq_instance *instance,
89 	const struct vchiq_service_params_kernel *params,
90 	unsigned int *pservice);
91 extern enum vchiq_status vchiq_close_service(unsigned int service);
92 extern enum vchiq_status vchiq_use_service(unsigned int service);
93 extern enum vchiq_status vchiq_release_service(unsigned int service);
94 extern void vchiq_msg_queue_push(unsigned int handle, struct vchiq_header *header);
95 extern void           vchiq_release_message(unsigned int service,
96 	struct vchiq_header *header);
97 extern int vchiq_queue_kernel_message(unsigned int handle, void *data,
98 				      unsigned int size);
99 extern enum vchiq_status vchiq_bulk_transmit(unsigned int service,
100 	const void *data, unsigned int size, void *userdata,
101 	enum vchiq_bulk_mode mode);
102 extern enum vchiq_status vchiq_bulk_receive(unsigned int service,
103 	void *data, unsigned int size, void *userdata,
104 	enum vchiq_bulk_mode mode);
105 extern void *vchiq_get_service_userdata(unsigned int service);
106 extern enum vchiq_status vchiq_get_peer_version(unsigned int handle,
107 	short *peer_version);
108 extern struct vchiq_header *vchiq_msg_hold(unsigned int handle);
109 
110 #endif /* VCHIQ_H */
111