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 v4 010/100] x86: spi: Add helper functions for Intel Fast SPI
Date: Thu, 21 Nov 2019 21:17:35 -0700	[thread overview]
Message-ID: <20191122041905.224686-8-sjg@chromium.org> (raw)
In-Reply-To: <20191122041905.224686-1-sjg@chromium.org>

Most x86 CPUs use a mechanism where the SPI flash is mapped into the very
top of 32-bit address space, so that it can be executed in place and read
simply by copying from memory. For an 8MB ROM the mapping starts at
0xff800000.

However some recent Intel CPUs do not use a simple 1:1 memory map. Instead
the map starts at a different address and not all of the SPI flash is
accessible through the map. This 'Fast SPI' feature requires that U-Boot
check the location of the map. It is also possible (optionally) to read
from the SPI flash using a driver.

Add support for booting from Fast SPI. The memory-mapped version is used
by both TPL and SPL on Apollo Lake.

In respect of a SPI flash driver, the actual SPI driver is ich.c - this
just adds a few helper functions and definitions.

This is used by Apollo Lake.

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

Changes in v4: None
Changes in v3:
- Add support for of-platdata for TPL
- Add the missing header file
- Change Fast-SPI driver into a helper file used by ICH SPI
- Don't include write() and erase() in TPL
- Drop 'a4' comment for register offset
- Merge in patch "x86: Add support for booting from Fast SPI"
- Reorder file so that write() and erase() are together
- Use pci_get_devfn()

Changes in v2: None

 arch/x86/cpu/intel_common/Makefile   |  1 +
 arch/x86/cpu/intel_common/fast_spi.c | 73 ++++++++++++++++++++++++++++
 arch/x86/include/asm/fast_spi.h      | 68 ++++++++++++++++++++++++++
 arch/x86/include/asm/spl.h           |  1 +
 4 files changed, 143 insertions(+)
 create mode 100644 arch/x86/cpu/intel_common/fast_spi.c
 create mode 100644 arch/x86/include/asm/fast_spi.h

diff --git a/arch/x86/cpu/intel_common/Makefile b/arch/x86/cpu/intel_common/Makefile
index 07f27c29ec..dfbc29f047 100644
--- a/arch/x86/cpu/intel_common/Makefile
+++ b/arch/x86/cpu/intel_common/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += report_platform.o
 obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += mrc.o
 endif
 obj-y += cpu.o
+obj-y += fast_spi.o
 obj-y += lpc.o
 ifndef CONFIG_TARGET_EFI_APP
 obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += microcode.o
