2 * Copyright IBM Corp. 2008, 2009
4 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
7 #include <linux/kernel.h>
8 #include <linux/module.h>
11 #include <asm/setup.h>
13 #define ADDR2G (1ULL << 31)
15 static void find_memory_chunks(struct mem_chunk chunk
[])
17 unsigned long long memsize
, rnmax
, rzm
;
18 unsigned long addr
= 0, size
;
22 rnmax
= sclp_get_rnmax();
23 memsize
= rzm
* rnmax
;
26 if (sizeof(long) == 4) {
27 rzm
= min(ADDR2G
, rzm
);
28 memsize
= memsize
? min(ADDR2G
, memsize
) : ADDR2G
;
35 if (memsize
&& addr
+ size
>= memsize
)
37 } while (type
== tprot(addr
+ size
));
38 if (type
== CHUNK_READ_WRITE
|| type
== CHUNK_READ_ONLY
) {
45 } while (addr
< memsize
&& i
< MEMORY_CHUNKS
);
48 void detect_memory_layout(struct mem_chunk chunk
[])
50 unsigned long flags
, cr0
;
52 memset(chunk
, 0, MEMORY_CHUNKS
* sizeof(struct mem_chunk
));
53 /* Disable IRQs, DAT and low address protection so tprot does the
54 * right thing and we don't get scheduled away with low address
55 * protection disabled.
57 flags
= __arch_local_irq_stnsm(0xf8);
58 __ctl_store(cr0
, 0, 0);
59 __ctl_clear_bit(0, 28);
60 find_memory_chunks(chunk
);
61 __ctl_load(cr0
, 0, 0);
62 arch_local_irq_restore(flags
);
64 EXPORT_SYMBOL(detect_memory_layout
);