| @@ -1,14 +1,14 @@ | | | @@ -1,14 +1,14 @@ |
1 | /* $NetBSD: fdt_machdep.c,v 1.32 2018/08/05 14:02:36 skrll Exp $ */ | | 1 | /* $NetBSD: fdt_machdep.c,v 1.33 2018/08/23 22:34:03 jmcneill Exp $ */ |
2 | | | 2 | |
3 | /*- | | 3 | /*- |
4 | * Copyright (c) 2015-2017 Jared McNeill <jmcneill@invisible.ca> | | 4 | * Copyright (c) 2015-2017 Jared McNeill <jmcneill@invisible.ca> |
5 | * All rights reserved. | | 5 | * All rights reserved. |
6 | * | | 6 | * |
7 | * Redistribution and use in source and binary forms, with or without | | 7 | * Redistribution and use in source and binary forms, with or without |
8 | * modification, are permitted provided that the following conditions | | 8 | * modification, are permitted provided that the following conditions |
9 | * are met: | | 9 | * are met: |
10 | * 1. Redistributions of source code must retain the above copyright | | 10 | * 1. Redistributions of source code must retain the above copyright |
11 | * notice, this list of conditions and the following disclaimer. | | 11 | * notice, this list of conditions and the following disclaimer. |
12 | * 2. Redistributions in binary form must reproduce the above copyright | | 12 | * 2. Redistributions in binary form must reproduce the above copyright |
13 | * notice, this list of conditions and the following disclaimer in the | | 13 | * notice, this list of conditions and the following disclaimer in the |
14 | * documentation and/or other materials provided with the distribution. | | 14 | * documentation and/or other materials provided with the distribution. |
| @@ -17,27 +17,27 @@ | | | @@ -17,27 +17,27 @@ |
17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | | 17 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | | 18 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, | | 19 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, | | 20 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | | 21 | * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED | | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED |
23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | | 23 | * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | | 24 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | | 25 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
26 | * SUCH DAMAGE. | | 26 | * SUCH DAMAGE. |
27 | */ | | 27 | */ |
28 | | | 28 | |
29 | #include <sys/cdefs.h> | | 29 | #include <sys/cdefs.h> |
30 | __KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.32 2018/08/05 14:02:36 skrll Exp $"); | | 30 | __KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.33 2018/08/23 22:34:03 jmcneill Exp $"); |
31 | | | 31 | |
32 | #include "opt_machdep.h" | | 32 | #include "opt_machdep.h" |
33 | #include "opt_bootconfig.h" | | 33 | #include "opt_bootconfig.h" |
34 | #include "opt_ddb.h" | | 34 | #include "opt_ddb.h" |
35 | #include "opt_md.h" | | 35 | #include "opt_md.h" |
36 | #include "opt_arm_debug.h" | | 36 | #include "opt_arm_debug.h" |
37 | #include "opt_multiprocessor.h" | | 37 | #include "opt_multiprocessor.h" |
38 | #include "opt_cpuoptions.h" | | 38 | #include "opt_cpuoptions.h" |
39 | | | 39 | |
40 | #include "ukbd.h" | | 40 | #include "ukbd.h" |
41 | | | 41 | |
42 | #include <sys/param.h> | | 42 | #include <sys/param.h> |
43 | #include <sys/systm.h> | | 43 | #include <sys/systm.h> |
| @@ -203,39 +203,45 @@ fdt_add_reserved_memory_range(uint64_t a | | | @@ -203,39 +203,45 @@ fdt_add_reserved_memory_range(uint64_t a |
203 | int error = extent_free(fdt_memory_ext, start, | | 203 | int error = extent_free(fdt_memory_ext, start, |
204 | end - start, EX_NOWAIT); | | 204 | end - start, EX_NOWAIT); |
205 | if (error != 0) | | 205 | if (error != 0) |
206 | printf("MEM ERROR: res %" PRIx64 "-%" PRIx64 " failed: %d\n", | | 206 | printf("MEM ERROR: res %" PRIx64 "-%" PRIx64 " failed: %d\n", |
207 | start, end, error); | | 207 | start, end, error); |
208 | else | | 208 | else |
209 | VPRINTF("MEM: res %" PRIx64 "-%" PRIx64 "\n", start, end); | | 209 | VPRINTF("MEM: res %" PRIx64 "-%" PRIx64 "\n", start, end); |
210 | } | | 210 | } |
211 | | | 211 | |
212 | /* | | 212 | /* |
213 | * Exclude memory ranges from memory config from the device tree | | 213 | * Exclude memory ranges from memory config from the device tree |
214 | */ | | 214 | */ |
215 | static void | | 215 | static void |
216 | fdt_add_reserved_memory(uint64_t max_addr) | | 216 | fdt_add_reserved_memory(uint64_t min_addr, uint64_t max_addr) |
217 | { | | 217 | { |
218 | uint64_t addr, size; | | 218 | uint64_t addr, size; |
219 | int index, error; | | 219 | int index, error; |
220 | | | 220 | |
221 | const int num = fdt_num_mem_rsv(fdtbus_get_data()); | | 221 | const int num = fdt_num_mem_rsv(fdtbus_get_data()); |
222 | for (index = 0; index <= num; index++) { | | 222 | for (index = 0; index <= num; index++) { |
223 | error = fdt_get_mem_rsv(fdtbus_get_data(), index, | | 223 | error = fdt_get_mem_rsv(fdtbus_get_data(), index, |
224 | &addr, &size); | | 224 | &addr, &size); |
225 | if (error != 0 || size == 0) | | 225 | if (error != 0 || size == 0) |
226 | continue; | | 226 | continue; |
| | | 227 | if (addr + size <= min_addr) |
| | | 228 | continue; |
227 | if (addr >= max_addr) | | 229 | if (addr >= max_addr) |
228 | continue; | | 230 | continue; |
| | | 231 | if (addr < min_addr) { |
| | | 232 | size -= (min_addr - addr); |
| | | 233 | addr = min_addr; |
| | | 234 | } |
229 | if (addr + size > max_addr) | | 235 | if (addr + size > max_addr) |
230 | size = max_addr - addr; | | 236 | size = max_addr - addr; |
231 | fdt_add_reserved_memory_range(addr, size); | | 237 | fdt_add_reserved_memory_range(addr, size); |
232 | } | | 238 | } |
233 | } | | 239 | } |
234 | | | 240 | |
235 | /* | | 241 | /* |
236 | * Define usable memory regions. | | 242 | * Define usable memory regions. |
237 | */ | | 243 | */ |
238 | static void | | 244 | static void |
239 | fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) | | 245 | fdt_build_bootconfig(uint64_t mem_start, uint64_t mem_end) |
240 | { | | 246 | { |
241 | const int memory = OF_finddevice("/memory"); | | 247 | const int memory = OF_finddevice("/memory"); |
| @@ -253,27 +259,27 @@ fdt_build_bootconfig(uint64_t mem_start, | | | @@ -253,27 +259,27 @@ fdt_build_bootconfig(uint64_t mem_start, |
253 | if (addr >= mem_end || size == 0) | | 259 | if (addr >= mem_end || size == 0) |
254 | continue; | | 260 | continue; |
255 | if (addr + size > mem_end) | | 261 | if (addr + size > mem_end) |
256 | size = mem_end - addr; | | 262 | size = mem_end - addr; |
257 | | | 263 | |
258 | error = extent_alloc_region(fdt_memory_ext, addr, size, | | 264 | error = extent_alloc_region(fdt_memory_ext, addr, size, |
259 | EX_NOWAIT); | | 265 | EX_NOWAIT); |
260 | if (error != 0) | | 266 | if (error != 0) |
261 | printf("MEM ERROR: add %" PRIx64 "-%" PRIx64 " failed: %d\n", | | 267 | printf("MEM ERROR: add %" PRIx64 "-%" PRIx64 " failed: %d\n", |
262 | addr, addr + size, error); | | 268 | addr, addr + size, error); |
263 | VPRINTF("MEM: add %" PRIx64 "-%" PRIx64 "\n", addr, addr + size); | | 269 | VPRINTF("MEM: add %" PRIx64 "-%" PRIx64 "\n", addr, addr + size); |
264 | } | | 270 | } |
265 | | | 271 | |
266 | fdt_add_reserved_memory(mem_end); | | 272 | fdt_add_reserved_memory(mem_start, mem_end); |
267 | | | 273 | |
268 | const uint64_t initrd_size = initrd_end - initrd_start; | | 274 | const uint64_t initrd_size = initrd_end - initrd_start; |
269 | if (initrd_size > 0) | | 275 | if (initrd_size > 0) |
270 | fdt_add_reserved_memory_range(initrd_start, initrd_size); | | 276 | fdt_add_reserved_memory_range(initrd_start, initrd_size); |
271 | | | 277 | |
272 | VPRINTF("Usable memory:\n"); | | 278 | VPRINTF("Usable memory:\n"); |
273 | bc->dramblocks = 0; | | 279 | bc->dramblocks = 0; |
274 | LIST_FOREACH(er, &fdt_memory_ext->ex_regions, er_link) { | | 280 | LIST_FOREACH(er, &fdt_memory_ext->ex_regions, er_link) { |
275 | VPRINTF(" %lx - %lx\n", er->er_start, er->er_end); | | 281 | VPRINTF(" %lx - %lx\n", er->er_start, er->er_end); |
276 | bc->dram[bc->dramblocks].address = er->er_start; | | 282 | bc->dram[bc->dramblocks].address = er->er_start; |
277 | bc->dram[bc->dramblocks].pages = | | 283 | bc->dram[bc->dramblocks].pages = |
278 | (er->er_end - er->er_start) / PAGE_SIZE; | | 284 | (er->er_end - er->er_start) / PAGE_SIZE; |
279 | bc->dramblocks++; | | 285 | bc->dramblocks++; |