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