<p>Furquan Shaikh has uploaded this change for <strong>review</strong>.</p><p><a href="https://review.coreboot.org/28796">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">drivers/generic: Add support for providing DSD properties<br><br>This change adds support in generic device driver to add properties to<br>DSD table. This driver can be used by all generic devices that do not<br>need any special handling other than simply adding device properties<br>to be used by OS.<br><br>BUG=b:112888584<br><br>Change-Id: I0ca6614f1ef322397618676bbf6da898bef18990<br>Signed-off-by: Furquan Shaikh <furquan@google.com><br>---<br>M src/drivers/generic/generic/Kconfig<br>M src/drivers/generic/generic/Makefile.inc<br>A src/drivers/generic/generic/chip.h<br>A src/drivers/generic/generic/generic.c<br>4 files changed, 131 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://review.coreboot.org:29418/coreboot refs/changes/96/28796/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/src/drivers/generic/generic/Kconfig b/src/drivers/generic/generic/Kconfig</span><br><span>index 864b878..7b16b62 100644</span><br><span>--- a/src/drivers/generic/generic/Kconfig</span><br><span>+++ b/src/drivers/generic/generic/Kconfig</span><br><span>@@ -1,2 +1,3 @@</span><br><span> config DRIVERS_GENERIC_GENERIC</span><br><span>       bool</span><br><span style="color: hsl(120, 100%, 40%);">+  depends on HAVE_ACPI_TABLES</span><br><span>diff --git a/src/drivers/generic/generic/Makefile.inc b/src/drivers/generic/generic/Makefile.inc</span><br><span>index b7db254..37a873b 100644</span><br><span>--- a/src/drivers/generic/generic/Makefile.inc</span><br><span>+++ b/src/drivers/generic/generic/Makefile.inc</span><br><span>@@ -1 +1 @@</span><br><span style="color: hsl(0, 100%, 40%);">-# Empty</span><br><span style="color: hsl(120, 100%, 40%);">+ramstage-$(CONFIG_DRIVERS_GENERIC_GENERIC) += generic.c</span><br><span>diff --git a/src/drivers/generic/generic/chip.h b/src/drivers/generic/generic/chip.h</span><br><span>new file mode 100644</span><br><span>index 0000000..64f1543</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/generic/generic/chip.h</span><br><span>@@ -0,0 +1,35 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Google LLC.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#ifndef __GENERIC_GENERIC_CHIP_H__</span><br><span style="color: hsl(120, 100%, 40%);">+#define __GENERIC_GENERIC_CHIP_H__</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpi_device.h></span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#define MAX_GENERIC_PROPERTY_LIST 10</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct drivers_generic_generic_config {</span><br><span style="color: hsl(120, 100%, 40%);">+    const char *hid;        /* ACPI _HID (required) */</span><br><span style="color: hsl(120, 100%, 40%);">+    const char *cid;        /* ACPI _CID */</span><br><span style="color: hsl(120, 100%, 40%);">+       const char *name;       /* ACPI Device Name */</span><br><span style="color: hsl(120, 100%, 40%);">+        const char *desc;       /* ACPI _DDN */</span><br><span style="color: hsl(120, 100%, 40%);">+       unsigned int uid;       /* ACPI _UID */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     /* Generic properties for exporting device-specific data to the OS */</span><br><span style="color: hsl(120, 100%, 40%);">+ struct acpi_dp property_list[MAX_GENERIC_PROPERTY_LIST];</span><br><span style="color: hsl(120, 100%, 40%);">+      int property_count;</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#endif /* __GENERIC_GENERIC_CHIP_H__ */</span><br><span>diff --git a/src/drivers/generic/generic/generic.c b/src/drivers/generic/generic/generic.c</span><br><span>new file mode 100644</span><br><span>index 0000000..44fe375</span><br><span>--- /dev/null</span><br><span>+++ b/src/drivers/generic/generic/generic.c</span><br><span>@@ -0,0 +1,94 @@</span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * This file is part of the coreboot project.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * Copyright 2018 Google LLC</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is free software; you can redistribute it and/or modify</span><br><span style="color: hsl(120, 100%, 40%);">+ * it under the terms of the GNU General Public License as published by</span><br><span style="color: hsl(120, 100%, 40%);">+ * the Free Software Foundation; version 2 of the License.</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This program is distributed in the hope that it will be useful,</span><br><span style="color: hsl(120, 100%, 40%);">+ * but WITHOUT ANY WARRANTY; without even the implied warranty of</span><br><span style="color: hsl(120, 100%, 40%);">+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the</span><br><span style="color: hsl(120, 100%, 40%);">+ * GNU General Public License for more details.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+#include <arch/acpi_device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <console/console.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/device.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <device/path.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <stdint.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include <string.h></span><br><span style="color: hsl(120, 100%, 40%);">+#include "chip.h"</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void generic_dev_fill_ssdt_generator(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      struct acpi_dp *dsd;</span><br><span style="color: hsl(120, 100%, 40%);">+  struct drivers_generic_generic_config *config = dev->chip_info;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+  if (!dev->enabled || !config)</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     if (!config->hid) {</span><br><span style="color: hsl(120, 100%, 40%);">+                printk(BIOS_ERR, "%s: ERROR: _HID required\n", dev_path(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+              return;</span><br><span style="color: hsl(120, 100%, 40%);">+       }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+   acpigen_write_scope(acpi_device_scope(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_device(acpi_device_name(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_name_string("_HID", config->hid);</span><br><span style="color: hsl(120, 100%, 40%);">+  if (config->cid)</span><br><span style="color: hsl(120, 100%, 40%);">+           acpigen_write_name_string("_CID", config->cid);</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_write_name_integer("_UID", config->uid);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_name_string("_DDN", config->desc);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_write_STA(acpi_device_status(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ dsd = acpi_dp_new_table("_DSD");</span><br><span style="color: hsl(120, 100%, 40%);">+    acpi_dp_add_property_list(dsd, config->property_list,</span><br><span style="color: hsl(120, 100%, 40%);">+                                config->property_count);</span><br><span style="color: hsl(120, 100%, 40%);">+ acpi_dp_write(dsd);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ acpigen_pop_len();      /* Device */</span><br><span style="color: hsl(120, 100%, 40%);">+  acpigen_pop_len();      /* Scope */</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(dev),</span><br><span style="color: hsl(120, 100%, 40%);">+         config->desc ? : dev->chip_ops->name, dev_path(dev));</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const char *generic_dev_prepare_name(void)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      static char name[5];</span><br><span style="color: hsl(120, 100%, 40%);">+  static unsigned int id;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     snprintf(name, sizeof(name), "G%03.3X", id++);</span><br><span style="color: hsl(120, 100%, 40%);">+      name[4] = '\0';</span><br><span style="color: hsl(120, 100%, 40%);">+       return name;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static const char *generic_dev_acpi_name(const struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+      const struct drivers_generic_generic_config *config = dev->chip_info;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+    if (config->name)</span><br><span style="color: hsl(120, 100%, 40%);">+          return config->name;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+     return generic_dev_prepare_name();</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static struct device_operations generic_dev_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+  .read_resources           = DEVICE_NOOP,</span><br><span style="color: hsl(120, 100%, 40%);">+      .set_resources            = DEVICE_NOOP,</span><br><span style="color: hsl(120, 100%, 40%);">+      .enable_resources         = DEVICE_NOOP,</span><br><span style="color: hsl(120, 100%, 40%);">+      .acpi_name                = &generic_dev_acpi_name,</span><br><span style="color: hsl(120, 100%, 40%);">+       .acpi_fill_ssdt_generator       = &generic_dev_fill_ssdt_generator,</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static void generic_dev_enable(struct device *dev)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+  dev->ops = &generic_dev_ops;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+struct chip_operations drivers_generic_generic_ops = {</span><br><span style="color: hsl(120, 100%, 40%);">+      CHIP_NAME("Generic Device")</span><br><span style="color: hsl(120, 100%, 40%);">+ .enable_dev = &generic_dev_enable</span><br><span style="color: hsl(120, 100%, 40%);">+};</span><br><span></span><br></pre><p>To view, visit <a href="https://review.coreboot.org/28796">change 28796</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://review.coreboot.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://review.coreboot.org/28796"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: coreboot </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I0ca6614f1ef322397618676bbf6da898bef18990 </div>
<div style="display:none"> Gerrit-Change-Number: 28796 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Furquan Shaikh <furquan@google.com> </div>