aboutsummaryrefslogtreecommitdiff
path: root/src/arch/x86/acpi.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/arch/x86/acpi.c')
-rw-r--r--src/arch/x86/acpi.c112
1 files changed, 112 insertions, 0 deletions
diff --git a/src/arch/x86/acpi.c b/src/arch/x86/acpi.c
index 02884c494c..56f64084e8 100644
--- a/src/arch/x86/acpi.c
+++ b/src/arch/x86/acpi.c
@@ -658,6 +658,118 @@ unsigned long acpi_write_hpet(device_t device, unsigned long current,
return current;
}
+void acpi_create_dbg2(acpi_dbg2_header_t *dbg2,
+ int port_type, int port_subtype,
+ acpi_addr_t *address, uint32_t address_size,
+ const char *device_path)
+{
+ uintptr_t current;
+ acpi_dbg2_device_t *device;
+ uint32_t *dbg2_addr_size;
+ acpi_header_t *header;
+ size_t path_len;
+ const char *path;
+ char *namespace;
+
+ /* Fill out header fields. */
+ current = (uintptr_t)dbg2;
+ memset(dbg2, 0, sizeof(acpi_dbg2_header_t));
+ header = &(dbg2->header);
+ header->revision = 0;
+ memcpy(header->signature, "DBG2", 4);
+ memcpy(header->oem_id, OEM_ID, 6);
+ memcpy(header->oem_table_id, ACPI_TABLE_CREATOR, 8);
+ memcpy(header->asl_compiler_id, ASLC, 4);
+
+ /* One debug device defined */
+ dbg2->devices_offset = sizeof(acpi_dbg2_header_t);
+ dbg2->devices_count = 1;
+ current += sizeof(acpi_dbg2_header_t);
+
+ /* Device comes after the header */
+ device = (acpi_dbg2_device_t *)current;
+ memset(device, 0, sizeof(acpi_dbg2_device_t));
+ current += sizeof(acpi_dbg2_device_t);
+
+ device->revision = 0;
+ device->address_count = 1;
+ device->port_type = port_type;
+ device->port_subtype = port_subtype;
+
+ /* Base Address comes after device structure */
+ memcpy((void *)current, address, sizeof(acpi_addr_t));
+ device->base_address_offset = current - (uintptr_t)device;
+ current += sizeof(acpi_addr_t);
+
+ /* Address Size comes after address structure */
+ dbg2_addr_size = (uint32_t *)current;
+ device->address_size_offset = current - (uintptr_t)device;
+ *dbg2_addr_size = address_size;
+ current += sizeof(uint32_t);
+
+ /* Namespace string comes last, use '.' if not provided */
+ path = device_path ? : ".";
+ /* Namespace string length includes NULL terminator */
+ path_len = strlen(path) + 1;
+ namespace = (char *)current;
+ device->namespace_string_length = path_len;
+ device->namespace_string_offset = current - (uintptr_t)device;
+ strncpy(namespace, path, path_len);
+ current += path_len;
+
+ /* Update structure lengths and checksum */
+ device->length = current - (uintptr_t)device;
+ header->length = current - (uintptr_t)dbg2;
+ header->checksum = acpi_checksum((uint8_t *)dbg2, header->length);
+}
+
+unsigned long acpi_write_dbg2_pci_uart(acpi_rsdp_t *rsdp, unsigned long current,
+ struct device *dev, uint8_t access_size)
+{
+ acpi_dbg2_header_t *dbg2 = (acpi_dbg2_header_t *)current;
+ struct resource *res;
+ acpi_addr_t address;
+
+ if (!dev) {
+ printk(BIOS_ERR, "%s: Device not found\n", __func__);
+ return current;
+ }
+ res = find_resource(dev, PCI_BASE_ADDRESS_0);
+ if (!res) {
+ printk(BIOS_ERR, "%s: Unable to find resource for %s\n",
+ __func__, dev_path(dev));
+ return current;
+ }
+
+ memset(&address, 0, sizeof(address));
+ if (res->flags & IORESOURCE_IO)
+ address.space_id = ACPI_ADDRESS_SPACE_IO;
+ else if (res->flags & IORESOURCE_MEM)
+ address.space_id = ACPI_ADDRESS_SPACE_MEMORY;
+ else {
+ printk(BIOS_ERR, "%s: Unknown address space type\n", __func__);
+ return current;
+ }
+
+ address.addrl = (uint32_t)res->base;
+ address.addrh = (uint32_t)((res->base >> 32) & 0xffffffff);
+ address.access_size = access_size;
+
+ acpi_create_dbg2(dbg2,
+ ACPI_DBG2_PORT_SERIAL,
+ ACPI_DBG2_PORT_SERIAL_16550,
+ &address, res->size,
+ acpi_device_path(dev));
+
+ if (dbg2->header.length) {
+ current += dbg2->header.length;
+ current = acpi_align_current(current);
+ acpi_add_table(rsdp, dbg2);
+ }
+
+ return current;
+}
+
void acpi_create_facs(acpi_facs_t *facs)
{
memset((void *)facs, 0, sizeof(acpi_facs_t));