2 * Copyright IBM Corp. 2008
3 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
6 #include <linux/kernel.h>
7 #include <linux/module.h>
10 #include <asm/setup.h>
12 static inline int tprot(unsigned long addr
)
22 : "+d" (rc
) : "a" (addr
) : "cc");
26 #define ADDR2G (1ULL << 31)
28 static void find_memory_chunks(struct mem_chunk chunk
[])
30 unsigned long long memsize
, rnmax
, rzm
;
31 unsigned long addr
= 0, size
;
35 rnmax
= sclp_get_rnmax();
36 memsize
= rzm
* rnmax
;
39 if (sizeof(long) == 4) {
40 rzm
= min(ADDR2G
, rzm
);
41 memsize
= memsize
? min(ADDR2G
, memsize
) : ADDR2G
;
48 if (memsize
&& addr
+ size
>= memsize
)
50 } while (type
== tprot(addr
+ size
));
51 if (type
== CHUNK_READ_WRITE
|| type
== CHUNK_READ_ONLY
) {
58 } while (addr
< memsize
&& i
< MEMORY_CHUNKS
);
61 void detect_memory_layout(struct mem_chunk chunk
[])
63 unsigned long flags
, cr0
;
65 memset(chunk
, 0, MEMORY_CHUNKS
* sizeof(struct mem_chunk
));
66 /* Disable IRQs, DAT and low address protection so tprot does the
67 * right thing and we don't get scheduled away with low address
68 * protection disabled.
70 flags
= __raw_local_irq_stnsm(0xf8);
71 __ctl_store(cr0
, 0, 0);
72 __ctl_clear_bit(0, 28);
73 find_memory_chunks(chunk
);
74 __ctl_load(cr0
, 0, 0);
75 __raw_local_irq_ssm(flags
);
77 EXPORT_SYMBOL(detect_memory_layout
);