Peter Marheine has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/82775?usp=email )
Change subject: chromeec: supporting reading long battery strings ......................................................................
chromeec: supporting reading long battery strings
The Chrome EC currently supports two ways to read battery strings on ACPI platforms:
* Read up to 8 bytes from EC shared memory BMFG, BMOD, ... * Send a EC_CMD_BATTERY_GET_STATIC host command and read strings from the response. This is assumed to be exclusively controlled by the OS, because host commands' use of buffers is prone to race conditions.
To support readout of longer strings via ACPI mechanisms, this change adds support for EC_ACPI_MEM_STRINGS_FIFO (https://crrev.com/c/5581473) and allows ACPI firmware to read strings of arbitrary length (currently limited to 64 characters in the implementation) from the EC and to determine whether this function is supported by the EC (falling back to shared memory if not).
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. If EC support is removed, correct strings are still shown in the OS. BRANCH=nissa
Change-Id: Ia29cacb7d86402490f9ac458f0be50e3f2192b04 Signed-off-by: Peter Marheine pmarheine@chromium.org --- M src/ec/google/chromeec/acpi/battery.asl M src/ec/google/chromeec/acpi/ec.asl 2 files changed, 80 insertions(+), 6 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/75/82775/1
diff --git a/src/ec/google/chromeec/acpi/battery.asl b/src/ec/google/chromeec/acpi/battery.asl index 5344111..b508995 100644 --- a/src/ec/google/chromeec/acpi/battery.asl +++ b/src/ec/google/chromeec/acpi/battery.asl @@ -54,6 +54,79 @@ Return (Local0) }
+// Cached flag for BSRF FIFO readout support from EC. +Name(BRSS, 0xff) + +// Read extended battery strings from the selected battery. +// Arg0 = string index +// +// If supported by the EC, strings of arbitrary length are read using the +// FIFO readout method. Otherwise short (no more than 8 bytes) strings are +// read from the EC shared memory map. The desired battery index should be +// selected with BTSW before calling this method. +Method(BRSX, 1, Serialized) +{ + // It doesn't make sense to read the FIFO support indicator. + if (Arg0 == 0) + { + Return ("") + } + + If (BRSS == 0xff) + { + // Write 0 to BSRF to read back a support indicator; nonzero and + // non-0xFF if FIFO readout is supported, assuming minimum v1 support + // for strings 1 through 3. + BSRF = 0 + BRSS = BSRF + + // 0xff readback also means no support for FIFO readout, when the EC + // doesn't even know what this command is. + if (BRSS == 0xff) + { + BRSS = 0 + } + } + + // If FIFO readout through BSRF is not supported, fall back to reading + // the short strings in EMEM. + If (BRSS == 0) + { + If (Arg0 == 1) + { + Return (ToString (Concatenate (BMOD, 0))) + } + ElseIf (Arg0 == 2) + { + Return (ToString (Concatenate (BSER, 0))) + } + ElseIf (Arg0 == 3) + { + Return (ToString (Concatenate (BMFG, 0))) + } + Else + { + Return ("") + } + } + + // Select requested parameter to read + BSRF = Arg0 + + // Read to end of string, or up to a reasonable maximum length. Reads of + // BSRF consume bytes from the FIFO, so take care to read it only once + // per byte of data. + Local0 = "" + Local1 = BSRF + While (Local1 != 0 && SizeOf (Local0) < 32) + { + Local0 = Concatenate (Local0, ToString (Local1)) + Local1 = BSRF + } + + Return (Local0) +} + // _BIF implementation. // Arg0 = battery index // Arg1 = PBIF @@ -86,9 +159,9 @@ Arg1[6] = Local2
// Get battery info from mainboard - Arg1[9] = ToString(Concatenate(BMOD, 0x00)) - Arg1[10] = ToString(Concatenate(BSER, 0x00)) - Arg1[12] = ToString(Concatenate(BMFG, 0x00)) + Arg1[9] = BRSX (1) + Arg1[10] = BRSX (2) + Arg1[12] = BRSX (3)
Release (^BATM) Return (Arg1) @@ -129,9 +202,9 @@ Arg1[8] = BTCC
// Get battery info from mainboard - Arg1[16] = ToString(Concatenate(BMOD, 0x00)) - Arg1[17] = ToString(Concatenate(BSER, 0x00)) - Arg1[19] = ToString(Concatenate(BMFG, 0x00)) + Arg1[16] = BRSX (1) + Arg1[17] = BRSX (2) + Arg1[19] = BRSX (3)
Release (^BATM) Return (Arg1) diff --git a/src/ec/google/chromeec/acpi/ec.asl b/src/ec/google/chromeec/acpi/ec.asl index d6d33b2..741ad59 100644 --- a/src/ec/google/chromeec/acpi/ec.asl +++ b/src/ec/google/chromeec/acpi/ec.asl @@ -100,6 +100,7 @@ USPP, 8, // USB Port Power RFWU, 8, // Retimer Firmware Update PBOK, 8, // Power source change count from dptf + BSRF, 8, // Battery string readout FIFO }
#if CONFIG(EC_GOOGLE_CHROMEEC_ACPI_MEMMAP)