Skip to contentSkip to conversation

Support to run U-Boot on sc7180 Trogdor Chromebooks

PATCH Superseded Stephen Boyd 4 participants 24 messages Feb 26, 2025 – Mar 27, 2025

Subsystems (13)

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v2 cover Support to run U-Boot on sc7180 Trogdor Chromebooks

This series supports running U-Boot as a payload on sc7180 Trogdor Chromebooks like Lazor or Wormdingler. This is a jumble of different patches to get to the final goal of booting a Linux distro from the eMMC on Lazor. I'm able to boot Fedora Workstation 41 from a USB stick on my Lazor.

I moved the reviewed patch to the start. After that one line fix there's a few patches to add support for the particular SoC used on Trogdor devices, sc7180. The next set of patches move the coreboot logic out of arch/x86/ into lib/ to find the coreboot tables on ARM and stash them in global data. Then I have a handful of patches to let the coreboot commands and utilities parse and populate various things like pstore and firmware details into the DTB with the proper data from the coreboot tables. Finally, I add the calls to coreboot dram parsing code in the snapdragon board so that if coreboot tables exist we get the memory info from coreboot instead of from an earlier stage DTB.

I tested the SPI driver with the crosec command. The cros bootflow method almost works, but it seems like chromeos userspace blows up spectacularly likely because crossystem can't figure out what board it is running on. I don't really care too much about booting chromeos userspace here so I'm ignoring that problem.

TODO:
* Get display working
* Implement FIT FDT picking similar to depthcharge based on coreboot tables

Do I need to add a board/google/trogdor directory?

Changes from v1 https://lore.kernel.org/r/[email protected]
* Add Kconfig file in lib/coreboot/ to hold the coreboot config stuff similar to EFI
* Couple new patches for ximg to support extracting the FDT from chromeos kernel partitions
* Move the timestamp file out of arch/x86 as well in a different patch

Stephen Boyd (15):
bootstd: cros: Return negative error code
clk: qcom: Add driver for sc7180
pinctrl: qcom: Add driver for sc7180
spi: Add Qualcomm GENI SPI driver
coreboot: Move coreboot logic out of x86 to a generic place
arm: Support running U-Boot as a coreboot payload on ARM64 cmd/cbsysinfo: Skip the CMOS 'option_table' when not present cmd/cbsysinfo: Allow on ARM as well
coreboot: Parse sku_id/fw_config from coreboot tables
pstore: Add pstore address from coreboot tables
coreboot: Add /firmware/coreboot node to DT
coreboot: Move timestamp parsing to generic place
mach-snapdragon: Support booting as a coreboot payload
cmd: ximg: Support LZO compressed images
cmd: ximg: Support LZ4 compressed images

 arch/arm/cpu/armv8/Makefile                   |   1 +
 arch/arm/cpu/armv8/coreboot/Makefile          |   4 +
 arch/arm/cpu/armv8/coreboot/cpu.c             |  33 ++
 arch/arm/include/asm/global_data.h            |   3 +
 arch/arm/mach-snapdragon/board.c              |  18 +
 arch/x86/Kconfig                              |  22 -
 arch/x86/cpu/coreboot/Kconfig                 |  33 --
 arch/x86/cpu/coreboot/Makefile                |   1 -
 arch/x86/cpu/coreboot/coreboot.c              |  10 +-
 arch/x86/cpu/coreboot/sdram.c                 |  78 +--
 arch/x86/cpu/cpu.c                            |  15 +-
 arch/x86/cpu/i386/cpu.c                       |   2 +-
 arch/x86/lib/bootm.c                          |   5 +-
 arch/x86/lib/coreboot/Makefile                |   1 -
 arch/x86/lib/coreboot/cb_support.c            |   2 +-
 arch/x86/lib/coreboot_table.c                 |   2 +-
 arch/x86/lib/tables.c                         |   2 +-
 arch/x86/lib/zimage.c                         |   3 -
 board/coreboot/coreboot/coreboot.c            |   2 +-
 board/coreboot/coreboot/sysinfo.c             |   2 +-
 board/google/chromebook_coral/coral.c         |   2 +-
 boot/Kconfig                                  |   1 +
 boot/bootmeth_cros.c                          |   2 +-
 boot/expo_build_cb.c                          |   2 +-
 boot/image-fdt.c                              |   4 +
 cmd/Kconfig                                   |   4 +-
 cmd/Makefile                                  |   1 +
 cmd/{x86 => }/cbsysinfo.c                     |   6 +-
 cmd/pstore.c                                  |  44 +-
 cmd/version.c                                 |   2 +-
 cmd/x86/Makefile                              |   1 -
 cmd/x86/cbcmos.c                              |   2 +-
 cmd/ximg.c                                    |  28 +
 drivers/clk/qcom/Kconfig                      |   8 +
 drivers/clk/qcom/Makefile                     |   1 +
 drivers/clk/qcom/clock-sc7180.c               | 150 +++++
 drivers/misc/cbmem_console.c                  |   2 +-
 drivers/pinctrl/qcom/Kconfig                  |   7 +
 drivers/pinctrl/qcom/Makefile                 |   1 +
 drivers/pinctrl/qcom/pinctrl-sc7180.c         | 106 ++++
 drivers/serial/serial_coreboot.c              |   2 +-
 drivers/spi/Kconfig                           |  10 +
 drivers/spi/Makefile                          |   1 +
 drivers/spi/spi-geni-qcom.c                   | 527 ++++++++++++++++++
 drivers/video/coreboot.c                      |   2 +-
 .../x86/include/asm => include}/cb_sysinfo.h  |  40 +-
 .../include/asm => include}/coreboot_tables.h |  11 +
 .../coreboot_timestamp.h                      |   9 +-
 lib/Makefile                                  |   2 +
 lib/coreboot/Kconfig                          |  55 ++
 {arch/x86/cpu => lib}/coreboot/Makefile       |   9 +-
 {arch/x86/lib => lib}/coreboot/cb_sysinfo.c   | 163 +++++-
 {arch/x86/cpu => lib}/coreboot/sdram.c        |  15 +-
 {arch/x86/cpu => lib}/coreboot/timestamp.c    |  15 +-
 54 files changed, 1244 insertions(+), 230 deletions(-)
 create mode 100644 arch/arm/cpu/armv8/coreboot/Makefile
 create mode 100644 arch/arm/cpu/armv8/coreboot/cpu.c
 delete mode 100644 arch/x86/cpu/coreboot/Kconfig
 rename cmd/{x86 => }/cbsysinfo.c (99%)
 create mode 100644 drivers/clk/qcom/clock-sc7180.c
 create mode 100644 drivers/pinctrl/qcom/pinctrl-sc7180.c
 create mode 100644 drivers/spi/spi-geni-qcom.c
 rename {arch/x86/include/asm => include}/cb_sysinfo.h (89%)
 rename {arch/x86/include/asm => include}/coreboot_tables.h (98%)
 rename arch/x86/include/asm/arch-coreboot/timestamp.h => include/coreboot_timestamp.h (63%)
 create mode 100644 lib/coreboot/Kconfig
 copy {arch/x86/cpu => lib}/coreboot/Makefile (75%)
 rename {arch/x86/lib => lib}/coreboot/cb_sysinfo.c (73%)
 copy {arch/x86/cpu => lib}/coreboot/sdram.c (87%)
 rename {arch/x86/cpu => lib}/coreboot/timestamp.c (83%)

base-commit: 313b9856f95419b01df7cc6b9a16f7b07d9fe13c

Signature · 1 line
Sent by a computer, using git, on the internet
#1 lore raw

PATCH v2 1/15 bootstd: cros: Return negative error code

This should be negative EFAULT to indicate an error code.

---
 boot/bootmeth_cros.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
boot/bootmeth_cros.c +1 -1
index c7b862e512a0..d4c4ed328bd0 100644
@@ -340,7 +340,7 @@ static int cros_read_kernel(struct bootflow *bflow)
 
 	/* Check that the header is not smaller than permitted */
 	if (priv->body_offset < PROBE_SIZE)
-		return log_msg_ret("san", EFAULT);
+		return log_msg_ret("san", -EFAULT);
 
 	/* Read kernel body */
 	num_blks = priv->body_size >> desc->log2blksz;
Signature · 1 line
Sent by a computer, using git, on the internet
#2 lore raw

PATCH v2 2/15 clk: qcom: Add driver for sc7180

In reply to Stephen Boyd

The clks are already configured properly by coreboot on sc7180, but this is good enough to make the MMC and USB drivers work.

---
 drivers/clk/qcom/Kconfig        |   8 ++
 drivers/clk/qcom/Makefile       |   1 +
 drivers/clk/qcom/clock-sc7180.c | 150 ++++++++++++++++++++++++++++++++
 3 files changed, 159 insertions(+)
 create mode 100644 drivers/clk/qcom/clock-sc7180.c
drivers/clk/qcom/Kconfig +8 -0
index cb867acc48c3..973ebc01ec31 100644
@@ -103,6 +103,14 @@ config CLK_QCOM_SM8650
 	  on the Snapdragon SM8650 SoC. This driver supports the clocks
 	  and resets exposed by the GCC hardware block.
 
+config CLK_QCOM_SC7180
+	bool "Qualcomm SC7180 GCC"
+	select CLK_QCOM
+	help
+	  Say Y here to enable support for the Global Clock Controller
+	  on the Snapdragon SC7180 SoC. This driver supports the clocks
+	  and resets exposed by the GCC hardware block.
+
 config CLK_QCOM_SC7280
 	bool "Qualcomm SC7280 GCC"
 	select CLK_QCOM
drivers/clk/qcom/Makefile +1 -0
index 1bc0f15005b3..aae9d5ea578e 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_CLK_QCOM_IPQ4019) += clock-ipq4019.o
 obj-$(CONFIG_CLK_QCOM_QCM2290) += clock-qcm2290.o
 obj-$(CONFIG_CLK_QCOM_QCS404) += clock-qcs404.o
 obj-$(CONFIG_CLK_QCOM_SA8775P) += clock-sa8775p.o
+obj-$(CONFIG_CLK_QCOM_SC7180) += clock-sc7180.o
 obj-$(CONFIG_CLK_QCOM_SC7280) += clock-sc7280.o
 obj-$(CONFIG_CLK_QCOM_SM6115) += clock-sm6115.o
 obj-$(CONFIG_CLK_QCOM_SM8150) += clock-sm8150.o
drivers/clk/qcom/clock-sc7180.c new file +150 -0

150 lines not on this page · raw message

Signature · 1 line
Sent by a computer, using git, on the internet
Reviewed-by on v2 2/15
#3 lore raw

Re: [PATCH v2 02/15] clk: qcom: Add driver for sc7180

Quoted 188 lines · Stephen Boyd

The clks are already configured properly by coreboot on sc7180, but this is good enough to make the MMC and USB drivers work.

---
  drivers/clk/qcom/Kconfig        |   8 ++
  drivers/clk/qcom/Makefile       |   1 +
  drivers/clk/qcom/clock-sc7180.c | 150 ++++++++++++++++++++++++++++++++
  3 files changed, 159 insertions(+)

create mode 100644 drivers/clk/qcom/clock-sc7180.c

drivers/clk/qcom/Kconfig +8 -0
index cb867acc48c3..973ebc01ec31 100644
@@ -103,6 +103,14 @@ config CLK_QCOM_SM8650
  	  on the Snapdragon SM8650 SoC. This driver supports the clocks
  	  and resets exposed by the GCC hardware block.
 
+config CLK_QCOM_SC7180
+	bool "Qualcomm SC7180 GCC"
+	select CLK_QCOM
+	help
+	  Say Y here to enable support for the Global Clock Controller
+	  on the Snapdragon SC7180 SoC. This driver supports the clocks
+	  and resets exposed by the GCC hardware block.
+
  config CLK_QCOM_SC7280
  	bool "Qualcomm SC7280 GCC"
  	select CLK_QCOM
drivers/clk/qcom/Makefile +1 -0
index 1bc0f15005b3..aae9d5ea578e 100644
@@ -10,6 +10,7 @@ obj-$(CONFIG_CLK_QCOM_IPQ4019) += clock-ipq4019.o
  obj-$(CONFIG_CLK_QCOM_QCM2290) += clock-qcm2290.o
  obj-$(CONFIG_CLK_QCOM_QCS404) += clock-qcs404.o
  obj-$(CONFIG_CLK_QCOM_SA8775P) += clock-sa8775p.o
+obj-$(CONFIG_CLK_QCOM_SC7180) += clock-sc7180.o
  obj-$(CONFIG_CLK_QCOM_SC7280) += clock-sc7280.o
  obj-$(CONFIG_CLK_QCOM_SM6115) += clock-sm6115.o
  obj-$(CONFIG_CLK_QCOM_SM8150) += clock-sm8150.o
