1#ifndef _PPC64_LMB_H
2#define _PPC64_LMB_H
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <linux/config.h>
17#include <asm/prom.h>
18
19extern unsigned long reloc_offset(void);
20
21#define MAX_LMB_REGIONS 64
22
23union lmb_reg_property {
24 struct reg_property32 addr32[MAX_LMB_REGIONS];
25 struct reg_property64 addr64[MAX_LMB_REGIONS];
26};
27
28#define LMB_MEMORY_AREA 1
29#define LMB_IO_AREA 2
30
31#define LMB_ALLOC_ANYWHERE 0
32#define LMB_ALLOC_FIRST4GBYTE (1UL<<32)
33
34struct lmb_property {
35 unsigned long base;
36 unsigned long physbase;
37 unsigned long size;
38 unsigned long type;
39};
40
41struct lmb_region {
42 unsigned long cnt;
43 unsigned long size;
44 unsigned long iosize;
45 unsigned long lcd_size;
46 struct lmb_property region[MAX_LMB_REGIONS+1];
47};
48
49struct lmb {
50 unsigned long debug;
51 unsigned long rmo_size;
52 struct lmb_region memory;
53 struct lmb_region reserved;
54};
55
56extern struct lmb lmb;
57
58extern void lmb_init(void);
59extern void lmb_analyze(void);
60extern long lmb_add(unsigned long, unsigned long);
61#ifdef CONFIG_MSCHUNKS
62extern long lmb_add_io(unsigned long base, unsigned long size);
63#endif
64extern long lmb_reserve(unsigned long, unsigned long);
65extern unsigned long lmb_alloc(unsigned long, unsigned long);
66extern unsigned long lmb_alloc_base(unsigned long, unsigned long, unsigned long);
67extern unsigned long lmb_phys_mem_size(void);
68extern unsigned long lmb_end_of_DRAM(void);
69extern unsigned long lmb_abs_to_phys(unsigned long);
70extern void lmb_dump(char *);
71
72static inline unsigned long
73lmb_addrs_overlap(unsigned long base1, unsigned long size1,
74 unsigned long base2, unsigned long size2)
75{
76 return ((base1 < (base2+size2)) && (base2 < (base1+size1)));
77}
78
79static inline long
80lmb_regions_overlap(struct lmb_region *rgn, unsigned long r1, unsigned long r2)
81{
82 unsigned long base1 = rgn->region[r1].base;
83 unsigned long size1 = rgn->region[r1].size;
84 unsigned long base2 = rgn->region[r2].base;
85 unsigned long size2 = rgn->region[r2].size;
86
87 return lmb_addrs_overlap(base1,size1,base2,size2);
88}
89
90static inline long
91lmb_addrs_adjacent(unsigned long base1, unsigned long size1,
92 unsigned long base2, unsigned long size2)
93{
94 if ( base2 == base1 + size1 ) {
95 return 1;
96 } else if ( base1 == base2 + size2 ) {
97 return -1;
98 }
99 return 0;
100}
101
102static inline long
103lmb_regions_adjacent(struct lmb_region *rgn, unsigned long r1, unsigned long r2)
104{
105 unsigned long base1 = rgn->region[r1].base;
106 unsigned long size1 = rgn->region[r1].size;
107 unsigned long type1 = rgn->region[r1].type;
108 unsigned long base2 = rgn->region[r2].base;
109 unsigned long size2 = rgn->region[r2].size;
110 unsigned long type2 = rgn->region[r2].type;
111
112 return (type1 == type2) && lmb_addrs_adjacent(base1,size1,base2,size2);
113}
114
115#endif
116