cia_pci.c revision 1.23.10.1
1/* $NetBSD: cia_pci.c,v 1.23.10.1 1999/07/01 23:00:57 thorpej Exp $ */ 2 3/* 4 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 5 * All rights reserved. 6 * 7 * Author: Chris G. Demetriou 8 * 9 * Permission to use, copy, modify and distribute this software and 10 * its documentation is hereby granted, provided that both the copyright 11 * notice and this permission notice appear in all copies of the 12 * software, derivative works or modified versions, and any portions 13 * thereof, and that both notices appear in supporting documentation. 14 * 15 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 16 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 17 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 18 * 19 * Carnegie Mellon requests users of this software to return to 20 * 21 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 22 * School of Computer Science 23 * Carnegie Mellon University 24 * Pittsburgh PA 15213-3890 25 * 26 * any improvements or extensions that they make and grant Carnegie the 27 * rights to redistribute these changes. 28 */ 29 30#include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 31 32__KERNEL_RCSID(0, "$NetBSD: cia_pci.c,v 1.23.10.1 1999/07/01 23:00:57 thorpej Exp $"); 33 34#include <sys/param.h> 35#include <sys/systm.h> 36#include <sys/kernel.h> 37#include <sys/device.h> 38#include <vm/vm.h> 39 40#include <dev/pci/pcireg.h> 41#include <dev/pci/pcivar.h> 42#include <alpha/pci/ciareg.h> 43#include <alpha/pci/ciavar.h> 44 45void cia_attach_hook __P((struct device *, struct device *, 46 struct pcibus_attach_args *)); 47int cia_bus_maxdevs __P((void *, int)); 48pcitag_t cia_make_tag __P((void *, int, int, int)); 49void cia_decompose_tag __P((void *, pcitag_t, int *, int *, 50 int *)); 51pcireg_t cia_conf_read __P((void *, pcitag_t, int)); 52void cia_conf_write __P((void *, pcitag_t, int, pcireg_t)); 53 54void 55cia_pci_init(pc, v) 56 pci_chipset_tag_t pc; 57 void *v; 58{ 59 60 pc->pc_conf_v = v; 61 pc->pc_attach_hook = cia_attach_hook; 62 pc->pc_bus_maxdevs = cia_bus_maxdevs; 63 pc->pc_make_tag = cia_make_tag; 64 pc->pc_decompose_tag = cia_decompose_tag; 65 pc->pc_conf_read = cia_conf_read; 66 pc->pc_conf_write = cia_conf_write; 67} 68 69void 70cia_attach_hook(parent, self, pba) 71 struct device *parent, *self; 72 struct pcibus_attach_args *pba; 73{ 74} 75 76int 77cia_bus_maxdevs(cpv, busno) 78 void *cpv; 79 int busno; 80{ 81 82 return 32; 83} 84 85pcitag_t 86cia_make_tag(cpv, b, d, f) 87 void *cpv; 88 int b, d, f; 89{ 90 91 return (b << 16) | (d << 11) | (f << 8); 92} 93 94void 95cia_decompose_tag(cpv, tag, bp, dp, fp) 96 void *cpv; 97 pcitag_t tag; 98 int *bp, *dp, *fp; 99{ 100 101 if (bp != NULL) 102 *bp = (tag >> 16) & 0xff; 103 if (dp != NULL) 104 *dp = (tag >> 11) & 0x1f; 105 if (fp != NULL) 106 *fp = (tag >> 8) & 0x7; 107} 108 109pcireg_t 110cia_conf_read(cpv, tag, offset) 111 void *cpv; 112 pcitag_t tag; 113 int offset; 114{ 115 struct cia_config *ccp = cpv; 116 pcireg_t *datap, data; 117 int s, secondary, ba; 118 u_int32_t old_cfg, errbits; 119 120#ifdef __GNUC__ 121 s = 0; /* XXX gcc -Wuninitialized */ 122 old_cfg = 0; /* XXX gcc -Wuninitialized */ 123#endif 124 125 /* 126 * Some (apparently-common) revisions of EB164 and AlphaStation 127 * firmware do the Wrong thing with PCI master and target aborts, 128 * which are caused by accesing the configuration space of devices 129 * that don't exist (for example). 130 * 131 * To work around this, we clear the CIA error register's PCI 132 * master and target abort bits before touching PCI configuration 133 * space and check it afterwards. If it indicates a master or target 134 * abort, the device wasn't there so we return 0xffffffff. 135 */ 136 REGVAL(CIA_CSR_CIA_ERR) = CIA_ERR_RCVD_MAS_ABT|CIA_ERR_RCVD_TAR_ABT; 137 alpha_mb(); 138 alpha_pal_draina(); 139 140 /* secondary if bus # != 0 */ 141 alpha_pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0); 142 if (secondary) { 143 s = splhigh(); 144 old_cfg = REGVAL(CIA_CSR_CFG); 145 alpha_mb(); 146 REGVAL(CIA_CSR_CFG) = old_cfg | 0x1; 147 alpha_mb(); 148 } 149 150 /* 151 * We just inline the BWX support, since this is the only 152 * difference between BWX and swiz for config space. 153 */ 154 if (ccp->cc_flags & CCF_PCI_USE_BWX) { 155 if (secondary) { 156 datap = 157 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF1 | 158 tag | (offset & ~0x03)); 159 } else { 160 datap = 161 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF0 | 162 tag | (offset & ~0x03)); 163 } 164 } else { 165 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF | 166 tag << 5UL | /* XXX */ 167 (offset & ~0x03) << 5 | /* XXX */ 168 0 << 5 | /* XXX */ 169 0x3 << 3); /* XXX */ 170 } 171 data = (pcireg_t)-1; 172 alpha_mb(); 173 if (!(ba = badaddr(datap, sizeof *datap))) 174 data = *datap; 175 alpha_mb(); 176 alpha_mb(); 177 178 if (secondary) { 179 alpha_mb(); 180 REGVAL(CIA_CSR_CFG) = old_cfg; 181 alpha_mb(); 182 splx(s); 183 } 184 185 alpha_pal_draina(); 186 alpha_mb(); 187 errbits = REGVAL(CIA_CSR_CIA_ERR); 188 if (errbits & (CIA_ERR_RCVD_MAS_ABT|CIA_ERR_RCVD_TAR_ABT)) { 189 ba = 1; 190 data = 0xffffffff; 191 } 192 193 if (errbits) { 194 REGVAL(CIA_CSR_CIA_ERR) = errbits; 195 alpha_mb(); 196 alpha_pal_draina(); 197 } 198 199#if 0 200 printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg, 201 data, datap, ba ? " (badaddr)" : ""); 202#endif 203 204 return data; 205} 206 207void 208cia_conf_write(cpv, tag, offset, data) 209 void *cpv; 210 pcitag_t tag; 211 int offset; 212 pcireg_t data; 213{ 214 struct cia_config *ccp = cpv; 215 pcireg_t *datap; 216 int s, secondary; 217 u_int32_t old_cfg; 218 219#ifdef __GNUC__ 220 s = 0; /* XXX gcc -Wuninitialized */ 221 old_cfg = 0; /* XXX gcc -Wuninitialized */ 222#endif 223 224 /* secondary if bus # != 0 */ 225 alpha_pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0); 226 if (secondary) { 227 s = splhigh(); 228 old_cfg = REGVAL(CIA_CSR_CFG); 229 alpha_mb(); 230 REGVAL(CIA_CSR_CFG) = old_cfg | 0x1; 231 alpha_mb(); 232 } 233 234 /* 235 * We just inline the BWX support, since this is the only 236 * difference between BWX and swiz for config space. 237 */ 238 if (ccp->cc_flags & CCF_PCI_USE_BWX) { 239 if (secondary) { 240 datap = 241 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF1 | 242 tag | (offset & ~0x03)); 243 } else { 244 datap = 245 (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_EV56_BWCONF0 | 246 tag | (offset & ~0x03)); 247 } 248 } else { 249 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF | 250 tag << 5UL | /* XXX */ 251 (offset & ~0x03) << 5 | /* XXX */ 252 0 << 5 | /* XXX */ 253 0x3 << 3); /* XXX */ 254 } 255 alpha_mb(); 256 *datap = data; 257 alpha_mb(); 258 alpha_mb(); 259 260 if (secondary) { 261 alpha_mb(); 262 REGVAL(CIA_CSR_CFG) = old_cfg; 263 alpha_mb(); 264 splx(s); 265 } 266 267#if 0 268 printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag, 269 reg, data, datap); 270#endif 271} 272