From d266c2db1c923c73bd401f1e02592e541de9bf4a Mon Sep 17 00:00:00 2001 From: Warner Losh Date: Mon, 6 Oct 2003 07:17:20 +0000 Subject: refactor how we do the quirk matching. this puts an ugly if into a routine of its own, and allows us to move the indentation back two layers making the code more readable. delete a prototype that should have been killed years ago in pccardvar.h. # adding quirks here is way harder than it needs to be. :-( --- sys/dev/pccard/pccard_cis_quirks.c | 108 +++++++++++++++++++------------------ sys/dev/pccard/pccardvar.h | 6 +-- 2 files changed, 58 insertions(+), 56 deletions(-) (limited to 'sys/dev') diff --git a/sys/dev/pccard/pccard_cis_quirks.c b/sys/dev/pccard/pccard_cis_quirks.c index 98cf67ef85d31..87928b506f3fc 100644 --- a/sys/dev/pccard/pccard_cis_quirks.c +++ b/sys/dev/pccard/pccard_cis_quirks.c @@ -208,6 +208,23 @@ static struct pccard_cis_quirk pccard_cis_quirks[] = { static int n_pccard_cis_quirks = sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]); +static int +pccard_cis_quirk_match(struct pccard_softc *sc, struct pccard_cis_quirk *q) +{ + if ((sc->card.manufacturer == q->manufacturer) && + (sc->card.product == q->product) && + (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && + (sc->card.product != PCMCIA_PRODUCT_INVALID)) || + ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && + (sc->card.product == PCMCIA_PRODUCT_INVALID) && + sc->card.cis1_info[0] && + (strcmp(sc->card.cis1_info[0], q->cis1_info[0]) == 0) && + sc->card.cis1_info[1] && + (strcmp(sc->card.cis1_info[1], q->cis1_info[1]) == 0)))) + return (1); + return (0); +} + void pccard_check_cis_quirks(device_t dev) { struct pccard_softc *sc = PCCARD_SOFTC(dev); @@ -215,69 +232,56 @@ void pccard_check_cis_quirks(device_t dev) int i, j; struct pccard_function *pf, *pf_next, *pf_last; struct pccard_config_entry *cfe, *cfe_next; + struct pccard_cis_quirk *q; pf = NULL; pf_last = NULL; for (i=0; icard.manufacturer == pccard_cis_quirks[i].manufacturer) && - (sc->card.product == pccard_cis_quirks[i].product) && - (((sc->card.manufacturer != PCMCIA_VENDOR_INVALID) && - (sc->card.product != PCMCIA_PRODUCT_INVALID)) || - ((sc->card.manufacturer == PCMCIA_VENDOR_INVALID) && - (sc->card.product == PCMCIA_PRODUCT_INVALID) && - sc->card.cis1_info[0] && - (strcmp(sc->card.cis1_info[0], - pccard_cis_quirks[i].cis1_info[0]) == 0) && - sc->card.cis1_info[1] && - (strcmp(sc->card.cis1_info[1], - pccard_cis_quirks[i].cis1_info[1]) == 0)))) { - if (!wiped) { - if (bootverbose) { - device_printf(dev, "using CIS quirks for "); - for (j = 0; j < 4; j++) { - if (sc->card.cis1_info[j] == NULL) - break; - if (j) - printf(", "); - printf("%s", sc->card.cis1_info[j]); - } - printf("\n"); + q = &pccard_cis_quirks[i]; + if (!pccard_cis_quirk_match(sc, q)) + continue; + if (!wiped) { + if (bootverbose) { + device_printf(dev, "using CIS quirks for "); + for (j = 0; j < 4; j++) { + if (sc->card.cis1_info[j] == NULL) + break; + if (j) + printf(", "); + printf("%s", sc->card.cis1_info[j]); } + printf("\n"); + } - for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; - pf = pf_next) { - for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; - cfe = cfe_next) { - cfe_next = STAILQ_NEXT(cfe, cfe_list); - free(cfe, M_DEVBUF); - } - pf_next = STAILQ_NEXT(pf, pf_list); - free(pf, M_DEVBUF); + for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; + pf = pf_next) { + for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; + cfe = cfe_next) { + cfe_next = STAILQ_NEXT(cfe, cfe_list); + free(cfe, M_DEVBUF); } - - STAILQ_INIT(&sc->card.pf_head); - wiped = 1; + pf_next = STAILQ_NEXT(pf, pf_list); + free(pf, M_DEVBUF); } - if (pf_last == pccard_cis_quirks[i].pf) { - cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); - *cfe = *pccard_cis_quirks[i].cfe; - - STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); - } else { - pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); - *pf = *pccard_cis_quirks[i].pf; - STAILQ_INIT(&pf->cfe_head); - - cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); - *cfe = *pccard_cis_quirks[i].cfe; - - STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); - STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); + STAILQ_INIT(&sc->card.pf_head); + wiped = 1; + } - pf_last = pccard_cis_quirks[i].pf; - } + if (pf_last == q->pf) { + cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); + *cfe = *q->cfe; + STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); + } else { + pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); + *pf = *q->pf; + STAILQ_INIT(&pf->cfe_head); + cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); + *cfe = *q->cfe; + STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); + STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); + pf_last = q->pf; } } } diff --git a/sys/dev/pccard/pccardvar.h b/sys/dev/pccard/pccardvar.h index 43266f0d63871..0289a3fb04bc2 100644 --- a/sys/dev/pccard/pccardvar.h +++ b/sys/dev/pccard/pccardvar.h @@ -203,9 +203,6 @@ struct pccard_softc { int sc_enabled_count; /* num functions enabled */ }; -void -pccardbus_if_setup(struct pccard_softc*); - struct pccard_cis_quirk { int32_t manufacturer; int32_t product; @@ -286,7 +283,8 @@ int pccard_scan_cis(device_t, #define PCCARD_SPACE_MEMORY 1 #define PCCARD_SPACE_IO 2 -#define pccard_mfc(sc) (STAILQ_FIRST(&(sc)->card.pf_head) && \ +#define pccard_mfc(sc) \ + (STAILQ_FIRST(&(sc)->card.pf_head) && \ STAILQ_NEXT(STAILQ_FIRST(&(sc)->card.pf_head),pf_list)) #define pccard_io_alloc(pf, start, size, align, pciop) \ -- cgit v1.3