acpi: Move ACPI table support out of arch/x86 (1/5)
This change moves all ACPI table support in coreboot currently living under arch/x86 into common code to make it architecture independent. ACPI table generation is not really tied to any architecture and hence it makes sense to move this to its own directory. In order to make it easier to review, this change is being split into multiple CLs. This is change 1/5 which moves .c files from arch/x86 to acpi/. The only acpi files that are still retained under arch/x86 are: a. acpi_s3.c: This doesn't really deal with ACPI tables. Also, there are some assumptions in there about SMM which will have to be resolved if this file needs to be moved to common code. b. acpi_bert_storage.c/bert_storage.h: This file is currently written specifically with x86 in mind. So, not moving the file for now. Motivation for this change: Not all stages on Picasso SoC are targeted for the same architecture. For example, verstage (if runs before bootblock) will be targeted for non-x86. This makes it difficult to add device tree to verstage which would be required to get to SoC configs from the tree. This is because the device tree on x86 platforms currently contains a lot of devices that require ACPI related enums and structs (like acpi_gpio, acpi_pld, acpi_dp and so on). Hence, this change removes all ACPI table support out of arch/x86. BUG=b:155428745 Change-Id: Icc6b793c52c86483a8c52e0555619e36869a869e Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/40930 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Felix Held <felix-coreboot@felixheld.de>
This commit is contained in:
@@ -1,4 +1,15 @@
|
||||
# SPDX-License-Identifier: GPL-2.0-only
|
||||
# This file is part of the coreboot project.
|
||||
|
||||
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += sata.c
|
||||
ifeq ($(CONFIG_HAVE_ACPI_TABLES),y)
|
||||
|
||||
ramstage-y += acpi.c
|
||||
ramstage-y += acpi_device.c
|
||||
ramstage-y += acpi_pld.c
|
||||
ramstage-y += acpigen.c
|
||||
ramstage-y += acpigen_dsm.c
|
||||
ramstage-y += acpigen_ps2_keybd.c
|
||||
|
||||
ramstage-y += sata.c
|
||||
|
||||
endif # CONFIG_GENERATE_ACPI_TABLES
|
||||
|
1641
src/acpi/acpi.c
Normal file
1641
src/acpi/acpi.c
Normal file
File diff suppressed because it is too large
Load Diff
961
src/acpi/acpi_device.c
Normal file
961
src/acpi/acpi_device.c
Normal file
@@ -0,0 +1,961 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/* This file is part of the coreboot project. */
|
||||
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
#include <arch/acpi.h>
|
||||
#include <arch/acpi_device.h>
|
||||
#include <arch/acpigen.h>
|
||||
#include <device/device.h>
|
||||
#include <device/path.h>
|
||||
#include <stdlib.h>
|
||||
#include <crc_byte.h>
|
||||
|
||||
#if CONFIG(GENERIC_GPIO_LIB)
|
||||
#include <gpio.h>
|
||||
#endif
|
||||
|
||||
#define ACPI_DP_UUID "daffd814-6eba-4d8c-8a91-bc9bbf4aa301"
|
||||
#define ACPI_DP_CHILD_UUID "dbb8e3e6-5886-4ba6-8795-1319f52a966b"
|
||||
|
||||
/* Write empty word value and return pointer to it */
|
||||
static void *acpi_device_write_zero_len(void)
|
||||
{
|
||||
char *p = acpigen_get_current();
|
||||
acpigen_emit_word(0);
|
||||
return p;
|
||||
}
|
||||
|
||||
/* Fill in length value from start to current at specified location */
|
||||
static void acpi_device_fill_from_len(char *ptr, char *start)
|
||||
{
|
||||
uint16_t len = acpigen_get_current() - start;
|
||||
ptr[0] = len & 0xff;
|
||||
ptr[1] = (len >> 8) & 0xff;
|
||||
}
|
||||
|
||||
/*
|
||||
* Fill in the length field with the value calculated from after
|
||||
* the 16bit field to acpigen current as this length value does
|
||||
* not include the length field itself.
|
||||
*/
|
||||
static void acpi_device_fill_len(void *ptr)
|
||||
{
|
||||
acpi_device_fill_from_len(ptr, ptr + sizeof(uint16_t));
|
||||
}
|
||||
|
||||
/* Locate and return the ACPI name for this device */
|
||||
const char *acpi_device_name(const struct device *dev)
|
||||
{
|
||||
const struct device *pdev = dev;
|
||||
const char *name = NULL;
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
/* Check for device specific handler */
|
||||
if (dev->ops->acpi_name)
|
||||
return dev->ops->acpi_name(dev);
|
||||
|
||||
/* Walk up the tree to find if any parent can identify this device */
|
||||
while (pdev->bus) {
|
||||
pdev = pdev->bus->dev;
|
||||
if (!pdev)
|
||||
break;
|
||||
if (pdev->path.type == DEVICE_PATH_ROOT)
|
||||
break;
|
||||
if (pdev->ops && pdev->ops->acpi_name)
|
||||
name = pdev->ops->acpi_name(dev);
|
||||
if (name)
|
||||
return name;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* Locate and return the ACPI _HID (Hardware ID) for this device */
|
||||
const char *acpi_device_hid(const struct device *dev)
|
||||
{
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
/* Check for device specific handler */
|
||||
if (dev->ops->acpi_hid)
|
||||
return dev->ops->acpi_hid(dev);
|
||||
|
||||
/*
|
||||
* Don't walk up the tree to find any parent that can identify this device, as
|
||||
* PNP devices are hard to identify.
|
||||
*/
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* Generate unique ID based on the ACPI path.
|
||||
* Collisions on the same _HID are possible but very unlikely.
|
||||
*/
|
||||
uint32_t acpi_device_uid(const struct device *dev)
|
||||
{
|
||||
const char *path = acpi_device_path(dev);
|
||||
if (!path)
|
||||
return 0;
|
||||
|
||||
return CRC(path, strlen(path), crc32_byte);
|
||||
}
|
||||
|
||||
/* Recursive function to find the root device and print a path from there */
|
||||
static ssize_t acpi_device_path_fill(const struct device *dev, char *buf,
|
||||
size_t buf_len, size_t cur)
|
||||
{
|
||||
const char *name = acpi_device_name(dev);
|
||||
ssize_t next = 0;
|
||||
|
||||
if (!name)
|
||||
return -1;
|
||||
|
||||
/*
|
||||
* Make sure this name segment will fit, including the path segment
|
||||
* separator and possible NUL terminator if this is the last segment.
|
||||
*/
|
||||
if (!dev || (cur + strlen(name) + 2) > buf_len)
|
||||
return cur;
|
||||
|
||||
/* Walk up the tree to the root device */
|
||||
if (dev->path.type != DEVICE_PATH_ROOT && dev->bus && dev->bus->dev)
|
||||
next = acpi_device_path_fill(dev->bus->dev, buf, buf_len, cur);
|
||||
if (next < 0)
|
||||
return next;
|
||||
|
||||
/* Fill in the path from the root device */
|
||||
next += snprintf(buf + next, buf_len - next, "%s%s",
|
||||
(dev->path.type == DEVICE_PATH_ROOT
|
||||
|| (strlen(name) == 0)) ?
|
||||
"" : ".", name);
|
||||
|
||||
return next;
|
||||
}
|
||||
|
||||
/*
|
||||
* Warning: just as with dev_path() this uses a static buffer
|
||||
* so should not be called mulitple times in one statement
|
||||
*/
|
||||
const char *acpi_device_path(const struct device *dev)
|
||||
{
|
||||
static char buf[DEVICE_PATH_MAX] = {};
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
if (acpi_device_path_fill(dev, buf, sizeof(buf), 0) <= 0)
|
||||
return NULL;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Return the path of the parent device as the ACPI Scope for this device */
|
||||
const char *acpi_device_scope(const struct device *dev)
|
||||
{
|
||||
static char buf[DEVICE_PATH_MAX] = {};
|
||||
|
||||
if (!dev || !dev->bus || !dev->bus->dev)
|
||||
return NULL;
|
||||
|
||||
if (acpi_device_path_fill(dev->bus->dev, buf, sizeof(buf), 0) <= 0)
|
||||
return NULL;
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
/* Concatenate the device path and provided name suffix */
|
||||
const char *acpi_device_path_join(const struct device *dev, const char *name)
|
||||
{
|
||||
static char buf[DEVICE_PATH_MAX] = {};
|
||||
ssize_t len;
|
||||
|
||||
if (!dev)
|
||||
return NULL;
|
||||
|
||||
/* Build the path of this device */
|
||||
len = acpi_device_path_fill(dev, buf, sizeof(buf), 0);
|
||||
if (len <= 0)
|
||||
return NULL;
|
||||
|
||||
/* Ensure there is room for the added name, separator, and NUL */
|
||||
if ((len + strlen(name) + 2) > sizeof(buf))
|
||||
return NULL;
|
||||
snprintf(buf + len, sizeof(buf) - len, ".%s", name);
|
||||
|
||||
return buf;
|
||||
}
|
||||
|
||||
int acpi_device_status(const struct device *dev)
|
||||
{
|
||||
if (!dev->enabled)
|
||||
return ACPI_STATUS_DEVICE_ALL_OFF;
|
||||
if (dev->hidden)
|
||||
return ACPI_STATUS_DEVICE_HIDDEN_ON;
|
||||
return ACPI_STATUS_DEVICE_ALL_ON;
|
||||
}
|
||||
|
||||
|
||||
/* Write the unique _UID based on ACPI device path. */
|
||||
void acpi_device_write_uid(const struct device *dev)
|
||||
{
|
||||
acpigen_write_name_integer("_UID", acpi_device_uid(dev));
|
||||
}
|
||||
|
||||
/* ACPI 6.1 section 6.4.3.6: Extended Interrupt Descriptor */
|
||||
void acpi_device_write_interrupt(const struct acpi_irq *irq)
|
||||
{
|
||||
void *desc_length;
|
||||
uint8_t flags;
|
||||
|
||||
if (!irq || !irq->pin)
|
||||
return;
|
||||
|
||||
/* This is supported by GpioInt() but not Interrupt() */
|
||||
if (irq->polarity == ACPI_IRQ_ACTIVE_BOTH)
|
||||
return;
|
||||
|
||||
/* Byte 0: Descriptor Type */
|
||||
acpigen_emit_byte(ACPI_DESCRIPTOR_INTERRUPT);
|
||||
|
||||
/* Byte 1-2: Length (filled in later) */
|
||||
desc_length = acpi_device_write_zero_len();
|
||||
|
||||
/*
|
||||
* 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(flags);
|
||||
|
||||
/* Byte 4: Interrupt Table Entry Count */
|
||||
acpigen_emit_byte(1);
|
||||
|
||||
/* Byte 5-8: Interrupt Number */
|
||||
acpigen_emit_dword(irq->pin);
|
||||
|
||||
/* Fill in Descriptor Length (account for len word) */
|
||||
acpi_device_fill_len(desc_length);
|
||||
}
|
||||
|
||||
/* ACPI 6.1 section 6.4.3.8.1 - GPIO Interrupt or I/O */
|
||||
void acpi_device_write_gpio(const struct acpi_gpio *gpio)
|
||||
{
|
||||
void *start, *desc_length;
|
||||
void *pin_table_offset, *vendor_data_offset, *resource_offset;
|
||||
uint16_t flags = 0;
|
||||
int pin;
|
||||
|
||||
if (!gpio || gpio->type > ACPI_GPIO_TYPE_IO)
|
||||
return;
|
||||
|
||||
start = acpigen_get_current();
|
||||
|
||||
/* Byte 0: Descriptor Type */
|
||||
acpigen_emit_byte(ACPI_DESCRIPTOR_GPIO);
|
||||
|
||||
/* Byte 1-2: Length (fill in later) */
|
||||
desc_length = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 3: Revision ID */
|
||||
acpigen_emit_byte(ACPI_GPIO_REVISION_ID);
|
||||
|
||||
/* Byte 4: GpioIo or GpioInt */
|
||||
acpigen_emit_byte(gpio->type);
|
||||
|
||||
/*
|
||||
* Byte 5-6: General Flags
|
||||
* [15:1]: 0 => Reserved
|
||||
* [0]: 1 => ResourceConsumer
|
||||
*/
|
||||
acpigen_emit_word(1 << 0);
|
||||
|
||||
switch (gpio->type) {
|
||||
case ACPI_GPIO_TYPE_INTERRUPT:
|
||||
/*
|
||||
* Byte 7-8: GPIO Interrupt Flags
|
||||
* [15:5]: 0 => Reserved
|
||||
* [4]: Wake (0=NO_WAKE 1=WAKE)
|
||||
* [3]: Sharing (0=EXCLUSIVE 1=SHARED)
|
||||
* [2:1]: Polarity (0=HIGH 1=LOW 2=BOTH)
|
||||
* [0]: Mode (0=LEVEL 1=EDGE)
|
||||
*/
|
||||
if (gpio->irq.mode == ACPI_IRQ_EDGE_TRIGGERED)
|
||||
flags |= 1 << 0;
|
||||
if (gpio->irq.shared == ACPI_IRQ_SHARED)
|
||||
flags |= 1 << 3;
|
||||
if (gpio->irq.wake == ACPI_IRQ_WAKE)
|
||||
flags |= 1 << 4;
|
||||
|
||||
switch (gpio->irq.polarity) {
|
||||
case ACPI_IRQ_ACTIVE_HIGH:
|
||||
flags |= 0 << 1;
|
||||
break;
|
||||
case ACPI_IRQ_ACTIVE_LOW:
|
||||
flags |= 1 << 1;
|
||||
break;
|
||||
case ACPI_IRQ_ACTIVE_BOTH:
|
||||
flags |= 2 << 1;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
|
||||
case ACPI_GPIO_TYPE_IO:
|
||||
/*
|
||||
* Byte 7-8: GPIO IO Flags
|
||||
* [15:4]: 0 => Reserved
|
||||
* [3]: Sharing (0=EXCLUSIVE 1=SHARED)
|
||||
* [2]: 0 => Reserved
|
||||
* [1:0]: IO Restriction
|
||||
* 0 => IoRestrictionNone
|
||||
* 1 => IoRestrictionInputOnly
|
||||
* 2 => IoRestrictionOutputOnly
|
||||
* 3 => IoRestrictionNoneAndPreserve
|
||||
*/
|
||||
flags |= gpio->io_restrict & 3;
|
||||
if (gpio->io_shared)
|
||||
flags |= 1 << 3;
|
||||
break;
|
||||
}
|
||||
acpigen_emit_word(flags);
|
||||
|
||||
/*
|
||||
* Byte 9: Pin Configuration
|
||||
* 0x01 => Default (no configuration applied)
|
||||
* 0x02 => Pull-up
|
||||
* 0x03 => Pull-down
|
||||
* 0x04-0x7F => Reserved
|
||||
* 0x80-0xff => Vendor defined
|
||||
*/
|
||||
acpigen_emit_byte(gpio->pull);
|
||||
|
||||
/* Byte 10-11: Output Drive Strength in 1/100 mA */
|
||||
acpigen_emit_word(gpio->output_drive_strength);
|
||||
|
||||
/* Byte 12-13: Debounce Timeout in 1/100 ms */
|
||||
acpigen_emit_word(gpio->interrupt_debounce_timeout);
|
||||
|
||||
/* Byte 14-15: Pin Table Offset, relative to start */
|
||||
pin_table_offset = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 16: Reserved */
|
||||
acpigen_emit_byte(0);
|
||||
|
||||
/* Byte 17-18: Resource Source Name Offset, relative to start */
|
||||
resource_offset = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 19-20: Vendor Data Offset, relative to start */
|
||||
vendor_data_offset = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 21-22: Vendor Data Length */
|
||||
acpigen_emit_word(0);
|
||||
|
||||
/* Fill in Pin Table Offset */
|
||||
acpi_device_fill_from_len(pin_table_offset, start);
|
||||
|
||||
/* Pin Table, one word for each pin */
|
||||
for (pin = 0; pin < gpio->pin_count; pin++) {
|
||||
uint16_t acpi_pin = gpio->pins[pin];
|
||||
#if CONFIG(GENERIC_GPIO_LIB)
|
||||
acpi_pin = gpio_acpi_pin(acpi_pin);
|
||||
#endif
|
||||
acpigen_emit_word(acpi_pin);
|
||||
}
|
||||
|
||||
/* Fill in Resource Source Name Offset */
|
||||
acpi_device_fill_from_len(resource_offset, start);
|
||||
|
||||
/* Resource Source Name String */
|
||||
#if CONFIG(GENERIC_GPIO_LIB)
|
||||
acpigen_emit_string(gpio->resource ? : gpio_acpi_path(gpio->pins[0]));
|
||||
#else
|
||||
acpigen_emit_string(gpio->resource);
|
||||
#endif
|
||||
|
||||
/* Fill in Vendor Data Offset */
|
||||
acpi_device_fill_from_len(vendor_data_offset, start);
|
||||
|
||||
/* Fill in GPIO Descriptor Length (account for len word) */
|
||||
acpi_device_fill_len(desc_length);
|
||||
}
|
||||
|
||||
/* ACPI 6.1 section 6.4.3.8.2.1 - I2cSerialBus() */
|
||||
void acpi_device_write_i2c(const struct acpi_i2c *i2c)
|
||||
{
|
||||
void *desc_length, *type_length;
|
||||
|
||||
/* Byte 0: Descriptor Type */
|
||||
acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS);
|
||||
|
||||
/* Byte 1+2: Length (filled in later) */
|
||||
desc_length = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 3: Revision ID */
|
||||
acpigen_emit_byte(ACPI_I2C_SERIAL_BUS_REVISION_ID);
|
||||
|
||||
/* Byte 4: Resource Source Index is Reserved */
|
||||
acpigen_emit_byte(0);
|
||||
|
||||
/* Byte 5: Serial Bus Type is I2C */
|
||||
acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_I2C);
|
||||
|
||||
/*
|
||||
* Byte 6: Flags
|
||||
* [7:2]: 0 => Reserved
|
||||
* [1]: 1 => ResourceConsumer
|
||||
* [0]: 0 => ControllerInitiated
|
||||
*/
|
||||
acpigen_emit_byte(1 << 1);
|
||||
|
||||
/*
|
||||
* Byte 7-8: Type Specific Flags
|
||||
* [15:1]: 0 => Reserved
|
||||
* [0]: 0 => 7bit, 1 => 10bit
|
||||
*/
|
||||
acpigen_emit_word(i2c->mode_10bit);
|
||||
|
||||
/* Byte 9: Type Specific Revision ID */
|
||||
acpigen_emit_byte(ACPI_I2C_TYPE_SPECIFIC_REVISION_ID);
|
||||
|
||||
/* Byte 10-11: I2C Type Data Length */
|
||||
type_length = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 12-15: I2C Bus Speed */
|
||||
acpigen_emit_dword(i2c->speed);
|
||||
|
||||
/* Byte 16-17: I2C Slave Address */
|
||||
acpigen_emit_word(i2c->address);
|
||||
|
||||
/* Fill in Type Data Length */
|
||||
acpi_device_fill_len(type_length);
|
||||
|
||||
/* Byte 18+: ResourceSource */
|
||||
acpigen_emit_string(i2c->resource);
|
||||
|
||||
/* Fill in I2C Descriptor Length */
|
||||
acpi_device_fill_len(desc_length);
|
||||
}
|
||||
|
||||
/* ACPI 6.1 section 6.4.3.8.2.2 - SpiSerialBus() */
|
||||
void acpi_device_write_spi(const struct acpi_spi *spi)
|
||||
{
|
||||
void *desc_length, *type_length;
|
||||
uint16_t flags = 0;
|
||||
|
||||
/* Byte 0: Descriptor Type */
|
||||
acpigen_emit_byte(ACPI_DESCRIPTOR_SERIAL_BUS);
|
||||
|
||||
/* Byte 1+2: Length (filled in later) */
|
||||
desc_length = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 3: Revision ID */
|
||||
acpigen_emit_byte(ACPI_SPI_SERIAL_BUS_REVISION_ID);
|
||||
|
||||
/* Byte 4: Resource Source Index is Reserved */
|
||||
acpigen_emit_byte(0);
|
||||
|
||||
/* Byte 5: Serial Bus Type is SPI */
|
||||
acpigen_emit_byte(ACPI_SERIAL_BUS_TYPE_SPI);
|
||||
|
||||
/*
|
||||
* Byte 6: Flags
|
||||
* [7:2]: 0 => Reserved
|
||||
* [1]: 1 => ResourceConsumer
|
||||
* [0]: 0 => ControllerInitiated
|
||||
*/
|
||||
acpigen_emit_byte(1 << 1);
|
||||
|
||||
/*
|
||||
* Byte 7-8: Type Specific Flags
|
||||
* [15:2]: 0 => Reserved
|
||||
* [1]: 0 => ActiveLow, 1 => ActiveHigh
|
||||
* [0]: 0 => FourWire, 1 => ThreeWire
|
||||
*/
|
||||
if (spi->wire_mode == SPI_3_WIRE_MODE)
|
||||
flags |= 1 << 0;
|
||||
if (spi->device_select_polarity == SPI_POLARITY_HIGH)
|
||||
flags |= 1 << 1;
|
||||
acpigen_emit_word(flags);
|
||||
|
||||
/* Byte 9: Type Specific Revision ID */
|
||||
acpigen_emit_byte(ACPI_SPI_TYPE_SPECIFIC_REVISION_ID);
|
||||
|
||||
/* Byte 10-11: SPI Type Data Length */
|
||||
type_length = acpi_device_write_zero_len();
|
||||
|
||||
/* Byte 12-15: Connection Speed */
|
||||
acpigen_emit_dword(spi->speed);
|
||||
|
||||
/* Byte 16: Data Bit Length */
|
||||
acpigen_emit_byte(spi->data_bit_length);
|
||||
|
||||
/* Byte 17: Clock Phase */
|
||||
acpigen_emit_byte(spi->clock_phase);
|
||||
|
||||
/* Byte 18: Clock Polarity */
|
||||
acpigen_emit_byte(spi->clock_polarity);
|
||||
|
||||
/* Byte 19-20: Device Selection */
|
||||
acpigen_emit_word(spi->device_select);
|
||||
|
||||
/* Fill in Type Data Length */
|
||||
acpi_device_fill_len(type_length);
|
||||
|
||||
/* Byte 21+: ResourceSource String */
|
||||
acpigen_emit_string(spi->resource);
|
||||
|
||||
/* Fill in SPI Descriptor Length */
|
||||
acpi_device_fill_len(desc_length);
|
||||
}
|
||||
|
||||
/* PowerResource() with Enable and/or Reset control */
|
||||
void acpi_device_add_power_res(const struct acpi_power_res_params *params)
|
||||
{
|
||||
static const char * const power_res_dev_states[] = { "_PR0", "_PR3" };
|
||||
unsigned int reset_gpio = params->reset_gpio ? params->reset_gpio->pins[0] : 0;
|
||||
unsigned int enable_gpio = params->enable_gpio ? params->enable_gpio->pins[0] : 0;
|
||||
unsigned int stop_gpio = params->stop_gpio ? params->stop_gpio->pins[0] : 0;
|
||||
|
||||
if (!reset_gpio && !enable_gpio && !stop_gpio)
|
||||
return;
|
||||
|
||||
/* PowerResource (PRIC, 0, 0) */
|
||||
acpigen_write_power_res("PRIC", 0, 0, power_res_dev_states,
|
||||
ARRAY_SIZE(power_res_dev_states));
|
||||
|
||||
/* Method (_STA, 0, NotSerialized) { Return (0x1) } */
|
||||
acpigen_write_STA(0x1);
|
||||
|
||||
/* Method (_ON, 0, Serialized) */
|
||||
acpigen_write_method_serialized("_ON", 0);
|
||||
if (reset_gpio)
|
||||
acpigen_enable_tx_gpio(params->reset_gpio);
|
||||
if (enable_gpio) {
|
||||
acpigen_enable_tx_gpio(params->enable_gpio);
|
||||
if (params->enable_delay_ms)
|
||||
acpigen_write_sleep(params->enable_delay_ms);
|
||||
}
|
||||
if (reset_gpio) {
|
||||
acpigen_disable_tx_gpio(params->reset_gpio);
|
||||
if (params->reset_delay_ms)
|
||||
acpigen_write_sleep(params->reset_delay_ms);
|
||||
}
|
||||
if (stop_gpio) {
|
||||
acpigen_disable_tx_gpio(params->stop_gpio);
|
||||
if (params->stop_delay_ms)
|
||||
acpigen_write_sleep(params->stop_delay_ms);
|
||||
}
|
||||
acpigen_pop_len(); /* _ON method */
|
||||
|
||||
/* Method (_OFF, 0, Serialized) */
|
||||
acpigen_write_method_serialized("_OFF", 0);
|
||||
if (stop_gpio) {
|
||||
acpigen_enable_tx_gpio(params->stop_gpio);
|
||||
if (params->stop_off_delay_ms)
|
||||
acpigen_write_sleep(params->stop_off_delay_ms);
|
||||
}
|
||||
if (reset_gpio) {
|
||||
acpigen_enable_tx_gpio(params->reset_gpio);
|
||||
if (params->reset_off_delay_ms)
|
||||
acpigen_write_sleep(params->reset_off_delay_ms);
|
||||
}
|
||||
if (enable_gpio) {
|
||||
acpigen_disable_tx_gpio(params->enable_gpio);
|
||||
if (params->enable_off_delay_ms)
|
||||
acpigen_write_sleep(params->enable_off_delay_ms);
|
||||
}
|
||||
acpigen_pop_len(); /* _OFF method */
|
||||
|
||||
acpigen_pop_len(); /* PowerResource PRIC */
|
||||
}
|
||||
|
||||
static void acpi_dp_write_array(const struct acpi_dp *array);
|
||||
static void acpi_dp_write_value(const struct acpi_dp *prop)
|
||||
{
|
||||
switch (prop->type) {
|
||||
case ACPI_DP_TYPE_INTEGER:
|
||||
acpigen_write_integer(prop->integer);
|
||||
break;
|
||||
case ACPI_DP_TYPE_STRING:
|
||||
case ACPI_DP_TYPE_CHILD:
|
||||
acpigen_write_string(prop->string);
|
||||
break;
|
||||
case ACPI_DP_TYPE_REFERENCE:
|
||||
acpigen_emit_namestring(prop->string);
|
||||
break;
|
||||
case ACPI_DP_TYPE_ARRAY:
|
||||
acpi_dp_write_array(prop->array);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* Package (2) { "prop->name", VALUE } */
|
||||
static void acpi_dp_write_property(const struct acpi_dp *prop)
|
||||
{
|
||||
acpigen_write_package(2);
|
||||
acpigen_write_string(prop->name);
|
||||
acpi_dp_write_value(prop);
|
||||
acpigen_pop_len();
|
||||
}
|
||||
|
||||
/* Write array of Device Properties */
|
||||
static void acpi_dp_write_array(const struct acpi_dp *array)
|
||||
{
|
||||
const struct acpi_dp *dp;
|
||||
char *pkg_count;
|
||||
|
||||
/* Package element count determined as it is populated */
|
||||
pkg_count = acpigen_write_package(0);
|
||||
|
||||
/*
|
||||
* Only acpi_dp of type DP_TYPE_TABLE is allowed to be an array.
|
||||
* DP_TYPE_TABLE does not have a value to be written. Thus, start
|
||||
* the loop from next type in the array.
|
||||
*/
|
||||
for (dp = array->next; dp; dp = dp->next) {
|
||||
acpi_dp_write_value(dp);
|
||||
(*pkg_count)++;
|
||||
}
|
||||
|
||||
acpigen_pop_len();
|
||||
}
|
||||
|
||||
static void acpi_dp_free(struct acpi_dp *dp)
|
||||
{
|
||||
while (dp) {
|
||||
struct acpi_dp *p = dp->next;
|
||||
|
||||
switch (dp->type) {
|
||||
case ACPI_DP_TYPE_CHILD:
|
||||
acpi_dp_free(dp->child);
|
||||
break;
|
||||
case ACPI_DP_TYPE_ARRAY:
|
||||
acpi_dp_free(dp->array);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
free(dp);
|
||||
dp = p;
|
||||
}
|
||||
}
|
||||
|
||||
void acpi_dp_write(struct acpi_dp *table)
|
||||
{
|
||||
struct acpi_dp *dp, *prop;
|
||||
char *dp_count, *prop_count = NULL;
|
||||
int child_count = 0;
|
||||
|
||||
if (!table || table->type != ACPI_DP_TYPE_TABLE || !table->next)
|
||||
return;
|
||||
|
||||
/* Name (name) */
|
||||
acpigen_write_name(table->name);
|
||||
|
||||
/* Device Property list starts with the next entry */
|
||||
prop = table->next;
|
||||
|
||||
/* Package (DP), default to assuming no properties or children */
|
||||
dp_count = acpigen_write_package(0);
|
||||
|
||||
/* Print base properties */
|
||||
for (dp = prop; dp; dp = dp->next) {
|
||||
if (dp->type == ACPI_DP_TYPE_CHILD) {
|
||||
child_count++;
|
||||
} else {
|
||||
/*
|
||||
* The UUID and package is only added when
|
||||
* we come across the first property. This
|
||||
* is to avoid creating a zero-length package
|
||||
* in situations where there are only children.
|
||||
*/
|
||||
if (!prop_count) {
|
||||
*dp_count += 2;
|
||||
/* ToUUID (ACPI_DP_UUID) */
|
||||
acpigen_write_uuid(ACPI_DP_UUID);
|
||||
/*
|
||||
* Package (PROP), element count determined as
|
||||
* it is populated
|
||||
*/
|
||||
prop_count = acpigen_write_package(0);
|
||||
}
|
||||
(*prop_count)++;
|
||||
acpi_dp_write_property(dp);
|
||||
}
|
||||
}
|
||||
if (prop_count) {
|
||||
/* Package (PROP) length, if a package was written */
|
||||
acpigen_pop_len();
|
||||
}
|
||||
|
||||
if (child_count) {
|
||||
/* Update DP package count to 2 or 4 */
|
||||
*dp_count += 2;
|
||||
/* ToUUID (ACPI_DP_CHILD_UUID) */
|
||||
acpigen_write_uuid(ACPI_DP_CHILD_UUID);
|
||||
|
||||
/* Print child pointer properties */
|
||||
acpigen_write_package(child_count);
|
||||
|
||||
for (dp = prop; dp; dp = dp->next)
|
||||
if (dp->type == ACPI_DP_TYPE_CHILD)
|
||||
acpi_dp_write_property(dp);
|
||||
/* Package (CHILD) length */
|
||||
acpigen_pop_len();
|
||||
}
|
||||
|
||||
/* Package (DP) length */
|
||||
acpigen_pop_len();
|
||||
|
||||
/* Recursively parse children into separate tables */
|
||||
for (dp = prop; dp; dp = dp->next)
|
||||
if (dp->type == ACPI_DP_TYPE_CHILD)
|
||||
acpi_dp_write(dp->child);
|
||||
|
||||
/* Clean up */
|
||||
acpi_dp_free(table);
|
||||
}
|
||||
|
||||
static struct acpi_dp *acpi_dp_new(struct acpi_dp *dp, enum acpi_dp_type type,
|
||||
const char *name)
|
||||
{
|
||||
struct acpi_dp *new;
|
||||
|
||||
new = malloc(sizeof(struct acpi_dp));
|
||||
if (!new)
|
||||
return NULL;
|
||||
|
||||
memset(new, 0, sizeof(*new));
|
||||
new->type = type;
|
||||
new->name = name;
|
||||
|
||||
if (dp) {
|
||||
/* Add to end of property list */
|
||||
while (dp->next)
|
||||
dp = dp->next;
|
||||
dp->next = new;
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_new_table(const char *name)
|
||||
{
|
||||
return acpi_dp_new(NULL, ACPI_DP_TYPE_TABLE, name);
|
||||
}
|
||||
|
||||
size_t acpi_dp_add_property_list(struct acpi_dp *dp,
|
||||
const struct acpi_dp *property_list,
|
||||
size_t property_count)
|
||||
{
|
||||
const struct acpi_dp *prop;
|
||||
size_t i, properties_added = 0;
|
||||
|
||||
if (!dp || !property_list)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < property_count; i++) {
|
||||
prop = &property_list[i];
|
||||
|
||||
if (prop->type == ACPI_DP_TYPE_UNKNOWN || !prop->name)
|
||||
continue;
|
||||
|
||||
switch (prop->type) {
|
||||
case ACPI_DP_TYPE_INTEGER:
|
||||
acpi_dp_add_integer(dp, prop->name, prop->integer);
|
||||
break;
|
||||
case ACPI_DP_TYPE_STRING:
|
||||
acpi_dp_add_string(dp, prop->name, prop->string);
|
||||
break;
|
||||
case ACPI_DP_TYPE_REFERENCE:
|
||||
acpi_dp_add_reference(dp, prop->name, prop->string);
|
||||
break;
|
||||
case ACPI_DP_TYPE_ARRAY:
|
||||
acpi_dp_add_array(dp, prop->array);
|
||||
break;
|
||||
case ACPI_DP_TYPE_CHILD:
|
||||
acpi_dp_add_child(dp, prop->name, prop->child);
|
||||
break;
|
||||
default:
|
||||
continue;
|
||||
}
|
||||
|
||||
++properties_added;
|
||||
}
|
||||
|
||||
return properties_added;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_integer(struct acpi_dp *dp, const char *name,
|
||||
uint64_t value)
|
||||
{
|
||||
if (!dp)
|
||||
return NULL;
|
||||
|
||||
struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_INTEGER, name);
|
||||
|
||||
if (new)
|
||||
new->integer = value;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_string(struct acpi_dp *dp, const char *name,
|
||||
const char *string)
|
||||
{
|
||||
if (!dp)
|
||||
return NULL;
|
||||
|
||||
struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_STRING, name);
|
||||
|
||||
if (new)
|
||||
new->string = string;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_reference(struct acpi_dp *dp, const char *name,
|
||||
const char *reference)
|
||||
{
|
||||
if (!dp)
|
||||
return NULL;
|
||||
|
||||
struct acpi_dp *new = acpi_dp_new(dp, ACPI_DP_TYPE_REFERENCE, name);
|
||||
|
||||
if (new)
|
||||
new->string = reference;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_child(struct acpi_dp *dp, const char *name,
|
||||
struct acpi_dp *child)
|
||||
{
|
||||
struct acpi_dp *new;
|
||||
|
||||
if (!dp || !child || child->type != ACPI_DP_TYPE_TABLE)
|
||||
return NULL;
|
||||
|
||||
new = acpi_dp_new(dp, ACPI_DP_TYPE_CHILD, name);
|
||||
if (new) {
|
||||
new->child = child;
|
||||
new->string = child->name;
|
||||
}
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_array(struct acpi_dp *dp, struct acpi_dp *array)
|
||||
{
|
||||
struct acpi_dp *new;
|
||||
|
||||
if (!dp || !array || array->type != ACPI_DP_TYPE_TABLE)
|
||||
return NULL;
|
||||
|
||||
new = acpi_dp_new(dp, ACPI_DP_TYPE_ARRAY, array->name);
|
||||
if (new)
|
||||
new->array = array;
|
||||
|
||||
return new;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_integer_array(struct acpi_dp *dp, const char *name,
|
||||
const uint64_t *array, int len)
|
||||
{
|
||||
struct acpi_dp *dp_array;
|
||||
int i;
|
||||
|
||||
if (!dp || len <= 0)
|
||||
return NULL;
|
||||
|
||||
dp_array = acpi_dp_new_table(name);
|
||||
if (!dp_array)
|
||||
return NULL;
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
if (!acpi_dp_add_integer(dp_array, NULL, array[i]))
|
||||
break;
|
||||
|
||||
acpi_dp_add_array(dp, dp_array);
|
||||
|
||||
return dp_array;
|
||||
}
|
||||
|
||||
struct acpi_dp *acpi_dp_add_gpio(struct acpi_dp *dp, const char *name,
|
||||
const char *ref, int index, int pin,
|
||||
int active_low)
|
||||
{
|
||||
if (!dp)
|
||||
return NULL;
|
||||
|
||||
struct acpi_dp *gpio = acpi_dp_new_table(name);
|
||||
|
||||
if (!gpio)
|
||||
return NULL;
|
||||
|
||||
/* The device that has _CRS containing GpioIO()/GpioInt() */
|
||||
acpi_dp_add_reference(gpio, NULL, ref);
|
||||
|
||||
/* Index of the GPIO resource in _CRS starting from zero */
|
||||
acpi_dp_add_integer(gpio, NULL, index);
|
||||
|
||||
/* Pin in the GPIO resource, typically zero */
|
||||
acpi_dp_add_integer(gpio, NULL, pin);
|
||||
|
||||
/* Set if pin is active low */
|
||||
acpi_dp_add_integer(gpio, NULL, active_low);
|
||||
|
||||
acpi_dp_add_array(dp, gpio);
|
||||
|
||||
return gpio;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function writes a PCI device with _ADR object:
|
||||
* Example:
|
||||
* Scope (\_SB.PCI0)
|
||||
* {
|
||||
* Device (IGFX)
|
||||
* {
|
||||
* Name (_ADR, 0x0000000000000000)
|
||||
* Method (_STA, 0, NotSerialized) { Return (status) }
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
void acpi_device_write_pci_dev(const struct device *dev)
|
||||
{
|
||||
const char *scope = acpi_device_scope(dev);
|
||||
const char *name = acpi_device_name(dev);
|
||||
|
||||
assert(dev->path.type == DEVICE_PATH_PCI);
|
||||
assert(name);
|
||||
assert(scope);
|
||||
|
||||
acpigen_write_scope(scope);
|
||||
acpigen_write_device(name);
|
||||
|
||||
acpigen_write_ADR_pci_device(dev);
|
||||
acpigen_write_STA(acpi_device_status(dev));
|
||||
|
||||
acpigen_pop_len(); /* Device */
|
||||
acpigen_pop_len(); /* Scope */
|
||||
}
|
160
src/acpi/acpi_pld.c
Normal file
160
src/acpi/acpi_pld.c
Normal file
@@ -0,0 +1,160 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/* This file is part of the coreboot project. */
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <arch/acpi.h>
|
||||
#include <arch/acpi_pld.h>
|
||||
|
||||
int acpi_pld_fill_usb(struct acpi_pld *pld, enum acpi_upc_type type,
|
||||
struct acpi_pld_group *group)
|
||||
{
|
||||
if (!pld)
|
||||
return -1;
|
||||
|
||||
memset(pld, 0, sizeof(struct acpi_pld));
|
||||
|
||||
/* Set defaults */
|
||||
pld->ignore_color = 1;
|
||||
pld->panel = PLD_PANEL_UNKNOWN;
|
||||
pld->vertical_position = PLD_VERTICAL_POSITION_CENTER;
|
||||
pld->horizontal_position = PLD_HORIZONTAL_POSITION_CENTER;
|
||||
pld->rotation = PLD_ROTATE_0;
|
||||
pld->visible = 1;
|
||||
pld->group.token = group->token;
|
||||
pld->group.position = group->position;
|
||||
|
||||
/* Set the shape based on port type */
|
||||
switch (type) {
|
||||
case UPC_TYPE_A:
|
||||
case UPC_TYPE_USB3_A:
|
||||
case UPC_TYPE_USB3_POWER_B:
|
||||
pld->shape = PLD_SHAPE_HORIZONTAL_RECTANGLE;
|
||||
break;
|
||||
case UPC_TYPE_MINI_AB:
|
||||
case UPC_TYPE_USB3_B:
|
||||
pld->shape = PLD_SHAPE_CHAMFERED;
|
||||
break;
|
||||
case UPC_TYPE_USB3_MICRO_B:
|
||||
case UPC_TYPE_USB3_MICRO_AB:
|
||||
pld->shape = PLD_SHAPE_HORIZONTAL_TRAPEZOID;
|
||||
break;
|
||||
case UPC_TYPE_C_USB2_ONLY:
|
||||
case UPC_TYPE_C_USB2_SS_SWITCH:
|
||||
case UPC_TYPE_C_USB2_SS:
|
||||
pld->shape = PLD_SHAPE_OVAL;
|
||||
break;
|
||||
case UPC_TYPE_INTERNAL:
|
||||
default:
|
||||
pld->shape = PLD_SHAPE_UNKNOWN;
|
||||
pld->visible = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int acpi_pld_to_buffer(const struct acpi_pld *pld, uint8_t *buf, int buf_len)
|
||||
{
|
||||
if (!pld || !buf)
|
||||
return -1;
|
||||
|
||||
memset(buf, 0, buf_len);
|
||||
|
||||
/* [0] Revision (=2) */
|
||||
buf[0] = 0x2;
|
||||
|
||||
if (pld->ignore_color) {
|
||||
/* [1] Ignore Color */
|
||||
buf[0] |= 0x80;
|
||||
} else {
|
||||
/* [15:8] Red Color */
|
||||
buf[1] = pld->color_red;
|
||||
/* [23:16] Green Color */
|
||||
buf[2] = pld->color_green;
|
||||
/* [31:24] Blue Color */
|
||||
buf[3] = pld->color_blue;
|
||||
}
|
||||
|
||||
/* [47:32] Width */
|
||||
buf[4] = pld->width & 0xff;
|
||||
buf[5] = pld->width >> 8;
|
||||
|
||||
/* [63:48] Height */
|
||||
buf[6] = pld->height & 0xff;
|
||||
buf[7] = pld->height >> 8;
|
||||
|
||||
/* [64] User Visible */
|
||||
buf[8] |= (pld->visible & 0x1);
|
||||
|
||||
/* [65] Dock */
|
||||
buf[8] |= (pld->dock & 0x1) << 1;
|
||||
|
||||
/* [66] Lid */
|
||||
buf[8] |= (pld->lid & 0x1) << 2;
|
||||
|
||||
/* [69:67] Panel */
|
||||
buf[8] |= (pld->panel & 0x7) << 3;
|
||||
|
||||
/* [71:70] Vertical Position */
|
||||
buf[8] |= (pld->vertical_position & 0x3) << 6;
|
||||
|
||||
/* [73:72] Horizontal Position */
|
||||
buf[9] |= (pld->horizontal_position & 0x3);
|
||||
|
||||
/* [77:74] Shape */
|
||||
buf[9] |= (pld->shape & 0xf) << 2;
|
||||
|
||||
/* [78] Orientation */
|
||||
buf[9] |= (pld->orientation & 0x1) << 6;
|
||||
|
||||
/* [86:79] Group Token (incorrectly defined as 1 bit in ACPI 6.2A) */
|
||||
buf[9] |= (pld->group.token & 0x1) << 7;
|
||||
buf[10] |= (pld->group.token >> 0x1) & 0x7f;
|
||||
|
||||
/* [94:87] Group Position */
|
||||
buf[10] |= (pld->group.position & 0x1) << 7;
|
||||
buf[11] |= (pld->group.position >> 0x1) & 0x7f;
|
||||
|
||||
/* [95] Bay */
|
||||
buf[11] |= (pld->bay & 0x1) << 7;
|
||||
|
||||
/* [96] Ejectable */
|
||||
buf[12] |= (pld->ejectable & 0x1);
|
||||
|
||||
/* [97] Ejectable with OSPM help */
|
||||
buf[12] |= (pld->ejectable_ospm & 0x1) << 1;
|
||||
|
||||
/* [105:98] Cabinet Number */
|
||||
buf[12] |= (pld->cabinet_number & 0x3f) << 2;
|
||||
buf[13] |= (pld->cabinet_number >> 6) & 0x3;
|
||||
|
||||
/* [113:106] Card Cage Number */
|
||||
buf[13] |= (pld->card_cage_number & 0x3f) << 2;
|
||||
buf[14] |= (pld->card_cage_number >> 6) & 0x3;
|
||||
|
||||
/* [114] PLD is a Reference Shape */
|
||||
buf[14] |= (pld->reference_shape & 0x1) << 2;
|
||||
|
||||
/* [118:115] Rotation */
|
||||
buf[14] |= (pld->rotation & 0xf) << 3;
|
||||
|
||||
/* [123:119] Draw Order */
|
||||
buf[14] |= (pld->draw_order & 0x1) << 7;
|
||||
buf[15] |= (pld->draw_order >> 1) & 0xf;
|
||||
|
||||
/* [127:124] Reserved */
|
||||
|
||||
/* Both 16 byte and 20 byte buffers are supported by the spec */
|
||||
if (buf_len == 20) {
|
||||
/* [143:128] Vertical Offset */
|
||||
buf[16] = pld->vertical_offset & 0xff;
|
||||
buf[17] = pld->vertical_offset >> 8;
|
||||
|
||||
/* [159:144] Horizontal Offset */
|
||||
buf[18] = pld->horizontal_offset & 0xff;
|
||||
buf[19] = pld->horizontal_offset >> 8;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
1888
src/acpi/acpigen.c
Normal file
1888
src/acpi/acpigen.c
Normal file
File diff suppressed because it is too large
Load Diff
52
src/acpi/acpigen_dsm.c
Normal file
52
src/acpi/acpigen_dsm.c
Normal file
@@ -0,0 +1,52 @@
|
||||
/* SPDX-License-Identifier: GPL-2.0-only */
|
||||
/* This file is part of the coreboot project. */
|
||||
|
||||
#include <arch/acpigen.h>
|
||||
#include <arch/acpigen_dsm.h>
|
||||
|
||||
/* ------------------- I2C HID DSM ---------------------------- */
|
||||
|
||||
#define ACPI_DSM_I2C_HID_UUID "3CDFF6F7-4267-4555-AD05-B30A3D8938DE"
|
||||
|
||||
static void i2c_hid_func0_cb(void *arg)
|
||||
{
|
||||
/* ToInteger (Arg1, Local2) */
|
||||
acpigen_write_to_integer(ARG1_OP, LOCAL2_OP);
|
||||
/* If (LEqual (Local2, 0x0)) */
|
||||
acpigen_write_if_lequal_op_int(LOCAL2_OP, 0x0);
|
||||
/* Return (Buffer (One) { 0x1f }) */
|
||||
acpigen_write_return_singleton_buffer(0x1f);
|
||||
acpigen_pop_len(); /* Pop : If */
|
||||
/* Else */
|
||||
acpigen_write_else();
|
||||
/* If (LEqual (Local2, 0x1)) */
|
||||
acpigen_write_if_lequal_op_int(LOCAL2_OP, 0x1);
|
||||
/* Return (Buffer (One) { 0x3f }) */
|
||||
acpigen_write_return_singleton_buffer(0x3f);
|
||||
acpigen_pop_len(); /* Pop : If */
|
||||
/* Else */
|
||||
acpigen_write_else();
|
||||
/* Return (Buffer (One) { 0x0 }) */
|
||||
acpigen_write_return_singleton_buffer(0x0);
|
||||
acpigen_pop_len(); /* Pop : Else */
|
||||
acpigen_pop_len(); /* Pop : Else */
|
||||
}
|
||||
|
||||
static void i2c_hid_func1_cb(void *arg)
|
||||
{
|
||||
struct dsm_i2c_hid_config *config = arg;
|
||||
acpigen_write_return_byte(config->hid_desc_reg_offset);
|
||||
}
|
||||
|
||||
static void (*i2c_hid_callbacks[2])(void *) = {
|
||||
i2c_hid_func0_cb,
|
||||
i2c_hid_func1_cb,
|
||||
};
|
||||
|
||||
void acpigen_write_dsm_i2c_hid(struct dsm_i2c_hid_config *config)
|
||||
{
|
||||
acpigen_write_dsm(ACPI_DSM_I2C_HID_UUID, i2c_hid_callbacks,
|
||||
ARRAY_SIZE(i2c_hid_callbacks), config);
|
||||
}
|
||||
|
||||
/* ------------------- End: I2C HID DSM ------------------------- */
|
302
src/acpi/acpigen_ps2_keybd.c
Normal file
302
src/acpi/acpigen_ps2_keybd.c
Normal file
@@ -0,0 +1,302 @@
|
||||
/*
|
||||
* This file is part of the coreboot project.
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-or-later
|
||||
*/
|
||||
|
||||
#include <arch/acpi.h>
|
||||
#include <arch/acpigen.h>
|
||||
#include <arch/acpigen_ps2_keybd.h>
|
||||
#include <console/console.h>
|
||||
#include <input-event-codes.h>
|
||||
|
||||
#define KEYMAP(scancode, keycode) (((uint32_t)(scancode) << 16) | (keycode & 0xFFFF))
|
||||
#define SCANCODE(keymap) ((keymap >> 16) & 0xFFFF)
|
||||
|
||||
/* Possible keymaps for function keys in the top row */
|
||||
static const uint32_t function_keymaps[] = {
|
||||
KEYMAP(0x3b, KEY_F1),
|
||||
KEYMAP(0x3c, KEY_F2),
|
||||
KEYMAP(0x3d, KEY_F3),
|
||||
KEYMAP(0x3e, KEY_F4),
|
||||
KEYMAP(0x3f, KEY_F5),
|
||||
KEYMAP(0x40, KEY_F6),
|
||||
KEYMAP(0x41, KEY_F7),
|
||||
KEYMAP(0x42, KEY_F8),
|
||||
KEYMAP(0x43, KEY_F9),
|
||||
KEYMAP(0x44, KEY_F10),
|
||||
KEYMAP(0x57, KEY_F11),
|
||||
KEYMAP(0x58, KEY_F12),
|
||||
KEYMAP(0x59, KEY_F13),
|
||||
KEYMAP(0x5a, KEY_F14),
|
||||
KEYMAP(0x5b, KEY_F15),
|
||||
};
|
||||
|
||||
/*
|
||||
* Possible keymaps for action keys in the top row. This is a superset of
|
||||
* possible keys. Individual keyboards will have a subset of these keys.
|
||||
* The scancodes are true / condensed 1 byte scancodes from set-1
|
||||
*/
|
||||
static const uint32_t action_keymaps[] = {
|
||||
[PS2_KEY_BACK] = KEYMAP(0xea, KEY_BACK), /* e06a */
|
||||
[PS2_KEY_FORWARD] = KEYMAP(0xe9, KEY_FORWARD), /* e069 */
|
||||
[PS2_KEY_REFRESH] = KEYMAP(0xe7, KEY_REFRESH), /* e067 */
|
||||
[PS2_KEY_FULLSCREEN] = KEYMAP(0x91, KEY_FULL_SCREEN), /* e011 */
|
||||
[PS2_KEY_OVERVIEW] = KEYMAP(0x92, KEY_SCALE), /* e012 */
|
||||
[PS2_KEY_VOL_MUTE] = KEYMAP(0xa0, KEY_MUTE), /* e020 */
|
||||
[PS2_KEY_VOL_DOWN] = KEYMAP(0xae, KEY_VOLUMEDOWN), /* e02e */
|
||||
[PS2_KEY_VOL_UP] = KEYMAP(0xb0, KEY_VOLUMEUP), /* e030 */
|
||||
[PS2_KEY_PLAY_PAUSE] = KEYMAP(0x9a, KEY_PLAYPAUSE), /* e01a */
|
||||
[PS2_KEY_NEXT_TRACK] = KEYMAP(0x99, KEY_NEXTSONG), /* e019 */
|
||||
[PS2_KEY_PREV_TRACK] = KEYMAP(0x90, KEY_PREVIOUSSONG), /* e010 */
|
||||
[PS2_KEY_SNAPSHOT] = KEYMAP(0x93, KEY_SYSRQ), /* e013 */
|
||||
[PS2_KEY_BRIGHTNESS_DOWN] = KEYMAP(0x94, KEY_BRIGHTNESSDOWN),/* e014 */
|
||||
[PS2_KEY_BRIGHTNESS_UP] = KEYMAP(0x95, KEY_BRIGHTNESSUP), /* e015 */
|
||||
[PS2_KEY_KBD_BKLIGHT_DOWN] = KEYMAP(0x97, KEY_KBDILLUMDOWN), /* e017 */
|
||||
[PS2_KEY_KBD_BKLIGHT_UP] = KEYMAP(0x98, KEY_KBDILLUMUP), /* e018 */
|
||||
[PS2_KEY_PRIVACY_SCRN_TOGGLE] = KEYMAP(0x96, /* e016 */
|
||||
KEY_PRIVACY_SCREEN_TOGGLE),
|
||||
};
|
||||
|
||||
/* Keymap for numeric keypad keys */
|
||||
static uint32_t numeric_keypad_keymaps[] = {
|
||||
/* Row-0 */
|
||||
KEYMAP(0xc9, KEY_PAGEUP),
|
||||
KEYMAP(0xd1, KEY_PAGEDOWN),
|
||||
KEYMAP(0xc7, KEY_HOME),
|
||||
KEYMAP(0xcf, KEY_END),
|
||||
/* Row-1 */
|
||||
KEYMAP(0xd3, KEY_DELETE),
|
||||
KEYMAP(0xb5, KEY_KPSLASH),
|
||||
KEYMAP(0x37, KEY_KPASTERISK),
|
||||
KEYMAP(0x4a, KEY_KPMINUS),
|
||||
/* Row-2 */
|
||||
KEYMAP(0x47, KEY_KP7),
|
||||
KEYMAP(0x48, KEY_KP8),
|
||||
KEYMAP(0x49, KEY_KP9),
|
||||
KEYMAP(0x4e, KEY_KPPLUS),
|
||||
/* Row-3 */
|
||||
KEYMAP(0x4b, KEY_KP4),
|
||||
KEYMAP(0x4c, KEY_KP5),
|
||||
KEYMAP(0x4d, KEY_KP6),
|
||||
/* Row-4 */
|
||||
KEYMAP(0x4f, KEY_KP1),
|
||||
KEYMAP(0x50, KEY_KP2),
|
||||
KEYMAP(0x51, KEY_KP3),
|
||||
KEYMAP(0x9c, KEY_KPENTER),
|
||||
/* Row-5 */
|
||||
KEYMAP(0x52, KEY_KP0),
|
||||
KEYMAP(0x53, KEY_KPDOT),
|
||||
};
|
||||
|
||||
/*
|
||||
* Keymap for rest of non-top-row keys. This is a superset of all the possible
|
||||
* keys that any chromeos keyboards can have.
|
||||
*/
|
||||
static uint32_t rest_of_keymaps[] = {
|
||||
/* Row-0 */
|
||||
KEYMAP(0x01, KEY_ESC),
|
||||
/* Row-1 */
|
||||
KEYMAP(0x29, KEY_GRAVE),
|
||||
KEYMAP(0x02, KEY_1),
|
||||
KEYMAP(0x03, KEY_2),
|
||||
KEYMAP(0x04, KEY_3),
|
||||
KEYMAP(0x05, KEY_4),
|
||||
KEYMAP(0x06, KEY_5),
|
||||
KEYMAP(0x07, KEY_6),
|
||||
KEYMAP(0x08, KEY_7),
|
||||
KEYMAP(0x09, KEY_8),
|
||||
KEYMAP(0x0a, KEY_9),
|
||||
KEYMAP(0x0b, KEY_0),
|
||||
KEYMAP(0x0c, KEY_MINUS),
|
||||
KEYMAP(0x0d, KEY_EQUAL),
|
||||
KEYMAP(0x7d, KEY_YEN), /* JP keyboards only */
|
||||
KEYMAP(0x0e, KEY_BACKSPACE),
|
||||
/* Row-2 */
|
||||
KEYMAP(0x0f, KEY_TAB),
|
||||
KEYMAP(0x10, KEY_Q),
|
||||
KEYMAP(0x11, KEY_W),
|
||||
KEYMAP(0x12, KEY_E),
|
||||
KEYMAP(0x13, KEY_R),
|
||||
KEYMAP(0x14, KEY_T),
|
||||
KEYMAP(0x15, KEY_Y),
|
||||
KEYMAP(0x16, KEY_U),
|
||||
KEYMAP(0x17, KEY_I),
|
||||
KEYMAP(0x18, KEY_O),
|
||||
KEYMAP(0x19, KEY_P),
|
||||
KEYMAP(0x1a, KEY_LEFTBRACE),
|
||||
KEYMAP(0x1b, KEY_RIGHTBRACE),
|
||||
KEYMAP(0x2b, KEY_BACKSLASH),
|
||||
/* Row-3 */
|
||||
KEYMAP(0xdb, KEY_LEFTMETA), /* Search Key */
|
||||
KEYMAP(0x1e, KEY_A),
|
||||
KEYMAP(0x1f, KEY_S),
|
||||
KEYMAP(0x20, KEY_D),
|
||||
KEYMAP(0x21, KEY_F),
|
||||
KEYMAP(0x22, KEY_G),
|
||||
KEYMAP(0x23, KEY_H),
|
||||
KEYMAP(0x24, KEY_J),
|
||||
KEYMAP(0x25, KEY_K),
|
||||
KEYMAP(0x26, KEY_L),
|
||||
KEYMAP(0x27, KEY_SEMICOLON),
|
||||
KEYMAP(0x28, KEY_APOSTROPHE),
|
||||
KEYMAP(0x1c, KEY_ENTER),
|
||||
/* Row-4 */
|
||||
KEYMAP(0x2a, KEY_LEFTSHIFT),
|
||||
KEYMAP(0x56, KEY_102ND), /* UK keyboards only */
|
||||
KEYMAP(0x2c, KEY_Z),
|
||||
KEYMAP(0x2d, KEY_X),
|
||||
KEYMAP(0x2e, KEY_C),
|
||||
KEYMAP(0x2f, KEY_V),
|
||||
KEYMAP(0x30, KEY_B),
|
||||
KEYMAP(0x31, KEY_N),
|
||||
KEYMAP(0x32, KEY_M),
|
||||
KEYMAP(0x33, KEY_COMMA),
|
||||
KEYMAP(0x34, KEY_DOT),
|
||||
KEYMAP(0x35, KEY_SLASH),
|
||||
KEYMAP(0x73, KEY_RO), /* JP keyboards only */
|
||||
KEYMAP(0x36, KEY_RIGHTSHIFT),
|
||||
/* Row-5 */
|
||||
KEYMAP(0x1d, KEY_LEFTCTRL),
|
||||
KEYMAP(0x38, KEY_LEFTALT),
|
||||
KEYMAP(0x7b, KEY_MUHENKAN), /* JP keyboards only */
|
||||
KEYMAP(0x39, KEY_SPACE),
|
||||
KEYMAP(0x79, KEY_HENKAN), /* JP keyboards only */
|
||||
KEYMAP(0xb8, KEY_RIGHTALT),
|
||||
KEYMAP(0x9d, KEY_RIGHTCTRL),
|
||||
/* Arrow keys */
|
||||
KEYMAP(0xcb, KEY_LEFT),
|
||||
KEYMAP(0xd0, KEY_DOWN),
|
||||
KEYMAP(0xcd, KEY_RIGHT),
|
||||
KEYMAP(0xc8, KEY_UP),
|
||||
};
|
||||
|
||||
static void ssdt_generate_physmap(struct acpi_dp *dp, uint8_t num_top_row_keys,
|
||||
enum ps2_action_key action_keys[])
|
||||
{
|
||||
struct acpi_dp *dp_array;
|
||||
enum ps2_action_key key;
|
||||
uint32_t keymap, i;
|
||||
|
||||
dp_array = acpi_dp_new_table("function-row-physmap");
|
||||
if (!dp_array) {
|
||||
printk(BIOS_ERR, "PS2K: couldn't write function-row-physmap\n");
|
||||
return;
|
||||
}
|
||||
|
||||
printk(BIOS_INFO, "PS2K: Physmap: [");
|
||||
for (i = 0; i < num_top_row_keys; i++) {
|
||||
key = action_keys[i];
|
||||
if (key && key < ARRAY_SIZE(action_keymaps)) {
|
||||
keymap = action_keymaps[key];
|
||||
} else {
|
||||
keymap = 0;
|
||||
printk(BIOS_ERR,
|
||||
"PS2K: invalid top-action-key-%u: %u(skipped)\n",
|
||||
i, key);
|
||||
}
|
||||
acpi_dp_add_integer(dp_array, NULL, SCANCODE(keymap));
|
||||
printk(BIOS_INFO, " %X", SCANCODE(keymap));
|
||||
}
|
||||
|
||||
printk(BIOS_INFO, " ]\n");
|
||||
acpi_dp_add_array(dp, dp_array);
|
||||
}
|
||||
|
||||
static void ssdt_generate_keymap(struct acpi_dp *dp, uint8_t num_top_row_keys,
|
||||
enum ps2_action_key action_keys[],
|
||||
bool can_send_function_keys,
|
||||
bool has_numeric_keypad,
|
||||
bool has_scrnlock_key)
|
||||
{
|
||||
struct acpi_dp *dp_array;
|
||||
enum ps2_action_key key;
|
||||
uint32_t keymap;
|
||||
unsigned int i, total = 0;
|
||||
|
||||
dp_array = acpi_dp_new_table("linux,keymap");
|
||||
if (!dp_array) {
|
||||
printk(BIOS_ERR, "PS2K: couldn't write linux,keymap\n");
|
||||
return;
|
||||
}
|
||||
|
||||
/* Write out keymap for top row action keys */
|
||||
for (i = 0; i < num_top_row_keys; i++) {
|
||||
key = action_keys[i];
|
||||
if (!key || key >= ARRAY_SIZE(action_keymaps)) {
|
||||
printk(BIOS_ERR,
|
||||
"PS2K: invalid top-action-key-%u: %u\n", i, key);
|
||||
continue;
|
||||
}
|
||||
keymap = action_keymaps[key];
|
||||
acpi_dp_add_integer(dp_array, NULL, keymap);
|
||||
total++;
|
||||
}
|
||||
|
||||
/* Write out keymap for function keys, if keyboard can send them */
|
||||
if (can_send_function_keys) {
|
||||
for (i = 0; i < num_top_row_keys; i++) {
|
||||
keymap = function_keymaps[i];
|
||||
acpi_dp_add_integer(dp_array, NULL, keymap);
|
||||
}
|
||||
|
||||
total += num_top_row_keys;
|
||||
}
|
||||
|
||||
/* Write out keymap for numeric keypad, if the keyboard has it */
|
||||
if (has_numeric_keypad) {
|
||||
for (i = 0; i < ARRAY_SIZE(numeric_keypad_keymaps); i++) {
|
||||
keymap = numeric_keypad_keymaps[i];
|
||||
acpi_dp_add_integer(dp_array, NULL, keymap);
|
||||
}
|
||||
|
||||
total += ARRAY_SIZE(numeric_keypad_keymaps);
|
||||
}
|
||||
|
||||
/* Provide keymap for screenlock only if it is present */
|
||||
if (has_scrnlock_key) {
|
||||
acpi_dp_add_integer(dp_array, NULL, KEYMAP(0x5d, KEY_SLEEP));
|
||||
total++;
|
||||
}
|
||||
|
||||
/* Write out keymap for rest of keys */
|
||||
for (i = 0; i < ARRAY_SIZE(rest_of_keymaps); i++) {
|
||||
keymap = rest_of_keymaps[i];
|
||||
acpi_dp_add_integer(dp_array, NULL, keymap);
|
||||
}
|
||||
|
||||
total += ARRAY_SIZE(rest_of_keymaps);
|
||||
printk(BIOS_INFO, "PS2K: Passing %u keymaps to kernel\n", total);
|
||||
|
||||
acpi_dp_add_array(dp, dp_array);
|
||||
}
|
||||
|
||||
void acpigen_ps2_keyboard_dsd(const char *scope, uint8_t num_top_row_keys,
|
||||
enum ps2_action_key action_keys[],
|
||||
bool can_send_function_keys,
|
||||
bool has_numeric_keypad,
|
||||
bool has_scrnlock_key)
|
||||
{
|
||||
struct acpi_dp *dsd;
|
||||
|
||||
if (!scope ||
|
||||
num_top_row_keys < PS2_MIN_TOP_ROW_KEYS ||
|
||||
num_top_row_keys > PS2_MAX_TOP_ROW_KEYS) {
|
||||
printk(BIOS_ERR, "PS2K: %s: invalid args\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
dsd = acpi_dp_new_table("_DSD");
|
||||
if (!dsd) {
|
||||
printk(BIOS_ERR, "PS2K: couldn't write _DSD\n");
|
||||
return;
|
||||
}
|
||||
|
||||
acpigen_write_scope(scope);
|
||||
ssdt_generate_physmap(dsd, num_top_row_keys, action_keys);
|
||||
ssdt_generate_keymap(dsd, num_top_row_keys, action_keys,
|
||||
can_send_function_keys, has_numeric_keypad,
|
||||
has_scrnlock_key);
|
||||
acpi_dp_write(dsd);
|
||||
acpigen_pop_len(); /* Scope */
|
||||
}
|
Reference in New Issue
Block a user