drivers/clk/qcom/clock-sc7180.c new file +140 -0
new file mode 100644
index 000000000000..b91c0f38c8f7
@@ -0,0 +1,150 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Clock drivers for Qualcomm sc7180
+ */
+
+#include <linux/types.h>
+#include <clk-uclass.h>
+#include <dm.h>
+#include <linux/bug.h>
+#include <linux/bitops.h>
+#include <dt-bindings/clock/qcom,gcc-sc7180.h>
+
+#include "clock-qcom.h"
+
+#define USB30_PRIM_MOCK_UTMI_CLK_CMD_RCGR 0xf034
+#define USB30_PRIM_MASTER_CLK_CMD_RCGR 0xf01c
+
+static const struct freq_tbl ftbl_gcc_qupv3_wrap1_s3_clk_src[] = {
+	F(7372800, CFG_CLK_SRC_GPLL0_EVEN, 1, 384, 15625),
+	F(14745600, CFG_CLK_SRC_GPLL0_EVEN, 1, 768, 15625),
+	F(19200000, CFG_CLK_SRC_CXO, 1, 0, 0),
+	F(29491200, CFG_CLK_SRC_GPLL0_EVEN, 1, 1536, 15625),
+	F(32000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 75),
+	F(48000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 25),
+	F(64000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 16, 75),
+	F(75000000, CFG_CLK_SRC_GPLL0_EVEN, 4, 0, 0),
+	F(80000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 4, 15),
+	F(96000000, CFG_CLK_SRC_GPLL0_EVEN, 1, 8, 25),
+	F(100000000, CFG_CLK_SRC_GPLL0_EVEN, 3, 0, 0),
+	{ }
+};
+
+static ulong sc7180_set_rate(struct clk *clk, ulong rate)
+{
+	struct msm_clk_priv *priv = dev_get_priv(clk->dev);
+	const struct freq_tbl *freq;
+
+	if (clk->id < priv->data->num_clks)
+		debug("%s: %s, requested rate=%ld\n", __func__, priv->data->clks[clk->id].name, rate);
+
+	switch (clk->id) {
+	case GCC_QUPV3_WRAP1_S2_CLK: /* UART8 */
+		freq = qcom_find_freq(ftbl_gcc_qupv3_wrap1_s3_clk_src, rate);
+		clk_rcg_set_rate_mnd(priv->base, 0x18278,
+				     freq->pre_div, freq->m, freq->n, freq->src, 16);
+		return freq->freq;
+	case GCC_USB30_PRIM_MOCK_UTMI_CLK:
+		WARN(rate != 19200000, "Unexpected rate for USB30_PRIM_MOCK_UTMI_CLK: %lu\n", rate);
+		clk_rcg_set_rate(priv->base, USB30_PRIM_MASTER_CLK_CMD_RCGR, 0, CFG_CLK_SRC_CXO);
+		return rate;
+	case GCC_USB30_PRIM_MASTER_CLK:
+		/* DT has 150000000 but this is actually rounded to 200000000 */
+		WARN(rate != 150000000, "Unexpected rate for USB30_PRIM_MASTER_CLK: %lu\n", rate);
+		clk_rcg_set_rate_mnd(priv->base, USB30_PRIM_MASTER_CLK_CMD_RCGR,
+				     3, 0, 0, CFG_CLK_SRC_GPLL0, 8);
+		clk_rcg_set_rate(priv->base, 0xf060, 0, 0);
+		return rate;
+	case GCC_SDCC1_APPS_CLK:
+		/* TODO: Actually set a rate here */
+		return rate;
+	default:
+		return 0;
+	}
+}
+
+static const struct gate_clk sc7180_clks[] = {
+	GATE_CLK(GCC_CFG_NOC_USB3_PRIM_AXI_CLK, 0x502c, 1),
+	GATE_CLK(GCC_USB30_PRIM_MASTER_CLK, 0xf010, 1),
+	GATE_CLK(GCC_AGGRE_USB3_PRIM_AXI_CLK, 0x8201c, 1),
+	GATE_CLK(GCC_USB30_PRIM_SLEEP_CLK, 0xf014, 1),
+	GATE_CLK(GCC_USB30_PRIM_MOCK_UTMI_CLK, 0xf018, 1),
+	GATE_CLK(GCC_USB3_PRIM_PHY_AUX_CLK, 0xf050, 1),
+	GATE_CLK(GCC_USB3_PRIM_PHY_COM_AUX_CLK, 0xf054, 1),
+	GATE_CLK(GCC_QUPV3_WRAP1_S2_CLK, 0x18274, 1),
+};
+
+static int sc7180_enable(struct clk *clk)
+{
+	struct msm_clk_priv *priv = dev_get_priv(clk->dev);
+
+	if (priv->data->num_clks < clk->id) {
+		debug("%s: unknown clk id %lu\n", __func__, clk->id);
+		return 0;
+	}
+
+	debug("%s: clk %ld: %s\n", __func__, clk->id, sc7180_clks[clk->id].name);
+
+	switch (clk->id) {
+	case GCC_AGGRE_USB3_PRIM_AXI_CLK:
+		qcom_gate_clk_en(priv, GCC_USB30_PRIM_MASTER_CLK);
+		fallthrough;
+	case GCC_USB30_PRIM_MASTER_CLK:
+		qcom_gate_clk_en(priv, GCC_USB3_PRIM_PHY_AUX_CLK);
+		qcom_gate_clk_en(priv, GCC_USB3_PRIM_PHY_COM_AUX_CLK);
+		break;
+	}
+
+	qcom_gate_clk_en(priv, clk->id);
+
+	return 0;
+}
+
+static const struct qcom_reset_map sc7180_gcc_resets[] = {
+	[GCC_QUSB2PHY_PRIM_BCR] = { 0x26000 },
+	[GCC_QUSB2PHY_SEC_BCR] = { 0x26004 },
+	[GCC_UFS_PHY_BCR] = { 0x77000 },
+	[GCC_USB30_PRIM_BCR] = { 0xf000 },
+	[GCC_USB3_DP_PHY_PRIM_BCR] = { 0x50008 },
+	[GCC_USB3_PHY_PRIM_BCR] = { 0x50000 },
+	[GCC_USB3PHY_PHY_PRIM_BCR] = { 0x50004 },
+	[GCC_USB_PHY_CFG_AHB2PHY_BCR] = { 0x6a000 },
+	[GCC_USB3_PHY_SEC_BCR] = { 0x5000c },
+	[GCC_USB3PHY_PHY_SEC_BCR] = { 0x50010 },
+	[GCC_USB3_DP_PHY_SEC_BCR] = { 0x50014 },
+	[GCC_USB_PHY_CFG_AHB2PHY_BCR] = { 0x6a000 },
+};
+
+static const struct qcom_power_map sc7180_gdscs[] = {
+	[UFS_PHY_GDSC] = { 0x77004 },
+	[USB30_PRIM_GDSC] = { 0xf004 },
+};
+
+static struct msm_clk_data sc7180_gcc_data = {
+	.resets = sc7180_gcc_resets,
+	.num_resets = ARRAY_SIZE(sc7180_gcc_resets),
+	.clks = sc7180_clks,
+	.num_clks = ARRAY_SIZE(sc7180_clks),
+
+	.power_domains = sc7180_gdscs,
+	.num_power_domains = ARRAY_SIZE(sc7180_gdscs),
+
+	.enable = sc7180_enable,
+	.set_rate = sc7180_set_rate,
+};
+
+static const struct udevice_id gcc_sc7180_of_match[] = {
+	{
+		.compatible = "qcom,gcc-sc7180",
+		.data = (ulong)&sc7180_gcc_data,
+	},

drivers/clk/qcom/clock-sc7180.c line 150

Quoted 10 lines
drivers/clk/qcom/clock-sc7180.c new file +10 -0
+	{ }
+};
+
+U_BOOT_DRIVER(gcc_sc7180) = {
+	.name		= "gcc_sc7180",
+	.id		= UCLASS_NOP,
+	.of_match	= gcc_sc7180_of_match,
+	.bind		= qcom_cc_bind,
+	.flags		= DM_FLAG_PRE_RELOC | DM_FLAG_DEFAULT_PD_CTRL_OFF,
+};

Looks good !

#4 lore raw

PATCH v2 3/15 pinctrl: qcom: Add driver for sc7180

In reply to Stephen Boyd

Add a driver for Qualcomm's sc7180 pinctrl device (TLMM). This is largely a copy of a similar driver in U-Boot along with reference to the Linux driver to fix up the data properly.

---
 drivers/pinctrl/qcom/Kconfig          |   7 ++
 drivers/pinctrl/qcom/Makefile         |   1 +
 drivers/pinctrl/qcom/pinctrl-sc7180.c | 106 ++++++++++++++++++++++++++
 3 files changed, 114 insertions(+)
 create mode 100644 drivers/pinctrl/qcom/pinctrl-sc7180.c
drivers/pinctrl/qcom/Kconfig +7 -0
index d3eb69985510..4772daba1ef3 100644
@@ -41,6 +41,13 @@ config PINCTRL_QCOM_QCS404
 	  Say Y here to enable support for pinctrl on the Snapdragon QCS404 SoC,
 	  as well as the associated GPIO driver.
 
+config PINCTRL_QCOM_SC7180
+	bool "Qualcomm SC7180 Pinctrl (TLMM)"
+	select PINCTRL_QCOM
+	help
+	  Say Y here to enable support for pinctrl on the Snapdragon SC7180 SoC,
+	  as well as the associated GPIO driver.
+
 config PINCTRL_QCOM_SDM845
 	bool "Qualcomm SDM845 GCC"
 	select PINCTRL_QCOM
drivers/pinctrl/qcom/Makefile +1 -0
index 06d3c95f93a6..ac5dfd1feb91 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_PINCTRL_QCOM_IPQ4019) += pinctrl-ipq4019.o
 obj-$(CONFIG_PINCTRL_QCOM_APQ8096) += pinctrl-apq8096.o
 obj-$(CONFIG_PINCTRL_QCOM_QCM2290) += pinctrl-qcm2290.o
 obj-$(CONFIG_PINCTRL_QCOM_QCS404) += pinctrl-qcs404.o
+obj-$(CONFIG_PINCTRL_QCOM_SC7180) += pinctrl-sc7180.o
 obj-$(CONFIG_PINCTRL_QCOM_SDM845) += pinctrl-sdm845.o
 obj-$(CONFIG_PINCTRL_QCOM_SM6115) += pinctrl-sm6115.o
 obj-$(CONFIG_PINCTRL_QCOM_SM8150) += pinctrl-sm8150.o
drivers/pinctrl/qcom/pinctrl-sc7180.c new file +106 -0

106 lines not on this page · raw message

Signature · 1 line
Sent by a computer, using git, on the internet
#5 lore raw

Re: [PATCH v2 03/15] pinctrl: qcom: Add driver for sc7180

Hi,

Quoted 125 lines · Stephen Boyd

Add a driver for Qualcomm's sc7180 pinctrl device (TLMM). This is largely a copy of a similar driver in U-Boot along with reference to the Linux driver to fix up the data properly.

---
  drivers/pinctrl/qcom/Kconfig          |   7 ++
  drivers/pinctrl/qcom/Makefile         |   1 +
  drivers/pinctrl/qcom/pinctrl-sc7180.c | 106 ++++++++++++++++++++++++++
  3 files changed, 114 insertions(+)

create mode 100644 drivers/pinctrl/qcom/pinctrl-sc7180.c

drivers/pinctrl/qcom/Kconfig +7 -0
index d3eb69985510..4772daba1ef3 100644
@@ -41,6 +41,13 @@ config PINCTRL_QCOM_QCS404
  	  Say Y here to enable support for pinctrl on the Snapdragon QCS404 SoC,
  	  as well as the associated GPIO driver.
 
+config PINCTRL_QCOM_SC7180
+	bool "Qualcomm SC7180 Pinctrl (TLMM)"
+	select PINCTRL_QCOM
+	help
+	  Say Y here to enable support for pinctrl on the Snapdragon SC7180 SoC,
+	  as well as the associated GPIO driver.
+
  config PINCTRL_QCOM_SDM845
  	bool "Qualcomm SDM845 GCC"
  	select PINCTRL_QCOM
drivers/pinctrl/qcom/Makefile +1 -0
index 06d3c95f93a6..ac5dfd1feb91 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_PINCTRL_QCOM_IPQ4019) += pinctrl-ipq4019.o
  obj-$(CONFIG_PINCTRL_QCOM_APQ8096) += pinctrl-apq8096.o
  obj-$(CONFIG_PINCTRL_QCOM_QCM2290) += pinctrl-qcm2290.o
  obj-$(CONFIG_PINCTRL_QCOM_QCS404) += pinctrl-qcs404.o
+obj-$(CONFIG_PINCTRL_QCOM_SC7180) += pinctrl-sc7180.o
  obj-$(CONFIG_PINCTRL_QCOM_SDM845) += pinctrl-sdm845.o
  obj-$(CONFIG_PINCTRL_QCOM_SM6115) += pinctrl-sm6115.o
  obj-$(CONFIG_PINCTRL_QCOM_SM8150) += pinctrl-sm8150.o
