drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c
Source file repositories/reference/linux-study-clean/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c- Extension
.c- Size
- 52882 bytes
- Lines
- 1950
- Domain
- Driver Families
- Bucket
- drivers/platform
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/errno.hlinux/kernel.hlinux/module.hlinux/mutex.hlinux/mm.hlinux/slab.hlinux/completion.hlinux/raspberrypi/vchiq.hlinux/vmalloc.hmedia/videobuf2-vmalloc.hlinux/raspberrypi/vchiq_arm.hmmal-common.hmmal-vchiq.hmmal-msg.h
Detected Declarations
struct vchiq_mmal_instancestruct mmal_msg_contextstruct vchiq_mmal_instancefunction get_msg_contextfunction lookup_msg_contextfunction release_msg_contextfunction event_to_host_cbfunction buffer_work_cbfunction vchiq_bulk_receivefunction bulk_receivefunction inline_receivefunction buffer_from_hostfunction buffer_to_host_cbfunction bulk_receive_cbfunction bulk_abort_cbfunction mmal_service_callbackfunction send_synchronous_mmal_msgfunction dump_port_infofunction port_to_mmal_msgfunction port_info_setfunction port_info_getfunction create_componentfunction destroy_componentfunction enable_componentfunction disable_componentfunction get_versionfunction port_action_portfunction port_action_handlefunction port_parameter_setfunction port_parameter_getfunction port_disablefunction list_for_each_safefunction port_enablefunction list_for_each_safefunction vchiq_mmal_port_set_formatfunction vchiq_mmal_port_parameter_setfunction vchiq_mmal_port_parameter_getfunction vchiq_mmal_port_enablefunction vchiq_mmal_port_disablefunction vchiq_mmal_port_connect_tunnelfunction vchiq_mmal_submit_bufferfunction mmal_vchi_buffer_initfunction mmal_vchi_buffer_cleanupfunction vchiq_mmal_component_initfunction vchiq_mmal_component_finalisefunction vchiq_mmal_component_enablefunction vchiq_mmal_component_disablefunction vchiq_mmal_version
Annotated Snippet
struct mmal_msg_context {
struct vchiq_mmal_instance *instance;
/* Index in the context_map idr so that we can find the
* mmal_msg_context again when servicing the VCHI reply.
*/
int handle;
union {
struct {
/* work struct for buffer_cb callback */
struct work_struct work;
/* work struct for deferred callback */
struct work_struct buffer_to_host_work;
/* mmal instance */
struct vchiq_mmal_instance *instance;
/* mmal port */
struct vchiq_mmal_port *port;
/* actual buffer used to store bulk reply */
struct mmal_buffer *buffer;
/* amount of buffer used */
unsigned long buffer_used;
/* MMAL buffer flags */
u32 mmal_flags;
/* Presentation and Decode timestamps */
s64 pts;
s64 dts;
int status; /* context status */
} bulk; /* bulk data */
struct {
/* message handle to release */
struct vchiq_header *msg_handle;
/* pointer to received message */
struct mmal_msg *msg;
/* received message length */
u32 msg_len;
/* completion upon reply */
struct completion cmplt;
} sync; /* synchronous response */
} u;
};
struct vchiq_mmal_instance {
unsigned int service_handle;
/* ensure serialised access to service */
struct mutex vchiq_mutex;
struct idr context_map;
/* protect accesses to context_map */
struct mutex context_map_lock;
struct vchiq_mmal_component component[VCHIQ_MMAL_MAX_COMPONENTS];
/* ordered workqueue to process all bulk operations */
struct workqueue_struct *bulk_wq;
/* handle for a vchiq instance */
struct vchiq_instance *vchiq_instance;
};
static struct mmal_msg_context *
get_msg_context(struct vchiq_mmal_instance *instance)
{
struct mmal_msg_context *msg_context;
int handle;
/* todo: should this be allocated from a pool to avoid kzalloc */
msg_context = kzalloc_obj(*msg_context);
if (!msg_context)
return ERR_PTR(-ENOMEM);
/* Create an ID that will be passed along with our message so
* that when we service the VCHI reply, we can look up what
* message is being replied to.
*/
mutex_lock(&instance->context_map_lock);
handle = idr_alloc(&instance->context_map, msg_context,
0, 0, GFP_KERNEL);
mutex_unlock(&instance->context_map_lock);
if (handle < 0) {
kfree(msg_context);
return ERR_PTR(handle);
}
Annotation
- Immediate include surface: `linux/errno.h`, `linux/kernel.h`, `linux/module.h`, `linux/mutex.h`, `linux/mm.h`, `linux/slab.h`, `linux/completion.h`, `linux/raspberrypi/vchiq.h`.
- Detected declarations: `struct vchiq_mmal_instance`, `struct mmal_msg_context`, `struct vchiq_mmal_instance`, `function get_msg_context`, `function lookup_msg_context`, `function release_msg_context`, `function event_to_host_cb`, `function buffer_work_cb`, `function vchiq_bulk_receive`, `function bulk_receive`.
- Atlas domain: Driver Families / drivers/platform.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.