diff options
author | jon <jon@FreeBSD.org> | 2001-08-26 23:55:34 +0000 |
---|---|---|
committer | jon <jon@FreeBSD.org> | 2001-08-26 23:55:34 +0000 |
commit | 1d2b5256d039caced9236ccd6ee9226e6873c431 (patch) | |
tree | 6a287bc4653fa2f4a89610297e17c51f2ca9090a /sys/dev/cardbus | |
parent | bdc326b1fd4b05028ba5fe876d55183b398d81c6 (diff) | |
download | FreeBSD-src-1d2b5256d039caced9236ccd6ee9226e6873c431.zip FreeBSD-src-1d2b5256d039caced9236ccd6ee9226e6873c431.tar.gz |
Non-functional changes to NEWCARD stuff.
This is the first part of a two-part update to NEWCARD. Changes in this
commit are non-functional, and includes the following:
* indentation and other changes to meet style(9).
* other minor style consistancy changes
* addition of comments
* renaming of device_t variables to be consistant across all of NEWCARD.
(note that not all style violations are fixed in this commit -- those that
aren't will be clobbered by the next commit.)
Diffstat (limited to 'sys/dev/cardbus')
-rw-r--r-- | sys/dev/cardbus/cardbus.c | 374 | ||||
-rw-r--r-- | sys/dev/cardbus/cardbus_cis.c | 261 | ||||
-rw-r--r-- | sys/dev/cardbus/cardbus_cis.h | 120 | ||||
-rw-r--r-- | sys/dev/cardbus/cardbusreg.h | 82 | ||||
-rw-r--r-- | sys/dev/cardbus/cardbusvar.h | 6 |
5 files changed, 429 insertions, 414 deletions
diff --git a/sys/dev/cardbus/cardbus.c b/sys/dev/cardbus/cardbus.c index f9527b9..02150b6 100644 --- a/sys/dev/cardbus/cardbus.c +++ b/sys/dev/cardbus/cardbus.c @@ -37,7 +37,7 @@ * Written by Jonathan Chen <jon@freebsd.org> */ -#define CARDBUS_DEBUG +#define CARDBUS_DEBUG #include <sys/param.h> #include <sys/systm.h> @@ -62,24 +62,22 @@ #include "pcib_if.h" #if defined CARDBUS_DEBUG -#define STATIC -#define DPRINTF(a) printf a -#define DEVPRINTF(x) device_printf x +#define DPRINTF(a) printf a +#define DEVPRINTF(x) device_printf x #else -#define STATIC static -#define DPRINTF(a) -#define DEVPRINTF(x) +#define DPRINTF(a) +#define DEVPRINTF(x) #endif #if !defined(lint) static const char rcsid[] = - "$FreeBSD$"; + "$FreeBSD$"; #endif struct cardbus_quirk { u_int32_t devid; /* Vendor/device of the card */ int type; -#define CARDBUS_QUIRK_MAP_REG 1 /* PCI map register in weird place */ +#define CARDBUS_QUIRK_MAP_REG 1 /* PCI map register in weird place */ int arg1; int arg2; }; @@ -88,73 +86,76 @@ struct cardbus_quirk cardbus_quirks[] = { { 0 } }; -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); -static int cardbus_add_map(device_t bdev, device_t dev, pcicfgregs *cfg, - int reg); -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); +static int cardbus_probe(device_t cbdev); +static int cardbus_attach(device_t cbdev); +static int cardbus_detach(device_t cbdev); +static void device_setup_regs(device_t brdev, int b, int s, int f, + pcicfgregs *cfg); +static int cardbus_attach_card(device_t cbdev); +static int cardbus_detach_card(device_t cbdev, int flags); +static void cardbus_driver_added(device_t cbdev, driver_t *driver); +static struct cardbus_devinfo * cardbus_read_device(device_t brdev, int b, + int s, int f); +static void cardbus_hdrtypedata(device_t brdev, 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 cbdev, device_t child, int type, + int rid, u_long start, u_long count); +static int cardbus_get_resource(device_t cbdev, device_t child, int type, + int rid, u_long *startp, u_long *countp); +static void cardbus_delete_resource(device_t cbdev, device_t child, + int type, int rid); +static int cardbus_set_resource_method(device_t cbdev, device_t child, + int type, int rid, u_long start, u_long count); +static int cardbus_get_resource_method(device_t cbdev, device_t child, + int type, int rid, u_long *startp, u_long *countp); +static void cardbus_delete_resource_method(device_t cbdev, device_t child, + int type, int rid); +static int cardbus_add_map(device_t cbdev, device_t dev, pcicfgregs *cfg, + int reg); +static void cardbus_add_resources(device_t dev, pcicfgregs* cfg); +static void cardbus_release_all_resources(device_t cbdev, + struct resource_list *rl); +static struct resource* cardbus_alloc_resource(device_t cbdev, 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 cbdev, 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 cbdev, device_t child); +static void cardbus_probe_nomatch(device_t cbdev, device_t child); +static int cardbus_read_ivar(device_t cbdev, device_t child, int which, + u_long *result); +static int cardbus_write_ivar(device_t cbdev, device_t child, int which, + uintptr_t value); +static u_int32_t cardbus_read_config_method(device_t cbdev, + device_t child, int reg, int width); +static void cardbus_write_config_method(device_t cbdev, device_t child, + int reg, u_int32_t val, int width); /************************************************************************/ /* Probe/Attach */ /************************************************************************/ static int -cardbus_probe(device_t dev) +cardbus_probe(device_t cbdev) { - device_set_desc(dev, "Cardbus bus (newcard)"); + device_set_desc(cbdev, "Cardbus bus (newcard)"); return 0; } static int -cardbus_attach(device_t dev) +cardbus_attach(device_t cbdev) { return 0; } static int -cardbus_detach(device_t dev) +cardbus_detach(device_t cbdev) { - cardbus_detach_card(dev, DETACH_FORCE); + cardbus_detach_card(cbdev, DETACH_FORCE); return 0; } @@ -163,37 +164,37 @@ cardbus_detach(device_t dev) /************************************************************************/ static void -device_setup_regs(device_t bdev, int b, int s, int f, pcicfgregs *cfg) +device_setup_regs(device_t brdev, int b, int s, int f, pcicfgregs *cfg) { - 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); + PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_INTLINE, + pci_get_irq(device_get_parent(brdev)), 1); + cfg->intline = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_INTLINE, 1); - 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(brdev, b, s, f, PCIR_CACHELNSZ, 0x08, 1); + cfg->cachelnsz = PCIB_READ_CONFIG(brdev, 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(brdev, b, s, f, PCIR_LATTIMER, 0xa8, 1); + cfg->lattimer = PCIB_READ_CONFIG(brdev, 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(brdev, b, s, f, PCIR_MINGNT, 0x14, 1); + cfg->mingnt = PCIB_READ_CONFIG(brdev, 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); + PCIB_WRITE_CONFIG(brdev, b, s, f, PCIR_MAXLAT, 0x14, 1); + cfg->maxlat = PCIB_READ_CONFIG(brdev, b, s, f, PCIR_MAXLAT, 1); } static int -cardbus_attach_card(device_t dev) +cardbus_attach_card(device_t cbdev) { - device_t bdev = device_get_parent(dev); + device_t brdev = device_get_parent(cbdev); int cardattached = 0; static int curr_bus_number = 2; /* XXX EVILE BAD (see below) */ int bus, slot, func; - cardbus_detach_card(dev, DETACH_NOWARN); /* detach existing cards */ + cardbus_detach_card(cbdev, DETACH_NOWARN); /* detach existing cards */ - POWER_ENABLE_SOCKET(bdev, dev); - bus = pcib_get_bus(dev); + POWER_ENABLE_SOCKET(brdev, cbdev); + bus = pcib_get_bus(cbdev); if (bus == 0) { /* * XXX EVILE BAD XXX @@ -202,58 +203,62 @@ cardbus_attach_card(device_t dev) * 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); + pci_write_config(brdev, PCIR_SECBUS_2, curr_bus_number, 1); + pci_write_config(brdev, PCIR_SUBBUS_2, curr_bus_number + 2, 1); curr_bus_number += 3; } + /* For each function, set it up and try to attach a driver to it */ 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); + cardbus_read_device(brdev, bus, slot, func); - if (dinfo == NULL) continue; + if (dinfo == NULL) + continue; if (dinfo->cfg.mfdev) cardbusfunchigh = CARDBUS_FUNCMAX; - device_setup_regs(bdev, bus, slot, func, &dinfo->cfg); + device_setup_regs(brdev, bus, slot, func, &dinfo->cfg); cardbus_print_verbose(dinfo); - dinfo->cfg.dev = device_add_child(dev, NULL, -1); + dinfo->cfg.dev = device_add_child(cbdev, NULL, -1); if (!dinfo->cfg.dev) { - DEVPRINTF((dev, "Cannot add child!\n")); + DEVPRINTF((cbdev, "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); + cardbus_do_cis(cbdev, dinfo->cfg.dev); if (device_probe_and_attach(dinfo->cfg.dev) != 0) { + /* when fail, release all resources */ cardbus_release_all_resources(dinfo->cfg.dev, - &dinfo->resources); + &dinfo->resources); } else cardattached++; } } - if (cardattached > 0) return 0; - POWER_DISABLE_SOCKET(bdev, dev); + if (cardattached > 0) + return 0; + POWER_DISABLE_SOCKET(brdev, cbdev); return ENOENT; } static int -cardbus_detach_card(device_t dev, int flags) +cardbus_detach_card(device_t cbdev, int flags) { int numdevs; device_t *devlist; int tmp; - int err=0; + int err = 0; - device_get_children(dev, &devlist, &numdevs); + device_get_children(cbdev, &devlist, &numdevs); if (numdevs == 0) { if (!(flags & DETACH_NOWARN)) { - DEVPRINTF((dev, "Detaching card: no cards to detach!\n")); - POWER_DISABLE_SOCKET(device_get_parent(dev), dev); + DEVPRINTF((cbdev, "detach_card: no card to detach!\n")); + POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev); } free(devlist, M_TEMP); return ENOENT; @@ -265,33 +270,33 @@ cardbus_detach_card(device_t dev, int flags) if (status == DS_ATTACHED || status == DS_BUSY) { if (device_detach(dinfo->cfg.dev) == 0 || - flags & DETACH_FORCE){ + flags & DETACH_FORCE) { cardbus_release_all_resources(dinfo->cfg.dev, - &dinfo->resources); - device_delete_child(dev, devlist[tmp]); + &dinfo->resources); + device_delete_child(cbdev, devlist[tmp]); } else { err++; } cardbus_freecfg(dinfo); } else { - device_delete_child(dev, devlist[tmp]); + device_delete_child(cbdev, devlist[tmp]); } } if (err == 0) - POWER_DISABLE_SOCKET(device_get_parent(dev), dev); + POWER_DISABLE_SOCKET(device_get_parent(cbdev), cbdev); free(devlist, M_TEMP); return err; } static void -cardbus_driver_added(device_t dev, driver_t *driver) +cardbus_driver_added(device_t cbdev, driver_t *driver) { int numdevs; device_t *devlist; - device_t bdev = device_get_parent(dev); + device_t brdev = device_get_parent(cbdev); int tmp, cardattached; - device_get_children(dev, &devlist, &numdevs); + device_get_children(cbdev, &devlist, &numdevs); cardattached = 0; for (tmp = 0; tmp < numdevs; tmp++) { @@ -300,25 +305,25 @@ cardbus_driver_added(device_t dev, driver_t *driver) } if (cardattached == 0) - POWER_ENABLE_SOCKET(bdev, dev); - DEVICE_IDENTIFY(driver, dev); + POWER_ENABLE_SOCKET(brdev, cbdev); + DEVICE_IDENTIFY(driver, cbdev); for (tmp = 0; tmp < numdevs; tmp++) { - if (device_get_state(devlist[tmp]) == DS_NOTPRESENT){ + 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); + cardbus_do_cis(cbdev, dinfo->cfg.dev); if (device_probe_and_attach(dinfo->cfg.dev) != 0) { cardbus_release_all_resources(dinfo->cfg.dev, - &dinfo->resources); + &dinfo->resources); } else cardattached++; } } if (cardattached == 0) - POWER_DISABLE_SOCKET(bdev, dev); + POWER_DISABLE_SOCKET(brdev, cbdev); free(devlist, M_TEMP); } @@ -329,15 +334,15 @@ cardbus_driver_added(device_t dev, driver_t *driver) /* read configuration header into pcicfgrect structure */ static struct cardbus_devinfo * -cardbus_read_device(device_t pcib, int b, int s, int f) +cardbus_read_device(device_t brdev, int b, int s, int f) { -#define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w) +#define REG(n, w) PCIB_READ_CONFIG(brdev, 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) { + if (PCIB_READ_CONFIG(brdev, b, s, f, PCIR_DEVVENDOR, 4) != -1) { devlist_entry = malloc(sizeof(struct cardbus_devinfo), - M_DEVBUF, M_WAITOK | M_ZERO); + M_DEVBUF, M_WAITOK | M_ZERO); if (devlist_entry == NULL) return (NULL); @@ -397,7 +402,7 @@ cardbus_read_device(device_t pcib, int b, int s, int f) cfg->mfdev = (cfg->hdrtype & PCIM_MFDEV) != 0; cfg->hdrtype &= ~PCIM_MFDEV; - cardbus_hdrtypedata(pcib, b, s, f, cfg); + cardbus_hdrtypedata(brdev, b, s, f, cfg); devlist_entry->conf.pc_sel.pc_bus = cfg->bus; devlist_entry->conf.pc_sel.pc_dev = cfg->slot; @@ -415,15 +420,15 @@ cardbus_read_device(device_t pcib, int b, int s, int f) devlist_entry->conf.pc_revid = cfg->revid; } return (devlist_entry); -#undef REG +#undef REG } /* extract header type specific config data */ static void -cardbus_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg) +cardbus_hdrtypedata(device_t brdev, int b, int s, int f, pcicfgregs *cfg) { -#define REG(n, w) PCIB_READ_CONFIG(pcib, b, s, f, n, w) +#define REG(n, w) PCIB_READ_CONFIG(brdev, b, s, f, n, w) switch (cfg->hdrtype) { case 0: cfg->subvendor = REG(PCIR_SUBVEND_0, 2); @@ -441,7 +446,7 @@ cardbus_hdrtypedata(device_t pcib, int b, int s, int f, pcicfgregs *cfg) cfg->nummaps = PCI_MAXMAPS_2; break; } -#undef REG +#undef REG } /* free pcicfgregs structure and all depending data structures */ @@ -461,19 +466,23 @@ cardbus_print_verbose(struct cardbus_devinfo *dinfo) pcicfgregs *cfg = &dinfo->cfg; printf("found->\tvendor=0x%04x, dev=0x%04x, revid=0x%02x\n", - cfg->vendor, cfg->device, cfg->revid); + 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); + 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); + 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); + printf("\tintpin=%c, irq=%d\n", + cfg->intpin + 'a' - 1, cfg->intline); } } @@ -482,20 +491,20 @@ 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) +cardbus_set_resource(device_t cbdev, 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) + if (device_get_parent(child) == cbdev) pci_write_config(child, rid, start, 4); return 0; } static int -cardbus_get_resource(device_t dev, device_t child, int type, int rid, - u_long *startp, u_long *countp) +cardbus_get_resource(device_t cbdev, 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; @@ -511,7 +520,7 @@ cardbus_get_resource(device_t dev, device_t child, int type, int rid, } static void -cardbus_delete_resource(device_t dev, device_t child, int type, int rid) +cardbus_delete_resource(device_t cbdev, device_t child, int type, int rid) { struct cardbus_devinfo *dinfo = device_get_ivars(child); struct resource_list *rl = &dinfo->resources; @@ -519,42 +528,44 @@ cardbus_delete_resource(device_t dev, device_t child, int type, int rid) rle = resource_list_find(rl, type, rid); if (rle) { if (rle->res) - bus_generic_release_resource(dev, child, type, rid, - rle->res); + bus_generic_release_resource(cbdev, child, type, rid, + rle->res); resource_list_delete(rl, type, rid); } - if (device_get_parent(child) == dev) + if (device_get_parent(child) == cbdev) pci_write_config(child, rid, 0, 4); } static int -cardbus_set_resource_method(device_t dev, device_t child, int type, int rid, - u_long start, u_long count) +cardbus_set_resource_method(device_t cbdev, device_t child, int type, int rid, + u_long start, u_long count) { 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); + ret = cardbus_set_resource(cbdev, child, type, rid, start, count); + if (ret != 0) + return ret; + return BUS_SET_RESOURCE(device_get_parent(cbdev), child, type, rid, + start, count); } static int -cardbus_get_resource_method(device_t dev, device_t child, int type, int rid, - u_long *startp, u_long *countp) +cardbus_get_resource_method(device_t cbdev, device_t child, int type, int rid, + u_long *startp, u_long *countp) { 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); + ret = cardbus_get_resource(cbdev, child, type, rid, startp, countp); + if (ret != 0) + return ret; + return BUS_GET_RESOURCE(device_get_parent(cbdev), child, type, rid, + startp, countp); } static void -cardbus_delete_resource_method(device_t dev, device_t child, - int type, int rid) +cardbus_delete_resource_method(device_t cbdev, device_t child, + int type, int rid) { - cardbus_delete_resource(dev, child, type, rid); - BUS_DELETE_RESOURCE(device_get_parent(dev), child, type, rid); + cardbus_delete_resource(cbdev, child, type, rid); + BUS_DELETE_RESOURCE(device_get_parent(cbdev), child, type, rid); } static int @@ -659,30 +670,29 @@ cardbus_add_resources(device_t dev, pcicfgregs* cfg) } static void -cardbus_release_all_resources(device_t dev, struct resource_list *rl) +cardbus_release_all_resources(device_t cbdev, 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, + bus_generic_release_resource(device_get_parent(cbdev), + cbdev, rle->type, rle->rid, rle->res); } } } 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) +cardbus_alloc_resource(device_t cbdev, device_t child, int type, + 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) + if (device_get_parent(child) == cbdev || child == cbdev) rle = resource_list_find(rl, type, *rid); if (rle) { if (flags & RF_ACTIVE) { @@ -700,26 +710,26 @@ cardbus_alloc_resource(device_t self, device_t child, int type, } return rle->res; /* XXX: check if range within start/end */ } else { - res = bus_generic_alloc_resource(self, child, type, rid, + res = bus_generic_alloc_resource(cbdev, 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, + cardbus_set_resource(cbdev, 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"); + device_printf(cbdev, "Resource Allocation Failed!\n"); return NULL; } } } static int -cardbus_release_resource(device_t dev, device_t child, int type, int rid, - struct resource *r) +cardbus_release_resource(device_t cbdev, device_t child, int type, int rid, + struct resource *r) { /* * According to the PCI 2.2 spec, devices may share an address @@ -744,7 +754,7 @@ cardbus_release_resource(device_t dev, device_t child, int type, int rid, static int cardbus_print_resources(struct resource_list *rl, const char *name, - int type, const char *format) + int type, const char *format) { struct resource_list_entry *rle; int printed, retval; @@ -763,7 +773,7 @@ cardbus_print_resources(struct resource_list *rl, const char *name, if (rle->count > 1) { retval += printf("-"); retval += printf(format, rle->start + - rle->count - 1); + rle->count - 1); } } } @@ -771,7 +781,7 @@ cardbus_print_resources(struct resource_list *rl, const char *name, } static int -cardbus_print_child(device_t dev, device_t child) +cardbus_print_child(device_t cbdev, device_t child) { struct cardbus_devinfo *dinfo; struct resource_list *rl; @@ -782,29 +792,31 @@ cardbus_print_child(device_t dev, device_t child) cfg = &dinfo->cfg; rl = &dinfo->resources; - retval += bus_print_child_header(dev, child); + retval += bus_print_child_header(cbdev, child); 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)); + if (device_get_flags(cbdev)) + retval += printf(" flags %#x", device_get_flags(cbdev)); retval += printf(" at device %d.%d", pci_get_slot(child), - pci_get_function(child)); + pci_get_function(child)); - retval += bus_print_child_footer(dev, child); + retval += bus_print_child_footer(cbdev, child); return (retval); } -static void cardbus_probe_nomatch(device_t dev, device_t child) { +static void +cardbus_probe_nomatch(device_t cbdev, device_t child) +{ struct cardbus_devinfo *dinfo; pcicfgregs *cfg; dinfo = device_get_ivars(child); cfg = &dinfo->cfg; - device_printf(dev, "<unknown card>"); + device_printf(cbdev, "<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) { @@ -816,7 +828,7 @@ 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) +cardbus_read_ivar(device_t cbdev, device_t child, int which, u_long *result) { struct cardbus_devinfo *dinfo; pcicfgregs *cfg; @@ -874,7 +886,7 @@ 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) +cardbus_write_ivar(device_t cbdev, device_t child, int which, uintptr_t value) { struct cardbus_devinfo *dinfo; pcicfgregs *cfg; @@ -909,26 +921,24 @@ 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) +cardbus_read_config_method(device_t cbdev, 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); + return PCIB_READ_CONFIG(device_get_parent(cbdev), + 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) +cardbus_write_config_method(device_t cbdev, 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); + PCIB_WRITE_CONFIG(device_get_parent(cbdev), + cfg->bus, cfg->slot, cfg->func, reg, val, width); } static device_method_t cardbus_methods[] = { diff --git a/sys/dev/cardbus/cardbus_cis.c b/sys/dev/cardbus/cardbus_cis.c index 492b5ce..883beb8 100644 --- a/sys/dev/cardbus/cardbus_cis.c +++ b/sys/dev/cardbus/cardbus_cis.c @@ -32,7 +32,7 @@ * CIS Handling for the Cardbus Bus */ -#define CARDBUS_DEBUG +#define CARDBUS_DEBUG #include <sys/param.h> #include <sys/systm.h> @@ -52,65 +52,62 @@ #include "card_if.h" #if defined CARDBUS_DEBUG -#define STATIC -#define DPRINTF(a) printf a -#define DEVPRINTF(x) device_printf x +#define DPRINTF(a) printf a +#define DEVPRINTF(x) device_printf x #else -#define STATIC static -#define DPRINTF(a) -#define DEVPRINTF(x) +#define DPRINTF(a) +#define DEVPRINTF(x) #endif #if !defined(lint) static const char rcsid[] = - "$FreeBSD$"; + "$FreeBSD$"; #endif -struct tuple_callbacks; - -static int cardbus_read_tuple_conf(device_t dev, device_t child, - u_int32_t *start, u_int32_t *off, - int *tupleid, int *len, u_int8_t *tupledata); -static int cardbus_read_tuple_exrom(device_t dev, struct resource *mem, - u_int32_t *start, u_int32_t *off, - int *tupleid, int *len, u_int8_t *tupledata); -static int cardbus_read_tuple_mem(device_t dev, device_t child, u_int32_t *start, - u_int32_t *off, int *tupleid, int *len, - u_int8_t *tupledata); -static int cardbus_read_tuple(device_t dev, device_t child, u_int32_t *start, - u_int32_t *off, int *tupleid, int *len, - u_int8_t *tupledata); -static int decode_tuple(device_t dev, device_t child, int tupleid, int len, - u_int8_t *tupledata, u_int32_t *start, u_int32_t *off, - struct tuple_callbacks *callbacks); -static int cardbus_parse_cis(device_t dev, device_t child, - struct tuple_callbacks *callbacks); - -#define DECODE_PARAMS \ - (device_t dev, device_t child, int id, int len, \ +#define DECODE_PARAMS \ + (device_t cbdev, device_t child, int id, int len, \ u_int8_t *tupledata, u_int32_t *start, u_int32_t *off, \ struct tuple_callbacks *info) -#define DECODE_PROTOTYPE(NAME) static int decode_tuple_ ## NAME DECODE_PARAMS + +struct tuple_callbacks { + int id; + char *name; + int (*func) DECODE_PARAMS; +}; + +#define DECODE_PROTOTYPE(NAME) static int decode_tuple_ ## NAME DECODE_PARAMS DECODE_PROTOTYPE(generic); DECODE_PROTOTYPE(nothing); DECODE_PROTOTYPE(copy); -DECODE_PROTOTYPE(bar); DECODE_PROTOTYPE(linktarget); DECODE_PROTOTYPE(vers_1); -DECODE_PROTOTYPE(manfid); DECODE_PROTOTYPE(funcid); +DECODE_PROTOTYPE(manfid); DECODE_PROTOTYPE(funce); -DECODE_PROTOTYPE(end); +DECODE_PROTOTYPE(bar); DECODE_PROTOTYPE(unhandled); - -struct tuple_callbacks { - int id; - char* name; - int (*func) DECODE_PARAMS; -}; -#define MAKETUPLE(NAME,FUNC) { CISTPL_ ## NAME, #NAME, decode_tuple_ ## FUNC } - -static char* funcnames[] = { +DECODE_PROTOTYPE(end); +static int cardbus_read_tuple_conf(device_t cbdev, device_t child, + u_int32_t *start, u_int32_t *off, int *tupleid, int *len, + u_int8_t *tupledata); +static int cardbus_read_tuple_exrom(device_t cbdev, struct resource *mem, + u_int32_t *start, u_int32_t *off, int *tupleid, int *len, + u_int8_t *tupledata); +static int cardbus_read_tuple_mem(device_t cbdev, device_t child, + u_int32_t *start, u_int32_t *off, int *tupleid, int *len, + u_int8_t *tupledata); +static int cardbus_read_tuple(device_t cbdev, device_t child, + u_int32_t *start, u_int32_t *off, int *tupleid, int *len, + u_int8_t *tupledata); +static int decode_tuple(device_t cbdev, device_t child, int tupleid, + int len, u_int8_t *tupledata, u_int32_t *start, + u_int32_t *off, struct tuple_callbacks *callbacks); +static int cardbus_parse_cis(device_t cbdev, device_t child, + struct tuple_callbacks *callbacks); + +#define MAKETUPLE(NAME,FUNC) { CISTPL_ ## NAME, #NAME, decode_tuple_ ## FUNC } + +static char *funcnames[] = { "Multi-Functioned", "Memory", "Serial Port", @@ -123,25 +120,29 @@ static char* funcnames[] = { "Security" }; -static struct cis_tupleinfo* cisread_buf; +static struct cis_tupleinfo *cisread_buf; static int ncisread_buf; +/* + * Handler functions for various CIS tuples + */ + DECODE_PROTOTYPE(generic) { #ifdef CARDBUS_DEBUG int i; if (info) - printf ("TUPLE: %s [%d]:", info->name, len); + printf("TUPLE: %s [%d]:", info->name, len); else - printf ("TUPLE: Unknown(0x%02x) [%d]:", id, len); + printf("TUPLE: Unknown(0x%02x) [%d]:", id, len); for (i = 0; i < len; i++) { if (i % 0x10 == 0 && len > 0x10) - printf ("\n 0x%02x:", i); - printf (" %02x", tupledata[i]); + printf("\n 0x%02x:", i); + printf(" %02x", tupledata[i]); } - printf ("\n"); + printf("\n"); #endif return 0; } @@ -153,13 +154,13 @@ DECODE_PROTOTYPE(nothing) DECODE_PROTOTYPE(copy) { - struct cis_tupleinfo* tmpbuf; + struct cis_tupleinfo *tmpbuf; - tmpbuf = malloc(sizeof(struct cis_tupleinfo)*(ncisread_buf+1), - M_DEVBUF, M_WAITOK); + tmpbuf = malloc(sizeof(struct cis_tupleinfo) * (ncisread_buf+1), + M_DEVBUF, M_WAITOK); if (ncisread_buf > 0) { memcpy(tmpbuf, cisread_buf, - sizeof(struct cis_tupleinfo)*ncisread_buf); + sizeof(struct cis_tupleinfo) * ncisread_buf); free(cisread_buf, M_DEVBUF); } cisread_buf = tmpbuf; @@ -167,7 +168,7 @@ DECODE_PROTOTYPE(copy) cisread_buf[ncisread_buf].id = id; cisread_buf[ncisread_buf].len = len; cisread_buf[ncisread_buf].data = malloc(len, M_DEVBUF, M_WAITOK); - memcpy (cisread_buf[ncisread_buf].data, tupledata, len); + memcpy(cisread_buf[ncisread_buf].data, tupledata, len); ncisread_buf++; return 0; } @@ -177,20 +178,20 @@ DECODE_PROTOTYPE(linktarget) #ifdef CARDBUS_DEBUG int i; - printf ("TUPLE: %s [%d]:", info->name, len); + printf("TUPLE: %s [%d]:", info->name, len); for (i = 0; i < len; i++) { if (i % 0x10 == 0 && len > 0x10) - printf ("\n 0x%02x:", i); - printf (" %02x", tupledata[i]); + printf("\n 0x%02x:", i); + printf(" %02x", tupledata[i]); } - printf ("\n"); + printf("\n"); #endif if (len != 3 || tupledata[0] != 'C' || tupledata[1] != 'I' || tupledata[2] != 'S') { printf("Invalid data for CIS Link Target!\n"); - decode_tuple_generic(dev, child, id, len, tupledata, - start, off, info); + decode_tuple_generic(cbdev, child, id, len, tupledata, + start, off, info); return EINVAL; } return 0; @@ -203,7 +204,7 @@ DECODE_PROTOTYPE(vers_1) printf("Product name: "); for (i = 2; i < len; i++) { if (tupledata[i] == '\0') - printf (" | "); + printf(" | "); else if (tupledata[i] == 0xff) break; else @@ -216,24 +217,25 @@ DECODE_PROTOTYPE(vers_1) DECODE_PROTOTYPE(funcid) { int i; - int numnames = sizeof(funcnames)/sizeof(funcnames[0]); + int numnames = sizeof(funcnames) / sizeof(funcnames[0]); printf("Functions: "); - for(i = 0; i < len; i++) { + for (i = 0; i < len; i++) { if (tupledata[i] < numnames) - printf ("%s", funcnames[tupledata[i]]); + printf("%s", funcnames[tupledata[i]]); else - printf ("Unknown(%d)", tupledata[i]); - if (i < len-1) printf(", "); + printf("Unknown(%d)", tupledata[i]); + if (i < len-1) + printf(", "); } - printf ("\n"); + printf("\n"); return 0; } DECODE_PROTOTYPE(manfid) { int i; - printf ("Manufacturer ID: "); + printf("Manufacturer ID: "); for (i = 0; i < len; i++) printf("%02x", tupledata[i]); printf("\n"); @@ -243,7 +245,7 @@ DECODE_PROTOTYPE(manfid) DECODE_PROTOTYPE(funce) { int i; - printf ("Function Extension: "); + printf("Function Extension: "); for (i = 0; i < len; i++) printf("%02x", tupledata[i]); printf("\n"); @@ -253,7 +255,7 @@ DECODE_PROTOTYPE(funce) DECODE_PROTOTYPE(bar) { if (len != 6) { - printf ("*** ERROR *** BAR length not 6 (%d)\n", len); + printf("*** ERROR *** BAR length not 6 (%d)\n", len); return EINVAL; } else { int type; @@ -263,25 +265,26 @@ DECODE_PROTOTYPE(bar) struct resource *res; reg = *(u_int16_t*)tupledata; - len = *(u_int32_t*)(tupledata+2); + len = *(u_int32_t*)(tupledata + 2); if (reg & TPL_BAR_REG_AS) { type = SYS_RES_IOPORT; } else { type = SYS_RES_MEMORY; } bar = (reg & TPL_BAR_REG_ASI_MASK) - 1; - if (bar < 0 || bar > 5 || (type == SYS_RES_IOPORT && bar == 5)) { - device_printf(dev, "Invalid BAR number: %02x(%02x)\n", - reg, bar); + if (bar < 0 || bar > 5 || + (type == SYS_RES_IOPORT && bar == 5)) { + device_printf(cbdev, "Invalid BAR number: %02x(%02x)\n", + reg, bar); return 0; } bar = CARDBUS_BASE0_REG + bar * 4; - DEVPRINTF((dev, "Opening BAR: type=%s, bar=%02x, len=%04x\n", - (type==SYS_RES_MEMORY)?"MEM":"IO", bar, len)); + DEVPRINTF((cbdev, "Opening BAR: type=%s, bar=%02x, len=%04x\n", + (type==SYS_RES_MEMORY)?"MEM":"IO", bar, len)); res = bus_generic_alloc_resource(child, child, type, &bar, 0, - ~0, len, rman_make_alignment_flags(len) | RF_ACTIVE); + ~0, len, rman_make_alignment_flags(len) | RF_ACTIVE); if (res == NULL) { - device_printf(dev, "Cannot allocate BAR %02x\n", bar); + device_printf(cbdev, "Cannot allocate BAR %02x\n", bar); } } return 0; @@ -289,7 +292,7 @@ DECODE_PROTOTYPE(bar) DECODE_PROTOTYPE(unhandled) { - printf ("TUPLE: %s [%d] is unhandled! Bailing...", info->name, len); + printf("TUPLE: %s [%d] is unhandled! Bailing...", info->name, len); return -1; } @@ -299,10 +302,13 @@ DECODE_PROTOTYPE(end) return 0; } +/* + * Functions to read the a tuple from the card + */ + static int -cardbus_read_tuple_conf(device_t dev, device_t child, u_int32_t *start, - u_int32_t *off, int *tupleid, int *len, - u_int8_t *tupledata) +cardbus_read_tuple_conf(device_t cbdev, device_t child, u_int32_t *start, + u_int32_t *off, int *tupleid, int *len, u_int8_t *tupledata) { int i, j; u_int32_t e; @@ -310,8 +316,8 @@ cardbus_read_tuple_conf(device_t dev, device_t child, u_int32_t *start, loc = CARDBUS_CIS_ADDR(*start) + *off; - e = pci_read_config(child, loc - loc%4, 4); - for (j = loc % 4; j>0; j--) + e = pci_read_config(child, loc - loc % 4, 4); + for (j = loc % 4; j > 0; j--) e >>= 8; *len = 0; for (i = loc, j = -2; j < *len; j++, i++) { @@ -325,17 +331,15 @@ cardbus_read_tuple_conf(device_t dev, device_t child, u_int32_t *start, tupledata[j] = 0xff & e; e >>= 8; } - *off += *len+2; + *off += *len + 2; return 0; } - static int -cardbus_read_tuple_exrom(device_t dev, struct resource *mem, u_int32_t *start, - u_int32_t *off, int *tupleid, int *len, - u_int8_t *tupledata) +cardbus_read_tuple_exrom(device_t cbdev, struct resource *mem, u_int32_t *start, + u_int32_t *off, int *tupleid, int *len, u_int8_t *tupledata) { -#define READROM(rom, type, offset) \ +#define READROM(rom, type, offset) \ (*((u_int ## type ##_t *)(((unsigned char*)rom) + offset))) int romnum = 0; @@ -348,7 +352,7 @@ cardbus_read_tuple_exrom(device_t dev, struct resource *mem, u_int32_t *start, imagenum = CARDBUS_CIS_ASI_ROM_IMAGE(*start); do { if (READROM(image, 16, CARDBUS_EXROM_SIGNATURE) != 0xaa55) { - device_printf (dev, "Bad header in rom %d: %04x\n", + device_printf(cbdev, "Bad header in rom %d: %04x\n", romnum, *(u_int16_t*)(image + CARDBUS_EXROM_SIGNATURE)); return ENXIO; @@ -376,15 +380,14 @@ cardbus_read_tuple_exrom(device_t dev, struct resource *mem, u_int32_t *start, image += imagesize; romnum++; } while ((READROM(data, 8, CARDBUS_EXROM_DATA_INDICATOR) & 0x80) == 0); - device_printf(dev, "Cannot read CIS: Not enough images of rom\n"); + device_printf(cbdev, "Cannot read CIS: Not enough images of rom\n"); return ENOENT; #undef READROM } static int -cardbus_read_tuple_mem(device_t dev, device_t child, u_int32_t *start, - u_int32_t *off, int *tupleid, int *len, - u_int8_t *tupledata) +cardbus_read_tuple_mem(device_t cbdev, device_t child, u_int32_t *start, + u_int32_t *off, int *tupleid, int *len, u_int8_t *tupledata) { struct resource *mem; bus_space_tag_t bt; @@ -403,12 +406,12 @@ cardbus_read_tuple_mem(device_t dev, device_t child, u_int32_t *start, bt = rman_get_bustag(mem); bh = rman_get_bushandle(mem); if (mem == NULL) { - device_printf(dev, "Failed to get memory for CIS reading\n"); + device_printf(cbdev, "Failed to get memory for CIS reading\n"); return ENOMEM; } if(CARDBUS_CIS_SPACE(*start) == CARDBUS_CIS_ASI_ROM) { - ret = cardbus_read_tuple_exrom(dev, mem, start, off, tupleid, + ret = cardbus_read_tuple_exrom(cbdev, mem, start, off, tupleid, len, tupledata); } else { *tupleid = bus_space_read_1(bt, bh, @@ -426,14 +429,13 @@ cardbus_read_tuple_mem(device_t dev, device_t child, u_int32_t *start, } static int -cardbus_read_tuple(device_t dev, device_t child, u_int32_t *start, - u_int32_t *off, int *tupleid, int *len, - u_int8_t *tupledata) +cardbus_read_tuple(device_t cbdev, device_t child, u_int32_t *start, + u_int32_t *off, int *tupleid, int *len, u_int8_t *tupledata) { switch(CARDBUS_CIS_SPACE(*start)) { case CARDBUS_CIS_ASI_TUPLE: - return cardbus_read_tuple_conf(dev, child, start, off, - tupleid, len, tupledata); + return cardbus_read_tuple_conf(cbdev, child, start, off, + tupleid, len, tupledata); case CARDBUS_CIS_ASI_BAR0: case CARDBUS_CIS_ASI_BAR1: case CARDBUS_CIS_ASI_BAR2: @@ -441,40 +443,43 @@ cardbus_read_tuple(device_t dev, device_t child, u_int32_t *start, case CARDBUS_CIS_ASI_BAR4: case CARDBUS_CIS_ASI_BAR5: case CARDBUS_CIS_ASI_ROM: - return cardbus_read_tuple_mem(dev, child, start, off, - tupleid, len, tupledata); + return cardbus_read_tuple_mem(cbdev, child, start, off, + tupleid, len, tupledata); default: - device_printf(dev, "Unable to read CIS: Unknown space: %d\n", - CARDBUS_CIS_SPACE(*start)); + device_printf(cbdev, "Unable to read CIS: Unknown space: %d\n", + CARDBUS_CIS_SPACE(*start)); return EINVAL; } } +/* + * Dispatch the right handler function per tuple + */ + static int -decode_tuple(device_t dev, device_t child, int tupleid, int len, - u_int8_t *tupledata, u_int32_t *start, u_int32_t *off, - struct tuple_callbacks *callbacks) +decode_tuple(device_t cbdev, device_t child, int tupleid, int len, + u_int8_t *tupledata, u_int32_t *start, u_int32_t *off, + struct tuple_callbacks *callbacks) { int i; for (i = 0; callbacks[i].id != CISTPL_GENERIC; i++) { if (tupleid == callbacks[i].id) - return callbacks[i].func(dev, child, tupleid, len, - tupledata, start, off, - &callbacks[i]); + return callbacks[i].func(cbdev, child, tupleid, len, + tupledata, start, off, &callbacks[i]); } if (tupleid < CISTPL_CUSTOMSTART) { - device_printf(dev, "Undefined tuple encountered, CIS parsing terminated\n"); + device_printf(cbdev, "Undefined tuple encountered, " + "CIS parsing terminated\n"); return EINVAL; } - return callbacks[i].func(dev, child, tupleid, len, - tupledata, start, off, - NULL); + return callbacks[i].func(cbdev, child, tupleid, len, + tupledata, start, off, NULL); } static int -cardbus_parse_cis(device_t dev, device_t child, - struct tuple_callbacks *callbacks) +cardbus_parse_cis(device_t cbdev, device_t child, + struct tuple_callbacks *callbacks) { u_int8_t tupledata[MAXTUPLESIZE]; int tupleid; @@ -487,15 +492,15 @@ cardbus_parse_cis(device_t dev, device_t child, start = pci_read_config(child, CARDBUS_CIS_REG, 4); off = 0; do { - cardbus_read_tuple(dev, child, &start, &off, &tupleid, &len, + cardbus_read_tuple(cbdev, child, &start, &off, &tupleid, &len, tupledata); if (expect_linktarget && tupleid != CISTPL_LINKTARGET) { - device_printf(dev, "Expecting link target, got 0x%x\n", - tupleid); + device_printf(cbdev, "Expecting link target, got 0x%x\n", + tupleid); return EINVAL; } - expect_linktarget = decode_tuple(dev, child, tupleid, len, + expect_linktarget = decode_tuple(cbdev, child, tupleid, len, tupledata, &start, &off, callbacks); if (expect_linktarget != 0) @@ -505,8 +510,8 @@ cardbus_parse_cis(device_t dev, device_t child, } int -cardbus_cis_read(device_t dev, device_t child, u_int8_t id, - struct cis_tupleinfo** buff, int* nret) +cardbus_cis_read(device_t cbdev, device_t child, u_int8_t id, + struct cis_tupleinfo **buff, int *nret) { struct tuple_callbacks cisread_callbacks[] = { MAKETUPLE(NULL, nothing), @@ -558,7 +563,7 @@ cardbus_cis_read(device_t dev, device_t child, u_int8_t id, cisread_callbacks[0].func = decode_tuple_copy; ncisread_buf = 0; cisread_buf = NULL; - ret = cardbus_parse_cis(dev, child, cisread_callbacks); + ret = cardbus_parse_cis(cbdev, child, cisread_callbacks); *buff = cisread_buf; *nret = ncisread_buf; @@ -566,7 +571,7 @@ cardbus_cis_read(device_t dev, device_t child, u_int8_t id, } void -cardbus_cis_free(device_t dev, struct cis_tupleinfo *buff, int* nret) +cardbus_cis_free(device_t cbdev, struct cis_tupleinfo *buff, int* nret) { int i; for (i = 0; i < *nret; i++) @@ -576,7 +581,7 @@ cardbus_cis_free(device_t dev, struct cis_tupleinfo *buff, int* nret) } int -cardbus_do_cis(device_t dev, device_t child) +cardbus_do_cis(device_t cbdev, device_t child) { struct tuple_callbacks init_callbacks[] = { MAKETUPLE(NULL, generic), @@ -619,5 +624,5 @@ cardbus_do_cis(device_t dev, device_t child) MAKETUPLE(END, end), MAKETUPLE(GENERIC, generic), }; - return cardbus_parse_cis(dev, child, init_callbacks); + return cardbus_parse_cis(cbdev, child, init_callbacks); } diff --git a/sys/dev/cardbus/cardbus_cis.h b/sys/dev/cardbus/cardbus_cis.h index f884eef..ca21090 100644 --- a/sys/dev/cardbus/cardbus_cis.h +++ b/sys/dev/cardbus/cardbus_cis.h @@ -34,74 +34,74 @@ struct cis_tupleinfo; -int cardbus_do_cis(device_t dev, device_t child); -int cardbus_cis_read(device_t dev, device_t child, u_int8_t id, - struct cis_tupleinfo** buff, int* nret); -void cardbus_cis_free(device_t dev, struct cis_tupleinfo *buff, int* nret); +int cardbus_do_cis(device_t, device_t); +int cardbus_cis_read(device_t, device_t, u_int8_t, struct cis_tupleinfo**, + int*); +void cardbus_cis_free(device_t, struct cis_tupleinfo*, int*); -#define MAXTUPLESIZE 0x400 +#define MAXTUPLESIZE 0x400 /* CIS TUPLES */ -#define CISTPL_NULL 0x00 -#define CISTPL_DEVICE 0x01 -#define CISTPL_LONG_LINK_CB 0x02 -#define CISTPL_INDIRECT 0x03 -#define CISTPL_CONFIG_CB 0x04 -#define CISTPL_CFTABLE_ENTRY_CB 0x05 -#define CISTPL_LONGLINK_MFC 0x06 -#define CISTPL_BAR 0x07 -#define CISTPL_PWR_MGMNT 0x08 -#define CISTPL_EXTDEVICE 0x09 -#define CISTPL_CHECKSUM 0x10 -#define CISTPL_LONGLINK_A 0x11 -#define CISTPL_LONGLINK_C 0x12 -#define CISTPL_LINKTARGET 0x13 -#define CISTPL_NO_LINK 0x14 -#define CISTPL_VERS_1 0x15 -#define CISTPL_ALTSTR 0x16 -#define CISTPL_DEVICE_A 0x17 -#define CISTPL_JEDEC_C 0x18 -#define CISTPL_JEDEC_A 0x19 -#define CISTPL_CONFIG 0x1A -#define CISTPL_CFTABLE_ENTRY 0x1B -#define CISTPL_DEVICE_OC 0x1C -#define CISTPL_DEVICE_OA 0x1D -#define CISTPL_DEVICE_GEO 0x1E -#define CISTPL_DEVICE_GEO_A 0x1F -#define CISTPL_MANFID 0x20 -#define CISTPL_FUNCID 0x21 -#define CISTPL_FUNCE 0x22 -#define CISTPL_SWIL 0x23 -#define CISTPL_VERS_2 0x40 -#define CISTPL_FORMAT 0x41 -#define CISTPL_GEOMETRY 0x42 -#define CISTPL_BYTEORDER 0x43 -#define CISTPL_DATE 0x44 -#define CISTPL_BATTERY 0x45 -#define CISTPL_ORG 0x46 -#define CISTPL_CUSTOMSTART 0x80 -#define CISTPL_END 0xFF +#define CISTPL_NULL 0x00 +#define CISTPL_DEVICE 0x01 +#define CISTPL_LONG_LINK_CB 0x02 +#define CISTPL_INDIRECT 0x03 +#define CISTPL_CONFIG_CB 0x04 +#define CISTPL_CFTABLE_ENTRY_CB 0x05 +#define CISTPL_LONGLINK_MFC 0x06 +#define CISTPL_BAR 0x07 +#define CISTPL_PWR_MGMNT 0x08 +#define CISTPL_EXTDEVICE 0x09 +#define CISTPL_CHECKSUM 0x10 +#define CISTPL_LONGLINK_A 0x11 +#define CISTPL_LONGLINK_C 0x12 +#define CISTPL_LINKTARGET 0x13 +#define CISTPL_NO_LINK 0x14 +#define CISTPL_VERS_1 0x15 +#define CISTPL_ALTSTR 0x16 +#define CISTPL_DEVICE_A 0x17 +#define CISTPL_JEDEC_C 0x18 +#define CISTPL_JEDEC_A 0x19 +#define CISTPL_CONFIG 0x1A +#define CISTPL_CFTABLE_ENTRY 0x1B +#define CISTPL_DEVICE_OC 0x1C +#define CISTPL_DEVICE_OA 0x1D +#define CISTPL_DEVICE_GEO 0x1E +#define CISTPL_DEVICE_GEO_A 0x1F +#define CISTPL_MANFID 0x20 +#define CISTPL_FUNCID 0x21 +#define CISTPL_FUNCE 0x22 +#define CISTPL_SWIL 0x23 +#define CISTPL_VERS_2 0x40 +#define CISTPL_FORMAT 0x41 +#define CISTPL_GEOMETRY 0x42 +#define CISTPL_BYTEORDER 0x43 +#define CISTPL_DATE 0x44 +#define CISTPL_BATTERY 0x45 +#define CISTPL_ORG 0x46 +#define CISTPL_CUSTOMSTART 0x80 +#define CISTPL_END 0xFF -#define CISTPL_GENERIC -1 /* catchall */ +#define CISTPL_GENERIC -1 /* catchall */ /* BAR */ -#define TPL_BAR_REG_ASI_MASK 0x07 -#define TPL_BAR_REG_AS 0x10 +#define TPL_BAR_REG_ASI_MASK 0x07 +#define TPL_BAR_REG_AS 0x10 /* CISTPL_FUNC */ -#define TPL_FUNC_MF 0 /* multi function tuple */ -#define TPL_FUNC_MEM 1 /* memory */ -#define TPL_FUNC_SERIAL 2 /* serial, including modem and fax */ -#define TPL_FUNC_PARALLEL 3 /* parallel, including printer and SCSI */ -#define TPL_FUNC_DISK 4 /* Disk */ -#define TPL_FUNC_VIDEO 5 /* Video Adaptor */ -#define TPL_FUNC_LAN 6 /* LAN Adaptor */ -#define TPL_FUNC_AIMS 7 /* Auto Inclement Mass Strages */ +#define TPL_FUNC_MF 0 /* multi function tuple */ +#define TPL_FUNC_MEM 1 /* memory */ +#define TPL_FUNC_SERIAL 2 /* serial, including modem and fax */ +#define TPL_FUNC_PARALLEL 3 /* parallel, including printer and SCSI */ +#define TPL_FUNC_DISK 4 /* Disk */ +#define TPL_FUNC_VIDEO 5 /* Video Adaptor */ +#define TPL_FUNC_LAN 6 /* LAN Adaptor */ +#define TPL_FUNC_AIMS 7 /* Auto Inclement Mass Strages */ /* TPL_FUNC_LAN */ -#define TPL_FUNCE_LAN_TECH 1 /* technology */ -#define TPL_FUNCE_LAN_SPEED 2 /* speed */ -#define TPL_FUNCE_LAN_MEDIA 2 /* which media do you use? */ -#define TPL_FUNCE_LAN_NID 4 /* node id (address) */ -#define TPL_FUNCE_LAN_CONN 5 /* connector type (shape) */ +#define TPL_FUNCE_LAN_TECH 1 /* technology */ +#define TPL_FUNCE_LAN_SPEED 2 /* speed */ +#define TPL_FUNCE_LAN_MEDIA 2 /* which media do you use? */ +#define TPL_FUNCE_LAN_NID 4 /* node id (address) */ +#define TPL_FUNCE_LAN_CONN 5 /* connector type (shape) */ diff --git a/sys/dev/cardbus/cardbusreg.h b/sys/dev/cardbus/cardbusreg.h index 95e7302..ec3157e 100644 --- a/sys/dev/cardbus/cardbusreg.h +++ b/sys/dev/cardbus/cardbusreg.h @@ -34,58 +34,58 @@ /* Cardbus bus constants */ -#define CARDBUS_SLOTMAX 0 -#define CARDBUS_FUNCMAX 7 +#define CARDBUS_SLOTMAX 0 +#define CARDBUS_FUNCMAX 7 /* Cardbus configuration header registers */ -#define CARDBUS_BASE0_REG 0x10 -#define CARDBUS_BASE1_REG 0x14 -#define CARDBUS_BASE2_REG 0x18 -#define CARDBUS_BASE3_REG 0x1C -#define CARDBUS_BASE4_REG 0x20 -#define CARDBUS_BASE5_REG 0x24 -#define CARDBUS_CIS_REG 0x28 -# define CARDBUS_CIS_ASIMASK 0x07 -# define CARDBUS_CIS_ADDRMASK 0x0ffffff8 -# define CARDBUS_CIS_ASI_TUPLE 0x00 -# define CARDBUS_CIS_ASI_BAR0 0x01 -# define CARDBUS_CIS_ASI_BAR1 0x02 -# define CARDBUS_CIS_ASI_BAR2 0x03 -# define CARDBUS_CIS_ASI_BAR3 0x04 -# define CARDBUS_CIS_ASI_BAR4 0x05 -# define CARDBUS_CIS_ASI_BAR5 0x06 -# define CARDBUS_CIS_ASI_ROM 0x07 -#define CARDBUS_ROM_REG 0x30 -# define CARDBUS_ROM_ENABLE 0x00000001 -# define CARDBUS_ROM_ADDRMASK 0xfffff800 +#define CARDBUS_BASE0_REG 0x10 +#define CARDBUS_BASE1_REG 0x14 +#define CARDBUS_BASE2_REG 0x18 +#define CARDBUS_BASE3_REG 0x1C +#define CARDBUS_BASE4_REG 0x20 +#define CARDBUS_BASE5_REG 0x24 +#define CARDBUS_CIS_REG 0x28 +# define CARDBUS_CIS_ASIMASK 0x07 +# define CARDBUS_CIS_ADDRMASK 0x0ffffff8 +# define CARDBUS_CIS_ASI_TUPLE 0x00 +# define CARDBUS_CIS_ASI_BAR0 0x01 +# define CARDBUS_CIS_ASI_BAR1 0x02 +# define CARDBUS_CIS_ASI_BAR2 0x03 +# define CARDBUS_CIS_ASI_BAR3 0x04 +# define CARDBUS_CIS_ASI_BAR4 0x05 +# define CARDBUS_CIS_ASI_BAR5 0x06 +# define CARDBUS_CIS_ASI_ROM 0x07 +#define CARDBUS_ROM_REG 0x30 +# define CARDBUS_ROM_ENABLE 0x00000001 +# define CARDBUS_ROM_ADDRMASK 0xfffff800 /* EXROM offsets for reading CIS */ -#define CARDBUS_EXROM_SIGNATURE 0x00 -#define CARDBUS_EXROM_DATA_PTR 0x18 +#define CARDBUS_EXROM_SIGNATURE 0x00 +#define CARDBUS_EXROM_DATA_PTR 0x18 -#define CARDBUS_EXROM_DATA_SIGNATURE 0x00 /* Signature ("PCIR") */ -#define CARDBUS_EXROM_DATA_VENDOR_ID 0x04 /* Vendor Identification */ -#define CARDBUS_EXROM_DATA_DEVICE_ID 0x06 /* Device Identification */ -#define CARDBUS_EXROM_DATA_LENGTH 0x0a /* PCI Data Structure Length */ -#define CARDBUS_EXROM_DATA_REV 0x0c /* PCI Data Structure Revision */ -#define CARDBUS_EXROM_DATA_CLASS_CODE 0x0d /* Class Code */ -#define CARDBUS_EXROM_DATA_IMAGE_LENGTH 0x10 /* Image Length */ -#define CARDBUS_EXROM_DATA_DATA_REV 0x12 /* Revision Level of Code/Data */ -#define CARDBUS_EXROM_DATA_CODE_TYPE 0x14 /* Code Type */ -#define CARDBUS_EXROM_DATA_INDICATOR 0x15 /* Indicator */ +#define CARDBUS_EXROM_DATA_SIGNATURE 0x00 /* Signature ("PCIR") */ +#define CARDBUS_EXROM_DATA_VENDOR_ID 0x04 /* Vendor Identification */ +#define CARDBUS_EXROM_DATA_DEVICE_ID 0x06 /* Device Identification */ +#define CARDBUS_EXROM_DATA_LENGTH 0x0a /* PCI Data Structure Length */ +#define CARDBUS_EXROM_DATA_REV 0x0c /* PCI Data Structure Revision */ +#define CARDBUS_EXROM_DATA_CLASS_CODE 0x0d /* Class Code */ +#define CARDBUS_EXROM_DATA_IMAGE_LENGTH 0x10 /* Image Length */ +#define CARDBUS_EXROM_DATA_DATA_REV 0x12 /* Revision Level of Code/Data */ +#define CARDBUS_EXROM_DATA_CODE_TYPE 0x14 /* Code Type */ +#define CARDBUS_EXROM_DATA_INDICATOR 0x15 /* Indicator */ /* useful macros */ -#define CARDBUS_CIS_ADDR(x) \ +#define CARDBUS_CIS_ADDR(x) \ (CARDBUS_CIS_ADDRMASK & (x)) -#define CARDBUS_CIS_SPACE(x) \ +#define CARDBUS_CIS_SPACE(x) \ (CARDBUS_CIS_ASIMASK & (x)) -#define CARDBUS_CIS_ASI_BAR(x) \ +#define CARDBUS_CIS_ASI_BAR(x) \ (((CARDBUS_CIS_ASIMASK & (x))-1)*4+0x10) -#define CARDBUS_CIS_ASI_ROM_IMAGE(x) \ +#define CARDBUS_CIS_ASI_ROM_IMAGE(x) \ (((x) >> 28) & 0xf) -#define CARDBUS_MAPREG_MEM_ADDR_MASK 0x0ffffff0 -#define CARDBUS_MAPREG_MEM_ADDR(mr) \ +#define CARDBUS_MAPREG_MEM_ADDR_MASK 0x0ffffff0 +#define CARDBUS_MAPREG_MEM_ADDR(mr) \ ((mr) & CARDBUS_MAPREG_MEM_ADDR_MASK) -#define CARDBUS_MAPREG_MEM_SIZE(mr) \ +#define CARDBUS_MAPREG_MEM_SIZE(mr) \ (CARDBUS_MAPREG_MEM_ADDR(mr) & -CARDBUS_MAPREG_MEM_ADDR(mr)) diff --git a/sys/dev/cardbus/cardbusvar.h b/sys/dev/cardbus/cardbusvar.h index a94cd99..7e0e3c5 100644 --- a/sys/dev/cardbus/cardbusvar.h +++ b/sys/dev/cardbus/cardbusvar.h @@ -33,7 +33,7 @@ */ struct cardbus_devinfo { - struct resource_list resources; - pcicfgregs cfg; - struct pci_conf conf; + struct resource_list resources; + pcicfgregs cfg; + struct pci_conf conf; }; |