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