summaryrefslogtreecommitdiff
path: root/src/soc/amd/common/block/acpi
diff options
context:
space:
mode:
authorAaron Durbin <adurbin@chromium.org>2020-08-14 15:08:10 -0600
committerAaron Durbin <adurbin@chromium.org>2020-08-17 17:40:01 +0000
commita244eb3dad1e81a1a7d15cf43ca7f622345ac230 (patch)
tree82bc9af863a4ed29e205d26a50dfbf8c1f9618fa /src/soc/amd/common/block/acpi
parent746e598d07091b574036bbcb2d358fa0ebe5f875 (diff)
soc/amd/common: add acpi_fill_gnvs()
In order to reduce code duplication provide an acpi_fill_gnvs() helper function. Intent is to move stoneyridge and picasso over to using this common implementation instead of duplicating it. BUG=b:159947207 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Change-Id: I21c6e2c24eaf42f31ae57c05df7f633d7dc266d9 Reviewed-on: https://review.coreboot.org/c/coreboot/+/44482 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Furquan Shaikh <furquan@google.com>
Diffstat (limited to 'src/soc/amd/common/block/acpi')
-rw-r--r--src/soc/amd/common/block/acpi/acpi.c38
1 files changed, 38 insertions, 0 deletions
diff --git a/src/soc/amd/common/block/acpi/acpi.c b/src/soc/amd/common/block/acpi/acpi.c
index be331e3fea..0e6dabf150 100644
--- a/src/soc/amd/common/block/acpi/acpi.c
+++ b/src/soc/amd/common/block/acpi/acpi.c
@@ -113,6 +113,44 @@ void acpi_clear_pm_gpe_status(void)
acpi_write32(MMIO_ACPI_GPE0_STS, acpi_read32(MMIO_ACPI_GPE0_STS));
}
+static int get_index_bit(uint32_t value, uint16_t limit)
+{
+ uint16_t i;
+ uint32_t t;
+
+ if (limit >= TOTAL_BITS(uint32_t))
+ return -1;
+
+ /* get a mask of valid bits. Ex limit = 3, set bits 0-2 */
+ t = (1 << limit) - 1;
+ if ((value & t) == 0)
+ return -1;
+ t = 1;
+ for (i = 0; i < limit; i++) {
+ if (value & t)
+ break;
+ t <<= 1;
+ }
+ return i;
+}
+
+void acpi_fill_gnvs(struct global_nvs *gnvs, const struct acpi_pm_gpe_state *state)
+{
+ int index;
+
+ index = get_index_bit(state->pm1_sts & state->pm1_en, PM1_LIMIT);
+ if (index < 0)
+ gnvs->pm1i = ~0ULL;
+ else
+ gnvs->pm1i = index;
+
+ index = get_index_bit(state->gpe0_sts & state->gpe0_en, GPE0_LIMIT);
+ if (index < 0)
+ gnvs->gpei = ~0ULL;
+ else
+ gnvs->gpei = index;
+}
+
static void save_sws(uint16_t pm1_status)
{
struct soc_power_reg *sws;