From nobody Mon Jun 15 07:33:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8960C433F5 for ; Mon, 2 May 2022 18:31:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386899AbiEBSec (ORCPT ); Mon, 2 May 2022 14:34:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386896AbiEBSeZ (ORCPT ); Mon, 2 May 2022 14:34:25 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id A7F326160 for ; Mon, 2 May 2022 11:30:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651516253; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2jB/3zr/hOAAqCnoexjZJZZ3VWJxDNXF2l2/CCgwTtU=; b=NP9UcBOHUelFC7R+NAfmfV5eejjwMv1iJgSk6FNPuq70IqkJLF4ayv75ER+ijxEwQ5W/li usmfNsNCf4isrJ3YhzmQ7Iw8W8l0lMZ6p/dcI28/HFRR2ECkU40SyWTNaBR7AN9VHSgeBF r/ylh7VIk8LBnFm+L1cvi9oTRwsqS88= Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-604-tUPB_VM9Mr2sRok-O7lYKQ-1; Mon, 02 May 2022 14:30:52 -0400 X-MC-Unique: tUPB_VM9Mr2sRok-O7lYKQ-1 Received: by mail-qv1-f72.google.com with SMTP id p3-20020a05621421e300b004562c4a6b08so11660755qvj.3 for ; Mon, 02 May 2022 11:30:52 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2jB/3zr/hOAAqCnoexjZJZZ3VWJxDNXF2l2/CCgwTtU=; b=IqLN+POMqmZX3Qwvo7MAVrWDw0OlcYm0lBfdI92VSL+sX7PC7BD5YsmTOdy1Rb/Tek nwQ0awsb62fvH7i6UGzcCl0h/EWrjYT4t51MpLRO7CDlGpVuEhvKPJH04+frciaNFTMm gqZYfOOcnUbdh+JTZH90fhYT7VhLEMtR57+PjC+0Vo96J6mS/7IBemNmU9CXHPPtP/j5 O7a+Ot7fP47XeELgd0iuIB2pWx40NzM1y0E112FR88k4TtqhisebSTklXiS44nkrqJew wzzh6FNTN+jkggGilIkLVEQ6t7YRnejhH7OW5iMV+9QTVfhJa6KL6yPNG+z6m5d9yFwT GErg== X-Gm-Message-State: AOAM533F56334rNvNElykn+7cclIqd7aF3vpeHg92ZtomS27XmweCo77 BHpf2+zHQcG9AQ99ajKx1cDjAY5OqZ/l3D4yr1OdZmT0VnokbXnLbeK9DwpmmnFMbUWZkPJfgAy V1X5R9cxiKiWVjBdjuDvIvPJn X-Received: by 2002:a05:620a:1902:b0:5f1:8f5d:b0f2 with SMTP id bj2-20020a05620a190200b005f18f5db0f2mr9595652qkb.60.1651516252190; Mon, 02 May 2022 11:30:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3CJBU92TjpturzqseBQ/Q0w/mIcCijpWAzznSsZQjXuIVQUluXrP1ZKrWbC/jmzJriC7Z4w== X-Received: by 2002:a05:620a:1902:b0:5f1:8f5d:b0f2 with SMTP id bj2-20020a05620a190200b005f18f5db0f2mr9595627qkb.60.1651516251874; Mon, 02 May 2022 11:30:51 -0700 (PDT) Received: from fedora.hitronhub.home (modemcable200.11-22-96.mc.videotron.ca. [96.22.11.200]) by smtp.gmail.com with ESMTPSA id h12-20020ac846cc000000b002f39b99f68esm4412204qto.40.2022.05.02.11.30.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 11:30:51 -0700 (PDT) From: Adrien Thierry To: Nicolas Saenz Julienne , Greg Kroah-Hartman Cc: Adrien Thierry , bcm-kernel-feedback-list@broadcom.com, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] staging: vchiq_arm: add reference to vchiq device in vchiq_state Date: Mon, 2 May 2022 14:30:40 -0400 Message-Id: <20220502183045.206519-2-athierry@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220502183045.206519-1-athierry@redhat.com> References: <20220502183045.206519-1-athierry@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Add a reference to the vchiq device in the vchiq_state structure. This allows the device structure to be passed around, which will be useful in order to get rid of the global g_dev structure. Signed-off-by: Adrien Thierry --- drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c | 2 +- .../staging/vc04_services/interface/vchiq_arm/vchiq_core.c | 4 +++- .../staging/vc04_services/interface/vchiq_arm/vchiq_core.h | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c = b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index 0596ac61e286..e6e0737c85fc 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -519,7 +519,7 @@ int vchiq_platform_init(struct platform_device *pdev, s= truct vchiq_state *state) *(char **)&g_fragments_base[i * g_fragments_size] =3D NULL; sema_init(&g_free_fragments_sema, MAX_FRAGMENTS); =20 - err =3D vchiq_init_state(state, vchiq_slot_zero); + err =3D vchiq_init_state(state, vchiq_slot_zero, dev); if (err) return err; =20 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 8f99272dbd6f..0d5c39d7c6e2 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -2142,7 +2142,7 @@ vchiq_init_slots(void *mem_base, int mem_size) } =20 int -vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_z= ero) +vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_z= ero, struct device *dev) { struct vchiq_shared_state *local; struct vchiq_shared_state *remote; @@ -2169,6 +2169,8 @@ vchiq_init_state(struct vchiq_state *state, struct vc= hiq_slot_zero *slot_zero) =20 memset(state, 0, sizeof(struct vchiq_state)); =20 + state->dev =3D dev; + /* * initialize shared state pointers */ 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 82b7bd7b54b2..352017ff5309 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -315,6 +315,7 @@ struct vchiq_slot_zero { }; =20 struct vchiq_state { + struct device *dev; int id; int initialised; enum vchiq_connstate conn_state; @@ -458,7 +459,7 @@ extern struct vchiq_slot_zero * vchiq_init_slots(void *mem_base, int mem_size); =20 extern int -vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_z= ero); +vchiq_init_state(struct vchiq_state *state, struct vchiq_slot_zero *slot_z= ero, struct device *dev); =20 extern enum vchiq_status vchiq_connect_internal(struct vchiq_state *state, struct vchiq_instance *i= nstance); --=20 2.35.1 From nobody Mon Jun 15 07:33:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 49BE3C433EF for ; Mon, 2 May 2022 18:31:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386917AbiEBSee (ORCPT ); Mon, 2 May 2022 14:34:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386895AbiEBSe1 (ORCPT ); Mon, 2 May 2022 14:34:27 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4B87262E2 for ; Mon, 2 May 2022 11:30:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651516256; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IxNZxlvmTY/YQf1jwR4G6BHTrDSIv2LIpY0iREiVw9Y=; b=dxhwtM54u1X8dHdPqgqM9XUVKcKXzrHKGgExw1NKp5rswd/1R6qZFoCvP2CtJybaMI8TlK wxY4jUR7T6PbRMDGAv6kHi1BDX4F2HTHf1dUDEc5/wq8gQrC6cAmD1Z32I6+BMfV/7c441 VovLznMpqRB8cmiUby8DLFdbw6JFJpQ= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-480-89-hMP1pO7SMTPsVvRgYbw-1; Mon, 02 May 2022 14:30:55 -0400 X-MC-Unique: 89-hMP1pO7SMTPsVvRgYbw-1 Received: by mail-qk1-f200.google.com with SMTP id 66-20020a370345000000b0069fcc5f6ac4so3761008qkd.19 for ; Mon, 02 May 2022 11:30:55 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IxNZxlvmTY/YQf1jwR4G6BHTrDSIv2LIpY0iREiVw9Y=; b=2oh8ZyHclm49E/zjO4UHMAZAjBdaeyOkzNTm1wpAutCBZtXWERPmxGlBVdbO3336wA HlJiSdn6XvAW0yCE80gFaNXNZ20OuTV3UkV2m5I2TmmNLDBlZElEp6pG1QLpLMG5i5hv lI9A/jRBzXkJHB7bEcpjZ6ew/nMIxCtGOCL7h5Gll/AxZjqB8q6PLZByi98peT0DZ3Td SKo3TdgB4bdcLfg3BLmatS8fHAP7fTvoX+VNELhnsUs2JtPYX18Qmhh5GwgOMv6VK/ve qBL8WoGrfjBaTc1Ac4MrhmNXw3AtU8SWBzgLp2WAZwa6cCmnoZSxkTz7+gTF5HsDphsW hqBg== X-Gm-Message-State: AOAM530K9qQncK7XbM+xjZdPys6WP3ySOXzFGTvJmbHdWmjwD1sP1fMN /tsTSSbOCIzdRHC914xOUtEfPS79G1fj+VYoeNob4GntIGFEuV/bORLxAoj+drdx1J/yFP3yYhv KG0mu7+JxVUIFH7bhSBn9G/Lk X-Received: by 2002:ac8:5c8d:0:b0:2f3:537a:b4f2 with SMTP id r13-20020ac85c8d000000b002f3537ab4f2mr11396332qta.384.1651516254805; Mon, 02 May 2022 11:30:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzRhQfJK7m5kj5xalWLNwoPibVXJ94UN1StlX7dJn1/AEcEj3VRC/G5ZzAnPS57HSrU9s7K6Q== X-Received: by 2002:ac8:5c8d:0:b0:2f3:537a:b4f2 with SMTP id r13-20020ac85c8d000000b002f3537ab4f2mr11396302qta.384.1651516254513; Mon, 02 May 2022 11:30:54 -0700 (PDT) Received: from fedora.hitronhub.home (modemcable200.11-22-96.mc.videotron.ca. [96.22.11.200]) by smtp.gmail.com with ESMTPSA id h12-20020ac846cc000000b002f39b99f68esm4412204qto.40.2022.05.02.11.30.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 11:30:54 -0700 (PDT) From: Adrien Thierry To: Greg Kroah-Hartman , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Nicolas Saenz Julienne Cc: Adrien Thierry , linux-staging@lists.linux.dev, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] staging: vchiq_arm: get rid of global device structure Date: Mon, 2 May 2022 14:30:41 -0400 Message-Id: <20220502183045.206519-3-athierry@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220502183045.206519-1-athierry@redhat.com> References: <20220502183045.206519-1-athierry@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Get rid of the global g_dev structure. This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure" Signed-off-by: Adrien Thierry --- .../bcm2835-audio/bcm2835-vchiq.c | 7 ++- .../include/linux/raspberrypi/vchiq.h | 12 ++-- .../interface/vchiq_arm/vchiq_arm.c | 63 +++++++++---------- .../interface/vchiq_arm/vchiq_core.c | 14 ++--- .../interface/vchiq_arm/vchiq_core.h | 10 +-- .../interface/vchiq_arm/vchiq_dev.c | 2 +- .../vc04_services/vchiq-mmal/mmal-vchiq.c | 2 +- 7 files changed, 53 insertions(+), 57 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/= drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index e429b33b4d39..701abe430877 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -322,6 +322,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *als= a_stream, unsigned int size, void *src) { struct bcm2835_audio_instance *instance =3D alsa_stream->instance; + struct bcm2835_vchi_ctx *vchi_ctx =3D alsa_stream->chip->vchi_ctx; + struct vchiq_instance *vchiq_instance =3D vchi_ctx->instance; struct vc_audio_msg m =3D { .type =3D VC_AUDIO_MSG_TYPE_WRITE, .write.count =3D size, @@ -343,9 +345,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *als= a_stream, count =3D size; if (!instance->max_packet) { /* Send the message to the videocore */ - status =3D vchiq_bulk_transmit(instance->service_handle, src, - count, NULL, - VCHIQ_BULK_MODE_BLOCKING); + status =3D vchiq_bulk_transmit(vchiq_instance, instance->service_handle,= src, count, + NULL, VCHIQ_BULK_MODE_BLOCKING); } else { while (count > 0) { int bytes =3D min(instance->max_packet, count); diff --git a/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.= h b/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h index c93f2f3e87bb..715f02e7f1e1 100644 --- a/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +++ b/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h @@ -96,12 +96,12 @@ extern void vchiq_release_message(unsigned in= t service, struct vchiq_header *header); extern int vchiq_queue_kernel_message(unsigned int handle, void *data, unsigned int size); -extern enum vchiq_status vchiq_bulk_transmit(unsigned int service, - const void *data, unsigned int size, void *userdata, - enum vchiq_bulk_mode mode); -extern enum vchiq_status vchiq_bulk_receive(unsigned int service, - void *data, unsigned int size, void *userdata, - enum vchiq_bulk_mode mode); +extern enum vchiq_status vchiq_bulk_transmit(struct vchiq_instance *instan= ce, unsigned int service, + const void *data, unsigned int size, void *userdata, + enum vchiq_bulk_mode mode); +extern enum vchiq_status vchiq_bulk_receive(struct vchiq_instance *instanc= e, unsigned int service, + void *data, unsigned int size, void *userdata, + enum vchiq_bulk_mode mode); extern void *vchiq_get_service_userdata(unsigned int service); extern enum vchiq_status vchiq_get_peer_version(unsigned int handle, short *peer_version); diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c = b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index e6e0737c85fc..3b447c635c3f 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -148,12 +148,11 @@ static unsigned int g_fragments_size; static char *g_fragments_base; static char *g_free_fragments; static struct semaphore g_free_fragments_sema; -static struct device *g_dev; =20 static DEFINE_SEMAPHORE(g_free_fragments_mutex); =20 static enum vchiq_status -vchiq_blocking_bulk_transfer(unsigned int handle, void *data, +vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int= handle, void *data, unsigned int size, enum vchiq_bulk_dir dir); =20 static irqreturn_t @@ -175,17 +174,17 @@ vchiq_doorbell_irq(int irq, void *dev_id) } =20 static void -cleanup_pagelistinfo(struct vchiq_pagelist_info *pagelistinfo) +cleanup_pagelistinfo(struct vchiq_instance *instance, struct vchiq_pagelis= t_info *pagelistinfo) { if (pagelistinfo->scatterlist_mapped) { - dma_unmap_sg(g_dev, pagelistinfo->scatterlist, + dma_unmap_sg(instance->state->dev, pagelistinfo->scatterlist, pagelistinfo->num_pages, pagelistinfo->dma_dir); } =20 if (pagelistinfo->pages_need_release) unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages); =20 - dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size, + dma_free_coherent(instance->state->dev, pagelistinfo->pagelist_buffer_siz= e, pagelistinfo->pagelist, pagelistinfo->dma_addr); } =20 @@ -212,7 +211,7 @@ is_adjacent_block(u32 *addrs, u32 addr, unsigned int k) */ =20 static struct vchiq_pagelist_info * -create_pagelist(char *buf, char __user *ubuf, +create_pagelist(struct vchiq_instance *instance, char *buf, char __user *u= buf, size_t count, unsigned short type) { struct pagelist *pagelist; @@ -250,7 +249,7 @@ create_pagelist(char *buf, char __user *ubuf, /* Allocate enough storage to hold the page pointers and the page * list */ - pagelist =3D dma_alloc_coherent(g_dev, pagelist_size, &dma_addr, + pagelist =3D dma_alloc_coherent(instance->state->dev, pagelist_size, &dma= _addr, GFP_KERNEL); =20 vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist); @@ -292,7 +291,7 @@ create_pagelist(char *buf, char __user *ubuf, size_t bytes =3D PAGE_SIZE - off; =20 if (!pg) { - cleanup_pagelistinfo(pagelistinfo); + cleanup_pagelistinfo(instance, pagelistinfo); return NULL; } =20 @@ -315,7 +314,7 @@ create_pagelist(char *buf, char __user *ubuf, /* This is probably due to the process being killed */ if (actual_pages > 0) unpin_user_pages(pages, actual_pages); - cleanup_pagelistinfo(pagelistinfo); + cleanup_pagelistinfo(instance, pagelistinfo); return NULL; } /* release user pages */ @@ -338,13 +337,13 @@ create_pagelist(char *buf, char __user *ubuf, count -=3D len; } =20 - dma_buffers =3D dma_map_sg(g_dev, + dma_buffers =3D dma_map_sg(instance->state->dev, scatterlist, num_pages, pagelistinfo->dma_dir); =20 if (dma_buffers =3D=3D 0) { - cleanup_pagelistinfo(pagelistinfo); + cleanup_pagelistinfo(instance, pagelistinfo); return NULL; } =20 @@ -378,7 +377,7 @@ create_pagelist(char *buf, char __user *ubuf, char *fragments; =20 if (down_interruptible(&g_free_fragments_sema)) { - cleanup_pagelistinfo(pagelistinfo); + cleanup_pagelistinfo(instance, pagelistinfo); return NULL; } =20 @@ -397,7 +396,7 @@ create_pagelist(char *buf, char __user *ubuf, } =20 static void -free_pagelist(struct vchiq_pagelist_info *pagelistinfo, +free_pagelist(struct vchiq_instance *instance, struct vchiq_pagelist_info = *pagelistinfo, int actual) { struct pagelist *pagelist =3D pagelistinfo->pagelist; @@ -411,7 +410,7 @@ free_pagelist(struct vchiq_pagelist_info *pagelistinfo, * NOTE: dma_unmap_sg must be called before the * cpu can touch any of the data/pages. */ - dma_unmap_sg(g_dev, pagelistinfo->scatterlist, + dma_unmap_sg(instance->state->dev, pagelistinfo->scatterlist, pagelistinfo->num_pages, pagelistinfo->dma_dir); pagelistinfo->scatterlist_mapped =3D 0; =20 @@ -460,7 +459,7 @@ free_pagelist(struct vchiq_pagelist_info *pagelistinfo, set_page_dirty(pages[i]); } =20 - cleanup_pagelistinfo(pagelistinfo); + cleanup_pagelistinfo(instance, pagelistinfo); } =20 int vchiq_platform_init(struct platform_device *pdev, struct vchiq_state *= state) @@ -547,7 +546,6 @@ int vchiq_platform_init(struct platform_device *pdev, s= truct vchiq_state *state) return err ? : -ENXIO; } =20 - g_dev =3D dev; vchiq_log_info(vchiq_arm_log_level, "vchiq_init - done (slots %pK, phys %= pad)", vchiq_slot_zero, &slot_phys); =20 @@ -615,12 +613,12 @@ remote_event_signal(struct remote_event *event) } =20 int -vchiq_prepare_bulk_data(struct vchiq_bulk *bulk, void *offset, +vchiq_prepare_bulk_data(struct vchiq_instance *instance, struct vchiq_bulk= *bulk, void *offset, void __user *uoffset, int size, int dir) { struct vchiq_pagelist_info *pagelistinfo; =20 - pagelistinfo =3D create_pagelist(offset, uoffset, size, + pagelistinfo =3D create_pagelist(instance, offset, uoffset, size, (dir =3D=3D VCHIQ_BULK_RECEIVE) ? PAGELIST_READ : PAGELIST_WRITE); @@ -640,10 +638,10 @@ vchiq_prepare_bulk_data(struct vchiq_bulk *bulk, void= *offset, } =20 void -vchiq_complete_bulk(struct vchiq_bulk *bulk) +vchiq_complete_bulk(struct vchiq_instance *instance, struct vchiq_bulk *bu= lk) { if (bulk && bulk->remote_data && bulk->actual) - free_pagelist((struct vchiq_pagelist_info *)bulk->remote_data, + free_pagelist(instance, (struct vchiq_pagelist_info *)bulk->remote_data, bulk->actual); } =20 @@ -834,8 +832,8 @@ vchiq_open_service(struct vchiq_instance *instance, EXPORT_SYMBOL(vchiq_open_service); =20 enum vchiq_status -vchiq_bulk_transmit(unsigned int handle, const void *data, unsigned int si= ze, - void *userdata, enum vchiq_bulk_mode mode) +vchiq_bulk_transmit(struct vchiq_instance *instance, unsigned int handle, = const void *data, + unsigned int size, void *userdata, enum vchiq_bulk_mode mode) { enum vchiq_status status; =20 @@ -843,13 +841,13 @@ vchiq_bulk_transmit(unsigned int handle, const void *= data, unsigned int size, switch (mode) { case VCHIQ_BULK_MODE_NOCALLBACK: case VCHIQ_BULK_MODE_CALLBACK: - status =3D vchiq_bulk_transfer(handle, + status =3D vchiq_bulk_transfer(instance, handle, (void *)data, NULL, size, userdata, mode, VCHIQ_BULK_TRANSMIT); break; case VCHIQ_BULK_MODE_BLOCKING: - status =3D vchiq_blocking_bulk_transfer(handle, (void *)data, size, + status =3D vchiq_blocking_bulk_transfer(instance, handle, (void *)data,= size, VCHIQ_BULK_TRANSMIT); break; default: @@ -871,8 +869,8 @@ vchiq_bulk_transmit(unsigned int handle, const void *da= ta, unsigned int size, } EXPORT_SYMBOL(vchiq_bulk_transmit); =20 -enum vchiq_status vchiq_bulk_receive(unsigned int handle, void *data, - unsigned int size, void *userdata, +enum vchiq_status vchiq_bulk_receive(struct vchiq_instance *instance, unsi= gned int handle, + void *data, unsigned int size, void *userdata, enum vchiq_bulk_mode mode) { enum vchiq_status status; @@ -881,12 +879,12 @@ enum vchiq_status vchiq_bulk_receive(unsigned int han= dle, void *data, switch (mode) { case VCHIQ_BULK_MODE_NOCALLBACK: case VCHIQ_BULK_MODE_CALLBACK: - status =3D vchiq_bulk_transfer(handle, data, NULL, + status =3D vchiq_bulk_transfer(instance, handle, data, NULL, size, userdata, mode, VCHIQ_BULK_RECEIVE); break; case VCHIQ_BULK_MODE_BLOCKING: - status =3D vchiq_blocking_bulk_transfer(handle, (void *)data, size, + status =3D vchiq_blocking_bulk_transfer(instance, handle, (void *)data,= size, VCHIQ_BULK_RECEIVE); break; default: @@ -909,10 +907,9 @@ enum vchiq_status vchiq_bulk_receive(unsigned int hand= le, void *data, EXPORT_SYMBOL(vchiq_bulk_receive); =20 static enum vchiq_status -vchiq_blocking_bulk_transfer(unsigned int handle, void *data, unsigned int= size, - enum vchiq_bulk_dir dir) +vchiq_blocking_bulk_transfer(struct vchiq_instance *instance, unsigned int= handle, void *data, + unsigned int size, enum vchiq_bulk_dir dir) { - struct vchiq_instance *instance; struct vchiq_service *service; enum vchiq_status status; struct bulk_waiter_node *waiter =3D NULL, *iter; @@ -921,8 +918,6 @@ vchiq_blocking_bulk_transfer(unsigned int handle, void = *data, unsigned int size, if (!service) return VCHIQ_ERROR; =20 - instance =3D service->instance; - vchiq_service_put(service); =20 mutex_lock(&instance->bulk_waiter_list_mutex); @@ -959,7 +954,7 @@ vchiq_blocking_bulk_transfer(unsigned int handle, void = *data, unsigned int size, } } =20 - status =3D vchiq_bulk_transfer(handle, data, NULL, size, + status =3D vchiq_bulk_transfer(instance, handle, data, NULL, size, &waiter->bulk_waiter, VCHIQ_BULK_MODE_BLOCKING, dir); if ((status !=3D VCHIQ_RETRY) || fatal_signal_pending(current) || !waiter= ->bulk_waiter.bulk) { 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 0d5c39d7c6e2..04eec18835da 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -1441,7 +1441,7 @@ abort_outstanding_bulks(struct vchiq_service *service, } =20 if (queue->process !=3D queue->local_insert) { - vchiq_complete_bulk(bulk); + vchiq_complete_bulk(service->instance, bulk); =20 vchiq_log_info(SRVTRACE_LEVEL(service), "%s %c%c%c%c d:%d ABORTED - tx len:%d, rx len:%d", @@ -1769,7 +1769,7 @@ parse_message(struct vchiq_state *state, struct vchiq= _header *header) =20 DEBUG_TRACE(PARSE_LINE); WARN_ON(queue->process =3D=3D queue->local_insert); - vchiq_complete_bulk(bulk); + vchiq_complete_bulk(service->instance, bulk); queue->process++; mutex_unlock(&service->bulk_mutex); DEBUG_TRACE(PARSE_LINE); @@ -2998,9 +2998,9 @@ vchiq_remove_service(unsigned int handle) * When called in blocking mode, the userdata field points to a bulk_waiter * structure. */ -enum vchiq_status vchiq_bulk_transfer(unsigned int handle, void *offset, v= oid __user *uoffset, - int size, void *userdata, enum vchiq_bulk_mode mode, - enum vchiq_bulk_dir dir) +enum vchiq_status vchiq_bulk_transfer(struct vchiq_instance *instance, uns= igned int handle, + void *offset, void __user *uoffset, int size, void *userdata, + enum vchiq_bulk_mode mode, enum vchiq_bulk_dir dir) { struct vchiq_service *service =3D find_service_by_handle(handle); struct vchiq_bulk_queue *queue; @@ -3077,7 +3077,7 @@ enum vchiq_status vchiq_bulk_transfer(unsigned int ha= ndle, void *offset, void __ bulk->size =3D size; bulk->actual =3D VCHIQ_BULK_ACTUAL_ABORTED; =20 - if (vchiq_prepare_bulk_data(bulk, offset, uoffset, size, dir)) + if (vchiq_prepare_bulk_data(instance, bulk, offset, uoffset, size, dir)) goto unlock_error_exit; =20 wmb(); @@ -3141,7 +3141,7 @@ enum vchiq_status vchiq_bulk_transfer(unsigned int ha= ndle, void *offset, void __ unlock_both_error_exit: mutex_unlock(&state->slot_mutex); cancel_bulk_error_exit: - vchiq_complete_bulk(bulk); + vchiq_complete_bulk(service->instance, bulk); unlock_error_exit: mutex_unlock(&service->bulk_mutex); =20 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 352017ff5309..2ce54ce9f02a 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -489,8 +489,8 @@ extern void remote_event_pollall(struct vchiq_state *state); =20 extern enum vchiq_status -vchiq_bulk_transfer(unsigned int handle, void *offset, void __user *uoffse= t, - int size, void *userdata, enum vchiq_bulk_mode mode, +vchiq_bulk_transfer(struct vchiq_instance *instance, unsigned int handle, = void *offset, + void __user *uoffset, int size, void *userdata, enum vchiq_bulk_mode= mode, enum vchiq_bulk_dir dir); =20 extern int @@ -556,10 +556,10 @@ vchiq_queue_message(unsigned int handle, void *context, size_t size); =20 -int vchiq_prepare_bulk_data(struct vchiq_bulk *bulk, void *offset, void __= user *uoffset, - int size, int dir); +int vchiq_prepare_bulk_data(struct vchiq_instance *instance, struct vchiq_= bulk *bulk, void *offset, + void __user *uoffset, int size, int dir); =20 -void vchiq_complete_bulk(struct vchiq_bulk *bulk); +void vchiq_complete_bulk(struct vchiq_instance *instance, struct vchiq_bul= k *bulk); =20 void remote_event_signal(struct remote_event *event); =20 diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c = b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index 66bbfec332ba..077e3fcbd651 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -330,7 +330,7 @@ static int vchiq_irq_queue_bulk_tx_rx(struct vchiq_inst= ance *instance, userdata =3D args->userdata; } =20 - status =3D vchiq_bulk_transfer(args->handle, NULL, args->data, args->size, + status =3D vchiq_bulk_transfer(instance, args->handle, NULL, args->data, = args->size, userdata, args->mode, dir); =20 if (!waiter) { diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/driver= s/staging/vc04_services/vchiq-mmal/mmal-vchiq.c index 249dd3e30c2f..88813af8de49 100644 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c @@ -293,7 +293,7 @@ static void buffer_to_host_work_cb(struct work_struct *= work) len =3D 8; /* queue the bulk submission */ vchiq_use_service(instance->service_handle); - ret =3D vchiq_bulk_receive(instance->service_handle, + ret =3D vchiq_bulk_receive(instance->vchiq_instance, instance->service_ha= ndle, msg_context->u.bulk.buffer->buffer, /* Actual receive needs to be a multiple * of 4 bytes --=20 2.35.1 From nobody Mon Jun 15 07:33:48 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EFB6EC433F5 for ; Mon, 2 May 2022 18:31:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1386929AbiEBSem (ORCPT ); Mon, 2 May 2022 14:34:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47866 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1386911AbiEBSed (ORCPT ); Mon, 2 May 2022 14:34:33 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 0C4C3614D for ; Mon, 2 May 2022 11:31:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651516260; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=sX9IPjZzNegxu8ysaGBmB7nYN8pL7VVRWVEhz+Com/0=; b=faZjhYN3YUZCwLI5D6wiPCHqGgb+cMiguTIXbFu0lyI4ElEC8UkWYfXQhaumdwhhPxfIBZ uUed/yIra8CkD64zAugJKg8n/Zylk6TBijSpKPrwsCPVHJTnGWzjjIlNz/FL6589Lj2KTI N4A2cl6ZL2U1vjF2RR9JzCOA7OOJAsI= Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-219-rMMqOpe2M3uhHEWhWhPu0w-1; Mon, 02 May 2022 14:30:59 -0400 X-MC-Unique: rMMqOpe2M3uhHEWhWhPu0w-1 Received: by mail-qk1-f200.google.com with SMTP id d186-20020a3768c3000000b0069fcfacbea0so3484071qkc.0 for ; Mon, 02 May 2022 11:30:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sX9IPjZzNegxu8ysaGBmB7nYN8pL7VVRWVEhz+Com/0=; b=fRxHf65me/tweRHkX4ES3ZQbw7svg7jbZs7LScYKTC2DyXBAI46MoGBYUz4kn4vRzf BhMltqGoy64nFgGaGSFqKk3BMMJxpj1T9q9GygQS3iO79rsb8EM+BuvsEjxT/53+RenL FT0b9QXepuC3dywGbYTnOFmlvKNBJC7RRaLtClRfl2sLIUebw+aseJDzrES5SH25vtn5 C3lS9+Th41UkaDUF6NAbBP20BF/VzIR8ERa8OVdnVbmBq5MamDAONFKueyJo28dD0VPu 5woERjyrzh6t0a4V72fho2j404EpSvYaaZbt2xdY4HwuARVSAdCHuOnromWQe/lFC6/3 DOhA== X-Gm-Message-State: AOAM531nFyTZ9K72oTaO2SJdcpKXWJ3tV6gzOtaL5OcRLVtZKT3Pr/cE dddv7VC5Qi+LoP3hrl9VRwl3/dpOR1vERYy6XwugpbaPCn+VAfs9zfdjXgA2N9fbeB6HP+1nKsf RCTik94OqF3LzAmd/DftToJEb X-Received: by 2002:a05:622a:2c8:b0:2f3:a3d3:5bb with SMTP id a8-20020a05622a02c800b002f3a3d305bbmr6027772qtx.593.1651516258026; Mon, 02 May 2022 11:30:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwNS7ss0/2w6Y63gGyneuMpGrLhb1WodEg5wU/DlQmQJDMVH9bUuXqF4onwapZsNXUQFkcVNg== X-Received: by 2002:a05:622a:2c8:b0:2f3:a3d3:5bb with SMTP id a8-20020a05622a02c800b002f3a3d305bbmr6027738qtx.593.1651516257589; Mon, 02 May 2022 11:30:57 -0700 (PDT) Received: from fedora.hitronhub.home (modemcable200.11-22-96.mc.videotron.ca. [96.22.11.200]) by smtp.gmail.com with ESMTPSA id h12-20020ac846cc000000b002f39b99f68esm4412204qto.40.2022.05.02.11.30.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 May 2022 11:30:57 -0700 (PDT) From: Adrien Thierry To: Greg Kroah-Hartman , Florian Fainelli , Ray Jui , Scott Branden , bcm-kernel-feedback-list@broadcom.com, Nicolas Saenz Julienne Cc: Adrien Thierry , linux-staging@lists.linux.dev, linux-rpi-kernel@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] staging: vchiq_arm: get rid of global vchiq_states array Date: Mon, 2 May 2022 14:30:42 -0400 Message-Id: <20220502183045.206519-4-athierry@redhat.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220502183045.206519-1-athierry@redhat.com> References: <20220502183045.206519-1-athierry@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Get rid of the global vchiq_states array. Access the vchiq state from the vchiq instance instead. This is part of an effort to address TODO item "Get rid of all non essential global structures and create a proper per device structure" Signed-off-by: Adrien Thierry --- .../bcm2835-audio/bcm2835-vchiq.c | 33 +++++--- .../include/linux/raspberrypi/vchiq.h | 37 +++++---- .../interface/vchiq_arm/vchiq_arm.c | 29 ++++--- .../interface/vchiq_arm/vchiq_arm.h | 8 +- .../interface/vchiq_arm/vchiq_core.c | 80 ++++++++++--------- .../interface/vchiq_arm/vchiq_core.h | 25 ++---- .../interface/vchiq_arm/vchiq_dev.c | 38 ++++----- .../vc04_services/vchiq-mmal/mmal-vchiq.c | 61 +++++++------- 8 files changed, 159 insertions(+), 152 deletions(-) diff --git a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c b/= drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c index 701abe430877..f4c2c9506d86 100644 --- a/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c +++ b/drivers/staging/vc04_services/bcm2835-audio/bcm2835-vchiq.c @@ -25,12 +25,14 @@ MODULE_PARM_DESC(force_bulk, "Force use of vchiq bulk f= or audio"); static void bcm2835_audio_lock(struct bcm2835_audio_instance *instance) { mutex_lock(&instance->vchi_mutex); - vchiq_use_service(instance->service_handle); + vchiq_use_service(instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle); } =20 static void bcm2835_audio_unlock(struct bcm2835_audio_instance *instance) { - vchiq_release_service(instance->service_handle); + vchiq_release_service(instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle); mutex_unlock(&instance->vchi_mutex); } =20 @@ -44,8 +46,8 @@ static int bcm2835_audio_send_msg_locked(struct bcm2835_a= udio_instance *instance init_completion(&instance->msg_avail_comp); } =20 - status =3D vchiq_queue_kernel_message(instance->service_handle, - m, sizeof(*m)); + status =3D vchiq_queue_kernel_message(instance->alsa_stream->chip->vchi_c= tx->instance, + instance->service_handle, m, sizeof(*m)); if (status) { dev_err(instance->dev, "vchi message queue failed: %d, msg=3D%d\n", @@ -89,11 +91,13 @@ static int bcm2835_audio_send_simple(struct bcm2835_aud= io_instance *instance, return bcm2835_audio_send_msg(instance, &m, wait); } =20 -static enum vchiq_status audio_vchi_callback(enum vchiq_reason reason, +static enum vchiq_status audio_vchi_callback(struct vchiq_instance *vchiq_= instance, + enum vchiq_reason reason, struct vchiq_header *header, unsigned int handle, void *userdata) { - struct bcm2835_audio_instance *instance =3D vchiq_get_service_userdata(ha= ndle); + struct bcm2835_audio_instance *instance =3D vchiq_get_service_userdata(vc= hiq_instance, + handle); struct vc_audio_msg *m; =20 if (reason !=3D VCHIQ_MESSAGE_AVAILABLE) @@ -114,7 +118,7 @@ static enum vchiq_status audio_vchi_callback(enum vchiq= _reason reason, dev_err(instance->dev, "unexpected callback type=3D%d\n", m->type); } =20 - vchiq_release_message(handle, header); + vchiq_release_message(vchiq_instance, instance->service_handle, header); return VCHIQ_SUCCESS; } =20 @@ -143,7 +147,8 @@ vc_vchi_audio_init(struct vchiq_instance *vchiq_instanc= e, } =20 /* Finished with the service for now */ - vchiq_release_service(instance->service_handle); + vchiq_release_service(instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle); =20 return 0; } @@ -153,10 +158,12 @@ static void vc_vchi_audio_deinit(struct bcm2835_audio= _instance *instance) int status; =20 mutex_lock(&instance->vchi_mutex); - vchiq_use_service(instance->service_handle); + vchiq_use_service(instance->alsa_stream->chip->vchi_ctx->instance, + instance->service_handle); =20 /* Close all VCHI service connections */ - status =3D vchiq_close_service(instance->service_handle); + status =3D vchiq_close_service(instance->alsa_stream->chip->vchi_ctx->ins= tance, + instance->service_handle); if (status) { dev_err(instance->dev, "failed to close VCHI service connection (status=3D%d)\n", @@ -226,7 +233,7 @@ int bcm2835_audio_open(struct bcm2835_alsa_stream *alsa= _stream) goto deinit; =20 bcm2835_audio_lock(instance); - vchiq_get_peer_version(instance->service_handle, + vchiq_get_peer_version(vchi_ctx->instance, instance->service_handle, &instance->peer_version); bcm2835_audio_unlock(instance); if (instance->peer_version < 2 || force_bulk) @@ -351,8 +358,8 @@ int bcm2835_audio_write(struct bcm2835_alsa_stream *als= a_stream, while (count > 0) { int bytes =3D min(instance->max_packet, count); =20 - status =3D vchiq_queue_kernel_message(instance->service_handle, - src, bytes); + status =3D vchiq_queue_kernel_message(vchiq_instance, + instance->service_handle, src, bytes); src +=3D bytes; count -=3D bytes; } diff --git a/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.= h b/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h index 715f02e7f1e1..ddb7bcdffc64 100644 --- a/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h +++ b/drivers/staging/vc04_services/include/linux/raspberrypi/vchiq.h @@ -53,9 +53,12 @@ struct vchiq_element { unsigned int size; }; =20 +struct vchiq_instance; + struct vchiq_service_base { int fourcc; - enum vchiq_status (*callback)(enum vchiq_reason reason, + enum vchiq_status (*callback)(struct vchiq_instance *instance, + enum vchiq_reason reason, struct vchiq_header *header, unsigned int handle, void *bulk_userdata); @@ -71,7 +74,8 @@ struct vchiq_completion_data_kernel { =20 struct vchiq_service_params_kernel { int fourcc; - enum vchiq_status (*callback)(enum vchiq_reason reason, + enum vchiq_status (*callback)(struct vchiq_instance *instance, + enum vchiq_reason reason, struct vchiq_header *header, unsigned int handle, void *bulk_userdata); @@ -80,31 +84,32 @@ struct vchiq_service_params_kernel { short version_min; /* Update for incompatible changes */ }; =20 -struct vchiq_instance; - extern enum vchiq_status vchiq_initialise(struct vchiq_instance **pinstanc= e); extern enum vchiq_status vchiq_shutdown(struct vchiq_instance *instance); extern enum vchiq_status vchiq_connect(struct vchiq_instance *instance); extern enum vchiq_status vchiq_open_service(struct vchiq_instance *instanc= e, const struct vchiq_service_params_kernel *params, unsigned int *pservice); -extern enum vchiq_status vchiq_close_service(unsigned int service); -extern enum vchiq_status vchiq_use_service(unsigned int service); -extern enum vchiq_status vchiq_release_service(unsigned int service); -extern void vchiq_msg_queue_push(unsigned int handle, struct vchiq_header = *header); -extern void vchiq_release_message(unsigned int service, - struct vchiq_header *header); -extern int vchiq_queue_kernel_message(unsigned int handle, void *data, - unsigned int size); +extern enum vchiq_status vchiq_close_service(struct vchiq_instance *instan= ce, + unsigned int service); +extern enum vchiq_status vchiq_use_service(struct vchiq_instance *instance= , unsigned int service); +extern enum vchiq_status vchiq_release_service(struct vchiq_instance *inst= ance, + unsigned int service); +extern void vchiq_msg_queue_push(struct vchiq_instance *instance, unsigned= int handle, + struct vchiq_header *header); +extern void vchiq_release_message(struct vchiq_instance *instance, unsigne= d int service, + struct vchiq_header *header); +extern int vchiq_queue_kernel_message(struct vchiq_instance *instance, uns= igned int handle, + void *data, unsigned int size); extern enum vchiq_status vchiq_bulk_transmit(struct vchiq_instance *instan= ce, unsigned int service, const void *data, unsigned int size, void *userdata, enum vchiq_bulk_mode mode); extern enum vchiq_status vchiq_bulk_receive(struct vchiq_instance *instanc= e, unsigned int service, void *data, unsigned int size, void *userdata, enum vchiq_bulk_mode mode); -extern void *vchiq_get_service_userdata(unsigned int service); -extern enum vchiq_status vchiq_get_peer_version(unsigned int handle, - short *peer_version); -extern struct vchiq_header *vchiq_msg_hold(unsigned int handle); +extern void *vchiq_get_service_userdata(struct vchiq_instance *instance, u= nsigned int service); +extern enum vchiq_status vchiq_get_peer_version(struct vchiq_instance *ins= tance, + unsigned int handle, short *peer_version); +extern struct vchiq_header *vchiq_msg_hold(struct vchiq_instance *instance= , unsigned int handle); =20 #endif /* VCHIQ_H */ diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c = b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c index 3b447c635c3f..2e5de4b4967b 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c @@ -819,7 +819,7 @@ vchiq_open_service(struct vchiq_instance *instance, *phandle =3D service->handle; status =3D vchiq_open_service_internal(service, current->pid); if (status !=3D VCHIQ_SUCCESS) { - vchiq_remove_service(service->handle); + vchiq_remove_service(instance, service->handle); *phandle =3D VCHIQ_SERVICE_HANDLE_INVALID; } } @@ -914,7 +914,7 @@ vchiq_blocking_bulk_transfer(struct vchiq_instance *ins= tance, unsigned int handl enum vchiq_status status; struct bulk_waiter_node *waiter =3D NULL, *iter; =20 - service =3D find_service_by_handle(handle); + service =3D find_service_by_handle(instance, handle); if (!service) return VCHIQ_ERROR; =20 @@ -1041,8 +1041,8 @@ add_completion(struct vchiq_instance *instance, enum = vchiq_reason reason, } =20 enum vchiq_status -service_callback(enum vchiq_reason reason, struct vchiq_header *header, - unsigned int handle, void *bulk_userdata) +service_callback(struct vchiq_instance *instance, enum vchiq_reason reason, + struct vchiq_header *header, unsigned int handle, void *bulk_userdata) { /* * How do we ensure the callback goes to the right client? @@ -1052,7 +1052,6 @@ service_callback(enum vchiq_reason reason, struct vch= iq_header *header, */ struct user_service *user_service; struct vchiq_service *service; - struct vchiq_instance *instance; bool skip_completion =3D false; =20 DEBUG_INITIALISE(g_state.local); @@ -1060,16 +1059,15 @@ service_callback(enum vchiq_reason reason, struct v= chiq_header *header, DEBUG_TRACE(SERVICE_CALLBACK_LINE); =20 rcu_read_lock(); - service =3D handle_to_service(handle); + service =3D handle_to_service(instance, handle); if (WARN_ON(!service)) { rcu_read_unlock(); return VCHIQ_SUCCESS; } =20 user_service =3D (struct user_service *)service->base.userdata; - instance =3D user_service->instance; =20 - if (!instance || instance->closing) { + if (instance->closing) { rcu_read_unlock(); return VCHIQ_SUCCESS; } @@ -1313,7 +1311,8 @@ vchiq_get_state(void) */ =20 static enum vchiq_status -vchiq_keepalive_vchiq_callback(enum vchiq_reason reason, +vchiq_keepalive_vchiq_callback(struct vchiq_instance *instance, + enum vchiq_reason reason, struct vchiq_header *header, unsigned int service_user, void *bulk_user) { @@ -1382,14 +1381,14 @@ vchiq_keepalive_thread_func(void *v) */ while (uc--) { atomic_inc(&arm_state->ka_use_ack_count); - status =3D vchiq_use_service(ka_handle); + status =3D vchiq_use_service(instance, ka_handle); if (status !=3D VCHIQ_SUCCESS) { vchiq_log_error(vchiq_susp_log_level, "%s vchiq_use_service error %d", __func__, status); } } while (rc--) { - status =3D vchiq_release_service(ka_handle); + status =3D vchiq_release_service(instance, ka_handle); if (status !=3D VCHIQ_SUCCESS) { vchiq_log_error(vchiq_susp_log_level, "%s vchiq_release_service error %d", __func__, @@ -1585,10 +1584,10 @@ vchiq_instance_set_trace(struct vchiq_instance *ins= tance, int trace) } =20 enum vchiq_status -vchiq_use_service(unsigned int handle) +vchiq_use_service(struct vchiq_instance *instance, unsigned int handle) { enum vchiq_status ret =3D VCHIQ_ERROR; - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); =20 if (service) { ret =3D vchiq_use_internal(service->state, service, USE_TYPE_SERVICE); @@ -1599,10 +1598,10 @@ vchiq_use_service(unsigned int handle) EXPORT_SYMBOL(vchiq_use_service); =20 enum vchiq_status -vchiq_release_service(unsigned int handle) +vchiq_release_service(struct vchiq_instance *instance, unsigned int handle) { enum vchiq_status ret =3D VCHIQ_ERROR; - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); =20 if (service) { ret =3D vchiq_release_internal(service->state, service); diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h = b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h index 2aa46b119a46..2851ef6b9cd0 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h @@ -86,10 +86,10 @@ extern struct vchiq_state * vchiq_get_state(void); =20 enum vchiq_status -vchiq_use_service(unsigned int handle); +vchiq_use_service(struct vchiq_instance *instance, unsigned int handle); =20 extern enum vchiq_status -vchiq_release_service(unsigned int handle); +vchiq_release_service(struct vchiq_instance *instance, unsigned int handle= ); =20 extern enum vchiq_status vchiq_check_service(struct vchiq_service *service); @@ -138,8 +138,8 @@ static inline int vchiq_register_chrdev(struct device *= parent) { return 0; } #endif /* IS_ENABLED(CONFIG_VCHIQ_CDEV) */ =20 extern enum vchiq_status -service_callback(enum vchiq_reason reason, struct vchiq_header *header, - unsigned int handle, void *bulk_userdata); +service_callback(struct vchiq_instance *vchiq_instance, enum vchiq_reason = reason, + struct vchiq_header *header, unsigned int handle, void *bulk_userdata); =20 extern void free_bulk_waiter(struct vchiq_instance *instance); 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 04eec18835da..0e9bd33078b2 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.c @@ -13,6 +13,7 @@ #include #include =20 +#include "vchiq_arm.h" #include "vchiq_core.h" =20 #define VCHIQ_SLOT_HANDLER_STACK 8192 @@ -161,7 +162,6 @@ int vchiq_sync_log_level =3D VCHIQ_LOG_DEFAULT; DEFINE_SPINLOCK(bulk_waiter_spinlock); static DEFINE_SPINLOCK(quota_spinlock); =20 -struct vchiq_state *vchiq_states[VCHIQ_MAX_STATES]; static unsigned int handle_seq; =20 static const char *const srvstate_names[] =3D { @@ -234,13 +234,20 @@ set_service_state(struct vchiq_service *service, int = newstate) service->srvstate =3D newstate; } =20 +struct vchiq_service *handle_to_service(struct vchiq_instance *instance, u= nsigned int handle) +{ + int idx =3D handle & (VCHIQ_MAX_SERVICES - 1); + + return rcu_dereference(instance->state->services[idx]); +} + struct vchiq_service * -find_service_by_handle(unsigned int handle) +find_service_by_handle(struct vchiq_instance *instance, unsigned int handl= e) { struct vchiq_service *service; =20 rcu_read_lock(); - service =3D handle_to_service(handle); + service =3D handle_to_service(instance, handle); if (service && service->srvstate !=3D VCHIQ_SRVSTATE_FREE && service->handle =3D=3D handle && kref_get_unless_zero(&service->ref_count)) { @@ -281,7 +288,7 @@ find_service_for_instance(struct vchiq_instance *instan= ce, unsigned int handle) struct vchiq_service *service; =20 rcu_read_lock(); - service =3D handle_to_service(handle); + service =3D handle_to_service(instance, handle); if (service && service->srvstate !=3D VCHIQ_SRVSTATE_FREE && service->handle =3D=3D handle && service->instance =3D=3D instance && @@ -302,7 +309,7 @@ find_closed_service_for_instance(struct vchiq_instance = *instance, unsigned int h struct vchiq_service *service; =20 rcu_read_lock(); - service =3D handle_to_service(handle); + service =3D handle_to_service(instance, handle); if (service && (service->srvstate =3D=3D VCHIQ_SRVSTATE_FREE || service->srvstate =3D=3D VCHIQ_SRVSTATE_CLOSED) && @@ -398,26 +405,26 @@ vchiq_service_put(struct vchiq_service *service) } =20 int -vchiq_get_client_id(unsigned int handle) +vchiq_get_client_id(struct vchiq_instance *instance, unsigned int handle) { struct vchiq_service *service; int id; =20 rcu_read_lock(); - service =3D handle_to_service(handle); + service =3D handle_to_service(instance, handle); id =3D service ? service->client_id : 0; rcu_read_unlock(); return id; } =20 void * -vchiq_get_service_userdata(unsigned int handle) +vchiq_get_service_userdata(struct vchiq_instance *instance, unsigned int h= andle) { void *userdata; struct vchiq_service *service; =20 rcu_read_lock(); - service =3D handle_to_service(handle); + service =3D handle_to_service(instance, handle); userdata =3D service ? service->base.userdata : NULL; rcu_read_unlock(); return userdata; @@ -466,7 +473,8 @@ make_service_callback(struct vchiq_service *service, en= um vchiq_reason reason, vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %pK, %pK)", service->state->id, service->localport, reason_names[reason], header, bulk_userdata); - status =3D service->base.callback(reason, header, service->handle, bulk_u= serdata); + status =3D service->base.callback(service->instance, reason, header, serv= ice->handle, + bulk_userdata); if (status =3D=3D VCHIQ_ERROR) { vchiq_log_warning(vchiq_core_log_level, "%d: ignoring ERROR from callback to service %x", @@ -475,7 +483,7 @@ make_service_callback(struct vchiq_service *service, en= um vchiq_reason reason, } =20 if (reason !=3D VCHIQ_MESSAGE_AVAILABLE) - vchiq_release_message(service->handle, header); + vchiq_release_message(service->instance, service->handle, header); =20 return status; } @@ -2149,11 +2157,6 @@ vchiq_init_state(struct vchiq_state *state, struct v= chiq_slot_zero *slot_zero, s char threadname[16]; int i, ret; =20 - if (vchiq_states[0]) { - pr_err("%s: VCHIQ state already initialized\n", __func__); - return -EINVAL; - } - local =3D &slot_zero->slave; remote =3D &slot_zero->master; =20 @@ -2274,8 +2277,6 @@ vchiq_init_state(struct vchiq_state *state, struct vc= hiq_slot_zero *slot_zero, s wake_up_process(state->recycle_thread); wake_up_process(state->sync_thread); =20 - vchiq_states[0] =3D state; - /* Indicate readiness to the other side */ local->initialised =3D 1; =20 @@ -2289,9 +2290,10 @@ vchiq_init_state(struct vchiq_state *state, struct v= chiq_slot_zero *slot_zero, s return ret; } =20 -void vchiq_msg_queue_push(unsigned int handle, struct vchiq_header *header) +void vchiq_msg_queue_push(struct vchiq_instance *instance, unsigned int ha= ndle, + struct vchiq_header *header) { - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); int pos; =20 if (!service) @@ -2311,9 +2313,9 @@ void vchiq_msg_queue_push(unsigned int handle, struct= vchiq_header *header) } EXPORT_SYMBOL(vchiq_msg_queue_push); =20 -struct vchiq_header *vchiq_msg_hold(unsigned int handle) +struct vchiq_header *vchiq_msg_hold(struct vchiq_instance *instance, unsig= ned int handle) { - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); struct vchiq_header *header; int pos; =20 @@ -2868,16 +2870,16 @@ vchiq_shutdown_internal(struct vchiq_state *state, = struct vchiq_instance *instan /* Find all services registered to this client and remove them. */ i =3D 0; while ((service =3D next_service_by_instance(state, instance, &i)) !=3D N= ULL) { - (void)vchiq_remove_service(service->handle); + (void)vchiq_remove_service(instance, service->handle); vchiq_service_put(service); } } =20 enum vchiq_status -vchiq_close_service(unsigned int handle) +vchiq_close_service(struct vchiq_instance *instance, unsigned int handle) { /* Unregister the service */ - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); enum vchiq_status status =3D VCHIQ_SUCCESS; =20 if (!service) @@ -2932,10 +2934,10 @@ vchiq_close_service(unsigned int handle) EXPORT_SYMBOL(vchiq_close_service); =20 enum vchiq_status -vchiq_remove_service(unsigned int handle) +vchiq_remove_service(struct vchiq_instance *instance, unsigned int handle) { /* Unregister the service */ - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); enum vchiq_status status =3D VCHIQ_SUCCESS; =20 if (!service) @@ -3002,7 +3004,7 @@ enum vchiq_status vchiq_bulk_transfer(struct vchiq_in= stance *instance, unsigned void *offset, void __user *uoffset, int size, void *userdata, enum vchiq_bulk_mode mode, enum vchiq_bulk_dir dir) { - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); struct vchiq_bulk_queue *queue; struct vchiq_bulk *bulk; struct vchiq_state *state; @@ -3152,13 +3154,13 @@ enum vchiq_status vchiq_bulk_transfer(struct vchiq_= instance *instance, unsigned } =20 enum vchiq_status -vchiq_queue_message(unsigned int handle, +vchiq_queue_message(struct vchiq_instance *instance, unsigned int handle, ssize_t (*copy_callback)(void *context, void *dest, size_t offset, size_t maxsize), void *context, size_t size) { - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); enum vchiq_status status =3D VCHIQ_ERROR; int data_id; =20 @@ -3201,12 +3203,13 @@ vchiq_queue_message(unsigned int handle, return status; } =20 -int vchiq_queue_kernel_message(unsigned int handle, void *data, unsigned i= nt size) +int vchiq_queue_kernel_message(struct vchiq_instance *instance, unsigned i= nt handle, void *data, + unsigned int size) { enum vchiq_status status; =20 while (1) { - status =3D vchiq_queue_message(handle, memcpy_copy_callback, + status =3D vchiq_queue_message(instance, handle, memcpy_copy_callback, data, size); =20 /* @@ -3225,10 +3228,10 @@ int vchiq_queue_kernel_message(unsigned int handle,= void *data, unsigned int siz EXPORT_SYMBOL(vchiq_queue_kernel_message); =20 void -vchiq_release_message(unsigned int handle, +vchiq_release_message(struct vchiq_instance *instance, unsigned int handle, struct vchiq_header *header) { - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); struct vchiq_shared_state *remote; struct vchiq_state *state; int slot_index; @@ -3267,10 +3270,10 @@ release_message_sync(struct vchiq_state *state, str= uct vchiq_header *header) } =20 enum vchiq_status -vchiq_get_peer_version(unsigned int handle, short *peer_version) +vchiq_get_peer_version(struct vchiq_instance *instance, unsigned int handl= e, short *peer_version) { enum vchiq_status status =3D VCHIQ_ERROR; - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); =20 if (!service) goto exit; @@ -3302,9 +3305,10 @@ void vchiq_get_config(struct vchiq_config *config) } =20 int -vchiq_set_service_option(unsigned int handle, enum vchiq_service_option op= tion, int value) +vchiq_set_service_option(struct vchiq_instance *instance, unsigned int han= dle, + enum vchiq_service_option option, int value) { - struct vchiq_service *service =3D find_service_by_handle(handle); + struct vchiq_service *service =3D find_service_by_handle(instance, handle= ); struct vchiq_service_quota *quota; int ret =3D -EINVAL; =20 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 2ce54ce9f02a..e08206397076 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_core.h @@ -450,8 +450,6 @@ extern int vchiq_core_log_level; extern int vchiq_core_msg_log_level; extern int vchiq_sync_log_level; =20 -extern struct vchiq_state *vchiq_states[VCHIQ_MAX_STATES]; - extern const char * get_conn_state_name(enum vchiq_connstate conn_state); =20 @@ -509,20 +507,10 @@ extern void request_poll(struct vchiq_state *state, struct vchiq_service *service, int poll_type); =20 -static inline struct vchiq_service * -handle_to_service(unsigned int handle) -{ - int idx =3D handle & (VCHIQ_MAX_SERVICES - 1); - struct vchiq_state *state =3D vchiq_states[(handle / VCHIQ_MAX_SERVICES) & - (VCHIQ_MAX_STATES - 1)]; - - if (!state) - return NULL; - return rcu_dereference(state->services[idx]); -} +struct vchiq_service *handle_to_service(struct vchiq_instance *instance, u= nsigned int handle); =20 extern struct vchiq_service * -find_service_by_handle(unsigned int handle); +find_service_by_handle(struct vchiq_instance *instance, unsigned int handl= e); =20 extern struct vchiq_service * find_service_by_port(struct vchiq_state *state, unsigned int localport); @@ -550,7 +538,7 @@ extern void vchiq_service_put(struct vchiq_service *service); =20 extern enum vchiq_status -vchiq_queue_message(unsigned int handle, +vchiq_queue_message(struct vchiq_instance *instance, unsigned int handle, ssize_t (*copy_callback)(void *context, void *dest, size_t offset, size_t maxsize), void *context, @@ -597,12 +585,13 @@ void vchiq_set_conn_state(struct vchiq_state *state, = enum vchiq_connstate newsta =20 void vchiq_log_dump_mem(const char *label, u32 addr, const void *void_mem,= size_t num_bytes); =20 -enum vchiq_status vchiq_remove_service(unsigned int service); +enum vchiq_status vchiq_remove_service(struct vchiq_instance *instance, un= signed int service); =20 -int vchiq_get_client_id(unsigned int service); +int vchiq_get_client_id(struct vchiq_instance *instance, unsigned int serv= ice); =20 void vchiq_get_config(struct vchiq_config *config); =20 -int vchiq_set_service_option(unsigned int service, enum vchiq_service_opti= on option, int value); +int vchiq_set_service_option(struct vchiq_instance *instance, unsigned int= service, + enum vchiq_service_option option, int value); =20 #endif diff --git a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c = b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c index 077e3fcbd651..7e297494437e 100644 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_dev.c @@ -108,8 +108,8 @@ static ssize_t vchiq_ioc_copy_element_data(void *contex= t, void *dest, } =20 static int -vchiq_ioc_queue_message(unsigned int handle, struct vchiq_element *element= s, - unsigned long count) +vchiq_ioc_queue_message(struct vchiq_instance *instance, unsigned int hand= le, + struct vchiq_element *elements, unsigned long count) { struct vchiq_io_copy_callback_context context; enum vchiq_status status =3D VCHIQ_SUCCESS; @@ -127,7 +127,7 @@ vchiq_ioc_queue_message(unsigned int handle, struct vch= iq_element *elements, total_size +=3D elements[i].size; } =20 - status =3D vchiq_queue_message(handle, vchiq_ioc_copy_element_data, + status =3D vchiq_queue_message(instance, handle, vchiq_ioc_copy_element_d= ata, &context, total_size); =20 if (status =3D=3D VCHIQ_ERROR) @@ -191,7 +191,7 @@ static int vchiq_ioc_create_service(struct vchiq_instan= ce *instance, if (args->is_open) { status =3D vchiq_open_service_internal(service, instance->pid); if (status !=3D VCHIQ_SUCCESS) { - vchiq_remove_service(service->handle); + vchiq_remove_service(instance, service->handle); return (status =3D=3D VCHIQ_RETRY) ? -EINTR : -EIO; } @@ -266,7 +266,7 @@ static int vchiq_ioc_dequeue_message(struct vchiq_insta= nce *instance, /* Copy to user space if msgbuf is not NULL */ if (!args->buf || (copy_to_user(args->buf, header->data, header->size) = =3D=3D 0)) { ret =3D header->size; - vchiq_release_message(service->handle, header); + vchiq_release_message(instance, service->handle, header); } else { ret =3D -EFAULT; } @@ -529,7 +529,7 @@ static int vchiq_ioc_await_completion(struct vchiq_inst= ance *instance, } =20 /* Now it has been copied, the message can be released. */ - vchiq_release_message(service->handle, header); + vchiq_release_message(instance, service->handle, header); =20 /* The completion must point to the msgbuf. */ user_completion.header =3D msgbuf; @@ -596,7 +596,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsign= ed long arg) i =3D 0; while ((service =3D next_service_by_instance(instance->state, instance, &i))) { - status =3D vchiq_remove_service(service->handle); + status =3D vchiq_remove_service(instance, service->handle); vchiq_service_put(service); if (status !=3D VCHIQ_SUCCESS) break; @@ -649,7 +649,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsign= ed long arg) break; =20 if (put_user(args.handle, &argp->handle)) { - vchiq_remove_service(args.handle); + vchiq_remove_service(instance, args.handle); ret =3D -EFAULT; } } break; @@ -673,8 +673,8 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsign= ed long arg) */ if (!user_service->close_pending) { status =3D (cmd =3D=3D VCHIQ_IOC_CLOSE_SERVICE) ? - vchiq_close_service(service->handle) : - vchiq_remove_service(service->handle); + vchiq_close_service(instance, service->handle) : + vchiq_remove_service(instance, service->handle); if (status !=3D VCHIQ_SUCCESS) break; } @@ -731,7 +731,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsign= ed long arg) =20 if (copy_from_user(elements, args.elements, args.count * sizeof(struct vchiq_element)) =3D=3D 0) - ret =3D vchiq_ioc_queue_message(args.handle, elements, + ret =3D vchiq_ioc_queue_message(instance, args.handle, elements, args.count); else ret =3D -EFAULT; @@ -788,7 +788,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsign= ed long arg) case VCHIQ_IOC_GET_CLIENT_ID: { unsigned int handle =3D (unsigned int)arg; =20 - ret =3D vchiq_get_client_id(handle); + ret =3D vchiq_get_client_id(instance, handle); } break; =20 case VCHIQ_IOC_GET_CONFIG: { @@ -827,7 +827,7 @@ vchiq_ioctl(struct file *file, unsigned int cmd, unsign= ed long arg) break; } =20 - ret =3D vchiq_set_service_option(args.handle, args.option, + ret =3D vchiq_set_service_option(instance, args.handle, args.option, args.value); } break; =20 @@ -908,6 +908,7 @@ vchiq_compat_ioctl_create_service(struct file *file, un= signed int cmd, { struct vchiq_create_service args; struct vchiq_create_service32 args32; + struct vchiq_instance *instance =3D file->private_data; long ret; =20 if (copy_from_user(&args32, ptrargs32, sizeof(args32))) @@ -926,12 +927,12 @@ vchiq_compat_ioctl_create_service(struct file *file, = unsigned int cmd, .handle =3D args32.handle, }; =20 - ret =3D vchiq_ioc_create_service(file->private_data, &args); + ret =3D vchiq_ioc_create_service(instance, &args); if (ret < 0) return ret; =20 if (put_user(args.handle, &ptrargs32->handle)) { - vchiq_remove_service(args.handle); + vchiq_remove_service(instance, args.handle); return -EFAULT; } =20 @@ -960,6 +961,7 @@ vchiq_compat_ioctl_queue_message(struct file *file, struct vchiq_queue_message args; struct vchiq_queue_message32 args32; struct vchiq_service *service; + struct vchiq_instance *instance =3D file->private_data; int ret; =20 if (copy_from_user(&args32, arg, sizeof(args32))) @@ -974,7 +976,7 @@ vchiq_compat_ioctl_queue_message(struct file *file, if (args32.count > MAX_ELEMENTS) return -EINVAL; =20 - service =3D find_service_for_instance(file->private_data, args.handle); + service =3D find_service_for_instance(instance, args.handle); if (!service) return -EINVAL; =20 @@ -994,7 +996,7 @@ vchiq_compat_ioctl_queue_message(struct file *file, compat_ptr(element32[count].data); elements[count].size =3D element32[count].size; } - ret =3D vchiq_ioc_queue_message(args.handle, elements, + ret =3D vchiq_ioc_queue_message(instance, args.handle, elements, args.count); } else { ret =3D -EINVAL; @@ -1261,7 +1263,7 @@ static int vchiq_release(struct inode *inode, struct = file *file) spin_unlock(&msg_queue_spinlock); =20 if (header) - vchiq_release_message(service->handle, header); + vchiq_release_message(instance, service->handle, header); spin_lock(&msg_queue_spinlock); } =20 diff --git a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c b/driver= s/staging/vc04_services/vchiq-mmal/mmal-vchiq.c index 88813af8de49..a1ab7ab7e908 100644 --- a/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c +++ b/drivers/staging/vc04_services/vchiq-mmal/mmal-vchiq.c @@ -292,7 +292,7 @@ static void buffer_to_host_work_cb(struct work_struct *= work) /* Dummy receive to ensure the buffers remain in order */ len =3D 8; /* queue the bulk submission */ - vchiq_use_service(instance->service_handle); + vchiq_use_service(instance->vchiq_instance, instance->service_handle); ret =3D vchiq_bulk_receive(instance->vchiq_instance, instance->service_ha= ndle, msg_context->u.bulk.buffer->buffer, /* Actual receive needs to be a multiple @@ -302,7 +302,7 @@ static void buffer_to_host_work_cb(struct work_struct *= work) msg_context, VCHIQ_BULK_MODE_CALLBACK); =20 - vchiq_release_service(instance->service_handle); + vchiq_release_service(instance->vchiq_instance, instance->service_handle); =20 if (ret !=3D 0) pr_err("%s: ctx: %p, vchiq_bulk_receive failed %d\n", @@ -436,15 +436,15 @@ buffer_from_host(struct vchiq_mmal_instance *instance, /* no payload in message */ m.u.buffer_from_host.payload_in_message =3D 0; =20 - vchiq_use_service(instance->service_handle); + vchiq_use_service(instance->vchiq_instance, instance->service_handle); =20 - ret =3D vchiq_queue_kernel_message(instance->service_handle, &m, + ret =3D vchiq_queue_kernel_message(instance->vchiq_instance, instance->se= rvice_handle, &m, sizeof(struct mmal_msg_header) + sizeof(m.u.buffer_from_host)); if (ret) atomic_dec(&port->buffers_with_vpu); =20 - vchiq_release_service(instance->service_handle); + vchiq_release_service(instance->vchiq_instance, instance->service_handle); =20 return ret; } @@ -548,11 +548,12 @@ static void bulk_abort_cb(struct vchiq_mmal_instance = *instance, } =20 /* incoming event service callback */ -static enum vchiq_status service_callback(enum vchiq_reason reason, +static enum vchiq_status service_callback(struct vchiq_instance *vchiq_ins= tance, + enum vchiq_reason reason, struct vchiq_header *header, unsigned int handle, void *bulk_ctx) { - struct vchiq_mmal_instance *instance =3D vchiq_get_service_userdata(handl= e); + struct vchiq_mmal_instance *instance =3D vchiq_get_service_userdata(vchiq= _instance, handle); u32 msg_len; struct mmal_msg *msg; struct mmal_msg_context *msg_context; @@ -572,25 +573,25 @@ static enum vchiq_status service_callback(enum vchiq_= reason reason, /* handling is different for buffer messages */ switch (msg->h.type) { case MMAL_MSG_TYPE_BUFFER_FROM_HOST: - vchiq_release_message(handle, header); + vchiq_release_message(vchiq_instance, handle, header); break; =20 case MMAL_MSG_TYPE_EVENT_TO_HOST: event_to_host_cb(instance, msg, msg_len); - vchiq_release_message(handle, header); + vchiq_release_message(vchiq_instance, handle, header); =20 break; =20 case MMAL_MSG_TYPE_BUFFER_TO_HOST: buffer_to_host_cb(instance, msg, msg_len); - vchiq_release_message(handle, header); + vchiq_release_message(vchiq_instance, handle, header); break; =20 default: /* messages dependent on header context to complete */ if (!msg->h.context) { pr_err("received message context was null!\n"); - vchiq_release_message(handle, header); + vchiq_release_message(vchiq_instance, handle, header); break; } =20 @@ -599,7 +600,7 @@ static enum vchiq_status service_callback(enum vchiq_re= ason reason, if (!msg_context) { pr_err("received invalid message context %u!\n", msg->h.context); - vchiq_release_message(handle, header); + vchiq_release_message(vchiq_instance, handle, header); break; } =20 @@ -678,13 +679,13 @@ static int send_synchronous_mmal_msg(struct vchiq_mma= l_instance *instance, DBG_DUMP_MSG(msg, (sizeof(struct mmal_msg_header) + payload_len), ">>> sync message"); =20 - vchiq_use_service(instance->service_handle); + vchiq_use_service(instance->vchiq_instance, instance->service_handle); =20 - ret =3D vchiq_queue_kernel_message(instance->service_handle, msg, + ret =3D vchiq_queue_kernel_message(instance->vchiq_instance, instance->se= rvice_handle, msg, sizeof(struct mmal_msg_header) + payload_len); =20 - vchiq_release_service(instance->service_handle); + vchiq_release_service(instance->vchiq_instance, instance->service_handle); =20 if (ret) { pr_err("error %d queuing message\n", ret); @@ -824,7 +825,7 @@ static int port_info_set(struct vchiq_mmal_instance *in= stance, port->component->handle, port->handle); =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -919,7 +920,7 @@ static int port_info_get(struct vchiq_mmal_instance *in= stance, pr_debug("%s:result:%d component:0x%x port:%d\n", __func__, ret, port->component->handle, port->handle); =20 - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -967,7 +968,7 @@ static int create_component(struct vchiq_mmal_instance = *instance, component->inputs, component->outputs, component->clocks); =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1000,7 +1001,7 @@ static int destroy_component(struct vchiq_mmal_instan= ce *instance, =20 release_msg: =20 - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1032,7 +1033,7 @@ static int enable_component(struct vchiq_mmal_instanc= e *instance, ret =3D -rmsg->u.component_enable_reply.status; =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1065,7 +1066,7 @@ static int disable_component(struct vchiq_mmal_instan= ce *instance, =20 release_msg: =20 - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1097,7 +1098,7 @@ static int get_version(struct vchiq_mmal_instance *in= stance, *minor_out =3D rmsg->u.version.minor; =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1139,7 +1140,7 @@ static int port_action_port(struct vchiq_mmal_instanc= e *instance, port_action_type_names[action_type], action_type); =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1187,7 +1188,7 @@ static int port_action_handle(struct vchiq_mmal_insta= nce *instance, action_type, connect_component_handle, connect_port_handle); =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1228,7 +1229,7 @@ static int port_parameter_set(struct vchiq_mmal_insta= nce *instance, ret, port->component->handle, port->handle, parameter_id); =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1287,7 +1288,7 @@ static int port_parameter_get(struct vchiq_mmal_insta= nce *instance, ret, port->component->handle, port->handle, parameter_id); =20 release_msg: - vchiq_release_message(instance->service_handle, rmsg_handle); + vchiq_release_message(instance->vchiq_instance, instance->service_handle,= rmsg_handle); =20 return ret; } @@ -1832,9 +1833,9 @@ int vchiq_mmal_finalise(struct vchiq_mmal_instance *i= nstance) if (mutex_lock_interruptible(&instance->vchiq_mutex)) return -EINTR; =20 - vchiq_use_service(instance->service_handle); + vchiq_use_service(instance->vchiq_instance, instance->service_handle); =20 - status =3D vchiq_close_service(instance->service_handle); + status =3D vchiq_close_service(instance->vchiq_instance, instance->servic= e_handle); if (status !=3D 0) pr_err("mmal-vchiq: VCHIQ close failed\n"); =20 @@ -1922,14 +1923,14 @@ int vchiq_mmal_init(struct vchiq_mmal_instance **ou= t_instance) goto err_close_services; } =20 - vchiq_release_service(instance->service_handle); + vchiq_release_service(instance->vchiq_instance, instance->service_handle); =20 *out_instance =3D instance; =20 return 0; =20 err_close_services: - vchiq_close_service(instance->service_handle); + vchiq_close_service(instance->vchiq_instance, instance->service_handle); destroy_workqueue(instance->bulk_wq); err_free: kfree(instance); --=20 2.35.1