Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 15 May 2014 20:58:23 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r266194 - in stable/10/sys: arm/arm arm/at91 arm/conf arm/econa arm/include arm/s3c2xx0 arm/sa11x0 arm/xscale/i80321 arm/xscale/i8134x arm/xscale/ixp425 arm/xscale/pxa conf
Message-ID:  <201405152058.s4FKwNUh001355@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Thu May 15 20:58:23 2014
New Revision: 266194
URL: http://svnweb.freebsd.org/changeset/base/266194

Log:
  MFC r261643, r261646, r261648, r261649, r261651, r261656, r261657, r261663,
      r261676, r261677, r261698, r261778
  
    Consolidate code related to setting up physical memory configuration into
    a new physmem.c file.
  
    Replace compile-time constant KERNPHYSADDR with abp_physaddr
  
    Calculate the kernel's load address from the PC in the elf / gzip
    trampoline instead of relying on KERNPHYSADDR as a compile-time constant.
  
    It turns out a global variable is the only straightforward way to
    communicate the kernel's physical load address from where it's known in
    initarm() into cpu_mp_start() which is called from non-arm code and
    takes no parameters.
  
    Remove the now unused MMU_INIT macro.
  
    Use vm_paddr_t, not vm_offset_t, when dealing with physical addresses.
  
    No need to set physmem in each initarm() instance anymore, it's handled
    in common code now.
  
    Pass the pagetable used from locore.S to initarm to allow it to map data
    in as required.
  
    Fix the physmem exclude-region clipping logic for the edge-trim case.
  
    Add some extra debugging output when DEBUG is defined.
  
    Update legacy platforms to use new arm_physmem helper routines.

Added:
  stable/10/sys/arm/arm/physmem.c
     - copied, changed from r261643, head/sys/arm/arm/physmem.c
  stable/10/sys/arm/include/physmem.h
     - copied, changed from r261643, head/sys/arm/include/physmem.h
