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_bulk_mode {
21 	VCHIQ_BULK_MODE_CALLBACK,
22 	VCHIQ_BULK_MODE_BLOCKING,
23 	VCHIQ_BULK_MODE_NOCALLBACK,
24 	VCHIQ_BULK_MODE_WAITING		/* Reserved for internal use */
25 };
26 
27 enum vchiq_service_option {
28 	VCHIQ_SERVICE_OPTION_AUTOCLOSE,
29 	VCHIQ_SERVICE_OPTION_SLOT_QUOTA,
30 	VCHIQ_SERVICE_OPTION_MESSAGE_QUOTA,
31 	VCHIQ_SERVICE_OPTION_SYNCHRONOUS,
32 	VCHIQ_SERVICE_OPTION_TRACE
33 };
34 
35 struct vchiq_header {
36 	/* The message identifier - opaque to applications. */
37 	int msgid;
38 
39 	/* Size of message data. */
40 	unsigned int size;
41 
42 	char data[];           /* message */
43 };
44 
45 struct vchiq_element {
46 	const void __user *data;
47 	unsigned int size;
48 };
49 
50 struct vchiq_instance;
51 
52 struct vchiq_service_base {
53 	int fourcc;
54 	int (*callback)(struct vchiq_instance *instance,
55 			enum vchiq_reason reason,
56 			struct vchiq_header *header,
57 			unsigned int handle,
58 			void *bulk_userdata);
59 	void *userdata;
60 };
61 
62 struct vchiq_completion_data_kernel {
63 	enum vchiq_reason reason;
64 	struct vchiq_header *header;
65 	void *service_userdata;
66 	void *bulk_userdata;
67 };
68 
69 struct vchiq_service_params_kernel {
70 	int fourcc;
71 	int (*callback)(struct vchiq_instance *instance,
72 			enum vchiq_reason reason,
73 			struct vchiq_header *header,
74 			unsigned int handle,
75 			void *bulk_userdata);
76 	void *userdata;
77 	short version;       /* Increment for non-trivial changes */
78 	short version_min;   /* Update for incompatible changes */
79 };
80 
81 extern int vchiq_initialise(struct vchiq_instance **pinstance);
82 extern int vchiq_shutdown(struct vchiq_instance *instance);
83 extern int vchiq_connect(struct vchiq_instance *instance);
84 extern int vchiq_open_service(struct vchiq_instance *instance,
85 			      const struct vchiq_service_params_kernel *params,
86 			      unsigned int *pservice);
87 extern int vchiq_close_service(struct vchiq_instance *instance,
88 			       unsigned int service);
89 extern int vchiq_use_service(struct vchiq_instance *instance, unsigned int service);
90 extern int vchiq_release_service(struct vchiq_instance *instance,
91 				 unsigned int service);
92 extern void vchiq_msg_queue_push(struct vchiq_instance *instance, unsigned int handle,
93 				 struct vchiq_header *header);
94 extern void vchiq_release_message(struct vchiq_instance *instance, unsigned int service,
95 				  struct vchiq_header *header);
96 extern int vchiq_queue_kernel_message(struct vchiq_instance *instance, unsigned int handle,
97 				      void *data, unsigned int size);
98 extern int vchiq_bulk_transmit(struct vchiq_instance *instance, unsigned int service,
99 			       const void *data, unsigned int size, void *userdata,
100 			       enum vchiq_bulk_mode mode);
101 extern int vchiq_bulk_receive(struct vchiq_instance *instance, unsigned int service,
102 			      void *data, unsigned int size, void *userdata,
103 			      enum vchiq_bulk_mode mode);
104 extern void *vchiq_get_service_userdata(struct vchiq_instance *instance, unsigned int service);
105 extern int vchiq_get_peer_version(struct vchiq_instance *instance, unsigned int handle,
106 				  short *peer_version);
107 extern struct vchiq_header *vchiq_msg_hold(struct vchiq_instance *instance, unsigned int handle);
108 
109 #endif /* VCHIQ_H */
110