1 /* 2 * Broadcom BM2835 V4L2 driver 3 * 4 * Copyright © 2013 Raspberry Pi (Trading) Ltd. 5 * 6 * This file is subject to the terms and conditions of the GNU General Public 7 * License. See the file COPYING in the main directory of this archive 8 * for more details. 9 * 10 * Authors: Vincent Sanders <vincent.sanders@collabora.co.uk> 11 * Dave Stevenson <dsteve@broadcom.com> 12 * Simon Mellor <simellor@broadcom.com> 13 * Luke Diamand <luked@broadcom.com> 14 */ 15 16 /* all the data structures which serialise the MMAL protocol. note 17 * these are directly mapped onto the recived message data. 18 * 19 * BEWARE: They seem to *assume* pointers are u32 and that there is no 20 * structure padding! 21 * 22 * NOTE: this implementation uses kernel types to ensure sizes. Rather 23 * than assigning values to enums to force their size the 24 * implementation uses fixed size types and not the enums (though the 25 * comments have the actual enum type 26 */ 27 28 #define VC_MMAL_VER 15 29 #define VC_MMAL_MIN_VER 10 30 #define VC_MMAL_SERVER_NAME MAKE_FOURCC("mmal") 31 32 /* max total message size is 512 bytes */ 33 #define MMAL_MSG_MAX_SIZE 512 34 /* with six 32bit header elements max payload is therefore 488 bytes */ 35 #define MMAL_MSG_MAX_PAYLOAD 488 36 37 #include "mmal-msg-common.h" 38 #include "mmal-msg-format.h" 39 #include "mmal-msg-port.h" 40 41 enum mmal_msg_type { 42 MMAL_MSG_TYPE_QUIT = 1, 43 MMAL_MSG_TYPE_SERVICE_CLOSED, 44 MMAL_MSG_TYPE_GET_VERSION, 45 MMAL_MSG_TYPE_COMPONENT_CREATE, 46 MMAL_MSG_TYPE_COMPONENT_DESTROY, /* 5 */ 47 MMAL_MSG_TYPE_COMPONENT_ENABLE, 48 MMAL_MSG_TYPE_COMPONENT_DISABLE, 49 MMAL_MSG_TYPE_PORT_INFO_GET, 50 MMAL_MSG_TYPE_PORT_INFO_SET, 51 MMAL_MSG_TYPE_PORT_ACTION, /* 10 */ 52 MMAL_MSG_TYPE_BUFFER_FROM_HOST, 53 MMAL_MSG_TYPE_BUFFER_TO_HOST, 54 MMAL_MSG_TYPE_GET_STATS, 55 MMAL_MSG_TYPE_PORT_PARAMETER_SET, 56 MMAL_MSG_TYPE_PORT_PARAMETER_GET, /* 15 */ 57 MMAL_MSG_TYPE_EVENT_TO_HOST, 58 MMAL_MSG_TYPE_GET_CORE_STATS_FOR_PORT, 59 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR, 60 MMAL_MSG_TYPE_CONSUME_MEM, 61 MMAL_MSG_TYPE_LMK, /* 20 */ 62 MMAL_MSG_TYPE_OPAQUE_ALLOCATOR_DESC, 63 MMAL_MSG_TYPE_DRM_GET_LHS32, 64 MMAL_MSG_TYPE_DRM_GET_TIME, 65 MMAL_MSG_TYPE_BUFFER_FROM_HOST_ZEROLEN, 66 MMAL_MSG_TYPE_PORT_FLUSH, /* 25 */ 67 MMAL_MSG_TYPE_HOST_LOG, 68 MMAL_MSG_TYPE_MSG_LAST 69 }; 70 71 /* port action request messages differ depending on the action type */ 72 enum mmal_msg_port_action_type { 73 MMAL_MSG_PORT_ACTION_TYPE_UNKNOWN = 0, /* Unkown action */ 74 MMAL_MSG_PORT_ACTION_TYPE_ENABLE, /* Enable a port */ 75 MMAL_MSG_PORT_ACTION_TYPE_DISABLE, /* Disable a port */ 76 MMAL_MSG_PORT_ACTION_TYPE_FLUSH, /* Flush a port */ 77 MMAL_MSG_PORT_ACTION_TYPE_CONNECT, /* Connect ports */ 78 MMAL_MSG_PORT_ACTION_TYPE_DISCONNECT, /* Disconnect ports */ 79 MMAL_MSG_PORT_ACTION_TYPE_SET_REQUIREMENTS, /* Set buffer requirements*/ 80 }; 81 82 struct mmal_msg_header { 83 u32 magic; 84 u32 type; /** enum mmal_msg_type */ 85 86 /* Opaque handle to the control service */ 87 u32 control_service; 88 89 u32 context; /** a u32 per message context */ 90 u32 status; /** The status of the vchiq operation */ 91 u32 padding; 92 }; 93 94 /* Send from VC to host to report version */ 95 struct mmal_msg_version { 96 u32 flags; 97 u32 major; 98 u32 minor; 99 u32 minimum; 100 }; 101 102 /* request to VC to create component */ 103 struct mmal_msg_component_create { 104 u32 client_component; /* component context */ 105 char name[128]; 106 u32 pid; /* For debug */ 107 }; 108 109 /* reply from VC to component creation request */ 110 struct mmal_msg_component_create_reply { 111 u32 status; /* enum mmal_msg_status - how does this differ to 112 * the one in the header? 113 */ 114 u32 component_handle; /* VideoCore handle for component */ 115 u32 input_num; /* Number of input ports */ 116 u32 output_num; /* Number of output ports */ 117 u32 clock_num; /* Number of clock ports */ 118 }; 119 120 /* request to VC to destroy a component */ 121 struct mmal_msg_component_destroy { 122 u32 component_handle; 123 }; 124 125 struct mmal_msg_component_destroy_reply { 126 u32 status; /** The component destruction status */ 127 }; 128 129 /* request and reply to VC to enable a component */ 130 struct mmal_msg_component_enable { 131 u32 component_handle; 132 }; 133 134 struct mmal_msg_component_enable_reply { 135 u32 status; /** The component enable status */ 136 }; 137 138 /* request and reply to VC to disable a component */ 139 struct mmal_msg_component_disable { 140 u32 component_handle; 141 }; 142 143 struct mmal_msg_component_disable_reply { 144 u32 status; /** The component disable status */ 145 }; 146 147 /* request to VC to get port information */ 148 struct mmal_msg_port_info_get { 149 u32 component_handle; /* component handle port is associated with */ 150 u32 port_type; /* enum mmal_msg_port_type */ 151 u32 index; /* port index to query */ 152 }; 153 154 /* reply from VC to get port info request */ 155 struct mmal_msg_port_info_get_reply { 156 u32 status; /** enum mmal_msg_status */ 157 u32 component_handle; /* component handle port is associated with */ 158 u32 port_type; /* enum mmal_msg_port_type */ 159 u32 port_index; /* port indexed in query */ 160 s32 found; /* unused */ 161 u32 port_handle; /**< Handle to use for this port */ 162 struct mmal_port port; 163 struct mmal_es_format format; /* elementary stream format */ 164 union mmal_es_specific_format es; /* es type specific data */ 165 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; /* es extra data */ 166 }; 167 168 /* request to VC to set port information */ 169 struct mmal_msg_port_info_set { 170 u32 component_handle; 171 u32 port_type; /* enum mmal_msg_port_type */ 172 u32 port_index; /* port indexed in query */ 173 struct mmal_port port; 174 struct mmal_es_format format; 175 union mmal_es_specific_format es; 176 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; 177 }; 178 179 /* reply from VC to port info set request */ 180 struct mmal_msg_port_info_set_reply { 181 u32 status; 182 u32 component_handle; /* component handle port is associated with */ 183 u32 port_type; /* enum mmal_msg_port_type */ 184 u32 index; /* port indexed in query */ 185 s32 found; /* unused */ 186 u32 port_handle; /**< Handle to use for this port */ 187 struct mmal_port port; 188 struct mmal_es_format format; 189 union mmal_es_specific_format es; 190 u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; 191 }; 192 193 /* port action requests that take a mmal_port as a parameter */ 194 struct mmal_msg_port_action_port { 195 u32 component_handle; 196 u32 port_handle; 197 u32 action; /* enum mmal_msg_port_action_type */ 198 struct mmal_port port; 199 }; 200 201 /* port action requests that take handles as a parameter */ 202 struct mmal_msg_port_action_handle { 203 u32 component_handle; 204 u32 port_handle; 205 u32 action; /* enum mmal_msg_port_action_type */ 206 u32 connect_component_handle; 207 u32 connect_port_handle; 208 }; 209 210 struct mmal_msg_port_action_reply { 211 u32 status; /** The port action operation status */ 212 }; 213 214 /* MMAL buffer transfer */ 215 216 /** Size of space reserved in a buffer message for short messages. */ 217 #define MMAL_VC_SHORT_DATA 128 218 219 /** Signals that the current payload is the end of the stream of data */ 220 #define MMAL_BUFFER_HEADER_FLAG_EOS (1<<0) 221 /** Signals that the start of the current payload starts a frame */ 222 #define MMAL_BUFFER_HEADER_FLAG_FRAME_START (1<<1) 223 /** Signals that the end of the current payload ends a frame */ 224 #define MMAL_BUFFER_HEADER_FLAG_FRAME_END (1<<2) 225 /** Signals that the current payload contains only complete frames (>1) */ 226 #define MMAL_BUFFER_HEADER_FLAG_FRAME \ 227 (MMAL_BUFFER_HEADER_FLAG_FRAME_START|MMAL_BUFFER_HEADER_FLAG_FRAME_END) 228 /** Signals that the current payload is a keyframe (i.e. self decodable) */ 229 #define MMAL_BUFFER_HEADER_FLAG_KEYFRAME (1<<3) 230 /** Signals a discontinuity in the stream of data (e.g. after a seek). 231 * Can be used for instance by a decoder to reset its state 232 */ 233 #define MMAL_BUFFER_HEADER_FLAG_DISCONTINUITY (1<<4) 234 /** Signals a buffer containing some kind of config data for the component 235 * (e.g. codec config data) 236 */ 237 #define MMAL_BUFFER_HEADER_FLAG_CONFIG (1<<5) 238 /** Signals an encrypted payload */ 239 #define MMAL_BUFFER_HEADER_FLAG_ENCRYPTED (1<<6) 240 /** Signals a buffer containing side information */ 241 #define MMAL_BUFFER_HEADER_FLAG_CODECSIDEINFO (1<<7) 242 /** Signals a buffer which is the snapshot/postview image from a stills 243 * capture 244 */ 245 #define MMAL_BUFFER_HEADER_FLAGS_SNAPSHOT (1<<8) 246 /** Signals a buffer which contains data known to be corrupted */ 247 #define MMAL_BUFFER_HEADER_FLAG_CORRUPTED (1<<9) 248 /** Signals that a buffer failed to be transmitted */ 249 #define MMAL_BUFFER_HEADER_FLAG_TRANSMISSION_FAILED (1<<10) 250 251 struct mmal_driver_buffer { 252 u32 magic; 253 u32 component_handle; 254 u32 port_handle; 255 u32 client_context; 256 }; 257 258 /* buffer header */ 259 struct mmal_buffer_header { 260 u32 next; /* next header */ 261 u32 priv; /* framework private data */ 262 u32 cmd; 263 u32 data; 264 u32 alloc_size; 265 u32 length; 266 u32 offset; 267 u32 flags; 268 s64 pts; 269 s64 dts; 270 u32 type; 271 u32 user_data; 272 }; 273 274 struct mmal_buffer_header_type_specific { 275 union { 276 struct { 277 u32 planes; 278 u32 offset[4]; 279 u32 pitch[4]; 280 u32 flags; 281 } video; 282 } u; 283 }; 284 285 struct mmal_msg_buffer_from_host { 286 /* The front 32 bytes of the buffer header are copied 287 * back to us in the reply to allow for context. This 288 * area is used to store two mmal_driver_buffer structures to 289 * allow for multiple concurrent service users. 290 */ 291 /* control data */ 292 struct mmal_driver_buffer drvbuf; 293 294 /* referenced control data for passthrough buffer management */ 295 struct mmal_driver_buffer drvbuf_ref; 296 struct mmal_buffer_header buffer_header; /* buffer header itself */ 297 struct mmal_buffer_header_type_specific buffer_header_type_specific; 298 s32 is_zero_copy; 299 s32 has_reference; 300 301 /** allows short data to be xfered in control message */ 302 u32 payload_in_message; 303 u8 short_data[MMAL_VC_SHORT_DATA]; 304 }; 305 306 /* port parameter setting */ 307 308 #define MMAL_WORKER_PORT_PARAMETER_SPACE 96 309 310 struct mmal_msg_port_parameter_set { 311 u32 component_handle; /* component */ 312 u32 port_handle; /* port */ 313 u32 id; /* Parameter ID */ 314 u32 size; /* Parameter size */ 315 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE]; 316 }; 317 318 struct mmal_msg_port_parameter_set_reply { 319 u32 status; /* enum mmal_msg_status todo: how does this 320 * differ to the one in the header? 321 */ 322 }; 323 324 /* port parameter getting */ 325 326 struct mmal_msg_port_parameter_get { 327 u32 component_handle; /* component */ 328 u32 port_handle; /* port */ 329 u32 id; /* Parameter ID */ 330 u32 size; /* Parameter size */ 331 }; 332 333 struct mmal_msg_port_parameter_get_reply { 334 u32 status; /* Status of mmal_port_parameter_get call */ 335 u32 id; /* Parameter ID */ 336 u32 size; /* Parameter size */ 337 uint32_t value[MMAL_WORKER_PORT_PARAMETER_SPACE]; 338 }; 339 340 /* event messages */ 341 #define MMAL_WORKER_EVENT_SPACE 256 342 343 struct mmal_msg_event_to_host { 344 u32 client_component; /* component context */ 345 346 u32 port_type; 347 u32 port_num; 348 349 u32 cmd; 350 u32 length; 351 u8 data[MMAL_WORKER_EVENT_SPACE]; 352 u32 delayed_buffer; 353 }; 354 355 /* all mmal messages are serialised through this structure */ 356 struct mmal_msg { 357 /* header */ 358 struct mmal_msg_header h; 359 /* payload */ 360 union { 361 struct mmal_msg_version version; 362 363 struct mmal_msg_component_create component_create; 364 struct mmal_msg_component_create_reply component_create_reply; 365 366 struct mmal_msg_component_destroy component_destroy; 367 struct mmal_msg_component_destroy_reply component_destroy_reply; 368 369 struct mmal_msg_component_enable component_enable; 370 struct mmal_msg_component_enable_reply component_enable_reply; 371 372 struct mmal_msg_component_disable component_disable; 373 struct mmal_msg_component_disable_reply component_disable_reply; 374 375 struct mmal_msg_port_info_get port_info_get; 376 struct mmal_msg_port_info_get_reply port_info_get_reply; 377 378 struct mmal_msg_port_info_set port_info_set; 379 struct mmal_msg_port_info_set_reply port_info_set_reply; 380 381 struct mmal_msg_port_action_port port_action_port; 382 struct mmal_msg_port_action_handle port_action_handle; 383 struct mmal_msg_port_action_reply port_action_reply; 384 385 struct mmal_msg_buffer_from_host buffer_from_host; 386 387 struct mmal_msg_port_parameter_set port_parameter_set; 388 struct mmal_msg_port_parameter_set_reply 389 port_parameter_set_reply; 390 struct mmal_msg_port_parameter_get 391 port_parameter_get; 392 struct mmal_msg_port_parameter_get_reply 393 port_parameter_get_reply; 394 395 struct mmal_msg_event_to_host event_to_host; 396 397 u8 payload[MMAL_MSG_MAX_PAYLOAD]; 398 } u; 399 }; 400