summaryrefslogtreecommitdiff
path: root/arch/ppc/lib/bat_rw.c
blob: c48c24015153ade7180d6accc9e62968127e792d (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
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
/*
 * (C) Copyright 2002
 * Rich Ireland, Enterasys Networks, rireland@enterasys.com.
 *
 * See file CREDITS for list of people who contributed to this
 * project.
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License as
 * published by the Free Software Foundation; either version 2 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 * MA 02111-1307 USA
 *
 */

#include <common.h>
#include <asm/processor.h>
#include <asm/mmu.h>
#include <asm/io.h>

#ifdef CONFIG_ADDR_MAP
#include <addr_map.h>
#endif

DECLARE_GLOBAL_DATA_PTR;

int write_bat (ppc_bat_t bat, unsigned long upper, unsigned long lower)
{
	int batn = -1;

	sync();

	switch (bat) {
	case DBAT0:
		mtspr (DBAT0L, lower);
		mtspr (DBAT0U, upper);
		batn = 0;
		break;
	case IBAT0:
		mtspr (IBAT0L, lower);
		mtspr (IBAT0U, upper);
		break;
	case DBAT1:
		mtspr (DBAT1L, lower);
		mtspr (DBAT1U, upper);
		batn = 1;
		break;
	case IBAT1:
		mtspr (IBAT1L, lower);
		mtspr (IBAT1U, upper);
		break;
	case DBAT2:
		mtspr (DBAT2L, lower);
		mtspr (DBAT2U, upper);
		batn = 2;
		break;
	case IBAT2:
		mtspr (IBAT2L, lower);
		mtspr (IBAT2U, upper);
		break;
	case DBAT3:
		mtspr (DBAT3L, lower);
		mtspr (DBAT3U, upper);
		batn = 3;
		break;
	case IBAT3:
		mtspr (IBAT3L, lower);
		mtspr (IBAT3U, upper);
		break;
#ifdef CONFIG_HIGH_BATS
	case DBAT4:
		mtspr (DBAT4L, lower);
		mtspr (DBAT4U, upper);
		batn = 4;
		break;
	case IBAT4:
		mtspr (IBAT4L, lower);
		mtspr (IBAT4U, upper);
		break;
	case DBAT5:
		mtspr (DBAT5L, lower);
		mtspr (DBAT5U, upper);
		batn = 5;
		break;
	case IBAT5:
		mtspr (IBAT5L, lower);
		mtspr (IBAT5U, upper);
		break;
	case DBAT6:
		mtspr (DBAT6L, lower);
		mtspr (DBAT6U, upper);
		batn = 6;
		break;
	case IBAT6:
		mtspr (IBAT6L, lower);
		mtspr (IBAT6U, upper);
		break;
	case DBAT7:
		mtspr (DBAT7L, lower);
		mtspr (DBAT7U, upper);
		batn = 7;
		break;
	case IBAT7:
		mtspr (IBAT7L, lower);
		mtspr (IBAT7U, upper);
		break;
#endif
	default:
		return (-1);
	}

#ifdef CONFIG_ADDR_MAP
	if ((gd->flags & GD_FLG_RELOC) && (batn >= 0)) {
		phys_size_t size;
		if (!BATU_VALID(upper))
			size = 0;
		else
			size = BATU_SIZE(upper);
		addrmap_set_entry(BATU_VADDR(upper), BATL_PADDR(lower),
				  size, batn);
	}
#endif

	sync();
	isync();

	return (0);
}

int read_bat (ppc_bat_t bat, unsigned long *upper, unsigned long *lower)
{
	unsigned long register u;
	unsigned long register l;

	switch (bat) {
	case DBAT0:
		l = mfspr (DBAT0L);
		u = mfspr (DBAT0U);
		break;
	case IBAT0:
		l = mfspr (IBAT0L);
		u = mfspr (IBAT0U);
		break;
	case DBAT1:
		l = mfspr (DBAT1L);
		u = mfspr (DBAT1U);
		break;
	case IBAT1:
		l = mfspr (IBAT1L);
		u = mfspr (IBAT1U);
		break;
	case DBAT2:
		l = mfspr (DBAT2L);
		u = mfspr (DBAT2U);
		break;
	case IBAT2:
		l = mfspr (IBAT2L);
		u = mfspr (IBAT2U);
		break;
	case DBAT3:
		l = mfspr (DBAT3L);
		u = mfspr (DBAT3U);
		break;
	case IBAT3:
		l = mfspr (IBAT3L);
		u = mfspr (IBAT3U);
		break;
#ifdef CONFIG_HIGH_BATS
	case DBAT4:
		l = mfspr (DBAT4L);
		u = mfspr (DBAT4U);
		break;
	case IBAT4:
		l = mfspr (IBAT4L);
		u = mfspr (IBAT4U);
		break;
	case DBAT5:
		l = mfspr (DBAT5L);
		u = mfspr (DBAT5U);
		break;
	case IBAT5:
		l = mfspr (IBAT5L);
		u = mfspr (IBAT5U);
		break;
	case DBAT6:
		l = mfspr (DBAT6L);
		u = mfspr (DBAT6U);
		break;
	case IBAT6:
		l = mfspr (IBAT6L);
		u = mfspr (IBAT6U);
		break;
	case DBAT7:
		l = mfspr (DBAT7L);
		u = mfspr (DBAT7U);
		break;
	case IBAT7:
		l = mfspr (IBAT7L);
		u = mfspr (IBAT7U);
		break;
#endif
	default:
		return (-1);
	}

	*upper = u;
	*lower = l;

	return (0);
}

void print_bats(void)
{
	printf("BAT registers:\n");

	printf ("\tIBAT0L = 0x%08X ", mfspr (IBAT0L));
	printf ("\tIBAT0U = 0x%08X\n", mfspr (IBAT0U));
	printf ("\tDBAT0L = 0x%08X ", mfspr (DBAT0L));
	printf ("\tDBAT0U = 0x%08X\n", mfspr (DBAT0U));
	printf ("\tIBAT1L = 0x%08X ", mfspr (IBAT1L));
	printf ("\tIBAT1U = 0x%08X\n", mfspr (IBAT1U));
	printf ("\tDBAT1L = 0x%08X ", mfspr (DBAT1L));
	printf ("\tDBAT1U = 0x%08X\n", mfspr (DBAT1U));
	printf ("\tIBAT2L = 0x%08X ", mfspr (IBAT2L));
	printf ("\tIBAT2U = 0x%08X\n", mfspr (IBAT2U));
	printf ("\tDBAT2L = 0x%08X ", mfspr (DBAT2L));
	printf ("\tDBAT2U = 0x%08X\n", mfspr (DBAT2U));
	printf ("\tIBAT3L = 0x%08X ", mfspr (IBAT3L));
	printf ("\tIBAT3U = 0x%08X\n", mfspr (IBAT3U));
	printf ("\tDBAT3L = 0x%08X ", mfspr (DBAT3L));
	printf ("\tDBAT3U = 0x%08X\n", mfspr (DBAT3U));

#ifdef CONFIG_HIGH_BATS
	printf ("\tIBAT4L = 0x%08X ", mfspr (IBAT4L));
	printf ("\tIBAT4U = 0x%08X\n", mfspr (IBAT4U));
	printf ("\tDBAT4L = 0x%08X ", mfspr (DBAT4L));
	printf ("\tDBAT4U = 0x%08X\n", mfspr (DBAT4U));
	printf ("\tIBAT5L = 0x%08X ", mfspr (IBAT5L));
	printf ("\tIBAT5U = 0x%08X\n", mfspr (IBAT5U));
	printf ("\tDBAT5L = 0x%08X ", mfspr (DBAT5L));
	printf ("\tDBAT5U = 0x%08X\n", mfspr (DBAT5U));
	printf ("\tIBAT6L = 0x%08X ", mfspr (IBAT6L));
	printf ("\tIBAT6U = 0x%08X\n", mfspr (IBAT6U));
	printf ("\tDBAT6L = 0x%08X ", mfspr (DBAT6L));
	printf ("\tDBAT6U = 0x%08X\n", mfspr (DBAT6U));
	printf ("\tIBAT7L = 0x%08X ", mfspr (IBAT7L));
	printf ("\tIBAT7U = 0x%08X\n", mfspr (IBAT7U));
	printf ("\tDBAT7L = 0x%08X ", mfspr (DBAT7L));
	printf ("\tDBAT7U = 0x%08X\n", mfspr (DBAT7U));
#endif
}