1 /* $NetBSD: lca.c,v 1.47 2009/03/14 21:04:02 dsl Exp $ */ 2 3 /*- 4 * Copyright (c) 2000 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Jason R. Thorpe. 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 /* 33 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 34 * All rights reserved. 35 * 36 * Authors: Jeffrey Hsu and Chris G. Demetriou 37 * 38 * Permission to use, copy, modify and distribute this software and 39 * its documentation is hereby granted, provided that both the copyright 40 * notice and this permission notice appear in all copies of the 41 * software, derivative works or modified versions, and any portions 42 * thereof, and that both notices appear in supporting documentation. 43 * 44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 46 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 47 * 48 * Carnegie Mellon requests users of this software to return to 49 * 50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 51 * School of Computer Science 52 * Carnegie Mellon University 53 * Pittsburgh PA 15213-3890 54 * 55 * any improvements or extensions that they make and grant Carnegie the 56 * rights to redistribute these changes. 57 */ 58 59 #include "opt_dec_axppci_33.h" 60 #include "opt_dec_alphabook1.h" 61 #include "opt_dec_eb66.h" 62 63 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 64 65 __KERNEL_RCSID(0, "$NetBSD: lca.c,v 1.47 2009/03/14 21:04:02 dsl Exp $"); 66 67 #include <sys/param.h> 68 #include <sys/systm.h> 69 #include <sys/kernel.h> 70 #include <sys/malloc.h> 71 #include <sys/device.h> 72 73 #include <uvm/uvm_extern.h> 74 75 #include <machine/autoconf.h> 76 #include <machine/rpb.h> 77 #include <machine/sysarch.h> 78 79 #include <dev/isa/isareg.h> 80 #include <dev/isa/isavar.h> 81 82 #include <dev/pci/pcireg.h> 83 #include <dev/pci/pcivar.h> 84 #include <alpha/pci/lcareg.h> 85 #include <alpha/pci/lcavar.h> 86 #ifdef DEC_AXPPCI_33 87 #include <alpha/pci/pci_axppci_33.h> 88 #endif 89 #ifdef DEC_ALPHABOOK1 90 #include <alpha/pci/pci_alphabook1.h> 91 #endif 92 #ifdef DEC_EB66 93 #include <alpha/pci/pci_eb66.h> 94 #endif 95 96 int lcamatch(struct device *, struct cfdata *, void *); 97 void lcaattach(struct device *, struct device *, void *); 98 99 CFATTACH_DECL(lca, sizeof(struct lca_softc), 100 lcamatch, lcaattach, NULL, NULL); 101 102 extern struct cfdriver lca_cd; 103 104 int lca_bus_get_window(int, int, 105 struct alpha_bus_space_translation *); 106 107 /* There can be only one. */ 108 int lcafound; 109 struct lca_config lca_configuration; 110 111 int 112 lcamatch(struct device *parent, struct cfdata *match, void *aux) 113 { 114 struct mainbus_attach_args *ma = aux; 115 116 /* Make sure that we're looking for a LCA. */ 117 if (strcmp(ma->ma_name, lca_cd.cd_name) != 0) 118 return (0); 119 120 if (lcafound) 121 return (0); 122 123 return (1); 124 } 125 126 /* 127 * Set up the chipset's function pointers. 128 */ 129 void 130 lca_init(struct lca_config *lcp, int mallocsafe) 131 { 132 133 /* 134 * The LCA HAE register is WRITE-ONLY, so we can't tell where 135 * the second sparse window is actually mapped. Therefore, 136 * we have to guess where it is. This seems to be the normal 137 * address. 138 */ 139 lcp->lc_s_mem_w2_masked_base = 0x80000000; 140 141 if (!lcp->lc_initted) { 142 /* don't do these twice since they set up extents */ 143 lca_bus_io_init(&lcp->lc_iot, lcp); 144 lca_bus_mem_init(&lcp->lc_memt, lcp); 145 146 /* 147 * We have 1 I/O window and 3 MEM windows. 148 */ 149 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_IO] = 1; 150 alpha_bus_window_count[ALPHA_BUS_TYPE_PCI_MEM] = 3; 151 alpha_bus_get_window = lca_bus_get_window; 152 } 153 lcp->lc_mallocsafe = mallocsafe; 154 155 lca_pci_init(&lcp->lc_pc, lcp); 156 alpha_pci_chipset = &lcp->lc_pc; 157 158 /* 159 * Refer to ``DECchip 21066 and DECchip 21068 Alpha AXP Microprocessors 160 * Hardware Reference Manual''. 161 * ... 162 */ 163 164 /* 165 * According to section 6.4.1, all bits of the IOC_HAE register are 166 * undefined after reset. Bits <31:27> are write-only. However, we 167 * cannot blindly set it to zero. The serial ROM code that initializes 168 * the PCI devices' address spaces, allocates sparse memory blocks in 169 * the range that must use the IOC_HAE register for address translation, 170 * and sets this register accordingly (see section 6.4.14). 171 * 172 * IOC_HAE left AS IS. 173 */ 174 175 /* According to section 6.4.2, all bits of the IOC_CONF register are 176 * undefined after reset. Bits <1:0> are write-only. Set them to 177 * 0x00 for PCI Type 0 configuration access. 178 * 179 * IOC_CONF set to ZERO. 180 */ 181 REGVAL64(LCA_IOC_CONF) = 0; 182 183 lcp->lc_initted = 1; 184 } 185 186 void 187 lcaattach(struct device *parent, struct device *self, void *aux) 188 { 189 struct lca_softc *sc = (struct lca_softc *)self; 190 struct lca_config *lcp; 191 struct pcibus_attach_args pba; 192 193 /* note that we've attached the chipset; can't have 2 LCAs. */ 194 /* Um, not sure about this. XXX JH */ 195 lcafound = 1; 196 197 /* 198 * set up the chipset's info; done once at console init time 199 * (maybe), but we must do it twice to take care of things 200 * that need to use memory allocation. 201 */ 202 lcp = sc->sc_lcp = &lca_configuration; 203 lca_init(lcp, 1); 204 205 /* XXX print chipset information */ 206 printf("\n"); 207 208 lca_dma_init(lcp); 209 210 switch (cputype) { 211 #ifdef DEC_AXPPCI_33 212 case ST_DEC_AXPPCI_33: 213 pci_axppci_33_pickintr(lcp); 214 break; 215 #endif 216 #ifdef DEC_ALPHABOOK1 217 case ST_ALPHABOOK1: 218 pci_alphabook1_pickintr(lcp); 219 break; 220 #endif 221 #ifdef DEC_EB66 222 case ST_EB66: 223 pci_eb66_pickintr(lcp); 224 break; 225 #endif 226 227 default: 228 panic("lcaattach: shouldn't be here, really..."); 229 } 230 231 pba.pba_iot = &lcp->lc_iot; 232 pba.pba_memt = &lcp->lc_memt; 233 pba.pba_dmat = 234 alphabus_dma_get_tag(&lcp->lc_dmat_direct, ALPHA_BUS_PCI); 235 pba.pba_dmat64 = NULL; 236 pba.pba_pc = &lcp->lc_pc; 237 pba.pba_bus = 0; 238 pba.pba_bridgetag = NULL; 239 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED | 240 PCI_FLAGS_MRL_OKAY | PCI_FLAGS_MRM_OKAY | PCI_FLAGS_MWI_OKAY; 241 config_found_ia(self, "pcibus", &pba, pcibusprint); 242 } 243 244 int 245 lca_bus_get_window(int type, int window, struct alpha_bus_space_translation *abst) 246 { 247 struct lca_config *lcp = &lca_configuration; 248 bus_space_tag_t st; 249 250 switch (type) { 251 case ALPHA_BUS_TYPE_PCI_IO: 252 st = &lcp->lc_iot; 253 break; 254 255 case ALPHA_BUS_TYPE_PCI_MEM: 256 st = &lcp->lc_memt; 257 break; 258 259 default: 260 panic("lca_bus_get_window"); 261 } 262 263 return (alpha_bus_space_get_window(st, window, abst)); 264 } 265