blob: 831a11736cc8f135780da00ad7e10042b8890a02 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Aneesh Bansal4b636c32016-01-22 17:05:59 +05302/*
3 * Copyright 2012-2016 Freescale Semiconductor, Inc.
Aneesh Bansal4b636c32016-01-22 17:05:59 +05304 */
5
Simon Glass0f2af882020-05-10 11:40:05 -06006#include <log.h>
Aneesh Bansal4b636c32016-01-22 17:05:59 +05307#include <asm/fsl_pamu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06008#include <asm/global_data.h>
Aneesh Bansal4b636c32016-01-22 17:05:59 +05309
10DECLARE_GLOBAL_DATA_PTR;
11
12void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
13{
14 int i = 0;
15 int j;
16
17 tbl->start_addr[i] =
Tom Rinibb4dd962022-11-16 13:10:37 -050018 (uint64_t)virt_to_phys((void *)CFG_SYS_SDRAM_BASE);
Tom Rinibc9d46b2022-12-04 10:04:50 -050019 tbl->size[i] = (phys_size_t)(min(gd->ram_size, CFG_MAX_MEM_MAPPED));
Aneesh Bansal4b636c32016-01-22 17:05:59 +053020 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
21
22 i++;
Tom Rini6a5dccc2022-11-16 13:10:41 -050023#ifdef CFG_SYS_FLASH_BASE_PHYS
Aneesh Bansal4b636c32016-01-22 17:05:59 +053024 tbl->start_addr[i] =
Tom Rini6a5dccc2022-11-16 13:10:41 -050025 (uint64_t)virt_to_phys((void *)CFG_SYS_FLASH_BASE_PHYS);
Aneesh Bansal4b636c32016-01-22 17:05:59 +053026 tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
27 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
28
29 i++;
30#endif
Tom Rini6a5dccc2022-11-16 13:10:41 -050031#if (defined(CONFIG_SPL_BUILD) && (CFG_SYS_INIT_L3_VADDR))
Sumit Gargf6d96cb2016-07-14 12:27:51 -040032 tbl->start_addr[i] =
Tom Rini6a5dccc2022-11-16 13:10:41 -050033 (uint64_t)virt_to_phys((void *)CFG_SYS_INIT_L3_VADDR);
Sumit Gargf6d96cb2016-07-14 12:27:51 -040034 tbl->size[i] = 256 * 1024; /* 256K CPC flash */
35 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
36
37 i++;
38#endif
Aneesh Bansal4b636c32016-01-22 17:05:59 +053039 debug("PAMU address\t\t\tsize\n");
40 for (j = 0; j < i ; j++)
41 debug("%llx \t\t\t%llx\n", tbl->start_addr[j], tbl->size[j]);
42
43 *num_entries = i;
44}
45
46int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
47{
48 struct pamu_addr_tbl tbl;
49 int num_entries = 0;
50 int ret = 0;
51
52 construct_pamu_addr_table(&tbl, &num_entries);
53
54 ret = config_pamu(&tbl, num_entries, liodn_ns);
55 if (ret)
56 return ret;
57
58 ret = config_pamu(&tbl, num_entries, liodn_s);
59 if (ret)
60 return ret;
61
62 return ret;
63}