drivers/pinctrl/qcom/pinctrl-sc7180.c new file +77 -0
new file mode 100644
index 000000000000..1edc74e5da95
@@ -0,0 +1,106 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Qualcomm SC7180 pinctrl
+ */
+
+#include <dm.h>
+
+#include "pinctrl-qcom.h"
+
+#define WEST	0x00000000
+#define NORTH	0x00400000
+#define SOUTH	0x00800000
+
+#define MAX_PIN_NAME_LEN 32
+static char pin_name[MAX_PIN_NAME_LEN] __section(".data");
+
+static const struct pinctrl_function msm_pinctrl_functions[] = {
+	{"qup12", 1},
+	{"gpio", 0},
+};
+
+static const unsigned int sc7180_pin_offsets[] = {
+	[0] = SOUTH, [1] = SOUTH, [2] = SOUTH, [3] = SOUTH, [4] = NORTH,
+	[5] = NORTH, [6] = NORTH, [7] = NORTH, [8] = NORTH, [9] = NORTH,
+	[10] = NORTH, [11] = NORTH, [12] = SOUTH, [13] = SOUTH, [14] = SOUTH,
+	[15] = SOUTH, [16] = SOUTH, [17] = SOUTH, [18] = SOUTH, [19] = SOUTH,
+	[20] = SOUTH, [21] = NORTH, [22] = NORTH, [23] = SOUTH, [24] = SOUTH,
+	[25] = SOUTH, [26] = SOUTH, [27] = SOUTH, [28] = SOUTH, [29] = NORTH,
+	[30] = SOUTH, [31] = NORTH, [32] = NORTH, [33] = NORTH, [34] = SOUTH,
+	[35] = SOUTH, [36] = SOUTH, [37] = SOUTH, [38] = SOUTH, [39] = SOUTH,
+	[40] = SOUTH, [41] = SOUTH, [42] = NORTH, [43] = NORTH, [44] = NORTH,
+	[45] = NORTH, [46] = NORTH, [47] = NORTH, [48] = NORTH, [49] = WEST,
+	[50] = WEST, [51] = WEST, [52] = WEST, [53] = WEST, [54] = WEST,
+	[55] = WEST, [56] = WEST, [57] = WEST, [58] = WEST, [59] = NORTH,
+	[60] = NORTH, [61] = NORTH, [62] = NORTH, [63] = NORTH, [64] = NORTH,
+	[65] = NORTH, [66] = NORTH, [67] = NORTH, [68] = NORTH, [69] = WEST,
+	[70] = NORTH, [71] = NORTH, [72] = NORTH, [73] = WEST, [74] = WEST,
+	[75] = WEST, [76] = WEST, [77] = WEST, [78] = WEST, [79] = WEST,
+	[80] = WEST, [81] = WEST, [82] = WEST, [83] = WEST, [84] = WEST,
+	[85] = WEST, [86] = NORTH, [87] = NORTH, [88] = NORTH, [89] = NORTH,
+	[90] = NORTH, [91] = NORTH, [92] = NORTH, [93] = NORTH, [94] = SOUTH,
+	[95] = WEST, [96] = WEST, [97] = WEST, [98] = WEST, [99] = WEST,
+	[100] = WEST, [101] = NORTH, [102] = NORTH, [103] = NORTH, [104] = WEST,
+	[105] = NORTH, [106] = NORTH, [107] = WEST, [108] = SOUTH, [109] = SOUTH,
+	[110] = NORTH, [111] = NORTH, [112] = NORTH, [113] = NORTH, [114] = NORTH,
+	[115] = WEST, [116] = WEST, [117] = WEST, [118] = WEST,
+};
+
+static const char *sc7180_get_function_name(struct udevice *dev,
+					     unsigned int selector)
+{
+	return msm_pinctrl_functions[selector].name;
+}
+
+static const char *sc7180_get_pin_name(struct udevice *dev,
+					unsigned int selector)
+{
+	static const char * const special_pins_names[] = {
+		"ufs_reset",
+		"sdc1_rclk",
+		"sdc1_clk",
+		"sdc1_cmd",
+		"sdc1_data",
+		"sdc2_clk",
+		"sdc2_cmd",
+		"sdc2_data",
+	};
+
+	if (selector >= 119 && selector <= 126)
+		snprintf(pin_name, MAX_PIN_NAME_LEN, special_pins_names[selector - 119]);
+	else
+		snprintf(pin_name, MAX_PIN_NAME_LEN, "gpio%u", selector);
+
+	return pin_name;
+}
+
+static unsigned int sc7180_get_function_mux(__maybe_unused unsigned int pin,

drivers/pinctrl/qcom/pinctrl-sc7180.c line 87

Quoted 10 lines
drivers/pinctrl/qcom/pinctrl-sc7180.c new file +10 -0
+					    unsigned int selector)
+{
+	return msm_pinctrl_functions[selector].val;
+}
+
+static const struct msm_pinctrl_data sc7180_data = {
+	.pin_data = {
+		.pin_offsets = sc7180_pin_offsets,
+		.pin_count = 127,
+		.special_pins_start = 119,

Could you implement the special_pins_data so the sdc and ufs pins can be used ?

=> https://elixir.bootlin.com/u-boot/v2025.01/source/drivers/pinctrl/qcom/pinctrl-sm8650.c#L45

Quoted 19 lines
drivers/pinctrl/qcom/pinctrl-sc7180.c new file +19 -0
+	},
+	.functions_count = ARRAY_SIZE(msm_pinctrl_functions),
+	.get_function_name = sc7180_get_function_name,
+	.get_function_mux = sc7180_get_function_mux,
+	.get_pin_name = sc7180_get_pin_name,
+};
+
+static const struct udevice_id msm_pinctrl_ids[] = {
+	{ .compatible = "qcom,sc7180-pinctrl", .data = (ulong)&sc7180_data },
+	{ /* Sentinal */ }
+};
+
+U_BOOT_DRIVER(pinctrl_sc7180) = {
+	.name		= "pinctrl_sc7180",
+	.id		= UCLASS_NOP,
+	.of_match	= msm_pinctrl_ids,
+	.ops		= &msm_pinctrl_ops,
+	.bind		= msm_pinctrl_bind,
+};
#6 lore raw

PATCH v2 4/15 spi: Add Qualcomm GENI SPI driver

In reply to Stephen Boyd

Add a SPI driver for Qualcomm's GENI hardware.

---
 drivers/spi/Kconfig         |  10 +
 drivers/spi/Makefile        |   1 +
 drivers/spi/spi-geni-qcom.c | 527 ++++++++++++++++++++++++++++++++++++
 3 files changed, 538 insertions(+)
 create mode 100644 drivers/spi/spi-geni-qcom.c
drivers/spi/Kconfig +10 -0
index 96ea033082b5..29e84098cb2f 100644
@@ -414,6 +414,16 @@ config SPI_QUP
 	  mode supports up to 50MHz, up to four chip selects, programmable
 	  data path from 4 bits to 32 bits and numerous protocol variants.
 
+config SPI_GENI_QCOM
+	bool "Qualcomm Generic Interface (GENI) SPI controller"
+	depends on ARCH_SNAPDRAGON
+	help
+	  Support for the Qualcomm Generic Interface (GENI) SPI controller.
+	  The Generic Interface (GENI) is a firmware based Qualcomm Universal
+	  Peripherals (QUP) Serial Engine (SE) Wrapper which can support multiple
+	  bus protocols depending on the firmware type loaded at early boot time
+	  based on system configuration.
+
 config RENESAS_RPC_SPI
 	bool "Renesas RPC SPI driver"
 	depends on RCAR_64 || RZA1
drivers/spi/Makefile +1 -0
index 7051e2a00c60..385e5b87d675 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
 obj-$(CONFIG_PIC32_SPI) += pic32_spi.o
 obj-$(CONFIG_PL022_SPI) += pl022_spi.o
 obj-$(CONFIG_SPI_QUP) += spi-qup.o
+obj-$(CONFIG_SPI_GENI_QCOM) += spi-geni-qcom.o
 obj-$(CONFIG_SPI_MXIC) += spi-mxic.o
 obj-$(CONFIG_RENESAS_RPC_SPI) += renesas_rpc_spi.o
 obj-$(CONFIG_ROCKCHIP_SFC) += rockchip_sfc.o
drivers/spi/spi-geni-qcom.c new file +527 -0

527 lines not on this page · raw message

Signature · 1 line
Sent by a computer, using git, on the internet
#7 lore raw

Re: [PATCH v2 04/15] spi: Add Qualcomm GENI SPI driver

Quoted 547 lines · Stephen Boyd

Add a SPI driver for Qualcomm's GENI hardware.

---
  drivers/spi/Kconfig         |  10 +
  drivers/spi/Makefile        |   1 +
  drivers/spi/spi-geni-qcom.c | 527 ++++++++++++++++++++++++++++++++++++
  3 files changed, 538 insertions(+)

create mode 100644 drivers/spi/spi-geni-qcom.c

drivers/spi/Kconfig +10 -0
index 96ea033082b5..29e84098cb2f 100644
@@ -414,6 +414,16 @@ config SPI_QUP
  	  mode supports up to 50MHz, up to four chip selects, programmable
  	  data path from 4 bits to 32 bits and numerous protocol variants.
 
+config SPI_GENI_QCOM
+	bool "Qualcomm Generic Interface (GENI) SPI controller"
+	depends on ARCH_SNAPDRAGON
+	help
+	  Support for the Qualcomm Generic Interface (GENI) SPI controller.
+	  The Generic Interface (GENI) is a firmware based Qualcomm Universal
+	  Peripherals (QUP) Serial Engine (SE) Wrapper which can support multiple
+	  bus protocols depending on the firmware type loaded at early boot time
+	  based on system configuration.
+
  config RENESAS_RPC_SPI
  	bool "Renesas RPC SPI driver"
  	depends on RCAR_64 || RZA1
drivers/spi/Makefile +1 -0
index 7051e2a00c60..385e5b87d675 100644
@@ -64,6 +64,7 @@ obj-$(CONFIG_OMAP3_SPI) += omap3_spi.o
  obj-$(CONFIG_PIC32_SPI) += pic32_spi.o
  obj-$(CONFIG_PL022_SPI) += pl022_spi.o
  obj-$(CONFIG_SPI_QUP) += spi-qup.o
+obj-$(CONFIG_SPI_GENI_QCOM) += spi-geni-qcom.o
  obj-$(CONFIG_SPI_MXIC) += spi-mxic.o
  obj-$(CONFIG_RENESAS_RPC_SPI) += renesas_rpc_spi.o
  obj-$(CONFIG_ROCKCHIP_SFC) += rockchip_sfc.o
