Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2021 Mark Kettenis <kettenis@openbsd.org> |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
Mark Kettenis | dfacafb | 2022-04-19 21:20:31 +0200 | [diff] [blame] | 8 | #include <dm/uclass-internal.h> |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 9 | #include <efi_loader.h> |
Mark Kettenis | 74ec048 | 2022-03-21 22:41:18 +0100 | [diff] [blame] | 10 | #include <lmb.h> |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 11 | |
| 12 | #include <asm/armv8/mmu.h> |
| 13 | #include <asm/global_data.h> |
| 14 | #include <asm/io.h> |
| 15 | #include <asm/system.h> |
| 16 | |
| 17 | DECLARE_GLOBAL_DATA_PTR; |
| 18 | |
Janne Grunau | 430ff52 | 2022-07-01 00:06:17 +0200 | [diff] [blame] | 19 | /* Apple M1/M2 */ |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 20 | |
| 21 | static struct mm_region t8103_mem_map[] = { |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 22 | { |
| 23 | /* I/O */ |
| 24 | .virt = 0x200000000, |
| 25 | .phys = 0x200000000, |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 26 | .size = 2UL * SZ_1G, |
| 27 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 28 | PTE_BLOCK_NON_SHARE | |
| 29 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 30 | }, { |
| 31 | /* I/O */ |
| 32 | .virt = 0x380000000, |
| 33 | .phys = 0x380000000, |
| 34 | .size = SZ_1G, |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 35 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 36 | PTE_BLOCK_NON_SHARE | |
| 37 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 38 | }, { |
| 39 | /* I/O */ |
| 40 | .virt = 0x500000000, |
| 41 | .phys = 0x500000000, |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 42 | .size = SZ_1G, |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 43 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 44 | PTE_BLOCK_NON_SHARE | |
| 45 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 46 | }, { |
| 47 | /* I/O */ |
| 48 | .virt = 0x680000000, |
| 49 | .phys = 0x680000000, |
| 50 | .size = SZ_512M, |
| 51 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 52 | PTE_BLOCK_NON_SHARE | |
| 53 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 54 | }, { |
| 55 | /* PCIE */ |
| 56 | .virt = 0x6a0000000, |
| 57 | .phys = 0x6a0000000, |
| 58 | .size = SZ_512M, |
| 59 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 60 | PTE_BLOCK_INNER_SHARE | |
| 61 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 62 | }, { |
| 63 | /* PCIE */ |
| 64 | .virt = 0x6c0000000, |
| 65 | .phys = 0x6c0000000, |
| 66 | .size = SZ_1G, |
| 67 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 68 | PTE_BLOCK_INNER_SHARE | |
| 69 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 70 | }, { |
| 71 | /* RAM */ |
| 72 | .virt = 0x800000000, |
| 73 | .phys = 0x800000000, |
| 74 | .size = 8UL * SZ_1G, |
| 75 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 76 | PTE_BLOCK_INNER_SHARE |
| 77 | }, { |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 78 | /* Framebuffer */ |
| 79 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | |
| 80 | PTE_BLOCK_INNER_SHARE | |
| 81 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 82 | }, { |
| 83 | /* List terminator */ |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 84 | 0, |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 85 | } |
| 86 | }; |
| 87 | |
| 88 | /* Apple M1 Pro/Max */ |
| 89 | |
| 90 | static struct mm_region t6000_mem_map[] = { |
| 91 | { |
| 92 | /* I/O */ |
| 93 | .virt = 0x280000000, |
| 94 | .phys = 0x280000000, |
| 95 | .size = SZ_1G, |
| 96 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 97 | PTE_BLOCK_NON_SHARE | |
| 98 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 99 | }, { |
| 100 | /* I/O */ |
| 101 | .virt = 0x380000000, |
| 102 | .phys = 0x380000000, |
| 103 | .size = SZ_1G, |
| 104 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 105 | PTE_BLOCK_NON_SHARE | |
| 106 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 107 | }, { |
| 108 | /* I/O */ |
| 109 | .virt = 0x580000000, |
| 110 | .phys = 0x580000000, |
| 111 | .size = SZ_512M, |
| 112 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 113 | PTE_BLOCK_NON_SHARE | |
| 114 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 115 | }, { |
| 116 | /* PCIE */ |
| 117 | .virt = 0x5a0000000, |
| 118 | .phys = 0x5a0000000, |
| 119 | .size = SZ_512M, |
| 120 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 121 | PTE_BLOCK_INNER_SHARE | |
| 122 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 123 | }, { |
| 124 | /* PCIE */ |
| 125 | .virt = 0x5c0000000, |
| 126 | .phys = 0x5c0000000, |
| 127 | .size = SZ_1G, |
| 128 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 129 | PTE_BLOCK_INNER_SHARE | |
| 130 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 131 | }, { |
| 132 | /* I/O */ |
| 133 | .virt = 0x700000000, |
| 134 | .phys = 0x700000000, |
| 135 | .size = SZ_1G, |
| 136 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 137 | PTE_BLOCK_NON_SHARE | |
| 138 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 139 | }, { |
| 140 | /* I/O */ |
| 141 | .virt = 0xb00000000, |
| 142 | .phys = 0xb00000000, |
| 143 | .size = SZ_1G, |
| 144 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 145 | PTE_BLOCK_NON_SHARE | |
| 146 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 147 | }, { |
| 148 | /* I/O */ |
| 149 | .virt = 0xf00000000, |
| 150 | .phys = 0xf00000000, |
| 151 | .size = SZ_1G, |
| 152 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 153 | PTE_BLOCK_NON_SHARE | |
| 154 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 155 | }, { |
| 156 | /* I/O */ |
| 157 | .virt = 0x1300000000, |
| 158 | .phys = 0x1300000000, |
| 159 | .size = SZ_1G, |
| 160 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 161 | PTE_BLOCK_NON_SHARE | |
| 162 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 163 | }, { |
| 164 | /* RAM */ |
| 165 | .virt = 0x10000000000, |
| 166 | .phys = 0x10000000000, |
| 167 | .size = 16UL * SZ_1G, |
| 168 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 169 | PTE_BLOCK_INNER_SHARE |
| 170 | }, { |
| 171 | /* Framebuffer */ |
| 172 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | |
| 173 | PTE_BLOCK_INNER_SHARE | |
| 174 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 175 | }, { |
| 176 | /* List terminator */ |
| 177 | 0, |
| 178 | } |
| 179 | }; |
| 180 | |
Janne Grunau | dc17432 | 2022-03-29 13:29:35 +0200 | [diff] [blame] | 181 | /* Apple M1 Ultra */ |
| 182 | |
| 183 | static struct mm_region t6002_mem_map[] = { |
| 184 | { |
| 185 | /* I/O */ |
| 186 | .virt = 0x280000000, |
| 187 | .phys = 0x280000000, |
| 188 | .size = SZ_1G, |
| 189 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 190 | PTE_BLOCK_NON_SHARE | |
| 191 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 192 | }, { |
| 193 | /* I/O */ |
| 194 | .virt = 0x380000000, |
| 195 | .phys = 0x380000000, |
| 196 | .size = SZ_1G, |
| 197 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 198 | PTE_BLOCK_NON_SHARE | |
| 199 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 200 | }, { |
| 201 | /* I/O */ |
| 202 | .virt = 0x580000000, |
| 203 | .phys = 0x580000000, |
| 204 | .size = SZ_512M, |
| 205 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 206 | PTE_BLOCK_NON_SHARE | |
| 207 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 208 | }, { |
| 209 | /* PCIE */ |
| 210 | .virt = 0x5a0000000, |
| 211 | .phys = 0x5a0000000, |
| 212 | .size = SZ_512M, |
| 213 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 214 | PTE_BLOCK_INNER_SHARE | |
| 215 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 216 | }, { |
| 217 | /* PCIE */ |
| 218 | .virt = 0x5c0000000, |
| 219 | .phys = 0x5c0000000, |
| 220 | .size = SZ_1G, |
| 221 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 222 | PTE_BLOCK_INNER_SHARE | |
| 223 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 224 | }, { |
| 225 | /* I/O */ |
| 226 | .virt = 0x700000000, |
| 227 | .phys = 0x700000000, |
| 228 | .size = SZ_1G, |
| 229 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 230 | PTE_BLOCK_NON_SHARE | |
| 231 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 232 | }, { |
| 233 | /* I/O */ |
| 234 | .virt = 0xb00000000, |
| 235 | .phys = 0xb00000000, |
| 236 | .size = SZ_1G, |
| 237 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 238 | PTE_BLOCK_NON_SHARE | |
| 239 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 240 | }, { |
| 241 | /* I/O */ |
| 242 | .virt = 0xf00000000, |
| 243 | .phys = 0xf00000000, |
| 244 | .size = SZ_1G, |
| 245 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 246 | PTE_BLOCK_NON_SHARE | |
| 247 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 248 | }, { |
| 249 | /* I/O */ |
| 250 | .virt = 0x1300000000, |
| 251 | .phys = 0x1300000000, |
| 252 | .size = SZ_1G, |
| 253 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 254 | PTE_BLOCK_NON_SHARE | |
| 255 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 256 | }, { |
| 257 | /* I/O */ |
| 258 | .virt = 0x2280000000, |
| 259 | .phys = 0x2280000000, |
| 260 | .size = SZ_1G, |
| 261 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 262 | PTE_BLOCK_NON_SHARE | |
| 263 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 264 | }, { |
| 265 | /* I/O */ |
| 266 | .virt = 0x2380000000, |
| 267 | .phys = 0x2380000000, |
| 268 | .size = SZ_1G, |
| 269 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 270 | PTE_BLOCK_NON_SHARE | |
| 271 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 272 | }, { |
| 273 | /* I/O */ |
| 274 | .virt = 0x2580000000, |
| 275 | .phys = 0x2580000000, |
| 276 | .size = SZ_512M, |
| 277 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 278 | PTE_BLOCK_NON_SHARE | |
| 279 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 280 | }, { |
| 281 | /* PCIE */ |
| 282 | .virt = 0x25a0000000, |
| 283 | .phys = 0x25a0000000, |
| 284 | .size = SZ_512M, |
| 285 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 286 | PTE_BLOCK_INNER_SHARE | |
| 287 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 288 | }, { |
| 289 | /* PCIE */ |
| 290 | .virt = 0x25c0000000, |
| 291 | .phys = 0x25c0000000, |
| 292 | .size = SZ_1G, |
| 293 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 294 | PTE_BLOCK_INNER_SHARE | |
| 295 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 296 | }, { |
| 297 | /* I/O */ |
| 298 | .virt = 0x2700000000, |
| 299 | .phys = 0x2700000000, |
| 300 | .size = SZ_1G, |
| 301 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 302 | PTE_BLOCK_NON_SHARE | |
| 303 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 304 | }, { |
| 305 | /* I/O */ |
| 306 | .virt = 0x2b00000000, |
| 307 | .phys = 0x2b00000000, |
| 308 | .size = SZ_1G, |
| 309 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 310 | PTE_BLOCK_NON_SHARE | |
| 311 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 312 | }, { |
| 313 | /* I/O */ |
| 314 | .virt = 0x2f00000000, |
| 315 | .phys = 0x2f00000000, |
| 316 | .size = SZ_1G, |
| 317 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 318 | PTE_BLOCK_NON_SHARE | |
| 319 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 320 | }, { |
| 321 | /* I/O */ |
| 322 | .virt = 0x3300000000, |
| 323 | .phys = 0x3300000000, |
| 324 | .size = SZ_1G, |
| 325 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 326 | PTE_BLOCK_NON_SHARE | |
| 327 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 328 | }, { |
| 329 | /* RAM */ |
| 330 | .virt = 0x10000000000, |
| 331 | .phys = 0x10000000000, |
| 332 | .size = 16UL * SZ_1G, |
| 333 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 334 | PTE_BLOCK_INNER_SHARE |
| 335 | }, { |
| 336 | /* Framebuffer */ |
| 337 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | |
| 338 | PTE_BLOCK_INNER_SHARE | |
| 339 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 340 | }, { |
| 341 | /* List terminator */ |
| 342 | 0, |
| 343 | } |
| 344 | }; |
| 345 | |
Mark Kettenis | 1b35070 | 2023-05-02 21:30:40 +0200 | [diff] [blame^] | 346 | /* Apple M2 Pro/Max */ |
| 347 | |
| 348 | static struct mm_region t6020_mem_map[] = { |
| 349 | { |
| 350 | /* I/O */ |
| 351 | .virt = 0x280000000, |
| 352 | .phys = 0x280000000, |
| 353 | .size = SZ_1G, |
| 354 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 355 | PTE_BLOCK_NON_SHARE | |
| 356 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 357 | }, { |
| 358 | /* I/O */ |
| 359 | .virt = 0x340000000, |
| 360 | .phys = 0x340000000, |
| 361 | .size = SZ_1G, |
| 362 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 363 | PTE_BLOCK_NON_SHARE | |
| 364 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 365 | }, { |
| 366 | /* I/O */ |
| 367 | .virt = 0x380000000, |
| 368 | .phys = 0x380000000, |
| 369 | .size = SZ_1G, |
| 370 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 371 | PTE_BLOCK_NON_SHARE | |
| 372 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 373 | }, { |
| 374 | /* I/O */ |
| 375 | .virt = 0x580000000, |
| 376 | .phys = 0x580000000, |
| 377 | .size = SZ_512M, |
| 378 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 379 | PTE_BLOCK_NON_SHARE | |
| 380 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 381 | }, { |
| 382 | /* PCIE */ |
| 383 | .virt = 0x5a0000000, |
| 384 | .phys = 0x5a0000000, |
| 385 | .size = SZ_512M, |
| 386 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 387 | PTE_BLOCK_INNER_SHARE | |
| 388 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 389 | }, { |
| 390 | /* PCIE */ |
| 391 | .virt = 0x5c0000000, |
| 392 | .phys = 0x5c0000000, |
| 393 | .size = SZ_1G, |
| 394 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRE) | |
| 395 | PTE_BLOCK_INNER_SHARE | |
| 396 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 397 | }, { |
| 398 | /* I/O */ |
| 399 | .virt = 0x700000000, |
| 400 | .phys = 0x700000000, |
| 401 | .size = SZ_1G, |
| 402 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 403 | PTE_BLOCK_NON_SHARE | |
| 404 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 405 | }, { |
| 406 | /* I/O */ |
| 407 | .virt = 0xb00000000, |
| 408 | .phys = 0xb00000000, |
| 409 | .size = SZ_1G, |
| 410 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 411 | PTE_BLOCK_NON_SHARE | |
| 412 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 413 | }, { |
| 414 | /* I/O */ |
| 415 | .virt = 0xf00000000, |
| 416 | .phys = 0xf00000000, |
| 417 | .size = SZ_1G, |
| 418 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 419 | PTE_BLOCK_NON_SHARE | |
| 420 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 421 | }, { |
| 422 | /* I/O */ |
| 423 | .virt = 0x1300000000, |
| 424 | .phys = 0x1300000000, |
| 425 | .size = SZ_1G, |
| 426 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 427 | PTE_BLOCK_NON_SHARE | |
| 428 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 429 | }, { |
| 430 | /* RAM */ |
| 431 | .virt = 0x10000000000, |
| 432 | .phys = 0x10000000000, |
| 433 | .size = 16UL * SZ_1G, |
| 434 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 435 | PTE_BLOCK_INNER_SHARE |
| 436 | }, { |
| 437 | /* Framebuffer */ |
| 438 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL_NC) | |
| 439 | PTE_BLOCK_INNER_SHARE | |
| 440 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 441 | }, { |
| 442 | /* List terminator */ |
| 443 | 0, |
| 444 | } |
| 445 | }; |
| 446 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 447 | struct mm_region *mem_map; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 448 | |
| 449 | int board_init(void) |
| 450 | { |
| 451 | return 0; |
| 452 | } |
| 453 | |
| 454 | int dram_init(void) |
| 455 | { |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 456 | return fdtdec_setup_mem_size_base(); |
| 457 | } |
| 458 | |
| 459 | int dram_init_banksize(void) |
| 460 | { |
| 461 | return fdtdec_setup_memory_banksize(); |
| 462 | } |
| 463 | |
| 464 | extern long fw_dtb_pointer; |
| 465 | |
| 466 | void *board_fdt_blob_setup(int *err) |
| 467 | { |
| 468 | /* Return DTB pointer passed by m1n1 */ |
| 469 | *err = 0; |
| 470 | return (void *)fw_dtb_pointer; |
| 471 | } |
| 472 | |
| 473 | void build_mem_map(void) |
| 474 | { |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 475 | ofnode node; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 476 | fdt_addr_t base; |
| 477 | fdt_size_t size; |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 478 | int i; |
| 479 | |
Janne Grunau | 430ff52 | 2022-07-01 00:06:17 +0200 | [diff] [blame] | 480 | if (of_machine_is_compatible("apple,t8103") || |
| 481 | of_machine_is_compatible("apple,t8112")) |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 482 | mem_map = t8103_mem_map; |
Mark Kettenis | 1b35070 | 2023-05-02 21:30:40 +0200 | [diff] [blame^] | 483 | else if (of_machine_is_compatible("apple,t6000") || |
| 484 | of_machine_is_compatible("apple,t6001")) |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 485 | mem_map = t6000_mem_map; |
Janne Grunau | dc17432 | 2022-03-29 13:29:35 +0200 | [diff] [blame] | 486 | else if (of_machine_is_compatible("apple,t6002")) |
| 487 | mem_map = t6002_mem_map; |
Mark Kettenis | 1b35070 | 2023-05-02 21:30:40 +0200 | [diff] [blame^] | 488 | else if (of_machine_is_compatible("apple,t6020") || |
| 489 | of_machine_is_compatible("apple,t6021")) |
| 490 | mem_map = t6020_mem_map; |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 491 | else |
| 492 | panic("Unsupported SoC\n"); |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 493 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 494 | /* Find list terminator. */ |
| 495 | for (i = 0; mem_map[i].size || mem_map[i].attrs; i++) |
| 496 | ; |
| 497 | |
| 498 | /* Align RAM mapping to page boundaries */ |
| 499 | base = gd->bd->bi_dram[0].start; |
| 500 | size = gd->bd->bi_dram[0].size; |
| 501 | size += (base - ALIGN_DOWN(base, SZ_4K)); |
| 502 | base = ALIGN_DOWN(base, SZ_4K); |
| 503 | size = ALIGN(size, SZ_4K); |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 504 | |
| 505 | /* Update RAM mapping */ |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 506 | mem_map[i - 2].virt = base; |
| 507 | mem_map[i - 2].phys = base; |
| 508 | mem_map[i - 2].size = size; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 509 | |
| 510 | node = ofnode_path("/chosen/framebuffer"); |
| 511 | if (!ofnode_valid(node)) |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 512 | return; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 513 | |
| 514 | base = ofnode_get_addr_size(node, "reg", &size); |
| 515 | if (base == FDT_ADDR_T_NONE) |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 516 | return; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 517 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 518 | /* Align framebuffer mapping to page boundaries */ |
| 519 | size += (base - ALIGN_DOWN(base, SZ_4K)); |
| 520 | base = ALIGN_DOWN(base, SZ_4K); |
| 521 | size = ALIGN(size, SZ_4K); |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 522 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 523 | /* Add framebuffer mapping */ |
| 524 | mem_map[i - 1].virt = base; |
| 525 | mem_map[i - 1].phys = base; |
| 526 | mem_map[i - 1].size = size; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 527 | } |
| 528 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 529 | void enable_caches(void) |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 530 | { |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 531 | build_mem_map(); |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 532 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 533 | icache_enable(); |
| 534 | dcache_enable(); |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 535 | } |
| 536 | |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 537 | u64 get_page_table_size(void) |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 538 | { |
Mark Kettenis | 73c82c8 | 2022-02-08 22:00:09 +0100 | [diff] [blame] | 539 | return SZ_256K; |
Mark Kettenis | 58d5127 | 2021-10-23 16:58:03 +0200 | [diff] [blame] | 540 | } |
Janne Grunau | 3a21671 | 2022-02-19 14:05:19 +0100 | [diff] [blame] | 541 | |
Mark Kettenis | 74ec048 | 2022-03-21 22:41:18 +0100 | [diff] [blame] | 542 | #define KERNEL_COMP_SIZE SZ_128M |
| 543 | |
Janne Grunau | 3a21671 | 2022-02-19 14:05:19 +0100 | [diff] [blame] | 544 | int board_late_init(void) |
| 545 | { |
Mark Kettenis | 74ec048 | 2022-03-21 22:41:18 +0100 | [diff] [blame] | 546 | struct lmb lmb; |
Janne Grunau | 3a21671 | 2022-02-19 14:05:19 +0100 | [diff] [blame] | 547 | u32 status = 0; |
| 548 | |
Mark Kettenis | 74ec048 | 2022-03-21 22:41:18 +0100 | [diff] [blame] | 549 | lmb_init_and_reserve(&lmb, gd->bd, (void *)gd->fdt_blob); |
Janne Grunau | 3a21671 | 2022-02-19 14:05:19 +0100 | [diff] [blame] | 550 | |
| 551 | /* somewhat based on the Linux Kernel boot requirements: |
| 552 | * align by 2M and maximal FDT size 2M |
| 553 | */ |
Mark Kettenis | 74ec048 | 2022-03-21 22:41:18 +0100 | [diff] [blame] | 554 | status |= env_set_hex("loadaddr", lmb_alloc(&lmb, SZ_1G, SZ_2M)); |
| 555 | status |= env_set_hex("fdt_addr_r", lmb_alloc(&lmb, SZ_2M, SZ_2M)); |
| 556 | status |= env_set_hex("kernel_addr_r", lmb_alloc(&lmb, SZ_128M, SZ_2M)); |
| 557 | status |= env_set_hex("ramdisk_addr_r", lmb_alloc(&lmb, SZ_1G, SZ_2M)); |
| 558 | status |= env_set_hex("kernel_comp_addr_r", |
| 559 | lmb_alloc(&lmb, KERNEL_COMP_SIZE, SZ_2M)); |
| 560 | status |= env_set_hex("kernel_comp_size", KERNEL_COMP_SIZE); |
| 561 | status |= env_set_hex("scriptaddr", lmb_alloc(&lmb, SZ_4M, SZ_2M)); |
| 562 | status |= env_set_hex("pxefile_addr_r", lmb_alloc(&lmb, SZ_4M, SZ_2M)); |
Janne Grunau | 3a21671 | 2022-02-19 14:05:19 +0100 | [diff] [blame] | 563 | |
| 564 | if (status) |
| 565 | log_warning("late_init: Failed to set run time variables\n"); |
| 566 | |
| 567 | return 0; |
| 568 | } |
Mark Kettenis | dfacafb | 2022-04-19 21:20:31 +0200 | [diff] [blame] | 569 | |
| 570 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 571 | { |
| 572 | struct udevice *dev; |
| 573 | const char *stdoutname; |
| 574 | int node, ret; |
| 575 | |
| 576 | /* |
| 577 | * Modify the "stdout-path" property under "/chosen" to point |
| 578 | * at "/chosen/framebuffer if a keyboard is available and |
| 579 | * we're not running under the m1n1 hypervisor. |
| 580 | * Developers can override this behaviour by dropping |
| 581 | * "vidconsole" from the "stdout" environment variable. |
| 582 | */ |
| 583 | |
| 584 | /* EL1 means we're running under the m1n1 hypervisor. */ |
| 585 | if (current_el() == 1) |
| 586 | return 0; |
| 587 | |
| 588 | ret = uclass_find_device(UCLASS_KEYBOARD, 0, &dev); |
| 589 | if (ret < 0) |
| 590 | return 0; |
| 591 | |
| 592 | stdoutname = env_get("stdout"); |
| 593 | if (!stdoutname || !strstr(stdoutname, "vidconsole")) |
| 594 | return 0; |
| 595 | |
| 596 | /* Make sure we actually have a framebuffer. */ |
| 597 | node = fdt_path_offset(blob, "/chosen/framebuffer"); |
| 598 | if (node < 0 || !fdtdec_get_is_enabled(blob, node)) |
| 599 | return 0; |
| 600 | |
| 601 | node = fdt_path_offset(blob, "/chosen"); |
| 602 | if (node < 0) |
| 603 | return 0; |
| 604 | fdt_setprop_string(blob, node, "stdout-path", "/chosen/framebuffer"); |
| 605 | |
| 606 | return 0; |
| 607 | } |