From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 35C6430596A for ; Fri, 31 Oct 2025 17:28:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931700; cv=none; b=gn8z9li3gGL7SmDdSrjuD8a/qFPTGR32Yd0iMeD9YoL/QwNY3GAxoXE7yYPzotOl6UXRtxo2hlPKcDBvRnrWdikg5FdwcrEs2gKveiBg2AnJ1DdBQlzTJq5X+cpO72tS+duYm7TLX2gz+V807c5DQVH2PDFAxQN2zC4Wsj9cveY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931700; c=relaxed/simple; bh=l68kN9KWDjW9nSkNO372Wnz3xFDAD1FzVJFblm6+7pw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=JH3rUuK6LNucwZyj4K8f7vBwpjZKfDPz/HZXGJ8wn/AHkZmKAYKXENfHyII4fMzEo8IhmV+ef7lFlUAVLXwXgUVMUBO29Mmcynmb7j9Wvr59dKXWBibGx5gdKWVUg0KRCMqLgAyfn/HifrxYMQUyY5DG3dGOqm+mdvsAI6PQ3Go= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=D4wBnh8r; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="D4wBnh8r" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B1EEE3A2; Fri, 31 Oct 2025 18:26:20 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931581; bh=l68kN9KWDjW9nSkNO372Wnz3xFDAD1FzVJFblm6+7pw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=D4wBnh8rAxcgn6ryZtItSuDdg0e5rsCnnj/+oPNrGcrn//aEZDkkAIy68TONrfQEe rZT3vAh+HADcrdY2EjHUfZbKTvWnCneR9yE0yz9ZHZdIn7etKg8doWy+Ub8Dja+tf2 dASRZNY3iIaJmmbdJskuYPdZwKc/VC4cRb9psxb4= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:21 +0530 Subject: [PATCH 01/13] platform/raspberrypi: vchiq-mmal: Avoid use of bool in structures Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-1-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=966; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=dAC4ccqqIuDds5cBVf3x31HLujLoig4utiWVx2tzBPM=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGUV8VJlXk1bMRIIzM6TX/TQUmI37R6cD456 M1HZLx4+t+JAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxlAAKCRBD3pH5JJpx RazcD/93LmOyrHw43/Q7OPUE0Eecq95o/vz5Tnmsdd7jFhUYmzxOzJcEhDnhpIYCnL1HiXPfW7a eAe8FFZ4SwSdgV1uBHEUf2fEc2H7V++r0bgUOwFhWDHVjUrfE0d6Xj45PP85YuzR/dDSaFfnpCv X1Rdq0yKdtekoXHbUd10HL6vhKKFysPD+B7INA/L+85sn5U7qvL10WnLHc1r2aE9Lsancwv8nCS G0LwKQPoX+nbfh2vzgaCEbll6Pjce5JWaDNzk32niWGsXb4mDIhRRRqtnDjjfQRmdG+cZFJP87L 6e/MM2KkWpPwLLIzdg/fzvR+P+BPF+fEzMJrjEDzuCkrGh49Cx3C0bR/9NJH0WtqG/0Av1w8MdW LlAhMGzKbXSi+vMfIoGy8mEWhTR6uWuoc6Pk8cyj60FldXR76NDWkKbVfyni0saF2KrOGNUdt4k YuGeHH9QcQLG6Yp0ts/b+EBXxr3d982eMcExwpDTY1exYW/Ek89iUR3MHa6FLDw8YXEeg/Xo95Q sBbcOsOdu4lp3+XTERyEaMMJkhVY/Q/T49Fp9nqXIrS7htS7cKGfOYW6Gq6SHOx7F0PcoKHzrpJ 1xK3How1d4qETh4Xd12bo5/4ixuY+n9IT3hDtMNBcbcpfNeUgaGLxAmrn1bPLWXY5Ei04Gfw2pK NlI5jhi/1TaoAgQ== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson Fixes up a checkpatch error "Avoid using bool structure members because of possible alignment issues". Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index cd073ed3ea2dd9c45b137f1a32e236e520b7b320..82c2c261fd9cf0669cbd2ca7c81= 4e0703317885a 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -1776,7 +1776,7 @@ int vchiq_mmal_component_enable(struct vchiq_mmal_ins= tance *instance, =20 ret =3D enable_component(instance, component); if (ret =3D=3D 0) - component->enabled =3D true; + component->enabled =3D 1; =20 mutex_unlock(&instance->vchiq_mutex); =20 --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0D9023233FA for ; Fri, 31 Oct 2025 17:28:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931702; cv=none; b=hNqrQpR1BpBxuLAt32mB33ZZ1zfdqarDRZGH1c5Bs/XbFdFfiaiH8gIdr1oV3fm7WhjlgA7PkfgnDg/ba9UYTGwcZ5lTn5IjvbqgZXi+TlutrA7SN/CjNn0f0tlefohXheeyqwe/Hx7RYqfY8JZrsT/c8YkvDEl+nqKK00sPJ14= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931702; c=relaxed/simple; bh=Y7nThyvwqpce8nW9iJ0THyTWhnt4FWq/t8yCxViAL2Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BKF///q6QnPZlmEViyVpXB0IaciWH39Ft1MYlIhjsnXUFpcrkyNCcX5yAO+k2lDLDG/jfNZcCZ8FsghaR0ZOzCg6kFpfwQoruAEpA+i/gl34tqSRWRc6TRp8BnirhJmzhwRFdtDA3iVdwHIHjuw8htAuaMxTMgTatPZ1oWJF2e8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=cHxdNjpc; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cHxdNjpc" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6D915446; Fri, 31 Oct 2025 18:26:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931586; bh=Y7nThyvwqpce8nW9iJ0THyTWhnt4FWq/t8yCxViAL2Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=cHxdNjpc+48gBksiqEin9x35j6nCW5JFYXTC+drP23ScYn3cRkJv/+yEZFjzditE6 jvl2lERrRAYaVjqEKqXF8ERhh3TNeLMbQ4ePc6l9wsxy/ZcNZDnMR1LWW3u3Suy5MS EAtrjHbs1xFV/eRujpjEocRGOYp+gSVLfr57TKHs= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:22 +0530 Subject: [PATCH 02/13] platform/raspberrypi: vchiq-mmal: Add support for event callbacks. Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-2-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=13198; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=HV7eDw2RJNoFQ/vfTNfIFTlG5/z3KZrEQLJcrzl3JN4=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGV9RRdyPVpR1rSPOcSsc8358HTjW4XoxmjR qv2iGr+wQiJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxlQAKCRBD3pH5JJpx RdDUEACBpm9+lpq2UhTPKAseXCk9mc8L4A4k+6B2mhdG9TIghaH3hWatp6kU+FatqTBJi4DQWyF 1LK/2eCq0Lrm/u5yzvwYEklPDpJ1fpnAGz2Gfvrctupmi7wXZktce40R3WhkSpCTbc+VzFoNqK/ fG+ZoNUdZfxhuft/S6DXHWC8TYWwAQec6v1Kf9xAHJ8eZsSd5eBoRrbpJSjaiNQhFpG/f2SJQZR 4O3drUgK5pe7vH+FKtEYfz1+nrDoXlFrxKp3/obQ+xegSqvAZ7q+zAX/Tgw0w9AGMp3ftgAvM9C gGz+90AcfJI3eXsu57No5AH+NimrpFinL+wyDaXah7tHxTM9eu9iGejtZN0Md4KE9x9fp6q9VMD ghwWljbdPcTpf/Rrnoq6ATFceHzHHwQQkXX57sMEKebRY0tzsPoeOs73WeBVCqa1r7hkWmvX3Wc yh0Zc79vp3I+i20cYT5em18vkJYYDEpzJdz2DN+ZAwLWrLTtHDxquZJm+cF9EqRS805fbN0OYCD zgGUQyAbUepK04hVXlZBOeh1MKDR4Qu43MS3OyTdlV8LmMwU4/JOOoBQhMPybxjMMYcKoFrsEGV 6ac8AfvjGCscZPpFRDdEsgVwTG2M+Q1gehB67ISTtu0Buoir7WukbNJ2NGgadIda5Illh9wyBah lSrITtGAlXAsuWQ== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson The codec uses the event mechanism to report things such as resolution changes. It is signalled by the cmd field of the buffer being non-zero. Add support for passing this information out to the client. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h | 1 + drivers/platform/raspberrypi/vchiq-mmal/mmal-msg.h | 35 ++++++++++++++= +++++++++++ drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 170 ++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++---------- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h | 4 +++ 4 files changed, 196 insertions(+), 14 deletions(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h b/driver= s/platform/raspberrypi/vchiq-mmal/mmal-common.h index b33129403a30347fe762d0377cacbda77434c211..0443be8198ea57fcd66d598ef7a= 46309d82ec7b7 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h @@ -50,6 +50,7 @@ struct mmal_buffer { =20 struct mmal_msg_context *msg_context; =20 + u32 cmd; /* MMAL command. 0=3Ddata. */ unsigned long length; u32 mmal_flags; s64 dts; diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg.h b/drivers/p= latform/raspberrypi/vchiq-mmal/mmal-msg.h index 1889494425eb65e4e2212e0806084a56087dc61d..7cccd5ee9a9e707b26dada6a950= 6d6a4145de32f 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg.h @@ -346,6 +346,41 @@ struct mmal_msg_port_parameter_get_reply { /* event messages */ #define MMAL_WORKER_EVENT_SPACE 256 =20 +/* Four CC's for events */ +#define MMAL_FOURCC(a, b, c, d) ((a) | (b << 8) | (c << 16) | (d << 24)) + +#define MMAL_EVENT_ERROR MMAL_FOURCC('E', 'R', 'R', 'O') +#define MMAL_EVENT_EOS MMAL_FOURCC('E', 'E', 'O', 'S') +#define MMAL_EVENT_FORMAT_CHANGED MMAL_FOURCC('E', 'F', 'C', 'H') +#define MMAL_EVENT_PARAMETER_CHANGED MMAL_FOURCC('E', 'P', 'C', 'H') + +/* Structs for each of the event message payloads */ +struct mmal_msg_event_eos { + u32 port_type; /**< Type of port that received the end of stream */ + u32 port_index; /**< Index of port that received the end of stream */ +}; + +/** Format changed event data. */ +struct mmal_msg_event_format_changed { + /* Minimum size of buffers the port requires */ + u32 buffer_size_min; + /* Minimum number of buffers the port requires */ + u32 buffer_num_min; + /* Size of buffers the port recommends for optimal performance. + * A value of zero means no special recommendation. + */ + u32 buffer_size_recommended; + /* Number of buffers the port recommends for optimal + * performance. A value of zero means no special recommendation. + */ + u32 buffer_num_recommended; + + u32 es_ptr; + struct mmal_es_format format; + union mmal_es_specific_format es; + u8 extradata[MMAL_FORMAT_EXTRADATA_MAX_SIZE]; +}; + struct mmal_msg_event_to_host { u32 client_component; /* component context */ =20 diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index 82c2c261fd9cf0669cbd2ca7c814e0703317885a..a115a391908da06e101e159905a= 4403b91e051c6 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -145,6 +145,8 @@ struct mmal_msg_context { /* Presentation and Decode timestamps */ s64 pts; s64 dts; + /* MMAL buffer command flag */ + u32 cmd; =20 int status; /* context status */ =20 @@ -232,18 +234,6 @@ release_msg_context(struct mmal_msg_context *msg_conte= xt) kfree(msg_context); } =20 -/* deals with receipt of event to host message */ -static void event_to_host_cb(struct vchiq_mmal_instance *instance, - struct mmal_msg *msg, u32 msg_len) -{ - pr_debug("unhandled event\n"); - pr_debug("component:%u port type:%d num:%d cmd:0x%x length:%d\n", - msg->u.event_to_host.client_component, - msg->u.event_to_host.port_type, - msg->u.event_to_host.port_num, - msg->u.event_to_host.cmd, msg->u.event_to_host.length); -} - /* workqueue scheduled callback * * we do this because it is important we do not call any other vchiq @@ -265,13 +255,18 @@ static void buffer_work_cb(struct work_struct *work) buffer->mmal_flags =3D msg_context->u.bulk.mmal_flags; buffer->dts =3D msg_context->u.bulk.dts; buffer->pts =3D msg_context->u.bulk.pts; + buffer->cmd =3D msg_context->u.bulk.cmd; =20 - atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu); + if (!buffer->cmd) + atomic_dec(&msg_context->u.bulk.port->buffers_with_vpu); =20 msg_context->u.bulk.port->buffer_cb(msg_context->u.bulk.instance, msg_context->u.bulk.port, msg_context->u.bulk.status, msg_context->u.bulk.buffer); + + if (buffer->cmd) + mutex_unlock(&msg_context->u.bulk.port->event_context_mutex); } =20 /* workqueue scheduled callback to handle receiving buffers @@ -349,6 +344,7 @@ static int bulk_receive(struct vchiq_mmal_instance *ins= tance, msg_context->u.bulk.buffer_used =3D rd_len; msg_context->u.bulk.dts =3D msg->u.buffer_from_host.buffer_header.dts; msg_context->u.bulk.pts =3D msg->u.buffer_from_host.buffer_header.pts; + msg_context->u.bulk.cmd =3D msg->u.buffer_from_host.buffer_header.cmd; =20 queue_work(msg_context->instance->bulk_wq, &msg_context->u.bulk.buffer_to_host_work); @@ -451,6 +447,103 @@ buffer_from_host(struct vchiq_mmal_instance *instance, return ret; } =20 +/* deals with receipt of event to host message */ +static void event_to_host_cb(struct vchiq_mmal_instance *instance, + struct mmal_msg *msg, u32 msg_len) +{ + /* FIXME: Not going to work on 64 bit */ + struct vchiq_mmal_component *component =3D + (struct vchiq_mmal_component *)msg->u.event_to_host.client_component; + struct vchiq_mmal_port *port =3D NULL; + struct mmal_msg_context *msg_context; + u32 port_num =3D msg->u.event_to_host.port_num; + + if (msg->u.buffer_from_host.drvbuf.magic =3D=3D MMAL_MAGIC) { + pr_err("%s: MMAL_MSG_TYPE_BUFFER_TO_HOST with bad magic\n", + __func__); + return; + } + + switch (msg->u.event_to_host.port_type) { + case MMAL_PORT_TYPE_CONTROL: + if (port_num) { + pr_err("%s: port_num of %u >=3D number of ports 1", + __func__, port_num); + return; + } + port =3D &component->control; + break; + case MMAL_PORT_TYPE_INPUT: + if (port_num >=3D component->inputs) { + pr_err("%s: port_num of %u >=3D number of ports %u", + __func__, port_num, + port_num >=3D component->inputs); + return; + } + port =3D &component->input[port_num]; + break; + case MMAL_PORT_TYPE_OUTPUT: + if (port_num >=3D component->outputs) { + pr_err("%s: port_num of %u >=3D number of ports %u", + __func__, port_num, + port_num >=3D component->outputs); + return; + } + port =3D &component->output[port_num]; + break; + case MMAL_PORT_TYPE_CLOCK: + if (port_num >=3D component->clocks) { + pr_err("%s: port_num of %u >=3D number of ports %u", + __func__, port_num, + port_num >=3D component->clocks); + return; + } + port =3D &component->clock[port_num]; + break; + default: + break; + } + + if (!mutex_trylock(&port->event_context_mutex)) { + pr_err("dropping event 0x%x\n", msg->u.event_to_host.cmd); + return; + } + msg_context =3D port->event_context; + + if (msg->h.status !=3D MMAL_MSG_STATUS_SUCCESS) { + /* message reception had an error */ + //pr_warn + pr_err("%s: error %d in reply\n", __func__, msg->h.status); + + msg_context->u.bulk.status =3D msg->h.status; + } else if (msg->u.event_to_host.length > MMAL_WORKER_EVENT_SPACE) { + /* data is not in message, queue a bulk receive */ + pr_err("%s: payload not in message - bulk receive??! NOT SUPPORTED\n", + __func__); + msg_context->u.bulk.status =3D -1; + } else { + memcpy(msg_context->u.bulk.buffer->buffer, + msg->u.event_to_host.data, + msg->u.event_to_host.length); + + msg_context->u.bulk.buffer_used =3D + msg->u.event_to_host.length; + + msg_context->u.bulk.mmal_flags =3D 0; + msg_context->u.bulk.dts =3D MMAL_TIME_UNKNOWN; + msg_context->u.bulk.pts =3D MMAL_TIME_UNKNOWN; + msg_context->u.bulk.cmd =3D msg->u.event_to_host.cmd; + + pr_debug("event component:%u port type:%d num:%d cmd:0x%x length:%d\n", + msg->u.event_to_host.client_component, + msg->u.event_to_host.port_type, + msg->u.event_to_host.port_num, + msg->u.event_to_host.cmd, msg->u.event_to_host.length); + } + + schedule_work(&msg_context->u.bulk.work); +} + /* deals with receipt of buffer to host message */ static void buffer_to_host_cb(struct vchiq_mmal_instance *instance, struct mmal_msg *msg, u32 msg_len) @@ -1333,6 +1426,7 @@ static int port_disable(struct vchiq_mmal_instance *i= nstance, mmalbuf->mmal_flags =3D 0; mmalbuf->dts =3D MMAL_TIME_UNKNOWN; mmalbuf->pts =3D MMAL_TIME_UNKNOWN; + mmalbuf->cmd =3D 0; port->buffer_cb(instance, port, 0, mmalbuf); } @@ -1634,6 +1728,43 @@ int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf) } EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup); =20 +static void init_event_context(struct vchiq_mmal_instance *instance, + struct vchiq_mmal_port *port) +{ + struct mmal_msg_context *ctx =3D get_msg_context(instance); + + mutex_init(&port->event_context_mutex); + + port->event_context =3D ctx; + ctx->u.bulk.instance =3D instance; + ctx->u.bulk.port =3D port; + ctx->u.bulk.buffer =3D + kzalloc(sizeof(*ctx->u.bulk.buffer), GFP_KERNEL); + if (!ctx->u.bulk.buffer) + goto release_msg_context; + ctx->u.bulk.buffer->buffer =3D kzalloc(MMAL_WORKER_EVENT_SPACE, + GFP_KERNEL); + if (!ctx->u.bulk.buffer->buffer) + goto release_buffer; + + INIT_WORK(&ctx->u.bulk.work, buffer_work_cb); + return; + +release_buffer: + kfree(ctx->u.bulk.buffer); +release_msg_context: + release_msg_context(ctx); +} + +static void free_event_context(struct vchiq_mmal_port *port) +{ + struct mmal_msg_context *ctx =3D port->event_context; + + kfree(ctx->u.bulk.buffer->buffer); + kfree(ctx->u.bulk.buffer); + release_msg_context(ctx); +} + /* Initialise a mmal component and its ports * */ @@ -1683,6 +1814,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_insta= nce *instance, ret =3D port_info_get(instance, &component->control); if (ret < 0) goto release_component; + init_event_context(instance, &component->control); =20 for (idx =3D 0; idx < component->inputs; idx++) { component->input[idx].type =3D MMAL_PORT_TYPE_INPUT; @@ -1693,6 +1825,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_insta= nce *instance, ret =3D port_info_get(instance, &component->input[idx]); if (ret < 0) goto release_component; + init_event_context(instance, &component->input[idx]); } =20 for (idx =3D 0; idx < component->outputs; idx++) { @@ -1704,6 +1837,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_insta= nce *instance, ret =3D port_info_get(instance, &component->output[idx]); if (ret < 0) goto release_component; + init_event_context(instance, &component->output[idx]); } =20 for (idx =3D 0; idx < component->clocks; idx++) { @@ -1715,6 +1849,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_insta= nce *instance, ret =3D port_info_get(instance, &component->clock[idx]); if (ret < 0) goto release_component; + init_event_context(instance, &component->clock[idx]); } =20 *component_out =3D component; @@ -1740,7 +1875,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init); int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance, struct vchiq_mmal_component *component) { - int ret; + int ret, idx; =20 if (mutex_lock_interruptible(&instance->vchiq_mutex)) return -EINTR; @@ -1752,6 +1887,13 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_= instance *instance, =20 component->in_use =3D false; =20 + for (idx =3D 0; idx < component->inputs; idx++) + free_event_context(&component->input[idx]); + for (idx =3D 0; idx < component->outputs; idx++) + free_event_context(&component->output[idx]); + for (idx =3D 0; idx < component->clocks; idx++) + free_event_context(&component->clock[idx]); + mutex_unlock(&instance->vchiq_mutex); =20 return ret; diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.h index 8c3959f6f97fb21bcaf2f21589ef291e754e7c19..190a0f42bd6b22c7493463da94c= 094265d85d8fa 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h @@ -79,6 +79,10 @@ struct vchiq_mmal_port { vchiq_mmal_buffer_cb buffer_cb; /* callback context */ void *cb_ctx; + + /* ensure serialised use of the one event context structure */ + struct mutex event_context_mutex; + struct mmal_msg_context *event_context; }; =20 struct vchiq_mmal_component { --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 66D6E34D4E9 for ; Fri, 31 Oct 2025 17:28:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931706; cv=none; b=oeF5PEN42RDpYmPo2QuOr7nYlTbXyup98UMuZ+V4B6ixDGTsClh2+GdaeWDz+NWgtrWaxjLgVDBBU7ocuoBWHcVQv+KbEzbjHRkAZhSzrq0HksgBL6l6HNBu4mqtP73fccAXj9B0lrjOjoiA4vA2QHrX1SWEqqO3F9JyjmzS7wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931706; c=relaxed/simple; bh=533NYx92g40jb1ADfvwqEdHJ9gcFkilXSs69QufQenU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=eJ1bapGNE8mCWMea5ElCHuD1GwE3p5w27xoCgHSRA6bjDENkBWwU3YOtNJbu2T35poOThwmrnexyv8Kw5bwshYzej6GsC+jN8nDrSAxS7d8bZyB4Vaw6ygnKpYWElplWz1Lc9N+IiDk+FUHyGU1m1EFqa4NRhm+Q5w0T+Sa0QHE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=o9te/yYP; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="o9te/yYP" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 1A325B5; Fri, 31 Oct 2025 18:26:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931592; bh=533NYx92g40jb1ADfvwqEdHJ9gcFkilXSs69QufQenU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=o9te/yYPtmNzGapb++L7vSxLJEaVhKTyq8ptOegIK/TqOGXg/FDMpmILI7g9jB/nP ATLXrZeU06CvXJsdCX+PZ/65hlN/Qmi+yUVFR26YRviej9kjMqPkYV0/TdvhaTf7hv QHoWyC4B4zVfTld899NJuK5cv9cWqkiK9d+aBwzs= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:23 +0530 Subject: [PATCH 03/13] platform/raspberrypi: vchiq-mmal: Support sending data to MMAL ports Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-3-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2041; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=GGB5nUrnx+IB8Xu2CwCZTqROE4qS6bk1utWTjQbFuYs=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGWd9fNZvo+twIRO1O5q6/cVyUHvPYmTjVQx EcGMVcq3QqJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxlgAKCRBD3pH5JJpx RWdAD/0VEPbvjctIPCAUaattr3z/NJ9SBxd1hWpz087+/NooVrkuFjCpIlF59I9FJnTQKaY+hLn G/u6PzlmJlOkvDb4+lWI6NZqP9bxc9EiheucJE0C4uSFb4foKtT+9k9zqa+MFNyFhqQ+t+dhsbE zWGhq6jI6F0AX9nkMXoaCBb1dxcTFhRbxIJ2ArGA0UH/IxNA+BvhHlgLLmDccyTWly8vudfeHXS vrg5E0YscM5mzKceg7gWtqBdy6+eo2UiNMIoAk7o+ZOCBg+k5ouy7aQBiOlUbG9VD8/1S+QUCsV D13LwXnYQkwNXatGpZbPmXx4HkzJsbtJAsc/jRsj8tlDgaTTKOCWNWqWlnANjI3mI1ANAaZKsBW 8GPov53HE+X7rnGiUQLk6fEDxyeqWfaRp5WH5ndY+t6o6vEVPyk/zmvhw9flB3O+F7kWkUAs6Zc MFn8bWHnlV/KvxVRTZuJyURyEqiqAg4sjTuBf7XgJVGfsk3AkVZ42iuYRXNbDCCHflRCar84/LP pr7gKdqdMPmd4d7cqAoeXhsYzFUkGB1sgEFs0MDrEcirIfGNJeF8dyGUA8bBq++M7ItgrIvEoff DM621AlXiK8eCTSVol5sFgGSuOSEYOl5xYq0917CM1xDIFct0XjG0dLnLeBTyn5f5h3lZffkBVb kULiK/jfnlUsSOA== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson Add the ability to send data to ports. This only supports zero copy mode as the required bulk transfer setup calls are not done. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 18 +++++++++++++---= -- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index a115a391908da06e101e159905a4403b91e051c6..1ad00bb0a02b482719a75749ed6= ca50f43df24b2 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -421,11 +421,19 @@ buffer_from_host(struct vchiq_mmal_instance *instance, m.u.buffer_from_host.buffer_header.data =3D (u32)(unsigned long)buf->buffer; m.u.buffer_from_host.buffer_header.alloc_size =3D buf->buffer_size; - m.u.buffer_from_host.buffer_header.length =3D 0; /* nothing used yet */ - m.u.buffer_from_host.buffer_header.offset =3D 0; /* no offset */ - m.u.buffer_from_host.buffer_header.flags =3D 0; /* no flags */ - m.u.buffer_from_host.buffer_header.pts =3D MMAL_TIME_UNKNOWN; - m.u.buffer_from_host.buffer_header.dts =3D MMAL_TIME_UNKNOWN; + if (port->type =3D=3D MMAL_PORT_TYPE_OUTPUT) { + m.u.buffer_from_host.buffer_header.length =3D 0; + m.u.buffer_from_host.buffer_header.offset =3D 0; + m.u.buffer_from_host.buffer_header.flags =3D 0; + m.u.buffer_from_host.buffer_header.pts =3D MMAL_TIME_UNKNOWN; + m.u.buffer_from_host.buffer_header.dts =3D MMAL_TIME_UNKNOWN; + } else { + m.u.buffer_from_host.buffer_header.length =3D buf->length; + m.u.buffer_from_host.buffer_header.offset =3D 0; + m.u.buffer_from_host.buffer_header.flags =3D buf->mmal_flags; + m.u.buffer_from_host.buffer_header.pts =3D buf->pts; + m.u.buffer_from_host.buffer_header.dts =3D buf->dts; + } =20 /* clear buffer type specific data */ memset(&m.u.buffer_from_host.buffer_header_type_specific, 0, --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A9D534EEEF for ; Fri, 31 Oct 2025 17:28:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931712; cv=none; b=jOAFtyYORcJEMhopXXsurI+8FuF7uacHefi1wNi16nG1x7buVU+giYVRAPKe/VPvS6o5cz5z6sjInrU9kYR0X0LYWmkuG2LjsxeM6nVy0d/LGCVRu5qSJvPcHj1CohDboPgslZEy+g0awNiEwaSxlOrMPCUaS4VjHDZnEgMbf00= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931712; c=relaxed/simple; bh=0VUnvhN+JpMns0ilAaC0RXBzsIqOeBD+ERttPQmNyI8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=LhhB79b04jzuga21c3L3+tWOTSIe4hOwKxpMiIabSWHoaUOXu8xlDdHB2KhfLY8Mm5QWR9uR5sTmhy5edNyETAw0cw0iZ0tOV7Vqg4yfWcaLW/TL97iBFCavS+y5tTAysv59djd2DQ/hUvIFeX1ivNU1CLX2PJLaH35Bmv03jjc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=rqmu002J; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="rqmu002J" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C2EBB5; Fri, 31 Oct 2025 18:26:37 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931597; bh=0VUnvhN+JpMns0ilAaC0RXBzsIqOeBD+ERttPQmNyI8=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=rqmu002Jn4ajVplh3U5ft9HREwtt9GyJP0vx91+GU42zBiP2ZH+aEuooz7l84Y3ob xE/pwVnRMVvdc38HECwGF7reFL7nqDCcn9od6keV2yQA7HU/cWYrUp2atfMzyqQEpL qomPkgGB2WBT1mFufeKHRx6Eiju6X25cwC2Q5s9k= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:24 +0530 Subject: [PATCH 04/13] platform/raspberrypi: vchiq-mmal: Fix client_component for 64 bit kernel Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-4-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1613; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=2VK8OHXcpTdqTpiX4wSB7ZKhEke5bjaA9vgjkEN/2M0=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGX+g4pLvMHyqwNp/aj0Link2ixR+06q0DXQ wacJ4x7sAiJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxlwAKCRBD3pH5JJpx RRPpD/9C5Vm9gJ3qGANqziq1xjWZiDH0CsCzRTusupu78C7pddH8gCdhc4Up/wfLuYCyM7T0b0R Mw6UuBd1wvq9XUQYSMiKVClTEzRQqTcaa7Fe9vk+YvjUB4xRGJBdiRN1IfEzB+kv5DD88mte1Dp btx9k6U40KsmDestcjB1aN2fmgogWZg6Ti6PjxQx3H1TAbCo5nC1BHQ85G3zr/WFIZIXnC+3MpB pUmo/ZcogM4mCZcRUX4vJY1GqYZe8+XuUYYhfkjHlsTP39tanlWOI/T9yPBvCmjGTbJ9j8XPkMf PYgZttqE+2MFLDVNPsxzmKnN8XrlvI2YaLIjsQBXiTLGyc1kKyE/qdZuySR0c1imHYsIMB3jY6P qqFhSjMZV6k0TYBb37c9KqAnzVxAcheZEiWnuDdHmAZvJ9FLMioLGnsu7lazF36ggCQ9eF9ujqa ESJzwNNxRIGyNclqY62LxAe2KQyBwvVda5/U5vaPn7LK8DOx9bzIs7zDX9JT5nABuHaEV29KjPm MtzzcrIfOuJegTU552YtvxhTN9VMIY7++nwXEu40owLtWjz74SEsLHTbW/O9uyxx+QuoDf0hQp3 NriZL+3waT+FQ/KlYNXGS6MrKSfZvafsoI6PVB8VDzOfxol3zGte3CdqpkSSxsWeZKU9KjiWgXG nTJY94EDZys8upg== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson The MMAL client_component field is used with the event mechanism to allow the client to identify the component for which the event is generated. The field is only 32bits in size, therefore we can't use a pointer to the component in a 64 bit kernel. Component handles are already held in an array per VCHI instance, so use the array index as the client_component handle to avoid having to create a new IDR for this purpose. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index 1ad00bb0a02b482719a75749ed6ca50f43df24b2..6381495fc3867013f74bd3754ed= 64e0a1ce01574 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -459,9 +459,9 @@ buffer_from_host(struct vchiq_mmal_instance *instance, static void event_to_host_cb(struct vchiq_mmal_instance *instance, struct mmal_msg *msg, u32 msg_len) { - /* FIXME: Not going to work on 64 bit */ + int comp_idx =3D msg->u.event_to_host.client_component; struct vchiq_mmal_component *component =3D - (struct vchiq_mmal_component *)msg->u.event_to_host.client_component; + &instance->component[comp_idx]; struct vchiq_mmal_port *port =3D NULL; struct mmal_msg_context *msg_context; u32 port_num =3D msg->u.event_to_host.port_num; --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C23FE3054F7 for ; Fri, 31 Oct 2025 17:28:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931716; cv=none; b=J8K/pCXy5SQlmkR7aVtCXYheUaefY/Dq4KsLeDsxXdESRtJq8+kajJTMch4Vzp1U/6PWo2lsx2gi94drkf7TzM+EAUJ7EHbcUcgH2cnGu9sUhjeYxgKXvhjE3xMoOP4Rj+wueSFEkj5xwkwhis4zqImuRGv1lBKq7/OcSX4P2e8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931716; c=relaxed/simple; bh=pOlUZ/eYmURkI9UAYzXg8XzcXPBjNBMhjQguuGX/sPU=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=qv7XSbsYbdmPOv3+rnNfuEkKQBWDD905098T3K0t88JgjXqUrD5HrYDQRUIv7+U1uC30rX5wdWDzF5SXXgjUTqeV2I7iM8EhkjKlrncCUAtscHLZ1elvEzl1jZRkM+Q8lD0Z4WOcekXheWs+NqHvtOkyDIJbh9D0yDMTI5fImvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=aD5hd/QZ; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="aD5hd/QZ" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 3A5073A2; Fri, 31 Oct 2025 18:26:42 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931602; bh=pOlUZ/eYmURkI9UAYzXg8XzcXPBjNBMhjQguuGX/sPU=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=aD5hd/QZjuAu2DbdSCIPFQhjdZbcliqwShb3T5PBuEnYTMAShyXKMkJ+X8PMwRWrI FKP1P4m0hVoyJC0nhaAgGl6dU8mBPg+Z3anTwd3j5e46b4aGQzfjGagdvDUcVCpRKs SM0jPtD/9gOTtDhovWhGO/D7oBRNtr+wE90OySkA= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:25 +0530 Subject: [PATCH 05/13] platform/raspberrypi: vchiq-mmal: Add in the bayer and gray formats Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-5-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3072; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=spTPBZUUYTCoXyLwYiPFicRWxsPp0oGfOuM0+6jDegE=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGYZjTE6iQ+/Z2roISP58pFWBX1/U/xtzJhV izcRsgqeX6JAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxmAAKCRBD3pH5JJpx RfqPEAC/u7t7MEC6xEzkyZzkuWCQII9Y7t6g7mP0O/cPj7eXyBH3pJaoo7Uw8tYMMJA16RFM4dJ 1HmEFDNI+mR7Uwx1xXNXhpG8zDivegPfepY/+AXmXwqrkT2MysaIsKWSM519IU8fjgw1UbfoyAe 4qIeZfHgGH9iZ4jclCh2A9zo13pb48/Z3qI4BxT8OXYVR+EcME+wEMTgTk5S/EvTYDgCGIt6bi1 DroblV5lXv47lettfSxpsvWUwqe4kvxt1vynCJyduS6cV1mmooU77r38JoFlMt1PXUlC7akJfRZ n7zCksgq4E5Lpj+MdTjugHnLds+TZmDN4Tz8l54jv31jjP4uSayOe+mKOADJih7jhilGA3So6uN yJLPnWuTKuW5CVBvJxHw/GuQ9WNnaV2D5jc4+BYrdgAcf0b+Eo+V/Iot/RBdILePQmr7cuckaoN PrVPugMLoQdLHU/6v/HLClIMxCXBzXItswM64o+BhlzFiiG7XPlKWjj/uBui/8sQhdOMHdu09wD SKv6+lCAT1m21KtQSf84BNC9tyhqPVN6pKTuILldx0SfHdk8LrXmyti2g02waKD6UOhm0ZOeO9t soEytmYGldaBGX4zJ9y5azgF/DFf/OhKPQFGJltLFxNU4TgnL4S/o5LuoRJttke2JlReTmJFoj7 2OKL32+/nLwqKZg== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson The ISP and codec support bayer and gray formats, so add in the encodings for them. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h | 41 ++++++++++++= +++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h b/dri= vers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h index e15ae7b24f73fd055806e2e88e5eec0e1b8bfe9d..826ed66deafd082f43539c5b470= 2a2e0b6a2fe95 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-encodings.h @@ -69,6 +69,47 @@ */ #define MMAL_ENCODING_OPAQUE MMAL_FOURCC('O', 'P', 'Q', 'V') =20 +/** + * Bayer formats + * FourCC values copied from V4L2 where defined. + */ +/* 8 bit per pixel Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR8 MMAL_FOURCC('B', 'A', '8', '1') +#define MMAL_ENCODING_BAYER_SGBRG8 MMAL_FOURCC('G', 'B', 'R', 'G') +#define MMAL_ENCODING_BAYER_SGRBG8 MMAL_FOURCC('G', 'R', 'B', 'G') +#define MMAL_ENCODING_BAYER_SRGGB8 MMAL_FOURCC('R', 'G', 'G', 'B') + +/* 10 bit per pixel packed Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR10P MMAL_FOURCC('p', 'B', 'A', 'A') +#define MMAL_ENCODING_BAYER_SGRBG10P MMAL_FOURCC('p', 'g', 'A', 'A') +#define MMAL_ENCODING_BAYER_SGBRG10P MMAL_FOURCC('p', 'G', 'A', 'A') +#define MMAL_ENCODING_BAYER_SRGGB10P MMAL_FOURCC('p', 'R', 'A', 'A') + +/* 12 bit per pixel packed Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR12P MMAL_FOURCC('p', 'B', '1', '2') +#define MMAL_ENCODING_BAYER_SGRBG12P MMAL_FOURCC('p', 'g', '1', '2') +#define MMAL_ENCODING_BAYER_SGBRG12P MMAL_FOURCC('p', 'G', '1', '2') +#define MMAL_ENCODING_BAYER_SRGGB12P MMAL_FOURCC('p', 'R', '1', '2') + +/* 14 bit per pixel packed Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR14P MMAL_FOURCC('p', 'B', 'E', 'E') +#define MMAL_ENCODING_BAYER_SGBRG14P MMAL_FOURCC('p', 'G', 'E', 'E') +#define MMAL_ENCODING_BAYER_SGRBG14P MMAL_FOURCC('p', 'g', 'E', 'E') +#define MMAL_ENCODING_BAYER_SRGGB14P MMAL_FOURCC('p', 'R', 'E', 'E') + +/* 16 bit per pixel Bayer formats. */ +#define MMAL_ENCODING_BAYER_SBGGR16 MMAL_FOURCC('B', 'G', '1', '6') +#define MMAL_ENCODING_BAYER_SGBRG16 MMAL_FOURCC('G', 'B', '1', '6') +#define MMAL_ENCODING_BAYER_SGRBG16 MMAL_FOURCC('G', 'R', '1', '6') +#define MMAL_ENCODING_BAYER_SRGGB16 MMAL_FOURCC('R', 'G', '1', '6') + +/* MIPI packed monochrome images */ +#define MMAL_ENCODING_GREY MMAL_FOURCC('G', 'R', 'E', 'Y') +#define MMAL_ENCODING_Y10P MMAL_FOURCC('Y', '1', '0', 'P') +#define MMAL_ENCODING_Y12P MMAL_FOURCC('Y', '1', '2', 'P') +#define MMAL_ENCODING_Y14P MMAL_FOURCC('Y', '1', '4', 'P') +#define MMAL_ENCODING_Y16 MMAL_FOURCC('Y', '1', '6', ' ') + /** An EGL image handle */ #define MMAL_ENCODING_EGL_IMAGE MMAL_FOURCC('E', 'G', 'L', 'I') --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E021F350D47 for ; Fri, 31 Oct 2025 17:28:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931721; cv=none; b=cmZZYR5nYGW5aevKncVZJj9XAofE+oTa5Zsyi5pH7u6ZrvDgYRyZdAa0wbpenLR9PfoPhrF9XWY+7tTwj2qtfooeCMbiaezvAjnc5JSKmD6m3iUhndv38ZHO01AHFy7HHH3SYmtQDiDFRQSSCYFleot34eyKVPCeUThR+2oAsYs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931721; c=relaxed/simple; bh=L2jskCFzVI8vu/VxoOiuw8oJHvcjhXC0BGW7Tik0EZE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BbSB3tWDEZYjE3tXCd+0V0bL1Yx5+WTz4UKFh2y0dx3oxbV5lxoxD7zGuRgQNfO+pU0bD/QznlruKY+fx4TdKuWjHJKrlk0MIL2E6kFMFdUztRh1Q0PWdZbc3bTRpFHyih8UeIdszWhHU1miCEoARyABZ6QNuPlIN/E6ol32IE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=ecJtDpaW; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="ecJtDpaW" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 12DF3B5; Fri, 31 Oct 2025 18:26:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931607; bh=L2jskCFzVI8vu/VxoOiuw8oJHvcjhXC0BGW7Tik0EZE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=ecJtDpaWBSsdWbqTB9WfO0ZAgCfK6oPUBQFzr4ywkc8ILhY7PBrk287JgiwN8iYgX +aJOUevbMNbzDVzfQyifE/oRFZIc6qgbo/i5RrWT/GEL48whOkLQLKJX/jjrxAydkU mKQ+vN2+hTsI/y1wDef537z7BWF5pDJFHCizyLCc= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:26 +0530 Subject: [PATCH 06/13] platform/raspberrypi: vchiq-mmal: Update video parameters Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-6-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2277; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=chq8KEMAdpSsSzxQiDjebF7K761kG8qgjKO6tzXXFxo=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGZeNUdnT5uwGciICWjn0Bs341CwEpZvzpCw F6gnxeQh7aJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxmQAKCRBD3pH5JJpx RXzsD/0UKwNYQXhWfszp1SLk0j7aatmNyK4ciO8eqrV2Qq+TfuYyP79JDN7/nwMKwndxEV4MiBO 3oOMK8DR9kt+OiAfIxR7I5Ccb637XMmOVj6EHcZUUA9HsmOYpZfERK9isM44t/2L4lB1Pv9MjDe OdXSxrQqw1qWGMvZyX+v1tSWF8K5MKeNlqN7sqtHXKKAS4BIaD7ZwWQbsN6PzkfLFUkFu4oKRsC pyCXm3wbRD2P3OBdZOJBq1UXrlO7jVRoavxU32hce80+2OYnOsB5Rvj1a2Wuak3BALVtIB6+gNy TCjsskoEsQL2T/6u3bB9QXSCBevOPjFeOBgNXV9hfzEUB7nNIfg7LNfuTMkCg4ph9cYx5GS7F47 kkgmpcbzruKOkI1eszELBykdlzJuXLAIga6PayDg/sdq4Hj6D7XsI6A8k2vA0TCJY+Zv1qLArlp sZccIkJ63nylB49Q8QY4eD5CEMDQ0OxVQMuoFR0rFUzZjvrGOYWKYJRM9FuxjsM2pJp7onoOkUF FQyYhsCNjSfvOpifwJNQMzndAUTu24n1zu56tSLZIH2ZV1AGwGxsBE/4zJoznSZ7/tb1W6SrRiu /2iQqDdYzpp7a1tvyV0JGfFLJJpVilUifHmLefxy7w8GIBQneVXnALlOw6KNLxvRbADnN2Dk9gS 7CLz6YS2tXlKTtw== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson mmal_parameters.h hasn't been updated to reflect additions made over the last few years. Update it to reflect the currently supported parameters. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h | 38 +++++++++++= ++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h b/dr= ivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h index a0cdd28101f2dd67fd6b64ce1c95c0cbbfe15fc4..0a4fc9252b1798d883047e22bbf= ca050017f938e 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-parameters.h @@ -577,7 +577,43 @@ enum mmal_parameter_video_type { MMAL_PARAMETER_VIDEO_ENCODE_H264_LOW_DELAY_HRD_FLAG, =20 /**< @ref MMAL_PARAMETER_BOOLEAN_T */ - MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_HEADER, + + /**< Take a @ref MMAL_PARAMETER_BOOLEAN_T. */ + MMAL_PARAMETER_VIDEO_ENCODE_SEI_ENABLE, + + /**< Take a @ref MMAL_PARAMETER_BOOLEAN_T. */ + MMAL_PARAMETER_VIDEO_ENCODE_INLINE_VECTORS, + + /**< Take a @ref MMAL_PARAMETER_VIDEO_RENDER_STATS_T. */ + MMAL_PARAMETER_VIDEO_RENDER_STATS, + + /**< Take a @ref MMAL_PARAMETER_VIDEO_INTERLACE_TYPE_T. */ + MMAL_PARAMETER_VIDEO_INTERLACE_TYPE, + + /**< Takes a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_VIDEO_INTERPOLATE_TIMESTAMPS, + + /**< Takes a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_VIDEO_ENCODE_SPS_TIMING, + + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */ + MMAL_PARAMETER_VIDEO_MAX_NUM_CALLBACKS, + + /**< Takes a @ref MMAL_PARAMETER_SOURCE_PATTERN_T */ + MMAL_PARAMETER_VIDEO_SOURCE_PATTERN, + + /**< Takes a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_VIDEO_ENCODE_SEPARATE_NAL_BUFS, + + /**< Takes a @ref MMAL_PARAMETER_UINT32_T */ + MMAL_PARAMETER_VIDEO_DROPPABLE_PFRAME_LENGTH, + + /**< Take a @ref MMAL_PARAMETER_VIDEO_STALL_T */ + MMAL_PARAMETER_VIDEO_STALL_THRESHOLD, + + /**< Take a @ref MMAL_PARAMETER_BOOLEAN_T */ + MMAL_PARAMETER_VIDEO_ENCODE_HEADERS_WITH_FRAME, }; =20 /** Valid mirror modes */ --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A7C003081B6 for ; Fri, 31 Oct 2025 17:28:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931725; cv=none; b=bE0jXWjpUEkegoJS2Fm+8jfz1CccROCTRw926IYSdOwE5qXTp0PEXffWUiJsLaT6c+KuKKGrpnsGDPAX+geDdeQFyNSxks47GD2cetT+Yr8sr3Zvh+lbzi4qxcW5sxs5OcaeYZz5h+LLc1E8KbB92lPg/o7VHxw+D5i88uAs75c= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931725; c=relaxed/simple; bh=Dukl/WKTNn0wwgbhbk8IkuZav/VzD6UEX4T6MaTL8AI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=CIwBaulFeDXdx4ASLScAhoI+QONEgsf6FGJrR6FGJ2E7yjl6W+zIVvSosKPj6plIIliHYUyewJ2NNMvyO8DpYE50LoinBOcTlWN9Tm3do9KicZC/25rDcXHhEK2cGUGjLMaVxDKCG3/xLqcV/+KnE9b8ZfiWUwydu1bTeo+KVug= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=JErt/xIl; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JErt/xIl" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 33F853A2; Fri, 31 Oct 2025 18:26:51 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931611; bh=Dukl/WKTNn0wwgbhbk8IkuZav/VzD6UEX4T6MaTL8AI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=JErt/xIluRppHac6UmQLtNHQ8xbdP7NMebnfJobJMrO/5beQL2n18ETgdXfBKSpco EWn77E+2ByJvQrUgVIkNXGX0CpMOMDMyXSFPcRNrNHa/kSyQFpORX8g9WWz6I6Hfud lTHcD+Q3zi755s+0J9L8LphMtHh1eKsmRROT2L9w= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:27 +0530 Subject: [PATCH 07/13] platform/raspberrypi: vchiq-mmal: Free the event context for control ports Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-7-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1053; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=fPg0a6AIcLpabOkEcm9pZiFTJR0XeNxvSGleuAQ11J8=; b=kA0DAAoBQ96R+SSacUUByyZiAGkE8ZqgehNmv8v3XSihPC2d1bJhKHNTCrIaLVCwkdJm2qI9e okCMwQAAQoAHRYhBE3g2Bjl1XXo1FqvxUPekfkkmnFFBQJpBPGaAAoJEEPekfkkmnFFM/0P/Rq7 34LlQMjVNWBWKTieL7tV5W5qqp0AtCNAaXhGrIbeczi/hRveSe6jo9KEPhaHbVFVwGsezputZBp h7gsry5T+tZRT4Vr5VzBrIh4zbxs9qwmIluDU8mGlx6DyT2eTS4C9tSN9Jp+2dokoeffT3B2qXd /ztToWAspYbDFGYtQzPzGxa/kR/HBq9G/7GfcQt4v+kf/x/j3CfX0XPppooHmwZGISts6/1AsOo xde1q4GxMDsqSwOgU/WTeVY+n/Ntax41+HA5O8XLpKe1wh4aFrGzfYWzmlgQY5HoAnAw0ZtVKO/ o51ZD90HlrLrNJ+GcNudDjpS2kW8/hGyf+9Y8olKSACykq63GQW7g+p2w/yVrYPkCeF/9sDx43J sSJqqxQnzGqqtVeSkAqw4cxyhFvMiSGV8LE2V7Wq/rbn0i8KgQ8E2+RmZp8lF8UsEVU84lVW04B dfLNf5pgo/Hw7JH9BJmkZrmcOZxNqVfQvTE3Jdr6Fi0yezUvd2FF29x/TS4Jrzk/65TMK8v/RD5 xnfysoE7UZNSaDzRXDjIxJjuqPdJtcJFXLhuu7LSHOwtgp1wItDO2ICwhEIjdV75g9lAkTVzv0B n+VAbnHixBd4QucxeRyllZ/LDOFnIvx8KMIN3riWx3kn3gLXuF9aPfuKXvlaFwzX8WTmCy612mN Mr+A4 X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson vchiq_mmal_component_init calls init_event_context for the control port, but vchiq_mmal_component_finalise didn't free it, causing a memory leak.. Add the free call. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index 6381495fc3867013f74bd3754ed64e0a1ce01574..36f3b068c825e6a26508aefe544= f7061c9559510 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -1902,6 +1902,8 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_i= nstance *instance, for (idx =3D 0; idx < component->clocks; idx++) free_event_context(&component->clock[idx]); =20 + free_event_context(&component->control); + mutex_unlock(&instance->vchiq_mutex); =20 return ret; --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1042C357A3A for ; Fri, 31 Oct 2025 17:28:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931731; cv=none; b=U12VCbw+MHC/rjeZi2ViZiBlXNDInKDOFj+xUiMW62Gxx2w2mFiysrRzZdCgdgUlUTPueuUshIgfaciVUnr9Smiifm9Z2ZFdugi0MkVkcSQe1QI2QLX9hJkspDwUt8fiqLef3Td3EtnOgjQmH7pMFzjPfIYvYB2qg5rWLG+2cfc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931731; c=relaxed/simple; bh=M82WFeZ7VFa/oUdRBWdKzF41B/nKaOXYBrqQT4FuP9Y=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=pOXVbMyWRydbNjGhWn+wrKx/xl4av0dhoQRNx7aY2LBAcaAnJU7j9DORwWLUQ8o81Q/NKVlEdc35Qwa0UisUlEYXK8+YRzreoNGauUA+BBvdbTEdG4I2aoqe/h4Bk8HN/ALNXUMSzP+QPlArCx9OhN15rmhkLzsetUN9pCemPOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=n1ZforE8; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="n1ZforE8" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CBBD53A2; Fri, 31 Oct 2025 18:26:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931618; bh=M82WFeZ7VFa/oUdRBWdKzF41B/nKaOXYBrqQT4FuP9Y=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=n1ZforE8se6yQpa1hRW6XeuqOfbEzxy2X8H17+hRobxK0Df31mofoTg5HKQTbORTz RuTJxS3j0j89pvaiKcXAC5kORXkBq2Fu+FzQhzY1pkgtb7DBs07SAzyZXNgbubemza PgSABl02s8tQDG5/+0rXjkuSgBVJwhCF2QgxU2nA= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:28 +0530 Subject: [PATCH 08/13] platform/raspberrypi: vchiq-mmal: Fix memory leak in error path Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-8-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dave Stevenson X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=2672; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=El+RK8d9+LHdrGvU0xUfqJDBZbtRjVDpARQlhUyJjtE=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGbBw5eStZhVv0NTK+DUkgbbUDFcFgFCQzwh /meHGhP0DyJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxmwAKCRBD3pH5JJpx RTgdD/9zIM/KFkyFaHgf7omYZbb8OUtQlRrw5U6e4jASYThQKOYjYQozZ/e0QFlE5QIuTQLkGKs Lf5em85iM90WSXjhL8WXk9dFKx3v36Ii1ySuAwwv21VwLYIwSpt6fGclGqomJEc39CFtsOEbkvp PIqEs46sZn5a6pUPAYNus9x6P36DG5tHSf9oaVKW8DPiKPUv/iww5ocvJgyfN4JfDedWDOYvpGJ /GWx+Xe+Kj4HyCLor+2GMI/A0RNpCEw9vQdAPdM5PcXgwyJoYbSkAbvAXY/xmPVRXLMOJIaW3ZJ A2cgtiXLcUCB9dJrIc6GuAQJ4jxVLUA9LrmU+rpI8yAZSnY/mQyTEa8AJUtaG7RuxQG1mC9cf9r R3MO1/gMxrEsulEEZs4BgxAQndIR1X0W5iQNPZoHBpBOq+dRI3XUHWYvdWioKhZZyBQutcPHY74 Uw/l0kFz1DF32kKYwqzkB4ytmnjmzCEOOlYvvk/wZ05+kipQK0twK51xHw+jfDcB857M7gURltw Tx8APgPaab7T5cdmMS+vxv+7QmttV8R/+t29VKHeKseCV7mfP6mGygmcDe7q+HGqBE3U8PBR/ND jXmlTiq7uSs1zMp4iizxD+TCLS4QC0CsZpGo8VSmh5427PnqcA1EMZzxlGdxfZWLreTD+tW/8yo 3gU72VCsqy7VL9w== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson On error, vchiq_mmal_component_init could leave the event context allocated for ports. Clean them up in the error path. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 29 ++++++++++++++++= ++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index 36f3b068c825e6a26508aefe544f7061c9559510..3c99d0f3e57178761ec57d97cd7= 7e59aa26143fa 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -1768,9 +1768,26 @@ static void free_event_context(struct vchiq_mmal_por= t *port) { struct mmal_msg_context *ctx =3D port->event_context; =20 + if (!ctx) + return; + kfree(ctx->u.bulk.buffer->buffer); kfree(ctx->u.bulk.buffer); release_msg_context(ctx); + port->event_context =3D NULL; +} + +static void release_all_event_contexts(struct vchiq_mmal_component *compon= ent) +{ + int idx; + + for (idx =3D 0; idx < component->inputs; idx++) + free_event_context(&component->input[idx]); + for (idx =3D 0; idx < component->outputs; idx++) + free_event_context(&component->output[idx]); + for (idx =3D 0; idx < component->clocks; idx++) + free_event_context(&component->clock[idx]); + free_event_context(&component->control); } =20 /* Initialise a mmal component and its ports @@ -1868,6 +1885,7 @@ int vchiq_mmal_component_init(struct vchiq_mmal_insta= nce *instance, =20 release_component: destroy_component(instance, component); + release_all_event_contexts(component); unlock: if (component) component->in_use =3D false; @@ -1883,7 +1901,7 @@ EXPORT_SYMBOL_GPL(vchiq_mmal_component_init); int vchiq_mmal_component_finalise(struct vchiq_mmal_instance *instance, struct vchiq_mmal_component *component) { - int ret, idx; + int ret; =20 if (mutex_lock_interruptible(&instance->vchiq_mutex)) return -EINTR; @@ -1895,14 +1913,7 @@ int vchiq_mmal_component_finalise(struct vchiq_mmal_= instance *instance, =20 component->in_use =3D false; =20 - for (idx =3D 0; idx < component->inputs; idx++) - free_event_context(&component->input[idx]); - for (idx =3D 0; idx < component->outputs; idx++) - free_event_context(&component->output[idx]); - for (idx =3D 0; idx < component->clocks; idx++) - free_event_context(&component->clock[idx]); - - free_event_context(&component->control); + release_all_event_contexts(component); =20 mutex_unlock(&instance->vchiq_mutex); =20 --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5FF06357A3A for ; Fri, 31 Oct 2025 17:28:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931740; cv=none; b=b2bpYxA486kMUbjPQN7g8T1lzLsnsfPqXokB4blMweSiUB/zspvG0nkqwEeHsRGUQBZFGvKQ4QN5uVoi1eAhffvacvhPsxB4HyDwFHHrQcS1GhlpwYYO5cQQ3RU54GblagCn8ueQBpuACpKPChg8f1GyevVQDyv2hAdJ4rNGUZw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931740; c=relaxed/simple; bh=grQSPhX3M2C7APZ+VGWgSK9kwgE76L2fxhG0WwyognQ=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=ZBrtAtcNqEAU2ThzjizZP9ugrajTSMhrh+S8f89pkDHIh/KtCUR8HFSr1SwRIVOu5b3rv630GfyW4nG7G/5Gsesox4bYqROIsmxm0gat7blLJSczkUtAI/xRBVvhJ0yIm1O6KOmxJN+I5e4NwAac/+7sh8kq3UmxzUj30EO4nuY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=jV94fz2B; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="jV94fz2B" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 98BA41690; Fri, 31 Oct 2025 18:27:02 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931623; bh=grQSPhX3M2C7APZ+VGWgSK9kwgE76L2fxhG0WwyognQ=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=jV94fz2Byn15cicqeMule0DF1d1sY1iEKId9rlpgLBHM3vqgfPPzNS775WD5EWcPu 6bXDBcj8L+zTSRnNG3wIRKg9E44+0t+c5GiXW3R5QAmlGKB/CAZCmS1frAkWvqtjip rL33XKMkSWRTm5BD1yP9/GyHedZpwaCe4UEgIHYs= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:29 +0530 Subject: [PATCH 09/13] platform/raspberrypi: Add new vc-sm-cma driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-9-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra , Dom Cobley , Alexander Winkowski , Greg Kroah-Hartman , Juerg Haefliger X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=88084; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=j+UQKltJZS78gTzfXzY90CvKGz4glRg/+kKymXhlljc=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGcGnqQW4oi4u4Xlenodqc6iIVjSS3Swo9gr YB6fCHzdHuJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxnAAKCRBD3pH5JJpx RfJbD/9dXk5YM8lIcHwXciCatZRy1VnQ7fJfJzdhCmTmBcbZGJWbG+WVktCQlTA47LLQUFtfjGJ dysyE7Z9Lk6AeTBExS4WH0dv951v9705HXELwk6jemsW/idbgrfvJs0dy/T07RnxOG6wKLlWbLJ n5GjVjpfZwFjt4uYexCT8gVe080xj3r48JipYGC254CrAzuuQjn0KqtrUyMIcKTG6UCSjfecgpb fA2U9VcSj2F6+s12kiBXnXKu2NqK+J6sMH7r00EjEPkRdKTHwwVX0z28vPbuSH/vplLCsJf3HZj gdeA8VmLI4iAZN3+fFDL686zVHyT1DsM8F/vNQOQdu9GtIw6Y+2VHKG71t+qLPGEVVQ4HpnKIcE xqOonmKZY0q09wfRwtjgGGqjjcEFYjyjXefeflBuUy6yrQ7BY1NYgIM/f/LD9LEadz2ES6VE2j6 787JU2C4nhcJWgzyFWJClMlKb+WHKf3sdBBlo9x4VMz+hjgzXXcMuKQymYmQNpjh05FhGZra3PD jkagemiu2fMoLZyRlzeA2ZiScEJl2wh1jAoElsFvaSU/2k0f043KJfLeOvo1n1DwEnIwLAJmjdl Uh4viWuLgX2sHlpNRv0a5HxSOgW1IManfGrv6V13YFx3GLstJjNvp5Ns1KcBTBm586+wjFpYTXT i/Lrh6l44u505bg== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson Add Broadcom VideoCore Shared Memory support. This new driver allows contiguous memory blocks to be imported into the VideoCore VPU memory map, and manages the lifetime of those objects, only releasing the source dmabuf once the VPU has confirmed it has finished with it. Signed-off-by: Dave Stevenson staging: vcsm-cma: Fix memory leak from not detaching dmabuf When importing there was a missing call to detach the buffer, so each import leaked the sg table entry. Actually the release process for both locally allocated and imported buffers is identical, so fix them to both use the same function. Signed-off-by: Dave Stevenson staging/vc-sm-cma: Avoid log spamming on Pi0/1 over cache alias. Pi 0/1 use the 0x80000000 cache alias as the ARM also sees the world through the VPU L2 cache. vc-sm-cma was trying to ensure it was in an uncached alias (0xc), and complaining on every allocation if it weren't. Reduce this logging. Signed-off-by: Dave Stevenson vc-sm-cma: Restore correct cache maintainance operations We have been using the more expensive flush operations rather than invalidate and clean since kernel rpi-5.9.y These are exposed with: 52f1453513ba95084ab811a030032fe605b0cbe2 Re-expose some dmi APIs for use in VCSM But I believe that commit was dropped when (non-cma) vc-sm was dropped, and didn't get updated when the commit was restored Signed-off-by: Dom Cobley staging: vc04_services: Fix clang14 warning Insert a break to fix a fallthrough warning from clang14. Since the fallthrough was to another break, this is a cosmetic change. See: https://github.com/raspberrypi/linux/issues/5078 Signed-off-by: Phil Elwell vc04_services/vc-sm-cma: Handle upstream require vchiq_instance to be passed around vc04_services/vc-sm-cma: Switch one-bit bitfields to bool Clang 16 warns: ../drivers/staging/vc04_services/vc-sm-cma/vc_sm.c:816:19: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion] buffer->imported =3D 1; ^ ~ ../drivers/staging/vc04_services/vc-sm-cma/vc_sm.c:822:17: warning: implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1 [-Wsingle-bit-bitfield-constant-conversion] buffer->in_use =3D 1; ^ ~ 2 warnings generated. Signed-off-by: Alexander Winkowski vc04_services: vcsm-cma: Detach from the correct dmabuf Commit d3292daee319 ("dma-buf: Make locking consistent in dma_buf_detach()") added checking that the same dmabuf for which dma_buf_attach was called is passed into dma_buf_detach, which flagged up that vcsm-cma was passing in the wrong dmabuf. Correct this so that we don't get the WARN on every dma_buf release. Signed-off-by: Dave Stevenson staging: vc04_services: vc-sm-cma: Remove deprecated header The vchiq_connected.h header was removed in f875976ecf45 ("staging: vc04_services: Drop vchiq_connected.[ch] files") to simplify the implementation. Update the vc_sm driver accordingly which can still use the same functions through the vchiq_arm.h header declarations. Signed-off-by: Kieran Bingham staging: vc04_services: vc-sm-cma: Drop include Makefile directive Drop the include directive. They can break the build, when one only wants to build a subdirectory. Replace with "../" for the includes in the vc_sm files instead. The fix is equivalent to the four patches between 29d49a76c5b2 ("staging: vc04_services: bcm2835-audio: Drop include Makefile directive")...2529ca211402 ("staging: vc04_services: interface: Drop include Makefile directive") Suggested-by: Greg Kroah-Hartman Signed-off-by: Kieran Bingham staging: vc04_services: vc-sm-cma: Register with vchiq_bus_type Register the vcsm rive with the vchiq_bus_type instead of useing the platform driver/device. Signed-off-by: Kieran Bingham staging: vc04_services: vc-sm-cma: Explicitly set DMA mask The platform model originally handled the DMA mask. Now that we are on the vchiq_bus we need to explicitly set this. Signed-off-by: Kieran Bingham staging: vc04_services: vc-sm-cma: Use [map|unmap]_attachment_unlocked lockdep throws warnings when using libcamera as buffers are mapped and unmapped as the dmabuf->resv lock hasn't been taken. Switch to using the _unlocked variants so that the framework takes the lock. https://github.com/raspberrypi/linux/issues/6814 Signed-off-by: Dave Stevenson staging: vc04_services: vc-sm-cma: Use a mutex instead of spinlock There are no contexts where we should be calling the kernelid_map IDR functions where we can't sleep, so switch from using a spinlock to using a mutex. https://github.com/raspberrypi/linux/issues/6815 Signed-off-by: Dave Stevenson staging: vc-sm-cma: Fix field-spanning write warning Replace one-element array with flexible-array member to fix: [ 11.725017] ------------[ cut here ]------------ [ 11.725038] memcpy: detected field-spanning write (size 4) of single fie= ld "hdr->body" at drivers/staging/vc04_services/vc-sm-cma/vc_sm_cma_vchi.c:= 130 (size 0) [ 11.725113] WARNING: CPU: 3 PID: 455 at drivers/staging/vc04_services/vc= -sm-cma/vc_sm_cma_vchi.c:130 vc_vchi_cmd_create+0x1a8/0x1d0 [vc_sm_cma] Signed-off-by: Juerg Haefliger platform/raspberrypi: vc-sm-cma: Fix smatch warnings Fix these two smatch warnings for the vc-sm-cma driver, rest were false positives: ../drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c:413 vc_sm_dma_buf_attach() warn: inconsistent returns '&buf->lock'. Locked on : 396 Unlocked on: 413 ../drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c:1225 vc_sm_cma_ioctl_alloc() error: we previously assumed 'buffer' could be null (see line 1113) Signed-off-by: Dave Stevenson [jai.luthra: fix checkpatch and smatch warnings, add entry in MAINTAINERS] Co-developed-by: Jai Luthra Signed-off-by: Jai Luthra --- MAINTAINERS | 7 + drivers/platform/raspberrypi/Kconfig | 2 + drivers/platform/raspberrypi/Makefile | 1 + drivers/platform/raspberrypi/vc-sm-cma/Kconfig | 9 + drivers/platform/raspberrypi/vc-sm-cma/Makefile | 9 + drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c | 1619 +++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++= +++++++++++++++++++++++++++++ drivers/platform/raspberrypi/vc-sm-cma/vc_sm.h | 83 ++++++ drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c | 513 +++++++++++= ++++++++++++++++++++++++++ drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.h | 63 +++++ drivers/platform/raspberrypi/vc-sm-cma/vc_sm_defs.h | 298 +++++++++++= ++++++++++ drivers/platform/raspberrypi/vc-sm-cma/vc_sm_knl.h | 28 ++ include/linux/raspberrypi/vc_sm_cma_ioctl.h | 114 +++++++++ 12 files changed, 2746 insertions(+) diff --git a/MAINTAINERS b/MAINTAINERS index df07d1a3c28d048e14a0f65c9f9ff01cc260013a..352c29bb3b94543bcb37c62d26d= 4c8bae48130ff 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -5289,6 +5289,13 @@ L: netdev@vger.kernel.org S: Maintained F: drivers/net/ethernet/broadcom/tg3.* =20 +BROADCOM VIDEOCORE SHARED MEMORY DRIVER +M: Raspberry Pi Kernel Maintenance +L: linux-kernel@vger.kernel.org +S: Maintained +F: drivers/platform/raspberrypi/vc-sm-cma/* +F: include/linux/raspberrypi/vc_sm_cma* + BROADCOM VK DRIVER M: Scott Branden R: Broadcom internal kernel review list diff --git a/drivers/platform/raspberrypi/Kconfig b/drivers/platform/raspbe= rrypi/Kconfig index 2c928440a47c08e4d452fe838fe4105c608995a4..68a7a2d5701cd6821ec4b7418a8= 6bf61011c83f6 100644 --- a/drivers/platform/raspberrypi/Kconfig +++ b/drivers/platform/raspberrypi/Kconfig @@ -48,5 +48,7 @@ config VCHIQ_CDEV endif =20 source "drivers/platform/raspberrypi/vchiq-mmal/Kconfig" +source "drivers/platform/raspberrypi/vc-sm-cma/Kconfig" + =20 endif diff --git a/drivers/platform/raspberrypi/Makefile b/drivers/platform/raspb= errypi/Makefile index 2a7c9511e5d8bbe11c05680eea016ef40796b648..1980f618e2185228e1fe173b1e9= 4a3ede0e15bbb 100644 --- a/drivers/platform/raspberrypi/Makefile +++ b/drivers/platform/raspberrypi/Makefile @@ -13,3 +13,4 @@ vchiq-objs +=3D vchiq-interface/vchiq_dev.o endif =20 obj-$(CONFIG_BCM2835_VCHIQ_MMAL) +=3D vchiq-mmal/ +obj-$(CONFIG_BCM_VC_SM_CMA) +=3D vc-sm-cma/ diff --git a/drivers/platform/raspberrypi/vc-sm-cma/Kconfig b/drivers/platf= orm/raspberrypi/vc-sm-cma/Kconfig new file mode 100644 index 0000000000000000000000000000000000000000..7daec14dcfc14b6a1492ca9e167= 0807b5b4f87d8 --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/Kconfig @@ -0,0 +1,9 @@ +config BCM_VC_SM_CMA + tristate "VideoCore Shared Memory (CMA) driver" + select BCM2835_VCHIQ + select DMA_SHARED_BUFFER + help + Say Y here to enable the shared memory interface that + supports sharing dmabufs with VideoCore. + This operates over the VCHIQ interface to a service + running on VideoCore. diff --git a/drivers/platform/raspberrypi/vc-sm-cma/Makefile b/drivers/plat= form/raspberrypi/vc-sm-cma/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..c12c1a13165c18927ab03e8edde= 762bcb7f32c9b --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/Makefile @@ -0,0 +1,9 @@ +# SPDX-License-Identifier: GPL-2.0 +vc-sm-cma-$(CONFIG_BCM_VC_SM_CMA) :=3D \ + vc_sm.o vc_sm_cma_vchi.o + +obj-$(CONFIG_BCM_VC_SM_CMA) +=3D vc-sm-cma.o + +ccflags-y +=3D \ + -D__VCCOREVER__=3D0 + diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c b/drivers/platf= orm/raspberrypi/vc-sm-cma/vc_sm.c new file mode 100644 index 0000000000000000000000000000000000000000..134a8fde7ebfc1325fcd2f5cc9b= 81ad48a22a802 --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.c @@ -0,0 +1,1619 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * VideoCore Shared Memory driver using CMA. + * + * Copyright: 2018, Raspberry Pi (Trading) Ltd + * Dave Stevenson + * + * Based on vmcs_sm driver from Broadcom Corporation for some API, + * and taking some code for buffer allocation and dmabuf handling from + * videobuf2. + * + * + * This driver has 3 main uses: + * 1) Allocating buffers for the kernel or userspace that can be shared wi= th the + * VPU. + * 2) Importing dmabufs from elsewhere for sharing with the VPU. + * 3) Allocating buffers for use by the VPU. + * + * In the first and second cases the native handle is a dmabuf. Releasing = the + * resource inherently comes from releasing the dmabuf, and this will trig= ger + * unmapping on the VPU. The underlying allocation and our buffer structur= e are + * retained until the VPU has confirmed that it has finished with it. + * + * For the VPU allocations the VPU is responsible for triggering the relea= se, + * and therefore the released message decrements the dma_buf refcount (wit= h the + * VPU mapping having already been marked as released). + */ + +/* ---- Include Files ----------------------------------------------------= - */ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vc_sm_cma_vchi.h" + +#include "vc_sm.h" +#include "vc_sm_knl.h" + +MODULE_IMPORT_NS("DMA_BUF"); + +/* ---- Private Constants and Types --------------------------------------= - */ + +#define DEVICE_NAME "vcsm-cma" +#define DEVICE_MINOR 0 + +#define VC_SM_RESOURCE_NAME_DEFAULT "sm-host-resource" + +#define VC_SM_DIR_ROOT_NAME "vcsm-cma" +#define VC_SM_STATE "state" + +/* Private file data associated with each opened device. */ +struct vc_sm_privdata_t { + pid_t pid; /* PID of creator. */ + + int restart_sys; /* Tracks restart on interrupt. */ + enum vc_sm_msg_type int_action; /* Interrupted action. */ + u32 int_trans_id; /* Interrupted transaction. */ +}; + +typedef int (*VC_SM_SHOW) (struct seq_file *s, void *v); +struct sm_pde_t { + VC_SM_SHOW show; /* Debug fs function hookup. */ + struct dentry *dir_entry; /* Debug fs directory entry. */ + void *priv_data; /* Private data */ +}; + +/* Global state information. */ +struct sm_state_t { + struct vchiq_device *device; + + struct miscdevice misc_dev; + + struct sm_instance *sm_handle; /* Handle for videocore service. */ + + struct mutex kernelid_map_lock; /* Mutex protecting kernelid_map */ + struct idr kernelid_map; + + struct mutex map_lock; /* Global map lock. */ + struct list_head buffer_list; /* List of buffer. */ + + struct vc_sm_privdata_t *data_knl; /* Kernel internal data tracking. */ + struct vc_sm_privdata_t *vpu_allocs; /* All allocations from the VPU */ + struct dentry *dir_root; /* Debug fs entries root. */ + struct sm_pde_t dir_state; /* Debug fs entries state sub-tree. */ + + bool require_released_callback; /* VPU will send a released msg when it + * has finished with a resource. + */ + u32 int_trans_id; /* Interrupted transaction. */ + struct vchiq_instance *vchiq_instance; +}; + +struct vc_sm_dma_buf_attachment { + struct device *dev; + struct sg_table sg_table; + struct list_head list; + enum dma_data_direction dma_dir; +}; + +/* ---- Private Variables ----------------------------------------------- = */ + +static struct sm_state_t *sm_state; +static int sm_inited; + +/* ---- Private Function Prototypes --------------------------------------= */ + +/* ---- Private Functions ------------------------------------------------= */ + +static int get_kernel_id(struct vc_sm_buffer *buffer) +{ + int handle; + + mutex_lock(&sm_state->kernelid_map_lock); + handle =3D idr_alloc(&sm_state->kernelid_map, buffer, 0, 0, GFP_KERNEL); + mutex_unlock(&sm_state->kernelid_map_lock); + + return handle; +} + +static struct vc_sm_buffer *lookup_kernel_id(int handle) +{ + return idr_find(&sm_state->kernelid_map, handle); +} + +static void free_kernel_id(int handle) +{ + mutex_lock(&sm_state->kernelid_map_lock); + idr_remove(&sm_state->kernelid_map, handle); + mutex_unlock(&sm_state->kernelid_map_lock); +} + +static int vc_sm_cma_seq_file_show(struct seq_file *s, void *v) +{ + struct sm_pde_t *sm_pde; + + sm_pde =3D (struct sm_pde_t *)(s->private); + + if (sm_pde && sm_pde->show) + sm_pde->show(s, v); + + return 0; +} + +static int vc_sm_cma_single_open(struct inode *inode, struct file *file) +{ + return single_open(file, vc_sm_cma_seq_file_show, inode->i_private); +} + +static const struct file_operations vc_sm_cma_debug_fs_fops =3D { + .open =3D vc_sm_cma_single_open, + .read =3D seq_read, + .llseek =3D seq_lseek, + .release =3D single_release, +}; + +static int vc_sm_cma_global_state_show(struct seq_file *s, void *v) +{ + struct vc_sm_buffer *resource =3D NULL; + int resource_count =3D 0; + + if (!sm_state) + return 0; + + seq_printf(s, "\nVC-ServiceHandle %p\n", sm_state->sm_handle); + + /* Log all applicable mapping(s). */ + + mutex_lock(&sm_state->map_lock); + seq_puts(s, "\nResources\n"); + if (!list_empty(&sm_state->buffer_list)) { + list_for_each_entry(resource, &sm_state->buffer_list, + global_buffer_list) { + resource_count++; + + seq_printf(s, "\nResource %p\n", + resource); + seq_printf(s, " NAME %s\n", + resource->name); + seq_printf(s, " SIZE %zu\n", + resource->size); + seq_printf(s, " DMABUF %p\n", + resource->dma_buf); + if (resource->imported) { + seq_printf(s, " ATTACH %p\n", + resource->import.attach); + seq_printf(s, " SGT %p\n", + resource->import.sgt); + } else { + seq_printf(s, " SGT %p\n", + resource->alloc.sg_table); + } + seq_printf(s, " DMA_ADDR %pad\n", + &resource->dma_addr); + seq_printf(s, " VC_HANDLE %08x\n", + resource->vc_handle); + seq_printf(s, " VC_MAPPING %d\n", + resource->vpu_state); + } + } + seq_printf(s, "\n\nTotal resource count: %d\n\n", resource_count); + + mutex_unlock(&sm_state->map_lock); + + return 0; +} + +/* + * Adds a buffer to the private data list which tracks all the allocated + * data. + */ +static void vc_sm_add_resource(struct vc_sm_privdata_t *privdata, + struct vc_sm_buffer *buffer) +{ + mutex_lock(&sm_state->map_lock); + list_add(&buffer->global_buffer_list, &sm_state->buffer_list); + mutex_unlock(&sm_state->map_lock); + + pr_debug("[%s]: added buffer %p (name %s, size %zu)\n", + __func__, buffer, buffer->name, buffer->size); +} + +/* + * Cleans up imported dmabuf. + * Should be called with mutex held. + */ +static void vc_sm_clean_up_dmabuf(struct vc_sm_buffer *buffer) +{ + if (!buffer->imported) + return; + + /* Handle cleaning up imported dmabufs */ + if (buffer->import.sgt) { + dma_buf_unmap_attachment_unlocked(buffer->import.attach, + buffer->import.sgt, + DMA_BIDIRECTIONAL); + buffer->import.sgt =3D NULL; + } + if (buffer->import.attach) { + dma_buf_detach(buffer->import.dma_buf, buffer->import.attach); + buffer->import.attach =3D NULL; + } +} + +/* + * Instructs VPU to decrement the refcount on a buffer. + */ +static void vc_sm_vpu_free(struct vc_sm_buffer *buffer) +{ + if (buffer->vc_handle && buffer->vpu_state =3D=3D VPU_MAPPED) { + struct vc_sm_free_t free =3D { buffer->vc_handle, 0 }; + int status =3D vc_sm_cma_vchi_free(sm_state->sm_handle, &free, + &sm_state->int_trans_id); + if (status !=3D 0 && status !=3D -EINTR) { + pr_err("[%s]: failed to free memory on videocore (status: %u, trans_id:= %u)\n", + __func__, status, sm_state->int_trans_id); + } + + if (sm_state->require_released_callback) { + /* Need to wait for the VPU to confirm the free. */ + + /* Retain a reference on this until the VPU has + * released it + */ + buffer->vpu_state =3D VPU_UNMAPPING; + } else { + buffer->vpu_state =3D VPU_NOT_MAPPED; + buffer->vc_handle =3D 0; + } + } +} + +/* + * Release an allocation. + * All refcounting is done via the dma buf object. + * + * Must be called with the mutex held. The function will either release the + * mutex (if defering the release) or destroy it. The caller must therefor= e not + * reuse the buffer on return. + */ +static void vc_sm_release_resource(struct vc_sm_buffer *buffer) +{ + pr_debug("[%s]: buffer %p (name %s, size %zu), imported %u\n", + __func__, buffer, buffer->name, buffer->size, + buffer->imported); + + if (buffer->vc_handle) { + /* We've sent the unmap request but not had the response. */ + pr_debug("[%s]: Waiting for VPU unmap response on %p\n", + __func__, buffer); + goto defer; + } + if (buffer->in_use) { + /* dmabuf still in use - we await the release */ + pr_debug("[%s]: buffer %p is still in use\n", __func__, buffer); + goto defer; + } + + /* Release the allocation (whether imported dmabuf or CMA allocation) */ + if (buffer->imported) { + if (buffer->import.dma_buf) + dma_buf_put(buffer->import.dma_buf); + else + pr_err("%s: Imported dmabuf already been put for buf %p\n", + __func__, buffer); + buffer->import.dma_buf =3D NULL; + } else { + dma_free_coherent(&sm_state->device->dev, buffer->size, + buffer->cookie, buffer->dma_addr); + } + + /* Free our buffer. Start by removing it from the list */ + mutex_lock(&sm_state->map_lock); + list_del(&buffer->global_buffer_list); + mutex_unlock(&sm_state->map_lock); + + pr_debug("%s: Release our allocation - done\n", __func__); + mutex_unlock(&buffer->lock); + + mutex_destroy(&buffer->lock); + + kfree(buffer); + return; + +defer: + mutex_unlock(&buffer->lock); +} + +/* Create support for private data tracking. */ +static struct vc_sm_privdata_t *vc_sm_cma_create_priv_data(pid_t id) +{ + char alloc_name[32]; + struct vc_sm_privdata_t *file_data =3D NULL; + + /* Allocate private structure. */ + file_data =3D kzalloc(sizeof(*file_data), GFP_KERNEL); + + if (!file_data) + return NULL; + + snprintf(alloc_name, sizeof(alloc_name), "%d", id); + + file_data->pid =3D id; + + return file_data; +} + +/* Dma buf operations for use with our own allocations */ + +static int vc_sm_dma_buf_attach(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) + +{ + struct vc_sm_dma_buf_attachment *a; + struct sg_table *sgt; + struct vc_sm_buffer *buf =3D dmabuf->priv; + struct scatterlist *rd, *wr; + int ret, i; + + a =3D kzalloc(sizeof(*a), GFP_KERNEL); + if (!a) + return -ENOMEM; + + pr_debug("%s dmabuf %p attachment %p\n", __func__, dmabuf, attachment); + + mutex_lock(&buf->lock); + + INIT_LIST_HEAD(&a->list); + + sgt =3D &a->sg_table; + + /* Copy the buf->base_sgt scatter list to the attachment, as we can't + * map the same scatter list to multiple attachments at the same time. + */ + ret =3D sg_alloc_table(sgt, buf->alloc.sg_table->orig_nents, GFP_KERNEL); + if (ret) { + kfree(a); + mutex_unlock(&buf->lock); + return -ENOMEM; + } + + rd =3D buf->alloc.sg_table->sgl; + wr =3D sgt->sgl; + for (i =3D 0; i < sgt->orig_nents; ++i) { + sg_set_page(wr, sg_page(rd), rd->length, rd->offset); + rd =3D sg_next(rd); + wr =3D sg_next(wr); + } + + a->dma_dir =3D DMA_NONE; + attachment->priv =3D a; + + list_add(&a->list, &buf->attachments); + mutex_unlock(&buf->lock); + + return 0; +} + +static void vc_sm_dma_buf_detach(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct vc_sm_dma_buf_attachment *a =3D attachment->priv; + struct vc_sm_buffer *buf =3D dmabuf->priv; + struct sg_table *sgt; + + pr_debug("%s dmabuf %p attachment %p\n", __func__, dmabuf, attachment); + if (!a) + return; + + sgt =3D &a->sg_table; + + /* release the scatterlist cache */ + if (a->dma_dir !=3D DMA_NONE) + dma_unmap_sg(attachment->dev, sgt->sgl, sgt->orig_nents, + a->dma_dir); + sg_free_table(sgt); + + mutex_lock(&buf->lock); + list_del(&a->list); + mutex_unlock(&buf->lock); + + kfree(a); +} + +static struct sg_table *vc_sm_map_dma_buf(struct dma_buf_attachment *attac= hment, + enum dma_data_direction direction) +{ + struct vc_sm_dma_buf_attachment *a =3D attachment->priv; + /* stealing dmabuf mutex to serialize map/unmap operations */ + struct sg_table *table; + + pr_debug("%s attachment %p\n", __func__, attachment); + table =3D &a->sg_table; + + /* return previously mapped sg table */ + if (a->dma_dir =3D=3D direction) + return table; + + /* release any previous cache */ + if (a->dma_dir !=3D DMA_NONE) { + dma_unmap_sg(attachment->dev, table->sgl, table->orig_nents, + a->dma_dir); + a->dma_dir =3D DMA_NONE; + } + + /* mapping to the client with new direction */ + table->nents =3D dma_map_sg(attachment->dev, table->sgl, + table->orig_nents, direction); + if (!table->nents) { + pr_err("failed to map scatterlist\n"); + return ERR_PTR(-EIO); + } + + a->dma_dir =3D direction; + + pr_debug("%s attachment %p\n", __func__, attachment); + return table; +} + +static void vc_sm_unmap_dma_buf(struct dma_buf_attachment *attachment, + struct sg_table *table, + enum dma_data_direction direction) +{ + pr_debug("%s attachment %p\n", __func__, attachment); + dma_unmap_sg(attachment->dev, table->sgl, table->nents, direction); +} + +static int vc_sm_dmabuf_mmap(struct dma_buf *dmabuf, struct vm_area_struct= *vma) +{ + struct vc_sm_buffer *buf =3D dmabuf->priv; + int ret; + + pr_debug("%s dmabuf %p, buf %p, vm_start %08lX\n", __func__, dmabuf, + buf, vma->vm_start); + + /* now map it to userspace */ + vma->vm_pgoff =3D 0; + + ret =3D dma_mmap_coherent(&sm_state->device->dev, vma, buf->cookie, + buf->dma_addr, buf->size); + + if (ret) { + pr_err("Remapping memory failed, error: %d\n", ret); + return ret; + } + + vm_flags_reset(vma, vma->vm_flags | VM_DONTEXPAND | VM_DONTDUMP); + + if (ret) + pr_err("%s: failure mapping buffer to userspace\n", + __func__); + + return ret; +} + +static void vc_sm_dma_buf_release(struct dma_buf *dmabuf) +{ + struct vc_sm_buffer *buffer; + + if (!dmabuf) + return; + + buffer =3D (struct vc_sm_buffer *)dmabuf->priv; + + mutex_lock(&buffer->lock); + + pr_debug("%s dmabuf %p, buffer %p\n", __func__, dmabuf, buffer); + + buffer->in_use =3D false; + + /* Unmap on the VPU */ + vc_sm_vpu_free(buffer); + pr_debug("%s vpu_free done\n", __func__); + + /* Unmap our dma_buf object (the vc_sm_buffer remains until released + * on the VPU). + */ + vc_sm_clean_up_dmabuf(buffer); + pr_debug("%s clean_up dmabuf done\n", __func__); + + /* buffer->lock will be destroyed by vc_sm_release_resource if finished + * with, otherwise unlocked. Do NOT unlock here. + */ + vc_sm_release_resource(buffer); + pr_debug("%s done\n", __func__); +} + +static int vc_sm_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + struct vc_sm_buffer *buf; + struct vc_sm_dma_buf_attachment *a; + + if (!dmabuf) + return -EFAULT; + + buf =3D dmabuf->priv; + if (!buf) + return -EFAULT; + + mutex_lock(&buf->lock); + + list_for_each_entry(a, &buf->attachments, list) { + dma_sync_sg_for_cpu(a->dev, a->sg_table.sgl, + a->sg_table.nents, direction); + } + mutex_unlock(&buf->lock); + + return 0; +} + +static int vc_sm_dma_buf_end_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + struct vc_sm_buffer *buf; + struct vc_sm_dma_buf_attachment *a; + + if (!dmabuf) + return -EFAULT; + buf =3D dmabuf->priv; + if (!buf) + return -EFAULT; + + mutex_lock(&buf->lock); + + list_for_each_entry(a, &buf->attachments, list) { + dma_sync_sg_for_device(a->dev, a->sg_table.sgl, + a->sg_table.nents, direction); + } + mutex_unlock(&buf->lock); + + return 0; +} + +static const struct dma_buf_ops dma_buf_ops =3D { + .map_dma_buf =3D vc_sm_map_dma_buf, + .unmap_dma_buf =3D vc_sm_unmap_dma_buf, + .mmap =3D vc_sm_dmabuf_mmap, + .release =3D vc_sm_dma_buf_release, + .attach =3D vc_sm_dma_buf_attach, + .detach =3D vc_sm_dma_buf_detach, + .begin_cpu_access =3D vc_sm_dma_buf_begin_cpu_access, + .end_cpu_access =3D vc_sm_dma_buf_end_cpu_access, +}; + +/* Dma_buf operations for chaining through to an imported dma_buf */ + +static +int vc_sm_import_dma_buf_attach(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct vc_sm_buffer *buf =3D dmabuf->priv; + + if (!buf->imported) + return -EINVAL; + return buf->import.dma_buf->ops->attach(buf->import.dma_buf, + attachment); +} + +static +void vc_sm_import_dma_buf_detatch(struct dma_buf *dmabuf, + struct dma_buf_attachment *attachment) +{ + struct vc_sm_buffer *buf =3D dmabuf->priv; + + if (!buf->imported) + return; + buf->import.dma_buf->ops->detach(buf->import.dma_buf, attachment); +} + +static +struct sg_table *vc_sm_import_map_dma_buf(struct dma_buf_attachment *attac= hment, + enum dma_data_direction direction) +{ + struct vc_sm_buffer *buf =3D attachment->dmabuf->priv; + + if (!buf->imported) + return NULL; + return buf->import.dma_buf->ops->map_dma_buf(attachment, + direction); +} + +static +void vc_sm_import_unmap_dma_buf(struct dma_buf_attachment *attachment, + struct sg_table *table, + enum dma_data_direction direction) +{ + struct vc_sm_buffer *buf =3D attachment->dmabuf->priv; + + if (!buf->imported) + return; + buf->import.dma_buf->ops->unmap_dma_buf(attachment, table, direction); +} + +static +int vc_sm_import_dmabuf_mmap(struct dma_buf *dmabuf, struct vm_area_struct= *vma) +{ + struct vc_sm_buffer *buf =3D dmabuf->priv; + + pr_debug("%s: mmap dma_buf %p, buf %p, imported db %p\n", __func__, + dmabuf, buf, buf->import.dma_buf); + if (!buf->imported) { + pr_err("%s: mmap dma_buf %p- not an imported buffer\n", + __func__, dmabuf); + return -EINVAL; + } + return buf->import.dma_buf->ops->mmap(buf->import.dma_buf, vma); +} + +static +int vc_sm_import_dma_buf_begin_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + struct vc_sm_buffer *buf =3D dmabuf->priv; + + if (!buf->imported) + return -EINVAL; + return buf->import.dma_buf->ops->begin_cpu_access(buf->import.dma_buf, + direction); +} + +static +int vc_sm_import_dma_buf_end_cpu_access(struct dma_buf *dmabuf, + enum dma_data_direction direction) +{ + struct vc_sm_buffer *buf =3D dmabuf->priv; + + if (!buf->imported) + return -EINVAL; + return buf->import.dma_buf->ops->end_cpu_access(buf->import.dma_buf, + direction); +} + +static const struct dma_buf_ops dma_buf_import_ops =3D { + .map_dma_buf =3D vc_sm_import_map_dma_buf, + .unmap_dma_buf =3D vc_sm_import_unmap_dma_buf, + .mmap =3D vc_sm_import_dmabuf_mmap, + .release =3D vc_sm_dma_buf_release, + .attach =3D vc_sm_import_dma_buf_attach, + .detach =3D vc_sm_import_dma_buf_detatch, + .begin_cpu_access =3D vc_sm_import_dma_buf_begin_cpu_access, + .end_cpu_access =3D vc_sm_import_dma_buf_end_cpu_access, +}; + +/* Import a dma_buf to be shared with VC. */ +static int +vc_sm_cma_import_dmabuf_internal(struct vc_sm_privdata_t *private, + struct dma_buf *dma_buf, + int fd, + struct dma_buf **imported_buf) +{ + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct vc_sm_buffer *buffer =3D NULL; + struct vc_sm_import import =3D { }; + struct vc_sm_import_result result =3D { }; + struct dma_buf_attachment *attach =3D NULL; + struct sg_table *sgt =3D NULL; + dma_addr_t dma_addr; + u32 cache_alias; + int ret =3D 0; + int status; + + /* Setup our allocation parameters */ + pr_debug("%s: importing dma_buf %p/fd %d\n", __func__, dma_buf, fd); + + if (fd < 0) + get_dma_buf(dma_buf); + else + dma_buf =3D dma_buf_get(fd); + + if (!dma_buf) + return -EINVAL; + + attach =3D dma_buf_attach(dma_buf, &sm_state->device->dev); + if (IS_ERR(attach)) { + ret =3D PTR_ERR(attach); + goto error; + } + + sgt =3D dma_buf_map_attachment_unlocked(attach, DMA_BIDIRECTIONAL); + if (IS_ERR(sgt)) { + ret =3D PTR_ERR(sgt); + goto error; + } + + /* Verify that the address block is contiguous */ + if (sgt->nents !=3D 1) { + ret =3D -ENOMEM; + goto error; + } + + /* Allocate local buffer to track this allocation. */ + buffer =3D kzalloc(sizeof(*buffer), GFP_KERNEL); + if (!buffer) { + ret =3D -ENOMEM; + goto error; + } + + import.type =3D VC_SM_ALLOC_NON_CACHED; + dma_addr =3D sg_dma_address(sgt->sgl); + import.addr =3D (u32)dma_addr; + cache_alias =3D import.addr & 0xC0000000; + if (cache_alias !=3D 0xC0000000 && cache_alias !=3D 0x80000000) { + pr_err("%s: Expecting an uncached alias for dma_addr %pad\n", + __func__, &dma_addr); + /* Note that this assumes we're on >=3D Pi2, but it implies a + * DT configuration error. + */ + import.addr |=3D 0xC0000000; + } + import.size =3D sg_dma_len(sgt->sgl); + import.allocator =3D current->tgid; + import.kernel_id =3D get_kernel_id(buffer); + + memcpy(import.name, VC_SM_RESOURCE_NAME_DEFAULT, + sizeof(VC_SM_RESOURCE_NAME_DEFAULT)); + + pr_debug("[%s]: attempt to import \"%s\" data - type %u, addr %pad, size = %u.\n", + __func__, import.name, import.type, &dma_addr, import.size); + + /* Allocate the videocore buffer. */ + status =3D vc_sm_cma_vchi_import(sm_state->sm_handle, &import, &result, + &sm_state->int_trans_id); + if (status =3D=3D -EINTR) { + pr_debug("[%s]: requesting import memory action restart (trans_id: %u)\n= ", + __func__, sm_state->int_trans_id); + ret =3D -ERESTARTSYS; + private->restart_sys =3D -EINTR; + private->int_action =3D VC_SM_MSG_TYPE_IMPORT; + goto error; + } else if (status || !result.res_handle) { + pr_debug("[%s]: failed to import memory on videocore (status: %u, trans_= id: %u)\n", + __func__, status, sm_state->int_trans_id); + ret =3D -ENOMEM; + goto error; + } + + mutex_init(&buffer->lock); + INIT_LIST_HEAD(&buffer->attachments); + memcpy(buffer->name, import.name, + min(sizeof(buffer->name), sizeof(import.name) - 1)); + + /* Keep track of the buffer we created. */ + buffer->private =3D private; + buffer->vc_handle =3D result.res_handle; + buffer->size =3D import.size; + buffer->vpu_state =3D VPU_MAPPED; + + buffer->imported =3D true; + buffer->import.dma_buf =3D dma_buf; + + buffer->import.attach =3D attach; + buffer->import.sgt =3D sgt; + buffer->dma_addr =3D dma_addr; + buffer->in_use =3D true; + buffer->kernel_id =3D import.kernel_id; + + /* + * We're done - we need to export a new dmabuf chaining through most + * functions, but enabling us to release our own internal references + * here. + */ + exp_info.ops =3D &dma_buf_import_ops; + exp_info.size =3D import.size; + exp_info.flags =3D O_RDWR; + exp_info.priv =3D buffer; + + buffer->dma_buf =3D dma_buf_export(&exp_info); + if (IS_ERR(buffer->dma_buf)) { + ret =3D PTR_ERR(buffer->dma_buf); + goto error; + } + + vc_sm_add_resource(private, buffer); + + *imported_buf =3D buffer->dma_buf; + + return 0; + +error: + if (result.res_handle) { + struct vc_sm_free_t free =3D { result.res_handle, 0 }; + + vc_sm_cma_vchi_free(sm_state->sm_handle, &free, + &sm_state->int_trans_id); + } + free_kernel_id(import.kernel_id); + kfree(buffer); + if (sgt) + dma_buf_unmap_attachment_unlocked(attach, sgt, DMA_BIDIRECTIONAL); + if (attach) + dma_buf_detach(dma_buf, attach); + dma_buf_put(dma_buf); + return ret; +} + +static int vc_sm_cma_vpu_alloc(u32 size, u32 align, const char *name, + u32 mem_handle, struct vc_sm_buffer **ret_buffer) +{ + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct vc_sm_buffer *buffer =3D NULL; + struct sg_table *sgt; + int aligned_size; + int ret =3D 0; + + /* Align to the user requested align */ + aligned_size =3D ALIGN(size, align); + /* and then to a page boundary */ + aligned_size =3D PAGE_ALIGN(aligned_size); + + if (!aligned_size) + return -EINVAL; + + /* Allocate local buffer to track this allocation. */ + buffer =3D kzalloc(sizeof(*buffer), GFP_KERNEL); + if (!buffer) + return -ENOMEM; + + mutex_init(&buffer->lock); + /* Acquire the mutex as vc_sm_release_resource will release it in the + * error path. + */ + mutex_lock(&buffer->lock); + + buffer->cookie =3D dma_alloc_coherent(&sm_state->device->dev, + aligned_size, &buffer->dma_addr, + GFP_KERNEL); + if (!buffer->cookie) { + pr_err("[%s]: dma_alloc_coherent alloc of %d bytes failed\n", + __func__, aligned_size); + ret =3D -ENOMEM; + goto error; + } + + pr_debug("[%s]: alloc of %d bytes success\n", + __func__, aligned_size); + + sgt =3D kmalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) { + ret =3D -ENOMEM; + goto error; + } + + ret =3D dma_get_sgtable(&sm_state->device->dev, sgt, buffer->cookie, + buffer->dma_addr, buffer->size); + if (ret < 0) { + pr_err("failed to get scatterlist from DMA API\n"); + kfree(sgt); + ret =3D -ENOMEM; + goto error; + } + buffer->alloc.sg_table =3D sgt; + + INIT_LIST_HEAD(&buffer->attachments); + + memcpy(buffer->name, name, + min(sizeof(buffer->name), strlen(name))); + + exp_info.ops =3D &dma_buf_ops; + exp_info.size =3D aligned_size; + exp_info.flags =3D O_RDWR; + exp_info.priv =3D buffer; + + buffer->dma_buf =3D dma_buf_export(&exp_info); + if (IS_ERR(buffer->dma_buf)) { + ret =3D PTR_ERR(buffer->dma_buf); + goto error; + } + buffer->dma_addr =3D (u32)sg_dma_address(buffer->alloc.sg_table->sgl); + if ((buffer->dma_addr & 0xC0000000) !=3D 0xC0000000) { + pr_warn_once("%s: Expecting an uncached alias for dma_addr %pad\n", + __func__, &buffer->dma_addr); + buffer->dma_addr |=3D 0xC0000000; + } + buffer->private =3D sm_state->vpu_allocs; + + buffer->vc_handle =3D mem_handle; + buffer->vpu_state =3D VPU_MAPPED; + buffer->vpu_allocated =3D 1; + buffer->size =3D size; + /* + * Create an ID that will be passed along with our message so + * that when we service the release reply, we can look up which + * resource is being released. + */ + buffer->kernel_id =3D get_kernel_id(buffer); + + vc_sm_add_resource(sm_state->vpu_allocs, buffer); + + mutex_unlock(&buffer->lock); + + *ret_buffer =3D buffer; + return 0; +error: + if (buffer) + vc_sm_release_resource(buffer); + return ret; +} + +static void +vc_sm_vpu_event(struct sm_instance *instance, struct vc_sm_result_t *reply, + int reply_len) +{ + switch (reply->trans_id & ~0x80000000) { + case VC_SM_MSG_TYPE_CLIENT_VERSION: + { + /* Acknowledge that the firmware supports the version command */ + pr_debug("%s: firmware acked version msg. Require release cb\n", + __func__); + sm_state->require_released_callback =3D true; + } + break; + case VC_SM_MSG_TYPE_RELEASED: + { + struct vc_sm_released *release =3D (struct vc_sm_released *)reply; + struct vc_sm_buffer *buffer =3D + lookup_kernel_id(release->kernel_id); + if (!buffer) { + pr_err("%s: VC released a buffer that is already released, kernel_id %d= \n", + __func__, release->kernel_id); + break; + } + mutex_lock(&buffer->lock); + + pr_debug("%s: Released addr %08x, size %u, id %08x, mem_handle %08x\n", + __func__, release->addr, release->size, + release->kernel_id, release->vc_handle); + + buffer->vc_handle =3D 0; + buffer->vpu_state =3D VPU_NOT_MAPPED; + free_kernel_id(release->kernel_id); + + if (buffer->vpu_allocated) { + /* VPU allocation, so release the dmabuf which will + * trigger the clean up. + */ + mutex_unlock(&buffer->lock); + dma_buf_put(buffer->dma_buf); + } else { + vc_sm_release_resource(buffer); + } + } + break; + case VC_SM_MSG_TYPE_VC_MEM_REQUEST: + { + struct vc_sm_buffer *buffer =3D NULL; + struct vc_sm_vc_mem_request *req =3D + (struct vc_sm_vc_mem_request *)reply; + struct vc_sm_vc_mem_request_result reply; + int ret; + + pr_debug("%s: Request %u bytes of memory, align %d name %s, trans_id %08= x\n", + __func__, req->size, req->align, req->name, + req->trans_id); + ret =3D vc_sm_cma_vpu_alloc(req->size, req->align, req->name, + req->vc_handle, &buffer); + + reply.trans_id =3D req->trans_id; + if (!ret) { + reply.addr =3D buffer->dma_addr; + reply.kernel_id =3D buffer->kernel_id; + pr_debug("%s: Allocated resource buffer %p, addr %pad\n", + __func__, buffer, &buffer->dma_addr); + } else { + pr_err("%s: Allocation failed size %u, name %s, vc_handle %u\n", + __func__, req->size, req->name, req->vc_handle); + reply.addr =3D 0; + reply.kernel_id =3D 0; + } + vc_sm_vchi_client_vc_mem_req_reply(sm_state->sm_handle, &reply, + &sm_state->int_trans_id); + break; + } + break; + default: + pr_err("%s: Unknown vpu cmd %x\n", __func__, reply->trans_id); + break; + } +} + +/* Userspace handling */ +/* + * Open the device. Creates a private state to help track all allocation + * associated with this device. + */ +static int vc_sm_cma_open(struct inode *inode, struct file *file) +{ + /* Make sure the device was started properly. */ + if (!sm_state) { + pr_err("[%s]: invalid device\n", __func__); + return -EPERM; + } + + file->private_data =3D vc_sm_cma_create_priv_data(current->tgid); + if (!file->private_data) { + pr_err("[%s]: failed to create data tracker\n", __func__); + + return -ENOMEM; + } + + return 0; +} + +/* + * Close the vcsm-cma device. + * All allocations are file descriptors to the dmabuf objects, so we will = get + * the clean up request on those as those are cleaned up. + */ +static int vc_sm_cma_release(struct inode *inode, struct file *file) +{ + struct vc_sm_privdata_t *file_data =3D + (struct vc_sm_privdata_t *)file->private_data; + int ret =3D 0; + + /* Make sure the device was started properly. */ + if (!sm_state || !file_data) { + pr_err("[%s]: invalid device\n", __func__); + ret =3D -EPERM; + goto out; + } + + pr_debug("[%s]: using private data %p\n", __func__, file_data); + + /* Terminate the private data. */ + kfree(file_data); + +out: + return ret; +} + +/* + * Allocate a shared memory handle and block. + * Allocation is from CMA, and then imported into the VPU mappings. + */ +static int vc_sm_cma_ioctl_alloc(struct vc_sm_privdata_t *private, + struct vc_sm_cma_ioctl_alloc *ioparam) +{ + DEFINE_DMA_BUF_EXPORT_INFO(exp_info); + struct vc_sm_buffer *buffer =3D NULL; + struct vc_sm_import import =3D { 0 }; + struct vc_sm_import_result result =3D { 0 }; + struct dma_buf *dmabuf =3D NULL; + struct sg_table *sgt; + int aligned_size; + int ret =3D 0; + int status; + int fd =3D -1; + + aligned_size =3D PAGE_ALIGN(ioparam->size); + + if (!aligned_size) + return -EINVAL; + + /* Allocate local buffer to track this allocation. */ + buffer =3D kzalloc(sizeof(*buffer), GFP_KERNEL); + if (!buffer) { + ret =3D -ENOMEM; + goto error; + } + + buffer->cookie =3D dma_alloc_coherent(&sm_state->device->dev, + aligned_size, + &buffer->dma_addr, + GFP_KERNEL); + if (!buffer->cookie) { + pr_err("[%s]: dma_alloc_coherent alloc of %d bytes failed\n", + __func__, aligned_size); + ret =3D -ENOMEM; + goto error; + } + + import.type =3D VC_SM_ALLOC_NON_CACHED; + import.allocator =3D current->tgid; + + if (*ioparam->name) + memcpy(import.name, ioparam->name, sizeof(import.name) - 1); + else + memcpy(import.name, VC_SM_RESOURCE_NAME_DEFAULT, + sizeof(VC_SM_RESOURCE_NAME_DEFAULT)); + + mutex_init(&buffer->lock); + INIT_LIST_HEAD(&buffer->attachments); + memcpy(buffer->name, import.name, + min(sizeof(buffer->name), sizeof(import.name) - 1)); + + exp_info.ops =3D &dma_buf_ops; + exp_info.size =3D aligned_size; + exp_info.flags =3D O_RDWR; + exp_info.priv =3D buffer; + + dmabuf =3D dma_buf_export(&exp_info); + if (IS_ERR(dmabuf)) { + ret =3D PTR_ERR(dmabuf); + goto error; + } + buffer->dma_buf =3D dmabuf; + + import.addr =3D buffer->dma_addr; + import.size =3D aligned_size; + import.kernel_id =3D get_kernel_id(buffer); + + /* Wrap it into a videocore buffer. */ + status =3D vc_sm_cma_vchi_import(sm_state->sm_handle, &import, &result, + &sm_state->int_trans_id); + if (status =3D=3D -EINTR) { + pr_debug("[%s]: requesting import memory action restart (trans_id: %u)\n= ", + __func__, sm_state->int_trans_id); + ret =3D -ERESTARTSYS; + private->restart_sys =3D -EINTR; + private->int_action =3D VC_SM_MSG_TYPE_IMPORT; + goto error; + } else if (status || !result.res_handle) { + pr_err("[%s]: failed to import memory on videocore (status: %u, trans_id= : %u)\n", + __func__, status, sm_state->int_trans_id); + ret =3D -ENOMEM; + goto error; + } + + /* Keep track of the buffer we created. */ + buffer->private =3D private; + buffer->vc_handle =3D result.res_handle; + buffer->size =3D import.size; + buffer->vpu_state =3D VPU_MAPPED; + buffer->kernel_id =3D import.kernel_id; + + sgt =3D kmalloc(sizeof(*sgt), GFP_KERNEL); + if (!sgt) { + ret =3D -ENOMEM; + goto error; + } + + ret =3D dma_get_sgtable(&sm_state->device->dev, sgt, buffer->cookie, + buffer->dma_addr, buffer->size); + if (ret < 0) { + /* FIXME: error handling */ + pr_err("failed to get scatterlist from DMA API\n"); + kfree(sgt); + ret =3D -ENOMEM; + goto error; + } + buffer->alloc.sg_table =3D sgt; + + fd =3D dma_buf_fd(dmabuf, O_CLOEXEC); + if (fd < 0) + goto error; + + vc_sm_add_resource(private, buffer); + + pr_debug("[%s]: Added resource as fd %d, buffer %p, private %p, dma_addr = %pad\n", + __func__, fd, buffer, private, &buffer->dma_addr); + + /* We're done */ + ioparam->handle =3D fd; + ioparam->vc_handle =3D buffer->vc_handle; + ioparam->dma_addr =3D buffer->dma_addr; + return 0; + +error: + pr_err("[%s]: something failed - cleanup. ret %d\n", __func__, ret); + + if (dmabuf) { + /* dmabuf has been exported, therefore allow dmabuf cleanup to + * deal with this + */ + dma_buf_put(dmabuf); + } else { + /* No dmabuf, therefore just free the buffer here */ + if (buffer && buffer->cookie) + dma_free_coherent(&sm_state->device->dev, buffer->size, + buffer->cookie, buffer->dma_addr); + kfree(buffer); + } + return ret; +} + +static long vc_sm_cma_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + int ret =3D 0; + unsigned int cmdnr =3D _IOC_NR(cmd); + struct vc_sm_privdata_t *file_data =3D + (struct vc_sm_privdata_t *)file->private_data; + + /* Validate we can work with this device. */ + if (!sm_state || !file_data) { + pr_err("[%s]: invalid device\n", __func__); + return -EPERM; + } + + /* Action is a re-post of a previously interrupted action? */ + if (file_data->restart_sys =3D=3D -EINTR) { + pr_debug("[%s]: clean up of action %u (trans_id: %u) following EINTR\n", + __func__, file_data->int_action, + file_data->int_trans_id); + + file_data->restart_sys =3D 0; + } + + /* Now process the command. */ + switch (cmdnr) { + /* New memory allocation. + */ + case VC_SM_CMA_CMD_ALLOC: + { + struct vc_sm_cma_ioctl_alloc ioparam; + + /* Get the parameter data. */ + if (copy_from_user + (&ioparam, (void *)arg, sizeof(ioparam)) !=3D 0) { + pr_err("[%s]: failed to copy-from-user for cmd %x\n", + __func__, cmdnr); + ret =3D -EFAULT; + break; + } + + ret =3D vc_sm_cma_ioctl_alloc(file_data, &ioparam); + if (!ret && + (copy_to_user((void *)arg, &ioparam, + sizeof(ioparam)) !=3D 0)) { + /* FIXME: Release allocation */ + pr_err("[%s]: failed to copy-to-user for cmd %x\n", + __func__, cmdnr); + ret =3D -EFAULT; + } + break; + } + + case VC_SM_CMA_CMD_IMPORT_DMABUF: + { + struct vc_sm_cma_ioctl_import_dmabuf ioparam; + struct dma_buf *new_dmabuf; + + /* Get the parameter data. */ + if (copy_from_user + (&ioparam, (void *)arg, sizeof(ioparam)) !=3D 0) { + pr_err("[%s]: failed to copy-from-user for cmd %x\n", + __func__, cmdnr); + ret =3D -EFAULT; + break; + } + + ret =3D vc_sm_cma_import_dmabuf_internal(file_data, + NULL, + ioparam.dmabuf_fd, + &new_dmabuf); + + if (!ret) { + struct vc_sm_buffer *buf =3D new_dmabuf->priv; + + ioparam.size =3D buf->size; + ioparam.handle =3D dma_buf_fd(new_dmabuf, + O_CLOEXEC); + ioparam.vc_handle =3D buf->vc_handle; + ioparam.dma_addr =3D buf->dma_addr; + + if (ioparam.handle < 0 || + (copy_to_user((void *)arg, &ioparam, + sizeof(ioparam)) !=3D 0)) { + dma_buf_put(new_dmabuf); + /* FIXME: Release allocation */ + ret =3D -EFAULT; + } + } + break; + } + + default: + pr_debug("[%s]: cmd %x tgid %u, owner %u\n", __func__, cmdnr, + current->tgid, file_data->pid); + + ret =3D -EINVAL; + break; + } + + return ret; +} + +#ifdef CONFIG_COMPAT +struct vc_sm_cma_ioctl_clean_invalid2_32 { + u32 op_count; + struct vc_sm_cma_ioctl_clean_invalid_block_32 { + u16 invalidate_mode; + u16 block_count; + compat_uptr_t start_address; + u32 block_size; + u32 inter_block_stride; + } s[]; +}; + +#define VC_SM_CMA_CMD_CLEAN_INVALID2_32\ + _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_CLEAN_INVALID2,\ + struct vc_sm_cma_ioctl_clean_invalid2_32) + +static long vc_sm_cma_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg) +{ + switch (cmd) { + case VC_SM_CMA_CMD_CLEAN_INVALID2_32: + /* FIXME */ + return -EINVAL; + + default: + return vc_sm_cma_ioctl(file, cmd, arg); + } +} +#endif + +/* Device operations that we managed in this driver. */ +static const struct file_operations vc_sm_ops =3D { + .owner =3D THIS_MODULE, + .unlocked_ioctl =3D vc_sm_cma_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl =3D vc_sm_cma_compat_ioctl, +#endif + .open =3D vc_sm_cma_open, + .release =3D vc_sm_cma_release, +}; + +/* Driver load/unload functions */ +/* Videocore connected. */ +static void vc_sm_connected_init(void) +{ + int ret; + struct vc_sm_version version; + struct vc_sm_result_t version_result; + + /* + * Digging the vchiq_drv_mgmt, so low here and through a global seems + * suspicious. + * + * The callbacks should be able to pass a parameter or context. + */ + struct vchiq_drv_mgmt *mgmt =3D dev_get_drvdata(sm_state->device->dev.par= ent); + + pr_debug("[%s]: start\n", __func__); + + /* + * Initialize and create a VCHI connection for the shared memory service + * running on videocore. + */ + ret =3D vchiq_initialise(&mgmt->state, &sm_state->vchiq_instance); + if (ret) { + pr_err("[%s]: failed to initialise VCHI instance (ret=3D%d)\n", + __func__, ret); + + return; + } + + ret =3D vchiq_connect(sm_state->vchiq_instance); + if (ret) { + pr_err("[%s]: failed to connect VCHI instance (ret=3D%d)\n", + __func__, ret); + + return; + } + + /* Initialize an instance of the shared memory service. */ + sm_state->sm_handle =3D vc_sm_cma_vchi_init(sm_state->vchiq_instance, 1, + vc_sm_vpu_event); + if (!sm_state->sm_handle) { + pr_err("[%s]: failed to initialize shared memory service\n", + __func__); + + return; + } + + /* Create a debug fs directory entry (root). */ + sm_state->dir_root =3D debugfs_create_dir(VC_SM_DIR_ROOT_NAME, NULL); + + sm_state->dir_state.show =3D &vc_sm_cma_global_state_show; + sm_state->dir_state.dir_entry =3D + debugfs_create_file(VC_SM_STATE, 0444, sm_state->dir_root, + &sm_state->dir_state, + &vc_sm_cma_debug_fs_fops); + + INIT_LIST_HEAD(&sm_state->buffer_list); + + /* Create a shared memory device. */ + sm_state->misc_dev.minor =3D MISC_DYNAMIC_MINOR; + sm_state->misc_dev.name =3D DEVICE_NAME; + sm_state->misc_dev.fops =3D &vc_sm_ops; + sm_state->misc_dev.parent =3D NULL; + /* Temporarily set as 666 until udev rules have been sorted */ + sm_state->misc_dev.mode =3D 0666; + ret =3D misc_register(&sm_state->misc_dev); + if (ret) { + pr_err("vcsm-cma: failed to register misc device.\n"); + goto err_remove_debugfs; + } + + sm_state->data_knl =3D vc_sm_cma_create_priv_data(0); + if (!sm_state->data_knl) { + pr_err("[%s]: failed to create kernel private data tracker\n", + __func__); + goto err_remove_misc_dev; + } + + version.version =3D 2; + ret =3D vc_sm_cma_vchi_client_version(sm_state->sm_handle, &version, + &version_result, + &sm_state->int_trans_id); + if (ret) { + pr_err("[%s]: Failed to send version request %d\n", __func__, + ret); + } + + /* Done! */ + sm_inited =3D 1; + pr_debug("[%s]: installed successfully\n", __func__); + return; + +err_remove_misc_dev: + misc_deregister(&sm_state->misc_dev); +err_remove_debugfs: + debugfs_remove_recursive(sm_state->dir_root); + vc_sm_cma_vchi_stop(sm_state->vchiq_instance, &sm_state->sm_handle); +} + +/* Driver loading. */ +static int bcm2835_vc_sm_cma_probe(struct vchiq_device *device) +{ + int err; + + pr_info("%s: Videocore shared memory driver\n", __func__); + + err =3D dma_set_mask_and_coherent(&device->dev, DMA_BIT_MASK(32)); + if (err) { + dev_err(&device->dev, "dma_set_mask_and_coherent failed: %d\n", + err); + return err; + } + + sm_state =3D devm_kzalloc(&device->dev, sizeof(*sm_state), GFP_KERNEL); + if (!sm_state) + return -ENOMEM; + sm_state->device =3D device; + mutex_init(&sm_state->map_lock); + + mutex_init(&sm_state->kernelid_map_lock); + idr_init_base(&sm_state->kernelid_map, 1); + + device->dev.dma_parms =3D devm_kzalloc(&device->dev, + sizeof(*device->dev.dma_parms), + GFP_KERNEL); + /* dma_set_max_seg_size checks if dma_parms is NULL. */ + dma_set_max_seg_size(&device->dev, 0x3FFFFFFF); + + vchiq_add_connected_callback(device, vc_sm_connected_init); + return 0; +} + +/* Driver unloading. */ +static void bcm2835_vc_sm_cma_remove(struct vchiq_device *device) +{ + pr_debug("[%s]: start\n", __func__); + if (sm_inited) { + misc_deregister(&sm_state->misc_dev); + + /* Remove all proc entries. */ + debugfs_remove_recursive(sm_state->dir_root); + + /* Stop the videocore shared memory service. */ + vc_sm_cma_vchi_stop(sm_state->vchiq_instance, &sm_state->sm_handle); + } + + if (sm_state) { + idr_destroy(&sm_state->kernelid_map); + + /* Free the memory for the state structure. */ + mutex_destroy(&sm_state->map_lock); + } + + pr_debug("[%s]: end\n", __func__); +} + +/* Kernel API calls */ +/* Get an internal resource handle mapped from the external one. */ +int vc_sm_cma_int_handle(void *handle) +{ + struct dma_buf *dma_buf =3D (struct dma_buf *)handle; + struct vc_sm_buffer *buf; + + /* Validate we can work with this device. */ + if (!sm_state || !handle) { + pr_err("[%s]: invalid input\n", __func__); + return 0; + } + + buf =3D (struct vc_sm_buffer *)dma_buf->priv; + return buf->vc_handle; +} +EXPORT_SYMBOL_GPL(vc_sm_cma_int_handle); + +/* Free a previously allocated shared memory handle and block. */ +int vc_sm_cma_free(void *handle) +{ + struct dma_buf *dma_buf =3D (struct dma_buf *)handle; + + /* Validate we can work with this device. */ + if (!sm_state || !handle) { + pr_err("[%s]: invalid input\n", __func__); + return -EPERM; + } + + pr_debug("%s: handle %p/dmabuf %p\n", __func__, handle, dma_buf); + + dma_buf_put(dma_buf); + + return 0; +} +EXPORT_SYMBOL_GPL(vc_sm_cma_free); + +/* Import a dmabuf to be shared with VC. */ +int vc_sm_cma_import_dmabuf(struct dma_buf *src_dmabuf, void **handle) +{ + struct dma_buf *new_dma_buf; + int ret; + + /* Validate we can work with this device. */ + if (!sm_state || !src_dmabuf || !handle) { + pr_err("[%s]: invalid input\n", __func__); + return -EPERM; + } + + ret =3D vc_sm_cma_import_dmabuf_internal(sm_state->data_knl, src_dmabuf, + -1, &new_dma_buf); + + if (!ret) { + pr_debug("%s: imported to ptr %p\n", __func__, new_dma_buf); + + /* Assign valid handle at this time.*/ + *handle =3D new_dma_buf; + } else { + /* + * succeeded in importing the dma_buf, but then + * failed to look it up again. How? + * Release the fd again. + */ + pr_err("%s: imported vc_sm_cma_get_buffer failed %d\n", + __func__, ret); + } + + return ret; +} +EXPORT_SYMBOL_GPL(vc_sm_cma_import_dmabuf); + +static struct vchiq_driver bcm2835_vcsm_cma_driver =3D { + .probe =3D bcm2835_vc_sm_cma_probe, + .remove =3D bcm2835_vc_sm_cma_remove, + .driver =3D { + .name =3D DEVICE_NAME, + .owner =3D THIS_MODULE, + }, +}; + +module_vchiq_driver(bcm2835_vcsm_cma_driver); + +MODULE_AUTHOR("Dave Stevenson"); +MODULE_DESCRIPTION("VideoCore CMA Shared Memory Driver"); +MODULE_LICENSE("GPL"); +MODULE_ALIAS("vcsm-cma"); diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.h b/drivers/platf= orm/raspberrypi/vc-sm-cma/vc_sm.h new file mode 100644 index 0000000000000000000000000000000000000000..aba4c0c0c7bb6688b24acc9f1ed= 00566341a28de --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm.h @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * VideoCore Shared Memory driver using CMA. + * + * Copyright: 2018, Raspberry Pi (Trading) Ltd + * + */ + +#ifndef VC_SM_H +#define VC_SM_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define VC_SM_MAX_NAME_LEN 32 + +enum vc_sm_vpu_mapping_state { + VPU_NOT_MAPPED, + VPU_MAPPED, + VPU_UNMAPPING +}; + +struct vc_sm_alloc_data { + unsigned long num_pages; + void *priv_virt; + struct sg_table *sg_table; +}; + +struct vc_sm_imported { + struct dma_buf *dma_buf; + struct dma_buf_attachment *attach; + struct sg_table *sgt; +}; + +struct vc_sm_buffer { + struct list_head global_buffer_list; /* Global list of buffers. */ + + /* Index in the kernel_id idr so that we can find the + * mmal_msg_context again when servicing the VCHI reply. + */ + int kernel_id; + + size_t size; + + /* Lock over all the following state for this buffer */ + struct mutex lock; + struct list_head attachments; + + char name[VC_SM_MAX_NAME_LEN]; + + bool in_use:1; /* Kernel is still using this resource */ + bool imported:1; /* Imported dmabuf */ + + enum vc_sm_vpu_mapping_state vpu_state; + u32 vc_handle; /* VideoCore handle for this buffer */ + int vpu_allocated; /* + * The VPU made this allocation. Release the + * local dma_buf when the VPU releases the + * resource. + */ + + /* DMABUF related fields */ + struct dma_buf *dma_buf; + dma_addr_t dma_addr; + void *cookie; + + struct vc_sm_privdata_t *private; + + union { + struct vc_sm_alloc_data alloc; + struct vc_sm_imported import; + }; +}; + +#endif diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c b/driv= ers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c new file mode 100644 index 0000000000000000000000000000000000000000..cb21becd69fe5ea02aecfc8cda6= 9aaadbaa1c76e --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.c @@ -0,0 +1,513 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * VideoCore Shared Memory CMA allocator + * + * Copyright: 2018, Raspberry Pi (Trading) Ltd + * Copyright 2011-2012 Broadcom Corporation. All rights reserved. + * + * Based on vmcs_sm driver from Broadcom Corporation. + * + */ + +/* ---- Include Files ----------------------------------------------------= - */ +#include +#include +#include +#include +#include +#include +#include +#include + +#include "vc_sm_cma_vchi.h" + +#define VC_SM_VER 1 +#define VC_SM_MIN_VER 0 + +/* ---- Private Constants and Types --------------------------------------= */ + +/* Command blocks come from a pool */ +#define SM_MAX_NUM_CMD_RSP_BLKS 32 + +/* The number of supported connections */ +#define SM_MAX_NUM_CONNECTIONS 3 + +struct sm_cmd_rsp_blk { + struct list_head head; /* To create lists */ + /* To be signaled when the response is there */ + struct completion cmplt; + + u32 id; + u16 length; + + u8 msg[VC_SM_MAX_MSG_LEN]; + + uint32_t wait:1; + uint32_t sent:1; + uint32_t alloc:1; + +}; + +struct sm_instance { + u32 num_connections; + unsigned int service_handle[SM_MAX_NUM_CONNECTIONS]; + struct task_struct *io_thread; + struct completion io_cmplt; + + vpu_event_cb vpu_event; + + /* Mutex over the following lists */ + struct mutex lock; + u32 trans_id; + struct list_head cmd_list; + struct list_head rsp_list; + struct list_head dead_list; + + struct sm_cmd_rsp_blk free_blk[SM_MAX_NUM_CMD_RSP_BLKS]; + + /* Mutex over the free_list */ + struct mutex free_lock; + struct list_head free_list; + + struct semaphore free_sema; + struct vchiq_instance *vchiq_instance; +}; + +/* ---- Private Variables ------------------------------------------------= */ + +/* ---- Private Function Prototypes --------------------------------------= */ + +/* ---- Private Functions ------------------------------------------------= */ +static int +bcm2835_vchi_msg_queue(struct vchiq_instance *vchiq_instance, unsigned int= handle, + void *data, + unsigned int size) +{ + return vchiq_queue_kernel_message(vchiq_instance, handle, data, size); +} + +static struct +sm_cmd_rsp_blk *vc_vchi_cmd_create(struct sm_instance *instance, + enum vc_sm_msg_type id, void *msg, + u32 size, int wait) +{ + struct sm_cmd_rsp_blk *blk; + struct vc_sm_msg_hdr_t *hdr; + + if (down_interruptible(&instance->free_sema)) { + blk =3D kmalloc(sizeof(*blk), GFP_KERNEL); + if (!blk) + return NULL; + + blk->alloc =3D 1; + init_completion(&blk->cmplt); + } else { + mutex_lock(&instance->free_lock); + blk =3D + list_first_entry(&instance->free_list, + struct sm_cmd_rsp_blk, head); + list_del(&blk->head); + mutex_unlock(&instance->free_lock); + } + + blk->sent =3D 0; + blk->wait =3D wait; + blk->length =3D sizeof(*hdr) + size; + + hdr =3D (struct vc_sm_msg_hdr_t *)blk->msg; + hdr->type =3D id; + mutex_lock(&instance->lock); + instance->trans_id++; + /* + * Retain the top bit for identifying asynchronous events, or VPU cmds. + */ + instance->trans_id &=3D ~0x80000000; + hdr->trans_id =3D instance->trans_id; + blk->id =3D instance->trans_id; + mutex_unlock(&instance->lock); + + if (size) + memcpy(hdr->body, msg, size); + + return blk; +} + +static void +vc_vchi_cmd_delete(struct sm_instance *instance, struct sm_cmd_rsp_blk *bl= k) +{ + if (blk->alloc) { + kfree(blk); + return; + } + + mutex_lock(&instance->free_lock); + list_add(&blk->head, &instance->free_list); + mutex_unlock(&instance->free_lock); + up(&instance->free_sema); +} + +static void vc_sm_cma_vchi_rx_ack(struct sm_instance *instance, + struct sm_cmd_rsp_blk *cmd, + struct vc_sm_result_t *reply, + u32 reply_len) +{ + mutex_lock(&instance->lock); + list_for_each_entry(cmd, + &instance->rsp_list, + head) { + if (cmd->id =3D=3D reply->trans_id) + break; + } + mutex_unlock(&instance->lock); + + if (&cmd->head =3D=3D &instance->rsp_list) { + //pr_debug("%s: received response %u, throw away...", + pr_err("%s: received response %u, throw away...", + __func__, + reply->trans_id); + } else if (reply_len > sizeof(cmd->msg)) { + pr_err("%s: reply too big (%u) %u, throw away...", + __func__, reply_len, + reply->trans_id); + } else { + memcpy(cmd->msg, reply, + reply_len); + complete(&cmd->cmplt); + } +} + +static int vc_sm_cma_vchi_videocore_io(void *arg) +{ + struct sm_instance *instance =3D arg; + struct sm_cmd_rsp_blk *cmd =3D NULL, *cmd_tmp; + struct vc_sm_result_t *reply; + struct vchiq_header *header; + s32 status; + int svc_use =3D 1; + + while (1) { + if (svc_use) + vchiq_release_service(instance->vchiq_instance, + instance->service_handle[0]); + svc_use =3D 0; + + if (wait_for_completion_interruptible(&instance->io_cmplt)) + continue; + vchiq_use_service(instance->vchiq_instance, instance->service_handle[0]); + svc_use =3D 1; + + do { + /* + * Get new command and move it to response list + */ + mutex_lock(&instance->lock); + if (list_empty(&instance->cmd_list)) { + /* no more commands to process */ + mutex_unlock(&instance->lock); + break; + } + cmd =3D list_first_entry(&instance->cmd_list, + struct sm_cmd_rsp_blk, head); + list_move(&cmd->head, &instance->rsp_list); + cmd->sent =3D 1; + mutex_unlock(&instance->lock); + /* Send the command */ + status =3D + bcm2835_vchi_msg_queue(instance->vchiq_instance, + instance->service_handle[0], + cmd->msg, cmd->length); + if (status) { + pr_err("%s: failed to queue message (%d)", + __func__, status); + } + + /* If no reply is needed then we're done */ + if (!cmd->wait) { + mutex_lock(&instance->lock); + list_del(&cmd->head); + mutex_unlock(&instance->lock); + vc_vchi_cmd_delete(instance, cmd); + continue; + } + + if (status) { + complete(&cmd->cmplt); + continue; + } + + } while (1); + + while ((header =3D vchiq_msg_hold(instance->vchiq_instance, + instance->service_handle[0]))) { + reply =3D (struct vc_sm_result_t *)header->data; + if (reply->trans_id & 0x80000000) { + /* Async event or cmd from the VPU */ + if (instance->vpu_event) + instance->vpu_event(instance, reply, + header->size); + } else { + vc_sm_cma_vchi_rx_ack(instance, cmd, reply, + header->size); + } + + vchiq_release_message(instance->vchiq_instance, + instance->service_handle[0], + header); + } + + /* Go through the dead list and free them */ + mutex_lock(&instance->lock); + list_for_each_entry_safe(cmd, cmd_tmp, &instance->dead_list, + head) { + list_del(&cmd->head); + vc_vchi_cmd_delete(instance, cmd); + } + mutex_unlock(&instance->lock); + } + + return 0; +} + +static int vc_sm_cma_vchi_callback(struct vchiq_instance *vchiq_instance, + enum vchiq_reason reason, + struct vchiq_header *header, + unsigned int handle, void *userdata, + void __user *cb_userdata) +{ + struct sm_instance *instance =3D vchiq_get_service_userdata(vchiq_instanc= e, handle); + + switch (reason) { + case VCHIQ_MESSAGE_AVAILABLE: + vchiq_msg_queue_push(vchiq_instance, handle, header); + complete(&instance->io_cmplt); + break; + + case VCHIQ_SERVICE_CLOSED: + pr_info("%s: service CLOSED!!", __func__); + break; + + default: + break; + } + + return 0; +} + +struct sm_instance *vc_sm_cma_vchi_init(struct vchiq_instance *vchiq_insta= nce, + unsigned int num_connections, + vpu_event_cb vpu_event) +{ + u32 i; + struct sm_instance *instance; + int status; + + pr_debug("%s: start", __func__); + + if (num_connections > SM_MAX_NUM_CONNECTIONS) { + pr_err("%s: unsupported number of connections %u (max=3D%u)", + __func__, num_connections, SM_MAX_NUM_CONNECTIONS); + + goto err_null; + } + /* Allocate memory for this instance */ + instance =3D kzalloc(sizeof(*instance), GFP_KERNEL); + + /* Misc initialisations */ + mutex_init(&instance->lock); + init_completion(&instance->io_cmplt); + INIT_LIST_HEAD(&instance->cmd_list); + INIT_LIST_HEAD(&instance->rsp_list); + INIT_LIST_HEAD(&instance->dead_list); + INIT_LIST_HEAD(&instance->free_list); + sema_init(&instance->free_sema, SM_MAX_NUM_CMD_RSP_BLKS); + mutex_init(&instance->free_lock); + for (i =3D 0; i < SM_MAX_NUM_CMD_RSP_BLKS; i++) { + init_completion(&instance->free_blk[i].cmplt); + list_add(&instance->free_blk[i].head, &instance->free_list); + } + + instance->vchiq_instance =3D vchiq_instance; + + /* Open the VCHI service connections */ + instance->num_connections =3D num_connections; + for (i =3D 0; i < num_connections; i++) { + struct vchiq_service_params_kernel params =3D { + .version =3D VC_SM_VER, + .version_min =3D VC_SM_MIN_VER, + .fourcc =3D VCHIQ_MAKE_FOURCC('S', 'M', 'E', 'M'), + .callback =3D vc_sm_cma_vchi_callback, + .userdata =3D instance, + }; + + status =3D vchiq_open_service(vchiq_instance, ¶ms, + &instance->service_handle[i]); + if (status) { + pr_err("%s: failed to open VCHI service (%d)", + __func__, status); + + goto err_close_services; + } + } + /* Create the thread which takes care of all io to/from videoocore. */ + instance->io_thread =3D kthread_create(&vc_sm_cma_vchi_videocore_io, + (void *)instance, "SMIO"); + if (!instance->io_thread) { + pr_err("%s: failed to create SMIO thread", __func__); + + goto err_close_services; + } + instance->vpu_event =3D vpu_event; + set_user_nice(instance->io_thread, -10); + wake_up_process(instance->io_thread); + + pr_debug("%s: success - instance %p", __func__, instance); + return instance; + +err_close_services: + for (i =3D 0; i < instance->num_connections; i++) { + if (instance->service_handle[i]) + vchiq_close_service(vchiq_instance, instance->service_handle[i]); + } + kfree(instance); +err_null: + pr_debug("%s: FAILED", __func__); + return NULL; +} + +int vc_sm_cma_vchi_stop(struct vchiq_instance *vchiq_instance, struct sm_i= nstance **handle) +{ + struct sm_instance *instance; + u32 i; + + if (!handle) { + pr_err("%s: invalid pointer to handle %p", __func__, handle); + goto lock; + } + + if (!*handle) { + pr_err("%s: invalid handle %p", __func__, *handle); + goto lock; + } + + instance =3D *handle; + + /* Close all VCHI service connections */ + for (i =3D 0; i < instance->num_connections; i++) { + vchiq_use_service(vchiq_instance, instance->service_handle[i]); + vchiq_close_service(vchiq_instance, instance->service_handle[i]); + } + + kfree(instance); + + *handle =3D NULL; + return 0; + +lock: + return -EINVAL; +} + +static int vc_sm_cma_vchi_send_msg(struct sm_instance *handle, + enum vc_sm_msg_type msg_id, void *msg, + u32 msg_size, void *result, u32 result_size, + u32 *cur_trans_id, u8 wait_reply) +{ + int status =3D 0; + struct sm_instance *instance =3D handle; + struct sm_cmd_rsp_blk *cmd_blk; + + if (!handle) { + pr_err("%s: invalid handle", __func__); + return -EINVAL; + } + if (!msg) { + pr_err("%s: invalid msg pointer", __func__); + return -EINVAL; + } + + cmd_blk =3D + vc_vchi_cmd_create(instance, msg_id, msg, msg_size, wait_reply); + if (!cmd_blk) { + pr_err("[%s]: failed to allocate global tracking resource", + __func__); + return -ENOMEM; + } + + if (cur_trans_id) + *cur_trans_id =3D cmd_blk->id; + + mutex_lock(&instance->lock); + list_add_tail(&cmd_blk->head, &instance->cmd_list); + mutex_unlock(&instance->lock); + complete(&instance->io_cmplt); + + if (!wait_reply) + /* We're done */ + return 0; + + /* Wait for the response */ + if (wait_for_completion_interruptible(&cmd_blk->cmplt)) { + mutex_lock(&instance->lock); + if (!cmd_blk->sent) { + list_del(&cmd_blk->head); + mutex_unlock(&instance->lock); + vc_vchi_cmd_delete(instance, cmd_blk); + return -ENXIO; + } + + list_move(&cmd_blk->head, &instance->dead_list); + mutex_unlock(&instance->lock); + complete(&instance->io_cmplt); + return -EINTR; /* We're done */ + } + + if (result && result_size) { + memcpy(result, cmd_blk->msg, result_size); + } else { + struct vc_sm_result_t *res =3D + (struct vc_sm_result_t *)cmd_blk->msg; + status =3D (res->success =3D=3D 0) ? 0 : -ENXIO; + } + + mutex_lock(&instance->lock); + list_del(&cmd_blk->head); + mutex_unlock(&instance->lock); + vc_vchi_cmd_delete(instance, cmd_blk); + return status; +} + +int vc_sm_cma_vchi_free(struct sm_instance *handle, struct vc_sm_free_t *m= sg, + u32 *cur_trans_id) +{ + return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_FREE, + msg, sizeof(*msg), 0, 0, cur_trans_id, 0); +} + +int vc_sm_cma_vchi_import(struct sm_instance *handle, struct vc_sm_import = *msg, + struct vc_sm_import_result *result, u32 *cur_trans_id) +{ + return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_IMPORT, + msg, sizeof(*msg), result, sizeof(*result), + cur_trans_id, 1); +} + +int vc_sm_cma_vchi_client_version(struct sm_instance *handle, + struct vc_sm_version *msg, + struct vc_sm_result_t *result, + u32 *cur_trans_id) +{ + return vc_sm_cma_vchi_send_msg(handle, VC_SM_MSG_TYPE_CLIENT_VERSION, + //msg, sizeof(*msg), result, sizeof(*result), + //cur_trans_id, 1); + msg, sizeof(*msg), NULL, 0, + cur_trans_id, 0); +} + +int vc_sm_vchi_client_vc_mem_req_reply(struct sm_instance *handle, + struct vc_sm_vc_mem_request_result *msg, + uint32_t *cur_trans_id) +{ + return vc_sm_cma_vchi_send_msg(handle, + VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY, + msg, sizeof(*msg), 0, 0, cur_trans_id, + 0); +} diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.h b/driv= ers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.h new file mode 100644 index 0000000000000000000000000000000000000000..a4f40d4cef0556e125cec4e8c31= cdab44b0be4f2 --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_cma_vchi.h @@ -0,0 +1,63 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * VideoCore Shared Memory CMA allocator + * + * Copyright: 2018, Raspberry Pi (Trading) Ltd + * Copyright 2011-2012 Broadcom Corporation. All rights reserved. + * + * Based on vmcs_sm driver from Broadcom Corporation. + * + */ + +#ifndef __VC_SM_CMA_VCHI_H__INCLUDED__ +#define __VC_SM_CMA_VCHI_H__INCLUDED__ + +#include + +#include "vc_sm_defs.h" + +/* + * Forward declare. + */ +struct sm_instance; + +typedef void (*vpu_event_cb)(struct sm_instance *instance, + struct vc_sm_result_t *reply, int reply_len); + +/* + * Initialize the shared memory service, opens up vchi connection to talk = to it. + */ +struct sm_instance *vc_sm_cma_vchi_init(struct vchiq_instance *vchi_instan= ce, + unsigned int num_connections, + vpu_event_cb vpu_event); + +/* + * Terminates the shared memory service. + */ +int vc_sm_cma_vchi_stop(struct vchiq_instance *vchi_instance, struct sm_in= stance **handle); + +/* + * Ask the shared memory service to free up some memory that was previously + * allocated by the vc_sm_cma_vchi_alloc function call. + */ +int vc_sm_cma_vchi_free(struct sm_instance *handle, struct vc_sm_free_t *m= sg, + u32 *cur_trans_id); + +/* + * Import a contiguous block of memory and wrap it in a GPU MEM_HANDLE_T. + */ +int vc_sm_cma_vchi_import(struct sm_instance *handle, struct vc_sm_import = *msg, + struct vc_sm_import_result *result, + u32 *cur_trans_id); + +int vc_sm_cma_vchi_client_version(struct sm_instance *handle, + struct vc_sm_version *msg, + struct vc_sm_result_t *result, + u32 *cur_trans_id); + +int vc_sm_vchi_client_vc_mem_req_reply(struct sm_instance *handle, + struct vc_sm_vc_mem_request_result *msg, + uint32_t *cur_trans_id); + +#endif /* __VC_SM_CMA_VCHI_H__INCLUDED__ */ diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_defs.h b/drivers/= platform/raspberrypi/vc-sm-cma/vc_sm_defs.h new file mode 100644 index 0000000000000000000000000000000000000000..7cabbadfe7ca4b4ed3e74e07194= d55294722380c --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_defs.h @@ -0,0 +1,298 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * VideoCore Shared Memory CMA allocator + * + * Copyright: 2018, Raspberry Pi (Trading) Ltd + * + * Based on vc_sm_defs.h from the vmcs_sm driver Copyright Broadcom Corpor= ation. + * All IPC messages are copied across to this file, even if the vc-sm-cma + * driver is not currently using them. + * + *************************************************************************= *** + */ + +#ifndef __VC_SM_DEFS_H__INCLUDED__ +#define __VC_SM_DEFS_H__INCLUDED__ + +#include + +/* Maximum message length */ +#define VC_SM_MAX_MSG_LEN (sizeof(union vc_sm_msg_union_t) + \ + sizeof(struct vc_sm_msg_hdr_t)) +#define VC_SM_MAX_RSP_LEN (sizeof(union vc_sm_msg_union_t)) + +/* Resource name maximum size */ +#define VC_SM_RESOURCE_NAME 32 + +/* + * Version to be reported to the VPU + * VPU assumes 0 (aka 1) which does not require the released callback, nor + * expect the client to handle VC_MEM_REQUESTS. + * Version 2 requires the released callback, and must support VC_MEM_REQUE= STS. + */ +#define VC_SM_PROTOCOL_VERSION 2 + +enum vc_sm_msg_type { + /* Message types supported for HOST->VC direction */ + + /* Allocate shared memory block */ + VC_SM_MSG_TYPE_ALLOC, + /* Lock allocated shared memory block */ + VC_SM_MSG_TYPE_LOCK, + /* Unlock allocated shared memory block */ + VC_SM_MSG_TYPE_UNLOCK, + /* Unlock allocated shared memory block, do not answer command */ + VC_SM_MSG_TYPE_UNLOCK_NOANS, + /* Free shared memory block */ + VC_SM_MSG_TYPE_FREE, + /* Resize a shared memory block */ + VC_SM_MSG_TYPE_RESIZE, + /* Walk the allocated shared memory block(s) */ + VC_SM_MSG_TYPE_WALK_ALLOC, + + /* A previously applied action will need to be reverted */ + VC_SM_MSG_TYPE_ACTION_CLEAN, + + /* + * Import a physical address and wrap into a MEM_HANDLE_T. + * Release with VC_SM_MSG_TYPE_FREE. + */ + VC_SM_MSG_TYPE_IMPORT, + /* + *Tells VC the protocol version supported by this client. + * 2 supports the async/cmd messages from the VPU for final release + * of memory, and for VC allocations. + */ + VC_SM_MSG_TYPE_CLIENT_VERSION, + /* Response to VC request for memory */ + VC_SM_MSG_TYPE_VC_MEM_REQUEST_REPLY, + + /* + * Asynchronous/cmd messages supported for VC->HOST direction. + * Signalled by setting the top bit in vc_sm_result_t trans_id. + */ + + /* + * VC has finished with an imported memory allocation. + * Release any Linux reference counts on the underlying block. + */ + VC_SM_MSG_TYPE_RELEASED, + /* VC request for memory */ + VC_SM_MSG_TYPE_VC_MEM_REQUEST, + + VC_SM_MSG_TYPE_MAX +}; + +/* Type of memory to be allocated */ +enum vc_sm_alloc_type_t { + VC_SM_ALLOC_CACHED, + VC_SM_ALLOC_NON_CACHED, +}; + +/* Message header for all messages in HOST->VC direction */ +struct vc_sm_msg_hdr_t { + u32 type; + u32 trans_id; + u8 body[]; +}; + +/* Request to allocate memory (HOST->VC) */ +struct vc_sm_alloc_t { + /* type of memory to allocate */ + enum vc_sm_alloc_type_t type; + /* byte amount of data to allocate per unit */ + u32 base_unit; + /* number of unit to allocate */ + u32 num_unit; + /* alignment to be applied on allocation */ + u32 alignment; + /* identity of who allocated this block */ + u32 allocator; + /* resource name (for easier tracking on vc side) */ + char name[VC_SM_RESOURCE_NAME]; + +}; + +/* Result of a requested memory allocation (VC->HOST) */ +struct vc_sm_alloc_result_t { + /* Transaction identifier */ + u32 trans_id; + + /* Resource handle */ + u32 res_handle; + /* Pointer to resource buffer */ + u32 res_mem; + /* Resource base size (bytes) */ + u32 res_base_size; + /* Resource number */ + u32 res_num; + +}; + +/* Request to free a previously allocated memory (HOST->VC) */ +struct vc_sm_free_t { + /* Resource handle (returned from alloc) */ + u32 res_handle; + /* Resource buffer (returned from alloc) */ + u32 res_mem; + +}; + +/* Request to lock a previously allocated memory (HOST->VC) */ +struct vc_sm_lock_unlock_t { + /* Resource handle (returned from alloc) */ + u32 res_handle; + /* Resource buffer (returned from alloc) */ + u32 res_mem; + +}; + +/* Request to resize a previously allocated memory (HOST->VC) */ +struct vc_sm_resize_t { + /* Resource handle (returned from alloc) */ + u32 res_handle; + /* Resource buffer (returned from alloc) */ + u32 res_mem; + /* Resource *new* size requested (bytes) */ + u32 res_new_size; + +}; + +/* Result of a requested memory lock (VC->HOST) */ +struct vc_sm_lock_result_t { + /* Transaction identifier */ + u32 trans_id; + + /* Resource handle */ + u32 res_handle; + /* Pointer to resource buffer */ + u32 res_mem; + /* + * Pointer to former resource buffer if the memory + * was reallocated + */ + u32 res_old_mem; + +}; + +/* Generic result for a request (VC->HOST) */ +struct vc_sm_result_t { + /* Transaction identifier */ + u32 trans_id; + + s32 success; + +}; + +/* Request to revert a previously applied action (HOST->VC) */ +struct vc_sm_action_clean_t { + /* Action of interest */ + enum vc_sm_msg_type res_action; + /* Transaction identifier for the action of interest */ + u32 action_trans_id; + +}; + +/* Request to remove all data associated with a given allocator (HOST->VC)= */ +struct vc_sm_free_all_t { + /* Allocator identifier */ + u32 allocator; +}; + +/* Request to import memory (HOST->VC) */ +struct vc_sm_import { + /* type of memory to allocate */ + enum vc_sm_alloc_type_t type; + /* pointer to the VC (ie physical) address of the allocated memory */ + u32 addr; + /* size of buffer */ + u32 size; + /* opaque handle returned in RELEASED messages */ + u32 kernel_id; + /* Allocator identifier */ + u32 allocator; + /* resource name (for easier tracking on vc side) */ + char name[VC_SM_RESOURCE_NAME]; +}; + +/* Result of a requested memory import (VC->HOST) */ +struct vc_sm_import_result { + /* Transaction identifier */ + u32 trans_id; + + /* Resource handle */ + u32 res_handle; +}; + +/* Notification that VC has finished with an allocation (VC->HOST) */ +struct vc_sm_released { + /* cmd type / trans_id */ + u32 cmd; + + /* pointer to the VC (ie physical) address of the allocated memory */ + u32 addr; + /* size of buffer */ + u32 size; + /* opaque handle returned in RELEASED messages */ + u32 kernel_id; + u32 vc_handle; +}; + +/* + * Client informing VC as to the protocol version it supports. + * >=3D2 requires the released callback, and supports VC asking for memory. + * Failure means that the firmware doesn't support this call, and therefor= e the + * client should either fail, or NOT rely on getting the released callback. + */ +struct vc_sm_version { + u32 version; +}; + +/* Request FROM VideoCore for some memory */ +struct vc_sm_vc_mem_request { + /* cmd type */ + u32 cmd; + + /* trans_id (from VPU) */ + u32 trans_id; + /* size of buffer */ + u32 size; + /* alignment of buffer */ + u32 align; + /* resource name (for easier tracking) */ + char name[VC_SM_RESOURCE_NAME]; + /* VPU handle for the resource */ + u32 vc_handle; +}; + +/* Response from the kernel to provide the VPU with some memory */ +struct vc_sm_vc_mem_request_result { + /* Transaction identifier for the VPU */ + u32 trans_id; + /* pointer to the physical address of the allocated memory */ + u32 addr; + /* opaque handle returned in RELEASED messages */ + u32 kernel_id; +}; + +/* Union of ALL messages */ +union vc_sm_msg_union_t { + struct vc_sm_alloc_t alloc; + struct vc_sm_alloc_result_t alloc_result; + struct vc_sm_free_t free; + struct vc_sm_lock_unlock_t lock_unlock; + struct vc_sm_action_clean_t action_clean; + struct vc_sm_resize_t resize; + struct vc_sm_lock_result_t lock_result; + struct vc_sm_result_t result; + struct vc_sm_free_all_t free_all; + struct vc_sm_import import; + struct vc_sm_import_result import_result; + struct vc_sm_version version; + struct vc_sm_released released; + struct vc_sm_vc_mem_request vc_request; + struct vc_sm_vc_mem_request_result vc_request_result; +}; + +#endif /* __VC_SM_DEFS_H__INCLUDED__ */ diff --git a/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_knl.h b/drivers/p= latform/raspberrypi/vc-sm-cma/vc_sm_knl.h new file mode 100644 index 0000000000000000000000000000000000000000..988fdd967922b75a3edcc5db67a= 1666f34c8fa93 --- /dev/null +++ b/drivers/platform/raspberrypi/vc-sm-cma/vc_sm_knl.h @@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * VideoCore Shared Memory CMA allocator + * + * Copyright: 2018, Raspberry Pi (Trading) Ltd + * + * Based on vc_sm_defs.h from the vmcs_sm driver Copyright Broadcom Corpor= ation. + * + */ + +#ifndef __VC_SM_KNL_H__INCLUDED__ +#define __VC_SM_KNL_H__INCLUDED__ + +#if !defined(__KERNEL__) +#error "This interface is for kernel use only..." +#endif + +/* Free a previously allocated or imported shared memory handle and block.= */ +int vc_sm_cma_free(void *handle); + +/* Get an internal resource handle mapped from the external one. */ +int vc_sm_cma_int_handle(void *handle); + +/* Import a block of memory into the GPU space. */ +int vc_sm_cma_import_dmabuf(struct dma_buf *dmabuf, void **handle); + +#endif /* __VC_SM_KNL_H__INCLUDED__ */ diff --git a/include/linux/raspberrypi/vc_sm_cma_ioctl.h b/include/linux/ra= spberrypi/vc_sm_cma_ioctl.h new file mode 100644 index 0000000000000000000000000000000000000000..e43bb2e76dfffb50cf0ec955f9b= 805fc840b91ab --- /dev/null +++ b/include/linux/raspberrypi/vc_sm_cma_ioctl.h @@ -0,0 +1,114 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +/* + * Copyright 2019 Raspberry Pi (Trading) Ltd. All rights reserved. + * + * Based on vmcs_sm_ioctl.h Copyright Broadcom Corporation. + */ + +#ifndef __VC_SM_CMA_IOCTL_H +#define __VC_SM_CMA_IOCTL_H + +/* ---- Include Files ----------------------------------------------------= */ + +#if defined(__KERNEL__) +#include /* Needed for standard types */ +#else +#include +#endif + +#include + +/* ---- Constants and Types ----------------------------------------------= */ + +#define VC_SM_CMA_RESOURCE_NAME 32 +#define VC_SM_CMA_RESOURCE_NAME_DEFAULT "sm-host-resource" + +/* Type define used to create unique IOCTL number */ +#define VC_SM_CMA_MAGIC_TYPE 'J' + +/* IOCTL commands on /dev/vc-sm-cma */ +enum vc_sm_cma_cmd_e { + VC_SM_CMA_CMD_ALLOC =3D 0x5A, /* Start at 0x5A arbitrarily */ + + VC_SM_CMA_CMD_IMPORT_DMABUF, + + VC_SM_CMA_CMD_CLEAN_INVALID2, + + VC_SM_CMA_CMD_LAST /* Do not delete */ +}; + +/* Cache type supported, conveniently matches the user space definition in + * user-vcsm.h. + */ +enum vc_sm_cma_cache_e { + VC_SM_CMA_CACHE_NONE, + VC_SM_CMA_CACHE_HOST, + VC_SM_CMA_CACHE_VC, + VC_SM_CMA_CACHE_BOTH, +}; + +/* IOCTL Data structures */ +struct vc_sm_cma_ioctl_alloc { + /* user -> kernel */ + __u32 size; + __u32 num; + __u32 cached; /* enum vc_sm_cma_cache_e */ + __u32 pad; + __u8 name[VC_SM_CMA_RESOURCE_NAME]; + + /* kernel -> user */ + __s32 handle; + __u32 vc_handle; + __u64 dma_addr; +}; + +struct vc_sm_cma_ioctl_import_dmabuf { + /* user -> kernel */ + __s32 dmabuf_fd; + __u32 cached; /* enum vc_sm_cma_cache_e */ + __u8 name[VC_SM_CMA_RESOURCE_NAME]; + + /* kernel -> user */ + __s32 handle; + __u32 vc_handle; + __u32 size; + __u32 pad; + __u64 dma_addr; +}; + +/* + * Cache functions to be set to struct vc_sm_cma_ioctl_clean_invalid2 + * invalidate_mode. + */ +#define VC_SM_CACHE_OP_NOP 0x00 +#define VC_SM_CACHE_OP_INV 0x01 +#define VC_SM_CACHE_OP_CLEAN 0x02 +#define VC_SM_CACHE_OP_FLUSH 0x03 + +struct vc_sm_cma_ioctl_clean_invalid2 { + __u32 op_count; + __u32 pad; + struct vc_sm_cma_ioctl_clean_invalid_block { + __u32 invalidate_mode; + __u32 block_count; + void * __user start_address; + __u32 block_size; + __u32 inter_block_stride; + } s[]; +}; + +/* IOCTL numbers */ +#define VC_SM_CMA_IOCTL_MEM_ALLOC\ + _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_ALLOC,\ + struct vc_sm_cma_ioctl_alloc) + +#define VC_SM_CMA_IOCTL_MEM_IMPORT_DMABUF\ + _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_IMPORT_DMABUF,\ + struct vc_sm_cma_ioctl_import_dmabuf) + +#define VC_SM_CMA_IOCTL_MEM_CLEAN_INVALID2\ + _IOR(VC_SM_CMA_MAGIC_TYPE, VC_SM_CMA_CMD_CLEAN_INVALID2,\ + struct vc_sm_cma_ioctl_clean_invalid2) + +#endif /* __VC_SM_CMA_IOCTL_H */ --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 48FEE358D04 for ; Fri, 31 Oct 2025 17:29:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931743; cv=none; b=sO+W59p0FVBMxa2RdNEM57pDz6Av04CCw35Qpo3Wr04Jjrw2C5ke583HiJkP05p0/9o4728+jTReucE9GbsP35/ZHSJ6qfQ5mCQiWtNgjEtuCXjmQhb1HItexGcvLnbQKQEa06/GAkiFEMkyEikube8UuLQh89fBe1uZ8eMnIxs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931743; c=relaxed/simple; bh=U1r0nv5AXygGMHYcKigeFLaG8n4Xm2MMN1SRS4hoeyw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=jnPBKe7LWChCvT/x0OEDz4n3kthTsckQAwK/sJNdSRod3MqciA7FLriErDT1WM8MD7CQXMFIiZa/AemQ09TM/0o6taYoiCr5r6YOvBg3QuhEyoruNMzCD5aKm8ZnFKpUGNuHfJNjgPmWec+LQQ3mZKPdWC9Xb/9brQjZYKNfHF8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=nTNNG1FM; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="nTNNG1FM" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B6C2D153F; Fri, 31 Oct 2025 18:27:08 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931629; bh=U1r0nv5AXygGMHYcKigeFLaG8n4Xm2MMN1SRS4hoeyw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=nTNNG1FM2zgGSzRXaFvLucUi75VvZ2uvC/EszDkGVml1QISKRmL5fqgeHqhg6CUex XdjQ1iWDoWBIdZjz1E9ifa8UGW9x44L+Kw8shIZXerMZo0+dBkHyZ592UdY+eWdIlb dw4Ld0aYfY7lmhfm6PWyCcHi+as1uX6waMZ3gYy4= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:30 +0530 Subject: [PATCH 10/13] platform/raspberrypi: vchiq-mmal: Use vc-sm-cma to support zero copy Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-10-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=6627; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=KDZDtOhXem1yRuj7hrgmvwIXzDdN3L/y3Nt8Pyh7uA4=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGdtXvKBuOM6wX4NA/G4afVFB8/czUATffgD BAE7Lbf6QeJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxnQAKCRBD3pH5JJpx Rd6KEACOsBycJdEJ60ZiBxbt/2wiVGKvhO+ug0UJN2OFrTX2GBMYGOII4eDXr5xLHOMKHmKxd1F h7CGPWWeZtMNsbRqlCkvdw5ZCEqv/VF3p1YF6ECiv3x01sZnYhsVgpT3mI7h4Arz53ziXQIX9up 7XthqUdx2MhjqgoyFGjRryDC+y5vSWwXwyrxFjWxprDdhfZM5Q0e/HjuLb8RBbebsfknG4qpS/E 6iUsIaPXZi2gso/e1/VVPPSYfpe/WvZ6D3fN50w/Zg3AQ2LekZFCq6kPBjPMCTTqqtTZYJGz86H SFoDDVq53t/l9uhCLnbWWmt0/xVDKpG2G6NxJ7aEVcY7h27TLtnIBgIA7U4TCV1qBmLB8nP5Uno zIpnxptIquyHlomXUdiqkH1iKmBsF5YHzZUH3kMOiMIIpx2uV4oFWVwSGEe9eE6ID/Z17xf0yny qyIhcp2XiiNLaEghJHG5Jzmg75rD58uzwHX8bqR00cNoq1XslaQtbb/ZyBgddJ1GRxnpGYv+Fgt THJWKPzMbscEF2ivWNfci1ezD7tCsEVOMAez1X9JVxdeseFdbJdX/XQrr648YG2KGASXeY2Xeco xu0M0XvBCgK8KyUMjPC+/QmpxuMmb7CoS16IPtZZweVtEJdEGnmpLcNEn9dVhENw5tUwBGkgzR3 d3a1PKw/8VScq6A== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson With the vc-sm-cma driver we can support zero copy of buffers between the kernel and VPU. Add this support to mmal-vchiq. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/Kconfig | 3 ++- drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h | 4 ++++ drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 66 +++++++++++++++= +++++++++++++++++++++++++++++++++++++++++++++++++-- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h | 1 + 4 files changed, 71 insertions(+), 3 deletions(-) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/Kconfig b/drivers/plat= form/raspberrypi/vchiq-mmal/Kconfig index c99525a0bb4525d497c74984b8b44a9079279b6f..5df9198cdab1786353aeab287f8= 3ea7f0630b317 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/Kconfig +++ b/drivers/platform/raspberrypi/vchiq-mmal/Kconfig @@ -1,6 +1,7 @@ config BCM2835_VCHIQ_MMAL tristate "BCM2835 MMAL VCHIQ service" - depends on BCM2835_VCHIQ + select BCM2835_VCHIQ + select BCM_VC_SM_CMA help Enables the MMAL API over VCHIQ interface as used for the majority of the multimedia services on VideoCore. diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h b/driver= s/platform/raspberrypi/vchiq-mmal/mmal-common.h index 0443be8198ea57fcd66d598ef7a46309d82ec7b7..a643cad54b1200a4c8bda9ea122= 8da54298b2862 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-common.h @@ -50,6 +50,10 @@ struct mmal_buffer { =20 struct mmal_msg_context *msg_context; =20 + struct dma_buf *dma_buf;/* Exported dmabuf fd from videobuf2 */ + void *vcsm_handle; /* VCSM handle having imported the dmabuf */ + u32 vc_handle; /* VC handle to that dmabuf */ + u32 cmd; /* MMAL command. 0=3Ddata. */ unsigned long length; u32 mmal_flags; diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index 3c99d0f3e57178761ec57d97cd77e59aa26143fa..02fbf061c171cba287657266aa1= 731333609b3b0 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -29,9 +29,12 @@ #include =20 #include "mmal-common.h" +#include "mmal-parameters.h" #include "mmal-vchiq.h" #include "mmal-msg.h" =20 +#include "../vc-sm-cma/vc_sm_knl.h" + /* * maximum number of components supported. * This matches the maximum permitted by default on the VPU @@ -418,8 +421,13 @@ buffer_from_host(struct vchiq_mmal_instance *instance, =20 /* buffer header */ m.u.buffer_from_host.buffer_header.cmd =3D 0; - m.u.buffer_from_host.buffer_header.data =3D - (u32)(unsigned long)buf->buffer; + if (port->zero_copy) { + m.u.buffer_from_host.buffer_header.data =3D buf->vc_handle; + } else { + m.u.buffer_from_host.buffer_header.data =3D + (u32)(unsigned long)buf->buffer; + } + m.u.buffer_from_host.buffer_header.alloc_size =3D buf->buffer_size; if (port->type =3D=3D MMAL_PORT_TYPE_OUTPUT) { m.u.buffer_from_host.buffer_header.length =3D 0; @@ -585,6 +593,22 @@ static void buffer_to_host_cb(struct vchiq_mmal_instan= ce *instance, =20 msg_context->u.bulk.status =3D msg->h.status; =20 + } else if (msg->u.buffer_from_host.is_zero_copy) { + /* + * Zero copy buffer, so nothing to do. + * Copy buffer info and make callback. + */ + msg_context->u.bulk.buffer_used =3D + msg->u.buffer_from_host.buffer_header.length; + msg_context->u.bulk.mmal_flags =3D + msg->u.buffer_from_host.buffer_header.flags; + msg_context->u.bulk.dts =3D + msg->u.buffer_from_host.buffer_header.dts; + msg_context->u.bulk.pts =3D + msg->u.buffer_from_host.buffer_header.pts; + msg_context->u.bulk.cmd =3D + msg->u.buffer_from_host.buffer_header.cmd; + } else if (msg->u.buffer_from_host.buffer_header.length =3D=3D 0) { /* empty buffer */ if (msg->u.buffer_from_host.buffer_header.flags & @@ -1531,6 +1555,9 @@ int vchiq_mmal_port_parameter_set(struct vchiq_mmal_i= nstance *instance, =20 mutex_unlock(&instance->vchiq_mutex); =20 + if (parameter =3D=3D MMAL_PARAMETER_ZERO_COPY && !ret) + port->zero_copy =3D !!(*(bool *)value); + return ret; } EXPORT_SYMBOL_GPL(vchiq_mmal_port_parameter_set); @@ -1699,6 +1726,31 @@ int vchiq_mmal_submit_buffer(struct vchiq_mmal_insta= nce *instance, unsigned long flags =3D 0; int ret; =20 + /* + * We really want to do this in mmal_vchi_buffer_init but can't as + * videobuf2 won't let us have the dmabuf there. + */ + if (port->zero_copy && buffer->dma_buf && !buffer->vcsm_handle) { + pr_debug("%s: import dmabuf %p\n", __func__, buffer->dma_buf); + ret =3D vc_sm_cma_import_dmabuf(buffer->dma_buf, + &buffer->vcsm_handle); + if (ret) { + pr_err("%s: vc_sm_import_dmabuf_fd failed, ret %d\n", + __func__, ret); + return ret; + } + + buffer->vc_handle =3D vc_sm_cma_int_handle(buffer->vcsm_handle); + if (!buffer->vc_handle) { + pr_err("%s: vc_sm_int_handle failed %d\n", + __func__, ret); + vc_sm_cma_free(buffer->vcsm_handle); + return ret; + } + pr_debug("%s: import dmabuf %p - got vc handle %08X\n", + __func__, buffer->dma_buf, buffer->vc_handle); + } + ret =3D buffer_from_host(instance, port, buffer); if (ret =3D=3D -EINVAL) { /* Port is disabled. Queue for when it is enabled. */ @@ -1732,6 +1784,16 @@ int mmal_vchi_buffer_cleanup(struct mmal_buffer *buf) release_msg_context(msg_context); buf->msg_context =3D NULL; =20 + if (buf->vcsm_handle) { + int ret; + + pr_debug("%s: vc_sm_cma_free on handle %p\n", __func__, + buf->vcsm_handle); + ret =3D vc_sm_cma_free(buf->vcsm_handle); + if (ret) + pr_err("%s: vcsm_free failed, ret %d\n", __func__, ret); + buf->vcsm_handle =3D 0; + } return 0; } EXPORT_SYMBOL_GPL(mmal_vchi_buffer_cleanup); diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.h index 190a0f42bd6b22c7493463da94c094265d85d8fa..ae9e26a3b05b9b640ecd6844990= a776d27354185 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.h @@ -49,6 +49,7 @@ typedef void (*vchiq_mmal_buffer_cb)(struct vchiq_mmal_in= stance *instance, =20 struct vchiq_mmal_port { bool enabled; + u32 zero_copy:1; u32 handle; u32 type; /* port type, cached to use on port info set */ u32 index; /* port index, cached to use on port info set */ --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 576A23590B2 for ; Fri, 31 Oct 2025 17:29:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931749; cv=none; b=GLr+zramnBJqI9n3AuElGqMJ6/yNEf6m8gl3iD5rXQgaMPw158aYF0Ok1sGAYR1EUrL4Bmik9o84LJsUdLBm+CH13k60WF4KYWx5D0ysPVK78UMDogB2/SMnN3ijzoxi2w1O9iFLZdkgCQn66P/ORZbbZMu9zKWVxJ0PlNMsCPo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931749; c=relaxed/simple; bh=5LsFZf/cIZrJvTxKTyeuhDVpVX8Vu2fnD0rlBUYfDdE=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=BOuQ/a8pxZdeeyU+pHw1ut5wC7OHd0XAdd1eGJ9tMiPuMVcm38T5Lf8Rfax9DDpUYOgNw1YVP3w/UszbWtzhzR7+U4+o49NI5jT0UWBGX5a5GFF/Y9ew/y60KBMMu/9mV9EVJk4Ju/3Zf4rcOv8YtPus9jqdcyW0Uk7IrEw8syo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=brKhu+F3; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="brKhu+F3" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id DD8BA16A8; Fri, 31 Oct 2025 18:27:13 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931634; bh=5LsFZf/cIZrJvTxKTyeuhDVpVX8Vu2fnD0rlBUYfDdE=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=brKhu+F3/ZRM/yOou/442+jj52hYUp94MxAi9MLiP3xMKIax2qmXoteg4rlTE8k52 HngMmcNsp7WkN+B/Gt98ljKXPvDlg2a3cOFPEjJL3jR8klcjPLVc9UBfBEkNUJFblY TN9ZolPxlnq9YyF9BvOTz3ETco/+y6AH9zr21T4A= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:31 +0530 Subject: [PATCH 11/13] platform/raspberrypi: vchiq-mmal: Reset buffers_with_vpu on port_enable Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-11-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1181; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=xRyZ+PABcf09n5xFUP7XusKRU9z53iVixMht1alL/A0=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGe+YXRZScfcvd11TYSAIT6cz7VulpYyCdGN b+AW3CIOimJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxngAKCRBD3pH5JJpx RQ7+D/9aCr4U1C13o6L/8MAlZAO+/GW5nOOwjVt/uijThW+GJnyexb/ttjdJ+/R4vdO4NxSxP+6 rDGYpQhMbFiaAKKd9wfMW+Vo4+dRAW8S2oy3PLKoGJVNU0A+sx6dHLbByDiMsg73ALYdJT5DwBu J1VwCfMoPuqVeKiVbRtZZoSYkUBlptGmsbqDqhQY1S/PB1VAQ5uU8bysjEm0YKqGhiWwXZPSik3 q8wgxim2pr3aRd1cfGM5PfyM3FUbzQRVK4k+B2Jxwxx2WtH0FsmjjN6/8DcY2z5KJrf0kMOTphz WEJwOU+kHIrRtfaHLVB5ei+1npC2y07IzCkhjn/mgdTbEHq0moUWH1nQbRPmmxbBwCUh3ovLn9t sYfI8A4ncKfoFh0ziwT29DF4X7EGZQ9EHyN5uAZ7bkTni2bjz8cKFZ0LN5p+K30uSv9b/Yv2wKB RGaBGTy2H+6sXNtxoszQt5irEMwNaaXpUNfv0XQVWDhfCxEWKmO28W8eN74k2YY++0gZrzxGSN7 86VpsndO1CZXzhJYdJQ/SgvC7fwPE9vebHA96+tvvZCHYOnJwSMsnyUljc3VI5XFr5C+MxP7lIY bjIjfVSz1d9DiUnSxpFNaWDnGDu60U5rP9HfHjpKmgyXZvNtJpDKq09GNTmWwvJ1Ecxub27UMVq 2jZ8mp83cYQFc2w== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson Should we go through the timeout failure case with port_disable not returning all buffers for whatever reason, the buffers_with_vpu counter gets left at a non-zero value, which will cause reference counting issues should the instance be reused. Reset the count when the port is enabled again, but before any buffers have been sent to the VPU. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c b/drivers= /platform/raspberrypi/vchiq-mmal/mmal-vchiq.c index 02fbf061c171cba287657266aa1731333609b3b0..f9e1a773fa55f885f240f4945b9= 80f77676d83a6 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-vchiq.c @@ -1490,6 +1490,8 @@ static int port_enable(struct vchiq_mmal_instance *in= stance, =20 port->enabled =3D true; =20 + atomic_set(&port->buffers_with_vpu, 0); + if (port->buffer_cb) { /* send buffer headers to videocore */ hdr_count =3D 1; --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id F29A4322DD0 for ; Fri, 31 Oct 2025 17:29:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931753; cv=none; b=KAqa88EGW+XjEFF2xwG/tWpqRD/e5C8uJyQ/quFB7Nd++rwsFDhh0J6QAX40T9vFvEnQF50wuCxDqYl1OSrfD3jdbdtzs9BVZ/+njIuBia5oK+eppkPSNT3j4tA16/88wSXwUdLLW/tHba8OFQCKG8i2ojD+BJXJ6np+xXpPlqg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931753; c=relaxed/simple; bh=IHdpFNsikDjuT9BvG//eWRR5pi+hu/fq3ze+TMixXdY=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=S5bve6Hau2SSiq3jj6489InlmVH8+WCwaUsZGTo4mBxZb08q0H0aMKvH8nTG106P3u3gr1R5k3h5pNlSzsjjSoeCBWsEUUCLEzkgDlk2rcAlvhUJIgeLq5DAF5VmWSiZLny0WQ6zvmG4yJNOGakqMaZJW7k8RymYjjO8vlfulsg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=XnWPCe5/; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="XnWPCe5/" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9769C1690; Fri, 31 Oct 2025 18:27:19 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931640; bh=IHdpFNsikDjuT9BvG//eWRR5pi+hu/fq3ze+TMixXdY=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=XnWPCe5/ePQcLPPtLmqvNtYKtS1yFi7KM5if6ekUiH0zYHDG1BHjOmYeCN6U6RvXg bXAsDFBb7TmeqHkzPsql+i+t+ATN41F3MHHAwcRKCOHTSsjpcTjGR3oGjnupgQ5DcG D1rfTObJzlDn8130tRh4QrPiSKVVXv1gCtu94ONQ= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:32 +0530 Subject: [PATCH 12/13] platform/raspberrypi: vchiq-mmal: Add defines for mmal_es_format flags Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-12-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1474; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=LKyLKcaXyAoycbYitlV+AZbBL6EJIX9O3KqfvKd+VMo=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGfPbO6xE5RAvpayH40riclLISxDRq+Kjii6 LATbX19oEKJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxnwAKCRBD3pH5JJpx RaCyD/9e+AS8wk5pcH9fFNkvLtraQMxN7/XsU/IhBDzTjJJkN8ZUdt7lWtLWb6NyeAFgEvEwcCR xaNkMTcJ3czi7F5z8R+H5dK1UrgsIsisx1zRcx9cIRIUO4lm857yz9clw4H6s/DgoIVA4bJ568x NzmcF3tE/eglgMG8LZF4MpTkDXkPFr5e3OAhMc/fAsC4+/tRuj3KhonaYXQQ+FGay+aC+HnX1Az fbbXGhAzsOhehsCbBjS/UQVlXfEYByWRlIemSgh3YOyymFU8wii/yMynGdWAVr1O7LGmKbrGT2i PrMm30SyLp29PvqTXfUZhIfGBJZfRT3LkTt/jpIm+ofi/AFaNImefRAaeLO6iH2ekMdFfMMVeYk VaYJAt0NBWzEvEqQUo+tGhaTK//YfPZjMTWz2A7z2FyVg+OqdsRYtrThAvlR+PXlAjmMFQNOE9N k/nGSBESspsT9pSsW9ZhsoTuibI90rU6CaSz6mRfWZ1t6kTpsGw3us+S+e7lIIxZfKOlwL3i4Sy BPBwRAdJeDwG6qG2ovQRbx8hkrL2GhrhYT7GhEYnrF6uHkhvGSjKdhS2D7X9J76S9iH4AhFlviy yfrZN9KDFqiz0orS4WFQzJcK6CZHx75dCk1AYBhCsVql85DV5y/Gi58N9G100BeRq+dfLgqhT42 vZqStSqkLzxfDCA== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson There is a flags field in struct mmal_es_format, but the defines for what the bits meant weren't included in the headers. For V4L2_PIX_FMT_NV12_COL128 support we need them, so add them in. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h b/dr= ivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h index 5569876d8c7d60477893c17f00c2e501b49d364a..e8f5ca85a7c4184320b33996967= a7a83e938d79b 100644 --- a/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h +++ b/drivers/platform/raspberrypi/vchiq-mmal/mmal-msg-format.h @@ -53,6 +53,16 @@ union mmal_es_specific_format { struct mmal_subpicture_format subpicture; }; =20 +/* The elementary stream will already be framed */ +#define MMAL_ES_FORMAT_FLAG_FRAMED BIT(0) +/* + * For column formats we ideally want to pass in the column stride. This h= asn't + * been the past behaviour, so require a new flag to be set should + * es->video.width be the column stride (in lines) instead of an ignored w= idth + * value. + */ +#define MMAL_ES_FORMAT_FLAG_COL_FMTS_WIDTH_IS_COL_STRIDE BIT(1) + /* Definition of an elementary stream format (MMAL_ES_FORMAT_T) */ struct mmal_es_format_local { u32 type; /* enum mmal_es_type */ --=20 2.51.0 From nobody Mon Feb 9 04:04:40 2026 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0158D322DD0 for ; Fri, 31 Oct 2025 17:29:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=213.167.242.64 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931758; cv=none; b=k6tf/WTgnAHe6ez1DNT5Q3GbJyqqAzEHJVre+f1j3X0XGywxdMDpWamlp55SHDTJzJ+ukXRr56zwOwVZvDhx0bxJRw0IHEpNDsCd/2W1AZXwa7SD6LtsSOgePzn8ZNI7DC6CNsXq4NGFPp+xB4V/f1S2B1EZBbWOzKTAPCWOnPY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1761931758; c=relaxed/simple; bh=9CJ7u1jnlnm84awcn639u6Yp/yBstqIpcAoOOdICSkI=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=AQTQQbjpXovOZYLHtwmD6l4IWU+sXWqyhg0eWmGJnA1gOEo+ZWLOHqVJ+gM85dC8pOJrD0BKoLePH7ZSspwb10vmC9rb9KOSU3SSvInjwkrH3Rhzf0Uf7wV8VcmJnmw5esupILJCGINr2Seey1ewx+i4kI2rgdvdRmDqLrzYC6w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com; spf=pass smtp.mailfrom=ideasonboard.com; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b=MJdDdwY6; arc=none smtp.client-ip=213.167.242.64 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=ideasonboard.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="MJdDdwY6" Received: from mail.ideasonboard.com (unknown [IPv6:2401:4900:1c69:314e:ee86:ae6e:30:9d13]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 660DD19AD; Fri, 31 Oct 2025 18:27:24 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761931644; bh=9CJ7u1jnlnm84awcn639u6Yp/yBstqIpcAoOOdICSkI=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=MJdDdwY6W2U6sGWpx79RZex9hPLCL0rz6ZVb0ZU5ctpvkqx6nGysWUil4gbDvrdjh 0M4INmFp7O38NvgKOYyD7zIWhUUpQIuvFs/ciPbbnjpGYmx/+d0NiU0qxXnBQmUUHB /KbzPPnKxIhxKSALiGtJPad4Ky7baUYW/M531ERs= From: Jai Luthra Date: Fri, 31 Oct 2025 22:57:33 +0530 Subject: [PATCH 13/13] platform/raspberrypi: vchiq: Register vc-sm-cma as a platform driver Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Message-Id: <20251031-b4-vc-sm-cma-v1-13-0dd5c0ec3f5c@ideasonboard.com> References: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> In-Reply-To: <20251031-b4-vc-sm-cma-v1-0-0dd5c0ec3f5c@ideasonboard.com> To: Florian Fainelli , Raspberry Pi Kernel Maintenance , bcm-kernel-feedback-list@broadcom.com Cc: Dave Stevenson , Phil Elwell , Stefan Wahren , Laurent Pinchart , Kieran Bingham , Sumit Semwal , =?utf-8?q?Christian_K=C3=B6nig?= , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Jai Luthra X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1464; i=jai.luthra@ideasonboard.com; h=from:subject:message-id; bh=rAaQpRHtWGp7BJRz7YWXM337EB/6DfYZ9A46xHhwYZY=; b=owEBbQKS/ZANAwAKAUPekfkkmnFFAcsmYgBpBPGgaG15cb+ogx/QrVis56z2df+pwHeMLcxzo qRCX/wZD3yJAjMEAAEKAB0WIQRN4NgY5dV16NRar8VD3pH5JJpxRQUCaQTxoAAKCRBD3pH5JJpx RbJgD/4wpdKvt6yg4rO214J6mG4ABEkpeK7I0bf88qPV1ZaNUcjEAz9XusPjEpkUOwDxPgoBfmH 1FBudws2zDI2/GgOa/H8/1+IWkJY+SSMWzo4hf/KbdWM8tvFST1efw5jt4Tc7UvmItrtbDXVesI Eswog4EObYV/E88rvqxRX9aaF3xEqwMz3H8an0MIGIt3DtU7gpO5AuaKcQBiXyUd+jPYy6TLijD /fHo0tkjjJC484M7eIE8IFoudnuoD1RHxZzDURgZAgpEBQur+y5k+mjsA6lKXoVdifBX5JYl3WV Mjpcl8i5V1I8+eM0dPzwaff1niZHbe5Twz66m8S02LIaAv0jDo3LF4w3lLDMDzX7Uv2jaR6XeKc e3yK+2u/SguX6cRULhgu4ukwWMFujsOFWi185jbLSZhF00Gy3YqaXCR5K9Ip7drsPMaxQv2pRW/ Fw98H16fY5yAKxlQSKHim9ETcdfSLm0uGCW6N9J43E6AKvSm4bNENCgh2TA6Cl+KPNwAPvuW1uj /veJBmoYagW91F+gyq23/VSeuQ6hhO6XMKzYyK5H8PMtV6p05OPo3aDYglBZS74P5JxvucjB4zQ 0NstgRBYQoeVRD5KKqyxmzzQNNm2k1FE64UAgMtcotHGoSW+lNc+NzsBl36WbwZNuxD0vr31ISP skDwFCSpnquUd9Q== X-Developer-Key: i=jai.luthra@ideasonboard.com; a=openpgp; fpr=4DE0D818E5D575E8D45AAFC543DE91F9249A7145 From: Dave Stevenson Register the vc-sm-cma driver as a platform driver under vchiq. Signed-off-by: Dave Stevenson Signed-off-by: Jai Luthra --- drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c b/dri= vers/platform/raspberrypi/vchiq-interface/vchiq_arm.c index 6a7b96d3dae6275a483ef15dc619c5510454765e..09d33bec46ec45175378fff8dd1= 084d0a8a12dd6 100644 --- a/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c +++ b/drivers/platform/raspberrypi/vchiq-interface/vchiq_arm.c @@ -63,6 +63,7 @@ * the interface. */ static struct vchiq_device *bcm2835_audio; +static struct vchiq_device *vcsm_cma; =20 static const struct vchiq_platform_info bcm2835_info =3D { .cache_line_size =3D 32, @@ -1421,6 +1422,7 @@ static int vchiq_probe(struct platform_device *pdev) =20 vchiq_debugfs_init(&mgmt->state); =20 + vcsm_cma =3D vchiq_device_register(&pdev->dev, "vcsm-cma"); bcm2835_audio =3D vchiq_device_register(&pdev->dev, "bcm2835-audio"); =20 return 0; @@ -1431,6 +1433,7 @@ static void vchiq_remove(struct platform_device *pdev) struct vchiq_drv_mgmt *mgmt =3D dev_get_drvdata(&pdev->dev); =20 vchiq_device_unregister(bcm2835_audio); + vchiq_device_unregister(vcsm_cma); vchiq_debugfs_deinit(); vchiq_deregister_chrdev(); vchiq_platform_uninit(mgmt); --=20 2.51.0