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 /arch/sparc/prom | |
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>
Diffstat (limited to 'arch/sparc/prom')
-rw-r--r-- | arch/sparc/prom/memory.c | 144 |
1 files changed, 62 insertions, 82 deletions
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 | } |