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