blob: 7b4690abc9f222d018ec595a6a26d0ba1763f750 [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>
7#include <asm/fsl_pamu.h>
8
9DECLARE_GLOBAL_DATA_PTR;
10
11void construct_pamu_addr_table(struct pamu_addr_tbl *tbl, int *num_entries)
12{
13 int i = 0;
14 int j;
15
16 tbl->start_addr[i] =
17 (uint64_t)virt_to_phys((void *)CONFIG_SYS_SDRAM_BASE);
18 tbl->size[i] = (phys_size_t)(min(gd->ram_size, CONFIG_MAX_MEM_MAPPED));
19 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
20
21 i++;
22#ifdef CONFIG_SYS_FLASH_BASE_PHYS
23 tbl->start_addr[i] =
24 (uint64_t)virt_to_phys((void *)CONFIG_SYS_FLASH_BASE_PHYS);
25 tbl->size[i] = 256 * 1024 * 1024; /* 256MB flash */
26 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
27
28 i++;
29#endif
Sumit Gargf6d96cb2016-07-14 12:27:51 -040030#if (defined(CONFIG_SPL_BUILD) && (CONFIG_SYS_INIT_L3_VADDR))
31 tbl->start_addr[i] =
32 (uint64_t)virt_to_phys((void *)CONFIG_SYS_INIT_L3_VADDR);
33 tbl->size[i] = 256 * 1024; /* 256K CPC flash */
34 tbl->end_addr[i] = tbl->start_addr[i] + tbl->size[i] - 1;
35
36 i++;
37#endif
Aneesh Bansal4b636c32016-01-22 17:05:59 +053038 debug("PAMU address\t\t\tsize\n");
39 for (j = 0; j < i ; j++)
40 debug("%llx \t\t\t%llx\n", tbl->start_addr[j], tbl->size[j]);
41
42 *num_entries = i;
43}
44
45int sec_config_pamu_table(uint32_t liodn_ns, uint32_t liodn_s)
46{
47 struct pamu_addr_tbl tbl;
48 int num_entries = 0;
49 int ret = 0;
50
51 construct_pamu_addr_table(&tbl, &num_entries);
52
53 ret = config_pamu(&tbl, num_entries, liodn_ns);
54 if (ret)
55 return ret;
56
57 ret = config_pamu(&tbl, num_entries, liodn_s);
58 if (ret)
59 return ret;
60
61 return ret;
62}