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.

Dependency Surface

Detected Declarations

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

Implementation Notes