All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH v2 22/22] x86: Add an 'mtrr' command to list and adjust MTRRs
Date: Thu,  1 Jan 2015 16:18:15 -0700	[thread overview]
Message-ID: <1420154295-16633-23-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1420154295-16633-1-git-send-email-sjg@chromium.org>

It is useful to be able to see the MTRR setup in U-Boot. Add a command
to list the state of the variable MTRR registers and allow them to be
changed.

Update the documentation to list some of the available commands.

This does not support fixed MTRRs as yet.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

Changes in v2:
- Move cmd_mtrr to arch/x86/lib
- Correct 'platform' typo

 arch/x86/lib/Makefile   |   1 +
 arch/x86/lib/cmd_mtrr.c | 138 ++++++++++++++++++++++++++++++++++++++++++++++++
 doc/README.x86          |  18 ++++++-
 3 files changed, 156 insertions(+), 1 deletion(-)
 create mode 100644 arch/x86/lib/cmd_mtrr.c

diff --git a/arch/x86/lib/Makefile b/arch/x86/lib/Makefile
index 73262d7..32d7b98 100644
--- a/arch/x86/lib/Makefile
+++ b/arch/x86/lib/Makefile
@@ -14,6 +14,7 @@ obj-$(CONFIG_HAVE_FSP) += cmd_hob.o
 obj-y	+= gcc.o
 obj-y	+= init_helpers.o
 obj-y	+= interrupts.o
+obj-y += cmd_mtrr.o
 obj-$(CONFIG_SYS_PCAT_INTERRUPTS) += pcat_interrupts.o
 obj-$(CONFIG_SYS_PCAT_TIMER) += pcat_timer.o
 obj-$(CONFIG_PCI) += pci_type1.o
