summaryrefslogtreecommitdiffstats
path: root/arch/mips64/sgi-ip27/ip27-memory.c
blob: 368a0d209b31a1b45c2586b721288a81c78a2dff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/* $Id: ip27-memory.c,v 1.2 2000/01/27 01:05:24 ralf Exp $
 *
 * This file is subject to the terms and conditions of the GNU General Public
 * License.  See the file "COPYING" in the main directory of this archive
 * for more details.
 *
 * Copyright (C) 2000 by Ralf Baechle
 * Copyright (C) 2000 by Silicon Graphics, Inc.
 *
 * On SGI IP27 the ARC memory configuration data is completly bogus but
 * alternate easier to use mechanisms are available.
 */
#include <linux/init.h>
#include <linux/config.h>
#include <linux/kernel.h>
#include <linux/mm.h>
#include <linux/bootmem.h>

#include <asm/page.h>
#include <asm/bootinfo.h>
#include <asm/addrspace.h>
#include <asm/sn/types.h>
#include <asm/sn/addrs.h>
#include <asm/sn/klconfig.h>
#include <asm/sn/arch.h>

typedef unsigned long pfn_t;			/* into <asm/sn/types.h> */
#define KDM_TO_PHYS(x)	((x) & TO_PHYS_MASK)	/* into asm/addrspace.h */

#define SLOT_PFNSHIFT	(SLOT_SHIFT - PAGE_SHIFT) /* into asm/sn/arch.h */
#define PFN_NASIDSHFT	(NASID_SHFT - PAGE_SHIFT)
#define mkpfn(nasid, off)	(((pfn_t)(nasid) << PFN_NASIDSHFT) | (off))
#define slot_getbasepfn(node,slot) \
		(mkpfn(COMPACT_TO_NASID_NODEID(node), slot<<SLOT_PFNSHIFT))
extern nasid_t compact_to_nasid_node[];

extern char _end;

#define PFN_UP(x)	(((x) + PAGE_SIZE-1) >> PAGE_SHIFT)
#define PFN_ALIGN(x)	(((unsigned long)(x) + (PAGE_SIZE - 1)) & PAGE_MASK)

short slot_lastfilled_cache[MAX_COMPACT_NODES];
unsigned short slot_psize_cache[MAX_COMPACT_NODES][MAX_MEM_SLOTS];

/*
 * Return pfn of first free page of memory on a node. PROM may allocate
 * data structures on the first couple of pages of the first slot of each 
 * node. If this is the case, getfirstfree(node) > getslotstart(node, 0).
 */
pfn_t node_getfirstfree(cnodeid_t cnode)
{
#ifdef LATER
	nasid_t nasid = COMPACT_TO_NASID_NODEID(cnode);

	if (cnode == 0)
		return KDM_TO_PHYS((unsigned long)(&_end));
	return KDM_TO_PHYS(SYMMON_STK_ADDR(nasid, 0));
#endif
	if (cnode == 0)
		return (KDM_TO_PHYS(PFN_ALIGN(&_end) - (CKSEG0 - K0BASE)) 
								>> PAGE_SHIFT);
	return slot_getbasepfn(cnode, 0);
}

/*
 * Return the number of pages of memory provided by the given slot
 * on the specified node.
 */
pfn_t slot_getsize(cnodeid_t node, int slot)
{
	return (pfn_t) slot_psize_cache[node][slot];
}

/*
 * Return the pfn of the last free page of memory on a node.
 */
pfn_t node_getmaxclick(cnodeid_t node)
{
	pfn_t	slot_psize;
	int	slot;

	/*
	 * Start at the top slot. When we find a slot with memory in it,
	 * that's the winner.
	 */
	for (slot = (node_getnumslots(node) - 1); slot >= 0; slot--) {
		if ((slot_psize = slot_getsize(node, slot))) {
			/* Return the basepfn + the slot size, minus 1. */
			return slot_getbasepfn(node, slot) + slot_psize - 1;
		}
	}

	/*
	 * If there's no memory on the node, return 0. This is likely
	 * to cause problems.
	 */
	return (pfn_t)0;
}