drivers/spi/spi-geni-qcom.c new file +498 -0
new file mode 100644
index 000000000000..9371f1530c9f
@@ -0,0 +1,527 @@
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (c) 2017-2018, The Linux foundation. All rights reserved.
+
+#include <asm/io.h>
+#include <clk.h>
+#include <dm.h>
+#include <errno.h>
+#include <linux/iopoll.h>
+#include <spi.h>
+#include <log.h>
+#include <dm/device.h>
+#include <dm/device_compat.h>
+#include <dm/ofnode.h>
+#include <dm/read.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+#include <linux/bitops.h>
+#include <time.h>
+#include <soc/qcom/geni-se.h>
+
+/* SPI SE specific registers and respective register fields */
+#define SE_SPI_CPHA		0x224
+#define CPHA			BIT(0)
+
+#define SE_SPI_LOOPBACK		0x22c
+#define LOOPBACK_ENABLE		0x1
+#define NORMAL_MODE		0x0
+#define LOOPBACK_MSK		GENMASK(1, 0)
+
+#define SE_SPI_CPOL		0x230
+#define CPOL			BIT(2)
+
+#define SE_SPI_DEMUX_OUTPUT_INV	0x24c
+
+#define SE_SPI_DEMUX_SEL	0x250
+
+#define SE_SPI_TRANS_CFG	0x25c
+#define CS_TOGGLE		BIT(1)
+
+#define SE_SPI_WORD_LEN		0x268
+#define WORD_LEN_MSK		GENMASK(9, 0)
+#define MIN_WORD_LEN		4
+
+#define SE_SPI_TX_TRANS_LEN	0x26c
+#define SE_SPI_RX_TRANS_LEN	0x270
+#define TRANS_LEN_MSK		GENMASK(23, 0)
+
+#define SE_SPI_PRE_POST_CMD_DLY	0x274
+
+#define SE_SPI_DELAY_COUNTERS	0x278
+#define SPI_INTER_WORDS_DELAY_MSK	GENMASK(9, 0)
+#define SPI_CS_CLK_DELAY_MSK		GENMASK(19, 10)
+#define SPI_CS_CLK_DELAY_SHFT		10
+
+#define SE_GENI_M_IRQ_CLEAR	0x618
+#define SE_GENI_M_IRQ_STATUS	0x610
+
+/* M_CMD OP codes for SPI */
+#define SPI_TX_ONLY		1
+#define SPI_RX_ONLY		2
+#define SPI_TX_RX		7
+#define SPI_CS_ASSERT		8
+#define SPI_CS_DEASSERT		9
+#define SPI_SCK_ONLY		10
+/* M_CMD params for SPI */
+#define SPI_PRE_CMD_DELAY	BIT(0)
+#define TIMESTAMP_BEFORE	BIT(1)
+#define FRAGMENTATION		BIT(2)
+#define TIMESTAMP_AFTER		BIT(3)
+#define POST_CMD_DELAY		BIT(4)
+
+#define BYTES_PER_FIFO_WORD	4U
+
+struct geni_spi_priv {
+	fdt_addr_t wrapper;
+	phys_addr_t base;
+	struct clk clk;
+	u32 tx_depth;
+	bool cs_high;
+};
+
+static void geni_se_setup_m_cmd(struct geni_spi_priv *priv, u32 cmd, u32 params)
+{
+	u32 m_cmd;
+
+	debug("%s: cmd=%#x, parms=%#x\n", __func__, cmd, params);
+	m_cmd = (cmd << M_OPCODE_SHFT) | (params & M_PARAMS_MSK);
+	writel(m_cmd, priv->base + SE_GENI_M_CMD0);
+}
+
+static void handle_se_timeout(struct geni_spi_priv *priv)
+{
+	int ret;
+	u32 m_irq;
+
+	writel(0, priv->base + SE_GENI_TX_WATERMARK_REG);
+
+	writel(M_CMD_CANCEL_EN, priv->base + SE_GENI_M_CMD_CTRL_REG);
+
+	ret = readl_poll_timeout(priv->base + SE_GENI_M_IRQ_STATUS, m_irq,
+				 (m_irq & M_CMD_CANCEL_EN) == M_CMD_CANCEL_EN,
+				 100);
+	writel(M_CMD_CANCEL_EN, priv->base + SE_GENI_M_IRQ_CLEAR);
+	if (ret < 0) {
+		printf("spi-geni-qcom: Cancel failed. Abort the operation\n");
+
+		writel_relaxed(M_CMD_ABORT_EN, priv->base + SE_GENI_M_CMD_CTRL_REG);
+		ret = readl_poll_timeout(priv->base + SE_GENI_M_IRQ_STATUS, m_irq,
+					 (m_irq & M_CMD_ABORT_EN) == M_CMD_ABORT_EN,
+					 100);
+		writel(M_CMD_ABORT_EN, priv->base + SE_GENI_M_IRQ_CLEAR);
+		if (ret < 0)
+			printf("spi-geni-qcom: Abort failed\n");
+	}
+}
+
+static int geni_spi_set_speed(struct udevice *dev, uint speed)
+{
+	/* TODO: Set a clk frequency or change divider here */
+	return 0;
+}
+
+static int geni_spi_set_mode(struct udevice *bus, uint mode)
+{
+	struct geni_spi_priv *priv = dev_get_priv(bus);
+	u32 loopback_cfg = 0, cpol = 0, cpha = 0;
+
+	if (mode & SPI_LOOP)
+		loopback_cfg = LOOPBACK_ENABLE;
+
+	if (mode & SPI_CPOL)
+		cpol = CPOL;
+
+	if (mode & SPI_CPHA)
+		cpha = CPHA;
+
+	if (mode & SPI_CS_HIGH)
+		priv->cs_high = true;
+
+	writel(loopback_cfg, priv->base + SE_SPI_LOOPBACK);
+	writel(cpha, priv->base + SE_SPI_CPHA);
+	writel(cpol, priv->base + SE_SPI_CPOL);
+
+	return 0;
+}
+
+static void geni_spi_reset(struct udevice *dev)
+{
+	struct udevice *bus = dev_get_parent(dev);
+	struct geni_spi_priv *priv = dev_get_priv(bus);
+
+	/* Driver may not be probed yet */
+	if (!priv)
+		return;
+}
+
+#define NUM_PACKING_VECTORS 4
+#define PACKING_START_SHIFT 5
+#define PACKING_DIR_SHIFT 4
+#define PACKING_LEN_SHIFT 1
+#define PACKING_STOP_BIT BIT(0)
+#define PACKING_VECTOR_SHIFT 10
+static void geni_spi_config_packing(struct geni_spi_priv *geni, int bpw,
+				    int pack_words, bool msb_to_lsb,
+				    bool tx_cfg, bool rx_cfg)
+{
+	u32 cfg0, cfg1, cfg[NUM_PACKING_VECTORS] = {0};
+	int len;
+	int temp_bpw = bpw;
+	int idx_start = msb_to_lsb ? bpw - 1 : 0;
+	int idx = idx_start;
+	int idx_delta = msb_to_lsb ? -BITS_PER_BYTE : BITS_PER_BYTE;
+	int ceil_bpw = ALIGN(bpw, BITS_PER_BYTE);
+	int iter = (ceil_bpw * pack_words) / BITS_PER_BYTE;
+	int i;
+
+	if (iter <= 0 || iter > NUM_PACKING_VECTORS)
+		return;
+
+	for (i = 0; i < iter; i++) {
+		len = min_t(int, temp_bpw, BITS_PER_BYTE) - 1;
+		cfg[i] = idx << PACKING_START_SHIFT;
+		cfg[i] |= msb_to_lsb << PACKING_DIR_SHIFT;
+		cfg[i] |= len << PACKING_LEN_SHIFT;
+
+		if (temp_bpw <= BITS_PER_BYTE) {
+			idx = ((i + 1) * BITS_PER_BYTE) + idx_start;
+			temp_bpw = bpw;
+		} else {
+			idx = idx + idx_delta;
+			temp_bpw = temp_bpw - BITS_PER_BYTE;
+		}
+	}
+	cfg[iter - 1] |= PACKING_STOP_BIT;
+	cfg0 = cfg[0] | (cfg[1] << PACKING_VECTOR_SHIFT);
+	cfg1 = cfg[2] | (cfg[3] << PACKING_VECTOR_SHIFT);
+
+	if (tx_cfg) {
+		writel(cfg0, geni->base + SE_GENI_TX_PACKING_CFG0);
+		writel(cfg1, geni->base + SE_GENI_TX_PACKING_CFG1);
+	}
+	if (rx_cfg) {
+		writel(cfg0, geni->base + SE_GENI_RX_PACKING_CFG0);
+		writel(cfg1, geni->base + SE_GENI_RX_PACKING_CFG1);
+	}
+
+	/*
+	 * Number of protocol words in each FIFO entry
+	 * 0 - 4x8, four words in each entry, max word size of 8 bits
+	 * 1 - 2x16, two words in each entry, max word size of 16 bits
+	 * 2 - 1x32, one word in each entry, max word size of 32 bits
+	 * 3 - undefined
+	 */
+	if (pack_words || bpw == 32)
+		writel(bpw / 16, geni->base + SE_GENI_BYTE_GRAN);
+}
+
+static u32 geni_spi_get_tx_fifo_depth(struct geni_spi_priv *geni)
+{
+	u32 val, hw_version, hw_major, hw_minor, tx_fifo_depth_mask;
+
+	hw_version = readl(geni->wrapper + QUP_HW_VER_REG);
+	hw_major = GENI_SE_VERSION_MAJOR(hw_version);
+	hw_minor = GENI_SE_VERSION_MINOR(hw_version);
+
+	if ((hw_major == 3 && hw_minor >= 10) || hw_major > 3)
+		tx_fifo_depth_mask = TX_FIFO_DEPTH_MSK_256_BYTES;
+	else
+		tx_fifo_depth_mask = TX_FIFO_DEPTH_MSK;
+
+	val = readl(geni->base + SE_HW_PARAM_0);
+
+	return (val & tx_fifo_depth_mask) >> TX_FIFO_DEPTH_SHFT;
+}
+
+static void geni_spi_drain_rx(struct geni_spi_priv *geni)
+{
+	u32 rx_fifo_status;
+	unsigned int rx_bytes;
+	unsigned int rx_last_byte_valid;
+	unsigned int i;
+
+	rx_fifo_status = readl(geni->base + SE_GENI_RX_FIFO_STATUS);
+	rx_bytes = (rx_fifo_status & RX_FIFO_WC_MSK) * BYTES_PER_FIFO_WORD;
+	if (rx_fifo_status & RX_LAST) {
+		rx_last_byte_valid = rx_fifo_status & RX_LAST_BYTE_VALID_MSK;
+		rx_last_byte_valid >>= RX_LAST_BYTE_VALID_SHFT;
+		if (rx_last_byte_valid && rx_last_byte_valid < 4)
+			rx_bytes -= BYTES_PER_FIFO_WORD - rx_last_byte_valid;
+	}
+
+	for (i = 0; i < DIV_ROUND_UP(rx_bytes, BYTES_PER_FIFO_WORD); i++)
+		readl(geni->base + SE_GENI_RX_FIFOn);
+}
+
+static void geni_spi_hw_init(struct udevice *dev)
+{
+	struct udevice *bus = dev_get_parent(dev);
+	struct geni_spi_priv *geni = dev_get_priv(bus);
+	u32 demux_output_inv = 0;
+	u32 val, demux_sel;
+
+	writel(0, geni->base + SE_GSI_EVENT_EN);
+	writel(0xffffffff, geni->base + SE_GENI_M_IRQ_CLEAR);
+	writel(0xffffffff, geni->base + SE_GENI_S_IRQ_CLEAR);
+	writel(0xffffffff, geni->base + SE_IRQ_EN);
+
+	val = readl(geni->base + GENI_CGC_CTRL);
+	val |= DEFAULT_CGC_EN;
+	writel(val, geni->base + GENI_CGC_CTRL);
+
+	writel(DEFAULT_IO_OUTPUT_CTRL_MSK, geni->base + GENI_OUTPUT_CTRL);
+	writel(FORCE_DEFAULT, geni->base + GENI_FORCE_DEFAULT_REG);
+
+	val = readl(geni->base + SE_IRQ_EN);
+	val |= GENI_M_IRQ_EN | GENI_S_IRQ_EN;
+	writel(val, geni->base + SE_IRQ_EN);
+
+	val = readl(geni->base + SE_GENI_DMA_MODE_EN);
+	val &= ~GENI_DMA_MODE_EN;
+	writel(val, geni->base + SE_GENI_DMA_MODE_EN);
+
+	writel(0, geni->base + SE_GSI_EVENT_EN);
+
+	writel(geni->tx_depth - 3, geni->base + SE_GENI_RX_WATERMARK_REG);
+	writel(geni->tx_depth - 2, geni->base + SE_GENI_RX_RFR_WATERMARK_REG);
+
+	val = readl(geni->base + SE_GENI_M_IRQ_EN);
+	val |= M_COMMON_GENI_M_IRQ_EN;
+	val |= M_CMD_DONE_EN | M_TX_FIFO_WATERMARK_EN;
+	val |= M_RX_FIFO_WATERMARK_EN | M_RX_FIFO_LAST_EN;
+	writel(val, geni->base + SE_GENI_M_IRQ_EN);
+
+	val = readl(geni->base + SE_GENI_S_IRQ_EN);
+	val |= S_COMMON_GENI_S_IRQ_EN;
+	writel(val, geni->base + SE_GENI_S_IRQ_EN);
+
+	if (geni->cs_high)
+		demux_output_inv = BIT(spi_chip_select(dev));
+	demux_sel = spi_chip_select(dev);
+	writel(demux_sel, geni->base + SE_SPI_DEMUX_SEL);
+	writel(demux_output_inv, geni->base + SE_SPI_DEMUX_OUTPUT_INV);
+
+	writel(((8 - MIN_WORD_LEN) & WORD_LEN_MSK), geni->base + SE_SPI_WORD_LEN);
+	geni_spi_config_packing(geni, BITS_PER_BYTE, 4, true, true, true);
+
+	geni_spi_drain_rx(geni);
+}
+
+static int geni_spi_claim_bus(struct udevice *dev)
+{
+	geni_spi_hw_init(dev);
+	return 0;
+}
+
+static int geni_spi_release_bus(struct udevice *dev)
+{
+	/* Reset the SPI hardware */
+	geni_spi_reset(dev);
+
+	return 0;
+}
+
+static int geni_spi_set_cs(struct udevice *bus, bool enable)
+{
+	struct geni_spi_priv *priv = dev_get_priv(bus);
+	u32 m_cmd = 0, m_irq;
+	int ret;
+
+	debug("%s: enable=%d\n", __func__, enable);
+
+	m_cmd = enable ? SPI_CS_ASSERT : SPI_CS_DEASSERT;
+	geni_se_setup_m_cmd(priv, m_cmd, 0);
+
+	ret = readl_poll_timeout(priv->base + SE_GENI_M_IRQ_STATUS, m_irq,
+				 (m_irq & M_CMD_DONE_EN) == M_CMD_DONE_EN,
+				 100);
+	writel(M_CMD_DONE_EN, priv->base + SE_GENI_M_IRQ_CLEAR);
+	if (ret) {
+		printf("spi-geni-qcom: Timeout setting cs\n");
+		handle_se_timeout(priv);
+		return ret;
+	}
+
+	return 0;
+}
+
+static unsigned int
+geni_spi_handle_tx(struct geni_spi_priv *geni, const u8 *dout, unsigned int tx_rem_bytes)
+{
+	unsigned int max_bytes;
+	unsigned int i = 0;
+
+	max_bytes = (geni->tx_depth - 1) * BYTES_PER_FIFO_WORD;
+	if (tx_rem_bytes < max_bytes)
+		max_bytes = tx_rem_bytes;
+
+	while (i < max_bytes) {
+		unsigned int j;
+		unsigned int bytes_to_write;
+		u32 fifo_word = 0;
+		u8 *fifo_byte = (u8 *)&fifo_word;
+
+		bytes_to_write = min(BYTES_PER_FIFO_WORD, max_bytes - i);
+		for (j = 0; j < bytes_to_write; j++)
+			fifo_byte[j] = dout[i++];
+		iowrite32_rep((void *)(geni->base + SE_GENI_TX_FIFOn), &fifo_word, 1);
+	}
+	tx_rem_bytes -= max_bytes;
+	if (!tx_rem_bytes)
+		writel(0, geni->base + SE_GENI_TX_WATERMARK_REG);
+
+	return max_bytes;
+}
+
+static int geni_spi_handle_rx(struct geni_spi_priv *geni, u8 *din, unsigned int rx_rem_bytes)
+{
+	u32 rx_fifo_status;
+	unsigned int rx_bytes;
+	unsigned int rx_last_byte_valid;
+	unsigned int i = 0;
+
+	rx_fifo_status = readl(geni->base + SE_GENI_RX_FIFO_STATUS);
+	rx_bytes = (rx_fifo_status & RX_FIFO_WC_MSK) * BYTES_PER_FIFO_WORD;
+	if (rx_fifo_status & RX_LAST) {
+		rx_last_byte_valid = rx_fifo_status & RX_LAST_BYTE_VALID_MSK;
+		rx_last_byte_valid >>= RX_LAST_BYTE_VALID_SHFT;
+		if (rx_last_byte_valid && rx_last_byte_valid < 4)
+			rx_bytes -= BYTES_PER_FIFO_WORD - rx_last_byte_valid;
+	}
+
+	if (rx_rem_bytes < rx_bytes)
+		rx_bytes = rx_rem_bytes;
+
+	while (i < rx_bytes) {
+		u32 fifo_word = 0;
+		u8 *fifo_byte = (u8 *)&fifo_word;
+		unsigned int bytes_to_read;
+		unsigned int j;
+
+		bytes_to_read = min(BYTES_PER_FIFO_WORD, rx_bytes - i);
+		ioread32_rep((void *)(geni->base + SE_GENI_RX_FIFOn), &fifo_word, 1);
+		for (j = 0; j < bytes_to_read; j++)
+			din[i++] = fifo_byte[j];
+	}
+
+	return rx_bytes;
+}
+
+static int geni_spi_xfer(struct udevice *dev, unsigned int bitlen,
+			 const void *dout, void *din, unsigned long flags)
+{
+	struct udevice *bus = dev_get_parent(dev);
+	struct geni_spi_priv *priv = dev_get_priv(bus);
+	unsigned int len = bitlen >> 3;
+	unsigned int rx_rem_bytes = din ? len : 0;
+	unsigned int tx_rem_bytes = dout ? len : 0;
+	int ret = 0;
+	u32 m_cmd = 0, m_irq;
+	ulong start;
+
+	if (len & ~TRANS_LEN_MSK) {
+		printf("spi-geni-qcom: transfer length too long (%d)\n", len);
+		return -EINVAL;
+	}
+
+	if (flags & SPI_XFER_BEGIN) {
+		geni_spi_hw_init(dev);
+		ret = geni_spi_set_cs(bus, true);
+		if (ret != 0)
+			return ret;
+	}
+
+	if (len) {
+		if (din) {
+			m_cmd |= SPI_RX_ONLY;
+			writel(len, priv->base + SE_SPI_RX_TRANS_LEN);
+		}
+		if (dout) {
+			m_cmd |= SPI_TX_ONLY;
+			writel(len, priv->base + SE_SPI_TX_TRANS_LEN);
+			writel(1, priv->base + SE_GENI_TX_WATERMARK_REG);
+		}
+
+		geni_se_setup_m_cmd(priv, m_cmd, FRAGMENTATION);
+
+		start = get_timer(0);
+		do {
+			ret = readl_poll_timeout(priv->base + SE_GENI_M_IRQ_STATUS, m_irq,
+						 m_irq != 0, 1000);
+			if ((m_irq & M_RX_FIFO_WATERMARK_EN) || (m_irq & M_RX_FIFO_LAST_EN)) {
+				rx_rem_bytes -= geni_spi_handle_rx(priv, din + len - rx_rem_bytes,
+								   rx_rem_bytes);
+			}
+			if (m_irq & M_TX_FIFO_WATERMARK_EN) {
+				tx_rem_bytes -= geni_spi_handle_tx(priv, dout + len - tx_rem_bytes,
+								   tx_rem_bytes);
+			}
+			writel(m_irq, priv->base + SE_GENI_M_IRQ_CLEAR);
+			if (m_irq & M_CMD_DONE_EN)
+				break;
+		} while (get_timer(start) < 100000);
+
+		if (!(m_irq & M_CMD_DONE_EN) || tx_rem_bytes || rx_rem_bytes) {
+			printf("spi-geni-qcom: Transfer failed\n");
+			handle_se_timeout(priv);
+			return -ETIMEDOUT;
+		}
+	}
+
+	if (flags & SPI_XFER_END) {
+		ret = geni_spi_set_cs(bus, false);
+		if (ret != 0)
+			return ret;
+	}
+
+	return ret;
+}
+
+static const struct dm_spi_ops geni_spi_ops = {
+	.claim_bus	= geni_spi_claim_bus,
+	.release_bus	= geni_spi_release_bus,
+	.xfer		= geni_spi_xfer,
+	.set_speed	= geni_spi_set_speed,
+	.set_mode	= geni_spi_set_mode,
+};
+
+static int geni_spi_probe(struct udevice *dev)
+{
+	ofnode parent_node = ofnode_get_parent(dev_ofnode(dev));
+	struct geni_spi_priv *priv = dev_get_priv(dev);
+	int ret;
+
+	priv->base = dev_read_addr(dev);
+	if (priv->base == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	priv->wrapper = ofnode_get_addr(parent_node);

drivers/spi/spi-geni-qcom.c line 508

Quoted 10 lines
drivers/spi/spi-geni-qcom.c new file +10 -0
+	if (priv->wrapper == FDT_ADDR_T_NONE)
+		return -EINVAL;
+
+	ret = clk_get_by_index(dev, 0, &priv->clk);
+	if (ret)
+		return ret;
+
+	ret = clk_enable(&priv->clk);
+	if (ret < 0)
+		return ret;

I think you should check for the protocol type and if FIFO is disabled like the i2c driver:
https://elixir.bootlin.com/u-boot/v2025.01/source/drivers/i2c/geni_i2c.c#L504

Neil

Quoted 19 lines
drivers/spi/spi-geni-qcom.c new file +19 -0
+
+	priv->tx_depth = geni_spi_get_tx_fifo_depth(priv);
+
+	return 0;
+}
+
+static const struct udevice_id spi_geni_ids[] = {
+	{ .compatible = "qcom,geni-spi" },
+	{ /* sentinel */ }
+};
+
+U_BOOT_DRIVER(geni_spi) = {
+	.name		= "geni_spi",
+	.id		= UCLASS_SPI,
+	.of_match	= spi_geni_ids,
+	.ops		= &geni_spi_ops,
+	.priv_auto	= sizeof(struct geni_spi_priv),
+	.probe		= geni_spi_probe,
+};
#8 lore raw

PATCH v2 5/15 coreboot: Move coreboot logic out of x86 to a generic place

In reply to Stephen Boyd

Lay the groundwork to run U-Boot as a payload on ARM coreboot based devices. Move the coreboot table parsing code out of arch/x86 into lib/coreboot. The headers like cb_sysinfo.h and coreboot_tables.h need to be globally accessible, so move them into the top level include directory. Introduce helper functions like board_get_usable_ram_top_from_coreboot(), dram_init_from_coreboot(), and dram_init_banksize_from_coreboot() so that boards can still override these common functions while also supporting booting as a coreboot payload.

---
 arch/x86/Kconfig                              | 22 ------
 arch/x86/cpu/coreboot/Kconfig                 | 33 --------
 arch/x86/cpu/coreboot/coreboot.c              |  4 +-
 arch/x86/cpu/coreboot/sdram.c                 | 78 +------------------
 arch/x86/cpu/coreboot/timestamp.c             |  2 +-
 arch/x86/cpu/cpu.c                            |  2 +-
 arch/x86/cpu/i386/cpu.c                       |  2 +-
 .../x86/include/asm/arch-coreboot/timestamp.h |  2 +-
 arch/x86/lib/coreboot/Makefile                |  1 -
 arch/x86/lib/coreboot/cb_support.c            |  2 +-
 arch/x86/lib/coreboot_table.c                 |  2 +-
 arch/x86/lib/tables.c                         |  2 +-
 board/coreboot/coreboot/coreboot.c            |  2 +-
 board/coreboot/coreboot/sysinfo.c             |  2 +-
 board/google/chromebook_coral/coral.c         |  2 +-
 boot/Kconfig                                  |  1 +
 boot/expo_build_cb.c                          |  2 +-
 cmd/version.c                                 |  2 +-
 cmd/x86/cbcmos.c                              |  2 +-
 cmd/x86/cbsysinfo.c                           |  2 +-
 drivers/misc/cbmem_console.c                  |  2 +-
 drivers/serial/serial_coreboot.c              |  2 +-
 drivers/video/coreboot.c                      |  2 +-
 .../x86/include/asm => include}/cb_sysinfo.h  | 22 +++++-
 .../include/asm => include}/coreboot_tables.h |  0
 lib/Makefile                                  |  2 +
 lib/coreboot/Kconfig                          | 55 +++++++++++++
 lib/coreboot/Makefile                         | 17 ++++
 {arch/x86/lib => lib}/coreboot/cb_sysinfo.c   | 14 +---
 {arch/x86/cpu => lib}/coreboot/sdram.c        | 15 +---
 30 files changed, 125 insertions(+), 173 deletions(-)
 delete mode 100644 arch/x86/cpu/coreboot/Kconfig
 rename {arch/x86/include/asm => include}/cb_sysinfo.h (94%)
 rename {arch/x86/include/asm => include}/coreboot_tables.h (100%)
 create mode 100644 lib/coreboot/Kconfig
 create mode 100644 lib/coreboot/Makefile
 rename {arch/x86/lib => lib}/coreboot/cb_sysinfo.c (95%)
 copy {arch/x86/cpu => lib}/coreboot/sdram.c (87%)
