From nobody Sat Dec 28 08:32:22 2024 Delivered-To: importer@patchew.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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass(p=quarantine dis=none) header.from=amd.com ARC-Seal: i=2; a=rsa-sha256; t=1733333003; cv=pass; d=zohomail.com; s=zohoarc; b=Ey8omc7mVoZScuhyjLPN4wbONroMDamJztoCgdhLmaw8s2vkXZRinIxkqtpp0a3ehZkvZuBxNI0WvQ6yvqrt12IUjr5gBVF55Bso9nODvdUoLg0uYQkSMnow0ebqhNTNobLiSoYe1sYG9WSG8yOLYcruQvRAVohJ++YcPrQjUAc= ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1733333003; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=eKRJlYZj/vM8lMPFruBRq7uav07apuOnarZh8uy17dk=; b=h4g13lXGE/Gc5NZAJkAsQt0S6junqKExmTdZO7MoqopPklgdXsT+zSv6bBFTePNSps1CuUW0UfCGM9jDyS9wGXNVh0F1F8/Za2F+6RmRV/fDubqcpcF6pR5/E2O7BZ9+yEARVLXOwTmCyhc5K78nwKRZUUMVKvGi+CQnv+KTo/w= ARC-Authentication-Results: i=2; 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; arc=pass (i=1 dmarc=pass fromdomain=amd.com); dmarc=pass header.from= (p=quarantine dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1733333003239385.0772162280706; Wed, 4 Dec 2024 09:23:23 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.848683.1263521 (Exim 4.92) (envelope-from ) id 1tIt5Y-0005U9-VZ; Wed, 04 Dec 2024 17:23:00 +0000 Received: by outflank-mailman (output) from mailman id 848683.1263521; Wed, 04 Dec 2024 17:23: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 1tIt5Y-0005U0-Su; Wed, 04 Dec 2024 17:23:00 +0000 Received: by outflank-mailman (input) for mailman id 848683; Wed, 04 Dec 2024 17:23:00 +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 1tIt5Y-0005EK-1y for xen-devel@lists.xenproject.org; Wed, 04 Dec 2024 17:23:00 +0000 Received: from NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11on20610.outbound.protection.outlook.com [2a01:111:f403:2414::610]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 6875bdc4-b264-11ef-a0d4-8be0dac302b0; Wed, 04 Dec 2024 18:22:59 +0100 (CET) Received: from BN9PR03CA0109.namprd03.prod.outlook.com (2603:10b6:408:fd::24) by MW6PR12MB8833.namprd12.prod.outlook.com (2603:10b6:303:23f::13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8230.11; Wed, 4 Dec 2024 17:22:54 +0000 Received: from BL02EPF0001A104.namprd05.prod.outlook.com (2603:10b6:408:fd:cafe::42) by BN9PR03CA0109.outlook.office365.com (2603:10b6:408:fd::24) with Microsoft SMTP Server (version=TLS1_3, cipher=TLS_AES_256_GCM_SHA384) id 15.20.8207.13 via Frontend Transport; Wed, 4 Dec 2024 17:22:53 +0000 Received: from SATLEXMB04.amd.com (165.204.84.17) by BL02EPF0001A104.mail.protection.outlook.com (10.167.241.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.8230.7 via Frontend Transport; Wed, 4 Dec 2024 17:22:53 +0000 Received: from SATLEXMB04.amd.com (10.181.40.145) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.39; Wed, 4 Dec 2024 11:22:52 -0600 Received: from xcbayankuma40.xilinx.com (10.180.168.240) by SATLEXMB04.amd.com (10.181.40.145) with Microsoft SMTP Server id 15.1.2507.39 via Frontend Transport; Wed, 4 Dec 2024 11:22:51 -0600 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: 6875bdc4-b264-11ef-a0d4-8be0dac302b0 ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=y90Y2MjkTusisFnjrDjGAwibOdxRwUHDXq44/e8mGqJDsKLGPDm6MeKhl7oqlYbdXT5SBOtB9dXxieaHC2B/+3uv1g4YBUymbQr1c82OgcUKIv/9BDAkxEyG0iVCQW0CVuiWob5dXl2rF+bxUIKVVit9d91zS0w7hwcT6HobAZgKfjn81GJqOXgCPxXomEB3tUbV+/9KWTIeCQXT/j3c721fW797B9tbsF8+RRaU5h8SyyQg600Mk44mzQJNCXB9aJy5cq1VaaVbdtS/GxuntXsrZ/q78vNLgJZdsPUn7XpdGrFFHX6pUAkSj6bf/J8ysIRq6DKOUNfym72e2QYisw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=eKRJlYZj/vM8lMPFruBRq7uav07apuOnarZh8uy17dk=; b=cY19GKTxKqgtNjjc4u2elEr+Z8O6NUFN4/kYPNeJJzP1ekdA6FW3m8KM5DhN5JRUCpbDLwWV/rtg32aeQjvsif/kyVJpEbPCcJ3xEH/pKFI9lnQ1LStOTPQqlIr3K7y3cARPq53m+SJEoN706+DNCfXZdKlCS0xqRCDBmVIX0pCNAx7ZGF+LWTtQ4jYb1BdJgqG9EBSsFSE4h7GgxNj2IfcRK7gHdVzXiliHV2YU2uz/sMHj5ChrYF3/dUwjD3f58UkL4zspqkeowsWJHX3i4wZtXUJ6GD92yzC4jQaLy1khvfmbga3teew179DyMPiw/qVjQgs8BEcSzvqWqzI3Xw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 165.204.84.17) smtp.rcpttodomain=lists.xenproject.org smtp.mailfrom=amd.com; dmarc=pass (p=quarantine sp=quarantine pct=100) action=none header.from=amd.com; dkim=none (message not signed); arc=none (0) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amd.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=eKRJlYZj/vM8lMPFruBRq7uav07apuOnarZh8uy17dk=; b=tK8GDlbkBvj3oBNdNWrsypxtp1Ff61nHvPXrKcVUGyxn7J2o3YaxHnQydBBJjttqqoMwrXUnkXVYJohDNhQRX/w54yIESW5IlDrGK5WjqcBlNsrO38QWFBIg9Vaz3QugqiAPjeNgOLehcCdmDo5E5Ow7QkvSjhyYC+PNRYvDOaw= X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 165.204.84.17) smtp.mailfrom=amd.com; dkim=none (message not signed) header.d=none;dmarc=pass action=none header.from=amd.com; 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; Received-SPF: Pass (protection.outlook.com: domain of amd.com designates 165.204.84.17 as permitted sender) receiver=protection.outlook.com; client-ip=165.204.84.17; helo=SATLEXMB04.amd.com; pr=C From: Ayan Kumar Halder To: CC: Ayan Kumar Halder , Stefano Stabellini , Julien Grall , Bertrand Marquis , Michal Orzel , "Volodymyr Babchuk" , Luca Fancellu Subject: [PATCH v3 1/2] xen/mpu: Map early uart when earlyprintk on Date: Wed, 4 Dec 2024 17:22:42 +0000 Message-ID: <20241204172243.1229942-2-ayan.kumar.halder@amd.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20241204172243.1229942-1-ayan.kumar.halder@amd.com> References: <20241204172243.1229942-1-ayan.kumar.halder@amd.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Received-SPF: None (SATLEXMB04.amd.com: ayan.kumar.halder@amd.com does not designate permitted sender hosts) X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: BL02EPF0001A104:EE_|MW6PR12MB8833:EE_ X-MS-Office365-Filtering-Correlation-Id: 31c31c7b-0477-450f-1b12-08dd1488494e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|1800799024|36860700013|376014|82310400026; X-Microsoft-Antispam-Message-Info: =?us-ascii?Q?EhqGEt+ISUOHHSEDsCU9D9Lnl+gOPPP3n/WRHKvphuVpFNue3ZI5dFN53zf5?= =?us-ascii?Q?X+hquwNZYduPOKCt5i7A65eDZapSwb2pd8LVUaVla25QkYn2wkXUqT+AdX5o?= =?us-ascii?Q?oZVS/0M+8g5svuvjZ111TtYy3LJu9iQt5HltJXW78zLzQGidL6NpEx+u8PLa?= =?us-ascii?Q?UKjx2BiGt62iOwac0zjfy0HwavPa1GjLW/kp8i3o99Nj/tEJighQMvpQKGvw?= =?us-ascii?Q?rZdzwXUfU+MfL5LaXAmgTrTrYOb4HlX5yxCf+0O6Jufc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xoUbR/vT4wkt2RCVntFajGlm4ptWZiE?= =?us-ascii?Q?5pj8NSy/3oHR6SEu+JqiOZzbqmCmHTjl/agNriSSeA3Hc7fh4XsE7O+JD+Zl?= =?us-ascii?Q?r27dpTcma3vXaPnuETMt6iYI3OUTDxp2MY57vo/0mfG8AGOC1/waXTBrJIab?= =?us-ascii?Q?XUVD4Z2wlMo8O0Kg+x2bTdrkFxfBvoz0Dx+LXE6tdXzw8/lUFeh4Ge6UlsFa?= =?us-ascii?Q?t033wj/f6bCqrCSpeI33uLrv6UntZhlxepHIhC2+UgHzPQtiJjXlaN4YlZgs?= =?us-ascii?Q?XD4OzF54kQnBM5gefQPC6Yu37VfStCb9?= X-Forefront-Antispam-Report: CIP:165.204.84.17;CTRY:US;LANG:en;SCL:1;SRV:;IPV:CAL;SFV:NSPM;H:SATLEXMB04.amd.com;PTR:InfoDomainNonexistent;CAT:NONE;SFS:(13230040)(1800799024)(36860700013)(376014)(82310400026);DIR:OUT;SFP:1101; X-OriginatorOrg: amd.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Dec 2024 17:22:53.3816 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 31c31c7b-0477-450f-1b12-08dd1488494e X-MS-Exchange-CrossTenant-Id: 3dd8961f-e488-4e60-8e11-a82d994e183d X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=3dd8961f-e488-4e60-8e11-a82d994e183d;Ip=[165.204.84.17];Helo=[SATLEXMB04.amd.com] X-MS-Exchange-CrossTenant-AuthSource: BL02EPF0001A104.namprd05.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW6PR12MB8833 X-ZohoMail-DKIM: pass (identity @amd.com) X-ZM-MESSAGEID: 1733333004343116600 Content-Type: text/plain; charset="utf-8" CONFIG_EARLY_UART_SIZE is introduced to let user provide physical size of early UART. Unlike MMU where we map a page in the virtual address space, here we need to know the exact physical size to be mapped. As VA =3D=3D PA in case of MPU, the memory layout follows exactly the hardw= are configuration. As a consequence, we set EARLY_UART_VIRTUAL_ADDRESS as phys= ical address. EARLY_UART_BASE_ADDRESS and EARLY_UART_SIZE should be aligned to the minimum size of MPU region (ie 64 bits) as per the hardware restrictions. Refer ARM DDI 0600A.d ID120821 A1.3 "A minimum protection region size of 64 bytes.". UART is mapped as nGnRE region (as specified by ATTR=3D100 , refer G1.3.13, MAIR_EL2, "---0100 Device memory nGnRE"). Also, it is mapped as outer share= able, RW at EL2 only and execution of instructions from the region is not permitt= ed. Signed-off-by: Ayan Kumar Halder Reviewed-by: Luca Fancellu Acked-by: Julien Grall --- Changes from :- v1 - 1. UART base address and size should be aligned to the minimum size of= MPU region (and not PAGE_SIZE). v2 - 1. In early_printk.h, included and fixed the macro n= ames. 2. Included in head.S. 3. Updated the commit message (to remove reference to R82 TRM) and added Lu= ca's R-b. xen/arch/arm/Kconfig.debug | 7 +++++++ xen/arch/arm/arm64/mpu/head.S | 10 +++++++++ xen/arch/arm/include/asm/early_printk.h | 28 ++++++++++++++++++++++++- 3 files changed, 44 insertions(+), 1 deletion(-) diff --git a/xen/arch/arm/Kconfig.debug b/xen/arch/arm/Kconfig.debug index 7660e599c0..84a0616102 100644 --- a/xen/arch/arm/Kconfig.debug +++ b/xen/arch/arm/Kconfig.debug @@ -121,6 +121,13 @@ config EARLY_UART_BASE_ADDRESS hex "Early printk, physical base address of debug UART" range 0x0 0xffffffff if ARM_32 =20 +config EARLY_UART_SIZE + depends on EARLY_PRINTK + depends on MPU + hex "Early printk, physical size of debug UART" + range 0x0 0xffffffff if ARM_32 + default 0x1000 + config EARLY_UART_PL011_BAUD_RATE depends on EARLY_UART_PL011 int "Early printk UART baud rate for pl011" diff --git a/xen/arch/arm/arm64/mpu/head.S b/xen/arch/arm/arm64/mpu/head.S index d3db5e53af..e4f2021f45 100644 --- a/xen/arch/arm/arm64/mpu/head.S +++ b/xen/arch/arm/arm64/mpu/head.S @@ -4,6 +4,7 @@ */ =20 #include +#include =20 /* Backgroud region enable/disable */ #define SCTLR_ELx_BR BIT(17, UL) @@ -11,8 +12,10 @@ #define REGION_TEXT_PRBAR 0x38 /* SH=3D11 AP=3D10 XN=3D00 */ #define REGION_RO_PRBAR 0x3A /* SH=3D11 AP=3D10 XN=3D10 */ #define REGION_DATA_PRBAR 0x32 /* SH=3D11 AP=3D00 XN=3D10 */ +#define REGION_DEVICE_PRBAR 0x22 /* SH=3D10 AP=3D00 XN=3D10 */ =20 #define REGION_NORMAL_PRLAR 0x0f /* NS=3D0 ATTR=3D111 EN=3D1 */ +#define REGION_DEVICE_PRLAR 0x09 /* NS=3D0 ATTR=3D100 EN=3D1 */ =20 /* * Macro to prepare and set a EL2 MPU memory region. @@ -140,6 +143,13 @@ FUNC(enable_boot_cpu_mm) ldr x2, =3D__bss_end prepare_xen_region x0, x1, x2, x3, x4, x5 =20 +#ifdef CONFIG_EARLY_PRINTK + /* Xen early UART section. */ + ldr x1, =3DCONFIG_EARLY_UART_BASE_ADDRESS + ldr x2, =3D(CONFIG_EARLY_UART_BASE_ADDRESS + CONFIG_EARLY_UART_SIZE) + prepare_xen_region x0, x1, x2, x3, x4, x5, attr_prbar=3DREGION_DEVICE_= PRBAR, attr_prlar=3DREGION_DEVICE_PRLAR +#endif + b enable_mpu ret END(enable_boot_cpu_mm) diff --git a/xen/arch/arm/include/asm/early_printk.h b/xen/arch/arm/include= /asm/early_printk.h index 46a5e562dd..219705a8b6 100644 --- a/xen/arch/arm/include/asm/early_printk.h +++ b/xen/arch/arm/include/asm/early_printk.h @@ -11,10 +11,33 @@ #define __ARM_EARLY_PRINTK_H__ =20 #include +#include #include =20 #ifdef CONFIG_EARLY_PRINTK =20 +#if defined(CONFIG_MPU) + +/* + * For MPU systems, there is no VMSA support in EL2, so we use VA =3D=3D PA + * for EARLY_UART_VIRTUAL_ADDRESS. + */ +#define EARLY_UART_VIRTUAL_ADDRESS CONFIG_EARLY_UART_BASE_ADDRESS + +/* + * User-defined EARLY_UART_BASE_ADDRESS and EARLY_UART_SIZE must be aligne= d to + * minimum size of MPU region. + */ +#if (CONFIG_EARLY_UART_BASE_ADDRESS % MPU_REGION_ALIGN) !=3D 0 +#error "EARLY_UART_BASE_ADDRESS must be aligned to minimum MPU region size" +#endif + +#if (CONFIG_EARLY_UART_SIZE % MPU_REGION_ALIGN) !=3D 0 +#error "EARLY_UART_SIZE must be aligned to minimum MPU region size" +#endif + +#elif defined(CONFIG_MMU) + /* need to add the uart address offset in page to the fixmap address */ #define EARLY_UART_VIRTUAL_ADDRESS \ (FIXMAP_ADDR(FIX_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRESS & ~PAGE_MA= SK)) @@ -22,6 +45,9 @@ #define TEMPORARY_EARLY_UART_VIRTUAL_ADDRESS \ (TEMPORARY_FIXMAP_ADDR(FIX_CONSOLE) + (CONFIG_EARLY_UART_BASE_ADDRESS = & ~PAGE_MASK)) =20 -#endif /* !CONFIG_EARLY_PRINTK */ +#else +#error "Unknown Memory management system" +#endif =20 +#endif /* !CONFIG_EARLY_PRINTK */ #endif --=20 2.25.1