1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_S390_MEM_DETECT_H
3 #define _ASM_S390_MEM_DETECT_H
5 #include <linux/types.h>
9 MEM_DETECT_SCLP_STOR_INFO
,
11 MEM_DETECT_SCLP_READ_INFO
,
15 struct mem_detect_block
{
21 * Storage element id is defined as 1 byte (up to 256 storage elements).
22 * In practise only storage element id 0 and 1 are used).
23 * According to architecture one storage element could have as much as
24 * 1020 subincrements. 255 mem_detect_blocks are embedded in mem_detect_info.
25 * If more mem_detect_blocks are required, a block of memory from already
26 * known mem_detect_block is taken (entries_extended points to it).
28 #define MEM_INLINED_ENTRIES 255 /* (PAGE_SIZE - 16) / 16 */
30 struct mem_detect_info
{
33 struct mem_detect_block entries
[MEM_INLINED_ENTRIES
];
34 struct mem_detect_block
*entries_extended
;
36 extern struct mem_detect_info mem_detect
;
38 void add_mem_detect_block(u64 start
, u64 end
);
40 static inline int __get_mem_detect_block(u32 n
, unsigned long *start
,
43 if (n
>= mem_detect
.count
) {
49 if (n
< MEM_INLINED_ENTRIES
) {
50 *start
= (unsigned long)mem_detect
.entries
[n
].start
;
51 *end
= (unsigned long)mem_detect
.entries
[n
].end
;
53 *start
= (unsigned long)mem_detect
.entries_extended
[n
- MEM_INLINED_ENTRIES
].start
;
54 *end
= (unsigned long)mem_detect
.entries_extended
[n
- MEM_INLINED_ENTRIES
].end
;
60 * for_each_mem_detect_block - early online memory range iterator
61 * @i: an integer used as loop variable
62 * @p_start: ptr to unsigned long for start address of the range
63 * @p_end: ptr to unsigned long for end address of the range
65 * Walks over detected online memory ranges.
67 #define for_each_mem_detect_block(i, p_start, p_end) \
68 for (i = 0, __get_mem_detect_block(i, p_start, p_end); \
69 i < mem_detect.count; \
70 i++, __get_mem_detect_block(i, p_start, p_end))
72 static inline void get_mem_detect_reserved(unsigned long *start
,
75 *start
= (unsigned long)mem_detect
.entries_extended
;
76 if (mem_detect
.count
> MEM_INLINED_ENTRIES
)
77 *size
= (mem_detect
.count
- MEM_INLINED_ENTRIES
) * sizeof(struct mem_detect_block
);
82 static inline unsigned long get_mem_detect_end(void)
87 if (mem_detect
.count
) {
88 __get_mem_detect_block(mem_detect
.count
- 1, &start
, &end
);