cia_pci.c revision 1.4
1/* $OpenBSD: cia_pci.c,v 1.4 1996/10/30 22:39:56 niklas Exp $ */ 2/* $NetBSD: cia_pci.c,v 1.5 1996/10/13 03:00:04 christos Exp $ */ 3 4/* 5 * Copyright (c) 1995, 1996 Carnegie-Mellon University. 6 * All rights reserved. 7 * 8 * Author: Chris G. Demetriou 9 * 10 * Permission to use, copy, modify and distribute this software and 11 * its documentation is hereby granted, provided that both the copyright 12 * notice and this permission notice appear in all copies of the 13 * software, derivative works or modified versions, and any portions 14 * thereof, and that both notices appear in supporting documentation. 15 * 16 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 17 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND 18 * FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 19 * 20 * Carnegie Mellon requests users of this software to return to 21 * 22 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 23 * School of Computer Science 24 * Carnegie Mellon University 25 * Pittsburgh PA 15213-3890 26 * 27 * any improvements or extensions that they make and grant Carnegie the 28 * rights to redistribute these changes. 29 */ 30 31#include <sys/param.h> 32#include <sys/systm.h> 33#include <sys/kernel.h> 34#include <sys/device.h> 35#include <vm/vm.h> 36 37#include <machine/autoconf.h> /* badaddr proto */ 38 39#include <dev/pci/pcireg.h> 40#include <dev/pci/pcivar.h> 41#include <alpha/pci/ciareg.h> 42#include <alpha/pci/ciavar.h> 43 44void cia_attach_hook __P((struct device *, struct device *, 45 struct pcibus_attach_args *)); 46int cia_bus_maxdevs __P((void *, int)); 47pcitag_t cia_make_tag __P((void *, int, int, int)); 48void cia_decompose_tag __P((void *, pcitag_t, int *, int *, 49 int *)); 50pcireg_t cia_conf_read __P((void *, pcitag_t, int)); 51void cia_conf_write __P((void *, pcitag_t, int, pcireg_t)); 52 53void 54cia_pci_init(pc, v) 55 pci_chipset_tag_t pc; 56 void *v; 57{ 58 59 pc->pc_conf_v = v; 60 pc->pc_attach_hook = cia_attach_hook; 61 pc->pc_bus_maxdevs = cia_bus_maxdevs; 62 pc->pc_make_tag = cia_make_tag; 63 pc->pc_decompose_tag = cia_decompose_tag; 64 pc->pc_conf_read = cia_conf_read; 65 pc->pc_conf_write = cia_conf_write; 66} 67 68void 69cia_attach_hook(parent, self, pba) 70 struct device *parent, *self; 71 struct pcibus_attach_args *pba; 72{ 73} 74 75int 76cia_bus_maxdevs(cpv, busno) 77 void *cpv; 78 int busno; 79{ 80 81 return 32; 82} 83 84pcitag_t 85cia_make_tag(cpv, b, d, f) 86 void *cpv; 87 int b, d, f; 88{ 89 90 return (b << 16) | (d << 11) | (f << 8); 91} 92 93void 94cia_decompose_tag(cpv, tag, bp, dp, fp) 95 void *cpv; 96 pcitag_t tag; 97 int *bp, *dp, *fp; 98{ 99 100 if (bp != NULL) 101 *bp = (tag >> 16) & 0xff; 102 if (dp != NULL) 103 *dp = (tag >> 11) & 0x1f; 104 if (fp != NULL) 105 *fp = (tag >> 8) & 0x7; 106} 107 108pcireg_t 109cia_conf_read(cpv, tag, offset) 110 void *cpv; 111 pcitag_t tag; 112 int offset; 113{ 114 struct cia_config *ccp = cpv; 115 pcireg_t *datap, data; 116 int s, secondary, ba; 117 int32_t old_haxr2; /* XXX */ 118 119 /* secondary if bus # != 0 */ 120 pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0); 121 if (secondary) { 122 s = splhigh(); 123 old_haxr2 = REGVAL(CIA_CSRS + 0x480); /* XXX */ 124 alpha_mb(); 125 REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1; /* XXX */ 126 alpha_mb(); 127 } 128 129 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF | 130 tag << 5UL | /* XXX */ 131 (offset & ~0x03) << 5 | /* XXX */ 132 0 << 5 | /* XXX */ 133 0x3 << 3); /* XXX */ 134 data = (pcireg_t)-1; 135 if (!(ba = badaddr(datap, sizeof *datap))) 136 data = *datap; 137 138 if (secondary) { 139 alpha_mb(); 140 REGVAL(CIA_CSRS + 0x480) = old_haxr2; /* XXX */ 141 alpha_mb(); 142 splx(s); 143 } 144 145#if 0 146 printf("cia_conf_read: tag 0x%lx, reg 0x%lx -> %x @ %p%s\n", tag, reg, 147 data, datap, ba ? " (badaddr)" : ""); 148#endif 149 150 return data; 151} 152 153void 154cia_conf_write(cpv, tag, offset, data) 155 void *cpv; 156 pcitag_t tag; 157 int offset; 158 pcireg_t data; 159{ 160 struct cia_config *ccp = cpv; 161 pcireg_t *datap; 162 int s, secondary; 163 int32_t old_haxr2; /* XXX */ 164 165 /* secondary if bus # != 0 */ 166 pci_decompose_tag(&ccp->cc_pc, tag, &secondary, 0, 0); 167 if (secondary) { 168 s = splhigh(); 169 old_haxr2 = REGVAL(CIA_CSRS + 0x480); /* XXX */ 170 alpha_mb(); 171 REGVAL(CIA_CSRS + 0x480) = old_haxr2 | 0x1; /* XXX */ 172 alpha_mb(); 173 } 174 175 datap = (pcireg_t *)ALPHA_PHYS_TO_K0SEG(CIA_PCI_CONF | 176 tag << 5UL | /* XXX */ 177 (offset & ~0x03) << 5 | /* XXX */ 178 0 << 5 | /* XXX */ 179 0x3 << 3); /* XXX */ 180 *datap = data; 181 182 if (secondary) { 183 alpha_mb(); 184 REGVAL(CIA_CSRS + 0x480) = old_haxr2; /* XXX */ 185 alpha_mb(); 186 splx(s); 187 } 188 189#if 0 190 printf("cia_conf_write: tag 0x%lx, reg 0x%lx -> 0x%x @ %p\n", tag, 191 reg, data, datap); 192#endif 193} 194