2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
2017-11-27 14:52:40 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause-FreeBSD
|
|
|
|
*
|
2003-02-17 21:20:35 +00:00
|
|
|
* Copyright (c) 2000,2001 Jonathan Chen. All rights reserved.
|
2019-12-04 16:56:11 +00:00
|
|
|
* Copyright (c) 2003-2008 M. Warner Losh <imp@FreeBSD.org>
|
2019-02-05 21:28:29 +00:00
|
|
|
*
|
1999-11-18 07:21:51 +00:00
|
|
|
* 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:12:10 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
1999-11-18 07:21:51 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2005-01-13 19:12:10 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1999-11-18 07:21:51 +00:00
|
|
|
*
|
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:12:10 +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.
|
1999-11-18 07:21:51 +00:00
|
|
|
*/
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1999-11-18 07:21:51 +00:00
|
|
|
#include <sys/param.h>
|
Extract eventfilter declarations to sys/_eventfilter.h
This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.
EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).
As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.
LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).
No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.
2019-05-20 00:38:23 +00:00
|
|
|
#include <sys/eventhandler.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
2004-05-30 17:57:46 +00:00
|
|
|
#include <sys/module.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
#include <sys/kernel.h>
|
2002-03-07 08:10:42 +00:00
|
|
|
#include <sys/sysctl.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <sys/bus.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
#include <machine/bus.h>
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <sys/rman.h>
|
|
|
|
#include <machine/resource.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2002-02-27 05:09:14 +00:00
|
|
|
#include <sys/pciio.h>
|
2001-08-27 00:09:42 +00:00
|
|
|
#include <dev/pci/pcivar.h>
|
|
|
|
#include <dev/pci/pcireg.h>
|
2003-02-16 02:06:50 +00:00
|
|
|
#include <dev/pci/pci_private.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
|
|
|
|
#include <dev/cardbus/cardbusreg.h>
|
|
|
|
#include <dev/cardbus/cardbusvar.h>
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <dev/cardbus/cardbus_cis.h>
|
2005-02-06 21:03:13 +00:00
|
|
|
#include <dev/pccard/pccard_cis.h>
|
2002-05-30 17:38:00 +00:00
|
|
|
#include <dev/pccard/pccardvar.h>
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
#include "power_if.h"
|
2000-10-18 03:25:13 +00:00
|
|
|
#include "pcib_if.h"
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2002-03-07 08:10:42 +00:00
|
|
|
/* sysctl vars */
|
2020-02-26 14:26:36 +00:00
|
|
|
static SYSCTL_NODE(_hw, OID_AUTO, cardbus, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
|
|
|
|
"CardBus parameters");
|
2002-03-07 08:10:42 +00:00
|
|
|
|
2002-03-15 06:41:01 +00:00
|
|
|
int cardbus_debug = 0;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_hw_cardbus, OID_AUTO, debug, CTLFLAG_RWTUN,
|
|
|
|
&cardbus_debug, 0, "CardBus debug");
|
2002-03-07 08:10:42 +00:00
|
|
|
|
2002-03-15 06:41:01 +00:00
|
|
|
int cardbus_cis_debug = 0;
|
2014-06-28 03:56:17 +00:00
|
|
|
SYSCTL_INT(_hw_cardbus, OID_AUTO, cis_debug, CTLFLAG_RWTUN,
|
|
|
|
&cardbus_cis_debug, 0, "CardBus CIS debug");
|
2002-03-07 08:10:42 +00:00
|
|
|
|
|
|
|
#define DPRINTF(a) if (cardbus_debug) printf a
|
|
|
|
#define DEVPRINTF(x) if (cardbus_debug) device_printf x
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
static int cardbus_attach(device_t cbdev);
|
|
|
|
static int cardbus_attach_card(device_t cbdev);
|
2002-10-07 23:00:51 +00:00
|
|
|
static int cardbus_detach(device_t cbdev);
|
2002-11-02 23:00:28 +00:00
|
|
|
static int cardbus_detach_card(device_t cbdev);
|
2007-05-16 23:40:08 +00:00
|
|
|
static void cardbus_device_setup_regs(pcicfgregs *cfg);
|
2002-10-07 23:00:51 +00:00
|
|
|
static void cardbus_driver_added(device_t cbdev, driver_t *driver);
|
|
|
|
static int cardbus_probe(device_t cbdev);
|
|
|
|
static int cardbus_read_ivar(device_t cbdev, device_t child, int which,
|
2003-02-16 02:06:50 +00:00
|
|
|
uintptr_t *result);
|
2009-03-10 22:04:52 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Probe/Attach */
|
|
|
|
/************************************************************************/
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
2001-08-26 23:55:34 +00:00
|
|
|
cardbus_probe(device_t cbdev)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2001-12-15 05:58:28 +00:00
|
|
|
device_set_desc(cbdev, "CardBus bus");
|
2005-12-30 19:25:04 +00:00
|
|
|
return (0);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
2001-08-26 23:55:34 +00:00
|
|
|
cardbus_attach(device_t cbdev)
|
2000-10-18 03:25:13 +00:00
|
|
|
{
|
2008-11-17 01:32:29 +00:00
|
|
|
struct cardbus_softc *sc;
|
2014-02-12 04:30:37 +00:00
|
|
|
#ifdef PCI_RES_BUS
|
|
|
|
int rid;
|
|
|
|
#endif
|
2005-12-29 01:43:47 +00:00
|
|
|
|
2008-11-17 01:32:29 +00:00
|
|
|
sc = device_get_softc(cbdev);
|
2005-12-29 01:43:47 +00:00
|
|
|
sc->sc_dev = cbdev;
|
2014-02-12 04:30:37 +00:00
|
|
|
#ifdef PCI_RES_BUS
|
|
|
|
rid = 0;
|
|
|
|
sc->sc_bus = bus_alloc_resource(cbdev, PCI_RES_BUS, &rid,
|
|
|
|
pcib_get_bus(cbdev), pcib_get_bus(cbdev), 1, 0);
|
|
|
|
if (sc->sc_bus == NULL) {
|
|
|
|
device_printf(cbdev, "failed to allocate bus number\n");
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
2015-01-14 05:41:31 +00:00
|
|
|
#else
|
|
|
|
device_printf(cbdev, "Your bus numbers may be AFU\n");
|
2014-02-12 04:30:37 +00:00
|
|
|
#endif
|
2005-12-30 19:25:04 +00:00
|
|
|
return (0);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static int
|
2001-08-26 23:55:34 +00:00
|
|
|
cardbus_detach(device_t cbdev)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2014-02-12 04:30:37 +00:00
|
|
|
#ifdef PCI_RES_BUS
|
|
|
|
struct cardbus_softc *sc;
|
|
|
|
#endif
|
2005-12-29 01:43:47 +00:00
|
|
|
|
2002-11-02 23:00:28 +00:00
|
|
|
cardbus_detach_card(cbdev);
|
2014-02-12 04:30:37 +00:00
|
|
|
#ifdef PCI_RES_BUS
|
|
|
|
sc = device_get_softc(cbdev);
|
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
|
|
|
device_printf(cbdev, "Freeing up the allocatd bus\n");
|
2014-02-12 04:30:37 +00:00
|
|
|
(void)bus_release_resource(cbdev, PCI_RES_BUS, 0, sc->sc_bus);
|
|
|
|
#endif
|
2005-12-30 19:25:04 +00:00
|
|
|
return (0);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2001-12-15 05:58:28 +00:00
|
|
|
static int
|
|
|
|
cardbus_suspend(device_t self)
|
|
|
|
{
|
2005-12-30 19:25:04 +00:00
|
|
|
|
2002-11-02 23:00:28 +00:00
|
|
|
cardbus_detach_card(self);
|
2001-12-15 05:58:28 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cardbus_resume(device_t self)
|
|
|
|
{
|
2005-12-30 19:25:04 +00:00
|
|
|
|
2001-12-15 05:58:28 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Attach/Detach card */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static void
|
2007-05-16 23:40:08 +00:00
|
|
|
cardbus_device_setup_regs(pcicfgregs *cfg)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2007-05-16 23:40:08 +00:00
|
|
|
device_t dev = cfg->dev;
|
2007-05-16 20:00:36 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Some cards power up with garbage in their BARs. This
|
|
|
|
* code clears all that junk out.
|
|
|
|
*/
|
2009-02-02 22:06:20 +00:00
|
|
|
for (i = 0; i < PCIR_MAX_BAR_0; i++)
|
2007-05-16 20:00:36 +00:00
|
|
|
pci_write_config(dev, PCIR_BAR(i), 0, 4);
|
|
|
|
|
2007-05-16 23:40:08 +00:00
|
|
|
cfg->intline =
|
|
|
|
pci_get_irq(device_get_parent(device_get_parent(dev)));
|
|
|
|
pci_write_config(dev, PCIR_INTLINE, cfg->intline, 1);
|
2007-05-16 20:00:36 +00:00
|
|
|
pci_write_config(dev, PCIR_CACHELNSZ, 0x08, 1);
|
|
|
|
pci_write_config(dev, PCIR_LATTIMER, 0xa8, 1);
|
|
|
|
pci_write_config(dev, PCIR_MINGNT, 0x14, 1);
|
|
|
|
pci_write_config(dev, PCIR_MAXLAT, 0x14, 1);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-15 03:42:12 +00:00
|
|
|
static struct pci_devinfo *
|
|
|
|
cardbus_alloc_devinfo(device_t dev)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
|
|
|
|
dinfo = malloc(sizeof(*dinfo), M_DEVBUF, M_WAITOK | M_ZERO);
|
|
|
|
return (&dinfo->pci);
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
2001-08-26 23:55:34 +00:00
|
|
|
cardbus_attach_card(device_t cbdev)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2001-08-26 23:55:34 +00:00
|
|
|
device_t brdev = device_get_parent(cbdev);
|
2005-02-06 21:03:13 +00:00
|
|
|
device_t child;
|
2007-09-30 11:05:18 +00:00
|
|
|
int bus, domain, slot, func;
|
2000-10-18 03:25:13 +00:00
|
|
|
int cardattached = 0;
|
2005-10-28 06:03:53 +00:00
|
|
|
int cardbusfunchigh = 0;
|
2008-11-17 01:32:29 +00:00
|
|
|
struct cardbus_softc *sc;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2008-11-17 01:32:29 +00:00
|
|
|
sc = device_get_softc(cbdev);
|
2002-11-02 23:00:28 +00:00
|
|
|
cardbus_detach_card(cbdev); /* detach existing cards */
|
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
|
|
|
POWER_DISABLE_SOCKET(brdev, cbdev); /* Turn the socket off first */
|
2001-08-26 23:55:34 +00:00
|
|
|
POWER_ENABLE_SOCKET(brdev, cbdev);
|
2007-09-30 11:05:18 +00:00
|
|
|
domain = pcib_get_domain(cbdev);
|
2001-08-26 23:55:34 +00:00
|
|
|
bus = pcib_get_bus(cbdev);
|
2005-10-28 06:03:53 +00:00
|
|
|
slot = 0;
|
2021-12-10 00:04:45 +00:00
|
|
|
bus_topo_lock();
|
2001-08-26 23:55:34 +00:00
|
|
|
/* For each function, set it up and try to attach a driver to it */
|
2005-10-28 06:03:53 +00:00
|
|
|
for (func = 0; func <= cardbusfunchigh; func++) {
|
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
|
|
|
|
dinfo = (struct cardbus_devinfo *)
|
2016-04-15 03:42:12 +00:00
|
|
|
pci_read_device(brdev, cbdev, domain, bus, slot, func);
|
2005-10-28 06:03:53 +00:00
|
|
|
if (dinfo == NULL)
|
|
|
|
continue;
|
|
|
|
if (dinfo->pci.cfg.mfdev)
|
|
|
|
cardbusfunchigh = PCI_FUNCMAX;
|
|
|
|
|
|
|
|
child = device_add_child(cbdev, NULL, -1);
|
|
|
|
if (child == NULL) {
|
|
|
|
DEVPRINTF((cbdev, "Cannot add child!\n"));
|
|
|
|
pci_freecfg((struct pci_devinfo *)dinfo);
|
|
|
|
continue;
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2005-10-28 06:03:53 +00:00
|
|
|
dinfo->pci.cfg.dev = child;
|
|
|
|
resource_list_init(&dinfo->pci.resources);
|
|
|
|
device_set_ivars(child, dinfo);
|
2008-11-17 01:32:29 +00:00
|
|
|
cardbus_device_create(sc, dinfo, cbdev, child);
|
2006-06-12 03:17:24 +00:00
|
|
|
if (cardbus_do_cis(cbdev, child) != 0)
|
|
|
|
DEVPRINTF((cbdev, "Warning: Bogus CIS ignored\n"));
|
2005-12-30 19:25:04 +00:00
|
|
|
pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 0);
|
|
|
|
pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci);
|
2007-05-16 23:40:08 +00:00
|
|
|
cardbus_device_setup_regs(&dinfo->pci.cfg);
|
2005-12-30 19:25:04 +00:00
|
|
|
pci_add_resources(cbdev, child, 1, dinfo->mprefetchable);
|
2005-10-28 06:03:53 +00:00
|
|
|
pci_print_verbose(&dinfo->pci);
|
2005-12-30 19:25:04 +00:00
|
|
|
if (device_probe_and_attach(child) == 0)
|
2005-10-28 06:03:53 +00:00
|
|
|
cardattached++;
|
2005-12-30 19:25:04 +00:00
|
|
|
else
|
|
|
|
pci_cfg_save(dinfo->pci.cfg.dev, &dinfo->pci, 1);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2021-12-10 00:04:45 +00:00
|
|
|
bus_topo_unlock();
|
2001-08-26 23:55:34 +00:00
|
|
|
if (cardattached > 0)
|
2002-11-02 23:00:28 +00:00
|
|
|
return (0);
|
2008-12-31 07:41:42 +00:00
|
|
|
/* POWER_DISABLE_SOCKET(brdev, cbdev); */
|
2002-11-02 23:00:28 +00:00
|
|
|
return (ENOENT);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 04:10:22 +00:00
|
|
|
static void
|
|
|
|
cardbus_child_deleted(device_t cbdev, device_t child)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
|
|
|
|
if (dinfo->pci.cfg.dev != child)
|
|
|
|
device_printf(cbdev, "devinfo dev mismatch\n");
|
|
|
|
cardbus_device_destroy(dinfo);
|
|
|
|
pci_child_deleted(cbdev, child);
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
2002-11-02 23:00:28 +00:00
|
|
|
cardbus_detach_card(device_t cbdev)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2001-08-26 23:55:34 +00:00
|
|
|
int err = 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2021-12-10 00:04:45 +00:00
|
|
|
bus_topo_lock();
|
2016-04-06 04:10:22 +00:00
|
|
|
err = bus_generic_detach(cbdev);
|
2021-02-27 07:00:52 +00:00
|
|
|
if (err == 0)
|
|
|
|
err = device_delete_children(cbdev);
|
2021-12-10 00:04:45 +00:00
|
|
|
bus_topo_unlock();
|
2016-04-06 04:10:22 +00:00
|
|
|
if (err)
|
|
|
|
return (err);
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2002-11-02 23:00:28 +00:00
|
|
|
POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev);
|
|
|
|
return (err);
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static void
|
2001-08-26 23:55:34 +00:00
|
|
|
cardbus_driver_added(device_t cbdev, driver_t *driver)
|
2000-11-28 00:05:20 +00:00
|
|
|
{
|
2001-01-06 18:04:55 +00:00
|
|
|
int numdevs;
|
|
|
|
device_t *devlist;
|
2003-02-11 05:31:35 +00:00
|
|
|
device_t dev;
|
|
|
|
int i;
|
2002-11-02 23:00:28 +00:00
|
|
|
struct cardbus_devinfo *dinfo;
|
2001-01-06 18:04:55 +00:00
|
|
|
|
2001-08-26 23:55:34 +00:00
|
|
|
DEVICE_IDENTIFY(driver, cbdev);
|
2007-01-19 08:49:28 +00:00
|
|
|
if (device_get_children(cbdev, &devlist, &numdevs) != 0)
|
|
|
|
return;
|
|
|
|
|
2003-02-12 05:57:02 +00:00
|
|
|
/*
|
|
|
|
* If there are no drivers attached, but there are children,
|
|
|
|
* then power the card up.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < numdevs; i++) {
|
|
|
|
dev = devlist[i];
|
|
|
|
if (device_get_state(dev) != DS_NOTPRESENT)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (i > 0 && i == numdevs)
|
|
|
|
POWER_ENABLE_SOCKET(device_get_parent(cbdev), cbdev);
|
2003-02-11 05:31:35 +00:00
|
|
|
for (i = 0; i < numdevs; i++) {
|
|
|
|
dev = devlist[i];
|
|
|
|
if (device_get_state(dev) != DS_NOTPRESENT)
|
|
|
|
continue;
|
|
|
|
dinfo = device_get_ivars(dev);
|
2003-02-16 02:06:50 +00:00
|
|
|
pci_print_verbose(&dinfo->pci);
|
2009-03-10 12:10:50 +00:00
|
|
|
if (bootverbose)
|
|
|
|
printf("pci%d:%d:%d:%d: reprobing on driver added\n",
|
|
|
|
dinfo->pci.cfg.domain, dinfo->pci.cfg.bus,
|
|
|
|
dinfo->pci.cfg.slot, dinfo->pci.cfg.func);
|
2005-12-30 19:25:04 +00:00
|
|
|
pci_cfg_restore(dinfo->pci.cfg.dev, &dinfo->pci);
|
2005-03-11 05:27:05 +00:00
|
|
|
if (device_probe_and_attach(dev) != 0)
|
2005-12-30 19:25:04 +00:00
|
|
|
pci_cfg_save(dev, &dinfo->pci, 1);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2001-02-08 21:47:45 +00:00
|
|
|
free(devlist, M_TEMP);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2002-03-15 06:41:01 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Other Bus Methods */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static int
|
2003-02-16 02:06:50 +00:00
|
|
|
cardbus_read_ivar(device_t cbdev, device_t child, int which, uintptr_t *result)
|
2002-03-15 06:41:01 +00:00
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
|
|
|
|
switch (which) {
|
2002-11-27 06:56:29 +00:00
|
|
|
case PCI_IVAR_ETHADDR:
|
|
|
|
/*
|
|
|
|
* The generic accessor doesn't deal with failure, so
|
|
|
|
* we set the return value, then return an error.
|
|
|
|
*/
|
2005-02-06 21:03:13 +00:00
|
|
|
if (dinfo->fepresent & (1 << PCCARD_TPLFE_TYPE_LAN_NID)) {
|
|
|
|
*((uint8_t **) result) = dinfo->funce.lan.nid;
|
|
|
|
break;
|
2002-11-27 06:56:29 +00:00
|
|
|
}
|
2005-02-06 21:03:13 +00:00
|
|
|
*((uint8_t **) result) = NULL;
|
|
|
|
return (EINVAL);
|
2002-03-15 06:41:01 +00:00
|
|
|
default:
|
2003-02-16 02:06:50 +00:00
|
|
|
return (pci_read_ivar(cbdev, child, which, result));
|
2002-03-15 06:41:01 +00:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static device_method_t cardbus_methods[] = {
|
|
|
|
/* Device interface */
|
|
|
|
DEVMETHOD(device_probe, cardbus_probe),
|
|
|
|
DEVMETHOD(device_attach, cardbus_attach),
|
2000-11-28 00:05:20 +00:00
|
|
|
DEVMETHOD(device_detach, cardbus_detach),
|
2001-12-15 05:58:28 +00:00
|
|
|
DEVMETHOD(device_suspend, cardbus_suspend),
|
|
|
|
DEVMETHOD(device_resume, cardbus_resume),
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
/* Bus interface */
|
2016-04-06 04:10:22 +00:00
|
|
|
DEVMETHOD(bus_child_deleted, cardbus_child_deleted),
|
2012-03-02 20:38:04 +00:00
|
|
|
DEVMETHOD(bus_get_dma_tag, bus_generic_get_dma_tag),
|
2002-03-15 06:41:01 +00:00
|
|
|
DEVMETHOD(bus_read_ivar, cardbus_read_ivar),
|
2000-11-28 00:05:20 +00:00
|
|
|
DEVMETHOD(bus_driver_added, cardbus_driver_added),
|
2022-06-23 18:44:28 +00:00
|
|
|
DEVMETHOD(bus_rescan, bus_null_rescan),
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
/* Card Interface */
|
|
|
|
DEVMETHOD(card_attach_card, cardbus_attach_card),
|
|
|
|
DEVMETHOD(card_detach_card, cardbus_detach_card),
|
|
|
|
|
2016-04-15 03:42:12 +00:00
|
|
|
/* PCI interface */
|
|
|
|
DEVMETHOD(pci_alloc_devinfo, cardbus_alloc_devinfo),
|
2000-10-18 03:25:13 +00:00
|
|
|
{0,0}
|
|
|
|
};
|
|
|
|
|
2005-12-29 10:38:42 +00:00
|
|
|
DEFINE_CLASS_1(cardbus, cardbus_driver, cardbus_methods,
|
|
|
|
sizeof(struct cardbus_softc), pci_driver);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2022-04-19 21:03:16 +00:00
|
|
|
DRIVER_MODULE(cardbus, cbb, cardbus_driver, 0, 0);
|
2002-05-30 17:38:00 +00:00
|
|
|
MODULE_VERSION(cardbus, 1);
|