pccard_cis_quirks.c revision 52506
1254244Speter/* $NetBSD: pcmcia_cis_quirks.c,v 1.3 1998/12/29 09:00:28 marc Exp $ */ 2254244Speter/* $FreeBSD: head/sys/dev/pccard/pccard_cis_quirks.c 52506 1999-10-26 06:52:31Z imp $ */ 3254244Speter 4254244Speter#define PCCARDDEBUG 5254244Speter 6254244Speter/* 7254244Speter * Copyright (c) 1998 Marc Horowitz. All rights reserved. 8254244Speter * 9254244Speter * Redistribution and use in source and binary forms, with or without 10254244Speter * modification, are permitted provided that the following conditions 11254244Speter * are met: 12254244Speter * 1. Redistributions of source code must retain the above copyright 13254244Speter * notice, this list of conditions and the following disclaimer. 14254244Speter * 2. Redistributions in binary form must reproduce the above copyright 15254244Speter * notice, this list of conditions and the following disclaimer in the 16254244Speter * documentation and/or other materials provided with the distribution. 17254244Speter * 3. All advertising materials mentioning features or use of this software 18254244Speter * must display the following acknowledgement: 19254244Speter * This product includes software developed by Marc Horowitz. 20254244Speter * 4. The name of the author may not be used to endorse or promote products 21254244Speter * derived from this software without specific prior written permission. 22254244Speter * 23254244Speter * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 24254244Speter * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 25254244Speter * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 26254244Speter * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 27254244Speter * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 28254244Speter * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 29254244Speter * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 30254244Speter * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 31254244Speter * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 32254244Speter * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33254244Speter */ 34254244Speter 35254244Speter#include <sys/param.h> 36254244Speter#include <sys/systm.h> 37254244Speter#include <sys/malloc.h> 38254244Speter#include <sys/module.h> 39254244Speter#include <sys/kernel.h> 40254244Speter#include <sys/queue.h> 41254244Speter#include <sys/types.h> 42254244Speter 43254244Speter#include <sys/bus.h> 44254244Speter#include <machine/bus.h> 45254244Speter#include <sys/rman.h> 46254244Speter#include <machine/resource.h> 47254244Speter 48254244Speter#include <dev/pccard/pccarddevs.h> 49254244Speter#include <dev/pccard/pccardreg.h> 50254244Speter#include <dev/pccard/pccardchip.h> 51254244Speter#include <dev/pccard/pccardvar.h> 52254244Speter 53254244Speter/* There are cards out there whose CIS flat-out lies. This file 54254244Speter contains struct pccard_function chains for those devices. */ 55254244Speter 56254244Speter/* these structures are just static templates which are then copied 57254244Speter into "live" allocated structures */ 58254244Speter 59254244Speterstruct pccard_function pccard_3cxem556_func0 = { 60254244Speter 0, /* function number */ 61254244Speter PCCARD_FUNCTION_NETWORK, 62254244Speter 0x07, /* last cfe number */ 63254244Speter 0x800, /* ccr_base */ 64254244Speter 0x63, /* ccr_mask */ 65254244Speter}; 66254244Speter 67254244Speterstruct pccard_config_entry pccard_3cxem556_func0_cfe0 = { 68254244Speter 0x07, /* cfe number */ 69254244Speter PCCARD_CFE_IO8 | PCCARD_CFE_IO16 | PCCARD_CFE_IRQLEVEL, 70254244Speter PCCARD_IFTYPE_IO, 71254244Speter 1, /* num_iospace */ 72254244Speter 4, /* iomask */ 73254244Speter { { 0x0010, 0 } }, /* iospace */ 74254244Speter 0xffff, /* irqmask */ 75254244Speter 0, /* num_memspace */ 76254244Speter { }, /* memspace */ 77254244Speter 0, /* maxtwins */ 78254244Speter}; 79254244Speter 80254244Speterstatic struct pccard_function pccard_3cxem556_func1 = { 81254244Speter 1, /* function number */ 82254244Speter PCCARD_FUNCTION_SERIAL, 83254244Speter 0x27, /* last cfe number */ 84254244Speter 0x900, /* ccr_base */ 85254244Speter 0x63, /* ccr_mask */ 86254244Speter}; 87254244Speter 88254244Speterstatic struct pccard_config_entry pccard_3cxem556_func1_cfe0 = { 89254244Speter 0x27, /* cfe number */ 90254244Speter PCCARD_CFE_IO8 | PCCARD_CFE_IRQLEVEL, 91254244Speter PCCARD_IFTYPE_IO, 92254244Speter 1, /* num_iospace */ 93254244Speter 3, /* iomask */ 94254244Speter { { 0x0008, 0 } }, /* iospace */ 95254244Speter 0xffff, /* irqmask */ 96254244Speter 0, /* num_memspace */ 97254244Speter { }, /* memspace */ 98254244Speter 0, /* maxtwins */ 99254244Speter}; 100254244Speter 101254244Speterstatic struct pccard_function pccard_sveclancard_func0 = { 102254244Speter 0, /* function number */ 103254244Speter PCCARD_FUNCTION_NETWORK, 104254244Speter 0x1, /* last cfe number */ 105254244Speter 0x100, /* ccr_base */ 106254244Speter 0x1, /* ccr_mask */ 107254244Speter}; 108254244Speter 109254244Speterstatic struct pccard_config_entry pccard_sveclancard_func0_cfe0 = { 110254244Speter 0x1, /* cfe number */ 111254244Speter PCCARD_CFE_MWAIT_REQUIRED | PCCARD_CFE_RDYBSY_ACTIVE | 112254244Speter PCCARD_CFE_WP_ACTIVE | PCCARD_CFE_BVD_ACTIVE | PCCARD_CFE_IO16, 113254244Speter PCCARD_IFTYPE_IO, 114254244Speter 1, /* num_iospace */ 115254244Speter 5, /* iomask */ 116254244Speter { { 0x20, 0x300 } }, /* iospace */ 117254244Speter 0xdeb8, /* irqmask */ 118254244Speter 0, /* num_memspace */ 119254244Speter { }, /* memspace */ 120254244Speter 0, /* maxtwins */ 121254244Speter}; 122254244Speter 123254244Speterstatic struct pccard_cis_quirk pccard_cis_quirks[] = { 124254244Speter { PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556, PCCARD_CIS_INVALID, 125254244Speter &pccard_3cxem556_func0, &pccard_3cxem556_func0_cfe0 }, 126254244Speter { PCCARD_VENDOR_3COM, PCCARD_PRODUCT_3COM_3CXEM556, PCCARD_CIS_INVALID, 127254244Speter &pccard_3cxem556_func1, &pccard_3cxem556_func1_cfe0 }, 128254244Speter { PCCARD_VENDOR_INVALID, PCCARD_PRODUCT_INVALID, PCCARD_CIS_SVEC_LANCARD, 129254244Speter &pccard_sveclancard_func0, &pccard_sveclancard_func0_cfe0 }, 130254244Speter}; 131254244Speter 132254244Speterstatic int n_pccard_cis_quirks = 133254244Speter sizeof(pccard_cis_quirks)/sizeof(pccard_cis_quirks[0]); 134254244Speter 135254244Spetervoid pccard_check_cis_quirks(device_t dev) 136254244Speter{ 137254244Speter struct pccard_softc *sc = (struct pccard_softc *) 138254244Speter device_get_softc(dev); 139254244Speter int wiped = 0; 140254244Speter int i, j; 141254244Speter struct pccard_function *pf, *pf_next, *pf_last; 142254244Speter struct pccard_config_entry *cfe, *cfe_next; 143254244Speter 144254244Speter pf = NULL; 145254244Speter pf_last = NULL; 146254244Speter 147254244Speter for (i=0; i<n_pccard_cis_quirks; i++) { 148254244Speter if ((sc->card.manufacturer == pccard_cis_quirks[i].manufacturer) && 149254244Speter (sc->card.product == pccard_cis_quirks[i].product) && 150254244Speter (((sc->card.manufacturer != PCCARD_VENDOR_INVALID) && 151254244Speter (sc->card.product != PCCARD_PRODUCT_INVALID)) || 152254244Speter ((sc->card.manufacturer == PCCARD_VENDOR_INVALID) && 153254244Speter (sc->card.product == PCCARD_PRODUCT_INVALID) && 154254244Speter sc->card.cis1_info[0] && 155254244Speter (strcmp(sc->card.cis1_info[0], 156254244Speter pccard_cis_quirks[i].cis1_info[0]) == 0) && 157254244Speter sc->card.cis1_info[1] && 158254244Speter (strcmp(sc->card.cis1_info[1], 159254244Speter pccard_cis_quirks[i].cis1_info[1]) == 0)))) { 160254244Speter if (!wiped) { 161254244Speter if (pccard_verbose) { 162254244Speter device_printf(dev, "using CIS quirks for "); 163254244Speter for (j = 0; j < 4; j++) { 164254244Speter if (sc->card.cis1_info[j] == NULL) 165254244Speter break; 166254244Speter if (j) 167254244Speter printf(", "); 168254244Speter printf("%s", sc->card.cis1_info[j]); 169254244Speter } 170254244Speter printf("\n"); 171254244Speter } 172254244Speter 173254244Speter for (pf = STAILQ_FIRST(&sc->card.pf_head); pf != NULL; 174254244Speter pf = pf_next) { 175254244Speter for (cfe = STAILQ_FIRST(&pf->cfe_head); cfe != NULL; 176254244Speter cfe = cfe_next) { 177254244Speter cfe_next = STAILQ_NEXT(cfe, cfe_list); 178254244Speter free(cfe, M_DEVBUF); 179254244Speter } 180254244Speter pf_next = STAILQ_NEXT(pf, pf_list); 181254244Speter free(pf, M_DEVBUF); 182254244Speter } 183254244Speter 184254244Speter STAILQ_INIT(&sc->card.pf_head); 185254244Speter wiped = 1; 186254244Speter } 187254244Speter 188254244Speter if (pf_last == pccard_cis_quirks[i].pf) { 189254244Speter cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 190254244Speter *cfe = *pccard_cis_quirks[i].cfe; 191254244Speter 192254244Speter STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 193254244Speter } else { 194254244Speter pf = malloc(sizeof(*pf), M_DEVBUF, M_NOWAIT); 195254244Speter *pf = *pccard_cis_quirks[i].pf; 196254244Speter STAILQ_INIT(&pf->cfe_head); 197254244Speter 198254244Speter cfe = malloc(sizeof(*cfe), M_DEVBUF, M_NOWAIT); 199254244Speter *cfe = *pccard_cis_quirks[i].cfe; 200254244Speter 201254244Speter STAILQ_INSERT_TAIL(&pf->cfe_head, cfe, cfe_list); 202254244Speter STAILQ_INSERT_TAIL(&sc->card.pf_head, pf, pf_list); 203254244Speter 204254244Speter pf_last = pccard_cis_quirks[i].pf; 205254244Speter } 206254244Speter } 207254244Speter } 208254244Speter} 209254244Speter