1 /* SPDX-License-Identifier: GPL-2.0-or-later */
3 * drmem.h: Power specific logical memory block representation
5 * Copyright 2017 IBM Corporation
8 #ifndef _ASM_POWERPC_LMB_H
9 #define _ASM_POWERPC_LMB_H
11 #include <linux/sched.h>
20 struct drmem_lmb_info
{
21 struct drmem_lmb
*lmbs
;
29 extern struct drmem_lmb_info
*drmem_info
;
31 static inline struct drmem_lmb
*drmem_lmb_next(struct drmem_lmb
*lmb
,
32 const struct drmem_lmb
*start
)
35 * DLPAR code paths can take several milliseconds per element
36 * when interacting with firmware. Ensure that we don't
37 * unfairly monopolize the CPU.
39 if (((++lmb
- start
) % 16) == 0)
45 #define for_each_drmem_lmb_in_range(lmb, start, end) \
46 for ((lmb) = (start); (lmb) < (end); lmb = drmem_lmb_next(lmb, start))
48 #define for_each_drmem_lmb(lmb) \
49 for_each_drmem_lmb_in_range((lmb), \
50 &drmem_info->lmbs[0], \
51 &drmem_info->lmbs[drmem_info->n_lmbs])
54 * The of_drconf_cell_v1 struct defines the layout of the LMB data
55 * specified in the ibm,dynamic-memory device tree property.
56 * The property itself is a 32-bit value specifying the number of
57 * LMBs followed by an array of of_drconf_cell_v1 entries, one
60 struct of_drconf_cell_v1
{
69 * Version 2 of the ibm,dynamic-memory property is defined as a
70 * 32-bit value specifying the number of LMB sets followed by an
71 * array of of_drconf_cell_v2 entries, one per LMB set.
73 struct of_drconf_cell_v2
{
81 #define DRCONF_MEM_ASSIGNED 0x00000008
82 #define DRCONF_MEM_AI_INVALID 0x00000040
83 #define DRCONF_MEM_RESERVED 0x00000080
84 #define DRCONF_MEM_HOTREMOVABLE 0x00000100
86 static inline u64
drmem_lmb_size(void)
88 return drmem_info
->lmb_size
;
91 #define DRMEM_LMB_RESERVED 0x80000000
93 static inline void drmem_mark_lmb_reserved(struct drmem_lmb
*lmb
)
95 lmb
->flags
|= DRMEM_LMB_RESERVED
;
98 static inline void drmem_remove_lmb_reservation(struct drmem_lmb
*lmb
)
100 lmb
->flags
&= ~DRMEM_LMB_RESERVED
;
103 static inline bool drmem_lmb_reserved(struct drmem_lmb
*lmb
)
105 return lmb
->flags
& DRMEM_LMB_RESERVED
;
108 u64
drmem_lmb_memory_max(void);
109 int walk_drmem_lmbs(struct device_node
*dn
, void *data
,
110 int (*func
)(struct drmem_lmb
*, const __be32
**, void *));
111 int drmem_update_dt(void);
113 #ifdef CONFIG_PPC_PSERIES
115 walk_drmem_lmbs_early(unsigned long node
, void *data
,
116 int (*func
)(struct drmem_lmb
*, const __be32
**, void *));
117 void drmem_update_lmbs(struct property
*prop
);
120 static inline void invalidate_lmb_associativity_index(struct drmem_lmb
*lmb
)
122 lmb
->aa_index
= 0xffffffff;
125 #endif /* _ASM_POWERPC_LMB_H */