Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 1 | /* |
Hans-Joachim Picht | 155af2f | 2009-06-16 10:30:52 +0200 | [diff] [blame] | 2 | * Copyright IBM Corp. 2008, 2009 |
| 3 | * |
| 4 | * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com> |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <linux/kernel.h> |
| 8 | #include <linux/module.h> |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 9 | #include <linux/memblock.h> |
| 10 | #include <linux/init.h> |
| 11 | #include <linux/debugfs.h> |
| 12 | #include <linux/seq_file.h> |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 13 | #include <asm/ipl.h> |
| 14 | #include <asm/sclp.h> |
| 15 | #include <asm/setup.h> |
| 16 | |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 17 | #define ADDR2G (1ULL << 31) |
| 18 | |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 19 | #define CHUNK_READ_WRITE 0 |
| 20 | #define CHUNK_READ_ONLY 1 |
| 21 | |
| 22 | static inline void memblock_physmem_add(phys_addr_t start, phys_addr_t size) |
| 23 | { |
| 24 | memblock_add_range(&memblock.memory, start, size, 0, 0); |
| 25 | memblock_add_range(&memblock.physmem, start, size, 0, 0); |
| 26 | } |
| 27 | |
| 28 | void __init detect_memory_memblock(void) |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 29 | { |
| 30 | unsigned long long memsize, rnmax, rzm; |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 31 | unsigned long addr, size; |
| 32 | int type; |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 33 | |
David Hildenbrand | 37c5f6c | 2015-05-06 13:18:59 +0200 | [diff] [blame] | 34 | rzm = sclp.rzm; |
| 35 | rnmax = sclp.rnmax; |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 36 | memsize = rzm * rnmax; |
| 37 | if (!rzm) |
| 38 | rzm = 1ULL << 17; |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 39 | max_physmem_end = memsize; |
| 40 | addr = 0; |
| 41 | /* keep memblock lists close to the kernel */ |
| 42 | memblock_set_bottom_up(true); |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 43 | do { |
| 44 | size = 0; |
| 45 | type = tprot(addr); |
| 46 | do { |
| 47 | size += rzm; |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 48 | if (max_physmem_end && addr + size >= max_physmem_end) |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 49 | break; |
| 50 | } while (type == tprot(addr + size)); |
| 51 | if (type == CHUNK_READ_WRITE || type == CHUNK_READ_ONLY) { |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 52 | if (max_physmem_end && (addr + size > max_physmem_end)) |
| 53 | size = max_physmem_end - addr; |
| 54 | memblock_physmem_add(addr, size); |
Heiko Carstens | 23d1742 | 2008-07-14 09:59:21 +0200 | [diff] [blame] | 55 | } |
| 56 | addr += size; |
Philipp Hachtmann | 50be634 | 2014-01-29 18:16:01 +0100 | [diff] [blame] | 57 | } while (addr < max_physmem_end); |
| 58 | memblock_set_bottom_up(false); |
| 59 | if (!max_physmem_end) |
| 60 | max_physmem_end = memblock_end_of_DRAM(); |
Michael Holzheu | 60a0c68 | 2011-10-30 15:16:40 +0100 | [diff] [blame] | 61 | } |