From nobody Fri Nov 29 14:30:59 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1638035560; cv=none; d=zohomail.com; s=zohoarc; b=CDNhAj+vl1T67Cm+1YJVBoY5Yy7QblN8FIO0sAUoh08Afdf41ckgJUGR8i4vVSMJg+MlQfOxdOyrzA0r7b2ujF7Jdy2L1GlrBZZK50tfwk9ourMlSX2t3p22fh0TaF9AVWF8QLiQXX/p3ywWDq048Z470NpEPJohvYK8HJDtKus= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1638035560; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=6dW0OZmNRebStbQFMM32RwjBwDJFFmt3LTZQMfVizWw=; b=hfUoF1LYrwkyIuSJSyykB/pl4dq0FJ6PwjYAjGfDpzFREv78QoAQGubNQqUPnkmUyPA8B1VdB2dd9UO3G4ZU933aqKNipfBq1XksaYb5zf3nRLcCuZ3dHQcQdIq7oxetBKD+fp+Z95ieAvQYA7rVaCIEOz81JqMJzMtsZpex6Hs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 163803556050153.65201502736954; Sat, 27 Nov 2021 09:52:40 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.234023.406230 (Exim 4.92) (envelope-from ) id 1mr1rk-0005Np-Te; Sat, 27 Nov 2021 17:52:00 +0000 Received: by outflank-mailman (output) from mailman id 234023.406230; Sat, 27 Nov 2021 17:52:00 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mr1rk-0005L7-G9; Sat, 27 Nov 2021 17:52:00 +0000 Received: by outflank-mailman (input) for mailman id 234023; Sat, 27 Nov 2021 17:51:59 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1mr1ri-0004Ih-I1 for xen-devel@lists.xenproject.org; Sat, 27 Nov 2021 17:51:58 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id b70fe854-4faa-11ec-976b-d102b41d0961; Sat, 27 Nov 2021 18:51:57 +0100 (CET) Received: by mail-lf1-x135.google.com with SMTP id u3so32562717lfl.2 for ; Sat, 27 Nov 2021 09:51:57 -0800 (PST) Received: from otyshchenko.router ([212.22.223.21]) by smtp.gmail.com with ESMTPSA id f18sm827075ljc.104.2021.11.27.09.51.56 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 27 Nov 2021 09:51:56 -0800 (PST) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: b70fe854-4faa-11ec-976b-d102b41d0961 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=6dW0OZmNRebStbQFMM32RwjBwDJFFmt3LTZQMfVizWw=; b=jh3p8yv6Z9HWUYrl8v0MV5RoXvgJriZ2SQ2qUyEfV8MJudGYyjYZBc0LdjhjSL1KaZ o51oKlE9EwthkSnIoTFUL0o93rFZCfUMART9dX3OVg02SjdVZIpOpot0LHUlVPl4K5Sp TdeKGLW2ad186m7TUrnHpRR4ECAThtY9iQqR7NRQIVCvSxgr1LFTpnatN9njbwLY+L9z 11o31+2JvQxupWl8nRXzJjz2YIA+AE9sqCO0riZx10KMtG/O9Z0dStqNiHReyQo+gTRI /O4i+Y2d4khjyg+2jOM05RDiai99QIaHpaKH1K0uTLd6LkVh30LR/GNW2JrJSjPO/T+W F0Sg== 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=6dW0OZmNRebStbQFMM32RwjBwDJFFmt3LTZQMfVizWw=; b=fza3qQHP9TeWsxHCy6kvCfCTnkBx+x3uHsMSrPcCdL67xQUPJbr414e0cGlrbys2SV nLIJVqUPX3/4jBEOeLwMktcw1L96tAgcM8bEzZT/tnqpw3BYL/BdFx5VaWt4fjraOIS9 i7WerYdCwDwV2qlIhdWW2U1RI2YkDO49UcBf3BZSPy+gHMzHn0yzVHdeovqyHbY4jmTd ijL4ESESrSY+mpB1RRiwK0qJM9oSxnn5T350ZceFd2ZKehWIAIHPI2q+F0ph6b2bzHBC 2Vbf0OVk1cDWUCCGPXh0cnxR3vuY8yb5L4g8+yRv/9B/0dCMG2xKmAEUHdaMXov8saXd vbFQ== X-Gm-Message-State: AOAM5309c2/PdOju1A701HHCfzyIlm4R/PffDnJTdTVaxCGw9wEPlgIO xZT7QaFBJP7BLdL+gmaniXHvE/YSLXM= X-Google-Smtp-Source: ABdhPJw/TZIsXkeZbL/imr/4eb3AnmQ0TJreSbrco2NPGdcPdHSUB5wq92oMDcimEGE0Ps3+nKgwaQ== X-Received: by 2002:ac2:4c0b:: with SMTP id t11mr37847197lfq.520.1638035517101; Sat, 27 Nov 2021 09:51:57 -0800 (PST) From: Oleksandr Tyshchenko To: xen-devel@lists.xenproject.org Cc: Oleksandr Tyshchenko , Jan Beulich , Paul Durrant , Stefano Stabellini , Julien Grall , Volodymyr Babchuk , Bertrand Marquis , Yoshihiro Shimoda , Oleksandr Andrushchenko Subject: [PATCH 07/10] iommu/ipmmu-vmsa: Add Renesas R8A779F0 (R-Car S4) support Date: Sat, 27 Nov 2021 19:51:42 +0200 Message-Id: <1638035505-16931-8-git-send-email-olekstysh@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1638035505-16931-1-git-send-email-olekstysh@gmail.com> References: <1638035505-16931-1-git-send-email-olekstysh@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1638035562411100015 From: Oleksandr Tyshchenko Based on the following commit from the Renesas BSP: 7003b9f732cffdc778fceb4bffb05ebb4540f726 located at: https://github.com/renesas-rcar/linux-bsp/tree/v5.10.41/rcar-5.1.3.rc5 Original commit message: commit 7003b9f732cffdc778fceb4bffb05ebb4540f726 Author: Nam Nguyen Date: Thu Feb 4 11:05:37 2021 +0700 iommu/ipmmu-vmsa: Add Renesas R8A779F0 (R-Car S4) support Adding IPMMU support for Renesas R8A779F0 R-Car S4. Suggested by: Hai Pham Signed-off-by: Nam Nguyen ********** The R-Car S4 is an automotive System-on-Chip (SoC) for Car Server/Communication Gateway and is one of the first products in Renesas=E2=80=99 4th-generation R-Car Family. The integrated IOMMU HW is also VMSA-compatible and supports stage 2 translation table format, therefore can be used with current driver with slight modifications (thanks to the prereq work). In the context of Xen driver the main differences between Gen3 and S4 are the following: - HW capacity was enlarged to support up to 16 IPMMU contexts (sets of page table) and up to 64 micro-TLBs per IPMMU device - the memory mapped registers have different bases and offsets Signed-off-by: Oleksandr Tyshchenko Signed-off-by: Oleksandr Andrushchenko --- xen/drivers/passthrough/Kconfig | 6 +-- xen/drivers/passthrough/arm/ipmmu-vmsa.c | 74 +++++++++++++++++++++++++---= ---- 2 files changed, 61 insertions(+), 19 deletions(-) diff --git a/xen/drivers/passthrough/Kconfig b/xen/drivers/passthrough/Kcon= fig index 09505aa..e1cb678 100644 --- a/xen/drivers/passthrough/Kconfig +++ b/xen/drivers/passthrough/Kconfig @@ -25,14 +25,14 @@ config ARM_SMMU_V3 the ARM SMMUv3 architecture. =20 config IPMMU_VMSA - bool "Renesas IPMMU-VMSA found in R-Car Gen3 SoCs" + bool "Renesas IPMMU-VMSA found in R-Car Gen3/S4 SoCs" depends on ARM_64 ---help--- Support for implementations of the Renesas IPMMU-VMSA found - in R-Car Gen3 SoCs. + in R-Car Gen3/S4 SoCs. =20 Say Y here if you are using newest R-Car Gen3 SoCs revisions - (H3 ES3.0, M3-W+, etc) which IPMMU hardware supports stage 2 + (H3 ES3.0, M3-W+, etc) or S4 SoCs which IPMMU hardware supports stage 2 translation table format and is able to use CPU's P2M table as is. =20 endif diff --git a/xen/drivers/passthrough/arm/ipmmu-vmsa.c b/xen/drivers/passthr= ough/arm/ipmmu-vmsa.c index d8f96fc..8dfdae8 100644 --- a/xen/drivers/passthrough/arm/ipmmu-vmsa.c +++ b/xen/drivers/passthrough/arm/ipmmu-vmsa.c @@ -1,15 +1,15 @@ /* * xen/drivers/passthrough/arm/ipmmu-vmsa.c * - * Driver for the Renesas IPMMU-VMSA found in R-Car Gen3 SoCs. + * Driver for the Renesas IPMMU-VMSA found in R-Car Gen3/S4 SoCs. * * The IPMMU-VMSA is VMSA-compatible I/O Memory Management Unit (IOMMU) * which provides address translation and access protection functionalities * to processing units and interconnect networks. * * Please note, current driver is supposed to work only with newest - * R-Car Gen3 SoCs revisions which IPMMU hardware supports stage 2 transla= tion - * table format and is able to use CPU's P2M table as is. + * R-Car Gen3/S4 SoCs revisions which IPMMU hardware supports stage 2 + * translation table format and is able to use CPU's P2M table as is. * * Based on Linux's IPMMU-VMSA driver from Renesas BSP: * drivers/iommu/ipmmu-vmsa.c @@ -20,9 +20,9 @@ * and Xen's SMMU driver: * xen/drivers/passthrough/arm/smmu.c * - * Copyright (C) 2014-2019 Renesas Electronics Corporation + * Copyright (C) 2014-2021 Renesas Electronics Corporation * - * Copyright (C) 2016-2019 EPAM Systems Inc. + * Copyright (C) 2016-2021 EPAM Systems Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms and conditions of the GNU General Public @@ -68,12 +68,18 @@ dev_print(dev, XENLOG_ERR, fmt, ## __VA_ARGS__) =20 /* - * R-Car Gen3 SoCs make use of up to 8 IPMMU contexts (sets of page table)= and - * these can be managed independently. Each context is mapped to one Xen d= omain. + * R-Car Gen3/S4 SoCs make use of up to 16 IPMMU contexts (sets of page ta= ble) + * and these can be managed independently. Each context is mapped to one X= en + * domain. */ -#define IPMMU_CTX_MAX 8U -/* R-Car Gen3 SoCs make use of up to 48 micro-TLBs per IPMMU device. */ -#define IPMMU_UTLB_MAX 48U +#define IPMMU_CTX_MAX 16U +/* R-Car Gen3/S4 SoCs make use of up to 64 micro-TLBs per IPMMU device. */ +#define IPMMU_UTLB_MAX 64U + +enum ipmmu_reg_layout { + IPMMU_REG_LAYOUT_RCAR_GEN3 =3D 0, + IPMMU_REG_LAYOUT_RCAR_S4, +}; =20 /* IPMMU context supports IPA size up to 40 bit. */ #define IPMMU_MAX_P2M_IPA_BITS 40 @@ -110,8 +116,12 @@ struct ipmmu_features { unsigned int number_of_contexts; unsigned int num_utlbs; unsigned int ctx_offset_base; + unsigned int ctx_offset_base_2; unsigned int ctx_offset_stride; + unsigned int ctx_offset_stride_adj; unsigned int utlb_offset_base; + unsigned int imuctr_ttsel_mask; + enum ipmmu_reg_layout reg_layout; }; =20 /* Root/Cache IPMMU device's information */ @@ -211,7 +221,6 @@ static DEFINE_SPINLOCK(ipmmu_devices_lock); #define IMUCTR0(n) (0x0300 + ((n) * 16)) #define IMUCTR32(n) (0x0600 + (((n) - 32) * 16)) #define IMUCTR_TTSEL_MMU(n) ((n) << 4) -#define IMUCTR_TTSEL_MASK (15 << 4) #define IMUCTR_TTSEL_SHIFT 4 #define IMUCTR_FLUSH (1 << 1) #define IMUCTR_MMUEN (1 << 0) @@ -316,8 +325,15 @@ static void ipmmu_write(struct ipmmu_vmsa_device *mmu,= uint32_t offset, static unsigned int ipmmu_ctx_reg(struct ipmmu_vmsa_device *mmu, unsigned int context_id, uint32_t reg) { + if ( mmu->features->reg_layout =3D=3D IPMMU_REG_LAYOUT_RCAR_S4 && + context_id >=3D 8 ) + return mmu->features->ctx_offset_base_2 + + (context_id - 8) * mmu->features->ctx_offset_stride + + context_id * mmu->features->ctx_offset_stride_adj + reg; + return mmu->features->ctx_offset_base + - context_id * mmu->features->ctx_offset_stride + reg; + context_id * mmu->features->ctx_offset_stride + + context_id * mmu->features->ctx_offset_stride_adj + reg; } =20 static uint32_t ipmmu_ctx_read(struct ipmmu_vmsa_device *mmu, @@ -448,7 +464,8 @@ static int ipmmu_utlb_enable(struct ipmmu_vmsa_domain *= domain, { unsigned int context_id; =20 - context_id =3D (imuctr & IMUCTR_TTSEL_MASK) >> IMUCTR_TTSEL_SHIFT; + context_id =3D (imuctr & mmu->features->imuctr_ttsel_mask) >> + IMUCTR_TTSEL_SHIFT; if ( domain->context_id !=3D context_id ) { dev_err(mmu->dev, "Micro-TLB %u already assigned to IPMMU cont= ext %u\n", @@ -738,8 +755,23 @@ static const struct ipmmu_features ipmmu_features_rcar= _gen3 =3D { .number_of_contexts =3D 8, .num_utlbs =3D 48, .ctx_offset_base =3D 0, + .ctx_offset_base_2 =3D 0, .ctx_offset_stride =3D 0x40, + .ctx_offset_stride_adj =3D 0, .utlb_offset_base =3D 0, + .imuctr_ttsel_mask =3D (15 << 4), +}; + +static const struct ipmmu_features ipmmu_features_rcar_s4 =3D { + .number_of_contexts =3D 16, + .num_utlbs =3D 64, + .ctx_offset_base =3D 0x10000, + .ctx_offset_base_2 =3D 0x10800, + .ctx_offset_stride =3D 0x40, + .ctx_offset_stride_adj =3D 0x1000, + .utlb_offset_base =3D 0x3000, + .imuctr_ttsel_mask =3D (31 << 4), + .reg_layout =3D IPMMU_REG_LAYOUT_RCAR_S4, }; =20 static void ipmmu_device_reset(struct ipmmu_vmsa_device *mmu) @@ -751,11 +783,12 @@ static void ipmmu_device_reset(struct ipmmu_vmsa_devi= ce *mmu) ipmmu_ctx_write(mmu, i, IMCTR, 0); } =20 -/* R-Car Gen3 SoCs product and cut information. */ +/* R-Car Gen3/S4 SoCs product and cut information. */ #define RCAR_PRODUCT_MASK 0x00007F00 #define RCAR_PRODUCT_H3 0x00004F00 #define RCAR_PRODUCT_M3W 0x00005200 #define RCAR_PRODUCT_M3N 0x00005500 +#define RCAR_PRODUCT_S4 0x00005A00 #define RCAR_CUT_MASK 0x000000FF #define RCAR_CUT_VER30 0x00000020 =20 @@ -803,6 +836,10 @@ static __init bool ipmmu_stage2_supported(void) stage2_supported =3D true; break; =20 + case RCAR_PRODUCT_S4: + stage2_supported =3D true; + break; + default: printk(XENLOG_ERR "ipmmu: Unsupported SoC version\n"); break; @@ -831,6 +868,10 @@ static const struct dt_device_match ipmmu_dt_match[] _= _initconst =3D .compatible =3D "renesas,ipmmu-r8a77961", .data =3D &ipmmu_features_rcar_gen3, }, + { + .compatible =3D "renesas,ipmmu-r8a779f0", + .data =3D &ipmmu_features_rcar_s4, + }, { /* sentinel */ }, }; =20 @@ -845,6 +886,7 @@ static int ipmmu_probe(struct dt_device_node *node) const struct dt_device_match *match; struct ipmmu_vmsa_device *mmu; uint64_t addr, size; + uint32_t reg; int irq, ret; =20 mmu =3D xzalloc(struct ipmmu_vmsa_device); @@ -930,8 +972,8 @@ static int ipmmu_probe(struct dt_device_node *node) * Use stage 2 translation table format when stage 2 translation * enabled. */ - ipmmu_write(mmu, IMSAUXCTLR, - ipmmu_read(mmu, IMSAUXCTLR) | IMSAUXCTLR_S2PTE); + reg =3D IMSAUXCTLR + mmu->features->ctx_offset_stride_adj; + ipmmu_write(mmu, reg, ipmmu_read(mmu, reg) | IMSAUXCTLR_S2PTE); =20 dev_info(&node->dev, "IPMMU context 0 is reserved\n"); set_bit(0, mmu->ctx); --=20 2.7.4