1 /* $NetBSD: ixp12x0_pci.c,v 1.3 2002/12/08 13:21:44 ichiro Exp $ */ 2 /* 3 * Copyright (c) 2002 The NetBSD Foundation, Inc. 4 * All rights reserved. 5 * 6 * This code is derived from software contributed to The NetBSD Foundation 7 * by Ichiro FUKUHARA and Naoto Shimazaki. 8 * 9 * Redistribution and use in source and binary forms, with or without 10 * modification, are permitted provided that the following conditions 11 * are met: 12 * 1. Redistributions of source code must retain the above copyright 13 * notice, this list of conditions and the following disclaimer. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice, this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 3. All advertising materials mentioning features or use of this software 18 * must display the following acknowledgement: 19 * This product includes software developed by the NetBSD 20 * Foundation, Inc. and its contributors. 21 * 4. Neither the name of The NetBSD Foundation nor the names of its 22 * contributors may be used to endorse or promote products derived 23 * from this software without specific prior written permission. 24 * 25 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 26 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 27 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 28 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 29 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 30 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 31 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 * POSSIBILITY OF SUCH DAMAGE. 36 */ 37 38 /* 39 * PCI configuration support for IXP12x0 Network Processor chip. 40 */ 41 42 #include <sys/param.h> 43 #include <sys/systm.h> 44 #include <sys/device.h> 45 #include <sys/extent.h> 46 #include <sys/malloc.h> 47 48 #include <uvm/uvm_extern.h> 49 50 #include <arm/ixp12x0/ixp12x0reg.h> 51 #include <arm/ixp12x0/ixp12x0var.h> 52 53 #include <dev/pci/pcireg.h> 54 #include <dev/pci/pcivar.h> 55 #include <dev/pci/pciconf.h> 56 57 #include "opt_pci.h" 58 #include "pci.h" 59 60 void ixp12x0_pci_attach_hook(struct device *, struct device *, 61 struct pcibus_attach_args *); 62 int ixp12x0_pci_bus_maxdevs(void *, int); 63 pcitag_t ixp12x0_pci_make_tag(void *, int, int, int); 64 void ixp12x0_pci_decompose_tag(void *, pcitag_t, int *, int *, int *); 65 pcireg_t ixp12x0_pci_conf_read(void *, pcitag_t, int); 66 void ixp12x0_pci_conf_write(void *, pcitag_t, int, pcireg_t); 67 68 #define MAX_PCI_DEVICES 4 69 70 /* 71 * IXM1200 PCI configuration Cycles 72 * Device Address 73 * ------------------------------------- 74 * 0 IXP1200 0x0800 - 0x08FF 75 * 1 i21555 0x1000 - 0x10FF 76 * 2 i82559 0x2000 - 0x20FF 77 * 3 PMC expansion 0x4000 - 0x40FF 78 */ 79 80 void 81 ixp12x0_pci_init(pc, cookie) 82 pci_chipset_tag_t pc; 83 void *cookie; 84 { 85 pc->pc_conf_v = cookie; 86 pc->pc_attach_hook = ixp12x0_pci_attach_hook; 87 pc->pc_bus_maxdevs = ixp12x0_pci_bus_maxdevs; 88 pc->pc_make_tag = ixp12x0_pci_make_tag; 89 pc->pc_decompose_tag = ixp12x0_pci_decompose_tag; 90 pc->pc_conf_read = ixp12x0_pci_conf_read; 91 pc->pc_conf_write = ixp12x0_pci_conf_write; 92 } 93 94 void 95 pci_conf_interrupt(pc, a, b, c, d, p) 96 pci_chipset_tag_t pc; 97 int a, b, c, d, *p; 98 { 99 /* Nothing */ 100 } 101 102 void 103 ixp12x0_pci_attach_hook(parent, self, pba) 104 struct device *parent; 105 struct device *self; 106 struct pcibus_attach_args *pba; 107 { 108 /* Nothing to do. */ 109 } 110 111 int 112 ixp12x0_pci_bus_maxdevs(v, busno) 113 void *v; 114 int busno; 115 { 116 return(MAX_PCI_DEVICES); 117 } 118 119 pcitag_t 120 ixp12x0_pci_make_tag(v, bus, device, function) 121 void *v; 122 int bus, device, function; 123 { 124 #ifdef PCI_DEBUG 125 printf("ixp12x0_pci_make_tag(v=%p, bus=%d, device=%d, function=%d)\n", 126 v, bus, device, function); 127 #endif 128 #ifdef PCI_DEBUG2 129 printf("ixp12x0_pci_make_tag return = 0x%x\n", 130 ((bus << 16) | (device << 11) | (function << 8))); 131 #endif 132 return ((bus << 16) | (device << 11) | (function << 8)); 133 } 134 135 void 136 ixp12x0_pci_decompose_tag(v, tag, busp, devicep, functionp) 137 void *v; 138 pcitag_t tag; 139 int *busp, *devicep, *functionp; 140 { 141 #ifdef PCI_DEBUG 142 printf("ixp12x0_pci_decompose_tag(v=%p, tag=0x%08lx, bp=%x, dp=%x, fp=%x)\n", 143 v, tag, (int)busp, (int)devicep, (int)functionp); 144 #endif 145 146 if (busp != NULL) 147 *busp = (tag >> 16) & 0xff; 148 if (devicep != NULL) 149 *devicep = (tag >> 11) & 0x1f; 150 if (functionp != NULL) 151 *functionp = (tag >> 8) & 0x7; 152 } 153 154 pcireg_t 155 ixp12x0_pci_conf_read(v, tag, offset) 156 void *v; 157 pcitag_t tag; 158 int offset; 159 { 160 int bus, device, function; 161 u_int address; 162 pcireg_t val; 163 164 ixp12x0_pci_decompose_tag(v, tag, &bus, &device, &function); 165 166 /* bus == 0 */ 167 address = IXP12X0_PCI_TYPE0_VBASE | 168 ((0x1) << (device)) << 11 | (offset & 0xff); /* XXX */ 169 170 val = *((unsigned int *)address); 171 172 #ifdef PCI_DEBUG 173 printf("ixp12x0_pci_conf_read(addr=%08x)(v=%p tag=0x%08lx offset=0x%02x)=0x%08x\n", 174 address, v, tag, offset, val); 175 #endif 176 #ifdef PCI_DEBUG2 177 printf("ixp12x0_pci_conf_read(addr=%08x)(bus=0x%08x device=0x%08x function=0x%08x offset=0x%02x)\n", address, bus, device, function, offset); 178 #endif 179 return(val); 180 } 181 182 void 183 ixp12x0_pci_conf_write(v, tag, offset, val) 184 void *v; 185 pcitag_t tag; 186 int offset; 187 pcireg_t val; 188 { 189 int bus, device, function; 190 u_int address; 191 192 ixp12x0_pci_decompose_tag(v, tag, &bus, &device, &function); 193 194 /* bus == 0 */ 195 address = IXP12X0_PCI_TYPE0_VBASE | 196 ((0x1) << (device)) << 11 | (offset & 0xff); /* XXX */ 197 198 199 #ifdef PCI_DEBUG 200 printf("ixp12x0_pci_conf_write(addr=%08x)(v=%p tag=0x%08lx offset=0x%02x)=0x%08x\n", 201 address, v, tag, offset, val); 202 #endif 203 *((unsigned int *)address) = val; 204 } 205