dm: Add programmatic generation of ACPI tables (part A)
Subsystems (7)
v2 cover dm: Add programmatic generation of ACPI tables (part A)
This is split from the original series in an attempt to get things applied in chunks.
The first 20 or so patches here have been reviewed and the changes here incorporate those comments.
Changes in v2:
- Don't bracket the definitions with DM_SPI
- Drop the other comment change since it is already applied
- Drop the Chrome OS pieces
- Rename the 'coreboot' console to 'U-Boot'
- Move LOGC_ACPI definition to this patch
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
- Add in the acpi_table.h header file to this patch
- Move the sandbox acpi_table.h header file to an earlier patch
- Use #defines for MADT and MCFG version numbers
- Drop two unnecessary __packed
- Move __packed to after struct
- Drop definition of ACPI_TABLE_CREATOR
- Make _acpi_write_dev_tables() static and switch argument order
- Generalise the ACPI function recursion with acpi_recurse_method()
- Drop CID value from i2c struct
- Switch parameter order of _acpi_fill_ssdt() and make it static
- Generalise the ACPI function recursion with acpi_recurse_method()
- Generalise the ACPI function recursion with acpi_recurse_method()
- Move ACPI_TABLE_CREATOR to here
- Generalise the ACPI function recursion with acpi_recurse_method()
Simon Glass (39):
cpu: Support querying the address width
spi: Add SPI mode enums
tpm: cr50: Release locality on exit
tpm: cr50: Add a comment for cr50_priv
tpm: cr50: Use the correct GPIO binding
tpm: Don't cleanup unless an error happens
dm: pci: Allow disabling auto-config for a device
x86: Correct wording of coreboot source code
x86: apl: Move p2sb ofdata reading to the correct method
pci: Adjust dm_pci_read_bar32() to return errors correctly
x86: apl: Add Global NVS table header
dm: core: Add basic ACPI support
acpi: Add a binding for ACPI settings in the device tree
acpi: Add a simple sandbox test
x86: Move acpi_table header to main include/ directory
acpi: Add an __ACPI__ preprocessor symbol
acpi: Add a central location for table version numbers
acpi: Add support for DMAR
acpi: Move acpi_fill_header() to generic code
acpi: Add a method to write tables for a device
acpi: Convert part of acpi_table to use acpi_ctx
x86: Allow devices to write ACPI tables
acpi: Drop code for missing XSDT from acpi_write_rsdp()
acpi: Move acpi_add_table() to generic code
acpi: Put table-setup code in its own function
acpi: Move the xsdt pointer to acpi_ctx
acpi: Add an acpi command
acpi: Add some tables required by the generation code
acpi: Add generation code for devices
acpi: Add functions to generate ACPI code
gpio: Add a method to convert a GPIO to ACPI
irq: Add a method to convert an interrupt to ACPI
acpi: Add support for SSDT generation
x86: acpi: Move MADT up a bit
acpi: Record the items added to SSDT
acpi: Support ordering SSDT data by device
x86: Allow devices to write an SSDT
acpi: Add support for DSDT generation
x86: Allow devices to write to DSDT
arch/sandbox/dts/test.dts | 13 + arch/sandbox/include/asm/acpi_table.h | 9 + arch/sandbox/include/asm/global_data.h | 1 + arch/x86/cpu/baytrail/acpi.c | 2 +- arch/x86/cpu/coreboot/timestamp.c | 4 +- arch/x86/cpu/cpu.c | 2 +- arch/x86/cpu/intel_common/p2sb.c | 35 +- arch/x86/cpu/quark/acpi.c | 2 +- arch/x86/cpu/tangier/acpi.c | 2 +- arch/x86/dts/chromebook_coral.dts | 2 +- arch/x86/include/asm/acpi_table.h | 376 ---- .../include/asm/arch-apollolake/global_nvs.h | 37 + .../x86/include/asm/arch-coreboot/timestamp.h | 4 +- arch/x86/include/asm/global_data.h | 1 + arch/x86/include/asm/intel_pinctrl_defs.h | 2 - arch/x86/lib/acpi.c | 2 +- arch/x86/lib/acpi_s3.c | 2 +- arch/x86/lib/acpi_table.c | 312 ++- arch/x86/lib/tables.c | 2 +- arch/x86/lib/zimage.c | 2 +- cmd/Kconfig | 14 + cmd/Makefile | 1 + cmd/acpi.c | 179 ++ doc/device-tree-bindings/chosen.txt | 9 + doc/device-tree-bindings/device.txt | 36 + .../gpio/intel,apl-gpio.txt | 2 +- .../input/hid-over-i2c.txt | 44 + .../interrupt-controller/intel,acpi-gpe.txt | 2 +- doc/device-tree-bindings/pci/x86-pci.txt | 24 + drivers/core/Kconfig | 9 + drivers/core/Makefile | 1 + drivers/core/acpi.c | 267 +++ drivers/cpu/cpu_sandbox.c | 1 + drivers/gpio/gpio-uclass.c | 21 + drivers/misc/irq-uclass.c | 18 +- drivers/pci/pci-uclass.c | 11 +- drivers/tpm/cr50_i2c.c | 24 +- drivers/tpm/tpm-uclass.c | 13 +- include/acpi_device.h | 744 ++++++++ include/acpi_table.h | 632 +++++++ include/acpigen.h | 482 +++++ include/asm-generic/gpio.h | 27 + include/cpu.h | 2 + include/dm/acpi.h | 167 ++ include/dm/device.h | 5 + include/dm/uclass-id.h | 1 + include/irq.h | 43 + include/log.h | 2 + include/spi.h | 33 + lib/Makefile | 1 + lib/acpi/Makefile | 6 + lib/acpi/acpi_device.c | 1204 ++++++++++++ lib/acpi/acpi_table.c | 259 +++ lib/acpi/acpigen.c | 1683 +++++++++++++++++ lib/efi_loader/efi_acpi.c | 2 +- scripts/Makefile.lib | 4 +- test/dm/Makefile | 1 + test/dm/acpi.c | 399 ++++ test/dm/cpu.c | 1 + 59 files changed, 6555 insertions(+), 631 deletions(-) create mode 100644 arch/sandbox/include/asm/acpi_table.h create mode 100644 arch/x86/include/asm/arch-apollolake/global_nvs.h create mode 100644 cmd/acpi.c create mode 100644 doc/device-tree-bindings/device.txt create mode 100644 doc/device-tree-bindings/input/hid-over-i2c.txt create mode 100644 drivers/core/acpi.c create mode 100644 include/acpi_device.h create mode 100644 include/acpi_table.h create mode 100644 include/acpigen.h create mode 100644 include/dm/acpi.h create mode 100644 lib/acpi/Makefile create mode 100644 lib/acpi/acpi_device.c create mode 100644 lib/acpi/acpi_table.c create mode 100644 lib/acpi/acpigen.c create mode 100644 test/dm/acpi.c
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 1/39 cpu: Support querying the address width
Different CPUs may support different address widths, meaning the amount of memory they can address. Add a property for this to the cpu_info struct.
---
Changes in v2: None
drivers/cpu/cpu_sandbox.c | 1 + include/cpu.h | 2 ++ test/dm/cpu.c | 1 + 3 files changed, 4 insertions(+)
drivers/cpu/cpu_sandbox.c +1 -0
@@ -19,6 +19,7 @@ int cpu_sandbox_get_info(struct udevice *dev, struct cpu_info *info) { info->cpu_freq =42 *42 *42 *42 *42 ; info->features =0x42424242 ; + info->address_width =IS_ENABLED (CONFIG_PHYS_64BIT ) ?64 :32 ;return 0 ; }
include/cpu.h +2 -0
@@ -44,10 +44,12 @@ enum {* * @cpu_freq: Current CPU frequency in Hz * @features: Flags for supported CPU features +* @address_width: Width of the CPU address space in bits (e.g. 32) */ struct cpu_info {ulong cpu_freq;ulong features; +uint address_width; };struct cpu_ops {
test/dm/cpu.c +1 -0
@@ -33,6 +33,7 @@ static int dm_test_cpu(struct unit_test_state *uts)ut_assertok (cpu_get_info (dev, &info));ut_asserteq (info.cpu_freq,42 *42 *42 *42 *42 );ut_asserteq (info.features,0x42424242 ); +ut_asserteq (info.address_width,32 );ut_asserteq (cpu_get_count (dev),42 );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 2/39 spi: Add SPI mode enums
In reply to Simon GlassWith ACPI we need to describe the settings of the SPI bus. Add enums to handle this.
---
Changes in v2:
- Don't bracket the definitions with DM_SPI
include/spi.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
include/spi.h +33 -0
@@ -66,6 +66,39 @@ struct dm_spi_slave_platdata {#endif /* CONFIG_DM_SPI */ +/** +* enum spi_clock_phase - indicates the clock phase to use for SPI (CPHA) +* +* @SPI_CLOCK_PHASE_FIRST: Data sampled on the first phase +* @SPI_CLOCK_PHASE_SECOND: Data sampled on the second phase +*/ +enum spi_clock_phase { +SPI_CLOCK_PHASE_FIRST , +SPI_CLOCK_PHASE_SECOND +}; + +/** +* enum spi_wire_mode - indicates the number of wires used for SPI +* +* @SPI_4_WIRE_MODE: Normal bidirectional mode with MOSI and MISO +* @SPI_3_WIRE_MODE: Unidirectional version with a single data line SISO +*/ +enum spi_wire_mode { +SPI_4_WIRE_MODE , +SPI_3_WIRE_MODE +}; + +/** +* enum spi_polarity - indicates the polarity of the SPI bus (CPOL) +* +* @SPI_POLARITY_LOW: Clock is low in idle state +* @SPI_POLARITY_HIGH: Clock is high in idle state +*/ +enum spi_polarity { +SPI_POLARITY_LOW , +SPI_POLARITY_HIGH +}; +/** * struct spi_slave - Representation of a SPI slave *
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 02/39] spi: Add SPI mode enums
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 6 lines
With ACPI we need to describe the settings of the SPI bus. Add enums to handle this.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>
Quoted 7 lines
---
Changes in v2:
- Don't bracket the definitions withDM_SPIinclude/spi.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)
PATCH v2 2/39 spi: Add SPI mode enums
In reply to Simon GlassQuoted 21 lines · Simon Glass
With ACPI we need to describe the settings of the SPI bus. Add enums to handle this.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2:
- Don't bracket the definitions withDM_SPIinclude/spi.h | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+)include/spi.h +0
-0@@ -66,6 +66,39 @@ struct dm_spi_slave_platdata {#endif /* CONFIG_DM_SPI */
include/spi.h struct dm_spi_slave_platdata { · line 77
Quoted 10 lines
include/spi.h +9
-0+/** +* enum spi_clock_phase - indicates the clock phase to use for SPI (CPHA) +* +* @SPI_CLOCK_PHASE_FIRST: Data sampled on the first phase +* @SPI_CLOCK_PHASE_SECOND: Data sampled on the second phase +*/ +enum spi_clock_phase { +SPI_CLOCK_PHASE_FIRST , +SPI_CLOCK_PHASE_SECOND
I always forget if absence of comma in such cases (where it's not obvious that the last item in the enum, struct or array is a terminator line) is U-Boot style, but I this the rule of thumb is to have comma at the end to simplify extension or adjustment in the future.
Quoted 30 lines
include/spi.h +24
-1+}; + +/** +* enum spi_wire_mode - indicates the number of wires used for SPI +* +* @SPI_4_WIRE_MODE: Normal bidirectional mode with MOSI and MISO +* @SPI_3_WIRE_MODE: Unidirectional version with a single data line SISO +*/ +enum spi_wire_mode { +SPI_4_WIRE_MODE , +SPI_3_WIRE_MODE +}; + +/** +* enum spi_polarity - indicates the polarity of the SPI bus (CPOL) +* +* @SPI_POLARITY_LOW: Clock is low in idle state +* @SPI_POLARITY_HIGH: Clock is high in idle state +*/ +enum spi_polarity { +SPI_POLARITY_LOW , +SPI_POLARITY_HIGH +}; +/** * struct spi_slave - Representation of a SPI slave * -- 2.25.1.481.gfbce0eb801-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 3/39 tpm: cr50: Release locality on exit
In reply to Simon GlassAt present the cr50 driver claims the locality and does not release it for Linux. This causes problems. Fix this by tracking what is claimed, and adding a 'remove' method.
---
Changes in v2: None
drivers/tpm/cr50_i2c.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-)
drivers/tpm/cr50_i2c.c +11 -2
@@ -206,7 +206,7 @@ static int release_locality(struct udevice *dev, int force)cr50_i2c_write (dev, addr, &buf,1 ); } - priv->locality =0 ; + priv->locality =-1 ;return 0 ; }
@@ -499,6 +499,7 @@ static int process_reset(struct udevice *dev)static int claim_locality (struct udevice *dev,int loc) {const u8 mask =TPM_ACCESS_VALID |TPM_ACCESS_ACTIVE_LOCALITY ; +struct cr50_priv *priv =dev_get_priv (dev);u8 access;int ret;
@@ -525,6 +526,7 @@ static int claim_locality(struct udevice *dev, int loc)return -EPERM ; }log_info ("Claimed locality %d\n" , loc); + priv->locality = loc;return 0 ; }
@@ -559,7 +561,11 @@ static int cr50_i2c_open(struct udevice *dev)static int cr50_i2c_cleanup (struct udevice *dev) { -release_locality (dev,1 ); +struct cr50_priv *priv =dev_get_priv (dev); + +printf ("%s: cleanup %d\n" , __func__, priv->locality); +if (priv->locality !=-1 ) +release_locality (dev,1 );return 0 ; }
@@ -631,6 +637,7 @@ static int cr50_i2c_probe(struct udevice *dev)return log_msg_ret ("vendor-id" , -EXDEV ); } priv->vendor = vendor; + priv->locality =-1 ;return 0 ; }
@@ -655,5 +662,7 @@ U_BOOT_DRIVER(cr50_i2c) = { .ops = &cr50_i2c_ops, .ofdata_to_platdata = cr50_i2c_ofdata_to_platdata, .probe = cr50_i2c_probe, + .remove = cr50_i2c_cleanup, .priv_auto_alloc_size = sizeof(struct cr50_priv), + .flags = DM_FLAG_OS_PREPARE, };
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 4/39 tpm: cr50: Add a comment for cr50_priv
In reply to Simon GlassAdd a comment for the private structure
---
Changes in v2:
- Drop the other comment change since it is already applied
drivers/tpm/cr50_i2c.c | 9 +++++++++ 1 file changed, 9 insertions(+)
drivers/tpm/cr50_i2c.c +9 -0
@@ -34,6 +34,15 @@ enum { CR50_MAX_BUF_SIZE = 63, }; +/** +* struct cr50_priv - Private driver data +* +* @ready_gpio: GPIO to use to check if the TPM is ready +* @irq: IRQ to use check if the TPM is ready (has priority over @ready_gpio) +* @locality: Currenttly claimed locality (-1 if none) +* @vendor: vendor: Vendor ID for TPM +* @use_irq: true to use @irq, false to use @ready if available +*/ struct cr50_priv {struct gpio_desc ready_gpio;struct irq irq;
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 5/39 tpm: cr50: Use the correct GPIO binding
In reply to Simon GlassThis device should use ready-gpios rather than ready-gpio. Fix it.
---
Changes in v2: None
arch/x86/dts/chromebook_coral.dts | 2 +- doc/device-tree-bindings/gpio/intel,apl-gpio.txt | 2 +- .../interrupt-controller/intel,acpi-gpe.txt | 2 +- drivers/tpm/cr50_i2c.c | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-)
arch/x86/dts/chromebook_coral.dts +1 -1
@@ -292,7 +292,7 @@ reg = <0x50>; compatible = "google,cr50"; u-boot,i2c-offset-len = <0>; - ready-gpio = <&gpio_n 28 GPIO_ACTIVE_LOW>; + ready-gpios = <&gpio_n 28 GPIO_ACTIVE_LOW>; interrupts-extended = <&acpi_gpe 0x3c 0>; }; };
doc/device-tree-bindings/gpio/intel,apl-gpio.txt +1 -1
@@ -47,7 +47,7 @@ Example: reg = <0x50>; compatible = "google,cr50"; u-boot,i2c-offset-len = <0>; - ready-gpio = <&gpio_n GPIO_28 GPIO_ACTIVE_LOW>; + ready-gpios = <&gpio_n GPIO_28 GPIO_ACTIVE_LOW>; }; };
doc/device-tree-bindings/interrupt-controller/intel,acpi-gpe.txt +1 -1
@@ -25,6 +25,6 @@ Example: tpm at 50 { reg = <0x50>; compatible = "google,cr50"; - ready-gpio = <&gpio_n 0x1c GPIO_ACTIVE_LOW>; + ready-gpios = <&gpio_n 0x1c GPIO_ACTIVE_LOW>; interrupts-extended = <&acpi_gpe 0x3c 0>; };
drivers/tpm/cr50_i2c.c +1 -1
@@ -607,7 +607,7 @@ static int cr50_i2c_ofdata_to_platdata(struct udevice *dev) priv->irq = irq; priv->use_irq = true; }else { - ret =gpio_request_by_name (dev,"ready-gpio" ,0 , + ret =gpio_request_by_name (dev,"ready-gpios" ,0 , &priv->ready_gpio,GPIOD_IS_IN );if (ret) { log_warning("Cr50 does not have an ready GPIO/interrupt (err=%d)\n",
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 6/39 tpm: Don't cleanup unless an error happens
In reply to Simon GlassAt present the cleanup() method is called on every transfer. It should only be called on failing transfers. Fix this and tidy up the error handling a little.
---
Changes in v2: None
drivers/tpm/tpm-uclass.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-)
drivers/tpm/tpm-uclass.c +10 -3
@@ -72,7 +72,7 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size,struct tpm_ops *ops =tpm_get_ops (dev);ulong start, stop;uint count, ordinal; -int ret, ret2; +int ret, ret2 =0 ;if (ops->xfer)return ops->xfer (dev, sendbuf, send_size, recvbuf, recv_size);
@@ -120,9 +120,16 @@ int tpm_xfer(struct udevice *dev, const uint8_t *sendbuf, size_t send_size, } }while (ret); - ret2 = ops->cleanup ? ops->cleanup (dev) :0 ; +if (ret) { +if (ops->cleanup) { + ret2 = ops->cleanup (dev); +if (ret2) +return log_msg_ret ("cleanup" , ret2); + } +return log_msg_ret ("xfer" , ret); + } -return ret2 ? ret2 : ret; +return 0 ; }UCLASS_DRIVER (tpm) = {
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 7/39 dm: pci: Allow disabling auto-config for a device
In reply to Simon GlassAdd a means to avoid configuring a device when needed. Add an explanation of why this is useful to the binding file.
---
Changes in v2: None
doc/device-tree-bindings/pci/x86-pci.txt | 24 ++++++++++++++++++++++++ drivers/pci/pci-uclass.c | 2 ++ 2 files changed, 26 insertions(+)
doc/device-tree-bindings/pci/x86-pci.txt +24 -0
@@ -10,6 +10,17 @@ Optional properties: configuration in TPL/SPL to reduce code size and boot time, since these phases only know about a small subset of PCI devices. +For PCI devices the following optional property is available: + +- pci,no-autoconfig : Don't automatically configure this PCI device at all. + This is used when the device is statically configured and must maintain + this same config throughout the boot process. An example is a serial + UART being used to debug PCI configuration, since reconfiguring it stops + the UART from working until the driver is re-probed, and this can cause + output to be lost. This should not generally be used in production code, + although it is often harmless. + + Example: pci {
@@ -21,4 +32,17 @@ pci { 0x42000000 0x0 0xb0000000 0xb0000000 0 0x10000000 0x01000000 0x0 0x1000 0x1000 0 0xefff>; u-boot,skip-auto-config-until-reloc; + + + serial: serial at 18,2 { + reg = <0x0200c210 0 0 0 0>; + u-boot,dm-pre-reloc; + compatible = "intel,apl-ns16550"; + early-regs = <0xde000000 0x20>; + reg-shift = <2>; + clock-frequency = <1843200>; + current-speed = <115200>; + acpi,name = "URT3"; + pci,no-autoconfig; + }; };
drivers/pci/pci-uclass.c +2 -0
@@ -536,6 +536,8 @@ int pci_auto_config_devices(struct udevice *bus)int ret;debug ("%s: device %s\n" , __func__, dev->name); +if (dev_read_bool (dev,"pci,no-autoconfig" )) +continue ; ret =dm_pciauto_config_device (dev);if (ret <0 )return ret;
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 7/39 dm: pci: Allow disabling auto-config for a device
Quoted 43 lines · Simon Glass
Add a means to avoid configuring a device when needed. Add an explanation of why this is useful to the binding file.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2: None
doc/device-tree-bindings/pci/x86-pci.txt | 24 ++++++++++++++++++++++++ drivers/pci/pci-uclass.c | 2 ++ 2 files changed, 26 insertions(+)doc/device-tree-bindings/pci/x86-pci.txt +14
-0@@ -10,6 +10,17 @@ Optional properties: configuration in TPL/SPL to reduce code size and boot time, since these phases only know about a small subset of PCI devices. +For PCI devices the following optional property is available: + +- pci,no-autoconfig : Don't automatically configure this PCI device at all. + This is used when the device is statically configured and must maintain + this same config throughout the boot process. An example is a serial + UART being used to debug PCI configuration, since reconfiguring it stops + the UART from working until the driver is re-probed, and this can cause + output to be lost. This should not generally be used in production code, + although it is often harmless. + + Example: pci {@@ -21,4 +32,17 @@ pci { 0x42000000 0x0 0xb0000000 0xb0000000 0 0x10000000 0x01000000 0x0 0x1000 0x1000 0 0xefff>; u-boot,skip-auto-config-until-reloc; + + + serial: serial at 18,2 {
doc/device-tree-bindings/pci/x86-pci.txt pci { · line 45
Quoted 10 lines
doc/device-tree-bindings/pci/x86-pci.txt +8
-0+ reg = <0x0200c210 0 0 0 0>; + u-boot,dm-pre-reloc; + compatible = "intel,apl-ns16550"; + early-regs = <0xde000000 0x20>; + reg-shift = <2>; + clock-frequency = <1843200>; + current-speed = <115200>; + acpi,name = "URT3";
Is this somehow being handled by the code at this point?
If no, please move to the patch that actually adds this functionality.
Quoted 19 lines
doc/device-tree-bindings/pci/x86-pci.txt +2
-0+ pci,no-autoconfig; + }; };drivers/pci/pci-uclass.c +2
-1@@ -536,6 +536,8 @@ int pci_auto_config_devices(struct udevice *bus)int ret;debug ("%s: device %s\n" , __func__, dev->name); +if (dev_read_bool (dev,"pci,no-autoconfig" )) +continue ; ret =dm_pciauto_config_device (dev);if (ret <0 )return ret; --2.25.1.481.gfbce0eb801-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 8/39 x86: Correct wording of coreboot source code
In reply to Simon GlassSome files are taken or modified from coreboot, but the files are no-longer part of the coreboot project. Fix the wording in a few places.
---
Changes in v2: None
arch/x86/cpu/coreboot/timestamp.c | 4 ++-- arch/x86/include/asm/arch-coreboot/timestamp.h | 4 ++-- arch/x86/include/asm/intel_pinctrl_defs.h | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-)
arch/x86/cpu/coreboot/timestamp.c +2 -2
@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0+ /* -* This file is part of the coreboot project. -* * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. +* +* Modified from the coreboot version */ #include <common.h>
arch/x86/include/asm/arch-coreboot/timestamp.h +2 -2
@@ -1,8 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* This file is part of the coreboot project. -* * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. +* +* Taken from the coreboot version */ #ifndef __COREBOOT_TIMESTAMP_H__
arch/x86/include/asm/intel_pinctrl_defs.h +0 -2
@@ -1,7 +1,5 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* This file is part of the coreboot project. -* * Copyright (C) 2015-2016 Intel Corp. * Copyright 2019 Google LLC *
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 08/39] x86: Correct wording of coreboot source code
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 6 lines
Some files are taken or modified from coreboot, but the files are no-longer part of the coreboot project. Fix the wording in a few places.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>
Quoted 8 lines
---
Changes in v2: None
arch/x86/cpu/coreboot/timestamp.c | 4 ++-- arch/x86/include/asm/arch-coreboot/timestamp.h | 4 ++-- arch/x86/include/asm/intel_pinctrl_defs.h | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-)
PATCH v2 8/39 x86: Correct wording of coreboot source code
In reply to Simon GlassQuoted 20 lines · Simon Glass
Some files are taken or modified from coreboot, but the files are no-longer part of the coreboot project. Fix the wording in a few places.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2: None
arch/x86/cpu/coreboot/timestamp.c | 4 ++-- arch/x86/include/asm/arch-coreboot/timestamp.h | 4 ++-- arch/x86/include/asm/intel_pinctrl_defs.h | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-)arch/x86/cpu/coreboot/timestamp.c +0
-0
arch/x86/cpu/coreboot/timestamp.c line 5
Quoted 7 lines
arch/x86/cpu/coreboot/timestamp.c +2
-2@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0+ /* -* This file is part of the coreboot project. -* * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. +* +* Modified from the coreboot version
Perhaps leave the period at the end of the line to follow English punctuation?
Quoted 33 lines
arch/x86/cpu/coreboot/timestamp.c +0
-0*/ #include <common.h> arch/x86/include/asm/arch-coreboot/timestamp.h +2
-2@@ -1,8 +1,8 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* This file is part of the coreboot project. -* * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. +* +* Taken from the coreboot version */ #ifndef __COREBOOT_TIMESTAMP_H__arch/x86/include/asm/intel_pinctrl_defs.h +0
-3@@ -1,7 +1,5 @@/* SPDX-License-Identifier: GPL-2.0 */ /* -* This file is part of the coreboot project. -* * Copyright (C) 2015-2016 Intel Corp. * Copyright 2019 Google LLC * -- 2.25.1.481.gfbce0eb801-goog
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 8/39 x86: Correct wording of coreboot source code
Hi Andy,
Quoted 17 lines · Andy Shevchenko
Quoted 15 lines · Simon Glass
Some files are taken or modified from coreboot, but the files are no-longer part of the coreboot project. Fix the wording in a few places.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2: None
arch/x86/cpu/coreboot/timestamp.c | 4 ++-- arch/x86/include/asm/arch-coreboot/timestamp.h | 4 ++-- arch/x86/include/asm/intel_pinctrl_defs.h | 2 -- 3 files changed, 4 insertions(+), 6 deletions(-)
Quoted 14 lines
arch/x86/cpu/coreboot/timestamp.c line 5
Quoted 12 lines
arch/x86/cpu/coreboot/timestamp.c +2
-2@@ -1,8 +1,8 @@// SPDX-License-Identifier: GPL-2.0+ /* -* This file is part of the coreboot project. -* * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved. +* +* Modified from the coreboot version Perhaps leave the period at the end of the line to follow English punctuation?
This is actually something I try to avoid. It is not a sentence and turning it into one by adding more words doesn't improve its value IMO.
Regards,
Simon
PATCH v2 9/39 x86: apl: Move p2sb ofdata reading to the correct method
In reply to Simon GlassWith P2SB the initial BAR (base-address register) is set up by TPL and this is used unchanged right through U-Boot.
At present the reading of this address is split between the ofdata() and probe() methods. There are a few problems that are unique to the p2sb. One is that its children need to call pcr_read32(), etc. which needs to have the p2sb address correct. Also some of its children are pinctrl devices and pinctrl is used when any device is probed. So p2sb really needs to get its base address set up in ofdata_to_platdata(), before it is probed.
Another point is that reading the p2sb BAR will not work if the p2sb is hidden. The FSP-S seems to hide it, presumably to avoid confusing PCI enumeration.
Reading ofdata in ofdata_to_platdata() is the correct place anyway, so this is easy to fix.
Move the code into one place and use the early-regs property in all cases for simplicity and to avoid needing to probe any PCI devices just to read the BAR.
---
Changes in v2: None
arch/x86/cpu/intel_common/p2sb.c | 35 +++++++++++--------------------- 1 file changed, 12 insertions(+), 23 deletions(-)
arch/x86/cpu/intel_common/p2sb.c +12 -23
@@ -92,46 +92,35 @@ int p2sb_ofdata_to_platdata(struct udevice *dev)#if !CONFIG_IS_ENABLED (OF_PLATDATA )int ret; +u32 base[2 ]; + ret =dev_read_u32_array (dev,"early-regs" , base,ARRAY_SIZE (base)); +if (ret) +return log_msg_ret ("Missing/short early-regs" , ret); + plat->mmio_base = base[0 ]; +/* TPL sets up the initial BAR */ if (spl_phase () ==PHASE_TPL ) { -u32 base[2 ]; - -/* TPL sets up the initial BAR */ - ret =dev_read_u32_array (dev,"early-regs" , base, -ARRAY_SIZE (base)); -if (ret) -return log_msg_ret ("Missing/short early-regs" , ret); - plat->mmio_base = base[0 ]; plat->bdf =pci_get_devfn (dev);if (plat->bdf <0 )return log_msg_ret ("Cannot get p2sb PCI address" , - plat->bdf); + plat->bdf); } + upriv->mmio_base = plat->mmio_base;#else plat->mmio_base = plat->dtplat.early_regs[0 ]; plat->bdf =pci_ofplat_get_devfn (plat->dtplat.reg[0 ]); -#endif upriv->mmio_base = plat->mmio_base; -debug ("p2sb: mmio_base=%x\n" , (uint )plat->mmio_base); +#endif return 0 ; }static int p2sb_probe (struct udevice *dev) { -if (spl_phase () ==PHASE_TPL ) { +if (spl_phase () ==PHASE_TPL )return p2sb_early_init (dev); - }else { -struct p2sb_platdata *plat =dev_get_platdata (dev); - - plat->mmio_base =dev_read_addr_pci (dev); -/* Don't set BDF since it should not be used */ -if (!plat->mmio_base || plat->mmio_base ==FDT_ADDR_T_NONE ) -return -EINVAL ; - -if (spl_phase () ==PHASE_SPL ) -return p2sb_spl_init (dev); - } +else if (spl_phase () ==PHASE_SPL ) +return p2sb_spl_init (dev);return 0 ; }
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 9/39 x86: apl: Move p2sb ofdata reading to the correct method
Quoted 22 lines · Simon Glass
With P2SB the initial BAR (base-address register) is set up by TPL and this is used unchanged right through U-Boot.
At present the reading of this address is split between the
ofdata()andprobe()methods. There are a few problems that are unique to the p2sb. One is that its children need to callpcr_read32(), etc. which needs to have the p2sb address correct. Also some of its children are pinctrl devices and pinctrl is used when any device is probed. So p2sb really needs to get its base address set up inofdata_to_platdata(), before it is probed.Another point is that reading the p2sb BAR will not work if the p2sb is hidden. The FSP-S seems to hide it, presumably to avoid confusing PCI enumeration.
Reading ofdata in
ofdata_to_platdata()is the correct place anyway, so this is easy to fix.Move the code into one place and use the early-regs property in all cases for simplicity and to avoid needing to probe any PCI devices just to read the BAR.
arch/x86/cpu/intel_common/p2sb.c int p2sb_ofdata_to_platdata(struct udevice *dev) · line 106
Quoted 4 lines
arch/x86/cpu/intel_common/p2sb.c +1
-1if (plat->bdf <0 )return log_msg_ret ("Cannot get p2sb PCI address" , - plat->bdf); + plat->bdf);
Not sure I understand this hunk WRT the patch itself.
arch/x86/cpu/intel_common/p2sb.c int p2sb_ofdata_to_platdata(struct udevice *dev)
Quoted 4 lines
arch/x86/cpu/intel_common/p2sb.c +2
-0+if (spl_phase () ==PHASE_TPL )return p2sb_early_init (dev); +else if (spl_phase () ==PHASE_SPL )
Redundant 'else', but I think we already discussed that and you prefer this way. However, I think this is waste of compilation time. In any case, matter of taste.
Quoted 1 line
arch/x86/cpu/intel_common/p2sb.c +1
-0+return p2sb_spl_init (dev);
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 9/39 x86: apl: Move p2sb ofdata reading to the correct method
Hi Andy,
Quoted 24 lines · Andy Shevchenko
Quoted 21 lines · Simon Glass
With P2SB the initial BAR (base-address register) is set up by TPL and this is used unchanged right through U-Boot.
At present the reading of this address is split between the
ofdata()andprobe()methods. There are a few problems that are unique to the p2sb. One is that its children need to callpcr_read32(), etc. which needs to have the p2sb address correct. Also some of its children are pinctrl devices and pinctrl is used when any device is probed. So p2sb really needs to get its base address set up inofdata_to_platdata(), before it is probed.Another point is that reading the p2sb BAR will not work if the p2sb is hidden. The FSP-S seems to hide it, presumably to avoid confusing PCI enumeration.
Reading ofdata in
ofdata_to_platdata()is the correct place anyway, so this is easy to fix.Move the code into one place and use the early-regs property in all cases for simplicity and to avoid needing to probe any PCI devices just to read the BAR.
Quoted 6 lines
arch/x86/cpu/intel_common/p2sb.c int p2sb_ofdata_to_platdata(struct udevice *dev) · line 106
Quoted 4 lines
if (
plat->bdf< 0)
return log_msg_ret("Cannot get p2sb PCI address",arch/x86/cpu/intel_common/p2sb.c +1
-1- plat->bdf); + plat->bdf);Not sure I understand this hunk WRT the patch itself.
This is to fix a checkpatch error - it reports problems in nearby lines.
Quoted 9 lines
arch/x86/cpu/intel_common/p2sb.c int p2sb_ofdata_to_platdata(struct udevice *dev)
Quoted 5 lines
arch/x86/cpu/intel_common/p2sb.c +2
-0+if (spl_phase () ==PHASE_TPL )return p2sb_early_init (dev); +else if (spl_phase () ==PHASE_SPL )Redundant 'else', but I think we already discussed that and you prefer this way. However, I think this is waste of compilation time. In any case, matter of taste.
Yes. I feel that it shows that there are two options.
Just for fun I wrote a program to try to benchmark the difference and it does not seem to be detectable.
Quoted 2 lines
Quoted 2 lines
+ return
p2sb_spl_init(dev);
Regards,
Simon
PATCH v2 9/39 x86: apl: Move p2sb ofdata reading to the correct method
Quoted 4 lines · Simon Glass
Quoted 1 line · Andy Shevchenko
On Sun, Mar 08, 2020 at 09:44:33PM -0600, Simon Glass wrote:
Quoted 8 lines
Quoted 6 lines
arch/x86/cpu/intel_common/p2sb.c int p2sb_ofdata_to_platdata(struct udevice *dev) · line 106
Quoted 4 lines
if (
plat->bdf< 0)
return log_msg_ret("Cannot get p2sb PCI address",arch/x86/cpu/intel_common/p2sb.c +1
-1- plat->bdf); + plat->bdf);Not sure I understand this hunk WRT the patch itself.
This is to fix a checkpatch error - it reports problems in nearby lines.
So, checkpatch insist on wrong indentation?!
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines
arch/x86/cpu/intel_common/p2sb.c +2
-0+if (spl_phase () ==PHASE_TPL )return p2sb_early_init (dev); +else if (spl_phase () ==PHASE_SPL )
Quoted 8 lines
Quoted 3 lines
Redundant 'else', but I think we already discussed that and you prefer this way. However, I think this is waste of compilation time. In any case, matter of taste.
Yes. I feel that it shows that there are two options.
Just for fun I wrote a program to try to benchmark the difference and it does not seem to be detectable.
Compiler optimizes it away in any case, so, you won't see any difference.
Quoted 1 line
Quoted 1 line
Quoted 1 line
+ return
p2sb_spl_init(dev);
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 10/39 pci: Adjust dm_pci_read_bar32() to return errors correctly
In reply to Simon GlassAt present if reading a BAR returns 0xffffffff (e.g. the device is not present) then the value is masked and a different value is returned. This makes it harder to detect the problem when debugging.
Update the function to avoid masking in this case.
---
Changes in v2: None
drivers/pci/pci-uclass.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
drivers/pci/pci-uclass.c +8 -1
@@ -1213,7 +1213,14 @@ u32 dm_pci_read_bar32(const struct udevice *dev, int barnum) bar =PCI_BASE_ADDRESS_0 + barnum *4 ;dm_pci_read_config32 (dev, bar, &addr); -if (addr &PCI_BASE_ADDRESS_SPACE_IO ) + +/* +* If we get an invalid address, return this so that comparisons with +* FDT_ADDR_T_NONE work correctly +*/ +if (addr ==0xffffffff ) +return addr; +else if (addr &PCI_BASE_ADDRESS_SPACE_IO )return addr &PCI_BASE_ADDRESS_IO_MASK ;else return addr &PCI_BASE_ADDRESS_MEM_MASK ;
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 10/39] pci: Adjust dm_pci_read_bar32() to return errors correctly
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 7 lines
At present if reading a BAR returns
0xffffffff(e.g. the device is not present) then the value is masked and a different value is returned. This makes it harder to detect the problem when debugging.Update the function to avoid masking in this case.
Quoted 8 lines
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2: None
drivers/pci/pci-uclass.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-)
PATCH v2 11/39 x86: apl: Add Global NVS table header
In reply to Simon GlassAdd the C version of this header. It includes a few Chrome OS bits which are disabled for a normal build.
---
Changes in v2:
- Drop the Chrome OS pieces
- Rename the 'coreboot' console to 'U-Boot'
.../include/asm/arch-apollolake/global_nvs.h | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 arch/x86/include/asm/arch-apollolake/global_nvs.h
arch/x86/include/asm/arch-apollolake/global_nvs.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2015-2017 Intel Corp. +* (Written by Lance Zhao <[email protected]> for Intel Corp.) +* Copyright Google LLC 2019 +* +* Modified from coreboot apollolake/include/soc/nvs.h +*/ + +#ifndef _GLOBAL_NVS_H_ +#define _GLOBAL_NVS_H_ + +struct __packed acpi_global_nvs { +/* Miscellaneous */ +u8 pcnt;/* 0x00 - Processor Count */ +u8 ppcm;/* 0x01 - Max PPC State */ +u8 lids;/* 0x02 - LID State */ +u8 pwrs;/* 0x03 - AC Power State */ +u8 dpte;/* 0x04 - Enable DPTF */ +u32 cbmc;/* 0x05 - 0x08 - U-Boot Console */ +u64 pm1i;/* 0x09 - 0x10 - System Wake Source - PM1 Index */ +u64 gpei;/* 0x11 - 0x18 - GPE Wake Source */ +u64 nhla;/* 0x19 - 0x20 - NHLT Address */ +u32 nhll;/* 0x21 - 0x24 - NHLT Length */ +u32 prt0;/* 0x25 - 0x28 - PERST_0 Address */ +u8 scdp;/* 0x29 - SD_CD GPIO portid */ +u8 scdo;/* 0x2A - GPIO pad offset relative to the community */ +u8 uior;/* 0x2B - UART debug controller init on S3 resume */ +u8 ecps;/* 0x2C - SGX Enabled status */ +u64 emna;/* 0x2D - 0x34 EPC base address */ +u64 elng;/* 0x35 - 0x3C EPC Length */ +u8 unused[195 ]; +u8 unused2[0xf00 ]; +#endif +}; + +#endif /* _GLOBAL_NVS_H_ */
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 11/39] x86: apl: Add Global NVS table header
Hi Simon,
Quoted 46 lines
-----"Simon Glass" <[email protected]> schrieb: -----
Add the C version of this header. It includes a few Chrome OS bits which are disabled for a normal build.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Drop the Chrome OS pieces
- Rename the 'coreboot' console to 'U-Boot'.../include/asm/arch-apollolake/global_nvs.h | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 arch/x86/include/asm/arch-apollolake/global_nvs.harch/x86/include/asm/arch-apollolake/global_nvs.h new file +24
-0@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright (C) 2015-2017 Intel Corp. +* (Written by Lance Zhao <[email protected]> for Intel Corp.) +* Copyright Google LLC 2019 +* +* Modified from coreboot apollolake/include/soc/nvs.h +*/ + +#ifndef _GLOBAL_NVS_H_ +#define _GLOBAL_NVS_H_ + +struct __packed acpi_global_nvs { +/* Miscellaneous */ +u8 pcnt;/* 0x00 - Processor Count */ +u8 ppcm;/* 0x01 - Max PPC State */ +u8 lids;/* 0x02 - LID State */ +u8 pwrs;/* 0x03 - AC Power State */ +u8 dpte;/* 0x04 - Enable DPTF */ +u32 cbmc;/* 0x05 - 0x08 - U-Boot Console */ +u64 pm1i;/* 0x09 - 0x10 - System Wake Source - PM1 Index */ +u64 gpei;/* 0x11 - 0x18 - GPE Wake Source */ +u64 nhla;/* 0x19 - 0x20 - NHLT Address */ +u32 nhll;/* 0x21 - 0x24 - NHLT Length */
arch/x86/include/asm/arch-apollolake/global_nvs.h line 34
Quoted 10 lines
arch/x86/include/asm/arch-apollolake/global_nvs.h new file +10
-0+u32 prt0;/* 0x25 - 0x28 - PERST_0 Address */ +u8 scdp;/* 0x29 - SD_CD GPIO portid */ +u8 scdo;/* 0x2A - GPIO pad offset relative to the community */ +u8 uior;/* 0x2B - UART debug controller init on S3 resume */ +u8 ecps;/* 0x2C - SGX Enabled status */ +u64 emna;/* 0x2D - 0x34 EPC base address */ +u64 elng;/* 0x35 - 0x3C EPC Length */ +u8 unused[195 ]; +u8 unused2[0xf00 ]; +#endif
Something happened here in v2, there is no matching #if for the #endif anymore.
Quoted 5 lines
arch/x86/include/asm/arch-apollolake/global_nvs.h new file +3
-0+}; + +#endif /* _GLOBAL_NVS_H_ */ Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 12/39 dm: core: Add basic ACPI support
In reply to Simon GlassACPI (Advanced Configuration and Power Interface) is an Intel standard for specifying information about a platform. It is a little like device tree but considerably more complicated and with more backslashes. A primary difference is that it supports an interpreted bytecode language.
Driver model does not use ACPI for U-Boot's configuration, but it is convenient to have it support generation of ACPI tables for passing to Linux, etc.
As a starting point, add an optional set of ACPI operations to each device. Initially only a single operation is available, to obtain the ACPI name for the device. More operations are added later.
Enable ACPI for sandbox to ensure build coverage and so that we can add tests.
---
Changes in v2:
- Move LOGC_ACPI definition to this patch
drivers/core/Kconfig | 9 ++++++ drivers/core/Makefile | 1 + drivers/core/acpi.c | 32 +++++++++++++++++++ include/dm/acpi.h | 73 +++++++++++++++++++++++++++++++++++++++++++ include/dm/device.h | 5 +++ include/log.h | 2 ++ 6 files changed, 122 insertions(+) create mode 100644 drivers/core/acpi.c create mode 100644 include/dm/acpi.h
drivers/core/Kconfig +9 -0
@@ -261,4 +261,13 @@ config DM_DEV_READ_INLINE bool default y if !OF_LIVE +config ACPIGEN + bool "Support ACPI table generation in driver model" + default y if SANDBOX || GENERATE_ACPI_TABLE + help + This option enables generation of ACPI tables using driver-model + devices. It adds a new operation struct to each driver, to support + things like generating device-specific tables and returning the ACPI + name of a device. + endmenu
drivers/core/Makefile +1 -0
@@ -3,6 +3,7 @@ # Copyright (c) 2013 Google, Inc obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o +obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o obj-$(CONFIG_$(SPL_)SIMPLE_BUS) += simple-bus.o
drivers/core/acpi.c new file +32 -0
@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Core driver model support for ACPI table generation +* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#define LOG_CATEOGRY LOGC_ACPI + +#include <common.h> +#include <dm.h> +#include <dm/acpi.h> +#include <dm/root.h> + +int acpi_return_name (char *out_name,const char *name) +{ +strcpy (out_name, name); + +return 0 ; +} + +int acpi_get_name (const struct udevice *dev,char *out_name) +{ +struct acpi_ops *aops; + + aops =device_get_acpi_ops (dev); +if (aops && aops->get_name) +return aops->get_name (dev, out_name); + +return -ENOSYS ; +}
include/dm/acpi.h new file +73 -0
73 lines not on this page · raw message
include/dm/device.h +5 -0
@@ -245,6 +245,8 @@ struct udevice_id {* pointers defined by the driver, to implement driver functions required by * the uclass. * @flags: driver flags - see DM_FLAGS_... +* @acpi_ops: Advanced Configuration and Power Interface (ACPI) operations, +* allowing the device to add things to the ACPI tables passed to Linux */ struct driver {char *name;
@@ -264,6 +266,9 @@ struct driver {int per_child_platdata_auto_alloc_size;const void *ops;/* driver-specific operations */ uint32_t flags; +#if CONFIG_IS_ENABLED (ACPIGEN ) +struct acpi_ops *acpi_ops; +#endif };/* Declare a new U-Boot driver */
include/log.h +2 -0
@@ -51,6 +51,8 @@ enum log_category_t {LOGC_SANDBOX ,/* Related to the sandbox board */ LOGC_BLOBLIST ,/* Bloblist */ LOGC_DEVRES ,/* Device resources (devres_... functions) */ +/* Intel Advanced Configuration and Power Interface (ACPI) */ +LOGC_ACPI ,LOGC_COUNT ,/* Number of log categories */ LOGC_END, /* Sentinel value for a list of log categories */
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 12/39] dm: core: Add basic ACPI support
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 76 lines
ACPI (Advanced Configuration and Power Interface) is an Intel standard for specifying information about a platform. It is a little like device tree but considerably more complicated and with more backslashes. A primary difference is that it supports an interpreted bytecode language.
Driver model does not use ACPI for U-Boot's configuration, but it is convenient to have it support generation of ACPI tables for passing to Linux, etc.
As a starting point, add an optional set of ACPI operations to each device. Initially only a single operation is available, to obtain the ACPI name for the device. More operations are added later.
Enable ACPI for sandbox to ensure build coverage and so that we can add tests.
Reviewed-by Bin Meng <[email protected]>Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- MoveLOGC_ACPIdefinition to this patchdrivers/core/Kconfig | 9 ++++++ drivers/core/Makefile | 1 + drivers/core/acpi.c | 32 +++++++++++++++++++ include/dm/acpi.h | 73 +++++++++++++++++++++++++++++++++++++++++++ include/dm/device.h | 5 +++ include/log.h | 2 ++ 6 files changed, 122 insertions(+) create mode 100644 drivers/core/acpi.c create mode 100644 include/dm/acpi.hdrivers/core/Kconfig +9
-0@@ -261,4 +261,13 @@ config DM_DEV_READ_INLINE bool default y if !OF_LIVE +config ACPIGEN + bool "Support ACPI table generation in driver model" + default y if SANDBOX || GENERATE_ACPI_TABLE + help + This option enables generation of ACPI tables using driver-model + devices. It adds a new operation struct to each driver, to support + things like generating device-specific tables and returning the ACPI + name of a device. + endmenudrivers/core/Makefile +1
-0@@ -3,6 +3,7 @@ # Copyright (c) 2013 Google, Inc obj-y += device.o fdtaddr.o lists.o root.o uclass.o util.o +obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi.o obj-$(CONFIG_DEVRES) += devres.o obj-$(CONFIG_$(SPL_)DM_DEVICE_REMOVE) += device-remove.o obj-$(CONFIG_$(SPL_)SIMPLE_BUS) += simple-bus.odrivers/core/acpi.c new file +6
-0@@ -0,0 +1,32 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Core driver model support for ACPI table generation +* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]>
drivers/core/acpi.c line 16
Quoted 10 lines
drivers/core/acpi.c new file +10
-0+*/ + +#define LOG_CATEOGRY LOGC_ACPI + +#include <common.h> +#include <dm.h> +#include <dm/acpi.h> +#include <dm/root.h> + +int acpi_return_name (char *out_name,const char *name)
A few nits:
* IMHO acpi_copy_name() would be a more fitting name. The function does not return a name, it copies it.
* Could we use strncpy + explicit null-termination instead of strcpy?
Quoted 123 lines
drivers/core/acpi.c new file +16
-0+{ +strcpy (out_name, name); + +return 0 ; +} + +int acpi_get_name (const struct udevice *dev,char *out_name) +{ +struct acpi_ops *aops; + + aops =device_get_acpi_ops (dev); +if (aops && aops->get_name) +return aops->get_name (dev, out_name); + +return -ENOSYS ; +}include/dm/acpi.h new file +73
-0@@ -0,0 +1,73 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Core ACPI (Advanced Configuration and Power Interface) support +* +* Copyright 2019 Google LLC +* Written by Simon Glass <[email protected]> +*/ + +#ifndef __DM_ACPI_H__ +#define __DM_ACPI_H__ + +/* Allow operations to be optional for ACPI */ +#if CONFIG_IS_ENABLED (ACPIGEN ) +#define acpi_ops_ptr (_ptr) .acpi_ops = _ptr, +#else +#define acpi_ops_ptr (_ptr) +#endif + +/* Length of an ACPI name string, excluding nul terminator */ +#define ACPI_NAME_LEN 4 + +/* Length of an ACPI name string including nul terminator */ +#define ACPI_NAME_MAX 5 + +/** +* struct acpi_ops - ACPI operations supported by driver model +*/ +struct acpi_ops { +/** +* get_name() - Obtain the ACPI name of a device +* +* @dev: Device to check +* @out_name: Place to put the name, must hold at least ACPI_NAME_MAX +* bytes +* @return 0 if OK, -ENOENT if no name is available, other -ve value on +* other error +*/ +int (*get_name)(const struct udevice *dev,char *out_name); +}; + +#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops) + +/** +* acpi_get_name() - Obtain the ACPI name of a device +* +* @dev: Device to check +* @out_name: Place to put the name, must hold at least ACPI_NAME_MAX +* bytes +* @return 0 if OK, -ENOENT if no name is available, other -ve value on +* other error +*/ +int acpi_get_name (const struct udevice *dev,char *out_name); + +/** +* acpi_return_name() - Copy an ACPI name to an output buffer +* +* This convenience function can be used to return a literal string as a name +* in functions that implement the get_name() method. +* +* For example: +* +* static int mydev_get_name(const struct udevice *dev, char *out_name) +* { +* return acpi_return_name(out_name, "WIBB"); +* } +* +* @out_name: Place to put the name +* @name: Name to copy +* @return 0 (always) +*/ +int acpi_return_name (char *out_name,const char *name); + +#endif include/dm/device.h +5
-0@@ -245,6 +245,8 @@ struct udevice_id {* pointers defined by the driver, to implement driver functions required by * the uclass. * @flags: driver flags - see DM_FLAGS_... +* @acpi_ops: Advanced Configuration and Power Interface (ACPI) operations, +* allowing the device to add things to the ACPI tables passed to Linux */ struct driver {char *name;@@ -264,6 +266,9 @@ struct driver {int per_child_platdata_auto_alloc_size;const void *ops;/* driver-specific operations */ uint32_t flags; +#if CONFIG_IS_ENABLED (ACPIGEN ) +struct acpi_ops *acpi_ops; +#endif };/* Declare a new U-Boot driver */ include/log.h +0
-0
include/log.h enum log_category_t { · line 54
Quoted 4 lines
include/log.h +1
-0@@ -51,6 +51,8 @@ enum log_category_t {LOGC_SANDBOX ,/* Related to the sandbox board */ LOGC_BLOBLIST ,/* Bloblist */ LOGC_DEVRES, /* Device resources (devres_... functions) */ +/* Intel Advanced Configuration and Power Interface (ACPI) */
I would drop the "Intel".
Quoted 7 lines
include/log.h +1
-0+LOGC_ACPI ,LOGC_COUNT ,/* Number of log categories */ LOGC_END, /* Sentinel value for a list of log categories */Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 12/39 dm: core: Add basic ACPI support
In reply to Simon GlassQuoted 1 line · Simon Glass
ACPI (Advanced Configuration and Power Interface) is an Intel standard
Not Intel for a long time. Or more precisely, not *only* Intel.
Also this should be corrected (I guess dropping Intel would work) everywhere in this series.
Quoted 4 lines
for specifying information about a platform.
It is a little like device
tree but considerably more complicated and with more backslashes.
For what purpose this passage?
Isn't the same reason why ARM64 choose ACPI to be supported for servers?
Quoted 13 lines
A
primary difference is that it supports an interpreted bytecode language.Driver model does not use ACPI for U-Boot's configuration, but it is convenient to have it support generation of ACPI tables for passing to Linux, etc.
As a starting point, add an optional set of ACPI operations to each device. Initially only a single operation is available, to obtain the ACPI name for the device. More operations are added later.
Enable ACPI for sandbox to ensure build coverage and so that we can add tests.
...
include/dm/acpi.h line 23
Quoted 5 lines
include/dm/acpi.h new file +5
-0+/* Length of an ACPI name string, excluding nul terminator */ +#define ACPI_NAME_LEN 4 + +/* Length of an ACPI name string including nul terminator */ +#define ACPI_NAME_MAX 5
Do we really need two definitions?
...
include/log.h enum log_category_t { · line 54
Quoted 1 line
include/log.h +1
-0+/* Intel Advanced Configuration and Power Interface (ACPI) */
Same as above for commit message.
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 12/39 dm: core: Add basic ACPI support
Hi Andy,
Quoted 8 lines · Andy Shevchenko
Quoted 1 line · Simon Glass
ACPI (Advanced Configuration and Power Interface) is an Intel standard
Not Intel for a long time. Or more precisely, not *only* Intel.
Also this should be corrected (I guess dropping Intel would work) everywhere in this series.
OK will do.
Quoted 25 lines
Quoted 5 lines
for specifying information about a platform.
It is a little like device
tree but considerably more complicated and with more backslashes.For what purpose this passage?
Isn't the same reason why ARM64 choose ACPI to be supported for servers?Quoted 13 lines
A
primary difference is that it supports an interpreted bytecode language.Driver model does not use ACPI for U-Boot's configuration, but it is convenient to have it support generation of ACPI tables for passing to Linux, etc.
As a starting point, add an optional set of ACPI operations to each device. Initially only a single operation is available, to obtain the ACPI name for the device. More operations are added later.
Enable ACPI for sandbox to ensure build coverage and so that we can add tests.
...
Quoted 7 lines
include/dm/acpi.h line 23
Quoted 5 lines
include/dm/acpi.h new file +5
-0+/* Length of an ACPI name string, excluding nul terminator */ +#define ACPI_NAME_LEN 4 + +/* Length of an ACPI name string including nul terminator */ +#define ACPI_NAME_MAX 5Do we really need two definitions?
It is annoying to have to use
char name[ACPI_NAME_LEN + 1]
everywhere.
On the other hand, some structs don't need a terminator, so we need ACPI_NAME_LEN.
I'll change it so one is computed from the other.
Quoted 7 lines
...
Quoted 1 line
+ /* Intel Advanced Configuration and Power Interface (ACPI) */
Same as above for commit message.
Regards,
Simon
PATCH v2 13/39 acpi: Add a binding for ACPI settings in the device tree
In reply to Simon GlassDevices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
---
Changes in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
doc/device-tree-bindings/device.txt | 36 +++++++++++++++ .../input/hid-over-i2c.txt | 44 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 doc/device-tree-bindings/device.txt create mode 100644 doc/device-tree-bindings/input/hid-over-i2c.txt
doc/device-tree-bindings/device.txt new file +36 -0
@@ -0,0 +1,36 @@ +Devices +======= + +Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented here. See +also hid-over-i2c.txt which describes HID devices. + + - acpi,has-power-resource : (boolean) true if this device has a power resource. + This causes a PRIC (ACPI PowerResource) to be written containing the + properties provided by this binding, to describe how to handle powering the + device up and down using GPIOs + - acpi,compatible : compatible string to report + - acpi,desc : Contains the string to use as the _DDN (DOS (Disk Operating + System) Device Name) + - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HID + - hid-descr-addr : HID register offset (for Human Interface Devices) + - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that + Linux will not re-init the device + - acpi,uid : _UID value for device + + +Example +------- + +synaptics_touchpad: synaptics-touchpad at 2c { + compatible = "hid-over-i2c"; + reg = <0x2c>; + acpi,hid = "PNP0C50"; + acpi,desc = "Synaptics Touchpad"; + interrupts-extended = <&acpi_gpe GPIO_18_IRQ + IRQ_TYPE_EDGE_FALLING>; + acpi,probed; + hid-descr-addr = <0x20>; +};
doc/device-tree-bindings/input/hid-over-i2c.txt new file +44 -0
44 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 13/39] acpi: Add a binding for ACPI settings in the device tree
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 27 lines
Devices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding documentdoc/device-tree-bindings/device.txt | 36 +++++++++++++++ .../input/hid-over-i2c.txt | 44 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 doc/device-tree-bindings/device.txt create mode 100644 doc/device-tree-bindings/input/hid-over-i2c.txtdoc/device-tree-bindings/device.txt new file +0
-0
doc/device-tree-bindings/device.txt line 10
Quoted 10 lines
doc/device-tree-bindings/device.txt new file +10
-0@@ -0,0 +1,36 @@ +Devices +======= + +Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented here. See +also hid-over-i2c.txt which describes HID devices. + + - acpi,has-power-resource : (boolean) true if this device has a power resource. + This causes a PRIC (ACPI PowerResource) to be written containing the
What is the meaning of PRIC? I can't find a defition for this term.
doc/device-tree-bindings/device.txt line 13
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+ properties provided by this binding, to describe how to handle powering the + device up and down using GPIOs + - acpi,compatible : compatible string to report
What does "compatible string" mean in this context? Does it refer to the "Compatible ID" (_CID) of ACPI? As stated in the previous mail thread [1], I think we could infer many of the ACPI properties from existing device tree properties. Especially I suspect that ACPI's _CID could have a 1:1 mapping to the compatible property in device tree. E.g. a driver which states that it is compatible with "hid-over-i2c" in its device tree description would know (implement internally) that it is also compatible with ACPI's _CID "PNP0C50", thus we would not have to add this information in the device tree.
[1] https://lists.denx.de/pipermail/u-boot/2020-February/398856.html
doc/device-tree-bindings/device.txt line 15
Quoted 2 lines
doc/device-tree-bindings/device.txt new file +2
-0+ - acpi,desc : Contains the string to use as the _DDN (DOS (Disk Operating + System) Device Name)
Nit: I assume "desc" stands for "description". But strictly speaking it is not a description, it is a device name. I would prefer something like "acpi,devname" or even "acpi,ddn".
doc/device-tree-bindings/device.txt line 18
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+ - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HID + - hid-descr-addr : HID register offset (for Human Interface Devices)
This property is already described in the file hid-over-i2c.txt (with a similar but slightly different text), thus I would not describe it here also.
doc/device-tree-bindings/device.txt line 20
Quoted 2 lines
doc/device-tree-bindings/device.txt new file +2
-0+ - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that + Linux will not re-init the device
I can't find 'linux,probed' in the Linux kernel.
I only find it in patches specific for chromium-os[2], but the description there does not match the description given here (there it is described as being probed before insertion vs. here it is described as not being probed any more).
[2] https://groups.google.com/a/chromium.org/forum/#!msg/chromium-os-reviews/4HTHl78IGHw/oz82uImnBgAJ
doc/device-tree-bindings/input/hid-over-i2c.txt
Quoted 18 lines
doc/device-tree-bindings/device.txt new file +16
-0+ - acpi,uid : _UID value for device + + +Example +------- + +synaptics_touchpad: synaptics-touchpad at 2c { + compatible = "hid-over-i2c"; + reg = <0x2c>; + acpi,hid = "PNP0C50"; + acpi,desc = "Synaptics Touchpad"; + interrupts-extended = <&acpi_gpe GPIO_18_IRQ + IRQ_TYPE_EDGE_FALLING>; + acpi,probed; + hid-descr-addr = <0x20>; +};doc/device-tree-bindings/input/hid-over-i2c.txt new file +0
-0
Adding the file hid-over-i2c.txt is straight forward, while getting the ACPI bindings correct is probably more tricky. Would it make sense to add this file in an individual patch?
doc/device-tree-bindings/input/hid-over-i2c.txt
Quoted 3 lines
index 0000000000..c76bafaf98
doc/device-tree-bindings/input/hid-over-i2c.txt new file +0
-0
This file is taken from the Linux kernel, should this be stated at the beginning? (I often see "Taken from ..." in source code files, I'm not sure how this is handled for documentation).
doc/device-tree-bindings/input/hid-over-i2c.txt line 11
Quoted 12 lines
doc/device-tree-bindings/input/hid-over-i2c.txt new file +11
-0@@ -0,0 +1,44 @@ +* HID over I2C Device-Tree bindings + +HID over I2C provides support for various Human Interface Devices over the +I2C bus. These devices can be for example touchpads, keyboards, touch screens +or sensors. + +The specification has been written by Microsoft and is currently available here: +http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx + +If this binding is used, the kernel module i2c-hid will handle the communication +with the device and the generic hid core layer will handle the protocol.
This sentence is specific to the Linux kernel, and does not really apply to U-Boot. I would propose one of the following:
* Point out specifically that the Linux kernel is talked about
* Drop the sentence
* State at the beginning of the file that the file is taken unmodified from the Linux kernel
Quoted 36 lines
doc/device-tree-bindings/input/hid-over-i2c.txt new file +33
-0+ +Required properties: +- compatible: must be "hid-over-i2c" +- reg: i2c slave address +- hid-descr-addr: HID descriptor address +- interrupts: interrupt line + +Additional optional properties: + +Some devices may support additional optional properties to help with, e.g., +power sequencing. The following properties can be supported by one or more +device-specific compatible properties, which should be used in addition to the +"hid-over-i2c" string. + +- compatible: + * "wacom,w9013" (Wacom W9013 digitizer). Supports: + - vdd-supply (3.3V) + - vddl-supply (1.8V) + - post-power-on-delay-ms + +- vdd-supply: phandle of the regulator that provides the supply voltage. +- post-power-on-delay-ms: time required by the device after enabling its regulators + or powering it on, before it is ready for communication. + +Example: + + i2c-hid-dev at 2c { + compatible = "hid-over-i2c"; + reg = <0x2c>; + hid-descr-addr = <0x0020>; + interrupt-parent = <&gpx3>; + interrupts = <3 2>; + };Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 13/39 acpi: Add a binding for ACPI settings in the device tree
Hi Wolfgang,
Quoted 6 lines · Wolfgang Wallner
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 2 lines
Devices need to report various identifiers in the ACPI tables. Rather
than
Quoted 13 lines
Quoted 13 lines
hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Fix definition of HID
- Infer hid-over-i2c CID value
- Add the hid-over-i2c binding document
Quoted 7 lines
Review
Quoted 7 lines
doc/device-tree-bindings/device.txt | 36 +++++++++++++++ .../input/hid-over-i2c.txt | 44 +++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 doc/device-tree-bindings/device.txt create mode 100644 doc/device-tree-bindings/input/hid-over-i2c.txt(quoted diff) +0
-0
b/doc/device-tree-bindings/device.txt
Quoted 11 lines
doc/device-tree-bindings/device.txt line 6
Quoted 11 lines
new file mode 100644
index 0000000000..31ec2fa31bdoc/device-tree-bindings/device.txt new file +6
-0@@ -0,0 +1,36 @@ +Devices +======= + +Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented
here. See
Quoted 3 lines
doc/device-tree-bindings/device.txt
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+also hid-over-i2c.txt which describes HID devices. + + - acpi,has-power-resource : (boolean) true if this device has a power
resource.
Quoted 1 line
doc/device-tree-bindings/device.txt line 10
Quoted 1 line
doc/device-tree-bindings/device.txt new file +1
-0+ This causes a PRIC (ACPI PowerResource) to be written containing
the
Quoted 2 lines
What is the meaning of PRIC? I can't find a defition for this term.
I'll drop that.
Quoted 2 lines
doc/device-tree-bindings/device.txt line 11
Quoted 2 lines
doc/device-tree-bindings/device.txt new file +1
-0+ properties provided by this binding, to describe how to handle
powering the
Quoted 6 lines
doc/device-tree-bindings/device.txt line 13
Quoted 2 lines
doc/device-tree-bindings/device.txt new file +2
-0+ device up and down using GPIOs + - acpi,compatible : compatible string to reportWhat does "compatible string" mean in this context? Does it refer to the "Compatible ID" (
_CID) of ACPI? As stated in the previous mail thread [1], I think we could infer many of the ACPI properties from existing device
tree
Quoted 5 lines
properties. Especially I suspect that ACPI's
_CIDcould have a 1:1 mapping to the compatible property in device tree. E.g. a driver which states that it is compatible with "hid-over-i2c" in its device tree description would know (implement internally) that it is also compatible with ACPI's_CID"PNP0C50", thus we would not have to add this information in the device
tree.
This is described to in the Linux binding file:
Documentation/acpi/enumeration.txt
The special DT namespace link device ID, PRP0001, provides a means to use the
existing DT-compatible device identification in ACPI and to satisfy the above
requirements following from the ACPI specification at the same time. Namely,
if PRP0001 is returned by _HID, the ACPI subsystem will look for the "compatible" property in the device object's _DSD and will use the value of that
property to identify the corresponding device in analogy with the original DT
device identification algorithm. If the "compatible" property is not present
or its value is not valid, the device will not be enumerated by the ACPI subsystem. Otherwise, it will be enumerated automatically as a platform device
(except when an I2C or SPI link from the device to its parent is present, in which case the ACPI core will leave the device enumeration to the parent's driver) and the identification strings from the "compatible" property value will
be used to find a driver for the device along with the device IDs listed by _CID
(if present).
So we set acpi,hid to "PRP0001" and acpi,compatible to the device-tree compatible string.
Quoted 4 lines
[1] https://lists.denx.de/pipermail/u-boot/2020-February/398856.html
Quoted 1 line
doc/device-tree-bindings/device.txt new file +1
-0+ - acpi,desc : Contains the string to use as the _DDN (DOS (Disk
Operating
Quoted 5 lines
doc/device-tree-bindings/device.txt line 15
Quoted 1 line
doc/device-tree-bindings/device.txt new file +1
-0+ System) Device Name)Nit: I assume "desc" stands for "description". But strictly speaking it is not a description, it is a device name. I would prefer something like "acpi,devname" or even "acpi,ddn".
OK we can go with acpi,ddn. I have been thinking about that as it is one less mapping to know.
Quoted 6 lines
doc/device-tree-bindings/device.txt line 18
Quoted 4 lines
doc/device-tree-bindings/device.txt new file +3
-0+ - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HID + - hid-descr-addr : HID register offset (for Human Interface Devices)This property is already described in the file hid-over-i2c.txt (with a
similar
Quoted 1 line
but slightly different text), thus I would not describe it here also.
Will drop.
Quoted 2 lines
doc/device-tree-bindings/device.txt line 19
Quoted 2 lines
doc/device-tree-bindings/device.txt new file +1
-0+ - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables
so that
Quoted 9 lines
doc/device-tree-bindings/device.txt line 20
Quoted 1 line
doc/device-tree-bindings/device.txt new file +1
-0+ Linux will not re-init the deviceI can't find 'linux,probed' in the Linux kernel.
I only find it in patches specific for chromium-os[2], but the description there does not match the description given here (there it is described as being probed before insertion vs. here it is described as not being probed any more).[2]
https://groups.google.com/a/chromium.org/forum/#!msg/chromium-os-reviews/4HTHl78IGHw/oz82uImnBgAJ
Yes it seems that this has not yet made it upstream to Linux.
I will fix the description.
Quoted 10 lines
Quoted 10 lines
doc/device-tree-bindings/device.txt new file +9
-0+ - acpi,uid : _UID value for device + + +Example +------- + +synaptics_touchpad: synaptics-touchpad at 2c { + compatible = "hid-over-i2c"; + reg = <0x2c>;
Quoted 8 lines
Review
Quoted 8 lines
doc/device-tree-bindings/device.txt new file +7
-0+ acpi,hid = "PNP0C50"; + acpi,desc = "Synaptics Touchpad"; + interrupts-extended = <&acpi_gpe GPIO_18_IRQ + IRQ_TYPE_EDGE_FALLING>; + acpi,probed; + hid-descr-addr = <0x20>; +};(quoted diff) +0
-0
b/doc/device-tree-bindings/input/hid-over-i2c.txt
Quoted 3 lines
Quoted 1 line
new file mode 100644
Adding the file hid-over-i2c.txt is straight forward, while getting the
ACPI
Quoted 1 line
bindings correct is probably more tricky. Would it make sense to add this
file
Quoted 1 line
in an individual patch?
OK I'll split it.
Quoted 7 lines
doc/device-tree-bindings/input/hid-over-i2c.txt
Quoted 4 lines
index 0000000000..c76bafaf98
doc/device-tree-bindings/input/hid-over-i2c.txt new file +0
-0This file is taken from the Linux kernel, should this be stated at the beginning? (I often see "Taken from ..." in source code files, I'm not
sure
Quoted 1 line
how this is handled for documentation).
Yes we normally mention that.
Quoted 5 lines
doc/device-tree-bindings/input/hid-over-i2c.txt line 3
Quoted 5 lines
doc/device-tree-bindings/input/hid-over-i2c.txt new file +3
-0@@ -0,0 +1,44 @@ +* HID over I2C Device-Tree bindings + +HID over I2C provides support for various Human Interface Devices over
the
Quoted 1 line
doc/device-tree-bindings/input/hid-over-i2c.txt line 4
Quoted 1 line
doc/device-tree-bindings/input/hid-over-i2c.txt new file +1
-0+I2C bus. These devices can be for example touchpads, keyboards, touch
screens
Quoted 3 lines
doc/device-tree-bindings/input/hid-over-i2c.txt
Quoted 3 lines
doc/device-tree-bindings/input/hid-over-i2c.txt new file +3
-0+or sensors. + +The specification has been written by Microsoft and is currently
available here:
Quoted 3 lines
doc/device-tree-bindings/input/hid-over-i2c.txt
Quoted 3 lines
doc/device-tree-bindings/input/hid-over-i2c.txt new file +3
-0+http://msdn.microsoft.com/en-us/library/windows/hardware/hh852380.aspx + +If this binding is used, the kernel module i2c-hid will handle the
communication
Quoted 1 line
doc/device-tree-bindings/input/hid-over-i2c.txt line 11
Quoted 1 line
doc/device-tree-bindings/input/hid-over-i2c.txt new file +1
-0+with the device and the generic hid core layer will handle the
protocol.
Quoted 2 lines
This sentence is specific to the Linux kernel, and does not really apply
to
Quoted 5 lines
U-Boot. I would propose one of the following:
* Point out specifically that the Linux kernel is talked about
* Drop the sentence
* State at the beginning of the file that the file is taken unmodified
from the
Quoted 1 line
Linux kernel
Yes it's funny that the bindings are supposed to describe hardware but sometimes the software creeps in.
In fact binding files are always supposed to be unmodified, so I don't think we can/should change it.
Regards,
Simon
Antwort: Re: [PATCH v2 13/39] acpi: Add a binding for ACPI settings in the device tree
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
[snip]
Quoted 33 lines
Quoted 4 lines
doc/device-tree-bindings/device.txt line 13
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+ properties provided by this binding, to describe how to handle powering the + device up and down using GPIOs + - acpi,compatible : compatible string to reportQuoted 8 lines
What does "compatible string" mean in this context? Does it refer to the "Compatible ID" (
_CID) of ACPI? As stated in the previous mail thread [1], I think we could infer many of the ACPI properties from existing device tree properties. Especially I suspect that ACPI's_CIDcould have a 1:1 mapping to the compatible property in device tree. E.g. a driver which states that it is compatible with "hid-over-i2c" in its device tree description would know (implement internally) that it is also compatible with ACPI's_CID"PNP0C50", thus we would not have to add this information in the device tree.This is described to in the Linux binding file:
Documentation/acpi/enumeration.txtThe special DT namespace link device ID, PRP0001, provides a means to use the existing DT-compatible device identification in ACPI and to satisfy the above requirements following from the ACPI specification at the same time. Namely, if PRP0001 is returned by
_HID, the ACPI subsystem will look for the "compatible" property in the device object's_DSDand will use the value of that property to identify the corresponding device in analogy with the original DT device identification algorithm. If the "compatible" property is not present or its value is not valid, the device will not be enumerated by the ACPI subsystem. Otherwise, it will be enumerated automatically as a platform device (except when an I2C or SPI link from the device to its parent is present, in which case the ACPI core will leave the device enumeration to the parent's driver) and the identification strings from the "compatible" property value will be used to find a driver for the device along with the device IDs listed by_CID(if present).
Quoted 1 line
So we set acpi,hid to "PRP0001" and acpi,compatible to the device-tree compatible string.
I think there are different cases that can be distinguished in which we need to translate between ACPI and device tree.
1) The OS has an existing ACPI binding for the device. U-Boot uses device tree for device description, but the OS uses ACPI (e.g. Linux on x86). We need a way to tell U-Boot how to create the appropriate ACPI descriptons.
2) There is no existing ACPI binding for the device in the OS, but there is already an existing device tree binding. As stated in the Linux documentation you have referred to, it would not make sense to introduce a new ACPI binding that would just be the same as the existing device tree one. As I understand this is what the "PRP0001" tag was introduced for (to reuse existing device tree descriptions and save redundant work).
Handling case 2:
PRP0001 allows to wire existing device tree properties into ACPI descriptions, and I think it provides a solution for most of case 2. So for case 2 I think most of the ACPI description can be autogenerated:
* Set _HID to "PRP0001"
* Pack all existing device tree properties into the ACPI _DSD method (this also implies that no additional "acpi,compatible" property is required, as we can reuse the existing "compatible" property)
I say "most of" because I don't know how to map certain parts between device tree and ACPI, e.g. interrupt descriptions.
Handling case 1:
Case 1 is more tricky, and up to now I was assuming you are targeting case 1 with the new additional properties. It might not be as straigt forward as in case 2, but I think also in this case we can infer most of the ACPI properties from the existing device tree properties without adding new ones. This is the example from the previous mail discussions where e.g. from a device tree "compatible" property "hid-over-i2c" we could infer the ACPI _HID "PNP0C50" without adding new properties in the device tree.
Again, I have left out more complex things like interrupts in this description.
Anyway, my experience with both device tree as well as ACPI is limited, so please take all my statements with a grain of salt.
regards, Wolfgang
PATCH v2 13/39 acpi: Add a binding for ACPI settings in the device tree
Hi Wolfgang,
Quoted 40 lines · Wolfgang Wallner
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
[snip]
Quoted 33 lines
Quoted 4 lines
doc/device-tree-bindings/device.txt line 13
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+ properties provided by this binding, to describe how to handle powering the + device up and down using GPIOs + - acpi,compatible : compatible string to reportQuoted 8 lines
What does "compatible string" mean in this context? Does it refer to the "Compatible ID" (
_CID) of ACPI? As stated in the previous mail thread [1], I think we could infer many of the ACPI properties from existing device tree properties. Especially I suspect that ACPI's_CIDcould have a 1:1 mapping to the compatible property in device tree. E.g. a driver which states that it is compatible with "hid-over-i2c" in its device tree description would know (implement internally) that it is also compatible with ACPI's_CID"PNP0C50", thus we would not have to add this information in the device tree.This is described to in the Linux binding file:
Documentation/acpi/enumeration.txtThe special DT namespace link device ID, PRP0001, provides a means to use the existing DT-compatible device identification in ACPI and to satisfy the above requirements following from the ACPI specification at the same time. Namely, if PRP0001 is returned by
_HID, the ACPI subsystem will look for the "compatible" property in the device object's_DSDand will use the value of that property to identify the corresponding device in analogy with the original DT device identification algorithm. If the "compatible" property is not present or its value is not valid, the device will not be enumerated by the ACPI subsystem. Otherwise, it will be enumerated automatically as a platform device (except when an I2C or SPI link from the device to its parent is present, in which case the ACPI core will leave the device enumeration to the parent's driver) and the identification strings from the "compatible" property value will be used to find a driver for the device along with the device IDs listed by_CID(if present).
Quoted 8 lines
Quoted 1 line
So we set acpi,hid to "PRP0001" and acpi,compatible to the device-tree compatible string.
I think there are different cases that can be distinguished in which we need to translate between ACPI and device tree.
1) The OS has an existing ACPI binding for the device. U-Boot uses device tree for device description, but the OS uses ACPI (e.g. Linux on x86). We need a way to tell U-Boot how to create the appropriate ACPI descriptons.
For now I'd like to do this in the U-Boot driver. We have so few drivers doing it that I don't think we can generalise this yet. If we start to see a pattern then we might start with some common code...
Quoted 17 lines
2) There is no existing ACPI binding for the device in the OS, but there is already an existing device tree binding. As stated in the Linux documentation you have referred to, it would not make sense to introduce a new ACPI binding that would just be the same as the existing device tree one. As I understand this is what the "PRP0001" tag was introduced for (to reuse existing device tree descriptions and save redundant work).
Handling case 2:
PRP0001 allows to wire existing device tree properties into ACPI descriptions, and I think it provides a solution for most of case 2. So for case 2 I think most of the ACPI description can be autogenerated:
* Set_HIDto "PRP0001"
* Pack all existing device tree properties into the ACPI_DSDmethod (this also implies that no additional "acpi,compatible" property is required, as we can reuse the existing "compatible" property)
Quoted 2 lines
I say "most of" because I don't know how to map certain parts between device tree and ACPI, e.g. interrupt descriptions.
...and perhaps end up with something like this. But I really don't feel comfortable trying to build out something like this with so few use cases. We don't even have one* in coral yet.
Quoted 10 lines
Handling case 1:
Case 1 is more tricky, and up to now I was assuming you are targeting case 1 with the new additional properties. It might not be as straigt forward as in case 2, but I think also in this case we can infer most of the ACPI properties from the existing device tree properties without adding new ones. This is the example from the previous mail discussions where e.g. from a device tree "compatible" property "hid-over-i2c" we could infer the ACPI_HID"PNP0C50" without adding new properties in the device tree.
Quoted 4 lines
Again, I have left out more complex things like interrupts in this description.
Anyway, my experience with both device tree as well as ACPI is limited, so please take all my statements with a grain of salt.
I suspect they may be some things we can do here to automate this. But again, this is for the future when we actually start to see these cases.
I have done the hid-over-i2c compatible string (automatically setting CID to PNP0C50) as we have two coral drivers that do that.
Regards,
Simon
PATCH v2 13/39 acpi: Add a binding for ACPI settings in the device tree
In reply to Simon GlassQuoted 5 lines · Simon Glass
Devices need to report various identifiers in the ACPI tables. Rather than hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
...
doc/device-tree-bindings/device.txt line 10
Quoted 7 lines
doc/device-tree-bindings/device.txt new file +7
-0+Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented here. See +also hid-over-i2c.txt which describes HID devices. + + - acpi,has-power-resource : (boolean) true if this device has a power resource. + This causes a PRIC (ACPI PowerResource) to be written containing the
What is PRIC?
doc/device-tree-bindings/device.txt line 13
Quoted 4 lines
doc/device-tree-bindings/device.txt new file +3
-0+ properties provided by this binding, to describe how to handle powering the + device up and down using GPIOs + - acpi,compatible : compatible string to report
Hmm... I didn't get this. Is it ACPI _CID?
doc/device-tree-bindings/device.txt line 17
Quoted 5 lines
+ - acpi,desc : Contains the string to use as the
_DDN(DOS (Disk Operatingdoc/device-tree-bindings/device.txt new file +3
-0+ System) Device Name) + - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HID
HID can be dropped to avoid confusion with below.
Quoted 4 lines
+ - hid-descr-addr : HID register offset (for Human Interface Devices)
+ - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables so that
+ Linux will not re-init the device
Why? How do we know that Linux will work correctly? Again, we must not depend on the OS behaviour.
Quoted 16 lines
+ - acpi,uid :
_UIDvalue for devicedoc/device-tree-bindings/device.txt new file +15
-0+ + +Example +------- + +synaptics_touchpad: synaptics-touchpad at 2c { + compatible = "hid-over-i2c"; + reg = <0x2c>; + acpi,hid = "PNP0C50"; + acpi,desc = "Synaptics Touchpad"; + interrupts-extended = <&acpi_gpe GPIO_18_IRQ + IRQ_TYPE_EDGE_FALLING>; + acpi,probed; + hid-descr-addr = <0x20>; +};
Signature · 2 lines
With Best Regards, Andy Shevchenko
PATCH v2 13/39 acpi: Add a binding for ACPI settings in the device tree
Hi Andy,
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Simon Glass
Devices need to report various identifiers in the ACPI tables. Rather
than
Quoted 10 lines
Quoted 4 lines
hard-coding these in drivers it is typically better to put them in the device tree.
Add a binding file to describe this.
...
doc/device-tree-bindings/device.txt
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+Device bindings are described by their own individual binding files. + +U-Boot provides for some optional properties which are documented
here. See
Quoted 3 lines
doc/device-tree-bindings/device.txt
Quoted 3 lines
doc/device-tree-bindings/device.txt new file +3
-0+also hid-over-i2c.txt which describes HID devices. + + - acpi,has-power-resource : (boolean) true if this device has a power
resource.
Quoted 1 line
Quoted 1 line
+ This causes a PRIC (ACPI PowerResource) to be written containing
the
Quoted 4 lines
What is PRIC?
Quoted 1 line
+ properties provided by this binding, to describe how to handle
powering the
Quoted 5 lines
Quoted 3 lines
+ device up and down using GPIOs
+ - acpi,compatible : compatible string to report
Hmm... I didn't get this. Is it ACPI
_CID?
Will add a pointer to the Linux ACPI docs for this.
Quoted 2 lines
Quoted 2 lines
+ - acpi,desc : Contains the string to use as the
_DDN(DOS (Disk
Operating
Quoted 6 lines
doc/device-tree-bindings/device.txt line 17
Quoted 4 lines
doc/device-tree-bindings/device.txt new file +3
-0+ System) Device Name) + - acpi,hid : Contains the string to use as the HID (Hardware ID) + identifier _HIDHID can be dropped to avoid confusion with below.
OK I am actually dropping the next line.
Quoted 4 lines
Quoted 4 lines
+ - hid-descr-addr : HID register offset (for Human Interface Devices)
+ - acpi,probed : Tells U-Boot to add 'linux,probed' to the ACPI tables
so that
Quoted 3 lines
Quoted 1 line
+ Linux will not re-init the device
Why? How do we know that Linux will work correctly? Again, we must not
depend
Quoted 1 line
on the OS behaviour.
The wording is incorrect, will update. This is effectively an 'optional' device.
Quoted 17 lines
Quoted 7 lines
+ - acpi,uid :
_UIDvalue for devicedoc/device-tree-bindings/device.txt new file +5
-0+ + +Example +------- +doc/device-tree-bindings/device.txt line 36
Quoted 10 lines
doc/device-tree-bindings/device.txt new file +10
-0+synaptics_touchpad: synaptics-touchpad at 2c { + compatible = "hid-over-i2c"; + reg = <0x2c>; + acpi,hid = "PNP0C50"; + acpi,desc = "Synaptics Touchpad"; + interrupts-extended = <&acpi_gpe GPIO_18_IRQ + IRQ_TYPE_EDGE_FALLING>; + acpi,probed; + hid-descr-addr = <0x20>; +};
Regards,
Simon
PATCH v2 14/39 acpi: Add a simple sandbox test
In reply to Simon GlassAdd a sandbox test for the basic ACPI functionality we have so far.
---
Changes in v2:
- Add in the acpi_table.h header file to this patch
arch/sandbox/dts/test.dts | 4 ++ arch/sandbox/include/asm/acpi_table.h | 9 +++++ include/dm/uclass-id.h | 1 + test/dm/Makefile | 1 + test/dm/acpi.c | 55 +++++++++++++++++++++++++++ 5 files changed, 70 insertions(+) create mode 100644 arch/sandbox/include/asm/acpi_table.h create mode 100644 test/dm/acpi.c
arch/sandbox/dts/test.dts +4 -0
@@ -206,6 +206,10 @@ compatible = "denx,u-boot-devres-test"; }; + acpi-test { + compatible = "denx,u-boot-acpi-test"; + }; + clocks { clk_fixed: clk-fixed { compatible = "fixed-clock";
arch/sandbox/include/asm/acpi_table.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0+ */ +/* +* Copyright 2019 Google LLC +*/ + +#ifndef __ASM_ACPI_TABLE_H__ +#define __ASM_ACPI_TABLE_H__ + +#endif /* __ASM_ACPI_TABLE_H__ */
include/dm/uclass-id.h +1 -0
@@ -20,6 +20,7 @@ enum uclass_id {UCLASS_TEST_PROBE ,UCLASS_TEST_DUMMY ,UCLASS_TEST_DEVRES , +UCLASS_TEST_ACPI ,UCLASS_SPI_EMUL ,/* sandbox SPI device emulator */ UCLASS_I2C_EMUL ,/* sandbox I2C device emulator */ UCLASS_I2C_EMUL_PARENT, /* parent for I2C device emulators */
test/dm/Makefile +1 -0
@@ -13,6 +13,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o # subsystem you must add sandbox tests here. obj-$(CONFIG_UT_DM) += core.o ifneq ($(CONFIG_SANDBOX),) +obj-$(CONFIG_ACPIGEN) += acpi.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o
test/dm/acpi.c new file +55 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 14/39] acpi: Add a simple sandbox test
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 10 lines
Add a sandbox test for the basic ACPI functionality we have so far.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2:
- Add in theacpi_table.hheader file to this patch
Quoted 6 lines
arch/sandbox/dts/test.dts | 4 ++ arch/sandbox/include/asm/acpi_table.h | 9 +++++ include/dm/uclass-id.h | 1 + test/dm/Makefile | 1 + test/dm/acpi.c | 55 +++++++++++++++++++++++++++ 5 files changed, 70 insertions(+)
PATCH v2 15/39 x86: Move acpi_table header to main include/ directory
In reply to Simon GlassThis file is potentially useful to other architectures saddled with ACPI so move it into a common location.
---
Changes in v2: None
arch/x86/cpu/baytrail/acpi.c | 2 +- arch/x86/cpu/cpu.c | 2 +- arch/x86/cpu/quark/acpi.c | 2 +- arch/x86/cpu/tangier/acpi.c | 2 +- arch/x86/include/asm/acpi_table.h | 376 ---------------------------- arch/x86/lib/acpi.c | 2 +- arch/x86/lib/acpi_s3.c | 2 +- arch/x86/lib/acpi_table.c | 2 +- arch/x86/lib/tables.c | 2 +- arch/x86/lib/zimage.c | 2 +- include/acpi_table.h | 394 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_acpi.c | 2 +- 12 files changed, 404 insertions(+), 386 deletions(-) create mode 100644 include/acpi_table.h
arch/x86/cpu/baytrail/acpi.c +1 -1
@@ -8,7 +8,7 @@#include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/io.h> #include <asm/tables.h> #include <asm/arch/global_nvs.h>
arch/x86/cpu/cpu.c +1 -1
@@ -28,7 +28,7 @@#include <malloc.h> #include <syscon.h> #include <asm/acpi.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/control_regs.h> #include <asm/coreboot_tables.h> #include <asm/cpu.h>
arch/x86/cpu/quark/acpi.c +1 -1
@@ -4,7 +4,7 @@*/ #include <common.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/tables.h> #include <asm/arch/global_nvs.h> #include <asm/arch/iomap.h>
arch/x86/cpu/tangier/acpi.c +1 -1
@@ -9,7 +9,7 @@#include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/ioapic.h> #include <asm/mpspec.h> #include <asm/tables.h>
arch/x86/include/asm/acpi_table.h +0 -376
382 lines not on this page · raw message
arch/x86/lib/acpi.c +1 -1
@@ -4,7 +4,7 @@*/ #include <common.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/io.h> #include <asm/tables.h>
arch/x86/lib/acpi_s3.c +1 -1
@@ -6,7 +6,7 @@#include <common.h> #include <acpi_s3.h> #include <asm/acpi.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/post.h> #include <linux/linkage.h>
arch/x86/lib/acpi_table.c +1 -1
@@ -13,7 +13,7 @@#include <serial.h> #include <version.h> #include <asm/acpi/global_nvs.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/ioapic.h> #include <asm/lapic.h> #include <asm/mpspec.h>
arch/x86/lib/tables.c +1 -1
@@ -9,7 +9,7 @@#include <asm/sfi.h> #include <asm/mpspec.h> #include <asm/tables.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/coreboot_tables.h> /**
arch/x86/lib/zimage.c +1 -1
@@ -16,7 +16,7 @@#include <env.h> #include <irq_func.h> #include <malloc.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> #include <asm/io.h> #include <asm/ptrace.h> #include <asm/zimage.h>
include/acpi_table.h new file +394 -0
394 lines not on this page · raw message
lib/efi_loader/efi_acpi.c +1 -1
@@ -7,7 +7,7 @@#include <common.h> #include <efi_loader.h> -#include <asm/acpi_table.h> +#include <acpi_table.h> static const efi_guid_t acpi_guid =EFI_ACPI_TABLE_GUID ;
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 15/39] x86: Move acpi_table header to main include/ directory
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 3 lines
This file is potentially useful to other architectures saddled with ACPI so move it into a common location.
Nit: "move most of its contents to a common location"
(not the complete file is moved, some parts stay at the old location)
Quoted 7 lines
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Changes in v2: None
Quoted 13 lines
arch/x86/cpu/baytrail/acpi.c | 2 +- arch/x86/cpu/cpu.c | 2 +- arch/x86/cpu/quark/acpi.c | 2 +- arch/x86/cpu/tangier/acpi.c | 2 +- arch/x86/include/asm/acpi_table.h | 376 ---------------------------- arch/x86/lib/acpi.c | 2 +- arch/x86/lib/acpi_s3.c | 2 +- arch/x86/lib/acpi_table.c | 2 +- arch/x86/lib/tables.c | 2 +- arch/x86/lib/zimage.c | 2 +- include/acpi_table.h | 394 ++++++++++++++++++++++++++++++ lib/efi_loader/efi_acpi.c | 2 +- 12 files changed, 404 insertions(+), 386 deletions(-)
PATCH v2 16/39 acpi: Add an __ACPI__ preprocessor symbol
In reply to Simon GlassThe ASL compiler cannot handle C structures and the like so needs some sort of header guard around these.
We already have an __ASSEMBLY__ #define but it seems best to create a new one for ACPI since the rules may be different.
Add the check to a few files that ACPI always includes.
---
Changes in v2: None
include/acpi_table.h | 4 ++++ include/dm/acpi.h | 4 ++++ scripts/Makefile.lib | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-)
include/acpi_table.h +4 -0
@@ -21,6 +21,8 @@#define ACPI_RSDP_REV_ACPI_1_0 0#define ACPI_RSDP_REV_ACPI_2_0 2 +#if !defined(__ACPI__) +/* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
@@ -389,6 +391,8 @@ struct __packed acpi_spcr {u32 reserved2; }; +#endif /* !__ACPI__*/ +#include <asm/acpi_table.h> #endif /* __ACPI_TABLE_H__ */
include/dm/acpi.h +4 -0
@@ -22,6 +22,8 @@/* Length of an ACPI name string including nul terminator */ #define ACPI_NAME_MAX 5 +#if !defined(__ACPI__) +/** * struct acpi_ops - ACPI operations supported by driver model */
@@ -70,4 +72,6 @@ int acpi_get_name(const struct udevice *dev, char *out_name);*/ int acpi_return_name (char *out_name,const char *name); +#endif /* __ACPI__ */ +#endif
scripts/Makefile.lib +2 -2
@@ -413,8 +413,8 @@ ASL_TMP = $(patsubst %.c,%.asl.tmp,$@) quiet_cmd_acpi_c_asl= ASL $< cmd_acpi_c_asl= \ - $(CPP) -x assembler-with-cpp -D__ASSEMBLY__ -P $(UBOOTINCLUDE) \ - -o $(ASL_TMP) $< && \ + $(CPP) -x assembler-with-cpp -D__ASSEMBLY__ -D__ACPI__ \ + -P $(UBOOTINCLUDE) -o $(ASL_TMP) $< && \ iasl -p $@ -tc $(ASL_TMP) $(if $(KBUILD_VERBOSE:1=), >/dev/null) && \ mv $(patsubst %.c,%.hex,$@) $@
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 16/39] acpi: Add an __ACPI__ preprocessor symbol
Hi Simon,
Quoted 12 lines
-----"Simon Glass" <[email protected]> schrieb: -----
The ASL compiler cannot handle C structures and the like so needs some sort of header guard around these.
We already have an
__ASSEMBLY__#define but it seems best to create a new one for ACPI since the rules may be different.Add the check to a few files that ACPI always includes.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>
Quoted 8 lines
---
Changes in v2: None
include/acpi_table.h | 4 ++++ include/dm/acpi.h | 4 ++++ scripts/Makefile.lib | 4 ++-- 3 files changed, 10 insertions(+), 2 deletions(-)
PATCH v2 17/39 acpi: Add a central location for table version numbers
In reply to Simon GlassEach ACPI table has its own version number. Add the version numbers in a single function so we can keep them consistent and easily see what versions are supported.
Start a new acpi_table file in a generic directory to house this function. We can move things over to this file from x86 as needed.
---
Changes in v2:
- Move the sandbox acpi_table.h header file to an earlier patch
- Use #defines for MADT and MCFG version numbers
include/acpi_table.h | 61 +++++++++++++++++++++++++++++++++++++++++++ lib/Makefile | 1 + lib/acpi/Makefile | 4 +++ lib/acpi/acpi_table.c | 60 ++++++++++++++++++++++++++++++++++++++++++ test/dm/acpi.c | 14 ++++++++++ 5 files changed, 140 insertions(+) create mode 100644 lib/acpi/Makefile create mode 100644 lib/acpi/acpi_table.c
include/acpi_table.h +61 -0
@@ -202,6 +202,26 @@ struct __packed acpi_fadt {struct acpi_gen_regaddr x_gpe1_blk; }; +/* FADT TABLE Revision values */ +#define ACPI_FADT_REV_ACPI_1_0 1 +#define ACPI_FADT_REV_ACPI_2_0 3 +#define ACPI_FADT_REV_ACPI_3_0 4 +#define ACPI_FADT_REV_ACPI_4_0 4 +#define ACPI_FADT_REV_ACPI_5_0 5 +#define ACPI_FADT_REV_ACPI_6_0 6 + +/* MADT TABLE Revision values */ +#define ACPI_MADT_REV_ACPI_3_0 2 +#define ACPI_MADT_REV_ACPI_4_0 3 +#define ACPI_MADT_REV_ACPI_5_0 3 +#define ACPI_MADT_REV_ACPI_6_0 5 + +#define ACPI_MCFG_REV_ACPI_3_0 1 + +/* IVRS Revision Field */ +#define IVRS_FORMAT_FIXED 0x01/* Type 10h & 11h only */ +#define IVRS_FORMAT_MIXED 0x02/* Type 10h, 11h, & 40h */ +/* FACS flags */ #define ACPI_FACS_S4BIOS_F BIT(0)#define ACPI_FACS_64BIT_WAKE_F BIT(1)
@@ -391,6 +411,47 @@ struct __packed acpi_spcr { u32 reserved2; }; +/* Tables defined by ACPI and generated by U-Boot */ +enum acpi_tables { +ACPITAB_BERT , +ACPITAB_DBG2 , +ACPITAB_DMAR , +ACPITAB_DSDT , +ACPITAB_FACS , +ACPITAB_FADT , +ACPITAB_HEST , +ACPITAB_HPET , +ACPITAB_IVRS , +ACPITAB_MADT , +ACPITAB_MCFG , +ACPITAB_RSDP , +ACPITAB_RSDT , +ACPITAB_SLIT , +ACPITAB_SRAT , +ACPITAB_SSDT , +ACPITAB_TCPA , +ACPITAB_TPM2 , +ACPITAB_XSDT , +ACPITAB_ECDT , + +/* Additional proprietary tables */ +ACPITAB_VFCT , +ACPITAB_NHLT , +ACPITAB_SPMI , + +ACPITAB_COUNT , +}; + +/** +* acpi_get_table_revision() - Get the revision number generated for a table +* +* This keeps the version-number information in one place +* +* @table: ACPI table to check +* @return version number that U-Boot generates +*/ +int acpi_get_table_revision (enum acpi_tables table); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/Makefile +1 -0
@@ -5,6 +5,7 @@ ifndef CONFIG_SPL_BUILD +obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi/ obj-$(CONFIG_EFI) += efi/ obj-$(CONFIG_EFI_LOADER) += efi_driver/ obj-$(CONFIG_EFI_LOADER) += efi_loader/
lib/acpi/Makefile new file +4 -0
@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += acpi_table.o
lib/acpi/acpi_table.c new file +60 -0
60 lines not on this page · raw message
test/dm/acpi.c +14 -0
@@ -7,6 +7,7 @@*/ #include <common.h> +#include <acpi_table.h> #include <dm.h> #include <dm/acpi.h> #include <dm/test.h>
@@ -53,3 +54,16 @@ static int dm_test_acpi_get_name(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_get_name,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_get_table_revision() */ +static int dm_test_acpi_get_table_revision (struct unit_test_state *uts) +{ +ut_asserteq (1 ,acpi_get_table_revision (ACPITAB_MCFG )); +ut_asserteq (2 ,acpi_get_table_revision (ACPITAB_RSDP )); +ut_asserteq (4 ,acpi_get_table_revision (ACPITAB_TPM2 )); +ut_asserteq (-EINVAL ,acpi_get_table_revision (ACPITAB_COUNT )); + +return 0 ; +} +DM_TEST (dm_test_acpi_get_table_revision, +DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 17/39] acpi: Add a central location for table version numbers
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 108 lines
Each ACPI table has its own version number. Add the version numbers in a single function so we can keep them consistent and easily see what versions are supported.
Start a new
acpi_tablefile in a generic directory to house this function. We can move things over to this file from x86 as needed.Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Move the sandboxacpi_table.hheader file to an earlier patch
- Use #defines for MADT and MCFG version numbersinclude/acpi_table.h | 61 +++++++++++++++++++++++++++++++++++++++++++ lib/Makefile | 1 + lib/acpi/Makefile | 4 +++ lib/acpi/acpi_table.c | 60 ++++++++++++++++++++++++++++++++++++++++++ test/dm/acpi.c | 14 ++++++++++ 5 files changed, 140 insertions(+) create mode 100644 lib/acpi/Makefile create mode 100644 lib/acpi/acpi_table.cinclude/acpi_table.h +61
-0@@ -202,6 +202,26 @@ struct __packed acpi_fadt {struct acpi_gen_regaddr x_gpe1_blk; }; +/* FADT TABLE Revision values */ +#define ACPI_FADT_REV_ACPI_1_0 1 +#define ACPI_FADT_REV_ACPI_2_0 3 +#define ACPI_FADT_REV_ACPI_3_0 4 +#define ACPI_FADT_REV_ACPI_4_0 4 +#define ACPI_FADT_REV_ACPI_5_0 5 +#define ACPI_FADT_REV_ACPI_6_0 6 + +/* MADT TABLE Revision values */ +#define ACPI_MADT_REV_ACPI_3_0 2 +#define ACPI_MADT_REV_ACPI_4_0 3 +#define ACPI_MADT_REV_ACPI_5_0 3 +#define ACPI_MADT_REV_ACPI_6_0 5 + +#define ACPI_MCFG_REV_ACPI_3_0 1 + +/* IVRS Revision Field */ +#define IVRS_FORMAT_FIXED 0x01/* Type 10h & 11h only */ +#define IVRS_FORMAT_MIXED 0x02/* Type 10h, 11h, & 40h */ +/* FACS flags */ #define ACPI_FACS_S4BIOS_F BIT(0)#define ACPI_FACS_64BIT_WAKE_F BIT(1)@@ -391,6 +411,47 @@ struct __packed acpi_spcr { u32 reserved2; }; +/* Tables defined by ACPI and generated by U-Boot */ +enum acpi_tables { +ACPITAB_BERT , +ACPITAB_DBG2 , +ACPITAB_DMAR , +ACPITAB_DSDT , +ACPITAB_FACS , +ACPITAB_FADT , +ACPITAB_HEST , +ACPITAB_HPET , +ACPITAB_IVRS , +ACPITAB_MADT , +ACPITAB_MCFG , +ACPITAB_RSDP , +ACPITAB_RSDT , +ACPITAB_SLIT , +ACPITAB_SRAT , +ACPITAB_SSDT , +ACPITAB_TCPA , +ACPITAB_TPM2 , +ACPITAB_XSDT , +ACPITAB_ECDT , + +/* Additional proprietary tables */ +ACPITAB_VFCT , +ACPITAB_NHLT , +ACPITAB_SPMI , + +ACPITAB_COUNT , +}; + +/** +* acpi_get_table_revision() - Get the revision number generated for a table +* +* This keeps the version-number information in one place +* +* @table: ACPI table to check +* @return version number that U-Boot generates +*/ +int acpi_get_table_revision (enum acpi_tables table); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h> lib/Makefile +0
-0
lib/Makefile line 8
Quoted 4 lines
lib/Makefile +1
-0@@ -5,6 +5,7 @@ ifndef CONFIG_SPL_BUILD +obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi/
Is $(SPL_TPL_) needed here?
I don't see a CONFIG_SPL_ACPIGEN, and this section of the file is also covered by "ifndef CONFIG_SPL_BUILD".
In any case, would it make sense to generate ACPI-related code for SPL and TPL? As U-Boot does not use ACPI, but only provides it to the kernel, I would assume we only need to handle ACPI tables in the last U-Boot stage before booting a kernel.
Quoted 19 lines
lib/Makefile +0
-0obj-$(CONFIG_EFI) += efi/ obj-$(CONFIG_EFI_LOADER) += efi_driver/ obj-$(CONFIG_EFI_LOADER) += efi_loader/lib/acpi/Makefile new file +4
-0@@ -0,0 +1,4 @@ +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-y += acpi_table.olib/acpi/acpi_table.c new file +0
-0
lib/acpi/acpi_table.c line 3
Quoted 3 lines
lib/acpi/acpi_table.c new file +3
-0@@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* +* Tests for ACPI table generation
The description here does not really fit, is this maybe a copy/paste mistake?
Quoted 8 lines
lib/acpi/acpi_table.c new file +8
-0+* +* Copyright 2019 Google LLC +*/ + +#include <common.h> +#include <acpi_table.h> + +int acpi_get_table_revision (enum acpi_tables table)
lib/acpi/acpi_table.c line 21
Quoted 10 lines
lib/acpi/acpi_table.c new file +10
-0+{ +switch (table) { +case ACPITAB_FADT : +return ACPI_FADT_REV_ACPI_3_0 ; +case ACPITAB_MADT : +return ACPI_MADT_REV_ACPI_3_0 ; +case ACPITAB_MCFG : +return ACPI_MCFG_REV_ACPI_3_0 ; +case ACPITAB_TCPA : +/* THis version and the rest are open-coded */
typo: This
lib/acpi/acpi_table.c line 27
Quoted 6 lines
lib/acpi/acpi_table.c new file +6
-0+return 2 ; +case ACPITAB_TPM2 : +return 4 ; +case ACPITAB_SSDT :/* ACPI 3.0 upto 6.3: 2 */ +return 2 ; +case ACPITAB_SRAT :/* ACPI 2.0: 1, ACPI 3.0: 2, ACPI 4.0 upto 6.3: 3 */
Nit: "up to" instead of "upto"?
Quoted 6 lines
lib/acpi/acpi_table.c new file +6
-0+return 1 ;/* TODO Should probably be upgraded to 2 */ +case ACPITAB_DMAR : +return 1 ; +case ACPITAB_SLIT :/* ACPI 2.0 upto 6.3: 1 */ +return 1 ; +case ACPITAB_SPMI :/* IMPI 2.0 */
lib/acpi/acpi_table.c line 43
Quoted 10 lines
lib/acpi/acpi_table.c new file +10
-0+return 5 ; +case ACPITAB_HPET :/* Currently 1. Table added in ACPI 2.0 */ +return 1 ; +case ACPITAB_VFCT :/* ACPI 2.0/3.0/4.0: 1 */ +return 1 ; +case ACPITAB_IVRS : +return IVRS_FORMAT_FIXED ; +case ACPITAB_DBG2 : +return 0 ; +case ACPITAB_FACS :/* ACPI 2.0/3.0: 1, ACPI 4.0 upto 6.3: 2 */
Nit: "up to" instead of "upto"?
Quoted 48 lines
lib/acpi/acpi_table.c new file +17
-0+return 1 ; +case ACPITAB_RSDT :/* ACPI 1.0 upto 6.3: 1 */ +return 1 ; +case ACPITAB_XSDT :/* ACPI 2.0 upto 6.3: 1 */ +return 1 ; +case ACPITAB_RSDP :/* ACPI 2.0 upto 6.3: 2 */ +return 2 ; +case ACPITAB_HEST : +return 1 ; +case ACPITAB_NHLT : +return 5 ; +case ACPITAB_BERT : +return 1 ; +default : +return -EINVAL ; + } +}test/dm/acpi.c +14
-0@@ -7,6 +7,7 @@*/ #include <common.h> +#include <acpi_table.h> #include <dm.h> #include <dm/acpi.h> #include <dm/test.h> @@ -53,3 +54,16 @@ static int dm_test_acpi_get_name(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_get_name,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_get_table_revision() */ +static int dm_test_acpi_get_table_revision (struct unit_test_state *uts) +{ +ut_asserteq (1 ,acpi_get_table_revision (ACPITAB_MCFG )); +ut_asserteq (2 ,acpi_get_table_revision (ACPITAB_RSDP )); +ut_asserteq (4 ,acpi_get_table_revision (ACPITAB_TPM2 )); +ut_asserteq (-EINVAL ,acpi_get_table_revision (ACPITAB_COUNT )); + +return 0 ; +} +DM_TEST (dm_test_acpi_get_table_revision, +DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 17/39 acpi: Add a central location for table version numbers
Hi Wolfgang,
Quoted 10 lines · Wolfgang Wallner
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 6 lines
Each ACPI table has its own version number. Add the version numbers in a single function so we can keep them consistent and easily see what versions are supported.
Start a new
acpi_tablefile in a generic directory to house this
function.
Quoted 78 lines
Quoted 78 lines
We can move things over to this file from x86 as needed.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Move the sandboxacpi_table.hheader file to an earlier patch
- Use #defines for MADT and MCFG version numbersinclude/acpi_table.h | 61 +++++++++++++++++++++++++++++++++++++++++++ lib/Makefile | 1 + lib/acpi/Makefile | 4 +++ lib/acpi/acpi_table.c | 60 ++++++++++++++++++++++++++++++++++++++++++ test/dm/acpi.c | 14 ++++++++++ 5 files changed, 140 insertions(+) create mode 100644 lib/acpi/Makefile create mode 100644 lib/acpi/acpi_table.cinclude/acpi_table.h +45
-0@@ -202,6 +202,26 @@ struct __packed acpi_fadt {struct acpi_gen_regaddr x_gpe1_blk; }; +/* FADT TABLE Revision values */ +#define ACPI_FADT_REV_ACPI_1_0 1 +#define ACPI_FADT_REV_ACPI_2_0 3 +#define ACPI_FADT_REV_ACPI_3_0 4 +#define ACPI_FADT_REV_ACPI_4_0 4 +#define ACPI_FADT_REV_ACPI_5_0 5 +#define ACPI_FADT_REV_ACPI_6_0 6 + +/* MADT TABLE Revision values */ +#define ACPI_MADT_REV_ACPI_3_0 2 +#define ACPI_MADT_REV_ACPI_4_0 3 +#define ACPI_MADT_REV_ACPI_5_0 3 +#define ACPI_MADT_REV_ACPI_6_0 5 + +#define ACPI_MCFG_REV_ACPI_3_0 1 + +/* IVRS Revision Field */ +#define IVRS_FORMAT_FIXED 0x01/* Type 10h & 11h only */ +#define IVRS_FORMAT_MIXED 0x02/* Type 10h, 11h, & 40h */ +/* FACS flags */ #define ACPI_FACS_S4BIOS_F BIT(0)#define ACPI_FACS_64BIT_WAKE_F BIT(1)@@ -391,6 +411,47 @@ struct __packed acpi_spcr {u32 reserved2; }; +/* Tables defined by ACPI and generated by U-Boot */ +enum acpi_tables { +ACPITAB_BERT , +ACPITAB_DBG2 , +ACPITAB_DMAR , +ACPITAB_DSDT , +ACPITAB_FACS , +ACPITAB_FADT , +ACPITAB_HEST , +ACPITAB_HPET , +ACPITAB_IVRS , +ACPITAB_MADT , +ACPITAB_MCFG , +ACPITAB_RSDP , +ACPITAB_RSDT , +ACPITAB_SLIT , +ACPITAB_SRAT , +ACPITAB_SSDT , +ACPITAB_TCPA , +ACPITAB_TPM2 , +ACPITAB_XSDT , +ACPITAB_ECDT , + +/* Additional proprietary tables */ +ACPITAB_VFCT ,
Quoted 8 lines
include/acpi_table.h struct __packed acpi_spcr {
Quoted 8 lines
include/acpi_table.h +8
-0+ACPITAB_NHLT , +ACPITAB_SPMI , + + ACPITAB_COUNT, +}; + +/** +* acpi_get_table_revision() - Get the revision number generated for a
table
Quoted 17 lines
Quoted 17 lines
include/acpi_table.h +8
-0+* +* This keeps the version-number information in one place +* +* @table: ACPI table to check +* @return version number that U-Boot generates +*/ +int acpi_get_table_revision (enum acpi_tables table); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h> lib/Makefile +0
-0@@ -5,6 +5,7 @@
Quoted 6 lines
lib/Makefile line 8
Quoted 3 lines
lib/Makefile +1
-0ifndef CONFIG_SPL_BUILD +obj-$(CONFIG_$(SPL_TPL_)ACPIGEN) += acpi/Is $(SPL_TPL_) needed here?
I don't see aCONFIG_SPL_ACPIGEN, and this section of the file is also
covered
Quoted 3 lines
by "ifndef
CONFIG_SPL_BUILD".In any case, would it make sense to generate ACPI-related code for SPL
and TPL?
Quoted 3 lines
As U-Boot does not use ACPI, but only provides it to the kernel, I would assume we only need to handle ACPI tables in the last U-Boot stage before booting a kernel.
That's right. The point of this is to only include it in U-Boot proper. Actually I should use $SPL here so will fix that.
Regards,
Simon
PATCH v2 18/39 acpi: Add support for DMAR
In reply to Simon GlassThe DMA Remapping Reporting (DMAR) table contains information about DMA remapping.
Add a version simple version of this table with only the minimum fields filled out. i.e. no entries.
---
Changes in v2:
- Drop two unnecessary __packed
- Move __packed to after struct
include/acpi_table.h | 57 +++++++++++++++++++++++++++++++++++++++++++ lib/acpi/acpi_table.c | 26 ++++++++++++++++++++ test/dm/acpi.c | 14 +++++++++++ 3 files changed, 97 insertions(+)
include/acpi_table.h +57 -0
@@ -21,6 +21,9 @@#define ACPI_RSDP_REV_ACPI_1_0 0#define ACPI_RSDP_REV_ACPI_2_0 2 +/* TODO(sjg at chromium.org): Figure out how to get compiler revision */ +#define ASL_REVISION 0 +#if !defined(__ACPI__)/*
@@ -360,6 +363,51 @@ struct acpi_csrt_shared_info {u32 max_block_size; }; +enum dmar_type { +DMAR_DRHD =0 , +DMAR_RMRR =1 , +DMAR_ATSR =2 , +DMAR_RHSA =3 , +DMAR_ANDD =4 +}; + +enum { +DRHD_INCLUDE_PCI_ALL =1 +}; + +enum dmar_flags { +DMAR_INTR_REMAP =1 <<0 , +DMAR_X2APIC_OPT_OUT =1 <<1 , +DMA_CTRL_PLATFORM_OPT_IN_FLAG =1 <<2 , +}; + +struct dmar_entry { +u16 type; +u16 length; +u8 flags; +u8 reserved; +u16 segment; +u64 bar; +}; + +struct dmar_rmrr_entry { +u16 type; +u16 length; +u16 reserved; +u16 segment; +u64 bar; +u64 limit; +}; + +/* DMAR (DMA Remapping Reporting Structure) */ +struct __packed acpi_dmar { +struct acpi_table_header header; +u8 host_address_width; +u8 flags; +u8 reserved[10 ]; +struct dmar_entry structure[0 ]; +}; +/* DBG2 definitions are partially used for SPCR interface_type */ /* Types for port_type field */
@@ -452,6 +500,15 @@ enum acpi_tables {*/ int acpi_get_table_revision (enum acpi_tables table); +/** +* acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table +* +* @dmar: Place to put the table +* @flags: DMAR flags to use +* @return 0 if OK, -ve on error +*/ +int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/acpi/acpi_table.c +26 -0
@@ -6,7 +6,33 @@*/ #include <common.h> +#include <dm.h> #include <acpi_table.h> +#include <cpu.h> + +int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags) +{ +struct acpi_table_header *header = &dmar->header; +struct cpu_info info; +struct udevice *cpu; +int ret; + + ret =uclass_first_device (UCLASS_CPU , &cpu); +if (ret) +return log_msg_ret ("cpu" , ret); + ret =cpu_get_info (cpu, &info); +memset ((void *)dmar,0 ,sizeof (struct acpi_dmar )); + +/* Fill out header fields. */ +acpi_fill_header (&dmar->header,"DMAR" ); + header->length =sizeof (struct acpi_dmar ); + header->revision =acpi_get_table_revision (ACPITAB_DMAR ); + + dmar->host_address_width = info.address_width -1 ; + dmar->flags = flags; + +return 0 ; +}int acpi_get_table_revision (enum acpi_tables table) {
test/dm/acpi.c +14 -0
@@ -67,3 +67,17 @@ static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) }DM_TEST (dm_test_acpi_get_table_revision,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_create_dmar() */ +static int dm_test_acpi_create_dmar (struct unit_test_state *uts) +{ +struct acpi_dmar dmar; + +ut_assertok (acpi_create_dmar (&dmar,DMAR_INTR_REMAP )); +ut_asserteq (DMAR_INTR_REMAP , dmar.flags); +ut_asserteq (DMAR_INTR_REMAP , dmar.flags); +ut_asserteq (32 -1 , dmar.host_address_width); + +return 0 ; +} +DM_TEST (dm_test_acpi_create_dmar,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 18/39] acpi: Add support for DMAR
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 38 lines
The DMA Remapping Reporting (DMAR) table contains information about DMA remapping.
Add a version simple version of this table with only the minimum fields filled out. i.e. no entries.
Reviewed-by Bin Meng <[email protected]>Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Drop two unnecessary__packed
- Move__packedto after structinclude/acpi_table.h | 57 +++++++++++++++++++++++++++++++++++++++++++ lib/acpi/acpi_table.c | 26 ++++++++++++++++++++ test/dm/acpi.c | 14 +++++++++++ 3 files changed, 97 insertions(+)include/acpi_table.h +3
-0@@ -21,6 +21,9 @@#define ACPI_RSDP_REV_ACPI_1_0 0#define ACPI_RSDP_REV_ACPI_2_0 2 +/* TODO(sjg at chromium.org): Figure out how to get compiler revision */ +#define ASL_REVISION 0 +#if !defined(__ACPI__)/* @@ -360,6 +363,51 @@ struct acpi_csrt_shared_info {u32 max_block_size; };
include/acpi_table.h struct acpi_csrt_shared_info { · line 375
Quoted 10 lines
include/acpi_table.h +10
-0+enum dmar_type { +DMAR_DRHD =0 , +DMAR_RMRR =1 , +DMAR_ATSR =2 , +DMAR_RHSA =3 , +DMAR_ANDD =4 +}; + +enum { +DRHD_INCLUDE_PCI_ALL =1
Could you use "1 << 0" or "BIT(0)" ?
Similar as the flag definitions below.
include/acpi_table.h struct acpi_csrt_shared_info { · line 381
Quoted 6 lines
include/acpi_table.h +6
-0+}; + +enum dmar_flags { +DMAR_INTR_REMAP =1 <<0 , +DMAR_X2APIC_OPT_OUT =1 <<1 , +DMA_CTRL_PLATFORM_OPT_IN_FLAG =1 <<2 ,
The first two entries are prefixed with DMAR_, the last one is not. Is this on purpose?
Could you use BIT(x) here?
Quoted 61 lines
include/acpi_table.h +38
-0+}; + +struct dmar_entry { +u16 type; +u16 length; +u8 flags; +u8 reserved; +u16 segment; +u64 bar; +}; + +struct dmar_rmrr_entry { +u16 type; +u16 length; +u16 reserved; +u16 segment; +u64 bar; +u64 limit; +}; + +/* DMAR (DMA Remapping Reporting Structure) */ +struct __packed acpi_dmar { +struct acpi_table_header header; +u8 host_address_width; +u8 flags; +u8 reserved[10 ]; +struct dmar_entry structure[0 ]; +}; +/* DBG2 definitions are partially used for SPCR interface_type */ /* Types for port_type field */ @@ -452,6 +500,15 @@ enum acpi_tables {*/ int acpi_get_table_revision (enum acpi_tables table); +/** +* acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table +* +* @dmar: Place to put the table +* @flags: DMAR flags to use +* @return 0 if OK, -ve on error +*/ +int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h> lib/acpi/acpi_table.c +4
-0@@ -6,7 +6,33 @@*/ #include <common.h> +#include <dm.h> #include <acpi_table.h> +#include <cpu.h> + +int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags)
lib/acpi/acpi_table.c line 23
Quoted 10 lines
lib/acpi/acpi_table.c +10
-0+{ +struct acpi_table_header *header = &dmar->header; +struct cpu_info info; +struct udevice *cpu; +int ret; + + ret =uclass_first_device (UCLASS_CPU , &cpu); +if (ret) +return log_msg_ret ("cpu" , ret); + ret =cpu_get_info (cpu, &info);
Here the return value of cpu_get_info() is ignored.
Quoted 22 lines
lib/acpi/acpi_table.c +12
-0+memset ((void *)dmar,0 ,sizeof (struct acpi_dmar )); + +/* Fill out header fields. */ +acpi_fill_header (&dmar->header,"DMAR" ); + header->length =sizeof (struct acpi_dmar ); + header->revision =acpi_get_table_revision (ACPITAB_DMAR ); + + dmar->host_address_width = info.address_width -1 ; + dmar->flags = flags; + +return 0 ; +}int acpi_get_table_revision (enum acpi_tables table) {test/dm/acpi.c +0
-0@@ -67,3 +67,17 @@ static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_get_table_revision,
test/dm/acpi.c static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) · line 78
Quoted 10 lines
test/dm/acpi.c +9
-0DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test acpi_create_dmar() */ +static int dm_test_acpi_create_dmar (struct unit_test_state *uts) +{ +struct acpi_dmar dmar; + +ut_assertok (acpi_create_dmar (&dmar,DMAR_INTR_REMAP )); +ut_asserteq (DMAR_INTR_REMAP , dmar.flags); +ut_asserteq (DMAR_INTR_REMAP , dmar.flags);
This test case is inserted twice.
Quoted 7 lines
test/dm/acpi.c +5
-0+ut_asserteq (32 -1 , dmar.host_address_width); + +return 0 ; +} +DM_TEST (dm_test_acpi_create_dmar,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 19/39 acpi: Move acpi_fill_header() to generic code
In reply to Simon GlassThis function needs to be used by sandbox for tests. Move it into the generic directory.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 9 --------- include/acpi_table.h | 10 ++++++++++ lib/acpi/acpi_table.c | 10 ++++++++++ test/dm/acpi.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 9 deletions(-)
arch/x86/lib/acpi_table.c +0 -9
@@ -60,15 +60,6 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, sizeof(struct acpi_rsdp)); } -void acpi_fill_header (struct acpi_table_header *header,char *signature) -{ -memcpy (header->signature, signature,4 ); -memcpy (header->oem_id,OEM_ID ,6 ); -memcpy (header->oem_table_id,OEM_TABLE_ID ,8 ); - header->oem_revision =U_BOOT_BUILD_DATE ; -memcpy (header->aslc_id,ASLC_ID ,4 ); -} -static void acpi_write_rsdt (struct acpi_rsdt *rsdt) {struct acpi_table_header *header = &(rsdt->header);
include/acpi_table.h +10 -0
@@ -509,6 +509,16 @@ int acpi_get_table_revision(enum acpi_tables table);*/ int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags); +/** +* acpi_fill_header() - Set up a new table header +* +* This sets all fields except length, revision, checksum and aslc_revision +* +* @header: ACPI header to update +* @signature: Table signature to use (4 characters) +*/ +void acpi_fill_header (struct acpi_table_header *header,char *signature); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/acpi/acpi_table.c +10 -0
@@ -9,6 +9,7 @@#include <dm.h> #include <acpi_table.h> #include <cpu.h> +#include <version.h> int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags) {
@@ -84,3 +85,12 @@ int acpi_get_table_revision(enum acpi_tables table)return -EINVAL ; } } + +void acpi_fill_header (struct acpi_table_header *header,char *signature) +{ +memcpy (header->signature, signature,4 ); +memcpy (header->oem_id,OEM_ID ,6 ); +memcpy (header->oem_table_id,OEM_TABLE_ID ,8 ); + header->oem_revision =U_BOOT_BUILD_DATE ; +memcpy (header->aslc_id,ASLC_ID ,4 ); +}
test/dm/acpi.c +28 -0
@@ -9,6 +9,7 @@#include <common.h> #include <acpi_table.h> #include <dm.h> +#include <version.h> #include <dm/acpi.h> #include <dm/test.h> #include <test/ut.h>
@@ -81,3 +82,30 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_create_dmar,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_fill_header() */ +static int dm_test_acpi_fill_header (struct unit_test_state *uts) +{ +struct acpi_table_header hdr; + +/* Make sure these 5 fields are not changed */ + hdr.length =0x11 ; + hdr.revision =0x22 ; + hdr.checksum =0x33 ; + hdr.aslc_revision =0x44 ; +acpi_fill_header (&hdr,"ABCD" ); + +ut_assertok (memcmp ("ABCD" , hdr.signature,sizeof (hdr.signature))); +ut_asserteq (0x11 , hdr.length); +ut_asserteq (0x22 , hdr.revision); +ut_asserteq (0x33 , hdr.checksum); +ut_assertok (memcmp (OEM_ID , hdr.oem_id,sizeof (hdr.oem_id))); +ut_assertok (memcmp (OEM_TABLE_ID , hdr.oem_table_id, +sizeof (hdr.oem_table_id))); +ut_asserteq (U_BOOT_BUILD_DATE , hdr.oem_revision); +ut_assertok (memcmp (ASLC_ID , hdr.aslc_id,sizeof (hdr.aslc_id))); +ut_asserteq (0x44 , hdr.aslc_revision); + +return 0 ; +} +DM_TEST (dm_test_acpi_fill_header,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 3 lines
This function needs to be used by sandbox for tests. Move it into the generic directory.
Nit: Move it into the generic directory and add a test for it.
Quoted 5 lines
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
Quoted 8 lines
Changes in v2: None
arch/x86/lib/acpi_table.c | 9 --------- include/acpi_table.h | 10 ++++++++++ lib/acpi/acpi_table.c | 10 ++++++++++ test/dm/acpi.c | 28 ++++++++++++++++++++++++++++ 4 files changed, 48 insertions(+), 9 deletions(-)
regards, Wolfgang
Antwort: [PATCH v2 19/39] acpi: Move acpi_fill_header() to generic code
Hi Simon,
looking at this patch some more I have another question, see below.
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 7 lines
This function needs to be used by sandbox for tests. Move it into the generic directory.
Signed-off-by Simon Glass <[email protected]>Reviewed-by Bin Meng <[email protected]>---
[snip]
Quoted 8 lines
test/dm/acpi.c +4
-0@@ -81,3 +82,30 @@ static int dm_test_acpi_create_dmar(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_create_dmar,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_fill_header() */ +static int dm_test_acpi_fill_header (struct unit_test_state *uts) +{
test/dm/acpi.c static int dm_test_acpi_create_dmar(struct unit_test_state *uts) · line 98
Quoted 10 lines
test/dm/acpi.c +10
-0+struct acpi_table_header hdr; + +/* Make sure these 5 fields are not changed */ + hdr.length =0x11 ; + hdr.revision =0x22 ; + hdr.checksum =0x33 ; + hdr.aslc_revision =0x44 ; +acpi_fill_header (&hdr,"ABCD" ); + +ut_assertok (memcmp ("ABCD" , hdr.signature,sizeof (hdr.signature)));
Could ut_asserteq_mem() be used here?
The output would be a little more verbose.
With ut_assertok(memcmp()):
test/dm/acpi.c:104, dm_test_acpi_fill_header(): 0 == memcmp("ABCD", hdr.signature, sizeof(hdr.signature)): Expected 0x0 (0), got 0x13 (19)
With ut_assertmem_eq():
test/dm/acpi.c:103, dm_test_acpi_fill_header(): "ABCD" = hdr.signature: Expected "41424344", got "41424331"
Quoted 15 lines
test/dm/acpi.c +13
-0+ut_asserteq (0x11 , hdr.length); +ut_asserteq (0x22 , hdr.revision); +ut_asserteq (0x33 , hdr.checksum); +ut_assertok (memcmp (OEM_ID , hdr.oem_id,sizeof (hdr.oem_id))); +ut_assertok (memcmp (OEM_TABLE_ID , hdr.oem_table_id, +sizeof (hdr.oem_table_id))); +ut_asserteq (U_BOOT_BUILD_DATE , hdr.oem_revision); +ut_assertok (memcmp (ASLC_ID , hdr.aslc_id,sizeof (hdr.aslc_id))); +ut_asserteq (0x44 , hdr.aslc_revision); + +return 0 ; +} +DM_TEST (dm_test_acpi_fill_header,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 20/39 acpi: Add a method to write tables for a device
In reply to Simon GlassA device may want to write out ACPI tables to describe itself to Linux. Add a method to permit this.
---
Changes in v2:
- Drop definition of ACPI_TABLE_CREATOR
- Make _acpi_write_dev_tables() static and switch argument order
- Generalise the ACPI function recursion with acpi_recurse_method()
arch/sandbox/dts/test.dts | 4 +++ drivers/core/acpi.c | 61 +++++++++++++++++++++++++++++++++++++++ include/dm/acpi.h | 30 +++++++++++++++++++ test/dm/acpi.c | 43 +++++++++++++++++++++++++++ 4 files changed, 138 insertions(+)
arch/sandbox/dts/test.dts +4 -0
@@ -210,6 +210,10 @@ compatible = "denx,u-boot-acpi-test"; }; + acpi-test2 { + compatible = "denx,u-boot-acpi-test"; + }; + clocks { clk_fixed: clk-fixed { compatible = "fixed-clock";
drivers/core/acpi.c +61 -0
72 lines not on this page · raw message
include/dm/acpi.h +30 -0
@@ -24,6 +24,17 @@#if !defined(__ACPI__) +/** +* struct acpi_ctx - Context used for writing ACPI tables +* +* This contains a few useful pieces of information used when writing +* +* @current: Current address for writing +*/ +struct acpi_ctx { +void *current; +}; +/** * struct acpi_ops - ACPI operations supported by driver model */
@@ -38,6 +49,15 @@ struct acpi_ops {* other error */ int (*get_name)(const struct udevice *dev,char *out_name); + +/** +* write_tables() - Write out any tables required by this device +* +* @dev: Device to write +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int (*write_tables)(const struct udevice *dev,struct acpi_ctx *ctx); };#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops)
@@ -72,6 +92,16 @@ int acpi_get_name(const struct udevice *dev, char *out_name);*/ int acpi_return_name (char *out_name,const char *name); +/** +* acpi_write_dev_tables() - Write ACPI tables required by devices +* +* This scans through all devices and tells them to write any tables they want +* to write. +* +* @return 0 if OK, -ve if any device returned an error +*/ +int acpi_write_dev_tables (struct acpi_ctx *ctx); +#endif /* __ACPI__ */ #endif
test/dm/acpi.c +43 -0
58 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 20/39] acpi: Add a method to write tables for a device
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 12 lines
A device may want to write out ACPI tables to describe itself to Linux. Add a method to permit this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Drop definition ofACPI_TABLE_CREATOR
- Make_acpi_write_dev_tables()static and switch argument order
- Generalise the ACPI function recursion withacpi_recurse_method()
Quoted 5 lines
arch/sandbox/dts/test.dts | 4 +++ drivers/core/acpi.c | 61 +++++++++++++++++++++++++++++++++++++++ include/dm/acpi.h | 30 +++++++++++++++++++ test/dm/acpi.c | 43 +++++++++++++++++++++++++++ 4 files changed, 138 insertions(+)
PATCH v2 21/39 acpi: Convert part of acpi_table to use acpi_ctx
In reply to Simon GlassThe current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this would be better done in a helper function.
Update write_acpi_tables() to make use of the new acpi_ctx structure, adding a few helpers to clean things up.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 88 +++++++++++++++++++-------------------- include/acpi_table.h | 36 ++++++++++++++++ lib/acpi/acpi_table.c | 22 ++++++++++ test/dm/acpi.c | 28 +++++++++++++ 4 files changed, 129 insertions(+), 45 deletions(-)
arch/x86/lib/acpi_table.c +43 -45
@@ -10,6 +10,7 @@#include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h> +#include <mapmem.h> #include <serial.h> #include <version.h> #include <asm/acpi/global_nvs.h>
@@ -19,6 +20,7 @@#include <asm/mpspec.h> #include <asm/tables.h> #include <asm/arch/global_nvs.h> +#include <dm/acpi.h> /* * IASL compiles the dsdt entries and writes the hex values
@@ -468,9 +470,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)/* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */ -ulong write_acpi_tables (ulong start) +ulong write_acpi_tables (ulong start_addr) { -u32 current; +struct acpi_ctx sctx, *ctx = &sctx;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt;
@@ -481,60 +483,61 @@ ulong write_acpi_tables(ulong start)struct acpi_madt *madt;struct acpi_csrt *csrt;struct acpi_spcr *spcr; +void *start; +ulong addr;int i; - current = start; + start =map_sysmem (start_addr,0 ); + ctx->current = start;/* Align ACPI tables to 16 byte */ - current =ALIGN (current,16 ); +acpi_align (ctx); -debug ("ACPI: Writing ACPI tables at %lx\n" , start); +debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr);/* We need at least an RSDP and an RSDT Table */ - rsdp = (struct acpi_rsdp *)current; - current +=sizeof (struct acpi_rsdp ); - current =ALIGN (current,16 ); - rsdt = (struct acpi_rsdt *)current; - current +=sizeof (struct acpi_rsdt ); - current =ALIGN (current,16 ); - xsdt = (struct acpi_xsdt *)current; - current +=sizeof (struct acpi_xsdt ); + rsdp = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); + rsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); + xsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));/* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). */ - current =ALIGN (current,64 ); +acpi_align_large (ctx);/* clear all table memory */ -memset ((void *)start,0 , current - start); +memset ((void *)start,0 , ctx->current - start);acpi_write_rsdp (rsdp, rsdt, xsdt);acpi_write_rsdt (rsdt);acpi_write_xsdt (xsdt);debug ("ACPI: * FACS\n" ); - facs = (struct acpi_facs *)current; - current +=sizeof (struct acpi_facs ); - current =ALIGN (current,16 ); + facs = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_facs ));acpi_create_facs (facs);debug ("ACPI: * DSDT\n" ); - dsdt = (struct acpi_table_header *)current; + dsdt = ctx->current;memcpy (dsdt, &AmlCode,sizeof (struct acpi_table_header )); - current +=sizeof (struct acpi_table_header ); -memcpy ((char *)current, +acpi_inc (ctx,sizeof (struct acpi_table_header )); +memcpy (ctx->current, (char *)&AmlCode +sizeof (struct acpi_table_header ), dsdt->length -sizeof (struct acpi_table_header )); - current += dsdt->length -sizeof (struct acpi_table_header ); - current =ALIGN (current,16 ); +acpi_inc_align (ctx, dsdt->length -sizeof (struct acpi_table_header ));/* Pack GNVS into the ACPI table area */ for (i =0 ; i < dsdt->length; i++) {u32 *gnvs = (u32 *)((u32 )dsdt + i);if (*gnvs ==ACPI_GNVS_ADDR ) { -debug ("Fix up global NVS in DSDT to 0x%08x\n" , current); - *gnvs = current; +ulong addr = (ulong )map_to_sysmem (ctx->current); + +debug ("Fix up global NVS in DSDT to %#08lx\n" , addr); + *gnvs = addr;break ; } }
@@ -544,51 +547,46 @@ ulong write_acpi_tables(ulong start) dsdt->checksum =table_compute_checksum ((void *)dsdt, dsdt->length);/* Fill in platform-specific global NVS variables */ -acpi_create_gnvs ((struct acpi_global_nvs *)current); - current +=sizeof (struct acpi_global_nvs ); - current =ALIGN (current,16 ); +acpi_create_gnvs (ctx->current); +acpi_inc_align (ctx,sizeof (struct acpi_global_nvs ));debug ("ACPI: * FADT\n" ); - fadt = (struct acpi_fadt *)current; - current +=sizeof (struct acpi_fadt ); - current =ALIGN (current,16 ); + fadt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_fadt ));acpi_create_fadt (fadt, facs, dsdt);acpi_add_table (rsdp, fadt);debug ("ACPI: * MADT\n" ); - madt = (struct acpi_madt *)current; + madt = ctx->current;acpi_create_madt (madt); - current += madt->header.length; +acpi_inc_align (ctx, madt->header.length);acpi_add_table (rsdp, madt); - current =ALIGN (current,16 );debug ("ACPI: * MCFG\n" ); - mcfg = (struct acpi_mcfg *)current; + mcfg = ctx->current;acpi_create_mcfg (mcfg); - current += mcfg->header.length; +acpi_inc_align (ctx, mcfg->header.length);acpi_add_table (rsdp, mcfg); - current =ALIGN (current,16 );debug ("ACPI: * CSRT\n" ); - csrt = (struct acpi_csrt *)current; + csrt = ctx->current;acpi_create_csrt (csrt); - current += csrt->header.length; +acpi_inc_align (ctx, csrt->header.length);acpi_add_table (rsdp, csrt); - current =ALIGN (current,16 );debug ("ACPI: * SPCR\n" ); - spcr = (struct acpi_spcr *)current; + spcr = ctx->current;acpi_create_spcr (spcr); - current += spcr->header.length; +acpi_inc_align (ctx, spcr->header.length);acpi_add_table (rsdp, spcr); - current =ALIGN (current,16 ); -debug ("current = %x\n" , current); + addr =map_to_sysmem (ctx->current); +debug ("current = %lx\n" , addr); acpi_rsdp_addr = (unsigned long )rsdp;debug ("ACPI: done\n" ); -return current; +return addr; }ulong acpi_get_rsdp_addr (void )
include/acpi_table.h +36 -0
@@ -26,6 +26,8 @@#if !defined(__ACPI__) +struct acpi_ctx ; +/* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
@@ -519,6 +521,40 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);*/ void acpi_fill_header (struct acpi_table_header *header,char *signature); +/** +* acpi_align() - Align the ACPI output pointer to a 16-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align (struct acpi_ctx *ctx); + +/** +* acpi_align_large() - Align the ACPI output pointer to a 64-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align_large (struct acpi_ctx *ctx); + +/** +* acpi_inc() - Increment the ACPI output pointer by a bit +* +* The pointer is NOT aligned afterwards. +* +* @ctx: ACPI context +* @amount: Amount to increment by +*/ +void acpi_inc (struct acpi_ctx *ctx,uint amount); + +/** +* acpi_inc_align() - Increment the ACPI output pointer by a bit and align +* +* The pointer is aligned afterwards. +* +* @ctx: ACPI context +* @amount: Amount to increment by +*/ +void acpi_inc_align (struct acpi_ctx *ctx,uint amount); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/acpi/acpi_table.c +22 -0
@@ -10,6 +10,7 @@#include <acpi_table.h> #include <cpu.h> #include <version.h> +#include <dm/acpi.h> int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags) {
@@ -94,3 +95,24 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature) header->oem_revision =U_BOOT_BUILD_DATE ;memcpy (header->aslc_id,ASLC_ID ,4 ); } + +void acpi_align (struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN ((ulong )ctx->current,16 ); +} + +void acpi_align_large (struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN ((ulong )ctx->current,64 ); +} + +void acpi_inc (struct acpi_ctx *ctx,uint amount) +{ + ctx->current += amount; +} + +void acpi_inc_align (struct acpi_ctx *ctx,uint amount) +{ + ctx->current += amount; +acpi_align (ctx); +}
test/dm/acpi.c +28 -0
@@ -152,3 +152,31 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_write_tables,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test basic ACPI functions */ +static int dm_test_acpi_basic (struct unit_test_state *uts) +{ +struct acpi_ctx ctx; + +/* Check align works */ + ctx.current = (void *)5 ; +acpi_align (&ctx); +ut_asserteq_ptr ((void *)16 , ctx.current); + +/* Check that align does nothing if already aligned */ +acpi_align (&ctx); +ut_asserteq_ptr ((void *)16 , ctx.current); +acpi_align_large (&ctx); +ut_asserteq_ptr ((void *)64 , ctx.current); +acpi_align_large (&ctx); +ut_asserteq_ptr ((void *)64 , ctx.current); + +/* Check incrementing */ +acpi_inc (&ctx,3 ); +ut_asserteq_ptr ((void *)67 , ctx.current); +acpi_inc_align (&ctx,3 ); +ut_asserteq_ptr ((void *)80 , ctx.current); + +return 0 ; +} +DM_TEST (dm_test_acpi_basic,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 21/39] acpi: Convert part of acpi_table to use acpi_ctx
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 217 lines
The current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this would be better done in a helper function.
Update
write_acpi_tables()to make use of the newacpi_ctxstructure, adding a few helpers to clean things up.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 88 +++++++++++++++++++-------------------- include/acpi_table.h | 36 ++++++++++++++++ lib/acpi/acpi_table.c | 22 ++++++++++ test/dm/acpi.c | 28 +++++++++++++ 4 files changed, 129 insertions(+), 45 deletions(-)arch/x86/lib/acpi_table.c +43
-45@@ -10,6 +10,7 @@#include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h> +#include <mapmem.h> #include <serial.h> #include <version.h> #include <asm/acpi/global_nvs.h> @@ -19,6 +20,7 @@#include <asm/mpspec.h> #include <asm/tables.h> #include <asm/arch/global_nvs.h> +#include <dm/acpi.h> /* * IASL compiles the dsdt entries and writes the hex values @@ -468,9 +470,9 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)/* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */ -ulong write_acpi_tables (ulong start) +ulong write_acpi_tables (ulong start_addr) { -u32 current; +struct acpi_ctx sctx, *ctx = &sctx;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt;@@ -481,60 +483,61 @@ ulong write_acpi_tables(ulong start)struct acpi_madt *madt;struct acpi_csrt *csrt;struct acpi_spcr *spcr; +void *start; +ulong addr;int i; - current = start; + start =map_sysmem (start_addr,0 ); + ctx->current = start;/* Align ACPI tables to 16 byte */ - current =ALIGN (current,16 ); +acpi_align (ctx); -debug ("ACPI: Writing ACPI tables at %lx\n" , start); +debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr);/* We need at least an RSDP and an RSDT Table */ - rsdp = (struct acpi_rsdp *)current; - current +=sizeof (struct acpi_rsdp ); - current =ALIGN (current,16 ); - rsdt = (struct acpi_rsdt *)current; - current +=sizeof (struct acpi_rsdt ); - current =ALIGN (current,16 ); - xsdt = (struct acpi_xsdt *)current; - current +=sizeof (struct acpi_xsdt ); + rsdp = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); + rsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); + xsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));/* * Per ACPI spec, the FACS table address must be aligned to a 64 byte * boundary (Windows checks this, but Linux does not). */ - current =ALIGN (current,64 ); +acpi_align_large (ctx);/* clear all table memory */ -memset ((void *)start,0 , current - start); +memset ((void *)start,0 , ctx->current - start);acpi_write_rsdp (rsdp, rsdt, xsdt);acpi_write_rsdt (rsdt);acpi_write_xsdt (xsdt);debug ("ACPI: * FACS\n" ); - facs = (struct acpi_facs *)current; - current +=sizeof (struct acpi_facs ); - current =ALIGN (current,16 ); + facs = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_facs ));acpi_create_facs (facs);debug ("ACPI: * DSDT\n" ); - dsdt = (struct acpi_table_header *)current; + dsdt = ctx->current;memcpy (dsdt, &AmlCode,sizeof (struct acpi_table_header )); - current +=sizeof (struct acpi_table_header ); -memcpy ((char *)current, +acpi_inc (ctx,sizeof (struct acpi_table_header )); +memcpy (ctx->current, (char *)&AmlCode +sizeof (struct acpi_table_header ), dsdt->length -sizeof (struct acpi_table_header )); - current += dsdt->length -sizeof (struct acpi_table_header ); - current =ALIGN (current,16 ); +acpi_inc_align (ctx, dsdt->length -sizeof (struct acpi_table_header ));/* Pack GNVS into the ACPI table area */ for (i =0 ; i < dsdt->length; i++) {u32 *gnvs = (u32 *)((u32 )dsdt + i);if (*gnvs ==ACPI_GNVS_ADDR ) { -debug ("Fix up global NVS in DSDT to 0x%08x\n" , current); - *gnvs = current; +ulong addr = (ulong )map_to_sysmem (ctx->current); + +debug ("Fix up global NVS in DSDT to %#08lx\n" , addr); + *gnvs = addr;break ; } }@@ -544,51 +547,46 @@ ulong write_acpi_tables(ulong start) dsdt->checksum =table_compute_checksum ((void *)dsdt, dsdt->length);/* Fill in platform-specific global NVS variables */ -acpi_create_gnvs ((struct acpi_global_nvs *)current); - current +=sizeof (struct acpi_global_nvs ); - current =ALIGN (current,16 ); +acpi_create_gnvs (ctx->current); +acpi_inc_align (ctx,sizeof (struct acpi_global_nvs ));debug ("ACPI: * FADT\n" ); - fadt = (struct acpi_fadt *)current; - current +=sizeof (struct acpi_fadt ); - current =ALIGN (current,16 ); + fadt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_fadt ));acpi_create_fadt (fadt, facs, dsdt);acpi_add_table (rsdp, fadt);debug ("ACPI: * MADT\n" ); - madt = (struct acpi_madt *)current; + madt = ctx->current;acpi_create_madt (madt); - current += madt->header.length; +acpi_inc_align (ctx, madt->header.length);acpi_add_table (rsdp, madt); - current =ALIGN (current,16 );debug ("ACPI: * MCFG\n" ); - mcfg = (struct acpi_mcfg *)current; + mcfg = ctx->current;acpi_create_mcfg (mcfg); - current += mcfg->header.length; +acpi_inc_align (ctx, mcfg->header.length);acpi_add_table (rsdp, mcfg); - current =ALIGN (current,16 );debug ("ACPI: * CSRT\n" ); - csrt = (struct acpi_csrt *)current; + csrt = ctx->current;acpi_create_csrt (csrt); - current += csrt->header.length; +acpi_inc_align (ctx, csrt->header.length);acpi_add_table (rsdp, csrt); - current =ALIGN (current,16 );debug ("ACPI: * SPCR\n" ); - spcr = (struct acpi_spcr *)current; + spcr = ctx->current;acpi_create_spcr (spcr); - current += spcr->header.length; +acpi_inc_align (ctx, spcr->header.length);acpi_add_table (rsdp, spcr); - current =ALIGN (current,16 ); -debug ("current = %x\n" , current); + addr =map_to_sysmem (ctx->current); +debug ("current = %lx\n" , addr); acpi_rsdp_addr = (unsigned long )rsdp;debug ("ACPI: done\n" ); -return current; +return addr; }ulong acpi_get_rsdp_addr (void )include/acpi_table.h +2
-0@@ -26,6 +26,8 @@#if !defined(__ACPI__) +struct acpi_ctx ; +/* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
include/acpi_table.h int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); · line 529
Quoted 9 lines
include/acpi_table.h +6
-0@@ -519,6 +521,40 @@ int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags);*/ void acpi_fill_header (struct acpi_table_header *header,char *signature); +/** +* acpi_align() - Align the ACPI output pointer to a 16-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align (struct acpi_ctx *ctx);
Nit: The function names acpi_align() and acpi_align_large() are both vague on the exact alignment that is used.
How about acpi_align16() and acpi_align64() ?
Quoted 17 lines
include/acpi_table.h +17
-0+ +/** +* acpi_align_large() - Align the ACPI output pointer to a 64-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align_large (struct acpi_ctx *ctx); + +/** +* acpi_inc() - Increment the ACPI output pointer by a bit +* +* The pointer is NOT aligned afterwards. +* +* @ctx: ACPI context +* @amount: Amount to increment by +*/ +void acpi_inc (struct acpi_ctx *ctx,uint amount);
include/acpi_table.h int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); · line 556
Quoted 10 lines
include/acpi_table.h +10
-0+ +/** +* acpi_inc_align() - Increment the ACPI output pointer by a bit and align +* +* The pointer is aligned afterwards. +* +* @ctx: ACPI context +* @amount: Amount to increment by +*/ +void acpi_inc_align (struct acpi_ctx *ctx,uint amount);
Similar nit as above: acpi_inc_align16() ?
Quoted 79 lines
include/acpi_table.h +1
-0+#endif /* !__ACPI__*/ #include <asm/acpi_table.h> lib/acpi/acpi_table.c +22
-0@@ -10,6 +10,7 @@#include <acpi_table.h> #include <cpu.h> #include <version.h> +#include <dm/acpi.h> int acpi_create_dmar (struct acpi_dmar *dmar,enum dmar_flags flags) {@@ -94,3 +95,24 @@ void acpi_fill_header(struct acpi_table_header *header, char *signature) header->oem_revision =U_BOOT_BUILD_DATE ;memcpy (header->aslc_id,ASLC_ID ,4 ); } + +void acpi_align (struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN ((ulong )ctx->current,16 ); +} + +void acpi_align_large (struct acpi_ctx *ctx) +{ + ctx->current = (void *)ALIGN ((ulong )ctx->current,64 ); +} + +void acpi_inc (struct acpi_ctx *ctx,uint amount) +{ + ctx->current += amount; +} + +void acpi_inc_align (struct acpi_ctx *ctx,uint amount) +{ + ctx->current += amount; +acpi_align (ctx); +}test/dm/acpi.c +28
-0@@ -152,3 +152,31 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_write_tables,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test basic ACPI functions */ +static int dm_test_acpi_basic (struct unit_test_state *uts) +{ +struct acpi_ctx ctx; + +/* Check align works */ + ctx.current = (void *)5 ; +acpi_align (&ctx); +ut_asserteq_ptr ((void *)16 , ctx.current); + +/* Check that align does nothing if already aligned */ +acpi_align (&ctx); +ut_asserteq_ptr ((void *)16 , ctx.current); +acpi_align_large (&ctx); +ut_asserteq_ptr ((void *)64 , ctx.current); +acpi_align_large (&ctx); +ut_asserteq_ptr ((void *)64 , ctx.current); + +/* Check incrementing */ +acpi_inc (&ctx,3 ); +ut_asserteq_ptr ((void *)67 , ctx.current); +acpi_inc_align (&ctx,3 ); +ut_asserteq_ptr ((void *)80 , ctx.current); + +return 0 ; +} +DM_TEST (dm_test_acpi_basic,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Apart from the nits above:
PATCH v2 21/39 acpi: Convert part of acpi_table to use acpi_ctx
Hi Wolfgang,
Quoted 7 lines · Wolfgang Wallner
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 3 lines
The current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this
would
Quoted 16 lines
Quoted 16 lines
be better done in a helper function.
Update
write_acpi_tables()to make use of the newacpi_ctxstructure, adding a few helpers to clean things up.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 88 +++++++++++++++++++-------------------- include/acpi_table.h | 36 ++++++++++++++++ lib/acpi/acpi_table.c | 22 ++++++++++ test/dm/acpi.c | 28 +++++++++++++ 4 files changed, 129 insertions(+), 45 deletions(-)
[..]
Quoted 10 lines
include/acpi_table.h int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); · line 529
Quoted 6 lines
include/acpi_table.h +6
-0+/** +* acpi_align() - Align the ACPI output pointer to a 16-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align (struct acpi_ctx *ctx);Nit: The function names
acpi_align()andacpi_align_large()are both vague on the exact alignment that is used.
How aboutacpi_align16()andacpi_align64()?
There is I think only one case where we use 64. Most of the time it is 16. So I thought it was a bit silly to put 16 in the function name - it is the standard alignment.
Perhaps I should use align() and align64()?
Regards,
Simon
Antwort: Re: [PATCH v2 21/39] acpi: Convert part of acpi_table to use acpi_ctx
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 40 lines
Hi Wolfgang,
Quoted 23 lines · Wolfgang Wallner
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 19 lines
The current code uses an address but a pointer would result in fewer casts. Also it repeats the alignment code in a lot of places so this would be better done in a helper function.
Update
write_acpi_tables()to make use of the newacpi_ctxstructure, adding a few helpers to clean things up.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 88 +++++++++++++++++++-------------------- include/acpi_table.h | 36 ++++++++++++++++ lib/acpi/acpi_table.c | 22 ++++++++++ test/dm/acpi.c | 28 +++++++++++++ 4 files changed, 129 insertions(+), 45 deletions(-)[..]
Quoted 10 lines
include/acpi_table.h int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); · line 529
Quoted 6 lines
include/acpi_table.h +6
-0+/** +* acpi_align() - Align the ACPI output pointer to a 16-byte boundary +* +* @ctx: ACPI context +*/ +void acpi_align (struct acpi_ctx *ctx);Nit: The function names
acpi_align()andacpi_align_large()are both vague on the exact alignment that is used.
How aboutacpi_align16()andacpi_align64()?
Quoted 3 lines
There is I think only one case where we use 64. Most of the time it is 16. So I thought it was a bit silly to put 16 in the function name - it is the standard alignment.
Perhaps I should use
align()andalign64()?
Yes, I'm fine with that.
regards, Wolfgang
PATCH v2 22/39 x86: Allow devices to write ACPI tables
In reply to Simon GlassCall the new core function to permit devices to write their own ACPI tables. These tables will appear after all other tables.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 2 ++ 1 file changed, 2 insertions(+)
arch/x86/lib/acpi_table.c +2 -0
@@ -580,6 +580,8 @@ ulong write_acpi_tables(ulong start_addr)acpi_inc_align (ctx, spcr->header.length);acpi_add_table (rsdp, spcr); +acpi_write_dev_tables (ctx); + addr =map_to_sysmem (ctx->current);debug ("current = %lx\n" , addr);
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 22/39] x86: Allow devices to write ACPI tables
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 27 lines
Call the new core function to permit devices to write their own ACPI tables. These tables will appear after all other tables.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 2 ++ 1 file changed, 2 insertions(+)arch/x86/lib/acpi_table.c +2
-0@@ -580,6 +580,8 @@ ulong write_acpi_tables(ulong start_addr)acpi_inc_align (ctx, spcr->header.length);acpi_add_table (rsdp, spcr); +acpi_write_dev_tables (ctx); + addr =map_to_sysmem (ctx->current);debug ("current = %lx\n" , addr);Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 23/39 acpi: Drop code for missing XSDT from acpi_write_rsdp()
In reply to Simon GlassWe don't actually support tables without an XSDT so we can drop this dead code.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
arch/x86/lib/acpi_table.c +2 -13
@@ -42,19 +42,8 @@ static void acpi_write_rsdp(struct acpi_rsdp *rsdp, struct acpi_rsdt *rsdt, rsdp->length =sizeof (struct acpi_rsdp ); rsdp->rsdt_address = (u32 )rsdt; -/* -* Revision: ACPI 1.0: 0, ACPI 2.0/3.0/4.0: 2 -* -* Some OSes expect an XSDT to be present for RSD PTR revisions >= 2. -* If we don't have an ACPI XSDT, force ACPI 1.0 (and thus RSD PTR -* revision 0) -*/ -if (xsdt ==NULL ) { - rsdp->revision =ACPI_RSDP_REV_ACPI_1_0 ; - }else { - rsdp->xsdt_address = (u64 )(u32 )xsdt; - rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ; - } + rsdp->xsdt_address = (u64 )(u32 )xsdt; + rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ;/* Calculate checksums */ rsdp->checksum =table_compute_checksum ((void *)rsdp,20 );
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 23/39] acpi: Drop code for missing XSDT from acpi_write_rsdp()
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 11 lines
We don't actually support tables without an XSDT so we can drop this dead code.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-)
PATCH v2 24/39 acpi: Move acpi_add_table() to generic code
In reply to Simon GlassMove this code to a generic location so that we can test it with sandbox. This requires adding a few new fields to acpi_ctx, so drop the local variables used in the original code.
Also use mapmem to avoid pointer-to-address casts which don't work on sandbox.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 82 +++++---------------------------------- include/acpi_table.h | 9 +++++ include/dm/acpi.h | 5 +++ lib/acpi/acpi_table.c | 64 ++++++++++++++++++++++++++++++ test/dm/acpi.c | 4 ++ 5 files changed, 92 insertions(+), 72 deletions(-)
arch/x86/lib/acpi_table.c +10 -72
@@ -83,66 +83,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt) sizeof(struct acpi_xsdt)); } -/** -* Add an ACPI table to the RSDT (and XSDT) structure, recalculate length -* and checksum. -*/ -static void acpi_add_table (struct acpi_rsdp *rsdp,void *table) -{ -int i, entries_num; -struct acpi_rsdt *rsdt; -struct acpi_xsdt *xsdt =NULL ; - -/* The RSDT is mandatory while the XSDT is not */ - rsdt = (struct acpi_rsdt *)rsdp->rsdt_address; - -if (rsdp->xsdt_address) - xsdt = (struct acpi_xsdt *)((u32 )rsdp->xsdt_address); - -/* This should always be MAX_ACPI_TABLES */ - entries_num =ARRAY_SIZE (rsdt->entry); - -for (i =0 ; i < entries_num; i++) { -if (rsdt->entry[i] ==0 ) -break ; - } - -if (i >= entries_num) { -debug ("ACPI: Error: too many tables\n" ); -return ; - } - -/* Add table to the RSDT */ - rsdt->entry[i] = (u32 )table; - -/* Fix RSDT length or the kernel will assume invalid entries */ - rsdt->header.length =sizeof (struct acpi_table_header ) + - (sizeof (u32) * (i +1 )); - -/* Re-calculate checksum */ - rsdt->header.checksum =0 ; - rsdt->header.checksum =table_compute_checksum ((u8 *)rsdt, - rsdt->header.length); - -/* -* And now the same thing for the XSDT. We use the same index as for -* now we want the XSDT and RSDT to always be in sync in U-Boot -*/ -if (xsdt) { -/* Add table to the XSDT */ - xsdt->entry[i] = (u64 )(u32 )table; - -/* Fix XSDT length */ - xsdt->header.length =sizeof (struct acpi_table_header ) + - (sizeof (u64) * (i +1 )); - -/* Re-calculate checksum */ - xsdt->header.checksum =0 ; - xsdt->header.checksum =table_compute_checksum ((u8 *)xsdt, - xsdt->header.length); - } -} -static void acpi_create_facs (struct acpi_facs *facs) {memset ((void *)facs,0 ,sizeof (struct acpi_facs ));
@@ -462,8 +402,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)ulong write_acpi_tables (ulong start_addr) {struct acpi_ctx sctx, *ctx = &sctx; -struct acpi_rsdp *rsdp; -struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt;struct acpi_facs *facs;struct acpi_table_header *dsdt;
@@ -485,9 +423,9 @@ ulong write_acpi_tables(ulong start_addr)debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr);/* We need at least an RSDP and an RSDT Table */ - rsdp = ctx->current; + ctx->rsdp = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); - rsdt = ctx->current; + ctx->rsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); xsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));
@@ -500,8 +438,8 @@ ulong write_acpi_tables(ulong start_addr)/* clear all table memory */ memset ((void *)start,0 , ctx->current - start); -acpi_write_rsdp (rsdp, rsdt, xsdt); -acpi_write_rsdt (rsdt); +acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); +acpi_write_rsdt (ctx->rsdt);acpi_write_xsdt (xsdt);debug ("ACPI: * FACS\n" );
@@ -543,38 +481,38 @@ ulong write_acpi_tables(ulong start_addr) fadt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_fadt ));acpi_create_fadt (fadt, facs, dsdt); -acpi_add_table (rsdp, fadt); +acpi_add_table (ctx, fadt);debug ("ACPI: * MADT\n" ); madt = ctx->current;acpi_create_madt (madt);acpi_inc_align (ctx, madt->header.length); -acpi_add_table (rsdp, madt); +acpi_add_table (ctx, madt);debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);acpi_inc_align (ctx, mcfg->header.length); -acpi_add_table (rsdp, mcfg); +acpi_add_table (ctx, mcfg);debug ("ACPI: * CSRT\n" ); csrt = ctx->current;acpi_create_csrt (csrt);acpi_inc_align (ctx, csrt->header.length); -acpi_add_table (rsdp, csrt); +acpi_add_table (ctx, csrt);debug ("ACPI: * SPCR\n" ); spcr = ctx->current;acpi_create_spcr (spcr);acpi_inc_align (ctx, spcr->header.length); -acpi_add_table (rsdp, spcr); +acpi_add_table (ctx, spcr);acpi_write_dev_tables (ctx); addr =map_to_sysmem (ctx->current);debug ("current = %lx\n" , addr); - acpi_rsdp_addr = (unsigned long )rsdp; + acpi_rsdp_addr = (unsigned long )ctx->rsdp;debug ("ACPI: done\n" );return addr;
include/acpi_table.h +9 -0
@@ -555,6 +555,15 @@ void acpi_inc(struct acpi_ctx *ctx, uint amount);*/ void acpi_inc_align (struct acpi_ctx *ctx,uint amount); +/** +* acpi_add_table() - Add a new table to the RSDP and XSDT +* +* @ctx: ACPI context +* @table: Table to add +* @return 0 if OK, -E2BIG if too many tables +*/ +int acpi_add_table (struct acpi_ctx *ctx,void *table); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
include/dm/acpi.h +5 -0
@@ -30,9 +30,14 @@* This contains a few useful pieces of information used when writing * * @current: Current address for writing +* @rsdp: Pointer to the Root System Description Pointer, typically used when +* adding a new table. The RSDP holds pointers to the RSDP and XSDT. +* @rsdt: Pointer to the Root System Description Table */ struct acpi_ctx {void *current; +struct acpi_rsdp *rsdp; +struct acpi_rsdt *rsdt; };/**
lib/acpi/acpi_table.c +64 -0
73 lines not on this page · raw message
test/dm/acpi.c +4 -0
@@ -21,10 +21,14 @@ static int testacpi_write_tables(const struct udevice *dev, struct acpi_ctx *ctx) {struct acpi_dmar *dmar; +int ret; dmar = (struct acpi_dmar *)ctx->current;acpi_create_dmar (dmar,DMAR_INTR_REMAP ); ctx->current +=sizeof (struct acpi_dmar ); + ret =acpi_add_table (ctx, dmar); +if (ret) +return log_msg_ret ("add" , ret);return 0 ; }
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 24/39] acpi: Move acpi_add_table() to generic code
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 193 lines
Move this code to a generic location so that we can test it with sandbox. This requires adding a few new fields to
acpi_ctx, so drop the local variables used in the original code.Also use mapmem to avoid pointer-to-address casts which don't work on sandbox.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 82 +++++---------------------------------- include/acpi_table.h | 9 +++++ include/dm/acpi.h | 5 +++ lib/acpi/acpi_table.c | 64 ++++++++++++++++++++++++++++++ test/dm/acpi.c | 4 ++ 5 files changed, 92 insertions(+), 72 deletions(-)arch/x86/lib/acpi_table.c +10
-72@@ -83,66 +83,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt) sizeof(struct acpi_xsdt)); } -/** -* Add an ACPI table to the RSDT (and XSDT) structure, recalculate length -* and checksum. -*/ -static void acpi_add_table (struct acpi_rsdp *rsdp,void *table) -{ -int i, entries_num; -struct acpi_rsdt *rsdt; -struct acpi_xsdt *xsdt =NULL ; - -/* The RSDT is mandatory while the XSDT is not */ - rsdt = (struct acpi_rsdt *)rsdp->rsdt_address; - -if (rsdp->xsdt_address) - xsdt = (struct acpi_xsdt *)((u32 )rsdp->xsdt_address); - -/* This should always be MAX_ACPI_TABLES */ - entries_num =ARRAY_SIZE (rsdt->entry); - -for (i =0 ; i < entries_num; i++) { -if (rsdt->entry[i] ==0 ) -break ; - } - -if (i >= entries_num) { -debug ("ACPI: Error: too many tables\n" ); -return ; - } - -/* Add table to the RSDT */ - rsdt->entry[i] = (u32 )table; - -/* Fix RSDT length or the kernel will assume invalid entries */ - rsdt->header.length =sizeof (struct acpi_table_header ) + - (sizeof (u32) * (i +1 )); - -/* Re-calculate checksum */ - rsdt->header.checksum =0 ; - rsdt->header.checksum =table_compute_checksum ((u8 *)rsdt, - rsdt->header.length); - -/* -* And now the same thing for the XSDT. We use the same index as for -* now we want the XSDT and RSDT to always be in sync in U-Boot -*/ -if (xsdt) { -/* Add table to the XSDT */ - xsdt->entry[i] = (u64 )(u32 )table; - -/* Fix XSDT length */ - xsdt->header.length =sizeof (struct acpi_table_header ) + - (sizeof (u64) * (i +1 )); - -/* Re-calculate checksum */ - xsdt->header.checksum =0 ; - xsdt->header.checksum =table_compute_checksum ((u8 *)xsdt, - xsdt->header.length); - } -} -static void acpi_create_facs (struct acpi_facs *facs) {memset ((void *)facs,0 ,sizeof (struct acpi_facs ));@@ -462,8 +402,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)ulong write_acpi_tables (ulong start_addr) {struct acpi_ctx sctx, *ctx = &sctx; -struct acpi_rsdp *rsdp; -struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt;struct acpi_facs *facs;struct acpi_table_header *dsdt;@@ -485,9 +423,9 @@ ulong write_acpi_tables(ulong start_addr)debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr);/* We need at least an RSDP and an RSDT Table */ - rsdp = ctx->current; + ctx->rsdp = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); - rsdt = ctx->current; + ctx->rsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); xsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));@@ -500,8 +438,8 @@ ulong write_acpi_tables(ulong start_addr)/* clear all table memory */ memset ((void *)start,0 , ctx->current - start); -acpi_write_rsdp (rsdp, rsdt, xsdt); -acpi_write_rsdt (rsdt); +acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); +acpi_write_rsdt (ctx->rsdt);acpi_write_xsdt (xsdt);debug ("ACPI: * FACS\n" );@@ -543,38 +481,38 @@ ulong write_acpi_tables(ulong start_addr) fadt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_fadt ));acpi_create_fadt (fadt, facs, dsdt); -acpi_add_table (rsdp, fadt); +acpi_add_table (ctx, fadt);debug ("ACPI: * MADT\n" ); madt = ctx->current;acpi_create_madt (madt);acpi_inc_align (ctx, madt->header.length); -acpi_add_table (rsdp, madt); +acpi_add_table (ctx, madt);debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);acpi_inc_align (ctx, mcfg->header.length); -acpi_add_table (rsdp, mcfg); +acpi_add_table (ctx, mcfg);debug ("ACPI: * CSRT\n" ); csrt = ctx->current;acpi_create_csrt (csrt);acpi_inc_align (ctx, csrt->header.length); -acpi_add_table (rsdp, csrt); +acpi_add_table (ctx, csrt);debug ("ACPI: * SPCR\n" ); spcr = ctx->current;acpi_create_spcr (spcr);acpi_inc_align (ctx, spcr->header.length); -acpi_add_table (rsdp, spcr); +acpi_add_table (ctx, spcr);acpi_write_dev_tables (ctx); addr =map_to_sysmem (ctx->current);debug ("current = %lx\n" , addr); - acpi_rsdp_addr = (unsigned long )rsdp; + acpi_rsdp_addr = (unsigned long )ctx->rsdp;debug ("ACPI: done\n" );return addr;include/acpi_table.h +9
-0@@ -555,6 +555,15 @@ void acpi_inc(struct acpi_ctx *ctx, uint amount);*/ void acpi_inc_align (struct acpi_ctx *ctx,uint amount); +/** +* acpi_add_table() - Add a new table to the RSDP and XSDT +* +* @ctx: ACPI context +* @table: Table to add +* @return 0 if OK, -E2BIG if too many tables +*/ +int acpi_add_table (struct acpi_ctx *ctx,void *table); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h> include/dm/acpi.h +0
-0
include/dm/acpi.h line 34
Quoted 5 lines
include/dm/acpi.h +2
-0@@ -30,9 +30,14 @@* This contains a few useful pieces of information used when writing * * @current: Current address for writing +* @rsdp: Pointer to the Root System Description Pointer, typically used when +* adding a new table. The RSDP holds pointers to the RSDP and XSDT.
typo: "to the RSDT" (not RSDP)
Quoted 109 lines
include/dm/acpi.h +3
-0+* @rsdt: Pointer to the Root System Description Table */ struct acpi_ctx {void *current; +struct acpi_rsdp *rsdp; +struct acpi_rsdt *rsdt; };/** lib/acpi/acpi_table.c +64
-0@@ -9,6 +9,8 @@#include <dm.h> #include <acpi_table.h> #include <cpu.h> +#include <mapmem.h> +#include <tables_csum.h> #include <version.h> #include <dm/acpi.h> @@ -116,3 +118,65 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount) ctx->current += amount;acpi_align (ctx); } + +/** +* Add an ACPI table to the RSDT (and XSDT) structure, recalculate length +* and checksum. +*/ +int acpi_add_table (struct acpi_ctx *ctx,void *table) +{ +int i, entries_num; +struct acpi_rsdt *rsdt; +struct acpi_xsdt *xsdt =NULL ; + +/* The RSDT is mandatory while the XSDT is not */ + rsdt = ctx->rsdt; + +if (ctx->rsdp->xsdt_address) + xsdt =map_sysmem (ctx->rsdp->xsdt_address,0 ); + +/* This should always be MAX_ACPI_TABLES */ + entries_num =ARRAY_SIZE (rsdt->entry); + +for (i =0 ; i < entries_num; i++) { +if (rsdt->entry[i] ==0 ) +break ; + } + +if (i >= entries_num) { +debug ("ACPI: Error: too many tables\n" ); +return -E2BIG ; + } + +/* Add table to the RSDT */ + rsdt->entry[i] =map_to_sysmem (table); + +/* Fix RSDT length or the kernel will assume invalid entries */ + rsdt->header.length =sizeof (struct acpi_table_header ) + + (sizeof (u32) * (i +1 )); + +/* Re-calculate checksum */ + rsdt->header.checksum =0 ; + rsdt->header.checksum =table_compute_checksum ((u8 *)rsdt, + rsdt->header.length); + +/* +* And now the same thing for the XSDT. We use the same index as for +* now we want the XSDT and RSDT to always be in sync in U-Boot +*/ +if (xsdt) { +/* Add table to the XSDT */ + xsdt->entry[i] =map_to_sysmem (table); + +/* Fix XSDT length */ + xsdt->header.length =sizeof (struct acpi_table_header ) + + (sizeof (u64) * (i +1 )); + +/* Re-calculate checksum */ + xsdt->header.checksum =0 ; + xsdt->header.checksum = +table_compute_checksum ((u8 *)xsdt, xsdt->header.length); + } + +return 0 ; +}test/dm/acpi.c +4
-0@@ -21,10 +21,14 @@ static int testacpi_write_tables(const struct udevice *dev, struct acpi_ctx *ctx) {struct acpi_dmar *dmar; +int ret; dmar = (struct acpi_dmar *)ctx->current;acpi_create_dmar (dmar,DMAR_INTR_REMAP ); ctx->current +=sizeof (struct acpi_dmar ); + ret =acpi_add_table (ctx, dmar); +if (ret) +return log_msg_ret ("add" , ret);return 0 ; }Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 25/39 acpi: Put table-setup code in its own function
In reply to Simon GlassWe always write three basic tables to ACPI at the start. Move this into its own function, along with acpi_fill_header(), so we can write a test for this code.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 77 +---------------------------------- include/acpi_table.h | 10 +++++ lib/acpi/acpi_table.c | 86 ++++++++++++++++++++++++++++++++++++++- test/dm/acpi.c | 55 ++++++++++++++++++++++++- 4 files changed, 148 insertions(+), 80 deletions(-)
arch/x86/lib/acpi_table.c +1 -76
@@ -31,58 +31,6 @@ extern const unsigned char AmlCode[];/* ACPI RSDP address to be used in boot parameters */ static ulong acpi_rsdp_addr; -static void acpi_write_rsdp (struct acpi_rsdp *rsdp,struct acpi_rsdt *rsdt, -struct acpi_xsdt *xsdt) -{ -memset (rsdp,0 ,sizeof (struct acpi_rsdp )); - -memcpy (rsdp->signature,RSDP_SIG ,8 ); -memcpy (rsdp->oem_id,OEM_ID ,6 ); - - rsdp->length =sizeof (struct acpi_rsdp ); - rsdp->rsdt_address = (u32 )rsdt; - - rsdp->xsdt_address = (u64 )(u32 )xsdt; - rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ; - -/* Calculate checksums */ - rsdp->checksum =table_compute_checksum ((void *)rsdp,20 ); - rsdp->ext_checksum =table_compute_checksum ((void *)rsdp, -sizeof (struct acpi_rsdp )); -} - -static void acpi_write_rsdt (struct acpi_rsdt *rsdt) -{ -struct acpi_table_header *header = &(rsdt->header); - -/* Fill out header fields */ -acpi_fill_header (header,"RSDT" ); - header->length =sizeof (struct acpi_rsdt ); - header->revision =1 ; - -/* Entries are filled in later, we come with an empty set */ - -/* Fix checksum */ - header->checksum =table_compute_checksum ((void *)rsdt, -sizeof (struct acpi_rsdt )); -} - -static void acpi_write_xsdt (struct acpi_xsdt *xsdt) -{ -struct acpi_table_header *header = &(xsdt->header); - -/* Fill out header fields */ -acpi_fill_header (header,"XSDT" ); - header->length =sizeof (struct acpi_xsdt ); - header->revision =1 ; - -/* Entries are filled in later, we come with an empty set */ - -/* Fix checksum */ - header->checksum =table_compute_checksum ((void *)xsdt, -sizeof (struct acpi_xsdt )); -} -static void acpi_create_facs (struct acpi_facs *facs) {memset ((void *)facs,0 ,sizeof (struct acpi_facs ));
@@ -402,7 +350,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)ulong write_acpi_tables (ulong start_addr) {struct acpi_ctx sctx, *ctx = &sctx; -struct acpi_xsdt *xsdt;struct acpi_facs *facs;struct acpi_table_header *dsdt;struct acpi_fadt *fadt;
@@ -415,32 +362,10 @@ ulong write_acpi_tables(ulong start_addr)int i; start =map_sysmem (start_addr,0 ); - ctx->current = start; - -/* Align ACPI tables to 16 byte */ -acpi_align (ctx);debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr); -/* We need at least an RSDP and an RSDT Table */ - ctx->rsdp = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); - ctx->rsdt = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); - xsdt = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_xsdt )); -/* -* Per ACPI spec, the FACS table address must be aligned to a 64 byte -* boundary (Windows checks this, but Linux does not). -*/ -acpi_align_large (ctx); - -/* clear all table memory */ -memset ((void *)start,0 , ctx->current - start); - -acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); -acpi_write_rsdt (ctx->rsdt); -acpi_write_xsdt (xsdt); +acpi_setup_base_tables (ctx, start);debug ("ACPI: * FACS\n" ); facs = ctx->current;
include/acpi_table.h +10 -0
@@ -564,6 +564,16 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount);*/ int acpi_add_table (struct acpi_ctx *ctx,void *table); +/** +* acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XDST +* +* Set up the context with the given start position. Some basic tables are +* always needed, so set them up as well. +* +* @ctx: Context to set up +*/ +void acpi_setup_base_tables (struct acpi_ctx *ctx,void *start); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h>
lib/acpi/acpi_table.c +84 -2
99 lines not on this page · raw message
test/dm/acpi.c +53 -2
77 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 25/39] acpi: Put table-setup code in its own function
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 126 lines
We always write three basic tables to ACPI at the start. Move this into its own function, along with
acpi_fill_header(), so we can write a test for this code.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
arch/x86/lib/acpi_table.c | 77 +---------------------------------- include/acpi_table.h | 10 +++++ lib/acpi/acpi_table.c | 86 ++++++++++++++++++++++++++++++++++++++- test/dm/acpi.c | 55 ++++++++++++++++++++++++- 4 files changed, 148 insertions(+), 80 deletions(-)arch/x86/lib/acpi_table.c +1
-76@@ -31,58 +31,6 @@ extern const unsigned char AmlCode[];/* ACPI RSDP address to be used in boot parameters */ static ulong acpi_rsdp_addr; -static void acpi_write_rsdp (struct acpi_rsdp *rsdp,struct acpi_rsdt *rsdt, -struct acpi_xsdt *xsdt) -{ -memset (rsdp,0 ,sizeof (struct acpi_rsdp )); - -memcpy (rsdp->signature,RSDP_SIG ,8 ); -memcpy (rsdp->oem_id,OEM_ID ,6 ); - - rsdp->length =sizeof (struct acpi_rsdp ); - rsdp->rsdt_address = (u32 )rsdt; - - rsdp->xsdt_address = (u64 )(u32 )xsdt; - rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ; - -/* Calculate checksums */ - rsdp->checksum =table_compute_checksum ((void *)rsdp,20 ); - rsdp->ext_checksum =table_compute_checksum ((void *)rsdp, -sizeof (struct acpi_rsdp )); -} - -static void acpi_write_rsdt (struct acpi_rsdt *rsdt) -{ -struct acpi_table_header *header = &(rsdt->header); - -/* Fill out header fields */ -acpi_fill_header (header,"RSDT" ); - header->length =sizeof (struct acpi_rsdt ); - header->revision =1 ; - -/* Entries are filled in later, we come with an empty set */ - -/* Fix checksum */ - header->checksum =table_compute_checksum ((void *)rsdt, -sizeof (struct acpi_rsdt )); -} - -static void acpi_write_xsdt (struct acpi_xsdt *xsdt) -{ -struct acpi_table_header *header = &(xsdt->header); - -/* Fill out header fields */ -acpi_fill_header (header,"XSDT" ); - header->length =sizeof (struct acpi_xsdt ); - header->revision =1 ; - -/* Entries are filled in later, we come with an empty set */ - -/* Fix checksum */ - header->checksum =table_compute_checksum ((void *)xsdt, -sizeof (struct acpi_xsdt )); -} -static void acpi_create_facs (struct acpi_facs *facs) {memset ((void *)facs,0 ,sizeof (struct acpi_facs ));@@ -402,7 +350,6 @@ static void acpi_create_spcr(struct acpi_spcr *spcr)ulong write_acpi_tables (ulong start_addr) {struct acpi_ctx sctx, *ctx = &sctx; -struct acpi_xsdt *xsdt;struct acpi_facs *facs;struct acpi_table_header *dsdt;struct acpi_fadt *fadt;@@ -415,32 +362,10 @@ ulong write_acpi_tables(ulong start_addr)int i; start =map_sysmem (start_addr,0 ); - ctx->current = start; - -/* Align ACPI tables to 16 byte */ -acpi_align (ctx);debug ("ACPI: Writing ACPI tables at %lx\n" , start_addr); -/* We need at least an RSDP and an RSDT Table */ - ctx->rsdp = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); - ctx->rsdt = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); - xsdt = ctx->current; -acpi_inc_align (ctx,sizeof (struct acpi_xsdt )); -/* -* Per ACPI spec, the FACS table address must be aligned to a 64 byte -* boundary (Windows checks this, but Linux does not). -*/ -acpi_align_large (ctx); - -/* clear all table memory */ -memset ((void *)start,0 , ctx->current - start); - -acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); -acpi_write_rsdt (ctx->rsdt); -acpi_write_xsdt (xsdt); +acpi_setup_base_tables (ctx, start);debug ("ACPI: * FACS\n" ); facs = ctx->current;include/acpi_table.h +0
-0
include/acpi_table.h void acpi_inc_align(struct acpi_ctx *ctx, uint amount); · line 568
Quoted 5 lines
include/acpi_table.h +2
-0@@ -564,6 +564,16 @@ void acpi_inc_align(struct acpi_ctx *ctx, uint amount);*/ int acpi_add_table (struct acpi_ctx *ctx,void *table); +/** +* acpi_setup_base_tables() - Set up context along with RSDP, RSDT and XDST
typo: XSDT
Quoted 98 lines
include/acpi_table.h +8
-0+* +* Set up the context with the given start position. Some basic tables are +* always needed, so set them up as well. +* +* @ctx: Context to set up +*/ +void acpi_setup_base_tables (struct acpi_ctx *ctx,void *start); +#endif /* !__ACPI__*/ #include <asm/acpi_table.h> lib/acpi/acpi_table.c +66
-2@@ -157,7 +157,7 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)/* Re-calculate checksum */ rsdt->header.checksum =0 ; - rsdt->header.checksum =table_compute_checksum ((u8 *)rsdt, + rsdt->header.checksum =table_compute_checksum (rsdt, rsdt->header.length);/* @@ -175,8 +175,90 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)/* Re-calculate checksum */ xsdt->header.checksum =0 ; xsdt->header.checksum = -table_compute_checksum ((u8 *)xsdt, xsdt->header.length); +table_compute_checksum (xsdt, xsdt->header.length); }return 0 ; } + +static void acpi_write_rsdp (struct acpi_rsdp *rsdp,struct acpi_rsdt *rsdt, +struct acpi_xsdt *xsdt) +{ +memset (rsdp,0 ,sizeof (struct acpi_rsdp )); + +memcpy (rsdp->signature,RSDP_SIG ,8 ); +memcpy (rsdp->oem_id,OEM_ID ,6 ); + + rsdp->length =sizeof (struct acpi_rsdp ); + rsdp->rsdt_address =map_to_sysmem (rsdt); + + rsdp->xsdt_address =map_to_sysmem (xsdt); + rsdp->revision =ACPI_RSDP_REV_ACPI_2_0 ; + +/* Calculate checksums */ + rsdp->checksum =table_compute_checksum (rsdp,20 ); + rsdp->ext_checksum =table_compute_checksum (rsdp, +sizeof (struct acpi_rsdp )); +} + +static void acpi_write_rsdt (struct acpi_rsdt *rsdt) +{ +struct acpi_table_header *header = &rsdt->header; + +/* Fill out header fields */ +acpi_fill_header (header,"RSDT" ); + header->length =sizeof (struct acpi_rsdt ); + header->revision =1 ; + +/* Entries are filled in later, we come with an empty set */ + +/* Fix checksum */ + header->checksum =table_compute_checksum (rsdt, +sizeof (struct acpi_rsdt )); +} + +static void acpi_write_xsdt (struct acpi_xsdt *xsdt) +{ +struct acpi_table_header *header = &xsdt->header; + +/* Fill out header fields */ +acpi_fill_header (header,"XSDT" ); + header->length =sizeof (struct acpi_xsdt ); + header->revision =1 ; + +/* Entries are filled in later, we come with an empty set */ + +/* Fix checksum */ + header->checksum =table_compute_checksum (xsdt, +sizeof (struct acpi_xsdt )); +} + +void acpi_setup_base_tables (struct acpi_ctx *ctx,void *start) +{ +struct acpi_xsdt *xsdt; + + ctx->current = start; + +/* Align ACPI tables to 16 byte */ +acpi_align (ctx); + +/* We need at least an RSDP and an RSDT Table */ + ctx->rsdp = ctx->current;
lib/acpi/acpi_table.c int acpi_add_table(struct acpi_ctx *ctx, void *table) · line 256
Quoted 10 lines
lib/acpi/acpi_table.c +10
-0+acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); + ctx->rsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); + xsdt = ctx->current; +acpi_inc_align (ctx,sizeof (struct acpi_xsdt )); +/* +* Per ACPI spec, the FACS table address must be aligned to a 64 byte +* boundary (Windows checks this, but Linux does not). +*/ +acpi_align_large (ctx);
Having this call inside of acpi_setup_base_tables() creates the requirement that the FACS is set up directly after the base tables. With the current code this is satisfied, but it might be overlooked by future refactoring.
Maybe move this call out directly in front of the setup of FACS?
Quoted 52 lines
lib/acpi/acpi_table.c +8
-0+ +/* clear all table memory */ +memset ((void *)start,'\0' , ctx->current - start); + +acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); +acpi_write_rsdt (ctx->rsdt); +acpi_write_xsdt (xsdt); +}test/dm/acpi.c +12
-2@@ -9,6 +9,9 @@#include <common.h> #include <acpi_table.h> #include <dm.h> +#include <malloc.h> +#include <mapmem.h> +#include <tables_csum.h> #include <version.h> #include <dm/acpi.h> #include <dm/test.h> @@ -138,9 +141,9 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts) buf =malloc (BUF_SIZE );ut_assertnonnull (buf); - ctx.current = buf; +acpi_setup_base_tables (&ctx, buf); + dmar = ctx.current;ut_assertok (acpi_write_dev_tables (&ctx)); - dmar = buf;/* * We should have two dmar tables, one for each "denx,u-boot-acpi-test" @@ -153,6 +156,11 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)ut_asserteq (DMAR_INTR_REMAP , dmar[1 ].flags);ut_asserteq (32 -1 , dmar[1 ].host_address_width); +/* Check that the pointers were added correctly */ +ut_asserteq (map_to_sysmem (dmar), ctx.rsdt->entry[0 ]); +ut_asserteq (map_to_sysmem (dmar +1 ), ctx.rsdt->entry[1 ]); +ut_asserteq (0 , ctx.rsdt->entry[2 ]); +return 0 ; }DM_TEST (dm_test_acpi_write_tables,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );@@ -184,3 +192,46 @@ static int dm_test_acpi_basic(struct unit_test_state *uts)return 0 ; }DM_TEST (dm_test_acpi_basic,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT ); + +/* Test acpi_setup_base_tables */
test/dm/acpi.c static int dm_test_acpi_basic(struct unit_test_state *uts) · line 206
Quoted 10 lines
test/dm/acpi.c +10
-0+static int dm_test_acpi_setup_base_tables (struct unit_test_state *uts) +{ +struct acpi_rsdp *rsdp; +struct acpi_rsdt *rsdt; +struct acpi_xsdt *xsdt; +struct acpi_ctx ctx; +void *buf, *end; + +/* Use an unaligned address deliberately */ + buf =memalign (64 ,BUF_SIZE );
Maybe I'm missing something, but as far as I understand it, the comment contradicts the code (aligning to 64 bytes makes it an aligned address, doesn't it?).
Quoted 33 lines
test/dm/acpi.c +31
-0+ut_assertnonnull (buf); +acpi_setup_base_tables (&ctx, buf +4 ); + + rsdp = buf +16 ; +ut_asserteq_ptr (rsdp, ctx.rsdp); +ut_assertok (memcmp (RSDP_SIG , rsdp->signature,sizeof (rsdp->signature))); +ut_asserteq (sizeof (*rsdp), rsdp->length); +ut_assertok (table_compute_checksum (rsdp,20 )); +ut_assertok (table_compute_checksum (rsdp,sizeof (*rsdp))); + + rsdt =PTR_ALIGN ((void *)rsdp +sizeof (*rsdp),16 ); +ut_asserteq_ptr (rsdt, ctx.rsdt); +ut_assertok (memcmp ("RSDT" , rsdt->header.signature,ACPI_NAME_LEN )); +ut_asserteq (sizeof (*rsdt), rsdt->header.length); +ut_assertok (table_compute_checksum (rsdt,sizeof (*rsdt))); + + xsdt =PTR_ALIGN ((void *)rsdt +sizeof (*rsdt),16 ); +ut_assertok (memcmp ("XSDT" , xsdt->header.signature,ACPI_NAME_LEN )); +ut_asserteq (sizeof (*xsdt), xsdt->header.length); +ut_assertok (table_compute_checksum (xsdt,sizeof (*xsdt))); + + end =PTR_ALIGN ((void *)xsdt +sizeof (*xsdt),64 ); +ut_asserteq_ptr (end, ctx.current); + +ut_asserteq (map_to_sysmem (rsdt), rsdp->rsdt_address); +ut_asserteq (map_to_sysmem (xsdt), rsdp->xsdt_address); + +return 0 ; +} +DM_TEST (dm_test_acpi_setup_base_tables, +DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
PATCH v2 26/39 acpi: Move the xsdt pointer to acpi_ctx
In reply to Simon GlassPut this in the context along with the other important pointers.
---
Changes in v2: None
include/dm/acpi.h | 2 ++ lib/acpi/acpi_table.c | 38 ++++++++++++++++---------------------- test/dm/acpi.c | 5 +++++ 3 files changed, 23 insertions(+), 22 deletions(-)
include/dm/acpi.h +2 -0
@@ -33,11 +33,13 @@* @rsdp: Pointer to the Root System Description Pointer, typically used when * adding a new table. The RSDP holds pointers to the RSDP and XSDT. * @rsdt: Pointer to the Root System Description Table +* @xsdt: Pointer to the Extended System Description Table */ struct acpi_ctx {void *current;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt; +struct acpi_xsdt *xsdt; };/**
lib/acpi/acpi_table.c +16 -22
@@ -127,13 +127,11 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table) {int i, entries_num;struct acpi_rsdt *rsdt; -struct acpi_xsdt *xsdt =NULL ; +struct acpi_xsdt *xsdt;/* The RSDT is mandatory while the XSDT is not */ rsdt = ctx->rsdt; - -if (ctx->rsdp->xsdt_address) - xsdt =map_sysmem (ctx->rsdp->xsdt_address,0 ); + xsdt = ctx->xsdt;/* This should always be MAX_ACPI_TABLES */ entries_num =ARRAY_SIZE (rsdt->entry);
@@ -164,19 +162,17 @@ int acpi_add_table(struct acpi_ctx *ctx, void *table)* And now the same thing for the XSDT. We use the same index as for * now we want the XSDT and RSDT to always be in sync in U-Boot */ -if (xsdt) { -/* Add table to the XSDT */ - xsdt->entry[i] =map_to_sysmem (table); - -/* Fix XSDT length */ - xsdt->header.length =sizeof (struct acpi_table_header ) + - (sizeof (u64) * (i +1 )); - -/* Re-calculate checksum */ - xsdt->header.checksum =0 ; - xsdt->header.checksum = -table_compute_checksum (xsdt, xsdt->header.length); - } +/* Add table to the XSDT */ + xsdt->entry[i] =map_to_sysmem (table); + +/* Fix XSDT length */ + xsdt->header.length =sizeof (struct acpi_table_header ) + + (sizeof (u64) * (i +1 )); + +/* Re-calculate checksum */ + xsdt->header.checksum =0 ; + xsdt->header.checksum =table_compute_checksum (xsdt, + xsdt->header.length);return 0 ; }
@@ -235,8 +231,6 @@ static void acpi_write_xsdt(struct acpi_xsdt *xsdt)void acpi_setup_base_tables (struct acpi_ctx *ctx,void *start) { -struct acpi_xsdt *xsdt; - ctx->current = start;/* Align ACPI tables to 16 byte */
@@ -247,7 +241,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)acpi_inc_align (ctx,sizeof (struct acpi_rsdp )); ctx->rsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_rsdt )); - xsdt = ctx->current; + ctx->xsdt = ctx->current;acpi_inc_align (ctx,sizeof (struct acpi_xsdt ));/* * Per ACPI spec, the FACS table address must be aligned to a 64 byte
@@ -258,7 +252,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)/* clear all table memory */ memset ((void *)start,'\0' , ctx->current - start); -acpi_write_rsdp (ctx->rsdp, ctx->rsdt, xsdt); +acpi_write_rsdp (ctx->rsdp, ctx->rsdt, ctx->xsdt);acpi_write_rsdt (ctx->rsdt); -acpi_write_xsdt (xsdt); +acpi_write_xsdt (ctx->xsdt); }
test/dm/acpi.c +5 -0
@@ -161,6 +161,10 @@ static int dm_test_acpi_write_tables(struct unit_test_state *uts)ut_asserteq (map_to_sysmem (dmar +1 ), ctx.rsdt->entry[1 ]);ut_asserteq (0 , ctx.rsdt->entry[2 ]); +ut_asserteq (map_to_sysmem (dmar), ctx.xsdt->entry[0 ]); +ut_asserteq (map_to_sysmem (dmar +1 ), ctx.xsdt->entry[1 ]); +ut_asserteq (0 , ctx.xsdt->entry[2 ]); +return 0 ; }DM_TEST (dm_test_acpi_write_tables,DM_TESTF_SCAN_PDATA |DM_TESTF_SCAN_FDT );
@@ -221,6 +225,7 @@ static int dm_test_acpi_setup_base_tables(struct unit_test_state *uts)ut_assertok (table_compute_checksum (rsdt,sizeof (*rsdt))); xsdt =PTR_ALIGN ((void *)rsdt +sizeof (*rsdt),16 ); +ut_asserteq_ptr (xsdt, ctx.xsdt);ut_assertok (memcmp ("XSDT" , xsdt->header.signature,ACPI_NAME_LEN ));ut_asserteq (sizeof (*xsdt), xsdt->header.length);ut_assertok (table_compute_checksum (xsdt,sizeof (*xsdt)));
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 26/39] acpi: Move the xsdt pointer to acpi_ctx
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 11 lines
Put this in the context along with the other important pointers.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
include/dm/acpi.h | 2 ++ lib/acpi/acpi_table.c | 38 ++++++++++++++++---------------------- test/dm/acpi.c | 5 +++++ 3 files changed, 23 insertions(+), 22 deletions(-)
PATCH v2 27/39 acpi: Add an acpi command
In reply to Simon GlassIt is useful to dump ACPI tables in U-Boot to see what has been generated. Add a command to handle this.
To allow the command to find the tables, add a position into the global data.
Support subcommands to list and dump the tables.
---
Changes in v2: None
arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + cmd/Kconfig | 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 179 +++++++++++++++++++++++++ lib/acpi/acpi_table.c | 1 + test/dm/acpi.c | 73 ++++++++++ 7 files changed, 270 insertions(+) create mode 100644 cmd/acpi.c
arch/sandbox/include/asm/global_data.h +1 -0
@@ -13,6 +13,7 @@struct arch_global_data {uint8_t *ram_buf;/* emulated RAM buffer */ void *text_base;/* pointer to base of text region */ +ulong acpi_start;/* Start address of ACPI tables */ };#include <asm-generic/global_data.h>
arch/x86/include/asm/global_data.h +1 -0
@@ -123,6 +123,7 @@ struct arch_global_data {#ifdef CONFIG_FSP_VERSION2 struct fsp_header *fsp_s_hdr;/* Pointer to FSP-S header */ #endif + ulong acpi_start; /* Start address of ACPI tables */ };#endif
cmd/Kconfig +14 -0
@@ -190,6 +190,20 @@ comment "Commands" menu "Info commands" +config CMD_ACPI + bool "acpi" + default y if ACPIGEN + help + List and dump ACPI tables. ACPI (Advanced Configuration and Power + Interface) is used mostly on x86 for providing information to the + Operating System about devices in the system. The tables are set up + by the firmware, typically U-Boot but possibly an earlier firmware + module, if U-Boot is chain-loaded from something else. ACPI tables + can also include code, to perform hardware-specific tasks required + by the Operating Systems. This allows some amount of separation + between the firmware and OS, and is particularly useful when you + want to make hardware changes without the OS needing to be adjusted. + config CMD_BDI bool "bdinfo" default y
cmd/Makefile +1 -0
@@ -11,6 +11,7 @@ obj-y += help.o obj-y += version.o # command +obj-$(CONFIG_CMD_ACPI) += acpi.o obj-$(CONFIG_CMD_AES) += aes.o obj-$(CONFIG_CMD_AB_SELECT) += ab_select.o obj-$(CONFIG_CMD_ADC) += adc.o
cmd/acpi.c new file +179 -0
179 lines not on this page · raw message
lib/acpi/acpi_table.c +1 -0
@@ -235,6 +235,7 @@ void acpi_setup_base_tables(struct acpi_ctx *ctx, void *start)/* Align ACPI tables to 16 byte */ acpi_align (ctx); + gd->arch.acpi_start =map_to_sysmem (ctx->current);/* We need at least an RSDP and an RSDT Table */ ctx->rsdp = ctx->current;
test/dm/acpi.c +73 -0
91 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 27/39] acpi: Add an acpi command
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 14 lines
It is useful to dump ACPI tables in U-Boot to see what has been generated. Add a command to handle this.
To allow the command to find the tables, add a position into the global data.
Support subcommands to list and dump the tables.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 9 lines
arch/sandbox/include/asm/global_data.h | 1 + arch/x86/include/asm/global_data.h | 1 + cmd/Kconfig | 14 ++ cmd/Makefile | 1 + cmd/acpi.c | 179 +++++++++++++++++++++++++ lib/acpi/acpi_table.c | 1 + test/dm/acpi.c | 73 ++++++++++ 7 files changed, 270 insertions(+) create mode 100644 cmd/acpi.c
PATCH v2 28/39 acpi: Add some tables required by the generation code
In reply to Simon GlassThe code which generates ACPI tables programmatically, add a few ACPI definitions required by that code.
---
Changes in v2: None
include/acpi_table.h | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+)
include/acpi_table.h +50 -0
@@ -28,6 +28,18 @@struct acpi_ctx ; +/* +* The assigned ACPI ID for the coreboot project is 'BOOT' +* http://www.uefi.org/acpi_id_list +*/ +#define COREBOOT_ACPI_ID "BOOT"/* ACPI ID for coreboot HIDs */ + +/* List of ACPI HID that use the coreboot ACPI ID */ +enum coreboot_acpi_ids { +COREBOOT_ACPI_ID_CBTABLE =0x0000 ,/* BOOT0000 */ +COREBOOT_ACPI_ID_MAX =0xFFFF ,/* BOOTFFFF */ +}; +/* * RSDP (Root System Description Pointer) * Note: ACPI 1.0 didn't have length, xsdt_address, and ext_checksum
@@ -365,6 +377,44 @@ struct acpi_csrt_shared_info {u32 max_block_size; }; +struct __packed acpi_cstate { +u8 ctype; +u16 latency; +u32 power; +struct acpi_gen_regaddr resource; +}; + +struct __packed acpi_tstate { +u32 percent; +u32 power; +u32 latency; +u32 control; +u32 status; +}; + +/* Port types for ACPI _UPC object */ +enum acpi_upc_type { +UPC_TYPE_A , +UPC_TYPE_MINI_AB , +UPC_TYPE_EXPRESSCARD , +UPC_TYPE_USB3_A , +UPC_TYPE_USB3_B , +UPC_TYPE_USB3_MICRO_B , +UPC_TYPE_USB3_MICRO_AB , +UPC_TYPE_USB3_POWER_B , +UPC_TYPE_C_USB2_ONLY , +UPC_TYPE_C_USB2_SS_SWITCH , +UPC_TYPE_C_USB2_SS , +UPC_TYPE_PROPRIETARY =0xff , +/* +* The following types are not directly defined in the ACPI +* spec but are used by coreboot to identify a USB device type. +*/ +UPC_TYPE_INTERNAL =0xff , +UPC_TYPE_UNUSED , +UPC_TYPE_HUB +}; +enum dmar_type {DMAR_DRHD =0 ,DMAR_RMRR =1 ,
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 29/39 acpi: Add generation code for devices
In reply to Simon GlassSome devices need to create ACPI tables to communcate their parameters to Linux. Add support for this.
---
Changes in v2:
- Drop CID value from i2c struct
include/acpi_device.h | 705 ++++++++++++++++++++++++++ lib/acpi/acpi_device.c | 1094 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 1799 insertions(+) create mode 100644 include/acpi_device.h create mode 100644 lib/acpi/acpi_device.c
include/acpi_device.h new file +705 -0
@@ -0,0 +1,705 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Generation of tables for particular device types +* +* Copyright 2019 Google LLC +* Mostly taken from coreboot file of the same name +*/ + +#ifndef __ACPI_DEVICE_H +#define __ACPI_DEVICE_H + +#include <i2c.h> +#include <irq.h> +#include <spi.h> +#include <asm-generic/gpio.h> + +struct acpi_ctx ; +struct irq ; +struct gpio_desc ; +struct udevice ; + +/** +* enum acpi_dp_type - types of device property objects +* +* These refer to the types defined by struct acpi_dp below +* +* @ACPI_DP_TYPE_UNKNOWN: Unknown / do not use +* @ACPI_DP_TYPE_INTEGER: Integer value (u64) in @integer +* @ACPI_DP_TYPE_STRING: String value in @string +* @ACPI_DP_TYPE_REFERENCE: Reference to another object, with value in @string +* @ACPI_DP_TYPE_TABLE: Type for a top-level table which may have children +* @ACPI_DP_TYPE_ARRAY: Array of items with first item in @array and following +* items linked from that item's @next +* @ACPI_DP_TYPE_CHILD: Child object, with siblings in that child's @next +*/ +enum acpi_dp_type { +ACPI_DP_TYPE_UNKNOWN , +ACPI_DP_TYPE_INTEGER , +ACPI_DP_TYPE_STRING , +ACPI_DP_TYPE_REFERENCE , +ACPI_DP_TYPE_TABLE , +ACPI_DP_TYPE_ARRAY , +ACPI_DP_TYPE_CHILD , +}; + +/* ACPI descriptor values for common descriptors: SERIAL_BUS means I2C */ +#define ACPI_DESCRIPTOR_LARGE BIT(7) +#define ACPI_DESCRIPTOR_INTERRUPT (ACPI_DESCRIPTOR_LARGE | 9) +#define ACPI_DESCRIPTOR_GPIO (ACPI_DESCRIPTOR_LARGE | 12) +#define ACPI_DESCRIPTOR_SERIAL_BUS (ACPI_DESCRIPTOR_LARGE | 14) + +/* +* PRP0001 is a special DT namespace link device ID. It provides a means to use +* existing DT-compatible device identification in ACPI. When this _HID is used +* by an ACPI device, the ACPI subsystem in OS looks up "compatible" property in +* the device object's _DSD and will use the value of that property to identify +* the corresponding device in analogy with the original DT device +* identification algorithm. +* More details can be found in Linux kernel documentation: +* Documentation/acpi/enumeration.txt +*/ +#define ACPI_DT_NAMESPACE_HID "PRP0001" + +/* Length of a full path to an ACPI device */ +#define ACPI_PATH_MAX 30 + +/** +* acpi_device_name() - Locate and return the ACPI name for this device +* +* @dev: Device to check +* @name: Returns the character name, must be at least ACPI_NAME_MAX long +* @return 0 if OK, -ve on error +*/ +int acpi_device_name (const struct udevice *dev,char *name); + +/** +* acpi_device_path() - Get the full path to an ACPI device +* +* This gets the full path in the form XXXX.YYYY.ZZZZ where XXXX is the root +* and ZZZZ is the device. All parent devices are added to the path. +* +* @dev: Device to check +* @buf: Buffer to place the path in (should be ACPI_PATH_MAX long) +* @maxlen: Size of buffer (typically ACPI_PATH_MAX) +* @return 0 if OK, -ve on error +*/ +int acpi_device_path (const struct udevice *dev,char *buf,int maxlen); + +/** +* acpi_device_scope() - Get the scope of an ACPI device +* +* This gets the scope which is the full path of the parent device, as per +* acpi_device_path(). +* +* @dev: Device to check +* @buf: Buffer to place the path in (should be ACPI_PATH_MAX long) +* @maxlen: Size of buffer (typically ACPI_PATH_MAX) +* @return 0 if OK, -EINVAL if the device has no parent, other -ve on other +* error +*/ +int acpi_device_scope (const struct udevice *dev,char *scope,int maxlen); + +/** +* acpi_device_status() - Get the status of a device +* +* This currently just returns ACPI_STATUS_DEVICE_ALL_ON. It does not support +* inactive or hidden devices. +* +* @dev: Device to check +* @return device status, as ACPI_STATUS_DEVICE_... +*/ +int acpi_device_status (const struct udevice *dev); + +/** enum acpi_irq_mode - edge/level trigger mode */ +enum acpi_irq_mode { +ACPI_IRQ_EDGE_TRIGGERED , +ACPI_IRQ_LEVEL_TRIGGERED , +}; + +/** +* enum acpi_irq_polarity - polarity of interrupt +* +* @ACPI_IRQ_ACTIVE_LOW - for ACPI_IRQ_EDGE_TRIGGERED this means falling edge +* @ACPI_IRQ_ACTIVE_HIGH - for ACPI_IRQ_EDGE_TRIGGERED this means rising edge +* @ACPI_IRQ_ACTIVE_BOTH - not meaningful for ACPI_IRQ_EDGE_TRIGGERED +*/ +enum acpi_irq_polarity { +ACPI_IRQ_ACTIVE_LOW , +ACPI_IRQ_ACTIVE_HIGH , +ACPI_IRQ_ACTIVE_BOTH , +}; + +/** +* enum acpi_irq_shared - whether interrupt is shared or not +* +* @ACPI_IRQ_EXCLUSIVE: only this device uses the interrupt +* @ACPI_IRQ_SHARED: other devices may use this interrupt +*/ +enum acpi_irq_shared { +ACPI_IRQ_EXCLUSIVE , +ACPI_IRQ_SHARED , +}; + +/** enum acpi_irq_wake - indicates whether this interrupt can wake the device */ +enum acpi_irq_wake { +ACPI_IRQ_NO_WAKE , +ACPI_IRQ_WAKE , +}; + +/** +* struct acpi_irq - representation of an ACPI interrupt +* +* @pin: ACPI pin that is monitored for the interrupt +* @mode: Edge/level triggering +* @polarity: Interrupt polarity +* @shared: Whether interrupt is shared or not +* @wake: Whether interrupt can wake the device from sleep +*/ +struct acpi_irq { +unsigned int pin; +enum acpi_irq_mode mode; +enum acpi_irq_polarity polarity; +enum acpi_irq_shared shared; +enum acpi_irq_wake wake; +}; + +/** +* enum acpi_gpio_type - type of the descriptor +* +* @ACPI_GPIO_TYPE_INTERRUPT: GpioInterrupt +* @ACPI_GPIO_TYPE_IO: GpioIo +*/ +enum acpi_gpio_type { +ACPI_GPIO_TYPE_INTERRUPT , +ACPI_GPIO_TYPE_IO , +}; + +/** +* enum acpi_gpio_pull - pull direction +* +* @ACPI_GPIO_PULL_DEFAULT: Use default value for pin +* @ACPI_GPIO_PULL_UP: Pull up +* @ACPI_GPIO_PULL_DOWN: Pull down +* @ACPI_GPIO_PULL_NONE: No pullup/pulldown +*/ +enum acpi_gpio_pull { +ACPI_GPIO_PULL_DEFAULT , +ACPI_GPIO_PULL_UP , +ACPI_GPIO_PULL_DOWN , +ACPI_GPIO_PULL_NONE , +}; + +/** +* enum acpi_gpio_io_restrict - controls input/output of pin +* +* @ACPI_GPIO_IO_RESTRICT_NONE: no restrictions +* @ACPI_GPIO_IO_RESTRICT_INPUT: input only (no output) +* @ACPI_GPIO_IO_RESTRICT_OUTPUT: output only (no input) +* @ACPI_GPIO_IO_RESTRICT_PRESERVE: preserve settings when driver not active +*/ +enum acpi_gpio_io_restrict { +ACPI_GPIO_IO_RESTRICT_NONE , +ACPI_GPIO_IO_RESTRICT_INPUT , +ACPI_GPIO_IO_RESTRICT_OUTPUT , +ACPI_GPIO_IO_RESTRICT_PRESERVE , +}; + +/** enum acpi_gpio_polarity - controls the GPIO polarity */ +enum acpi_gpio_polarity { +ACPI_GPIO_ACTIVE_HIGH =0 , +ACPI_GPIO_ACTIVE_LOW =1 , +}; + +#define ACPI_GPIO_REVISION_ID 1 +#define ACPI_GPIO_MAX_PINS 2 + +/** +* struct acpi_gpio - representation of an ACPI GPIO +* +* @pin_count: Number of pins represented +* @pins: List of pins +* @type: GPIO type +* @pull: Pullup/pulldown setting +* @resource: Resource name for this GPIO controller +* For GpioInt: +* @interrupt_debounce_timeout: Debounce timeout in units of 10us +* @irq: Interrupt +* +* For GpioIo: +* @output_drive_strength: Drive strength in units of 10uA +* @io_shared; true if GPIO is shared +* @io_restrict: I/O restriction setting +* @polarity: GPIO polarity +*/ +struct acpi_gpio { +int pin_count; +u16 pins[ACPI_GPIO_MAX_PINS ]; + +enum acpi_gpio_type type; +enum acpi_gpio_pull pull; +char resource[ACPI_PATH_MAX ]; + +/* GpioInt */ +u16 interrupt_debounce_timeout; +struct acpi_irq irq; + +/* GpioIo */ +u16 output_drive_strength; +bool io_shared; +enum acpi_gpio_io_restrict io_restrict; +enum acpi_gpio_polarity polarity; +}; + +/* ACPI Descriptors for Serial Bus interfaces */ +#define ACPI_SERIAL_BUS_TYPE_I2C 1 +#define ACPI_SERIAL_BUS_TYPE_SPI 2 +#define ACPI_I2C_SERIAL_BUS_REVISION_ID 1/* TODO: upgrade to 2 */ +#define ACPI_I2C_TYPE_SPECIFIC_REVISION_ID 1 +#define ACPI_SPI_SERIAL_BUS_REVISION_ID 1 +#define ACPI_SPI_TYPE_SPECIFIC_REVISION_ID 1 + +/** +* struct acpi_gpio - representation of an ACPI I2C device +* +* @address: 7-bit or 10-bit I2C address +* @mode_10bit: Which address size is used +* @speed: Bus speed in Hz +* @resource: Resource name for the I2C controller +*/ +struct acpi_i2c { +u16 address; +enum i2c_address_mode mode_10bit; +enum i2c_speed_rate speed; +const char *resource; +}; + +/** +* struct acpi_spi - representation of an ACPI SPI device +* +* @device_select: Chip select used by this device (typically 0) +* @device_select_polarity: Polarity for the device +* @wire_mode: Number of wires used for SPI +* @speed: Bus speed in Hz +* @data_bit_length: Word length for SPI (typically 8) +* @clock_phase: Clock phase to capture data +* @clock_polarity: Bus polarity +* @resource: Resource name for the SPI controller +*/ +struct acpi_spi { +u16 device_select; +enum spi_polarity device_select_polarity; +enum spi_wire_mode wire_mode; +unsigned int speed; +u8 data_bit_length; +enum spi_clock_phase clock_phase; +enum spi_polarity clock_polarity; +const char *resource; +}; + +/** +* struct acpi_power_res_params - power on/off sequence information +* +* This provides GPIOs and timing information for powering a device on and off. +* This can be applied to any device that has power control, so is fairly +* generic. +* +* @reset_gpio: GPIO used to take device out of reset or to put it into reset +* @reset_delay_ms: Delay to be inserted after device is taken out of reset +* (_ON method delay) +* @reset_off_delay_ms: Delay to be inserted after device is put into reset +* (_OFF method delay) +* @enable_gpio: GPIO used to enable device +* @enable_delay_ms: Delay to be inserted after device is enabled +* @enable_off_delay_ms: Delay to be inserted after device is disabled +* (_OFF method delay) +* @stop_gpio: GPIO used to stop operation of device +* @stop_delay_ms: Delay to be inserted after disabling stop (_ON method delay) +* @stop_off_delay_ms: Delay to be inserted after enabling stop. +* (_OFF method delay) +*/ +struct acpi_power_res_params { +struct acpi_gpio *reset_gpio; +unsigned int reset_delay_ms; +unsigned int reset_off_delay_ms; +struct acpi_gpio *enable_gpio; +unsigned int enable_delay_ms; +unsigned int enable_off_delay_ms; +struct acpi_gpio *stop_gpio; +unsigned int stop_delay_ms; +unsigned int stop_off_delay_ms; +}; + +/** +* struct acpi_dp - ACPI device properties +* +* Writing Device Properties objects via _DSD +* +* This provides a structure to handle nested device-specific data which ends +* up in a _DSD table. +* +* https://www.kernel.org/doc/html/latest/firmware-guide/acpi/DSD-properties-rules.html +* https://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf +* https://uefi.org/sites/default/files/resources/_DSD-hierarchical-data-extension-UUID-v1.1.pdf +* +* The Device Property Hierarchy can be multiple levels deep with multiple +* children possible in each level. In order to support this flexibility +* the device property hierarchy must be built up before being written out. +* +* For example: +* +* // Child table with string and integer +* struct acpi_dp *child = acpi_dp_new_table("CHLD"); +* acpi_dp_add_string(child, "childstring", "CHILD"); +* acpi_dp_add_integer(child, "childint", 100); +* +* // _DSD table with integer and gpio and child pointer +* struct acpi_dp *dsd = acpi_dp_new_table("_DSD"); +* acpi_dp_add_integer(dsd, "number1", 1); +* acpi_dp_add_gpio(dsd, "gpio", "\_SB.PCI0.GPIO", 0, 0, 1); +* acpi_dp_add_child(dsd, "child", child); +* +* // Write entries into SSDT and clean up resources +* acpi_dp_write(dsd); +* +* Name(_DSD, Package() { +* ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") +* Package() { +* Package() { "gpio", Package() { \_SB.PCI0.GPIO, 0, 0, 0 } } +* Package() { "number1", 1 } +* } +* ToUUID("dbb8e3e6-5886-4ba6-8795-1319f52a966b") +* Package() { +* Package() { "child", CHLD } +* } +* } +* Name(CHLD, Package() { +* ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301") +* Package() { +* Package() { "childstring", "CHILD" } +* Package() { "childint", 100 } +* } +* } +* +* @type: Table type +* @name: Name of object, typically _DSD but could be CHLD for a child object +* @next: Next object in list (next array element or next sibling) +* @child: Pointer to first child, if @type == ACPI_DP_TYPE_CHILD, else NULL +* @array: First array element, if @type == ACPI_DP_TYPE_ARRAY, else NULL +* @integer: Integer value of the property, if @type == ACPI_DP_TYPE_INTEGER +* @string: String value of the property, if @type == ACPI_DP_TYPE_STRING; +* child name if @type == ACPI_DP_TYPE_CHILD; +* reference name if @type == ACPI_DP_TYPE_REFERENCE; +*/ +struct acpi_dp { +enum acpi_dp_type type; +const char *name; +struct acpi_dp *next; +union { +struct acpi_dp *child; +struct acpi_dp *array; + }; +union { +u64 integer; +const char *string; + }; +}; + +/** +* acpi_dp_new_table() - Start a new Device Property table +* +* @ref: ACPI reference (e.g. "_DSD") +* @return pointer to table, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_new_table (const char *ref); + +/** +* acpi_dp_add_integer() - Add integer Device Property +* +* A new node is added to the end of the property list of @dp +* +* @dp: Table to add this property to +* @name: Name of property +* @value: Integer value +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_integer (struct acpi_dp *dp,const char *name, +u64 value); + +/** +* acpi_dp_add_string() - Add string Device Property +* +* A new node is added to the end of the property list of @dp +* +* @dp: Table to add this property to +* @name: Name of property +* @string: String value +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_string (struct acpi_dp *dp,const char *name, +const char *string); + +/** +* acpi_dp_add_reference() - Add reference Device Property +* +* A new node is added to the end of the property list of @dp +* +* @dp: Table to add this property to +* @name: Name of property +* @reference: Reference value +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_reference (struct acpi_dp *dp,const char *name, +const char *reference); + +/** +* acpi_dp_add_array() - Add array Device Property +* +* A new node is added to the end of the property list of @dp, with the array +* attached to that. +* +* @dp: Table to add this property to +* @name: Name of property +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_array (struct acpi_dp *dp,struct acpi_dp *array); + +/** +* acpi_dp_add_integer_array() - Add an array of integers +* +* A new node is added to the end of the property list of @dp, with the array +* attached to that. Each element of the array becomes a new node. +* +* @dp: Table to add this property to +* @name: Name of property +* @return pointer to new array node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_integer_array (struct acpi_dp *dp,const char *name, +u64 *array,int len); + +/** +* acpi_dp_add_gpio() - Add a GPIO binding Device Property +* +* A new node is added to the end of the property list of @dp, with the +* GPIO properties added to the the new node +* +* @dp: Table to add this property to +* @name: Name of property +* @ref: Reference of the device that has _CRS containing GpioIO()/GpioInt() +* @index: Index of the GPIO resource in _CRS starting from zero +* @pin: Pin in the GPIO resource, typically zero +* @active_low: true if pin is active low +* @return pointer to new node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_gpio (struct acpi_dp *dp,const char *name, +const char *ref,int index,int pin, +bool active_low); + +/** +* acpi_dp_add_child() - Add a child table of Device Properties +* +* A new node is added as a child of @dp +* +* @dp: Table to add this child to +* @name: Name of child +* @child: Child node to add +* @return pointer to new array node, or NULL if out of memory +*/ +struct acpi_dp *acpi_dp_add_child (struct acpi_dp *dp,const char *name, +struct acpi_dp *child); + +/** +* acpi_dp_add_property_list() - Add a list of of Device Properties +* +* This adds a list of properties to @dp. Any properties without a name or of +* type ACPI_DP_TYPE_UNKNOWN are ignored. +* +* @dp: Table to add properties to +* @property_list: List of properties to add +* @property_count: Number of properties in the list +* @return number of properties added +*/ +size_t acpi_dp_add_property_list (struct acpi_dp *dp, +const struct acpi_dp *property_list, +size_t property_count); + +/** +* acpi_dp_write() - Write Device Property hierarchy and clean up resources +* +* This writes the table using acpigen and then frees it +* +* @table: Table to write +* @return 0 if OK, -ve on error +*/ +int acpi_dp_write (struct acpi_ctx *ctx,struct acpi_dp *table); + +/** +* acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including +* information ACPI needs to use it. +* +* This writes a serial bus descriptor for the I2C device so that ACPI can +*/ +int acpi_device_write_i2c_dev (struct acpi_ctx *ctx,const struct udevice *dev); + +/** +* struct acpi_i2c_priv - Information read from device tree +* +* This is used by devices which want to specify various pieces of ACPI +* information, including power control. It allows a generic function to +* generate the information for ACPI, based on device-tree properties. +* +* @disable_gpio_export_in_crs: Don't export GPIOs in the CRS +* @reset_gpio: GPIO used to assert reset to the device +* @enable_gpio: GPIO used to enable the device +* @stop_gpio: GPIO used to stop the device +* @irq_gpio: GPIO used for interrupt (if @irq is not used) +* @irq: IRQ used for interrupt (if @irq_gpio is not used) +* @hid: _HID value for device (required) +* @uid: _UID value for device +* @desc: _DDN value for device +* @wake: Wake event, e.g. GPE0_DW1_15; 0 if none +* @property_count: Number of other DSD properties (currently always 0) +* @probed: true set set 'linux,probed' property +* @compat_string: Device tree compatible string to report through ACPI +* @has_power_resource: true if this device has a power resource +* @reset_delay_ms: Delay after de-asserting reset, in ms +* @reset_off_delay_ms: Delay after asserting reset (during power off) +* @enable_delay_ms: Delay after asserting enable +* @enable_off_delay_ms: Delay after de-asserting enable (during power off) +* @stop_delay_ms: Delay after de-aserting stop +* @stop_off_delay_ms: Delay after asserting stop (during power off) +* @hid_desc_reg_offset: HID register offset (for Human Interface Devices) +*/ +struct acpi_i2c_priv { +bool disable_gpio_export_in_crs; +struct gpio_desc reset_gpio; +struct gpio_desc enable_gpio; +struct gpio_desc irq_gpio; +struct gpio_desc stop_gpio; +struct irq irq; +const char *hid; +u32 uid; +const char *desc; +u32 wake; +u32 property_count; +bool probed; +const char *compat_string; +bool has_power_resource; +u32 reset_delay_ms; +u32 reset_off_delay_ms; +u32 enable_delay_ms; +u32 enable_off_delay_ms; +u32 stop_delay_ms; +u32 stop_off_delay_ms; +u32 hid_desc_reg_offset; +}; + +/** +* I2C Human-Interface Devices configuration +* +* @hid_desc_reg_offset: HID register offset +*/ +struct dsm_i2c_hid_config { +u8 hid_desc_reg_offset; +}; + +/** +* acpi_device_write_gpio() - Write GpioIo() or GpioInt() descriptor +* +* @gpio: GPIO information to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_gpio (struct acpi_ctx *ctx,const struct acpi_gpio *gpio); + +/* +* acpi_device_add_power_res() - Add a basic PowerResource block for a device +* +* This includes GPIOs to control enable, reset and stop operation of the +* device. Each GPIO is optional, but at least one must be provided. +* +* Reset - Put the device into / take the device out of reset. +* Enable - Enable / disable power to device. +* Stop - Stop / start operation of device. +* +* @return 0 if OK, -ve if at least one GPIO is not provided +*/ +int acpi_device_add_power_res (struct acpi_ctx *ctx, +const struct acpi_power_res_params *params); + +/** +* gpio_get_acpi() - Convert a GPIO description into an ACPI GPIO +* +* At present this is fairly limited. It only supports ACPI_GPIO_TYPE_IO and +* has hard-coded settings for type, pull, IO restrict and polarity. These +* could come from pinctrl potentially. +* +* @desc: GPIO description to convert +* @gpio: Place to put ACPI GPIO information +* @return 0 if OK, -ENOENT if @desc is invalid +*/ +int gpio_get_acpi (const struct gpio_desc *desc,struct acpi_gpio *gpio); + +/** +* acpi_device_write_dsm_i2c_hid() - Write a device-specific method for HID +* +* This writes a DSM for an I2C Human-Interface Device based on the config +* provided +* +* @config: Config information to write +*/ +void acpi_device_write_dsm_i2c_hid (struct acpi_ctx *ctx, +struct dsm_i2c_hid_config *config); + +/** +* acpi_dp_ofnode_copy_int() - Copy a property from device tree to DP +* +* This copies an integer property from the device tree to the ACPI DP table. +* +* @dev: Device to copy from +* @dp: DP to copy to +* @prop: Property name to copy +* @return 0 if OK, -ve on error +*/ +int acpi_dp_ofnode_copy_int (ofnode node,struct acpi_dp *dp,const char *prop); + +/** +* acpi_dp_dev_copy_str() - Copy a property from device tree to DP +* +* This copies a string property from the device tree to the ACPI DP table. +* +* @dev: Device to copy from +* @dp: DP to copy to +* @prop: Property name to copy +* @return 0 if OK, -ve on error +*/ +int acpi_dp_ofnode_copy_str (ofnode node,struct acpi_dp *dp,const char *prop); + +/** +* acpi_dp_dev_copy_int() - Copy a property from device tree to DP +* +* This copies an integer property from the device tree to the ACPI DP table. +* +* @dev: Device to copy from +* @dp: DP to copy to +* @prop: Property name to copy +* @return 0 if OK, -ve on error +*/ +int acpi_dp_dev_copy_int (const struct udevice *dev,struct acpi_dp *dp, +const char *prop); + +/** +* acpi_dp_dev_copy_str() - Copy a property from device tree to DP +* +* This copies a string property from the device tree to the ACPI DP table. +* +* @dev: Device to copy from +* @dp: DP to copy to +* @prop: Property name to copy +* @return 0 if OK, -ve on error +*/ +int acpi_dp_dev_copy_str (const struct udevice *dev,struct acpi_dp *dp, +const char *prop); + +int acpi_device_get_name (const struct udevice *dev,char *out_name); + +#endif
lib/acpi/acpi_device.c new file +1094 -0
1,094 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 30/39 acpi: Add functions to generate ACPI code
In reply to Simon GlassSometimes we need to generate ACPI code on the fly based on things only known at run time. Add a new 'acpigen' library to handle this. This code comes from coreboot and has been modified to support the acpi_ctx struct.
Also add acpi_device.c to the build, since these files are co-dependent.
---
Changes in v2: None
include/acpigen.h | 482 +++++++++++++ include/dm/acpi.h | 7 + include/irq.h | 2 + lib/acpi/Makefile | 2 + lib/acpi/acpigen.c | 1683 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 2176 insertions(+) create mode 100644 include/acpigen.h create mode 100644 lib/acpi/acpigen.c
include/acpigen.h new file +482 -0
@@ -0,0 +1,482 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* +* Core ACPI (Advanced Configuration and Power Interface) support +* +* Copyright 2019 Google LLC +* +* Modified from coreboot file acpigen.h +*/ + +#ifndef _ACPIGEN_H +#define _ACPIGEN_H + +#include <acpi_table.h> + +struct acpi_cstate ; +struct acpi_pld ; +struct acpi_gpio ; +struct acpi_tstate ; + +/* Values that can be returned for ACPI Device _STA method */ +#define ACPI_STATUS_DEVICE_PRESENT BIT(0) +#define ACPI_STATUS_DEVICE_ENABLED BIT(1) +#define ACPI_STATUS_DEVICE_SHOW_IN_UI BIT(2) +#define ACPI_STATUS_DEVICE_STATE_OK BIT(3) + +#define ACPI_STATUS_DEVICE_ALL_OFF 0 +#define ACPI_STATUS_DEVICE_ALL_ON (ACPI_STATUS_DEVICE_PRESENT |\ + ACPI_STATUS_DEVICE_ENABLED |\ + ACPI_STATUS_DEVICE_SHOW_IN_UI |\ + ACPI_STATUS_DEVICE_STATE_OK) +#define ACPI_STATUS_DEVICE_HIDDEN_ON (ACPI_STATUS_DEVICE_PRESENT |\ + ACPI_STATUS_DEVICE_ENABLED |\ + ACPI_STATUS_DEVICE_STATE_OK) + +/* ACPI Op/Prefix Codes */ +enum { +ZERO_OP =0x00 , +ONE_OP =0x01 , +ALIAS_OP =0x06 , +NAME_OP =0x08 , +BYTE_PREFIX =0x0A , +WORD_PREFIX =0x0B , +DWORD_PREFIX =0x0C , +STRING_PREFIX =0x0D , +QWORD_PREFIX =0x0E , +SCOPE_OP =0x10 , +BUFFER_OP =0x11 , +PACKAGE_OP =0x12 , +VARIABLE_PACKAGE_OP =0x13 , +METHOD_OP =0x14 , +EXTERNAL_OP =0x15 , +DUAL_NAME_PREFIX =0x2E , +MULTI_NAME_PREFIX =0x2F , +EXT_OP_PREFIX =0x5B , + +MUTEX_OP =0x01 , +EVENT_OP =0x01 , +SF_RIGHT_OP =0x10 , +SF_LEFT_OP =0x11 , +COND_REFOF_OP =0x12 , +CREATEFIELD_OP =0x13 , +LOAD_TABLE_OP =0x1f , +LOAD_OP =0x20 , +STALL_OP =0x21 , +SLEEP_OP =0x22 , +ACQUIRE_OP =0x23 , +SIGNAL_OP =0x24 , +WAIT_OP =0x25 , +RST_OP =0x26 , +RELEASE_OP =0x27 , +FROM_BCD_OP =0x28 , +TO_BCD_OP =0x29 , +UNLOAD_OP =0x2A , +REVISON_OP =0x30 , +DEBUG_OP =0x31 , +FATAL_OP =0x32 , +TIMER_OP =0x33 , +OPREGION_OP =0x80 , +FIELD_OP =0x81 , +DEVICE_OP =0x82 , +PROCESSOR_OP =0x83 , +POWER_RES_OP =0x84 , +THERMAL_ZONE_OP =0x85 , +INDEX_FIELD_OP =0x86 , +BANK_FIELD_OP =0x87 , +DATA_REGION_OP =0x88 , + +ROOT_PREFIX =0x5C , +PARENT_PREFIX =0x5D , +LOCAL0_OP =0x60 , +LOCAL1_OP =0x61 , +LOCAL2_OP =0x62 , +LOCAL3_OP =0x63 , +LOCAL4_OP =0x64 , +LOCAL5_OP =0x65 , +LOCAL6_OP =0x66 , +LOCAL7_OP =0x67 , +ARG0_OP =0x68 , +ARG1_OP =0x69 , +ARG2_OP =0x6A , +ARG3_OP =0x6B , +ARG4_OP =0x6C , +ARG5_OP =0x6D , +ARG6_OP =0x6E , +STORE_OP =0x70 , +REF_OF_OP =0x71 , +ADD_OP =0x72 , +CONCATENATE_OP =0x73 , +SUBTRACT_OP =0x74 , +INCREMENT_OP =0x75 , +DECREMENT_OP =0x76 , +MULTIPLY_OP =0x77 , +DIVIDE_OP =0x78 , +SHIFT_LEFT_OP =0x79 , +SHIFT_RIGHT_OP =0x7A , +AND_OP =0x7B , +NAND_OP =0x7C , +OR_OP =0x7D , +NOR_OP =0x7E , +XOR_OP =0x7F , +NOT_OP =0x80 , +FD_SHIFT_LEFT_BIT_OR =0x81 , +FD_SHIFT_RIGHT_BIT_OR =0x82 , +DEREF_OP =0x83 , +CONCATENATE_TEMP_OP =0x84 , +MOD_OP =0x85 , +NOTIFY_OP =0x86 , +SIZEOF_OP =0x87 , +INDEX_OP =0x88 , +MATCH_OP =0x89 , +CREATE_DWORD_OP =0x8A , +CREATE_WORD_OP =0x8B , +CREATE_BYTE_OP =0x8C , +CREATE_BIT_OP =0x8D , +OBJ_TYPE_OP =0x8E , +CREATE_QWORD_OP =0x8F , +LAND_OP =0x90 , +LOR_OP =0x91 , +LNOT_OP =0x92 , +LEQUAL_OP =0x93 , +LGREATER_OP =0x94 , +LLESS_OP =0x95 , +TO_BUFFER_OP =0x96 , +TO_DEC_STRING_OP =0x97 , +TO_HEX_STRING_OP =0x98 , +TO_INTEGER_OP =0x99 , +TO_STRING_OP =0x9C , +CP_OBJ_OP =0x9D , +MID_OP =0x9E , +CONTINUE_OP =0x9F , +IF_OP =0xA0 , +ELSE_OP =0xA1 , +WHILE_OP =0xA2 , +NOOP_OP =0xA3 , +RETURN_OP =0xA4 , +BREAK_OP =0xA5 , +COMMENT_OP =0xA9 , +BREAKPIONT_OP =0xCC , +ONES_OP =0xFF , +}; + +#define FIELDLIST_OFFSET (_bits) { .type = OFFSET, \ + .name = "", \ + .bits = _bits * 8, \ + } +#define FIELDLIST_NAMESTR (_name, _bits) { .type = NAME_STRING, \ + .name = _name, \ + .bits = _bits, \ + } + +#define FIELD_ANYACC 0 +#define FIELD_BYTEACC 1 +#define FIELD_WORDACC 2 +#define FIELD_DWORDACC 3 +#define FIELD_QWORDACC 4 +#define FIELD_BUFFERACC 5 +#define FIELD_NOLOCK (0 << 4) +#define FIELD_LOCK (1 << 4) +#define FIELD_PRESERVE (0 << 5) +#define FIELD_WRITEASONES (1 << 5) +#define FIELD_WRITEASZEROS (2 << 5) + +enum field_type { +OFFSET , +NAME_STRING , +FIELD_TYPE_MAX , +}; + +struct fieldlist { +enum field_type type; +const char *name; +u32 bits; +}; + +#define OPREGION (rname, space, offset, len) {.name = rname, \ + .regionspace = space, \ + .regionoffset = offset, \ + .regionlen = len, \ + } + +enum region_space { +SYSTEMMEMORY , +SYSTEMIO , +PCI_CONFIG , +EMBEDDEDCONTROL , +SMBUS , +CMOS , +PCIBARTARGET , +IPMI , +GPIO_REGION , +GPSERIALBUS , +PCC , +FIXED_HARDWARE =0x7F , +REGION_SPACE_MAX , +}; + +struct opregion { +const char *name; +enum region_space regionspace; +unsigned long regionoffset; +unsigned long regionlen; +}; + +#define DSM_UUID (DSM_UUID ,DSM_CALLBACKS ,DSM_COUNT ,DSM_ARG ) \ + { .uuid = DSM_UUID, \ + .callbacks = DSM_CALLBACKS, \ + .count = DSM_COUNT, \ + .arg = DSM_ARG, \ + } + +typedef void (*hid_callback_func )(struct acpi_ctx *ctx,void *arg); + +struct dsm_uuid { +const char *uuid; +hid_callback_func *callbacks; +size_t count; +void *arg; +}; + +/* version 1 has 15 fields, version 2 has 19, and version 3 has 21 */ +enum cppc_fields { +CPPC_HIGHEST_PERF ,/* can be DWORD */ +CPPC_NOMINAL_PERF ,/* can be DWORD */ +CPPC_LOWEST_NONL_PERF ,/* can be DWORD */ +CPPC_LOWEST_PERF ,/* can be DWORD */ +CPPC_GUARANTEED_PERF , +CPPC_DESIRED_PERF , +CPPC_MIN_PERF , +CPPC_MAX_PERF , +CPPC_PERF_REDUCE_TOLERANCE , +CPPC_TIME_WINDOW , +CPPC_COUNTER_WRAP ,/* can be DWORD */ +CPPC_REF_PERF_COUNTER , +CPPC_DELIVERED_PERF_COUNTER , +CPPC_PERF_LIMITED , +CPPC_ENABLE ,/* can be System I/O */ +CPPC_MAX_FIELDS_VER_1 , +CPPC_AUTO_SELECT =/* can be DWORD */ +CPPC_MAX_FIELDS_VER_1 , +CPPC_AUTO_ACTIVITY_WINDOW , +CPPC_PERF_PREF , +CPPC_REF_PERF ,/* can be DWORD */ +CPPC_MAX_FIELDS_VER_2 , +CPPC_LOWEST_FREQ =/* can be DWORD */ +CPPC_MAX_FIELDS_VER_2 , +CPPC_NOMINAL_FREQ ,/* can be DWORD */ +CPPC_MAX_FIELDS_VER_3 , +}; + +struct cppc_config { +u32 version;/* must be 1, 2, or 3 */ +/* +* The generic struct acpi_gen_regaddr structure is being used, though +* anything besides PPC or FFIXED generally requires checking +* if the OS has advertised support for it (via _OSC). +* +* NOTE: some fields permit DWORDs to be used. If you +* provide a System Memory register with all zeros (which +* represents unsupported) then this will be used as-is. +* Otherwise, a System Memory register with a 32-bit +* width will be converted into a DWORD field (the value +* of which will be the value of 'addrl'. Any other use +* of System Memory register is currently undefined. +* (i.e., if you have an actual need for System Memory +* then you'll need to adjust this kludge). +*/ +struct acpi_gen_regaddr regs[CPPC_MAX_FIELDS_VER_3 ]; +}; + +void acpigen_write_return_integer (struct acpi_ctx *ctx,u64 arg); +void acpigen_write_return_string (struct acpi_ctx *ctx,const char *arg); +void acpigen_write_len_f (struct acpi_ctx *ctx); +void acpigen_pop_len (struct acpi_ctx *ctx); +void acpigen_set_current (struct acpi_ctx *ctx,char *curr); +char *acpigen_get_current (struct acpi_ctx *ctx); +char *acpigen_write_package (struct acpi_ctx *ctx,int nr_el); +void acpigen_write_zero (struct acpi_ctx *ctx); +void acpigen_write_one (struct acpi_ctx *ctx); +void acpigen_write_ones (struct acpi_ctx *ctx); +void acpigen_write_byte (struct acpi_ctx *ctx,unsigned int data); +void acpigen_emit_byte (struct acpi_ctx *ctx,unsigned char data); +void acpigen_emit_ext_op (struct acpi_ctx *ctx,u8 op); +void acpigen_emit_word (struct acpi_ctx *ctx,unsigned int data); +void acpigen_emit_dword (struct acpi_ctx *ctx,unsigned int data); +void acpigen_emit_stream (struct acpi_ctx *ctx,const char *data,int size); +void acpigen_emit_string (struct acpi_ctx *ctx,const char *string); +void acpigen_emit_namestring (struct acpi_ctx *ctx,const char *namepath); +void acpigen_emit_eisaid (struct acpi_ctx *ctx,const char *eisaid); +void acpigen_write_word (struct acpi_ctx *ctx,unsigned int data); +void acpigen_write_dword (struct acpi_ctx *ctx,unsigned int data); +void acpigen_write_qword (struct acpi_ctx *ctx,u64 data); +void acpigen_write_integer (struct acpi_ctx *ctx,u64 data); +void acpigen_write_string (struct acpi_ctx *ctx,const char *string); +void acpigen_write_coreboot_hid (struct acpi_ctx *ctx, +enum coreboot_acpi_ids id); +void acpigen_write_name (struct acpi_ctx *ctx,const char *name); +void acpigen_write_name_zero (struct acpi_ctx *ctx,const char *name); +void acpigen_write_name_one (struct acpi_ctx *ctx,const char *name); +void acpigen_write_name_string (struct acpi_ctx *ctx,const char *name, +const char *string); +void acpigen_write_name_dword (struct acpi_ctx *ctx,const char *name,u32 val); +void acpigen_write_name_qword (struct acpi_ctx *ctx,const char *name,u64 val); +void acpigen_write_name_byte (struct acpi_ctx *ctx,const char *name,u8 val); +void acpigen_write_name_integer (struct acpi_ctx *ctx,const char *name, +u64 val); +void acpigen_write_scope (struct acpi_ctx *ctx,const char *name); +void acpigen_write_method (struct acpi_ctx *ctx,const char *name,int nargs); +void acpigen_write_method_serialized (struct acpi_ctx *ctx,const char *name, +int nargs); +void acpigen_write_device (struct acpi_ctx *ctx,const char *name); +void acpigen_write_ppc (struct acpi_ctx *ctx,u8 nr); +void acpigen_write_ppc_nvs (struct acpi_ctx *ctx); +void acpigen_write_empty_pct (struct acpi_ctx *ctx); +void acpigen_write_empty_ptc (struct acpi_ctx *ctx); +void acpigen_write_prw (struct acpi_ctx *ctx,u32 wake,u32 level); +void acpigen_write_sta (struct acpi_ctx *ctx,u8 status); +void acpigen_write_tpc (struct acpi_ctx *ctx,const char *gnvs_tpc_limit); +void acpigen_write_pss_package (struct acpi_ctx *ctx,u32 corefreq,u32 power, +u32 translat, +u32 busmlat,u32 control,u32 status); +enum psd_coord { +SW_ALL =0xfc , +SW_ANY =0xfd , +HW_ALL =0xfe +}; + +void acpigen_write_psd_package (struct acpi_ctx *ctx,u32 domain,u32 numprocs, +enum psd_coord coordtype); +void acpigen_write_cst_package_entry (struct acpi_ctx *ctx, +struct acpi_cstate *cstate); +void acpigen_write_cst_package (struct acpi_ctx *ctx,struct acpi_cstate *entry, +int nentries); + +enum csd_coord { +CSD_HW_ALL =0xfe , +}; + +void acpigen_write_CSD_package (struct acpi_ctx *ctx,u32 domain,u32 numprocs, +enum csd_coord coordtype,u32 index); +void acpigen_write_processor (struct acpi_ctx *ctx,u8 cpuindex,u32 pblock_addr, +u8 pblock_len); +void acpigen_write_processor_package (struct acpi_ctx *ctx,const char *name, +uint first_core,uint core_count); +void acpigen_write_processor_cnot (struct acpi_ctx *ctx,const uint num_cores); +void acpigen_write_tss_package (struct acpi_ctx *ctx,int entries, +struct acpi_tstate *tstate_list); +void acpigen_write_tsd_package (struct acpi_ctx *ctx,u32 domain,u32 numprocs, +enum psd_coord coordtype); +void acpigen_write_mem32fixed (struct acpi_ctx *ctx,int readwrite,u32 base, +u32 size); +void acpigen_write_register_resource (struct acpi_ctx *ctx, +const struct acpi_gen_regaddr *addr); +void acpigen_write_irq (struct acpi_ctx *ctx,u16 mask); +void acpigen_write_resourcetemplate_header (struct acpi_ctx *ctx); +void acpigen_write_resourcetemplate_footer (struct acpi_ctx *ctx); +int acpigen_write_uuid (struct acpi_ctx *ctx,const char *uuid); +void acpigen_write_power_res (struct acpi_ctx *ctx,const char *name,u8 level, +u16 order,const char *const dev_states[], +size_t dev_states_count); +void acpigen_write_sleep (struct acpi_ctx *ctx,u64 sleep_ms); +void acpigen_write_store (struct acpi_ctx *ctx); +void acpigen_write_store_ops (struct acpi_ctx *ctx,u8 src,u8 dst); +void acpigen_write_or (struct acpi_ctx *ctx,u8 arg1,u8 arg2,u8 res); +void acpigen_write_and (struct acpi_ctx *ctx,u8 arg1,u8 arg2,u8 res); +void acpigen_write_not (struct acpi_ctx *ctx,u8 arg,u8 res); +void acpigen_write_debug_string (struct acpi_ctx *ctx,const char *str); +void acpigen_write_debug_integer (struct acpi_ctx *ctx,u64 val); +void acpigen_write_debug_op (struct acpi_ctx *ctx,u8 op); +void acpigen_write_if (struct acpi_ctx *ctx); +void acpigen_write_if_and (struct acpi_ctx *ctx,u8 arg1,u8 arg2); +void acpigen_write_if_lequal_op_int (struct acpi_ctx *ctx,u8 op,u64 val); +void acpigen_write_else (struct acpi_ctx *ctx); +void acpigen_write_to_buffer (struct acpi_ctx *ctx,u8 src,u8 dst); +void acpigen_write_to_integer (struct acpi_ctx *ctx,u8 src,u8 dst); +void acpigen_write_byte_buffer (struct acpi_ctx *ctx,u8 *arr,size_t size); +void acpigen_write_return_byte_buffer (struct acpi_ctx *ctx,u8 *arr, +size_t size); +void acpigen_write_return_singleton_buffer (struct acpi_ctx *ctx,u8 arg); +void acpigen_write_return_byte (struct acpi_ctx *ctx,u8 arg); +void acpigen_write_upc (struct acpi_ctx *ctx,enum acpi_upc_type type); + +/* +* Generate ACPI AML code for _DSM method. +* This function takes as input uuid for the device, set of callbacks and +* argument to pass into the callbacks. Callbacks should ensure that Local0 and +* Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks. +*/ +int acpigen_write_dsm (struct acpi_ctx *ctx,const char *uuid, +hid_callback_func callbacks[],size_t count,void *arg); +int acpigen_write_dsm_uuid_arr (struct acpi_ctx *ctx,struct dsm_uuid *ids, +size_t count); + +/* +* Generate ACPI AML code for _CPC (struct acpi_ctx *ctx, Continuous Perfmance +* Control). Execute the package function once to create a global table, then +* execute the method function within each processor object to +* create a method that points to the global table. +*/ +int acpigen_write_cppc_package (struct acpi_ctx *ctx, +const struct cppc_config *config); +void acpigen_write_cppc_method (struct acpi_ctx *ctx); + +/* +* Generate ACPI AML code for _ROM method. +* This function takes as input ROM data and ROM length. +* The ROM length has to be multiple of 4096 and has to be less +* than the current implementation limit of 0x40000. +*/ +int acpigen_write_rom (struct acpi_ctx *ctx,void *bios,const size_t length); +/* +* Generate ACPI AML code for OperationRegion +* This function takes input region name, region space, region offset & region +* length. +*/ +void acpigen_write_opregion (struct acpi_ctx *ctx,struct opregion *opreg); +/* +* Generate ACPI AML code for Field +* This function takes input region name, fieldlist, count & flags. +*/ +int acpigen_write_field (struct acpi_ctx *ctx,const char *name, +struct fieldlist *l,size_t count,uint flags); +/* +* Generate ACPI AML code for IndexField +* This function takes input index name, data name, fieldlist, count & flags. +*/ +int acpigen_write_indexfield (struct acpi_ctx *ctx,const char *idx, +const char *data,struct fieldlist *l, +size_t count,uint flags); + +/* +* Soc-implemented functions for generating ACPI AML code for GPIO handling. All +* these functions are expected to use only Local5, Local6 and Local7 +* variables. If the functions call into another ACPI method, then there is no +* restriction on the use of Local variables. In case of get/read functions, +* return value is expected to be stored in Local0 variable. +* +* All functions return 0 on success and -1 on error. +*/ + +/* Generate ACPI AML code to return Rx value of GPIO in Local0. */ +int acpigen_soc_read_rx_gpio (struct acpi_ctx *ctx,uint gpio_num); + +/* Generate ACPI AML code to return Tx value of GPIO in Local0. */ +int acpigen_soc_get_tx_gpio (struct acpi_ctx *ctx,uint gpio_num); + +/* Generate ACPI AML code to set Tx value of GPIO to 1. */ +int acpigen_soc_set_tx_gpio (struct acpi_ctx *ctx,uint gpio_num); + +/* Generate ACPI AML code to set Tx value of GPIO to 0. */ +int acpigen_soc_clear_tx_gpio (struct acpi_ctx *ctx,uint gpio_num); + +/* +* Helper functions for enabling/disabling Tx GPIOs based on the GPIO +* polarity. These functions end up calling acpigen_soc_{set,clear}_tx_gpio to +* make callbacks into SoC acpigen code. +* +* Returns 0 on success and -1 on error. +*/ +int acpigen_enable_tx_gpio (struct acpi_ctx *ctx,struct acpi_gpio *gpio); +int acpigen_disable_tx_gpio (struct acpi_ctx *ctx,struct acpi_gpio *gpio); + +#endif
include/dm/acpi.h +7 -0
@@ -22,6 +22,9 @@/* Length of an ACPI name string including nul terminator */ #define ACPI_NAME_MAX 5 +/* Number of nested objects supported */ +#define ACPIGEN_LENSTACK_SIZE 10 +#if !defined(__ACPI__)/**
@@ -34,12 +37,16 @@* adding a new table. The RSDP holds pointers to the RSDP and XSDT. * @rsdt: Pointer to the Root System Description Table * @xsdt: Pointer to the Extended System Description Table +* @len_stack: Stack of 'length' words to fix up later +* @ltop: Points to current top of stack (0 = empty) */ struct acpi_ctx {void *current;struct acpi_rsdp *rsdp;struct acpi_rsdt *rsdt;struct acpi_xsdt *xsdt; +char *len_stack[ACPIGEN_LENSTACK_SIZE ]; +int ltop; };/**
include/irq.h +2 -0
@@ -8,6 +8,8 @@#ifndef __irq_H#define __irq_H +struct ofnode_phandle_args ; +/* * Interrupt controller types available. You can find a particular one with * irq_first_device_type()
lib/acpi/Makefile +2 -0
@@ -1,4 +1,6 @@ # SPDX-License-Identifier: GPL-2.0+ # +obj-y += acpigen.o +obj-y += acpi_device.o obj-y += acpi_table.o
lib/acpi/acpigen.c new file +1683 -0
1,683 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 30/39] acpi: Add functions to generate ACPI code
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 12 lines
Sometimes we need to generate ACPI code on the fly based on things only known at run time. Add a new 'acpigen' library to handle this. This code comes from coreboot and has been modified to support the
acpi_ctxstruct.Also add
acpi_device.cto the build, since these files are co-dependent.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 8 lines
include/acpigen.h | 482 +++++++++++++ include/dm/acpi.h | 7 + include/irq.h | 2 + lib/acpi/Makefile | 2 + lib/acpi/acpigen.c | 1683 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 2176 insertions(+) create mode 100644 include/acpigen.h create mode 100644 lib/acpi/acpigen.c
What coreboot version is this based on?
I have compared it to the current master in coreboot and there are some differences (ignoring the changes for acpi_ctx support).
regards, Wolfgang
PATCH v2 30/39 acpi: Add functions to generate ACPI code
Hi Wolfgang,
Quoted 25 lines · Wolfgang Wallner
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 12 lines
Sometimes we need to generate ACPI code on the fly based on things only known at run time. Add a new 'acpigen' library to handle this. This code comes from coreboot and has been modified to support the
acpi_ctxstruct.Also add
acpi_device.cto the build, since these files are co-dependent.Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
Quoted 8 lines
include/acpigen.h | 482 +++++++++++++ include/dm/acpi.h | 7 + include/irq.h | 2 + lib/acpi/Makefile | 2 + lib/acpi/acpigen.c | 1683 ++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 2176 insertions(+) create mode 100644 include/acpigen.h create mode 100644 lib/acpi/acpigen.c
Quoted 3 lines
What coreboot version is this based on?
I have compared it to the current master in coreboot and there are some differences (ignoring the changes foracpi_ctxsupport).
I don't think coreboot does releases very often. The commit is efa3084d63.
Regards,
Simon
PATCH v2 31/39 gpio: Add a method to convert a GPIO to ACPI
In reply to Simon GlassWhen generating ACPI tables we need to convert GPIOs in U-Boot to the ACPI structures required by ACPI. This is a SoC-specific conversion and cannot be handled by generic code, so add a new GPIO method to do the conversion.
---
Changes in v2: None
drivers/gpio/gpio-uclass.c | 21 +++++++++++++++++++++ include/acpi_device.h | 12 ++++++++++++ include/asm-generic/gpio.h | 27 +++++++++++++++++++++++++++ lib/acpi/acpi_device.c | 16 ++++++++++++++++ 4 files changed, 76 insertions(+)
drivers/gpio/gpio-uclass.c +21 -0
@@ -4,6 +4,7 @@*/ #include <common.h> +#include <acpi_device.h> #include <dm.h> #include <dm/device-internal.h> #include <dm/lists.h>
@@ -697,6 +698,26 @@ int gpio_get_status(struct udevice *dev, int offset, char *buf, int buffsize)return 0 ; } +#if CONFIG_IS_ENABLED (ACPIGEN ) +int gpio_get_acpi (const struct gpio_desc *desc,struct acpi_gpio *gpio) +{ +struct dm_gpio_ops *ops; + +if (!dm_gpio_is_valid (desc)) { +/* Indicate that the GPIO is not valid */ + gpio->pin_count =0 ; + gpio->pins[0 ] =0 ; +return -EINVAL ; + } + + ops =gpio_get_ops (desc->dev); +if (!ops->get_acpi) +return -ENOSYS ; + +return ops->get_acpi (desc, gpio); +} +#endif +int gpio_claim_vector (const int *gpio_num_array,const char *fmt) {int i, ret;
include/acpi_device.h +12 -0
@@ -533,6 +533,18 @@ size_t acpi_dp_add_property_list(struct acpi_dp *dp,*/ int acpi_dp_write (struct acpi_ctx *ctx,struct acpi_dp *table); +/** +* acpi_device_write_gpio_desc() - Write a GPIO to ACPI +* +* This creates a GPIO descriptor for a GPIO, including information ACPI needs +* to use it. The type is always ACPI_GPIO_TYPE_IO. +* +* @desc: GPIO to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_gpio_desc (struct acpi_ctx *ctx, +const struct gpio_desc *desc); +/** * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including * information ACPI needs to use it.
include/asm-generic/gpio.h +27 -0
@@ -9,6 +9,7 @@#include <dm/ofnode.h> +struct acpi_gpio ;struct ofnode_phandle_args ;/*
@@ -290,6 +291,20 @@ struct dm_gpio_ops {*/ int (*xlate)(struct udevice *dev,struct gpio_desc *desc,struct ofnode_phandle_args *args); + +#if CONFIG_IS_ENABLED (ACPIGEN ) +/** +* get_acpi() - Get the ACPI info for a GPIO +* +* This converts a GPIO to an ACPI structure for adding to the ACPI +* tables. +* +* @desc: GPIO description to convert +* @gpio: Output ACPI GPIO information +* @return ACPI pin number or -ve on error +*/ +int (*get_acpi)(const struct gpio_desc *desc,struct acpi_gpio *gpio); +#endif };/**
@@ -657,4 +672,16 @@ int dm_gpio_set_dir_flags(struct gpio_desc *desc, ulong flags);*/ int gpio_get_number (const struct gpio_desc *desc); +/** +* gpio_get_acpi() - Get the ACPI pin for a GPIO +* +* This converts a GPIO to an ACPI pin number for adding to the ACPI +* tables. If the GPIO is invalid, the pin_count and pins[0] are set to 0 +* +* @desc: GPIO description to convert +* @gpio: Output ACPI GPIO information +* @return ACPI pin number or -ve on error +*/ +int gpio_get_acpi (const struct gpio_desc *desc,struct acpi_gpio *gpio); +#endif /* _ASM_GENERIC_GPIO_H_ */
lib/acpi/acpi_device.c +16 -0
@@ -288,6 +288,22 @@ int acpi_device_write_gpio(struct acpi_ctx *ctx, const struct acpi_gpio *gpio)return 0 ; } +int acpi_device_write_gpio_desc (struct acpi_ctx *ctx, +const struct gpio_desc *desc) +{ +struct acpi_gpio gpio; +int ret; + + ret =gpio_get_acpi (desc, &gpio); +if (ret) +return log_msg_ret ("desc" , ret); + ret =acpi_device_write_gpio (ctx, &gpio); +if (ret) +return log_msg_ret ("gpio" , ret); + +return 0 ; +} +/* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */ static void acpi_device_write_i2c (struct acpi_ctx *ctx,const struct acpi_i2c *i2c)
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 31/39] gpio: Add a method to convert a GPIO to ACPI
Hi Simon,
-----"Simon Glass" <[email protected]> schrieb: -----
Quoted 8 lines
When generating ACPI tables we need to convert GPIOs in U-Boot to the ACPI structures required by ACPI. This is a SoC-specific conversion and cannot be handled by generic code, so add a new GPIO method to do the conversion.
Signed-off-by Simon Glass <[email protected]>---
Quoted 7 lines
Changes in v2: None
drivers/gpio/gpio-uclass.c | 21 +++++++++++++++++++++ include/acpi_device.h | 12 ++++++++++++ include/asm-generic/gpio.h | 27 +++++++++++++++++++++++++++ lib/acpi/acpi_device.c | 16 ++++++++++++++++ 4 files changed, 76 insertions(+)
PATCH v2 32/39 irq: Add a method to convert an interrupt to ACPI
In reply to Simon GlassWhen generating ACPI tables we need to convert IRQs in U-Boot to the ACPI structures required by ACPI. This is a SoC-specific conversion and cannot be handled by generic code, so add a new IRQ method to do the conversion.
---
Changes in v2: None
drivers/misc/irq-uclass.c | 18 +++++++- include/acpi_device.h | 27 +++++++++++ include/irq.h | 41 +++++++++++++++++ lib/acpi/acpi_device.c | 94 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 2 deletions(-)
drivers/misc/irq-uclass.c +16 -2
@@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq *irq)const struct irq_ops *ops;log_debug ("(dev=%p, irq=%p)\n" , dev, irq); -if (!irq) -return 0 ; ops =irq_get_ops (dev); irq->dev = dev;
@@ -176,6 +174,22 @@ int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)return 0 ; } +#if CONFIG_IS_ENABLED (ACPIGEN ) +int irq_get_acpi (const struct irq *irq,struct acpi_irq *acpi_irq) +{ +struct irq_ops *ops; + +if (!irq_is_valid (irq)) +return -EINVAL ; + + ops =irq_get_ops (irq->dev); +if (!ops->get_acpi) +return -ENOSYS ; + +return ops->get_acpi (irq, acpi_irq); +} +#endif +UCLASS_DRIVER (irq) = { .id =UCLASS_IRQ , .name ="irq" ,
include/acpi_device.h +27 -0
@@ -545,6 +545,33 @@ int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp *table);int acpi_device_write_gpio_desc (struct acpi_ctx *ctx,const struct gpio_desc *desc); +/** +* acpi_device_write_interrupt_irq() - Write an interrupt to ACPI +* +* This creates an interrupt descriptor for an interrupt, including information +* ACPI needs to use it. +* +* @req_irq: Interrupt to write +* @return 0 if OK, -ve on error +*/ +int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx, +const struct irq *req_irq); + +/** +* acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to ACPI +* +* This reads the an interrupt from the device tree, if available. If not it +* reads the first GPIO with the name @prop. +* +* If an interrupt is found, that is written to ACPI. If not, but an GPIO is +* found, that is written. +* +* @return 0 if OK, -ve if neither an interrupt nor a GPIO could be found, or +* some other error occurred +*/ +int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop); +/** * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including * information ACPI needs to use it.
include/irq.h +41 -0
71 lines not on this page · raw message
lib/acpi/acpi_device.c +94 -0
106 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 32/39] irq: Add a method to convert an interrupt to ACPI
Hi Simon,
"Simon Glass" <[email protected]> schrieb am 09.03.2020 04:44:56:
Quoted 7 lines
Von: "Simon Glass" <[email protected]>
An: "U-Boot Mailing List" <[email protected]>,
Kopie: "Bin Meng" <[email protected]>, "Wolfgang Wallner" <[email protected]>, "Andy Shevchenko" <[email protected]>, "Simon Glass" <[email protected]>
Datum: 09.03.2020 04:46
Betreff: [PATCH v2 32/39] irq: Add a method to convert an interrupt to
ACPI
Quoted 2 lines
When generating ACPI tables we need to convert IRQs in U-Boot to the
ACPI
Quoted 1 line
structures required by ACPI. This is a SoC-specific conversion and
cannot
Quoted 1 line
be handled by generic code, so add a new IRQ method to do the
conversion.
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq
Quoted 17 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
drivers/misc/irq-uclass.c | 18 +++++++- include/acpi_device.h | 27 +++++++++++ include/irq.h | 41 +++++++++++++++++ lib/acpi/acpi_device.c | 94 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 2 deletions(-)drivers/misc/irq-uclass.c +0
-0@@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq
*irq)
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq *irq) · line 157
Quoted 5 lines
drivers/misc/irq-uclass.c +0
-2const struct irq_ops *ops;log_debug ("(dev=%p, irq=%p)\n" , dev, irq); -if (!irq) -return 0 ;
Why is this code dropped?
Quoted 46 lines
drivers/misc/irq-uclass.c +16
-0ops =irq_get_ops (dev); irq->dev = dev;@@ -176,6 +174,22 @@ int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)return 0 ; } +#if CONFIG_IS_ENABLED (ACPIGEN ) +int irq_get_acpi (const struct irq *irq,struct acpi_irq *acpi_irq) +{ +struct irq_ops *ops; + +if (!irq_is_valid (irq)) +return -EINVAL ; + + ops =irq_get_ops (irq->dev); +if (!ops->get_acpi) +return -ENOSYS ; + +return ops->get_acpi (irq, acpi_irq); +} +#endif +UCLASS_DRIVER (irq) = { .id =UCLASS_IRQ ,.name = "irq",include/acpi_device.h +4
-0@@ -545,6 +545,33 @@ int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp *table);int acpi_device_write_gpio_desc (struct acpi_ctx *ctx,const struct gpio_desc *desc); +/** +* acpi_device_write_interrupt_irq() - Write an interrupt to ACPI +* +* This creates an interrupt descriptor for an interrupt, including information
+ * ACPI needs to use it.
+ *
+ * @req_irq: Interrupt to write
+ * @return 0 if OK, -ve on error
+ */
include/acpi_device.h int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp *table);
Quoted 5 lines
include/acpi_device.h +5
-0+int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx, +const struct irq *req_irq); + +/** +* acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to
ACPI
Quoted 2 lines
+ *
+ * This reads the an interrupt from the device tree, if available. If
not it
typo: "the an"
The description of what this function should do is rather vague. At least I'm not sure how it is meant to work.
Quoted 3 lines
+ * reads the first GPIO with the name @prop.
+ *
+ * If an interrupt is found, that is written to ACPI. If not, but an
GPIO is
Quoted 3 lines
+ * found, that is written.
+ *
+ * @return 0 if OK, -ve if neither an interrupt nor a GPIO could
befound, or
lib/acpi/acpi_device.c int acpi_device_write_gpio_desc(struct acpi_ctx
Quoted 152 lines
+ * some other error occurred
+ */include/acpi_device.h +3
-0+int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop); +/** * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including * information ACPI needs to use it. include/irq.h +41
-0@@ -8,6 +8,7 @@#ifndef __irq_H#define __irq_H +struct acpi_irq ;struct ofnode_phandle_args ;/* @@ -26,10 +27,12 @@ enum irq_dev_t {* * @dev: IRQ device that handles this irq * @id: ID to identify this irq with the device +* @flags: Flags associated with this interrupt (IRQ_TYPE_...) */ struct irq {struct udevice *dev;ulong id; +ulong flags; };/** @@ -121,10 +124,36 @@ struct irq_ops {* @return 0 if OK, or a negative error code. */ int (*free)(struct irq *irq); + +#if CONFIG_IS_ENABLED (ACPIGEN ) +/** +* get_acpi() - Get the ACPI info for an irq +* +* This converts a irq to an ACPI structure for adding to the ACPI +* tables. +* +* @irq: irq to convert +* @acpi_irq: Output ACPI interrupt information +* @return ACPI pin number or -ve on error +*/ +int (*get_acpi)(const struct irq *irq,struct acpi_irq *acpi_irq); +#endif };#define irq_get_ops (dev) ((struct irq_ops *)(dev)->driver->ops) +/** +* irq_is_valid() - Check if an IRQ is valid +* +* @irq: IRQ description containing device and ID, e.g. previously +* returned by irq_get_by_index() +* @return true if valid, false if not +*/ +static inline bool irq_is_valid (const struct irq *irq) +{ +return irq->dev !=NULL ; +} +/** * irq_route_pmc_gpio_gpe() - Get the GPIO for an event * @@ -225,4 +254,16 @@ int irq_free(struct irq *irq);*/ int irq_first_device_type (enum irq_dev_t type,struct udevice **devp); +/** +* irq_get_acpi() - Get the ACPI info for an irq +* +* This converts a irq to an ACPI structure for adding to the ACPI +* tables. +* +* @irq: irq to convert +* @acpi_irq: Output ACPI interrupt information +* @return ACPI pin number or -ve on error +*/ +int irq_get_acpi (const struct irq *irq,struct acpi_irq *acpi_irq); +#endif lib/acpi/acpi_device.c +52
-0@@ -154,6 +154,58 @@ int acpi_device_status(const struct udevice *dev)return ACPI_STATUS_DEVICE_ALL_ON ; } +/* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */ +static int acpi_device_write_interrupt (struct acpi_ctx *ctx, +const struct acpi_irq *irq) +{ +void *desc_length; +u8 flags; + +if (!irq || !irq->pin) +return -ENOENT ; + +/* This is supported by GpioInt() but not Interrupt() */ +if (irq->polarity ==ACPI_IRQ_ACTIVE_BOTH ) +return -EINVAL ; + +/* Byte 0: Descriptor Type */ +acpigen_emit_byte (ctx,ACPI_DESCRIPTOR_INTERRUPT ); + +/* Byte 1-2: Length (filled in later) */ + desc_length =acpi_device_write_zero_len (ctx); + +/* +* Byte 3: Flags +* [7:5]: Reserved +* [4]: Wake (0=NO_WAKE 1=WAKE) +* [3]: Sharing (0=EXCLUSIVE 1=SHARED) +* [2]: Polarity (0=HIGH 1=LOW) +* [1]: Mode (0=LEVEL 1=EDGE) +* [0]: Resource (0=PRODUCER 1=CONSUMER) +*/ + flags =1 <<0 ;/* ResourceConsumer */ +if (irq->mode ==ACPI_IRQ_EDGE_TRIGGERED ) + flags |=1 <<1 ; +if (irq->polarity ==ACPI_IRQ_ACTIVE_LOW ) + flags |=1 <<2 ; +if (irq->shared ==ACPI_IRQ_SHARED ) + flags |=1 <<3 ; +if (irq->wake ==ACPI_IRQ_WAKE ) + flags |=1 <<4 ; +acpigen_emit_byte (ctx, flags); + +/* Byte 4: Interrupt Table Entry Count */ +acpigen_emit_byte (ctx,1 ); + +/* Byte 5-8: Interrupt Number */ +acpigen_emit_dword (ctx, irq->pin); + +/* Fill in Descriptor Length (account for len word) */ +acpi_device_fill_len (ctx, desc_length); + +return 0 ; +} +/* ACPI 6.1 section 6.4.3.8.1 - GPIO Interrupt or I/O */ int acpi_device_write_gpio (struct acpi_ctx *ctx,const struct acpi_gpio *gpio){
lib/acpi/acpi_device.c +0
-0@@ -304,6 +356,48 @@ int acpi_device_write_gpio_desc(struct acpi_ctx
*ctx,
Quoted 31 lines
lib/acpi/acpi_device.c +28
-0return 0 ; } +int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx, +const struct irq *req_irq) +{ +struct acpi_irq irq; +int ret; + + ret =irq_get_acpi (req_irq, &irq); +if (ret) +return log_msg_ret ("get" , ret); + ret =acpi_device_write_interrupt (ctx, &irq); +if (ret) +return log_msg_ret ("write" , ret); + +return 0 ; +} + +int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop) +{ +struct irq req_irq; +int ret; + + ret =irq_get_by_index (dev,0 , &req_irq); +if (!ret) { + ret =acpi_device_write_interrupt_irq (ctx, &req_irq); +if (ret) +return log_msg_ret ("irq" , ret); + }else {
lib/acpi/acpi_device.c int acpi_device_write_gpio_desc(struct acpi_ctx *ctx, · line 396
Quoted 10 lines
lib/acpi/acpi_device.c +10
-0+struct gpio_desc req_gpio; + + ret =gpio_request_by_name (dev, prop,0 , &req_gpio, +GPIOD_IS_IN ); +if (ret) +return log_msg_ret ("no gpio" , ret); + ret =acpi_device_write_gpio_desc (ctx, &req_gpio); +if (ret) +return log_msg_ret ("gpio" , ret); + }
Both code paths set the index value hardcoded to 0. Why is that? Would other indices not make sense?
Quoted 10 lines
lib/acpi/acpi_device.c +4
-0+ +return 0 ; +} +/* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */ static void acpi_device_write_i2c (struct acpi_ctx *ctx,const struct acpi_i2c *i2c)Signature · 1 line
2.25.1.481.gfbce0eb801-goog
regards, Wolfgang
Antwort: [PATCH v2 32/39] irq: Add a method to convert an interrupt to ACPI
In reply to Simon GlassHi Simon,
I'm resending this mail, as my email client has broken the formating in the first attempt, sorry.
"Simon Glass" <[email protected]> schrieb am 09.03.2020 04:44:56:
Quoted 7 lines
Von: "Simon Glass" <[email protected]>
An: "U-Boot Mailing List" <[email protected]>,
Kopie: "Bin Meng" <[email protected]>, "Wolfgang Wallner" <[email protected]>, "Andy Shevchenko" <[email protected]>, "Simon Glass" <[email protected]>
Datum: 09.03.2020 04:46
Betreff: [PATCH v2 32/39] irq: Add a method to convert an interrupt to
ACPI
Quoted 2 lines
When generating ACPI tables we need to convert IRQs in U-Boot to the
ACPI
Quoted 1 line
structures required by ACPI. This is a SoC-specific conversion and
cannot
Quoted 1 line
be handled by generic code, so add a new IRQ method to do the
conversion.
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq
Quoted 17 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
drivers/misc/irq-uclass.c | 18 +++++++- include/acpi_device.h | 27 +++++++++++ include/irq.h | 41 +++++++++++++++++ lib/acpi/acpi_device.c | 94 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 2 deletions(-)drivers/misc/irq-uclass.c +0
-0@@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq
*irq)
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq *irq) · line 157
Quoted 5 lines
drivers/misc/irq-uclass.c +0
-2const struct irq_ops *ops;log_debug ("(dev=%p, irq=%p)\n" , dev, irq); -if (!irq) -return 0 ;
Why is this code dropped?
Quoted 46 lines
drivers/misc/irq-uclass.c +16
-0ops =irq_get_ops (dev); irq->dev = dev;@@ -176,6 +174,22 @@ int irq_first_device_type(enum irq_dev_t type, struct udevice **devp)return 0 ; } +#if CONFIG_IS_ENABLED (ACPIGEN ) +int irq_get_acpi (const struct irq *irq,struct acpi_irq *acpi_irq) +{ +struct irq_ops *ops; + +if (!irq_is_valid (irq)) +return -EINVAL ; + + ops =irq_get_ops (irq->dev); +if (!ops->get_acpi) +return -ENOSYS ; + +return ops->get_acpi (irq, acpi_irq); +} +#endif +UCLASS_DRIVER (irq) = { .id =UCLASS_IRQ ,.name = "irq",include/acpi_device.h +4
-0@@ -545,6 +545,33 @@ int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp *table);int acpi_device_write_gpio_desc (struct acpi_ctx *ctx,const struct gpio_desc *desc); +/** +* acpi_device_write_interrupt_irq() - Write an interrupt to ACPI +* +* This creates an interrupt descriptor for an interrupt, including information
+ * ACPI needs to use it.
+ *
+ * @req_irq: Interrupt to write
+ * @return 0 if OK, -ve on error
+ */
include/acpi_device.h int acpi_dp_write(struct acpi_ctx *ctx, struct acpi_dp *table);
Quoted 5 lines
include/acpi_device.h +5
-0+int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx, +const struct irq *req_irq); + +/** +* acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to
ACPI
Quoted 2 lines
+ *
+ * This reads the an interrupt from the device tree, if available. If
not it
typo: "the an"
The description of what this function should do is rather vague. At least I'm not sure how it is meant to work.
Quoted 3 lines
+ * reads the first GPIO with the name @prop.
+ *
+ * If an interrupt is found, that is written to ACPI. If not, but an
GPIO is
Quoted 3 lines
+ * found, that is written.
+ *
+ * @return 0 if OK, -ve if neither an interrupt nor a GPIO could
befound, or
lib/acpi/acpi_device.c int acpi_device_write_gpio_desc(struct acpi_ctx
Quoted 152 lines
+ * some other error occurred
+ */include/acpi_device.h +3
-0+int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop); +/** * acpi_device_write_i2c_dev() - Write an I2C device to ACPI, including * information ACPI needs to use it. include/irq.h +41
-0@@ -8,6 +8,7 @@#ifndef __irq_H#define __irq_H +struct acpi_irq ;struct ofnode_phandle_args ;/* @@ -26,10 +27,12 @@ enum irq_dev_t {* * @dev: IRQ device that handles this irq * @id: ID to identify this irq with the device +* @flags: Flags associated with this interrupt (IRQ_TYPE_...) */ struct irq {struct udevice *dev;ulong id; +ulong flags; };/** @@ -121,10 +124,36 @@ struct irq_ops {* @return 0 if OK, or a negative error code. */ int (*free)(struct irq *irq); + +#if CONFIG_IS_ENABLED (ACPIGEN ) +/** +* get_acpi() - Get the ACPI info for an irq +* +* This converts a irq to an ACPI structure for adding to the ACPI +* tables. +* +* @irq: irq to convert +* @acpi_irq: Output ACPI interrupt information +* @return ACPI pin number or -ve on error +*/ +int (*get_acpi)(const struct irq *irq,struct acpi_irq *acpi_irq); +#endif };#define irq_get_ops (dev) ((struct irq_ops *)(dev)->driver->ops) +/** +* irq_is_valid() - Check if an IRQ is valid +* +* @irq: IRQ description containing device and ID, e.g. previously +* returned by irq_get_by_index() +* @return true if valid, false if not +*/ +static inline bool irq_is_valid (const struct irq *irq) +{ +return irq->dev !=NULL ; +} +/** * irq_route_pmc_gpio_gpe() - Get the GPIO for an event * @@ -225,4 +254,16 @@ int irq_free(struct irq *irq);*/ int irq_first_device_type (enum irq_dev_t type,struct udevice **devp); +/** +* irq_get_acpi() - Get the ACPI info for an irq +* +* This converts a irq to an ACPI structure for adding to the ACPI +* tables. +* +* @irq: irq to convert +* @acpi_irq: Output ACPI interrupt information +* @return ACPI pin number or -ve on error +*/ +int irq_get_acpi (const struct irq *irq,struct acpi_irq *acpi_irq); +#endif lib/acpi/acpi_device.c +52
-0@@ -154,6 +154,58 @@ int acpi_device_status(const struct udevice *dev)return ACPI_STATUS_DEVICE_ALL_ON ; } +/* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */ +static int acpi_device_write_interrupt (struct acpi_ctx *ctx, +const struct acpi_irq *irq) +{ +void *desc_length; +u8 flags; + +if (!irq || !irq->pin) +return -ENOENT ; + +/* This is supported by GpioInt() but not Interrupt() */ +if (irq->polarity ==ACPI_IRQ_ACTIVE_BOTH ) +return -EINVAL ; + +/* Byte 0: Descriptor Type */ +acpigen_emit_byte (ctx,ACPI_DESCRIPTOR_INTERRUPT ); + +/* Byte 1-2: Length (filled in later) */ + desc_length =acpi_device_write_zero_len (ctx); + +/* +* Byte 3: Flags +* [7:5]: Reserved +* [4]: Wake (0=NO_WAKE 1=WAKE) +* [3]: Sharing (0=EXCLUSIVE 1=SHARED) +* [2]: Polarity (0=HIGH 1=LOW) +* [1]: Mode (0=LEVEL 1=EDGE) +* [0]: Resource (0=PRODUCER 1=CONSUMER) +*/ + flags =1 <<0 ;/* ResourceConsumer */ +if (irq->mode ==ACPI_IRQ_EDGE_TRIGGERED ) + flags |=1 <<1 ; +if (irq->polarity ==ACPI_IRQ_ACTIVE_LOW ) + flags |=1 <<2 ; +if (irq->shared ==ACPI_IRQ_SHARED ) + flags |=1 <<3 ; +if (irq->wake ==ACPI_IRQ_WAKE ) + flags |=1 <<4 ; +acpigen_emit_byte (ctx, flags); + +/* Byte 4: Interrupt Table Entry Count */ +acpigen_emit_byte (ctx,1 ); + +/* Byte 5-8: Interrupt Number */ +acpigen_emit_dword (ctx, irq->pin); + +/* Fill in Descriptor Length (account for len word) */ +acpi_device_fill_len (ctx, desc_length); + +return 0 ; +} +/* ACPI 6.1 section 6.4.3.8.1 - GPIO Interrupt or I/O */ int acpi_device_write_gpio (struct acpi_ctx *ctx,const struct acpi_gpio *gpio){
lib/acpi/acpi_device.c +0
-0@@ -304,6 +356,48 @@ int acpi_device_write_gpio_desc(struct acpi_ctx
*ctx,
Quoted 31 lines
lib/acpi/acpi_device.c +28
-0return 0 ; } +int acpi_device_write_interrupt_irq (struct acpi_ctx *ctx, +const struct irq *req_irq) +{ +struct acpi_irq irq; +int ret; + + ret =irq_get_acpi (req_irq, &irq); +if (ret) +return log_msg_ret ("get" , ret); + ret =acpi_device_write_interrupt (ctx, &irq); +if (ret) +return log_msg_ret ("write" , ret); + +return 0 ; +} + +int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop) +{ +struct irq req_irq; +int ret; + + ret =irq_get_by_index (dev,0 , &req_irq); +if (!ret) { + ret =acpi_device_write_interrupt_irq (ctx, &req_irq); +if (ret) +return log_msg_ret ("irq" , ret); + }else {
lib/acpi/acpi_device.c int acpi_device_write_gpio_desc(struct acpi_ctx *ctx, · line 396
Quoted 10 lines
lib/acpi/acpi_device.c +10
-0+struct gpio_desc req_gpio; + + ret =gpio_request_by_name (dev, prop,0 , &req_gpio, +GPIOD_IS_IN ); +if (ret) +return log_msg_ret ("no gpio" , ret); + ret =acpi_device_write_gpio_desc (ctx, &req_gpio); +if (ret) +return log_msg_ret ("gpio" , ret); + }
Both code paths set the index value hardcoded to 0. Why is that? Would other indices not make sense?
Quoted 10 lines
lib/acpi/acpi_device.c +4
-0+ +return 0 ; +} +/* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */ static void acpi_device_write_i2c (struct acpi_ctx *ctx,const struct acpi_i2c *i2c)Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 32/39 irq: Add a method to convert an interrupt to ACPI
Hi Wolfgang,
Quoted 42 lines · Wolfgang Wallner
Hi Simon,
I'm resending this mail, as my email client has broken the formating in the first attempt, sorry.
"Simon Glass" <[email protected]> schrieb am 09.03.2020 04:44:56:
Quoted 7 lines
Von: "Simon Glass" <[email protected]>
An: "U-Boot Mailing List" <[email protected]>,
Kopie: "Bin Meng" <[email protected]>, "Wolfgang Wallner" <[email protected]>, "Andy Shevchenko" <[email protected]>, "Simon Glass" <[email protected]>
Datum: 09.03.2020 04:46
Betreff: [PATCH v2 32/39] irq: Add a method to convert an interrupt toACPI
Quoted 2 lines
When generating ACPI tables we need to convert IRQs in U-Boot to the
ACPI
Quoted 1 line
structures required by ACPI. This is a SoC-specific conversion and
cannot
Quoted 1 line
be handled by generic code, so add a new IRQ method to do the
conversion.
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq
Quoted 17 lines
Signed-off-by Simon Glass <[email protected]>---
Changes in v2: None
drivers/misc/irq-uclass.c | 18 +++++++- include/acpi_device.h | 27 +++++++++++ include/irq.h | 41 +++++++++++++++++ lib/acpi/acpi_device.c | 94 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 178 insertions(+), 2 deletions(-)drivers/misc/irq-uclass.c +0
-0@@ -153,8 +153,6 @@ int irq_request(struct udevice *dev, struct irq*irq)
Quoted 7 lines
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq *irq) · line 157
Quoted 5 lines
drivers/misc/irq-uclass.c +0
-2const struct irq_ops *ops;log_debug ("(dev=%p, irq=%p)\n" , dev, irq); -if (!irq) -return 0 ;Why is this code dropped?
We don't support passing NULL to this function. It would be invalid and there is no point in adding code to check for it.
[..]
Quoted 11 lines
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq · line 157
Quoted 2 lines
drivers/misc/irq-uclass.c +2
-0+/** +* acpi_device_write_interrupt_or_gpio() - Write interrupt or GPIO to ACPI
drivers/misc/irq-uclass.c int irq_request(struct udevice *dev, struct irq
Quoted 2 lines
drivers/misc/irq-uclass.c +2
-0+* +* This reads the an interrupt from the device tree, if available. If not it
typo: "the an"
The description of what this function should do is rather vague. At least I'm not sure how it is meant to work.
OK I will beef it up.
[..]
Quoted 17 lines
Quoted 17 lines
drivers/misc/irq-uclass.c +17
-0+int acpi_device_write_interrupt_or_gpio (struct acpi_ctx *ctx, +struct udevice *dev,const char *prop) +{ +struct irq req_irq; +int ret; + + ret =irq_get_by_index (dev,0 , &req_irq); +if (!ret) { + ret =acpi_device_write_interrupt_irq (ctx, &req_irq); +if (ret) +return log_msg_ret ("irq" , ret); + }else { +struct gpio_desc req_gpio; + + ret =gpio_request_by_name (dev, prop,0 , &req_gpio, +GPIOD_IS_IN ); +if (ret)
Quoted 8 lines
drivers/misc/irq-uclass.c
Quoted 5 lines
drivers/misc/irq-uclass.c +5
-0+return log_msg_ret ("no gpio" , ret); + ret =acpi_device_write_gpio_desc (ctx, &req_gpio); +if (ret) +return log_msg_ret ("gpio" , ret); + }Both code paths set the index value hardcoded to 0. Why is that? Would other indices not make sense?
We only support a single interrupt / GPIO at present. We could expand this but there is no use case for that yet.
Regards,
Simon
PATCH v2 33/39 acpi: Add support for SSDT generation
In reply to Simon GlassSome devices need to generate code for the Secondary System Descriptor Table (SSDT). Add a method to handle this.
---
Changes in v2:
- Switch parameter order of _acpi_fill_ssdt() and make it static
arch/sandbox/dts/test.dts | 2 ++ drivers/core/acpi.c | 14 +++++++++++++ include/dm/acpi.h | 23 ++++++++++++++++++++++ test/dm/acpi.c | 41 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +2 -0
@@ -208,10 +208,12 @@ acpi-test { compatible = "denx,u-boot-acpi-test"; + acpi-ssdt-test-data = "ab"; }; acpi-test2 { compatible = "denx,u-boot-acpi-test"; + acpi-ssdt-test-data = "cd"; }; clocks {
drivers/core/acpi.c +14 -0
@@ -17,6 +17,7 @@/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES , +METHOD_FILL_SDDT , };/* Prototype for all methods */
@@ -49,6 +50,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method)switch (method) {case METHOD_WRITE_TABLES :return aops->write_tables; +case METHOD_FILL_SDDT : +return aops->fill_ssdt; } }
@@ -81,6 +84,17 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent,return 0 ; } +int acpi_fill_ssdt (struct acpi_ctx *ctx) +{ +int ret; + +log_debug ("Writing SSDT tables\n" ); + ret =acpi_recurse_method (ctx,dm_root (),METHOD_FILL_SDDT ); +log_debug ("Writing SSDT finished, err=%d\n" , ret); + +return ret; +} +int acpi_write_dev_tables (struct acpi_ctx *ctx) {int ret;
include/dm/acpi.h +23 -0
@@ -72,6 +72,19 @@ struct acpi_ops {* @return 0 if OK, -ve on error */ int (*write_tables)(const struct udevice *dev,struct acpi_ctx *ctx); + +/** +* fill_ssdt() - Generate SSDT code for a device +* +* This is called to create the SSDT code. THe method should write out +* whatever ACPI code is needed by this device. It will end up in the +* SSDT table. +* +* @dev: Device to write +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int (*fill_ssdt)(const struct udevice *dev,struct acpi_ctx *ctx); };#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops)
@@ -116,6 +129,16 @@ int acpi_return_name(char *out_name, const char *name);*/ int acpi_write_dev_tables (struct acpi_ctx *ctx); +/** +* acpi_fill_ssdt() - Generate ACPI tables for SSDT +* +* This is called to create the SSDT code for all devices. +* +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int acpi_fill_ssdt (struct acpi_ctx *ctx); +#endif /* __ACPI__ */ #endif
test/dm/acpi.c +40 -1
65 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 33/39] acpi: Add support for SSDT generation
Hi Simon,
"Simon Glass" <[email protected]> schrieb am 09.03.2020 04:44:57:
Quoted 17 lines
Betreff: [PATCH v2 33/39] acpi: Add support for SSDT generation
Some devices need to generate code for the Secondary System Descriptor Table (SSDT). Add a method to handle this.
Signed-off-by Simon Glass <[email protected]>---
Changes in v2:
- Switch parameter order of_acpi_fill_ssdt()and make it staticarch/sandbox/dts/test.dts | 2 ++ drivers/core/acpi.c | 14 +++++++++++++ include/dm/acpi.h | 23 ++++++++++++++++++++++ test/dm/acpi.c | 41 ++++++++++++++++++++++++++++++++++++++- 4 files changed, 79 insertions(+), 1 deletion(-)
[snip]
Quoted 5 lines
test/dm/acpi.c +0
-0@@ -7,6 +7,7 @@
[snip]
test/dm/acpi.c static int dm_test_acpi_cmd_dump(struct
Quoted 2 lines
static const struct
udevice_idtestacpi_ids[] = {test/dm/acpi.c +0
-0@@ -313,3 +325,30 @@ static int dm_test_acpi_cmd_dump(struct
unit_test_state *uts)
test/dm/acpi.c static int dm_test_acpi_cmd_dump(struct · line 327
Quoted 3 lines
test/dm/acpi.c +0
-0return 0 ; } DM_TEST(dm_test_acpi_cmd_dump, DM_TESTF_SCAN_PDATA |
DM_TESTF_SCAN_FDT);
test/dm/acpi.c static int dm_test_acpi_cmd_dump(struct unit_test_state *uts) · line 339
Quoted 12 lines
test/dm/acpi.c +12
-0+ +/* Test acpi_fill_ssdt() */ +static int dm_test_acpi_fill_ssdt (struct unit_test_state *uts) +{ +struct acpi_ctx ctx; +u8 *buf; + + buf =malloc (BUF_SIZE ); +ut_assertnonnull (buf); + + ctx.current = buf; + buf[4 ] ='z' ;/* sentinal */
nit: sentinel ?
test/dm/acpi.c static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
Quoted 3 lines
test/dm/acpi.c +3
-0+ut_assertok (acpi_fill_ssdt (&ctx)); + +/* These values come from acpi-test's acpi-ssdt-test-data property
*/
test/dm/acpi.c static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
Quoted 4 lines
test/dm/acpi.c +4
-0+ut_asserteq ('a' , buf[0 ]); +ut_asserteq ('b' , buf[1 ]); + +/* These values come from acpi-test2's acpi-ssdt-test-data property
*/
test/dm/acpi.c static int dm_test_acpi_cmd_dump(struct unit_test_state *uts)
Quoted 8 lines
test/dm/acpi.c +8
-0+ut_asserteq ('c' , buf[2 ]); +ut_asserteq ('d' , buf[3 ]); + +ut_asserteq ('z' , buf[4 ]); + +return 0 ; +} +DM_TEST(dm_test_acpi_fill_ssdt, DM_TESTF_SCAN_PDATA |
DM_TESTF_SCAN_FDT);
Quoted 3 lines
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
Antwort: [PATCH v2 33/39] acpi: Add support for SSDT generation
In reply to Simon GlassHi Simon,
during the review of a later patch I spotted a typo in this patch that I missed initially, see below.
"Simon Glass" <[email protected]> schrieb am 09.03.2020 04:44:57:
Quoted 6 lines
Betreff: [PATCH v2 33/39] acpi: Add support for SSDT generation
Some devices need to generate code for the Secondary System Descriptor Table (SSDT). Add a method to handle this.
Signed-off-by Simon Glass <[email protected]>
[snip]
drivers/core/acpi.c line 20
Quoted 9 lines
drivers/core/acpi.c +1
-0@@ -17,6 +17,7 @@/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES , +METHOD_FILL_SDDT ,
typo: this should be METHOD_FILL_SSDT
drivers/core/acpi.c line 22
Quoted 2 lines
drivers/core/acpi.c +0
-0};
regards, Wolfgang
PATCH v2 34/39 x86: acpi: Move MADT up a bit
In reply to Simon GlassPut this table before MCFG so that it matches the order that coreboot uses when passing tables to Linux. This is a cosmetic change since the order of the tables does not otherwise matter.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
arch/x86/lib/acpi_table.c +6 -6
@@ -408,18 +408,18 @@ ulong write_acpi_tables(ulong start_addr)acpi_create_fadt (fadt, facs, dsdt);acpi_add_table (ctx, fadt); -debug ("ACPI: * MADT\n" ); - madt = ctx->current; -acpi_create_madt (madt); -acpi_inc_align (ctx, madt->header.length); -acpi_add_table (ctx, madt); -debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);acpi_inc_align (ctx, mcfg->header.length);acpi_add_table (ctx, mcfg); +debug ("ACPI: * MADT\n" ); + madt = ctx->current; +acpi_create_madt (madt); +acpi_inc_align (ctx, madt->header.length); +acpi_add_table (ctx, madt); +debug ("ACPI: * CSRT\n" ); csrt = ctx->current;acpi_create_csrt (csrt);
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 35/39 acpi: Record the items added to SSDT
In reply to Simon GlassIt is useful to be able to control the order of data written to the SSDT so that we can compare the output against known-good kernel dumps.
Add code to record each item that is added along with the device that added it. That allows us to reorder things later if needed.
---
Changes in v2:
- Generalise the ACPI function recursion with acpi_recurse_method()
drivers/core/acpi.c | 83 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 79 insertions(+), 4 deletions(-)
drivers/core/acpi.c +79 -4
@@ -9,11 +9,20 @@#define LOG_CATEOGRY LOGC_ACPI#include <common.h> +#include <malloc.h> #include <dm.h> #include <dm/acpi.h> #include <dm/device-internal.h> #include <dm/root.h> +#define MAX_ITEMS 100 + +/* Type of table that we collected */ +enum gen_type_t { +TYPE_NONE , +TYPE_SSDT , +}; +/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES ,
@@ -23,6 +32,25 @@ enum method_t {/* Prototype for all methods */ typedef int (*acpi_method )(const struct udevice *dev,struct acpi_ctx *ctx); +/** +* struct acpi_item - Holds info about ACPI data generated by a driver method +* +* @dev: Device that generated this data +* @type: Table type it refers to +* @buf: Buffer containing the data +* @size: Size of the data in bytes +*/ +struct acpi_item { +struct udevice *dev; +enum gen_type_t type; +char *buf; +int size; +}; + +/* List of ACPI items collected */ +static struct acpi_item acpi_item[MAX_ITEMS ]; +static int item_count; +int acpi_return_name (char *out_name,const char *name) {strcpy (out_name, name);
@@ -41,6 +69,43 @@ int acpi_get_name(const struct udevice *dev, char *out_name)return -ENOSYS ; } +/** +* acpi_add_item() - Add a new item to the list of data collected +* +* @ctx: ACPI context +* @dev: Device that generated the data +* @type: Table type it refers to +* @start: The start of the data (the end is obtained from ctx->current) +* @return 0 if OK, -ENOSPC if too many items, -ENOMEM if out of memory +*/ +static int acpi_add_item (struct acpi_ctx *ctx,struct udevice *dev, +enum gen_type_t type,void *start) +{ +struct acpi_item *item; +void *end = ctx->current; + +if (item_count ==MAX_ITEMS ) { +log_err ("Too many items\n" ); +return log_msg_ret ("mem" , -ENOSPC ); + } + + item = &acpi_item[item_count]; + item->dev = dev; + item->type = type; + item->size = end - start; +if (!item->size) +return 0 ; + item->buf =malloc (item->size); +if (!item->buf) +return log_msg_ret ("mem" , -ENOMEM ); +memcpy (item->buf, start, item->size); + item_count++; +log_debug ("* %s: Added type %d, %p, size %x\n" , dev->name, type, start, + item->size); + +return 0 ; +} +acpi_method acpi_get_method (struct udevice *dev,enum method_t method) {struct acpi_ops *aops;
@@ -59,7 +124,7 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method) }int acpi_recurse_method (struct acpi_ctx *ctx,struct udevice *parent, -enum method_t method) +enum method_t method,enum gen_type_t type) {struct udevice *dev;acpi_method func;
@@ -67,6 +132,8 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, func =acpi_get_method (parent, method);if (func) { +void *start = ctx->current; +log_debug ("\n- %s %p\n" , parent->name, func); ret =device_ofdata_to_platdata (parent);if (ret)
@@ -74,9 +141,16 @@ int acpi_recurse_method(struct acpi_ctx *ctx, struct udevice *parent, ret =func (parent, ctx);if (ret)return log_msg_ret ("func" , ret); + +/* Add the item to the internal list */ +if (type !=TYPE_NONE ) { + ret =acpi_add_item (ctx, parent, type, start); +if (ret) +return log_msg_ret ("add" , ret); + } } device_foreach_child(dev, parent) { - ret =acpi_recurse_method (ctx, dev, method); + ret =acpi_recurse_method (ctx, dev, method, type);if (ret)return log_msg_ret ("recurse" , ret); }
@@ -89,7 +163,7 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)int ret;log_debug ("Writing SSDT tables\n" ); - ret =acpi_recurse_method (ctx,dm_root (),METHOD_FILL_SDDT ); + ret =acpi_recurse_method (ctx,dm_root (),METHOD_FILL_SDDT ,TYPE_SSDT );log_debug ("Writing SSDT finished, err=%d\n" , ret);return ret;
@@ -100,7 +174,8 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx)int ret;log_debug ("Writing device tables\n" ); - ret =acpi_recurse_method (ctx,dm_root (),METHOD_WRITE_TABLES ); + ret =acpi_recurse_method (ctx,dm_root (),METHOD_WRITE_TABLES , +TYPE_NONE );log_debug ("Writing finished, err=%d\n" , ret);return ret;
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 36/39 acpi: Support ordering SSDT data by device
In reply to Simon GlassAdd a /chosen property to control the order in which the data appears in the SSDT. This allows matching up U-Boot's output from a dump of the known-good data obtained from within Linux.
---
Changes in v2:
- Generalise the ACPI function recursion with acpi_recurse_method()
arch/sandbox/dts/test.dts | 5 ++- doc/device-tree-bindings/chosen.txt | 9 +++++ drivers/core/acpi.c | 62 +++++++++++++++++++++++++++++ test/dm/acpi.c | 17 ++++---- 4 files changed, 84 insertions(+), 9 deletions(-)
arch/sandbox/dts/test.dts +3 -2
@@ -206,12 +206,12 @@ compatible = "denx,u-boot-devres-test"; }; - acpi-test { + acpi_test1: acpi-test { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "ab"; }; - acpi-test2 { + acpi_test2: acpi-test2 { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "cd"; };
@@ -829,6 +829,7 @@ setting = "sunrise ohoka"; other-node = "/some-bus/c-test at 5"; int-values = <0x1937 72993>; + u-boot,acpi-ssdt-order = <&acpi_test2 &acpi_test1>; chosen-test { compatible = "denx,u-boot-fdt-test"; reg = <9 1>;
doc/device-tree-bindings/chosen.txt +9 -0
@@ -134,3 +134,12 @@ Example phandlepart = <&mmc 1>; }; }; + +u-boot,acpi-ssdt-order +---------------------- + +This provides the ordering to use when writing device data to the ACPI SSDT +(Secondary System Descriptor Table). Each cell is a phandle pointer to a device +node to add. The ACPI information is written in this order. + +If the ordering does not include all nodes, an error is generated.
drivers/core/acpi.c +62 -0
79 lines not on this page · raw message
test/dm/acpi.c +10 -7
@@ -336,16 +336,19 @@ static int dm_test_acpi_fill_ssdt(struct unit_test_state *uts)ut_assertnonnull (buf); ctx.current = buf; - buf[4 ] ='z' ;/* sentinal */ + buf[4 ] ='z' ;/* sentinel */ ut_assertok (acpi_fill_ssdt (&ctx)); -/* These values come from acpi-test's acpi-ssdt-test-data property */ -ut_asserteq ('a' , buf[0 ]); -ut_asserteq ('b' , buf[1 ]); +/* +* These values come from acpi-test2's acpi-ssdt-test-data property. +* This device comes first because of u-boot,acpi-ssdt-order +*/ +ut_asserteq ('c' , buf[0 ]); +ut_asserteq ('d' , buf[1 ]); -/* These values come from acpi-test2's acpi-ssdt-test-data property */ -ut_asserteq ('c' , buf[2 ]); -ut_asserteq ('d' , buf[3 ]); +/* These values come from acpi-test's acpi-ssdt-test-data property */ +ut_asserteq ('a' , buf[2 ]); +ut_asserteq ('b' , buf[3 ]);ut_asserteq ('z' , buf[4 ]);
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 37/39 x86: Allow devices to write an SSDT
In reply to Simon GlassCall the new core function to write the SSDT. This is made up of fragments generated by devices that have the fill_ssdt() method.
---
Changes in v2:
- Move ACPI_TABLE_CREATOR to here
arch/x86/lib/acpi_table.c | 50 +++++++++++++++++++++++++++++++++++++++ include/acpi_table.h | 1 + 2 files changed, 51 insertions(+)
arch/x86/lib/acpi_table.c +50 -0
@@ -7,6 +7,7 @@*/ #include <common.h> +#include <acpigen.h> #include <cpu.h> #include <dm.h> #include <dm/uclass-internal.h>
@@ -344,6 +345,46 @@ static void acpi_create_spcr(struct acpi_spcr *spcr) header->checksum =table_compute_checksum ((void *)spcr, header->length); } +static void acpi_ssdt_write_cbtable (struct acpi_ctx *ctx) +{ +uintptr_t base; +u32 size; + + base =0 ; + size =0 ; + +acpigen_write_device (ctx,"CTBL" ); +acpigen_write_coreboot_hid (ctx,COREBOOT_ACPI_ID_CBTABLE ); +acpigen_write_name_integer (ctx,"_UID" ,0 ); +acpigen_write_sta (ctx,ACPI_STATUS_DEVICE_HIDDEN_ON ); +acpigen_write_name (ctx,"_CRS" ); +acpigen_write_resourcetemplate_header (ctx); +acpigen_write_mem32fixed (ctx,0 , base, size); +acpigen_write_resourcetemplate_footer (ctx); +acpigen_pop_len (ctx); +} + +void acpi_create_ssdt (struct acpi_ctx *ctx,struct acpi_table_header *ssdt, +const char *oem_table_id) +{ +memset ((void *)ssdt,'\0' ,sizeof (struct acpi_table_header )); + +acpi_fill_header (ssdt,"SSDT" ); + ssdt->revision =acpi_get_table_revision (ACPITAB_SSDT ); + ssdt->aslc_revision =1 ; + ssdt->length =sizeof (struct acpi_table_header ); + +acpi_inc (ctx,sizeof (struct acpi_table_header )); + +/* Write object to declare coreboot tables */ +acpi_ssdt_write_cbtable (ctx); +acpi_fill_ssdt (ctx); + +/* (Re)calculate length and checksum. */ + ssdt->length = ctx->current - (void *)ssdt; + ssdt->checksum =table_compute_checksum ((void *)ssdt, ssdt->length); +} +/* * QEMU's version of write_acpi_tables is defined in drivers/misc/qfw.c */
@@ -353,6 +394,7 @@ ulong write_acpi_tables(ulong start_addr)struct acpi_facs *facs;struct acpi_table_header *dsdt;struct acpi_fadt *fadt; +struct acpi_table_header *ssdt;struct acpi_mcfg *mcfg;struct acpi_madt *madt;struct acpi_csrt *csrt;
@@ -408,6 +450,14 @@ ulong write_acpi_tables(ulong start_addr)acpi_create_fadt (fadt, facs, dsdt);acpi_add_table (ctx, fadt); +debug ("ACPI: * SSDT\n" ); + ssdt = (struct acpi_table_header *)ctx->current; +acpi_create_ssdt (ctx, ssdt,ACPI_TABLE_CREATOR ); +if (ssdt->length >sizeof (struct acpi_table_header )) { +acpi_inc_align (ctx, ssdt->length); +acpi_add_table (ctx, ssdt); + } +debug ("ACPI: * MCFG\n" ); mcfg = ctx->current;acpi_create_mcfg (mcfg);
include/acpi_table.h +1 -0
@@ -17,6 +17,7 @@#define OEM_ID "U-BOOT"/* U-Boot */ #define OEM_TABLE_ID "U-BOOTBL"/* U-Boot Table */ #define ASLC_ID "INTL"/* Intel ASL Compiler */ +#define ACPI_TABLE_CREATOR OEM_TABLE_ID#define ACPI_RSDP_REV_ACPI_1_0 0#define ACPI_RSDP_REV_ACPI_2_0 2
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 38/39 acpi: Add support for DSDT generation
In reply to Simon GlassSome devices need to inject extra code into the Differentiated System Descriptor Table (DSDT). Add a method to handle this.
---
Changes in v2:
- Generalise the ACPI function recursion with acpi_recurse_method()
arch/sandbox/dts/test.dts | 2 ++ drivers/core/acpi.c | 25 ++++++++++++++++++++++- include/dm/acpi.h | 23 +++++++++++++++++++++ test/dm/acpi.c | 42 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 91 insertions(+), 1 deletion(-)
arch/sandbox/dts/test.dts +2 -0
@@ -209,11 +209,13 @@ acpi_test1: acpi-test { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "ab"; + acpi-dsdt-test-data = "hi"; }; acpi_test2: acpi-test2 { compatible = "denx,u-boot-acpi-test"; acpi-ssdt-test-data = "cd"; + acpi-dsdt-test-data = "jk"; }; clocks {
drivers/core/acpi.c +24 -1
@@ -21,12 +21,14 @@enum gen_type_t {TYPE_NONE ,TYPE_SSDT , +TYPE_DSDT , };/* Type of method to call */ enum method_t {METHOD_WRITE_TABLES ,METHOD_FILL_SDDT , +METHOD_INJECT_DSDT , };/* Prototype for all methods */
@@ -129,7 +131,9 @@ static int build_type(struct acpi_ctx *ctx, void *start, enum gen_type_t type)void *end = ctx->current; ptr = start; - order =ofnode_read_chosen_prop ("u-boot,acpi-ssdt-order" , &size); + order =ofnode_read_chosen_prop (type ==TYPE_DSDT ? +"u-boot,acpi-dsdt-order" : +"u-boot,acpi-ssdt-order" , &size);if (!order) {log_warning ("Failed to find ordering, leaving as is\n" );return 0 ;
@@ -174,6 +178,8 @@ acpi_method acpi_get_method(struct udevice *dev, enum method_t method)return aops->write_tables;case METHOD_FILL_SDDT :return aops->fill_ssdt; +case METHOD_INJECT_DSDT : +return aops->inject_dsdt; } }
@@ -231,6 +237,23 @@ int acpi_fill_ssdt(struct acpi_ctx *ctx)return ret; } +int acpi_inject_dsdt (struct acpi_ctx *ctx) +{ +void *start = ctx->current; +int ret; + +log_debug ("Writing DSDT tables\n" ); + item_count =0 ; + ret =acpi_recurse_method (ctx,dm_root (),METHOD_INJECT_DSDT , +TYPE_DSDT ); +log_debug ("Writing DSDT finished, err=%d\n" , ret); + ret =build_type (ctx, start,TYPE_DSDT ); +if (ret) +return log_msg_ret ("build" , ret); + +return ret; +} +int acpi_write_dev_tables (struct acpi_ctx *ctx) {int ret;
include/dm/acpi.h +23 -0
@@ -85,6 +85,19 @@ struct acpi_ops {* @return 0 if OK, -ve on error */ int (*fill_ssdt)(const struct udevice *dev,struct acpi_ctx *ctx); + +/** +* inject_dsdt() - Generate DSDT code for a device +* +* This is called to create the DSDT code. THe method should write out +* whatever ACPI code is needed by this device. It will end up in the +* DSDT table. +* +* @dev: Device to write +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int (*inject_dsdt)(const struct udevice *dev,struct acpi_ctx *ctx); };#define device_get_acpi_ops (dev) ((dev)->driver->acpi_ops)
@@ -139,6 +152,16 @@ int acpi_write_dev_tables(struct acpi_ctx *ctx);*/ int acpi_fill_ssdt (struct acpi_ctx *ctx); +/** +* acpi_inject_dsdt() - Generate ACPI tables for DSDT +* +* This is called to create the DSDT code for all devices. +* +* @ctx: ACPI context to use +* @return 0 if OK, -ve on error +*/ +int acpi_inject_dsdt (struct acpi_ctx *ctx); +#endif /* __ACPI__ */ #endif
test/dm/acpi.c +42 -0
55 lines not on this page · raw message
Signature · 1 line
2.25.1.481.gfbce0eb801-goog
PATCH v2 39/39 x86: Allow devices to write to DSDT
In reply to Simon GlassCall the new core function to inject ASL programmatically into the DSDT. This is made up of fragments generated by devices that have the inject_dsdt() method. The normal, compiled ASL file is added after this.
---
Changes in v2: None
arch/x86/lib/acpi_table.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-)
arch/x86/lib/acpi_table.c +14 -1
@@ -422,7 +422,20 @@ ulong write_acpi_tables(ulong start_addr)memcpy (ctx->current, (char *)&AmlCode +sizeof (struct acpi_table_header ), dsdt->length -sizeof (struct acpi_table_header )); -acpi_inc_align (ctx, dsdt->length -sizeof (struct acpi_table_header )); + +if (dsdt->length >=sizeof (struct acpi_table_header )) { +acpi_inject_dsdt (ctx); +memcpy (ctx->current, + (char *)AmlCode +sizeof (struct acpi_table_header ), + dsdt->length -sizeof (struct acpi_table_header )); +acpi_inc (ctx, dsdt->length -sizeof (struct acpi_table_header )); + +/* (Re)calculate length and checksum. */ + dsdt->length = ctx->current - (void *)dsdt; + dsdt->checksum =0 ; + dsdt->checksum =table_compute_checksum (dsdt, dsdt->length); + } +acpi_align (ctx);/* Pack GNVS into the ACPI table area */ for (i =0 ; i < dsdt->length; i++) {
Signature · 1 line
2.25.1.481.gfbce0eb801-goog