linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: gregkh@linuxfoundation.org
Cc: kernel-list@raspberrypi.com, laurent.pinchart@ideasonboard.com,
	linux-rpi-kernel@lists.infradead.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org, devel@driverdev.osuosl.org,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: [PATCH v2 23/47] staging: vchiq: Move message queue into struct vchiq_service
Date: Mon, 29 Jun 2020 17:09:21 +0200	[thread overview]
Message-ID: <20200629150945.10720-24-nsaenzjulienne@suse.de> (raw)
In-Reply-To: <20200629150945.10720-1-nsaenzjulienne@suse.de>

This has historically been handled by vchi, but there is no reason why
this couldn't be handled directly in vchiq.

The patch tries to avoid altering any behavior, with the exception of
the msg_queue size, which is now fixed to VCHIQ_MAX_SLOTS (it was set to
VCHIQ_MAX_SLOTS / 2). This is done to match vchiq's user_service message
queue, which could be merged with this one in the future.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---
 drivers/staging/vc04_services/Makefile        |  1 -
 .../interface/vchiq_arm/vchiq_core.c          | 46 ++++++++++++
 .../interface/vchiq_arm/vchiq_core.h          |  6 ++
 .../interface/vchiq_arm/vchiq_if.h            |  2 +
 .../interface/vchiq_arm/vchiq_shim.c          | 24 ++----
 .../interface/vchiq_arm/vchiq_util.c          | 73 -------------------
 .../interface/vchiq_arm/vchiq_util.h          | 22 ------
 7 files changed, 61 insertions(+), 113 deletions(-)
 delete mode 100644 drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c

diff --git a/drivers/staging/vc04_services/Makefile b/drivers/staging/vc04_services/Makefile
index d37f21d1a219..922990919c40 100644
--- a/drivers/staging/vc04_services/Makefile
+++ b/drivers/staging/vc04_services/Makefile
@@ -7,7 +7,6 @@ vchiq-objs := \
    interface/vchiq_arm/vchiq_2835_arm.o \
    interface/vchiq_arm/vchiq_debugfs.o \
    interface/vchiq_arm/vchiq_shim.o \
-   interface/vchiq_arm/vchiq_util.o \
    interface/vchiq_arm/vchiq_connected.o \
 
 obj-$(CONFIG_SND_BCM2835)		+= bcm2835-audio/
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
index 0a2419bd305b..fe8ce6880e49 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c
@@ -2265,6 +2265,47 @@ vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_zero)
 	return VCHIQ_ERROR;
 }
 
