Jon Murphy has uploaded this change for review.

View Change

acpi: add support for reading long battery strings

This adds EC_ACPI_MEM_STRINGS_FIFO, a method for host firmware to read
arbitrarily long battery information strings (or any other string, but
currently only supporting battery strings).

On ACPI platforms, the host generally reads battery information from a
shared memory region where the strings are limited to 8 bytes in length.
Expanding those would consume a large fraction of the available shared
memory space (limited to 256 bytes), so this implements an ACPI command
(based on the ACPI Embedded Controller Interface Specification) allowing
the host to read strings of any length while consuming only one byte of
ACPI memory space.

Although the EC also supports reading long strings using host commands
(EC_CMD_BATTERY_GET_STATIC), host commands are assumed to be the
exclusive domain of the OS and unavailable to AP firmware because it
would require careful cooperation (locking) to ensure that firmware and
other software cannot interfere with each other's host commands.

BUG=b:339171261
TEST=on yaviks, the EC console logs FIFO readout messages when used in
ACPI and correct strings are shown in the OS.

Original-Cq-Depend: chromium:5599370,chromium:5605867,chromium:5605868
Original-Change-Id: Ibb3d4115f7d5c6b6c2512deb4e53077a48a355e3
Original-Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/5581473
Original-Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
Original-Commit-Queue: Peter Marheine <pmarheine@chromium.org>
Original-Code-Coverage: Zoss <zoss-cl-coverage@prod.google.com>
Original-Tested-by: Peter Marheine <pmarheine@chromium.org>

GitOrigin-RevId: 22e6b9a3ef43132f10e77bd5845b648fdbd387f1

Change-Id: I871433c66cefe5522f9ff942841518e0d6654ca3
Signed-off-by: Jon Murphy <jpmurphy@google.com>
---
M src/ec/google/chromeec/ec_commands.h
1 file changed, 59 insertions(+), 0 deletions(-)

git pull ssh://review.coreboot.org:29418/coreboot refs/changes/26/83526/1
diff --git a/src/ec/google/chromeec/ec_commands.h b/src/ec/google/chromeec/ec_commands.h
index 1673c8b..715f94c 100644
--- a/src/ec/google/chromeec/ec_commands.h
+++ b/src/ec/google/chromeec/ec_commands.h
@@ -527,6 +527,65 @@
(((x) & 0xf0) >> USB_RETIMER_FW_UPDATE_OP_SHIFT)

/*
+ * Offset 0x15 is reserved for PBOK, added to Coreboot in
+ * https://crrev.com/c/3840943 and proposed for inclusion here
+ * in https://crrev.com/c/3547317.
+ */
+
+/*
+ * Get extended strings from the EC.
+ * Write:
+ * String index, or 0 to probe for EC support.
+ * Read:
+ * String bytes, following by repeating null bytes.
+ *
+ * Writing a byte (EC_ACPI_MEM_STRINGS_FIFO_ID_*) selects a string, and the
+ * following reads return the non-null bytes of the string in sequence until
+ * the end of the string is reached. After the end of the string, reads 0 until
+ * another byte is written. This interface allows ACPI firmware to read longer
+ * strings from the EC than can reasonably fit into the shared memory region.
+ *
+ * To probe for EC support, write FIFO_ID_VERSION and read will return at least
+ * one nonzero (MEM_STRINGS_FIFO_V1 for example) if MEM_STRINGS_FIFO is
+ * supported. Returned values will indicate which strings are supported. If the
+ * first byte is 0xff, the strings FIFO is unsupported.
+ */
+#define EC_ACPI_MEM_STRINGS_FIFO 0x16
+
+/* String index to probe EC support. */
+#define EC_ACPI_MEM_STRINGS_FIFO_ID_VERSION 0
+#define EC_ACPI_MEM_STRINGS_FIFO_V1 1
+/*
+ * 0xff is the value the EC returns for unimplemented reads, indicating
+ * the current EC firmware does not implement this command.
+ */
+#define EC_ACPI_MEM_STRINGS_FIFO_UNSUPPORTED 0xff
+
+/*
+ * Battery model number for the selected battery. Supported since V1.
+ * Presents the same data as EC_MEMMAP_BATT_MODEL, but can provide more
+ * than 8 bytes.
+ *
+ * This and the other FIFO_ID_BATTERY strings can select one of multiple
+ * batteries by changing the value at EC_MEMMAP_BATT_INDEX. Once that index
+ * is changed, reads of these strings will return information for the
+ * corresponding battery, if present.
+ */
+#define EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_MODEL 1
+/*
+ * Battery serial number for the selected battery. Supported since V1.
+ * Presents the same data as EC_MEMMAP_BATT_SERIAL, but can provide more
+ * than 8 bytes.
+ */
+#define EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_SERIAL 2
+/*
+ * Battery manufacturer for the selected battery. Supported since V1.
+ * Presents the same data as EC_MEMMAP_BATT_MFGR, but can provide more
+ * than 8 bytes.
+ */
+#define EC_ACPI_MEM_STRINGS_FIFO_ID_BATTERY_MANUFACTURER 3
+
+/*
* ACPI addresses 0x20 - 0xff map to EC_MEMMAP offset 0x00 - 0xdf. This data
* is read-only from the AP. Added in EC_ACPI_MEM_VERSION 2.
*/

To view, visit change 83526. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-MessageType: newchange
Gerrit-Project: coreboot
Gerrit-Branch: main
Gerrit-Change-Id: I871433c66cefe5522f9ff942841518e0d6654ca3
Gerrit-Change-Number: 83526
Gerrit-PatchSet: 1
Gerrit-Owner: Jon Murphy <jpmurphy@google.com>