arch/x86/Kconfig +0 -22
index 006a59d6fa63..9e1370aae60c 100644
@@ -111,7 +111,6 @@ source "arch/x86/cpu/apollolake/Kconfig"
 source "arch/x86/cpu/baytrail/Kconfig"
 source "arch/x86/cpu/braswell/Kconfig"
 source "arch/x86/cpu/broadwell/Kconfig"
-source "arch/x86/cpu/coreboot/Kconfig"
 source "arch/x86/cpu/ivybridge/Kconfig"
 source "arch/x86/cpu/efi/Kconfig"
 source "arch/x86/cpu/qemu/Kconfig"
@@ -1041,27 +1040,6 @@ config INTEL_GMA_SWSMISCI
 
 endif # INTEL_SOC
 
-config COREBOOT_SYSINFO
-	bool "Support reading coreboot sysinfo"
-	default y if SYS_COREBOOT
-	help
-	  Select this option to read the coreboot sysinfo table on start-up,
-	  if present. This is written by coreboot before it exits and provides
-	  various pieces of information about the running system, including
-	  display, memory and build information. It is stored in
-	  struct sysinfo_t after parsing by get_coreboot_info().
-
-config SPL_COREBOOT_SYSINFO
-	bool "Support reading coreboot sysinfo"
-	depends on SPL
-	default y if COREBOOT_SYSINFO
-	help
-	  Select this option to read the coreboot sysinfo table in SPL,
-	  if present. This is written by coreboot before it exits and provides
-	  various pieces of information about the running system, including
-	  display, memory and build information. It is stored in
-	  struct sysinfo_t after parsing by get_coreboot_info().
-
 config ZBOOT
 	bool "Support the zImage format"
 	default y
arch/x86/cpu/coreboot/Kconfig deleted +0 -33
deleted file mode 100644
index 085302c04829..000000000000
@@ -1,33 +0,0 @@
-if VENDOR_COREBOOT
-
-config SYS_COREBOOT
-	bool
-	default y
-	imply SYS_NS16550
-	imply SCSI
-	imply SCSI_AHCI
-	imply AHCI_PCI
-	imply MMC
-	imply MMC_PCI
-	imply MMC_SDHCI
-	imply MMC_SDHCI_SDMA
-	imply USB
-	imply USB_EHCI_HCD
-	imply USB_XHCI_HCD
-	imply USB_STORAGE
-	imply USB_KEYBOARD
-	imply VIDEO_COREBOOT
-	imply E1000
-	imply ETH_DESIGNWARE
-	imply PCH_GBE
-	imply RTL8169
-	imply CMD_CBFS
-	imply FS_CBFS
-	imply CBMEM_CONSOLE
-	imply X86_TSC_READ_BASE
-	imply USE_PREBOOT
-	select BINMAN if X86_64
-	select SYSINFO
-	imply SYSINFO_EXTRA
-
-endif
arch/x86/cpu/coreboot/coreboot.c +3 -1
index fa7430b436f9..a092e8a27027 100644
@@ -5,6 +5,7 @@
  * Graeme Russ, [email protected].
  */
 
+#include <cb_sysinfo.h>
 #include <cpu_func.h>
 #include <event.h>
 #include <fdtdec.h>
@@ -14,7 +15,6 @@
 #include <asm/io.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
-#include <asm/cb_sysinfo.h>
 #include <asm/arch/timestamp.h>
 #include <dm/ofnode.h>
 
@@ -32,6 +32,8 @@ int arch_cpu_init(void)
 		printf("Failed to parse coreboot tables.\n");
 		return ret;
 	}
+	gd_set_acpi_start(map_to_sysmem(lib_sysinfo.rsdp));
+	gd_set_smbios_start(lib_sysinfo.smbios_start);
 
 	timestamp_init();
 
arch/x86/cpu/coreboot/sdram.c +4 -74

102 lines not on this page · raw message

arch/x86/cpu/coreboot/timestamp.c +1 -1
index 681191d85bb6..18be969ccea6 100644
@@ -6,9 +6,9 @@
  */
 
 #include <bootstage.h>
+#include <cb_sysinfo.h>
 #include <errno.h>
 #include <asm/arch/timestamp.h>
-#include <asm/cb_sysinfo.h>
 #include <asm/u-boot-x86.h>
 #include <linux/compiler.h>
 
arch/x86/cpu/cpu.c +1 -1
index a8b21406ac06..9ac2a6bf4a09 100644
@@ -22,6 +22,7 @@
 
 #include <bootstage.h>
 #include <command.h>
+#include <coreboot_tables.h>
 #include <cpu_func.h>
 #include <dm.h>
 #include <errno.h>
@@ -35,7 +36,6 @@
 #include <acpi/acpi_table.h>
 #include <asm/acpi.h>
 #include <asm/control_regs.h>
-#include <asm/coreboot_tables.h>
 #include <asm/cpu.h>
 #include <asm/global_data.h>
 #include <asm/lapic.h>
arch/x86/cpu/i386/cpu.c +1 -1
index a51a24498a7f..fd35cabe552f 100644
@@ -18,13 +18,13 @@
  * src/arch/x86/lib/cpu.c
  */
 
+#include <coreboot_tables.h>
 #include <cpu_func.h>
 #include <init.h>
 #include <log.h>
 #include <malloc.h>
 #include <spl.h>
 #include <asm/control_regs.h>
-#include <asm/coreboot_tables.h>
 #include <asm/cpu.h>
 #include <asm/global_data.h>
 #include <asm/mp.h>
arch/x86/include/asm/arch-coreboot/timestamp.h +1 -1
index bbf89447dde4..227316975047 100644
@@ -8,7 +8,7 @@
 #ifndef __COREBOOT_TIMESTAMP_H__
 #define __COREBOOT_TIMESTAMP_H__
 
-#include <asm/cb_sysinfo.h>
+#include <cb_sysinfo.h>
 
 void timestamp_init(void);
 void timestamp_add(enum timestamp_id id, uint64_t ts_time);
arch/x86/lib/coreboot/Makefile +0 -1
index cb0ae1d017b2..95dcaf8920db 100644
@@ -3,5 +3,4 @@
 # Copyright 2021 Google LLC
 #
 
-obj-y += cb_sysinfo.o
 obj-y += cb_support.o
arch/x86/lib/coreboot/cb_support.c +1 -1
index b4d5fa4af327..32880d18ed1e 100644
@@ -5,7 +5,7 @@
  * Copyright 2021 Google LLC
  */
 
-#include <asm/cb_sysinfo.h>
+#include <cb_sysinfo.h>
 #include <asm/e820.h>
 #include <linux/kernel.h>
 
arch/x86/lib/coreboot_table.c +1 -1
index 33fce5d0a5e5..ffe98ea491a0 100644
@@ -3,11 +3,11 @@
  * Copyright (C) 2016, Bin Meng <[email protected]>
  */
 
+#include <coreboot_tables.h>
 #include <malloc.h>
 #include <net.h>
 #include <vesa.h>
 #include <acpi/acpi_s3.h>
-#include <asm/coreboot_tables.h>
 #include <asm/e820.h>
 #include <asm/global_data.h>
 
arch/x86/lib/tables.c +1 -1
index 44fe80c52249..3d637792c848 100644
@@ -6,6 +6,7 @@
 #define LOG_CATEGORY LOGC_ACPI
 
 #include <bloblist.h>
+#include <coreboot_tables.h>
 #include <log.h>
 #include <malloc.h>
 #include <smbios.h>
@@ -14,7 +15,6 @@
 #include <asm/sfi.h>
 #include <asm/mpspec.h>
 #include <asm/tables.h>
-#include <asm/coreboot_tables.h>
 #include <linux/log2.h>
 #include <linux/sizes.h>
 
board/coreboot/coreboot/coreboot.c +1 -1
index f2ca10767681..c12af5c79322 100644
@@ -3,10 +3,10 @@
  * Copyright (C) 2018, Bin Meng <[email protected]>
  */
 
+#include <cb_sysinfo.h>
 #include <splash.h>
 #include <init.h>
 #include <smbios.h>
-#include <asm/cb_sysinfo.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
board/coreboot/coreboot/sysinfo.c +1 -1
index d6b19530023e..c510cd1e1b7f 100644
@@ -6,10 +6,10 @@
  * Written by Simon Glass <[email protected]>
  */
 
+#include <cb_sysinfo.h>
 #include <dm.h>
 #include <smbios.h>
 #include <sysinfo.h>
