aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/memblock.h
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2010-08-03 23:40:38 -0400
committerBenjamin Herrenschmidt <benh@kernel.crashing.org>2010-08-04 00:38:57 -0400
commit5b385f259fa4d356452e3b4729cbaf5213f4f55b (patch)
tree17bfa3a22d367eb80b4720275579407917a70f4b /include/linux/memblock.h
parentdbe3039e64b1dd4cf26f782d45b524f85b444ad4 (diff)
memblock: Introduce for_each_memblock() and new accessors
Walk memblock's using for_each_memblock() and use memblock_region_base/end_pfn() for getting to PFNs. Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Diffstat (limited to 'include/linux/memblock.h')
-rw-r--r--include/linux/memblock.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/linux/memblock.h b/include/linux/memblock.h
index 47bceb187058..c914112cd24f 100644
--- a/include/linux/memblock.h
+++ b/include/linux/memblock.h
@@ -64,6 +64,7 @@ extern int memblock_find(struct memblock_region *res);
64 64
65extern void memblock_dump_all(void); 65extern void memblock_dump_all(void);
66 66
67/* Obsolete accessors */
67static inline u64 68static inline u64
68memblock_size_bytes(struct memblock_type *type, unsigned long region_nr) 69memblock_size_bytes(struct memblock_type *type, unsigned long region_nr)
69{ 70{
@@ -86,6 +87,57 @@ memblock_end_pfn(struct memblock_type *type, unsigned long region_nr)
86 memblock_size_pages(type, region_nr); 87 memblock_size_pages(type, region_nr);
87} 88}
88 89
90/*
91 * pfn conversion functions
92 *
93 * While the memory MEMBLOCKs should always be page aligned, the reserved
94 * MEMBLOCKs may not be. This accessor attempt to provide a very clear
95 * idea of what they return for such non aligned MEMBLOCKs.
96 */
97
98/**
99 * memblock_region_base_pfn - Return the lowest pfn intersecting with the region
100 * @reg: memblock_region structure
101 */
102static inline unsigned long memblock_region_base_pfn(const struct memblock_region *reg)
103{
104 return reg->base >> PAGE_SHIFT;
105}
106
107/**
108 * memblock_region_last_pfn - Return the highest pfn intersecting with the region
109 * @reg: memblock_region structure
110 */
111static inline unsigned long memblock_region_last_pfn(const struct memblock_region *reg)
112{
113 return (reg->base + reg->size - 1) >> PAGE_SHIFT;
114}
115
116/**
117 * memblock_region_end_pfn - Return the pfn of the first page following the region
118 * but not intersecting it
119 * @reg: memblock_region structure
120 */
121static inline unsigned long memblock_region_end_pfn(const struct memblock_region *reg)
122{
123 return memblock_region_last_pfn(reg) + 1;
124}
125
126/**
127 * memblock_region_pages - Return the number of pages covering a region
128 * @reg: memblock_region structure
129 */
130static inline unsigned long memblock_region_pages(const struct memblock_region *reg)
131{
132 return memblock_region_end_pfn(reg) - memblock_region_end_pfn(reg);
133}
134
135#define for_each_memblock(memblock_type, region) \
136 for (region = memblock.memblock_type.regions; \
137 region < (memblock.memblock_type.regions + memblock.memblock_type.cnt); \
138 region++)
139
140
89#endif /* __KERNEL__ */ 141#endif /* __KERNEL__ */
90 142
91#endif /* _LINUX_MEMBLOCK_H */ 143#endif /* _LINUX_MEMBLOCK_H */