blob: b906279226a52c83ba7dea772caa89cf587efb11 [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
6#include <common.h>
Simon Glass0f2af882020-05-10 11:40:05 -06007#include <log.h>
Aneesh Bansal4b636c32016-01-22 17:05:59 +05308#include <asm/fsl_pamu.h>
Simon Glass3ba929a2020-10-30 21:38:53 -06009#include <asm/global_data.h>
Aneesh Bansal4b636c32016-01-22 17:05:59 +053010
11DECLARE_GLOBAL_DATA_PTR;
12
13void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
14{
15 int i = 0;
16 int j;
17
18 tbl->start_addr[i] =
Tom Rinibb4dd962022-11-16 13:10:37 -050019 (uint64_t)virt_to_phys((void *)CFG_SYS_SDRAM_BASE);
Tom Rinibc9d46b2022-12-04 10:04:50 -050020 tbl->size[i] = (phys_size_t)(min(gd->ram_size, CFG_MAX_MEM_MAPPED));
Aneesh Bansal4b636c32016-01-22 17:05:59 +053021 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
22
23 i++;
Tom Rini6a5dccc2022-11-16 13:10:41 -050024#ifdef CFG_SYS_FLASH_BASE_PHYS
Aneesh Bansal4b636c32016-01-22 17:05:59 +053025 tbl->start_addr[i] =
Tom Rini6a5dccc2022-11-16 13:10:41 -050026 (uint64_t)virt_to_phys((void *)CFG_SYS_FLASH_BASE_PHYS);
Aneesh Bansal4b636c32016-01-22 17:05:59 +053027 tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
28 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
29
30 i++;
31#endif
Tom Rini6a5dccc2022-11-16 13:10:41 -050032#if (defined(CONFIG_SPL_BUILD) && (CFG_SYS_INIT_L3_VADDR))
Sumit Gargf6d96cb2016-07-14 12:27:51 -040033 tbl->start_addr[i] =
Tom Rini6a5dccc2022-11-16 13:10:41 -050034 (uint64_t)virt_to_phys((void *)CFG_SYS_INIT_L3_VADDR);
Sumit Gargf6d96cb2016-07-14 12:27:51 -040035 tbl->size[i] = 256 * 1024; /* 256K CPC flash */
36 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
37
38 i++;
39#endif
Aneesh Bansal4b636c32016-01-22 17:05:59 +053040 debug("PAMU address\t\t\tsize\n");
41 for (j = 0; j < i ; j++)
42 debug("%llx \t\t\t%llx\n", tbl->start_addr[j], tbl->size[j]);
43
44 *num_entries = i;
45}
46
47int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
48{
49 struct pamu_addr_tbl tbl;
50 int num_entries = 0;
51 int ret = 0;
52
53 construct_pamu_addr_table(&tbl, &num_entries);
54
55 ret = config_pamu(&tbl, num_entries, liodn_ns);
56 if (ret)
57 return ret;
58
59 ret = config_pamu(&tbl, num_entries, liodn_s);
60 if (ret)
61 return ret;
62
63 return ret;
64}