From: Wei Liu Subject: [PATCH] hvmloader: write extra memory in CMOS Date: Tue, 12 Nov 2013 11:41:00 +0000 Message-ID: <1384256460-22158-1-git-send-email-wei.liu2@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: Received: from mail6.bemta5.messagelabs.com ([195.245.231.135]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1VgCLA-0006vU-UO for xen-devel@lists.xenproject.org; Tue, 12 Nov 2013 11:41:05 +0000 List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel@lists.xenproject.org Cc: Wei Liu List-Id: xen-devel@lists.xenproject.org Some firmware, such as OVMF relies on this value to get the size of extra memory above 4GB. Seabios in Xen doesn't need this as it gets e820 directly from Xen. Rombios doesn't read this value. Signed-off-by: Wei Liu --- tools/firmware/hvmloader/hvmloader.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tools/firmware/hvmloader/hvmloader.c b/tools/firmware/hvmloader/hvmloader.c index 1cc8cf2..327dffd 100644 --- a/tools/firmware/hvmloader/hvmloader.c +++ b/tools/firmware/hvmloader/hvmloader.c @@ -146,6 +146,7 @@ static void init_hypercalls(void) static void cmos_write_memory_size(void) { uint32_t base_mem = 640, ext_mem, alt_mem; + uint64_t extra_mem = 0; alt_mem = ext_mem = hvm_info->low_mem_pgend << PAGE_SHIFT; ext_mem = (ext_mem > 0x0100000) ? (ext_mem - 0x0100000) >> 10 : 0; @@ -153,6 +154,15 @@ static void cmos_write_memory_size(void) ext_mem = 0xffff; alt_mem = (alt_mem > 0x1000000) ? (alt_mem - 0x1000000) >> 16 : 0; + /* According to hvm_info: + * 0x100000000 to page_to_phys(high_mem_pgend)-1: + * RAM above 4GB + * extra_mem written to CMOS is represented as 64kb chunks + */ + extra_mem = hvm_info->high_mem_pgend; + extra_mem = (extra_mem > 0x100000) ? + (((extra_mem - 0x100000) << PAGE_SHIFT) >> 16) : 0; + /* All BIOSes: conventional memory (CMOS *always* reports 640kB). */ cmos_outb(0x15, (uint8_t)(base_mem >> 0)); cmos_outb(0x16, (uint8_t)(base_mem >> 8)); @@ -166,6 +176,11 @@ static void cmos_write_memory_size(void) /* Some BIOSes: alternative extended memory (64kB chunks above 16MB). */ cmos_outb(0x34, (uint8_t)( alt_mem >> 0)); cmos_outb(0x35, (uint8_t)( alt_mem >> 8)); + + /* Some BIOSes: extra memory (64kB chunks above 4GB) */ + cmos_outb(0x5d, (uint8_t)( extra_mem >> 16)); + cmos_outb(0x5c, (uint8_t)( extra_mem >> 8)); + cmos_outb(0x5b, (uint8_t)( extra_mem >> 0)); } /* -- 1.7.10.4