From patchwork Fri Sep 9 10:48:37 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 75870 Delivered-To: patch@linaro.org Received: by 10.140.106.11 with SMTP id d11csp280349qgf; Fri, 9 Sep 2016 03:56:12 -0700 (PDT) X-Received: by 10.66.2.168 with SMTP id 8mr5308337pav.87.1473418131369; Fri, 09 Sep 2016 03:48:51 -0700 (PDT) Return-Path: Received: from ml01.01.org (ml01.01.org. [198.145.21.10]) by mx.google.com with ESMTPS id d68si3433046pfa.77.2016.09.09.03.48.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 09 Sep 2016 03:48:51 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) client-ip=198.145.21.10; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org; spf=pass (google.com: best guess record for domain of edk2-devel-bounces@lists.01.org designates 198.145.21.10 as permitted sender) smtp.mailfrom=edk2-devel-bounces@lists.01.org; dmarc=fail (p=NONE dis=NONE) header.from=linaro.org Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id C08061A1E66; Fri, 9 Sep 2016 03:48:50 -0700 (PDT) X-Original-To: edk2-devel@lists.01.org Delivered-To: edk2-devel@lists.01.org Received: from mail-wm0-x22a.google.com (mail-wm0-x22a.google.com [IPv6:2a00:1450:400c:c09::22a]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 9E96C1A1E64 for ; Fri, 9 Sep 2016 03:48:49 -0700 (PDT) Received: by mail-wm0-x22a.google.com with SMTP id w12so25638519wmf.0 for ; Fri, 09 Sep 2016 03:48:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=/EecoSP/qrUUDmaiLb5ilDuPg5EmUBvo73B6ZEqXrMU=; b=ho57vraDitLtr9xRhMkRhelhKoYvSiSB39XBtbEcRllqKo1rezxW3OvoAaJ+zltk0V AidhAk0HZmt+xztVFtCMpxRAT5lHVvFYiq4ZgcduXWi9CTMMQM1o3cI3q82MqOrnvp4g 8h4cAyaTUwQurZqbfgOpx+wqLgzoYYUQhySys= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=/EecoSP/qrUUDmaiLb5ilDuPg5EmUBvo73B6ZEqXrMU=; b=lg8rInzRCylxv0iHyw5XaJ+tUKlQrDxkgyxS0X93VWbGKboyck8D+e/YFsoluNOsY+ mNh19slBnW57AwIsHIxlFemXuyblZe0jtlTpu2MuuSoKAFe4SCa+VhWmvlxHYV/p+CBZ bJg8uqyxpLOGyrXHZrnT5yC3jE56MLUN2621fntYgxOF5t/VtcrMuZtfrjn86xemU4dM xtJz3UN/COHRNhtWhcjQNurwvAZgR/p2GWHtG9sy/VjwlVuIcvSu13R9gImOLEzZmPvT h+hs5FWHEV+XUvZUmmq0Z9yQDl27USGZmHRFOZzx5FyuaOfhrlfWtH4ekT6mwuOUxAT5 Wxxw== X-Gm-Message-State: AE9vXwNpfTYRdsMZ6USqtP9EjQbdvl0S3fGWaxL4wu2dXjbN6Wb5ki+jMdBx4EgA5NzZJmvw X-Received: by 10.28.50.3 with SMTP id y3mr2434633wmy.23.1473418128038; Fri, 09 Sep 2016 03:48:48 -0700 (PDT) Received: from localhost.localdomain ([105.190.180.180]) by smtp.gmail.com with ESMTPSA id z4sm2716580wmg.19.2016.09.09.03.48.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 09 Sep 2016 03:48:47 -0700 (PDT) From: Ard Biesheuvel To: edk2-devel@lists.01.org, leif.lindholm@linaro.org, eugene@hp.com Date: Fri, 9 Sep 2016 11:48:37 +0100 Message-Id: <1473418120-31410-2-git-send-email-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1473418120-31410-1-git-send-email-ard.biesheuvel@linaro.org> References: <1473418120-31410-1-git-send-email-ard.biesheuvel@linaro.org> Subject: [edk2] [PATCH v2 1/4] ArmPkg/ArmMmuLib: deobfuscate GetRootTranslationTableInfo () X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heyi.guo@linaro.org, Ard Biesheuvel MIME-Version: 1.0 Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" The relations between T0SZ, the number of translation levels and the size/alignment of the root table can be expressed in simple arithmetic expressions, so get rid of the lookup table. Note that this disregards the fact that the maximum value of T0SZ is 39 not 42 (as one would expect for the smallest VA size using 2 levels) but since this corresponds to a VA size of 32 MB and 4 MB, respectively, neither of which are sufficient to run UEFI, we can safely ignore the distinction. Contributed-under: TianoCore Contribution Agreement 1.0 Signed-off-by: Ard Biesheuvel --- ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c | 35 +++----------------- 1 file changed, 4 insertions(+), 31 deletions(-) -- 2.7.4 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel diff --git a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c index 6e05e6085011..84a689af7c8a 100644 --- a/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c +++ b/ArmPkg/Library/ArmMmuLib/AArch64/ArmMmuLibCore.c @@ -121,20 +121,8 @@ GcdAttributeToArmAttribute ( } } -// Describe the T0SZ values for each translation table level -typedef struct { - UINTN MinT0SZ; - UINTN MaxT0SZ; - UINTN LargestT0SZ; // Generally (MaxT0SZ == LargestT0SZ) but at the Level3 Table - // the MaxT0SZ is not at the boundary of the table -} T0SZ_DESCRIPTION_PER_LEVEL; - -// Map table for the corresponding Level of Table -STATIC CONST T0SZ_DESCRIPTION_PER_LEVEL T0SZPerTableLevel[] = { - { 16, 24, 24 }, // Table Level 0 - { 25, 33, 33 }, // Table Level 1 - { 34, 39, 42 } // Table Level 2 -}; +#define MIN_T0SZ 16 +#define BITS_PER_LEVEL 9 VOID GetRootTranslationTableInfo ( @@ -143,28 +131,13 @@ GetRootTranslationTableInfo ( OUT UINTN *TableEntryCount ) { - UINTN Index; - - // Identify the level of the root table from the given T0SZ - for (Index = 0; Index < sizeof (T0SZPerTableLevel) / sizeof (T0SZ_DESCRIPTION_PER_LEVEL); Index++) { - if (T0SZ <= T0SZPerTableLevel[Index].MaxT0SZ) { - break; - } - } - - // If we have not found the corresponding maximum T0SZ then we use the last one - if (Index == sizeof (T0SZPerTableLevel) / sizeof (T0SZ_DESCRIPTION_PER_LEVEL)) { - Index--; - } - // Get the level of the root table if (TableLevel) { - *TableLevel = Index; + *TableLevel = (T0SZ - MIN_T0SZ) / BITS_PER_LEVEL; } - // The Size of the Table is 2^(T0SZ-LargestT0SZ) if (TableEntryCount) { - *TableEntryCount = 1 << (T0SZPerTableLevel[Index].LargestT0SZ - T0SZ + 1); + *TableEntryCount = 1UL << (BITS_PER_LEVEL - (T0SZ - MIN_T0SZ) % BITS_PER_LEVEL); } }