All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH v1 34/43] x86: apl: Fix save/restore of ITSS priorities
Date: Sun, 14 Jun 2020 21:57:29 -0600	[thread overview]
Message-ID: <20200614215726.v1.34.I47b041ba995bc87537c2b8b03e5c5dbee96ad725@changeid> (raw)
In-Reply-To: <20200615035738.248710-1-sjg@chromium.org>

The FSP-S changes the ITSS priorities. The code that tries to save it
before running FSP-S and restore it afterwards does not work as U-Boot
relocates in between the save and restore. This means that the driver
data saved before relocation is lost and the new driver just sees zeroes.

Fix this by allocating space in the relocated memory for the ITSS data.
Save it there and access it from the driver after relocation.

This fixes interrupt handling on coral.

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

 arch/x86/cpu/apollolake/fsp_s.c    | 11 +++++------
 arch/x86/cpu/cpu.c                 | 13 +++++++++++++
 arch/x86/cpu/intel_common/itss.c   | 25 +++++++++++++++++++++++--
 arch/x86/include/asm/global_data.h |  1 +
 arch/x86/include/asm/itss.h        |  2 +-
 drivers/misc/irq-uclass.c          |  2 +-
 6 files changed, 44 insertions(+), 10 deletions(-)

diff --git a/arch/x86/cpu/apollolake/fsp_s.c b/arch/x86/cpu/apollolake/fsp_s.c
index 3a54297a28..e54b0ac104 100644
--- a/arch/x86/cpu/apollolake/fsp_s.c
+++ b/arch/x86/cpu/apollolake/fsp_s.c
@@ -160,11 +160,6 @@ int arch_fsps_preinit(void)
 	ret = irq_first_device_type(X86_IRQT_ITSS, &itss);
 	if (ret)
 		return log_msg_ret("no itss", ret);
-	/*
-	 * Snapshot the current GPIO IRQ polarities. FSP is setting a default
-	 * policy that doesn't honour boards' requirements
-	 */
-	irq_snapshot_polarities(itss);
 
 	/*
 	 * Clear the GPI interrupt status and enable registers. These
@@ -203,7 +198,11 @@ int arch_fsp_init_r(void)
 	ret = irq_first_device_type(X86_IRQT_ITSS, &itss);
 	if (ret)
 		return log_msg_ret("no itss", ret);
-	/* Restore GPIO IRQ polarities back to previous settings */
+
+	/*
+	 * Restore GPIO IRQ polarities back to previous settings. This was
+	 * stored in reserve_arch() - see X86_IRQT_ITSS
+	 */
 	irq_restore_polarities(itss);
 
 	/* soc_init() */
diff --git a/arch/x86/cpu/cpu.c b/arch/x86/cpu/cpu.c
index baa7dae172..9bc243ebc8 100644
--- a/arch/x86/cpu/cpu.c
+++ b/arch/x86/cpu/cpu.c
@@ -25,6 +25,7 @@
 #include <dm.h>
 #include <errno.h>
 #include <init.h>
+#include <irq.h>
 #include <log.h>
 #include <malloc.h>
 #include <syscon.h>
@@ -274,6 +275,9 @@ int cpu_init_r(void)
 #ifndef CONFIG_EFI_STUB
 int reserve_arch(void)
 {
+	struct udevice *itss;
+	int ret;
+
 	if (IS_ENABLED(CONFIG_ENABLE_MRC_CACHE))
 		mrccache_reserve();
 
@@ -291,6 +295,15 @@ int reserve_arch(void)
 			fsp_save_s3_stack();
 		}
 	}
+	ret = irq_first_device_type(X86_IRQT_ITSS, &itss);
+	if (!ret) {
+		/*
+		 * Snapshot the current GPIO IRQ polarities. FSP-S is about to
+		 * run and will set a default policy that doesn't honour boards'
+		 * requirements
+		 */
+		irq_snapshot_polarities(itss);
+	}
 
 	return 0;
 }
diff --git a/arch/x86/cpu/intel_common/itss.c b/arch/x86/cpu/intel_common/itss.c
index 963afa8f5b..fe84ebe29f 100644
--- a/arch/x86/cpu/intel_common/itss.c
+++ b/arch/x86/cpu/intel_common/itss.c
@@ -65,14 +65,23 @@ static int snapshot_polarities(struct udevice *dev)
 	int i;
 
 	reg_start = start / IRQS_PER_IPC;