+void vchiq_msg_queue_push(unsigned handle, struct vchiq_header *header)
+{
+	struct vchiq_service *service = find_service_by_handle(handle);
+	int pos;
+
+	while (service->msg_queue_write == service->msg_queue_read +
+		VCHIQ_MAX_SLOTS) {
+		if (wait_for_completion_interruptible(&service->msg_queue_pop))
+			flush_signals(current);
+	}
+
+	pos = service->msg_queue_write++ & (VCHIQ_MAX_SLOTS - 1);
+	service->msg_queue[pos] = header;
+
+	complete(&service->msg_queue_push);
+}
+EXPORT_SYMBOL(vchiq_msg_queue_push);
+
+struct vchiq_header *vchiq_msg_hold(unsigned handle)
+{
+	struct vchiq_service *service = find_service_by_handle(handle);
+	struct vchiq_header *header;
+	int pos;
+
+	if (service->msg_queue_write == service->msg_queue_read)
+		return NULL;
+
+	while (service->msg_queue_write == service->msg_queue_read) {
+		if (wait_for_completion_interruptible(&service->msg_queue_push))
+			flush_signals(current);
+	}
+
+	pos = service->msg_queue_read++ & (VCHIQ_MAX_SLOTS - 1);
+	header = service->msg_queue[pos];
+
+	complete(&service->msg_queue_pop);
+
+	return header;
+}
+EXPORT_SYMBOL(vchiq_msg_hold);
+
 static int vchiq_validate_params(const struct vchiq_service_params *params)
 {
 	if (!params->callback || !params->fourcc) {
@@ -2319,12 +2360,17 @@ vchiq_add_service_internal(struct vchiq_state *state,
 	service->state         = state;
 	service->instance      = instance;
 	service->service_use_count = 0;
+	service->msg_queue_read = 0;
+	service->msg_queue_write = 0;
 	init_bulk_queue(&service->bulk_tx);
 	init_bulk_queue(&service->bulk_rx);
 	init_completion(&service->remove_event);
 	init_completion(&service->bulk_remove_event);
+	init_completion(&service->msg_queue_pop);
+	init_completion(&service->msg_queue_push);
 	mutex_init(&service->bulk_mutex);
 	memset(&service->stats, 0, sizeof(service->stats));
+	memset(&service->msg_queue, 0, sizeof(service->msg_queue));
 
 	/* Although it is perfectly possible to use a spinlock
 	** to protect the creation of services, it is overkill as it
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
index 1fe6cd8b86c0..b97b661bea1c 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h
@@ -297,6 +297,12 @@ struct vchiq_service {
 		uint64_t bulk_tx_bytes;
 		uint64_t bulk_rx_bytes;
 	} stats;
+
+	int msg_queue_read;
+	int msg_queue_write;
+	struct completion msg_queue_pop;
+	struct completion msg_queue_push;
+	struct vchiq_header *msg_queue[VCHIQ_MAX_SLOTS];
 };
 
 /* The quota information is outside struct vchiq_service so that it can
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h
index b62fd6d6f1ac..8fd51d885a18 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_if.h
@@ -136,5 +136,7 @@ extern enum vchiq_status vchiq_dump_phys_mem(unsigned int service,
 
 extern enum vchiq_status vchiq_get_peer_version(unsigned int handle,
       short *peer_version);
+extern void vchiq_msg_queue_push(unsigned handle, struct vchiq_header *header);
+extern struct vchiq_header *vchiq_msg_hold(unsigned handle);
 
 #endif /* VCHIQ_IF_H */
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
index 3ce4b7b5d55e..fb6f3c052e11 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_shim.c
@@ -13,8 +13,6 @@
 struct vchi_service {
 	unsigned int handle;
 
-	struct vchiu_queue queue;
-
 	vchi_callback callback;
 	void *callback_param;
 };
@@ -172,10 +170,9 @@ int32_t vchi_msg_hold(struct vchi_service *service, void **data,
 {
 	struct vchiq_header *header;
 
-	if (vchiu_queue_is_empty(&service->queue))
-		return -1;
-
-	header = vchiu_queue_pop(&service->queue);
+	header = vchiq_msg_hold(service->handle);
+	if (!header)
+		return -ENOENT;
 
 	*data = header->data;
 	*msg_size = header->size;
@@ -272,7 +269,7 @@ static enum vchiq_status shim_callback(enum vchiq_reason reason,
 		(struct vchi_service *)VCHIQ_GET_SERVICE_USERDATA(handle);
 
 	if (reason == VCHIQ_MESSAGE_AVAILABLE)
-		vchiu_queue_push(&service->queue, header);
+		vchiq_msg_queue_push(service->handle, header);
 
 	service->callback(service->callback_param, reason, bulk_user);
 
@@ -285,13 +282,8 @@ static struct vchi_service *service_alloc(struct vchiq_instance *instance,
 	struct vchi_service *service = kzalloc(sizeof(struct vchi_service), GFP_KERNEL);
 
 	if (service) {
-		if (!vchiu_queue_init(&service->queue, 64)) {
-			service->callback = setup->callback;
-			service->callback_param = setup->callback_param;
-		} else {
-			kfree(service);
-			service = NULL;
-		}
+		service->callback = setup->callback;
+		service->callback_param = setup->callback_param;
 	}
 
 	return service;
@@ -299,10 +291,8 @@ static struct vchi_service *service_alloc(struct vchiq_instance *instance,
 
 static void service_free(struct vchi_service *service)
 {
-	if (service) {
-		vchiu_queue_delete(&service->queue);
+	if (service)
 		kfree(service);
-	}
 }
 
 int32_t vchi_service_open(struct vchiq_instance *instance,
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c
deleted file mode 100644
index c1c81f9ab9e6..000000000000
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.c
+++ /dev/null
@@ -1,73 +0,0 @@
-// SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
-/* Copyright (c) 2010-2012 Broadcom. All rights reserved. */
-
-#include "vchiq_util.h"
-
-static inline int is_pow2(int i)
-{
-	return i && !(i & (i - 1));
-}
-
-int vchiu_queue_init(struct vchiu_queue *queue, int size)
-{
-	WARN_ON(!is_pow2(size));
-
-	queue->size = size;
-	queue->read = 0;
-	queue->write = 0;
-	queue->initialized = 1;
-
-	init_completion(&queue->pop);
-	init_completion(&queue->push);
-
-	queue->storage = kcalloc(size, sizeof(struct vchiq_header *),
-				 GFP_KERNEL);
-	if (!queue->storage) {
-		vchiu_queue_delete(queue);
-		return -ENOMEM;
-	}
-	return 0;
-}
-
-void vchiu_queue_delete(struct vchiu_queue *queue)
-{
-	kfree(queue->storage);
-}
-
-int vchiu_queue_is_empty(struct vchiu_queue *queue)
-{
-	return queue->read == queue->write;
-}
-
-void vchiu_queue_push(struct vchiu_queue *queue, struct vchiq_header *header)
-{
-	if (!queue->initialized)
-		return;
-
-	while (queue->write == queue->read + queue->size) {
-		if (wait_for_completion_interruptible(&queue->pop))
-			flush_signals(current);
-	}
-
-	queue->storage[queue->write & (queue->size - 1)] = header;
-	queue->write++;
-
-	complete(&queue->push);
-}
-
-struct vchiq_header *vchiu_queue_pop(struct vchiu_queue *queue)
-{
-	struct vchiq_header *header;
-
-	while (queue->write == queue->read) {
-		if (wait_for_completion_interruptible(&queue->push))
-			flush_signals(current);
-	}
-
-	header = queue->storage[queue->read & (queue->size - 1)];
-	queue->read++;
-
-	complete(&queue->pop);
-
-	return header;
-}
diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h
index 1c90a8da1a92..dcf081079c39 100644
--- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h
+++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_util.h
@@ -24,26 +24,4 @@
 
 #include "vchiq_if.h"
 
-struct vchiu_queue {
-	int size;
-	int read;
-	int write;
-	int initialized;
-
-	struct completion pop;
-	struct completion push;
-
-	struct vchiq_header **storage;
-};
-
-extern int  vchiu_queue_init(struct vchiu_queue *queue, int size);
-extern void vchiu_queue_delete(struct vchiu_queue *queue);
-
-extern int vchiu_queue_is_empty(struct vchiu_queue *queue);
-
-extern void vchiu_queue_push(struct vchiu_queue *queue,
-			     struct vchiq_header *header);
-
-extern struct vchiq_header *vchiu_queue_pop(struct vchiu_queue *queue);
-
 #endif
-- 
2.27.0


  parent reply	other threads:[~2020-06-29 20:37 UTC|newest]

Thread overview: 50+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-29 15:08 [PATCH v2 00/47] staging: vchiq: Getting rid of the vchi/vchiq split Nicolas Saenz Julienne
2020-06-29 15:08 ` [PATCH v2 01/47] staging: mmal-vchiq: Make timeout a defined parameter Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 02/47] staging: mmal-vchiq: Make a mmal_buf struct for passing parameters Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 03/47] staging: mmal-vchiq: Fixup vchiq-mmal include ordering Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 04/47] staging: mmal-vchiq: Fix client_component for 64 bit kernel Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 05/47] staging: mmal-vchiq: Always return the param size from param_get Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 06/47] staging: mmal-vchiq: If the VPU returns an error, don't negate it Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 07/47] staging: mmal-vchiq: Fix formatting errors in mmal_parameters.h Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 08/47] staging: vchiq_arm: Add a matching unregister call Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 09/47] staging: vchi: Get rid of all useless callback reasons Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 10/47] staging: vchi: Get rid of vchi_msg_peek() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 11/47] staging: vchi: Get rid of struct vchi_instance_handle Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 12/47] staging: vchi: Unify struct shim_service and struct vchi_service_handle Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 13/47] staging: vc04_services: bcm2835-audio: Use vchi_msg_hold() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 14/47] staging: vchi: Get rid of vchi_msg_dequeue() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 15/47] staging: vchi_common: Get rid of all unused definitions Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 16/47] staging: vchi: Get rid of unnecessary defines Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 17/47] staging: vc04_services: Get rid of vchi_cfg.h Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 18/47] staging: vchi: Get rid of flags argument in vchi_msg_hold() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 19/47] staging: vchi: Use enum vchiq_bulk_mode instead of vchi's transmission flags Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 20/47] staging: vchi: Use vchiq's enum vchiq_reason Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 21/47] staging: vchi: Get rid of effect less expression Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 22/47] staging: vchiq: Introduce vchiq_validate_params() Nicolas Saenz Julienne
2020-06-29 15:09 ` Nicolas Saenz Julienne [this message]
2020-06-29 15:09 ` [PATCH v2 24/47] staging: vchiq: Get rid of vchiq_util.h Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 25/47] staging: vchi: Expose struct vchi_service Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 26/47] staging: vchiq: Export vchiq_get_service_userdata() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 27/47] staging: vchiq: Export vchiq_msg_queue_push Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 28/47] staging: vchi: Get rid of vchiq_shim's message callback Nicolas Saenz Julienne
2020-08-28 14:31   ` Jacopo Mondi
2020-08-31 18:46     ` Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 29/47] staging: vchiq: Don't use a typedef for vchiq_callback Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 30/47] staging: vchi: Use struct vchiq_service_params Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 31/47] staging: vchi: Get rid of struct vchi_service Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 32/47] staging: vchiq: Pass vchiq's message when holding a message Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 33/47] staging: vchi: Rework vchi_msg_hold() to match vchiq_msg_hold() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 34/47] staging: vchiq: Unify fourcc definition mechanisms Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 35/47] staging: vchi: Get rid of struct vchiq_instance forward declaration Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 36/47] staging: vchi: Don't include vchiq_core.h Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 37/47] staging: vchiq: Get rid of unnecessary definitions in vchiq_if.h Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 38/47] staging: vchiq: Make vchiq_add_service() local Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 39/47] staging: vchiq: Move definitions only used by core into core header Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 40/47] staging: vchi: Get rid of vchi_bulk_queue_receive() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 41/47] staging: vchi: Get rid of vchi_bulk_queue_transmit() Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 42/47] staging: vchi: Move vchi_queue_kernel_message() into vchiq Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 43/47] staging: vchiq: Get rid of vchi Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 44/47] staging: vchiq: Move conditional barrier definition into vchiq_core.h Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 45/47] staging: vchiq: Use vchiq.h as the main header file for services Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 46/47] staging: vchiq: Move defines into core header Nicolas Saenz Julienne
2020-06-29 15:09 ` [PATCH v2 47/47] staging: vchiq: Move vchiq.h into include directory Nicolas Saenz Julienne

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200629150945.10720-24-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=devel@driverdev.osuosl.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kernel-list@raspberrypi.com \
    --cc=laurent.pinchart@ideasonboard.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).