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 phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 01587C433F5 for ; Tue, 29 Mar 2022 17:07:15 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A6CA284040; Tue, 29 Mar 2022 19:07:13 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="QrkXisaj"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3E93283D0C; Tue, 29 Mar 2022 19:07:12 +0200 (CEST) Received: from mail-wm1-x349.google.com (mail-wm1-x349.google.com [IPv6:2a00:1450:4864:20::349]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id A16B684040 for ; Tue, 29 Mar 2022 19:07:08 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3uzxDYgUKBloHLGKA8GG8D6.4GEM-3GGLDAKLK.56FP.56@flex--ptosi.bounces.google.com Received: by mail-wm1-x349.google.com with SMTP id m185-20020a1c26c2000000b0038c9e1197f6so2171775wmm.4 for ; Tue, 29 Mar 2022 10:07:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc:content-transfer-encoding; bh=wAT+9YjQAHxTzG55HVtLUbPsGeSGcCaJnPni0s3GEJk=; b=QrkXisajBiG/3XIg2yR+O8YqwOepJYKD6woRCgpf5vGRydgQU+2aLcaxN5pPV2k5NJ rkB1TaVg7DJvtLefDdohpMI1QU4C2DNOrIMka99QTpcOvhX/61hScxJlAkEiVqclwvxP D3OudLbq+Qvxju7xgYUPdbYQUWIgbEVvEk2lSl5EGAuxbHhUqxuobw0BlOpQpW4oFmFH MTrObHBPMKRS9cZjIcxrCC0Kcxy29y7RCzo1l7JhFJBKe13fS5FcApUH9TAMdoP1f08P ftiZIqShsEkxQ9Y7M1lejMaiuJyXNV0WZa2ULU9pFNKd3gPpgGrIIZHpaDf80L94E3sh eulA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc:content-transfer-encoding; bh=wAT+9YjQAHxTzG55HVtLUbPsGeSGcCaJnPni0s3GEJk=; b=o4Qsth74M/94bj6575iAF95mp1zlgVTiwqD1VRICufrivwUmJzBQFuHCl32xjy1kcr 84aj7ri+RaVKaO3taiebb0VaTf9sw95vClxrh1yfSkUXjvd7kw3xcsP3b8URMnOjbdv+ 4MveDK39nHtXk+6B9b9FmVElR60fhfoOBdOJ0UG6TsUXvgUrMqBXRRiz8h02jmD7h3M9 UFdkYyh0y43CgwEc+Jk48fKpX59oyTZtaMI1xOmGm0fi485WLWt0TgGckLUUj7ez/eUW akAiRArXdjCRUR+CxcJvZejBEtVbaLL++4XOfhudwRCrbQNbVE30DMCrU/DoFW3C6MdQ rnKA== X-Gm-Message-State: AOAM532SpGhZqNFaQqKrK0eHNxWxzcDLKqLilnkN8by6Q7lmJIQsLQmQ 7VnmcOVZm4V8HdXK+fSuPsQteSpjqWSNhuqV66xRs6jwRKEpT08ws0UDUvmghqkc7DSkA7+Sq2z jZY8TgnuUEdZrROah8nRAIQuHP/D7EdkANE+FGYvU64VI87o6AqpNXevY X-Google-Smtp-Source: ABdhPJy3YTPubSmo6Lu3A2jLtGiU26xd3OAmKlrxqEnrqONSfaZjOQ3Xzy4wPcOS2KXLruh0ZcwpOsrjaQ== X-Received: from ptosi1.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:afb]) (user=ptosi job=sendgmr) by 2002:a05:600c:3c89:b0:37f:aacb:cac7 with SMTP id bg9-20020a05600c3c8900b0037faacbcac7mr184704wmb.1.1648573627785; Tue, 29 Mar 2022 10:07:07 -0700 (PDT) Date: Tue, 29 Mar 2022 18:06:07 +0100 In-Reply-To: <20220329170607.689006-1-ptosi@google.com> Message-Id: <20220329170607.689006-3-ptosi@google.com> Mime-Version: 1.0 References: <20220329170607.689006-1-ptosi@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH 3/3] armv8: Initialize MAIR in early boot From: "=?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?=" To: u-boot@lists.denx.de Cc: "=?UTF-8?q?Pierre-Cl=C3=A9ment=20Tosi?=" , Tom Rini Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.5 at phobos.denx.de X-Virus-Status: Clean As the register is initialized to a constant value, it can be set at any point before the MMU has been enabled. Instead of waiting until the very last moment to do so, initialize it during early boot, when we initialize other system registers. This ensures it is valid at any point once the C runtime is up. Signed-off-by: Pierre-Cl=C3=A9ment Tosi Cc: Tom Rini --- arch/arm/cpu/armv8/Kconfig | 6 ++++++ arch/arm/cpu/armv8/start.S | 12 ++++++++++++ arch/arm/include/asm/armv8/mmu.h | 5 ----- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/arch/arm/cpu/armv8/Kconfig b/arch/arm/cpu/armv8/Kconfig index 9967376eca..efb451e9a5 100644 --- a/arch/arm/cpu/armv8/Kconfig +++ b/arch/arm/cpu/armv8/Kconfig @@ -31,6 +31,12 @@ config ARMV8_SET_SMPEN it can be safely enabled when EL2/EL3 initialized SMPEN bit or when CPU implementation doesn't include that register. =20 +config ARMV8_SET_MAIR + bool "Initialize the MAIR to its constant value out of boot" + default y if !SYS_DISABLE_DCACHE_OPS + help + Say Y here to set MAIR_ELx (MEMORY_ATTRIBUTES), needed by the MMU. + config ARMV8_SPIN_TABLE bool "Support spin-table enable method" depends on ARMV8_MULTIENTRY && OF_LIBFDT diff --git a/arch/arm/cpu/armv8/start.S b/arch/arm/cpu/armv8/start.S index 91b00a46cc..dca58922c1 100644 --- a/arch/arm/cpu/armv8/start.S +++ b/arch/arm/cpu/armv8/start.S @@ -135,6 +135,18 @@ pie_fixup_done: msr cpacr_el1, x0 /* Enable FP/SIMD */ 0: =20 +#ifdef CONFIG_ARMV8_SET_MAIR + ldr x2, =3D(MEMORY_ATTRIBUTES) + switch_el x1, 3f, 2f, 1f + b 0f +3: msr mair_el3, x2 + b 0f +2: msr mair_el2, x2 + b 0f +1: msr mair_el1, x2 +0: +#endif + #ifdef COUNTER_FREQUENCY branch_if_not_highest_el x0, 4f ldr x0, =3DCOUNTER_FREQUENCY diff --git a/arch/arm/include/asm/armv8/mmu.h b/arch/arm/include/asm/armv8/= mmu.h index 7c17c06e98..c9fbfcaed2 100644 --- a/arch/arm/include/asm/armv8/mmu.h +++ b/arch/arm/include/asm/armv8/mmu.h @@ -109,21 +109,16 @@ =20 static inline void set_ttbr_tcr(int el, u64 table, u64 tcr) { - const u64 attr =3D MEMORY_ATTRIBUTES; - asm volatile("dsb sy"); if (el =3D=3D 1) { asm volatile("msr ttbr0_el1, %0" : : "r" (table) : "memory"); asm volatile("msr tcr_el1, %0" : : "r" (tcr) : "memory"); - asm volatile("msr mair_el1, %0" : : "r" (attr) : "memory"); } else if (el =3D=3D 2) { asm volatile("msr ttbr0_el2, %0" : : "r" (table) : "memory"); asm volatile("msr tcr_el2, %0" : : "r" (tcr) : "memory"); - asm volatile("msr mair_el2, %0" : : "r" (attr) : "memory"); } else if (el =3D=3D 3) { asm volatile("msr ttbr0_el3, %0" : : "r" (table) : "memory"); asm volatile("msr tcr_el3, %0" : : "r" (tcr) : "memory"); - asm volatile("msr mair_el3, %0" : : "r" (attr) : "memory"); } else { hang(); } --=20 2.35.1.1021.g381101b075-goog