1 /* $NetBSD: autoconf.c,v 1.30 2023/12/20 00:40:43 thorpej Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1999
5 * Matthias Drochner. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: autoconf.c,v 1.30 2023/12/20 00:40:43 thorpej Exp $");
31
32 #include <sys/param.h>
33 #include <sys/systm.h>
34 #include <sys/buf.h>
35 #include <sys/conf.h>
36 #include <sys/device.h>
37 #include <sys/disklabel.h>
38 #include <sys/mount.h>
39 #include <sys/queue.h>
40 #include <sys/reboot.h>
41 #include <sys/tty.h>
42 #include <sys/kernel.h>
43
44 #include <uvm/uvm_extern.h>
45
46 #include <machine/autoconf.h>
47 #include <machine/vmparam.h>
48 #include <machine/cpu.h>
49 #include <machine/pmap.h>
50 #include <machine/pte.h>
51 #include <m68k/cacheops.h>
52
53 #include <cesfic/cesfic/isr.h>
54
55 u_int bootdev;
56
57 struct evcnt evcnt_fpsp_unimp, evcnt_fpsp_unsupp;
58
59 int mainbusmatch(device_t, cfdata_t, void *);
60 void mainbusattach(device_t, device_t, void *);
61 int mainbussearch(device_t, cfdata_t, const int *, void *);
62
63 CFATTACH_DECL_NEW(mainbus, 0,
64 mainbusmatch, mainbusattach, NULL, NULL);
65
66 int
mainbusmatch(device_t parent,cfdata_t match,void * aux)67 mainbusmatch(device_t parent, cfdata_t match, void *aux)
68 {
69 static bool mainbus_matched;
70
71 /* Allow only one instance. */
72 if (mainbus_matched)
73 return (0);
74
75 mainbus_matched = true;
76 return (1);
77 }
78
79 void
mainbusattach(device_t parent,device_t self,void * aux)80 mainbusattach(device_t parent, device_t self, void *aux)
81 {
82
83 printf("\n");
84
85 #ifdef FPSP /* XXX this shouldn't be here but in a "cpu" node */
86 evcnt_attach(self, "fpuni", &evcnt_fpsp_unimp);
87 evcnt_attach(self, "fpund", &evcnt_fpsp_unsupp);
88 #endif
89
90 /* Search for and attach children. */
91 config_search(self, NULL,
92 CFARGS(.search = mainbussearch));
93 }
94
95 int
mainbussearch(device_t parent,cfdata_t cf,const int * ldesc,void * aux)96 mainbussearch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
97 {
98
99 if (config_probe(parent, cf, NULL))
100 config_attach(parent, cf, NULL, NULL, CFARGS_NONE);
101 return (0);
102 }
103
104 int
mainbus_map(u_long physaddr,int size,int cacheable,void ** virtaddr)105 mainbus_map(u_long physaddr, int size, int cacheable, void ** virtaddr)
106 {
107
108 u_long pa, endpa;
109 vm_offset_t va;
110
111 pa = m68k_trunc_page(physaddr);
112 endpa = m68k_round_page(physaddr + size);
113
114 #ifdef DIAGNOSTIC
115 if (endpa <= pa)
116 panic("bus_mem_add_mapping: overflow");
117 #endif
118
119 va = uvm_km_alloc(kernel_map, endpa - pa, 0, UVM_KMF_VAONLY);
120 if (va == 0)
121 return (ENOMEM);
122
123 *virtaddr = (void*)(va + (physaddr & PGOFSET));
124 for (; pa < endpa; pa += PAGE_SIZE, va += PAGE_SIZE) {
125 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE, 0);
126 if (!cacheable) {
127 pt_entry_t *pte = kvtopte(va);
128 *pte |= PG_CI;
129 *pte &= ~PG_CCB;
130 }
131 }
132 TBIAS();
133
134 return (0);
135 }
136
137 void
cpu_configure(void)138 cpu_configure(void)
139 {
140
141 isrinit();
142
143 (void)splhigh();
144 if (config_rootfound("mainbus", NULL) == NULL)
145 panic("no mainbus found");
146
147 (void)spl0();
148 }
149
150 void
cpu_rootconf(void)151 cpu_rootconf(void)
152 {
153 rootconf();
154 }
155