1 /* $OpenBSD: irongate_pci.c,v 1.5 2008/06/26 05:42:08 ray Exp $ */ 2 /* $NetBSD: irongate_pci.c,v 1.2 2000/06/29 08:58:47 mrg Exp $ */ 3 4 /*- 5 * Copyright (c) 2000 The NetBSD Foundation, Inc. 6 * All rights reserved. 7 * 8 * This code is derived from software contributed to The NetBSD Foundation 9 * by Jason R. Thorpe. 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions and the following disclaimer. 16 * 2. Redistributions in binary form must reproduce the above copyright 17 * notice, this list of conditions and the following disclaimer in the 18 * documentation and/or other materials provided with the distribution. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 21 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 24 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 25 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 26 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 27 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 28 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 29 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 30 * POSSIBILITY OF SUCH DAMAGE. 31 */ 32 33 /* 34 * PCI Configuration Space support for the AMD 751 (``Irongate'') core logic 35 * chipset. 36 */ 37 38 #include <sys/param.h> 39 #include <sys/systm.h> 40 #include <sys/kernel.h> 41 #include <sys/device.h> 42 43 #include <uvm/uvm_extern.h> 44 45 #include <dev/pci/pcireg.h> 46 #include <dev/pci/pcivar.h> 47 #include <alpha/pci/irongatereg.h> 48 #include <alpha/pci/irongatevar.h> 49 50 void irongate_attach_hook(struct device *, struct device *, 51 struct pcibus_attach_args *); 52 int irongate_bus_maxdevs(void *, int); 53 pcitag_t irongate_make_tag(void *, int, int, int); 54 void irongate_decompose_tag(void *, pcitag_t, int *, int *, 55 int *); 56 pcireg_t irongate_conf_read(void *, pcitag_t, int); 57 void irongate_conf_write(void *, pcitag_t, int, pcireg_t); 58 59 /* AMD 751 systems are always single-processor, so this is easy. */ 60 #define PCI_CONF_LOCK(s) (s) = splhigh() 61 #define PCI_CONF_UNLOCK(s) splx((s)) 62 63 #define PCI_CONF_ADDR (IRONGATE_IO_BASE|IRONGATE_CONFADDR) 64 #define PCI_CONF_DATA (IRONGATE_IO_BASE|IRONGATE_CONFDATA) 65 66 #define REGVAL(r) (*(__volatile u_int32_t *)ALPHA_PHYS_TO_K0SEG(r)) 67 68 void 69 irongate_pci_init(pci_chipset_tag_t pc, void *v) 70 { 71 72 pc->pc_conf_v = v; 73 pc->pc_attach_hook = irongate_attach_hook; 74 pc->pc_bus_maxdevs = irongate_bus_maxdevs; 75 pc->pc_make_tag = irongate_make_tag; 76 pc->pc_decompose_tag = irongate_decompose_tag; 77 pc->pc_conf_read = irongate_conf_read; 78 pc->pc_conf_write = irongate_conf_write; 79 } 80 81 void 82 irongate_attach_hook(struct device *parent, struct device *self, 83 struct pcibus_attach_args *pba) 84 { 85 } 86 87 int 88 irongate_bus_maxdevs(void *ipv, int busno) 89 { 90 91 return 32; 92 } 93 94 pcitag_t 95 irongate_make_tag(void *ipv, int b, int d, int f) 96 { 97 98 return (b << 16) | (d << 11) | (f << 8); 99 } 100 101 void 102 irongate_decompose_tag(void *ipv, pcitag_t tag, int *bp, int *dp, int *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 irongate_conf_read(void *ipv, pcitag_t tag, int offset) 115 { 116 int d; 117 118 /* 119 * The AMD 751 appears in PCI configuration space, but 120 * that is ... counter-intuitive to the way we normally 121 * attach PCI-Host bridges on the Alpha. So, filter out 122 * the AMD 751 device here. We provide a private entry 123 * point for getting at it from machdep code. 124 */ 125 irongate_decompose_tag(ipv, tag, NULL, &d, NULL); 126 if (d == IRONGATE_PCIHOST_DEV) 127 return ((pcireg_t) -1); 128 129 return (irongate_conf_read0(ipv, tag, offset)); 130 } 131 132 pcireg_t 133 irongate_conf_read0(void *ipv, pcitag_t tag, int offset) 134 { 135 pcireg_t data; 136 int s; 137 138 PCI_CONF_LOCK(s); 139 REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff)); 140 alpha_mb(); 141 data = REGVAL(PCI_CONF_DATA); 142 REGVAL(PCI_CONF_ADDR) = 0; 143 alpha_mb(); 144 PCI_CONF_UNLOCK(s); 145 146 return (data); 147 } 148 149 void 150 irongate_conf_write(void *ipv, pcitag_t tag, int offset, pcireg_t data) 151 { 152 int s; 153 154 PCI_CONF_LOCK(s); 155 REGVAL(PCI_CONF_ADDR) = (CONFADDR_ENABLE | tag | (offset & 0xff)); 156 alpha_mb(); 157 REGVAL(PCI_CONF_DATA) = data; 158 alpha_mb(); 159 REGVAL(PCI_CONF_ADDR) = 0; 160 alpha_mb(); 161 PCI_CONF_UNLOCK(s); 162 } 163