-	reg_end = (end + IRQS_PER_IPC - 1) / IRQS_PER_IPC;
+	reg_end = DIV_ROUND_UP(end, IRQS_PER_IPC);
 
+	log_info("ITSS IRQ Polarities snapshot %p\n", priv->irq_snapshot);
 	for (i = reg_start; i < reg_end; i++) {
 		uint reg = PCR_ITSS_IPC0_CONF + sizeof(u32) * i;
 
 		priv->irq_snapshot[i] = pcr_read32(dev, reg);
+		log_debug("   - %d, reg %x: irq_snapshot[i] %x\n", i, reg,
+			  priv->irq_snapshot[i]);
 	}
 
+	/* Save the snapshot for use after relocation */
+	gd->start_addr_sp -= sizeof(*priv);
+	gd->start_addr_sp &= ~0xf;
+	gd->arch.itss_priv = (void *)gd->start_addr_sp;
+	memcpy(gd->arch.itss_priv, priv, sizeof(*priv));
+
 	return 0;
 }
 
@@ -91,16 +100,26 @@ static void show_polarities(struct udevice *dev, const char *msg)
 static int restore_polarities(struct udevice *dev)
 {
 	struct itss_priv *priv = dev_get_priv(dev);
+	struct itss_priv *old_priv;
 	const int start = GPIO_IRQ_START;
 	const int end = GPIO_IRQ_END;
 	int reg_start;
 	int reg_end;
 	int i;
 
+	/* Get the snapshot which was stored by the pre-reloc device */
+	old_priv = gd->arch.itss_priv;
+	if (!old_priv)
+		return log_msg_ret("priv", -EFAULT);
+	memcpy(priv->irq_snapshot, old_priv->irq_snapshot,
+	       sizeof(priv->irq_snapshot));
+
 	show_polarities(dev, "Before");
+	log_info("priv->irq_snapshot %p\n", priv->irq_snapshot);
 
 	reg_start = start / IRQS_PER_IPC;
-	reg_end = (end + IRQS_PER_IPC - 1) / IRQS_PER_IPC;
+	reg_end = DIV_ROUND_UP(end, IRQS_PER_IPC);
+
 
 	for (i = reg_start; i < reg_end; i++) {
 		u32 mask;
@@ -125,6 +144,8 @@ static int restore_polarities(struct udevice *dev)
 		mask &= ~((1U << irq_start) - 1);
 
 		reg = PCR_ITSS_IPC0_CONF + sizeof(u32) * i;
+		log_debug("   - %d, reg %x: mask %x, irq_snapshot[i] %x\n",
+			  i, reg, mask, priv->irq_snapshot[i]);
 		pcr_clrsetbits32(dev, reg, mask, mask & priv->irq_snapshot[i]);
 	}
 
diff --git a/arch/x86/include/asm/global_data.h b/arch/x86/include/asm/global_data.h
index 0e64c8a46d..5bc251c0dd 100644
--- a/arch/x86/include/asm/global_data.h
+++ b/arch/x86/include/asm/global_data.h
@@ -121,6 +121,7 @@ struct arch_global_data {
 #ifdef CONFIG_FSP_VERSION2
 	struct fsp_header *fsp_s_hdr;	/* Pointer to FSP-S header */
 #endif
+	void *itss_priv;		/* Private ITSS data pointer */
 	ulong acpi_start;		/* Start address of ACPI tables */
 };
 
diff --git a/arch/x86/include/asm/itss.h b/arch/x86/include/asm/itss.h
index c75d8fe8c2..f7d3240384 100644
--- a/arch/x86/include/asm/itss.h
+++ b/arch/x86/include/asm/itss.h
@@ -16,7 +16,7 @@
 
 #define ITSS_MAX_IRQ	119
 #define IRQS_PER_IPC	32
-#define NUM_IPC_REGS	((ITSS_MAX_IRQ + IRQS_PER_IPC - 1) / IRQS_PER_IPC)
+#define NUM_IPC_REGS	DIV_ROUND_UP(ITSS_MAX_IRQ, IRQS_PER_IPC)
 
 /* Max PXRC registers in ITSS */
 #define MAX_PXRC_CONFIG	(PCR_ITSS_PIRQH_ROUT - PCR_ITSS_PIRQA_ROUT + 1)
diff --git a/drivers/misc/irq-uclass.c b/drivers/misc/irq-uclass.c
index 98bc79eaba..6b32b451a6 100644
--- a/drivers/misc/irq-uclass.c
+++ b/drivers/misc/irq-uclass.c
@@ -170,7 +170,7 @@ int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)
 
 	ret = uclass_first_device_drvdata(UCLASS_IRQ, type, devp);
 	if (ret)