-#include <asm/cb_sysinfo.h>
 
 struct cb_sysinfo_priv {
 	const struct smbios_header *bios;
board/google/chromebook_coral/coral.c +1 -1
index db96534857c8..c0d50bf4c717 100644
@@ -6,6 +6,7 @@
 #define LOG_CATEGORY	UCLASS_SYSINFO
 
 #include <bloblist.h>
+#include <cb_sysinfo.h>
 #include <command.h>
 #include <cros_ec.h>
 #include <dm.h>
@@ -16,7 +17,6 @@
 #include <acpi/acpigen.h>
 #include <asm-generic/gpio.h>
 #include <asm/acpi_nhlt.h>
-#include <asm/cb_sysinfo.h>
 #include <asm/intel_gnvs.h>
 #include <asm/intel_pinctrl.h>
 #include <dm/acpi.h>
boot/Kconfig +1 -0
index c09a98c3233c..e6eb3da5d352 100644
@@ -1,5 +1,6 @@
 menu "Boot options"
 
+source "lib/coreboot/Kconfig"
 source "lib/efi_loader/Kconfig"
 
 menu "Boot images"
boot/expo_build_cb.c +1 -1
index 442ad760e796..47c62ca7e920 100644
@@ -8,6 +8,7 @@
 
 #define LOG_CATEGORY	LOGC_EXPO
 
+#include <cb_sysinfo.h>
 #include <cedit.h>
 #include <ctype.h>
 #include <errno.h>
@@ -15,7 +16,6 @@
 #include <log.h>
 #include <malloc.h>
 #include <vsprintf.h>
-#include <asm/cb_sysinfo.h>
 
 /**
  * struct build_info - Information to use when building
cmd/version.c +1 -1
index 53db1a0b6bd1..6c786314bfe5 100644
@@ -9,7 +9,7 @@
 #include <version_string.h>
 #include <linux/compiler.h>
 #ifdef CONFIG_SYS_COREBOOT
-#include <asm/cb_sysinfo.h>
+#include <cb_sysinfo.h>
 #endif
 
 static int do_version(struct cmd_tbl *cmdtp, int flag, int argc,
cmd/x86/cbcmos.c +1 -1
index fe5582fbf511..84a81be53cdd 100644
@@ -7,10 +7,10 @@
 
 #define LOG_CATEGORY	UCLASS_RTC
 
+#include <cb_sysinfo.h>
 #include <command.h>
 #include <dm.h>
 #include <rtc.h>
-#include <asm/cb_sysinfo.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
cmd/x86/cbsysinfo.c +1 -1
index ea4d89616f62..3936d30da0e1 100644
@@ -4,7 +4,7 @@
  * Written by Simon Glass <[email protected]>
  */
 
-#include <asm/cb_sysinfo.h>
+#include <cb_sysinfo.h>
 #include <command.h>
 #include <console.h>
 #include <asm/global_data.h>
drivers/misc/cbmem_console.c +1 -1
index 8220addd579b..5113e50c53b8 100644
@@ -3,9 +3,9 @@
  * Copyright (C) 2011 The ChromiumOS Authors.  All rights reserved.
  */
 
+#include <cb_sysinfo.h>
 #include <console.h>
 #include <linux/string.h>
-#include <asm/cb_sysinfo.h>
 
 void cbmemc_putc(struct stdio_dev *dev, char data)
 {
drivers/serial/serial_coreboot.c +1 -1
index b1f69f6998cf..1835e333aec0 100644
@@ -7,12 +7,12 @@
 
 #define LOG_CATGEGORY	UCLASS_SERIAL
 
+#include <cb_sysinfo.h>
 #include <dm.h>
 #include <log.h>
 #include <ns16550.h>
 #include <serial.h>
 #include <acpi/acpi_table.h>
-#include <asm/cb_sysinfo.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
drivers/video/coreboot.c +1 -1
index 9aede2626423..ed589cc42bfd 100644
@@ -3,11 +3,11 @@
  * Copyright (C) 2016, Bin Meng <[email protected]>
  */
 
+#include <cb_sysinfo.h>
 #include <dm.h>
 #include <init.h>
 #include <vesa.h>
 #include <video.h>
-#include <asm/cb_sysinfo.h>
 
 static int save_vesa_mode(struct cb_framebuffer *fb,
 			  struct vesa_mode_info *vesa)
include/cb_sysinfo.h renamed from arch/x86/include/asm/cb_sysinfo.h +21 -1
similarity index 94%
rename from arch/x86/include/asm/cb_sysinfo.h
rename to include/cb_sysinfo.h
index 5864b2700cec..62a483e10cef 100644
@@ -8,7 +8,7 @@
 #ifndef _COREBOOT_SYSINFO_H
 #define _COREBOOT_SYSINFO_H
 
-#include <asm/coreboot_tables.h>
+#include <coreboot_tables.h>
 #include <linux/types.h>
 
 /* Maximum number of memory range definitions */
@@ -246,4 +246,24 @@ int get_coreboot_info(struct sysinfo_t *info);
  */
 const struct sysinfo_t *cb_get_sysinfo(void);
 
+/**
+ * coreboot_dram_init_banksize() - Initilize RAM banksize from coreboot sysinfo
+ * table
+ */
+int coreboot_dram_init_banksize(void);
+
+/**
+ * coreboot_dram_init() - Configure available RAM banks from coreboot sysinfo
+ * table
+ */
+int coreboot_dram_init(void);
+
+/**
+ * coreboot_board_get_usable_ram_top() - Get the top of RAM usable by U-Boot
+ * while running as a coreboot payload
+ *
+ * Return: Physical address as the top of RAM
+ */
+phys_addr_t coreboot_board_get_usable_ram_top(phys_size_t total_size);
+
 #endif
include/coreboot_tables.h renamed from arch/x86/include/asm/coreboot_tables.h +0 -0
similarity index 100%
rename from arch/x86/include/asm/coreboot_tables.h
rename to include/coreboot_tables.h
lib/Makefile +2 -0
index a7bc2f3134a7..8fa018a4c941 100644
@@ -141,6 +141,8 @@ obj-$(CONFIG_LIB_UUID) += uuid.o
 obj-$(CONFIG_LIB_RAND) += rand.o
 obj-y += panic.o
 
+obj-$(CONFIG_$(XPL_)COREBOOT_SYSINFO)	+= coreboot/
+
 ifeq ($(CONFIG_XPL_BUILD),y)
 # SPL U-Boot may use full-printf, tiny-printf or none at all
 ifdef CONFIG_$(PHASE_)USE_TINY_PRINTF
lib/coreboot/Kconfig new file +55 -0

55 lines not on this page · raw message

lib/coreboot/Makefile new file +17 -0
new file mode 100644
index 000000000000..0f5cb90a056e
@@ -0,0 +1,17 @@
+# SPDX-License-Identifier: GPL-2.0+
+#
+# Copyright (c) 2011 The Chromium OS Authors.
+#
+# (C) Copyright 2008
+# Graeme Russ, [email protected].
+#
+# (C) Copyright 2006
+# Wolfgang Denk, DENX Software Engineering, [email protected].
+#
+# (C) Copyright 2002
+# Daniel Engström, Omicron Ceti AB, [email protected].
+
+obj-y += cb_sysinfo.o
+ifndef CONFIG_XPL_BUILD
+obj-y += sdram.o
+endif
lib/coreboot/cb_sysinfo.c renamed from arch/x86/lib/coreboot/cb_sysinfo.c +1 -13
similarity index 95%
rename from arch/x86/lib/coreboot/cb_sysinfo.c
rename to lib/coreboot/cb_sysinfo.c
index ec997fa49cf2..f8f2002d46f0 100644
@@ -6,7 +6,7 @@
  * Copyright (C) 2009 coresystems GmbH
  */
 
-#include <asm/cb_sysinfo.h>
+#include <cb_sysinfo.h>
 #include <init.h>
 #include <mapmem.h>
 #include <net.h>
@@ -23,13 +23,6 @@ DECLARE_GLOBAL_DATA_PTR;
  */
 struct sysinfo_t lib_sysinfo __section(".data");
 
-/*
- * Some of this is x86 specific, and the rest of it is generic. Right now,
- * since we only support x86, we'll avoid trying to make lots of infrastructure
- * we don't need. If in the future, we want to use coreboot on some other
- * architecture, then take out the generic parsing code and move it elsewhere.
- */
-
 /* === Parsing code === */
 /* This is the generic parsing code */
 
@@ -453,9 +446,6 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 	return 1;
 }
 
-/* == Architecture specific == */
-/* This is the x86 specific stuff */
-
 int get_coreboot_info(struct sysinfo_t *info)
 {
 	long addr;
@@ -470,8 +460,6 @@ int get_coreboot_info(struct sysinfo_t *info)
 	if (!ret)
 		return -ENOENT;
 	gd->arch.coreboot_table = addr;
-	gd_set_acpi_start(map_to_sysmem(info->rsdp));
-	gd_set_smbios_start(info->smbios_start);
 	gd->flags |= GD_FLG_SKIP_LL_INIT;
 
 	return 0;
lib/coreboot/sdram.c renamed from arch/x86/cpu/coreboot/sdram.c +4 -11
similarity index 87%
copy from arch/x86/cpu/coreboot/sdram.c
copy to lib/coreboot/sdram.c
index 013225f129a9..ac9a95b1d378 100644
@@ -6,18 +6,11 @@
  */
 
 #include <init.h>
-#include <asm/e820.h>
-#include <asm/cb_sysinfo.h>
+#include <cb_sysinfo.h>
 #include <asm/global_data.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
-unsigned int install_e820_map(unsigned int max_entries,
-			      struct e820_entry *entries)
-{
-	return cb_install_e820_map(max_entries, entries);
-}
-
 /*
  * This function looks for the highest region of memory lower than 4GB which
  * has enough space for U-Boot where U-Boot is aligned on a page boundary. It
@@ -26,7 +19,7 @@ unsigned int install_e820_map(unsigned int max_entries,
  * address, and how far U-Boot is moved by relocation are set in the global
  * data structure.
  */
-phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
+phys_addr_t coreboot_board_get_usable_ram_top(phys_size_t total_size)
 {
 	uintptr_t dest_addr = 0;
 	int i;
@@ -60,7 +53,7 @@ phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
 	return (ulong)dest_addr;
 }
 
-int dram_init(void)
+int coreboot_dram_init(void)
 {
 	int i;
 	phys_size_t ram_size = 0;
@@ -80,7 +73,7 @@ int dram_init(void)
 	return 0;
 }
 
-int dram_init_banksize(void)
+int coreboot_dram_init_banksize(void)
 {
 	int i, j;
 
Signature · 1 line
Sent by a computer, using git, on the internet
#9 lore raw

PATCH v2 6/15 arm: Support running U-Boot as a coreboot payload on ARM64

In reply to Stephen Boyd

Add a 'coreboot' cpu to armv8 that looks for the coreboot table near the top of the 4G address space.

---
 arch/arm/cpu/armv8/Makefile          |  1 +
 arch/arm/cpu/armv8/coreboot/Makefile |  4 ++++
 arch/arm/cpu/armv8/coreboot/cpu.c    | 33 ++++++++++++++++++++++++++++
 arch/arm/include/asm/global_data.h   |  3 +++
 arch/x86/cpu/cpu.c                   | 13 -----------
 include/cb_sysinfo.h                 |  7 ++++++
 lib/coreboot/Kconfig                 | 14 ++++++------
 lib/coreboot/cb_sysinfo.c            | 13 +++++++++++
 8 files changed, 68 insertions(+), 20 deletions(-)
 create mode 100644 arch/arm/cpu/armv8/coreboot/Makefile
 create mode 100644 arch/arm/cpu/armv8/coreboot/cpu.c
arch/arm/cpu/armv8/Makefile +1 -0
index b4126c61df15..39258a07db6c 100644
@@ -48,3 +48,4 @@ obj-$(CONFIG_ARMV8_CE_SHA1) += sha1_ce_glue.o sha1_ce_core.o
 obj-$(CONFIG_ARMV8_CE_SHA256) += sha256_ce_glue.o sha256_ce_core.o
 
 obj-$(CONFIG_SYSINFO_SMBIOS) += sysinfo.o
+obj-$(CONFIG_SYS_COREBOOT) += coreboot/
arch/arm/cpu/armv8/coreboot/Makefile new file +4 -0
new file mode 100644
index 000000000000..0eca9ff05900
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0+
+
+obj-y += cpu.o
+
arch/arm/cpu/armv8/coreboot/cpu.c new file +33 -0
new file mode 100644
index 000000000000..05ceff967989
@@ -0,0 +1,33 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <cb_sysinfo.h>
+#include <linux/errno.h>
+#include <linux/sizes.h>
+#include <log.h>
+
+long locate_coreboot_table(void)
+{
+	long addr;
+
+	/*
+	 * We look for LBIO somewhere inside the CBMEM arena, which is
+	 * typically at the top of the first 4G of RAM.
+	 */
+	addr = detect_coreboot_table_at(SZ_4G - SZ_8M, SZ_8M);
+	if (addr < 0)
+		return -ENOENT;
+
+	debug("Located coreboot table at %#lx\n", addr);
+	return addr;
+}
+
+int arch_cpu_init(void)
+{
+	int ret;
+
+	ret = get_coreboot_info(&lib_sysinfo);
+	if (ret != 0)
+		debug("Failed to parse coreboot tables.\n");
+
+	return 0;
+}
arch/arm/include/asm/global_data.h +3 -0
index 45401d5e3c8a..70299aec2df4 100644
@@ -108,6 +108,9 @@ struct arch_global_data {
 #ifdef CONFIG_SMBIOS
 	ulong smbios_start;		/* Start address of SMBIOS table */
 #endif
+#ifdef CONFIG_SYS_COREBOOT
+	ulong coreboot_table;		/* Address of coreboot table */
+#endif
 };
 
 #include <asm-generic/global_data.h>
arch/x86/cpu/cpu.c +0 -13
index 9ac2a6bf4a09..704a00e26045 100644
@@ -340,19 +340,6 @@ int reserve_arch(void)
 }
 #endif
 
-static long detect_coreboot_table_at(ulong start, ulong size)
-{
-	u32 *ptr, *end;
-
-	size /= 4;
-	for (ptr = (void *)start, end = ptr + size; ptr < end; ptr += 4) {
-		if (*ptr == 0x4f49424c) /* "LBIO" */
-			return (long)ptr;
-	}
-
-	return -ENOENT;
-}
-
 long locate_coreboot_table(void)
 {
 	long addr;
include/cb_sysinfo.h +7 -0
index 62a483e10cef..3bd997dcca39 100644
@@ -228,6 +228,13 @@ struct sysinfo_t {
 
 extern struct sysinfo_t lib_sysinfo;
 
+/**
+ * detect_coreboot_table_at() - Helper to find coreboot table
+ *
+ * Return: Address of coreboot table or -ENOENT on failure
+ */
+long detect_coreboot_table_at(ulong start, ulong size);
+
 /**
  * get_coreboot_info() - parse the coreboot sysinfo table
  *
lib/coreboot/Kconfig +7 -7
index 870693dca66c..eb686ac3c69f 100644
@@ -1,9 +1,9 @@
 menu "U-Boot as Coreboot payload"
-	depends on VENDOR_COREBOOT
+	depends on ARM64 || VENDOR_COREBOOT
 
 config SYS_COREBOOT
-	bool
-	default y
+	bool "Support for booting u-boot as a coreboot payload" if ARM64
+	default VENDOR_COREBOOT
 	imply SYS_NS16550
 	imply SCSI
 	imply SCSI_AHCI
@@ -17,15 +17,15 @@ config SYS_COREBOOT
 	imply USB_XHCI_HCD
 	imply USB_STORAGE
 	imply USB_KEYBOARD
-	imply VIDEO_COREBOOT
-	imply E1000
+	imply VIDEO_COREBOOT if x86
+	imply E1000 if x86
 	imply ETH_DESIGNWARE
-	imply PCH_GBE
+	imply PCH_GBE if X86
 	imply RTL8169
 	imply CMD_CBFS
 	imply FS_CBFS
 	imply CBMEM_CONSOLE
-	imply X86_TSC_READ_BASE
+	imply X86_TSC_READ_BASE if X86
 	imply USE_PREBOOT
 	select BINMAN if X86_64
 	select SYSINFO
lib/coreboot/cb_sysinfo.c +13 -0
index f8f2002d46f0..36cd352818a2 100644
@@ -446,6 +446,19 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 	return 1;
 }
 
+long detect_coreboot_table_at(ulong start, ulong size)
+{
+	u32 *ptr, *end;
+
+	size /= 4;
+	for (ptr = (void *)start, end = ptr + size; ptr < end; ptr += 4) {
+		if (*ptr == 0x4f49424c) /* "LBIO" */
+			return (long)ptr;
+	}
+
+	return -ENOENT;
+}
+
 int get_coreboot_info(struct sysinfo_t *info)
 {
 	long addr;
Signature · 1 line
Sent by a computer, using git, on the internet
#11 lore raw

PATCH v2 7/15 cmd/cbsysinfo: Skip the CMOS 'option_table' when not present

In reply to Stephen Boyd

The CMOS 'option_table' isn't populated on ARM devices running coreboot. Check to see if the pointer is NULL and bail out if it is.

---
 cmd/x86/cbsysinfo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
cmd/x86/cbsysinfo.c +1 -1
index 3936d30da0e1..ed7b50f6d0fc 100644
@@ -224,7 +224,7 @@ static void show_option_table(const struct cb_cmos_option_table *tab)
 	const void *ptr, *end;
 
 	print_ptr("option_table", tab);
-	if (!tab->size)
+	if (!tab || !tab->size)
 		return;
 
 	printf(" Bit  Len  Cfg  ID  Name\n");
Signature · 1 line
Sent by a computer, using git, on the internet
#12 lore raw

PATCH v2 8/15 cmd/cbsysinfo: Allow on ARM as well

In reply to Stephen Boyd

This command isn't x86 specific. Move it up one level so that it can be used on a platform that can find the coreboot table, i.e. x86 or ARM.

---
 cmd/Kconfig               | 4 ++--
 cmd/Makefile              | 1 +
 cmd/{x86 => }/cbsysinfo.c | 0
 cmd/x86/Makefile          | 1 -
 4 files changed, 3 insertions(+), 3 deletions(-)
 rename cmd/{x86 => }/cbsysinfo.c (100%)
cmd/Kconfig +2 -2
index a04fcaa0e08b..aa6e91455653 100644
@@ -2905,8 +2905,8 @@ menu "Debug commands"
 
 config CMD_CBSYSINFO
 	bool "cbsysinfo"
-	depends on X86
-	default y if SYS_COREBOOT
+	depends on SYS_COREBOOT
+	default y
 	help
 	  This provides information about the coreboot sysinfo table stored in
 	  memory by coreboot before jumping to U-Boot. It can be useful for
cmd/Makefile +1 -0
index 8410be576bb0..2e8034e9c5fd 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_CMD_BUTTON) += button.o
 obj-$(CONFIG_CMD_CAT) += cat.o
 obj-$(CONFIG_CMD_CACHE) += cache.o
 obj-$(CONFIG_CMD_CBFS) += cbfs.o
+obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o
 obj-$(CONFIG_CMD_CEDIT) += cedit.o
 obj-$(CONFIG_CMD_CLK) += clk.o
 obj-$(CONFIG_CMD_CLS) += cls.o
cmd/cbsysinfo.c renamed from cmd/x86/cbsysinfo.c +0 -0
similarity index 100%
rename from cmd/x86/cbsysinfo.c
rename to cmd/cbsysinfo.c
cmd/x86/Makefile +0 -1
index 5f3f5be2882f..870e941dcf00 100644
@@ -1,6 +1,5 @@
 # SPDX-License-Identifier: GPL-2.0+
 
-obj-$(CONFIG_CMD_CBSYSINFO) += cbsysinfo.o
 obj-y += cpuid.o msr.o mtrr.o
 obj-$(CONFIG_CMD_CBCMOS) += cbcmos.o
 obj-$(CONFIG_CMD_EXCEPTION) += exception.o
Signature · 1 line
Sent by a computer, using git, on the internet
Reviewed-by on v2 8/15
#13 lore raw

Re: [PATCH v2 08/15] cmd/cbsysinfo: Allow on ARM as well

Quoted 4 lines · Stephen Boyd

This command isn't x86 specific. Move it up one level so that it can be used on a platform that can find the coreboot table, i.e. x86 or ARM.

Signature · 1 line
Tom
#14 lore raw

PATCH v2 9/15 coreboot: Parse sku_id/fw_config from coreboot tables

In reply to Stephen Boyd

The SKU ID is part of the coreboot tables. Historically, it was under the coreboot tag for sku_id specifically, but modern coreboot versions have put all the ID values together in one entry CB_TAG_BOARD_CONFIG along with fw_config. Parse that tag to populate the sku_id and fw_config fields.

---
 cmd/cbsysinfo.c           |  2 ++
 include/cb_sysinfo.h      |  4 ++++
 include/coreboot_tables.h | 11 +++++++++++
 lib/coreboot/cb_sysinfo.c | 15 +++++++++++++++
 4 files changed, 32 insertions(+)
cmd/cbsysinfo.c +2 -0
index ed7b50f6d0fc..d6ab71a3db8d 100644
@@ -418,6 +418,8 @@ static void show_table(struct sysinfo_t *info, bool verbose)
 	print_ptr("MRC cache", info->mrc_cache);
 	print_ptr("ACPI GNVS", info->acpi_gnvs);
 	print_hex("Board ID", info->board_id);
+	print_hex("SKU ID", info->sku_id);
+	print_addr64("FWCONFIG", info->fw_config);
 	print_hex("RAM code", info->ram_code);
 	print_ptr("WiFi calib", info->wifi_calibration);
 	print_addr64("Ramoops buff", info->ramoops_buffer);
include/cb_sysinfo.h +4 -0
index 3bd997dcca39..604a276ea72b 100644
@@ -114,6 +114,8 @@
  * acpi_gnvs: @Pointer to Intel Global NVS struct, see struct acpi_global_nvs
  * @board_id: Board ID indicating the board variant, typically 0xffffffff
  * @ram_code: RAM code indicating the SDRAM type, typically 0xffffffff
+ * @sku_id: SKU ID indicating the board SKU, typically 0xffffffff
+ * @fw_config: FW config indicating the firmware configuration, typically 0xffffffff
  * @wifi_calibration: WiFi calibration info, NULL if none
  * @ramoops_buffer: Address of kernel Ramoops buffer
  * @ramoops_buffer_size: Sizeof of Ramoops buffer, typically 1MB
@@ -204,6 +206,8 @@ struct sysinfo_t {
 	void		*acpi_gnvs;
 	u32		board_id;
 	u32		ram_code;
+	u32		sku_id;
+	u64		fw_config;
 	void		*wifi_calibration;
 	u64	ramoops_buffer;
 	u32	ramoops_buffer_size;
include/coreboot_tables.h +11 -0
index 54aeffb9889d..6e7686e360c5 100644
@@ -438,6 +438,17 @@ struct cb_tsc_info {
 #define CB_TAG_SERIALNO			0x002a
 #define CB_MAX_SERIALNO_LENGTH		32
 
+#define CB_TAG_BOARD_CONFIG		0x0040
+struct cb_board_config {
+	u32 tag;
+	u32 size;
+
+	u64 fw_config;
+	u32 board_id;
+	u32 ram_code;
+	u32 sku_id;
+};
+
 #define CB_TAG_ACPI_RSDP		0x0043
 
 #define CB_TAG_CMOS_OPTION_TABLE	0x00c8
lib/coreboot/cb_sysinfo.c +15 -0
index 36cd352818a2..67497d4d65b4 100644
@@ -141,6 +141,16 @@ static void cb_parse_acpi_gnvs(unsigned char *ptr, struct sysinfo_t *info)
 	info->acpi_gnvs = map_sysmem(cbmem->cbmem_tab, 0);
 }
 
+static void cb_parse_board_config(unsigned char *ptr, struct sysinfo_t *info)
+{
+	struct cb_board_config *const cbbcfg = (struct cb_board_config *)ptr;
+
+	info->board_id = cbbcfg->board_id;
+	info->ram_code = cbbcfg->ram_code;
+	info->sku_id = cbbcfg->sku_id;
+	info->fw_config = cbbcfg->fw_config;
+}
+
 static void cb_parse_board_id(unsigned char *ptr, struct sysinfo_t *info)
 {
 	struct cb_board_id *const cbbid = (struct cb_board_id *)ptr;
@@ -295,6 +305,8 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 	 */
 	info->board_id = ~0;
 	info->ram_code = ~0;
+	info->sku_id = ~0;
+	info->fw_config = ~0ULL;
 
 	/* Now, walk the tables */
 	ptr += header->header_bytes;
@@ -395,6 +407,9 @@ static int cb_parse_header(void *addr, int len, struct sysinfo_t *info)
 		case CB_TAG_CBMEM_ENTRY:
 			cb_parse_cbmem_entry(ptr, info);
 			break;
+		case CB_TAG_BOARD_CONFIG:
+			cb_parse_board_config(ptr, info);
+			break;
 		case CB_TAG_BOARD_ID:
 			cb_parse_board_id(ptr, info);
 			break;
Signature · 1 line
Sent by a computer, using git, on the internet
#15 lore raw

PATCH v2 10/15 pstore: Add pstore address from coreboot tables

In reply to Stephen Boyd

Set the pstore address and size based on the coreboot tables if the coreboot tables are populated.

---
 cmd/pstore.c | 44 +++++++++++++++++++++++++++++++++++---------
 1 file changed, 35 insertions(+), 9 deletions(-)
cmd/pstore.c +35 -9
index 9795eea2dbc3..dccbf455e299 100644
@@ -3,8 +3,10 @@
  * Copyright © 2019 Collabora Ltd
  */
 
+#include <cb_sysinfo.h>
 #include <config.h>
 #include <command.h>
+#include <event.h>
 #include <fdtdec.h>
 #include <fs.h>
 #include <log.h>
@@ -141,6 +143,19 @@ static void pstore_init_buffer_size(void)
 		buffer_size = pstore_pmsg_size;
 }
 
+static void pstore_set_end(void)
+{
+	if (pstore_length < (pstore_record_size + pstore_console_size
+			     + pstore_ftrace_size + pstore_pmsg_size)) {
+		printf("pstore <len> should be larger than the sum of all records sizes\n");
+		pstore_length = 0;
+	}
+
+	log_debug("pstore set done: start 0x%08llx - length 0x%llx\n",
+		  (unsigned long long)pstore_addr,
+		  (unsigned long long)pstore_length);
+}
+
 /**
  * pstore_set() - Initialize PStore settings from command line arguments
  * @cmdtp: Command data struct pointer
@@ -194,19 +209,30 @@ static int pstore_set(struct cmd_tbl *cmdtp, int flag,  int argc,
 	if (argc > 7)
 		pstore_ecc_size = hextoul(argv[7], NULL);
 
-	if (pstore_length < (pstore_record_size + pstore_console_size
-			     + pstore_ftrace_size + pstore_pmsg_size)) {
-		printf("pstore <len> should be larger than the sum of all records sizes\n");
-		pstore_length = 0;
-	}
-
-	log_debug("pstore set done: start 0x%08llx - length 0x%llx\n",
-	          (unsigned long long)pstore_addr,
-	          (unsigned long long)pstore_length);
+	pstore_set_end();
 
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(SYS_COREBOOT)
+static int pstore_coreboot_init(void)
+{
+	const struct sysinfo_t *sysinfo;
+
+	sysinfo = cb_get_sysinfo();
+	if (!sysinfo)
+		return 0;
+
+	pstore_addr = sysinfo->ramoops_buffer;
+	pstore_length = sysinfo->ramoops_buffer_size;
+
+	pstore_set_end();
+
+	return 0;
+}
+EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, pstore_coreboot_init);
+#endif
+
 /**
  * pstore_print_buffer() - Print buffer
  * @type: buffer type
Signature · 1 line
Sent by a computer, using git, on the internet
#16 lore raw

PATCH v2 11/15 coreboot: Add /firmware/coreboot node to DT

In reply to Stephen Boyd

Populate the firmware node with a coreboot node detailing where the coreboot tables and CBMEM area are located.

---
 boot/image-fdt.c          |   4 ++
 include/cb_sysinfo.h      |   7 +++
 lib/coreboot/cb_sysinfo.c | 120 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 131 insertions(+)
boot/image-fdt.c +4 -0
index 9d1598b1a93c..d23d5438c0fa 100644
@@ -8,6 +8,7 @@
  * Wolfgang Denk, DENX Software Engineering, [email protected].
  */
 
+#include <cb_sysinfo.h>
 #include <command.h>
 #include <fdt_support.h>
 #include <fdtdec.h>
@@ -618,6 +619,9 @@ int image_setup_libfdt(struct bootm_headers *images, void *blob, bool lmb)
 #if IS_ENABLED(CONFIG_CMD_PSTORE)
 	/* Append PStore configuration */
 	fdt_fixup_pstore(blob);
+#endif
+#if CONFIG_IS_ENABLED(SYS_COREBOOT)
+	fdt_fixup_coreboot(blob);
 #endif
 	if (IS_ENABLED(CONFIG_OF_BOARD_SETUP)) {
 		const char *skip_board_fixup;
include/cb_sysinfo.h +7 -0
index 604a276ea72b..ad08a01a81d5 100644
@@ -257,6 +257,13 @@ int get_coreboot_info(struct sysinfo_t *info);
  */
 const struct sysinfo_t *cb_get_sysinfo(void);
 
+/**
+ * fdt_fixup_coreboot() - Add the /firmware/coreboot node to the FDT
+ *
+ * Add the /firmware/coreboot node to the FDT if U-Boot is a coreboot payload.
+ */
+void fdt_fixup_coreboot(void *blob);
+
 /**
  * coreboot_dram_init_banksize() - Initilize RAM banksize from coreboot sysinfo
  * table
lib/coreboot/cb_sysinfo.c +120 -0

129 lines not on this page · raw message

Signature · 1 line
Sent by a computer, using git, on the internet
#17 lore raw

PATCH v2 12/15 coreboot: Move timestamp parsing to generic place

In reply to Stephen Boyd

Move the timestamp code out of x86/cpu/coreboot to lib/coreboot and make it generic. This lets us migrate the timestamp table from coreboot into U-Boot's version of boot stage timing and use it on ARM based devices.

---
 arch/x86/cpu/coreboot/Makefile                      |  1 -
 arch/x86/cpu/coreboot/coreboot.c                    |  6 +-----
 arch/x86/lib/bootm.c                                |  5 ++---
 arch/x86/lib/zimage.c                               |  3 ---
 .../timestamp.h => include/coreboot_timestamp.h     |  7 -------
 lib/coreboot/Makefile                               |  1 +
 lib/coreboot/cb_sysinfo.c                           |  3 +++
 {arch/x86/cpu => lib}/coreboot/timestamp.c          | 13 ++++++++-----
 8 files changed, 15 insertions(+), 24 deletions(-)
 rename arch/x86/include/asm/arch-coreboot/timestamp.h => include/coreboot_timestamp.h (68%)
 rename {arch/x86/cpu => lib}/coreboot/timestamp.c (84%)
arch/x86/cpu/coreboot/Makefile +0 -1
index a6c7d0e56d50..f7ba346b83cd 100644
@@ -20,4 +20,3 @@ else
 obj-y += sdram.o
 endif
 obj-y += coreboot.o
-obj-y += timestamp.o
arch/x86/cpu/coreboot/coreboot.c +1 -5
index a092e8a27027..4e253c10726b 100644
@@ -6,6 +6,7 @@
  */
 
 #include <cb_sysinfo.h>
+#include <coreboot_timestamp.h>
 #include <cpu_func.h>
 #include <event.h>
 #include <fdtdec.h>
@@ -15,7 +16,6 @@
 #include <asm/io.h>
 #include <asm/msr.h>
 #include <asm/mtrr.h>
-#include <asm/arch/timestamp.h>
 #include <dm/ofnode.h>
 
 int arch_cpu_init(void)
@@ -35,8 +35,6 @@ int arch_cpu_init(void)
 	gd_set_acpi_start(map_to_sysmem(lib_sysinfo.rsdp));
 	gd_set_smbios_start(lib_sysinfo.smbios_start);
 
-	timestamp_init();
-
 	return 0;
 }
 
@@ -74,8 +72,6 @@ static void board_final_init(void)
 
 static int last_stage_init(void)
 {
-	timestamp_add_to_bootstage();
-
 	if (IS_ENABLED(CONFIG_XPL_BUILD))
 		return 0;
 
arch/x86/lib/bootm.c +2 -3
index 0827a884b1d2..f46d78946929 100644
@@ -10,6 +10,8 @@
 #include <bootm.h>
 #include <bootstage.h>
 #include <command.h>
+#include <coreboot_tables.h>
+#include <coreboot_timestamp.h>
 #include <efi.h>
 #include <hang.h>
 #include <log.h>
@@ -24,9 +26,6 @@
 #include <asm/cpu.h>
 #include <asm/byteorder.h>
 #include <asm/zimage.h>
-#ifdef CONFIG_SYS_COREBOOT
-#include <asm/arch/timestamp.h>
-#endif
 
 DECLARE_GLOBAL_DATA_PTR;
 
arch/x86/lib/zimage.c +0 -3
index 2eece34a073c..5e74fd46ace7 100644
@@ -31,9 +31,6 @@
 #include <asm/bootparam.h>
 #include <asm/efi.h>
 #include <asm/global_data.h>
-#ifdef CONFIG_SYS_COREBOOT
-#include <asm/arch/timestamp.h>
-#endif
 #include <linux/compiler.h>
 #include <linux/ctype.h>
 #include <linux/libfdt.h>
include/coreboot_timestamp.h renamed from arch/x86/include/asm/arch-coreboot/timestamp.h +0 -7
similarity index 68%
rename from arch/x86/include/asm/arch-coreboot/timestamp.h
rename to include/coreboot_timestamp.h
index 227316975047..8f34d801037d 100644
@@ -14,11 +14,4 @@ void timestamp_init(void);
 void timestamp_add(enum timestamp_id id, uint64_t ts_time);
 void timestamp_add_now(enum timestamp_id id);
 
-/**
- * timestamp_add_to_bootstage - Add important coreboot timestamps to bootstage
- *
- * Return: 0 if ok, -1 if no timestamps were found
- */
-int timestamp_add_to_bootstage(void);
-
 #endif
lib/coreboot/Makefile +1 -0
index 0f5cb90a056e..daeebc6654e3 100644
@@ -15,3 +15,4 @@ obj-y += cb_sysinfo.o
 ifndef CONFIG_XPL_BUILD
 obj-y += sdram.o
 endif
+obj-y += timestamp.o
lib/coreboot/cb_sysinfo.c +3 -0
index 7226b658c0d3..85348df4407b 100644
@@ -7,6 +7,7 @@
  */
 
 #include <cb_sysinfo.h>
+#include <coreboot_timestamp.h>
 #include <fdt_support.h>
 #include <init.h>
 #include <mapmem.h>
@@ -491,6 +492,8 @@ int get_coreboot_info(struct sysinfo_t *info)
 	gd->arch.coreboot_table = addr;
 	gd->flags |= GD_FLG_SKIP_LL_INIT;
 
+	timestamp_init();
+
 	return 0;
 }
 
lib/coreboot/timestamp.c renamed from arch/x86/cpu/coreboot/timestamp.c +8 -5
similarity index 84%
rename from arch/x86/cpu/coreboot/timestamp.c
rename to lib/coreboot/timestamp.c
index 18be969ccea6..192a28d7188a 100644
@@ -7,10 +7,12 @@
 
 #include <bootstage.h>
 #include <cb_sysinfo.h>
+#include <coreboot_tables.h>
+#include <coreboot_timestamp.h>
+#include <event.h>
 #include <errno.h>
-#include <asm/arch/timestamp.h>
-#include <asm/u-boot-x86.h>
 #include <linux/compiler.h>
+#include <time.h>
 
 void timestamp_init(void)
 {
@@ -33,10 +35,10 @@ void timestamp_add(enum timestamp_id id, uint64_t ts_time)
 
 void timestamp_add_now(enum timestamp_id id)
 {
-	timestamp_add(id, rdtsc());
+	timestamp_add(id, get_ticks());
 }
 
-int timestamp_add_to_bootstage(void)
+static int timestamp_add_to_bootstage(void)
 {
 	const struct sysinfo_t *info = cb_get_sysinfo();
 	const struct timestamp_table *ts_table = info->tstamp_table;
@@ -69,9 +71,10 @@ int timestamp_add_to_bootstage(void)
 		if (name) {
 			bootstage_add_record(0, name, BOOTSTAGEF_ALLOC,
 					     tse->entry_stamp /
-							get_tbclk_mhz());
+							(get_tbclk() / 1000000));
 		}
 	}
 
 	return 0;
 }
+EVENT_SPY_SIMPLE(EVT_LAST_STAGE_INIT, timestamp_add_to_bootstage);
Signature · 1 line
Sent by a computer, using git, on the internet
#18 lore raw

PATCH v2 13/15 mach-snapdragon: Support booting as a coreboot payload

In reply to Stephen Boyd

Coreboot sets up the DRAM, CPU, and devices before booting a payload, meaning we can parse the coreboot tables at boot for memory info when running as a payload. Use the memory descriptors from coreboot if the tables are present so that Snapdragon SoCs can run U-boot as a coreboot payload.

---
 arch/arm/mach-snapdragon/board.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
arch/arm/mach-snapdragon/board.c +18 -0
index 2ef936aab757..cb3df1c2adec 100644
@@ -14,6 +14,7 @@
 #include <asm/io.h>
 #include <asm/psci.h>
 #include <asm/system.h>
+#include <cb_sysinfo.h>
 #include <dm/device.h>
 #include <dm/pinctrl.h>
 #include <dm/uclass-internal.h>
@@ -48,6 +49,10 @@ static struct {
 
 int dram_init(void)
 {
+#ifdef CONFIG_SYS_COREBOOT
+	if (gd->arch.coreboot_table)
+		return coreboot_dram_init();
+#endif
 	/*
 	 * gd->ram_base / ram_size have been setup already
 	 * in qcom_parse_memory().
@@ -81,8 +86,21 @@ static void qcom_configure_bi_dram(void)
 	}
 }
 
+phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
+{
+#ifdef CONFIG_SYS_COREBOOT
+	if (gd->arch.coreboot_table)
+		return coreboot_board_get_usable_ram_top(total_size);
+#endif
+	return gd->ram_top;
+}
+
 int dram_init_banksize(void)
 {
+#ifdef CONFIG_SYS_COREBOOT
+	if (gd->arch.coreboot_table)
+		return coreboot_dram_init_banksize();
+#endif
 	qcom_configure_bi_dram();
 
 	return 0;
Signature · 1 line
Sent by a computer, using git, on the internet
Reviewed-by on v2 13/15
#19 lore raw

Re: [PATCH v2 13/15] mach-snapdragon: Support booting as a coreboot payload

Quoted 7 lines · Stephen Boyd

Coreboot sets up the DRAM, CPU, and devices before booting a payload, meaning we can parse the coreboot tables at boot for memory info when running as a payload. Use the memory descriptors from coreboot if the tables are present so that Snapdragon SoCs can run U-boot as a coreboot payload.

Quoted 49 lines
---
  arch/arm/mach-snapdragon/board.c | 18 ++++++++++++++++++
  1 file changed, 18 insertions(+)
arch/arm/mach-snapdragon/board.c +18 -0
index 2ef936aab757..cb3df1c2adec 100644
@@ -14,6 +14,7 @@
  #include <asm/io.h>
  #include <asm/psci.h>
  #include <asm/system.h>
+#include <cb_sysinfo.h>
  #include <dm/device.h>
  #include <dm/pinctrl.h>
  #include <dm/uclass-internal.h>
@@ -48,6 +49,10 @@ static struct {
 
  int dram_init(void)
  {
+#ifdef CONFIG_SYS_COREBOOT
+	if (gd->arch.coreboot_table)
+		return coreboot_dram_init();
+#endif
  	/*
  	 * gd->ram_base / ram_size have been setup already
  	 * in qcom_parse_memory().
@@ -81,8 +86,21 @@ static void qcom_configure_bi_dram(void)
  	}
  }
 
+phys_addr_t board_get_usable_ram_top(phys_size_t total_size)
+{
+#ifdef CONFIG_SYS_COREBOOT
+	if (gd->arch.coreboot_table)
+		return coreboot_board_get_usable_ram_top(total_size);
+#endif
+	return gd->ram_top;
+}
+
  int dram_init_banksize(void)
  {
+#ifdef CONFIG_SYS_COREBOOT
+	if (gd->arch.coreboot_table)
+		return coreboot_dram_init_banksize();
+#endif
  	qcom_configure_bi_dram();
 
  	return 0;
Signature · 1 line
Caleb (they/them)
#20 lore raw

PATCH v2 14/15 cmd: ximg: Support LZO compressed images

In reply to Stephen Boyd

Add support to decompress LZO images.

---
 cmd/ximg.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
cmd/ximg.c +15 -0
index 29d7c3279b39..a6341a078019 100644
@@ -14,6 +14,9 @@
 #include <cpu_func.h>
 #include <env.h>
 #include <gzip.h>
+#if IS_ENABLED(CONFIG_LZO)
+#include <linux/lzo.h>
+#endif
 #if IS_ENABLED(CONFIG_ZSTD)
 #include <linux/zstd.h>
 #endif
@@ -238,6 +241,18 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			}
 			break;
 #endif /* CONFIG_BZIP2 */
+#if IS_ENABLED(CONFIG_LZO)
+		case IH_COMP_LZO:
+			{
+				int ret;
+				size_t size = unc_len;
+				printf("   Uncompressing part %d ... ", part);
+
+				ret = lzop_decompress((void *)data, len, (void *)dest, &size);
+				len = size;
+			}
+			break;
+#endif /* CONFIG_LZO */
 #if IS_ENABLED(CONFIG_ZSTD)
 		case IH_COMP_ZSTD:
 			{
Signature · 1 line
Sent by a computer, using git, on the internet
#22 lore raw

PATCH v2 15/15 cmd: ximg: Support LZ4 compressed images

In reply to Stephen Boyd

Add support to decompress LZ4 images. LZ4 is used on more recent Chromebooks to store the FIT image.

---
 cmd/ximg.c | 13 +++++++++++++
 1 file changed, 13 insertions(+)
cmd/ximg.c +13 -0
index a6341a078019..eed66c776d12 100644
@@ -30,6 +30,7 @@
 #include <asm/byteorder.h>
 #include <asm/cache.h>
 #include <asm/io.h>
+#include <u-boot/lz4.h>
 
 static int
 do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
@@ -253,6 +254,18 @@ do_imgextract(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
 			}
 			break;
 #endif /* CONFIG_LZO */
+#if IS_ENABLED(CONFIG_LZ4)
+		case IH_COMP_LZ4:
+			{
+				int ret;
+				size_t size = unc_len;
+				printf("   Uncompressing part %d ... ", part);
+
+				ret = ulz4fn((void *)data, len, (void *)dest, &size);
+				len = size;
+			}
+			break;
+#endif /* CONFIG_LZ4 */
 #if IS_ENABLED(CONFIG_ZSTD)
 		case IH_COMP_ZSTD:
 			{
Signature · 1 line
Sent by a computer, using git, on the internet