1*993d4211Srin /* $NetBSD: machdep.c,v 1.52 2021/08/03 09:25:43 rin Exp $ */
2249e0067Shannken
3249e0067Shannken /*-
4249e0067Shannken * Copyright (c) 2003 The NetBSD Foundation, Inc.
5249e0067Shannken * All rights reserved.
6249e0067Shannken *
7249e0067Shannken * This code is derived from software contributed to The NetBSD Foundation
8249e0067Shannken * by Juergen Hannken-Illjes.
9249e0067Shannken *
10249e0067Shannken * Redistribution and use in source and binary forms, with or without
11249e0067Shannken * modification, are permitted provided that the following conditions
12249e0067Shannken * are met:
13249e0067Shannken * 1. Redistributions of source code must retain the above copyright
14249e0067Shannken * notice, this list of conditions and the following disclaimer.
15249e0067Shannken * 2. Redistributions in binary form must reproduce the above copyright
16249e0067Shannken * notice, this list of conditions and the following disclaimer in the
17249e0067Shannken * documentation and/or other materials provided with the distribution.
18249e0067Shannken *
19249e0067Shannken * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20249e0067Shannken * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21249e0067Shannken * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22249e0067Shannken * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23249e0067Shannken * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24249e0067Shannken * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25249e0067Shannken * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26249e0067Shannken * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27249e0067Shannken * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28249e0067Shannken * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29249e0067Shannken * POSSIBILITY OF SUCH DAMAGE.
30249e0067Shannken */
31249e0067Shannken
3214172728Slukem #include <sys/cdefs.h>
33*993d4211Srin __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2021/08/03 09:25:43 rin Exp $");
3439ce1865Shannken
3539ce1865Shannken #include "opt_explora.h"
3614172728Slukem
37249e0067Shannken #include <sys/param.h>
38bf9f8ea7Srin #include <sys/bus.h>
39249e0067Shannken #include <sys/kernel.h>
407eedb1d0Smrg #include <sys/module.h>
41bf9f8ea7Srin #include <sys/systm.h>
42249e0067Shannken
43fb44a857Sthorpej #include <prop/proplib.h>
44fb44a857Sthorpej
45249e0067Shannken #include <machine/explora.h>
46249e0067Shannken
47249e0067Shannken #include <powerpc/spr.h>
48ec4306c9Smatt #include <powerpc/ibm4xx/spr.h>
4951a2be50Smatt
5051a2be50Smatt #include <powerpc/ibm4xx/cpu.h>
51249e0067Shannken #include <powerpc/ibm4xx/dcr403cgx.h>
52331fcecaSrin #include <powerpc/ibm4xx/tlb.h>
53249e0067Shannken
54249e0067Shannken #define TLB_PG_SIZE (16*1024*1024)
55249e0067Shannken
56fb44a857Sthorpej static const unsigned int cpuspeed = 66000000;
57fb44a857Sthorpej
58dba36e03Smatt void initppc(vaddr_t, vaddr_t);
593e4ced31Shannken
60249e0067Shannken void
initppc(vaddr_t startkernel,vaddr_t endkernel)61dba36e03Smatt initppc(vaddr_t startkernel, vaddr_t endkernel)
62249e0067Shannken {
63249e0067Shannken u_int i, j, t, br[4];
64471efec8Skiyohara u_int maddr, msize, size;
65249e0067Shannken
66249e0067Shannken br[0] = mfdcr(DCR_BR4);
67249e0067Shannken br[1] = mfdcr(DCR_BR5);
68249e0067Shannken br[2] = mfdcr(DCR_BR6);
69249e0067Shannken br[3] = mfdcr(DCR_BR7);
70249e0067Shannken
71249e0067Shannken for (i = 0; i < 4; i++)
72249e0067Shannken for (j = i+1; j < 4; j++)
73249e0067Shannken if (br[j] < br[i])
74249e0067Shannken t = br[j], br[j] = br[i], br[i] = t;
75249e0067Shannken
76249e0067Shannken for (i = 0, size = 0; i < 4; i++) {
77249e0067Shannken if (((br[i] >> 19) & 3) != 3)
78249e0067Shannken continue;
79249e0067Shannken maddr = ((br[i] >> 24) & 0xff) << 20;
80249e0067Shannken msize = 1 << (20 + ((br[i] >> 21) & 7));
81249e0067Shannken if (maddr + msize > size)
82249e0067Shannken size = maddr + msize;
83249e0067Shannken }
84249e0067Shannken
85249e0067Shannken /*
86249e0067Shannken * Setup initial tlbs.
87e2db2efbSfreza * Kernel memory and console device are
8839ce1865Shannken * mapped into the first (reserved) tlbs.
89249e0067Shannken */
90249e0067Shannken
91e2db2efbSfreza for (maddr = 0; maddr < endkernel; maddr += TLB_PG_SIZE)
92471efec8Skiyohara ppc4xx_tlb_reserve(maddr, maddr, TLB_PG_SIZE, TLB_EX);
93249e0067Shannken
94e2db2efbSfreza /* Map PCKBC, PCKBC2, COM, LPT. This is far beyond physmem. */
956920dbe4Skiyohara ppc4xx_tlb_reserve(BASE_ISA, BASE_ISA, TLB_PG_SIZE, TLB_I | TLB_G);
96471efec8Skiyohara
9794ebc17bSrin #ifndef COM_IS_CONSOLE
98471efec8Skiyohara ppc4xx_tlb_reserve(BASE_FB, BASE_FB, TLB_PG_SIZE, TLB_I | TLB_G);
99471efec8Skiyohara ppc4xx_tlb_reserve(BASE_FB2, BASE_FB2, TLB_PG_SIZE, TLB_I | TLB_G);
10039ce1865Shannken #endif
101249e0067Shannken
102249e0067Shannken /* Disable all external interrupts */
103249e0067Shannken mtdcr(DCR_EXIER, 0);
104249e0067Shannken
105249e0067Shannken /* Disable all timer interrupts */
106249e0067Shannken mtspr(SPR_TCR, 0);
107249e0067Shannken
108ffbe1066Srin ibm40x_memsize_init(size, startkernel);
109dba36e03Smatt ibm4xx_init(startkernel, endkernel, pic_ext_intr);
110249e0067Shannken }
111249e0067Shannken
112249e0067Shannken void
cpu_startup(void)113249e0067Shannken cpu_startup(void)
114249e0067Shannken {
115fb44a857Sthorpej prop_number_t pn;
116249e0067Shannken
117249e0067Shannken /*
118ffbe1066Srin * cpu common startup
119249e0067Shannken */
1203252eee2Srin ibm4xx_cpu_startup("NCD Explora 450");
121249e0067Shannken
122249e0067Shannken /*
123249e0067Shannken * Set up the board properties database.
124249e0067Shannken */
125ffbe1066Srin board_info_init();
126249e0067Shannken
127fb44a857Sthorpej pn = prop_number_create_integer(ctob(physmem));
128fb44a857Sthorpej KASSERT(pn != NULL);
1298b3bae62Sthorpej if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
130249e0067Shannken panic("setting mem-size");
131fb44a857Sthorpej prop_object_release(pn);
132fb44a857Sthorpej
133fb44a857Sthorpej pn = prop_number_create_integer(cpuspeed);
134fb44a857Sthorpej KASSERT(pn != NULL);
135fb44a857Sthorpej if (prop_dictionary_set(board_properties, "processor-frequency",
1368b3bae62Sthorpej pn) == false)
137fb44a857Sthorpej panic("setting processor-frequency");
138fb44a857Sthorpej prop_object_release(pn);
13971114471Shannken
1407eedb1d0Smrg /*
1410cec5ffeSrin * Now that we have VM, malloc()s are OK in bus_space.
1420cec5ffeSrin */
1430cec5ffeSrin bus_space_mallocok();
1440cec5ffeSrin
1450cec5ffeSrin /*
146ffbe1066Srin * no fake mapiodev
1477eedb1d0Smrg */
148dba36e03Smatt fake_mapiodev = 0;
149249e0067Shannken }
150