WIP FPC-III support
[linux/fpc-iii.git] / arch / s390 / include / asm / mem_detect.h
bloba7c922a690509a22d279c42de7e2b8312152ec9d
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>
7 enum mem_info_source {
8 MEM_DETECT_NONE = 0,
9 MEM_DETECT_SCLP_STOR_INFO,
10 MEM_DETECT_DIAG260,
11 MEM_DETECT_SCLP_READ_INFO,
12 MEM_DETECT_BIN_SEARCH
15 struct mem_detect_block {
16 u64 start;
17 u64 end;
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 {
31 u32 count;
32 u8 info_source;
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,
41 unsigned long *end)
43 if (n >= mem_detect.count) {
44 *start = 0;
45 *end = 0;
46 return -1;
49 if (n < MEM_INLINED_ENTRIES) {
50 *start = (unsigned long)mem_detect.entries[n].start;
51 *end = (unsigned long)mem_detect.entries[n].end;
52 } else {
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;
56 return 0;
59 /**
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,
73 unsigned long *size)
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);
78 else
79 *size = 0;
82 static inline unsigned long get_mem_detect_end(void)
84 unsigned long start;
85 unsigned long end;
87 if (mem_detect.count) {
88 __get_mem_detect_block(mem_detect.count - 1, &start, &end);
89 return end;
91 return 0;
94 #endif