From patchwork Wed Apr 27 20:11:54 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Neri X-Patchwork-Id: 615801 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id 3qwB2w60Qbz9t6f; Thu, 28 Apr 2016 06:12:40 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1avVp9-00040d-6b; Wed, 27 Apr 2016 20:12:39 +0000 Received: from mga03.intel.com ([134.134.136.65]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1avVou-0003yP-KA for fwts-devel@lists.ubuntu.com; Wed, 27 Apr 2016 20:12:24 +0000 Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga103.jf.intel.com with ESMTP; 27 Apr 2016 13:12:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.24,543,1455004800"; d="scan'208";a="693336573" Received: from unknown (HELO luv-build.sc.intel.com) ([172.25.110.25]) by FMSMGA003.fm.intel.com with ESMTP; 27 Apr 2016 13:12:22 -0700 From: Ricardo Neri To: fwts-devel@lists.ubuntu.com Subject: [PATCH 3/3] bios: mtrr: redefine the end point of memory ranges Date: Wed, 27 Apr 2016 13:11:54 -0700 Message-Id: <1461787914-13902-4-git-send-email-ricardo.neri-calderon@linux.intel.com> X-Mailer: git-send-email 2.8.1 In-Reply-To: <1461787914-13902-1-git-send-email-ricardo.neri-calderon@linux.intel.com> References: <1461787914-13902-1-git-send-email-ricardo.neri-calderon@linux.intel.com> X-BeenThere: fwts-devel@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Firmware Test Suite Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: fwts-devel-bounces@lists.ubuntu.com Sender: fwts-devel-bounces@lists.ubuntu.com Currently the end of an entry partition is calculated as entry->end = entry->start + entry->size However, this leads to memory _ranges_ that are off by one byte at the end. For instance, if we had a range starting at 0x10 with a size of 0x10, the range should be [0x10, 0x1f]. Thus, entry->start should be 0x10 and entry->end should be 0x1f. Furthermore, Linux determines the size of the MTRR range by looking at the contents of the MTRR_PHYSMASKn registers. These registers are set in such a manner that a mask, not a size, determines whether a memory location belongs to the MTRR memory range [1]. The entry->start and entry->end values are used for two purposes: 1) Display the memory _ranges_ covered by each of the MTRR registers, and 2) Determine whether a particular memory range is covered by any of the MTRR registers. For 1), redefining the value of entry->end a) represents better what the MTRR registers actually mean and b) make the printout of such ranges similar to what the /proc/iomem file presents, which is used as input for the MTRR tests. For 2), the cache_type function needs to be updated for this new definition of entry->end. Simple algebra shows how the inequalities need to be adjusted. Let A, A' and B integers where A' = A - 1. If we have A > B A' + 1 > B then we can drop the second member of the expression at the left by using a greater-than sign. This can be done as involved quantities are integers. We can simply do A' >= B [1]. http://www.intel.com/content/www/us/en/processors /architectures-software-developer-manuals.html Signed-off-by: Ricardo Neri Acked-by: Colin Ian King Acked-by: Alex Hung --- src/bios/mtrr/mtrr.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bios/mtrr/mtrr.c b/src/bios/mtrr/mtrr.c index 8176803..120b943 100644 --- a/src/bios/mtrr/mtrr.c +++ b/src/bios/mtrr/mtrr.c @@ -144,7 +144,7 @@ static int get_mtrrs(void) if (ptr2 && (*ptr2 == 'k')) entry->size *= 1024; - entry->end = entry->start + entry->size; + entry->end = entry->start + entry->size - 1; if (strstr(line, "write-back")) entry->type = WRITE_BACK; @@ -174,7 +174,7 @@ static int cache_types(uint64_t start, uint64_t end) fwts_list_foreach(item, mtrr_list) { entry = fwts_list_data(struct mtrr_entry*, item); - if (entry->end > start && entry->start <= end) + if (entry->end >= start && entry->start <= end) type |= entry->type; } @@ -186,7 +186,7 @@ restart: fwts_list_foreach(item, mtrr_list) { entry = fwts_list_data(struct mtrr_entry*, item); - if (entry->end > end && entry->start < end) { + if (entry->end >= end && entry->start < end) { end = entry->start; if (end < start) end = start;