Annotation of sys/dev/pcmcia/aic_pcmcia.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: aic_pcmcia.c,v 1.15 2006/06/03 01:51:54 martin Exp $ */
2: /* $NetBSD: aic_pcmcia.c,v 1.6 1998/07/19 17:28:15 christos Exp $ */
3:
4: /*
5: * Copyright (c) 1997 Marc Horowitz. All rights reserved.
6: *
7: * Redistribution and use in source and binary forms, with or without
8: * modification, are permitted provided that the following conditions
9: * are met:
10: * 1. Redistributions of source code must retain the above copyright
11: * notice, this list of conditions and the following disclaimer.
12: * 2. Redistributions in binary form must reproduce the above copyright
13: * notice, this list of conditions and the following disclaimer in the
14: * documentation and/or other materials provided with the distribution.
15: * 3. All advertising materials mentioning features or use of this software
16: * must display the following acknowledgement:
17: * This product includes software developed by Marc Horowitz.
18: * 4. The name of the author may not be used to endorse or promote products
19: * derived from this software without specific prior written permission.
20: *
21: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30: * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31: */
32:
33: #include <sys/param.h>
34: #include <sys/systm.h>
35: #include <sys/selinfo.h>
36: #include <sys/device.h>
37:
38: #include <machine/cpu.h>
39: #include <machine/bus.h>
40: #include <machine/intr.h>
41:
42: #include <scsi/scsi_all.h>
43: #include <scsi/scsiconf.h>
44:
45: #include <dev/ic/aic6360var.h>
46:
47: #include <dev/pcmcia/pcmciareg.h>
48: #include <dev/pcmcia/pcmciavar.h>
49: #include <dev/pcmcia/pcmciadevs.h>
50:
51: int aic_pcmcia_match(struct device *, void *, void *);
52: void aic_pcmcia_attach(struct device *, struct device *, void *);
53: int aic_pcmcia_detach(struct device *, int);
54:
55: struct aic_pcmcia_softc {
56: struct aic_softc sc_aic; /* real "aic" softc */
57:
58: /* PCMCIA-specific goo. */
59: struct pcmcia_io_handle sc_pcioh; /* PCMCIA i/o space info */
60: int sc_io_window; /* our i/o window */
61: struct pcmcia_function *sc_pf; /* our PCMCIA function */
62: void *sc_ih; /* interrupt handler */
63: };
64:
65: struct cfattach aic_pcmcia_ca = {
66: sizeof(struct aic_pcmcia_softc), aic_pcmcia_match, aic_pcmcia_attach,
67: aic_pcmcia_detach
68: };
69:
70: struct aic_pcmcia_product {
71: u_int16_t app_vendor; /* PCMCIA vendor ID */
72: u_int16_t app_product; /* PCMCIA product ID */
73: int app_expfunc; /* expected function number */
74: } aic_pcmcia_prod[] = {
75: { PCMCIA_VENDOR_ADAPTEC, PCMCIA_PRODUCT_ADAPTEC_APA1460_1,
76: 0 },
77:
78: { PCMCIA_VENDOR_ADAPTEC, PCMCIA_PRODUCT_ADAPTEC_APA1460_2,
79: 0 },
80:
81: { PCMCIA_VENDOR_NEWMEDIA, PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER,
82: 0 }
83: };
84:
85: int
86: aic_pcmcia_match(parent, match, aux)
87: struct device *parent;
88: void *match, *aux;
89: {
90: struct pcmcia_attach_args *pa = aux;
91: int i;
92:
93: for (i = 0; i < sizeof(aic_pcmcia_prod)/sizeof(aic_pcmcia_prod[0]); i++)
94: if (pa->manufacturer == aic_pcmcia_prod[i].app_vendor &&
95: pa->product == aic_pcmcia_prod[i].app_product &&
96: pa->pf->number == aic_pcmcia_prod[i].app_expfunc)
97: return (1);
98: return (0);
99: }
100:
101: void
102: aic_pcmcia_attach(parent, self, aux)
103: struct device *parent, *self;
104: void *aux;
105: {
106: struct aic_pcmcia_softc *psc = (void *)self;
107: struct aic_softc *sc = &psc->sc_aic;
108: struct pcmcia_attach_args *pa = aux;
109: struct pcmcia_config_entry *cfe;
110: struct pcmcia_function *pf = pa->pf;
111: const char *intrstr;
112:
113: psc->sc_pf = pf;
114:
115: for (cfe = SIMPLEQ_FIRST(&pf->cfe_head); cfe != NULL;
116: cfe = SIMPLEQ_NEXT(cfe, cfe_list)) {
117: if (cfe->num_memspace != 0 ||
118: cfe->num_iospace != 1)
119: continue;
120:
121: /* The bustoaster has a default config as first
122: * entry, we don't want to use that. */
123:
124: if (pa->manufacturer == PCMCIA_VENDOR_NEWMEDIA &&
125: pa->product == PCMCIA_PRODUCT_NEWMEDIA_BUSTOASTER &&
126: cfe->iospace[0].start == 0)
127: continue;
128:
129: if (pcmcia_io_alloc(pa->pf, cfe->iospace[0].start,
130: cfe->iospace[0].length, AIC_NPORTS, &psc->sc_pcioh) == 0)
131: break;
132: }
133:
134: if (cfe == 0) {
135: printf(": can't alloc i/o space\n");
136: return;
137: }
138:
139: sc->sc_iot = psc->sc_pcioh.iot;
140: sc->sc_ioh = psc->sc_pcioh.ioh;
141:
142: /* Enable the card. */
143: pcmcia_function_init(pf, cfe);
144: if (pcmcia_function_enable(pf)) {
145: printf(": function enable failed\n");
146: return;
147: }
148:
149: /* Map in the io space */
150: if (pcmcia_io_map(pa->pf, PCMCIA_WIDTH_AUTO, 0, psc->sc_pcioh.size,
151: &psc->sc_pcioh, &psc->sc_io_window)) {
152: printf(": can't map i/o space\n");
153: return;
154: }
155:
156: printf(" port 0x%lx/%lu", psc->sc_pcioh.addr,
157: (u_long)psc->sc_pcioh.size);
158:
159: if (!aic_find(sc->sc_iot, sc->sc_ioh)) {
160: printf(": unable to detect chip!\n");
161: return;
162: }
163:
164: /* Establish the interrupt handler. */
165: psc->sc_ih = pcmcia_intr_establish(pa->pf, IPL_BIO,
166: aicintr, sc, sc->sc_dev.dv_xname);
167: intrstr = pcmcia_intr_string(psc->sc_pf, psc->sc_ih);
168: printf("%s%s\n", *intrstr ? ", " : "", intrstr);
169: if (psc->sc_ih == NULL)
170: return;
171:
172: aicattach(sc);
173:
174: }
175:
176: int
177: aic_pcmcia_detach(self, flags)
178: struct device *self;
179: int flags;
180: {
181: struct aic_pcmcia_softc *sc= (void *)self;
182: int error;
183:
184: error = aic_detach(self, flags);
185: if (error)
186: return (error);
187:
188: /* Unmap our i/o window and i/o space. */
189: pcmcia_io_unmap(sc->sc_pf, sc->sc_io_window);
190: pcmcia_io_free(sc->sc_pf, &sc->sc_pcioh);
191:
192: return (0);
193: }
CVSweb