All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH 16/22] x86: mtrr: Use MP calls to list the MTRRs
Date: Thu, 21 May 2020 20:23:20 -0600	[thread overview]
Message-ID: <20200521202309.16.Iafe7c878fb6d4c465087c6a3beb4d8d292eb2896@changeid> (raw)
In-Reply-To: <20200522022326.238388-1-sjg@chromium.org>

Update the mtrr command to use mp_run_on_cpus() to obtain its information.
Since the selected CPU is the boot CPU this does not change the result,
but it sets the stage for supporting other CPUs.

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

 arch/x86/cpu/mtrr.c         | 11 +++++++++++
 arch/x86/include/asm/mtrr.h | 30 ++++++++++++++++++++++++++++++
 cmd/x86/mtrr.c              | 25 +++++++++++++++++++++----
 3 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/arch/x86/cpu/mtrr.c b/arch/x86/cpu/mtrr.c
index 7ec0733337d..11f3ef08172 100644
--- a/arch/x86/cpu/mtrr.c
+++ b/arch/x86/cpu/mtrr.c
@@ -21,6 +21,7 @@
 #include <log.h>
 #include <asm/cache.h>
 #include <asm/io.h>
+#include <asm/mp.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
 
@@ -63,6 +64,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);
 }
 
+void mtrr_save_all(struct mtrr_info *info)
+{
+	int i;
+
+	for (i = 0; i < MTRR_COUNT; i++) {
+		info->mtrr[i].base = native_read_msr(MTRR_PHYS_BASE_MSR(i));
+		info->mtrr[i].mask = native_read_msr(MTRR_PHYS_MASK_MSR(i));
+	}
+}
+
 int mtrr_commit(bool do_caches)
 {
 	struct mtrr_request *req = gd->arch.mtrr_req;
diff --git a/arch/x86/include/asm/mtrr.h b/arch/x86/include/asm/mtrr.h
index 212a699c1b2..476d6f8a9cf 100644
--- a/arch/x86/include/asm/mtrr.h
+++ b/arch/x86/include/asm/mtrr.h
@@ -70,6 +70,26 @@ struct mtrr_state {
 	bool enable_cache;
 };
 
+/**
+ * struct mtrr - Information about a single MTRR
+ *
+ * @base: Base address and MTRR_BASE_TYPE_MASK
+ * @mask: Mask and MTRR_PHYS_MASK_VALID
+ */
+struct mtrr {
+	u64 base;
+	u64 mask;
+};
+
+/**
+ * struct mtrr_info - Information about all MTRRs
+ *
+ * @mtrr: Information about each mtrr
+ */
+struct mtrr_info {
+	struct mtrr mtrr[MTRR_COUNT];
+};
+
 /**
  * mtrr_open() - Prepare to adjust MTRRs
  *
@@ -129,6 +149,16 @@ int mtrr_commit(bool do_caches);
  */
 int mtrr_set_next_var(uint type, uint64_t base, uint64_t size);
 
+/**
+ * mtrr_save_all() - Save all the MTRRs
+ *
+ * This writes all MTRRs from the boot CPU into a struct so they can be loaded
+ * onto other CPUs
+ *
+ * @info: Place to put the MTRR info
+ */
+void mtrr_save_all(struct mtrr_info *info);
+
 #endif
 
 #if ((CONFIG_XIP_ROM_SIZE & (CONFIG_XIP_ROM_SIZE - 1)) != 0)
diff --git a/cmd/x86/mtrr.c b/cmd/x86/mtrr.c
index 5d25c5802af..01197044452 100644
--- a/cmd/x86/mtrr.c
+++ b/cmd/x86/mtrr.c
@@ -5,7 +5,9 @@
 
 #include <common.h>
 #include <command.h>
+#include <log.h>
 #include <asm/msr.h>
+#include <asm/mp.h>
 #include <asm/mtrr.h>
 
 static const char *const mtrr_type_name[MTRR_TYPE_COUNT] = {
@@ -18,19 +20,32 @@ static const char *const mtrr_type_name[MTRR_TYPE_COUNT] = {
 	"Back",
 };
 
-static int do_mtrr_list(void)
+static void save_mtrrs(void *arg)
 {
+	struct mtrr_info *info = arg;
+
+	mtrr_save_all(info);
+}
+
+static int do_mtrr_list(int cpu_select)
+{
+	struct mtrr_info info;
+	int ret;
 	int i;
 
 	printf("Reg Valid Write-type   %-16s %-16s %-16s\n", "Base   ||",
 	       "Mask   ||", "Size   ||");
+	memset(&info, '\0', sizeof(info));
+	ret = mp_run_on_cpus(cpu_select, save_mtrrs, &info);
+	if (ret)
+		return log_msg_ret("run", ret);
 	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));
+		base = info.mtrr[i].base;
+		mask = info.mtrr[i].mask;
 		size = ~mask & ((1ULL << CONFIG_CPU_ADDR_BITS) - 1);
 		size |= (1 << 12) - 1;
 		size += 1;
@@ -102,11 +117,13 @@ static int do_mtrr(struct cmd_tbl *cmdtp, int flag, int argc,
 		   char *const argv[])
 {
 	const char *cmd;
+	int cpu_select;
 	uint reg;
 
+	cpu_select = MP_SELECT_BSP;
 	cmd = argv[1];
 	if (argc < 2 || *cmd == 'l')
-		return do_mtrr_list();
+		return do_mtrr_list(cpu_select);
 	argc -= 2;
 	argv += 2;
 	if (argc <= 0)
-- 
2.27.0.rc0.183.gde8f92d652-goog

  parent reply	other threads:[~2020-05-22  2:23 UTC|newest]

Thread overview: 47+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-22  2:23 [PATCH 00/22] x86: Enhance MTRR functionality to support multiple CPUs Simon Glass
2020-05-22  2:23 ` [PATCH 01/22] x86: mp_init: Switch to livetree Simon Glass
2020-06-10 13:25   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 02/22] x86: Move MP code into mp_init Simon Glass
2020-06-10 13:25   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 03/22] x86: mp_init: Avoid declarations in header files Simon Glass
2020-06-10 13:25   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 04/22] x86: mp_init: Switch parameter names in start_aps() Simon Glass
2020-06-10 13:25   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 05/22] x86: mp_init: Drop the num_cpus static variable Simon Glass
2020-06-10 13:25   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 06/22] x86: mtrr: Fix 'ensable' typo Simon Glass
2020-06-10 13:26   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 07/22] x86: mp_init: Set up the CPU numbers at the start Simon Glass
2020-06-10 13:26   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 08/22] x86: mp_init: Adjust bsp_init() to return more information Simon Glass
2020-06-10 13:26   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 09/22] x86: cpu: Remove unnecessary #ifdefs Simon Glass
2020-06-10 13:26   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 10/22] x86: mp: Support APs waiting for instructions Simon Glass
2020-06-10 13:27   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 11/22] global_data: Add a generic global_data flag for SMP state Simon Glass
2020-06-10 13:27   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 12/22] x86: Set the SMP flag when MP init is complete Simon Glass
2020-06-10 13:27   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 13/22] x86: mp: Allow running functions on multiple CPUs Simon Glass
2020-06-10 13:27   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 14/22] x86: mp: Park CPUs before running the OS Simon Glass
2020-06-10 13:27   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 15/22] x86: mp: Add iterators for CPUs Simon Glass
2020-06-10 13:27   ` Wolfgang Wallner
2020-05-22  2:23 ` Simon Glass [this message]
2020-06-10 13:28   ` [PATCH 16/22] x86: mtrr: Use MP calls to list the MTRRs Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 17/22] x86: mtrr: Update MTRRs on all CPUs Simon Glass
2020-06-10 13:28   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 18/22] x86: mtrr: Add support for writing to MTRRs on any CPU Simon Glass
2020-06-10 13:28   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 19/22] x86: mtrr: Update the command to use the new mtrr calls Simon Glass
2020-06-10 13:28   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 20/22] x86: mtrr: Restructure so command execution is in one place Simon Glass
2020-06-10 13:28   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 21/22] x86: mtrr: Update 'mtrr' to allow setting MTRRs on any CPU Simon Glass
2020-06-10 13:29   ` Wolfgang Wallner
2020-05-22  2:23 ` [PATCH 22/22] x86: mtrr: Enhance 'mtrr' command to list " Simon Glass
2020-06-10 13:29   ` Wolfgang Wallner
2020-05-22 10:54 ` [PATCH 00/22] x86: Enhance MTRR functionality to support multiple CPUs Andy Shevchenko
2020-05-22 13:42   ` 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=20200521202309.16.Iafe7c878fb6d4c465087c6a3beb4d8d292eb2896@changeid \
    --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.