1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Broadcom BM2835 V4L2 driver 4 * 5 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 6 * 7 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 8 * Dave Stevenson <dsteve@broadcom.com> 9 * Simon Mellor <simellor@broadcom.com> 10 * Luke Diamand <luked@broadcom.com> 11 * 12 * MMAL interface to VCHIQ message passing 13 */ 14 15 #ifndef MMAL_VCHIQ_H 16 #define MMAL_VCHIQ_H 17 18 #include "mmal-msg-format.h" 19 20 #define MAX_PORT_COUNT 4 21 22 /* Maximum size of the format extradata. */ 23 #define MMAL_FORMAT_EXTRADATA_MAX_SIZE 128 24 25 struct vchiq_mmal_instance; 26 27 enum vchiq_mmal_es_type { 28 MMAL_ES_TYPE_UNKNOWN, /**< Unknown elementary stream type */ 29 MMAL_ES_TYPE_CONTROL, /**< Elementary stream of control commands */ 30 MMAL_ES_TYPE_AUDIO, /**< Audio elementary stream */ 31 MMAL_ES_TYPE_VIDEO, /**< Video elementary stream */ 32 MMAL_ES_TYPE_SUBPICTURE /**< Sub-picture elementary stream */ 33 }; 34 35 struct vchiq_mmal_port_buffer { 36 unsigned int num; /* number of buffers */ 37 u32 size; /* size of buffers */ 38 u32 alignment; /* alignment of buffers */ 39 }; 40 41 struct vchiq_mmal_port; 42 43 typedef void (*vchiq_mmal_buffer_cb)( 44 struct vchiq_mmal_instance *instance, 45 struct vchiq_mmal_port *port, 46 int status, struct mmal_buffer *buffer, 47 unsigned long length, u32 mmal_flags, s64 dts, s64 pts); 48 49 struct vchiq_mmal_port { 50 bool enabled; 51 u32 handle; 52 u32 type; /* port type, cached to use on port info set */ 53 u32 index; /* port index, cached to use on port info set */ 54 55 /* component port belongs to, allows simple deref */ 56 struct vchiq_mmal_component *component; 57 58 struct vchiq_mmal_port *connected; /* port conencted to */ 59 60 /* buffer info */ 61 struct vchiq_mmal_port_buffer minimum_buffer; 62 struct vchiq_mmal_port_buffer recommended_buffer; 63 struct vchiq_mmal_port_buffer current_buffer; 64 65 /* stream format */ 66 struct mmal_es_format_local format; 67 /* elementary stream format */ 68 union mmal_es_specific_format es; 69 70 /* data buffers to fill */ 71 struct list_head buffers; 72 /* lock to serialise adding and removing buffers from list */ 73 spinlock_t slock; 74 /* callback on buffer completion */ 75 vchiq_mmal_buffer_cb buffer_cb; 76 /* callback context */ 77 void *cb_ctx; 78 }; 79 80 struct vchiq_mmal_component { 81 bool enabled; 82 u32 handle; /* VideoCore handle for component */ 83 u32 inputs; /* Number of input ports */ 84 u32 outputs; /* Number of output ports */ 85 u32 clocks; /* Number of clock ports */ 86 struct vchiq_mmal_port control; /* control port */ 87 struct vchiq_mmal_port input[MAX_PORT_COUNT]; /* input ports */ 88 struct vchiq_mmal_port output[MAX_PORT_COUNT]; /* output ports */ 89 struct vchiq_mmal_port clock[MAX_PORT_COUNT]; /* clock ports */ 90 }; 91 92 int vchiq_mmal_init(struct vchiq_mmal_instance **out_instance); 93 int vchiq_mmal_finalise(struct vchiq_mmal_instance *instance); 94 95 /* Initialise a mmal component and its ports 96 * 97 */ 98 int vchiq_mmal_component_init( 99 struct vchiq_mmal_instance *instance, 100 const char *name, 101 struct vchiq_mmal_component **component_out); 102 103 int vchiq_mmal_component_finalise( 104 struct vchiq_mmal_instance *instance, 105 struct vchiq_mmal_component *component); 106 107 int vchiq_mmal_component_enable( 108 struct vchiq_mmal_instance *instance, 109 struct vchiq_mmal_component *component); 110 111 int vchiq_mmal_component_disable( 112 struct vchiq_mmal_instance *instance, 113 struct vchiq_mmal_component *component); 114 115 /* enable a mmal port 116 * 117 * enables a port and if a buffer callback provided enque buffer 118 * headers as appropriate for the port. 119 */ 120 int vchiq_mmal_port_enable( 121 struct vchiq_mmal_instance *instance, 122 struct vchiq_mmal_port *port, 123 vchiq_mmal_buffer_cb buffer_cb); 124 125 /* disable a port 126 * 127 * disable a port will dequeue any pending buffers 128 */ 129 int vchiq_mmal_port_disable(struct vchiq_mmal_instance *instance, 130 struct vchiq_mmal_port *port); 131 132 int vchiq_mmal_port_parameter_set(struct vchiq_mmal_instance *instance, 133 struct vchiq_mmal_port *port, 134 u32 parameter, 135 void *value, 136 u32 value_size); 137 138 int vchiq_mmal_port_parameter_get(struct vchiq_mmal_instance *instance, 139 struct vchiq_mmal_port *port, 140 u32 parameter, 141 void *value, 142 u32 *value_size); 143 144 int vchiq_mmal_port_set_format(struct vchiq_mmal_instance *instance, 145 struct vchiq_mmal_port *port); 146 147 int vchiq_mmal_port_connect_tunnel(struct vchiq_mmal_instance *instance, 148 struct vchiq_mmal_port *src, 149 struct vchiq_mmal_port *dst); 150 151 int vchiq_mmal_version(struct vchiq_mmal_instance *instance, 152 u32 *major_out, 153 u32 *minor_out); 154 155 int vchiq_mmal_submit_buffer(struct vchiq_mmal_instance *instance, 156 struct vchiq_mmal_port *port, 157 struct mmal_buffer *buf); 158 159 int mmal_vchi_buffer_init(struct vchiq_mmal_instance *instance, 160 struct mmal_buffer *buf); 161 int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf); 162 #endif /* MMAL_VCHIQ_H */ 163