zbbus.c revision 1.1
1/* $NetBSD: zbbus.c,v 1.1 2002/03/06 02:13:52 simonb Exp $ */ 2 3/* 4 * Copyright 2000, 2001 5 * Broadcom Corporation. All rights reserved. 6 * 7 * This software is furnished under license and may be used and copied only 8 * in accordance with the following terms and conditions. Subject to these 9 * conditions, you may download, copy, install, use, modify and distribute 10 * modified or unmodified copies of this software in source and/or binary 11 * form. No title or ownership is transferred hereby. 12 * 13 * 1) Any source code used, modified or distributed must reproduce and 14 * retain this copyright notice and list of conditions as they appear in 15 * the source file. 16 * 17 * 2) No right is granted to use any trade name, trademark, or logo of 18 * Broadcom Corporation. Neither the "Broadcom Corporation" name nor any 19 * trademark or logo of Broadcom Corporation may be used to endorse or 20 * promote products derived from this software without the prior written 21 * permission of Broadcom Corporation. 22 * 23 * 3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR IMPLIED 24 * WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR 26 * NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT SHALL BROADCOM BE LIABLE 27 * FOR ANY DAMAGES WHATSOEVER, AND IN PARTICULAR, BROADCOM SHALL NOT BE 28 * LIABLE FOR DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 29 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 30 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 31 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 32 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 33 * OR OTHERWISE), EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 */ 35 36#include <sys/param.h> 37#include <sys/systm.h> 38#include <sys/device.h> 39 40#include <mips/sibyte/include/zbbusvar.h> 41 42#include "locators.h" 43 44static int zbbus_match(struct device *, struct cfdata *, void *); 45static void zbbus_attach(struct device *, struct device *, void *); 46 47struct cfattach zbbus_ca = { 48 sizeof(struct device), zbbus_match, zbbus_attach 49}; 50 51static int zbbus_print(void *, const char *); 52static int zbbus_submatch(struct device *, struct cfdata *, void *); 53static const char *zbbus_entity_type_name(enum zbbus_entity_type type); 54 55static int zbbus_attached; 56 57static const struct zbbus_attach_locs sb1250_zbbus_devs[] = { 58 { 0, ZBBUS_ENTTYPE_CPU }, 59 { 1, ZBBUS_ENTTYPE_CPU }, 60 { 4, ZBBUS_ENTTYPE_SCD }, 61 { 2, ZBBUS_ENTTYPE_BRZ }, 62 { 3, ZBBUS_ENTTYPE_OBIO }, 63}; 64static const int sb1250_zbbus_dev_count = 65 sizeof sb1250_zbbus_devs / sizeof sb1250_zbbus_devs[0]; 66 67static int 68zbbus_match(struct device *parent, struct cfdata *match, void *aux) 69{ 70 71 if (zbbus_attached) 72 return (0); 73 return 1; 74} 75 76static void 77zbbus_attach(struct device *parent, struct device *self, void *aux) 78{ 79 struct zbbus_attach_args za; 80 int i; 81 82 printf("\n"); 83 zbbus_attached = 1; 84 85 sb1250_icu_init(); 86 87 for (i = 0; i < sb1250_zbbus_dev_count; i++) { 88 memset(&za, 0, sizeof za); 89 za.za_locs = sb1250_zbbus_devs[i]; 90 config_found_sm(self, &za, zbbus_print, zbbus_submatch); 91 } 92 93 return; 94} 95 96int 97zbbus_print(void *aux, const char *pnp) 98{ 99 struct zbbus_attach_args *zap = aux; 100 101 if (pnp) 102 printf("%s at %s", 103 zbbus_entity_type_name(zap->za_locs.za_type), pnp); 104 printf(" busid %d", zap->za_locs.za_busid); 105 return (UNCONF); 106} 107 108static int 109zbbus_submatch(struct device *parent, struct cfdata *cf, void *aux) 110{ 111 struct zbbus_attach_args *zap = aux; 112 113 if (cf->cf_loc[ZBBUSCF_BUSID] != ZBBUSCF_BUSID_DEFAULT && 114 cf->cf_loc[ZBBUSCF_BUSID] != zap->za_locs.za_busid) 115 return (0); 116 117 return ((*cf->cf_attach->ca_match)(parent, cf, aux)); 118} 119 120static const char * 121zbbus_entity_type_name(enum zbbus_entity_type type) 122{ 123 124 switch (type) { 125 case ZBBUS_ENTTYPE_CPU: 126 return ("cpu"); 127 case ZBBUS_ENTTYPE_SCD: 128 return ("sbscd"); 129 case ZBBUS_ENTTYPE_BRZ: 130 return ("sbbrz"); 131 case ZBBUS_ENTTYPE_OBIO: 132 return ("sbobio"); 133 } 134 panic("zbbus_entity_type_name"); 135 return ("panic"); 136} 137