pccard.c revision 102704
1/*	$NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $	*/
2/* $FreeBSD: head/sys/dev/pccard/pccard.c 102704 2002-08-31 16:07:17Z phk $ */
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/malloc.h>
36#include <sys/module.h>
37#include <sys/kernel.h>
38#include <sys/queue.h>
39#include <sys/sysctl.h>
40#include <sys/types.h>
41
42#include <sys/bus.h>
43#include <machine/bus.h>
44#include <sys/rman.h>
45#include <machine/resource.h>
46
47#include <net/ethernet.h>
48
49#include <dev/pccard/pccardreg.h>
50#include <dev/pccard/pccardvar.h>
51
52#include "power_if.h"
53#include "card_if.h"
54
55#define PCCARDDEBUG
56
57/* sysctl vars */
58SYSCTL_NODE(_hw, OID_AUTO, pccard, CTLFLAG_RD, 0, "PCCARD parameters");
59
60int	pccard_debug = 0;
61TUNABLE_INT("hw.pccard.debug", &pccard_debug);
62SYSCTL_INT(_hw_pccard, OID_AUTO, debug, CTLFLAG_RW,
63    &pccard_debug, 0,
64  "pccard debug");
65
66int	pccard_cis_debug = 0;
67TUNABLE_INT("hw.pccard.cis_debug", &pccard_cis_debug);
68SYSCTL_INT(_hw_pccard, OID_AUTO, cis_debug, CTLFLAG_RW,
69    &pccard_cis_debug, 0, "pccard CIS debug");
70
71#ifdef PCCARDDEBUG
72#define	DPRINTF(arg) if (pccard_debug) printf arg
73#define	DEVPRINTF(arg) if (pccard_debug) device_printf arg
74#define PRVERBOSE(arg) printf arg
75#define DEVPRVERBOSE(arg) device_printf arg
76#else
77#define	DPRINTF(arg)
78#define	DEVPRINTF(arg)
79#define PRVERBOSE(arg) if (bootverbose) printf arg
80#define DEVPRVERBOSE(arg) if (bootverbose) device_printf arg
81#endif
82
83static int	pccard_ccr_read(struct pccard_function *pf, int ccr);
84static void	pccard_ccr_write(struct pccard_function *pf, int ccr, int val);
85static int	pccard_attach_card(device_t dev);
86static int	pccard_detach_card(device_t dev, int flags);
87static int	pccard_card_gettype(device_t dev, int *type);
88static void	pccard_function_init(struct pccard_function *pf);
89static void	pccard_function_free(struct pccard_function *pf);
90static int	pccard_function_enable(struct pccard_function *pf);
91static void	pccard_function_disable(struct pccard_function *pf);
92static int	pccard_compat_do_probe(device_t bus, device_t dev);
93static int	pccard_compat_do_attach(device_t bus, device_t dev);
94static int	pccard_add_children(device_t dev, int busno);
95static int	pccard_probe(device_t dev);
96static int	pccard_attach(device_t dev);
97static int	pccard_detach(device_t dev);
98static void	pccard_print_resources(struct resource_list *rl,
99		    const char *name, int type, int count, const char *format);
100static int	pccard_print_child(device_t dev, device_t child);
101static int	pccard_set_resource(device_t dev, device_t child, int type,
102		    int rid, u_long start, u_long count);
103static int	pccard_get_resource(device_t dev, device_t child, int type,
104		    int rid, u_long *startp, u_long *countp);
105static void	pccard_delete_resource(device_t dev, device_t child, int type,
106		    int rid);
107static int	pccard_set_res_flags(device_t dev, device_t child, int type,
108		    int rid, u_int32_t flags);
109static int	pccard_set_memory_offset(device_t dev, device_t child, int rid,
110		    u_int32_t offset, u_int32_t *deltap);
111static int	pccard_read_ivar(device_t bus, device_t child, int which,
112		    u_char *result);
113static void	pccard_driver_added(device_t dev, driver_t *driver);
114static struct resource *pccard_alloc_resource(device_t dev,
115		    device_t child, int type, int *rid, u_long start,
116		    u_long end, u_long count, u_int flags);
117static int	pccard_release_resource(device_t dev, device_t child, int type,
118		    int rid, struct resource *r);
119static void	pccard_child_detached(device_t parent, device_t dev);
120static void	pccard_intr(void *arg);
121static int	pccard_setup_intr(device_t dev, device_t child,
122		    struct resource *irq, int flags, driver_intr_t *intr,
123		    void *arg, void **cookiep);
124static int	pccard_teardown_intr(device_t dev, device_t child,
125		    struct resource *r, void *cookie);
126
127static const struct pccard_product *
128pccard_do_product_lookup(device_t bus, device_t dev,
129			 const struct pccard_product *tab, size_t ent_size,
130			 pccard_product_match_fn matchfn);
131
132
133static int
134pccard_ccr_read(struct pccard_function *pf, int ccr)
135{
136	return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh,
137	    pf->pf_ccr_offset + ccr));
138}
139
140static void
141pccard_ccr_write(struct pccard_function *pf, int ccr, int val)
142{
143	if ((pf->ccr_mask) & (1 << (ccr / 2))) {
144		bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh,
145		    pf->pf_ccr_offset + ccr, val);
146	}
147}
148
149static int
150pccard_attach_card(device_t dev)
151{
152	struct pccard_softc *sc = PCCARD_SOFTC(dev);
153	struct pccard_function *pf;
154	struct pccard_ivar *ivar;
155	device_t child;
156
157	/*
158	 * this is here so that when socket_enable calls gettype, trt happens
159	 */
160	STAILQ_INIT(&sc->card.pf_head);
161
162	DEVPRINTF((dev, "chip_socket_enable\n"));
163	POWER_ENABLE_SOCKET(device_get_parent(dev), dev);
164
165	DEVPRINTF((dev, "read_cis\n"));
166	pccard_read_cis(sc);
167
168	DEVPRINTF((dev, "check_cis_quirks\n"));
169	pccard_check_cis_quirks(dev);
170
171	/*
172	 * bail now if the card has no functions, or if there was an error in
173	 * the cis.
174	 */
175
176	if (sc->card.error) {
177		device_printf (dev, "CARD ERROR!\n");
178		return (1);
179	}
180	if (STAILQ_EMPTY(&sc->card.pf_head)) {
181		device_printf (dev, "Card has no functions!\n");
182		return (1);
183	}
184
185	if (bootverbose || pccard_debug)
186		pccard_print_cis(dev);
187
188	DEVPRINTF((dev, "functions scanning\n"));
189	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
190		if (STAILQ_EMPTY(&pf->cfe_head))
191			continue;
192
193		pf->sc = sc;
194		pf->cfe = NULL;
195		pf->dev = NULL;
196	}
197
198	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
199		if (STAILQ_EMPTY(&pf->cfe_head))
200			continue;
201		/*
202		 * In NetBSD, the drivers are responsible for activating
203		 * each function of a card.  I think that in FreeBSD we
204		 * want to activate them enough for the usual bus_*_resource
205		 * routines will do the right thing.  This many mean a
206		 * departure from the current NetBSD model.
207		 *
208		 * This could get really ugly for multifunction cards.  But
209		 * it might also just fall out of the FreeBSD resource model.
210		 *
211		 */
212		ivar = malloc(sizeof(struct pccard_ivar), M_DEVBUF,
213		    M_WAITOK | M_ZERO);
214		child = device_add_child(dev, NULL, -1);
215		device_set_ivars(child, ivar);
216		ivar->fcn = pf;
217		pf->dev = child;
218		/*
219		 * XXX We might want to move the next two lines into
220		 * XXX the pccard interface layer.  For the moment, this
221		 * XXX is OK, but some drivers want to pick the config
222		 * XXX entry to use as well as some address tweaks (mostly
223		 * XXX due to bugs in decode logic that makes some
224		 * XXX addresses illegal or broken).
225		 */
226		pccard_function_init(pf);
227		if (sc->sc_enabled_count == 0)
228			POWER_ENABLE_SOCKET(device_get_parent(dev), dev);
229		if (pccard_function_enable(pf) == 0 &&
230		    device_probe_and_attach(child) == 0) {
231			DEVPRINTF((sc->dev, "function %d CCR at %d "
232			    "offset %x: %x %x %x %x, %x %x %x %x, %x\n",
233			    pf->number, pf->pf_ccr_window, pf->pf_ccr_offset,
234			    pccard_ccr_read(pf, 0x00),
235			pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04),
236			pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A),
237			pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E),
238			pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12)));
239		} else {
240			if (pf->cfe != NULL)
241				pccard_function_disable(pf);
242		}
243	}
244	if (sc->sc_enabled_count == 0)
245		pccard_detach_card(dev, 0);
246	return (0);
247}
248
249static int
250pccard_detach_card(device_t dev, int flags)
251{
252	struct pccard_softc *sc = PCCARD_SOFTC(dev);
253	struct pccard_function *pf;
254	struct pccard_config_entry *cfe;
255
256	/*
257	 * We are running on either the PCCARD socket's event thread
258	 * or in user context detaching a device by user request.
259	 */
260	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
261		int state = device_get_state(pf->dev);
262
263		if (state == DS_ATTACHED || state == DS_BUSY)
264			device_detach(pf->dev);
265		if (pf->cfe != NULL)
266			pccard_function_disable(pf);
267		pccard_function_free(pf);
268		if (pf->dev != NULL)
269			device_delete_child(dev, pf->dev);
270	}
271	if (sc->sc_enabled_count == 0)
272		POWER_DISABLE_SOCKET(device_get_parent(dev), dev);
273
274	while (NULL != (pf = STAILQ_FIRST(&sc->card.pf_head))) {
275		while (NULL != (cfe = STAILQ_FIRST(&pf->cfe_head))) {
276			STAILQ_REMOVE_HEAD(&pf->cfe_head, cfe_list);
277			free(cfe, M_DEVBUF);
278		}
279		STAILQ_REMOVE_HEAD(&sc->card.pf_head, pf_list);
280		free(pf, M_DEVBUF);
281	}
282	return (0);
283}
284
285static const struct pccard_product *
286pccard_do_product_lookup(device_t bus, device_t dev,
287			 const struct pccard_product *tab, size_t ent_size,
288			 pccard_product_match_fn matchfn)
289{
290	const struct pccard_product *ent;
291	int matches;
292	u_int32_t fcn;
293	u_int32_t vendor;
294	u_int32_t prod;
295	char *vendorstr;
296	char *prodstr;
297
298#ifdef DIAGNOSTIC
299	if (sizeof *ent > ent_size)
300		panic("pccard_product_lookup: bogus ent_size %ld",
301		    (long) ent_size);
302#endif
303	if (pccard_get_vendor(dev, &vendor))
304		return (NULL);
305	if (pccard_get_product(dev, &prod))
306		return (NULL);
307	if (pccard_get_function_number(dev, &fcn))
308		return (NULL);
309	if (pccard_get_vendor_str(dev, &vendorstr))
310		return (NULL);
311	if (pccard_get_product_str(dev, &prodstr))
312		return (NULL);
313	for (ent = tab; ent->pp_name != NULL; ent =
314	    (const struct pccard_product *) ((const char *) ent + ent_size)) {
315		matches = 1;
316		if (ent->pp_vendor == PCCARD_VENDOR_ANY &&
317		    ent->pp_product == PCCARD_VENDOR_ANY &&
318		    ent->pp_cis[0] == NULL &&
319		    ent->pp_cis[1] == NULL) {
320			device_printf(dev,
321			    "Total wildcard entry ignored for %s\n",
322			    ent->pp_name);
323			continue;
324		}
325		if (matches && ent->pp_vendor != PCCARD_VENDOR_ANY &&
326		    vendor != ent->pp_vendor)
327			matches = 0;
328		if (matches && ent->pp_product != PCCARD_PRODUCT_ANY &&
329		    prod != ent->pp_product)
330			matches = 0;
331		if (matches && fcn != ent->pp_expfunc)
332			matches = 0;
333		if (matches && ent->pp_cis[0] &&
334		    strcmp(ent->pp_cis[0], vendorstr) != 0)
335			matches = 0;
336		if (matches && ent->pp_cis[1] &&
337		    strcmp(ent->pp_cis[1], prodstr) != 0)
338			matches = 0;
339		/* XXX need to match cis[2] and cis[3] also XXX */
340		if (matchfn != NULL)
341			matches = (*matchfn)(dev, ent, matches);
342		if (matches)
343			return (ent);
344	}
345	return (NULL);
346}
347
348static int
349pccard_card_gettype(device_t dev, int *type)
350{
351	struct pccard_softc *sc = PCCARD_SOFTC(dev);
352	struct pccard_function *pf;
353
354	/*
355	 * set the iftype to memory if this card has no functions (not yet
356	 * probed), or only one function, and that is not initialized yet or
357	 * that is memory.
358	 */
359	pf = STAILQ_FIRST(&sc->card.pf_head);
360	if (pf == NULL ||
361	    (STAILQ_NEXT(pf, pf_list) == NULL &&
362	    (pf->cfe == NULL || pf->cfe->iftype == PCCARD_IFTYPE_MEMORY)))
363		*type = PCCARD_IFTYPE_MEMORY;
364	else
365		*type = PCCARD_IFTYPE_IO;
366	return (0);
367}
368
369/*
370 * Initialize a PCCARD function.  May be called as long as the function is
371 * disabled.
372 *
373 * Note: pccard_function_init should not keep resources allocated.  It should
374 * only set them up ala isa pnp, set the values in the rl lists, and return.
375 * Any resource held after pccard_function_init is called is a bug.  However,
376 * the bus routines to get the resources also assume that pccard_function_init
377 * does this, so they need to be fixed too.
378 */
379static void
380pccard_function_init(struct pccard_function *pf)
381{
382	struct pccard_config_entry *cfe;
383	int i;
384	struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
385	struct resource_list *rl = &devi->resources;
386	struct resource_list_entry *rle;
387	struct resource *r = 0;
388	device_t bus;
389	int start;
390	int end;
391	int spaces;
392
393	if (pf->pf_flags & PFF_ENABLED) {
394		printf("pccard_function_init: function is enabled");
395		return;
396	}
397	bus = device_get_parent(pf->dev);
398	/* Remember which configuration entry we are using. */
399	STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
400		for (i = 0; i < cfe->num_iospace; i++)
401			cfe->iores[i] = NULL;
402		cfe->irqres = NULL;
403		spaces = 0;
404		for (i = 0; i < cfe->num_iospace; i++) {
405			start = cfe->iospace[i].start;
406			if (start)
407				end = start + cfe->iospace[i].length - 1;
408			else
409				end = ~0;
410			cfe->iorid[i] = i;
411			DEVPRINTF((bus, "I/O rid %d start %x end %x\n",
412			    i, start, end));
413			r = cfe->iores[i] = bus_alloc_resource(bus,
414			    SYS_RES_IOPORT, &cfe->iorid[i], start, end,
415			    cfe->iospace[i].length,
416			    rman_make_alignment_flags(cfe->iospace[i].length));
417			if (cfe->iores[i] == NULL)
418				goto not_this_one;
419			resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i],
420			    rman_get_start(r), rman_get_end(r),
421			    cfe->iospace[i].length);
422			rle = resource_list_find(rl, SYS_RES_IOPORT,
423			    cfe->iorid[i]);
424			rle->res = r;
425			spaces++;
426		}
427		if (cfe->num_memspace > 0) {
428			/*
429			 * Not implement yet, Fix me.
430			 */
431			DEVPRINTF((bus, "Memory space not yet implemented.\n"));
432		}
433		if (spaces == 0) {
434			DEVPRINTF((bus, "Neither memory nor I/O mampped\n"));
435			goto not_this_one;
436		}
437		if (cfe->irqmask) {
438			cfe->irqrid = 0;
439			r = cfe->irqres = bus_alloc_resource(bus, SYS_RES_IRQ,
440			    &cfe->irqrid, 0, ~0, 1, 0);
441			if (cfe->irqres == NULL)
442				goto not_this_one;
443			resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid,
444			    rman_get_start(r), rman_get_end(r), 1);
445			rle = resource_list_find(rl, SYS_RES_IRQ,
446			    cfe->irqrid);
447			rle->res = r;
448		}
449		/* If we get to here, we've allocated all we need */
450		pf->cfe = cfe;
451		break;
452	    not_this_one:;
453		DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n",
454		    cfe->number));
455		/*
456		 * Release resources that we partially allocated
457		 * from this config entry.
458		 */
459		for (i = 0; i < cfe->num_iospace; i++) {
460			if (cfe->iores[i] != NULL) {
461				bus_release_resource(bus, SYS_RES_IOPORT,
462				    cfe->iorid[i], cfe->iores[i]);
463				rle = resource_list_find(rl, SYS_RES_IOPORT,
464				    cfe->iorid[i]);
465				rle->res = NULL;
466				resource_list_delete(rl, SYS_RES_IOPORT,
467				    cfe->iorid[i]);
468			}
469			cfe->iores[i] = NULL;
470		}
471		if (cfe->irqmask && cfe->irqres != NULL) {
472			bus_release_resource(bus, SYS_RES_IRQ,
473			    cfe->irqrid, cfe->irqres);
474			rle = resource_list_find(rl, SYS_RES_IRQ,
475			    cfe->irqrid);
476			rle->res = NULL;
477			resource_list_delete(rl, SYS_RES_IRQ, cfe->irqrid);
478			cfe->irqres = NULL;
479		}
480	}
481}
482
483/*
484 * Free resources allocated by pccard_function_init(), May be called as long
485 * as the function is disabled.
486 *
487 * NOTE: This function should be unnecessary.  pccard_function_init should
488 * never keep resources initialized.
489 */
490static void
491pccard_function_free(struct pccard_function *pf)
492{
493	struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
494	struct resource_list_entry *rle;
495
496	if (pf->pf_flags & PFF_ENABLED) {
497		printf("pccard_function_init: function is enabled");
498		return;
499	}
500
501	SLIST_FOREACH(rle, &devi->resources, link) {
502		if (rle->res) {
503			if (rle->res->r_dev != pf->sc->dev)
504				device_printf(pf->sc->dev,
505				    "function_free: Resource still owned by "
506				    "child, oops. "
507				    "(type=%d, rid=%d, addr=%lx)\n",
508				    rle->type, rle->rid,
509				    rman_get_start(rle->res));
510			BUS_RELEASE_RESOURCE(device_get_parent(pf->sc->dev),
511			    rle->res->r_dev, rle->type, rle->rid, rle->res);
512			rle->res = NULL;
513		}
514	}
515	resource_list_free(&devi->resources);
516}
517
518/* Enable a PCCARD function */
519static int
520pccard_function_enable(struct pccard_function *pf)
521{
522	struct pccard_function *tmp;
523	int reg;
524	device_t dev = pf->sc->dev;
525
526	if (pf->cfe == NULL) {
527		DEVPRVERBOSE((dev, "No config entry could be allocated.\n"));
528		return (ENOMEM);
529	}
530
531	/*
532	 * Increase the reference count on the socket, enabling power, if
533	 * necessary.
534	 */
535	pf->sc->sc_enabled_count++;
536
537	if (pf->pf_flags & PFF_ENABLED) {
538		/*
539		 * Don't do anything if we're already enabled.
540		 */
541		return (0);
542	}
543
544	/*
545	 * it's possible for different functions' CCRs to be in the same
546	 * underlying page.  Check for that.
547	 */
548	STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
549		if ((tmp->pf_flags & PFF_ENABLED) &&
550		    (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
551		    ((pf->ccr_base + PCCARD_CCR_SIZE) <=
552		    (tmp->ccr_base - tmp->pf_ccr_offset +
553		    tmp->pf_ccr_realsize))) {
554			pf->pf_ccrt = tmp->pf_ccrt;
555			pf->pf_ccrh = tmp->pf_ccrh;
556			pf->pf_ccr_realsize = tmp->pf_ccr_realsize;
557
558			/*
559			 * pf->pf_ccr_offset = (tmp->pf_ccr_offset -
560			 * tmp->ccr_base) + pf->ccr_base;
561			 */
562			/* pf->pf_ccr_offset =
563			    (tmp->pf_ccr_offset + pf->ccr_base) -
564			    tmp->ccr_base; */
565			pf->pf_ccr_window = tmp->pf_ccr_window;
566			break;
567		}
568	}
569	if (tmp == NULL) {
570		pf->ccr_rid = 0;
571		pf->ccr_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
572		    &pf->ccr_rid, 0, ~0, 1 << 10, RF_ACTIVE);
573		if (!pf->ccr_res)
574			goto bad;
575		DEVPRINTF((dev, "ccr_res == %lx-%lx, base=%lx\n",
576		    rman_get_start(pf->ccr_res), rman_get_end(pf->ccr_res),
577		    pf->ccr_base));
578		CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY,
579		    pf->ccr_rid, PCCARD_A_MEM_ATTR);
580		CARD_SET_MEMORY_OFFSET(device_get_parent(dev), dev,
581		    pf->ccr_rid, pf->ccr_base, &pf->pf_ccr_offset);
582		pf->pf_ccrt = rman_get_bustag(pf->ccr_res);
583		pf->pf_ccrh = rman_get_bushandle(pf->ccr_res);
584		pf->pf_ccr_realsize = 1;
585	}
586
587	reg = (pf->cfe->number & PCCARD_CCR_OPTION_CFINDEX);
588	reg |= PCCARD_CCR_OPTION_LEVIREQ;
589#ifdef COOKIE_FOR_WARNER
590	if (pccard_mfc(pf->sc)) {
591		reg |= (PCCARD_CCR_OPTION_FUNC_ENABLE |
592			PCCARD_CCR_OPTION_ADDR_DECODE);
593		/* PCCARD_CCR_OPTION_IRQ_ENABLE set elsewhere as needed */
594	}
595#endif
596	pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg);
597
598	reg = 0;
599	if ((pf->cfe->flags & PCCARD_CFE_IO16) == 0)
600		reg |= PCCARD_CCR_STATUS_IOIS8;
601	if (pf->cfe->flags & PCCARD_CFE_AUDIO)
602		reg |= PCCARD_CCR_STATUS_AUDIO;
603	pccard_ccr_write(pf, PCCARD_CCR_STATUS, reg);
604
605	pccard_ccr_write(pf, PCCARD_CCR_SOCKETCOPY, 0);
606
607	if (pccard_mfc(pf->sc)) {
608		long tmp, iosize;
609
610		tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase;
611		/* round up to nearest (2^n)-1 */
612		for (iosize = 1; iosize < tmp; iosize <<= 1)
613			;
614		iosize--;
615
616		pccard_ccr_write(pf, PCCARD_CCR_IOBASE0,
617				 pf->pf_mfc_iobase & 0xff);
618		pccard_ccr_write(pf, PCCARD_CCR_IOBASE1,
619				 (pf->pf_mfc_iobase >> 8) & 0xff);
620		pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0);
621		pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0);
622
623		pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize);
624	}
625
626#ifdef PCCARDDEBUG
627	if (pccard_debug) {
628		STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
629			device_printf(tmp->sc->dev,
630			    "function %d CCR at %d offset %x: "
631			    "%x %x %x %x, %x %x %x %x, %x\n",
632			    tmp->number, tmp->pf_ccr_window,
633			    tmp->pf_ccr_offset,
634			    pccard_ccr_read(tmp, 0x00),
635			    pccard_ccr_read(tmp, 0x02),
636			    pccard_ccr_read(tmp, 0x04),
637			    pccard_ccr_read(tmp, 0x06),
638			    pccard_ccr_read(tmp, 0x0A),
639			    pccard_ccr_read(tmp, 0x0C),
640			    pccard_ccr_read(tmp, 0x0E),
641			    pccard_ccr_read(tmp, 0x10),
642			    pccard_ccr_read(tmp, 0x12));
643		}
644	}
645#endif
646	pf->pf_flags |= PFF_ENABLED;
647	return (0);
648
649 bad:
650	/*
651	 * Decrement the reference count, and power down the socket, if
652	 * necessary.
653	 */
654	pf->sc->sc_enabled_count--;
655	DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count));
656
657	return (1);
658}
659
660/* Disable PCCARD function. */
661static void
662pccard_function_disable(struct pccard_function *pf)
663{
664	struct pccard_function *tmp;
665	device_t dev = pf->sc->dev;
666
667	if (pf->cfe == NULL)
668		panic("pccard_function_disable: function not initialized");
669
670	if ((pf->pf_flags & PFF_ENABLED) == 0) {
671		/*
672		 * Don't do anything if we're already disabled.
673		 */
674		return;
675	}
676
677	if (pf->intr_handler != NULL) {
678		struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
679		struct resource_list_entry *rle =
680		    resource_list_find(&devi->resources, SYS_RES_IRQ, 0);
681		BUS_TEARDOWN_INTR(dev, pf->dev, rle->res,
682		    pf->intr_handler_cookie);
683	}
684
685	/*
686	 * it's possible for different functions' CCRs to be in the same
687	 * underlying page.  Check for that.  Note we mark us as disabled
688	 * first to avoid matching ourself.
689	 */
690
691	pf->pf_flags &= ~PFF_ENABLED;
692	STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
693		if ((tmp->pf_flags & PFF_ENABLED) &&
694		    (pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
695		    ((pf->ccr_base + PCCARD_CCR_SIZE) <=
696		    (tmp->ccr_base - tmp->pf_ccr_offset +
697		    tmp->pf_ccr_realsize)))
698			break;
699	}
700
701	/* Not used by anyone else; unmap the CCR. */
702	if (tmp == NULL) {
703		bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid,
704		    pf->ccr_res);
705		pf->ccr_res = NULL;
706	}
707
708	/*
709	 * Decrement the reference count, and power down the socket, if
710	 * necessary.
711	 */
712	pf->sc->sc_enabled_count--;
713}
714
715#if 0
716/* XXX These functions are needed, but not like this XXX */
717int
718pccard_io_map(struct pccard_function *pf, int width, bus_addr_t offset,
719    bus_size_t size, struct pccard_io_handle *pcihp, int *windowp)
720{
721	int reg;
722
723	if (pccard_chip_io_map(pf->sc->pct, pf->sc->pch, width, offset, size,
724	    pcihp, windowp))
725		return (1);
726
727	/*
728	 * XXX in the multifunction multi-iospace-per-function case, this
729	 * needs to cooperate with io_alloc to make sure that the spaces
730	 * don't overlap, and that the ccr's are set correctly
731	 */
732
733	if (pccard_mfc(pf->sc)) {
734		long tmp, iosize;
735
736		if (pf->pf_mfc_iomax == 0) {
737			pf->pf_mfc_iobase = pcihp->addr + offset;
738			pf->pf_mfc_iomax = pf->pf_mfc_iobase + size;
739		} else {
740			/* this makes the assumption that nothing overlaps */
741			if (pf->pf_mfc_iobase > pcihp->addr + offset)
742				pf->pf_mfc_iobase = pcihp->addr + offset;
743			if (pf->pf_mfc_iomax < pcihp->addr + offset + size)
744				pf->pf_mfc_iomax = pcihp->addr + offset + size;
745		}
746
747		tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase;
748		/* round up to nearest (2^n)-1 */
749		for (iosize = 1; iosize >= tmp; iosize <<= 1)
750			;
751		iosize--;
752
753		pccard_ccr_write(pf, PCCARD_CCR_IOBASE0,
754		    pf->pf_mfc_iobase & 0xff);
755		pccard_ccr_write(pf, PCCARD_CCR_IOBASE1,
756		    (pf->pf_mfc_iobase >> 8) & 0xff);
757		pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0);
758		pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0);
759
760		pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize);
761
762#ifdef COOKIE_FOR_WARNER
763		reg = pccard_ccr_read(pf, PCCARD_CCR_OPTION);
764		reg |= PCCARD_CCR_OPTION_ADDR_DECODE;
765		pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg);
766#endif
767	}
768	return (0);
769}
770
771void
772pccard_io_unmap(struct pccard_function *pf, int window)
773{
774
775	pccard_chip_io_unmap(pf->sc->pct, pf->sc->pch, window);
776
777	/* XXX Anything for multi-function cards? */
778}
779#endif
780
781/*
782 * simulate the old "probe" routine.  In the new world order, the driver
783 * needs to grab devices while in the old they were assigned to the device by
784 * the pccardd process.  These symbols are exported to the upper layers.
785 */
786static int
787pccard_compat_do_probe(device_t bus, device_t dev)
788{
789	return (CARD_COMPAT_MATCH(dev));
790}
791
792static int
793pccard_compat_do_attach(device_t bus, device_t dev)
794{
795	int err;
796
797	err = CARD_COMPAT_PROBE(dev);
798	if (err == 0)
799		err = CARD_COMPAT_ATTACH(dev);
800	return (err);
801}
802
803#define PCCARD_NPORT	2
804#define PCCARD_NMEM	5
805#define PCCARD_NIRQ	1
806#define PCCARD_NDRQ	0
807
808static int
809pccard_add_children(device_t dev, int busno)
810{
811	/* Call parent to scan for any current children */
812	return (0);
813}
814
815static int
816pccard_probe(device_t dev)
817{
818	device_set_desc(dev, "16-bit PCCard bus");
819	return (pccard_add_children(dev, device_get_unit(dev)));
820}
821
822static int
823pccard_attach(device_t dev)
824{
825	struct pccard_softc *sc = PCCARD_SOFTC(dev);
826
827	sc->dev = dev;
828	sc->sc_enabled_count = 0;
829	return (bus_generic_attach(dev));
830}
831
832static int
833pccard_detach(device_t dev)
834{
835	pccard_detach_card(dev, 0);
836	return 0;
837}
838
839static int
840pccard_suspend(device_t self)
841{
842	pccard_detach_card(self, 0);
843	return (0);
844}
845
846static
847int
848pccard_resume(device_t self)
849{
850	return (0);
851}
852
853static void
854pccard_print_resources(struct resource_list *rl, const char *name, int type,
855    int count, const char *format)
856{
857	struct resource_list_entry *rle;
858	int printed;
859	int i;
860
861	printed = 0;
862	for (i = 0; i < count; i++) {
863		rle = resource_list_find(rl, type, i);
864		if (rle != NULL) {
865			if (printed == 0)
866				printf(" %s ", name);
867			else if (printed > 0)
868				printf(",");
869			printed++;
870			printf(format, rle->start);
871			if (rle->count > 1) {
872				printf("-");
873				printf(format, rle->start + rle->count - 1);
874			}
875		} else if (i > 3) {
876			/* check the first few regardless */
877			break;
878		}
879	}
880}
881
882static int
883pccard_print_child(device_t dev, device_t child)
884{
885	struct pccard_ivar *devi = PCCARD_IVAR(child);
886	struct resource_list *rl = &devi->resources;
887	int retval = 0;
888
889	retval += bus_print_child_header(dev, child);
890	retval += printf(" at");
891
892	if (devi != NULL) {
893		pccard_print_resources(rl, "port", SYS_RES_IOPORT,
894		    PCCARD_NPORT, "%#lx");
895		pccard_print_resources(rl, "iomem", SYS_RES_MEMORY,
896		    PCCARD_NMEM, "%#lx");
897		pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ,
898		    "%ld");
899		pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ,
900		    "%ld");
901		retval += printf(" function %d config %d", devi->fcn->number,
902		    devi->fcn->cfe->number);
903	}
904
905	retval += bus_print_child_footer(dev, child);
906
907	return (retval);
908}
909
910static int
911pccard_set_resource(device_t dev, device_t child, int type, int rid,
912		 u_long start, u_long count)
913{
914	struct pccard_ivar *devi = PCCARD_IVAR(child);
915	struct resource_list *rl = &devi->resources;
916
917	if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
918	    && type != SYS_RES_IRQ && type != SYS_RES_DRQ)
919		return (EINVAL);
920	if (rid < 0)
921		return (EINVAL);
922	if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT)
923		return (EINVAL);
924	if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM)
925		return (EINVAL);
926	if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ)
927		return (EINVAL);
928	if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ)
929		return (EINVAL);
930
931	resource_list_add(rl, type, rid, start, start + count - 1, count);
932	if (NULL != resource_list_alloc(rl, device_get_parent(dev), dev,
933	    type, &rid, start, start + count - 1, count, 0))
934		return 0;
935	else
936		return ENOMEM;
937}
938
939static int
940pccard_get_resource(device_t dev, device_t child, int type, int rid,
941    u_long *startp, u_long *countp)
942{
943	struct pccard_ivar *devi = PCCARD_IVAR(child);
944	struct resource_list *rl = &devi->resources;
945	struct resource_list_entry *rle;
946
947	rle = resource_list_find(rl, type, rid);
948	if (rle == NULL)
949		return (ENOENT);
950
951	if (startp != NULL)
952		*startp = rle->start;
953	if (countp != NULL)
954		*countp = rle->count;
955
956	return (0);
957}
958
959static void
960pccard_delete_resource(device_t dev, device_t child, int type, int rid)
961{
962	struct pccard_ivar *devi = PCCARD_IVAR(child);
963	struct resource_list *rl = &devi->resources;
964	resource_list_delete(rl, type, rid);
965}
966
967static int
968pccard_set_res_flags(device_t dev, device_t child, int type, int rid,
969    u_int32_t flags)
970{
971	return (CARD_SET_RES_FLAGS(device_get_parent(dev), child, type,
972	    rid, flags));
973}
974
975static int
976pccard_set_memory_offset(device_t dev, device_t child, int rid,
977    u_int32_t offset, u_int32_t *deltap)
978
979{
980	return (CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid,
981	    offset, deltap));
982}
983
984static int
985pccard_read_ivar(device_t bus, device_t child, int which, u_char *result)
986{
987	struct pccard_ivar *devi = PCCARD_IVAR(child);
988	struct pccard_function *func = devi->fcn;
989	struct pccard_softc *sc = PCCARD_SOFTC(bus);
990
991	/* PCCARD_IVAR_ETHADDR unhandled from oldcard */
992	switch (which) {
993	default:
994	case PCCARD_IVAR_ETHADDR:
995		bcopy(func->pf_funce_lan_nid, result, ETHER_ADDR_LEN);
996		break;
997	case PCCARD_IVAR_VENDOR:
998		*(u_int32_t *) result = sc->card.manufacturer;
999		break;
1000	case PCCARD_IVAR_PRODUCT:
1001		*(u_int32_t *) result = sc->card.product;
1002		break;
1003	case PCCARD_IVAR_PRODEXT:
1004		*(u_int16_t *) result = sc->card.prodext;
1005		break;
1006	case PCCARD_IVAR_FUNCTION:
1007		*(u_int32_t *) result = func->function;
1008		break;
1009	case PCCARD_IVAR_FUNCTION_NUMBER:
1010		if (!func) {
1011			device_printf(bus, "No function number, bug!\n");
1012			return (ENOENT);
1013		}
1014		*(u_int32_t *) result = func->number;
1015		break;
1016	case PCCARD_IVAR_VENDOR_STR:
1017		*(char **) result = sc->card.cis1_info[0];
1018		break;
1019	case PCCARD_IVAR_PRODUCT_STR:
1020		*(char **) result = sc->card.cis1_info[1];
1021		break;
1022	case PCCARD_IVAR_CIS3_STR:
1023		*(char **) result = sc->card.cis1_info[2];
1024		break;
1025	case PCCARD_IVAR_CIS4_STR:
1026		*(char **) result = sc->card.cis1_info[2];
1027		break;
1028	}
1029	return (0);
1030}
1031
1032static void
1033pccard_driver_added(device_t dev, driver_t *driver)
1034{
1035	struct pccard_softc *sc = PCCARD_SOFTC(dev);
1036	struct pccard_function *pf;
1037	device_t child;
1038
1039	if (sc->sc_enabled_count == 0) {
1040		CARD_REPROBE_CARD(device_get_parent(dev), dev);
1041		return;
1042	}
1043
1044	STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
1045		if (STAILQ_EMPTY(&pf->cfe_head))
1046			continue;
1047		child = pf->dev;
1048		if (device_get_state(child) != DS_NOTPRESENT)
1049			continue;
1050		if (pccard_function_enable(pf) == 0 &&
1051		    device_probe_and_attach(child) == 0) {
1052			DEVPRINTF((sc->dev, "function %d CCR at %d "
1053			    "offset %x: %x %x %x %x, %x %x %x %x, %x\n",
1054			    pf->number, pf->pf_ccr_window, pf->pf_ccr_offset,
1055			    pccard_ccr_read(pf, 0x00),
1056			pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04),
1057			pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A),
1058			pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E),
1059			pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12)));
1060		} else {
1061			if (pf->cfe != NULL)
1062				pccard_function_disable(pf);
1063		}
1064	}
1065	return;
1066}
1067
1068static struct resource *
1069pccard_alloc_resource(device_t dev, device_t child, int type, int *rid,
1070    u_long start, u_long end, u_long count, u_int flags)
1071{
1072	struct pccard_ivar *dinfo;
1073	struct resource_list_entry *rle = 0;
1074	int passthrough = (device_get_parent(child) != dev);
1075
1076	if (passthrough) {
1077		return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
1078		    type, rid, start, end, count, flags));
1079	}
1080
1081	dinfo = device_get_ivars(child);
1082	rle = resource_list_find(&dinfo->resources, type, *rid);
1083
1084	if (!rle)
1085		return NULL;		/* no resource of that type/rid */
1086
1087	if (!rle->res) {
1088		device_printf(dev, "WARNING: Resource not reserved by pccard bus\n");
1089		return NULL;
1090	} else {
1091		if (rle->res->r_dev != dev)
1092			return (NULL);
1093		bus_release_resource(dev, type, *rid, rle->res);
1094		rle->res = NULL;
1095		switch(type) {
1096		case SYS_RES_IOPORT:
1097		case SYS_RES_MEMORY:
1098			if (!(flags & RF_ALIGNMENT_MASK))
1099				flags |= rman_make_alignment_flags(rle->count);
1100			break;
1101		case SYS_RES_IRQ:
1102			flags |= RF_SHAREABLE;
1103			break;
1104		}
1105		rle->res = resource_list_alloc(&dinfo->resources, dev, child,
1106		    type, rid, rle->start, rle->end, rle->count, flags);
1107		return (rle->res);
1108	}
1109}
1110
1111static int
1112pccard_release_resource(device_t dev, device_t child, int type, int rid,
1113    struct resource *r)
1114{
1115	struct pccard_ivar *dinfo;
1116	int passthrough = (device_get_parent(child) != dev);
1117	struct resource_list_entry *rle = 0;
1118	int ret;
1119	int flags;
1120
1121	if (passthrough)
1122		return BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
1123		    type, rid, r);
1124
1125	dinfo = device_get_ivars(child);
1126
1127	rle = resource_list_find(&dinfo->resources, type, rid);
1128
1129	if (!rle) {
1130		device_printf(dev, "Allocated resource not found, "
1131		    "%d %x %lx %lx\n",
1132		    type, rid, rman_get_start(r), rman_get_size(r));
1133		return ENOENT;
1134	}
1135	if (!rle->res) {
1136		device_printf(dev, "Allocated resource not recorded\n");
1137		return ENOENT;
1138	}
1139
1140	ret = BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
1141	    type, rid, r);
1142	switch(type) {
1143	case SYS_RES_IOPORT:
1144	case SYS_RES_MEMORY:
1145		flags = rman_make_alignment_flags(rle->count);
1146		break;
1147	case SYS_RES_IRQ:
1148		flags = RF_SHAREABLE;
1149		break;
1150	default:
1151		flags = 0;
1152	}
1153	rle->res = bus_alloc_resource(dev, type, &rid,
1154	    rle->start, rle->end, rle->count, flags);
1155	if (rle->res == NULL)
1156		device_printf(dev, "release_resource: "
1157		    "unable to reaquire resource\n");
1158	return ret;
1159}
1160
1161static void
1162pccard_child_detached(device_t parent, device_t dev)
1163{
1164	struct pccard_ivar *ivar = PCCARD_IVAR(dev);
1165	struct pccard_function *pf = ivar->fcn;
1166
1167	pccard_function_disable(pf);
1168}
1169
1170static void
1171pccard_intr(void *arg)
1172{
1173	struct pccard_function *pf = (struct pccard_function*) arg;
1174	int reg;
1175
1176	if (pf->intr_handler == NULL)
1177		return;
1178
1179	/*
1180	 * XXX The CCR_STATUS register bits used here are
1181	 * only valid for multi function cards.
1182	 */
1183	reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);
1184	if (reg & PCCARD_CCR_STATUS_INTR) {
1185		pccard_ccr_write(pf, PCCARD_CCR_STATUS,
1186				 reg & ~PCCARD_CCR_STATUS_INTR);
1187		pf->intr_handler(pf->intr_handler_arg);
1188	}
1189}
1190
1191static int
1192pccard_setup_intr(device_t dev, device_t child, struct resource *irq,
1193    int flags, driver_intr_t *intr, void *arg, void **cookiep)
1194{
1195	struct pccard_ivar *ivar = PCCARD_IVAR(child);
1196	struct pccard_function *func = ivar->fcn;
1197	int err;
1198
1199	if (func->intr_handler != NULL)
1200		panic("Only one interrupt handler per function allowed");
1201	err = bus_generic_setup_intr(dev, child, irq, flags, pccard_intr,
1202	    func, cookiep);
1203	if (err != 0)
1204		return (err);
1205	func->intr_handler = intr;
1206	func->intr_handler_arg = arg;
1207	func->intr_handler_cookie = *cookiep;
1208#ifdef COOKIE_FOR_WARNER
1209	/* XXX Not sure this is right to write to ccr */
1210	pccard_ccr_write(func, PCCARD_CCR_OPTION,
1211	    pccard_ccr_read(func, PCCARD_CCR_OPTION) |
1212	    PCCARD_CCR_OPTION_IREQ_ENABLE);
1213#endif
1214	return (0);
1215}
1216
1217static int
1218pccard_teardown_intr(device_t dev, device_t child, struct resource *r,
1219    void *cookie)
1220{
1221	struct pccard_ivar *ivar = PCCARD_IVAR(child);
1222	struct pccard_function *func = ivar->fcn;
1223	int ret;
1224
1225#ifdef COOKIE_FOR_WARNER
1226	/* XXX Not sure this is right to write to ccr */
1227	pccard_ccr_write(func, PCCARD_CCR_OPTION,
1228	    pccard_ccr_read(func, PCCARD_CCR_OPTION) &
1229	    ~PCCARD_CCR_OPTION_IREQ_ENABLE);
1230#endif
1231	ret = bus_generic_teardown_intr(dev, child, r, cookie);
1232	if (ret == 0) {
1233		func->intr_handler = NULL;
1234		func->intr_handler_arg = NULL;
1235		func->intr_handler_cookie = NULL;
1236	}
1237
1238	return (ret);
1239}
1240
1241static device_method_t pccard_methods[] = {
1242	/* Device interface */
1243	DEVMETHOD(device_probe,		pccard_probe),
1244	DEVMETHOD(device_attach,	pccard_attach),
1245	DEVMETHOD(device_detach,	pccard_detach),
1246	DEVMETHOD(device_shutdown,	bus_generic_shutdown),
1247	DEVMETHOD(device_suspend,	pccard_suspend),
1248	DEVMETHOD(device_resume,	pccard_resume),
1249
1250	/* Bus interface */
1251	DEVMETHOD(bus_print_child,	pccard_print_child),
1252	DEVMETHOD(bus_driver_added,	pccard_driver_added),
1253	DEVMETHOD(bus_child_detached,	pccard_child_detached),
1254	DEVMETHOD(bus_alloc_resource,	pccard_alloc_resource),
1255	DEVMETHOD(bus_release_resource,	pccard_release_resource),
1256	DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
1257	DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
1258	DEVMETHOD(bus_setup_intr,	pccard_setup_intr),
1259	DEVMETHOD(bus_teardown_intr,	pccard_teardown_intr),
1260	DEVMETHOD(bus_set_resource,	pccard_set_resource),
1261	DEVMETHOD(bus_get_resource,	pccard_get_resource),
1262	DEVMETHOD(bus_delete_resource,	pccard_delete_resource),
1263	DEVMETHOD(bus_read_ivar,	pccard_read_ivar),
1264
1265	/* Card Interface */
1266	DEVMETHOD(card_set_res_flags,	pccard_set_res_flags),
1267	DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset),
1268	DEVMETHOD(card_get_type,	pccard_card_gettype),
1269	DEVMETHOD(card_attach_card,	pccard_attach_card),
1270	DEVMETHOD(card_detach_card,	pccard_detach_card),
1271	DEVMETHOD(card_compat_do_probe, pccard_compat_do_probe),
1272	DEVMETHOD(card_compat_do_attach, pccard_compat_do_attach),
1273	DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup),
1274
1275	{ 0, 0 }
1276};
1277
1278static driver_t pccard_driver = {
1279	"pccard",
1280	pccard_methods,
1281	sizeof(struct pccard_softc)
1282};
1283
1284devclass_t	pccard_devclass;
1285
1286/* Maybe we need to have a slot device? */
1287DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0);
1288DRIVER_MODULE(pccard, pc98pcic, pccard_driver, pccard_devclass, 0, 0);
1289DRIVER_MODULE(pccard, cbb, pccard_driver, pccard_devclass, 0, 0);
1290DRIVER_MODULE(pccard, tcic, pccard_driver, pccard_devclass, 0, 0);
1291MODULE_VERSION(pccard, 1);
1292/*MODULE_DEPEND(pccard, pcic, 1, 1, 1);*/
1293