1 /* $OpenBSD: lca.c,v 1.23 2013/06/04 19:12:34 miod Exp $ */ 2 /* $NetBSD: lca.c,v 1.14 1996/12/05 01:39:35 cgd Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 35 * All rights reserved. 36 * 37 * Authors: Jeffrey Hsu and Chris G. Demetriou 38 * 39 * Permission to use, copy, modify and distribute this software and 40 * its documentation is hereby granted, provided that both the copyright 41 * notice and this permission notice appear in all copies of the 42 * software, derivative works or modified versions, and any portions 43 * thereof, and that both notices appear in supporting documentation. 44 * 45 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 46 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 47 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 48 * 49 * Carnegie Mellon requests users of this software to return to 50 * 51 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 52 * School of Computer Science 53 * Carnegie Mellon University 54 * Pittsburgh PA 15213-3890 55 * 56 * any improvements or extensions that they make and grant Carnegie the 57 * rights to redistribute these changes. 58 */ 59 60 #include <sys/param.h> 61 #include <sys/systm.h> 62 #include <sys/kernel.h> 63 #include <sys/malloc.h> 64 #include <sys/device.h> 65 66 #include <uvm/uvm_extern.h> 67 68 #include <machine/autoconf.h> 69 #include <machine/cpuconf.h> 70 #include <machine/rpb.h> 71 72 #include <dev/isa/isareg.h> 73 #include <dev/isa/isavar.h> 74 75 #include <dev/pci/pcireg.h> 76 #include <dev/pci/pcivar.h> 77 #include <alpha/pci/lcareg.h> 78 #include <alpha/pci/lcavar.h> 79 #ifdef DEC_AXPPCI_33 80 #include <alpha/pci/pci_axppci_33.h> 81 #endif 82 #ifdef DEC_ALPHABOOK1 83 #include <alpha/pci/pci_alphabook1.h> 84 #endif 85 #ifdef DEC_EB66 86 #include <alpha/pci/pci_eb66.h> 87 #endif 88 89 int lcamatch(struct device *, void *, void *); 90 void lcaattach(struct device *, struct device *, void *); 91 92 struct cfattach lca_ca = { 93 sizeof(struct device), lcamatch, lcaattach, 94 }; 95 96 struct cfdriver lca_cd = { 97 NULL, "lca", DV_DULL, 98 }; 99 100 int lcaprint(void *, const char *pnp); 101 102 #if 0 103 int lca_bus_get_window(int, int, 104 struct alpha_bus_space_translation *); 105 #endif 106 void lca_machine_check(unsigned long, struct trapframe *, unsigned long, 107 unsigned long); 108 109 /* There can be only one. */ 110 int lcafound; 111 struct lca_config lca_configuration; 112 113 int 114 lcamatch(parent, match, aux) 115 struct device *parent; 116 void *match; 117 void *aux; 118 { 119 struct mainbus_attach_args *ma = aux; 120 121 /* Make sure that we're looking for a LCA. */ 122 if (strcmp(ma->ma_name, lca_cd.cd_name) != 0) 123 return (0); 124 125 if (lcafound) 126 return (0); 127 128 return (1); 129 } 130 131 /* 132 * Set up the chipset's function pointers. 133 */ 134 void 135 lca_init(lcp, mallocsafe) 136 struct lca_config *lcp; 137 int mallocsafe; 138 { 139 140 /* 141 * The LCA HAE register is WRITE-ONLY, so we can't tell where 142 * the second sparse window is actually mapped. Therefore, 143 * we have to guess where it is. This seems to be the normal 144 * address. 145 */ 146 lcp->lc_s_mem_w2_masked_base = 0x80000000; 147 148 if (!lcp->lc_initted) { 149 /* don't do these twice since they set up extents */ 150 lca_bus_io_init(&lcp->lc_iot, lcp); 151 lca_bus_mem_init(&lcp->lc_memt, lcp); 152 153 #if 0 154 /* 155 * We have 1 I/O window and 3 MEM windows. 156 */ 157 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1; 158 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3; 159 alpha_bus_get_window = lca_bus_get_window; 160 #endif 161 } 162 lcp->lc_mallocsafe = mallocsafe; 163 164 lca_pci_init(&lcp->lc_pc, lcp); 165 alpha_pci_chipset = &lcp->lc_pc; 166 alpha_pci_chipset->pc_name = "lca"; 167 alpha_pci_chipset->pc_mem = LCA_PCI_SPARSE; 168 alpha_pci_chipset->pc_ports = LCA_PCI_SIO; 169 alpha_pci_chipset->pc_hae_mask = IOC_HAE_ADDREXT; 170 alpha_pci_chipset->pc_dense = LCA_PCI_DENSE; 171 alpha_pci_chipset->pc_bwx = 0; 172 173 /* 174 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors 175 * Hardware Reference Manual''. 176 * ... 177 */ 178 179 /* 180 * According to section 6.4.1, all bits of the IOC_HAE register are 181 * undefined after reset. Bits <31:27> are write-only. However, we 182 * cannot blindly set it to zero. The serial ROM code that initializes 183 * the PCI devices' address spaces, allocates sparse memory blocks in 184 * the range that must use the IOC_HAE register for address translation, 185 * and sets this register accordingly (see section 6.4.14). 186 * 187 * IOC_HAE left AS IS. 188 */ 189 190 /* 191 * According to section 6.4.2, all bits of the IOC_CONF register are 192 * undefined after reset. Bits <1:0> are write-only. Set them to 193 * 0x00 for PCI Type 0 configuration access. 194 * 195 * IOC_CONF set to ZERO. 196 */ 197 REGVAL64(LCA_IOC_CONF) = 0; 198 199 /* 200 * Disable parity on the bus. According to Linux, on some systems, 201 * siop(4) behaves badly unless parity is disabled. 202 */ 203 REGVAL64(LCA_IOC_PAR_DIS) = IOC_PAR_DISABLE; 204 205 lcp->lc_initted = 1; 206 } 207 208 void 209 lcaattach(parent, self, aux) 210 struct device *parent, *self; 211 void *aux; 212 { 213 struct lca_config *lcp; 214 struct pcibus_attach_args pba; 215 216 /* note that we've attached the chipset; can't have 2 LCAs. */ 217 /* Um, not sure about this. XXX JH */ 218 lcafound = 1; 219 220 /* 221 * set up the chipset's info; done once at console init time 222 * (maybe), but we must do it twice to take care of things 223 * that need to use memory allocation. 224 */ 225 lcp = &lca_configuration; 226 lca_init(lcp, 1); 227 228 /* XXX print chipset information */ 229 printf("\n"); 230 231 lca_dma_init(lcp); 232 233 /* safe to override since LCA machines do not set mcheck_handler */ 234 platform.mcheck_handler = lca_machine_check; 235 236 switch (cputype) { 237 #ifdef DEC_AXPPCI_33 238 case ST_DEC_AXPPCI_33: 239 pci_axppci_33_pickintr(lcp); 240 break; 241 #endif 242 #ifdef DEC_ALPHABOOK1 243 case ST_ALPHABOOK1: 244 pci_alphabook1_pickintr(lcp); 245 break; 246 #endif 247 #ifdef DEC_EB66 248 case ST_EB66: 249 pci_eb66_pickintr(lcp); 250 break; 251 #endif 252 253 default: 254 panic("lcaattach: shouldn't be here, really..."); 255 } 256 257 bzero(&pba, sizeof(pba)); 258 pba.pba_busname = "pci"; 259 pba.pba_iot = &lcp->lc_iot; 260 pba.pba_memt = &lcp->lc_memt; 261 pba.pba_dmat = 262 alphabus_dma_get_tag(&lcp->lc_dmat_direct, ALPHA_BUS_PCI); 263 pba.pba_pc = &lcp->lc_pc; 264 pba.pba_domain = pci_ndomains++; 265 pba.pba_bus = 0; 266 #ifdef notyet 267 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED | 268 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 269 #endif 270 config_found(self, &pba, lcaprint); 271 } 272 273 int 274 lcaprint(aux, pnp) 275 void *aux; 276 const char *pnp; 277 { 278 register struct pcibus_attach_args *pba = aux; 279 280 /* only PCIs can attach to LCAes; easy. */ 281 if (pnp) 282 printf("%s at %s", pba->pba_busname, pnp); 283 printf(" bus %d", pba->pba_bus); 284 return (UNCONF); 285 } 286 287 #if 0 288 int 289 lca_bus_get_window(type, window, abst) 290 int type, window; 291 struct alpha_bus_space_translation *abst; 292 { 293 struct lca_config *lcp = &lca_configuration; 294 bus_space_tag_t st; 295 296 switch (type) { 297 case ALPHA_BUS_TYPE_PCI_IO: 298 st = &lcp->lc_iot; 299 break; 300 301 case ALPHA_BUS_TYPE_PCI_MEM: 302 st = &lcp->lc_memt; 303 break; 304 305 default: 306 panic("lca_bus_get_window"); 307 } 308 309 return (alpha_bus_space_get_window(st, window, abst)); 310 } 311 #endif 312 313 void 314 lca_machine_check(unsigned long mces, struct trapframe *framep, 315 unsigned long vector, unsigned long param) 316 { 317 int64_t stat0; 318 319 machine_check(mces, framep, vector, param); 320 /* clear error flags in IOC_STATUS0 register */ 321 stat0 = REGVAL64(LCA_IOC_STAT0); 322 REGVAL64(LCA_IOC_STAT0) = stat0; 323 } 324