From patchwork Sun Sep 6 21:43:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1358498 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=h4lNbxpv; 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 4Bl4rf0KMHz9sSn for ; Mon, 7 Sep 2020 07:52:17 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id C71FE824B7; Sun, 6 Sep 2020 23:45: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="h4lNbxpv"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CFD638244F; Sun, 6 Sep 2020 23:44:57 +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-io1-xd41.google.com (mail-io1-xd41.google.com [IPv6:2607:f8b0:4864:20::d41]) (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 28D3382437 for ; Sun, 6 Sep 2020 23:44:55 +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-io1-xd41.google.com with SMTP id b16so12211547ioj.4 for ; Sun, 06 Sep 2020 14:44:55 -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=YblfywE4OHcyl1DFTeiyumd7iCT4l70Un0A0G+tT/m0=; b=h4lNbxpvgUayGbvlVDz4BylLQZED8ddIcNWyvSTQ9jpzz6WGhZc1upzfXm3nwkXH64 ohTQf0bZWpHKV3VTLwm6VEdoOsS8vayAsFrRlU1cfDHrKGb4Ulk/j52h3paqAdzMIGNL wCJ9kW3cRcClzog11MvyznLEpYBxoThfxUfOE= 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=YblfywE4OHcyl1DFTeiyumd7iCT4l70Un0A0G+tT/m0=; b=D7nvtF5Wqa0b+u3z2wUx0hHfLrTG5++jAPuEVk6c/QwiZwUAOaTj8TA4UamYC9RBoD TT3JdPtmVqVatCNMLmnVjpKt5DBoio45JDxLjHlJ/FXBGhd8vkkW4BEldQ+yA/N4dUVK wN4z5koEmnC6xA3g9aa7E/4SWdOTblY7M94WDeqsB/cUeyQZc7OYTNvwtEl1K8YF+Zpv OdnR0j1vM2cY0cpUHhz1j9FigSOVJj+vo6LcDTuCfoEelnfVEVVjI4g5Linqq/f0GQyP 5wkLThNMbDaUiq61PolBWpOzgpjbd8nCSFF6XiFBnJ+xELCg/AHH0Np8XDcUTMVZfKHh KUAQ== X-Gm-Message-State: AOAM533vUVAbSOQljDFFJczffRLHJC7e/WW/wVa4n/U2Fj4c0G8qQsw6 0X3UCdXo1w4FVmOpX6MX0Sne2ehUJkuv9BHA X-Google-Smtp-Source: ABdhPJyBbvEodLVCe+S1EC3kl0+KsIgYHMfmQl/P4G18U4nx7rooRsHOvZPu94FhBcE7AF/I5J0Ppw== X-Received: by 2002:a02:8791:: with SMTP id t17mr16361475jai.89.1599428693748; Sun, 06 Sep 2020 14:44:53 -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 w13sm6232663iox.10.2020.09.06.14.44.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 06 Sep 2020 14:44:53 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Wolfgang Wallner , Bin Meng , Bernhard Messerklinger , Andy Shevchenko , Simon Glass Subject: [PATCH v3 42/57] x86: Sort the MTRR table Date: Sun, 6 Sep 2020 15:43:50 -0600 Message-Id: <20200906154340.v3.42.I889d71c12fa7f745008c16751f9a6d71009242a8@changeid> X-Mailer: git-send-email 2.28.0.526.ge36021eeef-goog In-Reply-To: <20200906214405.71632-1-sjg@chromium.org> References: <20200906214405.71632-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 --- (no changes since v1) 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);