grackle.c revision 1.7
1/* $NetBSD: grackle.c,v 1.7 2003/06/15 23:09:02 fvdl Exp $ */ 2 3/*- 4 * Copyright (c) 2000 Tsubai Masanari. All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. The name of the author may not be used to endorse or promote products 15 * derived from this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#include <sys/param.h> 30#include <sys/device.h> 31#include <sys/systm.h> 32 33#include <dev/pci/pcivar.h> 34#include <dev/ofw/openfirm.h> 35#include <dev/ofw/ofw_pci.h> 36 37#include <machine/autoconf.h> 38 39struct grackle_softc { 40 struct device sc_dev; 41 struct pci_bridge sc_pc; 42}; 43 44void grackle_attach __P((struct device *, struct device *, void *)); 45int grackle_match __P((struct device *, struct cfdata *, void *)); 46int grackle_print __P((void *, const char *)); 47 48pcireg_t grackle_conf_read __P((pci_chipset_tag_t, pcitag_t, int)); 49void grackle_conf_write __P((pci_chipset_tag_t, pcitag_t, int, pcireg_t)); 50 51CFATTACH_DECL(grackle, sizeof(struct grackle_softc), 52 grackle_match, grackle_attach, NULL, NULL); 53 54int 55grackle_match(parent, cf, aux) 56 struct device *parent; 57 struct cfdata *cf; 58 void *aux; 59{ 60 struct confargs *ca = aux; 61 char compat[32]; 62 63 if (strcmp(ca->ca_name, "pci") != 0) 64 return 0; 65 66 memset(compat, 0, sizeof(compat)); 67 OF_getprop(ca->ca_node, "compatible", compat, sizeof(compat)); 68 if (strcmp(compat, "grackle") != 0) 69 return 0; 70 71 return 1; 72} 73 74#define GRACKLE_ADDR 0xfec00000 75#define GRACKLE_DATA 0xfee00000 76 77void 78grackle_attach(parent, self, aux) 79 struct device *parent, *self; 80 void *aux; 81{ 82 struct grackle_softc *sc = (void *)self; 83 pci_chipset_tag_t pc = &sc->sc_pc; 84 struct confargs *ca = aux; 85 struct pcibus_attach_args pba; 86 int len, node = ca->ca_node; 87 u_int32_t busrange[2]; 88 struct ranges { 89 u_int32_t pci_hi, pci_mid, pci_lo; 90 u_int32_t host; 91 u_int32_t size_hi, size_lo; 92 } ranges[6], *rp = ranges; 93 94 printf("\n"); 95 96 /* PCI bus number */ 97 if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8) 98 return; 99 100 pc->node = node; 101 pc->addr = mapiodev(GRACKLE_ADDR, 4); 102 pc->data = mapiodev(GRACKLE_DATA, 4); 103 pc->bus = busrange[0]; 104 pc->conf_read = grackle_conf_read; 105 pc->conf_write = grackle_conf_write; 106 pc->memt = (bus_space_tag_t)0; 107 108 /* find i/o tag */ 109 len = OF_getprop(node, "ranges", ranges, sizeof(ranges)); 110 if (len == -1) 111 return; 112 while (len >= sizeof(ranges[0])) { 113 if ((rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) == 114 OFW_PCI_PHYS_HI_SPACE_IO) 115 pc->iot = (bus_space_tag_t)rp->host; 116 len -= sizeof(ranges[0]); 117 rp++; 118 } 119 120 memset(&pba, 0, sizeof(pba)); 121 pba.pba_busname = "pci"; 122 pba.pba_memt = pc->memt; 123 pba.pba_iot = pc->iot; 124 pba.pba_dmat = &pci_bus_dma_tag; 125 pba.pba_dmat64 = NULL; 126 pba.pba_bus = pc->bus; 127 pba.pba_bridgetag = NULL; 128 pba.pba_pc = pc; 129 pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED; 130 131 config_found(self, &pba, grackle_print); 132} 133 134int 135grackle_print(aux, pnp) 136 void *aux; 137 const char *pnp; 138{ 139 struct pcibus_attach_args *pa = aux; 140 141 if (pnp) 142 aprint_normal("%s at %s", pa->pba_busname, pnp); 143 aprint_normal(" bus %d", pa->pba_bus); 144 return UNCONF; 145} 146 147pcireg_t 148grackle_conf_read(pc, tag, reg) 149 pci_chipset_tag_t pc; 150 pcitag_t tag; 151 int reg; 152{ 153 pcireg_t data; 154 int s; 155 156 s = splhigh(); 157 158 out32rb(pc->addr, tag | reg); 159 data = 0xffffffff; 160 if (!badaddr(pc->data, 4)) 161 data = in32rb(pc->data); 162 out32rb(pc->addr, 0); 163 164 splx(s); 165 166 return data; 167} 168 169void 170grackle_conf_write(pc, tag, reg, data) 171 pci_chipset_tag_t pc; 172 pcitag_t tag; 173 int reg; 174 pcireg_t data; 175{ 176 int s; 177 178 s = splhigh(); 179 180 out32rb(pc->addr, tag | reg); 181 out32rb(pc->data, data); 182 out32rb(pc->addr, 0); 183 184 splx(s); 185} 186