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