Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Stephen Warren | 59d63f7 | 2012-09-01 16:27:56 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2012 Stephen Warren |
| 4 | * |
| 5 | * See file CREDITS for list of people who contributed to this |
| 6 | * project. |
Stephen Warren | 59d63f7 | 2012-09-01 16:27:56 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
Simon Glass | 9edefc2 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 10 | #include <cpu_func.h> |
Matthias Brugger | dd47ca7 | 2019-11-19 16:01:04 +0100 | [diff] [blame] | 11 | #include <dm/device.h> |
| 12 | #include <fdt_support.h> |
Stephen Warren | 59d63f7 | 2012-09-01 16:27:56 +0000 | [diff] [blame] | 13 | |
Matthias Brugger | 917a1e9 | 2019-11-19 16:01:05 +0100 | [diff] [blame] | 14 | #ifdef CONFIG_ARM64 |
| 15 | #include <asm/armv8/mmu.h> |
| 16 | |
| 17 | static struct mm_region bcm283x_mem_map[] = { |
| 18 | { |
| 19 | .virt = 0x00000000UL, |
| 20 | .phys = 0x00000000UL, |
| 21 | .size = 0x3f000000UL, |
| 22 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 23 | PTE_BLOCK_INNER_SHARE |
| 24 | }, { |
| 25 | .virt = 0x3f000000UL, |
| 26 | .phys = 0x3f000000UL, |
| 27 | .size = 0x01000000UL, |
| 28 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 29 | PTE_BLOCK_NON_SHARE | |
| 30 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 31 | }, { |
| 32 | /* List terminator */ |
| 33 | 0, |
| 34 | } |
| 35 | }; |
| 36 | |
| 37 | static struct mm_region bcm2711_mem_map[] = { |
| 38 | { |
| 39 | .virt = 0x00000000UL, |
| 40 | .phys = 0x00000000UL, |
| 41 | .size = 0xfe000000UL, |
| 42 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 43 | PTE_BLOCK_INNER_SHARE |
| 44 | }, { |
| 45 | .virt = 0xfe000000UL, |
| 46 | .phys = 0xfe000000UL, |
| 47 | .size = 0x01800000UL, |
| 48 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 49 | PTE_BLOCK_NON_SHARE | |
| 50 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 51 | }, { |
| 52 | /* List terminator */ |
| 53 | 0, |
| 54 | } |
| 55 | }; |
| 56 | |
| 57 | struct mm_region *mem_map = bcm283x_mem_map; |
| 58 | |
| 59 | /* |
| 60 | * I/O address space varies on different chip versions. |
| 61 | * We set the base address by inspecting the DTB. |
| 62 | */ |
| 63 | static const struct udevice_id board_ids[] = { |
| 64 | { .compatible = "brcm,bcm2837", .data = (ulong)&bcm283x_mem_map}, |
| 65 | { .compatible = "brcm,bcm2838", .data = (ulong)&bcm2711_mem_map}, |
| 66 | { .compatible = "brcm,bcm2711", .data = (ulong)&bcm2711_mem_map}, |
| 67 | { }, |
| 68 | }; |
| 69 | |
| 70 | static void _rpi_update_mem_map(struct mm_region *pd) |
| 71 | { |
| 72 | int i; |
| 73 | |
| 74 | for (i = 0; i < 2; i++) { |
| 75 | mem_map[i].virt = pd[i].virt; |
| 76 | mem_map[i].phys = pd[i].phys; |
| 77 | mem_map[i].size = pd[i].size; |
| 78 | mem_map[i].attrs = pd[i].attrs; |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | static void rpi_update_mem_map(void) |
| 83 | { |
| 84 | int ret; |
| 85 | struct mm_region *mm; |
| 86 | const struct udevice_id *of_match = board_ids; |
| 87 | |
| 88 | while (of_match->compatible) { |
| 89 | ret = fdt_node_check_compatible(gd->fdt_blob, 0, |
| 90 | of_match->compatible); |
| 91 | if (!ret) { |
| 92 | mm = (struct mm_region *)of_match->data; |
| 93 | _rpi_update_mem_map(mm); |
| 94 | break; |
| 95 | } |
| 96 | |
| 97 | of_match++; |
| 98 | } |
| 99 | } |
| 100 | #else |
| 101 | static void rpi_update_mem_map(void) {} |
| 102 | #endif |
| 103 | |
Matthias Brugger | dd47ca7 | 2019-11-19 16:01:04 +0100 | [diff] [blame] | 104 | unsigned long rpi_bcm283x_base = 0x3f000000; |
Matthias Brugger | 8e3361c | 2019-11-19 16:01:03 +0100 | [diff] [blame] | 105 | |
Stephen Warren | 59d63f7 | 2012-09-01 16:27:56 +0000 | [diff] [blame] | 106 | int arch_cpu_init(void) |
| 107 | { |
| 108 | icache_enable(); |
| 109 | |
| 110 | return 0; |
| 111 | } |
Alexander Graf | ccd9d51 | 2016-03-16 15:41:23 +0100 | [diff] [blame] | 112 | |
Matthias Brugger | 8e3361c | 2019-11-19 16:01:03 +0100 | [diff] [blame] | 113 | int mach_cpu_init(void) |
| 114 | { |
Matthias Brugger | dd47ca7 | 2019-11-19 16:01:04 +0100 | [diff] [blame] | 115 | int ret, soc_offset; |
| 116 | u64 io_base, size; |
| 117 | |
Matthias Brugger | 917a1e9 | 2019-11-19 16:01:05 +0100 | [diff] [blame] | 118 | rpi_update_mem_map(); |
| 119 | |
Matthias Brugger | dd47ca7 | 2019-11-19 16:01:04 +0100 | [diff] [blame] | 120 | /* Get IO base from device tree */ |
| 121 | soc_offset = fdt_path_offset(gd->fdt_blob, "/soc"); |
| 122 | if (soc_offset < 0) |
| 123 | return soc_offset; |
| 124 | |
| 125 | ret = fdt_read_range((void *)gd->fdt_blob, soc_offset, 0, NULL, |
| 126 | &io_base, &size); |
| 127 | if (ret) |
| 128 | return ret; |
| 129 | |
| 130 | rpi_bcm283x_base = io_base; |
Matthias Brugger | 8e3361c | 2019-11-19 16:01:03 +0100 | [diff] [blame] | 131 | |
| 132 | return 0; |
| 133 | } |
Matthias Brugger | dd47ca7 | 2019-11-19 16:01:04 +0100 | [diff] [blame] | 134 | |
Alexander Graf | ccd9d51 | 2016-03-16 15:41:23 +0100 | [diff] [blame] | 135 | #ifdef CONFIG_ARMV7_LPAE |
| 136 | void enable_caches(void) |
| 137 | { |
| 138 | dcache_enable(); |
| 139 | } |
| 140 | #endif |