3131 * Define a startpg just past the end of the kernel image and a lastpg
3232 * that corresponds to the end of real or simulated platform memory.
3333 */
34- #define bootmem_startpg (PFN_UP(((unsigned long) _end) - PAGE_OFFSET))
34+ #define bootmem_startpg (PFN_UP(((unsigned long) _end) - PAGE_OFFSET + PHYS_OFFSET ))
3535
36- unsigned long bootmem_lastpg ; /* Should be set by platform code */
36+ unsigned long bootmem_lastpg ; /* Should be set by platform code */
37+ unsigned long __phys_offset ; /* physical kernel offset >> 12 */
3738
3839/* Set as variable to limit PMD copies */
3940int max_kernel_seg = 0x303 ;
@@ -44,7 +45,6 @@ unsigned long zero_page_mask;
4445/* indicate pfn's of high memory */
4546unsigned long highstart_pfn , highend_pfn ;
4647
47- /* struct mmu_gather defined in asm-generic.h; */
4848DEFINE_PER_CPU (struct mmu_gather , mmu_gathers );
4949
5050/* Default cache attribute for newly created page tables */
@@ -71,7 +71,7 @@ void __init mem_init(void)
7171{
7272 /* No idea where this is actually declared. Seems to evade LXR. */
7373 totalram_pages += free_all_bootmem ();
74- num_physpages = bootmem_lastpg ; /* seriously, what? */
74+ num_physpages = bootmem_lastpg - ARCH_PFN_OFFSET ;
7575
7676 printk (KERN_INFO "totalram_pages = %ld\n" , totalram_pages );
7777
@@ -193,6 +193,9 @@ void __init setup_arch_memory(void)
193193 * This needs to change for highmem setups.
194194 */
195195
196+ /* Prior to this, bootmem_lastpg is actually mem size */
197+ bootmem_lastpg += ARCH_PFN_OFFSET ;
198+
196199 /* Memory size needs to be a multiple of 16M */
197200 bootmem_lastpg = PFN_DOWN ((bootmem_lastpg << PAGE_SHIFT ) &
198201 ~((BIG_KERNEL_PAGE_SIZE ) - 1 ));
@@ -201,12 +204,15 @@ void __init setup_arch_memory(void)
201204 * Reserve the top DMA_RESERVE bytes of RAM for DMA (uncached)
202205 * memory allocation
203206 */
204- bootmap_size = init_bootmem (bootmem_startpg , bootmem_lastpg -
205- PFN_DOWN (DMA_RESERVED_BYTES ));
207+
208+ max_low_pfn = bootmem_lastpg - PFN_DOWN (DMA_RESERVED_BYTES );
209+ min_low_pfn = ARCH_PFN_OFFSET ;
210+ bootmap_size = init_bootmem_node (NODE_DATA (0 ), bootmem_startpg , min_low_pfn , max_low_pfn );
206211
207212 printk (KERN_INFO "bootmem_startpg: 0x%08lx\n" , bootmem_startpg );
208213 printk (KERN_INFO "bootmem_lastpg: 0x%08lx\n" , bootmem_lastpg );
209214 printk (KERN_INFO "bootmap_size: %d\n" , bootmap_size );
215+ printk (KERN_INFO "min_low_pfn: 0x%08lx\n" , min_low_pfn );
210216 printk (KERN_INFO "max_low_pfn: 0x%08lx\n" , max_low_pfn );
211217
212218 /*
@@ -221,14 +227,17 @@ void __init setup_arch_memory(void)
221227 /* this actually only goes to the end of the first gig */
222228 segtable_end = segtable + (1 <<(30 - 22 ));
223229
224- /* Move forward to the start of empty pages */
225- segtable += bootmem_lastpg >> (22 - PAGE_SHIFT );
230+ /*
231+ * Move forward to the start of empty pages; take into account
232+ * phys_offset shift.
233+ */
226234
235+ segtable += (bootmem_lastpg - ARCH_PFN_OFFSET )>>(22 - PAGE_SHIFT );
227236 {
228- int i ;
237+ int i ;
229238
230- for (i = 1 ; i <= DMA_RESERVE ; i ++ )
231- segtable [- i ] = ((segtable [- i ] & __HVM_PTE_PGMASK_4MB )
239+ for (i = 1 ; i <= DMA_RESERVE ; i ++ )
240+ segtable [- i ] = ((segtable [- i ] & __HVM_PTE_PGMASK_4MB )
232241 | __HVM_PTE_R | __HVM_PTE_W | __HVM_PTE_X
233242 | __HEXAGON_C_UNC << 6
234243 | __HVM_PDE_S_4MB );
@@ -256,7 +265,7 @@ void __init setup_arch_memory(void)
256265 * Free all the memory that wasn't taken up by the bootmap, the DMA
257266 * reserve, or kernel itself.
258267 */
259- free_bootmem (PFN_PHYS (bootmem_startpg )+ bootmap_size ,
268+ free_bootmem (PFN_PHYS (bootmem_startpg ) + bootmap_size ,
260269 PFN_PHYS (bootmem_lastpg - bootmem_startpg ) - bootmap_size -
261270 DMA_RESERVED_BYTES );
262271
0 commit comments