[PATCH 3/5] firmware: google memconsole: Add coreboot support

2017-03-23 Thread Thierry Escande
Coreboot (http://www.coreboot.org) allows to save the firmware console
output in a memory buffer. With this patch, the address of this memory
buffer is obtained from coreboot tables on x86 chromebook devices
declaring an ACPI device with name matching GOOGCB00 or BOOT.

If the memconsole-coreboot driver is able to find the coreboot table,
the memconsole driver sets the cbmem_console address and initializes the
memconsole sysfs entries.

The coreboot_table-acpi driver is responsible for setting the address of
the coreboot table header when probed. If this address is not yet set
when memconsole-coreboot is probed, then the probe is deferred by
returning -EPROBE_DEFER.

This patch is a rework/split/merge of patches from the chromeos v4.4
kernel tree originally authored by:
 Vadim Bendebury 
 Wei-Ning Huang 
 Yuji Sasaki 
 Duncan Laurie 
 Julius Werner 
 Brian Norris 

Signed-off-by: Thierry Escande 
---
 drivers/firmware/google/Kconfig   |  25 +-
 drivers/firmware/google/Makefile  |   3 +
 drivers/firmware/google/coreboot_table-acpi.c |  88 +
 drivers/firmware/google/coreboot_table.c  |  94 ++
 drivers/firmware/google/coreboot_table.h  |  50 
 drivers/firmware/google/memconsole-coreboot.c | 109 ++
 6 files changed, 368 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/google/coreboot_table-acpi.c
 create mode 100644 drivers/firmware/google/coreboot_table.c
 create mode 100644 drivers/firmware/google/coreboot_table.h
 create mode 100644 drivers/firmware/google/memconsole-coreboot.c

diff --git a/drivers/firmware/google/Kconfig b/drivers/firmware/google/Kconfig
index 27a0658..840bd62 100644
--- a/drivers/firmware/google/Kconfig
+++ b/drivers/firmware/google/Kconfig
@@ -19,9 +19,23 @@ config GOOGLE_SMI
  clearing the EFI event log and reading and writing NVRAM
  variables.
 
+config GOOGLE_COREBOOT_TABLE
+   tristate
+   depends on GOOGLE_COREBOOT_TABLE_ACPI
+
+config GOOGLE_COREBOOT_TABLE_ACPI
+   tristate "Coreboot Table Access - ACPI"
+   depends on ACPI
+   select GOOGLE_COREBOOT_TABLE
+   help
+ This option enables the coreboot_table module, which provides other
+ firmware modules to access to the coreboot table. The coreboot table
+ pointer is accessed through the ACPI "GOOGCB00" object.
+ If unsure say N.
+
 config GOOGLE_MEMCONSOLE
tristate
-   depends on GOOGLE_MEMCONSOLE_X86_LEGACY
+   depends on GOOGLE_MEMCONSOLE_X86_LEGACY || GOOGLE_MEMCONSOLE_COREBOOT
 
 config GOOGLE_MEMCONSOLE_X86_LEGACY
tristate "Firmware Memory Console - X86 Legacy support"
@@ -32,4 +46,13 @@ config GOOGLE_MEMCONSOLE_X86_LEGACY
  the EBDA on Google servers.  If found, this log is exported to
  userland in the file /sys/firmware/log.
 
+config GOOGLE_MEMCONSOLE_COREBOOT
+   tristate "Firmware Memory Console"
+   depends on GOOGLE_COREBOOT_TABLE
+   select GOOGLE_MEMCONSOLE
+   help
+ This option enables the kernel to search for a firmware log in
+ the coreboot table.  If found, this log is exported to userland
+ in the file /sys/firmware/log.
+
 endif # GOOGLE_FIRMWARE
diff --git a/drivers/firmware/google/Makefile b/drivers/firmware/google/Makefile
index 10683ef..662a83e 100644
--- a/drivers/firmware/google/Makefile
+++ b/drivers/firmware/google/Makefile
@@ -1,4 +1,7 @@
 
 obj-$(CONFIG_GOOGLE_SMI)   += gsmi.o
+obj-$(CONFIG_GOOGLE_COREBOOT_TABLE)+= coreboot_table.o
+obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_ACPI)   += coreboot_table-acpi.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE)+= memconsole.o
+obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT)   += memconsole-coreboot.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE_X86_LEGACY) += memconsole-x86-legacy.o
diff --git a/drivers/firmware/google/coreboot_table-acpi.c 
b/drivers/firmware/google/coreboot_table-acpi.c
new file mode 100644
index 000..fb98db2
--- /dev/null
+++ b/drivers/firmware/google/coreboot_table-acpi.c
@@ -0,0 +1,88 @@
+/*
+ * coreboot_table-acpi.c
+ *
+ * Using ACPI to locate Coreboot table and provide coreboot table access.
+ *
+ * Copyright 2017 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2.0 as published by
+ * the Free Software Foundation.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "coreboot_table.h"
+
+static int 

[PATCH 3/5] firmware: google memconsole: Add coreboot support

2017-03-23 Thread Thierry Escande
Coreboot (http://www.coreboot.org) allows to save the firmware console
output in a memory buffer. With this patch, the address of this memory
buffer is obtained from coreboot tables on x86 chromebook devices
declaring an ACPI device with name matching GOOGCB00 or BOOT.

If the memconsole-coreboot driver is able to find the coreboot table,
the memconsole driver sets the cbmem_console address and initializes the
memconsole sysfs entries.

The coreboot_table-acpi driver is responsible for setting the address of
the coreboot table header when probed. If this address is not yet set
when memconsole-coreboot is probed, then the probe is deferred by
returning -EPROBE_DEFER.

This patch is a rework/split/merge of patches from the chromeos v4.4
kernel tree originally authored by:
 Vadim Bendebury 
 Wei-Ning Huang 
 Yuji Sasaki 
 Duncan Laurie 
 Julius Werner 
 Brian Norris 

Signed-off-by: Thierry Escande 
---
 drivers/firmware/google/Kconfig   |  25 +-
 drivers/firmware/google/Makefile  |   3 +
 drivers/firmware/google/coreboot_table-acpi.c |  88 +
 drivers/firmware/google/coreboot_table.c  |  94 ++
 drivers/firmware/google/coreboot_table.h  |  50 
 drivers/firmware/google/memconsole-coreboot.c | 109 ++
 6 files changed, 368 insertions(+), 1 deletion(-)
 create mode 100644 drivers/firmware/google/coreboot_table-acpi.c
 create mode 100644 drivers/firmware/google/coreboot_table.c
 create mode 100644 drivers/firmware/google/coreboot_table.h
 create mode 100644 drivers/firmware/google/memconsole-coreboot.c

diff --git a/drivers/firmware/google/Kconfig b/drivers/firmware/google/Kconfig
index 27a0658..840bd62 100644
--- a/drivers/firmware/google/Kconfig
+++ b/drivers/firmware/google/Kconfig
@@ -19,9 +19,23 @@ config GOOGLE_SMI
  clearing the EFI event log and reading and writing NVRAM
  variables.
 
+config GOOGLE_COREBOOT_TABLE
+   tristate
+   depends on GOOGLE_COREBOOT_TABLE_ACPI
+
+config GOOGLE_COREBOOT_TABLE_ACPI
+   tristate "Coreboot Table Access - ACPI"
+   depends on ACPI
+   select GOOGLE_COREBOOT_TABLE
+   help
+ This option enables the coreboot_table module, which provides other
+ firmware modules to access to the coreboot table. The coreboot table
+ pointer is accessed through the ACPI "GOOGCB00" object.
+ If unsure say N.
+
 config GOOGLE_MEMCONSOLE
tristate
-   depends on GOOGLE_MEMCONSOLE_X86_LEGACY
+   depends on GOOGLE_MEMCONSOLE_X86_LEGACY || GOOGLE_MEMCONSOLE_COREBOOT
 
 config GOOGLE_MEMCONSOLE_X86_LEGACY
tristate "Firmware Memory Console - X86 Legacy support"
@@ -32,4 +46,13 @@ config GOOGLE_MEMCONSOLE_X86_LEGACY
  the EBDA on Google servers.  If found, this log is exported to
  userland in the file /sys/firmware/log.
 
+config GOOGLE_MEMCONSOLE_COREBOOT
+   tristate "Firmware Memory Console"
+   depends on GOOGLE_COREBOOT_TABLE
+   select GOOGLE_MEMCONSOLE
+   help
+ This option enables the kernel to search for a firmware log in
+ the coreboot table.  If found, this log is exported to userland
+ in the file /sys/firmware/log.
+
 endif # GOOGLE_FIRMWARE
diff --git a/drivers/firmware/google/Makefile b/drivers/firmware/google/Makefile
index 10683ef..662a83e 100644
--- a/drivers/firmware/google/Makefile
+++ b/drivers/firmware/google/Makefile
@@ -1,4 +1,7 @@
 
 obj-$(CONFIG_GOOGLE_SMI)   += gsmi.o
+obj-$(CONFIG_GOOGLE_COREBOOT_TABLE)+= coreboot_table.o
+obj-$(CONFIG_GOOGLE_COREBOOT_TABLE_ACPI)   += coreboot_table-acpi.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE)+= memconsole.o
+obj-$(CONFIG_GOOGLE_MEMCONSOLE_COREBOOT)   += memconsole-coreboot.o
 obj-$(CONFIG_GOOGLE_MEMCONSOLE_X86_LEGACY) += memconsole-x86-legacy.o
diff --git a/drivers/firmware/google/coreboot_table-acpi.c 
b/drivers/firmware/google/coreboot_table-acpi.c
new file mode 100644
index 000..fb98db2
--- /dev/null
+++ b/drivers/firmware/google/coreboot_table-acpi.c
@@ -0,0 +1,88 @@
+/*
+ * coreboot_table-acpi.c
+ *
+ * Using ACPI to locate Coreboot table and provide coreboot table access.
+ *
+ * Copyright 2017 Google Inc.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License v2.0 as published by
+ * the Free Software Foundation.
+ *
+ * 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 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "coreboot_table.h"
+
+static int coreboot_table_acpi_probe(struct platform_device *pdev)
+{
+   phys_addr_t phyaddr;
+   resource_size_t len;
+   struct coreboot_table_header __iomem