1 /* $NetBSD: autoconf.c,v 1.6 2002/10/02 05:06:53 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/param.h> 30 #include <sys/systm.h> 31 #include <sys/buf.h> 32 #include <sys/conf.h> 33 #include <sys/device.h> 34 #include <sys/device.h> 35 #include <sys/disklabel.h> 36 #include <sys/malloc.h> 37 #include <sys/mount.h> 38 #include <sys/queue.h> 39 #include <sys/reboot.h> 40 #include <sys/tty.h> 41 #include <sys/kernel.h> 42 43 #include <uvm/uvm_extern.h> 44 45 #include <machine/autoconf.h> 46 #include <machine/vmparam.h> 47 #include <machine/cpu.h> 48 #include <machine/pmap.h> 49 #include <machine/pte.h> 50 51 #include <cesfic/cesfic/isr.h> 52 53 struct device *booted_device; 54 int booted_partition; 55 56 u_int bootdev; 57 58 struct evcnt evcnt_fpsp_unimp, evcnt_fpsp_unsupp; 59 60 int mainbusmatch __P((struct device *, struct cfdata *, void *)); 61 void mainbusattach __P((struct device *, struct device *, void *)); 62 int mainbussearch __P((struct device *, struct cfdata *, void *)); 63 64 CFATTACH_DECL(mainbus, sizeof(struct device), 65 mainbusmatch, mainbusattach, NULL, NULL); 66 67 int 68 mainbusmatch(parent, match, aux) 69 struct device *parent; 70 struct cfdata *match; 71 void *aux; 72 { 73 static int mainbus_matched = 0; 74 75 /* Allow only one instance. */ 76 if (mainbus_matched) 77 return (0); 78 79 mainbus_matched = 1; 80 return (1); 81 } 82 83 void 84 mainbusattach(parent, self, aux) 85 struct device *parent, *self; 86 void *aux; 87 { 88 89 printf("\n"); 90 91 #ifdef FPSP /* XXX this shouldn't be here but in a "cpu" node */ 92 evcnt_attach(self, "fpuni", &evcnt_fpsp_unimp); 93 evcnt_attach(self, "fpund", &evcnt_fpsp_unsupp); 94 #endif 95 96 /* Search for and attach children. */ 97 config_search(mainbussearch, self, NULL); 98 } 99 100 int 101 mainbussearch(parent, cf, aux) 102 struct device *parent; 103 struct cfdata *cf; 104 void *aux; 105 { 106 107 if (config_match(parent, cf, NULL) > 0) 108 config_attach(parent, cf, NULL, NULL); 109 return (0); 110 } 111 112 int 113 mainbus_map(physaddr, size, cacheable, virtaddr) 114 u_long physaddr; 115 int size; 116 int cacheable; 117 void ** virtaddr; 118 { 119 120 u_long pa, endpa; 121 vm_offset_t va; 122 123 pa = m68k_trunc_page(physaddr); 124 endpa = m68k_round_page(physaddr + size); 125 126 #ifdef DIAGNOSTIC 127 if (endpa <= pa) 128 panic("bus_mem_add_mapping: overflow"); 129 #endif 130 131 va = uvm_km_valloc(kernel_map, endpa - pa); 132 if (va == 0) 133 return (ENOMEM); 134 135 *virtaddr = (void*)(va + (physaddr & PGOFSET)); 136 for (; pa < endpa; pa += NBPG, va += NBPG) { 137 pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE); 138 if (!cacheable) { 139 pt_entry_t *pte = kvtopte(va); 140 *pte |= PG_CI; 141 *pte &= ~PG_CCB; 142 } 143 } 144 145 return (0); 146 } 147 148 void 149 cpu_configure() 150 { 151 152 isrinit(); 153 154 (void)splhigh(); 155 if (config_rootfound("mainbus", "mainbus") == NULL) 156 panic("no mainbus found"); 157 158 (void)spl0(); 159 cold = 0; 160 161 isrprintlevels(); 162 } 163 164 void 165 cpu_rootconf() 166 { 167 setroot(0, 0); 168 } 169