Loading...
1/*
2 * Copyright IBM Corp. 2008, 2009
3 *
4 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
5 */
6
7#include <linux/kernel.h>
8#include <linux/module.h>
9#include <linux/memblock.h>
10#include <linux/init.h>
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
13#include <asm/ipl.h>
14#include <asm/sclp.h>
15#include <asm/setup.h>
16
17#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)
27{
28 unsigned long memsize, rnmax, rzm, addr, size;
29 int type;
30
31 rzm = sclp.rzm;
32 rnmax = sclp.rnmax;
33 memsize = rzm * rnmax;
34 if (!rzm)
35 rzm = 1UL << 17;
36 max_physmem_end = memsize;
37 addr = 0;
38 /* keep memblock lists close to the kernel */
39 memblock_set_bottom_up(true);
40 do {
41 size = 0;
42 type = tprot(addr);
43 do {
44 size += rzm;
45 if (max_physmem_end && addr + size >= max_physmem_end)
46 break;
47 } while (type == tprot(addr + size));
48 if (type == CHUNK_READ_WRITE || type == CHUNK_READ_ONLY) {
49 if (max_physmem_end && (addr + size > max_physmem_end))
50 size = max_physmem_end - addr;
51 memblock_physmem_add(addr, size);
52 }
53 addr += size;
54 } while (addr < max_physmem_end);
55 memblock_set_bottom_up(false);
56 if (!max_physmem_end)
57 max_physmem_end = memblock_end_of_DRAM();
58}
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright IBM Corp. 2008, 2009
4 *
5 * Author(s): Heiko Carstens <heiko.carstens@de.ibm.com>
6 */
7
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>
13#include <asm/ipl.h>
14#include <asm/sclp.h>
15#include <asm/setup.h>
16
17#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_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);
26}
27
28void __init detect_memory_memblock(void)
29{
30 unsigned long memsize, rnmax, rzm, addr, size;
31 int type;
32
33 rzm = sclp.rzm;
34 rnmax = sclp.rnmax;
35 memsize = rzm * rnmax;
36 if (!rzm)
37 rzm = 1UL << 17;
38 max_physmem_end = memsize;
39 addr = 0;
40 /* keep memblock lists close to the kernel */
41 memblock_set_bottom_up(true);
42 do {
43 size = 0;
44 /* assume lowcore is writable */
45 type = addr ? tprot(addr) : CHUNK_READ_WRITE;
46 do {
47 size += rzm;
48 if (max_physmem_end && addr + size >= max_physmem_end)
49 break;
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);
55 }
56 addr += size;
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();
61 memblock_dump_all();
62}