1#ifndef _PPC64_LMB_H
2#define _PPC64_LMB_H
3
4/*
5 * Definitions for talking to the Open Firmware PROM on
6 * Power Macintosh computers.
7 *
8 * Copyright (C) 2001 Peter Bergner, IBM Corp.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
14 */
15
16#include <asm/prom.h>
17
18extern unsigned long reloc_offset(void);
19
20#define MAX_LMB_REGIONS 64
21
22union lmb_reg_property {
23	struct reg_property32 addr32[MAX_LMB_REGIONS];
24	struct reg_property64 addr64[MAX_LMB_REGIONS];
25};
26
27#define LMB_MEMORY_AREA	1
28#define LMB_IO_AREA	2
29
30#define LMB_ALLOC_ANYWHERE	0
31#define LMB_ALLOC_FIRST4GBYTE	(1UL<<32)
32
33struct lmb_property {
34	unsigned long base;
35	unsigned long physbase;
36	unsigned long size;
37	unsigned long type;
38};
39
40struct lmb_region {
41	unsigned long cnt;
42	unsigned long size;
43	unsigned long iosize;
44	unsigned long lcd_size;		/* Least Common Denominator */
45	struct lmb_property region[MAX_LMB_REGIONS+1];
46};
47
48struct lmb {
49	unsigned long debug;
50	unsigned long rmo_size;
51	struct lmb_region memory;
52	struct lmb_region reserved;
53};
54
55extern struct lmb lmb;
56
57extern void lmb_init(void);
58extern void lmb_analyze(void);
59extern long lmb_add(unsigned long, unsigned long);
60#ifdef CONFIG_MSCHUNKS
61extern long lmb_add_io(unsigned long base, unsigned long size);
62#endif /* CONFIG_MSCHUNKS */
63extern long lmb_reserve(unsigned long, unsigned long);
64extern unsigned long lmb_alloc(unsigned long, unsigned long);
65extern unsigned long lmb_alloc_base(unsigned long, unsigned long, unsigned long);
66extern unsigned long lmb_phys_mem_size(void);
67extern unsigned long lmb_end_of_DRAM(void);
68extern unsigned long lmb_abs_to_phys(unsigned long);
69extern void lmb_dump(char *);
70
71static inline unsigned long
72lmb_addrs_overlap(unsigned long base1, unsigned long size1,
73                  unsigned long base2, unsigned long size2)
74{
75        return ((base1 < (base2+size2)) && (base2 < (base1+size1)));
76}
77
78static inline long
79lmb_regions_overlap(struct lmb_region *rgn, unsigned long r1, unsigned long r2)
80{
81	unsigned long base1 = rgn->region[r1].base;
82        unsigned long size1 = rgn->region[r1].size;
83	unsigned long base2 = rgn->region[r2].base;
84        unsigned long size2 = rgn->region[r2].size;
85
86	return lmb_addrs_overlap(base1,size1,base2,size2);
87}
88
89static inline long
90lmb_addrs_adjacent(unsigned long base1, unsigned long size1,
91		   unsigned long base2, unsigned long size2)
92{
93	if ( base2 == base1 + size1 ) {
94		return 1;
95	} else if ( base1 == base2 + size2 ) {
96		return -1;
97	}
98	return 0;
99}
100
101static inline long
102lmb_regions_adjacent(struct lmb_region *rgn, unsigned long r1, unsigned long r2)
103{
104	unsigned long base1 = rgn->region[r1].base;
105        unsigned long size1 = rgn->region[r1].size;
106        unsigned long type1 = rgn->region[r1].type;
107	unsigned long base2 = rgn->region[r2].base;
108        unsigned long size2 = rgn->region[r2].size;
109        unsigned long type2 = rgn->region[r2].type;
110
111	return (type1 == type2) && lmb_addrs_adjacent(base1,size1,base2,size2);
112}
113
114#endif /* _PPC64_LMB_H */
115