From patchwork Mon Jan 27 05:06:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1229598 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=fail (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=Vfc88M6n; 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 485dXR5BRQz9sR1 for ; Mon, 27 Jan 2020 16:26:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A681181942; Mon, 27 Jan 2020 06:14:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (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=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="Vfc88M6n"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A3242817F0; Mon, 27 Jan 2020 06:10:34 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-0.1 required=5.0 tests=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-xd43.google.com (mail-io1-xd43.google.com [IPv6:2607:f8b0:4864:20::d43]) (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 45F2B81782 for ; Mon, 27 Jan 2020 06:09:44 +0100 (CET) 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-xd43.google.com with SMTP id s24so7030392iog.5 for ; Sun, 26 Jan 2020 21:09:44 -0800 (PST) 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=gcqYwRkzYNPGqSa4Gevh+IEB46GaKOFitcyqatPBEYU=; b=Vfc88M6nEK5Dx96jKSUVDmXsyKJCJMz6AlIoZJuoxiqHj7H95u7dSLXtrtt2LKxyEo HOTnKRmFJkDf608W8yk9MWvwaYb36B2rvE6RGrIUCvM+6q7PX2HlaohceWhk6u789z2D UQHejf/LdliI2C8t32xHJpx1VzCIG4ZOaQMts= 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=gcqYwRkzYNPGqSa4Gevh+IEB46GaKOFitcyqatPBEYU=; b=O+j1h6G34vbUb0PSRpCeVpa8FhKOhv0SsFOQSpqL4XzdGlFRpk9ynXpmdDZHDmHez+ cVsp3pNbVERafopENQ9W23HcAy0y2Huqmkmbs3y4uNqQkpsBPQ55u6pC+hvxq54vOcR9 Z7n2FqX76EgDFieaAFW9azglHdUjg2QDmsRQlOnoneCCLcSZu+rQziHzqOCFYCeWIw/8 QuD1ju8VcPvEgSrz1DxSb08NWJ8qnlj5e7JIpj4MUzg1uPXHbDiQDONwVvJoIIYoFiHm 0tNMo5SWEDbrUQT5d8Roul7WQebJ8Z5h4YenghmXNcv4T6IRz+QFRY/XXnA8dXRtrJfA 1efQ== X-Gm-Message-State: APjAAAXrkXOtY9w+XTLNym7Hk1c/7nzv39glOO0/I2DTolIsqcY88Xub OtuW6gFVNIBV3IO/xY4Wfku/NwyntNKL3Q== X-Google-Smtp-Source: APXvYqwEzu+bixrW8bvH6EyxoK0QXTthHTangjlsbBr1Le0BmSqpzl+O4QsH99dzDNiSTO6q9F3m/w== X-Received: by 2002:a6b:dd07:: with SMTP id f7mr11069299ioc.3.1580101782986; Sun, 26 Jan 2020 21:09:42 -0800 (PST) Received: from kiwi.bld.corp.google.com ([2620:15c:183:0:8223:87c:a681:66aa]) by smtp.gmail.com with ESMTPSA id h23sm4313195ilf.57.2020.01.26.21.09.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 26 Jan 2020 21:09:42 -0800 (PST) From: Simon Glass To: U-Boot Mailing List Subject: [PATCH 099/108] x86: Sort the MTRR table Date: Sun, 26 Jan 2020 22:06:46 -0700 Message-Id: <20200126220508.99.I889d71c12fa7f745008c16751f9a6d71009242a8@changeid> X-Mailer: git-send-email 2.25.0.341.g760bfbb309-goog In-Reply-To: <20200127050655.170614-1-sjg@chromium.org> References: <20200127050655.170614-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 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.101.4 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 a43cb7fc15..5a4eb648fb 100644 --- a/arch/x86/cpu/mtrr.c +++ b/arch/x86/cpu/mtrr.c @@ -18,6 +18,7 @@ #include #include +#include #include #include #include @@ -61,6 +62,16 @@ static void set_var_mtrr(uint reg, uint type, uint64_t start, uint64_t size) wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask | MTRR_PHYS_MASK_VALID); } +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; @@ -75,6 +86,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);