summaryrefslogtreecommitdiff
path: root/chip/mt_scp/mt818x/memmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'chip/mt_scp/mt818x/memmap.c')
-rw-r--r--chip/mt_scp/mt818x/memmap.c86
1 files changed, 41 insertions, 45 deletions
diff --git a/chip/mt_scp/mt818x/memmap.c b/chip/mt_scp/mt818x/memmap.c
index 6d8f2b0c87..0ecb370cf3 100644
--- a/chip/mt_scp/mt818x/memmap.c
+++ b/chip/mt_scp/mt818x/memmap.c
@@ -1,4 +1,4 @@
-/* Copyright 2018 The Chromium OS Authors. All rights reserved.
+/* Copyright 2018 The ChromiumOS Authors
* Use of this source code is governed by a BSD-style license that can be
* found in the LICENSE file.
*
@@ -12,6 +12,7 @@
#include "memmap.h"
#include "registers.h"
#include "util.h"
+#include "task.h"
/*
* Map SCP address (bits 31~28) to AP address
@@ -34,13 +35,13 @@
#define MAP_INVALID 0xff
static const uint8_t addr_map[16] = {
- MAP_INVALID, /* 0x0: SRAM */
- MAP_INVALID, /* 0x1: Cached access (see below) */
- 0x4, 0x5, /* 0x2-0x3 */
- MAP_INVALID, MAP_INVALID, /* 0x4-0x5 (unmapped: registers) */
- 0x6, 0x7, 0x8, /* 0x6-0x8 */
- 0x0, 0x1, 0x2, 0x3, /* 0x9-0xc */
- 0x1, 0xa, 0x9 /* 0xd-0xf */
+ MAP_INVALID, /* 0x0: SRAM */
+ MAP_INVALID, /* 0x1: Cached access (see below) */
+ 0x4, 0x5, /* 0x2-0x3 */
+ MAP_INVALID, MAP_INVALID, /* 0x4-0x5 (unmapped: registers) */
+ 0x6, 0x7, 0x8, /* 0x6-0x8 */
+ 0x0, 0x1, 0x2, 0x3, /* 0x9-0xc */
+ 0x1, 0xa, 0x9 /* 0xd-0xf */
};
/*
@@ -49,8 +50,6 @@ static const uint8_t addr_map[16] = {
*/
#define CACHE_TRANS_AP_ADDR 0x50000000
#define CACHE_TRANS_SCP_CACHE_ADDR 0x10000000
-/* FIXME: This should be configurable */
-#define CACHE_TRANS_AP_SIZE 0x00400000
#ifdef CONFIG_DRAM_BASE
BUILD_ASSERT(CONFIG_DRAM_BASE_LOAD == CACHE_TRANS_AP_ADDR);
@@ -60,16 +59,14 @@ BUILD_ASSERT(CONFIG_DRAM_BASE == CACHE_TRANS_SCP_CACHE_ADDR);
static void cpu_invalidate_icache(void)
{
SCP_CACHE_OP(CACHE_ICACHE) &= ~SCP_CACHE_OP_OP_MASK;
- SCP_CACHE_OP(CACHE_ICACHE) |=
- OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN;
+ SCP_CACHE_OP(CACHE_ICACHE) |= OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN;
asm volatile("dsb; isb");
}
void cpu_invalidate_dcache(void)
{
SCP_CACHE_OP(CACHE_DCACHE) &= ~SCP_CACHE_OP_OP_MASK;
- SCP_CACHE_OP(CACHE_DCACHE) |=
- OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN;
+ SCP_CACHE_OP(CACHE_DCACHE) |= OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN;
/* Read is necessary to confirm the invalidation finish. */
REG32(CACHE_TRANS_SCP_CACHE_ADDR);
asm volatile("dsb;");
@@ -80,6 +77,8 @@ void cpu_invalidate_dcache_range(uintptr_t base, unsigned int length)
size_t pos;
uintptr_t addr;
+ interrupt_disable();
+
for (pos = 0; pos < length; pos += SCP_CACHE_LINE_SIZE) {
addr = base + pos;
SCP_CACHE_OP(CACHE_DCACHE) = addr & SCP_CACHE_OP_TADDR_MASK;
@@ -88,17 +87,18 @@ void cpu_invalidate_dcache_range(uintptr_t base, unsigned int length)
/* Read necessary to confirm the invalidation finish. */
REG32(addr);
}
+
asm volatile("dsb;");
+ interrupt_enable();
}
void cpu_clean_invalidate_dcache(void)
{
SCP_CACHE_OP(CACHE_DCACHE) &= ~SCP_CACHE_OP_OP_MASK;
- SCP_CACHE_OP(CACHE_DCACHE) |=
- OP_CACHE_FLUSH_ALL_LINES | SCP_CACHE_OP_EN;
+ SCP_CACHE_OP(CACHE_DCACHE) |= OP_CACHE_FLUSH_ALL_LINES |
+ SCP_CACHE_OP_EN;
SCP_CACHE_OP(CACHE_DCACHE) &= ~SCP_CACHE_OP_OP_MASK;
- SCP_CACHE_OP(CACHE_DCACHE) |=
- OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN;
+ SCP_CACHE_OP(CACHE_DCACHE) |= OP_INVALIDATE_ALL_LINES | SCP_CACHE_OP_EN;
/* Read necessary to confirm the invalidation finish. */
REG32(CACHE_TRANS_SCP_CACHE_ADDR);
asm volatile("dsb;");
@@ -109,6 +109,7 @@ void cpu_clean_invalidate_dcache_range(uintptr_t base, unsigned int length)
size_t pos;
uintptr_t addr;
+ interrupt_disable();
for (pos = 0; pos < length; pos += SCP_CACHE_LINE_SIZE) {
addr = base + pos;
SCP_CACHE_OP(CACHE_DCACHE) = addr & SCP_CACHE_OP_TADDR_MASK;
@@ -120,7 +121,9 @@ void cpu_clean_invalidate_dcache_range(uintptr_t base, unsigned int length)
/* Read necessary to confirm the invalidation finish. */
REG32(addr);
}
+
asm volatile("dsb;");
+ interrupt_enable();
}
static void scp_cache_init(void)
@@ -137,8 +140,8 @@ static void scp_cache_init(void)
* should only be be configured in kernel driver before
* laoding the firmware. b/137920815#comment18
*/
- SCP_CACHE_CON(c) &= (SCP_CACHE_CON_CACHESIZE_MASK |
- SCP_CACHE_CON_WAYEN);
+ SCP_CACHE_CON(c) &=
+ (SCP_CACHE_CON_CACHESIZE_MASK | SCP_CACHE_CON_WAYEN);
SCP_CACHE_REGION_EN(c) = 0;
SCP_CACHE_ENTRY(c, region) = 0;
SCP_CACHE_END_ENTRY(c, region) = 0;
@@ -164,7 +167,7 @@ static void scp_cache_init(void)
/* Disable sleep protect */
SCP_SLP_PROTECT_CFG = SCP_SLP_PROTECT_CFG &
- ~(P_CACHE_SLP_PROT_EN | D_CACHE_SLP_PROT_EN);
+ ~(P_CACHE_SLP_PROT_EN | D_CACHE_SLP_PROT_EN);
/* Enable region 0 for both I-cache and D-cache. */
for (c = 0; c < CACHE_COUNT; c++) {
@@ -186,16 +189,16 @@ static void scp_cache_init(void)
cpu_invalidate_dcache();
}
-static int command_cacheinfo(int argc, char **argv)
+static int command_cacheinfo(int argc, const char **argv)
{
- const char cache_name[] = {'I', 'D'};
+ const char cache_name[] = { 'I', 'D' };
int c;
for (c = 0; c < 2; c++) {
uint64_t hit = ((uint64_t)SCP_CACHE_HCNT0U(c) << 32) |
- SCP_CACHE_HCNT0L(c);
+ SCP_CACHE_HCNT0L(c);
uint64_t access = ((uint64_t)SCP_CACHE_CCNT0U(c) << 32) |
- SCP_CACHE_CCNT0L(c);
+ SCP_CACHE_CCNT0L(c);
ccprintf("%ccache hit count: %llu\n", cache_name[c], hit);
ccprintf("%ccache access count: %llu\n", cache_name[c], access);
@@ -203,8 +206,7 @@ static int command_cacheinfo(int argc, char **argv)
return EC_SUCCESS;
}
-DECLARE_SAFE_CONSOLE_COMMAND(cacheinfo, command_cacheinfo,
- NULL,
+DECLARE_SAFE_CONSOLE_COMMAND(cacheinfo, command_cacheinfo, NULL,
"Dump cache info");
void scp_memmap_init(void)
@@ -221,11 +223,9 @@ void scp_memmap_init(void)
* EXT_ADDR1[13:8] remap register for addr msb 31~28 equal to 0x3
* EXT_ADDR0[5:0] remap register for addr msb 31~28 equal to 0x2
*/
- SCP_REMAP_CFG1 =
- (uint32_t)addr_map[0x7] << 24 |
- (uint32_t)addr_map[0x6] << 16 |
- (uint32_t)addr_map[0x3] << 8 |
- (uint32_t)addr_map[0x2];
+ SCP_REMAP_CFG1 = (uint32_t)addr_map[0x7] << 24 |
+ (uint32_t)addr_map[0x6] << 16 |
+ (uint32_t)addr_map[0x3] << 8 | (uint32_t)addr_map[0x2];
/*
* SCP_REMAP_CFG2
@@ -234,11 +234,9 @@ void scp_memmap_init(void)
* EXT_ADDR5[13:8] remap register for addr msb 31~28 equal to 0x9
* EXT_ADDR4[5:0] remap register for addr msb 31~28 equal to 0x8
*/
- SCP_REMAP_CFG2 =
- (uint32_t)addr_map[0xb] << 24 |
- (uint32_t)addr_map[0xa] << 16 |
- (uint32_t)addr_map[0x9] << 8 |
- (uint32_t)addr_map[0x8];
+ SCP_REMAP_CFG2 = (uint32_t)addr_map[0xb] << 24 |
+ (uint32_t)addr_map[0xa] << 16 |
+ (uint32_t)addr_map[0x9] << 8 | (uint32_t)addr_map[0x8];
/*
* SCP_REMAP_CFG3
* AUD_ADDR[31:28] remap register for addr msb 31~28 equal to 0xd
@@ -246,11 +244,9 @@ void scp_memmap_init(void)
* EXT_ADDR9[13:8] remap register for addr msb 31~28 equal to 0xe
* EXT_ADDR8[5:0] remap register for addr msb 31~28 equal to 0xc
*/
- SCP_REMAP_CFG3 =
- (uint32_t)addr_map[0xd] << 28 |
- (uint32_t)addr_map[0xf] << 16 |
- (uint32_t)addr_map[0xe] << 8 |
- (uint32_t)addr_map[0xc];
+ SCP_REMAP_CFG3 = (uint32_t)addr_map[0xd] << 28 |
+ (uint32_t)addr_map[0xf] << 16 |
+ (uint32_t)addr_map[0xe] << 8 | (uint32_t)addr_map[0xc];
/* Initialize cache remapping. */
scp_cache_init();
@@ -266,7 +262,7 @@ int memmap_ap_to_scp(uintptr_t ap_addr, uintptr_t *scp_addr)
continue;
*scp_addr = (ap_addr & SCP_REMAP_ADDR_LSB_MASK) |
- (i << SCP_REMAP_ADDR_SHIFT);
+ (i << SCP_REMAP_ADDR_SHIFT);
return EC_SUCCESS;
}
@@ -281,7 +277,7 @@ int memmap_scp_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr)
return EC_ERROR_INVAL;
*ap_addr = (scp_addr & SCP_REMAP_ADDR_LSB_MASK) |
- (addr_map[i] << SCP_REMAP_ADDR_SHIFT);
+ (addr_map[i] << SCP_REMAP_ADDR_SHIFT);
return EC_SUCCESS;
}
@@ -310,7 +306,7 @@ int memmap_scp_cache_to_ap(uintptr_t scp_addr, uintptr_t *ap_addr)
uintptr_t lsb;
if ((scp_addr & SCP_L1_EXT_ADDR_OTHER_MSB_MASK) !=
- CACHE_TRANS_SCP_CACHE_ADDR)
+ CACHE_TRANS_SCP_CACHE_ADDR)
return EC_ERROR_INVAL;
lsb = scp_addr & SCP_L1_EXT_ADDR_OTHER_LSB_MASK;