diff --git a/arch/x86/lib/cmd_mtrr.c b/arch/x86/lib/cmd_mtrr.c
new file mode 100644
index 0000000..7e0506b
--- /dev/null
+++ b/arch/x86/lib/cmd_mtrr.c
@@ -0,0 +1,138 @@
+/*
+ * (C) Copyright 2014 Google, Inc
+ *
+ * SPDX-License-Identifier:	GPL-2.0+
+ */
+
+#include <common.h>
+#include <asm/msr.h>
+#include <asm/mtrr.h>
+
+static const char *const mtrr_type_name[MTRR_TYPE_COUNT] = {
+	"Uncacheable",
+	"Combine",
+	"2",
+	"3",
+	"Through",
+	"Protect",
+	"Back",
+};
+
+static int do_mtrr_list(void)
+{
+	int i;
+
+	printf("Reg Valid Write-type   %-16s %-16s %-16s\n", "Base   ||",
+	       "Mask   ||", "Size   ||");
+	for (i = 0; i < MTRR_COUNT; i++) {
+		const char *type = "Invalid";
+		uint64_t base, mask, size;
+		bool valid;
+
+		base = native_read_msr(MTRR_PHYS_BASE_MSR(i));
+		mask = native_read_msr(MTRR_PHYS_MASK_MSR(i));
+		size = ~mask & ((1ULL << CONFIG_CPU_ADDR_BITS) - 1);
+		size |= (1 << 12) - 1;
+		size += 1;
+		valid = mask & MTRR_PHYS_MASK_VALID;
+		type = mtrr_type_name[base & MTRR_BASE_TYPE_MASK];
+		printf("%d   %-5s %-12s %016llx %016llx %016llx\n", i,
+		       valid ? "Y" : "N", type, base, mask, size);
+	}
+
+	return 0;
+}
+
+static int do_mtrr_set(uint reg, int argc, char * const argv[])
+{
+	const char *typename = argv[0];
+	struct mtrr_state state;
+	uint32_t start, size;
+	uint64_t base, mask;
+	int i, type = -1;
+	bool valid;
+
+	if (argc < 3)
+		return CMD_RET_USAGE;
+	for (i = 0; i < MTRR_TYPE_COUNT; i++) {
+		if (*typename == *mtrr_type_name[i])
+			type = i;
+	}
+	if (type == -1) {
+		printf("Invalid type name %s\n", typename);
+		return CMD_RET_USAGE;
+	}
+	start = simple_strtoul(argv[1], NULL, 16);
+	size = simple_strtoul(argv[2], NULL, 16);
+
+	base = start | type;
+	valid = native_read_msr(MTRR_PHYS_MASK_MSR(reg)) & MTRR_PHYS_MASK_VALID;
+	mask = ~((uint64_t)size - 1);
+	mask &= (1ULL << CONFIG_CPU_ADDR_BITS) - 1;
+	if (valid)
+		mask |= MTRR_PHYS_MASK_VALID;
+
+	printf("base=%llx, mask=%llx\n", base, mask);
+	mtrr_open(&state);
+	wrmsrl(MTRR_PHYS_BASE_MSR(reg), base);
+	wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask);
+	mtrr_close(&state);
+
+	return 0;
+}
+
+static int mtrr_set_valid(int reg, bool valid)
+{
+	struct mtrr_state state;
+	uint64_t mask;
+
+	mtrr_open(&state);
+	mask = native_read_msr(MTRR_PHYS_MASK_MSR(reg));
+	if (valid)
+		mask |= MTRR_PHYS_MASK_VALID;
+	else
+		mask &= ~MTRR_PHYS_MASK_VALID;
+	wrmsrl(MTRR_PHYS_MASK_MSR(reg), mask);
+	mtrr_close(&state);
+
+	return 0;
+}
+
+static int do_mtrr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
+{
+	const char *cmd;
+	uint reg;
+
+	cmd = argv[1];
+	if (argc < 2 || *cmd == 'l')
+		return do_mtrr_list();
+	argc -= 2;
+	argv += 2;
+	if (argc <= 0)
+		return CMD_RET_USAGE;
+	reg = simple_strtoul(argv[0], NULL, 16);
+	if (reg >= MTRR_COUNT) {
+		printf("Invalid register number\n");
+		return CMD_RET_USAGE;
+	}
+	if (*cmd == 'e')
+		return mtrr_set_valid(reg, true);
+	else if (*cmd == 'd')
+		return mtrr_set_valid(reg, false);
+	else if (*cmd == 's')
+		return do_mtrr_set(reg, argc - 1, argv + 1);
+	else
+		return CMD_RET_USAGE;
+
+	return 0;
+}
+
+U_BOOT_CMD(
+	mtrr,	6,	1,	do_mtrr,
+	"Use x86 memory type range registers (32-bit only)",
+	"[list]        - list current registers\n"
+	"set <reg> <type> <start> <size>   - set a register\n"
+	"\t<type> is Uncacheable, Combine, Through, Protect, Back\n"
+	"disable <reg>      - disable a register\n"
+	"ensable <reg>      - enable a register"
+);
diff --git a/doc/README.x86 b/doc/README.x86
index 5fab044..b474161 100644
--- a/doc/README.x86
+++ b/doc/README.x86
@@ -110,9 +110,25 @@ be turned on. Not every device on the board is configured via devie tree, but
 more and more devices will be added as time goes by. Check out the directory
 arch/x86/dts/ for these device tree source files.
 
+Useful Commands
+---------------
+
+In keeping with the U-Boot philosophy of providing functions to check and
+adjust internal settings, there are several x86-specific commands that may be
+useful:
+
+hob  - Display information about Firmware Support Package (FSP) Hand-off
+	 Block. This is only available on platforms which use FSP, mostly
+	 Atom.
+iod  - Display I/O memory
+iow  - Write I/O memory
+mtrr - List and set the Memory Type Range Registers (MTRR). These are used to
+	 tell the CPU whether memory is cacheable and if so the cache write
+	 mode to use. U-Boot sets up some reasonable values but you can
+	 adjust then with this command.
+
 TODO List
 ---------
-- MTRR support (for performance)
 - Audio
 - Chrome OS verified boot
 - SMI and ACPI support, to provide platform info and facilities to Linux
