1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright IBM Corp. 2008, 2009
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
8 #include <linux/kernel.h>
9 #include <linux/memblock.h>
10 #include <linux/init.h>
11 #include <linux/debugfs.h>
12 #include <linux/seq_file.h>
15 #include <asm/setup.h>
17 #define CHUNK_READ_WRITE 0
18 #define CHUNK_READ_ONLY 1
20 static inline void memblock_physmem_add(phys_addr_t start
, phys_addr_t size
)
22 memblock_dbg("memblock_physmem_add: [%#016llx-%#016llx]\n",
23 start
, start
+ size
- 1);
24 memblock_add_range(&memblock
.memory
, start
, size
, 0, 0);
25 memblock_add_range(&memblock
.physmem
, start
, size
, 0, 0);
28 void __init
detect_memory_memblock(void)
30 unsigned long memsize
, rnmax
, rzm
, addr
, size
;
35 memsize
= rzm
* rnmax
;
38 max_physmem_end
= memsize
;
40 /* keep memblock lists close to the kernel */
41 memblock_set_bottom_up(true);
44 /* assume lowcore is writable */
45 type
= addr
? tprot(addr
) : CHUNK_READ_WRITE
;
48 if (max_physmem_end
&& addr
+ size
>= max_physmem_end
)
50 } while (type
== tprot(addr
+ size
));
51 if (type
== CHUNK_READ_WRITE
|| type
== CHUNK_READ_ONLY
) {
52 if (max_physmem_end
&& (addr
+ size
> max_physmem_end
))
53 size
= max_physmem_end
- addr
;
54 memblock_physmem_add(addr
, size
);
57 } while (addr
< max_physmem_end
);
58 memblock_set_bottom_up(false);
60 max_physmem_end
= memblock_end_of_DRAM();