xref: /netbsd/sys/arch/powerpc/oea/prep_machdep.c (revision 29878ada)
1*29878adaSthorpej /* $NetBSD: prep_machdep.c,v 1.13 2021/02/27 01:31:23 thorpej Exp $ */
2d974db0aSgarbled 
3d974db0aSgarbled /*-
4d974db0aSgarbled  * Copyright (c) 2007 The NetBSD Foundation, Inc.
5d974db0aSgarbled  * All rights reserved.
6d974db0aSgarbled  *
7d974db0aSgarbled  * This code is derived from software contributed to The NetBSD Foundation
8d974db0aSgarbled  * by Tim Rightnour
9d974db0aSgarbled  *
10d974db0aSgarbled  * Redistribution and use in source and binary forms, with or without
11d974db0aSgarbled  * modification, are permitted provided that the following conditions
12d974db0aSgarbled  * are met:
13d974db0aSgarbled  * 1. Redistributions of source code must retain the above copyright
14d974db0aSgarbled  *    notice, this list of conditions and the following disclaimer.
15d974db0aSgarbled  * 2. Redistributions in binary form must reproduce the above copyright
16d974db0aSgarbled  *    notice, this list of conditions and the following disclaimer in the
17d974db0aSgarbled  *    documentation and/or other materials provided with the distribution.
18d974db0aSgarbled  *
19d974db0aSgarbled  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20d974db0aSgarbled  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21d974db0aSgarbled  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22d974db0aSgarbled  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23d974db0aSgarbled  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24d974db0aSgarbled  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25d974db0aSgarbled  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26d974db0aSgarbled  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27d974db0aSgarbled  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28d974db0aSgarbled  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29d974db0aSgarbled  * POSSIBILITY OF SUCH DAMAGE.
30d974db0aSgarbled  */
31d974db0aSgarbled 
32d974db0aSgarbled /*
33d974db0aSgarbled  * This is a set of general routines that most PReP-similar machines have
34d974db0aSgarbled  * in common.  Machines that use these routines do not have to be fully
35d974db0aSgarbled  * PReP compliant, the only requirement is that they use a PReP memory map.
36d974db0aSgarbled  * IE, io at 0x80000000 and mem at 0xc0000000.
37d974db0aSgarbled  */
38d974db0aSgarbled 
39d974db0aSgarbled #include <sys/cdefs.h>
40*29878adaSthorpej __KERNEL_RCSID(0, "$NetBSD: prep_machdep.c,v 1.13 2021/02/27 01:31:23 thorpej Exp $");
410cc72e51Sapb 
4245cb1d76Srin #include "ksyms.h"
4345cb1d76Srin 
4445cb1d76Srin #ifdef _KERNEL_OPT
4545cb1d76Srin #include "opt_ddb.h"
460cc72e51Sapb #include "opt_modular.h"
4745cb1d76Srin #endif
48d974db0aSgarbled 
49d974db0aSgarbled #include <sys/param.h>
50d974db0aSgarbled #include <sys/extent.h>
51d974db0aSgarbled #include <sys/kernel.h>
52d974db0aSgarbled #include <sys/reboot.h>
53d974db0aSgarbled #include <sys/ksyms.h>
54d974db0aSgarbled 
55d974db0aSgarbled #include <uvm/uvm_extern.h>
56d974db0aSgarbled #include <machine/powerpc.h>
57fe6db6ffSdyoung #include <sys/bus.h>
58d974db0aSgarbled #include <machine/pmap.h>
59d974db0aSgarbled #include <powerpc/oea/bat.h>
60d974db0aSgarbled 
61d974db0aSgarbled #ifdef DDB
62d974db0aSgarbled #include <machine/db_machdep.h>
63d974db0aSgarbled #include <ddb/db_extern.h>
64d974db0aSgarbled #endif
65d974db0aSgarbled 
660efea177Sad #if NKSYMS || defined(DDB) || defined(MODULAR)
67d974db0aSgarbled extern void *endsym, *startsym;
68d974db0aSgarbled #endif
69d974db0aSgarbled extern struct mem_region physmemr[2], availmemr[2];
70d974db0aSgarbled 
71d974db0aSgarbled struct powerpc_bus_space prep_io_space_tag = {
72d974db0aSgarbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
73d974db0aSgarbled 	.pbs_offset = PREP_BUS_SPACE_IO,
74d974db0aSgarbled 	.pbs_base = 0x00000000,
75d974db0aSgarbled 	.pbs_limit = PREP_PHYS_SIZE_IO,
76d974db0aSgarbled };
77d974db0aSgarbled 
78d974db0aSgarbled struct powerpc_bus_space genppc_isa_io_space_tag = {
79d974db0aSgarbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_IO_TYPE,
80d974db0aSgarbled 	.pbs_offset = PREP_BUS_SPACE_IO,
81d974db0aSgarbled 	.pbs_base = 0x00000000,
82d974db0aSgarbled 	.pbs_limit = PREP_ISA_SIZE_IO,
83d974db0aSgarbled };
84d974db0aSgarbled 
85d974db0aSgarbled struct powerpc_bus_space prep_mem_space_tag = {
86d974db0aSgarbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
87d974db0aSgarbled 	.pbs_offset = PREP_BUS_SPACE_MEM,
88d974db0aSgarbled 	.pbs_base = 0x00000000,
89d974db0aSgarbled 	.pbs_limit = PREP_PHYS_SIZE_MEM,
90d974db0aSgarbled };
91d974db0aSgarbled 
92d974db0aSgarbled struct powerpc_bus_space genppc_isa_mem_space_tag = {
93d974db0aSgarbled 	.pbs_flags = _BUS_SPACE_LITTLE_ENDIAN|_BUS_SPACE_MEM_TYPE,
94d974db0aSgarbled 	.pbs_offset = PREP_BUS_SPACE_MEM,
95d974db0aSgarbled 	.pbs_base = 0x00000000,
96d974db0aSgarbled 	.pbs_limit = PREP_ISA_SIZE_MEM,
97d974db0aSgarbled };
98d974db0aSgarbled 
99d974db0aSgarbled static char ex_storage[2][EXTENT_FIXED_STORAGE_SIZE(8)]
100d974db0aSgarbled 	__attribute__((aligned(8)));
101d974db0aSgarbled 
102d974db0aSgarbled void
prep_bus_space_init(void)103d974db0aSgarbled prep_bus_space_init(void)
104d974db0aSgarbled {
105d974db0aSgarbled 	int error;
106d974db0aSgarbled 
107d974db0aSgarbled 	error = bus_space_init(&prep_io_space_tag, "ioport",
108d974db0aSgarbled 	    ex_storage[0], sizeof(ex_storage[0]));
109d974db0aSgarbled 	if (error)
110d974db0aSgarbled 		panic("prep_bus_space_init: can't init io tag");
111d974db0aSgarbled 
112d974db0aSgarbled 	error = extent_alloc_region(prep_io_space_tag.pbs_extent,
113d974db0aSgarbled 	    PREP_PHYS_RESVD_START_IO, PREP_PHYS_RESVD_SIZE_IO, EX_NOWAIT);
114d974db0aSgarbled 	if (error)
115d974db0aSgarbled 		panic("prep_bus_space_init: can't block out reserved I/O"
116d974db0aSgarbled 		    " space 0x10000-0x7fffff: error=%d", error);
117d974db0aSgarbled 
118d974db0aSgarbled 	error = bus_space_init(&prep_mem_space_tag, "iomem",
119d974db0aSgarbled 	    ex_storage[1], sizeof(ex_storage[1]));
120d974db0aSgarbled 	if (error)
121d974db0aSgarbled 		panic("prep_bus_space_init: can't init mem tag");
122d974db0aSgarbled 
123d974db0aSgarbled 	genppc_isa_io_space_tag.pbs_extent = prep_io_space_tag.pbs_extent;
124d974db0aSgarbled 	error = bus_space_init(&genppc_isa_io_space_tag, "isa-ioport", NULL, 0);	if (error)
125d974db0aSgarbled 		panic("prep_bus_space_init: can't init isa io tag");
126d974db0aSgarbled 
127d974db0aSgarbled 	genppc_isa_mem_space_tag.pbs_extent = prep_mem_space_tag.pbs_extent;
128d974db0aSgarbled 	error = bus_space_init(&genppc_isa_mem_space_tag, "isa-iomem", NULL, 0);
129d974db0aSgarbled 	if (error)
130d974db0aSgarbled 		panic("prep_bus_space_init: can't init isa mem tag");
131d974db0aSgarbled }
132d974db0aSgarbled 
133d974db0aSgarbled /*
134d974db0aSgarbled  * just a few calls used in initppc() all in one place so everything gets
135d974db0aSgarbled  * done the same across the ports
136d974db0aSgarbled  */
137d974db0aSgarbled 
138d974db0aSgarbled void
prep_initppc(u_long startkernel,u_long endkernel,u_int args,paddr_t pa,...)139*29878adaSthorpej prep_initppc(u_long startkernel, u_long endkernel, u_int args, paddr_t pa, ...)
140d974db0aSgarbled {
141*29878adaSthorpej 	va_list ap;
142d974db0aSgarbled 
143d974db0aSgarbled 	/*
144*29878adaSthorpej 	 * Set up fixed BAT registers.  We map the PReP IO and MEM
145*29878adaSthorpej 	 * space, plus any additional regions the platform wants.
146d974db0aSgarbled 	 */
147d974db0aSgarbled 	oea_batinit(
148d974db0aSgarbled 	    PREP_BUS_SPACE_MEM, BAT_BL_256M,
149d974db0aSgarbled 	    PREP_BUS_SPACE_IO,  BAT_BL_256M,
150d974db0aSgarbled 	    0);
151d974db0aSgarbled 
152*29878adaSthorpej 	va_start(ap, pa);
153*29878adaSthorpej 	while (pa != 0) {
154*29878adaSthorpej 		register_t len = va_arg(ap, register_t);
155*29878adaSthorpej 		oea_iobat_add(pa, len);
156*29878adaSthorpej 		pa = va_arg(ap, paddr_t);
157*29878adaSthorpej 	}
158*29878adaSthorpej 	va_end(ap);
159*29878adaSthorpej 
160d974db0aSgarbled 	/* Install vectors and interrupt handler. */
161d974db0aSgarbled 	oea_init(NULL);
162d974db0aSgarbled 
163d974db0aSgarbled 	/* Initialize bus_space. */
164d974db0aSgarbled 	prep_bus_space_init();
165d974db0aSgarbled 
166d974db0aSgarbled 	/* Initialize the console asap. */
167d974db0aSgarbled 	consinit();
168d974db0aSgarbled 
169d974db0aSgarbled 	/* Set the page size */
1700dec4042Scherry 	uvm_md_init();
171d974db0aSgarbled 
172d974db0aSgarbled 	/* Initialize pmap module */
173d974db0aSgarbled 	pmap_bootstrap(startkernel, endkernel);
174d974db0aSgarbled 
1750efea177Sad #if NKSYMS || defined(DDB) || defined(MODULAR)
176719a906eSmartin 	ksyms_addsyms_elf((int)((u_long)endsym - (u_long)startsym), startsym, endsym);
177d974db0aSgarbled #endif
178d974db0aSgarbled 
179d974db0aSgarbled #ifdef DDB
180d974db0aSgarbled 	boothowto = args;
181d974db0aSgarbled 	if (boothowto & RB_KDB)
182d974db0aSgarbled 		Debugger();
183d974db0aSgarbled #endif
184d974db0aSgarbled }
185d974db0aSgarbled 
186d974db0aSgarbled void
mem_regions(struct mem_region ** mem,struct mem_region ** avail)187d974db0aSgarbled mem_regions(struct mem_region **mem, struct mem_region **avail)
188d974db0aSgarbled {
189d974db0aSgarbled 
190d974db0aSgarbled 	*mem = physmemr;
191d974db0aSgarbled 	*avail = availmemr;
192d974db0aSgarbled }
193