[coreboot-gerrit] Patch set updated for coreboot: device: Add an ACPI device name and path concept to devices

Duncan Laurie (dlaurie@google.com) gerrit at coreboot.org
Mon May 16 22:55:19 CEST 2016


Duncan Laurie (dlaurie at google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/14840

-gerrit

commit 50918719141ac0f4dfdf62e53b8c54aa9bcc1ec4
Author: Duncan Laurie <dlaurie at chromium.org>
Date:   Sun May 8 18:15:25 2016 -0700

    device: Add an ACPI device name and path concept to devices
    
    Add a function to "struct device_operations" to return the ACPI name
    for the device, and helper functions to find this name (either from
    the device or its parent) and to build a fully qualified ACPI path
    from the root device.
    
    This addition will allow device drivers generate their ACPI AML in the
    SSDT at boot, with customization supplied by devicetree.cb, instead of
    needing custom DSDT ASL for every mainboard.
    
    The root device acpi_name is defined as "\\_SB" and is used to start
    the path when building a fully qualified name.
    
    This requires SOC support to provide handlers for returning the ACPI
    name for devices that it owns, and those names must match the objects
    declared in the DSDT.  The handler can be done either in each device
    driver or with a global handler for the entire SOC.
    
    Simplified example of how this can be used for an i2c device declared
    in devicetree.cb with:
    
      chip soc/intel/skylake          # "\_SB" (from root device)
        device domain 0 on            # "PCI0"
          device pci 19.2 on          # "I2C4"
            chip drivers/i2c/test0
              device i2c 1a.0 on end  # "TST0"
            end
          end
        end
      end
    
    And basic SSDT generating code in the device driver:
    
      acpigen_write_scope(acpi_device_path(dev->bus->dev));
      acpigen_write_device(acpi_device_name(dev));
      acpigen_write_string("_HID", "TEST0000");
      acpigen_write_byte("_UID", 0);
      acpigen_pop_len(); /* device */
      acpigen_pop_len(); /* scope */
    
    Will produce this ACPI code:
    
      Scope (\_SB.PCI0.I2C4) {
        Device (TST0) {
          Name (_HID, "TEST0000")
          Name (_UID, 0)
        }
      }
    
    Change-Id: Ie149595aeab96266fa5f006e7934339f0119ac54
    Signed-off-by: Duncan Laurie <dlaurie at chromium.org>
---
 src/arch/x86/Makefile.inc               |  1 +
 src/arch/x86/acpi_device.c              | 73 +++++++++++++++++++++++++++++++++
 src/arch/x86/include/arch/acpi_device.h | 23 +++++++++++
 src/device/root_device.c                | 10 +++++
 src/include/device/device.h             |  1 +
 5 files changed, 108 insertions(+)

diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index a363430..f7e9c7c 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -349,6 +349,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 0000000..7623645
--- /dev/null
+++ b/src/arch/x86/acpi_device.c
@@ -0,0 +1,73 @@
+/*
+ * 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)
+{
+	/* 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 int acpi_device_path_fill(struct device *dev, char *buf, int cur)
+{
+	const char *name = acpi_device_name(dev);
+	int next = 0;
+
+	/* Make sure this name segment will fit */
+	if (!dev || !name || (cur + strlen(name) + 2) > DEVICE_PATH_MAX)
+		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, cur);
+
+	/* Fill in the path from the root device */
+	next += snprintf(buf + next, DEVICE_PATH_MAX - 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, 0) <= 0)
+		return NULL;
+
+	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 0000000..b0b9baa
--- /dev/null
+++ b/src/arch/x86/include/arch/acpi_device.h
@@ -0,0 +1,23 @@
+/*
+ * 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);
+
+#endif
diff --git a/src/device/root_device.c b/src/device/root_device.c
index 7ff10ae..ed1f7d7 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 d9af64a..00ff3d9 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;



More information about the coreboot-gerrit mailing list