Fix some oddities in and around arch/i386/kernel/srat.c, with some cleanups attached. -- wli arch/i386/kernel/numaq.c | 3 - arch/i386/kernel/srat.c | 106 +++++++++++++++++++--------------------------- include/asm-i386/io.h | 28 ++++++++---- include/asm-i386/mmzone.h | 1 4 files changed, 66 insertions(+), 72 deletions(-) diff -prauN pgcl-2.5.70-bk6-1/arch/i386/kernel/numaq.c pgcl-2.5.70-bk6-2/arch/i386/kernel/numaq.c --- pgcl-2.5.70-bk6-1/arch/i386/kernel/numaq.c 2003-06-02 00:22:35.000000000 -0700 +++ pgcl-2.5.70-bk6-2/arch/i386/kernel/numaq.c 2003-06-02 02:17:05.000000000 -0700 @@ -30,9 +30,6 @@ #include #include -/* These are needed before the pgdat's are created */ -extern long node_start_pfn[], node_end_pfn[]; - #define MB_TO_PAGES(addr) ((addr) << (20 - MMUPAGE_SHIFT)) /* diff -prauN pgcl-2.5.70-bk6-1/arch/i386/kernel/srat.c pgcl-2.5.70-bk6-2/arch/i386/kernel/srat.c --- pgcl-2.5.70-bk6-1/arch/i386/kernel/srat.c 2003-05-26 18:00:25.000000000 -0700 +++ pgcl-2.5.70-bk6-2/arch/i386/kernel/srat.c 2003-06-02 02:38:40.000000000 -0700 @@ -24,23 +24,20 @@ * Send feedback to Pat Gaughen */ #include +#include #include #include #include #include #include +#include /* * proximity macros and definitions */ -#define NODE_ARRAY_INDEX(x) ((x) / 8) /* 8 bits/char */ -#define NODE_ARRAY_OFFSET(x) ((x) % 8) /* 8 bits/char */ -#define BMAP_SET(bmap, bit) ((bmap)[NODE_ARRAY_INDEX(bit)] |= 1 << NODE_ARRAY_OFFSET(bit)) -#define BMAP_TEST(bmap, bit) ((bmap)[NODE_ARRAY_INDEX(bit)] & (1 << NODE_ARRAY_OFFSET(bit))) -#define MAX_PXM_DOMAINS 256 /* 1 byte and no promises about values */ -/* bitmap length; _PXM is at most 255 */ -#define PXM_BITMAP_LEN (MAX_PXM_DOMAINS / 8) -static u8 pxm_bitmap[PXM_BITMAP_LEN]; /* bitmap of proximity domains */ +#define MAX_PXM_DOMAINS 256 /* 1 byte and no promises about values */ + +static DECLARE_BITMAP(pxm_bitmap, MAX_PXM_DOMAINS); #define MAX_CHUNKS_PER_NODE 4 #define MAXCHUNKS (MAX_CHUNKS_PER_NODE * MAX_NUMNODES) @@ -57,10 +54,6 @@ static int num_memory_chunks; /* total static int zholes_size_init; static unsigned long zholes_size[MAX_NUMNODES * MAX_NR_ZONES]; -extern unsigned long node_start_pfn[], node_end_pfn[]; - -extern void * boot_ioremap(unsigned long, unsigned long); - /* Identify CPU proximity domains */ static void __init parse_cpu_affinity_structure(char *p) { @@ -71,7 +64,7 @@ static void __init parse_cpu_affinity_st return; /* empty entry */ /* mark this node as "seen" in node bitmap */ - BMAP_SET(pxm_bitmap, cpu_affinity->proximity_domain); + set_bit(cpu_affinity->proximity_domain, pxm_bitmap); printk("CPU 0x%02X in proximity domain 0x%02X\n", cpu_affinity->apic_id, cpu_affinity->proximity_domain); @@ -94,7 +87,7 @@ static void __init parse_memory_affinity return; /* empty entry */ /* mark this node as "seen" in node bitmap */ - BMAP_SET(pxm_bitmap, memory_affinity->proximity_domain); + set_bit(memory_affinity->proximity_domain, pxm_bitmap); /* calculate info for memory chunk structure */ paddr = memory_affinity->base_addr_hi; @@ -102,8 +95,8 @@ static void __init parse_memory_affinity size = memory_affinity->length_hi; size = (size << 32) | memory_affinity->length_lo; - start_pfn = paddr >> PAGE_SHIFT; - end_pfn = (paddr + size) >> PAGE_SHIFT; + start_pfn = paddr >> MMUPAGE_SHIFT; + end_pfn = (paddr + size) >> MMUPAGE_SHIFT; pxm = memory_affinity->proximity_domain; @@ -140,25 +133,20 @@ static void __init parse_memory_affinity #if MAX_NR_ZONES != 3 #error "MAX_NR_ZONES != 3, chunk_to_zone requires review" #endif -/* Take a chunk of pages from page frame cstart to cend and count the number - * of pages in each zone, returned via zones[]. +/* + * Take a chunk of pages from page frame cstart to cend and count the number + * of pages in each zone, returned via zones[]. This has a hardcoded bias + * to round up; for uses other than holes, introduce a bias argument to + * round differently in each case. */ static __init void chunk_to_zones(unsigned long cstart, unsigned long cend, unsigned long *zones) { - unsigned long max_dma; - extern unsigned long max_low_pfn; - + unsigned long rend, max_dma = __pa(MAX_DMA_ADDRESS)/MMUPAGE_SIZE; int z; - unsigned long rend; - - /* FIXME: MAX_DMA_ADDRESS and max_low_pfn are trying to provide - * similarly scoped information and should be handled in a consistant - * manner. - */ - max_dma = virt_to_phys((char *)MAX_DMA_ADDRESS) >> PAGE_SHIFT; - /* Split the hole into the zones in which it falls. Repeatedly + /* + * Split the hole into the zones in which it falls. Repeatedly * take the segment in which the remaining hole starts, round it * to the end of that zone. */ @@ -176,7 +164,7 @@ static __init void chunk_to_zones(unsign z = ZONE_HIGHMEM; rend = cend; } - zones[z] += rend - cstart; + zones[z] += (rend - cstart + PAGE_MMUCOUNT - 1)/PAGE_MMUCOUNT; cstart = rend; } } @@ -192,9 +180,7 @@ static void __init initialize_physnode_m for (i = num_memory_chunks; --i >= 0; nmcp++) { for (pfn = nmcp->start_pfn; pfn <= nmcp->end_pfn; pfn += PAGES_PER_ELEMENT) - { - physnode_map[pfn / PAGES_PER_ELEMENT] = (int)nmcp->nid; - } + physnode_map[pfn/PAGES_PER_ELEMENT] = (int)nmcp->nid; } } @@ -245,7 +231,7 @@ static int __init acpi20_parse_srat(stru */ numnodes = 0; /* init total nodes in system */ for (i = 0; i < MAX_PXM_DOMAINS; i++) { - if (BMAP_TEST(pxm_bitmap, i)) { + if (test_bit(i, pxm_bitmap)) { pxm_to_nid_map[i] = numnodes; nid_to_pxm_map[numnodes] = i; node_set_online(numnodes); @@ -253,8 +239,7 @@ static int __init acpi20_parse_srat(stru } } - if (numnodes == 0) - BUG(); + BUG_ON(!numnodes); /* set cnode id in memory chunk structure */ for (i = 0; i < num_memory_chunks; i++) @@ -263,25 +248,24 @@ static int __init acpi20_parse_srat(stru initialize_physnode_map(); printk("pxm bitmap: "); - for (i = 0; i < sizeof(pxm_bitmap); i++) { - printk("%02X ", pxm_bitmap[i]); - } + for (i = 0; i < sizeof(pxm_bitmap); i++) + printk("%08X ", pxm_bitmap[i]); + printk("\n"); printk("Number of logical nodes in system = %d\n", numnodes); printk("Number of memory chunks in system = %d\n", num_memory_chunks); - for (j = 0; j < num_memory_chunks; j++){ + for (j = 0; j < num_memory_chunks; j++) printk("chunk %d nid %d start_pfn %08lx end_pfn %08lx\n", j, node_memory_chunk[j].nid, node_memory_chunk[j].start_pfn, node_memory_chunk[j].end_pfn); - } /*calculate node_start_pfn/node_end_pfn arrays*/ for (nid = 0; nid < numnodes; nid++) { int been_here_before = 0; - for (j = 0; j < num_memory_chunks; j++){ + for (j = 0; j < num_memory_chunks; j++) { if (node_memory_chunk[j].nid == nid) { if (been_here_before == 0) { node_start_pfn[nid] = node_memory_chunk[j].start_pfn; @@ -397,28 +381,28 @@ printk("Begin table scan....\n"); */ static void __init get_zholes_init(void) { - int nid; - int c; - int first; + int nid, c, first; unsigned long end = 0; for (nid = 0; nid < numnodes; nid++) { first = 1; - for (c = 0; c < num_memory_chunks; c++){ - if (node_memory_chunk[c].nid == nid) { - if (first) { - end = node_memory_chunk[c].end_pfn; - first = 0; - - } else { - /* Record any gap between this chunk - * and the previous chunk on this node - * against the zones it spans. - */ - chunk_to_zones(end, - node_memory_chunk[c].start_pfn, - &zholes_size[nid * MAX_NR_ZONES]); - } + for (c = 0; c < num_memory_chunks; c++) { + if (node_memory_chunk[c].nid != nid) + continue; + + /* + * Record any gap between this chunk and the + * previous chunk on this node against the zones + * it spans. Also, round up the sizes of holes + * subtracted out to PAGE_SIZE multiples. + */ + if (!first) + chunk_to_zones(end, + node_memory_chunk[c].start_pfn, + &zholes_size[MAX_NR_ZONES*nid]); + else { + end = node_memory_chunk[c].end_pfn; + first = 0; } } } @@ -430,7 +414,7 @@ unsigned long * __init get_zholes_size(i zholes_size_init++; get_zholes_init(); } - if((nid >= numnodes) | (nid >= MAX_NUMNODES)) + if (nid < 0 || nid >= numnodes || nid >= MAX_NUMNODES) printk("%s: nid = %d is invalid. numnodes = %d", __FUNCTION__, nid, numnodes); return &zholes_size[nid * MAX_NR_ZONES]; diff -prauN pgcl-2.5.70-bk6-1/include/asm-i386/io.h pgcl-2.5.70-bk6-2/include/asm-i386/io.h --- pgcl-2.5.70-bk6-1/include/asm-i386/io.h 2003-06-02 00:22:36.000000000 -0700 +++ pgcl-2.5.70-bk6-2/include/asm-i386/io.h 2003-06-02 02:25:34.000000000 -0700 @@ -69,7 +69,7 @@ * this function */ -static inline unsigned long virt_to_phys(volatile void * address) +static inline unsigned long virt_to_phys(volatile void *address) { return __pa(address); } @@ -87,7 +87,7 @@ static inline unsigned long virt_to_phys * this function */ -static inline void * phys_to_virt(unsigned long address) +static inline void *phys_to_virt(unsigned long address) { return __va(address); } @@ -97,7 +97,7 @@ static inline void * phys_to_virt(unsign */ #define page_to_phys(page) ((dma_addr_t)page_to_pfn(page) << MMUPAGE_SHIFT) -extern void * __ioremap(unsigned long offset, unsigned long size, unsigned long flags); +void *__ioremap(unsigned long offset, unsigned long size, unsigned long flags); /** * ioremap - map bus memory into CPU space @@ -111,21 +111,33 @@ extern void * __ioremap(unsigned long of * address. */ -static inline void * ioremap (unsigned long offset, unsigned long size) +static inline void *ioremap(unsigned long offset, unsigned long size) { return __ioremap(offset, size, 0); } -extern void * ioremap_nocache (unsigned long offset, unsigned long size); -extern void iounmap(void *addr); +void *ioremap_nocache(unsigned long offset, unsigned long size); +void iounmap(void *addr); + /* * bt_ioremap() and bt_iounmap() are for temporary early boot-time * mappings, before the real ioremap() is functional. * A boot-time mapping is currently limited to at most 16 pages. */ -extern void *bt_ioremap(unsigned long offset, unsigned long size); -extern void bt_iounmap(void *addr, unsigned long size); +void *bt_ioremap(unsigned long offset, unsigned long size); +void bt_iounmap(void *addr, unsigned long size); + +#ifdef CONFIG_BOOT_IOREMAP +/* + * boot_ioremap() is an "even earlier" ioremap, primarily for use + * when the pagetable formats used during early boot differ from + * those used at runtime, e.g. PAE booting off of non-PAE pagetables. + * Don't use this unless you _really_ know what you're doing. + * -- wli + */ +void *boot_ioremap(unsigned long paddr, unsigned long size); +#endif /* CONFIG_BOOT_IOREMAP */ /* * ISA I/O bus memory addresses are 1:1 with the physical address. diff -prauN pgcl-2.5.70-bk6-1/include/asm-i386/mmzone.h pgcl-2.5.70-bk6-2/include/asm-i386/mmzone.h --- pgcl-2.5.70-bk6-1/include/asm-i386/mmzone.h 2003-06-02 00:22:36.000000000 -0700 +++ pgcl-2.5.70-bk6-2/include/asm-i386/mmzone.h 2003-06-02 02:16:26.000000000 -0700 @@ -11,6 +11,7 @@ #ifdef CONFIG_DISCONTIGMEM extern struct pglist_data *node_data[]; +extern unsigned long node_start_pfn[], node_end_pfn[]; /* * Following are macros that are specific to this numa platform.