Clean up the PCI attachment a bit, and adjust the other pieces

to suit.
This commit is contained in:
thorpej 2001-01-20 02:15:01 +00:00
parent cd3120ae66
commit a0f7017e2e
3 changed files with 118 additions and 160 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cy.c,v 1.16 2000/11/01 23:54:57 eeh Exp $ */
/* $NetBSD: cy.c,v 1.17 2001/01/20 02:15:02 thorpej Exp $ */
/*
* cy.c
@ -213,7 +213,7 @@ cy_attach(parent, self, aux)
} /* for(each CD1400 on a card... ) */
printf(": %d ports\n", port);
printf("%s: %d ports\n", sc->sc_dev.dv_xname, port);
/* ensure an edge for the next interrupt */
bus_space_write_1(sc->sc_memt, sc->sc_bsh,

View File

@ -1,4 +1,4 @@
/* $NetBSD: cy_isa.c,v 1.10 1998/06/09 07:24:58 thorpej Exp $ */
/* $NetBSD: cy_isa.c,v 1.11 2001/01/20 02:15:01 thorpej Exp $ */
/*
* cy.c
@ -7,7 +7,6 @@
* (currently not tested with Cyclom-32 cards)
*
* Timo Rossi, 1996
*
*/
#include <sys/param.h>
@ -24,18 +23,15 @@
#include <dev/ic/cyreg.h>
#include <dev/ic/cyvar.h>
static int cy_probe_isa __P((struct device *, struct cfdata *, void *));
static void cy_attach_isa __P((struct device *, struct device *, void *));
int cy_isa_probe(struct device *, struct cfdata *, void *);
void cy_isa_attach(struct device *, struct device *, void *);
struct cfattach cy_isa_ca = {
sizeof(struct cy_softc), cy_probe_isa, cy_attach_isa
sizeof(struct cy_softc), cy_isa_probe, cy_isa_attach
};
static int
cy_probe_isa(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
int
cy_isa_probe(struct device *parent, struct cfdata *match, void *aux)
{
struct isa_attach_args *ia = aux;
struct cy_softc sc;
@ -47,15 +43,11 @@ cy_probe_isa(parent, match, aux)
sc.sc_bustype = CY_BUSTYPE_ISA;
/* Disallow wildcarded memory address. */
if (ia->ia_maddr == ISACF_IOMEM_DEFAULT) {
printf("%s: memory addr not defined\n", sc.sc_dev.dv_xname);
if (ia->ia_maddr == ISACF_IOMEM_DEFAULT)
return (0);
}
if (ia->ia_irq == IRQUNK) {
printf("%s: interrupt not defined\n", sc.sc_dev.dv_xname);
if (ia->ia_irq == IRQUNK)
return 0;
}
if (bus_space_map(ia->ia_memt, ia->ia_maddr, CY_MEMSIZE, 0,
&sc.sc_bsh) != 0)
@ -70,13 +62,11 @@ cy_probe_isa(parent, match, aux)
ia->ia_msize = CY_MEMSIZE;
}
return found;
return (found);
}
static void
cy_attach_isa(parent, self, aux)
struct device *parent, *self;
void *aux;
void
cy_isa_attach(struct device *parent, struct device *self, void *aux)
{
struct cy_softc *sc = (void *) self;
struct isa_attach_args *ia = aux;
@ -84,14 +74,17 @@ cy_attach_isa(parent, self, aux)
sc->sc_memt = ia->ia_memt;
sc->sc_bustype = CY_BUSTYPE_ISA;
printf(": Cyclades-Y multiport serial\n");
if (bus_space_map(ia->ia_memt, ia->ia_maddr, CY_MEMSIZE, 0,
&sc->sc_bsh) != 0) {
printf(": cannot map mem space\n");
printf("%s: unable to map device registers\n",
sc->sc_dev.dv_xname);
return;
}
if (cy_find(sc) == 0) {
printf(": cy_find failed\n");
printf("%s: unable to find CD1400s\n", sc->sc_dev.dv_xname);
return;
}
@ -99,7 +92,7 @@ cy_attach_isa(parent, self, aux)
sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq,
IST_EDGE, IPL_TTY, cy_intr, sc);
if (sc->sc_ih == NULL)
printf("%s: couldn't establish interrupt", sc->sc_dev.dv_xname);
printf("%s: unable to establish interrupt",
sc->sc_dev.dv_xname);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: cy_pci.c,v 1.10 2000/12/28 22:59:11 sommerfeld Exp $ */
/* $NetBSD: cy_pci.c,v 1.11 2001/01/20 02:15:02 thorpej Exp $ */
/*
* cy_pci.c
@ -7,8 +7,8 @@
* (currently not tested with Cyclom-32 cards)
*
* Timo Rossi, 1996
*
*/
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
@ -24,182 +24,147 @@
#include <dev/ic/cyreg.h>
#include <dev/ic/cyvar.h>
static int cy_match_pci __P((struct device *, struct cfdata *, void *));
static void cy_attach_pci __P((struct device *, struct device *, void *));
static int cy_map_pci __P((struct pci_attach_args *, bus_space_tag_t *,
bus_space_handle_t *, bus_size_t *, bus_space_tag_t *,
bus_space_handle_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 cy_pci_softc {
struct cy_softc sc_cy; /* real cy softc */
struct cfattach cy_pci_ca = {
sizeof(struct cy_softc), cy_match_pci, cy_attach_pci
bus_space_tag_t sc_iot; /* PLX runtime i/o tag */
bus_space_handle_t sc_ioh; /* PLX runtime i/o handle */
};
static int
cy_map_pci(pap, iotp, iohp, iosizep, memtp, memhp, memsizep)
struct pci_attach_args *pap;
bus_space_tag_t *iotp, *memtp;
bus_space_handle_t *iohp, *memhp;
bus_size_t *iosizep, *memsizep;
int cy_pci_match(struct device *, struct cfdata *, void *);
void cy_pci_attach(struct device *, struct device *, void *);
struct cfattach cy_pci_ca = {
sizeof(struct cy_pci_softc), cy_pci_match, cy_pci_attach
};
static const struct cy_pci_product {
pci_product_id_t cp_product; /* product ID */
pcireg_t cp_memtype; /* memory type */
} cy_pci_products[] = {
{ PCI_PRODUCT_CYCLADES_CYCLOMY_1,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT_1M },
{ PCI_PRODUCT_CYCLADES_CYCLOM4Y_1,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT_1M },
{ PCI_PRODUCT_CYCLADES_CYCLOM8Y_1,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT_1M },
{ PCI_PRODUCT_CYCLADES_CYCLOMY_2,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT },
{ PCI_PRODUCT_CYCLADES_CYCLOM4Y_2,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT },
{ PCI_PRODUCT_CYCLADES_CYCLOM8Y_2,
PCI_MAPREG_TYPE_MEM|PCI_MAPREG_MEM_TYPE_32BIT },
{ 0,
0 },
};
static const int cy_pci_nproducts =
sizeof(cy_pci_products) / sizeof(cy_pci_products[0]);
static const struct cy_pci_product *
cy_pci_lookup(const struct pci_attach_args *pa)
{
int ioh_valid, memh_valid;
pcireg_t expected;
const struct cy_pci_product *cp;
int i;
/* Map I/O (if possible). */
ioh_valid = (pci_mapreg_map(pap, 0x14, PCI_MAPREG_TYPE_IO, 0,
iotp, iohp, NULL, iosizep) == 0);
if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_CYCLADES)
return (NULL);
/* Map mem (if possible). Expected mem type depends on board ID. */
expected = PCI_MAPREG_TYPE_MEM;
switch (PCI_PRODUCT(pap->pa_id)) {
case PCI_PRODUCT_CYCLADES_CYCLOMY_1:
case PCI_PRODUCT_CYCLADES_CYCLOM4Y_1:
case PCI_PRODUCT_CYCLADES_CYCLOM8Y_1:
expected |= PCI_MAPREG_MEM_TYPE_32BIT_1M;
break;
default:
expected |= PCI_MAPREG_MEM_TYPE_32BIT;
for (i = 0; i < cy_pci_nproducts; i++) {
cp = &cy_pci_products[i];
if (PCI_PRODUCT(pa->pa_id) == cp->cp_product)
return (cp);
}
memh_valid = (pci_mapreg_map(pap, 0x18, expected, 0,
memtp, memhp, NULL, memsizep) == 0);
if (ioh_valid && memh_valid)
return (1);
if (ioh_valid)
bus_space_unmap(*iotp, *iohp, *iosizep);
if (memh_valid)
bus_space_unmap(*memtp, *memhp, *memsizep);
return (0);
return (NULL);
}
static void
cy_unmap_pci(iot, ioh, iosize, memt, memh, memsize)
bus_space_tag_t iot, memt;
bus_space_handle_t ioh, memh;
bus_size_t iosize, memsize;
int
cy_pci_match(struct device *parent, struct cfdata *match, void *aux)
{
bus_space_unmap(iot, ioh, iosize);
bus_space_unmap(memt, memh, memsize);
struct pci_attach_args *pa = aux;
return (cy_pci_lookup(pa) != NULL);
}
static int
cy_match_pci(parent, match, aux)
struct device *parent;
struct cfdata *match;
void *aux;
void
cy_pci_attach(struct device *parent, struct device *self, void *aux)
{
struct pci_attach_args *pap = aux;
bus_space_tag_t iot, memt;
bus_space_handle_t ioh, memh;
bus_size_t iosize, memsize;
if (PCI_VENDOR(pap->pa_id) != PCI_VENDOR_CYCLADES)
return 0;
switch (PCI_PRODUCT(pap->pa_id)) {
case PCI_PRODUCT_CYCLADES_CYCLOMY_1:
case PCI_PRODUCT_CYCLADES_CYCLOMY_2:
case PCI_PRODUCT_CYCLADES_CYCLOM4Y_1:
case PCI_PRODUCT_CYCLADES_CYCLOM4Y_2:
case PCI_PRODUCT_CYCLADES_CYCLOM8Y_1:
case PCI_PRODUCT_CYCLADES_CYCLOM8Y_2:
break;
default:
return 0;
}
#ifdef CY_DEBUG
printf("cy: Found Cyclades PCI device, id = 0x%x\n", pap->pa_id);
#endif
if (cy_map_pci(pap, &iot, &ioh, &iosize, &memt, &memh, &memsize) == 0)
return (0);
#if 0
XXX probably should do something like this, but this code is just
XXX too broken.
#ifdef CY_DEBUG
printf("%s: pci mapped mem 0x%lx (size %d), io 0x%x (size %d)\n",
sc.sc_dev.dv_xname, memaddr, memsize, iobase, iosize);
#endif
if ((rv = cy_find(&sc)) == 0)
printf("%s: PCI Cyclom card with no CD1400s!?\n",
sc.sc_dev.dv_xname);
#endif /* 0 */
cy_unmap_pci(iot, ioh, iosize, memt, memh, memsize);
return (1);
}
static void
cy_attach_pci(parent, self, aux)
struct device *parent, *self;
void *aux;
{
struct cy_softc *sc = (void *) self;
struct pci_attach_args *pap = aux;
pci_intr_handle_t intrhandle;
bus_space_tag_t iot, memt;
bus_space_handle_t ioh, memh;
bus_size_t iosize, memsize;
struct cy_pci_softc *psc = (void *) self;
struct cy_softc *sc = (void *) &psc->sc_cy;
struct pci_attach_args *pa = aux;
pci_intr_handle_t ih;
const struct cy_pci_product *cp;
const char *intrstr;
int plx_ver;
sc->sc_bustype = CY_BUSTYPE_PCI;
if (cy_map_pci(pap, &iot, &ioh, &iosize, &memt, &memh,
&memsize) == 0) {
printf(": unable to map device registers\n");
cp = cy_pci_lookup(pa);
if (cp == NULL)
panic("cy_pci_attach: impossible");
printf(": Cyclades-Y multiport serial\n");
if (pci_mapreg_map(pa, 0x14, PCI_MAPREG_TYPE_IO, 0,
&psc->sc_iot, &psc->sc_ioh, NULL, NULL) != 0) {
printf("%s: unable to map PLX registers\n",
sc->sc_dev.dv_xname);
return;
}
sc->sc_memt = memt;
sc->sc_bsh = memh;
if (pci_mapreg_map(pa, 0x18, cp->cp_memtype, 0,
&sc->sc_memt, &sc->sc_bsh, NULL, NULL) != 0) {
printf("%s: unable to map device registers\n",
sc->sc_dev.dv_xname);
return;
}
if (cy_find(sc) == 0) {
printf(": cannot find CD1400s\n");
printf("%s: unable to find CD1400s\n", sc->sc_dev.dv_xname);
return;
}
/* Set up interrupt handler. */
if (pci_intr_map(pap, &intrhandle) != 0) {
printf(": couldn't map PCI interrupt\n");
/*
* XXX Like the Cyclades-Z, we should really check the EEPROM to
* determine the "poll or interrupt" setting. For now, we always
* map the interrupt and enable it in the PLX.
*/
/* Map and establish the interrupt. */
if (pci_intr_map(pa, &ih) != 0) {
printf(": unable to map 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);
intrstr = pci_intr_string(pa->pa_pc, ih);
sc->sc_ih = pci_intr_establish(pa->pa_pc, ih, IPL_TTY, cy_intr, sc);
if (sc->sc_ih == NULL) {
printf(": couldn't establish interrupt");
printf(": unable to establish interrupt");
if (intrstr != NULL)
printf(" at %s", intrstr);
printf("\n");
return;
}
if (intrstr != NULL)
printf(": interrupting at %s\n%s", intrstr, self->dv_xname);
printf("%s: interrupting at %s\n", sc->sc_dev.dv_xname, intrstr);
/* attach the hardware */
cy_attach(parent, self, aux);
plx_ver = bus_space_read_1(memt, memh, CY_PLX_VER) & 0x0f;
plx_ver = bus_space_read_1(sc->sc_memt, sc->sc_bsh, CY_PLX_VER) & 0x0f;
/* Enable PCI card interrupts */
switch (plx_ver) {
case CY_PLX_9050:
bus_space_write_2(iot, ioh, CY_PCI_INTENA_9050,
bus_space_read_2(iot, ioh, CY_PCI_INTENA_9050) | 0x40);
bus_space_write_2(psc->sc_iot, psc->sc_ioh, CY_PCI_INTENA_9050,
bus_space_read_2(psc->sc_iot, psc->sc_ioh,
CY_PCI_INTENA_9050) | 0x40);
break;
case CY_PLX_9060:
case CY_PLX_9080:
default:
bus_space_write_2(iot, ioh, CY_PCI_INTENA,
bus_space_read_2(iot, ioh, CY_PCI_INTENA) | 0x900);
bus_space_write_2(psc->sc_iot, psc->sc_ioh, CY_PCI_INTENA,
bus_space_read_2(psc->sc_iot, psc->sc_ioh,
CY_PCI_INTENA) | 0x900);
}
}