summaryrefslogtreecommitdiff
path: root/chip
diff options
context:
space:
mode:
authorTzung-Bi Shih <tzungbi@chromium.org>2020-07-20 16:13:50 +0800
committerCommit Bot <commit-bot@chromium.org>2020-07-21 11:20:08 +0000
commitf54bbec3624c9b211715f586f75771dae12ad74c (patch)
tree65f4b6875ef52705c5ea799a0aac23fcf6e2aecf /chip
parente489ebdacb60409cdb6d763cc858b9b8df3f8854 (diff)
downloadchrome-ec-f54bbec3624c9b211715f586f75771dae12ad74c.tar.gz
chip/mt8192_scp: add memory maps
Adds memory maps for mapping SCP address to AP address and vice versa. BRANCH=none BUG=b:146213943 BUG=b:156222459 TEST=make BOARD=asurada_scp Signed-off-by: Tzung-Bi Shih <tzungbi@chromium.org> Change-Id: I5e5e34044f54d304bcbe591bf48d6e955d4ed512 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2306900 Reviewed-by: Jett Rink <jettrink@chromium.org> Reviewed-by: Eric Yilun Lin <yllin@chromium.org>
Diffstat (limited to 'chip')
-rw-r--r--chip/mt8192_scp/build.mk1
-rw-r--r--chip/mt8192_scp/memmap.c111
-rw-r--r--chip/mt8192_scp/memmap.h31
-rw-r--r--chip/mt8192_scp/system.c30
4 files changed, 145 insertions, 28 deletions
diff --git a/chip/mt8192_scp/build.mk b/chip/mt8192_scp/build.mk
index 86ba6a499c..0925ff2245 100644
--- a/chip/mt8192_scp/build.mk
+++ b/chip/mt8192_scp/build.mk
@@ -12,6 +12,7 @@ CORE:=riscv-rv32i
chip-y+=clock.o
chip-y+=gpio.o
chip-y+=intc.o
+chip-y+=memmap.o
chip-y+=system.o
chip-y+=uart.o
diff --git a/chip/mt8192_scp/memmap.c b/chip/mt8192_scp/memmap.c
new file mode 100644
index 0000000000..63fa4f8fc5
--- /dev/null
+++ b/chip/mt8192_scp/memmap.c
@@ -0,0 +1,111 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#include "registers.h"
+#include "stdint.h"
+
+/*
+ * Map SCP address (bits 31~28) to AP address
+ *
+ * SCP address AP address Note
+ *
+ * 0x0000_0000 SRAM
+ * 0x1000_0000 0x6000_0000 un-cached DRAM
+ * 0x2000_0000 0x7000_0000 un-cached DRAM
+ * 0x3000_0000
+ *
+ * 0x4000_0000
+ * 0x5000_0000 0x0000_0000
+ * 0x6000_0000 0x1000_0000
+ * 0x7000_0000 0xa000_0000
+ *
+ * 0x8000_0000
+ * 0x9000_0000 0x8000_0000
+ * 0xa000_0000 0x9000_0000
+ * 0xb000_0000
+ *
+ * 0xc000_0000 0x8000_0000
+ * 0xd000_0000 0x2000_0000
+ * 0xe000_0000 0x3000_0000
+ * 0xf000_0000 0x5000_0000
+ */
+
+#define REMAP_ADDR_SHIFT 28
+#define REMAP_ADDR_LSB_MASK (BIT(REMAP_ADDR_SHIFT) - 1)
+#define REMAP_ADDR_MSB_MASK ((~0) << REMAP_ADDR_SHIFT)
+#define MAP_INVALID 0xff
+
+static const uint8_t addr_map[16] = {
+ MAP_INVALID, /* SRAM */
+ 0x6, /* ext_addr_0x1 */
+ 0x7, /* ext_addr_0x2 */
+ MAP_INVALID, /* no ext_addr_0x3 */
+
+ MAP_INVALID, /* no ext_addr_0x4 */
+ 0x0, /* ext_addr_0x5 */
+ 0x1, /* ext_addr_0x6 */
+ 0xa, /* ext_addr_0x7 */
+
+ MAP_INVALID, /* no ext_addr_0x8 */
+ 0x8, /* ext_addr_0x9 */
+ 0x9, /* ext_addr_0xa */
+ MAP_INVALID, /* no ext_addr_0xb */
+
+ 0x8, /* ext_addr_0xc */
+ 0x2, /* ext_addr_0xd */
+ 0x3, /* ext_addr_0xe */
+ 0x5, /* ext_addr_0xf */
+};
+
+void memmap_init(void)
+{
+ SCP_R_REMAP_0X0123 =
+ (uint32_t)addr_map[0x1] << 8 |
+ (uint32_t)addr_map[0x2] << 16;
+
+ SCP_R_REMAP_0X4567 =
+ (uint32_t)addr_map[0x5] << 8 |
+ (uint32_t)addr_map[0x6] << 16 |
+ (uint32_t)addr_map[0x7] << 24;
+
+ SCP_R_REMAP_0X89AB =
+ (uint32_t)addr_map[0x9] << 8 |
+ (uint32_t)addr_map[0xa] << 16;
+
+ SCP_R_REMAP_0XCDEF =
+ (uint32_t)addr_map[0xc] |
+ (uint32_t)addr_map[0xd] << 8 |
+ (uint32_t)addr_map[0xe] << 16 |
+ (uint32_t)addr_map[0xf] << 24;
+}
+
+int memmap_ap_to_scp(uintptr_t ap_addr, uintptr_t *scp_addr)
+{
+ int i;
+ uint8_t msb = ap_addr >> REMAP_ADDR_SHIFT;
+
+ for (i = 0; i < ARRAY_SIZE(addr_map); ++i) {
+ if (addr_map[i] != msb)
+ continue;
+
+ *scp_addr = (ap_addr & REMAP_ADDR_LSB_MASK) |
+ (i << REMAP_ADDR_SHIFT);
+ return EC_SUCCESS;
+ }
+
+ return EC_ERROR_INVAL;
+}
+
+int memmap_scp_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr)
+{
+ int i = scp_addr >> REMAP_ADDR_SHIFT;
+
+ if (addr_map[i] == MAP_INVALID)
+ return EC_ERROR_INVAL;
+
+ *ap_addr = (scp_addr & REMAP_ADDR_LSB_MASK) |
+ (addr_map[i] << REMAP_ADDR_SHIFT);
+ return EC_SUCCESS;
+}
diff --git a/chip/mt8192_scp/memmap.h b/chip/mt8192_scp/memmap.h
new file mode 100644
index 0000000000..0857c9a89e
--- /dev/null
+++ b/chip/mt8192_scp/memmap.h
@@ -0,0 +1,31 @@
+/* Copyright 2020 The Chromium OS Authors. All rights reserved.
+ * Use of this source code is governed by a BSD-style license that can be
+ * found in the LICENSE file.
+ */
+
+#ifndef __CROS_EC_MEMMAP_H
+#define __CROS_EC_MEMMAP_H
+
+#include "stdint.h"
+
+void memmap_init(void);
+
+/**
+ * Translate AP addr to SCP addr.
+ *
+ * @param ap_addr AP address to translate
+ * @param scp_addr Translated AP address
+ * @return EC_SUCCESS or EC_ERROR_INVAL
+ */
+int memmap_ap_to_scp(uintptr_t ap_addr, uintptr_t *scp_addr);
+
+/**
+ * Translate SCP addr to AP addr.
+ *
+ * @param scp_addr SCP address to translate
+ * @param ap_addr Translated SCP address
+ * @return EC_SUCCESS or EC_ERROR_INVAL
+ */
+int memmap_scp_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr);
+
+#endif /* #ifndef __CROS_EC_MEMMAP_H */
diff --git a/chip/mt8192_scp/system.c b/chip/mt8192_scp/system.c
index 7a68209625..3c5b6c837b 100644
--- a/chip/mt8192_scp/system.c
+++ b/chip/mt8192_scp/system.c
@@ -5,39 +5,13 @@
/* System : hardware specific implementation */
+#include "memmap.h"
#include "registers.h"
#include "system.h"
-static void scp_remap_init(void)
-{
- /*
- * external address SCP address
- *
- * 0x10000000 0x60000000
- * 0x20000000 0x70000000
- * 0x30000000
- * 0x40000000
- * 0x50000000
- * 0x60000000 0x10000000
- * 0x70000000 0xA0000000
- * 0x80000000
- * 0x90000000 0x80000000
- * 0xA0000000 0x90000000
- * 0xB0000000
- * 0xC0000000 0x80000000
- * 0xD0000000 0x20000000
- * 0xE0000000 0x30000000
- * 0xF0000000 0x50000000
- */
- SCP_R_REMAP_0X0123 = 0x00070600;
- SCP_R_REMAP_0X4567 = 0x0A010000;
- SCP_R_REMAP_0X89AB = 0x00090800;
- SCP_R_REMAP_0XCDEF = 0x05030208;
-}
-
void system_pre_init(void)
{
- scp_remap_init();
+ memmap_init();
/* Disable jump (it has only RW) and enable MPU. */
/* TODO: implement MPU */
system_disable_jump();