Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 9 Sep 2008 13:18:57 GMT
From:      Rafal Jaworowski <raj@FreeBSD.org>
To:        Perforce Change Reviews <perforce@freebsd.org>
Subject:   PERFORCE change 149474 for review
Message-ID:  <200809091318.m89DIvOc019001@repoman.freebsd.org>

next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=149474

Change 149474 by raj@raj_mimi on 2008/09/09 13:18:50

	Dynamically calculate the number of required L2 tables in initarm().
	
	This lets the mv_machdep.c better handle varying sizes of system DRAM.
	
	Obtained from:	Marvell, Semihalf

Affected files ...

.. //depot/projects/arm/src/sys/arm/mv/mv_machdep.c#3 edit

Differences ...

==== //depot/projects/arm/src/sys/arm/mv/mv_machdep.c#3 (text+ko) ====

@@ -89,8 +89,12 @@
 #define KERNEL_PT_SYS	0	/* Page table for mapping proc0 zero page */
 #define KERNEL_PT_KERN	1
 
-/* This should be evenly divisable by PAGE_SIZE / L2_TABLE_SIZE_REAL (or 4) */
-#define NUM_KERNEL_PTS	8
+/*
+ * This is the number of L2 page tables required for covering max
+ * (hypothetical) memsize of 4GB and all kernel mappings (vectors, msgbuf,
+ * stacks etc.), uprounded to be divisible by 4.
+ */
+#define KERNEL_PT_MAX	78
 
 /* Define various stack sizes in pages */
 #define IRQ_STACK_SIZE	1
@@ -104,7 +108,7 @@
 extern const struct pmap_devmap	*pmap_devmap_bootstrap_table;
 extern vm_offset_t		pmap_bootstrap_lastaddr;
 
-struct pv_addr kernel_pt_table[NUM_KERNEL_PTS];
+struct pv_addr kernel_pt_table[KERNEL_PT_MAX];
 
 extern void *_end;
 extern int *end;
@@ -136,7 +140,7 @@
 	vm_offset_t freemempos;
 	vm_offset_t l2_start;
 	vm_offset_t lastaddr;
-	uint32_t memsize;
+	uint32_t memsize, l2size;
 
 	boothowto = RB_VERBOSE | RB_SINGLE;
 
@@ -150,6 +154,21 @@
 	pcpu_init(pcpup, 0, sizeof(struct pcpu));
 	PCPU_SET(curthread, &thread0);
 
+	memsize = platform_ramsize();
+	
+	/* Calculate number of L2 tables needed for mapping vm_page_array */
+	l2size = (memsize / PAGE_SIZE) * sizeof(struct vm_page);
+	l2size = (l2size >> L1_S_SHIFT) + 1;
+
+	/* 
+	 * Add one table for end of kernel map, one for stacks, msgbuf and
+	 * L1 and L2 tables map and one for vectors map.
+	 */
+	l2size += 3;
+
+	/* Make it divisible by 4 */
+	l2size = (l2size + 3) & ~3;
+
 #define KERNEL_TEXT_BASE (KERNBASE)
 	freemempos = (lastaddr + PAGE_MASK) & ~PAGE_MASK;
 
@@ -167,7 +186,7 @@
 		freemempos += PAGE_SIZE;
 	valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
 
-	for (i = 0; i < NUM_KERNEL_PTS; ++i) {
+	for (i = 0; i < l2size; ++i) {
 		if (!(i % (PAGE_SIZE / L2_TABLE_SIZE_REAL))) {
 			valloc_pages(kernel_pt_table[i],
 			    L2_TABLE_SIZE / PAGE_SIZE);
@@ -210,11 +229,11 @@
 	 * and kernel structures
 	 */
 	l2_start = lastaddr & ~(L1_S_OFFSET);
-	for (i = 0 ; i < NUM_KERNEL_PTS - 1; i++)
+	for (i = 0 ; i < l2size - 1; i++)
 		pmap_link_l2pt(l1pagetable, l2_start + i * L1_S_SIZE,
 		    &kernel_pt_table[KERNEL_PT_KERN + i]);
 
-	pmap_curmaxkvaddr = l2_start + NUM_KERNEL_PTS * L1_S_SIZE;
+	pmap_curmaxkvaddr = l2_start + (l2size - 1) * L1_S_SIZE;
 	
 	/* Map kernel code and data */
 	pmap_map_chunk(l1pagetable, KERNVIRTADDR, KERNPHYSADDR,
@@ -228,7 +247,7 @@
 
 	pmap_map_chunk(l1pagetable, kernel_pt_table[0].pv_va,
 	    kernel_pt_table[0].pv_pa,
-	    L2_TABLE_SIZE_REAL * NUM_KERNEL_PTS,
+	    L2_TABLE_SIZE_REAL * l2size,
 	    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
 
 	/* Map allocated stacks and msgbuf */
@@ -249,7 +268,6 @@
 	cpu_tlb_flushID();
 	cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL * 2));
 	cninit();
-	memsize = platform_ramsize();
 	physmem = memsize / PAGE_SIZE;
 
 	/*



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