1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2012-2016 Freescale Semiconductor, Inc.
4  */
5 
6 #include <common.h>
7 #include <asm/fsl_pamu.h>
8 
9 DECLARE_GLOBAL_DATA_PTR;
10 
construct_pamu_addr_table(struct pamu_addr_tbl * tbl,int * num_entries)11 void 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
30 #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
38 	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 
sec_config_pamu_table(uint32_t liodn_ns,uint32_t liodn_s)45 int 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 }
63