1515#endif
1616#include <linux/swap.h>
1717#include <linux/module.h>
18+ #include <linux/highmem.h>
1819#include <asm/page.h>
1920#include <asm/pgalloc.h>
2021#include <asm/sections.h>
@@ -27,6 +28,12 @@ EXPORT_SYMBOL(empty_zero_page);
2728static const unsigned long low_mem_start = CONFIG_LINUX_LINK_BASE ;
2829static unsigned long low_mem_sz ;
2930
31+ #ifdef CONFIG_HIGHMEM
32+ static unsigned long min_high_pfn ;
33+ static u64 high_mem_start ;
34+ static u64 high_mem_sz ;
35+ #endif
36+
3037/* User can over-ride above with "mem=nnn[KkMm]" in cmdline */
3138static int __init setup_mem_sz (char * str )
3239{
@@ -41,10 +48,22 @@ early_param("mem", setup_mem_sz);
4148
4249void __init early_init_dt_add_memory_arch (u64 base , u64 size )
4350{
44- low_mem_sz = size ;
45- BUG_ON (base != low_mem_start );
51+ int in_use = 0 ;
52+
53+ if (!low_mem_sz ) {
54+ BUG_ON (base != low_mem_start );
55+ low_mem_sz = size ;
56+ in_use = 1 ;
57+ } else {
58+ #ifdef CONFIG_HIGHMEM
59+ high_mem_start = base ;
60+ high_mem_sz = size ;
61+ in_use = 1 ;
62+ #endif
63+ }
4664
47- pr_info ("Memory @ %llx of %ldM\n" , base , TO_MB (size ));
65+ pr_info ("Memory @ %llx [%lldM] %s\n" ,
66+ base , TO_MB (size ), !in_use ? "Not used" :"" );
4867}
4968
5069#ifdef CONFIG_BLK_DEV_INITRD
@@ -74,6 +93,7 @@ early_param("initrd", early_initrd);
7493void __init setup_arch_memory (void )
7594{
7695 unsigned long zones_size [MAX_NR_ZONES ];
96+ unsigned long zones_holes [MAX_NR_ZONES ];
7797
7898 init_mm .start_code = (unsigned long )_text ;
7999 init_mm .end_code = (unsigned long )_etext ;
@@ -86,9 +106,26 @@ void __init setup_arch_memory(void)
86106 /* Last usable page of low mem */
87107 max_low_pfn = max_pfn = PFN_DOWN (low_mem_start + low_mem_sz );
88108
89- max_mapnr = max_low_pfn - min_low_pfn ;
109+ #ifdef CONFIG_HIGHMEM
110+ min_high_pfn = PFN_DOWN (high_mem_start );
111+ max_pfn = PFN_DOWN (high_mem_start + high_mem_sz );
112+ #endif
113+
114+ max_mapnr = max_pfn - min_low_pfn ;
90115
91116 /*------------- bootmem allocator setup -----------------------*/
117+
118+ /*
119+ * seed the bootmem allocator after any DT memory node parsing or
120+ * "mem=xxx" cmdline overrides have potentially updated @arc_mem_sz
121+ *
122+ * Only low mem is added, otherwise we have crashes when allocating
123+ * mem_map[] itself. NO_BOOTMEM allocates mem_map[] at the end of
124+ * avail memory, ending in highmem with a > 32-bit address. However
125+ * it then tries to memset it with a truncaed 32-bit handle, causing
126+ * the crash
127+ */
128+
92129 memblock_add (low_mem_start , low_mem_sz );
93130 memblock_reserve (low_mem_start , __pa (_end ) - low_mem_start );
94131
@@ -101,7 +138,17 @@ void __init setup_arch_memory(void)
101138
102139 /*----------------- node/zones setup --------------------------*/
103140 memset (zones_size , 0 , sizeof (zones_size ));
141+ memset (zones_holes , 0 , sizeof (zones_holes ));
142+
104143 zones_size [ZONE_NORMAL ] = max_low_pfn - min_low_pfn ;
144+ zones_holes [ZONE_NORMAL ] = 0 ;
145+
146+ #ifdef CONFIG_HIGHMEM
147+ zones_size [ZONE_HIGHMEM ] = max_pfn - max_low_pfn ;
148+
149+ /* This handles the peripheral address space hole */
150+ zones_holes [ZONE_HIGHMEM ] = min_high_pfn - max_low_pfn ;
151+ #endif
105152
106153 /*
107154 * We can't use the helper free_area_init(zones[]) because it uses
@@ -112,9 +159,12 @@ void __init setup_arch_memory(void)
112159 free_area_init_node (0 , /* node-id */
113160 zones_size , /* num pages per zone */
114161 min_low_pfn , /* first pfn of node */
115- NULL ); /* NO holes */
162+ zones_holes ); /* holes */
116163
117- high_memory = (void * )end_mem ;
164+ #ifdef CONFIG_HIGHMEM
165+ high_memory = (void * )(min_high_pfn << PAGE_SHIFT );
166+ kmap_init ();
167+ #endif
118168}
119169
120170/*
@@ -125,6 +175,14 @@ void __init setup_arch_memory(void)
125175 */
126176void __init mem_init (void )
127177{
178+ #ifdef CONFIG_HIGHMEM
179+ unsigned long tmp ;
180+
181+ reset_all_zones_managed_pages ();
182+ for (tmp = min_high_pfn ; tmp < max_pfn ; tmp ++ )
183+ free_highmem_page (pfn_to_page (tmp ));
184+ #endif
185+
128186 free_all_bootmem ();
129187 mem_init_print_info (NULL );
130188}
0 commit comments