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