x86: coral: Add support for Cr50
Subsystems (8)
v2 cover x86: coral: Add support for Cr50
This series adds a driver for the Cr50 security chip and enables it on coral. This supports the 'tpm' command.
In order to make this work a few other changes are included:
- Additional UCLASS_IRQ operations to support requesting and reading interrupts, using the device tree
- A driver for ACPI general-purpose events
There are also a few small clean-ups to the recently landed Apollo Lake support.
This series relies on this patch:
http://patchwork.ozlabs.org/patch/1214541/
Changes in v2:
- Add new patch to allow iterating devices without uclass_get()
- Add new patch to find a device by drvdata
- Add new patch to change syscon to use helper function
- Add new patch to change tegra driver to use helper function
- Move intel-clock.h inclusion to the correct patch
- Move 'success' comment into this patch
- Update to use the new DM helper function
- Move 'success' comment into previous patch
- Move intel-clock.h inclusion to the correct patch
- Significant rewrite of cr50 init procedure
- Support use of interrupts
- Update the commit message
- Add new patches to handle requesting interrupts and interrupt state
Simon Glass (17):
dm: core: Allow iterating devices without uclass_get()
dm: core: Add a function to find a device by drvdata
dm: core: Change syscon to use helper function
tegra: i2c: Change driver to use helper function
x86: Add a clock driver for Intel devices
x86: apl: Use the clock driver
x86: apl: Drop the I2C config in FSP-S
x86: coral: Update i2c and rtc status
dm: irq: Add support for interrupt controller types
x86: Give each driver an IRQ type
x86: itss: Add of-platdata support
dm: irq: Add support for requesting interrupts
x86: Add support for ACPI general-purpose events
x86: coral: Add I2C and TPM device-tree definitions
tpm: Add more TPM2 definitions
tpm: Add a driver for H1/Cr50
x86: coral: Enable TPM
arch/sandbox/dts/test.dts | 5 +- arch/sandbox/include/asm/test.h | 4 + arch/x86/Kconfig | 33 + arch/x86/cpu/Makefile | 1 + arch/x86/cpu/acpi_gpe.c | 85 +++ arch/x86/cpu/apollolake/Kconfig | 4 + arch/x86/cpu/apollolake/fsp_s.c | 62 +- arch/x86/cpu/i386/interrupt.c | 3 +- arch/x86/cpu/intel_common/itss.c | 12 +- arch/x86/cpu/irq.c | 3 +- arch/x86/dts/chromebook_coral.dts | 93 +++ configs/chromebook_coral_defconfig | 3 +- doc/board/google/chromebook_coral.rst | 2 - .../interrupt-controller/intel,acpi-gpe.txt | 30 + .../interrupt-controller/interrupts.txt | 131 ++++ drivers/clk/Kconfig | 10 + drivers/clk/Makefile | 1 + drivers/clk/intel/Makefile | 6 + drivers/clk/intel/clk_intel.c | 41 ++ drivers/core/syscon-uclass.c | 15 +- drivers/core/uclass.c | 17 + drivers/i2c/tegra_i2c.c | 13 +- drivers/misc/irq-uclass.c | 131 +++- drivers/misc/irq_sandbox.c | 43 +- drivers/pinctrl/intel/pinctrl.c | 2 +- drivers/tpm/Kconfig | 10 + drivers/tpm/Makefile | 1 + drivers/tpm/cr50_i2c.c | 661 ++++++++++++++++++ include/dm/test.h | 2 + include/dm/uclass.h | 31 + include/dt-bindings/clock/intel-clock.h | 15 + include/irq.h | 138 ++++ include/tpm-v2.h | 31 + test/dm/irq.c | 45 ++ test/dm/test-fdt.c | 42 ++ 35 files changed, 1633 insertions(+), 93 deletions(-) create mode 100644 arch/x86/cpu/acpi_gpe.c create mode 100644 doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt create mode 100644 doc/device-tree-bindings/interrupt-controller/interrupts.txt create mode 100644 drivers/clk/intel/Makefile create mode 100644 drivers/clk/intel/clk_intel.c create mode 100644 drivers/tpm/cr50_i2c.c create mode 100644 include/dt-bindings/clock/intel-clock.h
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 1/17 dm: core: Allow iterating devices without uclass_get()
At present we have uclass_foreach_dev() which requires that uclass_get() be called beforehand to find the uclass. This is good if we suspect that that function might fail, but often we know that the uclass is available.
Add a new helper which does this uclass_get() automatically, so that only the uclass ID is needed.
---
Changes in v2:
- Add new patch to allow iterating devices without uclass_get()
include/dm/uclass.h | 17 +++++++++++++++++ test/dm/test-fdt.c | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+)
include/dm/uclass.h +17 -0
@@ -365,6 +365,23 @@ int uclass_next_device_check(struct udevice **devp);*/ int uclass_resolve_seq (struct udevice *dev); +/** +* uclass_id_foreach_dev() - Helper function to iteration through devices +* +* This creates a for() loop which works through the available devices in +* a uclass ID in order from start to end. +* +* If for some reason the uclass cannot be found, this does nothing. +* +* @id: enum uclass_id ID to use +* @pos: struct udevice * to hold the current device. Set to NULL when there +* are no more devices. +* @uc: temporary uclass variable (struct udevice *) +*/ +#define uclass_id_foreach_dev (id, pos, uc) \ + if (!uclass_get(id, &uc)) \ + list_for_each_entry(pos, &uc->dev_head, uclass_node) +/** * uclass_foreach_dev() - Helper function to iteration through devices *
test/dm/test-fdt.c +21 -0
@@ -448,6 +448,27 @@ static int dm_test_first_next_device(struct unit_test_state *uts) }DM_TEST (dm_test_first_next_device,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); +/* Test iteration through devices in a uclass */ +static int dm_test_uclass_foreach (struct unit_test_state *uts) +{ +struct udevice *dev; +struct uclass *uc; +int count; + + count =0 ; +uclass_id_foreach_dev (UCLASS_TEST_FDT , dev, uc) + count++; +ut_asserteq (8 , count); + + count =0 ; +uclass_foreach_dev (dev, uc) + count++; +ut_asserteq (8 , count); + +return 0 ; +} +DM_TEST (dm_test_uclass_foreach,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); +/** * check_devices() - Check return values and pointers *
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 1/17 dm: core: Allow iterating devices without uclass_get()
Quoted 9 lines · Simon Glass
At present we have
uclass_foreach_dev()which requires thatuclass_get()be called beforehand to find the uclass. This is good if we suspect that that function might fail, but often we know that the uclass is available.Add a new helper which does this
uclass_get()automatically, so that only the uclass ID is needed.Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v2:
- Add new patch to allow iterating devices withoutuclass_get()include/dm/uclass.h | 17 +++++++++++++++++ test/dm/test-fdt.c | 21 +++++++++++++++++++++ 2 files changed, 38 insertions(+)
PATCH v2 2/17 dm: core: Add a function to find a device by drvdata
In reply to Simon GlassIt is sometimes useful to find a device in a uclass using only its driver data. The driver data often indicates the 'subtype' of the device, e,g, via its compatible string.
Add a function to handle this.
---
Changes in v2:
- Add new patch to find a device by drvdata
drivers/core/uclass.c | 17 +++++++++++++++++ include/dm/test.h | 2 ++ include/dm/uclass.h | 14 ++++++++++++++ test/dm/test-fdt.c | 21 +++++++++++++++++++++ 4 files changed, 54 insertions(+)
drivers/core/uclass.c +17 -0
@@ -629,6 +629,23 @@ int uclass_next_device_check(struct udevice **devp)return device_probe (*devp); } +int uclass_first_device_drvdata (enum uclass_id id,ulong driver_data, +struct udevice **devp) +{ +struct udevice *dev; +struct uclass *uc; + + uclass_id_foreach_dev(id, dev, uc) { +if (dev_get_driver_data (dev) == driver_data) { + *devp = dev; + +return device_probe (dev); + } + } + +return -ENODEV ; +} +int uclass_bind_device (struct udevice *dev) {struct uclass *uc;
include/dm/test.h +2 -0
@@ -56,6 +56,8 @@ enum {enum {DM_TEST_TYPE_FIRST =0 ,DM_TEST_TYPE_SECOND , + +DM_TEST_TYPE_COUNT , };/* The number added to the ping total on each probe */
include/dm/uclass.h +14 -0
@@ -350,6 +350,20 @@ int uclass_first_device_check(enum uclass_id id, struct udevice **devp);*/ int uclass_next_device_check (struct udevice **devp); +/** +* uclass_first_device_drvdata() - Find the first device with given driver data +* +* This searches through the devices for a particular uclass looking for one +* that has the given driver data. +* +* @id: Uclass ID to check +* @driver_data: Driver data to search for +* @devp: Returns pointer to the first matching device in that uclass, if found +* @return 0 if found, -ENODEV if not found, other -ve on error +*/ +int uclass_first_device_drvdata (enum uclass_id id,ulong driver_data, +struct udevice **devp); +/** * uclass_resolve_seq() - Resolve a device's sequence number *
test/dm/test-fdt.c +21 -0
@@ -893,3 +893,24 @@ static int dm_test_read_int(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_read_int,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test iteration through devices by drvdata */ +static int dm_test_uclass_drvdata (struct unit_test_state *uts) +{ +struct udevice *dev; + +ut_assertok (uclass_first_device_drvdata (UCLASS_TEST_FDT , +DM_TEST_TYPE_FIRST , &dev)); +ut_asserteq_str ("a-test" , dev->name); + +ut_assertok (uclass_first_device_drvdata (UCLASS_TEST_FDT , +DM_TEST_TYPE_SECOND , &dev)); +ut_asserteq_str ("d-test" , dev->name); + +ut_asserteq (-ENODEV ,uclass_first_device_drvdata (UCLASS_TEST_FDT , +DM_TEST_TYPE_COUNT , + &dev)); + +return 0 ; +} +DM_TEST (dm_test_uclass_drvdata,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 2/17 dm: core: Add a function to find a device by drvdata
Quoted 10 lines · Simon Glass
It is sometimes useful to find a device in a uclass using only its driver data. The driver data often indicates the 'subtype' of the device, e,g, via its compatible string.
Add a function to handle this.
Signed-off-by Simon Glass <[email protected]>---
Quoted 9 lines
Changes in v2:
- Add new patch to find a device by drvdatadrivers/core/uclass.c | 17 +++++++++++++++++ include/dm/test.h | 2 ++ include/dm/uclass.h | 14 ++++++++++++++ test/dm/test-fdt.c | 21 +++++++++++++++++++++ 4 files changed, 54 insertions(+)
PATCH v2 3/17 dm: core: Change syscon to use helper function
In reply to Simon GlassNow that we have uclass_first_device_drvdata(), use it from syscon to reduce code duplication.
---
Changes in v2:
- Add new patch to change syscon to use helper function
drivers/core/syscon-uclass.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
drivers/core/syscon-uclass.c +4 -11
@@ -128,22 +128,15 @@ struct regmap *syscon_regmap_lookup_by_phandle(struct udevice *dev,int syscon_get_by_driver_data (ulong driver_data,struct udevice **devp) { -struct udevice *dev; -struct uclass *uc;int ret; *devp =NULL ; - ret =uclass_get (UCLASS_SYSCON , &uc); + + ret =uclass_first_device_drvdata (UCLASS_SYSCON , driver_data, devp);if (ret) -return ret; - uclass_foreach_dev(dev, uc) { -if (dev->driver_data == driver_data) { - *devp = dev; -return device_probe (dev); - } - } +return log_msg_ret ("find" , ret); -return -ENODEV ; +return 0 ; }struct regmap *syscon_get_regmap_by_driver_data (ulong driver_data)
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 3/17 dm: core: Change syscon to use helper function
Quoted 4 lines · Simon Glass
Now that we have
uclass_first_device_drvdata(), use it from syscon to reduce code duplication.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add new patch to change syscon to use helper functiondrivers/core/syscon-uclass.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-)
PATCH v2 4/17 tegra: i2c: Change driver to use helper function
In reply to Simon GlassNow that we have uclass_first_device_drvdata(), use it from the I2C driver to reduce code duplication.
---
Changes in v2:
- Add new patch to change tegra driver to use helper function
drivers/i2c/tegra_i2c.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
drivers/i2c/tegra_i2c.c +1 -12
@@ -499,18 +499,7 @@ static int tegra_i2c_xfer(struct udevice *bus, struct i2c_msg *msg,int tegra_i2c_get_dvc_bus (struct udevice **busp) { -struct udevice *bus; - -for (uclass_first_device (UCLASS_I2C , &bus); - bus; -uclass_next_device (&bus)) { -if (dev_get_driver_data (bus) ==TYPE_DVC ) { - *busp = bus; -return 0 ; - } - } - -return -ENODEV ; +return uclass_first_device_drvdata (UCLASS_I2C ,TYPE_DVC , busp); }static const struct dm_i2c_ops tegra_i2c_ops = {
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 4/17 tegra: i2c: Change driver to use helper function
Hello Simon,
Am 04.02.2020 um 01:19 schrieb Simon Glass:
Quoted 11 lines
Now that we have
uclass_first_device_drvdata(), use it from the I2C driver to reduce code duplication.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add new patch to change tegra driver to use helper functiondrivers/i2c/tegra_i2c.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH v2 4/17 tegra: i2c: Change driver to use helper function
In reply to Simon GlassQuoted 4 lines · Simon Glass
Now that we have
uclass_first_device_drvdata(), use it from the I2C driver to reduce code duplication.
Quoted 9 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Add new patch to change tegra driver to use helper functiondrivers/i2c/tegra_i2c.c | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-)
PATCH v2 5/17 x86: Add a clock driver for Intel devices
In reply to Simon GlassSo far we have avoided adding a clock driver for Intel devices. But the Designware I2C driver needs a different clock (133MHz) on Intel devices than on others (166MHz). Add a simple driver that provides this information.
This driver can be expanded later as needed.
---
Changes in v2: None
drivers/clk/Kconfig | 10 ++++++ drivers/clk/Makefile | 1 + drivers/clk/intel/Makefile | 6 ++++ drivers/clk/intel/clk_intel.c | 41 +++++++++++++++++++++++++ include/dt-bindings/clock/intel-clock.h | 15 +++++++++ 5 files changed, 73 insertions(+) create mode 100644 drivers/clk/intel/Makefile create mode 100644 drivers/clk/intel/clk_intel.c create mode 100644 include/dt-bindings/clock/intel-clock.h
drivers/clk/Kconfig +10 -0
@@ -73,6 +73,16 @@ config CLK_COMPOSITE_CCF Enable this option if you want to (re-)use the Linux kernel's Common Clock Framework [CCF] composite code in U-Boot's clock driver. +config CLK_INTEL + bool "Enable clock driver for Intel x86" + depends on CLK && X86 + help + This provides very basic support for clocks on Intel SoCs. The driver + is barely used at present but could be expanded as needs arise. + Much clock configuration in U-Boot is either set up by the FSP, or + set up by U-Boot itself but only statically. Thus the driver does not + support changing clock rates, only querying them. + config CLK_STM32F bool "Enable clock driver support for STM32F family" depends on CLK && (STM32F7 || STM32F4)
drivers/clk/Makefile +1 -0
@@ -25,6 +25,7 @@ obj-$(CONFIG_CLK_MVEBU) += mvebu/ obj-$(CONFIG_CLK_BCM6345) += clk_bcm6345.o obj-$(CONFIG_CLK_BOSTON) += clk_boston.o obj-$(CONFIG_CLK_EXYNOS) += exynos/ +obj-$(CONFIG_$(SPL_TPL_)CLK_INTEL) += intel/ obj-$(CONFIG_CLK_HSDK) += clk-hsdk-cgu.o obj-$(CONFIG_CLK_MPC83XX) += mpc83xx_clk.o obj-$(CONFIG_CLK_OWL) += owl/
drivers/clk/intel/Makefile new file +6 -0
@@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0+ +# +# Copyright 2010 Google LLC +# + +obj-y += clk_intel.o
drivers/clk/intel/clk_intel.c new file +41 -0
41 lines not on this page · raw message
include/dt-bindings/clock/intel-clock.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* This header provides constants for Intel clocks. +* +* The constants defined in this header are used in the device tree +* +* Copyright 2019 Google LLC +*/ + +#ifndef _DT_BINDINGS_CLK_INTEL_H +#define _DT_BINDINGS_CLK_INTEL_H + +#define CLK_I2C 1 + +#endif
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 5/17 x86: Add a clock driver for Intel devices
Quoted 13 lines · Simon Glass
So far we have avoided adding a clock driver for Intel devices. But the Designware I2C driver needs a different clock (133MHz) on Intel devices than on others (166MHz). Add a simple driver that provides this information.
This driver can be expanded later as needed.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 10 lines
drivers/clk/Kconfig | 10 ++++++ drivers/clk/Makefile | 1 + drivers/clk/intel/Makefile | 6 ++++ drivers/clk/intel/clk_intel.c | 41 +++++++++++++++++++++++++ include/dt-bindings/clock/intel-clock.h | 15 +++++++++ 5 files changed, 73 insertions(+) create mode 100644 drivers/clk/intel/Makefile create mode 100644 drivers/clk/intel/clk_intel.c create mode 100644 include/dt-bindings/clock/intel-clock.h
PATCH v2 6/17 x86: apl: Use the clock driver
In reply to Simon GlassEnable the Intel clock driver and modify coral's device tree to use it.
---
Changes in v2:
- Move intel-clock.h inclusion to the correct patch
arch/x86/cpu/apollolake/Kconfig | 3 +++ arch/x86/dts/chromebook_coral.dts | 5 +++++ 2 files changed, 8 insertions(+)
arch/x86/cpu/apollolake/Kconfig +3 -0
@@ -39,6 +39,9 @@ config INTEL_APOLLOLAKE imply HAVE_X86_FIT imply INTEL_GPIO imply SMP + imply CLK + imply CMD_CLK + imply CLK_INTEL if INTEL_APOLLOLAKE
arch/x86/dts/chromebook_coral.dts +5 -0
@@ -39,6 +39,11 @@ stdout-path = &serial; }; + clk: clock { + compatible = "intel,apl-clk"; + #clock-cells = <1>; + }; + cpus { u-boot,dm-pre-reloc; #address-cells = <1>;
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 7/17 x86: apl: Drop the I2C config in FSP-S
In reply to Simon GlassThis config is not actually used here and in U-Boot it seems better to set this using the device tree for each individual controller. The monolithic config of the FSP-S is only necessary if the FSP is actually configuring something, but here it is not.
The FSP-S does enable/disable the various I2C ports. It might be nice to handle this using the okay/disabled property of each port, but that can be considered later.
---
Changes in v2: None
arch/x86/cpu/apollolake/fsp_s.c | 58 --------------------------------- 1 file changed, 58 deletions(-)
arch/x86/cpu/apollolake/fsp_s.c +0 -58
@@ -24,7 +24,6 @@#define HIDE_BIT BIT(0)#define INTEL_GSPI_MAX 3 -#define INTEL_I2C_DEV_MAX 8#define MAX_USB2_PORTS 8enum {
@@ -32,36 +31,6 @@ enum { CHIPSET_LOCKDOWN_COREBOOT, /* coreboot handles locking */ }; -enum i2c_speed { -I2C_SPEED_STANDARD =100000 , -I2C_SPEED_FAST =400000 , -I2C_SPEED_FAST_PLUS =1000000 , -I2C_SPEED_HIGH =3400000 , -I2C_SPEED_FAST_ULTRA =5000000 , -}; - -/* -* Timing values are in units of clock period, with the clock speed -* provided by the SOC -* -* TODO(sjg at chromium.org): Connect this up to the I2C driver -*/ -struct dw_i2c_speed_config { -enum i2c_speed speed; -/* SCL high and low period count */ -u16 scl_lcnt; -u16 scl_hcnt; -/* -* SDA hold time should be 300ns in standard and fast modes -* and long enough for deterministic logic level change in -* fast-plus and high speed modes. -* -* [15:0] SDA TX Hold Time -* [23:16] SDA RX Hold Time -*/ -u32 sda_hold; -}; -/* Serial IRQ control. SERIRQ_QUIET is the default (0) */ enum serirq_mode {SERIRQ_QUIET ,
@@ -69,32 +38,6 @@ enum serirq_mode { SERIRQ_OFF, }; -/* -* This I2C controller has support for 3 independent speed configs but can -* support both FAST_PLUS and HIGH speeds through the same set of speed -* config registers. These are treated separately so the speed config values -* can be provided via ACPI to the OS. -*/ -#define DW_I2C_SPEED_CONFIG_COUNT 4 - -struct dw_i2c_bus_config { -/* Bus should be enabled in TPL with temporary base */ -int early_init; -/* Bus speed in Hz, default is I2C_SPEED_FAST (400 KHz) */ -enum i2c_speed speed; -/* -* If rise_time_ns is non-zero the calculations for lcnt and hcnt -* registers take into account the times of the bus. However, if -* there is a match in speed_config those register values take -* precedence -*/ -int rise_time_ns; -int fall_time_ns; -int data_hold_time_ns; -/* Specific bus speed configuration */ -struct dw_i2c_speed_config speed_config[DW_I2C_SPEED_CONFIG_COUNT ]; -}; -struct gspi_cfg {/* Bus speed in MHz */ u32 speed_mhz;
@@ -110,7 +53,6 @@ struct gspi_cfg {struct soc_intel_common_config {int chipset_lockdown;struct gspi_cfg gspi[INTEL_GSPI_MAX ]; -struct dw_i2c_bus_config i2c[INTEL_I2C_DEV_MAX ]; };enum pnp_settings {
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 7/17 x86: apl: Drop the I2C config in FSP-S
Quoted 10 lines · Simon Glass
This config is not actually used here and in U-Boot it seems better to set this using the device tree for each individual controller. The monolithic config of the FSP-S is only necessary if the FSP is actually configuring something, but here it is not.
The FSP-S does enable/disable the various I2C ports. It might be nice to handle this using the okay/disabled property of each port, but that can be considered later.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/cpu/apollolake/fsp_s.c | 58 --------------------------------- 1 file changed, 58 deletions(-)
PATCH v2 8/17 x86: coral: Update i2c and rtc status
In reply to Simon GlassThese are actually working correctly, so update the status.
---
Changes in v2: None
doc/board/google/chromebook_coral.rst | 2 -- 1 file changed, 2 deletions(-)
doc/board/google/chromebook_coral.rst +0 -2
@@ -213,9 +213,7 @@ To do - left-side USB - USB-C - Cr50 (security chip: a basic driver is running but not included here) - - I2C (driver exists but not enabled in device tree) - Sound (Intel I2S support exists, but need da7219 driver) - - RTC (driver exists but not enabled in device tree) - Various minor features supported by LPC, etc. - Booting Chrome OS, e.g. with verified boot - Integrate with Chrome OS vboot
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 8/17 x86: coral: Update i2c and rtc status
Quoted 11 lines · Simon Glass
These are actually working correctly, so update the status.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
doc/board/google/chromebook_coral.rst | 2 -- 1 file changed, 2 deletions(-)
PATCH v2 9/17 dm: irq: Add support for interrupt controller types
In reply to Simon GlassThere can be different types of interrupt controllers in a system and some drivers may need to distinguish between these. In general this can be handled using the device tree by adding the interrupt information to device nodes.
However on x86 devices we have interrupt controllers which are not tied to any particular device and not really used in U-Boot. These still need to be inited, so a convenient method is to give each controller a type and allow a particular controller type to be probed.
Add support for this in sandbox along with a test.
---
Changes in v2:
- Move 'success' comment into this patch
- Update to use the new DM helper function
arch/sandbox/include/asm/test.h | 4 ++++ drivers/misc/irq-uclass.c | 15 ++++++++++++++- drivers/misc/irq_sandbox.c | 2 +- include/irq.h | 23 +++++++++++++++++++++++ test/dm/irq.c | 14 ++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-)
arch/sandbox/include/asm/test.h +4 -0
@@ -45,6 +45,10 @@#define PCI_EA_BAR2_MAGIC 0x72727272#define PCI_EA_BAR4_MAGIC 0x74747474 +enum { +SANDBOX_IRQN_PEND =1 ,/* Interrupt number for 'pending' test */ +}; +/* System controller driver data */ enum {SYSCON0 =32 ,
drivers/misc/irq-uclass.c +14 -1
@@ -1,11 +1,13 @@// SPDX-License-Identifier: GPL-2.0+ /* -* Copyright (C) 2015, Bin Meng <[email protected]> +* Copyright 2019 Google, LLC +* Written by Simon Glass <[email protected]> */ #include <common.h> #include <dm.h> #include <irq.h> +#include <dm/device-internal.h> int irq_route_pmc_gpio_gpe (struct udevice *dev,uint pmc_gpe_num) {
@@ -47,6 +49,17 @@ int irq_restore_polarities(struct udevice *dev)return ops->restore_polarities (dev); } +int irq_first_device_type (enum irq_dev_t type,struct udevice **devp) +{ +int ret; + + ret =uclass_first_device_drvdata (UCLASS_IRQ , type, devp); +if (ret) +return log_msg_ret ("find" , ret); + +return 0 ; +} +UCLASS_DRIVER (irq) = { .id =UCLASS_IRQ , .name ="irq" ,
drivers/misc/irq_sandbox.c +1 -1
@@ -43,7 +43,7 @@ static const struct irq_ops sandbox_irq_ops = { };static const struct udevice_id sandbox_irq_ids[] = { - { .compatible ="sandbox,irq" }, + { .compatible ="sandbox,irq" ,SANDBOX_IRQT_BASE }, { } };
include/irq.h +23 -0
@@ -8,6 +8,17 @@#ifndef __irq_H#define __irq_H +/* +* Interrupt controller types available. You can find a particular one with +* irq_first_device_type() +*/ +enum irq_dev_t { +X86_IRQT_BASE ,/* Base controller */ +X86_IRQT_ITSS ,/* ITSS controller, e.g. on APL */ +X86_IRQT_ACPI_GPE ,/* ACPI General-Purpose Events controller */ +SANDBOX_IRQT_BASE ,/* Sandbox testing */ +}; +/** * struct irq_ops - Operations for the IRQ */
@@ -85,4 +96,16 @@ int irq_snapshot_polarities(struct udevice *dev);*/ int irq_restore_polarities (struct udevice *dev); +/** +* irq_first_device_type() - Get a particular interrupt controller +* +* On success this returns an activated interrupt device. +* +* @type: Type to find +* @devp: Returns the device, if found +* @return 0 if OK, -ENODEV if not found, other -ve error if uclass failed to +* probe +*/ +int irq_first_device_type (enum irq_dev_t type,struct udevice **devp); +#endif
test/dm/irq.c +14 -0
@@ -8,6 +8,7 @@#include <common.h> #include <dm.h> #include <irq.h> +#include <asm/test.h> #include <dm/test.h> #include <test/ut.h>
@@ -30,3 +31,16 @@ static int dm_test_irq_base(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_irq_base,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test of irq_first_device_type() */ +static int dm_test_irq_type (struct unit_test_state *uts) +{ +struct udevice *dev; + +ut_assertok (irq_first_device_type (SANDBOX_IRQT_BASE , &dev)); +ut_asserteq (-ENODEV ,irq_first_device_type (X86_IRQT_BASE , &dev)); + +return 0 ; +} +DM_TEST (dm_test_irq_type,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); +
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 9/17 dm: irq: Add support for interrupt controller types
Quoted 20 lines · Simon Glass
There can be different types of interrupt controllers in a system and some drivers may need to distinguish between these. In general this can be handled using the device tree by adding the interrupt information to device nodes.
However on x86 devices we have interrupt controllers which are not tied to any particular device and not really used in U-Boot. These still need to be inited, so a convenient method is to give each controller a type and allow a particular controller type to be probed.
Add support for this in sandbox along with a test.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Move 'success' comment into this patch
- Update to use the new DM helper function
Quoted 7 lines
arch/sandbox/include/asm/test.h | 4 ++++ drivers/misc/irq-uclass.c | 15 ++++++++++++++- drivers/misc/irq_sandbox.c | 2 +- include/irq.h | 23 +++++++++++++++++++++++ test/dm/irq.c | 14 ++++++++++++++ 5 files changed, 56 insertions(+), 2 deletions(-)
PATCH v2 10/17 x86: Give each driver an IRQ type
In reply to Simon GlassAdd an IRQ type to each driver and use irq_first_device_type() to find and probe the correct one.
---
Changes in v2:
- Move 'success' comment into previous patch
arch/x86/cpu/apollolake/fsp_s.c | 4 ++-- arch/x86/cpu/i386/interrupt.c | 3 ++- arch/x86/cpu/intel_common/itss.c | 2 +- arch/x86/cpu/irq.c | 3 ++- drivers/pinctrl/intel/pinctrl.c | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-)
arch/x86/cpu/apollolake/fsp_s.c +2 -2
@@ -535,7 +535,7 @@ int arch_fsps_preinit(void)struct udevice *itss;int ret; - ret =uclass_first_device_err (UCLASS_IRQ , &itss); + ret =irq_first_device_type (X86_IRQT_ITSS , &itss);if (ret)return log_msg_ret ("no itss" , ret);/*
@@ -576,7 +576,7 @@ int arch_fsp_init_r(void)if (ret)return ret; - ret =uclass_first_device_err (UCLASS_IRQ , &itss); + ret =irq_first_device_type (X86_IRQT_ITSS , &itss);if (ret)return log_msg_ret ("no itss" , ret);/* Restore GPIO IRQ polarities back to previous settings */
arch/x86/cpu/i386/interrupt.c +2 -1
@@ -15,6 +15,7 @@#include <efi_loader.h> #include <hang.h> #include <init.h> +#include <irq.h> #include <irq_func.h> #include <asm/control_regs.h> #include <asm/i8259.h>
@@ -264,7 +265,7 @@ int interrupt_init(void)int ret;/* Try to set up the interrupt router, but don't require one */ - ret =uclass_first_device_err (UCLASS_IRQ , &dev); + ret =irq_first_device_type (X86_IRQT_BASE , &dev);if (ret && ret != -ENODEV )return ret;
arch/x86/cpu/intel_common/itss.c +1 -1
@@ -199,7 +199,7 @@ static const struct irq_ops itss_ops = { };static const struct udevice_id itss_ids[] = { - { .compatible ="intel,itss" }, + { .compatible ="intel,itss" , .data =X86_IRQT_ITSS }, { } };
arch/x86/cpu/irq.c +2 -1
@@ -7,6 +7,7 @@#include <dm.h> #include <errno.h> #include <fdtdec.h> +#include <irq.h> #include <malloc.h> #include <asm/io.h> #include <asm/irq.h>
@@ -351,7 +352,7 @@ int irq_router_probe(struct udevice *dev) }static const struct udevice_id irq_router_ids[] = { - { .compatible ="intel,irq-router" }, + { .compatible ="intel,irq-router" , .data =X86_IRQT_BASE }, { } };
drivers/pinctrl/intel/pinctrl.c +1 -1
@@ -613,7 +613,7 @@ int intel_pinctrl_ofdata_to_platdata(struct udevice *dev,log_err ("Cannot find community for pid %d\n" , pplat->pid);return -EDOM ; } - ret =uclass_first_device_err (UCLASS_IRQ , &priv->itss); + ret =irq_first_device_type (X86_IRQT_ITSS , &priv->itss);if (ret)return log_msg_ret ("Cannot find ITSS" , ret); priv->comm = comm;
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 10/17 x86: Give each driver an IRQ type
Quoted 10 lines · Simon Glass
Add an IRQ type to each driver and use
irq_first_device_type()to find and probe the correct one.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Move 'success' comment into previous patch
Quoted 7 lines
arch/x86/cpu/apollolake/fsp_s.c | 4 ++-- arch/x86/cpu/i386/interrupt.c | 3 ++- arch/x86/cpu/intel_common/itss.c | 2 +- arch/x86/cpu/irq.c | 3 ++- drivers/pinctrl/intel/pinctrl.c | 2 +- 5 files changed, 8 insertions(+), 6 deletions(-)
PATCH v2 11/17 x86: itss: Add of-platdata support
In reply to Simon GlassAllow this driver to be used in TPL by setting up the interrupt type correctly.
---
Changes in v2: None
arch/x86/cpu/intel_common/itss.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
arch/x86/cpu/intel_common/itss.c +10 -0
@@ -146,6 +146,15 @@ static int route_pmc_gpio_gpe(struct udevice *dev, uint pmc_gpe_num)return -ENOENT ; } +static int itss_bind (struct udevice *dev) +{ +/* This is not set with of-platdata, so set it manually */ +if (CONFIG_IS_ENABLED (OF_PLATDATA )) + dev->driver_data =X86_IRQT_ITSS ; + +return 0 ; +} +static int itss_ofdata_to_platdata (struct udevice *dev) {struct itss_priv *priv =dev_get_priv (dev);
@@ -208,6 +217,7 @@ U_BOOT_DRIVER(itss_drv) = { .id = UCLASS_IRQ, .of_match = itss_ids, .ops = &itss_ops, + .bind = itss_bind, .ofdata_to_platdata = itss_ofdata_to_platdata, .platdata_auto_alloc_size = sizeof(struct itss_platdata), .priv_auto_alloc_size = sizeof(struct itss_priv),
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 11/17 x86: itss: Add of-platdata support
Quoted 4 lines · Simon Glass
Allow this driver to be used in TPL by setting up the interrupt type correctly.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/cpu/intel_common/itss.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
PATCH v2 12/17 dm: irq: Add support for requesting interrupts
In reply to Simon GlassAt present driver model supports the IRQ uclass but there is no way to request a particular interrupt for a driver.
Add a mechanism, similar to clock and reset, to read the interrupts required by a device from the device tree and to request those interrupts.
U-Boot itself does not have interrupt-driven handlers, so just provide a means to read and clear an interrupt. This can be useful to handle peripherals which must use an interrupt to determine when data is available, for example.
Bring over the basic binding file as well, from Linux v5.4. Note that the older binding is not supported in U-Boot; the newer 'special form' must be used.
Add a simple test of the new functionality.
---
Changes in v2: None
arch/sandbox/dts/test.dts | 5 +- .../interrupt-controller/interrupts.txt | 131 ++++++++++++++++++ drivers/misc/irq-uclass.c | 116 ++++++++++++++++ drivers/misc/irq_sandbox.c | 41 ++++++ include/irq.h | 115 +++++++++++++++ test/dm/irq.c | 31 +++++ 6 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 doc/device-tree-bindings/interrupt-controller/interrupts.txt
arch/sandbox/dts/test.dts +4 -1
@@ -93,6 +93,7 @@ <&gpio_b 9 0xc 3 2 1>; int-value = <1234>; uint-value = <(-1234)>; + interrupts-extended = <&irq 3 0>; }; junk {
@@ -357,8 +358,10 @@ vss-microvolts = <0>; }; - irq { + irq: irq { compatible = "sandbox,irq"; + interrupt-controller; + #interrupt-cells = <2>; }; lcd {
doc/device-tree-bindings/interrupt-controller/interrupts.txt new file +131 -0
131 lines not on this page · raw message
drivers/misc/irq-uclass.c +116 -0
130 lines not on this page · raw message
drivers/misc/irq_sandbox.c +41 -0
62 lines not on this page · raw message
include/irq.h +115 -0
135 lines not on this page · raw message
test/dm/irq.c +31 -0
@@ -44,3 +44,34 @@ static int dm_test_irq_type(struct unit_test_state *uts) }DM_TEST (dm_test_irq_type,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); +/* Test of irq_read_and_clear() */ +static int dm_test_read_and_clear (struct unit_test_state *uts) +{ +struct irq irq; + +ut_assertok (irq_first_device_type (SANDBOX_IRQT_BASE , &irq.dev)); + irq.id =SANDBOX_IRQN_PEND ; +ut_asserteq (0 ,irq_read_and_clear (&irq)); +ut_asserteq (0 ,irq_read_and_clear (&irq)); +ut_asserteq (0 ,irq_read_and_clear (&irq)); +ut_asserteq (1 ,irq_read_and_clear (&irq)); +ut_asserteq (0 ,irq_read_and_clear (&irq)); + +return 0 ; +} +DM_TEST (dm_test_read_and_clear,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test of irq_request() */ +static int dm_test_request (struct unit_test_state *uts) +{ +struct udevice *dev; +struct irq irq; + +ut_assertok (uclass_first_device_err (UCLASS_TEST_FDT , &dev)); +ut_asserteq_str ("a-test" , dev->name); +ut_assertok (irq_get_by_index (dev,0 , &irq)); +ut_asserteq (3 , irq.id); + +return 0 ; +} +DM_TEST (dm_test_request,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 12/17 dm: irq: Add support for requesting interrupts
Quoted 23 lines · Simon Glass
At present driver model supports the IRQ uclass but there is no way to request a particular interrupt for a driver.
Add a mechanism, similar to clock and reset, to read the interrupts required by a device from the device tree and to request those interrupts.
U-Boot itself does not have interrupt-driven handlers, so just provide a means to read and clear an interrupt. This can be useful to handle peripherals which must use an interrupt to determine when data is available, for example.
Bring over the basic binding file as well, from Linux v5.4. Note that the older binding is not supported in U-Boot; the newer 'special form' must be used.
Add a simple test of the new functionality.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 9 lines
arch/sandbox/dts/test.dts | 5 +- .../interrupt-controller/interrupts.txt | 131 ++++++++++++++++++ drivers/misc/irq-uclass.c | 116 ++++++++++++++++ drivers/misc/irq_sandbox.c | 41 ++++++ include/irq.h | 115 +++++++++++++++ test/dm/irq.c | 31 +++++ 6 files changed, 438 insertions(+), 1 deletion(-) create mode 100644 doc/device-tree-bindings/interrupt-controller/interrupts.txt
PATCH v2 13/17 x86: Add support for ACPI general-purpose events
In reply to Simon GlassACPI GPEs are used to signal interrupts from peripherals that are accessed via ACPI. In U-Boot these are modelled as interrupts using a separate interrupt controller. Configuration is via the device tree.
Add a simple driver for this.
---
Changes in v2: None
arch/x86/Kconfig | 33 +++++++ arch/x86/cpu/Makefile | 1 + arch/x86/cpu/acpi_gpe.c | 85 +++++++++++++++++++ .../interrupt-controller/intel,acpi-gpe.txt | 30 +++++++ 4 files changed, 149 insertions(+) create mode 100644 arch/x86/cpu/acpi_gpe.c create mode 100644 doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
arch/x86/Kconfig +33 -0
@@ -910,4 +910,37 @@ config X86_OFFSET_SPL depends on SPL && X86 default SPL_TEXT_BASE +config ACPI_GPE + bool "Support ACPI general-purpose events" + help + Enable a driver for ACPI GPEs to allow peripherals to send interrupts + via ACPI to the OS. In U-Boot this is only used when U-Boot itself + needs access to these interrupts. This can happen when it uses a + peripheral that is set up to use GPEs and so cannot use the normal + GPIO mechanism for polling an input. + + See https://queue.acm.org/blogposting.cfm?id=18977 for more info + +config SPL_ACPI_GPE + bool "Support ACPI general-purpose events in SPL" + help + Enable a driver for ACPI GPEs to allow peripherals to send interrupts + via ACPI to the OS. In U-Boot this is only used when U-Boot itself + needs access to these interrupts. This can happen when it uses a + peripheral that is set up to use GPEs and so cannot use the normal + GPIO mechanism for polling an input. + + See https://queue.acm.org/blogposting.cfm?id=18977 for more info + +config TPL_ACPI_GPE + bool "Support ACPI general-purpose events in TPL" + help + Enable a driver for ACPI GPEs to allow peripherals to send interrupts + via ACPI to the OS. In U-Boot this is only used when U-Boot itself + needs access to these interrupts. This can happen when it uses a + peripheral that is set up to use GPEs and so cannot use the normal + GPIO mechanism for polling an input. + + See https://queue.acm.org/blogposting.cfm?id=18977 for more info + endmenu
arch/x86/cpu/Makefile +1 -0
@@ -55,6 +55,7 @@ obj-$(CONFIG_INTEL_QUEENSBAY) += queensbay/ obj-$(CONFIG_INTEL_TANGIER) += tangier/ obj-$(CONFIG_APIC) += lapic.o ioapic.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += irq.o +obj-$(CONFIG_$(SPL_TPL_)ACPI_GPE) += acpi_gpe.o obj-$(CONFIG_QFW) += qfw_cpu.o ifndef CONFIG_$(SPL_)X86_64 obj-$(CONFIG_SMP) += mp_init.o
arch/x86/cpu/acpi_gpe.c new file +85 -0
85 lines not on this page · raw message
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +30 -0
@@ -0,0 +1,30 @@ +* Intel Advanced Configuration and Power Interface General Purpose Events + +This describes an interrupt controller which provides access to GPEs supported +by the SoC. + +Required properties: + +- compatible : "intel,acpi-gpe" +- interrupt-controller : Identifies the node as an interrupt controller +- #interrupt-cells : The number of cells to define the interrupts. Must be 2: + cell 0: interrupt number (normally >=32 since GPEs below that are reserved) + cell 1: 0 (flags, but none are currently defined) +- reg : The register bank for the controller (set this to the ACPI base). + +Example: + + general-purpose-events { + reg = <IOMAP_ACPI_BASE IOMAP_ACPI_SIZE>; + compatible = "intel,acpi-gpe"; + interrupt-controller; + #interrupt-cells = <2>; + }; + + ... + tpm at 50 { + reg = <0x50>; + compatible = "google,cr50"; + ready-gpio = <&gpio_n 0x1c GPIO_ACTIVE_LOW>; + interrupts-extended = <&acpi_gpe 0x3c 0>; + };
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 13/17 x86: Add support for ACPI general-purpose events
Quoted 173 lines · Simon Glass
ACPI GPEs are used to signal interrupts from peripherals that are accessed via ACPI. In U-Boot these are modelled as interrupts using a separate interrupt controller. Configuration is via the device tree.
Add a simple driver for this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/Kconfig | 33 +++++++ arch/x86/cpu/Makefile | 1 + arch/x86/cpu/acpi_gpe.c | 85 +++++++++++++++++++ .../interrupt-controller/intel,acpi-gpe.txt | 30 +++++++ 4 files changed, 149 insertions(+) create mode 100644 arch/x86/cpu/acpi_gpe.c create mode 100644 doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txtarch/x86/Kconfig +33
-0@@ -910,4 +910,37 @@ config X86_OFFSET_SPL depends on SPL && X86 default SPL_TEXT_BASE +config ACPI_GPE + bool "Support ACPI general-purpose events" + help + Enable a driver for ACPI GPEs to allow peripherals to send interrupts + via ACPI to the OS. In U-Boot this is only used when U-Boot itself + needs access to these interrupts. This can happen when it uses a + peripheral that is set up to use GPEs and so cannot use the normal + GPIO mechanism for polling an input. + + See https://queue.acm.org/blogposting.cfm?id=18977 for more info + +config SPL_ACPI_GPE + bool "Support ACPI general-purpose events in SPL" + help + Enable a driver for ACPI GPEs to allow peripherals to send interrupts + via ACPI to the OS. In U-Boot this is only used when U-Boot itself + needs access to these interrupts. This can happen when it uses a + peripheral that is set up to use GPEs and so cannot use the normal + GPIO mechanism for polling an input. + + See https://queue.acm.org/blogposting.cfm?id=18977 for more info + +config TPL_ACPI_GPE + bool "Support ACPI general-purpose events in TPL" + help + Enable a driver for ACPI GPEs to allow peripherals to send interrupts + via ACPI to the OS. In U-Boot this is only used when U-Boot itself + needs access to these interrupts. This can happen when it uses a + peripheral that is set up to use GPEs and so cannot use the normal + GPIO mechanism for polling an input. + + See https://queue.acm.org/blogposting.cfm?id=18977 for more info + endmenuarch/x86/cpu/Makefile +1
-0@@ -55,6 +55,7 @@ obj-$(CONFIG_INTEL_QUEENSBAY) += queensbay/ obj-$(CONFIG_INTEL_TANGIER) += tangier/ obj-$(CONFIG_APIC) += lapic.o ioapic.o obj-$(CONFIG_$(SPL_TPL_)X86_32BIT_INIT) += irq.o +obj-$(CONFIG_$(SPL_TPL_)ACPI_GPE) += acpi_gpe.o obj-$(CONFIG_QFW) += qfw_cpu.o ifndef CONFIG_$(SPL_)X86_64 obj-$(CONFIG_SMP) += mp_init.oarch/x86/cpu/acpi_gpe.c new file +85
-0@@ -0,0 +1,85 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Copyright 2019 Google, LLC +* Written by Simon Glass <[email protected]> +*/ + +#include <common.h> +#include <dm.h> +#include <irq.h> +#include <asm/io.h> + +/** +* struct acpi_gpe_priv - private driver information +* +* @acpi_base: Base I/O address of ACPI registers +*/ +struct acpi_gpe_priv { +ulong acpi_base; +}; + +#define GPE0_STS (x) (0x20 + ((x) * 4)) + +static int acpi_gpe_read_and_clear (struct irq *irq) +{ +struct acpi_gpe_priv *priv =dev_get_priv (irq->dev); +u32 mask, sts; +ulong start; +int ret =0 ; +int bank; + + bank = irq->id /32 ; + mask =1 << (irq->id %32 ); + +/* Wait up to 1ms for GPE status to clear */ + start =get_timer (0 ); +do { +if (get_timer (start) >1 ) +return ret; + + sts =inl (priv->acpi_base +GPE0_STS (bank)); +if (sts & mask) { +outl (mask, priv->acpi_base +GPE0_STS (bank)); + ret =1 ; + } + }while (sts & mask); + +return ret; +} + +static int acpi_gpe_ofdata_to_platdata (struct udevice *dev) +{ +struct acpi_gpe_priv *priv =dev_get_priv (dev); + + priv->acpi_base =dev_read_addr (dev); +if (!priv->acpi_base || priv->acpi_base ==FDT_ADDR_T_NONE ) +return log_msg_ret ("acpi_base" , -EINVAL ); + +return 0 ; +} + +static int acpi_gpe_of_xlate (struct irq *irq,struct ofnode_phandle_args *args) +{ + irq->id = args->args[0 ]; + +return 0 ; +} + +static const struct irq_ops acpi_gpe_ops = { + .read_and_clear = acpi_gpe_read_and_clear, + .of_xlate = acpi_gpe_of_xlate, +}; + +static const struct udevice_id acpi_gpe_ids[] = { + { .compatible ="intel,acpi-gpe" , .data =X86_IRQT_ACPI_GPE }, + { } +}; + +U_BOOT_DRIVER (acpi_gpe_drv) = { + .name ="acpi_gpe" , + .id =UCLASS_IRQ , + .of_match = acpi_gpe_ids, + .ops = &acpi_gpe_ops, + .ofdata_to_platdata = acpi_gpe_ofdata_to_platdata, + .priv_auto_alloc_size =sizeof (struct acpi_gpe_priv ), +};doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +2
-0@@ -0,0 +1,30 @@ +* Intel Advanced Configuration and Power Interface General Purpose Events +
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt line 12
Quoted 10 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +10
-0+This describes an interrupt controller which provides access to GPEs supported +by the SoC. + +Required properties: + +- compatible : "intel,acpi-gpe" +- interrupt-controller : Identifies the node as an interrupt controller +- #interrupt-cells : The number of cells to define the interrupts. Must be 2: + cell 0: interrupt number (normally >=32 since GPEs below that are reserved) + cell 1: 0 (flags, but none are currently defined)
I wonder why we have to use #interrupt-cells = <2> since cell 1 is always zero
Quoted 9 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +9
-0+- reg : The register bank for the controller (set this to the ACPI base). + +Example: + + general-purpose-events { + reg = <IOMAP_ACPI_BASE IOMAP_ACPI_SIZE>; + compatible = "intel,acpi-gpe"; + interrupt-controller; + #interrupt-cells = <2>;
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
Quoted 10 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +9
-1+ }; + + ... + tpm at 50 { + reg = <0x50>; + compatible = "google,cr50"; + ready-gpio = <&gpio_n 0x1c GPIO_ACTIVE_LOW>; + interrupts-extended = <&acpi_gpe 0x3c 0>; + }; --
PATCH v2 13/17 x86: Add support for ACPI general-purpose events
Hi Bin,
Quoted 22 lines · Bin Meng
Quoted 20 lines · Simon Glass
ACPI GPEs are used to signal interrupts from peripherals that are accessed via ACPI. In U-Boot these are modelled as interrupts using a separate interrupt controller. Configuration is via the device tree.
Add a simple driver for this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/Kconfig | 33 +++++++ arch/x86/cpu/Makefile | 1 + arch/x86/cpu/acpi_gpe.c | 85 +++++++++++++++++++ .../interrupt-controller/intel,acpi-gpe.txt | 30 +++++++ 4 files changed, 149 insertions(+) create mode 100644 arch/x86/cpu/acpi_gpe.c create mode 100644 doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
[..]
Quoted 12 lines
Quoted 12 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +6
-0@@ -0,0 +1,30 @@ +* Intel Advanced Configuration and Power Interface General Purpose Events + +This describes an interrupt controller which provides access to GPEs supported +by the SoC. + +Required properties:
Quoted 8 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt line 12
Quoted 6 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +6
-0+ +- compatible : "intel,acpi-gpe" +- interrupt-controller : Identifies the node as an interrupt controller +- #interrupt-cells : The number of cells to define the interrupts. Must be 2: + cell 0: interrupt number (normally >=32 since GPEs below that are reserved) + cell 1: 0 (flags, but none are currently defined)I wonder why we have to use #interrupt-cells = <2> since cell 1 is always zero
I am thinking that we will need a lot of flags eventually and want to avoid needing to change the binding later.
Quoted 14 lines
Quoted 14 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +13
-0+- reg : The register bank for the controller (set this to the ACPI base). + +Example: + + general-purpose-events { + reg = <IOMAP_ACPI_BASE IOMAP_ACPI_SIZE>; + compatible = "intel,acpi-gpe"; + interrupt-controller; + #interrupt-cells = <2>; + }; + + ... + tpm at 50 {
Quoted 8 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt
Quoted 6 lines
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt new file +5
-1+ reg = <0x50>; + compatible = "google,cr50"; + ready-gpio = <&gpio_n 0x1c GPIO_ACTIVE_LOW>; + interrupts-extended = <&acpi_gpe 0x3c 0>; + }; --Reviewed-by Bin Meng <[email protected]>
Regards,
Simon
PATCH v2 14/17 x86: coral: Add I2C and TPM device-tree definitions
In reply to Simon GlassAdd nodes to the device tree for Cr50 and other available I2C ports. Also enable the ACPI interrupt driver.
---
Changes in v2:
- Move intel-clock.h inclusion to the correct patch
arch/x86/cpu/apollolake/Kconfig | 1 + arch/x86/dts/chromebook_coral.dts | 88 +++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+)
arch/x86/cpu/apollolake/Kconfig +1 -0
@@ -42,6 +42,7 @@ config INTEL_APOLLOLAKE imply CLK imply CMD_CLK imply CLK_INTEL + imply ACPI_GPE if INTEL_APOLLOLAKE
arch/x86/dts/chromebook_coral.dts +88 -0
112 lines not on this page · raw message
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 14/17 x86: coral: Add I2C and TPM device-tree definitions
Quoted 5 lines · Simon Glass
Add nodes to the device tree for Cr50 and other available I2C ports. Also enable the ACPI interrupt driver.
Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v2:
- Moveintel-clock.hinclusion to the correct patcharch/x86/cpu/apollolake/Kconfig | 1 + arch/x86/dts/chromebook_coral.dts | 88 +++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+)
PATCH v2 15/17 tpm: Add more TPM2 definitions
In reply to Simon GlassAdd definitions for access and status.
Need to drop the mixed case.
---
Changes in v2: None
include/tpm-v2.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
include/tpm-v2.h +31 -0
@@ -161,6 +161,37 @@ enum tpm_index_attrs { TPMA_NV_AUTHWRITE | TPMA_NV_POLICYWRITE, }; +enum { +TPM_ACCESS_VALID =1 <<7 , +TPM_ACCESS_ACTIVE_LOCALITY =1 <<5 , +TPM_ACCESS_REQUEST_PENDING =1 <<2 , +TPM_ACCESS_REQUEST_USE =1 <<1 , +TPM_ACCESS_ESTABLISHMENT =1 <<0 , +}; + +enum { +TPM_STS_FAMILY_SHIFT =26 , +TPM_STS_FAMILY_MASK =0x3 <<TPM_STS_FAMILY_SHIFT , +TPM_STS_FAMILY_TPM2 =1 <<TPM_STS_FAMILY_SHIFT , +TPM_STS_RESE_TESTABLISMENT_BIT =1 <<25 , +TPM_STS_COMMAND_CANCEL =1 <<24 , +TPM_STS_BURST_COUNT_SHIFT =8 , +TPM_STS_BURST_COUNT_MASK =0xffff <<TPM_STS_BURST_COUNT_SHIFT , +TPM_STS_VALID =1 <<7 , +TPM_STS_COMMAND_READY =1 <<6 , +TPM_STS_GO =1 <<5 , +TPM_STS_DATA_AVAIL =1 <<4 , +TPM_STS_DATA_EXPECT =1 <<3 , +TPM_STS_SELF_TEST_DONE =1 <<2 , +TPM_STS_RESPONSE_RETRY =1 <<1 , +}; + +enum { +TPM_CMD_COUNT_OFFSET =2 , +TPM_CMD_ORDINAL_OFFSET =6 , +TPM_MAX_BUF_SIZE =1260 , +}; +/** * Issue a TPM2_Startup command. *
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 15/17 tpm: Add more TPM2 definitions
Quoted 5 lines · Simon Glass
Add definitions for access and status.
Need to drop the mixed case.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
include/tpm-v2.h | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+)
PATCH v2 16/17 tpm: Add a driver for H1/Cr50
In reply to Simon GlassH1 is a Google security chip present in recent Chromebooks, Pixel phones and other devices. Cr50 is the name of the software that runs on H1 in Chromebooks.
This chip is used to handle TPM-like functionality and also has quite a few additional features.
Add a driver for this.
---
Changes in v2:
- Significant rewrite of cr50 init procedure
- Support use of interrupts
drivers/tpm/Kconfig | 10 + drivers/tpm/Makefile | 1 + drivers/tpm/cr50_i2c.c | 661 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 672 insertions(+) create mode 100644 drivers/tpm/cr50_i2c.c
drivers/tpm/Kconfig +10 -0
@@ -127,6 +127,16 @@ config TPM_V2 if TPM_V2 +config TPM2_CR50_I2C + bool "Enable support for Google cr50 TPM" + depends on DM_I2C + help + Cr50 is an implementation of a TPM on Google's H1 security chip. + This uses the same open-source firmware as the Chromium OS EC. + While Cr50 has other features, its primary role is as the root of + trust for a devuce, It operates like a TPM and can be used with + verified boot. Cr50 is used on recent Chromebooks (since 2017). + config TPM2_TIS_SANDBOX bool "Enable sandbox TPMv2.x driver" depends on TPM_V2 && SANDBOX
drivers/tpm/Makefile +1 -0
@@ -10,5 +10,6 @@ obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o +obj-$(CONFIG_TPM2_CR50_I2C) += cr50_i2c.o obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.o
drivers/tpm/cr50_i2c.c new file +661 -0
661 lines not on this page · raw message
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 16/17 tpm: Add a driver for H1/Cr50
Hi Simon,
Quoted 29 lines · Simon Glass
H1 is a Google security chip present in recent Chromebooks, Pixel phones and other devices. Cr50 is the name of the software that runs on H1 in Chromebooks.
This chip is used to handle TPM-like functionality and also has quite a few additional features.
Add a driver for this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Significant rewrite of cr50 init procedure
- Support use of interruptsdrivers/tpm/Kconfig | 10 + drivers/tpm/Makefile | 1 + drivers/tpm/cr50_i2c.c | 661 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 672 insertions(+) create mode 100644 drivers/tpm/cr50_i2c.cdrivers/tpm/Kconfig +0
-0@@ -127,6 +127,16 @@ config TPM_V2
drivers/tpm/Kconfig config TPM_V2 · line 137
Quoted 10 lines
drivers/tpm/Kconfig +8
-0if TPM_V2 +config TPM2_CR50_I2C + bool "Enable support for Google cr50 TPM" + depends on DM_I2C + help + Cr50 is an implementation of a TPM on Google's H1 security chip. + This uses the same open-source firmware as the Chromium OS EC. + While Cr50 has other features, its primary role is as the root of + trust for a devuce, It operates like a TPM and can be used with
typo: device
Quoted 81 lines
drivers/tpm/Kconfig +2
-0+ verified boot. Cr50 is used on recent Chromebooks (since 2017). + config TPM2_TIS_SANDBOX bool "Enable sandbox TPMv2.x driver" depends on TPM_V2 && SANDBOXdrivers/tpm/Makefile +1
-0@@ -10,5 +10,6 @@ obj-$(CONFIG_TPM_TIS_SANDBOX) += tpm_tis_sandbox.o obj-$(CONFIG_TPM_ST33ZP24_I2C) += tpm_tis_st33zp24_i2c.o obj-$(CONFIG_TPM_ST33ZP24_SPI) += tpm_tis_st33zp24_spi.o +obj-$(CONFIG_TPM2_CR50_I2C) += cr50_i2c.o obj-$(CONFIG_TPM2_TIS_SANDBOX) += tpm2_tis_sandbox.o obj-$(CONFIG_TPM2_TIS_SPI) += tpm2_tis_spi.odrivers/tpm/cr50_i2c.c new file +59
-0@@ -0,0 +1,661 @@ +// SPDX-License-Identifier: GPL-2.0 +/* +* Cr50 / H1 TPM support +* +* Copyright 2018 Google LLC +*/ + +#define LOG_CATEGORY UCLASS_TPM + +#include <common.h> +#include <dm.h> +#include <i2c.h> +#include <irq.h> +#include <spl.h> +#include <tpm-v2.h> +#include <asm/gpio.h> +#include <asm/io.h> +#include <asm/arch/iomap.h> +#include <asm/arch/pm.h> + +enum { +TIMEOUT_INIT_MS =30000 ,/* Very long timeout for TPM init */ +TIMEOUT_LONG_US =2 *1000 *1000 , +TIMEOUT_SHORT_US =2 *1000 , +TIMEOUT_NO_IRQ_US =20 *1000 , +TIMEOUT_IRQ_US =100 *1000 , +}; + +enum { +CR50_DID_VID =0x00281ae0L +}; + +enum { +CR50_MAX_BUF_SIZE =63 , +}; + +struct cr50_priv { +struct gpio_desc ready_gpio; +struct irq irq; +int locality; +uint vendor; +bool use_irq; +}; + +/* Wait for interrupt to indicate TPM is ready */ +static int cr50_i2c_wait_tpm_ready (struct udevice *dev) +{ +struct cr50_priv *priv =dev_get_priv (dev); +ulong timeout, base; +int i; + +if (!priv->use_irq && !dm_gpio_is_valid (&priv->ready_gpio)) { +/* Fixed delay if interrupt not supported */ +udelay (TIMEOUT_NO_IRQ_US ); +return 0 ; + } + + base =timer_get_us (); + timeout = base +TIMEOUT_IRQ_US ;
drivers/tpm/cr50_i2c.c line 69
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+ + i =0 ; +while (priv->use_irq ? !irq_read_and_clear (&priv->irq) : + !dm_gpio_get_value (&priv->ready_gpio)) { + i++; +if ((int )(timer_get_us () - timeout) >=0 ) { +log_warning ("Timeout\n" ); +/* +* Use this instead of -ETIMEDOUT which is used by i2c +*/
nits: use single line comment format
Quoted 11 lines
drivers/tpm/cr50_i2c.c new file +11
-0+return -ETIME ; + } + } +log_debug ("i=%d\n" , i); + +return 0 ; +} + +/* Clear pending interrupts */ +static void cr50_i2c_clear_tpm_irq (struct udevice *dev) +{
drivers/tpm/cr50_i2c.c line 90
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+struct cr50_priv *priv =dev_get_priv (dev); + +if (priv->use_irq) +irq_read_and_clear (&priv->irq); +} + +/* +* cr50_i2c_read() - read from TPM register +* +* @tpm: TPM chip information
this should be @dev
Quoted 34 lines
drivers/tpm/cr50_i2c.c new file +34
-0+* @addr: register address to read from +* @buffer: provided by caller +* @len: number of bytes to read +* +* 1) send register address byte 'addr' to the TPM +* 2) wait for TPM to indicate it is ready +* 3) read 'len' bytes of TPM response into the provided 'buffer' +* +* Return 0 on success. -ve on error +*/ +static int cr50_i2c_read (struct udevice *dev,u8 addr,u8 *buffer, +size_t len) +{ +int ret; + +/* Clear interrupt before starting transaction */ +cr50_i2c_clear_tpm_irq (dev); + +/* Send the register address byte to the TPM */ + ret =dm_i2c_write (dev,0 , &addr,1 ); +if (ret) { +log_err ("Address write failed (err=%d)\n" , ret); +return ret; + } + +/* Wait for TPM to be ready with response data */ + ret =cr50_i2c_wait_tpm_ready (dev); +if (ret) +return ret; + +/* Read response data frrom the TPM */ + ret =dm_i2c_read (dev,0 , buffer, len); +if (ret) { +log_err ("Read response failed (err=%d)\n" , ret);
drivers/tpm/cr50_i2c.c line 134
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+return ret; + } + +return 0 ; +} + +/* +* cr50_i2c_write() - write to TPM register +* +* @tpm: TPM chip information
this should be @dev
Quoted 148 lines
drivers/tpm/cr50_i2c.c new file +148
-0+* @addr: register address to write to +* @buffer: data to write +* @len: number of bytes to write +* +* 1) prepend the provided address to the provided data +* 2) send the address+data to the TPM +* 3) wait for TPM to indicate it is done writing +* +* Returns -1 on error, 0 on success. +*/ +static int cr50_i2c_write (struct udevice *dev,u8 addr,const u8 *buffer, +size_t len) +{ +u8 buf[len +1 ]; +int ret; + +if (len >CR50_MAX_BUF_SIZE ) { +log_err ("Length %zd is too large\n" , len); +return -E2BIG ; + } + +/* Prepend the 'register address' to the buffer */ + buf[0 ] = addr; +memcpy (buf +1 , buffer, len); + +/* Clear interrupt before starting transaction */ +cr50_i2c_clear_tpm_irq (dev); + +/* Send write request buffer with address */ + ret =dm_i2c_write (dev,0 , buf, len +1 ); +if (ret) { +log_err ("Error writing to TPM (err=%d)\n" , ret); +return ret; + } + +/* Wait for TPM to be ready */ +return cr50_i2c_wait_tpm_ready (dev); +} + +static inline u8 tpm_access (u8 locality) +{ +return 0x0 | (locality <<4 ); +} + +static inline u8 tpm_sts (u8 locality) +{ +return 0x1 | (locality <<4 ); +} + +static inline u8 tpm_data_fifo (u8 locality) +{ +return 0x5 | (locality <<4 ); +} + +static inline u8 tpm_did_vid (u8 locality) +{ +return 0x6 | (locality <<4 ); +} + +static int release_locality (struct udevice *dev,int force) +{ +struct cr50_priv *priv =dev_get_priv (dev); +u8 mask =TPM_ACCESS_VALID |TPM_ACCESS_REQUEST_PENDING ; +u8 addr =tpm_access (priv->locality); +int ret; +u8 buf; + + ret =cr50_i2c_read (dev, addr, &buf,1 ); +if (ret) +return ret; + +if (force || (buf & mask) == mask) { + buf =TPM_ACCESS_ACTIVE_LOCALITY ; +cr50_i2c_write (dev, addr, &buf,1 ); + } + + priv->locality =0 ; + +return 0 ; +} + +/* cr50 requires all 4 bytes of status register to be read */ +static int cr50_i2c_status (struct udevice *dev) +{ +struct cr50_priv *priv =dev_get_priv (dev); +u8 buf[4 ]; +int ret; + + ret =cr50_i2c_read (dev,tpm_sts (priv->locality), buf,sizeof (buf)); +if (ret) { +log_warning ("%s: Failed to read status\n" , __func__); +return ret; + } + +return buf[0 ]; +} + +/* cr50 requires all 4 bytes of status register to be written */ +static int cr50_i2c_ready (struct udevice *dev) +{ +struct cr50_priv *priv =dev_get_priv (dev); +u8 buf[4 ] = {TPM_STS_COMMAND_READY }; +int ret; + + ret =cr50_i2c_write (dev,tpm_sts (priv->locality), buf,sizeof (buf)); +if (ret) +return ret; + +udelay (TIMEOUT_SHORT_US ); + +return 0 ; +} + +static int cr50_i2c_wait_burststs (struct udevice *dev,u8 mask, +size_t *burst,int *status) +{ +struct cr50_priv *priv =dev_get_priv (dev); +ulong timeout; +u32 buf; + +/* +* cr50 uses bytes 3:2 of status register for burst count and all 4 +* bytes must be read +*/ + timeout =timer_get_us () +TIMEOUT_LONG_US ; +while (timer_get_us () < timeout) { +if (cr50_i2c_read (dev,tpm_sts (priv->locality), + (u8 *)&buf,sizeof (buf)) <0 ) { +udelay (TIMEOUT_SHORT_US ); +continue ; + } + + *status = buf &0xff ; + *burst =le16_to_cpu ((buf >>8 ) &0xffff ); + +if ((*status & mask) == mask && + *burst >0 && *burst <=CR50_MAX_BUF_SIZE ) +return 0 ; + +udelay (TIMEOUT_SHORT_US ); + } + +log_warning ("Timeout reading burst and status\n" ); + +return -ETIMEDOUT ; +} + +static int cr50_i2c_recv (struct udevice *dev,u8 *buf,size_t buf_len)
drivers/tpm/cr50_i2c.c line 292
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+{ +struct cr50_priv *priv =dev_get_priv (dev); +size_t burstcnt, expected, current, len; +u8 addr =tpm_data_fifo (priv->locality); +u8 mask =TPM_STS_VALID |TPM_STS_DATA_AVAIL ; +u32 expected_buf; +int status; +int ret; + +debug ("%s: len=%x\n" , __func__, buf_len);
nits: should this be log_xxx APIs?
Quoted 68 lines
drivers/tpm/cr50_i2c.c new file +68
-0+if (buf_len <TPM_HEADER_SIZE ) +return -E2BIG ; + + ret =cr50_i2c_wait_burststs (dev, mask, &burstcnt, &status); +if (ret <0 ) { +log_warning ("First chunk not available\n" ); + goto out_err; + } + +/* Read first chunk of burstcnt bytes */ +if (cr50_i2c_read (dev, addr, buf, burstcnt) <0 ) { +log_warning ("Read failed\n" ); + goto out_err; + } + +/* Determine expected data in the return buffer */ +memcpy (&expected_buf, buf +TPM_CMD_COUNT_OFFSET ,sizeof (expected_buf)); + expected =be32_to_cpu (expected_buf); +if (expected > buf_len) { +log_warning ("Too much data: %zu > %zu\n" , expected, buf_len); + goto out_err; + } + +/* Now read the rest of the data */ + current = burstcnt; +while (current < expected) { +/* Read updated burst count and check status */ +if (cr50_i2c_wait_burststs (dev, mask, &burstcnt, &status) <0 ) { +log_warning ("- burst failure1\n" ); + goto out_err; + } + + len =min (burstcnt, expected - current); +if (cr50_i2c_read (dev, addr, buf + current, len) !=0 ) { +log_warning ("Read failed\n" ); + goto out_err; + } + + current += len; + } + +if (cr50_i2c_wait_burststs (dev,TPM_STS_VALID , &burstcnt, + &status) <0 ) { +log_warning ("- burst failure2\n" ); + goto out_err; + } +if (status &TPM_STS_DATA_AVAIL ) { +log_warning ("Data still available\n" ); + goto out_err; + } + +return current; + +out_err: +/* Abort current transaction if still pending */ + ret =cr50_i2c_status (dev); +if (ret <0 ) +return ret; +if (ret &TPM_STS_COMMAND_READY ) { + ret =cr50_i2c_ready (dev); +if (ret) +return ret; + } + +return -EIO ; +} + +static int cr50_i2c_send (struct udevice *dev,const u8 *buf,size_t len)
drivers/tpm/cr50_i2c.c line 370
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+{ +struct cr50_priv *priv =dev_get_priv (dev); + +int status; +size_t burstcnt, limit, sent =0 ; +u8 tpm_go[4 ] = {TPM_STS_GO }; +ulong timeout; +int ret; + +debug ("%s: len=%x\n" , __func__, len);
nits: should this be log_xxx APIs?
Quoted 66 lines
drivers/tpm/cr50_i2c.c new file +66
-0+ timeout =timer_get_us () +TIMEOUT_LONG_US ; +do { + ret =cr50_i2c_status (dev); +if (ret <0 ) + goto out_err; +if (ret &TPM_STS_COMMAND_READY ) +break ; + +if (timer_get_us () > timeout) + goto out_err; + + ret =cr50_i2c_ready (dev); +if (ret) + goto out_err; + }while (1 ); + +while (len >0 ) { +u8 mask =TPM_STS_VALID ; + +/* Wait for data if this is not the first chunk */ +if (sent >0 ) + mask |=TPM_STS_DATA_EXPECT ; + +if (cr50_i2c_wait_burststs (dev, mask, &burstcnt, &status) <0 ) + goto out_err; + +/* +* Use burstcnt - 1 to account for the address byte +* that is inserted by cr50_i2c_write() +*/ + limit =min (burstcnt -1 , len); +if (cr50_i2c_write (dev,tpm_data_fifo (priv->locality), + &buf[sent], limit) !=0 ) { +log_warning ("Write failed\n" ); + goto out_err; + } + + sent += limit; + len -= limit; + } + +/* Ensure TPM is not expecting more data */ +if (cr50_i2c_wait_burststs (dev,TPM_STS_VALID , &burstcnt, &status) <0 ) + goto out_err; +if (status &TPM_STS_DATA_EXPECT ) { +log_warning ("Data still expected\n" ); + goto out_err; + } + +/* Start the TPM command */ + ret =cr50_i2c_write (dev,tpm_sts (priv->locality), tpm_go, +sizeof (tpm_go)); +if (ret) { +log_warning ("Start command failed\n" ); + goto out_err; + } + +return sent; + +out_err: +/* Abort current transaction if still pending */ + ret =cr50_i2c_status (dev); + +if (ret <0 || (ret &TPM_STS_COMMAND_READY )) { + ret =cr50_i2c_ready (dev); +if (ret)
drivers/tpm/cr50_i2c.c line 446
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+return ret; + } + +return -EIO ; +} + +/** +* process_reset() - Wait for the Cr50 to reset +* +* Cr50 processes reset requests asynchronously and consceivably could be busy
typo: conceivably
Quoted 41 lines
drivers/tpm/cr50_i2c.c new file +41
-0+* executing a long command and not reacting to the reset pulse for a while. +* +* This function will make sure that the AP does not proceed with boot until +* TPM finished reset processing. +* +* @dev: Cr50 device +* @return 0 if OK, -EPERM if locality could not be taken +*/ +static int process_reset (struct udevice *dev) +{ +const int loc =0 ; +u8 access; +ulong start; + +/* +* Locality is released by TPM reset. +* +* If locality is taken at this point, this could be due to the fact +* that the TPM is performing a long operation and has not processed +* reset request yet. We'll wait up to CR50_TIMEOUT_INIT_MS and see if +* it releases locality when reset is processed. +*/ + start =get_timer (0 ); + do { + const u8 mask = TPM_ACCESS_VALID | TPM_ACCESS_ACTIVE_LOCALITY; + int ret; + + ret = cr50_i2c_read(dev, tpm_access(loc), + &access, sizeof(access)); + if (ret || ((access & mask) == mask)) { + /* + * Don't bombard the chip with traffic; let it keep + * processing the command. + */ + mdelay(2); + continue; + } + + log_warning("TPM ready after %ld ms\n", get_timer(start)); + + return 0;
drivers/tpm/cr50_i2c.c line 497
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +10
-0+ }while (get_timer (start) <TIMEOUT_INIT_MS ); + +log_warning ("TPM failed to reset after %ld ms, status: %#x\n" , +get_timer (start), access); + +return -EPERM ; +} + +/* +* Locality could be already claimed (if this is a later coreboot stage and
coreboot?
drivers/tpm/cr50_i2c.c line 498
Quoted 1 line
drivers/tpm/cr50_i2c.c new file +1
-0+* the RO did not release it), or not yet claimed, if this is verstage or the
verstage?
Quoted 154 lines
drivers/tpm/cr50_i2c.c new file +154
-0+* older RO did release it. +*/ +static int claim_locality (struct udevice *dev,int loc) +{ +const u8 mask =TPM_ACCESS_VALID |TPM_ACCESS_ACTIVE_LOCALITY ; +u8 access; +int ret; + + ret =cr50_i2c_read (dev,tpm_access (loc), &access,sizeof (access)); +if (ret) +return log_msg_ret ("read1" , ret); + +if ((access & mask) == mask) { +log_warning ("Locality already claimed\n" ); +return 0 ; + } + + access =TPM_ACCESS_REQUEST_USE ; + ret =cr50_i2c_write (dev,tpm_access (loc), &access,sizeof (access)); +if (ret) +return log_msg_ret ("write" , ret); + + ret =cr50_i2c_read (dev,tpm_access (loc), &access,sizeof (access)); +if (ret) +return log_msg_ret ("read2" , ret); + +if ((access & mask) != mask) { +log_err ("Failed to claim locality\n" ); +return -EPERM ; + } +log_info ("Claimed locality %d\n" , loc); + +return 0 ; +} + +static int cr50_i2c_get_desc (struct udevice *dev,char *buf,int size) +{ +struct dm_i2c_chip *chip =dev_get_parent_platdata (dev); +struct cr50_priv *priv =dev_get_priv (dev); + +return snprintf (buf, size,"cr50 TPM 2.0 (i2c %02x id %x) irq=%d" , + chip->chip_addr, priv->vendor >>16 , priv->use_irq); +} + +static int cr50_i2c_open (struct udevice *dev) +{ +char buf[80 ]; +int ret; + + ret =process_reset (dev); +if (ret) +return log_msg_ret ("reset" , ret); + + ret =claim_locality (dev,0 ); +if (ret) +return log_msg_ret ("claim" , ret); + +cr50_i2c_get_desc (dev, buf,sizeof (buf)); +log_debug ("%s\n" , buf); + +return 0 ; +} + +static int cr50_i2c_cleanup (struct udevice *dev) +{ +release_locality (dev,1 ); + +return 0 ; +} + +enum { +TPM_TIMEOUT_MS =5 , +SHORT_TIMEOUT_MS =750 , +LONG_TIMEOUT_MS =2000 , +}; + +static int cr50_i2c_ofdata_to_platdata (struct udevice *dev) +{ +struct tpm_chip_priv *upriv =dev_get_uclass_priv (dev); +struct cr50_priv *priv =dev_get_priv (dev); +struct irq irq; +int ret; + + upriv->version =TPM_V2 ; + upriv->duration_ms[TPM_SHORT ] =SHORT_TIMEOUT_MS ; + upriv->duration_ms[TPM_MEDIUM ] =LONG_TIMEOUT_MS ; + upriv->duration_ms[TPM_LONG ] =LONG_TIMEOUT_MS ; + upriv->retry_time_ms =TPM_TIMEOUT_MS ; + + upriv->pcr_count =32 ; + upriv->pcr_select_min =2 ; + +/* Optional GPIO to track when cr50 is ready */ + ret =irq_get_by_index (dev,0 , &irq); +if (!ret) { + priv->irq = irq; + priv->use_irq = true; + }else { + ret =gpio_request_by_name (dev,"ready-gpio" ,0 , + &priv->ready_gpio,GPIOD_IS_IN ); +if (ret) { +log_warning ("Cr50 does not have an ready GPIO/interrupt (err=%d)\n" , + ret); + } + } + +return 0 ; +} + +static int cr50_i2c_probe (struct udevice *dev) +{ +struct cr50_priv *priv =dev_get_priv (dev); +u32 vendor =0 ; +ulong start; + +/* +* 150ms should be enough to synchronise with the TPM even under the +* worst nested-reset-request conditions. In the vast majority of cases +* there will be no wait at all. +*/ + start =get_timer (0 ); +while (get_timer (start) <150 ) { +int ret; + +/* Exit once DID and VID verified */ + ret =cr50_i2c_read (dev,tpm_did_vid (0 ), (u8 *)&vendor,4 ); +if (!ret && vendor ==CR50_DID_VID ) +break ; + +/* TPM might be resetting; let's retry in a bit */ +mdelay (10 ); + } +if (vendor !=CR50_DID_VID ) { +log_debug ("DID_VID %08x not recognised\n" , vendor); +return log_msg_ret ("vendor-id" , -EXDEV ); + } + priv->vendor = vendor; + +return 0 ; +} + +static const struct tpm_ops cr50_i2c_ops = { + .open = cr50_i2c_open, + .get_desc = cr50_i2c_get_desc, + .send = cr50_i2c_send, + .recv = cr50_i2c_recv, + .cleanup = cr50_i2c_cleanup, +}; + +static const struct udevice_id cr50_i2c_ids[] = { + { .compatible ="google,cr50" }, + { } +}; +
drivers/tpm/cr50_i2c.c
Quoted 10 lines
drivers/tpm/cr50_i2c.c new file +9
-1+U_BOOT_DRIVER (cr50_i2c) = { + .name ="cr50_i2c" , + .id =UCLASS_TPM , + .of_match = cr50_i2c_ids, + .ops = &cr50_i2c_ops, + .ofdata_to_platdata = cr50_i2c_ofdata_to_platdata, + .probe = cr50_i2c_probe, + .priv_auto_alloc_size =sizeof (struct cr50_priv ), +}; --
Regards,
Bin
PATCH v2 17/17 x86: coral: Enable TPM
In reply to Simon GlassEnable TPM2 so that we can use cr50.
---
Changes in v2:
- Update the commit message
- Add new patches to handle requesting interrupts and interrupt state
configs/chromebook_coral_defconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
configs/chromebook_coral_defconfig +2 -1
@@ -53,7 +53,6 @@ CONFIG_CMD_TIME=y CONFIG_CMD_SOUND=y CONFIG_CMD_BOOTSTAGE=y CONFIG_CMD_TPM=y -CONFIG_CMD_TPM_TEST=y CONFIG_CMD_EXT2=y CONFIG_CMD_EXT4=y CONFIG_CMD_EXT4_WRITE=y
@@ -90,6 +89,8 @@ CONFIG_SPI=y CONFIG_ICH_SPI=y CONFIG_TPL_SYSRESET=y CONFIG_TPM_TIS_LPC=y +# CONFIG_TPM_V1 is not set +CONFIG_TPM2_CR50_I2C=y CONFIG_USB_XHCI_HCD=y CONFIG_USB_STORAGE=y CONFIG_USB_KEYBOARD=y
Signature · 1 line
2.25.0.341.g760bfbb309-goog
PATCH v2 17/17 x86: coral: Enable TPM
Quoted 4 lines · Simon Glass
Enable TPM2 so that we can use cr50.
Signed-off-by Simon Glass <[email protected]>
Quoted 9 lines
---
Changes in v2:
- Update the commit message
- Add new patches to handle requesting interrupts and interrupt stateconfigs/chromebook_coral_defconfig | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)