o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
/* $NetBSD: pcmcia.c,v 1.23 2000/07/28 19:17:02 drochner Exp $ */
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1997 Marc Horowitz. All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by Marc Horowitz.
|
|
|
|
* 4. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/module.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/queue.h>
|
2002-03-07 08:03:53 +00:00
|
|
|
#include <sys/sysctl.h>
|
1999-10-26 06:52:31 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2001-09-02 06:37:41 +00:00
|
|
|
#include <net/ethernet.h>
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
#include <dev/pccard/pccardreg.h>
|
|
|
|
#include <dev/pccard/pccardvar.h>
|
|
|
|
|
2000-01-06 07:30:28 +00:00
|
|
|
#include "power_if.h"
|
2000-04-13 06:42:58 +00:00
|
|
|
#include "card_if.h"
|
2000-01-06 07:30:28 +00:00
|
|
|
|
|
|
|
#define PCCARDDEBUG
|
|
|
|
|
2002-03-07 08:03:53 +00:00
|
|
|
/* sysctl vars */
|
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, pccard, CTLFLAG_RD, 0, "PCCARD parameters");
|
|
|
|
|
2002-02-04 15:55:21 +00:00
|
|
|
int pccard_debug = 0;
|
2002-03-07 08:03:53 +00:00
|
|
|
TUNABLE_INT("hw.pccard.debug", &pccard_debug);
|
|
|
|
SYSCTL_INT(_hw_pccard, OID_AUTO, debug, CTLFLAG_RW,
|
|
|
|
&pccard_debug, 0,
|
|
|
|
"pccard debug");
|
|
|
|
|
|
|
|
int pccard_cis_debug = 0;
|
|
|
|
TUNABLE_INT("hw.pccard.cis_debug", &pccard_cis_debug);
|
|
|
|
SYSCTL_INT(_hw_pccard, OID_AUTO, cis_debug, CTLFLAG_RW,
|
|
|
|
&pccard_cis_debug, 0, "pccard CIS debug");
|
|
|
|
|
|
|
|
#ifdef PCCARDDEBUG
|
1999-10-26 06:52:31 +00:00
|
|
|
#define DPRINTF(arg) if (pccard_debug) printf arg
|
2000-01-06 07:30:28 +00:00
|
|
|
#define DEVPRINTF(arg) if (pccard_debug) device_printf arg
|
2000-10-19 22:36:41 +00:00
|
|
|
#define PRVERBOSE(arg) printf arg
|
|
|
|
#define DEVPRVERBOSE(arg) device_printf arg
|
1999-10-26 06:52:31 +00:00
|
|
|
#else
|
|
|
|
#define DPRINTF(arg)
|
2000-01-06 07:30:28 +00:00
|
|
|
#define DEVPRINTF(arg)
|
2000-10-19 22:36:41 +00:00
|
|
|
#define PRVERBOSE(arg) if (bootverbose) printf arg
|
|
|
|
#define DEVPRVERBOSE(arg) if (bootverbose) device_printf arg
|
1999-10-26 06:52:31 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
static int pccard_ccr_read(struct pccard_function *pf, int ccr);
|
|
|
|
static void pccard_ccr_write(struct pccard_function *pf, int ccr, int val);
|
|
|
|
static int pccard_attach_card(device_t dev);
|
2002-11-02 23:00:28 +00:00
|
|
|
static int pccard_detach_card(device_t dev);
|
2001-08-27 00:09:42 +00:00
|
|
|
static void pccard_function_init(struct pccard_function *pf);
|
|
|
|
static void pccard_function_free(struct pccard_function *pf);
|
|
|
|
static int pccard_function_enable(struct pccard_function *pf);
|
|
|
|
static void pccard_function_disable(struct pccard_function *pf);
|
|
|
|
static int pccard_compat_do_probe(device_t bus, device_t dev);
|
|
|
|
static int pccard_compat_do_attach(device_t bus, device_t dev);
|
|
|
|
static int pccard_add_children(device_t dev, int busno);
|
|
|
|
static int pccard_probe(device_t dev);
|
|
|
|
static int pccard_attach(device_t dev);
|
|
|
|
static int pccard_detach(device_t dev);
|
|
|
|
static void pccard_print_resources(struct resource_list *rl,
|
|
|
|
const char *name, int type, int count, const char *format);
|
|
|
|
static int pccard_print_child(device_t dev, device_t child);
|
|
|
|
static int pccard_set_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_long start, u_long count);
|
|
|
|
static int pccard_get_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_long *startp, u_long *countp);
|
|
|
|
static void pccard_delete_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid);
|
|
|
|
static int pccard_set_res_flags(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_int32_t flags);
|
|
|
|
static int pccard_set_memory_offset(device_t dev, device_t child, int rid,
|
|
|
|
u_int32_t offset, u_int32_t *deltap);
|
2002-10-07 23:05:33 +00:00
|
|
|
static void pccard_probe_nomatch(device_t cbdev, device_t child);
|
2001-08-27 00:09:42 +00:00
|
|
|
static int pccard_read_ivar(device_t bus, device_t child, int which,
|
|
|
|
u_char *result);
|
|
|
|
static void pccard_driver_added(device_t dev, driver_t *driver);
|
|
|
|
static struct resource *pccard_alloc_resource(device_t dev,
|
|
|
|
device_t child, int type, int *rid, u_long start,
|
|
|
|
u_long end, u_long count, u_int flags);
|
|
|
|
static int pccard_release_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid, struct resource *r);
|
|
|
|
static void pccard_child_detached(device_t parent, device_t dev);
|
|
|
|
static void pccard_intr(void *arg);
|
|
|
|
static int pccard_setup_intr(device_t dev, device_t child,
|
|
|
|
struct resource *irq, int flags, driver_intr_t *intr,
|
|
|
|
void *arg, void **cookiep);
|
|
|
|
static int pccard_teardown_intr(device_t dev, device_t child,
|
|
|
|
struct resource *r, void *cookie);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
2002-05-30 17:38:00 +00:00
|
|
|
static const struct pccard_product *
|
|
|
|
pccard_do_product_lookup(device_t bus, device_t dev,
|
|
|
|
const struct pccard_product *tab, size_t ent_size,
|
|
|
|
pccard_product_match_fn matchfn);
|
|
|
|
|
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
static int
|
2001-03-22 05:41:20 +00:00
|
|
|
pccard_ccr_read(struct pccard_function *pf, int ccr)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
return (bus_space_read_1(pf->pf_ccrt, pf->pf_ccrh,
|
|
|
|
pf->pf_ccr_offset + ccr));
|
|
|
|
}
|
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
static void
|
2001-03-22 05:41:20 +00:00
|
|
|
pccard_ccr_write(struct pccard_function *pf, int ccr, int val)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
if ((pf->ccr_mask) & (1 << (ccr / 2))) {
|
|
|
|
bus_space_write_1(pf->pf_ccrt, pf->pf_ccrh,
|
|
|
|
pf->pf_ccr_offset + ccr, val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-04-08 07:02:03 +00:00
|
|
|
static int
|
|
|
|
pccard_set_default_descr(device_t dev)
|
|
|
|
{
|
2003-10-26 00:51:40 +00:00
|
|
|
const char *vendorstr, *prodstr;
|
|
|
|
char *str;
|
2003-04-08 07:02:03 +00:00
|
|
|
|
|
|
|
if (pccard_get_vendor_str(dev, &vendorstr))
|
|
|
|
return (0);
|
|
|
|
if (pccard_get_product_str(dev, &prodstr))
|
|
|
|
return (0);
|
|
|
|
str = malloc(strlen(vendorstr) + strlen(prodstr) + 2, M_DEVBUF,
|
|
|
|
M_WAITOK);
|
|
|
|
sprintf(str, "%s %s", vendorstr, prodstr);
|
|
|
|
device_set_desc_copy(dev, str);
|
|
|
|
free(str, M_DEVBUF);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
static int
|
|
|
|
pccard_attach_card(device_t dev)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
2000-08-19 19:22:04 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
1999-10-26 06:52:31 +00:00
|
|
|
struct pccard_function *pf;
|
2000-09-16 06:52:20 +00:00
|
|
|
struct pccard_ivar *ivar;
|
2000-06-18 05:28:59 +00:00
|
|
|
device_t child;
|
2002-08-31 18:34:30 +00:00
|
|
|
int i;
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* this is here so that when socket_enable calls gettype, trt happens
|
|
|
|
*/
|
|
|
|
STAILQ_INIT(&sc->card.pf_head);
|
|
|
|
|
2000-01-06 07:30:28 +00:00
|
|
|
DEVPRINTF((dev, "chip_socket_enable\n"));
|
|
|
|
POWER_ENABLE_SOCKET(device_get_parent(dev), dev);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
2000-01-06 07:30:28 +00:00
|
|
|
DEVPRINTF((dev, "read_cis\n"));
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_read_cis(sc);
|
|
|
|
|
2000-01-06 07:30:28 +00:00
|
|
|
DEVPRINTF((dev, "check_cis_quirks\n"));
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_check_cis_quirks(dev);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* bail now if the card has no functions, or if there was an error in
|
|
|
|
* the cis.
|
|
|
|
*/
|
|
|
|
|
2001-01-06 18:04:55 +00:00
|
|
|
if (sc->card.error) {
|
2002-08-31 18:34:30 +00:00
|
|
|
device_printf(dev, "CARD ERROR!\n");
|
1999-10-26 06:52:31 +00:00
|
|
|
return (1);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
|
|
|
if (STAILQ_EMPTY(&sc->card.pf_head)) {
|
2002-08-31 18:34:30 +00:00
|
|
|
device_printf(dev, "Card has no functions!\n");
|
1999-10-26 06:52:31 +00:00
|
|
|
return (1);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
|
2002-02-09 21:34:06 +00:00
|
|
|
if (bootverbose || pccard_debug)
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_print_cis(dev);
|
|
|
|
|
2000-01-06 07:30:28 +00:00
|
|
|
DEVPRINTF((dev, "functions scanning\n"));
|
2002-08-31 18:34:30 +00:00
|
|
|
i = -1;
|
1999-10-26 06:52:31 +00:00
|
|
|
STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
|
2002-08-31 18:34:30 +00:00
|
|
|
i++;
|
|
|
|
if (STAILQ_EMPTY(&pf->cfe_head)) {
|
|
|
|
device_printf(dev,
|
|
|
|
"Function %d has no config entries.!\n", i);
|
1999-10-26 06:52:31 +00:00
|
|
|
continue;
|
2002-08-31 18:34:30 +00:00
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
pf->sc = sc;
|
|
|
|
pf->cfe = NULL;
|
2000-08-22 04:25:57 +00:00
|
|
|
pf->dev = NULL;
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
2002-10-07 23:05:33 +00:00
|
|
|
DEVPRINTF((dev, "Card has %d functions. pccard_mfc is %d\n", i + 1,
|
2002-08-31 18:34:30 +00:00
|
|
|
pccard_mfc(sc)));
|
2001-08-27 00:09:42 +00:00
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
|
|
|
|
if (STAILQ_EMPTY(&pf->cfe_head))
|
|
|
|
continue;
|
2000-06-18 05:28:59 +00:00
|
|
|
/*
|
|
|
|
* In NetBSD, the drivers are responsible for activating
|
|
|
|
* each function of a card. I think that in FreeBSD we
|
|
|
|
* want to activate them enough for the usual bus_*_resource
|
|
|
|
* routines will do the right thing. This many mean a
|
|
|
|
* departure from the current NetBSD model.
|
|
|
|
*
|
2002-10-07 23:05:33 +00:00
|
|
|
* This seems to work well in practice for most cards.
|
|
|
|
* However, there are two cases that are problematic.
|
|
|
|
* If a driver wishes to pick and chose which config
|
|
|
|
* entry to use, then this method falls down. These
|
|
|
|
* are usually older cards. In addition, there are
|
|
|
|
* some cards that have multiple hardware units on the
|
|
|
|
* cards, but presents only one CIS chain. These cards
|
|
|
|
* are combination cards, but only one of these units
|
|
|
|
* can be on at a time.
|
2000-06-18 05:28:59 +00:00
|
|
|
*/
|
2000-10-29 16:29:05 +00:00
|
|
|
ivar = malloc(sizeof(struct pccard_ivar), M_DEVBUF,
|
2003-02-19 05:47:46 +00:00
|
|
|
M_WAITOK | M_ZERO);
|
2000-06-18 05:28:59 +00:00
|
|
|
child = device_add_child(dev, NULL, -1);
|
2000-09-16 06:52:20 +00:00
|
|
|
device_set_ivars(child, ivar);
|
2000-10-09 03:40:15 +00:00
|
|
|
ivar->fcn = pf;
|
2000-10-16 07:51:12 +00:00
|
|
|
pf->dev = child;
|
2000-10-15 17:21:50 +00:00
|
|
|
/*
|
|
|
|
* XXX We might want to move the next two lines into
|
|
|
|
* XXX the pccard interface layer. For the moment, this
|
|
|
|
* XXX is OK, but some drivers want to pick the config
|
|
|
|
* XXX entry to use as well as some address tweaks (mostly
|
|
|
|
* XXX due to bugs in decode logic that makes some
|
|
|
|
* XXX addresses illegal or broken).
|
|
|
|
*/
|
2000-09-16 06:52:20 +00:00
|
|
|
pccard_function_init(pf);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (sc->sc_enabled_count == 0)
|
|
|
|
POWER_ENABLE_SOCKET(device_get_parent(dev), dev);
|
2000-10-19 22:36:41 +00:00
|
|
|
if (pccard_function_enable(pf) == 0 &&
|
2003-04-08 07:02:03 +00:00
|
|
|
pccard_set_default_descr(child) == 0 &&
|
2000-10-19 22:36:41 +00:00
|
|
|
device_probe_and_attach(child) == 0) {
|
2000-01-06 07:30:28 +00:00
|
|
|
DEVPRINTF((sc->dev, "function %d CCR at %d "
|
2003-11-02 20:18:19 +00:00
|
|
|
"offset %x mask %x: "
|
|
|
|
"%x %x %x %x, %x %x %x %x, %x\n",
|
2000-10-15 17:21:50 +00:00
|
|
|
pf->number, pf->pf_ccr_window, pf->pf_ccr_offset,
|
2003-11-02 20:18:19 +00:00
|
|
|
pf->ccr_mask, pccard_ccr_read(pf, 0x00),
|
1999-10-26 06:52:31 +00:00
|
|
|
pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04),
|
|
|
|
pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A),
|
|
|
|
pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E),
|
|
|
|
pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12)));
|
2000-10-15 17:21:50 +00:00
|
|
|
} else {
|
2001-11-26 07:14:00 +00:00
|
|
|
if (pf->cfe != NULL)
|
|
|
|
pccard_function_disable(pf);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
2001-03-22 05:41:20 +00:00
|
|
|
return (0);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
static int
|
2002-11-02 23:00:28 +00:00
|
|
|
pccard_detach_card(device_t dev)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
2000-08-19 19:22:04 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
1999-10-26 06:52:31 +00:00
|
|
|
struct pccard_function *pf;
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_config_entry *cfe;
|
2003-09-05 03:08:08 +00:00
|
|
|
int state;
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* We are running on either the PCCARD socket's event thread
|
|
|
|
* or in user context detaching a device by user request.
|
|
|
|
*/
|
|
|
|
STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
|
2003-09-05 03:08:08 +00:00
|
|
|
if (pf->dev == NULL)
|
|
|
|
continue;
|
|
|
|
state = device_get_state(pf->dev);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (state == DS_ATTACHED || state == DS_BUSY)
|
|
|
|
device_detach(pf->dev);
|
2001-11-26 07:14:00 +00:00
|
|
|
if (pf->cfe != NULL)
|
|
|
|
pccard_function_disable(pf);
|
2001-08-27 00:09:42 +00:00
|
|
|
pccard_function_free(pf);
|
2002-11-14 05:13:52 +00:00
|
|
|
device_delete_child(dev, pf->dev);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
if (sc->sc_enabled_count == 0)
|
|
|
|
POWER_DISABLE_SOCKET(device_get_parent(dev), dev);
|
|
|
|
|
|
|
|
while (NULL != (pf = STAILQ_FIRST(&sc->card.pf_head))) {
|
|
|
|
while (NULL != (cfe = STAILQ_FIRST(&pf->cfe_head))) {
|
|
|
|
STAILQ_REMOVE_HEAD(&pf->cfe_head, cfe_list);
|
|
|
|
free(cfe, M_DEVBUF);
|
|
|
|
}
|
|
|
|
STAILQ_REMOVE_HEAD(&sc->card.pf_head, pf_list);
|
|
|
|
free(pf, M_DEVBUF);
|
|
|
|
}
|
2001-03-22 05:41:20 +00:00
|
|
|
return (0);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
2002-05-30 17:38:00 +00:00
|
|
|
static const struct pccard_product *
|
|
|
|
pccard_do_product_lookup(device_t bus, device_t dev,
|
2003-03-18 02:40:40 +00:00
|
|
|
const struct pccard_product *tab, size_t ent_size,
|
|
|
|
pccard_product_match_fn matchfn)
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
{
|
|
|
|
const struct pccard_product *ent;
|
|
|
|
int matches;
|
|
|
|
u_int32_t fcn;
|
|
|
|
u_int32_t vendor;
|
|
|
|
u_int32_t prod;
|
2003-10-26 00:51:40 +00:00
|
|
|
const char *vendorstr;
|
|
|
|
const char *prodstr;
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (sizeof *ent > ent_size)
|
2003-03-18 02:40:40 +00:00
|
|
|
panic("pccard_product_lookup: bogus ent_size %jd",
|
|
|
|
(intmax_t) ent_size);
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
#endif
|
|
|
|
if (pccard_get_vendor(dev, &vendor))
|
|
|
|
return (NULL);
|
|
|
|
if (pccard_get_product(dev, &prod))
|
|
|
|
return (NULL);
|
|
|
|
if (pccard_get_function_number(dev, &fcn))
|
|
|
|
return (NULL);
|
|
|
|
if (pccard_get_vendor_str(dev, &vendorstr))
|
|
|
|
return (NULL);
|
|
|
|
if (pccard_get_product_str(dev, &prodstr))
|
|
|
|
return (NULL);
|
2003-04-10 04:11:15 +00:00
|
|
|
for (ent = tab; ent->pp_vendor != 0; ent =
|
2001-08-27 00:09:42 +00:00
|
|
|
(const struct pccard_product *) ((const char *) ent + ent_size)) {
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
matches = 1;
|
2001-11-20 06:15:24 +00:00
|
|
|
if (ent->pp_vendor == PCCARD_VENDOR_ANY &&
|
2003-04-04 14:40:01 +00:00
|
|
|
ent->pp_product == PCCARD_PRODUCT_ANY &&
|
2001-11-20 06:15:24 +00:00
|
|
|
ent->pp_cis[0] == NULL &&
|
|
|
|
ent->pp_cis[1] == NULL) {
|
2003-04-09 15:54:00 +00:00
|
|
|
if (ent->pp_name)
|
|
|
|
device_printf(dev,
|
|
|
|
"Total wildcard entry ignored for %s\n",
|
|
|
|
ent->pp_name);
|
2001-11-20 06:15:24 +00:00
|
|
|
continue;
|
|
|
|
}
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
if (matches && ent->pp_vendor != PCCARD_VENDOR_ANY &&
|
|
|
|
vendor != ent->pp_vendor)
|
|
|
|
matches = 0;
|
|
|
|
if (matches && ent->pp_product != PCCARD_PRODUCT_ANY &&
|
|
|
|
prod != ent->pp_product)
|
|
|
|
matches = 0;
|
|
|
|
if (matches && fcn != ent->pp_expfunc)
|
|
|
|
matches = 0;
|
2001-01-21 08:09:00 +00:00
|
|
|
if (matches && ent->pp_cis[0] &&
|
|
|
|
strcmp(ent->pp_cis[0], vendorstr) != 0)
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
matches = 0;
|
2001-01-21 08:09:00 +00:00
|
|
|
if (matches && ent->pp_cis[1] &&
|
|
|
|
strcmp(ent->pp_cis[1], prodstr) != 0)
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
matches = 0;
|
2001-01-21 08:09:00 +00:00
|
|
|
/* XXX need to match cis[2] and cis[3] also XXX */
|
o Merge in changes to the NetBSD sources:
pcmciavar.h 1.9->1.12
1.12, enami, minor coding nits
1.11, augustss, (pcmcia_devinfo NRFB)
1.10, cgd, add generic lookup routines
pcmcia.c 1.14->1.23
1.23, drochner, (probe code printing, NRFB)
1.22, augustss, KNF
1.21, uch, (hpcmips tweaks NRFB)
1.20, chopps, remove bogus debug
1.19, enami, minor coding nits
1.18, augustss, (pcmcia_devinfo NRFB)
1.17, nathanw, LP64 printf fixes
1.16, cgd, add generic lookup routines
1.15, aymeric, printf fixes
NRFB == not relevant to freebsd
o Expand the pccard matching routines to include the ability to match
against the CIS strings since our current driver database is based on
that.
o Add lots more ivars to get the information necessary to snag these values.
2000-09-22 01:15:26 +00:00
|
|
|
if (matchfn != NULL)
|
|
|
|
matches = (*matchfn)(dev, ent, matches);
|
|
|
|
if (matches)
|
|
|
|
return (ent);
|
|
|
|
}
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
/*
|
|
|
|
* Initialize a PCCARD function. May be called as long as the function is
|
|
|
|
* disabled.
|
2001-08-27 01:18:21 +00:00
|
|
|
*
|
|
|
|
* Note: pccard_function_init should not keep resources allocated. It should
|
|
|
|
* only set them up ala isa pnp, set the values in the rl lists, and return.
|
|
|
|
* Any resource held after pccard_function_init is called is a bug. However,
|
|
|
|
* the bus routines to get the resources also assume that pccard_function_init
|
|
|
|
* does this, so they need to be fixed too.
|
1999-10-26 06:52:31 +00:00
|
|
|
*/
|
2001-08-27 00:09:42 +00:00
|
|
|
static void
|
2001-01-06 18:04:55 +00:00
|
|
|
pccard_function_init(struct pccard_function *pf)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
2000-09-16 06:52:20 +00:00
|
|
|
struct pccard_config_entry *cfe;
|
2000-10-16 07:51:12 +00:00
|
|
|
int i;
|
2000-10-17 06:29:21 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
|
|
|
|
struct resource_list *rl = &devi->resources;
|
2001-01-07 20:40:23 +00:00
|
|
|
struct resource_list_entry *rle;
|
2000-10-17 06:29:21 +00:00
|
|
|
struct resource *r = 0;
|
|
|
|
device_t bus;
|
2000-10-22 04:46:56 +00:00
|
|
|
int start;
|
|
|
|
int end;
|
2002-02-19 05:04:37 +00:00
|
|
|
int spaces;
|
2000-09-16 06:52:20 +00:00
|
|
|
|
2001-01-06 18:04:55 +00:00
|
|
|
if (pf->pf_flags & PFF_ENABLED) {
|
|
|
|
printf("pccard_function_init: function is enabled");
|
|
|
|
return;
|
|
|
|
}
|
2000-10-17 06:29:21 +00:00
|
|
|
bus = device_get_parent(pf->dev);
|
1999-10-26 06:52:31 +00:00
|
|
|
/* Remember which configuration entry we are using. */
|
2001-02-04 16:08:18 +00:00
|
|
|
STAILQ_FOREACH(cfe, &pf->cfe_head, cfe_list) {
|
2000-10-16 07:51:12 +00:00
|
|
|
for (i = 0; i < cfe->num_iospace; i++)
|
|
|
|
cfe->iores[i] = NULL;
|
|
|
|
cfe->irqres = NULL;
|
2002-02-19 05:04:37 +00:00
|
|
|
spaces = 0;
|
2000-10-16 07:51:12 +00:00
|
|
|
for (i = 0; i < cfe->num_iospace; i++) {
|
2000-10-22 04:46:56 +00:00
|
|
|
start = cfe->iospace[i].start;
|
|
|
|
if (start)
|
|
|
|
end = start + cfe->iospace[i].length - 1;
|
|
|
|
else
|
|
|
|
end = ~0;
|
2000-10-16 07:51:12 +00:00
|
|
|
cfe->iorid[i] = i;
|
2002-02-19 05:04:37 +00:00
|
|
|
DEVPRINTF((bus, "I/O rid %d start %x end %x\n",
|
|
|
|
i, start, end));
|
2000-10-17 06:29:21 +00:00
|
|
|
r = cfe->iores[i] = bus_alloc_resource(bus,
|
2000-10-22 04:46:56 +00:00
|
|
|
SYS_RES_IOPORT, &cfe->iorid[i], start, end,
|
2001-01-06 18:04:55 +00:00
|
|
|
cfe->iospace[i].length,
|
2000-10-22 04:46:56 +00:00
|
|
|
rman_make_alignment_flags(cfe->iospace[i].length));
|
2001-05-10 06:55:39 +00:00
|
|
|
if (cfe->iores[i] == NULL)
|
2000-10-16 07:51:12 +00:00
|
|
|
goto not_this_one;
|
2000-10-17 06:29:21 +00:00
|
|
|
resource_list_add(rl, SYS_RES_IOPORT, cfe->iorid[i],
|
|
|
|
rman_get_start(r), rman_get_end(r),
|
|
|
|
cfe->iospace[i].length);
|
2001-05-10 06:55:39 +00:00
|
|
|
rle = resource_list_find(rl, SYS_RES_IOPORT,
|
|
|
|
cfe->iorid[i]);
|
|
|
|
rle->res = r;
|
2002-02-19 05:04:37 +00:00
|
|
|
spaces++;
|
2000-10-16 07:51:12 +00:00
|
|
|
}
|
|
|
|
if (cfe->num_memspace > 0) {
|
2001-09-02 06:37:41 +00:00
|
|
|
/*
|
|
|
|
* Not implement yet, Fix me.
|
|
|
|
*/
|
2002-02-19 05:04:37 +00:00
|
|
|
DEVPRINTF((bus, "Memory space not yet implemented.\n"));
|
|
|
|
}
|
|
|
|
if (spaces == 0) {
|
|
|
|
DEVPRINTF((bus, "Neither memory nor I/O mampped\n"));
|
|
|
|
goto not_this_one;
|
2000-10-16 07:51:12 +00:00
|
|
|
}
|
|
|
|
if (cfe->irqmask) {
|
|
|
|
cfe->irqrid = 0;
|
2004-03-17 17:50:55 +00:00
|
|
|
r = cfe->irqres = bus_alloc_resource_any(bus,
|
|
|
|
SYS_RES_IRQ, &cfe->irqrid, 0);
|
2001-05-10 06:55:39 +00:00
|
|
|
if (cfe->irqres == NULL)
|
2000-10-16 07:51:12 +00:00
|
|
|
goto not_this_one;
|
2000-10-17 06:29:21 +00:00
|
|
|
resource_list_add(rl, SYS_RES_IRQ, cfe->irqrid,
|
|
|
|
rman_get_start(r), rman_get_end(r), 1);
|
2001-05-10 06:55:39 +00:00
|
|
|
rle = resource_list_find(rl, SYS_RES_IRQ,
|
|
|
|
cfe->irqrid);
|
|
|
|
rle->res = r;
|
2000-10-16 07:51:12 +00:00
|
|
|
}
|
|
|
|
/* If we get to here, we've allocated all we need */
|
2000-10-15 17:21:50 +00:00
|
|
|
pf->cfe = cfe;
|
2000-10-16 07:51:12 +00:00
|
|
|
break;
|
|
|
|
not_this_one:;
|
2000-10-22 04:46:56 +00:00
|
|
|
DEVPRVERBOSE((bus, "Allocation failed for cfe %d\n",
|
|
|
|
cfe->number));
|
2000-10-19 22:36:41 +00:00
|
|
|
/*
|
|
|
|
* Release resources that we partially allocated
|
|
|
|
* from this config entry.
|
|
|
|
*/
|
2000-10-16 07:51:12 +00:00
|
|
|
for (i = 0; i < cfe->num_iospace; i++) {
|
2001-05-10 06:55:39 +00:00
|
|
|
if (cfe->iores[i] != NULL) {
|
2001-01-06 18:04:55 +00:00
|
|
|
bus_release_resource(bus, SYS_RES_IOPORT,
|
2000-10-16 07:51:12 +00:00
|
|
|
cfe->iorid[i], cfe->iores[i]);
|
2001-08-27 00:09:42 +00:00
|
|
|
rle = resource_list_find(rl, SYS_RES_IOPORT,
|
2001-05-10 06:55:39 +00:00
|
|
|
cfe->iorid[i]);
|
|
|
|
rle->res = NULL;
|
|
|
|
resource_list_delete(rl, SYS_RES_IOPORT,
|
|
|
|
cfe->iorid[i]);
|
2001-04-21 02:29:09 +00:00
|
|
|
}
|
2000-10-16 07:51:12 +00:00
|
|
|
cfe->iores[i] = NULL;
|
|
|
|
}
|
2001-05-10 06:55:39 +00:00
|
|
|
if (cfe->irqmask && cfe->irqres != NULL) {
|
2000-10-17 06:29:21 +00:00
|
|
|
bus_release_resource(bus, SYS_RES_IRQ,
|
2000-10-16 07:51:12 +00:00
|
|
|
cfe->irqrid, cfe->irqres);
|
2001-05-10 06:55:39 +00:00
|
|
|
rle = resource_list_find(rl, SYS_RES_IRQ,
|
|
|
|
cfe->irqrid);
|
|
|
|
rle->res = NULL;
|
|
|
|
resource_list_delete(rl, SYS_RES_IRQ, cfe->irqrid);
|
2000-10-16 07:51:12 +00:00
|
|
|
cfe->irqres = NULL;
|
|
|
|
}
|
2000-10-15 17:21:50 +00:00
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
/*
|
|
|
|
* Free resources allocated by pccard_function_init(), May be called as long
|
|
|
|
* as the function is disabled.
|
2001-08-27 01:18:21 +00:00
|
|
|
*
|
|
|
|
* NOTE: This function should be unnecessary. pccard_function_init should
|
|
|
|
* never keep resources initialized.
|
2001-08-27 00:09:42 +00:00
|
|
|
*/
|
|
|
|
static void
|
|
|
|
pccard_function_free(struct pccard_function *pf)
|
|
|
|
{
|
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
if (pf->pf_flags & PFF_ENABLED) {
|
|
|
|
printf("pccard_function_init: function is enabled");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SLIST_FOREACH(rle, &devi->resources, link) {
|
|
|
|
if (rle->res) {
|
2003-04-08 07:02:03 +00:00
|
|
|
if (rman_get_device(rle->res) != pf->sc->dev)
|
2001-08-27 00:09:42 +00:00
|
|
|
device_printf(pf->sc->dev,
|
|
|
|
"function_free: Resource still owned by "
|
|
|
|
"child, oops. "
|
|
|
|
"(type=%d, rid=%d, addr=%lx)\n",
|
|
|
|
rle->type, rle->rid,
|
|
|
|
rman_get_start(rle->res));
|
|
|
|
BUS_RELEASE_RESOURCE(device_get_parent(pf->sc->dev),
|
2003-04-08 07:02:03 +00:00
|
|
|
pf->sc->dev, rle->type, rle->rid, rle->res);
|
2001-08-27 00:09:42 +00:00
|
|
|
rle->res = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
resource_list_free(&devi->resources);
|
|
|
|
}
|
|
|
|
|
2003-11-02 20:18:19 +00:00
|
|
|
static void
|
|
|
|
pccard_mfc_adjust_iobase(struct pccard_function *pf, bus_addr_t addr,
|
|
|
|
bus_addr_t offset, bus_size_t size)
|
|
|
|
{
|
2003-11-03 16:04:31 +00:00
|
|
|
bus_size_t iosize, tmp;
|
2003-11-02 20:18:19 +00:00
|
|
|
|
|
|
|
if (addr != 0) {
|
|
|
|
if (pf->pf_mfc_iomax == 0) {
|
|
|
|
pf->pf_mfc_iobase = addr + offset;
|
|
|
|
pf->pf_mfc_iomax = pf->pf_mfc_iobase + size;
|
|
|
|
} else {
|
|
|
|
/* this makes the assumption that nothing overlaps */
|
|
|
|
if (pf->pf_mfc_iobase > addr + offset)
|
|
|
|
pf->pf_mfc_iobase = addr + offset;
|
|
|
|
if (pf->pf_mfc_iomax < addr + offset + size)
|
|
|
|
pf->pf_mfc_iomax = addr + offset + size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
tmp = pf->pf_mfc_iomax - pf->pf_mfc_iobase;
|
|
|
|
/* round up to nearest (2^n)-1 */
|
|
|
|
for (iosize = 1; iosize < tmp; iosize <<= 1)
|
|
|
|
;
|
|
|
|
iosize--;
|
|
|
|
|
2003-11-04 06:30:59 +00:00
|
|
|
DEVPRINTF((pf->dev, "MFC: I/O base %#jx IOSIZE %#jx\n",
|
|
|
|
(uintmax_t)pf->pf_mfc_iobase, (uintmax_t)(iosize + 1)));
|
2003-11-02 20:18:19 +00:00
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_IOBASE0,
|
|
|
|
pf->pf_mfc_iobase & 0xff);
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_IOBASE1,
|
|
|
|
(pf->pf_mfc_iobase >> 8) & 0xff);
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_IOBASE2, 0);
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_IOBASE3, 0);
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_IOSIZE, iosize);
|
|
|
|
}
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
/* Enable a PCCARD function */
|
2001-08-27 00:09:42 +00:00
|
|
|
static int
|
2000-01-10 06:58:17 +00:00
|
|
|
pccard_function_enable(struct pccard_function *pf)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
struct pccard_function *tmp;
|
|
|
|
int reg;
|
2000-01-10 06:58:17 +00:00
|
|
|
device_t dev = pf->sc->dev;
|
2001-01-07 08:08:54 +00:00
|
|
|
|
2000-10-19 22:36:41 +00:00
|
|
|
if (pf->cfe == NULL) {
|
|
|
|
DEVPRVERBOSE((dev, "No config entry could be allocated.\n"));
|
2001-03-22 05:41:20 +00:00
|
|
|
return (ENOMEM);
|
2000-10-19 22:36:41 +00:00
|
|
|
}
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Increase the reference count on the socket, enabling power, if
|
|
|
|
* necessary.
|
|
|
|
*/
|
2001-08-27 00:09:42 +00:00
|
|
|
pf->sc->sc_enabled_count++;
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
if (pf->pf_flags & PFF_ENABLED) {
|
|
|
|
/*
|
|
|
|
* Don't do anything if we're already enabled.
|
|
|
|
*/
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* it's possible for different functions' CCRs to be in the same
|
|
|
|
* underlying page. Check for that.
|
|
|
|
*/
|
|
|
|
STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
|
|
|
|
if ((tmp->pf_flags & PFF_ENABLED) &&
|
|
|
|
(pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
|
|
|
|
((pf->ccr_base + PCCARD_CCR_SIZE) <=
|
2001-08-27 00:09:42 +00:00
|
|
|
(tmp->ccr_base - tmp->pf_ccr_offset +
|
|
|
|
tmp->pf_ccr_realsize))) {
|
1999-10-26 06:52:31 +00:00
|
|
|
pf->pf_ccrt = tmp->pf_ccrt;
|
|
|
|
pf->pf_ccrh = tmp->pf_ccrh;
|
|
|
|
pf->pf_ccr_realsize = tmp->pf_ccr_realsize;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* pf->pf_ccr_offset = (tmp->pf_ccr_offset -
|
|
|
|
* tmp->ccr_base) + pf->ccr_base;
|
|
|
|
*/
|
2001-01-06 18:04:55 +00:00
|
|
|
/* pf->pf_ccr_offset =
|
1999-10-26 06:52:31 +00:00
|
|
|
(tmp->pf_ccr_offset + pf->ccr_base) -
|
2001-01-06 18:04:55 +00:00
|
|
|
tmp->ccr_base; */
|
1999-10-26 06:52:31 +00:00
|
|
|
pf->pf_ccr_window = tmp->pf_ccr_window;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (tmp == NULL) {
|
2000-01-10 06:58:17 +00:00
|
|
|
pf->ccr_rid = 0;
|
|
|
|
pf->ccr_res = bus_alloc_resource(dev, SYS_RES_MEMORY,
|
2001-01-06 18:04:55 +00:00
|
|
|
&pf->ccr_rid, 0, ~0, 1 << 10, RF_ACTIVE);
|
|
|
|
if (!pf->ccr_res)
|
1999-10-26 06:52:31 +00:00
|
|
|
goto bad;
|
2002-11-14 14:02:32 +00:00
|
|
|
DEVPRINTF((dev, "ccr_res == %lx-%lx, base=%x\n",
|
2001-01-07 08:08:54 +00:00
|
|
|
rman_get_start(pf->ccr_res), rman_get_end(pf->ccr_res),
|
|
|
|
pf->ccr_base));
|
2000-06-18 05:28:59 +00:00
|
|
|
CARD_SET_RES_FLAGS(device_get_parent(dev), dev, SYS_RES_MEMORY,
|
|
|
|
pf->ccr_rid, PCCARD_A_MEM_ATTR);
|
2001-01-06 18:04:55 +00:00
|
|
|
CARD_SET_MEMORY_OFFSET(device_get_parent(dev), dev,
|
2001-01-07 16:31:09 +00:00
|
|
|
pf->ccr_rid, pf->ccr_base, &pf->pf_ccr_offset);
|
2000-01-10 06:58:17 +00:00
|
|
|
pf->pf_ccrt = rman_get_bustag(pf->ccr_res);
|
|
|
|
pf->pf_ccrh = rman_get_bushandle(pf->ccr_res);
|
|
|
|
pf->pf_ccr_realsize = 1;
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reg = (pf->cfe->number & PCCARD_CCR_OPTION_CFINDEX);
|
|
|
|
reg |= PCCARD_CCR_OPTION_LEVIREQ;
|
|
|
|
if (pccard_mfc(pf->sc)) {
|
|
|
|
reg |= (PCCARD_CCR_OPTION_FUNC_ENABLE |
|
|
|
|
PCCARD_CCR_OPTION_ADDR_DECODE);
|
2001-08-27 01:24:33 +00:00
|
|
|
/* PCCARD_CCR_OPTION_IRQ_ENABLE set elsewhere as needed */
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_OPTION, reg);
|
|
|
|
|
|
|
|
reg = 0;
|
|
|
|
if ((pf->cfe->flags & PCCARD_CFE_IO16) == 0)
|
|
|
|
reg |= PCCARD_CCR_STATUS_IOIS8;
|
|
|
|
if (pf->cfe->flags & PCCARD_CFE_AUDIO)
|
|
|
|
reg |= PCCARD_CCR_STATUS_AUDIO;
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_STATUS, reg);
|
|
|
|
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_SOCKETCOPY, 0);
|
|
|
|
|
2003-11-02 20:18:19 +00:00
|
|
|
if (pccard_mfc(pf->sc))
|
|
|
|
pccard_mfc_adjust_iobase(pf, 0, 0, 0);
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
#ifdef PCCARDDEBUG
|
|
|
|
if (pccard_debug) {
|
|
|
|
STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
|
2001-01-06 18:04:55 +00:00
|
|
|
device_printf(tmp->sc->dev,
|
2000-01-06 07:30:28 +00:00
|
|
|
"function %d CCR at %d offset %x: "
|
|
|
|
"%x %x %x %x, %x %x %x %x, %x\n",
|
2001-01-06 18:04:55 +00:00
|
|
|
tmp->number, tmp->pf_ccr_window,
|
2000-01-06 07:30:28 +00:00
|
|
|
tmp->pf_ccr_offset,
|
|
|
|
pccard_ccr_read(tmp, 0x00),
|
|
|
|
pccard_ccr_read(tmp, 0x02),
|
|
|
|
pccard_ccr_read(tmp, 0x04),
|
|
|
|
pccard_ccr_read(tmp, 0x06),
|
|
|
|
pccard_ccr_read(tmp, 0x0A),
|
2001-01-06 18:04:55 +00:00
|
|
|
pccard_ccr_read(tmp, 0x0C),
|
2000-01-06 07:30:28 +00:00
|
|
|
pccard_ccr_read(tmp, 0x0E),
|
|
|
|
pccard_ccr_read(tmp, 0x10),
|
|
|
|
pccard_ccr_read(tmp, 0x12));
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
pf->pf_flags |= PFF_ENABLED;
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
bad:
|
|
|
|
/*
|
|
|
|
* Decrement the reference count, and power down the socket, if
|
|
|
|
* necessary.
|
|
|
|
*/
|
2001-08-27 00:09:42 +00:00
|
|
|
pf->sc->sc_enabled_count--;
|
2000-08-26 00:07:40 +00:00
|
|
|
DEVPRINTF((dev, "bad --enabled_count = %d\n", pf->sc->sc_enabled_count));
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Disable PCCARD function. */
|
2001-08-27 00:09:42 +00:00
|
|
|
static void
|
2000-01-10 06:58:17 +00:00
|
|
|
pccard_function_disable(struct pccard_function *pf)
|
1999-10-26 06:52:31 +00:00
|
|
|
{
|
|
|
|
struct pccard_function *tmp;
|
2000-01-10 06:58:17 +00:00
|
|
|
device_t dev = pf->sc->dev;
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
if (pf->cfe == NULL)
|
2000-06-18 05:28:59 +00:00
|
|
|
panic("pccard_function_disable: function not initialized");
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
if ((pf->pf_flags & PFF_ENABLED) == 0) {
|
|
|
|
/*
|
|
|
|
* Don't do anything if we're already disabled.
|
|
|
|
*/
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2001-01-06 18:04:55 +00:00
|
|
|
if (pf->intr_handler != NULL) {
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(pf->dev);
|
|
|
|
struct resource_list_entry *rle =
|
|
|
|
resource_list_find(&devi->resources, SYS_RES_IRQ, 0);
|
|
|
|
BUS_TEARDOWN_INTR(dev, pf->dev, rle->res,
|
|
|
|
pf->intr_handler_cookie);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
/*
|
|
|
|
* it's possible for different functions' CCRs to be in the same
|
|
|
|
* underlying page. Check for that. Note we mark us as disabled
|
|
|
|
* first to avoid matching ourself.
|
|
|
|
*/
|
|
|
|
|
|
|
|
pf->pf_flags &= ~PFF_ENABLED;
|
|
|
|
STAILQ_FOREACH(tmp, &pf->sc->card.pf_head, pf_list) {
|
|
|
|
if ((tmp->pf_flags & PFF_ENABLED) &&
|
|
|
|
(pf->ccr_base >= (tmp->ccr_base - tmp->pf_ccr_offset)) &&
|
|
|
|
((pf->ccr_base + PCCARD_CCR_SIZE) <=
|
2001-08-27 00:09:42 +00:00
|
|
|
(tmp->ccr_base - tmp->pf_ccr_offset +
|
|
|
|
tmp->pf_ccr_realsize)))
|
1999-10-26 06:52:31 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Not used by anyone else; unmap the CCR. */
|
|
|
|
if (tmp == NULL) {
|
2001-01-06 18:04:55 +00:00
|
|
|
bus_release_resource(dev, SYS_RES_MEMORY, pf->ccr_rid,
|
2000-01-10 06:58:17 +00:00
|
|
|
pf->ccr_res);
|
|
|
|
pf->ccr_res = NULL;
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Decrement the reference count, and power down the socket, if
|
|
|
|
* necessary.
|
|
|
|
*/
|
2001-08-27 00:09:42 +00:00
|
|
|
pf->sc->sc_enabled_count--;
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
/*
|
|
|
|
* simulate the old "probe" routine. In the new world order, the driver
|
|
|
|
* needs to grab devices while in the old they were assigned to the device by
|
|
|
|
* the pccardd process. These symbols are exported to the upper layers.
|
|
|
|
*/
|
2001-03-22 06:00:07 +00:00
|
|
|
static int
|
|
|
|
pccard_compat_do_probe(device_t bus, device_t dev)
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
{
|
|
|
|
return (CARD_COMPAT_MATCH(dev));
|
|
|
|
}
|
|
|
|
|
2001-03-22 06:00:07 +00:00
|
|
|
static int
|
|
|
|
pccard_compat_do_attach(device_t bus, device_t dev)
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
{
|
|
|
|
int err;
|
|
|
|
|
|
|
|
err = CARD_COMPAT_PROBE(dev);
|
2003-08-25 18:20:03 +00:00
|
|
|
if (err <= 0)
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
err = CARD_COMPAT_ATTACH(dev);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
|
1999-11-29 06:42:55 +00:00
|
|
|
#define PCCARD_NPORT 2
|
|
|
|
#define PCCARD_NMEM 5
|
|
|
|
#define PCCARD_NIRQ 1
|
|
|
|
#define PCCARD_NDRQ 0
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
static int
|
|
|
|
pccard_add_children(device_t dev, int busno)
|
|
|
|
{
|
2000-04-13 06:42:58 +00:00
|
|
|
/* Call parent to scan for any current children */
|
2001-03-22 05:41:20 +00:00
|
|
|
return (0);
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_probe(device_t dev)
|
|
|
|
{
|
2000-10-19 22:36:41 +00:00
|
|
|
device_set_desc(dev, "16-bit PCCard bus");
|
2001-03-22 05:41:20 +00:00
|
|
|
return (pccard_add_children(dev, device_get_unit(dev)));
|
1999-10-26 06:52:31 +00:00
|
|
|
}
|
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
static int
|
|
|
|
pccard_attach(device_t dev)
|
|
|
|
{
|
2000-08-19 19:22:04 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
2000-06-18 05:28:59 +00:00
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
sc->dev = dev;
|
2000-06-18 05:28:59 +00:00
|
|
|
sc->sc_enabled_count = 0;
|
2001-03-22 05:41:20 +00:00
|
|
|
return (bus_generic_attach(dev));
|
2000-04-13 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
static int
|
|
|
|
pccard_detach(device_t dev)
|
|
|
|
{
|
2002-11-02 23:00:28 +00:00
|
|
|
pccard_detach_card(dev);
|
2001-08-27 00:09:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-12-15 05:58:28 +00:00
|
|
|
static int
|
|
|
|
pccard_suspend(device_t self)
|
|
|
|
{
|
2002-11-02 23:00:28 +00:00
|
|
|
pccard_detach_card(self);
|
2001-12-15 05:58:28 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static
|
|
|
|
int
|
|
|
|
pccard_resume(device_t self)
|
|
|
|
{
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1999-11-29 06:42:55 +00:00
|
|
|
static void
|
|
|
|
pccard_print_resources(struct resource_list *rl, const char *name, int type,
|
|
|
|
int count, const char *format)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
int printed;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
printed = 0;
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
rle = resource_list_find(rl, type, i);
|
2001-05-10 06:55:39 +00:00
|
|
|
if (rle != NULL) {
|
1999-11-29 06:42:55 +00:00
|
|
|
if (printed == 0)
|
|
|
|
printf(" %s ", name);
|
|
|
|
else if (printed > 0)
|
|
|
|
printf(",");
|
|
|
|
printed++;
|
|
|
|
printf(format, rle->start);
|
|
|
|
if (rle->count > 1) {
|
|
|
|
printf("-");
|
|
|
|
printf(format, rle->start + rle->count - 1);
|
|
|
|
}
|
|
|
|
} else if (i > 3) {
|
|
|
|
/* check the first few regardless */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_print_child(device_t dev, device_t child)
|
|
|
|
{
|
2000-10-09 03:40:15 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
1999-11-29 06:42:55 +00:00
|
|
|
struct resource_list *rl = &devi->resources;
|
|
|
|
int retval = 0;
|
|
|
|
|
|
|
|
retval += bus_print_child_header(dev, child);
|
|
|
|
retval += printf(" at");
|
|
|
|
|
2001-05-10 06:55:39 +00:00
|
|
|
if (devi != NULL) {
|
1999-11-29 06:42:55 +00:00
|
|
|
pccard_print_resources(rl, "port", SYS_RES_IOPORT,
|
|
|
|
PCCARD_NPORT, "%#lx");
|
|
|
|
pccard_print_resources(rl, "iomem", SYS_RES_MEMORY,
|
|
|
|
PCCARD_NMEM, "%#lx");
|
|
|
|
pccard_print_resources(rl, "irq", SYS_RES_IRQ, PCCARD_NIRQ,
|
|
|
|
"%ld");
|
2001-01-06 18:04:55 +00:00
|
|
|
pccard_print_resources(rl, "drq", SYS_RES_DRQ, PCCARD_NDRQ,
|
1999-11-29 06:42:55 +00:00
|
|
|
"%ld");
|
2000-10-18 02:21:00 +00:00
|
|
|
retval += printf(" function %d config %d", devi->fcn->number,
|
|
|
|
devi->fcn->cfe->number);
|
1999-11-29 06:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
retval += bus_print_child_footer(dev, child);
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_set_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_long start, u_long count)
|
|
|
|
{
|
2000-10-09 03:40:15 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
1999-11-29 06:42:55 +00:00
|
|
|
struct resource_list *rl = &devi->resources;
|
|
|
|
|
|
|
|
if (type != SYS_RES_IOPORT && type != SYS_RES_MEMORY
|
|
|
|
&& type != SYS_RES_IRQ && type != SYS_RES_DRQ)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (EINVAL);
|
1999-11-29 06:42:55 +00:00
|
|
|
if (rid < 0)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (EINVAL);
|
1999-11-29 06:42:55 +00:00
|
|
|
if (type == SYS_RES_IOPORT && rid >= PCCARD_NPORT)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (EINVAL);
|
1999-11-29 06:42:55 +00:00
|
|
|
if (type == SYS_RES_MEMORY && rid >= PCCARD_NMEM)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (EINVAL);
|
1999-11-29 06:42:55 +00:00
|
|
|
if (type == SYS_RES_IRQ && rid >= PCCARD_NIRQ)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (EINVAL);
|
1999-11-29 06:42:55 +00:00
|
|
|
if (type == SYS_RES_DRQ && rid >= PCCARD_NDRQ)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (EINVAL);
|
1999-11-29 06:42:55 +00:00
|
|
|
|
|
|
|
resource_list_add(rl, type, rid, start, start + count - 1, count);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (NULL != resource_list_alloc(rl, device_get_parent(dev), dev,
|
|
|
|
type, &rid, start, start + count - 1, count, 0))
|
|
|
|
return 0;
|
|
|
|
else
|
|
|
|
return ENOMEM;
|
1999-11-29 06:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_get_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_long *startp, u_long *countp)
|
|
|
|
{
|
2000-10-09 03:40:15 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
1999-11-29 06:42:55 +00:00
|
|
|
struct resource_list *rl = &devi->resources;
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
2001-05-10 06:55:39 +00:00
|
|
|
if (rle == NULL)
|
2001-03-22 05:41:20 +00:00
|
|
|
return (ENOENT);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-05-10 06:55:39 +00:00
|
|
|
if (startp != NULL)
|
1999-11-29 06:42:55 +00:00
|
|
|
*startp = rle->start;
|
2001-05-10 06:55:39 +00:00
|
|
|
if (countp != NULL)
|
1999-11-29 06:42:55 +00:00
|
|
|
*countp = rle->count;
|
|
|
|
|
2001-03-22 05:41:20 +00:00
|
|
|
return (0);
|
1999-11-29 06:42:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pccard_delete_resource(device_t dev, device_t child, int type, int rid)
|
|
|
|
{
|
2000-10-09 03:40:15 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
1999-11-29 06:42:55 +00:00
|
|
|
struct resource_list *rl = &devi->resources;
|
|
|
|
resource_list_delete(rl, type, rid);
|
|
|
|
}
|
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
static int
|
|
|
|
pccard_set_res_flags(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_int32_t flags)
|
|
|
|
{
|
2001-03-22 05:41:20 +00:00
|
|
|
return (CARD_SET_RES_FLAGS(device_get_parent(dev), child, type,
|
|
|
|
rid, flags));
|
2000-04-13 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_set_memory_offset(device_t dev, device_t child, int rid,
|
2001-08-27 00:09:42 +00:00
|
|
|
u_int32_t offset, u_int32_t *deltap)
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
{
|
2001-03-22 05:41:20 +00:00
|
|
|
return (CARD_SET_MEMORY_OFFSET(device_get_parent(dev), child, rid,
|
|
|
|
offset, deltap));
|
2000-04-13 06:42:58 +00:00
|
|
|
}
|
|
|
|
|
2002-10-07 23:05:33 +00:00
|
|
|
static void
|
|
|
|
pccard_probe_nomatch(device_t bus, device_t child)
|
|
|
|
{
|
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
|
|
|
struct pccard_function *func = devi->fcn;
|
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(bus);
|
|
|
|
|
|
|
|
device_printf(bus, "<unknown card>");
|
|
|
|
printf(" (manufacturer=0x%04x, product=0x%04x) at function %d\n",
|
|
|
|
sc->card.manufacturer, sc->card.product, func->number);
|
|
|
|
device_printf(bus, " CIS info: %s, %s, %s\n", sc->card.cis1_info[0],
|
|
|
|
sc->card.cis1_info[1], sc->card.cis1_info[2]);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_child_location_str(device_t bus, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
|
|
|
struct pccard_function *func = devi->fcn;
|
|
|
|
|
|
|
|
snprintf(buf, buflen, "function=%d", func->number);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_child_pnpinfo_str(device_t bus, device_t child, char *buf,
|
|
|
|
size_t buflen)
|
|
|
|
{
|
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
|
|
|
struct pccard_function *func = devi->fcn;
|
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(bus);
|
|
|
|
|
|
|
|
snprintf(buf, buflen, "manufacturer=0x%04x product=0x%04x "
|
|
|
|
"cisvendor=\"%s\" cisproduct=\"%s\" function_type=%d",
|
|
|
|
sc->card.manufacturer, sc->card.product, sc->card.cis1_info[0],
|
|
|
|
sc->card.cis1_info[1], func->function);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
static int
|
|
|
|
pccard_read_ivar(device_t bus, device_t child, int which, u_char *result)
|
|
|
|
{
|
2000-10-09 03:40:15 +00:00
|
|
|
struct pccard_ivar *devi = PCCARD_IVAR(child);
|
2000-10-07 05:48:51 +00:00
|
|
|
struct pccard_function *func = devi->fcn;
|
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(bus);
|
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
default:
|
|
|
|
case PCCARD_IVAR_ETHADDR:
|
2001-09-02 06:37:41 +00:00
|
|
|
bcopy(func->pf_funce_lan_nid, result, ETHER_ADDR_LEN);
|
2000-10-07 05:48:51 +00:00
|
|
|
break;
|
|
|
|
case PCCARD_IVAR_VENDOR:
|
|
|
|
*(u_int32_t *) result = sc->card.manufacturer;
|
|
|
|
break;
|
|
|
|
case PCCARD_IVAR_PRODUCT:
|
|
|
|
*(u_int32_t *) result = sc->card.product;
|
|
|
|
break;
|
2002-02-20 14:30:46 +00:00
|
|
|
case PCCARD_IVAR_PRODEXT:
|
|
|
|
*(u_int16_t *) result = sc->card.prodext;
|
|
|
|
break;
|
2001-04-21 04:08:39 +00:00
|
|
|
case PCCARD_IVAR_FUNCTION:
|
|
|
|
*(u_int32_t *) result = func->function;
|
|
|
|
break;
|
2000-10-07 05:48:51 +00:00
|
|
|
case PCCARD_IVAR_FUNCTION_NUMBER:
|
2000-10-09 03:40:15 +00:00
|
|
|
if (!func) {
|
|
|
|
device_printf(bus, "No function number, bug!\n");
|
|
|
|
return (ENOENT);
|
|
|
|
}
|
|
|
|
*(u_int32_t *) result = func->number;
|
2000-10-07 05:48:51 +00:00
|
|
|
break;
|
|
|
|
case PCCARD_IVAR_VENDOR_STR:
|
|
|
|
*(char **) result = sc->card.cis1_info[0];
|
|
|
|
break;
|
|
|
|
case PCCARD_IVAR_PRODUCT_STR:
|
|
|
|
*(char **) result = sc->card.cis1_info[1];
|
|
|
|
break;
|
|
|
|
case PCCARD_IVAR_CIS3_STR:
|
|
|
|
*(char **) result = sc->card.cis1_info[2];
|
|
|
|
break;
|
2000-10-15 17:21:50 +00:00
|
|
|
case PCCARD_IVAR_CIS4_STR:
|
2002-10-07 07:18:32 +00:00
|
|
|
*(char **) result = sc->card.cis1_info[3];
|
2000-10-15 17:21:50 +00:00
|
|
|
break;
|
2000-10-07 05:48:51 +00:00
|
|
|
}
|
|
|
|
return (0);
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
}
|
|
|
|
|
2000-10-07 05:48:51 +00:00
|
|
|
static void
|
|
|
|
pccard_driver_added(device_t dev, driver_t *driver)
|
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
|
|
|
struct pccard_function *pf;
|
|
|
|
device_t child;
|
|
|
|
|
|
|
|
STAILQ_FOREACH(pf, &sc->card.pf_head, pf_list) {
|
|
|
|
if (STAILQ_EMPTY(&pf->cfe_head))
|
|
|
|
continue;
|
|
|
|
child = pf->dev;
|
|
|
|
if (device_get_state(child) != DS_NOTPRESENT)
|
|
|
|
continue;
|
|
|
|
if (pccard_function_enable(pf) == 0 &&
|
|
|
|
device_probe_and_attach(child) == 0) {
|
|
|
|
DEVPRINTF((sc->dev, "function %d CCR at %d "
|
|
|
|
"offset %x: %x %x %x %x, %x %x %x %x, %x\n",
|
|
|
|
pf->number, pf->pf_ccr_window, pf->pf_ccr_offset,
|
|
|
|
pccard_ccr_read(pf, 0x00),
|
|
|
|
pccard_ccr_read(pf, 0x02), pccard_ccr_read(pf, 0x04),
|
|
|
|
pccard_ccr_read(pf, 0x06), pccard_ccr_read(pf, 0x0A),
|
|
|
|
pccard_ccr_read(pf, 0x0C), pccard_ccr_read(pf, 0x0E),
|
|
|
|
pccard_ccr_read(pf, 0x10), pccard_ccr_read(pf, 0x12)));
|
|
|
|
} else {
|
2001-11-26 07:14:00 +00:00
|
|
|
if (pf->cfe != NULL)
|
|
|
|
pccard_function_disable(pf);
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
2000-10-07 05:48:51 +00:00
|
|
|
}
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
|
2000-10-17 06:29:21 +00:00
|
|
|
static struct resource *
|
|
|
|
pccard_alloc_resource(device_t dev, device_t child, int type, int *rid,
|
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_ivar *dinfo;
|
|
|
|
struct resource_list_entry *rle = 0;
|
|
|
|
int passthrough = (device_get_parent(child) != dev);
|
2003-11-02 20:18:19 +00:00
|
|
|
int isdefault = (start == 0 && end == ~0UL && count == 1);
|
2002-10-07 23:05:33 +00:00
|
|
|
struct resource *r = NULL;
|
2000-10-17 06:29:21 +00:00
|
|
|
|
2003-11-02 20:18:19 +00:00
|
|
|
/* XXX I'm no longer sure this is right */
|
2001-08-27 00:09:42 +00:00
|
|
|
if (passthrough) {
|
|
|
|
return (BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
|
|
|
|
type, rid, start, end, count, flags));
|
2000-10-17 06:29:21 +00:00
|
|
|
}
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
rle = resource_list_find(&dinfo->resources, type, *rid);
|
|
|
|
|
2003-11-02 20:18:19 +00:00
|
|
|
if (rle == NULL && isdefault)
|
|
|
|
return (NULL); /* no resource of that type/rid */
|
|
|
|
if (rle == NULL || rle->res == NULL) {
|
|
|
|
/* Do we want this device to own it? */
|
|
|
|
/* XXX I think so, but that might be lame XXX */
|
|
|
|
r = bus_alloc_resource(dev, type, rid, start, end,
|
|
|
|
count, flags /* XXX aligment? */);
|
|
|
|
if (r == NULL)
|
|
|
|
goto bad;
|
|
|
|
resource_list_add(&dinfo->resources, type, *rid,
|
|
|
|
rman_get_start(r), rman_get_end(r), count);
|
|
|
|
rle = resource_list_find(&dinfo->resources, type, *rid);
|
|
|
|
if (!rle)
|
|
|
|
goto bad;
|
|
|
|
rle->res = r;
|
2000-10-18 02:21:00 +00:00
|
|
|
}
|
2003-11-02 20:18:19 +00:00
|
|
|
/*
|
|
|
|
* XXX the following looks wrong, in theory, but likely it is
|
|
|
|
* XXX needed because of how the CIS code allocates resources
|
|
|
|
* XXX for this device.
|
|
|
|
*/
|
2003-04-08 07:02:03 +00:00
|
|
|
if (rman_get_device(rle->res) != dev)
|
2002-10-07 23:05:33 +00:00
|
|
|
return (NULL);
|
|
|
|
bus_release_resource(dev, type, *rid, rle->res);
|
|
|
|
rle->res = NULL;
|
|
|
|
switch(type) {
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
if (!(flags & RF_ALIGNMENT_MASK))
|
|
|
|
flags |= rman_make_alignment_flags(rle->count);
|
|
|
|
break;
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
flags |= RF_SHAREABLE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
rle->res = resource_list_alloc(&dinfo->resources, dev, child,
|
|
|
|
type, rid, rle->start, rle->end, rle->count, flags);
|
|
|
|
return (rle->res);
|
|
|
|
bad:;
|
|
|
|
device_printf(dev, "WARNING: Resource not reserved by pccard\n");
|
|
|
|
return (NULL);
|
2000-10-17 06:29:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_release_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
struct resource *r)
|
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_ivar *dinfo;
|
|
|
|
int passthrough = (device_get_parent(child) != dev);
|
|
|
|
struct resource_list_entry *rle = 0;
|
|
|
|
int ret;
|
|
|
|
int flags;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
if (passthrough)
|
|
|
|
return BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
|
|
|
|
type, rid, r);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
dinfo = device_get_ivars(child);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
rle = resource_list_find(&dinfo->resources, type, rid);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
if (!rle) {
|
|
|
|
device_printf(dev, "Allocated resource not found, "
|
|
|
|
"%d %x %lx %lx\n",
|
|
|
|
type, rid, rman_get_start(r), rman_get_size(r));
|
|
|
|
return ENOENT;
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
if (!rle->res) {
|
|
|
|
device_printf(dev, "Allocated resource not recorded\n");
|
|
|
|
return ENOENT;
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
ret = BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
|
|
|
|
type, rid, r);
|
|
|
|
switch(type) {
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
case SYS_RES_MEMORY:
|
|
|
|
flags = rman_make_alignment_flags(rle->count);
|
|
|
|
break;
|
|
|
|
case SYS_RES_IRQ:
|
|
|
|
flags = RF_SHAREABLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
flags = 0;
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
rle->res = bus_alloc_resource(dev, type, &rid,
|
|
|
|
rle->start, rle->end, rle->count, flags);
|
|
|
|
if (rle->res == NULL)
|
|
|
|
device_printf(dev, "release_resource: "
|
|
|
|
"unable to reaquire resource\n");
|
|
|
|
return ret;
|
2000-10-17 06:29:21 +00:00
|
|
|
}
|
|
|
|
|
2000-10-19 22:36:41 +00:00
|
|
|
static void
|
|
|
|
pccard_child_detached(device_t parent, device_t dev)
|
|
|
|
{
|
|
|
|
struct pccard_ivar *ivar = PCCARD_IVAR(dev);
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_function *pf = ivar->fcn;
|
2000-10-19 22:36:41 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
pccard_function_disable(pf);
|
2000-10-19 22:36:41 +00:00
|
|
|
}
|
|
|
|
|
2001-01-06 18:04:55 +00:00
|
|
|
static void
|
2001-01-07 20:40:23 +00:00
|
|
|
pccard_intr(void *arg)
|
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
struct pccard_function *pf = (struct pccard_function*) arg;
|
|
|
|
int reg;
|
2002-09-04 06:53:37 +00:00
|
|
|
int doisr = 1;
|
2001-08-27 00:09:42 +00:00
|
|
|
|
2001-08-27 01:24:33 +00:00
|
|
|
/*
|
2002-09-04 06:53:37 +00:00
|
|
|
* MFC cards know if they interrupted, so we have to ack the
|
|
|
|
* interrupt and call the ISR. Non-MFC cards don't have these
|
|
|
|
* bits, so they always get called. Many non-MFC cards have
|
|
|
|
* this bit set always upon read, but some do not.
|
|
|
|
*
|
|
|
|
* We always ack the interrupt, even if there's no ISR
|
|
|
|
* for the card. This is done on the theory that acking
|
|
|
|
* the interrupt will pacify the card enough to keep an
|
|
|
|
* interrupt storm from happening. Of course this won't
|
|
|
|
* help in the non-MFC case.
|
2003-06-13 21:30:29 +00:00
|
|
|
*
|
|
|
|
* This has no impact for MPSAFEness of the client drivers.
|
|
|
|
* We register this with whatever flags the intr_handler
|
|
|
|
* was registered with. All these functions are MPSAFE.
|
2001-08-27 01:24:33 +00:00
|
|
|
*/
|
2002-09-04 06:53:37 +00:00
|
|
|
if (pccard_mfc(pf->sc)) {
|
|
|
|
reg = pccard_ccr_read(pf, PCCARD_CCR_STATUS);
|
|
|
|
if (reg & PCCARD_CCR_STATUS_INTR)
|
|
|
|
pccard_ccr_write(pf, PCCARD_CCR_STATUS,
|
|
|
|
reg & ~PCCARD_CCR_STATUS_INTR);
|
|
|
|
else
|
|
|
|
doisr = 0;
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2002-09-04 06:53:37 +00:00
|
|
|
if (pf->intr_handler != NULL && doisr)
|
|
|
|
pf->intr_handler(pf->intr_handler_arg);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-01-07 20:40:23 +00:00
|
|
|
pccard_setup_intr(device_t dev, device_t child, struct resource *irq,
|
|
|
|
int flags, driver_intr_t *intr, void *arg, void **cookiep)
|
2001-01-06 18:04:55 +00:00
|
|
|
{
|
2002-08-31 18:34:30 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
2001-01-06 18:04:55 +00:00
|
|
|
struct pccard_ivar *ivar = PCCARD_IVAR(child);
|
|
|
|
struct pccard_function *func = ivar->fcn;
|
2002-02-10 03:34:44 +00:00
|
|
|
int err;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
|
|
|
if (func->intr_handler != NULL)
|
2002-08-12 22:34:12 +00:00
|
|
|
panic("Only one interrupt handler per function allowed");
|
2002-02-10 03:34:44 +00:00
|
|
|
err = bus_generic_setup_intr(dev, child, irq, flags, pccard_intr,
|
|
|
|
func, cookiep);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
2001-01-06 18:04:55 +00:00
|
|
|
func->intr_handler = intr;
|
|
|
|
func->intr_handler_arg = arg;
|
2001-08-27 00:09:42 +00:00
|
|
|
func->intr_handler_cookie = *cookiep;
|
2002-08-31 18:34:30 +00:00
|
|
|
if (pccard_mfc(sc)) {
|
|
|
|
pccard_ccr_write(func, PCCARD_CCR_OPTION,
|
|
|
|
pccard_ccr_read(func, PCCARD_CCR_OPTION) |
|
|
|
|
PCCARD_CCR_OPTION_IREQ_ENABLE);
|
|
|
|
}
|
2001-03-22 05:41:20 +00:00
|
|
|
return (0);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2001-01-07 20:40:23 +00:00
|
|
|
pccard_teardown_intr(device_t dev, device_t child, struct resource *r,
|
|
|
|
void *cookie)
|
2001-01-06 18:04:55 +00:00
|
|
|
{
|
2002-08-31 18:34:30 +00:00
|
|
|
struct pccard_softc *sc = PCCARD_SOFTC(dev);
|
2001-01-06 18:04:55 +00:00
|
|
|
struct pccard_ivar *ivar = PCCARD_IVAR(child);
|
|
|
|
struct pccard_function *func = ivar->fcn;
|
2001-08-27 00:09:42 +00:00
|
|
|
int ret;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2002-08-31 18:34:30 +00:00
|
|
|
if (pccard_mfc(sc)) {
|
|
|
|
pccard_ccr_write(func, PCCARD_CCR_OPTION,
|
|
|
|
pccard_ccr_read(func, PCCARD_CCR_OPTION) &
|
|
|
|
~PCCARD_CCR_OPTION_IREQ_ENABLE);
|
|
|
|
}
|
2002-02-10 03:34:44 +00:00
|
|
|
ret = bus_generic_teardown_intr(dev, child, r, cookie);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (ret == 0) {
|
|
|
|
func->intr_handler = NULL;
|
|
|
|
func->intr_handler_arg = NULL;
|
|
|
|
func->intr_handler_cookie = NULL;
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
|
|
|
|
return (ret);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
|
|
|
|
2003-11-02 20:18:19 +00:00
|
|
|
static int
|
|
|
|
pccard_activate_resource(device_t brdev, device_t child, int type, int rid,
|
|
|
|
struct resource *r)
|
|
|
|
{
|
|
|
|
struct pccard_ivar *ivar = PCCARD_IVAR(child);
|
|
|
|
struct pccard_function *pf = ivar->fcn;
|
|
|
|
|
|
|
|
switch(type) {
|
|
|
|
case SYS_RES_IOPORT:
|
|
|
|
/*
|
|
|
|
* We need to adjust IOBASE[01] and IOSIZE if we're an MFC
|
|
|
|
* card.
|
|
|
|
*/
|
|
|
|
if (pccard_mfc(pf->sc))
|
|
|
|
pccard_mfc_adjust_iobase(pf, rman_get_start(r), 0,
|
|
|
|
rman_get_size(r));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (bus_generic_activate_resource(brdev, child, type, rid, r));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pccard_deactivate_resource(device_t brdev, device_t child, int type,
|
|
|
|
int rid, struct resource *r)
|
|
|
|
{
|
|
|
|
/* XXX undo pccard_activate_resource? XXX */
|
|
|
|
return (bus_generic_deactivate_resource(brdev, child, type, rid, r));
|
|
|
|
}
|
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
static device_method_t pccard_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, pccard_probe),
|
2000-04-13 06:42:58 +00:00
|
|
|
DEVMETHOD(device_attach, pccard_attach),
|
2001-08-27 00:09:42 +00:00
|
|
|
DEVMETHOD(device_detach, pccard_detach),
|
1999-10-26 06:52:31 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
2001-12-15 05:58:28 +00:00
|
|
|
DEVMETHOD(device_suspend, pccard_suspend),
|
|
|
|
DEVMETHOD(device_resume, pccard_resume),
|
1999-10-26 06:52:31 +00:00
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, pccard_print_child),
|
2000-10-07 05:48:51 +00:00
|
|
|
DEVMETHOD(bus_driver_added, pccard_driver_added),
|
2000-10-19 22:36:41 +00:00
|
|
|
DEVMETHOD(bus_child_detached, pccard_child_detached),
|
2000-10-17 06:29:21 +00:00
|
|
|
DEVMETHOD(bus_alloc_resource, pccard_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, pccard_release_resource),
|
2003-11-02 20:18:19 +00:00
|
|
|
DEVMETHOD(bus_activate_resource, pccard_activate_resource),
|
|
|
|
DEVMETHOD(bus_deactivate_resource, pccard_deactivate_resource),
|
2001-01-06 18:04:55 +00:00
|
|
|
DEVMETHOD(bus_setup_intr, pccard_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, pccard_teardown_intr),
|
1999-10-26 06:52:31 +00:00
|
|
|
DEVMETHOD(bus_set_resource, pccard_set_resource),
|
|
|
|
DEVMETHOD(bus_get_resource, pccard_get_resource),
|
|
|
|
DEVMETHOD(bus_delete_resource, pccard_delete_resource),
|
2002-10-07 23:05:33 +00:00
|
|
|
DEVMETHOD(bus_probe_nomatch, pccard_probe_nomatch),
|
Implement indirection in the pccard probe/attach. This should make it
possible to have different probe/attach semantics between the two
systems and yet still use the same driver for both.
Compatibility methods for OLDCARD drivers. We use these routines to make
it possible to call the OLDCARD driver's probe routine in the context that
it expects. For OLDCARD these are implemented as pass throughs to the
device_{probe,attach} routines. For NEWCARD they are implemented such
such that probe becomes strictly a matching routine and attach does both
the old probe and old attach.
compat devices should use the following:
/* Device interface */
DEVMETHOD(device_probe), pccard_compat_probe),
DEVMETHOD(device_attach), pccard_compat_attach),
/* Card interface */
DEVMETHOD(card_compat_match, foo_match), /* newly written */
DEVMETHOD(card_compat_probe, foo_probe), /* old probe */
DEVMETHOD(card_compat_attach, foo_attach), /* old attach */
This will allow a single driver binary image to be used for both
OLDCARD and NEWCARD.
Drivers wishing to not retain OLDCARD compatibility needn't do this.
ep driver minorly updated.
sn driver updated more than minorly. Add module dependencies to allow
module to load. Also change name to if_sn. Add some debugging code.
attempt to fix the cannot allocate memory problem I'd been seeing.
Minor formatting nits.
2000-09-19 04:39:20 +00:00
|
|
|
DEVMETHOD(bus_read_ivar, pccard_read_ivar),
|
2002-10-07 23:05:33 +00:00
|
|
|
DEVMETHOD(bus_child_pnpinfo_str, pccard_child_pnpinfo_str),
|
|
|
|
DEVMETHOD(bus_child_location_str, pccard_child_location_str),
|
1999-10-26 06:52:31 +00:00
|
|
|
|
2000-04-13 06:42:58 +00:00
|
|
|
/* Card Interface */
|
|
|
|
DEVMETHOD(card_set_res_flags, pccard_set_res_flags),
|
|
|
|
DEVMETHOD(card_set_memory_offset, pccard_set_memory_offset),
|
|
|
|
DEVMETHOD(card_attach_card, pccard_attach_card),
|
|
|
|
DEVMETHOD(card_detach_card, pccard_detach_card),
|
2001-03-22 06:00:07 +00:00
|
|
|
DEVMETHOD(card_compat_do_probe, pccard_compat_do_probe),
|
|
|
|
DEVMETHOD(card_compat_do_attach, pccard_compat_do_attach),
|
2002-05-30 17:38:00 +00:00
|
|
|
DEVMETHOD(card_do_product_lookup, pccard_do_product_lookup),
|
2000-04-13 06:42:58 +00:00
|
|
|
|
1999-10-26 06:52:31 +00:00
|
|
|
{ 0, 0 }
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t pccard_driver = {
|
|
|
|
"pccard",
|
|
|
|
pccard_methods,
|
2000-08-19 19:22:04 +00:00
|
|
|
sizeof(struct pccard_softc)
|
1999-10-26 06:52:31 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
devclass_t pccard_devclass;
|
|
|
|
|
2002-08-15 08:02:23 +00:00
|
|
|
/* Maybe we need to have a slot device? */
|
1999-11-29 06:42:55 +00:00
|
|
|
DRIVER_MODULE(pccard, pcic, pccard_driver, pccard_devclass, 0, 0);
|
2002-08-15 08:02:23 +00:00
|
|
|
DRIVER_MODULE(pccard, cbb, pccard_driver, pccard_devclass, 0, 0);
|
2000-08-22 04:25:57 +00:00
|
|
|
MODULE_VERSION(pccard, 1);
|