2000-02-04 10:48:11 +03:00
|
|
|
/* $NetBSD: bandit.c,v 1.15 2000/02/04 07:48:11 tsubai Exp $ */
|
1999-05-05 08:37:19 +04:00
|
|
|
|
|
|
|
/*-
|
2000-02-03 22:27:43 +03:00
|
|
|
* Copyright (c) 2000 Tsubai Masanari. All rights reserved.
|
1999-05-05 08:37:19 +04:00
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2000-02-03 22:27:43 +03:00
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
1999-05-05 08:37:19 +04:00
|
|
|
*
|
2000-02-03 22:27:43 +03:00
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
1998-05-15 14:15:45 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/device.h>
|
1998-10-15 18:39:53 +04:00
|
|
|
#include <sys/systm.h>
|
1998-05-15 14:15:45 +04:00
|
|
|
|
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/ofw/openfirm.h>
|
1999-05-05 08:37:19 +04:00
|
|
|
#include <dev/ofw/ofw_pci.h>
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
#include <machine/autoconf.h>
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
struct bandit_softc {
|
|
|
|
struct device sc_dev;
|
|
|
|
struct pci_bridge sc_pc;
|
|
|
|
};
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
void bandit_attach __P((struct device *, struct device *, void *));
|
|
|
|
int bandit_match __P((struct device *, struct cfdata *, void *));
|
|
|
|
int bandit_print __P((void *, const char *));
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
pcireg_t bandit_conf_read __P((pci_chipset_tag_t, pcitag_t, int));
|
|
|
|
void bandit_conf_write __P((pci_chipset_tag_t, pcitag_t, int, pcireg_t));
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
static void bandit_init __P((struct bandit_softc *));
|
1998-07-17 22:40:31 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
struct cfattach bandit_ca = {
|
|
|
|
sizeof(struct bandit_softc), bandit_match, bandit_attach
|
|
|
|
};
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
int
|
|
|
|
bandit_match(parent, cf, aux)
|
|
|
|
struct device *parent;
|
|
|
|
struct cfdata *cf;
|
|
|
|
void *aux;
|
1998-05-15 14:15:45 +04:00
|
|
|
{
|
2000-02-03 22:27:43 +03:00
|
|
|
struct confargs *ca = aux;
|
|
|
|
|
2000-02-04 06:40:42 +03:00
|
|
|
if (strcmp(ca->ca_name, "bandit") == 0 ||
|
|
|
|
strcmp(ca->ca_name, "chaos") == 0)
|
2000-02-03 22:27:43 +03:00
|
|
|
return 1;
|
1999-05-05 08:37:19 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
return 0;
|
1998-05-15 14:15:45 +04:00
|
|
|
}
|
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
void
|
|
|
|
bandit_attach(parent, self, aux)
|
|
|
|
struct device *parent, *self;
|
|
|
|
void *aux;
|
1998-05-15 14:15:45 +04:00
|
|
|
{
|
2000-02-03 22:27:43 +03:00
|
|
|
struct bandit_softc *sc = (void *)self;
|
|
|
|
pci_chipset_tag_t pc = &sc->sc_pc;
|
|
|
|
struct confargs *ca = aux;
|
|
|
|
struct pcibus_attach_args pba;
|
|
|
|
int len, node = ca->ca_node;
|
|
|
|
u_int32_t reg[2], busrange[2];
|
|
|
|
struct ranges {
|
|
|
|
u_int32_t pci_hi, pci_mid, pci_lo;
|
|
|
|
u_int32_t host;
|
|
|
|
u_int32_t size_hi, size_lo;
|
|
|
|
} ranges[6], *rp = ranges;
|
|
|
|
|
|
|
|
printf("\n");
|
|
|
|
|
|
|
|
/* Bandit address */
|
|
|
|
if (OF_getprop(node, "reg", reg, sizeof(reg)) < 8)
|
1998-05-15 14:15:45 +04:00
|
|
|
return;
|
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
/* PCI bus number */
|
|
|
|
if (OF_getprop(node, "bus-range", busrange, sizeof(busrange)) != 8)
|
|
|
|
return;
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
pc->node = node;
|
|
|
|
pc->addr = mapiodev(reg[0] + 0x800000, 4);
|
|
|
|
pc->data = mapiodev(reg[0] + 0xc00000, 8);
|
|
|
|
pc->bus = busrange[0];
|
|
|
|
pc->conf_read = bandit_conf_read;
|
|
|
|
pc->conf_write = bandit_conf_write;
|
|
|
|
pc->memt = (bus_space_tag_t)0;
|
|
|
|
|
|
|
|
/* find i/o tag */
|
|
|
|
len = OF_getprop(node, "ranges", ranges, sizeof(ranges));
|
|
|
|
if (len == -1)
|
|
|
|
return;
|
|
|
|
while (len >= sizeof(ranges[0])) {
|
|
|
|
if ((rp->pci_hi & OFW_PCI_PHYS_HI_SPACEMASK) ==
|
|
|
|
OFW_PCI_PHYS_HI_SPACE_IO)
|
|
|
|
pc->iot = (bus_space_tag_t)rp->host;
|
|
|
|
len -= sizeof(ranges[0]);
|
|
|
|
rp++;
|
1998-05-15 14:15:45 +04:00
|
|
|
}
|
2000-02-03 22:27:43 +03:00
|
|
|
|
|
|
|
bandit_init(sc);
|
|
|
|
|
|
|
|
bzero(&pba, sizeof(pba));
|
|
|
|
pba.pba_busname = "pci";
|
|
|
|
pba.pba_memt = pc->memt;
|
|
|
|
pba.pba_iot = pc->iot;
|
|
|
|
pba.pba_dmat = &pci_bus_dma_tag;
|
|
|
|
pba.pba_bus = pc->bus;
|
|
|
|
pba.pba_pc = pc;
|
|
|
|
pba.pba_flags = PCI_FLAGS_IO_ENABLED | PCI_FLAGS_MEM_ENABLED;
|
|
|
|
|
|
|
|
config_found(self, &pba, bandit_print);
|
1998-05-15 14:15:45 +04:00
|
|
|
}
|
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
int
|
|
|
|
bandit_print(aux, pnp)
|
|
|
|
void *aux;
|
|
|
|
const char *pnp;
|
|
|
|
{
|
|
|
|
struct pcibus_attach_args *pa = aux;
|
|
|
|
|
|
|
|
if (pnp)
|
|
|
|
printf("%s at %s", pa->pba_busname, pnp);
|
|
|
|
printf(" bus %d", pa->pba_bus);
|
|
|
|
return UNCONF;
|
|
|
|
}
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
pcireg_t
|
|
|
|
bandit_conf_read(pc, tag, reg)
|
|
|
|
pci_chipset_tag_t pc;
|
|
|
|
pcitag_t tag;
|
|
|
|
int reg;
|
1998-05-15 14:15:45 +04:00
|
|
|
{
|
2000-02-03 22:27:43 +03:00
|
|
|
pcireg_t data;
|
|
|
|
int bus, dev, func, s;
|
|
|
|
u_int32_t x;
|
1998-07-13 23:27:13 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
pci_decompose_tag(pc, tag, &bus, &dev, &func);
|
1998-10-15 18:39:53 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
/*
|
|
|
|
* bandit's minimum device number of the first bus is 11.
|
|
|
|
* So we behave as if there is no device when dev < 11.
|
|
|
|
*/
|
|
|
|
if (func > 7)
|
|
|
|
panic("pci_conf_read: func > 7");
|
|
|
|
|
|
|
|
if (bus == pc->bus) {
|
|
|
|
if (dev < 11) {
|
|
|
|
if (reg == PCI_ID_REG)
|
|
|
|
return 0xffffffff;
|
|
|
|
else
|
|
|
|
panic("pci_conf_read: dev < 11");
|
1998-07-13 23:27:13 +04:00
|
|
|
}
|
2000-02-03 22:27:43 +03:00
|
|
|
x = (1 << dev) | (func << 8) | reg;
|
|
|
|
} else
|
|
|
|
x = tag | reg | 1;
|
1998-07-13 23:27:13 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
s = splhigh();
|
|
|
|
|
|
|
|
out32rb(pc->addr, x);
|
|
|
|
DELAY(10);
|
|
|
|
data = 0xffffffff;
|
|
|
|
if (!badaddr(pc->data, 4))
|
|
|
|
data = in32rb(pc->data);
|
|
|
|
DELAY(10);
|
|
|
|
out32rb(pc->addr, 0);
|
|
|
|
DELAY(10);
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return data;
|
1998-05-15 14:15:45 +04:00
|
|
|
}
|
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
void
|
|
|
|
bandit_conf_write(pc, tag, reg, data)
|
1998-05-15 14:15:45 +04:00
|
|
|
pci_chipset_tag_t pc;
|
|
|
|
pcitag_t tag;
|
2000-02-03 22:27:43 +03:00
|
|
|
int reg;
|
|
|
|
pcireg_t data;
|
|
|
|
{
|
|
|
|
int bus, dev, func, s;
|
|
|
|
u_int32_t x;
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
pci_decompose_tag(pc, tag, &bus, &dev, &func);
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
if (func > 7)
|
|
|
|
panic("pci_conf_write: func > 7");
|
1998-07-17 22:40:31 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
if (bus == pc->bus) {
|
|
|
|
if (dev < 11)
|
|
|
|
panic("pci_conf_write: dev < 11");
|
|
|
|
x = (1 << dev) | (func << 8) | reg;
|
|
|
|
} else
|
|
|
|
x = tag | reg | 1;
|
1998-07-17 22:40:31 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
s = splhigh();
|
1998-07-17 22:40:31 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
out32rb(pc->addr, x);
|
|
|
|
DELAY(10);
|
|
|
|
out32rb(pc->data, data);
|
|
|
|
DELAY(10);
|
|
|
|
out32rb(pc->addr, 0);
|
|
|
|
DELAY(10);
|
1998-05-15 14:15:45 +04:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
#define PCI_BANDIT 11
|
|
|
|
|
|
|
|
#define PCI_REG_MODE_SELECT 0x50
|
|
|
|
|
|
|
|
#define PCI_MODE_IO_COHERENT 0x040 /* I/O coherent */
|
|
|
|
|
|
|
|
void
|
|
|
|
bandit_init(sc)
|
|
|
|
struct bandit_softc *sc;
|
|
|
|
{
|
|
|
|
pci_chipset_tag_t pc = &sc->sc_pc;
|
|
|
|
pcitag_t tag;
|
|
|
|
u_int mode;
|
|
|
|
|
|
|
|
tag = pci_make_tag(pc, pc->bus, PCI_BANDIT, 0);
|
|
|
|
if ((pci_conf_read(pc, tag, PCI_ID_REG) & 0xffff) == 0xffff)
|
1999-02-04 17:54:00 +03:00
|
|
|
return;
|
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
mode = pci_conf_read(pc, tag, PCI_REG_MODE_SELECT);
|
1999-02-04 17:54:00 +03:00
|
|
|
|
2000-02-03 22:27:43 +03:00
|
|
|
if ((mode & PCI_MODE_IO_COHERENT) == 0) {
|
|
|
|
mode |= PCI_MODE_IO_COHERENT;
|
|
|
|
pci_conf_write(pc, tag, PCI_REG_MODE_SELECT, mode);
|
|
|
|
}
|
1998-05-15 14:15:45 +04:00
|
|
|
}
|