summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arch/x86/Makefile.inc1
-rw-r--r--src/arch/x86/acpi_device.c111
-rw-r--r--src/arch/x86/include/arch/acpi_device.h25
-rw-r--r--src/device/root_device.c10
-rw-r--r--src/include/device/device.h1
5 files changed, 148 insertions, 0 deletions
diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index c27bb1a994..536caa32dd 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -350,6 +350,7 @@ ramstage-$(CONFIG_GENERATE_PIRQ_TABLE) += pirq_routing.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi.c
ramstage-$(CONFIG_GENERATE_SMBIOS_TABLES) += smbios.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpigen.c
+ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi_device.c
ramstage-$(CONFIG_HAVE_ACPI_RESUME) += wakeup.S
ramstage-y += c_start.S
diff --git a/src/arch/x86/acpi_device.c b/src/arch/x86/acpi_device.c
new file mode 100644
index 0000000000..b3861a2392
--- /dev/null
+++ b/src/arch/x86/acpi_device.c
@@ -0,0 +1,111 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#include <string.h>
+#include <arch/acpi.h>
+#include <arch/acpi_device.h>
+#include <arch/acpigen.h>
+#include <device/device.h>
+#include <device/path.h>
+
+/* Locate and return the ACPI name for this device */
+const char *acpi_device_name(struct device *dev)
+{
+ if (!dev)
+ return NULL;
+
+ /* Check for device specific handler */
+ if (dev->ops->acpi_name)
+ return dev->ops->acpi_name(dev);
+
+ /* Check parent device in case it has a global handler */
+ if (dev->bus && dev->bus->dev->ops->acpi_name)
+ return dev->bus->dev->ops->acpi_name(dev);
+
+ return NULL;
+}
+
+/* Recursive function to find the root device and print a path from there */
+static size_t acpi_device_path_fill(struct device *dev, char *buf,
+ size_t buf_len, size_t cur)
+{
+ const char *name = acpi_device_name(dev);
+ size_t next = 0;
+
+ /*
+ * Make sure this name segment will fit, including the path segment
+ * separator and possible NUL terminator if this is the last segment.
+ */
+ if (!dev || !name || (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);
+
+ /* Fill in the path from the root device */
+ next += snprintf(buf + next, buf_len - next, "%s%s",
+ dev->path.type == DEVICE_PATH_ROOT ? "" : ".", 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(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(struct device *dev)
+{
+ if (!dev || !dev->bus || !dev->bus->dev)
+ return NULL;
+
+ return acpi_device_path(dev->bus->dev);
+}
+
+/* Concatentate the device path and provided name suffix */
+const char *acpi_device_path_join(struct device *dev, const char *name)
+{
+ static char buf[DEVICE_PATH_MAX] = {};
+ size_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;
+}
diff --git a/src/arch/x86/include/arch/acpi_device.h b/src/arch/x86/include/arch/acpi_device.h
new file mode 100644
index 0000000000..2cad9b5d21
--- /dev/null
+++ b/src/arch/x86/include/arch/acpi_device.h
@@ -0,0 +1,25 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright 2016 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; version 2 of the License.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+#ifndef __ACPI_DEVICE_H
+#define __ACPI_DEVICE_H
+
+struct device;
+const char *acpi_device_name(struct device *dev);
+const char *acpi_device_path(struct device *dev);
+const char *acpi_device_scope(struct device *dev);
+const char *acpi_device_path_join(struct device *dev, const char *name);
+
+#endif
diff --git a/src/device/root_device.c b/src/device/root_device.c
index 7ff10ae844..ed1f7d7bfc 100644
--- a/src/device/root_device.c
+++ b/src/device/root_device.c
@@ -130,6 +130,13 @@ static void root_dev_reset(struct bus *bus)
hard_reset();
}
+#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
+static const char *root_dev_acpi_name(struct device *dev)
+{
+ return "\\_SB";
+}
+#endif
+
/**
* Default device operation for root device.
*
@@ -144,4 +151,7 @@ struct device_operations default_dev_ops_root = {
.init = DEVICE_NOOP,
.scan_bus = root_dev_scan_bus,
.reset_bus = root_dev_reset,
+#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
+ .acpi_name = root_dev_acpi_name,
+#endif
};
diff --git a/src/include/device/device.h b/src/include/device/device.h
index d9af64adf5..00ff3d9a07 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -59,6 +59,7 @@ struct device_operations {
unsigned long (*write_acpi_tables)(device_t dev, unsigned long start, struct acpi_rsdp *rsdp);
void (*acpi_fill_ssdt_generator)(device_t dev);
void (*acpi_inject_dsdt_generator)(device_t dev);
+ const char *(*acpi_name)(device_t dev);
#endif
const struct pci_operations *ops_pci;
const struct smbus_bus_operations *ops_smbus_bus;