1 /* $NetBSD: lca_pci.c,v 1.15 2002/05/15 16:57:42 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: lca_pci.c,v 1.15 2002/05/15 16:57:42 thorpej Exp $"); 33 34 #include <sys/param.h> 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/device.h> 38 39 #include <uvm/uvm_extern.h> 40 41 #include <dev/pci/pcireg.h> 42 #include <dev/pci/pcivar.h> 43 #include <alpha/pci/lcareg.h> 44 #include <alpha/pci/lcavar.h> 45 46 void lca_attach_hook __P((struct device *, struct device *, 47 struct pcibus_attach_args *)); 48 int lca_bus_maxdevs __P((void *, int)); 49 pcitag_t lca_make_tag __P((void *, int, int, int)); 50 void lca_decompose_tag __P((void *, pcitag_t, int *, int *, 51 int *)); 52 pcireg_t lca_conf_read __P((void *, pcitag_t, int)); 53 void lca_conf_write __P((void *, pcitag_t, int, pcireg_t)); 54 55 void 56 lca_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 = lca_attach_hook; 63 pc->pc_bus_maxdevs = lca_bus_maxdevs; 64 pc->pc_make_tag = lca_make_tag; 65 pc->pc_decompose_tag = lca_decompose_tag; 66 pc->pc_conf_read = lca_conf_read; 67 pc->pc_conf_write = lca_conf_write; 68 } 69 70 void 71 lca_attach_hook(parent, self, pba) 72 struct device *parent, *self; 73 struct pcibus_attach_args *pba; 74 { 75 } 76 77 int 78 lca_bus_maxdevs(cpv, busno) 79 void *cpv; 80 int busno; 81 { 82 83 if (busno == 0) 84 return 16; 85 else 86 return 32; 87 } 88 89 pcitag_t 90 lca_make_tag(cpv, b, d, f) 91 void *cpv; 92 int b, d, f; 93 { 94 95 return (b << 16) | (d << 11) | (f << 8); 96 } 97 98 void 99 lca_decompose_tag(cpv, tag, bp, dp, fp) 100 void *cpv; 101 pcitag_t tag; 102 int *bp, *dp, *fp; 103 { 104 105 if (bp != NULL) 106 *bp = (tag >> 16) & 0xff; 107 if (dp != NULL) 108 *dp = (tag >> 11) & 0x1f; 109 if (fp != NULL) 110 *fp = (tag >> 8) & 0x7; 111 } 112 113 pcireg_t 114 lca_conf_read(cpv, tag, offset) 115 void *cpv; 116 pcitag_t tag; 117 int offset; 118 { 119 struct lca_config *lcp = cpv; 120 pcireg_t *datap, data; 121 int s, secondary, device, ba; 122 123 s = 0; /* XXX gcc -Wuninitialized */ 124 125 /* secondary if bus # != 0 */ 126 pci_decompose_tag(&lcp->lc_pc, tag, &secondary, &device, 0); 127 if (secondary) { 128 s = splhigh(); 129 alpha_mb(); 130 REGVAL(LCA_IOC_CONF) = 0x01; 131 alpha_mb(); 132 } else { 133 /* 134 * on the LCA, must frob the tag used for 135 * devices on the primary bus, in the same ways 136 * as is used by type 1 configuration cycles 137 * on PCs. 138 */ 139 tag = (1 << (device + 11)) | (tag & 0x7ff); 140 } 141 142 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF | 143 tag << 5UL | /* XXX */ 144 (offset & ~0x03) << 5 | /* XXX */ 145 0 << 5 | /* XXX */ 146 0x3 << 3); /* XXX */ 147 data = (pcireg_t)-1; 148 if (!(ba = badaddr(datap, sizeof *datap))) 149 data = *datap; 150 151 if (secondary) { 152 alpha_mb(); 153 REGVAL(LCA_IOC_CONF) = 0x00; 154 alpha_mb(); 155 splx(s); 156 } 157 158 #if 0 159 printf("lca_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg, 160 data, datap, ba ? " (badaddr)" : ""); 161 #endif 162 163 return data; 164 } 165 166 void 167 lca_conf_write(cpv, tag, offset, data) 168 void *cpv; 169 pcitag_t tag; 170 int offset; 171 pcireg_t data; 172 { 173 struct lca_config *lcp = cpv; 174 pcireg_t *datap; 175 int s, secondary, device; 176 177 s = 0; /* XXX gcc -Wuninitialized */ 178 179 /* secondary if bus # != 0 */ 180 pci_decompose_tag(&lcp->lc_pc, tag, &secondary, &device, 0); 181 if (secondary) { 182 s = splhigh(); 183 alpha_mb(); 184 REGVAL(LCA_IOC_CONF) = 0x01; 185 alpha_mb(); 186 } else { 187 /* 188 * on the LCA, must frob the tag used for 189 * devices on the primary bus, in the same ways 190 * as is used by type 1 configuration cycles 191 * on PCs. 192 */ 193 tag = (1 << (device + 11)) | (tag & 0x7ff); 194 } 195 196 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(LCA_PCI_CONF | 197 tag << 5UL | /* XXX */ 198 (offset & ~0x03) << 5 | /* XXX */ 199 0 << 5 | /* XXX */ 200 0x3 << 3); /* XXX */ 201 *datap = data; 202 203 if (secondary) { 204 alpha_mb(); 205 REGVAL(LCA_IOC_CONF) = 0x00; 206 alpha_mb(); 207 splx(s); 208 } 209 210 #if 0 211 printf("lca_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag, 212 reg, data, datap); 213 #endif 214 } 215