Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp2350163pxb; Mon, 20 Sep 2021 19:44:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy9PP+q6LkciWnWoKnlfK7XXRoUTlVHpOdE6XRAfHGeB2/qAfWDPR3/tJhQbz/lxHYGzlx8 X-Received: by 2002:a05:6e02:1525:: with SMTP id i5mr14383173ilu.122.1632192295428; Mon, 20 Sep 2021 19:44:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1632192295; cv=none; d=google.com; s=arc-20160816; b=fNoRLBPBgvBuJI6vaiX8EO8MAXrCK7W3UbyvHk6nQEIJiS4b01VapQ6EnujRC8qG0F D4oTvN6praWjWuNRor/IPyec8YfSr0fVMxbAnQAz3PqjWseRiIF8q3anCJ9rklRIJ6gM 7LwqTS/SgB+qfLLC832W1Ds8CJYLhU6AQI9GUAJui9Dv8+3VQk5bvu/pYHPoeqrKKtIM JDDJJy6LIUlhS+fN4N35Lr8WA0qM/9ynHol1LEzSyt6E9nhbdtX1XGARQGgBd5/eBbCj rR1gZq9qMMQEYh009JsHJlRaAvUOVB88tRH42MsVc2Uowrpj2S9eQtADunhvmVrT/qDW iOhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=juCQX/Vfw5S0wBZ0WvY0MJnvvdWqbXL5/wQeLHZQOLo=; b=G7Q4eW9yGK4/tXs90Y/hMxERZJCroaCoHRjkuZWOfgK01MWhv688pdUdGc0Z8bD7wU ndLMJWoXn8xQYqD8JcZR41ggpNQj4TiryG6ycaoidcvNyGm3TL8xODzAMsIPPbdJcgPM MgepM2MNj22vjga8Sj896QsGCx42tyUuhI8Znsx6V6C82PIUmK4fCNTkiZbpJ1856TQ7 aaePdSZ4Ru7hTV+d9ds6oh3VzQ8l25Ysj3ClrlInkyua5rZU9sNep/HmXtrlexXDwP9C HNnSLJVZU8bqAnaFidkv2S37cnQ2WKu+7Wh5KGT86vtoY1n9npjG0DMC5yUuZlGayWxp 1CsQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GkgFKZT5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id i12si13291438jaf.41.2021.09.20.19.44.44; Mon, 20 Sep 2021 19:44:55 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GkgFKZT5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1378284AbhITSYW (ORCPT + 99 others); Mon, 20 Sep 2021 14:24:22 -0400 Received: from mail.kernel.org ([198.145.29.99]:39242 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1351729AbhITSQ5 (ORCPT ); Mon, 20 Sep 2021 14:16:57 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 551B663297; Mon, 20 Sep 2021 17:22:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1632158542; bh=iB5+bIJ4Yo/7MimJcE96cw8bw1TAQhGETmul9zVhY5I=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GkgFKZT58bAjy8l5sIAZAUzcgiqKNWw/1hqgA3tNTF2wrYKoRcbhuvhQjfzJn0Lmg XWjatg8lN+h2dzyw7holCO1c7pkgnQXcCVB2IWxfu9gBHSc9S1u12GBBc7PPO+dtsI eplRk42qBOdl0ttvrvMMBLQLbOfLULFLsuPDEHTg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Lucas Stach , Michael Walle , Marek Vasut , Christian Gmeiner Subject: [PATCH 5.4 205/260] drm/etnaviv: reference MMU context when setting up hardware state Date: Mon, 20 Sep 2021 18:43:43 +0200 Message-Id: <20210920163938.075311428@linuxfoundation.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20210920163931.123590023@linuxfoundation.org> References: <20210920163931.123590023@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Lucas Stach commit d6408538f091fb22d47f792d4efa58143d56c3fb upstream. Move the refcount manipulation of the MMU context to the point where the hardware state is programmed. At that point it is also known if a previous MMU state is still there, or the state needs to be reprogrammed with a potentially different context. Cc: stable@vger.kernel.org # 5.4 Signed-off-by: Lucas Stach Tested-by: Michael Walle Tested-by: Marek Vasut Reviewed-by: Christian Gmeiner Signed-off-by: Greg Kroah-Hartman --- drivers/gpu/drm/etnaviv/etnaviv_gpu.c | 24 ++++++++++++------------ drivers/gpu/drm/etnaviv/etnaviv_iommu.c | 4 ++++ drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c | 8 ++++++++ 3 files changed, 24 insertions(+), 12 deletions(-) --- a/drivers/gpu/drm/etnaviv/etnaviv_gpu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_gpu.c @@ -617,17 +617,19 @@ void etnaviv_gpu_start_fe(struct etnaviv gpu->fe_running = true; } -static void etnaviv_gpu_start_fe_idleloop(struct etnaviv_gpu *gpu) +static void etnaviv_gpu_start_fe_idleloop(struct etnaviv_gpu *gpu, + struct etnaviv_iommu_context *context) { - u32 address = etnaviv_cmdbuf_get_va(&gpu->buffer, - &gpu->mmu_context->cmdbuf_mapping); u16 prefetch; + u32 address; /* setup the MMU */ - etnaviv_iommu_restore(gpu, gpu->mmu_context); + etnaviv_iommu_restore(gpu, context); /* Start command processor */ prefetch = etnaviv_buffer_init(gpu); + address = etnaviv_cmdbuf_get_va(&gpu->buffer, + &gpu->mmu_context->cmdbuf_mapping); etnaviv_gpu_start_fe(gpu, address, prefetch); } @@ -1311,14 +1313,12 @@ struct dma_fence *etnaviv_gpu_submit(str goto out_unlock; } - if (!gpu->fe_running) { - gpu->mmu_context = etnaviv_iommu_context_get(submit->mmu_context); - etnaviv_gpu_start_fe_idleloop(gpu); - } else { - if (submit->prev_mmu_context) - etnaviv_iommu_context_put(submit->prev_mmu_context); - submit->prev_mmu_context = etnaviv_iommu_context_get(gpu->mmu_context); - } + if (!gpu->fe_running) + etnaviv_gpu_start_fe_idleloop(gpu, submit->mmu_context); + + if (submit->prev_mmu_context) + etnaviv_iommu_context_put(submit->prev_mmu_context); + submit->prev_mmu_context = etnaviv_iommu_context_get(gpu->mmu_context); if (submit->nr_pmrs) { gpu->event[event[1]].sync_point = &sync_point_perfmon_sample_pre; --- a/drivers/gpu/drm/etnaviv/etnaviv_iommu.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_iommu.c @@ -92,6 +92,10 @@ static void etnaviv_iommuv1_restore(stru struct etnaviv_iommuv1_context *v1_context = to_v1_context(context); u32 pgtable; + if (gpu->mmu_context) + etnaviv_iommu_context_put(gpu->mmu_context); + gpu->mmu_context = etnaviv_iommu_context_get(context); + /* set base addresses */ gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_RA, context->global->memory_base); gpu_write(gpu, VIVS_MC_MEMORY_BASE_ADDR_FE, context->global->memory_base); --- a/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c +++ b/drivers/gpu/drm/etnaviv/etnaviv_iommu_v2.c @@ -172,6 +172,10 @@ static void etnaviv_iommuv2_restore_nons if (gpu_read(gpu, VIVS_MMUv2_CONTROL) & VIVS_MMUv2_CONTROL_ENABLE) return; + if (gpu->mmu_context) + etnaviv_iommu_context_put(gpu->mmu_context); + gpu->mmu_context = etnaviv_iommu_context_get(context); + prefetch = etnaviv_buffer_config_mmuv2(gpu, (u32)v2_context->mtlb_dma, (u32)context->global->bad_page_dma); @@ -192,6 +196,10 @@ static void etnaviv_iommuv2_restore_sec( if (gpu_read(gpu, VIVS_MMUv2_SEC_CONTROL) & VIVS_MMUv2_SEC_CONTROL_ENABLE) return; + if (gpu->mmu_context) + etnaviv_iommu_context_put(gpu->mmu_context); + gpu->mmu_context = etnaviv_iommu_context_get(context); + gpu_write(gpu, VIVS_MMUv2_PTA_ADDRESS_LOW, lower_32_bits(context->global->v2.pta_dma)); gpu_write(gpu, VIVS_MMUv2_PTA_ADDRESS_HIGH,