From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: 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 Cc: heyi.guo@linaro.org, Ard Biesheuvel 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: [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: , X-List-Received-Date: Fri, 09 Sep 2016 10:48:50 -0000 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(-) 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); } } -- 2.7.4