Wed Jun 14 04:54:21 2017 UTC ()
Pull up following revision(s) (requested by jmcneill in ticket #31):
	sys/arch/evbarm/fdt/fdt_machdep.c: revision 1.7
Parse more than one entry from the /memory node's reg property.


(snj)
diff -r1.4.2.1 -r1.4.2.2 src/sys/arch/evbarm/fdt/fdt_machdep.c

cvs diff -r1.4.2.1 -r1.4.2.2 src/sys/arch/evbarm/fdt/fdt_machdep.c (expand / switch to unified diff)

--- src/sys/arch/evbarm/fdt/fdt_machdep.c 2017/06/06 16:26:53 1.4.2.1
+++ src/sys/arch/evbarm/fdt/fdt_machdep.c 2017/06/14 04:54:21 1.4.2.2
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: fdt_machdep.c,v 1.4.2.1 2017/06/06 16:26:53 snj Exp $ */ 1/* $NetBSD: fdt_machdep.c,v 1.4.2.2 2017/06/14 04:54:21 snj 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.4.2.1 2017/06/06 16:26:53 snj Exp $"); 30__KERNEL_RCSID(0, "$NetBSD: fdt_machdep.c,v 1.4.2.2 2017/06/14 04:54:21 snj Exp $");
31 31
32#include "opt_machdep.h" 32#include "opt_machdep.h"
33#include "opt_ddb.h" 33#include "opt_ddb.h"
34#include "opt_md.h" 34#include "opt_md.h"
35#include "opt_arm_debug.h" 35#include "opt_arm_debug.h"
36#include "opt_multiprocessor.h" 36#include "opt_multiprocessor.h"
37#include "opt_cpuoptions.h" 37#include "opt_cpuoptions.h"
38 38
39#include <sys/param.h> 39#include <sys/param.h>
40#include <sys/systm.h> 40#include <sys/systm.h>
41#include <sys/bus.h> 41#include <sys/bus.h>
42#include <sys/atomic.h> 42#include <sys/atomic.h>
43#include <sys/cpu.h> 43#include <sys/cpu.h>
@@ -129,26 +129,54 @@ fdt_printn(u_int n, int base) @@ -129,26 +129,54 @@ fdt_printn(u_int n, int base)
129 do { 129 do {
130 fdt_putchar(*--p); 130 fdt_putchar(*--p);
131 } while (p > buf); 131 } while (p > buf);
132} 132}
133#define DPRINTF(...) printf(__VA_ARGS__) 133#define DPRINTF(...) printf(__VA_ARGS__)
134#define DPRINT(x) fdt_putstr(x) 134#define DPRINT(x) fdt_putstr(x)
135#define DPRINTN(x,b) fdt_printn((x), (b)) 135#define DPRINTN(x,b) fdt_printn((x), (b))
136#else 136#else
137#define DPRINTF(...) 137#define DPRINTF(...)
138#define DPRINT(x) 138#define DPRINT(x)
139#define DPRINTN(x,b) 139#define DPRINTN(x,b)
140#endif 140#endif
141 141
 142/*
 143 * Get the first physically contiguous region of memory.
 144 */
 145static void
 146fdt_get_memory(uint64_t *paddr, uint64_t *psize)
 147{
 148 const int memory = OF_finddevice("/memory");
 149 uint64_t cur_addr, cur_size;
 150 int index;
 151
 152 /* Assume the first entry is the start of memory */
 153 if (fdtbus_get_reg64(memory, 0, paddr, psize) != 0)
 154 panic("Cannot determine memory size");
 155
 156 DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
 157 0, *paddr, *psize);
 158
 159 /* If subsequent entries follow the previous one, append them. */
 160 for (index = 1;
 161 fdtbus_get_reg64(memory, index, &cur_addr, &cur_size) == 0;
 162 index++) {
 163 DPRINTF("FDT /memory [%d] @ 0x%" PRIx64 " size 0x%" PRIx64 "\n",
 164 index, cur_addr, cur_size);
 165 if (*paddr + *psize == cur_addr)
 166 *psize += cur_size;
 167 }
 168}
 169
142u_int 170u_int
143initarm(void *arg) 171initarm(void *arg)
144{ 172{
145 const struct arm_platform *plat; 173 const struct arm_platform *plat;
146 uint64_t memory_addr, memory_size; 174 uint64_t memory_addr, memory_size;
147 psize_t ram_size = 0; 175 psize_t ram_size = 0;
148 176
149 /* Load FDT */ 177 /* Load FDT */
150 const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2]; 178 const uint8_t *fdt_addr_r = (const uint8_t *)uboot_args[2];
151 int error = fdt_check_header(fdt_addr_r); 179 int error = fdt_check_header(fdt_addr_r);
152 if (error == 0) { 180 if (error == 0) {
153 error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data)); 181 error = fdt_move(fdt_addr_r, fdt_data, sizeof(fdt_data));
154 if (error != 0) 182 if (error != 0)
@@ -209,29 +237,27 @@ initarm(void *arg) @@ -209,29 +237,27 @@ initarm(void *arg)
209 char mi_bootargs[] = BOOT_ARGS; 237 char mi_bootargs[] = BOOT_ARGS;
210 parse_mi_bootargs(mi_bootargs); 238 parse_mi_bootargs(mi_bootargs);
211#endif 239#endif
212 240
213 DPRINTF("KERNEL_BASE=0x%x, " 241 DPRINTF("KERNEL_BASE=0x%x, "
214 "KERNEL_VM_BASE=0x%x, " 242 "KERNEL_VM_BASE=0x%x, "
215 "KERNEL_VM_BASE - KERNEL_BASE=0x%x, " 243 "KERNEL_VM_BASE - KERNEL_BASE=0x%x, "
216 "KERNEL_BASE_VOFFSET=0x%x\n", 244 "KERNEL_BASE_VOFFSET=0x%x\n",
217 KERNEL_BASE, 245 KERNEL_BASE,
218 KERNEL_VM_BASE, 246 KERNEL_VM_BASE,
219 KERNEL_VM_BASE - KERNEL_BASE, 247 KERNEL_VM_BASE - KERNEL_BASE,
220 KERNEL_BASE_VOFFSET); 248 KERNEL_BASE_VOFFSET);
221 249
222 const int memory = OF_finddevice("/memory"); 250 fdt_get_memory(&memory_addr, &memory_size);
223 if (fdtbus_get_reg64(memory, 0, &memory_addr, &memory_size) != 0) 
224 panic("Cannot determine memory size"); 
225 251
226#if !defined(_LP64) 252#if !defined(_LP64)
227 /* Cannot map memory above 4GB */ 253 /* Cannot map memory above 4GB */
228 if (memory_addr + memory_size > 0x100000000) 254 if (memory_addr + memory_size > 0x100000000)
229 memory_size = 0x100000000 - memory_addr; 255 memory_size = 0x100000000 - memory_addr;
230#endif 256#endif
231 257
232 ram_size = (bus_size_t)memory_size; 258 ram_size = (bus_size_t)memory_size;
233 259
234#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS 260#ifdef __HAVE_MM_MD_DIRECT_MAPPED_PHYS
235 const bool mapallmem_p = true; 261 const bool mapallmem_p = true;
236#ifndef PMAP_NEED_ALLOC_POOLPAGE 262#ifndef PMAP_NEED_ALLOC_POOLPAGE
237 if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) { 263 if (ram_size > KERNEL_VM_BASE - KERNEL_BASE) {