diff options
author | Duncan Laurie <dlaurie@chromium.org> | 2016-05-10 13:18:17 -0700 |
---|---|---|
committer | Duncan Laurie <dlaurie@google.com> | 2016-05-28 03:48:55 +0200 |
commit | 559e947306d9a8684f7c0879c122a9b3b3f87c16 (patch) | |
tree | 69da36f121c27acf2704a7343ad47ae2a01dd870 /src/arch/x86/include | |
parent | 70c86d9b265a7ea821fcd1b0684d60393d9908c1 (diff) |
acpi_device: Add support for writing ACPI Device Properties
The recent ACPI specification extensions have formally defined a
method for describing device information with a key=value format that
is modeled after the Devicetree/DTS format using a special crafted
object named _DSD with a specific UUID for this format.
There are three defined Device Property types: Integers, Strings, and
References. It is also possible to have arrays of these properties
under one key=value pair. Strings and References are both represented
as character arrays but result in different generated ACPI OpCodes.
Various helpers are provided for writing the Device Property header
(to fill in the object name and UUID) and footer (to fill in the
property count and device length values) as well as for writing the
different Device Property types. A specific helper is provided for
writing the defined GPIO binding Device Property that is used to allow
GPIOs to be referred to by name rather than resource index.
This is all documented in the _DSD Device Properties UUID document:
http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf
This will be used by device drivers to provide device properties that
are consumed by the operating system. Devicetree bindings are often
described in the linux kernel at Documentation/devicetree/bindings/
A sample driver here has an input GPIO that it needs to describe to
the kernel driver:
chip.h:
struct drivers_generic_sample_config {
struct acpi_gpio mode_gpio;
};
sample.c:
static void acpi_fill_ssdt_generator(struct device *dev) {
struct drivers_generic_sample_config *config = dev->chip_info;
const char *path = acpi_device_path(dev);
...
acpi_device_write_gpio(&config->mode_gpio);
...
acpi_dp_write_header();
acpi_dp_write_gpio("mode-gpio", path, 0, 0, 0);
acpi_dp_write_footer();
...
}
devicetree.cb:
device pci 1f.0 on
chip drivers/generic/sample
register "mode_gpio" = "ACPI_GPIO_INPUT(GPP_B1)"
device generic 0 on end
end
end
SSDT.dsl:
Name (_CRS, ResourceTemplate () {
GpioIo (Exclusive, PullDefault, 0, 0, IoRestrictionInputOnly,
"\\_SB.PCI0.GPIO", 0, ResourceConsumer) { 25 }
})
Name (_DSD, Package () {
ToUUID ("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"),
Package () {
Package () {"mode-gpio", Package () { \_SB.PCI0.LPCB, 0, 0, 1 }}
}
})
Change-Id: I93ffd09e59d05c09e38693e221a87085469be3ad
Signed-off-by: Duncan Laurie <dlaurie@chromium.org>
Reviewed-on: https://review.coreboot.org/14937
Tested-by: build bot (Jenkins)
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'src/arch/x86/include')
-rw-r--r-- | src/arch/x86/include/arch/acpi_device.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/src/arch/x86/include/arch/acpi_device.h b/src/arch/x86/include/arch/acpi_device.h index dc7f26c14b..65f49b2cb0 100644 --- a/src/arch/x86/include/arch/acpi_device.h +++ b/src/arch/x86/include/arch/acpi_device.h @@ -228,4 +228,64 @@ struct acpi_spi { /* Write SPI Bus descriptor to SSDT AML output */ void acpi_device_write_spi(const struct acpi_spi *spi); +/* + * Device Properties with _DSD + * http://uefi.org/sites/default/files/resources/_DSD-device-properties-UUID.pdf + */ + +#define ACPI_DP_UUID "daffd814-6eba-4d8c-8a91-bc9bbf4aa301" + +enum acpi_dp_type { + ACPI_DP_TYPE_INTEGER, + ACPI_DP_TYPE_STRING, + ACPI_DP_TYPE_REFERENCE, +}; + +struct acpi_dp { + enum acpi_dp_type type; + union { + uint64_t integer; + const char *string; + }; +}; + +#define ACPI_DP_INTEGER(x) { .type = ACPI_DP_TYPE_INTEGER, .integer = x } +#define ACPI_DP_STRING(x) { .type = ACPI_DP_TYPE_STRING, .string = x } +#define ACPI_DP_REFERENCE(x) { .type = ACPI_DP_TYPE_REFERENCE, .string = x } + +/* + * Writing Device Properties objects via _DSD + */ + +/* Start a set of Device Properties with _DSD and UUID */ +void acpi_dp_write_header(void); + +/* End the Device Properties set and fill in length values */ +void acpi_dp_write_footer(void); + +/* Write a Device Property value, but not the key */ +void acpi_dp_write_value(const struct acpi_dp *prop); + +/* Write a Device Property, both key and value */ +void acpi_dp_write_keyval(const char *key, const struct acpi_dp *prop); + +/* Write an integer as a Device Property */ +void acpi_dp_write_integer(const char *key, uint64_t value); + +/* Write a string as a Device Property */ +void acpi_dp_write_string(const char *key, const char *value); + +/* Write an ACPI reference as a Device Property */ +void acpi_dp_write_reference(const char *key, const char *value); + +/* Write an array of Device Properties */ +void acpi_dp_write_array(const char *key, const struct acpi_dp *array, int len); + +/* Write an array of integers as Device Properties */ +void acpi_dp_write_integer_array(const char *key, uint64_t *array, int len); + +/* Write a GPIO binding Device Property */ +void acpi_dp_write_gpio(const char *key, const char *ref, int index, + int pin, int active_low); + #endif |