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_instance;
57 
58 struct vchiq_service_base {
59 	int fourcc;
60 	enum vchiq_status (*callback)(struct vchiq_instance *instance,
61 				      enum vchiq_reason reason,
62 				      struct vchiq_header *header,
63 				      unsigned int handle,
64 				      void *bulk_userdata);
65 	void *userdata;
66 };
67 
68 struct vchiq_completion_data_kernel {
69 	enum vchiq_reason reason;
70 	struct vchiq_header *header;
71 	void *service_userdata;
72 	void *bulk_userdata;
73 };
74 
75 struct vchiq_service_params_kernel {
76 	int fourcc;
77 	enum vchiq_status (*callback)(struct vchiq_instance *instance,
78 				      enum vchiq_reason reason,
79 				      struct vchiq_header *header,
80 				      unsigned int handle,
81 				      void *bulk_userdata);
82 	void *userdata;
83 	short version;       /* Increment for non-trivial changes */
84 	short version_min;   /* Update for incompatible changes */
85 };
86 
87 struct vchiq_instance;
88 
89 extern int vchiq_initialise(struct vchiq_instance **pinstance);
90 extern enum vchiq_status vchiq_shutdown(struct vchiq_instance *instance);
91 extern enum vchiq_status vchiq_connect(struct vchiq_instance *instance);
92 extern enum vchiq_status vchiq_open_service(struct vchiq_instance *instance,
93 	const struct vchiq_service_params_kernel *params,
94 	unsigned int *pservice);
95 extern enum vchiq_status vchiq_close_service(struct vchiq_instance *instance,
96 					     unsigned int service);
97 extern enum vchiq_status vchiq_use_service(struct vchiq_instance *instance, unsigned int service);
98 extern enum vchiq_status vchiq_release_service(struct vchiq_instance *instance,
99 					       unsigned int service);
100 extern void vchiq_msg_queue_push(struct vchiq_instance *instance, unsigned int handle,
101 				 struct vchiq_header *header);
102 extern void vchiq_release_message(struct vchiq_instance *instance, unsigned int service,
103 				  struct vchiq_header *header);
104 extern int vchiq_queue_kernel_message(struct vchiq_instance *instance, unsigned int handle,
105 				      void *data, unsigned int size);
106 extern enum vchiq_status vchiq_bulk_transmit(struct vchiq_instance *instance, unsigned int service,
107 					     const void *data, unsigned int size, void *userdata,
108 					     enum vchiq_bulk_mode mode);
109 extern enum vchiq_status vchiq_bulk_receive(struct vchiq_instance *instance, unsigned int service,
110 					    void *data, unsigned int size, void *userdata,
111 					    enum vchiq_bulk_mode mode);
112 extern void *vchiq_get_service_userdata(struct vchiq_instance *instance, unsigned int service);
113 extern enum vchiq_status vchiq_get_peer_version(struct vchiq_instance *instance,
114 						unsigned int handle,
115 						short *peer_version);
116 extern struct vchiq_header *vchiq_msg_hold(struct vchiq_instance *instance, unsigned int handle);
117 
118 #endif /* VCHIQ_H */
119