Merge tag 'u-boot-atmel-fixes-2020.07-a' of https://gitlab.denx.de/u-boot/custodians...
[oweals/u-boot.git] / arch / powerpc / cpu / mpc8xxx / pamu_table.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright 2012-2016 Freescale Semiconductor, Inc.
4  */
5
6 #include <common.h>
7 #include <log.h>
8 #include <asm/fsl_pamu.h>
9
10 DECLARE_GLOBAL_DATA_PTR;
11
12 void 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] =
18                         (uint64_t)virt_to_phys((void *)CONFIG_SYS_SDRAM_BASE);
19         tbl->size[i] = (phys_size_t)(min(gd->ram_size, CONFIG_MAX_MEM_MAPPED));
20         tbl->end_addr[i] = tbl->start_addr[i] +  tbl->size[i] - 1;
21
22         i++;
23 #ifdef CONFIG_SYS_FLASH_BASE_PHYS
24         tbl->start_addr[i] =
25                 (uint64_t)virt_to_phys((void *)CONFIG_SYS_FLASH_BASE_PHYS);
26         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
31 #if (defined(CONFIG_SPL_BUILD) && (CONFIG_SYS_INIT_L3_VADDR))
32         tbl->start_addr[i] =
33                 (uint64_t)virt_to_phys((void *)CONFIG_SYS_INIT_L3_VADDR);
34         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
39         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
46 int 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 }