1 /* $NetBSD: mainbus.c,v 1.1 2015/04/29 08:32:00 hikaru Exp $ */ 2 3 /* 4 * Copyright (c) 2007 5 * Internet Initiative Japan, Inc. 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 REGENTS AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __KERNEL_RCSID(0, "$NetBSD: mainbus.c,v 1.1 2015/04/29 08:32:00 hikaru Exp $"); 31 32 #include <sys/param.h> 33 #include <sys/systm.h> 34 #include <sys/device.h> 35 36 #include <mips/cavium/include/mainbusvar.h> 37 38 static int mainbus_match(device_t, struct cfdata *, void *); 39 static void mainbus_attach(device_t, device_t, void *); 40 static int mainbus_submatch(device_t, cfdata_t, const int *, void *); 41 static int mainbus_print(void *, const char *); 42 43 CFATTACH_DECL_NEW(mainbus, sizeof(device_t), mainbus_match, mainbus_attach, 44 NULL, NULL); 45 46 static int 47 mainbus_match(device_t parent, struct cfdata *match, void *aux) 48 { 49 static int once = 0; 50 51 if (once != 0) 52 return 0; 53 once = 1; 54 55 return 1; 56 } 57 58 static void 59 mainbus_attach(device_t parent, device_t self, void *aux) 60 { 61 int i; 62 struct mainbus_attach_args aa; 63 64 aprint_normal("\n"); 65 66 for (i = 0; i < (int)mainbus_ndevs; i++) { 67 aa.aa_name = mainbus_devs[i]; 68 (void)config_found_sm_loc(self, "mainbus", NULL, &aa, 69 mainbus_print, mainbus_submatch); 70 } 71 } 72 73 static int 74 mainbus_submatch(device_t parent, cfdata_t cf, const int *locs, void *aux) 75 { 76 struct mainbus_attach_args *aa = aux; 77 78 if (strcmp(cf->cf_name, aa->aa_name) != 0) 79 return 0; 80 81 return config_match(parent, cf, aux); 82 } 83 84 static int 85 mainbus_print(void *aux, const char *pnp) 86 { 87 struct mainbus_attach_args *aa = aux; 88 89 if (pnp != 0) 90 return QUIET; 91 92 if (pnp) 93 aprint_normal("%s at %s", aa->aa_name, pnp); 94 95 return UNCONF; 96 } 97