1 /* $NetBSD: machdep.c,v 1.52 2021/08/03 09:25:43 rin Exp $ */
2
3 /*-
4 * Copyright (c) 2003 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Juergen Hannken-Illjes.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.52 2021/08/03 09:25:43 rin Exp $");
34
35 #include "opt_explora.h"
36
37 #include <sys/param.h>
38 #include <sys/bus.h>
39 #include <sys/kernel.h>
40 #include <sys/module.h>
41 #include <sys/systm.h>
42
43 #include <prop/proplib.h>
44
45 #include <machine/explora.h>
46
47 #include <powerpc/spr.h>
48 #include <powerpc/ibm4xx/spr.h>
49
50 #include <powerpc/ibm4xx/cpu.h>
51 #include <powerpc/ibm4xx/dcr403cgx.h>
52 #include <powerpc/ibm4xx/tlb.h>
53
54 #define TLB_PG_SIZE (16*1024*1024)
55
56 static const unsigned int cpuspeed = 66000000;
57
58 void initppc(vaddr_t, vaddr_t);
59
60 void
initppc(vaddr_t startkernel,vaddr_t endkernel)61 initppc(vaddr_t startkernel, vaddr_t endkernel)
62 {
63 u_int i, j, t, br[4];
64 u_int maddr, msize, size;
65
66 br[0] = mfdcr(DCR_BR4);
67 br[1] = mfdcr(DCR_BR5);
68 br[2] = mfdcr(DCR_BR6);
69 br[3] = mfdcr(DCR_BR7);
70
71 for (i = 0; i < 4; i++)
72 for (j = i+1; j < 4; j++)
73 if (br[j] < br[i])
74 t = br[j], br[j] = br[i], br[i] = t;
75
76 for (i = 0, size = 0; i < 4; i++) {
77 if (((br[i] >> 19) & 3) != 3)
78 continue;
79 maddr = ((br[i] >> 24) & 0xff) << 20;
80 msize = 1 << (20 + ((br[i] >> 21) & 7));
81 if (maddr + msize > size)
82 size = maddr + msize;
83 }
84
85 /*
86 * Setup initial tlbs.
87 * Kernel memory and console device are
88 * mapped into the first (reserved) tlbs.
89 */
90
91 for (maddr = 0; maddr < endkernel; maddr += TLB_PG_SIZE)
92 ppc4xx_tlb_reserve(maddr, maddr, TLB_PG_SIZE, TLB_EX);
93
94 /* Map PCKBC, PCKBC2, COM, LPT. This is far beyond physmem. */
95 ppc4xx_tlb_reserve(BASE_ISA, BASE_ISA, TLB_PG_SIZE, TLB_I | TLB_G);
96
97 #ifndef COM_IS_CONSOLE
98 ppc4xx_tlb_reserve(BASE_FB, BASE_FB, TLB_PG_SIZE, TLB_I | TLB_G);
99 ppc4xx_tlb_reserve(BASE_FB2, BASE_FB2, TLB_PG_SIZE, TLB_I | TLB_G);
100 #endif
101
102 /* Disable all external interrupts */
103 mtdcr(DCR_EXIER, 0);
104
105 /* Disable all timer interrupts */
106 mtspr(SPR_TCR, 0);
107
108 ibm40x_memsize_init(size, startkernel);
109 ibm4xx_init(startkernel, endkernel, pic_ext_intr);
110 }
111
112 void
cpu_startup(void)113 cpu_startup(void)
114 {
115 prop_number_t pn;
116
117 /*
118 * cpu common startup
119 */
120 ibm4xx_cpu_startup("NCD Explora 450");
121
122 /*
123 * Set up the board properties database.
124 */
125 board_info_init();
126
127 pn = prop_number_create_integer(ctob(physmem));
128 KASSERT(pn != NULL);
129 if (prop_dictionary_set(board_properties, "mem-size", pn) == false)
130 panic("setting mem-size");
131 prop_object_release(pn);
132
133 pn = prop_number_create_integer(cpuspeed);
134 KASSERT(pn != NULL);
135 if (prop_dictionary_set(board_properties, "processor-frequency",
136 pn) == false)
137 panic("setting processor-frequency");
138 prop_object_release(pn);
139
140 /*
141 * Now that we have VM, malloc()s are OK in bus_space.
142 */
143 bus_space_mallocok();
144
145 /*
146 * no fake mapiodev
147 */
148 fake_mapiodev = 0;
149 }
150