From patchwork Tue Sep 22 18:45:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1369214 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=85.214.62.61; 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=l+YlHwxd; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (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 4Bwr944PSpz9sTS for ; Wed, 23 Sep 2020 04:55:20 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4ECE08269C; Tue, 22 Sep 2020 20:48:58 +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="l+YlHwxd"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3C6518261B; Tue, 22 Sep 2020 20:47:22 +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=-3.5 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-ot1-x342.google.com (mail-ot1-x342.google.com [IPv6:2607:f8b0:4864:20::342]) (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 70F2D823F0 for ; Tue, 22 Sep 2020 20:47:07 +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-ot1-x342.google.com with SMTP id o8so16589027otl.4 for ; Tue, 22 Sep 2020 11:47:07 -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=4DjT/os920d9utGwy2Wf5yBX7tobtblKATJw9ssO0as=; b=l+YlHwxdw+ISHzy/k/3H500rbUS1FKaEnjP2LxnjqsRBl63Iz8nKNiCi8nAQ5ao2pD CoSMYPKHxc3xDtmYrFYNxZ4opml+PS8wzD9f1C2P+8iOaduqF7TcYp1C67yFGX1r8nV6 eGC6ia39KB9qZc9Xi4mopECQbqWpOCaRCxZFc= 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=4DjT/os920d9utGwy2Wf5yBX7tobtblKATJw9ssO0as=; b=e2AiprD+V4Eyy1DiAepP7VhLBEhhEc+GYBhUBoE/o2SN9VAY+yaRthvfAQ/EnlO8dl VogelqRbEIlj0gKfmRJ3CmDgEBZb6tCnlrDCuhqrwM3L9pQclXLezI8EIMeICcK+Dcgk BNin1hN7tdBKUcJB6kuHM3z8BsKAEhP215YFryjM1IzhKa9VCmGHmZWJRY1ENTJVXk/D E5jDYPUW7nLb/iMvHlYt+mffY00RjSKXVnvdUatyKtydCoDSIFEXz3VZN2lzFYttA8/E JvC686DXe6JXwFEi+Y1+wXbHgykQphgScM3r8vLNGuS9FavYuAYZRiYi88ucxfh8PhwJ eFjw== X-Gm-Message-State: AOAM533lD12C90wZMqahSpxFBbqqO73+WSMnCGfzo+oAoTmyxMPvpBEK zXKT7Gf3P68/07u2CIVP7gBPIQeUitM2ZrYS X-Google-Smtp-Source: ABdhPJy9dt04lAOmUXpdj49PI9f4arAzyEwTA51V58FILdZjt+CR8Y9td2QK2NIfiFcd4PEwgtHbEw== X-Received: by 2002:a9d:764c:: with SMTP id o12mr3529516otl.159.1600800425615; Tue, 22 Sep 2020 11:47:05 -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 q24sm7622663oij.19.2020.09.22.11.47.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Sep 2020 11:47:05 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Andy Shevchenko , Wolfgang Wallner , Bin Meng , Bernhard Messerklinger , Simon Glass Subject: [PATCH v4 42/59] x86: Sort the MTRR table Date: Tue, 22 Sep 2020 12:45:27 -0600 Message-Id: <20200922124521.v4.42.I889d71c12fa7f745008c16751f9a6d71009242a8@changeid> X-Mailer: git-send-email 2.28.0.681.g6f77f65b4e-goog In-Reply-To: <20200922184544.2920969-1-sjg@chromium.org> References: <20200922184544.2920969-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);