blob: d612cc3eec6a311e77cfa9a9659fe26308c6a7e6 [file] [log] [blame]
Heiko Carstens23d17422008-07-14 09:59:21 +02001/*
Hans-Joachim Picht155af2f2009-06-16 10:30:52 +02002 * Copyright IBM Corp. 2008, 2009
3 *
4 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
Heiko Carstens23d17422008-07-14 09:59:21 +02005 */
6
7#include <linux/kernel.h>
8#include <linux/module.h>
Philipp Hachtmann50be6342014-01-29 18:16:01 +01009#include <linux/memblock.h>
10#include <linux/init.h>
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
Heiko Carstens23d17422008-07-14 09:59:21 +020013#include <asm/ipl.h>
14#include <asm/sclp.h>
15#include <asm/setup.h>
16
Philipp Hachtmann50be6342014-01-29 18:16:01 +010017#define CHUNK_READ_WRITE 0
18#define CHUNK_READ_ONLY 1
19
20static inline void memblock_physmem_add(phys_addr_t start, phys_addr_t size)
21{
22 memblock_add_range(&memblock.memory, start, size, 0, 0);
23 memblock_add_range(&memblock.physmem, start, size, 0, 0);
24}
25
26void __init detect_memory_memblock(void)
Heiko Carstens23d17422008-07-14 09:59:21 +020027{
Heiko Carstens423d5b32015-12-31 10:07:21 +010028 unsigned long memsize, rnmax, rzm, addr, size;
Philipp Hachtmann50be6342014-01-29 18:16:01 +010029 int type;
Heiko Carstens23d17422008-07-14 09:59:21 +020030
David Hildenbrand37c5f6c2015-05-06 13:18:59 +020031 rzm = sclp.rzm;
32 rnmax = sclp.rnmax;
Heiko Carstens23d17422008-07-14 09:59:21 +020033 memsize = rzm * rnmax;
34 if (!rzm)
Heiko Carstens423d5b32015-12-31 10:07:21 +010035 rzm = 1UL << 17;
Philipp Hachtmann50be6342014-01-29 18:16:01 +010036 max_physmem_end = memsize;
37 addr = 0;
38 /* keep memblock lists close to the kernel */
39 memblock_set_bottom_up(true);
Heiko Carstens23d17422008-07-14 09:59:21 +020040 do {
41 size = 0;
42 type = tprot(addr);
43 do {
44 size += rzm;
Philipp Hachtmann50be6342014-01-29 18:16:01 +010045 if (max_physmem_end && addr + size >= max_physmem_end)
Heiko Carstens23d17422008-07-14 09:59:21 +020046 break;
47 } while (type == tprot(addr + size));
48 if (type == CHUNK_READ_WRITE || type == CHUNK_READ_ONLY) {
Philipp Hachtmann50be6342014-01-29 18:16:01 +010049 if (max_physmem_end && (addr + size > max_physmem_end))
50 size = max_physmem_end - addr;
51 memblock_physmem_add(addr, size);
Heiko Carstens23d17422008-07-14 09:59:21 +020052 }
53 addr += size;
Philipp Hachtmann50be6342014-01-29 18:16:01 +010054 } while (addr < max_physmem_end);
55 memblock_set_bottom_up(false);
56 if (!max_physmem_end)
57 max_physmem_end = memblock_end_of_DRAM();
Michael Holzheu60a0c682011-10-30 15:16:40 +010058}