diff --git a/arch/x86/cpu/intel_common/fast_spi.c b/arch/x86/cpu/intel_common/fast_spi.c
new file mode 100644
index 0000000000..a6e3d0a5bf
--- /dev/null
+++ b/arch/x86/cpu/intel_common/fast_spi.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright 2019 Google LLC
+ */
+
+#include <common.h>
+#include <asm/io.h>
+#include <asm/cpu_common.h>
+#include <asm/fast_spi.h>
+#include <asm/pci.h>
+
+/*
+ * Returns bios_start and fills in size of the BIOS region.
+ */
+static ulong fast_spi_get_bios_region(struct fast_spi_regs *regs,
+				      uint *bios_size)
+{
+	ulong bios_start, bios_end;
+
+	/*
+	 * BIOS_BFPREG provides info about BIOS-Flash Primary Region Base and
+	 * Limit. Base and Limit fields are in units of 4K.
+	 */
+	u32 val = readl(&regs->bfp);
+
+	bios_start = (val & SPIBAR_BFPREG_PRB_MASK) << 12;
+	bios_end = (((val & SPIBAR_BFPREG_PRL_MASK) >>
+		     SPIBAR_BFPREG_PRL_SHIFT) + 1) << 12;
+	*bios_size = bios_end - bios_start;
+
+	return bios_start;
+}
+
+int fast_spi_get_bios_mmap(pci_dev_t pdev, ulong *map_basep, uint *map_sizep,
+			   uint *offsetp)
+{
+	struct fast_spi_regs *regs;
+	ulong bar, base, mmio_base;
+
+	/* Special case to find mapping without probing the device */
+	pci_x86_read_config(pdev, PCI_BASE_ADDRESS_0, &bar, PCI_SIZE_32);
+	mmio_base = bar & PCI_BASE_ADDRESS_MEM_MASK;
+	regs = (struct fast_spi_regs *)mmio_base;
+	base = fast_spi_get_bios_region(regs, map_sizep);
+	*map_basep = (u32)-*map_sizep - base;
+	*offsetp = base;
+
+	return 0;
+}
+
+int fast_spi_early_init(pci_dev_t pdev, ulong mmio_base)
+{
+	/* Program Temporary BAR for SPI */
+	pci_x86_write_config(pdev, PCI_BASE_ADDRESS_0,
+			     mmio_base | PCI_BASE_ADDRESS_SPACE_MEMORY,
+			     PCI_SIZE_32);
+
+	/* Enable Bus Master and MMIO Space */
+	pci_x86_clrset_config(pdev, PCI_COMMAND, 0, PCI_COMMAND_MASTER |
+			      PCI_COMMAND_MEMORY, PCI_SIZE_8);
+
+	/*
+	 * Disable the BIOS write protect so write commands are allowed.
+	 * Enable Prefetching and caching.
+	 */
+	pci_x86_clrset_config(pdev, SPIBAR_BIOS_CONTROL,
+			      SPIBAR_BIOS_CONTROL_EISS |
+			      SPIBAR_BIOS_CONTROL_CACHE_DISABLE,
+			      SPIBAR_BIOS_CONTROL_WPD |
+			      SPIBAR_BIOS_CONTROL_PREFETCH_ENABLE, PCI_SIZE_8);
+
+	return 0;
+}
diff --git a/arch/x86/include/asm/fast_spi.h b/arch/x86/include/asm/fast_spi.h
new file mode 100644
index 0000000000..6894298526
--- /dev/null
+++ b/arch/x86/include/asm/fast_spi.h
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * Copyright (C) 2017 Intel Corporation.
+ */
+
+#ifndef ASM_FAST_SPI_H
+#define ASM_FAST_SPI_H
+
+/* Register offsets from the MMIO region base (PCI_BASE_ADDRESS_0) */
+struct fast_spi_regs {
+	u32 bfp;
+	u32 hsfsts_ctl;
+	u32 faddr;
+	u32 dlock;
+
+	u32 fdata[0x10];
+
+	u32 fracc;
+	u32 freg[12];
+	u32 fpr[5];
+	u32 gpr0;
+	u32 spare2;
+	u32 sts_ctl;
+	u16 preop;
+	u16 optype;
+	u8 opmenu[8];
+
+	u32 spare3;
+	u32 fdoc;
+	u32 fdod;
+	u32 spare4;
+	u32 afc;
+	u32 vscc[2];
+	u32 ptinx;
+	u32 ptdata;
+};
+check_member(fast_spi_regs, ptdata, 0xd0);
+
+/* Bit definitions for BFPREG (0x00) register */
+#define SPIBAR_BFPREG_PRB_MASK		0x7fff
+#define SPIBAR_BFPREG_PRL_SHIFT		16
+#define SPIBAR_BFPREG_PRL_MASK		(0x7fff << SPIBAR_BFPREG_PRL_SHIFT)
+
+/* PCI configuration registers */
+#define SPIBAR_BIOS_CONTROL			0xdc
+#define SPIBAR_BIOS_CONTROL_WPD			BIT(0)
+#define SPIBAR_BIOS_CONTROL_LOCK_ENABLE		BIT(1)
+#define SPIBAR_BIOS_CONTROL_CACHE_DISABLE	BIT(2)
+#define SPIBAR_BIOS_CONTROL_PREFETCH_ENABLE	BIT(3)
+#define SPIBAR_BIOS_CONTROL_EISS		BIT(5)
+#define SPIBAR_BIOS_CONTROL_BILD		BIT(7)
+
+/**
+ * fast_spi_get_bios_mmap() - Get memory map for SPI flash
+ *
+ * @pdev:	PCI device to use (this is the Fast SPI device)
+ * @map_basep:	Returns base memory address for mapped SPI
+ * @map_sizep:	Returns size of mapped SPI
+ * @offsetp:	Returns start offset of SPI flash where the map works
+ *	correctly (offsets before this are not visible)
+ * @return 0 (always)
+ */
+int fast_spi_get_bios_mmap(pci_dev_t pdev, ulong *map_basep, uint *map_sizep,
+			   uint *offsetp);
+
+int fast_spi_early_init(pci_dev_t pdev, ulong mmio_base);
+
+#endif	/* ASM_FAST_SPI_H */
diff --git a/arch/x86/include/asm/spl.h b/arch/x86/include/asm/spl.h
index 1bef4877eb..cc6cac08f2 100644
--- a/arch/x86/include/asm/spl.h
+++ b/arch/x86/include/asm/spl.h
@@ -11,6 +11,7 @@
 
 enum {
 	BOOT_DEVICE_SPI_MMAP	= 10,
+	BOOT_DEVICE_FAST_SPI,
 	BOOT_DEVICE_CROS_VBOOT,
 };
 
