prep_machdep.c revision 1.13
1/* $NetBSD: prep_machdep.c,v 1.13 2021/02/27 01:31:23 thorpej Exp $ */
2
3/*-
4 * Copyright (c) 2007 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Tim Rightnour
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/*
33 * This is a set of general routines that most PReP-similar machines have
34 * in common.  Machines that use these routines do not have to be fully
35 * PReP compliant, the only requirement is that they use a PReP memory map.
36 * IE, io at 0x80000000 and mem at 0xc0000000.
37 */
38
39#include <sys/cdefs.h>
40__KERNEL_RCSID(0, "$NetBSD: prep_machdep.c,v 1.13 2021/02/27 01:31:23 thorpej Exp $");
41
42#include "ksyms.h"
43
44#ifdef _KERNEL_OPT
45#include "opt_ddb.h"
46#include "opt_modular.h"
47#endif
48
49#include <sys/param.h>
50#include <sys/extent.h>
51#include <sys/kernel.h>
52#include <sys/reboot.h>
53#include <sys/ksyms.h>
54
55#include <uvm/uvm_extern.h>
56#include <machine/powerpc.h>
57#include <sys/bus.h>
58#include <machine/pmap.h>
59#include <powerpc/oea/bat.h>
60
61#ifdef DDB
62#include <machine/db_machdep.h>
63#include <ddb/db_extern.h>
64#endif
65
66#if NKSYMS || defined(DDB) || defined(MODULAR)
67extern void *endsym, *startsym;
68#endif
69extern struct mem_region physmemr[2], availmemr[2];
70
71struct powerpc_bus_space prep_io_space_tag = {
72	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
73	.pbs_offset = PREP_BUS_SPACE_IO,
74	.pbs_base = 0x00000000,
75	.pbs_limit = PREP_PHYS_SIZE_IO,
76};
77
78struct powerpc_bus_space genppc_isa_io_space_tag = {
79	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
80	.pbs_offset = PREP_BUS_SPACE_IO,
81	.pbs_base = 0x00000000,
82	.pbs_limit = PREP_ISA_SIZE_IO,
83};
84
85struct powerpc_bus_space prep_mem_space_tag = {
86	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
87	.pbs_offset = PREP_BUS_SPACE_MEM,
88	.pbs_base = 0x00000000,
89	.pbs_limit = PREP_PHYS_SIZE_MEM,
90};
91
92struct powerpc_bus_space genppc_isa_mem_space_tag = {
93	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
94	.pbs_offset = PREP_BUS_SPACE_MEM,
95	.pbs_base = 0x00000000,
96	.pbs_limit = PREP_ISA_SIZE_MEM,
97};
98
99static char ex_storage[2][EXTENT_FIXED_STORAGE_SIZE(8)]
100	__attribute__((aligned(8)));
101
102void
103prep_bus_space_init(void)
104{
105	int error;
106
107	error = bus_space_init(&prep_io_space_tag, "ioport",
108	    ex_storage[0], sizeof(ex_storage[0]));
109	if (error)
110		panic("prep_bus_space_init: can't init io tag");
111
112	error = extent_alloc_region(prep_io_space_tag.pbs_extent,
113	    PREP_PHYS_RESVD_START_IO, PREP_PHYS_RESVD_SIZE_IO, EX_NOWAIT);
114	if (error)
115		panic("prep_bus_space_init: can't block out reserved I/O"
116		    " space 0x10000-0x7fffff: error=%d", error);
117
118	error = bus_space_init(&prep_mem_space_tag, "iomem",
119	    ex_storage[1], sizeof(ex_storage[1]));
120	if (error)
121		panic("prep_bus_space_init: can't init mem tag");
122
123	genppc_isa_io_space_tag.pbs_extent = prep_io_space_tag.pbs_extent;
124	error = bus_space_init(&genppc_isa_io_space_tag, "isa-ioport", NULL, 0);	if (error)
125		panic("prep_bus_space_init: can't init isa io tag");
126
127	genppc_isa_mem_space_tag.pbs_extent = prep_mem_space_tag.pbs_extent;
128	error = bus_space_init(&genppc_isa_mem_space_tag, "isa-iomem", NULL, 0);
129	if (error)
130		panic("prep_bus_space_init: can't init isa mem tag");
131}
132
133/*
134 * just a few calls used in initppc() all in one place so everything gets
135 * done the same across the ports
136 */
137
138void
139prep_initppc(u_long startkernel, u_long endkernel, u_int args, paddr_t pa, ...)
140{
141	va_list ap;
142
143	/*
144	 * Set up fixed BAT registers.  We map the PReP IO and MEM
145	 * space, plus any additional regions the platform wants.
146	 */
147	oea_batinit(
148	    PREP_BUS_SPACE_MEM, BAT_BL_256M,
149	    PREP_BUS_SPACE_IO,  BAT_BL_256M,
150	    0);
151
152	va_start(ap, pa);
153	while (pa != 0) {
154		register_t len = va_arg(ap, register_t);
155		oea_iobat_add(pa, len);
156		pa = va_arg(ap, paddr_t);
157	}
158	va_end(ap);
159
160	/* Install vectors and interrupt handler. */
161	oea_init(NULL);
162
163	/* Initialize bus_space. */
164	prep_bus_space_init();
165
166	/* Initialize the console asap. */
167	consinit();
168
169	/* Set the page size */
170	uvm_md_init();
171
172	/* Initialize pmap module */
173	pmap_bootstrap(startkernel, endkernel);
174
175#if NKSYMS || defined(DDB) || defined(MODULAR)
176	ksyms_addsyms_elf((int)((u_long)endsym - (u_long)startsym), startsym, endsym);
177#endif
178
179#ifdef DDB
180	boothowto = args;
181	if (boothowto & RB_KDB)
182		Debugger();
183#endif
184}
185
186void
187mem_regions(struct mem_region **mem, struct mem_region **avail)
188{
189
190	*mem = physmemr;
191	*avail = availmemr;
192}
193