Modified:
  stable/10/sys/arm/arm/elf_trampoline.c
  stable/10/sys/arm/arm/locore.S
  stable/10/sys/arm/arm/machdep.c
  stable/10/sys/arm/arm/mp_machdep.c
  stable/10/sys/arm/at91/at91_machdep.c
  stable/10/sys/arm/conf/VYBRID.common
  stable/10/sys/arm/econa/econa_machdep.c
  stable/10/sys/arm/include/cpu.h
  stable/10/sys/arm/include/machdep.h
  stable/10/sys/arm/s3c2xx0/s3c24x0_machdep.c
  stable/10/sys/arm/sa11x0/assabet_machdep.c
  stable/10/sys/arm/xscale/i80321/ep80219_machdep.c
  stable/10/sys/arm/xscale/i80321/iq31244_machdep.c
  stable/10/sys/arm/xscale/i8134x/crb_machdep.c
  stable/10/sys/arm/xscale/ixp425/avila_machdep.c
  stable/10/sys/arm/xscale/pxa/pxa_machdep.c
  stable/10/sys/conf/files.arm
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/sys/arm/arm/elf_trampoline.c
==============================================================================
--- stable/10/sys/arm/arm/elf_trampoline.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/arm/elf_trampoline.c	Thu May 15 20:58:23 2014	(r266194)
@@ -186,14 +186,20 @@ static void arm9_setup(void);
 void
 _startC(void)
 {
-	int physaddr = KERNPHYSADDR;
 	int tmp1;
 	unsigned int sp = ((unsigned int)&_end & ~3) + 4;
-#if defined(FLASHADDR) && defined(PHYSADDR) && defined(LOADERRAMADDR)
-	unsigned int pc;
+	unsigned int pc, kernphysaddr;
 
+	/*
+	 * Figure out the physical address the kernel was loaded at.  This
+	 * assumes the entry point (this code right here) is in the first page,
+	 * which will always be the case for this trampoline code.
+	 */
 	__asm __volatile("mov %0, pc\n"
 	    : "=r" (pc));
+	kernphysaddr = pc & ~PAGE_MASK;
+
+#if defined(FLASHADDR) && defined(PHYSADDR) && defined(LOADERRAMADDR)
 	if ((FLASHADDR > LOADERRAMADDR && pc >= FLASHADDR) ||
 	    (FLASHADDR < LOADERRAMADDR && pc < LOADERRAMADDR)) {
 		/*
@@ -247,7 +253,7 @@ _startC(void)
 			 "mov pc, %0\n"
 			 "2: nop\n"
 			 "mov sp, %2\n"
-			 : "=r" (tmp1), "+r" (physaddr), "+r" (sp));
+			 : "=r" (tmp1), "+r" (kernphysaddr), "+r" (sp));
 #ifndef KZIP
 #ifdef CPU_ARM9
 	/* So that idcache_wbinv works; */

Modified: stable/10/sys/arm/arm/locore.S
==============================================================================
--- stable/10/sys/arm/arm/locore.S	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/arm/locore.S	Thu May 15 20:58:23 2014	(r266194)
@@ -221,7 +221,7 @@ mmu_done:
 	ldr	pc, .Lvirt_done
 
 virt_done:
-	mov	r1, #24			/* loader info size is 24 bytes also second arg */
+	mov	r1, #28			/* loader info size is 28 bytes also second arg */
 	subs	sp, sp, r1		/* allocate arm_boot_params struct on stack */
 	bic	sp, sp, #7		/* align stack to 8 bytes */
 	mov	r0, sp			/* loader info pointer is first arg */
@@ -232,6 +232,8 @@ virt_done:
 	str	fp, [r0, #16]		/* store r3 from boot loader */
 	ldr	r5, =KERNPHYSADDR	/* load KERNPHYSADDR as the physical address */
 	str	r5, [r0, #20]		/* store the physical address */
+	ldr	r5, Lstartup_pagetable
+	str	r5, [r0, #24]		/* store the pagetable address */
 	mov	fp, #0			/* trace back starts here */
 	bl	_C_LABEL(initarm)	/* Off we go */
 
@@ -277,11 +279,6 @@ build_pagetables:
 
 	RET
 
-#define MMU_INIT(va,pa,n_sec,attr) \
-	.word	n_sec					    ; \
-	.word	4*((va)>>L1_S_SHIFT)			    ; \
-	.word	(pa)|(attr)				    ;
-
 Lvirtaddr:
 	.word	KERNVIRTADDR
 Lphysaddr:

Modified: stable/10/sys/arm/arm/machdep.c
==============================================================================
--- stable/10/sys/arm/arm/machdep.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/arm/machdep.c	Thu May 15 20:58:23 2014	(r266194)
@@ -97,6 +97,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/md_var.h>
 #include <machine/metadata.h>
 #include <machine/pcb.h>
+#include <machine/physmem.h>
 #include <machine/reg.h>
 #include <machine/trap.h>
 #include <machine/undefined.h>
@@ -122,8 +123,6 @@ uint32_t cpu_reset_address = 0;
 int cold = 1;
 vm_offset_t vector_page;
 
-long realmem = 0;
-
 int (*_arm_memcpy)(void *, void *, int, int) = NULL;
 int (*_arm_bzero)(void *, int, int) = NULL;
 int _min_memcpy_size = 0;
@@ -144,9 +143,6 @@ extern vm_offset_t ksym_start, ksym_end;
 
 static struct pv_addr kernel_pt_table[KERNEL_PT_MAX];
 
-vm_paddr_t phys_avail[10];
-vm_paddr_t dump_avail[4];
-
 extern u_int data_abort_handler_address;
 extern u_int prefetch_abort_handler_address;
 extern u_int undefined_handler_address;
@@ -356,6 +352,7 @@ static void
 cpu_startup(void *dummy)
 {
 	struct pcb *pcb = thread0.td_pcb;
+	const unsigned int mbyte = 1024 * 1024;
 #ifdef ARM_TP_ADDRESS
 #ifndef ARM_CACHE_LOCK_ENABLE
 	vm_page_t m;
@@ -364,36 +361,21 @@ cpu_startup(void *dummy)
 
 	identify_arm_cpu();
 
-	printf("real memory  = %ju (%ju MB)\n", (uintmax_t)ptoa(physmem),
-	    (uintmax_t)ptoa(physmem) / 1048576);
-	realmem = physmem;
+	vm_ksubmap_init(&kmi);
 
 	/*
 	 * Display the RAM layout.
 	 */
-	if (bootverbose) {
-		int indx;
-
-		printf("Physical memory chunk(s):\n");
-		for (indx = 0; phys_avail[indx + 1] != 0; indx += 2) {
-			vm_paddr_t size;
-
-			size = phys_avail[indx + 1] - phys_avail[indx];
-			printf("  0x%08jx - 0x%08jx, %ju KBytes (%ju pages)\n",
-			    (uintmax_t)phys_avail[indx],
-			    (uintmax_t)phys_avail[indx + 1] - 1,
-			    (uintmax_t)size / 1024, (uintmax_t)size / PAGE_SIZE);
-		}
-	}
-
-	vm_ksubmap_init(&kmi);
-
+	printf("real memory  = %ju (%ju MB)\n", 
+	    (uintmax_t)arm32_ptob(realmem),
+	    (uintmax_t)arm32_ptob(realmem) / mbyte);
 	printf("avail memory = %ju (%ju MB)\n",
-	    (uintmax_t)ptoa(cnt.v_free_count),
-	    (uintmax_t)ptoa(cnt.v_free_count) / 1048576);
-
-	if (bootverbose)
+	    (uintmax_t)arm32_ptob(cnt.v_free_count),
+	    (uintmax_t)arm32_ptob(cnt.v_free_count) / mbyte);
+	if (bootverbose) {
+		arm_physmem_print_tables();
 		arm_devmap_print_table();
+	}
 
 	bufinit();
 	vm_pager_bufferinit();
@@ -780,44 +762,6 @@ makectx(struct trapframe *tf, struct pcb
 }
 
 /*
- * Make a standard dump_avail array.  Can't make the phys_avail
- * since we need to do that after we call pmap_bootstrap, but this
- * is needed before pmap_boostrap.
- */
-void
-arm_dump_avail_init(vm_paddr_t physaddr, vm_offset_t ramsize, size_t max)
-{
-#ifdef LINUX_BOOT_ABI
-	/*
-	 * Linux boot loader passes us the actual banks of memory, so use them
-	 * to construct the dump_avail array.
-	 */
-	if (membanks > 0) 
-	{
-		int i, j;
-
-		if (max < (membanks + 1) * 2)
-			panic("dump_avail[%d] too small for %d banks\n",
-			    max, membanks);
-		for (j = 0, i = 0; i < membanks; i++) {
-			dump_avail[j++] = round_page(memstart[i]);
-			dump_avail[j++] = trunc_page(memstart[i] + memsize[i]);
-		}
-		dump_avail[j++] = 0;
-		dump_avail[j++] = 0;
-		return;
-	}
-#endif
-	if (max < 4)
-		panic("dump_avail too small\n");
-
-	dump_avail[0] = round_page(physaddr);
-	dump_avail[1] = trunc_page(physaddr + ramsize);
-	dump_avail[2] = 0;
-	dump_avail[3] = 0;
-}
-
-/*
  * Fake up a boot descriptor table
  */
 vm_offset_t
@@ -910,11 +854,8 @@ linux_parse_boot_param(struct arm_boot_p
 		case ATAG_CORE:
 			break;
 		case ATAG_MEM:
-			if (membanks < LBABI_MAX_BANKS) {
-				memstart[membanks] = walker->u.tag_mem.start;
-				memsize[membanks] = walker->u.tag_mem.size;
-			}
-			membanks++;
+			arm_physmem_hardware_region(walker->u.tag_mem.start,
+			    walker->u.tag_mem.size);
 			break;
 		case ATAG_INITRD2:
 			break;
@@ -1077,120 +1018,10 @@ print_kenv(void)
 		debugf(" %x %s\n", (uint32_t)cp, cp);
 }
 
-static void
-physmap_init(struct mem_region *availmem_regions, int availmem_regions_sz,
-    vm_offset_t kernload)
-{
-	int i, j, cnt;
-	vm_offset_t phys_kernelend;
-	uint32_t s, e, sz;
-	struct mem_region *mp, *mp1;
-
-	phys_kernelend = kernload + (virtual_avail - KERNVIRTADDR);
-
-	/*
-	 * Remove kernel physical address range from avail
-	 * regions list. Page align all regions.
-	 * Non-page aligned memory isn't very interesting to us.
-	 * Also, sort the entries for ascending addresses.
-	 */
-	sz = 0;
-	cnt = availmem_regions_sz;
-	debugf("processing avail regions:\n");
-	for (mp = availmem_regions; mp->mr_size; mp++) {
-		s = mp->mr_start;
-		e = mp->mr_start + mp->mr_size;
-		debugf(" %08x-%08x -> ", s, e);
-		/* Check whether this region holds all of the kernel. */
-		if (s < kernload && e > phys_kernelend) {
-			availmem_regions[cnt].mr_start = phys_kernelend;
-			availmem_regions[cnt++].mr_size = e - phys_kernelend;
-			e = kernload;
-		}
-		/* Look whether this regions starts within the kernel. */
-		if (s >= kernload && s < phys_kernelend) {
-			if (e <= phys_kernelend)
-				goto empty;
-			s = phys_kernelend;
-		}
-		/* Now look whether this region ends within the kernel. */
-		if (e > kernload && e <= phys_kernelend) {
-			if (s >= kernload) {
-				goto empty;
-			}
-			e = kernload;
-		}
-		/* Now page align the start and size of the region. */
-		s = round_page(s);
-		e = trunc_page(e);
-		if (e < s)
-			e = s;
-		sz = e - s;
-		debugf("%08x-%08x = %x\n", s, e, sz);
-
-		/* Check whether some memory is left here. */
-		if (sz == 0) {
-		empty:
-			printf("skipping\n");
-			bcopy(mp + 1, mp,
-			    (cnt - (mp - availmem_regions)) * sizeof(*mp));
-			cnt--;
-			mp--;
-			continue;
-		}
-
-		/* Do an insertion sort. */
-		for (mp1 = availmem_regions; mp1 < mp; mp1++)
-			if (s < mp1->mr_start)
-				break;
-		if (mp1 < mp) {
-			bcopy(mp1, mp1 + 1, (char *)mp - (char *)mp1);
-			mp1->mr_start = s;
-			mp1->mr_size = sz;
-		} else {
-			mp->mr_start = s;
-			mp->mr_size = sz;
-		}
-	}
-	availmem_regions_sz = cnt;
-
-	/* Fill in phys_avail table, based on availmem_regions */
-	debugf("fill in phys_avail:\n");
-	for (i = 0, j = 0; i < availmem_regions_sz; i++, j += 2) {
-
-		debugf(" region: 0x%08x - 0x%08x (0x%08x)\n",
-		    availmem_regions[i].mr_start,
-		    availmem_regions[i].mr_start + availmem_regions[i].mr_size,
-		    availmem_regions[i].mr_size);
-
-		/*
-		 * We should not map the page at PA 0x0000000, the VM can't
-		 * handle it, as pmap_extract() == 0 means failure.
-		 */
-		if (availmem_regions[i].mr_start > 0 ||
-		    availmem_regions[i].mr_size > PAGE_SIZE) {
-			vm_size_t size;
-			phys_avail[j] = availmem_regions[i].mr_start;
-
-			size = availmem_regions[i].mr_size;
-			if (phys_avail[j] == 0) {
-				phys_avail[j] += PAGE_SIZE;
-				size -= PAGE_SIZE;
-			}
-			phys_avail[j + 1] = availmem_regions[i].mr_start + size;
-		} else
-			j -= 2;
-	}
-	phys_avail[j] = 0;
-	phys_avail[j + 1] = 0;
-}
-
 void *
 initarm(struct arm_boot_params *abp)
 {
-	struct mem_region memory_regions[FDT_MEM_REGIONS];
-	struct mem_region availmem_regions[FDT_MEM_REGIONS];
-	struct mem_region reserved_regions[FDT_MEM_REGIONS];
+	struct mem_region mem_regions[FDT_MEM_REGIONS];
 	struct pv_addr kernel_l1pt;
 	struct pv_addr dpcpu;
 	vm_offset_t dtbp, freemempos, l2_start, lastaddr;
@@ -1198,15 +1029,11 @@ initarm(struct arm_boot_params *abp)
 	char *env;
 	void *kmdp;
 	u_int l1pagetable;
-	int i = 0, j = 0, err_devmap = 0;
-	int memory_regions_sz;
-	int availmem_regions_sz;
-	int reserved_regions_sz;
-	vm_offset_t start, end;
-	vm_offset_t rstart, rend;
-	int curr;
+	int i, j, err_devmap, mem_regions_sz;
 
 	lastaddr = parse_boot_param(abp);
+	arm_physmem_kernaddr = abp->abp_physaddr;
+
 	memsize = 0;
 	set_cpufuncs();
 
@@ -1235,72 +1062,14 @@ initarm(struct arm_boot_params *abp)
 		while (1);
 
 	/* Grab physical memory regions information from device tree. */
-	if (fdt_get_mem_regions(memory_regions, &memory_regions_sz,
-	    &memsize) != 0)
-		while(1);
-
-	/* Grab physical memory regions information from device tree. */
-	if (fdt_get_reserved_regions(reserved_regions, &reserved_regions_sz) != 0)
-		reserved_regions_sz = 0;
-		
-	/*
-	 * Now exclude all the reserved regions
-	 */
-	curr = 0;
-	for (i = 0; i < memory_regions_sz; i++) {
-		start = memory_regions[i].mr_start;
-		end = start + memory_regions[i].mr_size;
-		for (j = 0; j < reserved_regions_sz; j++) {
-			rstart = reserved_regions[j].mr_start;
-			rend = rstart + reserved_regions[j].mr_size;
-			/* 
-			 * Restricted region is before available
-			 * Skip restricted region
-			 */
-			if (rend <= start)
-				continue;
-			/* 
-			 * Restricted region is behind available
-			 * No  further processing required
-			 */
-			if (rstart >= end)
-				break;
-			/*
-			 * Restricted region includes memory region
-			 * skip available region
-			 */
-			if ((start >= rstart) && (rend >= end)) {
-				start = rend;
-				end = rend;
-				break;
-			}
-			/*
-			 * Memory region includes restricted region
-			 */
-			if ((rstart > start) && (end > rend)) {
-				availmem_regions[curr].mr_start = start;
-				availmem_regions[curr++].mr_size = rstart - start;
-				start = rend;
-				break;
-			}
-			/*
-			 * Memory region partially overlaps with restricted
-			 */
-			if ((rstart >= start) && (rstart <= end)) {
-				end = rstart;
-			}
-			else if ((rend >= start) && (rend <= end)) {
-				start = rend;
-			}
-		}
-
-		if (end > start) {
-			availmem_regions[curr].mr_start = start;
-			availmem_regions[curr++].mr_size = end - start;
-		}
-	}
-
-	availmem_regions_sz = curr;
+	if (fdt_get_mem_regions(mem_regions, &mem_regions_sz, &memsize) != 0)
+		panic("Cannot get physical memory regions");
+	arm_physmem_hardware_regions(mem_regions, mem_regions_sz);
+
+	/* Grab reserved memory regions information from device tree. */
+	if (fdt_get_reserved_regions(mem_regions, &mem_regions_sz) == 0)
+		arm_physmem_exclude_regions(mem_regions, mem_regions_sz, 
+		    EXFLAG_NODUMP | EXFLAG_NOALLOC);
 
 	/* Platform-specific initialisation */
 	initarm_early_init();
@@ -1339,7 +1108,7 @@ initarm(struct arm_boot_params *abp)
 		freemempos += PAGE_SIZE;
 	valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
 
-	for (i = 0; i < l2size; ++i) {
+	for (i = 0, j = 0; i < l2size; ++i) {
 		if (!(i % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
 			valloc_pages(kernel_pt_table[i],
 			    L2_TABLE_SIZE / PAGE_SIZE);
@@ -1446,8 +1215,6 @@ initarm(struct arm_boot_params *abp)
 
 	cninit();
 
-	physmem = memsize / PAGE_SIZE;
-
 	debugf("initarm: console initialized\n");
 	debugf(" arg1 kmdp = 0x%08x\n", (uint32_t)kmdp);
 	debugf(" boothowto = 0x%08x\n", boothowto);
@@ -1498,17 +1265,22 @@ initarm(struct arm_boot_params *abp)
 
 	arm_intrnames_init();
 	arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
-	arm_dump_avail_init(abp->abp_physaddr, memsize,
-	    sizeof(dump_avail) / sizeof(dump_avail[0]));
 	pmap_bootstrap(freemempos, &kernel_l1pt);
 	msgbufp = (void *)msgbufpv.pv_va;
 	msgbufinit(msgbufp, msgbufsize);
 	mutex_init();
 
 	/*
-	 * Prepare map of physical memory regions available to vm subsystem.
+	 * Exclude the kernel (and all the things we allocated which immediately
+	 * follow the kernel) from the VM allocation pool but not from crash
+	 * dumps.  virtual_avail is a global variable which tracks the kva we've
+	 * "allocated" while setting up pmaps.
+	 *
+	 * Prepare the list of physical memory available to the vm subsystem.
 	 */
-	physmap_init(availmem_regions, availmem_regions_sz, abp->abp_physaddr);
+	arm_physmem_exclude_region(abp->abp_physaddr, 
+	    (virtual_avail - KERNVIRTADDR), EXFLAG_NOALLOC);
+	arm_physmem_init_kernel_globals();
 
 	init_param2(physmem);
 	kdb_init();

Modified: stable/10/sys/arm/arm/mp_machdep.c
==============================================================================
--- stable/10/sys/arm/arm/mp_machdep.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/arm/mp_machdep.c	Thu May 15 20:58:23 2014	(r266194)
@@ -47,6 +47,7 @@ __FBSDID("$FreeBSD$");
 #include <machine/smp.h>
 #include <machine/pcb.h>
 #include <machine/pte.h>
+#include <machine/physmem.h>
 #include <machine/intr.h>
 #include <machine/vmparam.h>
 #ifdef VFP
@@ -120,16 +121,16 @@ cpu_mp_start(void)
 		    M_WAITOK | M_ZERO);
 	temp_pagetable_va = (vm_offset_t)contigmalloc(L1_TABLE_SIZE,
 	    M_TEMP, 0, 0x0, 0xffffffff, L1_TABLE_SIZE, 0);
-	addr = KERNPHYSADDR;
-	addr_end = (vm_offset_t)&_end - KERNVIRTADDR + KERNPHYSADDR;
+	addr = arm_physmem_kernaddr;
+	addr_end = (vm_offset_t)&_end - KERNVIRTADDR + arm_physmem_kernaddr;
 	addr_end &= ~L1_S_OFFSET;
 	addr_end += L1_S_SIZE;
 	bzero((void *)temp_pagetable_va,  L1_TABLE_SIZE);
-	for (addr = KERNPHYSADDR; addr <= addr_end; addr += L1_S_SIZE) { 
+	for (addr = arm_physmem_kernaddr; addr <= addr_end; addr += L1_S_SIZE) { 
 		((int *)(temp_pagetable_va))[addr >> L1_S_SHIFT] =
 		    L1_TYPE_S|L1_SHARED|L1_S_C|L1_S_AP(AP_KRW)|L1_S_DOM(PMAP_DOMAIN_KERNEL)|addr;
 		((int *)(temp_pagetable_va))[(addr -
-			KERNPHYSADDR + KERNVIRTADDR) >> L1_S_SHIFT] = 
+			arm_physmem_kernaddr + KERNVIRTADDR) >> L1_S_SHIFT] = 
 		    L1_TYPE_S|L1_SHARED|L1_S_C|L1_S_AP(AP_KRW)|L1_S_DOM(PMAP_DOMAIN_KERNEL)|addr;
 	}
 

Copied and modified: stable/10/sys/arm/arm/physmem.c (from r261643, head/sys/arm/arm/physmem.c)
==============================================================================
--- head/sys/arm/arm/physmem.c	Sat Feb  8 23:54:16 2014	(r261643, copy source)
+++ stable/10/sys/arm/arm/physmem.c	Thu May 15 20:58:23 2014	(r266194)
@@ -49,7 +49,7 @@ __FBSDID("$FreeBSD$");
 #define	MAX_EXCNT	10
 
 struct region {
-	vm_offset_t	addr;
+	vm_paddr_t	addr;
 	vm_size_t	size;
 	uint32_t	flags;
 };
@@ -89,6 +89,9 @@ vm_paddr_t dump_avail[MAX_AVAIL_ENTRIES 
 /* This is the total number of hardware pages, excluded or not. */
 long realmem;
 
+/* The address at which the kernel was loaded.  Set early in initarm(). */
+vm_paddr_t arm_physmem_kernaddr;
+
 /*
  * Print the contents of the physical and excluded region tables using the
  * provided printf-like output function (which will be either printf or
@@ -119,6 +122,16 @@ physmem_dump_tables(int (*prfunc)(const 
 		    (flags & EXFLAG_NOALLOC) ? "NoAlloc" : "",
 		    (flags & EXFLAG_NODUMP)  ? "NoDump" : "");
 	}
+
+#ifdef DEBUG
+	prfunc("Avail lists:\n");
+	for (i = 0; phys_avail[i] != 0; ++i) {
+		prfunc("  phys_avail[%d] 0x%08x\n", i, phys_avail[i]);
+	}
+	for (i = 0; dump_avail[i] != 0; ++i) {
+		prfunc("  dump_avail[%d] 0x%08x\n", i, dump_avail[i]);
+	}
+#endif
 }
 
 /*
@@ -195,14 +208,14 @@ regions_to_avail(vm_paddr_t *avail, uint
 				continue;
 			}
 			/*
-			 * If excluded region partially overlaps this region,
-			 * trim the excluded portion off the appropriate end.
+			 * We know the excluded region overlaps either the start
+			 * or end of this hardware region (but not both), trim
+			 * the excluded portion off the appropriate end.
 			 */
-			if ((xstart >= start) && (xstart <= end)) {
-				end = xstart;
-			} else if ((xend >= start) && (xend <= end)) {
+			if (xstart <= start)
 				start = xend;
-			}
+			else
+				end = xstart;
 		}
 		/*
 		 * If the trimming actions above left a non-zero size, create an
@@ -224,7 +237,7 @@ regions_to_avail(vm_paddr_t *avail, uint
  * Insertion-sort a new entry into a regions list; sorted by start address.
  */
 static void
-insert_region(struct region *regions, size_t rcnt, vm_offset_t addr,
+insert_region(struct region *regions, size_t rcnt, vm_paddr_t addr,
     vm_size_t size, uint32_t flags)
 {
 	size_t i;
@@ -246,7 +259,7 @@ insert_region(struct region *regions, si
  * Add a hardware memory region.
  */
 void
-arm_physmem_hardware_region(vm_offset_t pa, vm_size_t sz)
+arm_physmem_hardware_region(vm_paddr_t pa, vm_size_t sz)
 {
 	vm_offset_t adj;
 
@@ -274,7 +287,7 @@ arm_physmem_hardware_region(vm_offset_t 
 /*
  * Add an exclusion region.
  */
-void arm_physmem_exclude_region(vm_offset_t pa, vm_size_t sz, uint32_t exflags)
+void arm_physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t exflags)
 {
 	vm_offset_t adj;
 

Modified: stable/10/sys/arm/at91/at91_machdep.c
==============================================================================
--- stable/10/sys/arm/at91/at91_machdep.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/at91/at91_machdep.c	Thu May 15 20:58:23 2014	(r266194)
@@ -68,6 +68,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/exec.h>
 #include <sys/kdb.h>
 #include <sys/msgbuf.h>
+#include <machine/physmem.h>
 #include <machine/reg.h>
 #include <machine/cpu.h>
 #include <machine/board.h>
@@ -199,9 +200,6 @@ const struct arm_devmap_entry at91_devma
 
 /* Physical and virtual addresses for some global pages */
 
-vm_paddr_t phys_avail[10];
-vm_paddr_t dump_avail[4];
-
 struct pv_addr systempage;
 struct pv_addr msgbufpv;
 struct pv_addr irqstack;
@@ -463,6 +461,7 @@ initarm(struct arm_boot_params *abp)
 	vm_offset_t lastaddr;
 
 	lastaddr = parse_boot_param(abp);
+	arm_physmem_kernaddr = abp->abp_physaddr;
 	set_cpufuncs();
 	pcpu0_init();
 
@@ -473,7 +472,7 @@ initarm(struct arm_boot_params *abp)
 	/* Define a macro to simplify memory allocation */
 #define valloc_pages(var, np)						\
 	alloc_pages((var).pv_va, (np));					\
-	(var).pv_pa = (var).pv_va + (KERNPHYSADDR - KERNVIRTADDR);
+	(var).pv_pa = (var).pv_va + (abp->abp_physaddr - KERNVIRTADDR);
 
 #define alloc_pages(var, np)						\
 	(var) = freemempos;						\
@@ -493,7 +492,7 @@ initarm(struct arm_boot_params *abp)
 			    L2_TABLE_SIZE_REAL;
 			kernel_pt_table[i].pv_pa =
 			    kernel_pt_table[i].pv_va - KERNVIRTADDR +
-			    KERNPHYSADDR;
+			    abp->abp_physaddr;
 		}
 	}
 	/*
@@ -591,7 +590,6 @@ initarm(struct arm_boot_params *abp)
 		printf("Warning: No soc support for %s found.\n", soc_info.name);
 
 	memsize = board_init();
-	physmem = memsize / PAGE_SIZE;
 
 	/*
 	 * Pages were allocated during the secondary bootstrap for the
@@ -630,8 +628,6 @@ initarm(struct arm_boot_params *abp)
 	arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
 
 	pmap_curmaxkvaddr = afterkern + L1_S_SIZE * (KERNEL_PT_KERN_NUM - 1);
-	arm_dump_avail_init(abp->abp_physaddr, memsize,
-	    sizeof(dump_avail)/sizeof(dump_avail[0]));
 	/* Always use the 256MB of KVA we have available between the kernel and devices */
 	vm_max_kernel_address = KERNVIRTADDR + (256 << 20);
 	pmap_bootstrap(freemempos, &kernel_l1pt);
@@ -639,15 +635,21 @@ initarm(struct arm_boot_params *abp)
 	msgbufinit(msgbufp, msgbufsize);
 	mutex_init();
 
-	i = 0;
-#if PHYSADDR != KERNPHYSADDR
-	phys_avail[i++] = PHYSADDR;
-	phys_avail[i++] = KERNPHYSADDR;
-#endif
-	phys_avail[i++] = virtual_avail - KERNVIRTADDR + KERNPHYSADDR;
-	phys_avail[i++] = PHYSADDR + memsize;
-	phys_avail[i++] = 0;
-	phys_avail[i++] = 0;
+	/*
+	 * Add the physical ram we have available.
+	 *
+	 * Exclude the kernel, and all the things we allocated which immediately
+	 * follow the kernel, from the VM allocation pool but not from crash
+	 * dumps.  virtual_avail is a global variable which tracks the kva we've
+	 * "allocated" while setting up pmaps.
+	 *
+	 * Prepare the list of physical memory available to the vm subsystem.
+	 */
+	arm_physmem_hardware_region(PHYSADDR, memsize);
+	arm_physmem_exclude_region(abp->abp_physaddr, 
+	    virtual_avail - KERNVIRTADDR, EXFLAG_NOALLOC);
+	arm_physmem_init_kernel_globals();
+
 	init_param2(physmem);
 	kdb_init();
 	return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -

Modified: stable/10/sys/arm/conf/VYBRID.common
==============================================================================
--- stable/10/sys/arm/conf/VYBRID.common	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/conf/VYBRID.common	Thu May 15 20:58:23 2014	(r266194)
@@ -61,11 +61,11 @@ options		BREAK_TO_DEBUGGER
 #options	VERBOSE_SYSINIT		#Enable verbose sysinit messages
 options		KDB
 options		DDB			#Enable the kernel debugger
-options		INVARIANTS		#Enable calls of extra sanity checking
-options		INVARIANT_SUPPORT	#Extra sanity checks of internal structures, required by INVARIANTS
+#options	INVARIANTS		#Enable calls of extra sanity checking
+#options	INVARIANT_SUPPORT	#Extra sanity checks of internal structures, required by INVARIANTS
 #options	WITNESS			#Enable checks to detect deadlocks and cycles
 #options	WITNESS_SKIPSPIN	#Don't run witness on spinlocks for speed
-options		DIAGNOSTIC
+#options	DIAGNOSTIC
 
 # NFS support
 options		NFSCL			#Network Filesystem Client

Modified: stable/10/sys/arm/econa/econa_machdep.c
==============================================================================
--- stable/10/sys/arm/econa/econa_machdep.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/econa/econa_machdep.c	Thu May 15 20:58:23 2014	(r266194)
@@ -60,6 +60,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/exec.h>
 #include <sys/kdb.h>
 #include <sys/msgbuf.h>
+#include <machine/physmem.h>
 #include <machine/reg.h>
 #include <machine/cpu.h>
 
@@ -98,9 +99,6 @@ struct pv_addr kernel_pt_table[NUM_KERNE
 
 /* Physical and virtual addresses for some global pages */
 
-vm_paddr_t phys_avail[10];
-vm_paddr_t dump_avail[4];
-
 struct pv_addr systempage;
 struct pv_addr msgbufpv;
 struct pv_addr irqstack;
@@ -180,6 +178,7 @@ initarm(struct arm_boot_params *abp)
 
 	boothowto = RB_VERBOSE;
 	lastaddr = parse_boot_param(abp);
+	arm_physmem_kernaddr = abp->abp_physaddr;
 	set_cpufuncs();
 	pcpu0_init();
 
@@ -191,7 +190,7 @@ initarm(struct arm_boot_params *abp)
 	/* Define a macro to simplify memory allocation */
 #define	valloc_pages(var, np)                   \
 	alloc_pages((var).pv_va, (np));         \
-	(var).pv_pa = (var).pv_va + (KERNPHYSADDR - KERNVIRTADDR);
+	(var).pv_pa = (var).pv_va + (abp->abp_physaddr - KERNVIRTADDR);
 
 #define	alloc_pages(var, np)			\
 	(var) = freemempos;		\
@@ -211,7 +210,7 @@ initarm(struct arm_boot_params *abp)
 			    L2_TABLE_SIZE_REAL;
 			kernel_pt_table[loop].pv_pa =
 			    kernel_pt_table[loop].pv_va - KERNVIRTADDR +
-			    KERNPHYSADDR;
+			    abp->abp_physaddr;
 		}
 	}
 	/*
@@ -284,7 +283,6 @@ initarm(struct arm_boot_params *abp)
 	cninit();
 	mem_info = ((*ddr) >> 4) & 0x3;
 	memsize = (8<<mem_info)*1024*1024;
-	physmem = memsize / PAGE_SIZE;
 
 	/*
 	 * Pages were allocated during the secondary bootstrap for the
@@ -322,8 +320,6 @@ initarm(struct arm_boot_params *abp)
 	arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
 
 	pmap_curmaxkvaddr = afterkern + L1_S_SIZE * (KERNEL_PT_KERN_NUM - 1);
-	arm_dump_avail_init(abp->abp_physaddr, memsize,
-	    sizeof(dump_avail) / sizeof(dump_avail[0]));
 	vm_max_kernel_address = KERNVIRTADDR + 3 * memsize;
 	pmap_bootstrap(freemempos, &kernel_l1pt);
 
@@ -332,16 +328,21 @@ initarm(struct arm_boot_params *abp)
 
 	mutex_init();
 
-	i = 0;
-#if PHYSADDR != KERNPHYSADDR
-	phys_avail[i++] = PHYSADDR;
-	phys_avail[i++] = KERNPHYSADDR;
-#endif
-	phys_avail[i++] = virtual_avail - KERNVIRTADDR + KERNPHYSADDR;
-
-	phys_avail[i++] = PHYSADDR + memsize;
-	phys_avail[i++] = 0;
-	phys_avail[i++] = 0;
+	/*
+	 * Add the physical ram we have available.
+	 *
+	 * Exclude the kernel, and all the things we allocated which immediately
+	 * follow the kernel, from the VM allocation pool but not from crash
+	 * dumps.  virtual_avail is a global variable which tracks the kva we've
+	 * "allocated" while setting up pmaps.
+	 *
+	 * Prepare the list of physical memory available to the vm subsystem.
+	 */
+	arm_physmem_hardware_region(PHYSADDR, memsize);
+	arm_physmem_exclude_region(abp->abp_physaddr, 
+	    virtual_avail - KERNVIRTADDR, EXFLAG_NOALLOC);
+	arm_physmem_init_kernel_globals();
+
 	init_param2(physmem);
 	kdb_init();
 

Modified: stable/10/sys/arm/include/cpu.h
==============================================================================
--- stable/10/sys/arm/include/cpu.h	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/include/cpu.h	Thu May 15 20:58:23 2014	(r266194)
@@ -35,6 +35,11 @@ get_cyclecount(void)
 
 extern vm_offset_t vector_page;
 
+/*
+ * Params passed into initarm. If you change the size of this you will
+ * need to update locore.S to allocate more memory on the stack before
+ * it calls initarm.
+ */
 struct arm_boot_params {
 	register_t	abp_size;	/* Size of this structure */
 	register_t	abp_r0;		/* r0 from the boot loader */
@@ -42,6 +47,7 @@ struct arm_boot_params {
 	register_t	abp_r2;		/* r2 from the boot loader */
 	register_t	abp_r3;		/* r3 from the boot loader */
 	vm_offset_t	abp_physaddr;	/* The kernel physical address */
+	vm_offset_t	abp_pagetable;	/* The early page table */
 };
 
 void	arm_vector_init(vm_offset_t, int);

Modified: stable/10/sys/arm/include/machdep.h
==============================================================================
--- stable/10/sys/arm/include/machdep.h	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/include/machdep.h	Thu May 15 20:58:23 2014	(r266194)
@@ -71,7 +71,4 @@ void initarm_late_init(void);
 void board_set_serial(uint64_t);
 void board_set_revision(uint32_t);
 
-/* Setup standard arrays */
-void arm_dump_avail_init(vm_paddr_t, vm_offset_t, size_t);
-
 #endif /* !_MACHINE_MACHDEP_H_ */

Copied and modified: stable/10/sys/arm/include/physmem.h (from r261643, head/sys/arm/include/physmem.h)
==============================================================================
--- head/sys/arm/include/physmem.h	Sat Feb  8 23:54:16 2014	(r261643, copy source)
+++ stable/10/sys/arm/include/physmem.h	Thu May 15 20:58:23 2014	(r266194)
@@ -30,6 +30,11 @@
 #define	_MACHINE_PHYSMEM_H_
 
 /*
+ * The physical address at which the kernel was loaded.
+ */
+extern vm_paddr_t arm_physmem_kernaddr;
+
+/*
  * Routines to help configure physical ram.
  *
  * Multiple regions of contiguous physical ram can be added (in any order).
@@ -47,8 +52,8 @@
 #define	EXFLAG_NODUMP	0x01
 #define	EXFLAG_NOALLOC	0x02
 
-void arm_physmem_hardware_region(vm_offset_t pa, vm_size_t sz);
-void arm_physmem_exclude_region(vm_offset_t pa, vm_size_t sz, uint32_t flags);
+void arm_physmem_hardware_region(vm_paddr_t pa, vm_size_t sz);
+void arm_physmem_exclude_region(vm_paddr_t pa, vm_size_t sz, uint32_t flags);
 void arm_physmem_init_kernel_globals(void);
 void arm_physmem_print_tables(void);
 

Modified: stable/10/sys/arm/s3c2xx0/s3c24x0_machdep.c
==============================================================================
--- stable/10/sys/arm/s3c2xx0/s3c24x0_machdep.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/s3c2xx0/s3c24x0_machdep.c	Thu May 15 20:58:23 2014	(r266194)
@@ -70,6 +70,7 @@ __FBSDID("$FreeBSD$");
 #include <sys/exec.h>
 #include <sys/kdb.h>
 #include <sys/msgbuf.h>
+#include <machine/physmem.h>
 #include <machine/reg.h>
 #include <machine/cpu.h>
 
@@ -113,9 +114,6 @@ struct pv_addr kernel_pt_table[NUM_KERNE
 
 /* Physical and virtual addresses for some global pages */
 
-vm_paddr_t phys_avail[10];
-vm_paddr_t dump_avail[4];
-
 struct pv_addr systempage;
 struct pv_addr msgbufpv;
 struct pv_addr irqstack;
@@ -227,6 +225,7 @@ initarm(struct arm_boot_params *abp)
 
 	boothowto = 0;  /* Likely not needed */
 	lastaddr = parse_boot_param(abp);
+	arm_physmem_kernaddr = abp->abp_physaddr;
 	i = 0;
 	set_cpufuncs();
 	cpufuncs.cf_sleep = s3c24x0_sleep;
@@ -241,7 +240,7 @@ initarm(struct arm_boot_params *abp)
 	/* Define a macro to simplify memory allocation */
 #define valloc_pages(var, np)			\
 	alloc_pages((var).pv_va, (np));		\
-	(var).pv_pa = (var).pv_va + (KERNPHYSADDR - KERNVIRTADDR);
+	(var).pv_pa = (var).pv_va + (abp->abp_physaddr - KERNVIRTADDR);
 
 #define alloc_pages(var, np)			\
 	(var) = freemempos;			\
@@ -261,7 +260,7 @@ initarm(struct arm_boot_params *abp)
 			    L2_TABLE_SIZE_REAL;
 			kernel_pt_table[loop].pv_pa =
 			    kernel_pt_table[loop].pv_va - KERNVIRTADDR +
-			    KERNPHYSADDR;
+			    abp->abp_physaddr;
 		}
 	}
 	/*
@@ -384,20 +383,26 @@ initarm(struct arm_boot_params *abp)
 	arm_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
 
 	pmap_curmaxkvaddr = afterkern + 0x100000 * (KERNEL_PT_KERN_NUM - 1);
-	arm_dump_avail_init(abp->abp_physaddr, memsize,
-	    sizeof(dump_avail) / sizeof(dump_avail[0]));
 	vm_max_kernel_address = KERNVIRTADDR + 3 * memsize;
 	pmap_bootstrap(freemempos, &kernel_l1pt);
 	msgbufp = (void*)msgbufpv.pv_va;
 	msgbufinit(msgbufp, msgbufsize);
 	mutex_init();
 
-	physmem = memsize / PAGE_SIZE;
-
-	phys_avail[0] = virtual_avail - KERNVIRTADDR + KERNPHYSADDR;
-	phys_avail[1] = PHYSADDR + memsize;
-	phys_avail[2] = 0;
-	phys_avail[3] = 0;
+	/*
+	 * Add the physical ram we have available.
+	 *
+	 * Exclude the kernel, and all the things we allocated which immediately
+	 * follow the kernel, from the VM allocation pool but not from crash
+	 * dumps.  virtual_avail is a global variable which tracks the kva we've
+	 * "allocated" while setting up pmaps.
+	 *
+	 * Prepare the list of physical memory available to the vm subsystem.
+	 */
+	arm_physmem_hardware_region(PHYSADDR, memsize);
+	arm_physmem_exclude_region(abp->abp_physaddr, 
+	    virtual_avail - KERNVIRTADDR, EXFLAG_NOALLOC);
+	arm_physmem_init_kernel_globals();
 
 	init_param2(physmem);
 	kdb_init();

Modified: stable/10/sys/arm/sa11x0/assabet_machdep.c
==============================================================================
--- stable/10/sys/arm/sa11x0/assabet_machdep.c	Thu May 15 20:41:16 2014	(r266193)
+++ stable/10/sys/arm/sa11x0/assabet_machdep.c	Thu May 15 20:58:23 2014	(r266194)
@@ -87,6 +87,8 @@ __FBSDID("$FreeBSD$");
 #include <machine/machdep.h>
 #include <machine/metadata.h>
 #include <machine/armreg.h>
+#include <machine/physmem.h>
+
 #include <machine/bus.h>
 #include <sys/reboot.h>
 
@@ -122,8 +124,6 @@ extern vm_offset_t sa1_cache_clean_addr;
 #endif
 /* Physical and virtual addresses for some global pages */
 
-vm_paddr_t phys_avail[10];
-vm_paddr_t dump_avail[4];
 vm_paddr_t physical_start;
 vm_paddr_t physical_end;
 vm_paddr_t physical_freestart;
@@ -202,9 +202,9 @@ initarm(struct arm_boot_params *abp)
 
 	boothowto = RB_VERBOSE | RB_SINGLE;     /* Default value */
 	lastaddr = parse_boot_param(abp);
+	arm_physmem_kernaddr = abp->abp_physaddr;
 	cninit();
 	set_cpufuncs();
-	physmem = memsize / PAGE_SIZE;
 	pcpu0_init();
 
 	/* Do basic tuning, hz etc */
@@ -374,16 +374,25 @@ initarm(struct arm_boot_params *abp)
 	cpu_setup("");
 
 	pmap_curmaxkvaddr = freemempos + KERNEL_PT_VMDATA_NUM * 0x400000;
-
-	dump_avail[0] = phys_avail[0] = round_page(virtual_avail);
-	dump_avail[1] = phys_avail[1] = 0xc0000000 + 0x02000000 - 1;
-	dump_avail[2] = phys_avail[2] = 0;
-	dump_avail[3] = phys_avail[3] = 0;
-					
 	mutex_init();
 	vm_max_kernel_address = 0xd0000000;
 	pmap_bootstrap(freemempos, &kernel_l1pt);
 
+	/*
+	 * Add the physical ram we have available.
+	 *
+	 * Exclude the kernel (and all the things we allocated which immediately
+	 * follow the kernel) from the VM allocation pool but not from crash
+	 * dumps.  virtual_avail is a global variable which tracks the kva we've
+	 * "allocated" while setting up pmaps.
+	 *
+	 * Prepare the list of physical memory available to the vm subsystem.
+	 */
+	arm_physmem_hardware_region(physical_start, memsize);
+	arm_physmem_exclude_region(abp->abp_physaddr, 
+	    virtual_avail - KERNVIRTADDR, EXFLAG_NOALLOC);
+	arm_physmem_init_kernel_globals();
+
 	init_param2(physmem);
 	kdb_init();
 	return ((void *)(kernelstack.pv_va + USPACE_SVC_STACK_TOP -

*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405152058.s4FKwNUh001355>