1 /* $NetBSD: apecs_pci.c,v 1.13 1997/04/07 23:40:28 cgd 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 <machine/options.h> /* Config options headers */ 31 #include <sys/cdefs.h> /* RCS ID & Copyright macro defns */ 32 33 __KERNEL_RCSID(0, "$NetBSD: apecs_pci.c,v 1.13 1997/04/07 23:40:28 cgd Exp $"); 34 35 #include <sys/param.h> 36 #include <sys/systm.h> 37 #include <sys/kernel.h> 38 #include <sys/device.h> 39 #include <vm/vm.h> 40 41 #include <dev/pci/pcireg.h> 42 #include <dev/pci/pcivar.h> 43 #include <alpha/pci/apecsreg.h> 44 #include <alpha/pci/apecsvar.h> 45 46 void apecs_attach_hook __P((struct device *, struct device *, 47 struct pcibus_attach_args *)); 48 int apecs_bus_maxdevs __P((void *, int)); 49 pcitag_t apecs_make_tag __P((void *, int, int, int)); 50 void apecs_decompose_tag __P((void *, pcitag_t, int *, int *, 51 int *)); 52 pcireg_t apecs_conf_read __P((void *, pcitag_t, int)); 53 void apecs_conf_write __P((void *, pcitag_t, int, pcireg_t)); 54 55 void 56 apecs_pci_init(pc, v) 57 pci_chipset_tag_t pc; 58 void *v; 59 { 60 61 pc->pc_conf_v = v; 62 pc->pc_attach_hook = apecs_attach_hook; 63 pc->pc_bus_maxdevs = apecs_bus_maxdevs; 64 pc->pc_make_tag = apecs_make_tag; 65 pc->pc_decompose_tag = apecs_decompose_tag; 66 pc->pc_conf_read = apecs_conf_read; 67 pc->pc_conf_write = apecs_conf_write; 68 } 69 70 void 71 apecs_attach_hook(parent, self, pba) 72 struct device *parent, *self; 73 struct pcibus_attach_args *pba; 74 { 75 } 76 77 int 78 apecs_bus_maxdevs(cpv, busno) 79 void *cpv; 80 int busno; 81 { 82 83 return 32; 84 } 85 86 pcitag_t 87 apecs_make_tag(cpv, b, d, f) 88 void *cpv; 89 int b, d, f; 90 { 91 92 return (b << 16) | (d << 11) | (f << 8); 93 } 94 95 void 96 apecs_decompose_tag(cpv, tag, bp, dp, fp) 97 void *cpv; 98 pcitag_t tag; 99 int *bp, *dp, *fp; 100 { 101 102 if (bp != NULL) 103 *bp = (tag >> 16) & 0xff; 104 if (dp != NULL) 105 *dp = (tag >> 11) & 0x1f; 106 if (fp != NULL) 107 *fp = (tag >> 8) & 0x7; 108 } 109 110 pcireg_t 111 apecs_conf_read(cpv, tag, offset) 112 void *cpv; 113 pcitag_t tag; 114 int offset; 115 { 116 struct apecs_config *acp = cpv; 117 pcireg_t *datap, data; 118 int s, secondary, ba; 119 int32_t old_haxr2; /* XXX */ 120 121 #ifdef DIAGNOSTIC 122 s = 0; /* XXX gcc -Wuninitialized */ 123 old_haxr2 = 0; /* XXX gcc -Wuninitialized */ 124 #endif 125 126 /* secondary if bus # != 0 */ 127 pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0); 128 if (secondary) { 129 s = splhigh(); 130 old_haxr2 = REGVAL(EPIC_HAXR2); 131 alpha_mb(); 132 REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1; 133 alpha_mb(); 134 } 135 136 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF | 137 tag << 5UL | /* XXX */ 138 (offset & ~0x03) << 5 | /* XXX */ 139 0 << 5 | /* XXX */ 140 0x3 << 3); /* XXX */ 141 data = (pcireg_t)-1; 142 if (!(ba = badaddr(datap, sizeof *datap))) 143 data = *datap; 144 145 if (secondary) { 146 alpha_mb(); 147 REGVAL(EPIC_HAXR2) = old_haxr2; 148 alpha_mb(); 149 splx(s); 150 } 151 152 #if 0 153 printf("apecs_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg, 154 data, datap, ba ? " (badaddr)" : ""); 155 #endif 156 157 return data; 158 } 159 160 void 161 apecs_conf_write(cpv, tag, offset, data) 162 void *cpv; 163 pcitag_t tag; 164 int offset; 165 pcireg_t data; 166 { 167 struct apecs_config *acp = cpv; 168 pcireg_t *datap; 169 int s, secondary; 170 int32_t old_haxr2; /* XXX */ 171 172 #ifdef DIAGNOSTIC 173 s = 0; /* XXX gcc -Wuninitialized */ 174 old_haxr2 = 0; /* XXX gcc -Wuninitialized */ 175 #endif 176 177 /* secondary if bus # != 0 */ 178 pci_decompose_tag(&acp->ac_pc, tag, &secondary, 0, 0); 179 if (secondary) { 180 s = splhigh(); 181 old_haxr2 = REGVAL(EPIC_HAXR2); 182 alpha_mb(); 183 REGVAL(EPIC_HAXR2) = old_haxr2 | 0x1; 184 alpha_mb(); 185 } 186 187 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(APECS_PCI_CONF | 188 tag << 5UL | /* XXX */ 189 (offset & ~0x03) << 5 | /* XXX */ 190 0 << 5 | /* XXX */ 191 0x3 << 3); /* XXX */ 192 *datap = data; 193 194 if (secondary) { 195 alpha_mb(); 196 REGVAL(EPIC_HAXR2) = old_haxr2; 197 alpha_mb(); 198 splx(s); 199 } 200 201 #if 0 202 printf("apecs_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag, 203 reg, data, datap); 204 #endif 205 } 206