static pfn_t slot_psize_compute(cnodeid_t node, int slot)
{
	nasid_t nasid;
	lboard_t *brd;
	klmembnk_t *banks;
	unsigned long size;

	nasid = COMPACT_TO_NASID_NODEID(node);
	/* Find the node board */
	brd = find_lboard_real((lboard_t *)KL_CONFIG_INFO(nasid), KLTYPE_IP27);
	if (!brd)
		return 0;

	/* Get the memory bank structure */
	banks = (klmembnk_t *)find_first_component(brd, KLSTRUCT_MEMBNK);
	if (!banks)
		return 0;

	/* Size in _Megabytes_ */
	size = (unsigned long)banks->membnk_bnksz[slot/4];

	/* hack for 128 dimm banks */
	if (size <= 128) {
		if (slot%4 == 0) {
			size <<= 20;		/* size in bytes */
			return(size >> PAGE_SHIFT);
		} else {
			return 0;
		}
	} else {
		size /= 4;
		size <<= 20;
		return(size >> PAGE_SHIFT);
	}
}

pfn_t szmem(pfn_t fpage, pfn_t maxpmem)
{
	int node, slot;
	int numslots;
	pfn_t num_pages = 0;
	pfn_t slot_psize;

	for (node = 0; node < numnodes; node++) {
		numslots = node_getnumslots(node);
		for (slot = 0; slot < numslots; slot++) {
			slot_psize = slot_psize_compute(node, slot);
			num_pages += slot_psize;
			slot_psize_cache[node][slot] = 
					(unsigned short) slot_psize;
			if (slot_psize)
				slot_lastfilled_cache[node] = slot;
		}
	}
	if (maxpmem)
		return((maxpmem > num_pages) ? num_pages : maxpmem);
	else
		return num_pages;
}

/*
 * Currently, the intranode memory hole support assumes that each slot
 * contains at least 32 MBytes of memory. We assume all bootmem data
 * fits on the first slot.
 */
void __init prom_meminit(void)
{
	extern void mlreset(void);
	cnodeid_t node;
	pfn_t slot_firstpfn, slot_lastpfn, slot_freepfn, numpages;
	unsigned long bootmap_size;

	mlreset();
	numpages = szmem(0, 0);
	for (node = 0; node < numnodes; node++) {
		slot_firstpfn = slot_getbasepfn(node, 0);
		slot_lastpfn = slot_firstpfn + slot_getsize(node, 0);
		slot_freepfn = node_getfirstfree(node);
		printk("Node %d slot 0: 0x%lx 0x%lx 0x%lx\n", node, 
			slot_firstpfn<<PAGE_SHIFT, slot_lastpfn<<PAGE_SHIFT,
			slot_freepfn<<PAGE_SHIFT);
		/* delete next 2 lines when we have numa support */
		if (node == 0) {
		max_low_pfn = (slot_lastpfn - slot_firstpfn);
	  	bootmap_size = init_bootmem_node(node, slot_freepfn, 
						slot_firstpfn, slot_lastpfn);
		free_bootmem_node(node, slot_firstpfn << PAGE_SHIFT, 
				(slot_lastpfn - slot_firstpfn) << PAGE_SHIFT);
		reserve_bootmem_node(node, slot_firstpfn << PAGE_SHIFT,
		  ((slot_freepfn - slot_firstpfn) << PAGE_SHIFT) + bootmap_size);
		}
	}
	printk("Total memory probed : 0x%lx pages\n", numpages);
}

int __init page_is_ram(unsigned long pagenr)
{
        return 1;
}

void __init
prom_free_prom_memory (void)
{
	/* We got nothing to free here ...  */
}