diff options
author | David S. Miller <davem@davemloft.net> | 2008-05-02 01:28:17 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-05-02 08:22:53 -0400 |
commit | 9f2b2a5f68c27c00f1e1f1922de5aa2f24505ed8 (patch) | |
tree | 2afd44efe02154ab1bfcbd47e1d8ba55167da4e5 | |
parent | ccc34028d46230f715eeda4c8cce27e919934fad (diff) |
sparc32: More memory probing consolidation.
The PROM library function prom_meminit() builds a table,
prom_phys_avail[], just so that probe_memory() in
arch/sparc/mm/fault.c can copy it into sp_banks[].
Just have prom_meminit() fill in the sp_banks[] array directly, and
remove duplicated sort() function.
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | arch/sparc/kernel/setup.c | 5 | ||||
-rw-r--r-- | arch/sparc/mm/fault.c | 61 | ||||
-rw-r--r-- | arch/sparc/prom/memory.c | 144 | ||||
-rw-r--r-- | include/asm-sparc/oplib.h | 7 | ||||
-rw-r--r-- | include/asm-sparc/page.h | 5 |
5 files changed, 71 insertions, 151 deletions
diff --git a/arch/sparc/kernel/setup.c b/arch/sparc/kernel/setup.c index 3c13137685da..8a55c4f0df84 100644 --- a/arch/sparc/kernel/setup.c +++ b/arch/sparc/kernel/setup.c | |||
@@ -180,11 +180,9 @@ static void __init boot_flags_init(char *commands) | |||
180 | 180 | ||
181 | /* This routine will in the future do all the nasty prom stuff | 181 | /* This routine will in the future do all the nasty prom stuff |
182 | * to probe for the mmu type and its parameters, etc. This will | 182 | * to probe for the mmu type and its parameters, etc. This will |
183 | * also be where SMP things happen plus the Sparc specific memory | 183 | * also be where SMP things happen. |
184 | * physical memory probe as on the alpha. | ||
185 | */ | 184 | */ |
186 | 185 | ||
187 | extern int prom_probe_memory(void); | ||
188 | extern void sun4c_probe_vac(void); | 186 | extern void sun4c_probe_vac(void); |
189 | extern char cputypval; | 187 | extern char cputypval; |
190 | extern unsigned long start, end; | 188 | extern unsigned long start, end; |
@@ -268,7 +266,6 @@ void __init setup_arch(char **cmdline_p) | |||
268 | if (ARCH_SUN4C_SUN4) | 266 | if (ARCH_SUN4C_SUN4) |
269 | sun4c_probe_vac(); | 267 | sun4c_probe_vac(); |
270 | load_mmu(); | 268 | load_mmu(); |
271 | (void) prom_probe_memory(); | ||
272 | 269 | ||
273 | phys_base = 0xffffffffUL; | 270 | phys_base = 0xffffffffUL; |
274 | highest_paddr = 0UL; | 271 | highest_paddr = 0UL; |
diff --git a/arch/sparc/mm/fault.c b/arch/sparc/mm/fault.c index f25876a56fe6..abd50795a7b6 100644 --- a/arch/sparc/mm/fault.c +++ b/arch/sparc/mm/fault.c | |||
@@ -47,64 +47,15 @@ int vac_size, vac_linesize, vac_do_hw_vac_flushes; | |||
47 | int vac_entries_per_context, vac_entries_per_segment; | 47 | int vac_entries_per_context, vac_entries_per_segment; |
48 | int vac_entries_per_page; | 48 | int vac_entries_per_page; |
49 | 49 | ||
50 | /* Nice, simple, prom library does all the sweating for us. ;) */ | 50 | /* Return how much physical memory we have. */ |
51 | int prom_probe_memory (void) | 51 | unsigned long probe_memory(void) |
52 | { | 52 | { |
53 | register struct linux_mlist_v0 *mlist; | 53 | unsigned long total = 0; |
54 | register unsigned long bytes, base_paddr, tally; | 54 | int i; |
55 | register int i; | ||
56 | |||
57 | i = 0; | ||
58 | mlist= prom_meminfo(); | ||
59 | bytes = tally = mlist->num_bytes; | ||
60 | base_paddr = (unsigned long) mlist->start_adr; | ||
61 | |||
62 | sp_banks[0].base_addr = base_paddr; | ||
63 | sp_banks[0].num_bytes = bytes; | ||
64 | |||
65 | while (mlist->theres_more != (void *) 0){ | ||
66 | i++; | ||
67 | mlist = mlist->theres_more; | ||
68 | bytes = mlist->num_bytes; | ||
69 | tally += bytes; | ||
70 | if (i > SPARC_PHYS_BANKS-1) { | ||
71 | printk ("The machine has more banks than " | ||
72 | "this kernel can support\n" | ||
73 | "Increase the SPARC_PHYS_BANKS " | ||
74 | "setting (currently %d)\n", | ||
75 | SPARC_PHYS_BANKS); | ||
76 | i = SPARC_PHYS_BANKS-1; | ||
77 | break; | ||
78 | } | ||
79 | |||
80 | sp_banks[i].base_addr = (unsigned long) mlist->start_adr; | ||
81 | sp_banks[i].num_bytes = mlist->num_bytes; | ||
82 | } | ||
83 | |||
84 | i++; | ||
85 | sp_banks[i].base_addr = 0xdeadbeef; | ||
86 | sp_banks[i].num_bytes = 0; | ||
87 | |||
88 | /* Now mask all bank sizes on a page boundary, it is all we can | ||
89 | * use anyways. | ||
90 | */ | ||
91 | for(i=0; sp_banks[i].num_bytes != 0; i++) | ||
92 | sp_banks[i].num_bytes &= PAGE_MASK; | ||
93 | |||
94 | return tally; | ||
95 | } | ||
96 | |||
97 | /* Traverse the memory lists in the prom to see how much physical we | ||
98 | * have. | ||
99 | */ | ||
100 | unsigned long | ||
101 | probe_memory(void) | ||
102 | { | ||
103 | int total; | ||
104 | 55 | ||
105 | total = prom_probe_memory(); | 56 | for (i = 0; sp_banks[i].num_bytes; i++) |
57 | total += sp_banks[i].num_bytes; | ||
106 | 58 | ||
107 | /* Oh man, much nicer, keep the dirt in promlib. */ | ||
108 | return total; | 59 | return total; |
109 | } | 60 | } |
110 | 61 | ||
diff --git a/arch/sparc/prom/memory.c b/arch/sparc/prom/memory.c index 08ac1bf2e588..947f047dc95a 100644 --- a/arch/sparc/prom/memory.c +++ b/arch/sparc/prom/memory.c | |||
@@ -1,120 +1,100 @@ | |||
1 | /* memory.c: Prom routine for acquiring various bits of information | 1 | /* memory.c: Prom routine for acquiring various bits of information |
2 | * about RAM on the machine, both virtual and physical. | 2 | * about RAM on the machine, both virtual and physical. |
3 | * | 3 | * |
4 | * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu) | 4 | * Copyright (C) 1995, 2008 David S. Miller (davem@davemloft.net) |
5 | * Copyright (C) 1997 Michael A. Griffith (grif@acm.org) | 5 | * Copyright (C) 1997 Michael A. Griffith (grif@acm.org) |
6 | */ | 6 | */ |
7 | 7 | ||
8 | #include <linux/kernel.h> | 8 | #include <linux/kernel.h> |
9 | #include <linux/sort.h> | ||
9 | #include <linux/init.h> | 10 | #include <linux/init.h> |
10 | 11 | ||
11 | #include <asm/openprom.h> | 12 | #include <asm/openprom.h> |
12 | #include <asm/sun4prom.h> | 13 | #include <asm/sun4prom.h> |
13 | #include <asm/oplib.h> | 14 | #include <asm/oplib.h> |
15 | #include <asm/page.h> | ||
14 | 16 | ||
15 | /* This routine, for consistency, returns the ram parameters in the | 17 | static int __init prom_meminit_v0(void) |
16 | * V0 prom memory descriptor format. I choose this format because I | 18 | { |
17 | * think it was the easiest to work with. I feel the religious | 19 | struct linux_mlist_v0 *p; |
18 | * arguments now... ;) Also, I return the linked lists sorted to | 20 | int index; |
19 | * prevent paging_init() upset stomach as I have not yet written | ||
20 | * the pepto-bismol kernel module yet. | ||
21 | */ | ||
22 | 21 | ||
23 | struct linux_prom_registers prom_reg_memlist[64]; | 22 | index = 0; |
23 | for (p = *(romvec->pv_v0mem.v0_available); p; p = p->theres_more) { | ||
24 | sp_banks[index].base_addr = (unsigned long) p->start_adr; | ||
25 | sp_banks[index].num_bytes = p->num_bytes; | ||
26 | index++; | ||
27 | } | ||
24 | 28 | ||
25 | struct linux_mlist_v0 prom_phys_avail[64]; | 29 | return index; |
30 | } | ||
26 | 31 | ||
27 | /* Internal Prom library routine to sort a linux_mlist_v0 memory | 32 | static int __init prom_meminit_v2(void) |
28 | * list. Used below in initialization. | ||
29 | */ | ||
30 | static void __init | ||
31 | prom_sortmemlist(struct linux_mlist_v0 *thislist) | ||
32 | { | 33 | { |
33 | int swapi = 0; | 34 | struct linux_prom_registers reg[64]; |
34 | int i, mitr, tmpsize; | 35 | int node, size, num_ents, i; |
35 | char *tmpaddr; | 36 | |
36 | char *lowest; | 37 | node = prom_searchsiblings(prom_getchild(prom_root_node), "memory"); |
37 | 38 | size = prom_getproperty(node, "available", (char *) reg, sizeof(reg)); | |
38 | for(i=0; thislist[i].theres_more; i++) { | 39 | num_ents = size / sizeof(struct linux_prom_registers); |
39 | lowest = thislist[i].start_adr; | 40 | |
40 | for(mitr = i+1; thislist[mitr-1].theres_more; mitr++) | 41 | for (i = 0; i < num_ents; i++) { |
41 | if(thislist[mitr].start_adr < lowest) { | 42 | sp_banks[i].base_addr = reg[i].phys_addr; |
42 | lowest = thislist[mitr].start_adr; | 43 | sp_banks[i].num_bytes = reg[i].reg_size; |
43 | swapi = mitr; | ||
44 | } | ||
45 | if(lowest == thislist[i].start_adr) continue; | ||
46 | tmpaddr = thislist[swapi].start_adr; | ||
47 | tmpsize = thislist[swapi].num_bytes; | ||
48 | for(mitr = swapi; mitr > i; mitr--) { | ||
49 | thislist[mitr].start_adr = thislist[mitr-1].start_adr; | ||
50 | thislist[mitr].num_bytes = thislist[mitr-1].num_bytes; | ||
51 | } | ||
52 | thislist[i].start_adr = tmpaddr; | ||
53 | thislist[i].num_bytes = tmpsize; | ||
54 | } | 44 | } |
55 | 45 | ||
56 | return; | 46 | return num_ents; |
47 | } | ||
48 | |||
49 | static int __init prom_meminit_sun4(void) | ||
50 | { | ||
51 | #ifdef CONFIG_SUN4 | ||
52 | sp_banks[0].base_addr = 0; | ||
53 | sp_banks[0].num_bytes = *(sun4_romvec->memoryavail); | ||
54 | #endif | ||
55 | return 1; | ||
56 | } | ||
57 | |||
58 | static int sp_banks_cmp(const void *a, const void *b) | ||
59 | { | ||
60 | const struct sparc_phys_banks *x = a, *y = b; | ||
61 | |||
62 | if (x->base_addr > y->base_addr) | ||
63 | return 1; | ||
64 | if (x->base_addr < y->base_addr) | ||
65 | return -1; | ||
66 | return 0; | ||
57 | } | 67 | } |
58 | 68 | ||
59 | /* Initialize the memory lists based upon the prom version. */ | 69 | /* Initialize the memory lists based upon the prom version. */ |
60 | void __init prom_meminit(void) | 70 | void __init prom_meminit(void) |
61 | { | 71 | { |
62 | int node = 0; | 72 | int i, num_ents = 0; |
63 | unsigned int iter, num_regs; | ||
64 | struct linux_mlist_v0 *mptr; /* ptr for traversal */ | ||
65 | 73 | ||
66 | switch(prom_vers) { | 74 | switch (prom_vers) { |
67 | case PROM_V0: | 75 | case PROM_V0: |
68 | /* Nice, kind of easier to do in this case. */ | 76 | num_ents = prom_meminit_v0(); |
69 | for(mptr = (*(romvec->pv_v0mem.v0_available)), iter=0; | ||
70 | mptr; mptr=mptr->theres_more, iter++) { | ||
71 | prom_phys_avail[iter].start_adr = mptr->start_adr; | ||
72 | prom_phys_avail[iter].num_bytes = mptr->num_bytes; | ||
73 | prom_phys_avail[iter].theres_more = &prom_phys_avail[iter+1]; | ||
74 | } | ||
75 | prom_phys_avail[iter-1].theres_more = NULL; | ||
76 | prom_sortmemlist(prom_phys_avail); | ||
77 | break; | 77 | break; |
78 | |||
78 | case PROM_V2: | 79 | case PROM_V2: |
79 | case PROM_V3: | 80 | case PROM_V3: |
80 | /* Grrr, have to traverse the prom device tree ;( */ | 81 | num_ents = prom_meminit_v2(); |
81 | node = prom_getchild(prom_root_node); | ||
82 | node = prom_searchsiblings(node, "memory"); | ||
83 | num_regs = prom_getproperty(node, "available", | ||
84 | (char *) prom_reg_memlist, | ||
85 | sizeof(prom_reg_memlist)); | ||
86 | num_regs = (num_regs/sizeof(struct linux_prom_registers)); | ||
87 | for(iter=0; iter<num_regs; iter++) { | ||
88 | prom_phys_avail[iter].start_adr = | ||
89 | (char *) prom_reg_memlist[iter].phys_addr; | ||
90 | prom_phys_avail[iter].num_bytes = | ||
91 | (unsigned long) prom_reg_memlist[iter].reg_size; | ||
92 | prom_phys_avail[iter].theres_more = | ||
93 | &prom_phys_avail[iter+1]; | ||
94 | } | ||
95 | prom_phys_avail[iter-1].theres_more = NULL; | ||
96 | prom_sortmemlist(prom_phys_avail); | ||
97 | break; | 82 | break; |
98 | 83 | ||
99 | case PROM_SUN4: | 84 | case PROM_SUN4: |
100 | #ifdef CONFIG_SUN4 | 85 | num_ents = prom_meminit_sun4(); |
101 | /* how simple :) */ | ||
102 | prom_phys_avail[0].start_adr = NULL; | ||
103 | prom_phys_avail[0].num_bytes = *(sun4_romvec->memoryavail); | ||
104 | prom_phys_avail[0].theres_more = NULL; | ||
105 | #endif | ||
106 | break; | 86 | break; |
107 | 87 | ||
108 | default: | 88 | default: |
109 | break; | 89 | break; |
110 | }; | 90 | } |
111 | } | 91 | sort(sp_banks, num_ents, sizeof(struct sparc_phys_banks), |
92 | sp_banks_cmp, NULL); | ||
112 | 93 | ||
113 | /* This returns a pointer to our libraries internal v0 format | 94 | /* Sentinel. */ |
114 | * available memory list. | 95 | sp_banks[num_ents].base_addr = 0xdeadbeef; |
115 | */ | 96 | sp_banks[num_ents].num_bytes = 0; |
116 | struct linux_mlist_v0 * | 97 | |
117 | prom_meminfo(void) | 98 | for (i = 0; i < num_ents; i++) |
118 | { | 99 | sp_banks[i].num_bytes &= PAGE_MASK; |
119 | return prom_phys_avail; | ||
120 | } | 100 | } |
diff --git a/include/asm-sparc/oplib.h b/include/asm-sparc/oplib.h index 6ff1a3bb15bc..22dc39d97b4e 100644 --- a/include/asm-sparc/oplib.h +++ b/include/asm-sparc/oplib.h | |||
@@ -84,13 +84,6 @@ extern int prom_devclose(int device_handle); | |||
84 | extern void prom_seek(int device_handle, unsigned int seek_hival, | 84 | extern void prom_seek(int device_handle, unsigned int seek_hival, |
85 | unsigned int seek_lowval); | 85 | unsigned int seek_lowval); |
86 | 86 | ||
87 | /* Machine memory configuration routine. */ | ||
88 | |||
89 | /* This function returns a V0 format available memory descriptor entry. | ||
90 | * This list is pre-sorted, | ||
91 | */ | ||
92 | extern struct linux_mlist_v0 *prom_meminfo(void); | ||
93 | |||
94 | /* Miscellaneous routines, don't really fit in any category per se. */ | 87 | /* Miscellaneous routines, don't really fit in any category per se. */ |
95 | 88 | ||
96 | /* Reboot the machine with the command line passed. */ | 89 | /* Reboot the machine with the command line passed. */ |
diff --git a/include/asm-sparc/page.h b/include/asm-sparc/page.h index 39ccf2da297c..1625a8c3e0d2 100644 --- a/include/asm-sparc/page.h +++ b/include/asm-sparc/page.h | |||
@@ -38,12 +38,11 @@ | |||
38 | 38 | ||
39 | /* The following structure is used to hold the physical | 39 | /* The following structure is used to hold the physical |
40 | * memory configuration of the machine. This is filled in | 40 | * memory configuration of the machine. This is filled in |
41 | * probe_memory() and is later used by mem_init() to set up | 41 | * prom_meminit() and is later used by mem_init() to set up |
42 | * mem_map[]. We statically allocate SPARC_PHYS_BANKS of | 42 | * mem_map[]. We statically allocate SPARC_PHYS_BANKS+1 of |
43 | * these structs, this is arbitrary. The entry after the | 43 | * these structs, this is arbitrary. The entry after the |
44 | * last valid one has num_bytes==0. | 44 | * last valid one has num_bytes==0. |
45 | */ | 45 | */ |
46 | |||
47 | struct sparc_phys_banks { | 46 | struct sparc_phys_banks { |
48 | unsigned long base_addr; | 47 | unsigned long base_addr; |
49 | unsigned long num_bytes; | 48 | unsigned long num_bytes; |