Furquan Shaikh (furquan(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17091
-gerrit
commit 770d36cff3ca82c40650471f1391d4bd27860313
Author: Furquan Shaikh <furquan(a)chromium.org>
Date: Fri Oct 21 16:40:17 2016 -0700
arch/x86/acpigen_dsm: Add support for DSM types
Currently, the only supported DSM type is I2C
HID(3CDFF6F7-4267-4555-AD05-B30A3D8938DE). This provides the required
callbacks for generating ACPI AML codes for different function
identifiers for I2C HID.
BUG=chrome-os-partner:57846
Change-Id: Ia403e11f7ce4824956e3c879547ec927478db7b1
Signed-off-by: Furquan Shaikh <furquan(a)chromium.org>
---
src/arch/x86/Makefile.inc | 1 +
src/arch/x86/acpigen_dsm.c | 65 +++++++++++++++++++++++++++++++++
src/arch/x86/include/arch/acpigen_dsm.h | 27 ++++++++++++++
3 files changed, 93 insertions(+)
diff --git a/src/arch/x86/Makefile.inc b/src/arch/x86/Makefile.inc
index 782ca63..c4bb1cc 100644
--- a/src/arch/x86/Makefile.inc
+++ b/src/arch/x86/Makefile.inc
@@ -313,6 +313,7 @@ ifeq ($(CONFIG_ARCH_RAMSTAGE_X86_32)$(CONFIG_ARCH_RAMSTAGE_X86_64),y)
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpigen.c
+ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpigen_dsm.c
ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi_device.c
ramstage-$(CONFIG_HAVE_ACPI_RESUME) += acpi_s3.c
ramstage-y += boot.c
diff --git a/src/arch/x86/acpigen_dsm.c b/src/arch/x86/acpigen_dsm.c
new file mode 100644
index 0000000..c6d614a
--- /dev/null
+++ b/src/arch/x86/acpigen_dsm.c
@@ -0,0 +1,65 @@
+/*
+ * 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 <arch/acpigen.h>
+#include <arch/acpigen_dsm.h>
+#include <stdlib.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(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(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 ------------------------- */
diff --git a/src/arch/x86/include/arch/acpigen_dsm.h b/src/arch/x86/include/arch/acpigen_dsm.h
new file mode 100644
index 0000000..2d8bb48
--- /dev/null
+++ b/src/arch/x86/include/arch/acpigen_dsm.h
@@ -0,0 +1,27 @@
+/*
+ * 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 __ARCH_ACPIGEN_DSM_H__
+#define __ARCH_ACPIGEN_DSM_H__
+
+#include <stdint.h>
+
+struct dsm_i2c_hid_config {
+ uint8_t hid_desc_reg_offset;
+};
+
+void acpigen_write_dsm_i2c_hid(struct dsm_i2c_hid_config *config);
+
+#endif /* __ARCH_ACPIGEN_DSM_H__ */
Furquan Shaikh (furquan(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17090
-gerrit
commit 32212b4b622449021651556ba1d8091c663ac16e
Author: Furquan Shaikh <furquan(a)chromium.org>
Date: Fri Oct 21 16:37:41 2016 -0700
arch/x86/acpigen: Add support for _DSM method generation
Add acpigen_write_dsm that generates ACPI AML code for _DSM
method. Caller should provide set of callbacks with callback[i]
corresponding to function index i of DSM method. Local0 and Local1
should not be used in any of the callbacks.
BUG=chrome-os-partner:57846
Change-Id: Ie18cba080424488fe00cc626ea50aa92c1dbb199
Signed-off-by: Furquan Shaikh <furquan(a)chromium.org>
---
src/arch/x86/acpigen.c | 60 +++++++++++++++++++++++++++++++++++++
src/arch/x86/include/arch/acpigen.h | 8 +++++
2 files changed, 68 insertions(+)
diff --git a/src/arch/x86/acpigen.c b/src/arch/x86/acpigen.c
index e42b620..e712564 100644
--- a/src/arch/x86/acpigen.c
+++ b/src/arch/x86/acpigen.c
@@ -1030,6 +1030,66 @@ void acpigen_write_return_byte(uint8_t arg)
acpigen_write_byte(arg);
}
+/*
+ * Generate ACPI AML code for _DSM method.
+ * This function takes as input uuid for the device, set of callbacks and
+ * argument to pass into the callbacks. Callbacks should ensure that Local0 and
+ * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
+ */
+void acpigen_write_dsm(const char *uuid, void (*callbacks[])(void *),
+ size_t count, void *arg)
+{
+ size_t i;
+
+ /* Method (_DSM, 4, Serialized) */
+ acpigen_write_method_serialized("_DSM", 0x4);
+
+ /* ToBuffer (Arg0, Local0) */
+ acpigen_write_to_buffer(ARG0_OP, LOCAL0_OP);
+
+ /* If (LEqual (Local0, ToUUID(uuid))) */
+ acpigen_write_if();
+ acpigen_emit_byte(LEQUAL_OP);
+ acpigen_emit_byte(LOCAL0_OP);
+ acpigen_write_uuid(uuid);
+
+ /* ToInteger (Arg2, Local1) */
+ acpigen_write_to_integer(ARG2_OP, LOCAL1_OP);
+ acpigen_write_debug_op(LOCAL1_OP);
+
+ for (i = 0; i < count; i++) {
+ /* If (Lequal (Local1, i)) */
+ acpigen_write_if_lequal(LOCAL1_OP, i);
+
+ /* Callback to write if handler. */
+ if (callbacks[i])
+ callbacks[i](arg);
+
+ acpigen_pop_len(); /* If */
+
+ /* Else */
+ acpigen_write_else();
+ }
+
+ /* Default case: Return (Buffer (One) { 0x0 }) */
+ acpigen_write_return_singleton_buffer(0x0);
+
+ /* Pop lengths for all the else clauses. */
+ for (i = 0; i < count; i++)
+ acpigen_pop_len();
+
+ acpigen_pop_len(); /* If (LEqual (Local0, ToUUID(uuid))) */
+
+ /* Else */
+ acpigen_write_else();
+
+ /* Return (Buffer (One) { 0x0 }) */
+ acpigen_write_return_singleton_buffer(0x0);
+
+ acpigen_pop_len(); /* Else */
+ acpigen_pop_len(); /* Method _DSM */
+}
+
/* Soc-implemented functions -- weak definitions. */
int __attribute__((weak)) acpigen_soc_read_rx_gpio(unsigned gpio_num)
{
diff --git a/src/arch/x86/include/arch/acpigen.h b/src/arch/x86/include/arch/acpigen.h
index aeb61d3..5cca53f 100644
--- a/src/arch/x86/include/arch/acpigen.h
+++ b/src/arch/x86/include/arch/acpigen.h
@@ -167,6 +167,14 @@ void acpigen_write_byte_buffer(uint8_t *arr, uint8_t size);
void acpigen_write_return_byte_buffer(uint8_t *arr, uint8_t size);
void acpigen_write_return_singleton_buffer(uint8_t arg);
void acpigen_write_return_byte(uint8_t arg);
+/*
+ * Generate ACPI AML code for _DSM method.
+ * This function takes as input uuid for the device, set of callbacks and
+ * argument to pass into the callbacks. Callbacks should ensure that Local0 and
+ * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
+ */
+void acpigen_write_dsm(const char *uuid, void (*callbacks[])(void *),
+ size_t count, void *arg);
int get_cst_entries(acpi_cstate_t **);
Furquan Shaikh (furquan(a)google.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/17089
-gerrit
commit f230c588a66b15db26b13234a51183b948b75f86
Author: Furquan Shaikh <furquan(a)chromium.org>
Date: Fri Oct 21 16:24:07 2016 -0700
drivers/i2c/generic: Re-factor SSDT generation code
1. Export i2c_generic_fill_ssdt to allow other device-specific i2c
drivers to share and re-use the same code for generating AML code for
SSDT. In order to achieve this, following changes are required:
a. Add macro I2C_GENERIC_CONFIG that defines a structure with all
generic i2c device-tree properties. This macro should be placed by the
using driver at the start of its config structure.
b. Accept a callback function to add any device specific information to
SSDT. If generic driver is used directly by a device, callback would be
NULL. Other devices using a separate i2c driver can provide a callback
to add any properties to SSDT.
2. Allow device to provide _CID.
BUG=chrome-os-partner:57846
Change-Id: I3a0054e22b81f9d6d407bef417eae5e9edc04ee4
Signed-off-by: Furquan Shaikh <furquan(a)chromium.org>
---
src/drivers/i2c/generic/chip.h | 31 +--------------
src/drivers/i2c/generic/generic.c | 16 +++++++-
src/drivers/i2c/generic/generic.h | 80 +++++++++++++++++++++++++++++++++++++++
3 files changed, 96 insertions(+), 31 deletions(-)
diff --git a/src/drivers/i2c/generic/chip.h b/src/drivers/i2c/generic/chip.h
index e84fc38..4614ba3 100644
--- a/src/drivers/i2c/generic/chip.h
+++ b/src/drivers/i2c/generic/chip.h
@@ -1,34 +1,7 @@
#include <arch/acpi_device.h>
#include <device/i2c.h>
+#include "generic.h"
struct drivers_i2c_generic_config {
- const char *hid; /* ACPI _HID (required) */
- const char *name; /* ACPI Device Name */
- const char *desc; /* Device Description */
- unsigned uid; /* ACPI _UID */
- enum i2c_speed speed; /* Bus speed in Hz, default is I2C_SPEED_FAST */
- unsigned wake; /* Wake GPE */
- struct acpi_irq irq; /* Interrupt */
-
- /*
- * This flag will add a device propery which will indicate
- * to the OS that it should probe this device before adding it.
- *
- * This can be used to declare a device that may not exist on
- * the board, for example to support multiple trackpad vendors.
- */
- int probed;
-
- /* GPIO used to indicate if this device is present */
- unsigned device_present_gpio;
- unsigned device_present_gpio_invert;
-
- /* GPIO used to take device out of reset or to put it into reset. */
- unsigned reset_gpio;
- /* Delay to be inserted after device is taken out of reset. */
- unsigned reset_delay_ms;
- /* GPIO used to enable device. */
- unsigned enable_gpio;
- /* Delay to be inserted after device is enabled. */
- unsigned enable_delay_ms;
+ I2C_GENERIC_CONFIG;
};
diff --git a/src/drivers/i2c/generic/generic.c b/src/drivers/i2c/generic/generic.c
index 7f078b0..410f396 100644
--- a/src/drivers/i2c/generic/generic.c
+++ b/src/drivers/i2c/generic/generic.c
@@ -61,7 +61,8 @@ static void i2c_generic_add_power_res(struct drivers_i2c_generic_config *config)
acpigen_pop_len(); /* PowerResource PRIC */
}
-static void i2c_generic_fill_ssdt(struct device *dev)
+void i2c_generic_fill_ssdt(struct device *dev,
+ void (*callback)(struct device *dev))
{
struct drivers_i2c_generic_config *config = dev->chip_info;
const char *scope = acpi_device_scope(dev);
@@ -85,6 +86,8 @@ static void i2c_generic_fill_ssdt(struct device *dev)
acpigen_write_scope(scope);
acpigen_write_device(acpi_device_name(dev));
acpigen_write_name_string("_HID", config->hid);
+ if (config->cid)
+ acpigen_write_name_string("_CID", config->cid);
acpigen_write_name_integer("_UID", config->uid);
acpigen_write_name_string("_DDN", config->desc);
acpigen_write_STA(ACPI_STATUS_DEVICE_ALL_ON);
@@ -111,6 +114,10 @@ static void i2c_generic_fill_ssdt(struct device *dev)
/* Power Resource */
i2c_generic_add_power_res(config);
+ /* Callback if any. */
+ if (callback)
+ callback(dev);
+
acpigen_pop_len(); /* Device */
acpigen_pop_len(); /* Scope */
@@ -118,6 +125,11 @@ static void i2c_generic_fill_ssdt(struct device *dev)
config->desc ? : dev->chip_ops->name, dev_path(dev));
}
+static void i2c_generic_fill_ssdt_generator(struct device *dev)
+{
+ i2c_generic_fill_ssdt(dev, NULL);
+}
+
/* Use name specified in config or build one from I2C address */
static const char *i2c_generic_acpi_name(struct device *dev)
{
@@ -139,7 +151,7 @@ static struct device_operations i2c_generic_ops = {
.enable_resources = DEVICE_NOOP,
#if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES)
.acpi_name = &i2c_generic_acpi_name,
- .acpi_fill_ssdt_generator = &i2c_generic_fill_ssdt,
+ .acpi_fill_ssdt_generator = &i2c_generic_fill_ssdt_generator,
#endif
};
diff --git a/src/drivers/i2c/generic/generic.h b/src/drivers/i2c/generic/generic.h
new file mode 100644
index 0000000..60445c2
--- /dev/null
+++ b/src/drivers/i2c/generic/generic.h
@@ -0,0 +1,80 @@
+/*
+ * 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 __I2C_GENERIC_GENERIC_H__
+#define __I2C_GENERIC_GENERIC_H__
+
+#include <device/device.h>
+
+/*
+ * Macro defining all the generic i2c device-tree properties that are used by
+ * ssdt generator. Drivers using i2c_generic_fill_ssdt should place this macro
+ * at the start of their config structure.
+ */
+#define I2C_GENERIC_CONFIG \
+ struct { \
+ /* ACPI _HID (required) */ \
+ const char *hid; \
+ /* ACPI _CID */ \
+ const char *cid; \
+ /* ACPI Device Name */ \
+ const char *name; \
+ /* Device Description */ \
+ const char *desc; \
+ /* ACPI _UID */ \
+ unsigned uid; \
+ /* Bus speed in Hz, default is I2C_SPEED_FAST */ \
+ enum i2c_speed speed; \
+ /* Wake GPE */ \
+ unsigned wake; \
+ /* Interrupt */ \
+ struct acpi_irq irq; \
+ /* \
+ * This flag will add a device propery which will \
+ * indicate to the OS that it should probe this \
+ * device before adding it. \
+ * \
+ * This can be used to declare a device that may not \
+ * exist on the board, for example to support multiple \
+ * trackpad vendors. \
+ */ \
+ int probed; \
+ /* GPIO used to indicate if this device is present */ \
+ unsigned device_present_gpio; \
+ unsigned device_present_gpio_invert; \
+ /* \
+ * GPIO used to take device out of reset or to put \
+ * it into reset. */ \
+ unsigned reset_gpio; \
+ /* \
+ * Delay to be inserted after device is taken out of \
+ * reset. */ \
+ unsigned reset_delay_ms; \
+ /* GPIO used to enable device. */ \
+ unsigned enable_gpio; \
+ /* Delay to be inserted after device is enabled. */ \
+ unsigned enable_delay_ms; \
+ }
+
+/*
+ * Fills in generic information about i2c device from device-tree
+ * properties. Place I2C_GENERIC_CONFIG at the start of device config
+ * structure. Callback can be provided to fill in any device-specific
+ * information in SSDT.
+ */
+void i2c_generic_fill_ssdt(struct device *dev,
+ void (*callback)(struct device *dev));
+
+#endif /* __I2C_GENERIC_GENERIC_H__ */