-- 
2.2.0.rc0.207.ga3a616c

  parent reply	other threads:[~2015-01-01 23:18 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-01 23:17 [U-Boot] [PATCH v2 0/22] x86: Add support for MTRRs Simon Glass
2015-01-01 23:17 ` [U-Boot] [PATCH v2 01/22] x86: Correct XIP_ROM_SIZE Simon Glass
2015-01-05 17:39   ` Simon Glass
2015-01-01 23:17 ` [U-Boot] [PATCH v2 02/22] x86: Drop RAMTOP Kconfig Simon Glass
2015-01-04  2:26   ` Bin Meng
2015-01-05 17:39     ` Simon Glass
2015-01-01 23:17 ` [U-Boot] [PATCH v2 03/22] x86: Correct ifdtool microcode calculation Simon Glass
2015-01-05 17:39   ` Simon Glass
2015-01-01 23:17 ` [U-Boot] [PATCH v2 04/22] x86: video: Add support for CONFIG_CONSOLE_SCROLL_LINES Simon Glass
2015-01-20  0:33   ` Simon Glass
2015-01-20  7:44     ` Anatolij Gustschin
2015-01-23 23:55       ` Simon Glass
2015-01-20  7:42   ` Anatolij Gustschin
2015-01-01 23:17 ` [U-Boot] [PATCH v2 05/22] x86: config: Always scroll the display by 5 lines, for speed Simon Glass
2015-01-23 23:55   ` Simon Glass
2015-01-01 23:17 ` [U-Boot] [PATCH v2 06/22] x86: video: Add a debug() to display the frame buffer address Simon Glass
2015-01-05 17:39   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 07/22] x86: pci: Don't return a vesa mode when there is not video Simon Glass
2015-01-05 17:39   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 08/22] x86: video: Add debug option to time the BIOS copy Simon Glass
2015-01-05 17:39   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 09/22] x86: ivybridge: Only run the Video BIOS when video is enabled Simon Glass
2015-01-04  2:31   ` Bin Meng
2015-01-05 17:40     ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 10/22] x86: Use cache, don't clear the display in video BIOS Simon Glass
2015-01-05 17:40   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 11/22] x86: Tidy up VESA mode numbers Simon Glass
2015-01-05 17:40   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 12/22] x86: pci: Display vesa modes in hex Simon Glass
2015-01-05 17:40   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 13/22] x86: ivybridge: Drop support for ROM caching Simon Glass
2015-01-05 17:40   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 14/22] x86: Add support for MTRRs Simon Glass
2015-01-05 17:41   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 15/22] x86: ivybridge: Set up an MTRR for the video frame buffer Simon Glass
2015-01-04  3:18   ` Bin Meng
2015-01-04  3:20     ` Simon Glass
2015-01-04  3:28       ` Bin Meng
2015-01-05 17:41         ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 16/22] x86: board_f: Adjust x86 boot order for performance Simon Glass
2015-01-05 17:41   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 17/22] x86: ivybridge: Request MTRRs for DRAM regions Simon Glass
2015-01-05 17:41   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 18/22] x86: Commit the current MTRRs before relocation Simon Glass
2015-01-05 17:41   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 19/22] x86: ivybridge: Add a way to turn off the CAR Simon Glass
2015-01-05 17:41   ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 20/22] x86: Disable CAR before relocation on platforms that need it Simon Glass
2015-01-04  3:53   ` Bin Meng
2015-01-05 17:41     ` Simon Glass
2015-01-01 23:18 ` [U-Boot] [PATCH v2 21/22] x86: ivybridge: Update microcode early in boot Simon Glass
2015-01-05 17:41   ` Simon Glass
2015-01-01 23:18 ` Simon Glass [this message]
2015-01-04  4:13   ` [U-Boot] [PATCH v2 22/22] x86: Add an 'mtrr' command to list and adjust MTRRs Bin Meng
2015-01-05 17:41     ` Simon Glass

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420154295-16633-23-git-send-email-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.