From patchwork Mon Jul 27 03:45:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1336649 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=m6IL1b4S; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BFQsm42DJz9sPB for ; Mon, 27 Jul 2020 13:54:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id AD86982389; Mon, 27 Jul 2020 05:49:28 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="m6IL1b4S"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 1BF488232C; Mon, 27 Jul 2020 05:46:47 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-oi1-x244.google.com (mail-oi1-x244.google.com [IPv6:2607:f8b0:4864:20::244]) (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 0C0A38229F for ; Mon, 27 Jul 2020 05:46:17 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-oi1-x244.google.com with SMTP id u63so1464813oie.5 for ; Sun, 26 Jul 2020 20:46:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sEybB10kFXxavUB2Ve+Rd55uzcJP2xhfdU0+dnh5PYU=; b=m6IL1b4S3G2F/xpXoVVzp5dMpmg1uR5l5w2gWX2pLxolMpIw3UB2EV7Zu/b5d5NL/Y T9ByCGy88YweVv1nH8viQ0HOAVTxbjBpDi738QTdwgFKvrkC6lboPy6iTw6OpnxyYVab aoW1oREE7JIbDFMoR6SbjOvb80F9zG+6Z6V5k= 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=sEybB10kFXxavUB2Ve+Rd55uzcJP2xhfdU0+dnh5PYU=; b=QU4jPdihLV7KWUjOEYDTqo8bva5iSnmn+eiWpDu++ieKHk4CT1HROvZvaHyvBRqZsE Ea8c3kYq6PvcjEPJy1wjLZfn1R8RJ2iXJ77nyiEUO2faMRj2Qk+bTUw2sp65DRvRzJtY 3zvdj/AYONKPDP0RzqaWV4N4S2yFMbAdph8PU3ttXVSHtaf/KMDsQssumIBBr+Rak6Un M5DOmlqg/GEh9E0SsQBIyl/YcJX22eAe++5EdzAjTBxuMyFKtoQK6kzCKljoQP0OTBBu p5B7wLRJuLbvhY40SgXD45pmtQxGCuGGGb6WjokisNf/YCG9yYT2RbczBguvdNUXduVw QJdQ== X-Gm-Message-State: AOAM531fY+OM7XEkK6zFM5SpC6gerhIo2P4aRTDquVnYw72CrWPDWq+Q w7RlfmM6c/NJTTEKkBqpsRMEELJD5GCjZA== X-Google-Smtp-Source: ABdhPJy5F1f6+MVo01y+6OZxqoDuxEg80YTtxelEXg6mfJLph97RXoar8ueTOBBPcoLPZ1/DW2PonQ== X-Received: by 2002:a54:460b:: with SMTP id p11mr17084508oip.77.1595821575780; Sun, 26 Jul 2020 20:46:15 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id p64sm1808996oih.39.2020.07.26.20.46.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jul 2020 20:46:15 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Wolfgang Wallner , Bin Meng , Simon Glass Subject: [PATCH v1 40/54] x86: Sort the MTRR table Date: Sun, 26 Jul 2020 21:45:12 -0600 Message-Id: <20200726214408.v1.40.I889d71c12fa7f745008c16751f9a6d71009242a8@changeid> X-Mailer: git-send-email 2.28.0.rc0.142.g3c755180ce-goog In-Reply-To: <20200727034526.1461514-1-sjg@chromium.org> References: <20200727034526.1461514-1-sjg@chromium.org> MIME-Version: 1.0 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.102.3 at phobos.denx.de X-Virus-Status: Clean At present the MTRR registers are programmed with the list the U-Boot builds up in the same order. In some cases this list may be out of order. It looks better in Linux to have the registers in order, so sort them, Signed-off-by: Simon Glass --- arch/x86/cpu/mtrr.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c index 2468d88a80a..08fa80f8bc7 100644 --- a/arch/x86/cpu/mtrr.c +++ b/arch/x86/cpu/mtrr.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include #include @@ -124,6 +125,16 @@ static int mtrr_copy_to_aps(void) return 0; } +static int h_comp_mtrr(const void *p1, const void *p2) +{ + const struct mtrr_request *req1 = p1; + const struct mtrr_request *req2 = p2; + + s64 diff = req1->start - req2->start; + + return diff < 0 ? -1 : diff > 0 ? 1 : 0; +} + int mtrr_commit(bool do_caches) { struct mtrr_request *req = gd->arch.mtrr_req; @@ -139,6 +150,7 @@ int mtrr_commit(bool do_caches) debug("open\n"); mtrr_open(&state, do_caches); debug("open done\n"); + qsort(req, gd->arch.mtrr_req_count, sizeof(*req), h_comp_mtrr); for (i = 0; i < gd->arch.mtrr_req_count; i++, req++) set_var_mtrr(i, req->type, req->start, req->size);