1 /* $Id: exb.c,v 1.2 2010/11/06 16:30:15 uebayasi Exp $ */ 2 3 /*- 4 * Copyright (c) 2010 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software developed for The NetBSD Foundation 8 * by Masao Uebayashi. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 #include <sys/cdefs.h> 33 __KERNEL_RCSID(0, "$NetBSD: exb.c,v 1.2 2010/11/06 16:30:15 uebayasi Exp $"); 34 35 #include "locators.h" 36 37 #include <sys/param.h> 38 #include <sys/systm.h> 39 #include <sys/device.h> 40 #include <sys/extent.h> 41 #include <sys/bus.h> 42 43 #include <powerpc/ibm4xx/dcr4xx.h> 44 #include <powerpc/ibm4xx/dev/exbvar.h> 45 46 struct exb_softc { 47 }; 48 49 extern const struct exb_conf exb_confs[]; 50 51 static int exb_match(device_t, struct cfdata *, void *); 52 static void exb_attach(device_t, struct device *, void *); 53 static int exb_print(void *, const char *); 54 55 CFATTACH_DECL_NEW(exb, sizeof(struct exb_softc), exb_match, exb_attach, 56 NULL, NULL); 57 58 static struct powerpc_bus_space exb_bus_space_tag = 59 { _BUS_SPACE_BIG_ENDIAN | _BUS_SPACE_MEM_TYPE, 0 }; 60 61 static int 62 exb_match(device_t parent, struct cfdata *cf, void *aux) 63 { 64 65 return 1; 66 } 67 68 static void 69 exb_attach(device_t parent, device_t self, void *aux) 70 { 71 const struct exb_conf *ec = exb_confs; 72 uint32_t ebc0_bNcr; 73 bus_addr_t base, size; 74 int locs[EXBCF_NLOCS]; 75 76 printf("\n"); 77 78 /* mtdcr needs a constant */ 79 switch (device_unit(self)) { 80 case 0: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B0CR); break; 81 case 1: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B1CR); break; 82 case 2: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B2CR); break; 83 case 3: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B3CR); break; 84 case 4: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B4CR); break; 85 case 5: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B5CR); break; 86 case 6: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B6CR); break; 87 case 7: mtdcr(DCR_EBC0_CFGADDR, DCR_EBC0_B7CR); break; 88 } 89 ebc0_bNcr = mfdcr(DCR_EBC0_CFGDATA); 90 base = ebc0_bNcr & 0xfff00000; 91 size = 0x00100000 << ((ebc0_bNcr & 0x000e0000) >> 17); 92 93 exb_bus_space_tag.pbs_base = base; 94 exb_bus_space_tag.pbs_limit = base + size - 1; 95 96 while (ec->ec_name) { 97 struct exb_conf ec1; 98 99 locs[EXBCF_ADDR] = ec->ec_addr; 100 101 ec1 = *ec; 102 ec1.ec_bust = exb_get_bus_space_tag(); 103 104 config_found_sm_loc(self, "exb", locs, &ec1, exb_print, 105 config_stdsubmatch); 106 ec++; 107 } 108 } 109 110 static int 111 exb_print(void *aux, const char *bus) 112 { 113 struct exb_conf *ec = aux; 114 115 if (bus) 116 return QUIET; 117 118 if (ec->ec_addr) 119 printf(" addr %"PRIxBUSADDR, ec->ec_addr); 120 121 return UNCONF; 122 } 123 124 bus_space_tag_t 125 exb_get_bus_space_tag(void) 126 { 127 static char ex_storage[EXTENT_FIXED_STORAGE_SIZE(8)] 128 __attribute__((aligned(8))); 129 static int exb_bus_space_tag_inited; 130 131 if (exb_bus_space_tag_inited == 0) { 132 if (bus_space_init(&exb_bus_space_tag, "exbtag", 133 ex_storage, sizeof(ex_storage))) 134 panic("exb_attach: Failed to initialise exb_bus_space_tag"); 135 exb_bus_space_tag_inited = 1; 136 } 137 return &exb_bus_space_tag; 138 } 139