use pci_map_register(). Also, almost a complete rewrite/cleanup of this

code.  (It still needs more!)
This commit is contained in:
cgd 1997-04-13 19:55:09 +00:00
parent 41a0ca7403
commit 8593458137
1 changed files with 100 additions and 95 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cy_pci.c,v 1.4 1996/10/21 22:56:29 thorpej Exp $ */ /* $NetBSD: cy_pci.c,v 1.5 1997/04/13 19:55:09 cgd Exp $ */
/* /*
* cy_pci.c * cy_pci.c
@ -24,88 +24,78 @@
#include <dev/ic/cyreg.h> #include <dev/ic/cyreg.h>
#include <dev/ic/cyvar.h> #include <dev/ic/cyvar.h>
static int cy_probe_pci __P((struct device *, void *, void *)); #ifdef __BROKEN_INDIRECT_CONFIG
static int cy_match_pci __P((struct device *, void *, void *));
#else
static int cy_match_pci __P((struct device *, struct cfdata *, void *));
#endif
static void cy_attach_pci __P((struct device *, struct device *, void *)); static void cy_attach_pci __P((struct device *, struct device *, void *));
static int cy_map_pci __P((struct pci_attach_args *, struct cy_softc *, static int cy_map_pci __P((struct pci_attach_args *, bus_space_tag_t *,
bus_space_handle_t *, bus_size_t *, bus_size_t *)); bus_space_handle_t *, bus_size_t *, bus_space_tag_t *,
static void cy_unmap_pci __P((struct cy_softc *, bus_space_handle_t, bus_space_handle_t *, bus_size_t *));
bus_size_t, bus_size_t)); static void cy_unmap_pci __P((bus_space_tag_t, bus_space_handle_t,
bus_size_t, bus_space_tag_t, bus_space_handle_t, bus_size_t));
struct cfattach cy_pci_ca = { struct cfattach cy_pci_ca = {
sizeof(struct cy_softc), cy_probe_pci, cy_attach_pci sizeof(struct cy_softc), cy_match_pci, cy_attach_pci
}; };
static int static int
cy_map_pci(pa, sc, ioh, iosize, memsize) cy_map_pci(pap, iotp, iohp, iosizep, memtp, memhp, memsizep)
struct pci_attach_args *pa; struct pci_attach_args *pap;
struct cy_softc *sc; bus_space_tag_t *iotp, *memtp;
bus_space_handle_t *ioh; bus_space_handle_t *iohp, *memhp;
bus_size_t *memsize; bus_size_t *iosizep, *memsizep;
bus_size_t *iosize;
{ {
bus_addr_t iobase; int ioh_valid, memh_valid;
bus_addr_t memaddr;
int cacheable;
if (pci_mem_find(pa->pa_pc, pa->pa_tag, 0x18, &memaddr, memsize, ioh_valid = (pci_map_register(pap, 0x14,
&cacheable) != 0) { PCI_MAPREG_TYPE_IO, 0,
printf("%s: can't find PCI card memory", sc->sc_dev.dv_xname); iotp, iohp, NULL, iosizep) == 0);
return 0; memh_valid = (pci_map_register(pap, 0x18,
} PCI_MAPREG_TYPE_MEM | PCI_MAPREG_MEM_TYPE_32BIT, 0,
/* map the memory (non-cacheable) */ memtp, memhp, NULL, memsizep) == 0);
if (bus_space_map(sc->sc_memt, memaddr, *memsize, 0,
&sc->sc_bsh) != 0) {
printf("%s: couldn't map PCI memory region\n",
sc->sc_dev.dv_xname);
return 0;
}
/* the PCI Cyclom IO space is only used for enabling interrupts */
if (pci_io_find(pa->pa_pc, pa->pa_tag, 0x14, &iobase, iosize) != 0) {
printf("%s: couldn't find PCI io region\n",
sc->sc_dev.dv_xname);
goto unmapmem;
}
if (bus_space_map(sc->sc_iot, iobase, *iosize, 0, ioh) != 0) {
printf("%s: couldn't map PCI io region\n", sc->sc_dev.dv_xname);
goto unmapio;
}
return 1;
unmapio: if (ioh_valid && memh_valid)
bus_space_unmap(sc->sc_iot, *ioh, *iosize); return (1);
unmapmem:
bus_space_unmap(sc->sc_memt, sc->sc_bsh, *memsize); if (ioh_valid)
return 0; bus_space_unmap(*iotp, *iohp, *iosizep);
if (memh_valid)
bus_space_unmap(*memtp, *memhp, *memsizep);
return (0);
} }
static void static void
cy_unmap_pci(sc, ioh, iosize, memsize) cy_unmap_pci(iot, ioh, iosize, memt, memh, memsize)
struct cy_softc *sc; bus_space_tag_t iot, memt;
bus_space_handle_t ioh; bus_space_handle_t ioh, memh;
bus_size_t iosize; bus_size_t iosize, memsize;
bus_size_t memsize;
{ {
bus_space_unmap(sc->sc_iot, ioh, iosize); bus_space_unmap(iot, ioh, iosize);
bus_space_unmap(sc->sc_memt, sc->sc_bsh, memsize); bus_space_unmap(memt, memh, memsize);
} }
static int static int
cy_probe_pci(parent, match, aux) cy_match_pci(parent, match, aux)
struct device *parent; struct device *parent;
void *match, *aux; #ifdef __BROKEN_INDIRECT_CONFIG
void *match;
#else
struct cfdata *match;
#endif
void *aux;
{ {
struct pci_attach_args *pa = aux; struct pci_attach_args *pap = aux;
bus_space_handle_t ioh; bus_space_tag_t iot, memt;
bus_size_t memsize; bus_space_handle_t ioh, memh;
bus_size_t iosize; bus_size_t iosize, memsize;
int rv = 0;
struct cy_softc sc;
if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CYCLADES) if (PCI_VENDOR(pap->pa_id) != PCI_VENDOR_CYCLADES)
return 0; return 0;
switch (PCI_PRODUCT(pa->pa_id)) { switch (PCI_PRODUCT(pap->pa_id)) {
case PCI_PRODUCT_CYCLADES_CYCLOMY_1: case PCI_PRODUCT_CYCLADES_CYCLOMY_1:
break; break;
case PCI_PRODUCT_CYCLADES_CYCLOMY_2: case PCI_PRODUCT_CYCLADES_CYCLOMY_2:
@ -115,17 +105,15 @@ cy_probe_pci(parent, match, aux)
} }
#ifdef CY_DEBUG #ifdef CY_DEBUG
printf("cy: Found Cyclades PCI device, id = 0x%x\n", pa->pa_id); printf("cy: Found Cyclades PCI device, id = 0x%x\n", pap->pa_id);
#endif #endif
/* XXX THIS IS TOTALLY WRONG! XXX */
memcpy(&sc.sc_dev, match, sizeof(struct device));
sc.sc_iot = pa->pa_iot; if (cy_map_pci(pap, &iot, &ioh, &iosize, &memt, &memh, &memsize) == 0)
sc.sc_memt = pa->pa_memt; return (0);
sc.sc_bustype = CY_BUSTYPE_PCI;
if (cy_map_pci(pa, &sc, &ioh, &iosize, &memsize) == 0) #if 0
return 0; XXX probably should do something like this, but this code is just
XXX too broken.
#ifdef CY_DEBUG #ifdef CY_DEBUG
printf("%s: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n", printf("%s: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n",
@ -135,9 +123,10 @@ cy_probe_pci(parent, match, aux)
if ((rv = cy_find(&sc)) == 0) if ((rv = cy_find(&sc)) == 0)
printf("%s: PCI Cyclom card with no CD1400s!?\n", printf("%s: PCI Cyclom card with no CD1400s!?\n",
sc.sc_dev.dv_xname); sc.sc_dev.dv_xname);
#endif /* 0 */
cy_unmap_pci(&sc, ioh, iosize, memsize); cy_unmap_pci(iot, ioh, iosize, memt, memh, memsize);
return rv; return (1);
} }
@ -147,36 +136,52 @@ cy_attach_pci(parent, self, aux)
void *aux; void *aux;
{ {
struct cy_softc *sc = (void *) self; struct cy_softc *sc = (void *) self;
struct pci_attach_args *pap = aux;
pci_intr_handle_t intrhandle; pci_intr_handle_t intrhandle;
bus_space_handle_t ioh; bus_space_tag_t iot, memt;
bus_size_t memsize; bus_space_handle_t ioh, memh;
bus_size_t iosize; bus_size_t iosize, memsize;
struct pci_attach_args *pa = aux; const char *intrstr;
sc->sc_iot = pa->pa_iot;
sc->sc_memt = pa->pa_memt;
sc->sc_bustype = CY_BUSTYPE_PCI; sc->sc_bustype = CY_BUSTYPE_PCI;
if (cy_map_pci(pa, sc, &ioh, &iosize, &memsize) == 0) if (cy_map_pci(pap, &iot, &ioh, &iosize, &memt, &memh,
panic("%s: mapping failed", sc->sc_dev.dv_xname); &memsize) == 0) {
printf(": unable to map device registers\n");
return;
}
if (cy_find(sc) == 0) sc->sc_memt = memt;
panic("%s: Cannot find card", sc->sc_dev.dv_xname); sc->sc_bsh = memh;
if (cy_find(sc) == 0) {
printf(": cannot find CD1400s\n");
return;
}
/* Set up interrupt handler. */
if (pci_intr_map(pap->pa_pc, pap->pa_intrtag, pap->pa_intrpin,
pap->pa_intrline, &intrhandle) != 0) {
printf(": couldn't map PCI interrupt\n");
return;
}
intrstr = pci_intr_string(pap->pa_pc, intrhandle);
sc->sc_ih = pci_intr_establish(pap->pa_pc, intrhandle, IPL_TTY,
cy_intr, sc);
if (sc->sc_ih == NULL) {
printf(": couldn't establish interrupt", sc->sc_dev.dv_xname);
if (intrstr != NULL)
printf(" at %s", intrstr);
printf("\n");
return;
}
if (intrstr != NULL)
printf(": interrupting at %s\n%s", intrstr, self->dv_xname);
/* attach the hardware */
cy_attach(parent, self, aux); cy_attach(parent, self, aux);
/* Enable PCI card interrupts */ /* Enable PCI card interrupts */
bus_space_write_2(sc->sc_iot, ioh, CY_PCI_INTENA, bus_space_write_2(iot, ioh, CY_PCI_INTENA,
bus_space_read_2(sc->sc_iot, ioh, CY_PCI_INTENA) | 0x900); bus_space_read_2(iot, ioh, CY_PCI_INTENA) | 0x900);
if (pci_intr_map(pa->pa_pc, pa->pa_intrtag, pa->pa_intrpin,
pa->pa_intrline, &intrhandle) != 0)
panic("%s: couldn't map PCI interrupt", sc->sc_dev.dv_xname);
sc->sc_ih = pci_intr_establish(pa->pa_pc, intrhandle,
IPL_TTY, cy_intr, sc);
if (sc->sc_ih == NULL)
panic("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
} }