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