2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2004-01-04 22:10:00 +00:00
|
|
|
* Copyright (c) 2002-2004 M. Warner Losh.
|
|
|
|
* Copyright (c) 2000-2001 Jonathan Chen.
|
2000-10-18 03:25:13 +00:00
|
|
|
* 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
|
2005-01-13 19:05:25 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
2000-10-18 03:25:13 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2005-01-13 19:05:25 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
2000-10-18 03:25:13 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2005-01-13 19:05:25 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
2000-10-18 03:25:13 +00:00
|
|
|
* 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.
|
2005-01-13 19:05:25 +00:00
|
|
|
*
|
2000-10-18 03:25:13 +00:00
|
|
|
*/
|
|
|
|
|
2005-01-11 05:34:14 +00:00
|
|
|
/*-
|
2002-04-13 04:07:07 +00:00
|
|
|
* Copyright (c) 1998, 1999 and 2000
|
|
|
|
* HAYAKAWA Koichi. 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 HAYAKAWA Koichi.
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/*
|
2002-10-11 04:30:59 +00:00
|
|
|
* Driver for PCI to CardBus Bridge chips
|
2004-08-12 06:50:29 +00:00
|
|
|
* and PCI to PCMCIA Bridge chips
|
|
|
|
* and ISA to PCMCIA host adapters
|
|
|
|
* and C Bus to PCMCIA host adapters
|
2000-10-18 03:25:13 +00:00
|
|
|
*
|
|
|
|
* References:
|
|
|
|
* TI Datasheets:
|
|
|
|
* http://www-s.ti.com/cgi-bin/sc/generic2.cgi?family=PCI+CARDBUS+CONTROLLERS
|
|
|
|
*
|
|
|
|
* Written by Jonathan Chen <jon@freebsd.org>
|
|
|
|
* The author would like to acknowledge:
|
|
|
|
* * HAYAKAWA Koichi: Author of the NetBSD code for the same thing
|
|
|
|
* * Warner Losh: Newbus/newcard guru and author of the pccard side of things
|
|
|
|
* * YAMAMOTO Shigeru: Author of another FreeBSD cardbus driver
|
|
|
|
* * David Cross: Author of the initial ugly hack for a specific cardbus card
|
|
|
|
*/
|
|
|
|
|
2003-11-12 05:21:06 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <sys/param.h>
|
2004-08-12 06:50:29 +00:00
|
|
|
#include <sys/bus.h>
|
2002-06-13 07:19:31 +00:00
|
|
|
#include <sys/condvar.h>
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <sys/errno.h>
|
|
|
|
#include <sys/kernel.h>
|
2004-05-30 17:57:46 +00:00
|
|
|
#include <sys/module.h>
|
2004-08-12 06:50:29 +00:00
|
|
|
#include <sys/kthread.h>
|
2007-05-31 19:29:20 +00:00
|
|
|
#include <sys/interrupt.h>
|
2001-03-29 10:23:45 +00:00
|
|
|
#include <sys/lock.h>
|
2001-03-30 16:05:50 +00:00
|
|
|
#include <sys/malloc.h>
|
2000-11-28 00:05:20 +00:00
|
|
|
#include <sys/mutex.h>
|
2004-08-12 06:50:29 +00:00
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/rman.h>
|
2001-11-26 07:17:09 +00:00
|
|
|
#include <sys/sysctl.h>
|
2004-08-12 06:50:29 +00:00
|
|
|
#include <sys/systm.h>
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
#include <machine/resource.h>
|
|
|
|
|
2003-08-22 06:42:59 +00:00
|
|
|
#include <dev/pci/pcireg.h>
|
|
|
|
#include <dev/pci/pcivar.h>
|
2014-02-12 04:30:37 +00:00
|
|
|
#include <dev/pci/pcib_private.h>
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
#include <dev/pccard/pccardreg.h>
|
|
|
|
#include <dev/pccard/pccardvar.h>
|
2002-01-29 06:50:18 +00:00
|
|
|
|
|
|
|
#include <dev/exca/excareg.h>
|
|
|
|
#include <dev/exca/excavar.h>
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
#include <dev/pccbb/pccbbreg.h>
|
|
|
|
#include <dev/pccbb/pccbbvar.h>
|
|
|
|
|
|
|
|
#include "power_if.h"
|
|
|
|
#include "card_if.h"
|
|
|
|
#include "pcib_if.h"
|
|
|
|
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
#define DPRINTF(x) do { if (cbb_debug) printf x; } while (0)
|
|
|
|
#define DEVPRINTF(x) do { if (cbb_debug) device_printf x; } while (0)
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
#define PCI_MASK_CONFIG(DEV,REG,MASK,SIZE) \
|
2000-10-18 03:25:13 +00:00
|
|
|
pci_write_config(DEV, REG, pci_read_config(DEV, REG, SIZE) MASK, SIZE)
|
|
|
|
#define PCI_MASK2_CONFIG(DEV,REG,MASK1,MASK2,SIZE) \
|
|
|
|
pci_write_config(DEV, REG, ( \
|
|
|
|
pci_read_config(DEV, REG, SIZE) MASK1) MASK2, SIZE)
|
|
|
|
|
2003-08-20 06:13:01 +00:00
|
|
|
#define CBB_CARD_PRESENT(s) ((s & CBB_STATE_CD) == 0)
|
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
#define CBB_START_MEM 0x88000000
|
|
|
|
#define CBB_START_32_IO 0x1000
|
|
|
|
#define CBB_START_16_IO 0x100
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
devclass_t cbb_devclass;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-11-26 07:17:09 +00:00
|
|
|
/* sysctl vars */
|
2011-11-07 15:43:11 +00:00
|
|
|
static SYSCTL_NODE(_hw, OID_AUTO, cbb, CTLFLAG_RD, 0, "CBB parameters");
|
2001-11-26 07:17:09 +00:00
|
|
|
|
|
|
|
/* There's no way to say TUNEABLE_LONG to get the right types */
|
2002-08-15 08:01:24 +00:00
|
|
|
u_long cbb_start_mem = CBB_START_MEM;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_ULONG(_hw_cbb, OID_AUTO, start_memory, CTLFLAG_RWTUN,
|
2002-08-15 08:01:24 +00:00
|
|
|
&cbb_start_mem, CBB_START_MEM,
|
2001-11-26 07:17:09 +00:00
|
|
|
"Starting address for memory allocations");
|
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
u_long cbb_start_16_io = CBB_START_16_IO;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_ULONG(_hw_cbb, OID_AUTO, start_16_io, CTLFLAG_RWTUN,
|
2002-08-15 08:01:24 +00:00
|
|
|
&cbb_start_16_io, CBB_START_16_IO,
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
"Starting ioport for 16-bit cards");
|
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
u_long cbb_start_32_io = CBB_START_32_IO;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_ULONG(_hw_cbb, OID_AUTO, start_32_io, CTLFLAG_RWTUN,
|
2002-08-15 08:01:24 +00:00
|
|
|
&cbb_start_32_io, CBB_START_32_IO,
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
"Starting ioport for 32-bit cards");
|
|
|
|
|
|
|
|
int cbb_debug = 0;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_hw_cbb, OID_AUTO, debug, CTLFLAG_RWTUN, &cbb_debug, 0,
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
"Verbose cardbus bridge debugging");
|
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
static void cbb_insert(struct cbb_softc *sc);
|
|
|
|
static void cbb_removal(struct cbb_softc *sc);
|
2005-07-14 20:46:59 +00:00
|
|
|
static uint32_t cbb_detect_voltage(device_t brdev);
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
static int cbb_cardbus_reset_power(device_t brdev, device_t child, int on);
|
2002-08-15 08:01:24 +00:00
|
|
|
static int cbb_cardbus_io_open(device_t brdev, int win, uint32_t start,
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t end);
|
2002-08-15 08:01:24 +00:00
|
|
|
static int cbb_cardbus_mem_open(device_t brdev, int win,
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t start, uint32_t end);
|
2002-08-15 08:01:24 +00:00
|
|
|
static void cbb_cardbus_auto_open(struct cbb_softc *sc, int type);
|
|
|
|
static int cbb_cardbus_activate_resource(device_t brdev, device_t child,
|
2001-08-27 00:09:42 +00:00
|
|
|
int type, int rid, struct resource *res);
|
2002-08-15 08:01:24 +00:00
|
|
|
static int cbb_cardbus_deactivate_resource(device_t brdev,
|
2001-08-27 00:09:42 +00:00
|
|
|
device_t child, int type, int rid, struct resource *res);
|
2002-08-15 08:01:24 +00:00
|
|
|
static struct resource *cbb_cardbus_alloc_resource(device_t brdev,
|
2001-08-26 23:55:34 +00:00
|
|
|
device_t child, int type, int *rid, u_long start,
|
2003-08-07 15:04:27 +00:00
|
|
|
u_long end, u_long count, u_int flags);
|
2002-08-15 08:01:24 +00:00
|
|
|
static int cbb_cardbus_release_resource(device_t brdev, device_t child,
|
2001-08-27 00:09:42 +00:00
|
|
|
int type, int rid, struct resource *res);
|
2004-08-12 06:50:29 +00:00
|
|
|
static int cbb_cardbus_power_enable_socket(device_t brdev,
|
|
|
|
device_t child);
|
2009-02-04 21:11:31 +00:00
|
|
|
static int cbb_cardbus_power_disable_socket(device_t brdev,
|
2004-08-12 06:50:29 +00:00
|
|
|
device_t child);
|
2007-05-31 19:29:20 +00:00
|
|
|
static int cbb_func_filt(void *arg);
|
2004-08-12 06:50:29 +00:00
|
|
|
static void cbb_func_intr(void *arg);
|
2002-01-14 02:59:06 +00:00
|
|
|
|
2002-01-29 06:50:18 +00:00
|
|
|
static void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_remove_res(struct cbb_softc *sc, struct resource *res)
|
2002-01-29 06:50:18 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_reslist *rle;
|
2002-01-29 06:50:18 +00:00
|
|
|
|
|
|
|
SLIST_FOREACH(rle, &sc->rl, link) {
|
|
|
|
if (rle->res == res) {
|
2002-08-15 08:01:24 +00:00
|
|
|
SLIST_REMOVE(&sc->rl, rle, cbb_reslist, link);
|
2002-01-29 06:50:18 +00:00
|
|
|
free(rle, M_DEVBUF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct resource *
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_find_res(struct cbb_softc *sc, int type, int rid)
|
2002-01-14 02:59:06 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_reslist *rle;
|
2002-01-29 06:50:18 +00:00
|
|
|
|
|
|
|
SLIST_FOREACH(rle, &sc->rl, link)
|
|
|
|
if (SYS_RES_MEMORY == rle->type && rid == rle->rid)
|
|
|
|
return (rle->res);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_insert_res(struct cbb_softc *sc, struct resource *res, int type,
|
2002-01-29 06:50:18 +00:00
|
|
|
int rid)
|
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_reslist *rle;
|
2002-01-29 06:50:18 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Need to record allocated resource so we can iterate through
|
|
|
|
* it later.
|
|
|
|
*/
|
2002-08-15 08:01:24 +00:00
|
|
|
rle = malloc(sizeof(struct cbb_reslist), M_DEVBUF, M_NOWAIT);
|
2003-11-12 05:21:06 +00:00
|
|
|
if (rle == NULL)
|
2002-08-15 08:01:24 +00:00
|
|
|
panic("cbb_cardbus_alloc_resource: can't record entry!");
|
2002-01-29 06:50:18 +00:00
|
|
|
rle->res = res;
|
|
|
|
rle->type = type;
|
|
|
|
rle->rid = rid;
|
|
|
|
SLIST_INSERT_HEAD(&sc->rl, rle, link);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_destroy_res(struct cbb_softc *sc)
|
2002-01-29 06:50:18 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_reslist *rle;
|
2002-01-29 06:50:18 +00:00
|
|
|
|
|
|
|
while ((rle = SLIST_FIRST(&sc->rl)) != NULL) {
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
device_printf(sc->dev, "Danger Will Robinson: Resource "
|
2002-01-29 06:50:18 +00:00
|
|
|
"left allocated! This is a bug... "
|
|
|
|
"(rid=%x, type=%d, addr=%lx)\n", rle->rid, rle->type,
|
|
|
|
rman_get_start(rle->res));
|
|
|
|
SLIST_REMOVE_HEAD(&sc->rl, link);
|
|
|
|
free(rle, M_DEVBUF);
|
|
|
|
}
|
2002-01-14 02:59:06 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2003-08-10 02:40:49 +00:00
|
|
|
/*
|
|
|
|
* Disable function interrupts by telling the bridge to generate IRQ1
|
|
|
|
* interrupts. These interrupts aren't really generated by the chip, since
|
|
|
|
* IRQ1 is reserved. Some chipsets assert INTA# inappropriately during
|
|
|
|
* initialization, so this helps to work around the problem.
|
2003-11-07 23:12:59 +00:00
|
|
|
*
|
|
|
|
* XXX We can't do this workaround for all chipsets, because this
|
|
|
|
* XXX causes interference with the keyboard because somechipsets will
|
|
|
|
* XXX actually signal IRQ1 over their serial interrupt connections to
|
|
|
|
* XXX the south bridge. Disable it it for now.
|
2003-08-10 02:40:49 +00:00
|
|
|
*/
|
2004-08-12 06:50:29 +00:00
|
|
|
void
|
2003-08-10 02:40:49 +00:00
|
|
|
cbb_disable_func_intr(struct cbb_softc *sc)
|
|
|
|
{
|
2003-11-08 03:28:43 +00:00
|
|
|
#if 0
|
2003-08-10 02:40:49 +00:00
|
|
|
uint8_t reg;
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
reg = (exca_getb(&sc->exca[0], EXCA_INTR) & ~EXCA_INTR_IRQ_MASK) |
|
2003-08-10 02:40:49 +00:00
|
|
|
EXCA_INTR_IRQ_RESERVED1;
|
2004-08-12 06:50:29 +00:00
|
|
|
exca_putb(&sc->exca[0], EXCA_INTR, reg);
|
2003-11-07 23:12:59 +00:00
|
|
|
#endif
|
2003-08-10 02:40:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable function interrupts. We turn on function interrupts when the card
|
|
|
|
* requests an interrupt. The PCMCIA standard says that we should set
|
|
|
|
* the lower 4 bits to 0 to route via PCI. Note: we call this for both
|
|
|
|
* CardBus and R2 (PC Card) cases, but it should have no effect on CardBus
|
|
|
|
* cards.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cbb_enable_func_intr(struct cbb_softc *sc)
|
|
|
|
{
|
|
|
|
uint8_t reg;
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
reg = (exca_getb(&sc->exca[0], EXCA_INTR) & ~EXCA_INTR_IRQ_MASK) |
|
2003-08-10 02:40:49 +00:00
|
|
|
EXCA_INTR_IRQ_NONE;
|
2004-08-12 06:50:29 +00:00
|
|
|
exca_putb(&sc->exca[0], EXCA_INTR, reg);
|
2003-08-10 02:40:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_detach(device_t brdev)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-11-28 00:05:20 +00:00
|
|
|
device_t *devlist;
|
2007-02-15 07:13:38 +00:00
|
|
|
int tmp, tries, error, numdevs;
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2006-02-07 18:38:51 +00:00
|
|
|
/*
|
|
|
|
* Before we delete the children (which we have to do because
|
|
|
|
* attach doesn't check for children busses correctly), we have
|
|
|
|
* to detach the children. Even if we didn't need to delete the
|
|
|
|
* children, we have to detach them.
|
|
|
|
*/
|
|
|
|
error = bus_generic_detach(brdev);
|
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2006-02-07 18:38:51 +00:00
|
|
|
/*
|
|
|
|
* Since the attach routine doesn't search for children before it
|
|
|
|
* attaches them to this device, we must delete them here in order
|
|
|
|
* for the kldload/unload case to work. If we failed to do that, then
|
|
|
|
* we'd get duplicate devices when cbb.ko was reloaded.
|
|
|
|
*/
|
2007-02-15 07:13:38 +00:00
|
|
|
tries = 10;
|
|
|
|
do {
|
|
|
|
error = device_get_children(brdev, &devlist, &numdevs);
|
|
|
|
if (error == 0)
|
|
|
|
break;
|
|
|
|
/*
|
|
|
|
* Try hard to cope with low memory.
|
|
|
|
*/
|
|
|
|
if (error == ENOMEM) {
|
2007-02-27 17:27:23 +00:00
|
|
|
pause("cbbnomem", 1);
|
2007-02-15 07:13:38 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
} while (tries-- > 0);
|
2006-02-07 18:38:51 +00:00
|
|
|
for (tmp = 0; tmp < numdevs; tmp++)
|
|
|
|
device_delete_child(brdev, devlist[tmp]);
|
2001-02-08 22:14:27 +00:00
|
|
|
free(devlist, M_TEMP);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2005-10-29 03:27:43 +00:00
|
|
|
/* Turn off the interrupts */
|
|
|
|
cbb_set(sc, CBB_SOCKET_MASK, 0);
|
|
|
|
|
|
|
|
/* reset 16-bit pcmcia bus */
|
|
|
|
exca_clrb(&sc->exca[0], EXCA_INTR, EXCA_INTR_RESET);
|
|
|
|
|
|
|
|
/* turn off power */
|
|
|
|
cbb_power(brdev, CARD_OFF);
|
|
|
|
|
|
|
|
/* Ack the interrupt */
|
|
|
|
cbb_set(sc, CBB_SOCKET_EVENT, 0xffffffff);
|
|
|
|
|
2005-10-08 06:51:47 +00:00
|
|
|
/*
|
2007-10-20 23:23:23 +00:00
|
|
|
* Wait for the thread to die. kproc_exit will do a wakeup
|
2015-08-21 21:47:29 +00:00
|
|
|
* on the event thread's struct proc * so that we know it is
|
2007-05-16 19:53:49 +00:00
|
|
|
* safe to proceed. IF the thread is running, set the please
|
2005-10-08 06:51:47 +00:00
|
|
|
* die flag and wait for it to comply. Since the wakeup on
|
2007-10-20 23:23:23 +00:00
|
|
|
* the event thread happens only in kproc_exit, we don't
|
2005-10-08 06:51:47 +00:00
|
|
|
* need to loop here.
|
|
|
|
*/
|
2005-10-29 03:27:43 +00:00
|
|
|
bus_teardown_intr(brdev, sc->irq_res, sc->intrhand);
|
2007-05-16 19:53:49 +00:00
|
|
|
mtx_lock(&sc->mtx);
|
2002-08-15 08:01:24 +00:00
|
|
|
sc->flags |= CBB_KTHREAD_DONE;
|
2006-05-24 17:22:53 +00:00
|
|
|
while (sc->flags & CBB_KTHREAD_RUNNING) {
|
|
|
|
DEVPRINTF((sc->dev, "Waiting for thread to die\n"));
|
2008-12-05 05:20:08 +00:00
|
|
|
wakeup(&sc->intrhand);
|
2002-10-08 03:53:52 +00:00
|
|
|
msleep(sc->event_thread, &sc->mtx, PWAIT, "cbbun", 0);
|
2001-11-26 05:42:45 +00:00
|
|
|
}
|
2002-10-08 03:53:52 +00:00
|
|
|
mtx_unlock(&sc->mtx);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
bus_release_resource(brdev, SYS_RES_IRQ, 0, sc->irq_res);
|
2004-05-21 06:10:13 +00:00
|
|
|
bus_release_resource(brdev, SYS_RES_MEMORY, CBBR_SOCKBASE,
|
|
|
|
sc->base_res);
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
mtx_destroy(&sc->mtx);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_setup_intr(device_t dev, device_t child, struct resource *irq,
|
2007-02-23 12:19:07 +00:00
|
|
|
int flags, driver_filter_t *filt, driver_intr_t *intr, void *arg,
|
|
|
|
void **cookiep)
|
2002-02-10 03:28:37 +00:00
|
|
|
{
|
2002-10-07 23:11:29 +00:00
|
|
|
struct cbb_intrhand *ih;
|
|
|
|
struct cbb_softc *sc = device_get_softc(dev);
|
2004-08-12 06:50:29 +00:00
|
|
|
int err;
|
2002-02-10 03:28:37 +00:00
|
|
|
|
2007-05-31 19:29:20 +00:00
|
|
|
if (filt == NULL && intr == NULL)
|
|
|
|
return (EINVAL);
|
2002-10-07 23:11:29 +00:00
|
|
|
ih = malloc(sizeof(struct cbb_intrhand), M_DEVBUF, M_NOWAIT);
|
|
|
|
if (ih == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
*cookiep = ih;
|
2007-05-31 19:29:20 +00:00
|
|
|
ih->filt = filt;
|
2002-10-07 23:11:29 +00:00
|
|
|
ih->intr = intr;
|
|
|
|
ih->arg = arg;
|
2004-08-12 06:50:29 +00:00
|
|
|
ih->sc = sc;
|
2002-02-10 03:28:37 +00:00
|
|
|
/*
|
|
|
|
* XXX need to turn on ISA interrupts, if we ever support them, but
|
|
|
|
* XXX for now that's all we need to do.
|
|
|
|
*/
|
2004-08-12 06:50:29 +00:00
|
|
|
err = BUS_SETUP_INTR(device_get_parent(dev), child, irq, flags,
|
2007-06-04 03:13:24 +00:00
|
|
|
filt ? cbb_func_filt : NULL, intr ? cbb_func_intr : NULL, ih,
|
|
|
|
&ih->cookie);
|
2004-08-12 06:50:29 +00:00
|
|
|
if (err != 0) {
|
|
|
|
free(ih, M_DEVBUF);
|
|
|
|
return (err);
|
|
|
|
}
|
|
|
|
cbb_enable_func_intr(sc);
|
2007-06-04 05:59:44 +00:00
|
|
|
sc->cardok = 1;
|
2004-08-12 06:50:29 +00:00
|
|
|
return 0;
|
2002-02-10 03:28:37 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_teardown_intr(device_t dev, device_t child, struct resource *irq,
|
2002-02-10 03:28:37 +00:00
|
|
|
void *cookie)
|
|
|
|
{
|
2002-10-07 23:11:29 +00:00
|
|
|
struct cbb_intrhand *ih;
|
2004-08-12 06:50:29 +00:00
|
|
|
int err;
|
2002-10-07 23:11:29 +00:00
|
|
|
|
2002-02-10 03:28:37 +00:00
|
|
|
/* XXX Need to do different things for ISA interrupts. */
|
2002-10-07 23:11:29 +00:00
|
|
|
ih = (struct cbb_intrhand *) cookie;
|
2004-08-12 06:50:29 +00:00
|
|
|
err = BUS_TEARDOWN_INTR(device_get_parent(dev), child, irq,
|
|
|
|
ih->cookie);
|
|
|
|
if (err != 0)
|
|
|
|
return (err);
|
2002-10-07 23:11:29 +00:00
|
|
|
free(ih, M_DEVBUF);
|
|
|
|
return (0);
|
2002-02-10 03:28:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_driver_added(device_t brdev, driver_t *driver)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-11-28 00:05:20 +00:00
|
|
|
device_t *devlist;
|
2003-04-08 06:52:16 +00:00
|
|
|
device_t dev;
|
2000-11-28 00:05:20 +00:00
|
|
|
int tmp;
|
|
|
|
int numdevs;
|
2003-04-08 06:52:16 +00:00
|
|
|
int wake = 0;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
DEVICE_IDENTIFY(driver, brdev);
|
2007-02-15 07:13:38 +00:00
|
|
|
tmp = device_get_children(brdev, &devlist, &numdevs);
|
|
|
|
if (tmp != 0) {
|
|
|
|
device_printf(brdev, "Cannot get children list, no reprobe\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-11-28 00:05:20 +00:00
|
|
|
for (tmp = 0; tmp < numdevs; tmp++) {
|
2003-04-08 06:52:16 +00:00
|
|
|
dev = devlist[tmp];
|
|
|
|
if (device_get_state(dev) == DS_NOTPRESENT &&
|
2007-02-15 07:22:27 +00:00
|
|
|
device_probe_and_attach(dev) == 0)
|
2003-04-08 06:52:16 +00:00
|
|
|
wake++;
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
2001-02-08 22:14:27 +00:00
|
|
|
free(devlist, M_TEMP);
|
2001-08-27 00:09:42 +00:00
|
|
|
|
2008-12-05 05:20:08 +00:00
|
|
|
if (wake > 0)
|
|
|
|
wakeup(&sc->intrhand);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_child_detached(device_t brdev, device_t child)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-11-26 05:42:45 +00:00
|
|
|
|
2007-02-15 07:22:27 +00:00
|
|
|
/* I'm not sure we even need this */
|
|
|
|
if (child != sc->cbdev && child != sc->exca[0].pccarddev)
|
2003-04-08 06:52:16 +00:00
|
|
|
device_printf(brdev, "Unknown child detached: %s\n",
|
|
|
|
device_get_nameunit(child));
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Kthreads */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_event_thread(void *arg)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = arg;
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t status;
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
int err;
|
2003-08-09 21:05:54 +00:00
|
|
|
int not_a_card = 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2012-01-27 21:49:02 +00:00
|
|
|
/*
|
|
|
|
* We need to act as a power sequencer on startup. Delay 2s/channel
|
|
|
|
* to ensure the other channels have had a chance to come up. We likely
|
|
|
|
* should add a lock that's shared on a per-slot basis so that only
|
|
|
|
* one power event can happen per slot at a time.
|
|
|
|
*/
|
|
|
|
pause("cbbstart", hz * device_get_unit(sc->dev) * 2);
|
2006-05-24 17:22:53 +00:00
|
|
|
mtx_lock(&sc->mtx);
|
2002-08-15 08:01:24 +00:00
|
|
|
sc->flags |= CBB_KTHREAD_RUNNING;
|
2003-06-12 03:37:28 +00:00
|
|
|
while ((sc->flags & CBB_KTHREAD_DONE) == 0) {
|
2007-05-16 19:53:49 +00:00
|
|
|
mtx_unlock(&sc->mtx);
|
2009-08-20 19:17:53 +00:00
|
|
|
/*
|
|
|
|
* We take out Giant here because we need it deep,
|
|
|
|
* down in the bowels of the vm system for mapping the
|
|
|
|
* memory we need to read the CIS. In addition, since
|
|
|
|
* we are adding/deleting devices from the dev tree,
|
|
|
|
* and that code isn't MP safe, we have to hold Giant.
|
|
|
|
*/
|
|
|
|
mtx_lock(&Giant);
|
2003-06-12 03:37:28 +00:00
|
|
|
status = cbb_get(sc, CBB_SOCKET_STATE);
|
2015-01-16 06:19:08 +00:00
|
|
|
DPRINTF(("Status is 0x%x\n", status));
|
2003-08-20 06:13:01 +00:00
|
|
|
if (!CBB_CARD_PRESENT(status)) {
|
2003-08-10 02:40:49 +00:00
|
|
|
not_a_card = 0; /* We know card type */
|
|
|
|
cbb_removal(sc);
|
|
|
|
} else if (status & CBB_STATE_NOT_A_CARD) {
|
2003-08-09 21:05:54 +00:00
|
|
|
/*
|
2007-03-04 19:33:12 +00:00
|
|
|
* Up to 10 times, try to rescan the card when we see
|
|
|
|
* NOT_A_CARD. 10 is somehwat arbitrary. When this
|
|
|
|
* pathology hits, there's a ~40% chance each try will
|
|
|
|
* fail. 10 tries takes about 5s and results in a
|
|
|
|
* 99.99% certainty of the results.
|
2003-08-09 21:05:54 +00:00
|
|
|
*/
|
2007-03-04 19:33:12 +00:00
|
|
|
if (not_a_card++ < 10) {
|
2003-08-09 21:05:54 +00:00
|
|
|
DEVPRINTF((sc->dev,
|
|
|
|
"Not a card bit set, rescanning\n"));
|
|
|
|
cbb_setb(sc, CBB_SOCKET_FORCE, CBB_FORCE_CV_TEST);
|
|
|
|
} else {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"Can't determine card type\n");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
not_a_card = 0; /* We know card type */
|
2003-08-10 02:40:49 +00:00
|
|
|
cbb_insert(sc);
|
2003-08-09 21:05:54 +00:00
|
|
|
}
|
2009-08-20 19:17:53 +00:00
|
|
|
mtx_unlock(&Giant);
|
2002-10-08 03:53:52 +00:00
|
|
|
|
2009-02-17 02:14:04 +00:00
|
|
|
/*
|
|
|
|
* First time through we need to tell mountroot that we're
|
|
|
|
* done.
|
|
|
|
*/
|
|
|
|
if (sc->sc_root_token) {
|
|
|
|
root_mount_rel(sc->sc_root_token);
|
|
|
|
sc->sc_root_token = NULL;
|
|
|
|
}
|
|
|
|
|
2002-02-20 16:20:27 +00:00
|
|
|
/*
|
2007-03-04 19:33:12 +00:00
|
|
|
* Wait until it has been 250ms since the last time we
|
2002-02-20 16:20:27 +00:00
|
|
|
* get an interrupt. We handle the rest of the interrupt
|
2003-06-12 03:37:28 +00:00
|
|
|
* at the top of the loop. Although we clear the bit in the
|
|
|
|
* ISR, we signal sc->cv from the detach path after we've
|
|
|
|
* set the CBB_KTHREAD_DONE bit, so we can't do a simple
|
2007-03-04 19:33:12 +00:00
|
|
|
* 250ms sleep here.
|
2003-08-18 03:15:44 +00:00
|
|
|
*
|
|
|
|
* In our ISR, we turn off the card changed interrupt. Turn
|
|
|
|
* them back on here before we wait for them to happen. We
|
|
|
|
* turn them on/off so that we can tolerate a large latency
|
|
|
|
* between the time we signal cbb_event_thread and it gets
|
|
|
|
* a chance to run.
|
2002-02-20 16:20:27 +00:00
|
|
|
*/
|
2002-06-13 07:19:31 +00:00
|
|
|
mtx_lock(&sc->mtx);
|
2008-12-05 05:20:08 +00:00
|
|
|
cbb_setb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_CD | CBB_SOCKET_MASK_CSTS);
|
2008-12-07 18:34:27 +00:00
|
|
|
msleep(&sc->intrhand, &sc->mtx, 0, "-", 0);
|
2002-10-07 23:11:29 +00:00
|
|
|
err = 0;
|
2003-06-12 03:37:28 +00:00
|
|
|
while (err != EWOULDBLOCK &&
|
2002-10-07 23:11:29 +00:00
|
|
|
(sc->flags & CBB_KTHREAD_DONE) == 0)
|
2008-12-07 18:34:27 +00:00
|
|
|
err = msleep(&sc->intrhand, &sc->mtx, 0, "-", hz / 5);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2006-05-24 17:22:53 +00:00
|
|
|
DEVPRINTF((sc->dev, "Thread terminating\n"));
|
2002-08-15 08:01:24 +00:00
|
|
|
sc->flags &= ~CBB_KTHREAD_RUNNING;
|
2006-05-24 17:22:53 +00:00
|
|
|
mtx_unlock(&sc->mtx);
|
2007-10-20 23:23:23 +00:00
|
|
|
kproc_exit(0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Insert/removal */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_insert(struct cbb_softc *sc)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t sockevent, sockstate;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-10-07 23:11:29 +00:00
|
|
|
sockevent = cbb_get(sc, CBB_SOCKET_EVENT);
|
|
|
|
sockstate = cbb_get(sc, CBB_SOCKET_STATE);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
DEVPRINTF((sc->dev, "card inserted: event=0x%08x, state=%08x\n",
|
2001-08-26 23:55:34 +00:00
|
|
|
sockevent, sockstate));
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2003-08-09 20:49:22 +00:00
|
|
|
if (sockstate & CBB_STATE_R2_CARD) {
|
2007-02-15 07:22:27 +00:00
|
|
|
if (device_is_attached(sc->exca[0].pccarddev)) {
|
2004-08-12 06:50:29 +00:00
|
|
|
sc->flags |= CBB_16BIT_CARD;
|
|
|
|
exca_insert(&sc->exca[0]);
|
2005-07-17 07:48:28 +00:00
|
|
|
} else {
|
|
|
|
device_printf(sc->dev,
|
|
|
|
"16-bit card inserted, but no pccard bus.\n");
|
2004-08-12 06:50:29 +00:00
|
|
|
}
|
2003-08-09 20:49:22 +00:00
|
|
|
} else if (sockstate & CBB_STATE_CB_CARD) {
|
2007-02-15 07:22:27 +00:00
|
|
|
if (device_is_attached(sc->cbdev)) {
|
2002-08-15 08:01:24 +00:00
|
|
|
sc->flags &= ~CBB_16BIT_CARD;
|
2005-01-11 05:38:01 +00:00
|
|
|
CARD_ATTACH_CARD(sc->cbdev);
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
} else {
|
|
|
|
device_printf(sc->dev,
|
2002-10-11 04:30:59 +00:00
|
|
|
"CardBus card inserted, but no cardbus bus.\n");
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
} else {
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
/*
|
|
|
|
* We should power the card down, and try again a couple of
|
|
|
|
* times if this happens. XXX
|
|
|
|
*/
|
2003-02-14 06:21:51 +00:00
|
|
|
device_printf(sc->dev, "Unsupported card type detected\n");
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_removal(struct cbb_softc *sc)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2007-06-04 05:59:44 +00:00
|
|
|
sc->cardok = 0;
|
2002-11-14 05:18:53 +00:00
|
|
|
if (sc->flags & CBB_16BIT_CARD) {
|
2004-08-12 06:50:29 +00:00
|
|
|
exca_removal(&sc->exca[0]);
|
2002-11-14 05:18:53 +00:00
|
|
|
} else {
|
2007-02-15 07:22:27 +00:00
|
|
|
if (device_is_attached(sc->cbdev))
|
2002-11-14 05:18:53 +00:00
|
|
|
CARD_DETACH_CARD(sc->cbdev);
|
|
|
|
}
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_destroy_res(sc);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Interrupt Handler */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2007-05-31 19:29:20 +00:00
|
|
|
static int
|
|
|
|
cbb_func_filt(void *arg)
|
2004-08-12 06:50:29 +00:00
|
|
|
{
|
|
|
|
struct cbb_intrhand *ih = (struct cbb_intrhand *)arg;
|
|
|
|
struct cbb_softc *sc = ih->sc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Make sure that the card is really there.
|
|
|
|
*/
|
2007-06-04 05:59:44 +00:00
|
|
|
if (!sc->cardok)
|
2007-05-31 19:29:20 +00:00
|
|
|
return (FILTER_STRAY);
|
2004-08-12 06:50:29 +00:00
|
|
|
if (!CBB_CARD_PRESENT(cbb_get(sc, CBB_SOCKET_STATE))) {
|
2007-06-04 05:59:44 +00:00
|
|
|
sc->cardok = 0;
|
2007-06-03 05:42:05 +00:00
|
|
|
return (FILTER_HANDLED);
|
2004-08-12 06:50:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2007-06-03 05:42:05 +00:00
|
|
|
* nb: don't have to check for giant or not, since that's done in the
|
|
|
|
* ISR dispatch and one can't hold Giant in a filter anyway...
|
2004-08-12 06:50:29 +00:00
|
|
|
*/
|
2007-06-04 03:13:24 +00:00
|
|
|
return ((*ih->filt)(ih->arg));
|
2007-05-31 19:29:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cbb_func_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct cbb_intrhand *ih = (struct cbb_intrhand *)arg;
|
2007-06-03 05:42:05 +00:00
|
|
|
struct cbb_softc *sc = ih->sc;
|
2007-05-31 19:29:20 +00:00
|
|
|
|
2007-06-03 05:42:05 +00:00
|
|
|
/*
|
|
|
|
* While this check may seem redundant, it helps close a race
|
|
|
|
* condition. If the card is ejected after the filter runs, but
|
|
|
|
* before this ISR can be scheduled, then we need to do the same
|
|
|
|
* filtering to prevent the card's ISR from being called. One could
|
|
|
|
* argue that the card's ISR should be able to cope, but experience
|
|
|
|
* has shown they can't always. This mitigates the problem by making
|
|
|
|
* the race quite a bit smaller. Properly written client ISRs should
|
|
|
|
* cope with the card going away in the middle of the ISR. We assume
|
|
|
|
* that drivers that are sophisticated enough to use filters don't
|
|
|
|
* need our protection. This also allows us to ensure they *ARE*
|
|
|
|
* called if their filter said they needed to be called.
|
|
|
|
*/
|
|
|
|
if (ih->filt == NULL) {
|
2007-06-04 05:59:44 +00:00
|
|
|
if (!sc->cardok)
|
2007-06-03 05:42:05 +00:00
|
|
|
return;
|
|
|
|
if (!CBB_CARD_PRESENT(cbb_get(sc, CBB_SOCKET_STATE))) {
|
2007-06-04 05:59:44 +00:00
|
|
|
sc->cardok = 0;
|
2007-06-03 05:42:05 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Call the registered ithread interrupt handler. This entire routine
|
|
|
|
* will be called with Giant if this isn't an MP safe driver, or not
|
|
|
|
* if it is. Either way, we don't have to worry.
|
|
|
|
*/
|
2007-05-31 19:29:20 +00:00
|
|
|
ih->intr(ih->arg);
|
2004-08-12 06:50:29 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
2000-11-28 00:05:20 +00:00
|
|
|
/* Generic Power functions */
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2005-07-14 20:46:59 +00:00
|
|
|
static uint32_t
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_detect_voltage(device_t brdev)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t psr;
|
2005-07-14 20:46:59 +00:00
|
|
|
uint32_t vol = CARD_UKN_CARD;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
psr = cbb_get(sc, CBB_SOCKET_STATE);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2006-03-24 07:52:00 +00:00
|
|
|
if (psr & CBB_STATE_5VCARD && psr & CBB_STATE_5VSOCK)
|
2000-10-18 03:25:13 +00:00
|
|
|
vol |= CARD_5V_CARD;
|
2006-03-24 07:52:00 +00:00
|
|
|
if (psr & CBB_STATE_3VCARD && psr & CBB_STATE_3VSOCK)
|
2000-10-18 03:25:13 +00:00
|
|
|
vol |= CARD_3V_CARD;
|
2006-03-24 07:52:00 +00:00
|
|
|
if (psr & CBB_STATE_XVCARD && psr & CBB_STATE_XVSOCK)
|
2000-10-18 03:25:13 +00:00
|
|
|
vol |= CARD_XV_CARD;
|
2006-03-24 07:52:00 +00:00
|
|
|
if (psr & CBB_STATE_YVCARD && psr & CBB_STATE_YVSOCK)
|
2000-10-18 03:25:13 +00:00
|
|
|
vol |= CARD_YV_CARD;
|
|
|
|
|
2001-11-26 05:42:45 +00:00
|
|
|
return (vol);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2003-06-06 06:00:49 +00:00
|
|
|
static uint8_t
|
|
|
|
cbb_o2micro_power_hack(struct cbb_softc *sc)
|
|
|
|
{
|
|
|
|
uint8_t reg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue #2: INT# not qualified with IRQ Routing Bit. An
|
2005-09-22 06:01:44 +00:00
|
|
|
* unexpected PCI INT# may be generated during PC Card
|
2003-06-06 06:00:49 +00:00
|
|
|
* initialization even with the IRQ Routing Bit Set with some
|
2005-09-22 06:01:44 +00:00
|
|
|
* PC Cards.
|
2003-06-06 06:00:49 +00:00
|
|
|
*
|
|
|
|
* This is a two part issue. The first part is that some of
|
|
|
|
* our older controllers have an issue in which the slot's PCI
|
|
|
|
* INT# is NOT qualified by the IRQ routing bit (PCI reg. 3Eh
|
|
|
|
* bit 7). Regardless of the IRQ routing bit, if NO ISA IRQ
|
|
|
|
* is selected (ExCA register 03h bits 3:0, of the slot, are
|
|
|
|
* cleared) we will generate INT# if IREQ# is asserted. The
|
2005-09-22 06:01:44 +00:00
|
|
|
* second part is because some PC Cards prematurally assert
|
2003-06-06 06:00:49 +00:00
|
|
|
* IREQ# before the ExCA registers are fully programmed. This
|
|
|
|
* in turn asserts INT# because ExCA register 03h bits 3:0
|
|
|
|
* (ISA IRQ Select) are not yet programmed.
|
|
|
|
*
|
|
|
|
* The fix for this issue, which will work for any controller
|
|
|
|
* (old or new), is to set ExCA register 03h bits 3:0 = 0001b
|
|
|
|
* (select IRQ1), of the slot, before turning on slot power.
|
|
|
|
* Selecting IRQ1 will result in INT# NOT being asserted
|
|
|
|
* (because IRQ1 is selected), and IRQ1 won't be asserted
|
|
|
|
* because our controllers don't generate IRQ1.
|
2005-07-17 07:48:28 +00:00
|
|
|
*
|
|
|
|
* Other, non O2Micro controllers will generate irq 1 in some
|
2005-07-17 19:40:05 +00:00
|
|
|
* situations, so we can't do this hack for everybody. Reports of
|
|
|
|
* keyboard controller's interrupts being suppressed occurred when
|
|
|
|
* we did this.
|
2003-06-06 06:00:49 +00:00
|
|
|
*/
|
2004-08-12 06:50:29 +00:00
|
|
|
reg = exca_getb(&sc->exca[0], EXCA_INTR);
|
|
|
|
exca_putb(&sc->exca[0], EXCA_INTR, (reg & 0xf0) | 1);
|
2003-06-06 06:00:49 +00:00
|
|
|
return (reg);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Restore the damage that cbb_o2micro_power_hack does to EXCA_INTR so
|
|
|
|
* we don't have an interrupt storm on power on. This has the efect of
|
|
|
|
* disabling card status change interrupts for the duration of poweron.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
cbb_o2micro_power_hack2(struct cbb_softc *sc, uint8_t reg)
|
|
|
|
{
|
2004-08-12 06:50:29 +00:00
|
|
|
exca_putb(&sc->exca[0], EXCA_INTR, reg);
|
2003-06-06 06:00:49 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_power(device_t brdev, int volts)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2006-08-12 09:06:55 +00:00
|
|
|
uint32_t status, sock_ctrl, reg_ctrl, mask;
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2005-07-17 07:48:28 +00:00
|
|
|
int cnt, sane;
|
2003-06-06 06:00:49 +00:00
|
|
|
int retval = 0;
|
2005-07-14 20:46:59 +00:00
|
|
|
int on = 0;
|
2003-06-06 06:00:49 +00:00
|
|
|
uint8_t reg = 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
sock_ctrl = cbb_get(sc, CBB_SOCKET_CONTROL);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2003-06-07 20:18:45 +00:00
|
|
|
sock_ctrl &= ~CBB_SOCKET_CTRL_VCCMASK;
|
2000-10-18 03:25:13 +00:00
|
|
|
switch (volts & CARD_VCCMASK) {
|
2003-06-07 20:18:45 +00:00
|
|
|
case 5:
|
|
|
|
sock_ctrl |= CBB_SOCKET_CTRL_VCC_5V;
|
2005-07-14 20:46:59 +00:00
|
|
|
on++;
|
2000-10-18 03:25:13 +00:00
|
|
|
break;
|
2003-06-07 20:18:45 +00:00
|
|
|
case 3:
|
|
|
|
sock_ctrl |= CBB_SOCKET_CTRL_VCC_3V;
|
2005-07-14 20:46:59 +00:00
|
|
|
on++;
|
2000-10-18 03:25:13 +00:00
|
|
|
break;
|
2003-06-07 20:18:45 +00:00
|
|
|
case XV:
|
|
|
|
sock_ctrl |= CBB_SOCKET_CTRL_VCC_XV;
|
2005-07-14 20:46:59 +00:00
|
|
|
on++;
|
2000-10-18 03:25:13 +00:00
|
|
|
break;
|
2003-06-07 20:18:45 +00:00
|
|
|
case YV:
|
|
|
|
sock_ctrl |= CBB_SOCKET_CTRL_VCC_YV;
|
2005-07-14 20:46:59 +00:00
|
|
|
on++;
|
2003-06-07 20:18:45 +00:00
|
|
|
break;
|
|
|
|
case 0:
|
2000-10-18 03:25:13 +00:00
|
|
|
break;
|
|
|
|
default:
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0); /* power NEVER changed */
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2003-06-07 20:18:45 +00:00
|
|
|
/* VPP == VCC */
|
|
|
|
sock_ctrl &= ~CBB_SOCKET_CTRL_VPPMASK;
|
|
|
|
sock_ctrl |= ((sock_ctrl >> 4) & 0x07);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
if (cbb_get(sc, CBB_SOCKET_CONTROL) == sock_ctrl)
|
2001-11-26 05:42:45 +00:00
|
|
|
return (1); /* no change necessary */
|
2003-06-07 20:18:45 +00:00
|
|
|
DEVPRINTF((sc->dev, "cbb_power: %dV\n", volts));
|
2003-06-06 06:00:49 +00:00
|
|
|
if (volts != 0 && sc->chipset == CB_O2MICRO)
|
|
|
|
reg = cbb_o2micro_power_hack(sc);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2005-07-17 07:48:28 +00:00
|
|
|
/*
|
2008-12-07 22:49:47 +00:00
|
|
|
* We have to mask the card change detect interrupt while we're
|
|
|
|
* messing with the power. It is allowed to bounce while we're
|
|
|
|
* messing with power as things settle down. In addition, we mask off
|
|
|
|
* the card's function interrupt by routing it via the ISA bus. This
|
|
|
|
* bit generally only affects 16-bit cards. Some bridges allow one to
|
|
|
|
* set another bit to have it also affect 32-bit cards. Since 32-bit
|
|
|
|
* cards are required to be better behaved, we don't bother to get
|
|
|
|
* into those bridge specific features.
|
|
|
|
*
|
|
|
|
* XXX I wonder if we need to enable the READY bit interrupt in the
|
|
|
|
* EXCA CSC register for 16-bit cards, and disable the CD bit?
|
2005-07-17 07:48:28 +00:00
|
|
|
*/
|
|
|
|
mask = cbb_get(sc, CBB_SOCKET_MASK);
|
|
|
|
mask |= CBB_SOCKET_MASK_POWER;
|
|
|
|
mask &= ~CBB_SOCKET_MASK_CD;
|
|
|
|
cbb_set(sc, CBB_SOCKET_MASK, mask);
|
2005-07-17 19:40:05 +00:00
|
|
|
PCI_MASK_CONFIG(brdev, CBBR_BRIDGECTRL,
|
|
|
|
|CBBM_BRIDGECTRL_INTR_IREQ_ISA_EN, 2);
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_set(sc, CBB_SOCKET_CONTROL, sock_ctrl);
|
2005-07-14 20:46:59 +00:00
|
|
|
if (on) {
|
|
|
|
mtx_lock(&sc->mtx);
|
|
|
|
cnt = sc->powerintr;
|
2006-08-12 09:06:55 +00:00
|
|
|
/*
|
2008-12-07 22:49:47 +00:00
|
|
|
* We have a shortish timeout of 500ms here. Some bridges do
|
2015-01-16 06:19:08 +00:00
|
|
|
* not generate a POWER_CYCLE event for 16-bit cards. In
|
|
|
|
* those cases, we have to cope the best we can, and having
|
|
|
|
* only a short delay is better than the alternatives. Others
|
|
|
|
* raise the power cycle a smidge before it is really ready.
|
|
|
|
* We deal with those below.
|
2006-08-12 09:06:55 +00:00
|
|
|
*/
|
|
|
|
sane = 10;
|
2005-07-17 07:48:28 +00:00
|
|
|
while (!(cbb_get(sc, CBB_SOCKET_STATE) & CBB_STATE_POWER_CYCLE) &&
|
|
|
|
cnt == sc->powerintr && sane-- > 0)
|
2008-12-07 18:34:27 +00:00
|
|
|
msleep(&sc->powerintr, &sc->mtx, 0, "-", hz / 20);
|
2005-07-14 20:46:59 +00:00
|
|
|
mtx_unlock(&sc->mtx);
|
2011-06-18 02:25:08 +00:00
|
|
|
|
|
|
|
/*
|
2011-06-18 03:16:51 +00:00
|
|
|
* Relax for 100ms. Some bridges appear to assert this signal
|
2015-01-16 06:19:08 +00:00
|
|
|
* right away, but before the card has stabilized. Other
|
|
|
|
* cards need need more time to cope up reliabily.
|
|
|
|
* Experiments with troublesome setups show this to be a
|
|
|
|
* "cheap" way to enhance reliabilty. We need not do this for
|
|
|
|
* "off" since we don't touch the card after we turn it off.
|
2011-06-18 02:25:08 +00:00
|
|
|
*/
|
2011-06-18 03:16:51 +00:00
|
|
|
pause("cbbPwr", min(hz / 10, 1));
|
2011-06-18 02:25:08 +00:00
|
|
|
|
2006-08-12 09:06:55 +00:00
|
|
|
/*
|
2015-01-16 06:19:08 +00:00
|
|
|
* The TOPIC95B requires a little bit extra time to get its
|
|
|
|
* act together, so delay for an additional 100ms. Also as
|
|
|
|
* documented below, it doesn't seem to set the POWER_CYCLE
|
|
|
|
* bit, so don't whine if it never came on.
|
2006-08-12 09:06:55 +00:00
|
|
|
*/
|
2011-06-18 02:25:08 +00:00
|
|
|
if (sc->chipset == CB_TOPIC95)
|
2007-02-27 17:27:23 +00:00
|
|
|
pause("cbb95B", hz / 10);
|
2011-06-18 02:25:08 +00:00
|
|
|
else if (sane <= 0)
|
2005-07-17 07:48:28 +00:00
|
|
|
device_printf(sc->dev, "power timeout, doom?\n");
|
2005-07-14 20:46:59 +00:00
|
|
|
}
|
2005-07-17 07:48:28 +00:00
|
|
|
|
|
|
|
/*
|
2005-07-17 19:40:05 +00:00
|
|
|
* After the power is good, we can turn off the power interrupt.
|
2015-01-16 06:19:08 +00:00
|
|
|
* However, the PC Card standard says that we must delay turning the
|
|
|
|
* CD bit back on for a bit to allow for bouncyness on power down
|
|
|
|
* (recall that we don't wait above for a power down, since we don't
|
|
|
|
* get an interrupt for that). We're called either from the suspend
|
|
|
|
* code in which case we don't want to turn card change on again, or
|
|
|
|
* we're called from the card insertion code, in which case the cbb
|
|
|
|
* thread will turn it on for us before it waits to be woken by a
|
|
|
|
* change event.
|
2006-08-12 09:06:55 +00:00
|
|
|
*
|
2015-01-16 06:19:08 +00:00
|
|
|
* NB: Topic95B doesn't set the power cycle bit. we assume that
|
|
|
|
* both it and the TOPIC95 behave the same.
|
2005-07-17 07:48:28 +00:00
|
|
|
*/
|
2005-07-14 20:46:59 +00:00
|
|
|
cbb_clrb(sc, CBB_SOCKET_MASK, CBB_SOCKET_MASK_POWER);
|
2002-08-15 08:01:24 +00:00
|
|
|
status = cbb_get(sc, CBB_SOCKET_STATE);
|
2006-08-12 09:06:55 +00:00
|
|
|
if (on && sc->chipset != CB_TOPIC95) {
|
2005-07-14 20:46:59 +00:00
|
|
|
if ((status & CBB_STATE_POWER_CYCLE) == 0)
|
|
|
|
device_printf(sc->dev, "Power not on?\n");
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2003-08-09 20:49:22 +00:00
|
|
|
if (status & CBB_STATE_BAD_VCC_REQ) {
|
2015-01-16 06:19:08 +00:00
|
|
|
device_printf(sc->dev, "Bad Vcc requested\n");
|
2008-12-05 04:43:25 +00:00
|
|
|
/*
|
|
|
|
* Turn off the power, and try again. Retrigger other
|
|
|
|
* active interrupts via force register. From NetBSD
|
|
|
|
* PR 36652, coded by me to description there.
|
|
|
|
*/
|
|
|
|
sock_ctrl &= ~CBB_SOCKET_CTRL_VCCMASK;
|
|
|
|
sock_ctrl &= ~CBB_SOCKET_CTRL_VPPMASK;
|
|
|
|
cbb_set(sc, CBB_SOCKET_CONTROL, sock_ctrl);
|
|
|
|
status &= ~CBB_STATE_BAD_VCC_REQ;
|
|
|
|
status &= ~CBB_STATE_DATA_LOST;
|
|
|
|
status |= CBB_FORCE_CV_TEST;
|
|
|
|
cbb_set(sc, CBB_SOCKET_FORCE, status);
|
2003-06-06 06:00:49 +00:00
|
|
|
goto done;
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2006-08-12 09:06:55 +00:00
|
|
|
if (sc->chipset == CB_TOPIC97) {
|
|
|
|
reg_ctrl = pci_read_config(sc->dev, TOPIC_REG_CTRL, 4);
|
|
|
|
reg_ctrl &= ~TOPIC97_REG_CTRL_TESTMODE;
|
|
|
|
if (on)
|
|
|
|
reg_ctrl |= TOPIC97_REG_CTRL_CLKRUN_ENA;
|
|
|
|
else
|
|
|
|
reg_ctrl &= ~TOPIC97_REG_CTRL_CLKRUN_ENA;
|
|
|
|
pci_write_config(sc->dev, TOPIC_REG_CTRL, reg_ctrl, 4);
|
|
|
|
}
|
2005-07-17 19:40:05 +00:00
|
|
|
PCI_MASK_CONFIG(brdev, CBBR_BRIDGECTRL,
|
|
|
|
& ~CBBM_BRIDGECTRL_INTR_IREQ_ISA_EN, 2);
|
2003-06-06 06:00:49 +00:00
|
|
|
retval = 1;
|
|
|
|
done:;
|
|
|
|
if (volts != 0 && sc->chipset == CB_O2MICRO)
|
|
|
|
cbb_o2micro_power_hack2(sc, reg);
|
|
|
|
return (retval);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2005-07-14 20:46:59 +00:00
|
|
|
static int
|
|
|
|
cbb_current_voltage(device_t brdev)
|
|
|
|
{
|
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
|
|
|
uint32_t ctrl;
|
|
|
|
|
|
|
|
ctrl = cbb_get(sc, CBB_SOCKET_CONTROL);
|
|
|
|
switch (ctrl & CBB_SOCKET_CTRL_VCCMASK) {
|
|
|
|
case CBB_SOCKET_CTRL_VCC_5V:
|
|
|
|
return CARD_5V_CARD;
|
|
|
|
case CBB_SOCKET_CTRL_VCC_3V:
|
|
|
|
return CARD_3V_CARD;
|
|
|
|
case CBB_SOCKET_CTRL_VCC_XV:
|
|
|
|
return CARD_XV_CARD;
|
|
|
|
case CBB_SOCKET_CTRL_VCC_YV:
|
|
|
|
return CARD_YV_CARD;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
/*
|
|
|
|
* detect the voltage for the card, and set it. Since the power
|
|
|
|
* used is the square of the voltage, lower voltages is a big win
|
|
|
|
* and what Windows does (and what Microsoft prefers). The MS paper
|
2005-07-14 20:46:59 +00:00
|
|
|
* also talks about preferring the CIS entry as well, but that has
|
|
|
|
* to be done elsewhere. We also optimize power sequencing here
|
|
|
|
* and don't change things if we're already powered up at a supported
|
|
|
|
* voltage.
|
|
|
|
*
|
|
|
|
* In addition, we power up with OE disabled. We'll set it later
|
|
|
|
* in the power up sequence.
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
*/
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_do_power(device_t brdev)
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
{
|
2004-04-06 22:41:14 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2005-07-14 20:46:59 +00:00
|
|
|
uint32_t voltage, curpwr;
|
|
|
|
uint32_t status;
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
|
2005-07-14 20:46:59 +00:00
|
|
|
/* Don't enable OE (output enable) until power stable */
|
2004-08-12 06:50:29 +00:00
|
|
|
exca_clrb(&sc->exca[0], EXCA_PWRCTL, EXCA_PWRCTL_OE);
|
2004-04-06 20:13:29 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
voltage = cbb_detect_voltage(brdev);
|
2005-07-14 20:46:59 +00:00
|
|
|
curpwr = cbb_current_voltage(brdev);
|
|
|
|
status = cbb_get(sc, CBB_SOCKET_STATE);
|
|
|
|
if ((status & CBB_STATE_POWER_CYCLE) && (voltage & curpwr))
|
|
|
|
return 0;
|
|
|
|
/* Prefer lowest voltage supported */
|
2003-06-07 20:18:45 +00:00
|
|
|
cbb_power(brdev, CARD_OFF);
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
if (voltage & CARD_YV_CARD)
|
2003-06-07 20:18:45 +00:00
|
|
|
cbb_power(brdev, CARD_VCC(YV));
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
else if (voltage & CARD_XV_CARD)
|
2003-06-07 20:18:45 +00:00
|
|
|
cbb_power(brdev, CARD_VCC(XV));
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
else if (voltage & CARD_3V_CARD)
|
2003-06-07 20:18:45 +00:00
|
|
|
cbb_power(brdev, CARD_VCC(3));
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
else if (voltage & CARD_5V_CARD)
|
2003-06-07 20:18:45 +00:00
|
|
|
cbb_power(brdev, CARD_VCC(5));
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
else {
|
|
|
|
device_printf(brdev, "Unknown card voltage\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
2002-10-11 04:30:59 +00:00
|
|
|
/* CardBus power functions */
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
static int
|
2009-03-12 06:25:30 +00:00
|
|
|
cbb_cardbus_reset_power(device_t brdev, device_t child, int on)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
uint32_t b, h;
|
|
|
|
int delay, count, zero_seen, func;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2005-07-15 03:25:22 +00:00
|
|
|
/*
|
2008-08-09 07:41:18 +00:00
|
|
|
* Asserting reset for 20ms is necessary for most bridges. For some
|
2008-12-05 04:46:26 +00:00
|
|
|
* reason, the Ricoh RF5C47x bridges need it asserted for 400ms. The
|
|
|
|
* root cause of this is unknown, and NetBSD does the same thing.
|
2005-07-15 03:25:22 +00:00
|
|
|
*/
|
2008-08-09 04:08:36 +00:00
|
|
|
delay = sc->chipset == CB_RF5C47X ? 400 : 20;
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
PCI_MASK_CONFIG(brdev, CBBR_BRIDGECTRL, |CBBM_BRIDGECTRL_RESET, 2);
|
2007-02-27 17:27:23 +00:00
|
|
|
pause("cbbP3", hz * delay / 1000);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2008-08-09 07:41:18 +00:00
|
|
|
/*
|
2008-12-05 04:46:26 +00:00
|
|
|
* If a card exists and we're turning it on, take it out of reset.
|
|
|
|
* After clearing reset, wait up to 1.1s for the first configuration
|
|
|
|
* register (vendor/product) configuration register of device 0.0 to
|
|
|
|
* become != 0xffffffff. The PCMCIA PC Card Host System Specification
|
|
|
|
* says that when powering up the card, the PCI Spec v2.1 must be
|
|
|
|
* followed. In PCI spec v2.2 Table 4-6, Trhfa (Reset High to first
|
|
|
|
* Config Access) is at most 2^25 clocks, or just over 1s. Section
|
|
|
|
* 2.2.1 states any card not ready to participate in bus transactions
|
|
|
|
* must tristate its outputs. Therefore, any access to its
|
|
|
|
* configuration registers must be ignored. In that state, the config
|
|
|
|
* reg will read 0xffffffff. Section 6.2.1 states a vendor id of
|
|
|
|
* 0xffff is invalid, so this can never match a real card. Print a
|
|
|
|
* warning if it never returns a real id. The PCMCIA PC Card
|
|
|
|
* Electrical Spec Section 5.2.7.1 implies only device 0 is present on
|
|
|
|
* a cardbus bus, so that's the only register we check here.
|
2008-08-09 07:41:18 +00:00
|
|
|
*/
|
2008-08-09 04:08:36 +00:00
|
|
|
if (on && CBB_CARD_PRESENT(cbb_get(sc, CBB_SOCKET_STATE))) {
|
2008-08-09 07:41:18 +00:00
|
|
|
PCI_MASK_CONFIG(brdev, CBBR_BRIDGECTRL,
|
|
|
|
&~CBBM_BRIDGECTRL_RESET, 2);
|
2008-08-10 09:55:14 +00:00
|
|
|
b = pcib_get_bus(child);
|
2008-08-09 07:41:18 +00:00
|
|
|
count = 1100 / 20;
|
2008-08-09 04:08:36 +00:00
|
|
|
do {
|
|
|
|
pause("cbbP4", hz * 2 / 100);
|
2008-08-09 15:55:10 +00:00
|
|
|
} while (PCIB_READ_CONFIG(brdev, b, 0, 0, PCIR_DEVVENDOR, 4) ==
|
|
|
|
0xfffffffful && --count >= 0);
|
2008-08-09 04:08:36 +00:00
|
|
|
if (count < 0)
|
2008-08-09 07:41:18 +00:00
|
|
|
device_printf(brdev, "Warning: Bus reset timeout\n");
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Some cards (so far just an atheros card I have) seem to
|
|
|
|
* come out of reset in a funky state. They report they are
|
|
|
|
* multi-function cards, but have nonsense for some of the
|
|
|
|
* higher functions. So if the card claims to be MFDEV, and
|
|
|
|
* any of the higher functions' ID is 0, then we've hit the
|
|
|
|
* bug and we'll try again.
|
|
|
|
*/
|
|
|
|
h = PCIB_READ_CONFIG(brdev, b, 0, 0, PCIR_HDRTYPE, 1);
|
|
|
|
if ((h & PCIM_MFDEV) == 0)
|
|
|
|
return 0;
|
|
|
|
zero_seen = 0;
|
|
|
|
for (func = 1; func < 8; func++) {
|
|
|
|
h = PCIB_READ_CONFIG(brdev, b, 0, func,
|
|
|
|
PCIR_DEVVENDOR, 4);
|
|
|
|
if (h == 0)
|
|
|
|
zero_seen++;
|
|
|
|
}
|
|
|
|
if (!zero_seen)
|
|
|
|
return 0;
|
|
|
|
return (EINVAL);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cbb_cardbus_power_disable_socket(device_t brdev, device_t child)
|
|
|
|
{
|
|
|
|
cbb_power(brdev, CARD_OFF);
|
|
|
|
cbb_cardbus_reset_power(brdev, child, 0);
|
|
|
|
return (0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_power_enable_socket(device_t brdev, device_t child)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
int err, count;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2003-08-20 23:43:20 +00:00
|
|
|
if (!CBB_CARD_PRESENT(cbb_get(sc, CBB_SOCKET_STATE)))
|
2001-11-26 05:42:45 +00:00
|
|
|
return (ENODEV);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
On my Lenovo T400, a Atheros 2413 has a problem powering up
sometimes. It will power up wrong and identify itself badly:
cardbus0: <network, ethernet> at device 0.0 (no driver attached)
cardbus0: <simple comms, UART> at device 0.1 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.2 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.3 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.4 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.5 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.6 (no driver attached)
cardbus0: <old, non-VGA display device> at device 0.7 (no driver attached)
All the higher numbered functions (.2 and above) have a config space
of all 0's. This smells a bit like a special debug mode, but the
current atheros driver doesn't cope. It is unclear if this card is
just a flake, or if we're doing something wrong in the power-up
sequence.
Put a work around into the code that tests for this rather unusual
condition. If we power a CardBus device up, and the device says it is
multi-function, and any of the functions have a 0 device ID, try the
power-up sequence again.
2015-02-18 05:53:04 +00:00
|
|
|
count = 10;
|
|
|
|
do {
|
|
|
|
err = cbb_do_power(brdev);
|
|
|
|
if (err)
|
|
|
|
return (err);
|
|
|
|
err = cbb_cardbus_reset_power(brdev, child, 1);
|
|
|
|
if (err) {
|
|
|
|
device_printf(brdev, "Reset failed, trying again.\n");
|
|
|
|
cbb_cardbus_power_disable_socket(brdev, child);
|
|
|
|
pause("cbbErr1", hz / 10); /* wait 100ms */
|
|
|
|
}
|
|
|
|
} while (err != 0 && count-- > 0);
|
2009-02-04 21:11:31 +00:00
|
|
|
return (0);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
/************************************************************************/
|
2002-10-11 04:30:59 +00:00
|
|
|
/* CardBus Resource */
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2014-01-27 19:49:52 +00:00
|
|
|
static void
|
|
|
|
cbb_activate_window(device_t brdev, int type)
|
|
|
|
{
|
|
|
|
|
|
|
|
PCI_ENABLE_IO(device_get_parent(brdev), brdev, type);
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_io_open(device_t brdev, int win, uint32_t start, uint32_t end)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
|
|
|
int basereg;
|
|
|
|
int limitreg;
|
|
|
|
|
|
|
|
if ((win < 0) || (win > 1)) {
|
2001-08-26 23:55:34 +00:00
|
|
|
DEVPRINTF((brdev,
|
2002-08-15 08:01:24 +00:00
|
|
|
"cbb_cardbus_io_open: window out of range %d\n", win));
|
2001-11-26 05:42:45 +00:00
|
|
|
return (EINVAL);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
basereg = win * 8 + CBBR_IOBASE0;
|
|
|
|
limitreg = win * 8 + CBBR_IOLIMIT0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
pci_write_config(brdev, basereg, start, 4);
|
|
|
|
pci_write_config(brdev, limitreg, end, 4);
|
2014-01-27 19:49:52 +00:00
|
|
|
cbb_activate_window(brdev, SYS_RES_IOPORT);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_mem_open(device_t brdev, int win, uint32_t start, uint32_t end)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
|
|
|
int basereg;
|
|
|
|
int limitreg;
|
|
|
|
|
|
|
|
if ((win < 0) || (win > 1)) {
|
2001-08-26 23:55:34 +00:00
|
|
|
DEVPRINTF((brdev,
|
2002-08-15 08:01:24 +00:00
|
|
|
"cbb_cardbus_mem_open: window out of range %d\n", win));
|
2001-11-26 05:42:45 +00:00
|
|
|
return (EINVAL);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2008-12-05 04:48:04 +00:00
|
|
|
basereg = win * 8 + CBBR_MEMBASE0;
|
|
|
|
limitreg = win * 8 + CBBR_MEMLIMIT0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
pci_write_config(brdev, basereg, start, 4);
|
|
|
|
pci_write_config(brdev, limitreg, end, 4);
|
2014-01-27 19:49:52 +00:00
|
|
|
cbb_activate_window(brdev, SYS_RES_MEMORY);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2005-12-29 23:38:45 +00:00
|
|
|
#define START_NONE 0xffffffff
|
|
|
|
#define END_NONE 0
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static void
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_auto_open(struct cbb_softc *sc, int type)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t starts[2];
|
|
|
|
uint32_t ends[2];
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_reslist *rle;
|
2005-12-29 23:38:45 +00:00
|
|
|
int align, i;
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t reg;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2005-12-29 23:38:45 +00:00
|
|
|
starts[0] = starts[1] = START_NONE;
|
|
|
|
ends[0] = ends[1] = END_NONE;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
if (type == SYS_RES_MEMORY)
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
align = CBB_MEMALIGN;
|
2001-08-27 00:09:42 +00:00
|
|
|
else if (type == SYS_RES_IOPORT)
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
align = CBB_IOALIGN;
|
2001-08-27 00:09:42 +00:00
|
|
|
else
|
|
|
|
align = 1;
|
|
|
|
|
|
|
|
SLIST_FOREACH(rle, &sc->rl, link) {
|
2000-10-18 03:25:13 +00:00
|
|
|
if (rle->type != type)
|
2005-12-29 23:38:45 +00:00
|
|
|
continue;
|
|
|
|
if (rle->res == NULL)
|
|
|
|
continue;
|
|
|
|
if (!(rman_get_flags(rle->res) & RF_ACTIVE))
|
|
|
|
continue;
|
|
|
|
if (rman_get_flags(rle->res) & RF_PREFETCHABLE)
|
|
|
|
i = 1;
|
|
|
|
else
|
|
|
|
i = 0;
|
|
|
|
if (rman_get_start(rle->res) < starts[i])
|
|
|
|
starts[i] = rman_get_start(rle->res);
|
|
|
|
if (rman_get_end(rle->res) > ends[i])
|
|
|
|
ends[i] = rman_get_end(rle->res);
|
|
|
|
}
|
|
|
|
for (i = 0; i < 2; i++) {
|
|
|
|
if (starts[i] == START_NONE)
|
|
|
|
continue;
|
|
|
|
starts[i] &= ~(align - 1);
|
|
|
|
ends[i] = ((ends[i] + align - 1) & ~(align - 1)) - 1;
|
|
|
|
}
|
|
|
|
if (starts[0] != START_NONE && starts[1] != START_NONE) {
|
|
|
|
if (starts[0] < starts[1]) {
|
|
|
|
if (ends[0] > starts[1]) {
|
|
|
|
device_printf(sc->dev, "Overlapping ranges"
|
|
|
|
" for prefetch and non-prefetch memory\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
} else {
|
2005-12-29 23:38:45 +00:00
|
|
|
if (ends[1] > starts[0]) {
|
|
|
|
device_printf(sc->dev, "Overlapping ranges"
|
|
|
|
" for prefetch and non-prefetch memory\n");
|
|
|
|
return;
|
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
if (type == SYS_RES_MEMORY) {
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_mem_open(sc->dev, 0, starts[0], ends[0]);
|
|
|
|
cbb_cardbus_mem_open(sc->dev, 1, starts[1], ends[1]);
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
reg = pci_read_config(sc->dev, CBBR_BRIDGECTRL, 2);
|
2005-12-29 23:38:45 +00:00
|
|
|
reg &= ~(CBBM_BRIDGECTRL_PREFETCH_0 |
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
CBBM_BRIDGECTRL_PREFETCH_1);
|
2005-12-29 23:38:45 +00:00
|
|
|
if (starts[1] != START_NONE)
|
|
|
|
reg |= CBBM_BRIDGECTRL_PREFETCH_1;
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
pci_write_config(sc->dev, CBBR_BRIDGECTRL, reg, 2);
|
2005-12-29 23:38:45 +00:00
|
|
|
if (bootverbose) {
|
|
|
|
device_printf(sc->dev, "Opening memory:\n");
|
|
|
|
if (starts[0] != START_NONE)
|
|
|
|
device_printf(sc->dev, "Normal: %#x-%#x\n",
|
|
|
|
starts[0], ends[0]);
|
|
|
|
if (starts[1] != START_NONE)
|
|
|
|
device_printf(sc->dev, "Prefetch: %#x-%#x\n",
|
|
|
|
starts[1], ends[1]);
|
2005-12-27 19:18:11 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
} else if (type == SYS_RES_IOPORT) {
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_io_open(sc->dev, 0, starts[0], ends[0]);
|
|
|
|
cbb_cardbus_io_open(sc->dev, 1, starts[1], ends[1]);
|
2005-12-29 23:38:45 +00:00
|
|
|
if (bootverbose && starts[0] != START_NONE)
|
|
|
|
device_printf(sc->dev, "Opening I/O: %#x-%#x\n",
|
|
|
|
starts[0], ends[0]);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_activate_resource(device_t brdev, device_t child, int type,
|
2001-08-27 00:09:42 +00:00
|
|
|
int rid, struct resource *res)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
int ret;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
ret = BUS_ACTIVATE_RESOURCE(device_get_parent(brdev), child,
|
|
|
|
type, rid, res);
|
2001-11-26 05:42:45 +00:00
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_auto_open(device_get_softc(brdev), type);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_deactivate_resource(device_t brdev, device_t child, int type,
|
2001-08-27 00:09:42 +00:00
|
|
|
int rid, struct resource *res)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
int ret;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
ret = BUS_DEACTIVATE_RESOURCE(device_get_parent(brdev), child,
|
|
|
|
type, rid, res);
|
2001-11-26 05:42:45 +00:00
|
|
|
if (ret != 0)
|
|
|
|
return (ret);
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_auto_open(device_get_softc(brdev), type);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
static struct resource *
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_alloc_resource(device_t brdev, device_t child, int type,
|
2003-08-07 15:04:27 +00:00
|
|
|
int *rid, u_long start, u_long end, u_long count, u_int flags)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-08-27 00:09:42 +00:00
|
|
|
int tmp;
|
|
|
|
struct resource *res;
|
2004-04-06 22:41:14 +00:00
|
|
|
u_long align;
|
2001-08-27 00:09:42 +00:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_IRQ:
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
tmp = rman_get_start(sc->irq_res);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (start > tmp || end < tmp || count != 1) {
|
|
|
|
device_printf(child, "requested interrupt %ld-%ld,"
|
2002-08-15 08:01:24 +00:00
|
|
|
"count = %ld not supported by cbb\n",
|
2001-08-27 00:09:42 +00:00
|
|
|
start, end, count);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (NULL);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
start = end = tmp;
|
2003-04-28 18:50:59 +00:00
|
|
|
flags |= RF_SHAREABLE;
|
2001-08-27 00:09:42 +00:00
|
|
|
break;
|
|
|
|
case SYS_RES_IOPORT:
|
2002-08-15 08:01:24 +00:00
|
|
|
if (start <= cbb_start_32_io)
|
|
|
|
start = cbb_start_32_io;
|
2001-08-27 00:09:42 +00:00
|
|
|
if (end < start)
|
|
|
|
end = start;
|
2005-12-27 19:18:11 +00:00
|
|
|
if (count > (1 << RF_ALIGNMENT(flags)))
|
|
|
|
flags = (flags & ~RF_ALIGNMENT_MASK) |
|
|
|
|
rman_make_alignment_flags(count);
|
2001-08-27 00:09:42 +00:00
|
|
|
break;
|
|
|
|
case SYS_RES_MEMORY:
|
2002-08-15 08:01:24 +00:00
|
|
|
if (start <= cbb_start_mem)
|
|
|
|
start = cbb_start_mem;
|
2001-08-27 00:09:42 +00:00
|
|
|
if (end < start)
|
|
|
|
end = start;
|
2004-04-06 22:50:50 +00:00
|
|
|
if (count < CBB_MEMALIGN)
|
|
|
|
align = CBB_MEMALIGN;
|
|
|
|
else
|
|
|
|
align = count;
|
|
|
|
if (align > (1 << RF_ALIGNMENT(flags)))
|
|
|
|
flags = (flags & ~RF_ALIGNMENT_MASK) |
|
2004-04-06 22:41:14 +00:00
|
|
|
rman_make_alignment_flags(align);
|
2001-08-27 00:09:42 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
res = BUS_ALLOC_RESOURCE(device_get_parent(brdev), child, type, rid,
|
|
|
|
start, end, count, flags & ~RF_ACTIVE);
|
|
|
|
if (res == NULL) {
|
2007-05-16 18:44:56 +00:00
|
|
|
printf("cbb alloc res fail type %d rid %x\n", type, *rid);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (NULL);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_insert_res(sc, res, type, *rid);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (flags & RF_ACTIVE)
|
|
|
|
if (bus_activate_resource(child, type, *rid, res) != 0) {
|
|
|
|
bus_release_resource(child, type, *rid, res);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (NULL);
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
|
|
|
|
2001-11-26 05:42:45 +00:00
|
|
|
return (res);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_cardbus_release_resource(device_t brdev, device_t child, int type,
|
2001-08-27 00:09:42 +00:00
|
|
|
int rid, struct resource *res)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-11-26 05:42:45 +00:00
|
|
|
int error;
|
2001-08-27 00:09:42 +00:00
|
|
|
|
|
|
|
if (rman_get_flags(res) & RF_ACTIVE) {
|
|
|
|
error = bus_deactivate_resource(child, type, rid, res);
|
|
|
|
if (error != 0)
|
2001-11-26 05:42:45 +00:00
|
|
|
return (error);
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_remove_res(sc, res);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (BUS_RELEASE_RESOURCE(device_get_parent(brdev), child,
|
|
|
|
type, rid, res));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
2000-11-28 00:05:20 +00:00
|
|
|
/* PC Card Power Functions */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_power_enable_socket(device_t brdev, device_t child)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
int err;
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
DPRINTF(("cbb_pcic_socket_enable:\n"));
|
2000-11-28 00:05:20 +00:00
|
|
|
|
|
|
|
/* power down/up the socket to reset */
|
2002-08-15 08:01:24 +00:00
|
|
|
err = cbb_do_power(brdev);
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
2004-08-12 06:50:29 +00:00
|
|
|
exca_reset(&sc->exca[0], child);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 21:11:31 +00:00
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_power_disable_socket(device_t brdev, device_t child)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
DPRINTF(("cbb_pcic_socket_disable\n"));
|
2000-11-28 00:05:20 +00:00
|
|
|
|
2007-03-05 05:40:24 +00:00
|
|
|
/* Turn off the card's interrupt and leave it in reset, wait 10ms */
|
2005-10-08 06:57:13 +00:00
|
|
|
exca_putb(&sc->exca[0], EXCA_INTR, 0);
|
2007-02-27 17:27:23 +00:00
|
|
|
pause("cbbP1", hz / 100);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
|
|
|
/* power down the socket */
|
2005-07-14 20:46:59 +00:00
|
|
|
cbb_power(brdev, CARD_OFF);
|
2005-10-08 06:57:13 +00:00
|
|
|
exca_putb(&sc->exca[0], EXCA_PWRCTL, 0);
|
2000-11-28 00:05:20 +00:00
|
|
|
|
|
|
|
/* wait 300ms until power fails (Tpf). */
|
2007-03-05 05:40:24 +00:00
|
|
|
pause("cbbP2", hz * 300 / 1000);
|
2007-02-16 05:36:59 +00:00
|
|
|
|
|
|
|
/* enable CSC interrupts */
|
|
|
|
exca_putb(&sc->exca[0], EXCA_INTR, EXCA_INTR_ENABLE);
|
2009-02-04 21:11:31 +00:00
|
|
|
return (0);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
2002-01-29 06:50:18 +00:00
|
|
|
/* POWER methods */
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_power_enable_socket(device_t brdev, device_t child)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
if (sc->flags & CBB_16BIT_CARD)
|
|
|
|
return (cbb_pcic_power_enable_socket(brdev, child));
|
2009-02-04 21:11:31 +00:00
|
|
|
return (cbb_cardbus_power_enable_socket(brdev, child));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2009-02-04 21:11:31 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_power_disable_socket(device_t brdev, device_t child)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
|
|
|
if (sc->flags & CBB_16BIT_CARD)
|
2009-02-04 21:11:31 +00:00
|
|
|
return (cbb_pcic_power_disable_socket(brdev, child));
|
|
|
|
return (cbb_cardbus_power_disable_socket(brdev, child));
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
2003-06-07 20:47:35 +00:00
|
|
|
|
2001-08-27 00:09:42 +00:00
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_activate_resource(device_t brdev, device_t child, int type, int rid,
|
2001-08-27 00:09:42 +00:00
|
|
|
struct resource *res)
|
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2014-01-27 19:49:52 +00:00
|
|
|
int error;
|
|
|
|
|
|
|
|
error = exca_activate_resource(&sc->exca[0], child, type, rid, res);
|
|
|
|
if (error == 0)
|
|
|
|
cbb_activate_window(brdev, type);
|
|
|
|
return (error);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_deactivate_resource(device_t brdev, device_t child, int type,
|
2001-08-27 00:09:42 +00:00
|
|
|
int rid, struct resource *res)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2004-08-12 06:50:29 +00:00
|
|
|
return (exca_deactivate_resource(&sc->exca[0], child, type, rid, res));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
static struct resource *
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_alloc_resource(device_t brdev, device_t child, int type, int *rid,
|
2003-08-07 15:04:27 +00:00
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2001-08-27 00:09:42 +00:00
|
|
|
struct resource *res = NULL;
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2004-04-12 21:04:54 +00:00
|
|
|
int align;
|
2001-08-27 00:09:42 +00:00
|
|
|
int tmp;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2000-10-22 04:37:57 +00:00
|
|
|
switch (type) {
|
|
|
|
case SYS_RES_MEMORY:
|
2002-08-15 08:01:24 +00:00
|
|
|
if (start < cbb_start_mem)
|
|
|
|
start = cbb_start_mem;
|
2001-08-27 00:09:42 +00:00
|
|
|
if (end < start)
|
|
|
|
end = start;
|
2004-04-12 21:04:54 +00:00
|
|
|
if (count < CBB_MEMALIGN)
|
|
|
|
align = CBB_MEMALIGN;
|
|
|
|
else
|
|
|
|
align = count;
|
|
|
|
if (align > (1 << RF_ALIGNMENT(flags)))
|
|
|
|
flags = (flags & ~RF_ALIGNMENT_MASK) |
|
|
|
|
rman_make_alignment_flags(align);
|
2000-10-22 04:37:57 +00:00
|
|
|
break;
|
|
|
|
case SYS_RES_IOPORT:
|
2002-08-15 08:01:24 +00:00
|
|
|
if (start < cbb_start_16_io)
|
|
|
|
start = cbb_start_16_io;
|
2000-10-22 04:37:57 +00:00
|
|
|
if (end < start)
|
|
|
|
end = start;
|
|
|
|
break;
|
|
|
|
case SYS_RES_IRQ:
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
tmp = rman_get_start(sc->irq_res);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (start > tmp || end < tmp || count != 1) {
|
|
|
|
device_printf(child, "requested interrupt %ld-%ld,"
|
2002-08-15 08:01:24 +00:00
|
|
|
"count = %ld not supported by cbb\n",
|
2001-08-27 00:09:42 +00:00
|
|
|
start, end, count);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (NULL);
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
2000-10-22 04:37:57 +00:00
|
|
|
flags |= RF_SHAREABLE;
|
Bulk changes made during the BSDcon kernel summit and travel afterwards.
Appologies for making this one bulk commit, but I have tested all these
changes together and don't want to break anything by trying to disentangle
it.
o Make debugging a sysctl/tunable
o Remove flags word from yenta chip info, it is unused
o Make 16-bit card I/O range and 32-bit card I/O range tunables
o Start the rename of pccbb to cbb to match NetBSD by misc renames.
o Kill the now bogus list of softcs to create kthread. Instead, just
create the kthread in the attach routine.
o Remove sc_ from some structure names. It isn't needed.
o Refine chipset lookup code.
o Match generic PCI <-> CardBus bridges. We specifically don't generically
match PCI PCMCIA bridges because they are not, with one exception, yenta
devices.
o Add some comments about the why we need to have a function table ala
OLDCARD
o The PCI interrupt routing by using the ExCA registers is needed for
for all bridges, per the spec, not just TI ones.
o Collapse TOPIC95 and TOPIC95B.
o Using the ToPIC 97 and 100 datasheets, try to support these bridges better,
but more work is needed.
o Generally clarify some XXX comments and add them in a few places where
things didn't look right to me.
o Move interrupt generating register access until after we establish an ISR.
o Add support for YV and XV cards. X and Y are numbers to be determined
later (but maybe never).
o factor powerup code for 16-bit and 32-bit cards.
o When a card supports more than one voltage, prefer the lowest supported
volage. Windows does this, and MS's design guides imply this is the
right thing to do.
o Document race between kthread_exit(0) and kldunload's unmapping of pages
that John Baldwin and I discovered.
o Debounce the CSC interrupt a little better.
o When a 16-bit card is inserted when we don't have a pccard child,
warn about it better. Ditto for 32-bit card.
o Ack ALL the interrupt bits that we get, not just 0x1.
o maybe a couple minor style nits corrected.
2002-02-17 03:11:11 +00:00
|
|
|
start = end = rman_get_start(sc->irq_res);
|
2000-10-22 04:37:57 +00:00
|
|
|
break;
|
|
|
|
}
|
2001-08-27 00:09:42 +00:00
|
|
|
res = BUS_ALLOC_RESOURCE(device_get_parent(brdev), child, type, rid,
|
|
|
|
start, end, count, flags & ~RF_ACTIVE);
|
|
|
|
if (res == NULL)
|
2001-11-26 05:42:45 +00:00
|
|
|
return (NULL);
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_insert_res(sc, res, type, *rid);
|
2000-10-18 03:25:13 +00:00
|
|
|
if (flags & RF_ACTIVE) {
|
2001-08-27 00:09:42 +00:00
|
|
|
if (bus_activate_resource(child, type, *rid, res) != 0) {
|
|
|
|
bus_release_resource(child, type, *rid, res);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (NULL);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-11-26 05:42:45 +00:00
|
|
|
return (res);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_release_resource(device_t brdev, device_t child, int type,
|
2001-08-26 23:55:34 +00:00
|
|
|
int rid, struct resource *res)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-11-26 05:42:45 +00:00
|
|
|
int error;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
|
|
|
if (rman_get_flags(res) & RF_ACTIVE) {
|
|
|
|
error = bus_deactivate_resource(child, type, rid, res);
|
|
|
|
if (error != 0)
|
2001-11-26 05:42:45 +00:00
|
|
|
return (error);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_remove_res(sc, res);
|
2001-11-26 05:42:45 +00:00
|
|
|
return (BUS_RELEASE_RESOURCE(device_get_parent(brdev), child,
|
|
|
|
type, rid, res));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* PC Card methods */
|
|
|
|
/************************************************************************/
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_set_res_flags(device_t brdev, device_t child, int type, int rid,
|
2009-02-04 21:11:31 +00:00
|
|
|
u_long flags)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-08-27 00:09:42 +00:00
|
|
|
struct resource *res;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
if (type != SYS_RES_MEMORY)
|
|
|
|
return (EINVAL);
|
2002-08-15 08:01:24 +00:00
|
|
|
res = cbb_find_res(sc, type, rid);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (res == NULL) {
|
|
|
|
device_printf(brdev,
|
|
|
|
"set_res_flags: specified rid not found\n");
|
2001-11-26 05:42:45 +00:00
|
|
|
return (ENOENT);
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
2004-08-12 06:50:29 +00:00
|
|
|
return (exca_mem_set_flags(&sc->exca[0], res, flags));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_pcic_set_memory_offset(device_t brdev, device_t child, int rid,
|
2002-01-14 02:59:06 +00:00
|
|
|
uint32_t cardaddr, uint32_t *deltap)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-08-27 00:09:42 +00:00
|
|
|
struct resource *res;
|
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
res = cbb_find_res(sc, SYS_RES_MEMORY, rid);
|
2001-08-27 00:09:42 +00:00
|
|
|
if (res == NULL) {
|
|
|
|
device_printf(brdev,
|
|
|
|
"set_memory_offset: specified rid not found\n");
|
2001-11-26 05:42:45 +00:00
|
|
|
return (ENOENT);
|
2001-08-27 00:09:42 +00:00
|
|
|
}
|
2004-08-12 06:50:29 +00:00
|
|
|
return (exca_mem_set_offset(&sc->exca[0], res, cardaddr, deltap));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
2000-11-28 00:05:20 +00:00
|
|
|
/* BUS Methods */
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_activate_resource(device_t brdev, device_t child, int type, int rid,
|
2001-08-26 23:55:34 +00:00
|
|
|
struct resource *r)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
if (sc->flags & CBB_16BIT_CARD)
|
|
|
|
return (cbb_pcic_activate_resource(brdev, child, type, rid, r));
|
2000-10-18 03:25:13 +00:00
|
|
|
else
|
2002-08-15 08:01:24 +00:00
|
|
|
return (cbb_cardbus_activate_resource(brdev, child, type, rid,
|
2001-11-26 05:42:45 +00:00
|
|
|
r));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_deactivate_resource(device_t brdev, device_t child, int type,
|
2001-08-26 23:55:34 +00:00
|
|
|
int rid, struct resource *r)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
if (sc->flags & CBB_16BIT_CARD)
|
|
|
|
return (cbb_pcic_deactivate_resource(brdev, child, type,
|
2001-11-26 05:42:45 +00:00
|
|
|
rid, r));
|
2000-10-18 03:25:13 +00:00
|
|
|
else
|
2002-08-15 08:01:24 +00:00
|
|
|
return (cbb_cardbus_deactivate_resource(brdev, child, type,
|
2001-11-26 05:42:45 +00:00
|
|
|
rid, r));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
struct resource *
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_alloc_resource(device_t brdev, device_t child, int type, int *rid,
|
2003-08-07 15:04:27 +00:00
|
|
|
u_long start, u_long end, u_long count, u_int flags)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
if (sc->flags & CBB_16BIT_CARD)
|
|
|
|
return (cbb_pcic_alloc_resource(brdev, child, type, rid,
|
2001-11-26 05:42:45 +00:00
|
|
|
start, end, count, flags));
|
2000-10-18 03:25:13 +00:00
|
|
|
else
|
2002-08-15 08:01:24 +00:00
|
|
|
return (cbb_cardbus_alloc_resource(brdev, child, type, rid,
|
2001-11-26 05:42:45 +00:00
|
|
|
start, end, count, flags));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_release_resource(device_t brdev, device_t child, int type, int rid,
|
2001-08-26 23:55:34 +00:00
|
|
|
struct resource *r)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2002-08-15 08:01:24 +00:00
|
|
|
if (sc->flags & CBB_16BIT_CARD)
|
|
|
|
return (cbb_pcic_release_resource(brdev, child, type,
|
2001-11-26 05:42:45 +00:00
|
|
|
rid, r));
|
2000-10-18 03:25:13 +00:00
|
|
|
else
|
2002-08-15 08:01:24 +00:00
|
|
|
return (cbb_cardbus_release_resource(brdev, child, type,
|
2001-11-26 05:42:45 +00:00
|
|
|
rid, r));
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_read_ivar(device_t brdev, device_t child, int which, uintptr_t *result)
|
2000-12-13 01:28:00 +00:00
|
|
|
{
|
2002-08-15 08:01:24 +00:00
|
|
|
struct cbb_softc *sc = device_get_softc(brdev);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2000-12-13 01:28:00 +00:00
|
|
|
switch (which) {
|
2007-09-30 11:05:18 +00:00
|
|
|
case PCIB_IVAR_DOMAIN:
|
|
|
|
*result = sc->domain;
|
|
|
|
return (0);
|
2000-12-13 01:28:00 +00:00
|
|
|
case PCIB_IVAR_BUS:
|
2014-02-12 04:30:37 +00:00
|
|
|
*result = sc->bus.sec;
|
2001-11-26 05:42:45 +00:00
|
|
|
return (0);
|
2000-12-13 01:28:00 +00:00
|
|
|
}
|
2001-11-26 05:42:45 +00:00
|
|
|
return (ENOENT);
|
2000-12-13 01:28:00 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2002-08-15 08:01:24 +00:00
|
|
|
cbb_write_ivar(device_t brdev, device_t child, int which, uintptr_t value)
|
2000-12-13 01:28:00 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
switch (which) {
|
2007-09-30 11:05:18 +00:00
|
|
|
case PCIB_IVAR_DOMAIN:
|
|
|
|
return (EINVAL);
|
2000-12-13 01:28:00 +00:00
|
|
|
case PCIB_IVAR_BUS:
|
2014-02-12 04:30:37 +00:00
|
|
|
return (EINVAL);
|
2000-12-13 01:28:00 +00:00
|
|
|
}
|
2001-11-26 05:42:45 +00:00
|
|
|
return (ENOENT);
|
2000-12-13 01:28:00 +00:00
|
|
|
}
|
|
|
|
|
2004-08-12 06:50:29 +00:00
|
|
|
int
|
2009-02-04 21:11:31 +00:00
|
|
|
cbb_child_present(device_t parent, device_t child)
|
2002-11-14 05:20:39 +00:00
|
|
|
{
|
2009-02-04 21:11:31 +00:00
|
|
|
struct cbb_softc *sc = (struct cbb_softc *)device_get_softc(parent);
|
2002-11-14 05:20:39 +00:00
|
|
|
uint32_t sockstate;
|
|
|
|
|
|
|
|
sockstate = cbb_get(sc, CBB_SOCKET_STATE);
|
2007-06-04 05:59:44 +00:00
|
|
|
return (CBB_CARD_PRESENT(sockstate) && sc->cardok);
|
2002-11-14 05:20:39 +00:00
|
|
|
}
|