1 /* $NetBSD: mainbus.c,v 1.32 2008/07/09 20:23:50 joerg Exp $ */ 2 3 /* 4 * Copyright (c) 1994, 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 32 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.32 2008/07/09 20:23:50 joerg Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/device.h> 37 #include <sys/reboot.h> 38 #include <sys/conf.h> 39 40 #include <machine/autoconf.h> 41 #include <machine/rpb.h> 42 #include <machine/cpuconf.h> 43 44 /* Definition of the mainbus driver. */ 45 static int mbmatch(device_t, cfdata_t, void *); 46 static void mbattach(device_t, device_t, void *); 47 static int mbprint(void *, const char *); 48 49 CFATTACH_DECL_NEW(mainbus, 0, mbmatch, mbattach, NULL, NULL); 50 51 /* There can be only one. */ 52 int mainbus_found; 53 54 static int 55 mbmatch(device_t parent, cfdata_t cf, void *aux) 56 { 57 58 if (mainbus_found) 59 return (0); 60 61 return (1); 62 } 63 64 static void 65 mbattach(device_t parent, device_t self, void *aux) 66 { 67 struct mainbus_attach_args ma; 68 struct pcs *pcsp; 69 int i, cpuattachcnt; 70 extern int ncpus; 71 72 mainbus_found = 1; 73 74 printf("\n"); 75 76 /* 77 * Try to find and attach all of the CPUs in the machine. 78 */ 79 cpuattachcnt = 0; 80 for (i = 0; i < hwrpb->rpb_pcs_cnt; i++) { 81 pcsp = LOCATE_PCS(hwrpb, i); 82 if ((pcsp->pcs_flags & PCS_PP) == 0) 83 continue; 84 85 ma.ma_name = "cpu"; 86 ma.ma_slot = i; 87 if (config_found(self, &ma, mbprint) != NULL) 88 cpuattachcnt++; 89 } 90 if (ncpus != cpuattachcnt) 91 printf("WARNING: %d cpus in machine, %d attached\n", 92 ncpus, cpuattachcnt); 93 94 if (platform.iobus != NULL) { 95 ma.ma_name = platform.iobus; 96 ma.ma_slot = 0; /* meaningless */ 97 config_found(self, &ma, mbprint); 98 } 99 } 100 101 static int 102 mbprint(void *aux, const char *pnp) 103 { 104 struct mainbus_attach_args *ma = aux; 105 106 if (pnp) 107 aprint_normal("%s at %s", ma->ma_name, pnp); 108 109 return (UNCONF); 110 } 111