machdep.c revision 1.26.4.2 1 1.26.4.2 rmind /* $NetBSD: machdep.c,v 1.26.4.2 2011/03/05 20:50:15 rmind Exp $ */
2 1.1 matt
3 1.1 matt /*
4 1.1 matt * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5 1.1 matt * Copyright (C) 1995, 1996 TooLs GmbH.
6 1.1 matt * All rights reserved.
7 1.1 matt *
8 1.1 matt * Redistribution and use in source and binary forms, with or without
9 1.1 matt * modification, are permitted provided that the following conditions
10 1.1 matt * are met:
11 1.1 matt * 1. Redistributions of source code must retain the above copyright
12 1.1 matt * notice, this list of conditions and the following disclaimer.
13 1.1 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 matt * notice, this list of conditions and the following disclaimer in the
15 1.1 matt * documentation and/or other materials provided with the distribution.
16 1.1 matt * 3. All advertising materials mentioning features or use of this software
17 1.1 matt * must display the following acknowledgement:
18 1.1 matt * This product includes software developed by TooLs GmbH.
19 1.1 matt * 4. The name of TooLs GmbH may not be used to endorse or promote products
20 1.1 matt * derived from this software without specific prior written permission.
21 1.1 matt *
22 1.1 matt * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23 1.1 matt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 1.1 matt * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 1.1 matt * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 1.1 matt * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27 1.1 matt * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28 1.1 matt * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29 1.1 matt * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30 1.1 matt * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31 1.1 matt * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 1.1 matt */
33 1.13 lukem
34 1.13 lukem #include <sys/cdefs.h>
35 1.26.4.2 rmind __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.26.4.2 2011/03/05 20:50:15 rmind Exp $");
36 1.1 matt
37 1.1 matt #include "opt_marvell.h"
38 1.24 apb #include "opt_modular.h"
39 1.8 matt #include "opt_ev64260.h"
40 1.1 matt #include "opt_compat_netbsd.h"
41 1.1 matt #include "opt_ddb.h"
42 1.1 matt #include "opt_inet.h"
43 1.1 matt #include "opt_ccitt.h"
44 1.1 matt #include "opt_iso.h"
45 1.1 matt #include "opt_ns.h"
46 1.1 matt #include "opt_ipkdb.h"
47 1.1 matt
48 1.26.4.1 rmind #define _POWERPC_BUS_DMA_PRIVATE
49 1.26.4.1 rmind
50 1.1 matt #include <sys/param.h>
51 1.26.4.1 rmind #include <sys/bus.h>
52 1.1 matt #include <sys/conf.h>
53 1.1 matt #include <sys/device.h>
54 1.26.4.1 rmind #include <sys/extent.h>
55 1.1 matt #include <sys/kernel.h>
56 1.26.4.1 rmind #include <sys/ksyms.h>
57 1.1 matt #include <sys/mount.h>
58 1.1 matt #include <sys/reboot.h>
59 1.1 matt #include <sys/systm.h>
60 1.6 matt #include <sys/termios.h>
61 1.26.4.1 rmind #include <sys/vnode.h>
62 1.1 matt
63 1.1 matt #include <uvm/uvm_extern.h>
64 1.1 matt
65 1.1 matt #include <net/netisr.h>
66 1.1 matt
67 1.1 matt #include <machine/db_machdep.h>
68 1.1 matt #include <machine/pmap.h>
69 1.1 matt #include <machine/powerpc.h>
70 1.1 matt
71 1.1 matt #include <powerpc/oea/bat.h>
72 1.26.4.1 rmind #include <powerpc/pic/picvar.h>
73 1.26.4.1 rmind #include <powerpc/pio.h>
74 1.1 matt
75 1.1 matt #include <ddb/db_extern.h>
76 1.1 matt
77 1.1 matt #include <dev/cons.h>
78 1.1 matt
79 1.1 matt #include "com.h"
80 1.1 matt #if (NCOM > 0)
81 1.1 matt #include <dev/ic/comreg.h>
82 1.1 matt #include <dev/ic/comvar.h>
83 1.1 matt #endif
84 1.1 matt
85 1.2 matt #include <dev/marvell/gtreg.h>
86 1.1 matt #include <dev/marvell/gtvar.h>
87 1.1 matt
88 1.6 matt #include "gtmpsc.h"
89 1.6 matt #if (NGTMPSC > 0)
90 1.26.4.1 rmind #include <dev/marvell/gtbrgreg.h>
91 1.6 matt #include <dev/marvell/gtsdmareg.h>
92 1.6 matt #include <dev/marvell/gtmpscreg.h>
93 1.6 matt #include <dev/marvell/gtmpscvar.h>
94 1.6 matt #endif
95 1.6 matt
96 1.11 ragge #include "ksyms.h"
97 1.26.4.1 rmind #include "locators.h"
98 1.26.4.1 rmind
99 1.11 ragge
100 1.1 matt /*
101 1.1 matt * Global variables used here and there
102 1.1 matt */
103 1.1 matt #define PMONMEMREGIONS 32
104 1.1 matt struct mem_region physmemr[PMONMEMREGIONS], availmemr[PMONMEMREGIONS];
105 1.1 matt
106 1.1 matt void initppc(u_int, u_int, u_int, void *); /* Called from locore */
107 1.26.4.1 rmind static void gt_bus_space_init(void);
108 1.26.4.1 rmind static inline void gt_record_memory(int, paddr_t, paddr_t, paddr_t);
109 1.26.4.1 rmind static void gt_find_memory(paddr_t);
110 1.4 matt
111 1.26.4.1 rmind bus_addr_t gt_base = 0;
112 1.8 matt
113 1.26.4.1 rmind extern int primary_pic;
114 1.26.4.1 rmind struct pic_ops *discovery_pic;
115 1.26.4.1 rmind struct pic_ops *discovery_gpp_pic[4];
116 1.26.4.1 rmind
117 1.26.4.1 rmind
118 1.26.4.1 rmind struct powerpc_bus_space ev64260_pci0_mem_bs_tag = {
119 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
120 1.4 matt 0x00000000, 0x00000000, 0x00000000,
121 1.4 matt };
122 1.26.4.1 rmind struct powerpc_bus_space ev64260_pci0_io_bs_tag = {
123 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
124 1.4 matt 0x00000000, 0x00000000, 0x00000000,
125 1.4 matt };
126 1.26.4.1 rmind struct powerpc_bus_space ev64260_pci1_mem_bs_tag = {
127 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
128 1.4 matt 0x00000000, 0x00000000, 0x00000000,
129 1.4 matt };
130 1.26.4.1 rmind struct powerpc_bus_space ev64260_pci1_io_bs_tag = {
131 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
132 1.4 matt 0x00000000, 0x00000000, 0x00000000,
133 1.4 matt };
134 1.26.4.1 rmind struct powerpc_bus_space ev64260_obio0_bs_tag = {
135 1.8 matt _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO0_STRIDE,
136 1.8 matt 0x00000000, 0x00000000, 0x00000000,
137 1.8 matt };
138 1.26.4.1 rmind struct powerpc_bus_space ev64260_obio1_bs_tag = {
139 1.8 matt _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO1_STRIDE,
140 1.8 matt 0x00000000, 0x00000000, 0x00000000,
141 1.8 matt };
142 1.26.4.1 rmind struct powerpc_bus_space ev64260_obio2_bs_tag = {
143 1.8 matt _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO2_STRIDE,
144 1.8 matt 0x00000000, 0x00000000, 0x00000000,
145 1.8 matt };
146 1.26.4.1 rmind struct powerpc_bus_space ev64260_obio3_bs_tag = {
147 1.8 matt _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE|OBIO3_STRIDE,
148 1.8 matt 0x00000000, 0x00000000, 0x00000000,
149 1.8 matt };
150 1.26.4.1 rmind struct powerpc_bus_space ev64260_bootcs_bs_tag = {
151 1.8 matt _BUS_SPACE_BIG_ENDIAN|_BUS_SPACE_MEM_TYPE,
152 1.4 matt 0x00000000, 0x00000000, 0x00000000,
153 1.4 matt };
154 1.26.4.1 rmind struct powerpc_bus_space ev64260_gt_bs_tag = {
155 1.4 matt _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
156 1.26.4.1 rmind 0x00000000, 0x00000000, GT_SIZE,
157 1.4 matt };
158 1.4 matt
159 1.26.4.1 rmind struct powerpc_bus_space *ev64260_obio_bs_tags[5] = {
160 1.26.4.1 rmind &ev64260_obio0_bs_tag, &ev64260_obio1_bs_tag, &ev64260_obio2_bs_tag,
161 1.26.4.1 rmind &ev64260_obio3_bs_tag, &ev64260_bootcs_bs_tag
162 1.4 matt };
163 1.1 matt
164 1.8 matt static char ex_storage[10][EXTENT_FIXED_STORAGE_SIZE(8)]
165 1.4 matt __attribute__((aligned(8)));
166 1.4 matt
167 1.8 matt const struct gt_decode_info {
168 1.8 matt bus_addr_t low_decode;
169 1.8 matt bus_addr_t high_decode;
170 1.8 matt } decode_regs[] = {
171 1.8 matt { GT_SCS0_Low_Decode, GT_SCS0_High_Decode },
172 1.8 matt { GT_SCS1_Low_Decode, GT_SCS1_High_Decode },
173 1.8 matt { GT_SCS2_Low_Decode, GT_SCS2_High_Decode },
174 1.8 matt { GT_SCS3_Low_Decode, GT_SCS3_High_Decode },
175 1.8 matt { GT_CS0_Low_Decode, GT_CS0_High_Decode },
176 1.8 matt { GT_CS1_Low_Decode, GT_CS1_High_Decode },
177 1.8 matt { GT_CS2_Low_Decode, GT_CS2_High_Decode },
178 1.8 matt { GT_CS3_Low_Decode, GT_CS3_High_Decode },
179 1.8 matt { GT_BootCS_Low_Decode, GT_BootCS_High_Decode },
180 1.1 matt };
181 1.1 matt
182 1.26.4.1 rmind struct powerpc_bus_dma_tag ev64260_bus_dma_tag = {
183 1.26.4.1 rmind 0, /* _bounce_thresh */
184 1.26.4.1 rmind _bus_dmamap_create,
185 1.26.4.1 rmind _bus_dmamap_destroy,
186 1.26.4.1 rmind _bus_dmamap_load,
187 1.26.4.1 rmind _bus_dmamap_load_mbuf,
188 1.26.4.1 rmind _bus_dmamap_load_uio,
189 1.26.4.1 rmind _bus_dmamap_load_raw,
190 1.26.4.1 rmind _bus_dmamap_unload,
191 1.26.4.1 rmind _bus_dmamap_sync,
192 1.26.4.1 rmind _bus_dmamem_alloc,
193 1.26.4.1 rmind _bus_dmamem_free,
194 1.26.4.1 rmind _bus_dmamem_map,
195 1.26.4.1 rmind _bus_dmamem_unmap,
196 1.26.4.1 rmind _bus_dmamem_mmap,
197 1.26.4.1 rmind };
198 1.26.4.1 rmind
199 1.26.4.1 rmind
200 1.1 matt void
201 1.25 dsl initppc(u_int startkernel, u_int endkernel, u_int args, void *btinfo)
202 1.1 matt {
203 1.26.4.1 rmind extern struct cfdata cfdata[];
204 1.26.4.1 rmind cfdata_t cf = &cfdata[0];
205 1.1 matt
206 1.26.4.1 rmind /* Get mapped address of gt(System Controller) */
207 1.26.4.1 rmind while (cf->cf_name != NULL) {
208 1.26.4.1 rmind if (strcmp(cf->cf_name, "gt") == 0 &&
209 1.26.4.1 rmind *cf->cf_loc != MAINBUSCF_ADDR_DEFAULT)
210 1.26.4.1 rmind break;
211 1.26.4.1 rmind cf++;
212 1.26.4.1 rmind }
213 1.26.4.1 rmind if (cf->cf_name == NULL)
214 1.26.4.1 rmind panic("where is gt?");
215 1.26.4.1 rmind gt_base = *cf->cf_loc;
216 1.26.4.1 rmind
217 1.26.4.1 rmind ev64260_gt_bs_tag.pbs_offset = gt_base;
218 1.26.4.1 rmind ev64260_gt_bs_tag.pbs_base = gt_base;
219 1.26.4.1 rmind ev64260_gt_bs_tag.pbs_limit += gt_base;
220 1.26.4.1 rmind oea_batinit(gt_base, BAT_BL_256M);
221 1.1 matt
222 1.26.4.1 rmind oea_init(NULL);
223 1.1 matt
224 1.26.4.1 rmind gt_bus_space_init();
225 1.26.4.1 rmind gt_find_memory(roundup(endkernel, PAGE_SIZE));
226 1.5 matt
227 1.4 matt consinit();
228 1.1 matt
229 1.26.4.1 rmind /*
230 1.1 matt * Set the page size.
231 1.1 matt */
232 1.1 matt uvm_setpagesize();
233 1.1 matt
234 1.1 matt /*
235 1.1 matt * Initialize pmap module.
236 1.1 matt */
237 1.1 matt pmap_bootstrap(startkernel, endkernel);
238 1.1 matt
239 1.22 ad #if NKSYMS || defined(DDB) || defined(MODULAR)
240 1.8 matt {
241 1.8 matt extern void *startsym, *endsym;
242 1.23 martin ksyms_addsyms_elf((int)((u_int)endsym - (u_int)startsym),
243 1.8 matt startsym, endsym);
244 1.8 matt }
245 1.1 matt #endif
246 1.1 matt #ifdef IPKDB
247 1.1 matt /*
248 1.1 matt * Now trap to IPKDB
249 1.1 matt */
250 1.1 matt ipkdb_init();
251 1.1 matt if (boothowto & RB_KDB)
252 1.1 matt ipkdb_connect(0);
253 1.1 matt #endif
254 1.1 matt }
255 1.1 matt
256 1.1 matt /*
257 1.1 matt * Machine dependent startup code.
258 1.1 matt */
259 1.1 matt void
260 1.8 matt cpu_startup(void)
261 1.1 matt {
262 1.1 matt register_t msr;
263 1.1 matt
264 1.1 matt oea_startup(NULL);
265 1.1 matt
266 1.26.4.1 rmind pic_init();
267 1.26.4.1 rmind discovery_pic = setup_discovery_pic();
268 1.26.4.1 rmind primary_pic = 0;
269 1.26.4.1 rmind discovery_gpp_pic[0] = setup_discovery_gpp_pic(discovery_pic, 0);
270 1.26.4.1 rmind discovery_gpp_pic[1] = setup_discovery_gpp_pic(discovery_pic, 8);
271 1.26.4.1 rmind discovery_gpp_pic[2] = setup_discovery_gpp_pic(discovery_pic, 16);
272 1.26.4.1 rmind discovery_gpp_pic[3] = setup_discovery_gpp_pic(discovery_pic, 24);
273 1.26.4.1 rmind /*
274 1.26.4.1 rmind * GPP interrupts establishes later.
275 1.26.4.1 rmind */
276 1.26.4.1 rmind
277 1.26.4.1 rmind oea_install_extint(pic_ext_intr);
278 1.26.4.1 rmind
279 1.1 matt /*
280 1.1 matt * Now that we have VM, malloc()s are OK in bus_space.
281 1.1 matt */
282 1.3 matt bus_space_mallocok();
283 1.1 matt
284 1.1 matt /*
285 1.1 matt * Now allow hardware interrupts.
286 1.1 matt */
287 1.26.4.1 rmind splraise(-1);
288 1.19 perry __asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
289 1.1 matt : "=r"(msr)
290 1.1 matt : "K"(PSL_EE));
291 1.1 matt }
292 1.1 matt
293 1.1 matt /*
294 1.1 matt * consinit
295 1.1 matt * Initialize system console.
296 1.1 matt */
297 1.1 matt void
298 1.8 matt consinit(void)
299 1.1 matt {
300 1.26.4.1 rmind
301 1.6 matt #ifdef MPSC_CONSOLE
302 1.6 matt /* PMON using MPSC0 @ 9600 */
303 1.26.4.1 rmind const int brg = GTMPSC_CRR_BRG0;
304 1.26.4.1 rmind const int baud = 9600;
305 1.26.4.1 rmind uint32_t cr;
306 1.26.4.1 rmind
307 1.26.4.1 rmind #if 1
308 1.26.4.1 rmind /*
309 1.26.4.1 rmind * XXX HACK FIXME
310 1.26.4.1 rmind * PMON output has not been flushed. give him a chance
311 1.26.4.1 rmind */
312 1.26.4.1 rmind DELAY(100000); /* XXX */
313 1.26.4.1 rmind #endif
314 1.26.4.1 rmind /* Setup MPSC Routing Registers */
315 1.26.4.1 rmind out32rb(gt_base + GTMPSC_MRR, GTMPSC_MRR_RES);
316 1.26.4.1 rmind cr = in32rb(gt_base + GTMPSC_RCRR);
317 1.26.4.1 rmind cr &= ~GTMPSC_CRR(MPSC_CONSOLE, GTMPSC_CRR_MASK);
318 1.26.4.1 rmind cr |= GTMPSC_CRR(MPSC_CONSOLE, brg);
319 1.26.4.1 rmind out32rb(gt_base + GTMPSC_RCRR, cr);
320 1.26.4.1 rmind out32rb(gt_base + GTMPSC_TCRR, cr);
321 1.26.4.1 rmind
322 1.26.4.1 rmind /* Setup Baud Rate Configuration Register of Baud Rate Generator */
323 1.26.4.1 rmind out32rb(gt_base + BRG_BCR(brg),
324 1.26.4.1 rmind BRG_BCR_EN | GT_MPSC_CLOCK_SOURCE | compute_cdv(baud));
325 1.26.4.1 rmind
326 1.26.4.1 rmind gtmpsccnattach(&ev64260_gt_bs_tag, &ev64260_bus_dma_tag, gt_base,
327 1.26.4.1 rmind MPSC_CONSOLE, brg, baud,
328 1.6 matt (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
329 1.6 matt #else
330 1.4 matt /* PPCBOOT using COM1 @ 57600 */
331 1.12 thorpej comcnattach(>_obio2_bs_tag, 0, 57600,
332 1.12 thorpej COM_FREQ*2, COM_TYPE_NORMAL,
333 1.4 matt (TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8);
334 1.4 matt #endif
335 1.1 matt }
336 1.1 matt
337 1.1 matt /*
338 1.1 matt * Halt or reboot the machine after syncing/dumping according to howto.
339 1.1 matt */
340 1.1 matt void
341 1.8 matt cpu_reboot(int howto, char *what)
342 1.1 matt {
343 1.1 matt static int syncing;
344 1.1 matt static char str[256];
345 1.1 matt char *ap = str, *ap1 = ap;
346 1.1 matt
347 1.1 matt boothowto = howto;
348 1.1 matt if (!cold && !(howto & RB_NOSYNC) && !syncing) {
349 1.1 matt syncing = 1;
350 1.1 matt vfs_shutdown(); /* sync */
351 1.1 matt resettodr(); /* set wall clock */
352 1.1 matt }
353 1.1 matt splhigh();
354 1.1 matt if (howto & RB_HALT) {
355 1.1 matt doshutdownhooks();
356 1.21 dyoung pmf_system_shutdown(boothowto);
357 1.1 matt printf("halted\n\n");
358 1.1 matt cnhalt();
359 1.1 matt while(1);
360 1.1 matt }
361 1.1 matt if (!cold && (howto & RB_DUMP))
362 1.1 matt oea_dumpsys();
363 1.1 matt doshutdownhooks();
364 1.21 dyoung
365 1.21 dyoung pmf_system_shutdown(boothowto);
366 1.1 matt printf("rebooting\n\n");
367 1.1 matt if (what && *what) {
368 1.1 matt if (strlen(what) > sizeof str - 5)
369 1.1 matt printf("boot string too large, ignored\n");
370 1.1 matt else {
371 1.1 matt strcpy(str, what);
372 1.1 matt ap1 = ap = str + strlen(str);
373 1.1 matt *ap++ = ' ';
374 1.1 matt }
375 1.1 matt }
376 1.1 matt *ap++ = '-';
377 1.1 matt if (howto & RB_SINGLE)
378 1.1 matt *ap++ = 's';
379 1.1 matt if (howto & RB_KDB)
380 1.1 matt *ap++ = 'd';
381 1.1 matt *ap++ = 0;
382 1.1 matt if (ap[-2] == '-')
383 1.1 matt *ap1 = 0;
384 1.1 matt gt_watchdog_reset();
385 1.1 matt /* NOTREACHED */
386 1.1 matt while (1);
387 1.1 matt }
388 1.1 matt
389 1.8 matt void
390 1.26.4.1 rmind mem_regions(struct mem_region **mem, struct mem_region **avail)
391 1.1 matt {
392 1.1 matt
393 1.26.4.1 rmind *mem = physmemr;
394 1.26.4.1 rmind *avail = availmemr;
395 1.1 matt }
396 1.4 matt
397 1.26.4.1 rmind static void
398 1.4 matt gt_bus_space_init(void)
399 1.4 matt {
400 1.8 matt const struct gt_decode_info *di;
401 1.4 matt uint32_t datal, datah;
402 1.26.4.1 rmind int error, bs, i;
403 1.4 matt
404 1.26.4.1 rmind bs = 0;
405 1.26.4.1 rmind error = bus_space_init(&ev64260_gt_bs_tag, "gt",
406 1.8 matt ex_storage[bs], sizeof(ex_storage[bs]));
407 1.26.4.1 rmind bs++;
408 1.4 matt
409 1.26.4.1 rmind for (i = 0, di = &decode_regs[4]; i < 5; i++, di++) {
410 1.26.4.1 rmind struct powerpc_bus_space *memt = ev64260_obio_bs_tags[i];
411 1.4 matt
412 1.26.4.1 rmind datal = in32rb(gt_base + di->low_decode);
413 1.26.4.1 rmind datah = in32rb(gt_base + di->high_decode);
414 1.8 matt
415 1.8 matt if (GT_LowAddr_GET(datal) >= GT_HighAddr_GET(datal)) {
416 1.26.4.1 rmind ev64260_obio_bs_tags[i] = NULL;
417 1.8 matt continue;
418 1.8 matt }
419 1.8 matt memt->pbs_offset = GT_LowAddr_GET(datal);
420 1.8 matt memt->pbs_limit = GT_HighAddr_GET(datah) + 1 -
421 1.8 matt memt->pbs_offset;
422 1.8 matt
423 1.8 matt error = bus_space_init(memt, "obio2",
424 1.8 matt ex_storage[bs], sizeof(ex_storage[bs]));
425 1.8 matt bs++;
426 1.8 matt }
427 1.4 matt
428 1.26.4.1 rmind datal = in32rb(gt_base + GT_PCI0_Mem0_Low_Decode);
429 1.26.4.1 rmind datah = in32rb(gt_base + GT_PCI0_Mem0_High_Decode);
430 1.9 matt #if defined(GT_PCI0_MEMBASE)
431 1.9 matt datal &= ~0xfff;
432 1.9 matt datal |= (GT_PCI0_MEMBASE >> 20);
433 1.26.4.1 rmind out32rb(gt_base + GT_PCI0_Mem0_Low_Decode, datal);
434 1.9 matt #endif
435 1.9 matt #if defined(GT_PCI0_MEMSIZE)
436 1.9 matt datah &= ~0xfff;
437 1.26.4.1 rmind datah |= (GT_PCI0_MEMSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
438 1.26.4.1 rmind out32rb(gt_base + GT_PCI0_Mem0_High_Decode, datal);
439 1.9 matt #endif
440 1.26.4.1 rmind ev64260_pci0_mem_bs_tag.pbs_base = GT_LowAddr_GET(datal);
441 1.26.4.1 rmind ev64260_pci0_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
442 1.4 matt
443 1.26.4.1 rmind error = bus_space_init(&ev64260_pci0_mem_bs_tag, "pci0-mem",
444 1.8 matt ex_storage[bs], sizeof(ex_storage[bs]));
445 1.8 matt bs++;
446 1.4 matt
447 1.26.4.1 rmind #if 1 /* XXXXXX */
448 1.6 matt /*
449 1.7 matt * Make sure PCI0 Memory is BAT mapped.
450 1.7 matt */
451 1.8 matt if (GT_LowAddr_GET(datal) < GT_HighAddr_GET(datal))
452 1.26.4.1 rmind oea_iobat_add(ev64260_pci0_mem_bs_tag.pbs_base & SEGMENT_MASK,
453 1.26.4.1 rmind BAT_BL_256M);
454 1.26.4.1 rmind #endif
455 1.7 matt
456 1.7 matt /*
457 1.6 matt * Make sure that I/O space start at 0.
458 1.6 matt */
459 1.26.4.1 rmind out32rb(gt_base + GT_PCI1_IO_Remap, 0);
460 1.6 matt
461 1.26.4.1 rmind datal = in32rb(gt_base + GT_PCI0_IO_Low_Decode);
462 1.26.4.1 rmind datah = in32rb(gt_base + GT_PCI0_IO_High_Decode);
463 1.9 matt #if defined(GT_PCI0_IOBASE)
464 1.9 matt datal &= ~0xfff;
465 1.9 matt datal |= (GT_PCI0_IOBASE >> 20);
466 1.26.4.1 rmind out32rb(gt_base + GT_PCI0_IO_Low_Decode, datal);
467 1.9 matt #endif
468 1.9 matt #if defined(GT_PCI0_IOSIZE)
469 1.9 matt datah &= ~0xfff;
470 1.26.4.1 rmind datah |= (GT_PCI0_IOSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
471 1.26.4.1 rmind out32rb(gt_base + GT_PCI0_IO_High_Decode, datal);
472 1.9 matt #endif
473 1.26.4.1 rmind ev64260_pci0_io_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
474 1.26.4.1 rmind ev64260_pci0_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
475 1.26.4.1 rmind ev64260_pci0_io_bs_tag.pbs_offset;
476 1.4 matt
477 1.26.4.1 rmind error = bus_space_init(&ev64260_pci0_io_bs_tag, "pci0-ioport",
478 1.8 matt ex_storage[bs], sizeof(ex_storage[bs]));
479 1.8 matt bs++;
480 1.4 matt
481 1.26.4.1 rmind datal = in32rb(gt_base + GT_PCI1_Mem0_Low_Decode);
482 1.26.4.1 rmind datah = in32rb(gt_base + GT_PCI1_Mem0_High_Decode);
483 1.9 matt #if defined(GT_PCI1_MEMBASE)
484 1.9 matt datal &= ~0xfff;
485 1.9 matt datal |= (GT_PCI1_MEMBASE >> 20);
486 1.26.4.1 rmind out32rb(gt_base + GT_PCI1_Mem0_Low_Decode, datal);
487 1.9 matt #endif
488 1.9 matt #if defined(GT_PCI1_MEMSIZE)
489 1.9 matt datah &= ~0xfff;
490 1.26.4.1 rmind datah |= (GT_PCI1_MEMSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
491 1.26.4.1 rmind out32rb(gt_base + GT_PCI1_Mem0_High_Decode, datal);
492 1.9 matt #endif
493 1.26.4.1 rmind ev64260_pci1_mem_bs_tag.pbs_base = GT_LowAddr_GET(datal);
494 1.26.4.1 rmind ev64260_pci1_mem_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1;
495 1.4 matt
496 1.26.4.1 rmind error = bus_space_init(&ev64260_pci1_mem_bs_tag, "pci1-mem",
497 1.8 matt ex_storage[bs], sizeof(ex_storage[bs]));
498 1.8 matt bs++;
499 1.7 matt
500 1.26.4.1 rmind #if 1 /* XXXXXX */
501 1.7 matt /*
502 1.7 matt * Make sure PCI1 Memory is BAT mapped.
503 1.7 matt */
504 1.8 matt if (GT_LowAddr_GET(datal) < GT_HighAddr_GET(datal))
505 1.26.4.1 rmind oea_iobat_add(ev64260_pci1_mem_bs_tag.pbs_base & SEGMENT_MASK,
506 1.26.4.1 rmind BAT_BL_256M);
507 1.26.4.1 rmind #endif
508 1.4 matt
509 1.6 matt /*
510 1.6 matt * Make sure that I/O space start at 0.
511 1.6 matt */
512 1.26.4.1 rmind out32rb(gt_base + GT_PCI1_IO_Remap, 0);
513 1.6 matt
514 1.26.4.1 rmind datal = in32rb(gt_base + GT_PCI1_IO_Low_Decode);
515 1.26.4.1 rmind datah = in32rb(gt_base + GT_PCI1_IO_High_Decode);
516 1.9 matt #if defined(GT_PCI1_IOBASE)
517 1.9 matt datal &= ~0xfff;
518 1.9 matt datal |= (GT_PCI1_IOBASE >> 20);
519 1.26.4.1 rmind out32rb(gt_base + GT_PCI1_IO_Low_Decode, datal);
520 1.9 matt #endif
521 1.9 matt #if defined(GT_PCI1_IOSIZE)
522 1.9 matt datah &= ~0xfff;
523 1.26.4.1 rmind datah |= (GT_PCI1_IOSIZE + GT_LowAddr_GET(datal) - 1) >> 20;
524 1.26.4.1 rmind out32rb(gt_base + GT_PCI1_IO_High_Decode, datal);
525 1.9 matt #endif
526 1.26.4.1 rmind ev64260_pci1_io_bs_tag.pbs_offset = GT_LowAddr_GET(datal);
527 1.26.4.1 rmind ev64260_pci1_io_bs_tag.pbs_limit = GT_HighAddr_GET(datah) + 1 -
528 1.26.4.1 rmind ev64260_pci1_io_bs_tag.pbs_offset;
529 1.4 matt
530 1.26.4.1 rmind error = bus_space_init(&ev64260_pci1_io_bs_tag, "pci1-ioport",
531 1.8 matt ex_storage[bs], sizeof(ex_storage[bs]));
532 1.8 matt bs++;
533 1.26.4.1 rmind }
534 1.4 matt
535 1.26.4.1 rmind static inline void
536 1.26.4.1 rmind gt_record_memory(int j, paddr_t start, paddr_t end, paddr_t endkernel)
537 1.26.4.1 rmind {
538 1.26.4.1 rmind physmemr[j].start = start;
539 1.26.4.1 rmind physmemr[j].size = end - start;
540 1.26.4.1 rmind if (start < endkernel)
541 1.26.4.1 rmind start = endkernel;
542 1.26.4.1 rmind availmemr[j].start = start;
543 1.26.4.1 rmind availmemr[j].size = end - start;
544 1.26.4.1 rmind }
545 1.26.4.1 rmind
546 1.26.4.1 rmind static void
547 1.26.4.1 rmind gt_find_memory(paddr_t endkernel)
548 1.26.4.1 rmind {
549 1.26.4.1 rmind paddr_t start = ~0, end = 0;
550 1.26.4.1 rmind const struct gt_decode_info *di;
551 1.26.4.1 rmind int i, j = 0, first = 1;
552 1.26.4.1 rmind
553 1.26.4.1 rmind /*
554 1.26.4.1 rmind * Round kernel end to a page boundary.
555 1.26.4.1 rmind */
556 1.26.4.1 rmind for (i = 0; i < 4; i++) {
557 1.26.4.1 rmind paddr_t nstart, nend;
558 1.26.4.1 rmind
559 1.26.4.1 rmind di = &decode_regs[i];
560 1.26.4.1 rmind nstart = GT_LowAddr_GET(in32rb(gt_base + di->low_decode));
561 1.26.4.1 rmind nend = GT_HighAddr_GET(in32rb(gt_base + di->high_decode)) + 1;
562 1.26.4.1 rmind if (nstart >= nend)
563 1.26.4.1 rmind continue;
564 1.26.4.1 rmind if (first) {
565 1.26.4.1 rmind /*
566 1.26.4.1 rmind * First entry? Just remember it.
567 1.26.4.1 rmind */
568 1.26.4.1 rmind start = nstart;
569 1.26.4.1 rmind end = nend;
570 1.26.4.1 rmind first = 0;
571 1.26.4.1 rmind } else if (nstart == end) {
572 1.26.4.1 rmind /*
573 1.26.4.1 rmind * Contiguous? Just update the end.
574 1.26.4.1 rmind */
575 1.26.4.1 rmind end = nend;
576 1.26.4.1 rmind } else {
577 1.26.4.1 rmind /*
578 1.26.4.1 rmind * Disjoint? record it.
579 1.26.4.1 rmind */
580 1.26.4.1 rmind gt_record_memory(j, start, end, endkernel);
581 1.26.4.1 rmind start = nstart;
582 1.26.4.1 rmind end = nend;
583 1.26.4.1 rmind j++;
584 1.26.4.1 rmind }
585 1.26.4.1 rmind }
586 1.26.4.1 rmind gt_record_memory(j, start, end, endkernel);
587 1.4 matt }
588