From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BBCADC4338F for ; Sat, 31 Jul 2021 08:45:52 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id B4C7860EB5 for ; Sat, 31 Jul 2021 08:45:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org B4C7860EB5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5B46A83267; Sat, 31 Jul 2021 10:45:49 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.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=gmail.com header.i=@gmail.com header.b="KHJa0nvB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C39DF83259; Sat, 31 Jul 2021 10:45:45 +0200 (CEST) Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 2F76182DD3 for ; Sat, 31 Jul 2021 10:45:42 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=bmeng.cn@gmail.com Received: by mail-pj1-x1030.google.com with SMTP id k4-20020a17090a5144b02901731c776526so24214515pjm.4 for ; Sat, 31 Jul 2021 01:45:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qXH7S4cNKldgIYEJyOtBYiXw/CgkF37moczMh9BUBn4=; b=KHJa0nvB7PYfQf3/i3DQfOIngp1DC88CXVJGomitM4lLweQOVJHn9dPSsqKouefHPM ltiZKymIPmzTU190bvoup/E4MdOinonBS3XVZU3Zkwrzuyaww6d6I3rcg/XuOqvi4Hc8 hoQmEmORAl1q7Cj7cG+2njlciAWTF81mMdSH7qfxXsQ/JKgL/8/1v+CEXgJRWgYk4F71 ShjJ73W1qwzgDpIgOsWJ+zmUjjtJHa9ClDjQgPSS8qwGBdz58xXeSvQJ6H6kZTb5iR9r xr+SJDJANP1l4ewKBo3mDg5Mk8Rs0Tg4qe9132bBoz8zryKL8ej43mmIvC4YGNPYvw8m z7Xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qXH7S4cNKldgIYEJyOtBYiXw/CgkF37moczMh9BUBn4=; b=jMSiCdV7/EjN98DekE5tuM8X1T+PL7Iu7u1XnQ7obZF9n8mCYS4UhCKSt3OUuTA+Ed y5VIkn2DkPjzbcXRVIKJRERQI0uAaorTNiqMk3ABgsWSKGM1JG9BxUCeaLS+Pb+XEr3B DDKlkrpEDVgwyPM++IhGteXqzsyWXt4vhBSvyQzjGQoiI6AQvmoVwDn5fBI0HXSbJVlN HEHo8RsLjIcAgk5EfjC+B+VPqz1MR5zHdC2qHmNE5QWTQRq2YPnrQFZtSwDaRR/9Iy4L Os9yvlG1HRzTiPvsNGJ+XPG1FdbSWRSDAtvQunpuUEqsHvl234lIN36c9vd9ZCCFlxrM f6Zw== X-Gm-Message-State: AOAM532KnCqvpPIBeeDYVrzrM2G9bpp/ohvgW5rxMjgqwFJKv7sjeAL5 4OZ6ekoEtWPZeLF1zfvF0J4= X-Google-Smtp-Source: ABdhPJxfi4FM99v7zM4QiKRA16SDDG84naellhco1B7jEts44FCec6pAdzo6UE3ngaCGhFZel40bHw== X-Received: by 2002:a63:1d47:: with SMTP id d7mr5319469pgm.44.1627721140558; Sat, 31 Jul 2021 01:45:40 -0700 (PDT) Received: from i9-aorus-gtx1080.localdomain (144.168.56.201.16clouds.com. [144.168.56.201]) by smtp.gmail.com with ESMTPSA id h6sm688355pfv.155.2021.07.31.01.45.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 31 Jul 2021 01:45:40 -0700 (PDT) From: Bin Meng To: Simon Glass , u-boot@lists.denx.de Cc: Bin Meng Subject: [PATCH 1/7] x86: fsp: Don't program MTRR for DRAM Date: Sat, 31 Jul 2021 16:45:23 +0800 Message-Id: <20210731084529.7524-2-bmeng.cn@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210731084529.7524-1-bmeng.cn@gmail.com> References: <20210731084529.7524-1-bmeng.cn@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 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.2 at phobos.denx.de X-Virus-Status: Clean This actually reverts the following 2 commits: commit 427911001809 ("x86: Set up the MTRR for SDRAM") commit d46c0932a9d4 ("x86: fsp: Adjust calculations for MTRR range and DRAM top") There are several outstanding issues as to why: * For FSP1, the system memory and reserved memory used by FSP are already programmed in the MTRR by FSP. * The 'mtrr_top' mistakenly includes TSEG memory range that has the same RES_MEM_RESERVED resource type. Its address is programmed and reported by FSP to be near the top of 4 GiB space, which is not what we want for SDRAM. * The call to mtrr_add_request() is not guaranteed to have its size to be exactly the power of 2. This causes reserved bits of the IA32_MTRR_PHYSMASK register to be written which generates #GP. Signed-off-by: Bin Meng --- arch/x86/lib/fsp/fsp_dram.c | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/arch/x86/lib/fsp/fsp_dram.c b/arch/x86/lib/fsp/fsp_dram.c index 8ad9aeedac..928c5225cd 100644 --- a/arch/x86/lib/fsp/fsp_dram.c +++ b/arch/x86/lib/fsp/fsp_dram.c @@ -11,7 +11,6 @@ #include #include #include -#include #include #include @@ -42,10 +41,8 @@ int fsp_scan_for_ram_size(void) int dram_init_banksize(void) { - efi_guid_t fsp = FSP_HOB_RESOURCE_OWNER_FSP_GUID; const struct hob_header *hdr; struct hob_res_desc *res_desc; - phys_addr_t mtrr_top; phys_addr_t low_end; uint bank; @@ -53,47 +50,35 @@ int dram_init_banksize(void) gd->bd->bi_dram[0].start = 0; gd->bd->bi_dram[0].size = gd->ram_size; - mtrr_add_request(MTRR_TYPE_WRBACK, 0, gd->ram_size); return 0; } - low_end = 0; /* top of low memory usable by U-Boot */ - mtrr_top = 0; /* top of low memory (even if reserved) */ + low_end = 0; for (bank = 1, hdr = gd->arch.hob_list; bank < CONFIG_NR_DRAM_BANKS && !end_of_hob(hdr); hdr = get_next_hob(hdr)) { if (hdr->type != HOB_TYPE_RES_DESC) continue; res_desc = (struct hob_res_desc *)hdr; - if (!guidcmp(&res_desc->owner, &fsp)) - low_end = res_desc->phys_start; if (res_desc->type != RES_SYS_MEM && res_desc->type != RES_MEM_RESERVED) continue; if (res_desc->phys_start < (1ULL << 32)) { - mtrr_top = max(mtrr_top, - res_desc->phys_start + res_desc->len); - } else { - gd->bd->bi_dram[bank].start = res_desc->phys_start; - gd->bd->bi_dram[bank].size = res_desc->len; - mtrr_add_request(MTRR_TYPE_WRBACK, res_desc->phys_start, - res_desc->len); - log_debug("ram %llx %llx\n", - gd->bd->bi_dram[bank].start, - gd->bd->bi_dram[bank].size); + low_end = max(low_end, + res_desc->phys_start + res_desc->len); + continue; } + + gd->bd->bi_dram[bank].start = res_desc->phys_start; + gd->bd->bi_dram[bank].size = res_desc->len; + log_debug("ram %llx %llx\n", gd->bd->bi_dram[bank].start, + gd->bd->bi_dram[bank].size); } /* Add the memory below 4GB */ gd->bd->bi_dram[0].start = 0; gd->bd->bi_dram[0].size = low_end; - /* - * Set up an MTRR to the top of low, reserved memory. This is necessary - * for graphics to run at full speed in U-Boot. - */ - mtrr_add_request(MTRR_TYPE_WRBACK, 0, mtrr_top); - return 0; } @@ -166,7 +151,7 @@ unsigned int install_e820_map(unsigned int max_entries, #if CONFIG_IS_ENABLED(HANDOFF) && IS_ENABLED(CONFIG_USE_HOB) int handoff_arch_save(struct spl_handoff *ho) { - ho->arch.usable_ram_top = gd->bd->bi_dram[0].size; + ho->arch.usable_ram_top = fsp_get_usable_lowmem_top(gd->arch.hob_list); ho->arch.hob_list = gd->arch.hob_list; return 0; -- 2.25.1