-- 
2.24.0.432.g9d3f5f5b63-goog

  parent reply	other threads:[~2019-11-22  4:17 UTC|newest]

Thread overview: 104+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-22  4:17 [U-Boot] [PATCH v4 000/100] x86: Add initial support for apollolake Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 001/100] binman: Add a library to access binman entries Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 002/100] dm: gpio: Allow control of GPIO uclass in SPL Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 003/100] dm: core: Fix offset_to_ofnode() with invalid offset Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 004/100] dm: pci: Allow delaying auto-config until after relocation Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 005/100] dm: pci: Move pci_get_devfn() into a common file Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 006/100] net: Move the checksum functions to lib/ Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 007/100] i2c: designware: Tidy up PCI support Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 008/100] i2c: designware: Avoid using static data Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 009/100] i2c: designware: Support use in SPL Simon Glass
2019-11-22  4:17 ` Simon Glass [this message]
2019-11-22  4:17 ` [U-Boot] [PATCH v4 011/100] fdt: Show the preprocessed .dts file on error Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 012/100] board_r: Move early-timer init later Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 013/100] RFC: sandbox: net: Suppress the MAC-address warnings Simon Glass
2019-11-22 21:11   ` Joe Hershberger
2019-11-22  4:17 ` [U-Boot] [PATCH v4 014/100] Revert "RFC: sandbox: net: Suppress the MAC-address warnings" Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 015/100] x86: timer: use a timer base of 0 Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 016/100] x86: timer: Reduce timer code size in TPL on Intel CPUs Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 017/100] x86: Drop unnecessary cpu code for TPL Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 018/100] x86: Drop unnecessary interrupt " Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 019/100] x86: power: Add an ACPI PMC uclass Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 020/100] x86: sandbox: Add a PMC emulator and test Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 021/100] x86: power: Add a 'pmc' command Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 022/100] pci: Add support for p2sb uclass Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 023/100] sandbox: Disable mmio by default in tests Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 024/100] sandbox: Add PCI driver and test for p2sb Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 025/100] x86: Move UCLASS_IRQ into a separate file Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 026/100] sandbox: Add a test for IRQ Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 027/100] x86: Define the SPL image start Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 028/100] x86: Reduce mrccache record alignment size Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 029/100] x86: Correct mrccache find_next_mrc_cache() calculation Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 030/100] x86: Adjust mrccache_get_region() to use livetree Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 031/100] x86: Adjust mrccache_get_region() to support get_mmap() Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 032/100] x86: Add a new global_data member for the cache record Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 033/100] x86: Tidy up error handling in mrccache_save() Simon Glass
2019-11-22  4:17 ` [U-Boot] [PATCH v4 034/100] x86: Update mrccache to support multiple caches Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 035/100] x86: Add mrccache support for a 'variable' cache Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 036/100] x86: Don't export mrccache_update() Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 037/100] x86: Move fsp_prepare_mrc_cache() to fsp1 directory Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 038/100] x86: Set the DRAM banks to reflect real location Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 039/100] x86: Set up the MTRR for SDRAM Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 040/100] x86: Don't imply libfdt or SPI flash in TPL Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 041/100] x86: Allow removal of standard PCH drivers Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 042/100] x86: Allow interrupt to happen once Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 043/100] x86: fsp: Make graphics support common to FSP1/2 Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 044/100] x86: fsp: Correct wrong header inlude in fsp_support.c Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 045/100] x86: fsp: Add FSP2 base support Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 046/100] x86: fsp: Set up an MTRR for the graphics frame buffer Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 047/100] x86: fsp: Add a new arch_fsp_init_r() hook Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 048/100] x86: fsp: Allow remembering the location of FSP-S Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 049/100] x86: fsp: Make the notify API call common Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 050/100] x86: Don't include the BIOS emulator in TPL Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 051/100] x86: Add an option to include a FIT Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 052/100] x86: Add support for newer CAR schemes Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 053/100] x86: Disable microcode section for FSP2 Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 054/100] x86: Update the fsp command " Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 055/100] x86: Update .dtsi file " Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 056/100] x86: Add an option to control the position of U-Boot Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 057/100] x86: Add an option to control the position of SPL Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 058/100] x86: Add an fdtmap and image-header Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 059/100] x86: Don't repeat microcode in U-Boot if not needed Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 060/100] x86: Separate out U-Boot and device tree in ROM image Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 061/100] x86: Make MSR_PKG_POWER_SKU common Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 062/100] spi: Correct operations check in dm_spi_xfer() Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 063/100] x86: spi: Don't enable SPI_FLASH_BAR by default Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 064/100] spi: ich: Move init function just above probe() Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 065/100] spi: ich: Move the protection/lockdown code into a function Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 066/100] spi: ich: Convert to livetree Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 067/100] spi: ich: Fix header order Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 068/100] spi: ich: Various small tidy-ups Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 069/100] spi: ich: Add mmio_base to struct ich_spi_platdata Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 070/100] dm: doc: Add a note about of-platdata and header files Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 071/100] spi: ich: Correct max-size bug in ich_spi_adjust_size() Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 072/100] spi: ich: Support of-platdata for fast-spi Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 073/100] spi: ich: Support hardware sequencing Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 074/100] spi: ich: Add support for get_mmap() method Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 075/100] spi: ich: Add TPL support Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 076/100] spi: ich: Add Apollo Lake support Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 077/100] mtd: spi: Export spi_flash_std_probe() Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 078/100] x86: Enable pinctrl in SPL and TPL Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 079/100] x86: Add low-power subsystem (lpss) support Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 080/100] x86: Add a generic Intel pinctrl driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 081/100] x86: Add a generic Intel GPIO driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 082/100] x86: apl: Add basic IO addresses Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 083/100] x86: apl: Add PMC driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 084/100] x86: apl: Add UART driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 085/100] x86: apl: Add pinctrl driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 086/100] i2c: designware: Add Apollo Lake support Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 087/100] x86: apl: Add systemagent driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 088/100] x86: apl: Add hostbridge driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 089/100] x86: apl: Add ITSS driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 090/100] x86: apl: Add LPC driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 091/100] x86: apl: Add PCH driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 092/100] x86: apl: Add PUNIT driver Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 093/100] x86: apl: Add SPL loaders Simon Glass
2019-11-22  4:18 ` [U-Boot] [PATCH v4 094/100] x86: apl: Add a CPU driver Simon Glass
2019-11-22  4:19 ` [U-Boot] [PATCH v4 095/100] x86: apl: Add SPL/TPL init Simon Glass
2019-11-22  4:19 ` [U-Boot] [PATCH v4 096/100] x86: apl: Add P2SB driver Simon Glass
2019-11-22  4:19 ` [U-Boot] [PATCH v4 097/100] x86: apl: Add Kconfig and Makefile Simon Glass
2019-11-22  4:19 ` [U-Boot] [PATCH v4 098/100] x86: apl: Add FSP structures Simon Glass
2019-11-22  4:19 ` [U-Boot] [PATCH v4 099/100] x86: apl: Add FSP support Simon Glass
2019-11-22  4:19 ` [U-Boot] [PATCH v4 100/100] x86: Add chromebook_coral Simon Glass
2019-11-22 12:25 ` [U-Boot] [PATCH v4 000/100] x86: Add initial support for apollolake Simon Glass
2019-11-23 12:58   ` Bin Meng

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=20191122041905.224686-8-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.