1999-11-18 07:21:51 +00:00
|
|
|
/*
|
2000-10-18 03:25:13 +00:00
|
|
|
* Copyright (c) 2000,2001 Jonathan Chen.
|
|
|
|
* All rights reserved.
|
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
|
2000-10-18 03:25:13 +00:00
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
1999-11-18 07:21:51 +00:00
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
2000-10-18 03:25:13 +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
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS 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.
|
1999-11-18 07:21:51 +00:00
|
|
|
*
|
2000-10-18 03:25:13 +00:00
|
|
|
* $FreeBSD$
|
1999-11-18 07:21:51 +00:00
|
|
|
*/
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Cardbus Bus Driver
|
|
|
|
*
|
|
|
|
* much of the bus code was stolen directly from sys/pci/pci.c
|
|
|
|
* (Copyright (c) 1997, Stefan Esser <se@freebsd.org>)
|
|
|
|
*
|
|
|
|
* Written by Jonathan Chen <jon@freebsd.org>
|
|
|
|
*/
|
|
|
|
|
1999-11-18 07:21:51 +00:00
|
|
|
#define CARDBUS_DEBUG
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/systm.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
|
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
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
#include <pci/pcivar.h>
|
|
|
|
#include <pci/pcireg.h>
|
|
|
|
#include <sys/pciio.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>
|
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 "card_if.h"
|
|
|
|
#include "pcib_if.h"
|
1999-11-18 07:21:51 +00:00
|
|
|
|
|
|
|
#if defined CARDBUS_DEBUG
|
|
|
|
#define STATIC
|
|
|
|
#define DPRINTF(a) printf a
|
2000-10-18 03:25:13 +00:00
|
|
|
#define DEVPRINTF(x) device_printf x
|
1999-11-18 07:21:51 +00:00
|
|
|
#else
|
|
|
|
#define STATIC static
|
|
|
|
#define DPRINTF(a)
|
2000-10-18 03:25:13 +00:00
|
|
|
#define DEVPRINTF(x)
|
1999-11-18 07:21:51 +00:00
|
|
|
#endif
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
#if !defined(lint)
|
|
|
|
static const char rcsid[] =
|
2000-11-28 00:05:20 +00:00
|
|
|
"$FreeBSD$";
|
2000-10-18 03:25:13 +00:00
|
|
|
#endif
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
struct cardbus_quirk {
|
|
|
|
u_int32_t devid; /* Vendor/device of the card */
|
|
|
|
int type;
|
2001-02-06 09:25:10 +00:00
|
|
|
#define CARDBUS_QUIRK_MAP_REG 1 /* PCI map register in weird place */
|
2000-10-18 03:25:13 +00:00
|
|
|
int arg1;
|
|
|
|
int arg2;
|
1999-11-18 07:21:51 +00:00
|
|
|
};
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
struct cardbus_quirk cardbus_quirks[] = {
|
|
|
|
{ 0 }
|
|
|
|
};
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int cardbus_probe(device_t dev);
|
|
|
|
static int cardbus_attach(device_t dev);
|
|
|
|
static void device_setup_regs(device_t cbdev, int b, int s, int f,
|
|
|
|
pcicfgregs *cfg);
|
|
|
|
static int cardbus_attach_card(device_t dev);
|
|
|
|
static int cardbus_detach_card(device_t dev, int flags);
|
|
|
|
static struct cardbus_devinfo *cardbus_read_device(device_t pcib,
|
|
|
|
int b, int s, int f);
|
|
|
|
static void cardbus_hdrtypedata(device_t pcib, int b, int s, int f,
|
|
|
|
pcicfgregs *cfg);
|
|
|
|
static int cardbus_freecfg(struct cardbus_devinfo *dinfo);
|
|
|
|
static void cardbus_print_verbose(struct cardbus_devinfo *dinfo);
|
|
|
|
static int cardbus_set_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_long start, u_long count);
|
|
|
|
static int cardbus_get_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_long *startp, u_long *countp);
|
|
|
|
static void cardbus_delete_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid);
|
|
|
|
static int cardbus_set_resource_method(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_long start, u_long count);
|
|
|
|
static int cardbus_get_resource_method(device_t dev, device_t child, int type,
|
|
|
|
int rid, u_long *startp, u_long *countp);
|
2000-11-28 00:52:40 +00:00
|
|
|
static int cardbus_add_map(device_t bdev, device_t dev, pcicfgregs *cfg,
|
|
|
|
int reg);
|
2000-10-18 03:25:13 +00:00
|
|
|
static void cardbus_add_resources(device_t dev, pcicfgregs* cfg);
|
|
|
|
static void cardbus_release_all_resources(device_t dev,
|
|
|
|
struct resource_list *rl);
|
|
|
|
static struct resource* cardbus_alloc_resource(device_t self, device_t child,
|
|
|
|
int type, int* rid,u_long start,
|
|
|
|
u_long end, u_long count,
|
|
|
|
u_int flags);
|
|
|
|
static int cardbus_release_resource(device_t dev, device_t child, int type,
|
|
|
|
int rid, struct resource *r);
|
|
|
|
static int cardbus_print_resources(struct resource_list *rl, const char *name,
|
|
|
|
int type, const char *format);
|
|
|
|
static int cardbus_print_child(device_t dev, device_t child);
|
|
|
|
static void cardbus_probe_nomatch(device_t dev, device_t child);
|
|
|
|
static int cardbus_read_ivar(device_t dev, device_t child, int which,
|
|
|
|
u_long *result);
|
|
|
|
static int cardbus_write_ivar(device_t dev, device_t child, int which,
|
|
|
|
uintptr_t value);
|
|
|
|
static u_int32_t cardbus_read_config_method(device_t dev, device_t child,
|
|
|
|
int reg, int width);
|
|
|
|
static void cardbus_write_config_method(device_t dev, device_t child, int reg,
|
|
|
|
u_int32_t val, int width);
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Probe/Attach */
|
|
|
|
/************************************************************************/
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_probe(device_t dev)
|
|
|
|
{
|
|
|
|
device_set_desc(dev, "Cardbus bus (newcard)");
|
1999-11-18 07:21:51 +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
|
|
|
|
cardbus_attach(device_t dev)
|
|
|
|
{
|
1999-11-18 07:21:51 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static int
|
|
|
|
cardbus_detach(device_t dev)
|
|
|
|
{
|
|
|
|
cardbus_detach_card(dev, DETACH_FORCE);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Attach/Detach card */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static void
|
|
|
|
device_setup_regs(device_t bdev, int b, int s, int f, pcicfgregs *cfg)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
PCIB_WRITE_CONFIG(bdev, b, s, f, PCIR_INTLINE,
|
|
|
|
pci_get_irq(device_get_parent(bdev)), 1);
|
|
|
|
cfg->intline = PCIB_READ_CONFIG(bdev, b, s, f, PCIR_INTLINE, 1);
|
2000-11-28 00:52:40 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
PCIB_WRITE_CONFIG(bdev, b, s, f, PCIR_CACHELNSZ, 0x08, 1);
|
|
|
|
cfg->cachelnsz = PCIB_READ_CONFIG(bdev, b, s, f, PCIR_CACHELNSZ, 1);
|
|
|
|
|
|
|
|
PCIB_WRITE_CONFIG(bdev, b, s, f, PCIR_LATTIMER, 0xa8, 1);
|
|
|
|
cfg->lattimer = PCIB_READ_CONFIG(bdev, b, s, f, PCIR_LATTIMER, 1);
|
|
|
|
|
|
|
|
PCIB_WRITE_CONFIG(bdev, b, s, f, PCIR_MINGNT, 0x14, 1);
|
|
|
|
cfg->mingnt = PCIB_READ_CONFIG(bdev, b, s, f, PCIR_MINGNT, 1);
|
|
|
|
|
|
|
|
PCIB_WRITE_CONFIG(bdev, b, s, f, PCIR_MAXLAT, 0x14, 1);
|
|
|
|
cfg->maxlat = PCIB_READ_CONFIG(bdev, b, s, f, PCIR_MAXLAT, 1);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_attach_card(device_t dev)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
device_t bdev = device_get_parent(dev);
|
|
|
|
int cardattached = 0;
|
|
|
|
static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */
|
|
|
|
int bus, slot, func;
|
|
|
|
|
2001-01-06 18:04:55 +00:00
|
|
|
cardbus_detach_card(dev, DETACH_NOWARN); /* detach existing cards */
|
2000-10-18 03:25:13 +00:00
|
|
|
|
2001-01-06 18:04:55 +00:00
|
|
|
POWER_ENABLE_SOCKET(bdev, dev);
|
2000-12-13 01:28:00 +00:00
|
|
|
bus = pcib_get_bus(dev);
|
2000-10-18 03:25:13 +00:00
|
|
|
if (bus == 0) {
|
|
|
|
/*
|
|
|
|
* XXX EVILE BAD XXX
|
|
|
|
* Not all BIOSes initialize the secondary bus number properly,
|
|
|
|
* so if the default is bad, we just put one in and hope it
|
|
|
|
* works.
|
|
|
|
*/
|
|
|
|
bus = curr_bus_number;
|
|
|
|
pci_write_config (bdev, PCIR_SECBUS_2, curr_bus_number, 1);
|
|
|
|
pci_write_config (bdev, PCIR_SUBBUS_2, curr_bus_number+2, 1);
|
|
|
|
curr_bus_number += 3;
|
|
|
|
}
|
|
|
|
for (slot = 0; slot <= CARDBUS_SLOTMAX; slot++) {
|
|
|
|
int cardbusfunchigh = 0;
|
|
|
|
for (func = 0; func <= cardbusfunchigh; func++) {
|
|
|
|
struct cardbus_devinfo *dinfo =
|
|
|
|
cardbus_read_device(bdev, bus, slot, func);
|
|
|
|
|
|
|
|
if (dinfo == NULL) continue;
|
|
|
|
if (dinfo->cfg.mfdev)
|
|
|
|
cardbusfunchigh = CARDBUS_FUNCMAX;
|
|
|
|
device_setup_regs(bdev, bus, slot, func, &dinfo->cfg);
|
|
|
|
cardbus_print_verbose(dinfo);
|
|
|
|
dinfo->cfg.dev = device_add_child(dev, NULL, -1);
|
|
|
|
if (!dinfo->cfg.dev) {
|
|
|
|
DEVPRINTF((dev, "Cannot add child!\n"));
|
|
|
|
cardbus_freecfg(dinfo);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
resource_list_init(&dinfo->resources);
|
|
|
|
device_set_ivars(dinfo->cfg.dev, dinfo);
|
|
|
|
cardbus_add_resources(dinfo->cfg.dev, &dinfo->cfg);
|
|
|
|
cardbus_do_cis(dev, dinfo->cfg.dev);
|
|
|
|
if (device_probe_and_attach(dinfo->cfg.dev) != 0) {
|
|
|
|
cardbus_release_all_resources(dinfo->cfg.dev,
|
|
|
|
&dinfo->resources);
|
|
|
|
} else
|
|
|
|
cardattached++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cardattached > 0) return 0;
|
2000-11-28 00:05:20 +00:00
|
|
|
POWER_DISABLE_SOCKET(bdev, dev);
|
2000-10-18 03:25:13 +00:00
|
|
|
return ENOENT;
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_detach_card(device_t dev, int flags)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
int numdevs;
|
|
|
|
device_t *devlist;
|
|
|
|
int tmp;
|
|
|
|
int err=0;
|
|
|
|
|
|
|
|
device_get_children(dev, &devlist, &numdevs);
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
if (numdevs == 0) {
|
2001-01-06 18:04:55 +00:00
|
|
|
if (!(flags & DETACH_NOWARN)) {
|
|
|
|
DEVPRINTF((dev, "Detaching card: no cards to detach!\n"));
|
|
|
|
POWER_DISABLE_SOCKET(device_get_parent(dev), dev);
|
|
|
|
}
|
2001-02-08 21:47:45 +00:00
|
|
|
free(devlist, M_TEMP);
|
2000-10-18 03:25:13 +00:00
|
|
|
return ENOENT;
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
for (tmp = 0; tmp < numdevs; tmp++) {
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(devlist[tmp]);
|
2001-01-06 18:04:55 +00:00
|
|
|
int status = device_get_state(devlist[tmp]);
|
|
|
|
|
|
|
|
if (status == DS_ATTACHED || status == DS_BUSY) {
|
|
|
|
if (device_detach(dinfo->cfg.dev) == 0 ||
|
|
|
|
flags & DETACH_FORCE){
|
|
|
|
cardbus_release_all_resources(dinfo->cfg.dev,
|
|
|
|
&dinfo->resources);
|
|
|
|
device_delete_child(dev, devlist[tmp]);
|
|
|
|
} else {
|
|
|
|
err++;
|
|
|
|
}
|
|
|
|
cardbus_freecfg(dinfo);
|
|
|
|
} else {
|
2000-11-28 00:05:20 +00:00
|
|
|
device_delete_child(dev, devlist[tmp]);
|
2001-01-06 18:04:55 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2000-11-28 00:05:20 +00:00
|
|
|
if (err == 0)
|
|
|
|
POWER_DISABLE_SOCKET(device_get_parent(dev), dev);
|
2001-02-08 21:47:45 +00:00
|
|
|
free(devlist, M_TEMP);
|
2000-10-18 03:25:13 +00:00
|
|
|
return err;
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static void
|
|
|
|
cardbus_driver_added(device_t dev, driver_t *driver)
|
|
|
|
{
|
2001-01-06 18:04:55 +00:00
|
|
|
int numdevs;
|
|
|
|
device_t *devlist;
|
|
|
|
device_t bdev = device_get_parent(dev);
|
|
|
|
int tmp, cardattached;
|
|
|
|
|
|
|
|
device_get_children(dev, &devlist, &numdevs);
|
|
|
|
|
|
|
|
cardattached = 0;
|
|
|
|
for (tmp = 0; tmp < numdevs; tmp++) {
|
|
|
|
if (device_get_state(devlist[tmp]) != DS_NOTPRESENT)
|
|
|
|
cardattached++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cardattached == 0)
|
|
|
|
POWER_ENABLE_SOCKET(bdev, dev);
|
|
|
|
DEVICE_IDENTIFY(driver, dev);
|
|
|
|
for (tmp = 0; tmp < numdevs; tmp++) {
|
|
|
|
if (device_get_state(devlist[tmp]) == DS_NOTPRESENT){
|
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
dinfo = device_get_ivars(devlist[tmp]);
|
|
|
|
resource_list_init(&dinfo->resources);
|
|
|
|
cardbus_add_resources(dinfo->cfg.dev, &dinfo->cfg);
|
|
|
|
cardbus_do_cis(dev, dinfo->cfg.dev);
|
|
|
|
if (device_probe_and_attach(dinfo->cfg.dev) != 0) {
|
|
|
|
cardbus_release_all_resources(dinfo->cfg.dev,
|
|
|
|
&dinfo->resources);
|
|
|
|
} else
|
|
|
|
cardattached++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (cardattached == 0)
|
|
|
|
POWER_DISABLE_SOCKET(bdev, dev);
|
2001-02-08 21:47:45 +00:00
|
|
|
free(devlist, M_TEMP);
|
2000-11-28 00:05:20 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* PCI-Like config reading (copied from pci.c */
|
|
|
|
/************************************************************************/
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/* read configuration header into pcicfgrect structure */
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static struct cardbus_devinfo *
|
|
|
|
cardbus_read_device(device_t pcib, int b, int s, int f)
|
|
|
|
{
|
|
|
|
#define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w)
|
|
|
|
pcicfgregs *cfg = NULL;
|
|
|
|
struct cardbus_devinfo *devlist_entry = NULL;
|
|
|
|
|
|
|
|
if (PCIB_READ_CONFIG(pcib, b, s, f, PCIR_DEVVENDOR, 4) != -1) {
|
|
|
|
devlist_entry = malloc(sizeof(struct cardbus_devinfo),
|
2000-11-27 23:55:19 +00:00
|
|
|
M_DEVBUF, M_WAITOK | M_ZERO);
|
2000-10-18 03:25:13 +00:00
|
|
|
if (devlist_entry == NULL)
|
|
|
|
return (NULL);
|
|
|
|
|
|
|
|
cfg = &devlist_entry->cfg;
|
2000-11-28 00:52:40 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
cfg->bus = b;
|
|
|
|
cfg->slot = s;
|
|
|
|
cfg->func = f;
|
|
|
|
cfg->vendor = REG(PCIR_VENDOR, 2);
|
|
|
|
cfg->device = REG(PCIR_DEVICE, 2);
|
|
|
|
cfg->cmdreg = REG(PCIR_COMMAND, 2);
|
|
|
|
cfg->statreg = REG(PCIR_STATUS, 2);
|
|
|
|
cfg->baseclass = REG(PCIR_CLASS, 1);
|
|
|
|
cfg->subclass = REG(PCIR_SUBCLASS, 1);
|
|
|
|
cfg->progif = REG(PCIR_PROGIF, 1);
|
|
|
|
cfg->revid = REG(PCIR_REVID, 1);
|
|
|
|
cfg->hdrtype = REG(PCIR_HEADERTYPE, 1);
|
|
|
|
cfg->cachelnsz = REG(PCIR_CACHELNSZ, 1);
|
|
|
|
cfg->lattimer = REG(PCIR_LATTIMER, 1);
|
|
|
|
cfg->intpin = REG(PCIR_INTPIN, 1);
|
|
|
|
cfg->intline = REG(PCIR_INTLINE, 1);
|
|
|
|
#ifdef __alpha__
|
|
|
|
alpha_platform_assign_pciintr(cfg);
|
|
|
|
#endif
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
#ifdef APIC_IO
|
|
|
|
if (cfg->intpin != 0) {
|
|
|
|
int airq;
|
|
|
|
|
|
|
|
airq = pci_apic_irq(cfg->bus, cfg->slot, cfg->intpin);
|
|
|
|
if (airq >= 0) {
|
|
|
|
/* PCI specific entry found in MP table */
|
|
|
|
if (airq != cfg->intline) {
|
|
|
|
undirect_pci_irq(cfg->intline);
|
|
|
|
cfg->intline = airq;
|
|
|
|
}
|
|
|
|
} else {
|
2001-01-06 18:04:55 +00:00
|
|
|
/*
|
2000-10-18 03:25:13 +00:00
|
|
|
* PCI interrupts might be redirected to the
|
|
|
|
* ISA bus according to some MP tables. Use the
|
|
|
|
* same methods as used by the ISA devices
|
|
|
|
* devices to find the proper IOAPIC int pin.
|
|
|
|
*/
|
|
|
|
airq = isa_apic_irq(cfg->intline);
|
|
|
|
if ((airq >= 0) && (airq != cfg->intline)) {
|
|
|
|
/* XXX: undirect_pci_irq() ? */
|
|
|
|
undirect_isa_irq(cfg->intline);
|
|
|
|
cfg->intline = airq;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif /* APIC_IO */
|
|
|
|
|
|
|
|
cfg->mingnt = REG(PCIR_MINGNT, 1);
|
|
|
|
cfg->maxlat = REG(PCIR_MAXLAT, 1);
|
|
|
|
|
|
|
|
cfg->mfdev = (cfg->hdrtype & PCIM_MFDEV) != 0;
|
|
|
|
cfg->hdrtype &= ~PCIM_MFDEV;
|
|
|
|
|
|
|
|
cardbus_hdrtypedata(pcib, b, s, f, cfg);
|
|
|
|
|
|
|
|
devlist_entry->conf.pc_sel.pc_bus = cfg->bus;
|
|
|
|
devlist_entry->conf.pc_sel.pc_dev = cfg->slot;
|
|
|
|
devlist_entry->conf.pc_sel.pc_func = cfg->func;
|
|
|
|
devlist_entry->conf.pc_hdr = cfg->hdrtype;
|
|
|
|
|
|
|
|
devlist_entry->conf.pc_subvendor = cfg->subvendor;
|
|
|
|
devlist_entry->conf.pc_subdevice = cfg->subdevice;
|
|
|
|
devlist_entry->conf.pc_vendor = cfg->vendor;
|
|
|
|
devlist_entry->conf.pc_device = cfg->device;
|
|
|
|
|
|
|
|
devlist_entry->conf.pc_class = cfg->baseclass;
|
|
|
|
devlist_entry->conf.pc_subclass = cfg->subclass;
|
|
|
|
devlist_entry->conf.pc_progif = cfg->progif;
|
|
|
|
devlist_entry->conf.pc_revid = cfg->revid;
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
return (devlist_entry);
|
|
|
|
#undef REG
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/* extract header type specific config data */
|
|
|
|
|
|
|
|
static void
|
|
|
|
cardbus_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg)
|
|
|
|
{
|
|
|
|
#define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w)
|
|
|
|
switch (cfg->hdrtype) {
|
|
|
|
case 0:
|
|
|
|
cfg->subvendor = REG(PCIR_SUBVEND_0, 2);
|
|
|
|
cfg->subdevice = REG(PCIR_SUBDEV_0, 2);
|
|
|
|
cfg->nummaps = PCI_MAXMAPS_0;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
cfg->subvendor = REG(PCIR_SUBVEND_1, 2);
|
|
|
|
cfg->subdevice = REG(PCIR_SUBDEV_1, 2);
|
|
|
|
cfg->nummaps = PCI_MAXMAPS_1;
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
cfg->subvendor = REG(PCIR_SUBVEND_2, 2);
|
|
|
|
cfg->subdevice = REG(PCIR_SUBDEV_2, 2);
|
|
|
|
cfg->nummaps = PCI_MAXMAPS_2;
|
|
|
|
break;
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
#undef REG
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/* free pcicfgregs structure and all depending data structures */
|
|
|
|
|
1999-11-18 07:21:51 +00:00
|
|
|
static int
|
2000-10-18 03:25:13 +00:00
|
|
|
cardbus_freecfg(struct cardbus_devinfo *dinfo)
|
|
|
|
{
|
|
|
|
free(dinfo, M_DEVBUF);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cardbus_print_verbose(struct cardbus_devinfo *dinfo)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
if (bootverbose) {
|
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
printf("found->\tvendor=0x%04x, dev=0x%04x, revid=0x%02x\n",
|
|
|
|
cfg->vendor, cfg->device, cfg->revid);
|
|
|
|
printf("\tclass=%02x-%02x-%02x, hdrtype=0x%02x, mfdev=%d\n",
|
|
|
|
cfg->baseclass, cfg->subclass, cfg->progif,
|
|
|
|
cfg->hdrtype, cfg->mfdev);
|
|
|
|
#ifdef CARDBUS_DEBUG
|
|
|
|
printf("\tcmdreg=0x%04x, statreg=0x%04x, cachelnsz=%d (dwords)\n",
|
|
|
|
cfg->cmdreg, cfg->statreg, cfg->cachelnsz);
|
|
|
|
printf("\tlattimer=0x%02x (%d ns), mingnt=0x%02x (%d ns), maxlat=0x%02x (%d ns)\n",
|
|
|
|
cfg->lattimer, cfg->lattimer * 30,
|
|
|
|
cfg->mingnt, cfg->mingnt * 250, cfg->maxlat, cfg->maxlat * 250);
|
|
|
|
#endif /* CARDBUS_DEBUG */
|
|
|
|
if (cfg->intpin > 0)
|
|
|
|
printf("\tintpin=%c, irq=%d\n", cfg->intpin +'a' -1, cfg->intline);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Resources */
|
|
|
|
/************************************************************************/
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_set_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_long start, u_long count)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
resource_list_add(rl, type, rid, start, start + count - 1, count);
|
|
|
|
if (device_get_parent(child) == dev)
|
|
|
|
pci_write_config(child, rid, start, 4);
|
1999-11-18 07:21:51 +00:00
|
|
|
return 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
cardbus_get_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_long *startp, u_long *countp)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (!rle)
|
|
|
|
return ENOENT;
|
|
|
|
if (startp)
|
|
|
|
*startp = rle->start;
|
|
|
|
if (countp)
|
|
|
|
*countp = rle->count;
|
1999-11-18 07:21:51 +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 void
|
|
|
|
cardbus_delete_resource(device_t dev, device_t child, int type, int rid)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
rle = resource_list_find(rl, type, rid);
|
|
|
|
if (rle) {
|
|
|
|
if (rle->res)
|
|
|
|
bus_generic_release_resource(dev, child, type, rid,
|
|
|
|
rle->res);
|
|
|
|
resource_list_delete(rl, type, rid);
|
|
|
|
}
|
|
|
|
if (device_get_parent(child) == dev)
|
|
|
|
pci_write_config(child, rid, 0, 4);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-10-18 03:25:13 +00:00
|
|
|
cardbus_set_resource_method(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_long start, u_long count)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
int ret;
|
|
|
|
ret = cardbus_set_resource(dev, child, type, rid, start, count);
|
|
|
|
if (ret != 0) return ret;
|
|
|
|
return BUS_SET_RESOURCE(device_get_parent(dev), child, type, rid,
|
|
|
|
start, count);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_get_resource_method(device_t dev, device_t child, int type, int rid,
|
|
|
|
u_long *startp, u_long *countp)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
int ret;
|
|
|
|
ret = cardbus_get_resource(dev, child, type, rid, startp, countp);
|
|
|
|
if (ret != 0) return ret;
|
|
|
|
return BUS_GET_RESOURCE(device_get_parent(dev), child, type, rid,
|
|
|
|
startp, countp);
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static void
|
|
|
|
cardbus_delete_resource_method(device_t dev, device_t child,
|
|
|
|
int type, int rid)
|
|
|
|
{
|
|
|
|
cardbus_delete_resource(dev, child, type, rid);
|
|
|
|
BUS_DELETE_RESOURCE(device_get_parent(dev), child, type, rid);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-11-28 00:52:40 +00:00
|
|
|
static int
|
2000-10-18 03:25:13 +00:00
|
|
|
cardbus_add_map(device_t cbdev, device_t dev, pcicfgregs *cfg, int reg)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(dev);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
struct resource_list_entry *rle;
|
2000-11-28 00:52:40 +00:00
|
|
|
struct resource *res;
|
2000-10-18 03:25:13 +00:00
|
|
|
device_t bdev = device_get_parent(cbdev);
|
|
|
|
u_int32_t size;
|
|
|
|
u_int32_t testval;
|
|
|
|
int type;
|
2000-11-28 00:52:40 +00:00
|
|
|
|
|
|
|
if (reg == CARDBUS_ROM_REG)
|
|
|
|
testval = CARDBUS_ROM_ADDRMASK;
|
|
|
|
else
|
|
|
|
testval = ~0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
PCIB_WRITE_CONFIG(bdev, cfg->bus, cfg->slot, cfg->func,
|
2000-11-28 00:52:40 +00:00
|
|
|
reg, testval, 4);
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
testval = PCIB_READ_CONFIG(bdev, cfg->bus, cfg->slot, cfg->func,
|
|
|
|
reg, 4);
|
2000-11-28 00:52:40 +00:00
|
|
|
if (testval == ~0 || testval == 0)
|
|
|
|
return 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
if ((testval&1) == 0)
|
|
|
|
type = SYS_RES_MEMORY;
|
|
|
|
else
|
|
|
|
type = SYS_RES_IOPORT;
|
|
|
|
|
|
|
|
size = CARDBUS_MAPREG_MEM_SIZE(testval);
|
|
|
|
res = bus_generic_alloc_resource(cbdev, dev, type, ®, 0, ~0, size,
|
|
|
|
rman_make_alignment_flags(size));
|
|
|
|
if (res) {
|
|
|
|
u_int32_t start = rman_get_start(res);
|
|
|
|
u_int32_t end = rman_get_end(res);
|
|
|
|
cardbus_set_resource(cbdev, dev, type, reg, start,end-start+1);
|
|
|
|
rle = resource_list_find(rl, type, reg);
|
|
|
|
rle->res = res;
|
|
|
|
} else {
|
|
|
|
device_printf(dev, "Unable to add map %02x\n", reg);
|
2000-11-28 00:52:40 +00:00
|
|
|
type = 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2000-11-28 00:52:40 +00:00
|
|
|
return type;
|
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 void
|
|
|
|
cardbus_add_resources(device_t dev, pcicfgregs* cfg)
|
|
|
|
{
|
|
|
|
device_t cbdev = device_get_parent(dev);
|
2000-11-28 00:52:40 +00:00
|
|
|
device_t bdev = device_get_parent(cbdev);
|
2000-10-18 03:25:13 +00:00
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(dev);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
struct cardbus_quirk *q;
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
struct resource *res;
|
2000-11-28 00:05:20 +00:00
|
|
|
int rid;
|
2000-11-28 00:52:40 +00:00
|
|
|
u_int command;
|
|
|
|
int type;
|
|
|
|
int types;
|
2000-10-18 03:25:13 +00:00
|
|
|
int i;
|
|
|
|
|
2000-11-28 00:52:40 +00:00
|
|
|
types = 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
for (i = 0; i < cfg->nummaps; i++) {
|
2000-11-28 00:52:40 +00:00
|
|
|
type = cardbus_add_map(cbdev, dev, cfg, PCIR_MAPS + i*4);
|
|
|
|
types |= 0x1 << type;
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
2000-11-28 00:52:40 +00:00
|
|
|
type = cardbus_add_map(cbdev, dev, cfg, CARDBUS_ROM_REG);
|
|
|
|
types |= 0x1 << type;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
for (q = &cardbus_quirks[0]; q->devid; q++) {
|
|
|
|
if (q->devid == ((cfg->device << 16) | cfg->vendor)
|
2000-11-28 00:52:40 +00:00
|
|
|
&& q->type == CARDBUS_QUIRK_MAP_REG) {
|
|
|
|
type = cardbus_add_map(cbdev, dev, cfg, q->arg1);
|
|
|
|
types |= 0x1 << type;
|
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
}
|
|
|
|
|
2000-11-28 00:52:40 +00:00
|
|
|
command = PCIB_READ_CONFIG(bdev, cfg->bus, cfg->slot,
|
|
|
|
cfg->func, PCIR_COMMAND, 2);
|
|
|
|
if ((types & (0x1 << SYS_RES_MEMORY)) != 0)
|
|
|
|
command |= PCIM_CMD_MEMEN;
|
|
|
|
if ((types & (0x1 << SYS_RES_IOPORT)) != 0)
|
|
|
|
command |= PCIM_CMD_PORTEN;
|
|
|
|
command |= PCIM_CMD_BUSMASTEREN;
|
|
|
|
PCIB_WRITE_CONFIG(bdev, cfg->bus, cfg->slot, cfg->func,
|
|
|
|
PCIR_COMMAND, command, 2);
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
rid = 0;
|
2000-10-18 03:25:13 +00:00
|
|
|
res = bus_generic_alloc_resource(cbdev, dev, SYS_RES_IRQ,
|
2000-11-28 00:05:20 +00:00
|
|
|
&rid, 0, ~0, 1, RF_SHAREABLE);
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
if (res == NULL)
|
|
|
|
panic("Cannot allocate IRQ for card\n");
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
resource_list_add(rl, SYS_RES_IRQ, rid,
|
2000-10-18 03:25:13 +00:00
|
|
|
rman_get_start(res), rman_get_start(res), 1);
|
2000-11-28 00:05:20 +00:00
|
|
|
rle = resource_list_find(rl, SYS_RES_IRQ, rid);
|
2000-10-18 03:25:13 +00:00
|
|
|
rle->res = res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cardbus_release_all_resources(device_t dev, struct resource_list *rl)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
|
|
|
|
SLIST_FOREACH(rle, rl, link) {
|
|
|
|
if (rle->res) {
|
|
|
|
bus_generic_release_resource(device_get_parent(dev),
|
|
|
|
dev, rle->type, rle->rid,
|
|
|
|
rle->res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static struct resource*
|
|
|
|
cardbus_alloc_resource(device_t self, device_t child, int type,
|
2000-10-18 03:25:13 +00:00
|
|
|
int* rid, u_long start, u_long end,
|
|
|
|
u_long count, u_int flags)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
struct resource_list *rl = &dinfo->resources;
|
|
|
|
struct resource_list_entry *rle = NULL;
|
|
|
|
struct resource *res;
|
|
|
|
|
|
|
|
if (device_get_parent(child) == self || child == self)
|
|
|
|
rle = resource_list_find(rl, type, *rid);
|
|
|
|
if (rle) {
|
2000-11-28 00:52:40 +00:00
|
|
|
if (flags & RF_ACTIVE) {
|
2001-01-06 18:04:55 +00:00
|
|
|
if (bus_activate_resource(child, rle->type, *rid,
|
2000-10-18 03:25:13 +00:00
|
|
|
rle->res)) {
|
|
|
|
return NULL;
|
|
|
|
}
|
2000-11-28 00:52:40 +00:00
|
|
|
if (*rid == CARDBUS_ROM_REG) {
|
|
|
|
uint32_t rom_reg;
|
|
|
|
|
|
|
|
rom_reg = pci_read_config(child, *rid, 4);
|
|
|
|
rom_reg |= CARDBUS_ROM_ENABLE;
|
|
|
|
pci_write_config(child, *rid, rom_reg, 4);
|
|
|
|
}
|
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
return rle->res; /* XXX: check if range within start/end */
|
|
|
|
} else {
|
|
|
|
res = bus_generic_alloc_resource(self, child, type, rid,
|
|
|
|
start, end, count, flags);
|
|
|
|
if (res) {
|
|
|
|
start = rman_get_start(res);
|
|
|
|
end = rman_get_end(res);
|
|
|
|
cardbus_set_resource(self, child, type, *rid, start,
|
|
|
|
end-start+1);
|
|
|
|
rle = resource_list_find(rl, type, *rid);
|
|
|
|
rle->res = res;
|
|
|
|
return res;
|
|
|
|
} else {
|
|
|
|
device_printf(self, "Resource Allocation Failed!\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2000-10-18 03:25:13 +00:00
|
|
|
cardbus_release_resource(device_t dev, device_t child, int type, int rid,
|
|
|
|
struct resource *r)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-11-28 00:52:40 +00:00
|
|
|
/*
|
|
|
|
* According to the PCI 2.2 spec, devices may share an address
|
|
|
|
* decoder between memory mapped ROM access and memory
|
|
|
|
* mapped register access. To be safe, disable ROM access
|
|
|
|
* whenever it is released.
|
|
|
|
*/
|
|
|
|
if (rid == CARDBUS_ROM_REG) {
|
|
|
|
uint32_t rom_reg;
|
|
|
|
|
|
|
|
rom_reg = pci_read_config(child, rid, 4);
|
|
|
|
rom_reg &= ~CARDBUS_ROM_ENABLE;
|
|
|
|
pci_write_config(child, rid, rom_reg, 4);
|
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
return bus_deactivate_resource(child, type, rid, r);
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
/************************************************************************/
|
|
|
|
/* Other Bus Methods */
|
|
|
|
/************************************************************************/
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_print_resources(struct resource_list *rl, const char *name,
|
|
|
|
int type, const char *format)
|
|
|
|
{
|
|
|
|
struct resource_list_entry *rle;
|
|
|
|
int printed, retval;
|
|
|
|
|
|
|
|
printed = 0;
|
|
|
|
retval = 0;
|
|
|
|
/* Yes, this is kinda cheating */
|
|
|
|
SLIST_FOREACH(rle, rl, link) {
|
|
|
|
if (rle->type == type) {
|
|
|
|
if (printed == 0)
|
|
|
|
retval += printf(" %s ", name);
|
|
|
|
else if (printed > 0)
|
|
|
|
retval += printf(",");
|
|
|
|
printed++;
|
|
|
|
retval += printf(format, rle->start);
|
|
|
|
if (rle->count > 1) {
|
|
|
|
retval += printf("-");
|
|
|
|
retval += printf(format, rle->start +
|
|
|
|
rle->count - 1);
|
|
|
|
}
|
|
|
|
}
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
return retval;
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_print_child(device_t dev, device_t child)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
struct resource_list *rl;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
int retval = 0;
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
rl = &dinfo->resources;
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
retval += bus_print_child_header(dev, child);
|
1999-11-18 07:21:51 +00:00
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
retval += cardbus_print_resources(rl, "port", SYS_RES_IOPORT, "%#lx");
|
|
|
|
retval += cardbus_print_resources(rl, "mem", SYS_RES_MEMORY, "%#lx");
|
|
|
|
retval += cardbus_print_resources(rl, "irq", SYS_RES_IRQ, "%ld");
|
|
|
|
if (device_get_flags(dev))
|
|
|
|
retval += printf(" flags %#x", device_get_flags(dev));
|
|
|
|
|
|
|
|
retval += printf(" at device %d.%d", pci_get_slot(child),
|
|
|
|
pci_get_function(child));
|
|
|
|
|
|
|
|
retval += bus_print_child_footer(dev, child);
|
|
|
|
|
|
|
|
return (retval);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void cardbus_probe_nomatch(device_t dev, device_t child) {
|
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
device_printf(dev, "<unknown card>");
|
|
|
|
printf(" (vendor=0x%04x, dev=0x%04x)", cfg->vendor, cfg->device);
|
|
|
|
printf(" at %d.%d", pci_get_slot(child), pci_get_function(child));
|
|
|
|
if (cfg->intpin > 0 && cfg->intline != 255) {
|
|
|
|
printf(" irq %d", cfg->intline);
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
return;
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
|
|
|
|
2000-10-18 03:25:13 +00:00
|
|
|
static int
|
|
|
|
cardbus_read_ivar(device_t dev, device_t child, int which, u_long *result)
|
1999-11-18 07:21:51 +00:00
|
|
|
{
|
2000-10-18 03:25:13 +00:00
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
case PCI_IVAR_SUBVENDOR:
|
|
|
|
*result = cfg->subvendor;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_SUBDEVICE:
|
|
|
|
*result = cfg->subdevice;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_VENDOR:
|
|
|
|
*result = cfg->vendor;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_DEVICE:
|
|
|
|
*result = cfg->device;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_DEVID:
|
|
|
|
*result = (cfg->device << 16) | cfg->vendor;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_CLASS:
|
|
|
|
*result = cfg->baseclass;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_SUBCLASS:
|
|
|
|
*result = cfg->subclass;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_PROGIF:
|
|
|
|
*result = cfg->progif;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_REVID:
|
|
|
|
*result = cfg->revid;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_INTPIN:
|
|
|
|
*result = cfg->intpin;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_IRQ:
|
|
|
|
*result = cfg->intline;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_BUS:
|
|
|
|
*result = cfg->bus;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_SLOT:
|
|
|
|
*result = cfg->slot;
|
|
|
|
break;
|
|
|
|
case PCI_IVAR_FUNCTION:
|
|
|
|
*result = cfg->func;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
return 0;
|
1999-11-18 07:21:51 +00:00
|
|
|
}
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
static int
|
|
|
|
cardbus_write_ivar(device_t dev, device_t child, int which, uintptr_t value)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo;
|
|
|
|
pcicfgregs *cfg;
|
|
|
|
|
|
|
|
dinfo = device_get_ivars(child);
|
|
|
|
cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
switch (which) {
|
|
|
|
case PCI_IVAR_SUBVENDOR:
|
|
|
|
case PCI_IVAR_SUBDEVICE:
|
|
|
|
case PCI_IVAR_VENDOR:
|
|
|
|
case PCI_IVAR_DEVICE:
|
|
|
|
case PCI_IVAR_DEVID:
|
|
|
|
case PCI_IVAR_CLASS:
|
|
|
|
case PCI_IVAR_SUBCLASS:
|
|
|
|
case PCI_IVAR_PROGIF:
|
|
|
|
case PCI_IVAR_REVID:
|
|
|
|
case PCI_IVAR_INTPIN:
|
|
|
|
case PCI_IVAR_IRQ:
|
|
|
|
case PCI_IVAR_BUS:
|
|
|
|
case PCI_IVAR_SLOT:
|
|
|
|
case PCI_IVAR_FUNCTION:
|
|
|
|
return EINVAL; /* disallow for now */
|
|
|
|
default:
|
|
|
|
return ENOENT;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
/* Compatibility with PCI bus (XXX: Do we need this?) */
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static u_int32_t
|
|
|
|
cardbus_read_config_method(device_t dev, device_t child, int reg, int width)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
return PCIB_READ_CONFIG(device_get_parent(dev),
|
|
|
|
cfg->bus, cfg->slot, cfg->func,
|
|
|
|
reg, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
cardbus_write_config_method(device_t dev, device_t child, int reg,
|
|
|
|
u_int32_t val, int width)
|
|
|
|
{
|
|
|
|
struct cardbus_devinfo *dinfo = device_get_ivars(child);
|
|
|
|
pcicfgregs *cfg = &dinfo->cfg;
|
|
|
|
|
|
|
|
PCIB_WRITE_CONFIG(device_get_parent(dev),
|
|
|
|
cfg->bus, cfg->slot, cfg->func,
|
|
|
|
reg, val, width);
|
|
|
|
}
|
|
|
|
|
|
|
|
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),
|
2000-10-18 03:25:13 +00:00
|
|
|
DEVMETHOD(device_shutdown, bus_generic_shutdown),
|
|
|
|
DEVMETHOD(device_suspend, bus_generic_suspend),
|
|
|
|
DEVMETHOD(device_resume, bus_generic_resume),
|
|
|
|
|
|
|
|
/* Bus interface */
|
|
|
|
DEVMETHOD(bus_print_child, cardbus_print_child),
|
|
|
|
DEVMETHOD(bus_probe_nomatch, cardbus_probe_nomatch),
|
|
|
|
DEVMETHOD(bus_read_ivar, cardbus_read_ivar),
|
|
|
|
DEVMETHOD(bus_write_ivar, cardbus_write_ivar),
|
2000-11-28 00:05:20 +00:00
|
|
|
DEVMETHOD(bus_driver_added, cardbus_driver_added),
|
2000-10-18 03:25:13 +00:00
|
|
|
DEVMETHOD(bus_alloc_resource, cardbus_alloc_resource),
|
|
|
|
DEVMETHOD(bus_release_resource, cardbus_release_resource),
|
|
|
|
DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
|
|
|
|
DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
|
|
|
|
DEVMETHOD(bus_setup_intr, bus_generic_setup_intr),
|
|
|
|
DEVMETHOD(bus_teardown_intr, bus_generic_teardown_intr),
|
2000-11-28 00:05:20 +00:00
|
|
|
DEVMETHOD(bus_driver_added, bus_generic_driver_added),
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
DEVMETHOD(bus_set_resource, cardbus_set_resource_method),
|
|
|
|
DEVMETHOD(bus_get_resource, cardbus_get_resource_method),
|
|
|
|
DEVMETHOD(bus_delete_resource, cardbus_delete_resource_method),
|
|
|
|
|
|
|
|
/* Card Interface */
|
|
|
|
DEVMETHOD(card_attach_card, cardbus_attach_card),
|
|
|
|
DEVMETHOD(card_detach_card, cardbus_detach_card),
|
2001-01-06 18:04:55 +00:00
|
|
|
DEVMETHOD(card_cis_read, cardbus_cis_read),
|
|
|
|
DEVMETHOD(card_cis_free, cardbus_cis_free),
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
/* Cardbus/PCI interface */
|
|
|
|
DEVMETHOD(pci_read_config, cardbus_read_config_method),
|
|
|
|
DEVMETHOD(pci_write_config, cardbus_write_config_method),
|
|
|
|
|
|
|
|
{0,0}
|
|
|
|
};
|
|
|
|
|
|
|
|
static driver_t cardbus_driver = {
|
|
|
|
"cardbus",
|
|
|
|
cardbus_methods,
|
|
|
|
0 /* no softc */
|
|
|
|
};
|
|
|
|
|
2000-11-28 00:05:20 +00:00
|
|
|
static devclass_t cardbus_devclass;
|
2000-10-18 03:25:13 +00:00
|
|
|
|
|
|
|
DRIVER_MODULE(cardbus, pccbb, cardbus_driver, cardbus_devclass, 0, 0);
|
2001-01-06 18:04:55 +00:00
|
|
|
/*
|
2000-11-28 00:05:20 +00:00
|
|
|
MODULE_DEPEND(cardbus, pccbb, 1, 1, 1);
|
2001-01-06 18:04:55 +00:00
|
|
|
*/
|