-		return log_msg_ret("find", ret);
+		return ret;
 
 	return 0;
 }
-- 
2.27.0.290.gba653c62da-goog

  parent reply	other threads:[~2020-06-15  3:57 UTC|newest]

Thread overview: 143+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-15  3:56 [PATCH v1 00/43] x86: Programmatic generation of ACPI tables (Part C) Simon Glass
2020-06-15  3:56 ` [PATCH v1 01/43] binman: Allow setting the ROM offset Simon Glass
2020-06-15  3:56 ` [PATCH v1 02/43] binman: Refactor binman_entry_find() to allow other nodes Simon Glass
2020-06-30  2:33   ` Bin Meng
2020-07-08  2:22     ` Simon Glass
2020-07-08  4:07       ` Bin Meng
2020-07-08 14:40         ` Tom Rini
2020-06-15  3:56 ` [PATCH v1 03/43] binman: Add way to locate an entry in memory Simon Glass
2020-06-15  3:56 ` [PATCH v1 04/43] acpi: Allow creating the GNVS to fail Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  2:36   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 05/43] dtoc: Support ACPI paths in of-platdata Simon Glass
2020-06-15  3:57 ` [PATCH v1 06/43] dm: core: Add a way of overriding the ACPI device path Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 07/43] dm: acpi: Add support for the NHLT table Simon Glass
2020-06-25 13:35   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-07-03  0:46     ` Simon Glass
2020-07-03  0:54       ` Bin Meng
2020-07-03  3:50         ` Simon Glass
2020-07-03  4:33           ` Bin Meng
2020-07-06 19:21             ` Simon Glass
2020-07-07  0:22               ` Bin Meng
2020-07-08  3:25                 ` Simon Glass
2020-07-12 19:37                   ` Simon Glass
2020-07-13  6:09                     ` Bin Meng
2020-07-14 13:31                       ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 08/43] acpi: Export functions to write sized values Simon Glass
2020-06-25 13:35   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-07-08  2:23     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 09/43] acpi: Support generation of a scope Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 10/43] acpi: Support generation of a generic register Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-30  2:49   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 11/43] acpi: mmc: Generate ACPI info for the PCI SD Card Simon Glass
2020-06-25 13:35   ` Wolfgang Wallner
2020-06-30  5:57   ` Bin Meng
2020-07-08  2:23     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 12/43] x86: Add bindings for NHLT Simon Glass
2020-06-25 13:36   ` Wolfgang Wallner
2020-06-30  5:57   ` Bin Meng
2020-07-08  3:32     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 13/43] acpi: Support generation of a device Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-30  5:58   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 14/43] acpi: Support writing named values Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-30  5:58   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 15/43] sound: Add an ACPI driver for Dialog Semicondutor da7219 Simon Glass
2020-06-30  6:06   ` Bin Meng
2020-07-08  3:32     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 16/43] sound: Add an ACPI driver for Maxim MAX98357ac Simon Glass
2020-06-15  3:57 ` [PATCH v1 17/43] x86: pinctrl: Add a way to get the pinctrl reg address Simon Glass
2020-06-25 13:36   ` Wolfgang Wallner
2020-06-30  6:42   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 18/43] x86: pinctrl: Update comment for intel_pinctrl_get_pad() Simon Glass
2020-06-30  6:42   ` Bin Meng
2020-07-03  0:46     ` Simon Glass
2020-07-03  0:58       ` Bin Meng
2020-07-06 18:42         ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 19/43] x86: pinctrl: Add multi-ACPI control Simon Glass
2020-06-30  6:42   ` Bin Meng
2020-07-02  8:11   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 20/43] x86: pinctrl: Set up itss in the probe() method Simon Glass
2020-06-30  6:42   ` Bin Meng
2020-07-03  0:46     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 21/43] x86: pinctrl: Drop the acpi_name member Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 22/43] x86: Add support for building up an NHLT structure Simon Glass
2020-06-15  3:57 ` [PATCH v1 23/43] x86: Add error checking for csrt table generation Simon Glass
2020-06-30  7:47   ` Bin Meng
2020-07-02  8:11   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 24/43] x86: apl: Use memory-mapped access for VBT Simon Glass
2020-06-30  7:47   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 25/43] x86: gpio: Add support for obtaining ACPI info for a GPIO Simon Glass
2020-06-30  7:47   ` Bin Meng
2020-07-08  3:32     ` Simon Glass
2020-07-08 11:06       ` Wolfgang Wallner
2020-08-29 21:20         ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 26/43] i2c: designware_i2c: Add a little more debugging Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-07-03  6:05   ` Heiko Schocher
2020-06-15  3:57 ` [PATCH v1 27/43] i2c: Add log_ret() on error Simon Glass
2020-06-25 12:45   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-07-03  6:10   ` Heiko Schocher
2020-06-15  3:57 ` [PATCH v1 28/43] i2c: designware_i2c: Support ACPI table generation Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-07-08  3:33     ` Simon Glass
2020-07-03  6:10   ` Heiko Schocher
2020-06-15  3:57 ` [PATCH v1 29/43] p2sb: Add a method to hide the bus Simon Glass
2020-06-23 10:49   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 30/43] x86: apl: Support set_hide() in p2sb driver Simon Glass
2020-06-23 10:49   ` Wolfgang Wallner
2020-06-30  7:54   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 31/43] x86: apl: Hide the p2sb on exit from U-Boot Simon Glass
2020-06-23 10:49   ` Wolfgang Wallner
2020-06-30  8:27   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 32/43] pmc: Move common registers to the header file Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:27   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 33/43] x86: irq: Support flags for acpi_gpe Simon Glass
2020-06-30  8:27   ` Bin Meng
2020-07-01 15:15   ` Wolfgang Wallner
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` Simon Glass [this message]
2020-06-30  8:27   ` [PATCH v1 34/43] x86: apl: Fix save/restore of ITSS priorities Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 35/43] x86: Add debugging to table writing Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:27   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 36/43] x86: apl: Adjust FSP-M code to avoid hard-coded address Simon Glass
2020-06-25 10:55   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 37/43] x86: Store the coreboot table address in global_data Simon Glass
2020-06-30  8:40   ` Bin Meng
2020-07-01 15:16   ` Wolfgang Wallner
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 38/43] x86: mp: Allow use of mp_run_on_cpus() without MP Simon Glass
2020-06-30  8:40   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 39/43] x86: Update the comment about booting for FSP2 Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:40   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 40/43] x86: Drop setup_pcat_compatibility() Simon Glass
2020-06-30  8:40   ` Bin Meng
2020-07-08  3:33     ` Simon Glass
2020-06-15  3:57 ` [PATCH v1 41/43] x86: acpi: Correct the version of the MADT Simon Glass
2020-06-30  8:42   ` Bin Meng
2020-07-01 15:16   ` Wolfgang Wallner
2020-06-15  3:57 ` [PATCH v1 42/43] x86: Rename board_final_cleanup() to board_final_init() Simon Glass
2020-06-25 12:46   ` Wolfgang Wallner
2020-06-30  8:42   ` Bin Meng
2020-06-15  3:57 ` [PATCH v1 43/43] acpi: Enable ACPI table generation by default on x86 Simon Glass
2020-06-30  8:42   ` Bin Meng
2020-07-02  8:11 ` [PATCH v1 22/43] x86: Add support for building up an NHLT structure Wolfgang Wallner
2020-07-08  3:32   ` Simon Glass
2020-07-08 11:05     ` Wolfgang Wallner

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=20200614215726.v1.34.I47b041ba995bc87537c2b8b03e5c5dbee96ad725@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.