summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorFederico G. Schwindt <fgsch@cvs.openbsd.org>2005-09-13 18:44:39 +0000
committerFederico G. Schwindt <fgsch@cvs.openbsd.org>2005-09-13 18:44:39 +0000
commit620f89b005d1a46be2ef666fdc71756367c6a5b1 (patch)
tree9d31f33080f31106b829fb74c5e111ce3c8732d2 /sys/dev
parent8b7270dba0b25292d64705901d088b5758d9366f (diff)
knf; no binary change.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/cardbus/cardbus.c8
-rw-r--r--sys/dev/cardbus/cardbus_exrom.c60
-rw-r--r--sys/dev/cardbus/cardbus_map.c170
-rw-r--r--sys/dev/cardbus/cardbusvar.h308
-rw-r--r--sys/dev/cardbus/rbus.c466
-rw-r--r--sys/dev/cardbus/rbus.h70
6 files changed, 473 insertions, 609 deletions
diff --git a/sys/dev/cardbus/cardbus.c b/sys/dev/cardbus/cardbus.c
index 81100a2e3c7..ed8b27b9a5b 100644
--- a/sys/dev/cardbus/cardbus.c
+++ b/sys/dev/cardbus/cardbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cardbus.c,v 1.28 2005/09/13 15:21:24 mickey Exp $ */
+/* $OpenBSD: cardbus.c,v 1.29 2005/09/13 18:44:38 fgsch Exp $ */
/* $NetBSD: cardbus.c,v 1.24 2000/04/02 19:11:37 mycroft Exp $ */
/*
@@ -33,7 +33,6 @@
* POSSIBILITY OF SUCH DAMAGE.
*/
-#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
@@ -64,17 +63,16 @@
STATIC void cardbusattach(struct device *, struct device *, void *);
/* STATIC int cardbusprint(void *, const char *); */
-int cardbus_attach_card(struct cardbus_softc *);
STATIC int cardbusmatch(struct device *, void *, void *);
static int cardbussubmatch(struct device *, void *, void *);
static int cardbusprint(void *, const char *);
-typedef void (*tuple_decode_func)(u_int8_t*, int, void *);
+typedef void (*tuple_decode_func)(u_int8_t *, int, void *);
static int decode_tuples(u_int8_t *, int, tuple_decode_func, void *);
#ifdef CARDBUS_DEBUG
-static void print_tuple(u_int8_t*, int, void *);
+static void print_tuple(u_int8_t *, int, void *);
#endif
static int cardbus_read_tuples(struct cardbus_attach_args *,
diff --git a/sys/dev/cardbus/cardbus_exrom.c b/sys/dev/cardbus/cardbus_exrom.c
index 6ca01da5e94..76b706a7aa8 100644
--- a/sys/dev/cardbus/cardbus_exrom.c
+++ b/sys/dev/cardbus/cardbus_exrom.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cardbus_exrom.c,v 1.3 2005/09/12 22:52:50 miod Exp $ */
+/* $OpenBSD: cardbus_exrom.c,v 1.4 2005/09/13 18:44:38 fgsch Exp $ */
/* $NetBSD: cardbus_exrom.c,v 1.4 2000/02/03 06:47:31 thorpej Exp $ */
/*
@@ -108,26 +108,26 @@ cardbus_read_exrom(bus_space_tag_t romt, bus_space_handle_t romh,
size_t image_size;
struct cardbus_rom_image *image;
u_int16_t val;
-
+
SIMPLEQ_INIT(head);
do {
val = READ_INT16(romt, romh, addr + CARDBUS_EXROM_SIGNATURE);
if (val != 0xaa55) {
- DPRINTF(("%s: bad header signature in ROM image %u: 0x%04x\n",
- __func__, rom_image, val));
+ DPRINTF(("%s: bad header signature in ROM image "
+ "%u: 0x%04x\n", __func__, rom_image, val));
return (1);
}
- dataptr = addr +
- READ_INT16(romt, romh, addr + CARDBUS_EXROM_DATA_PTR);
+ dataptr = addr + READ_INT16(romt, romh,
+ addr + CARDBUS_EXROM_DATA_PTR);
/* get the ROM image size, in blocks */
- image_size = READ_INT16(romt, romh,
+ image_size = READ_INT16(romt, romh,
dataptr + CARDBUS_EXROM_DATA_IMAGE_LENGTH);
/* XXX
* Some ROMs seem to have this as zero, can we assume
* this means 1 block?
*/
- if (image_size == 0)
+ if (image_size == 0)
image_size = 1;
image_size <<= 9;
@@ -150,48 +150,6 @@ cardbus_read_exrom(bus_space_tag_t romt, bus_space_handle_t romh,
rom_image++;
} while ((bus_space_read_1(romt, romh,
dataptr + CARDBUS_EXROM_DATA_INDICATOR) & 0x80) == 0);
- return (0);
-}
-#if 0
-struct cardbus_exrom_data_structure {
- char signature[4];
- cardbusreg_t id; /* vendor & device id */
- u_int16_t structure_length;
- u_int8_t structure_revision;
- cardbusreg_t class; /* class code in upper 24 bits */
- u_int16_t image_length;
- u_int16_t data_revision;
- u_int8_t code_type;
- u_int8_t indicator;
-};
-
-int
-pci_exrom_parse_data_structure(bus_space_tag_t tag,
- bus_space_handle_t handle, struct pci_exrom_data_structure *ds)
-{
- unsigned char hdr[16];
- int length;
-
- bus_space_read_region_1(tag, handle, dataptr, hdr, sizeof(hdr));
- memcpy(header->signature, hdr + PCI_EXROM_DATA_SIGNATURE, 4);
-#define LEINT16(B, O) ((B)[(O)] | ((B)[(O) + 1] << 8))
- header->id = LEINT16(hdr, PCI_EXROM_DATA_VENDOR_ID) |
- (LEINT16(hdr, PCI_EXROM_DATA_DEVICE_ID) << 16);
- header->structure_length = LEINT16(hdr, PCI_EXROM_DATA_LENGTH);
- header->structure_rev = hdr[PCI_EXROM_DATA_REV];
- header->class = (hdr[PCI_EXROM_DATA_CLASS_CODE] << 8) |
- (hdr[PCI_EXROM_DATA_CLASS_CODE + 1] << 16) |
- (hdr[PCI_EXROM_DATA_CLASS_CODE + 2] << 24);
- header->image_length = LEINT16(hdr, PCI_EXROM_DATA_IMAGE_LENGTH) << 16;
- header->data_revision = LEINT16(hdr, PCI_EXROM_DATA_DATA_REV);
- header->code_type = hdr[PCI_EXROM_DATA_CODE_TYPE];
- header->indicator = hdr[PCI_EXROM_DATA_INDICATOR];
-
- length = min(length, header->image_length - 0x18 - offset);
- bus_space_read_region_1(tag, handle, dataptr + 0x18 + offset,
- buf, length);
-
- return (length);
+ return (0);
}
-#endif
diff --git a/sys/dev/cardbus/cardbus_map.c b/sys/dev/cardbus/cardbus_map.c
index e4bb8fbe20b..201a220000f 100644
--- a/sys/dev/cardbus/cardbus_map.c
+++ b/sys/dev/cardbus/cardbus_map.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cardbus_map.c,v 1.4 2004/07/04 23:10:48 brad Exp $ */
+/* $OpenBSD: cardbus_map.c,v 1.5 2005/09/13 18:44:38 fgsch Exp $ */
/* $NetBSD: cardbus_map.c,v 1.10 2000/03/07 00:31:46 mycroft Exp $ */
/*
@@ -34,7 +34,6 @@
*/
-#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
@@ -59,11 +58,11 @@
static int cardbus_io_find(cardbus_chipset_tag_t, cardbus_function_tag_t,
- cardbustag_t, int, cardbusreg_t,
- bus_addr_t *, bus_size_t *, int *);
+ cardbustag_t, int, cardbusreg_t, bus_addr_t *, bus_size_t *,
+ int *);
static int cardbus_mem_find(cardbus_chipset_tag_t, cardbus_function_tag_t,
- cardbustag_t, int, cardbusreg_t,
- bus_addr_t *, bus_size_t *, int *);
+ cardbustag_t, int, cardbusreg_t, bus_addr_t *, bus_size_t *,
+ int *);
/*
* static int cardbus_io_find(cardbus_chipset_tag_t cc,
@@ -73,25 +72,18 @@ static int cardbus_mem_find(cardbus_chipset_tag_t, cardbus_function_tag_t,
* This code is stolen from sys/dev/pci_map.c.
*/
static int
-cardbus_io_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
- cardbus_chipset_tag_t cc;
- cardbus_function_tag_t cf;
- cardbustag_t tag;
- int reg;
- cardbusreg_t type;
- bus_addr_t *basep;
- bus_size_t *sizep;
- int *flagsp;
+cardbus_io_find(cardbus_chipset_tag_t cc, cardbus_function_tag_t cf,
+ cardbustag_t tag, int reg, cardbusreg_t type, bus_addr_t *basep,
+ bus_size_t *sizep, int *flagsp)
{
cardbusreg_t address, mask;
int s;
/* EXT ROM is able to map on memory space ONLY. */
- if (reg == CARDBUS_ROM_REG) {
- return 1;
- }
+ if (reg == CARDBUS_ROM_REG)
+ return (1);
- if(reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3)) {
+ if (reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3)) {
panic("cardbus_io_find: bad request");
}
@@ -114,29 +106,24 @@ cardbus_io_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
if (PCI_MAPREG_TYPE(address) != PCI_MAPREG_TYPE_IO) {
printf("cardbus_io_find: expected type i/o, found mem\n");
- return 1;
+ return (1);
}
if (PCI_MAPREG_IO_SIZE(mask) == 0) {
printf("cardbus_io_find: void region\n");
- return 1;
+ return (1);
}
- if (basep != 0) {
+ if (basep != 0)
*basep = PCI_MAPREG_IO_ADDR(address);
- }
- if (sizep != 0) {
+ if (sizep != 0)
*sizep = PCI_MAPREG_IO_SIZE(mask);
- }
- if (flagsp != 0) {
+ if (flagsp != 0)
*flagsp = 0;
- }
- return 0;
+ return (0);
}
-
-
/*
* static int cardbus_mem_find(cardbus_chipset_tag_t cc,
* cardbus_function_tag_t cf, cardbustag_t tag,
@@ -145,20 +132,14 @@ cardbus_io_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
* This code is stolen from sys/dev/pci_map.c.
*/
static int
-cardbus_mem_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
- cardbus_chipset_tag_t cc;
- cardbus_function_tag_t cf;
- cardbustag_t tag;
- int reg;
- cardbusreg_t type;
- bus_addr_t *basep;
- bus_size_t *sizep;
- int *flagsp;
+cardbus_mem_find(cardbus_chipset_tag_t cc, cardbus_function_tag_t cf,
+ cardbustag_t tag, int reg, cardbusreg_t type, bus_addr_t *basep,
+ bus_size_t *sizep, int *flagsp)
{
cardbusreg_t address, mask;
int s;
- if (reg != CARDBUS_ROM_REG &&
+ if (reg != CARDBUS_ROM_REG &&
(reg < PCI_MAPREG_START || reg >= PCI_MAPREG_END || (reg & 3))) {
panic("cardbus_mem_find: bad request");
}
@@ -184,20 +165,21 @@ cardbus_mem_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
/* memory space BAR */
if (PCI_MAPREG_TYPE(address) != PCI_MAPREG_TYPE_MEM) {
- printf("cardbus_mem_find: expected type mem, found i/o\n");
- return 1;
+ printf("cardbus_mem_find: expected type mem, "
+ "found i/o\n");
+ return (1);
}
if (PCI_MAPREG_MEM_TYPE(address) != PCI_MAPREG_MEM_TYPE(type)) {
- printf("cardbus_mem_find: expected mem type %08x, found %08x\n",
- PCI_MAPREG_MEM_TYPE(type),
+ printf("cardbus_mem_find: expected mem type %08x, "
+ "found %08x\n", PCI_MAPREG_MEM_TYPE(type),
PCI_MAPREG_MEM_TYPE(address));
- return 1;
+ return (1);
}
}
if (PCI_MAPREG_MEM_SIZE(mask) == 0) {
printf("cardbus_mem_find: void region\n");
- return 1;
+ return (1);
}
switch (PCI_MAPREG_MEM_TYPE(address)) {
@@ -206,18 +188,16 @@ cardbus_mem_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
break;
case PCI_MAPREG_MEM_TYPE_64BIT:
printf("cardbus_mem_find: 64-bit memory mapping register\n");
- return 1;
+ return (1);
default:
printf("cardbus_mem_find: reserved mapping register type\n");
- return 1;
+ return (1);
}
- if (basep != 0) {
+ if (basep != 0)
*basep = PCI_MAPREG_MEM_ADDR(address);
- }
- if (sizep != 0) {
+ if (sizep != 0)
*sizep = PCI_MAPREG_MEM_SIZE(mask);
- }
if (flagsp != 0) {
*flagsp =
#ifdef BUS_SPACE_MAP_PREFETCHABLE
@@ -226,12 +206,9 @@ cardbus_mem_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
#endif
0;
}
-
- return 0;
-}
-
-
+ return (0);
+}
/*
* int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
@@ -244,14 +221,9 @@ cardbus_mem_find(cc, cf, tag, reg, type, basep, sizep, flagsp)
* written on the BAR.
*/
int
-cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
- struct cardbus_softc *sc;
- int func, reg, busflags;
- cardbusreg_t type;
- bus_space_tag_t *tagp;
- bus_space_handle_t *handlep;
- bus_addr_t *basep;
- bus_size_t *sizep;
+cardbus_mapreg_map(struct cardbus_softc *sc, int func, int reg,
+ cardbusreg_t type, int busflags, bus_space_tag_t *tagp,
+ bus_space_handle_t *handlep, bus_addr_t *basep, bus_size_t *sizep)
{
cardbus_chipset_tag_t cc = sc->sc_cc;
cardbus_function_tag_t cf = sc->sc_cf;
@@ -265,23 +237,24 @@ cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
int flags;
int status = 0;
- cardbustag_t tag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, func);
+ cardbustag_t tag = cardbus_make_tag(cc, cf, sc->sc_bus,
+ sc->sc_device, func);
DPRINTF(("cardbus_mapreg_map called: %s %x\n", sc->sc_dev.dv_xname,
type));
if (PCI_MAPREG_TYPE(type) == PCI_MAPREG_TYPE_IO) {
- if (cardbus_io_find(cc, cf, tag, reg, type, &base, &size, &flags)) {
+ if (cardbus_io_find(cc, cf, tag, reg, type, &base, &size,
+ &flags))
status = 1;
- }
bustag = sc->sc_iot;
#if rbus
rbustag = sc->sc_rbus_iot;
#endif
} else {
- if (cardbus_mem_find(cc, cf, tag, reg, type, &base, &size, &flags)){
+ if (cardbus_mem_find(cc, cf, tag, reg, type, &base, &size,
+ &flags))
status = 1;
- }
bustag = sc->sc_memt;
#if rbus
rbustag = sc->sc_rbus_memt;
@@ -290,9 +263,8 @@ cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
if (status == 0) {
#if rbus
bus_addr_t mask = size - 1;
- if (base != 0) {
+ if (base != 0)
mask = 0xffffffff;
- }
if ((*cf->cardbus_space_alloc)(cc, rbustag, base, size, mask,
size, busflags | flags, &base, &handle)) {
panic("io alloc");
@@ -304,7 +276,8 @@ cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
bus_addr_t start = base;
bus_addr_t end = base + size;
}
- if (bus_space_alloc(bustag, start, end, size, size, 0, 0, &base, &handle)) {
+ if (bus_space_alloc(bustag, start, end, size, size, 0, 0,
+ &base, &handle)) {
panic("io alloc");
}
#endif
@@ -313,27 +286,19 @@ cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
DPRINTF(("cardbus_mapreg_map: physaddr %lx\n", (unsigned long)base));
- if (tagp != 0) {
+ if (tagp != 0)
*tagp = bustag;
- }
- if (handlep != 0) {
+ if (handlep != 0)
*handlep = handle;
- }
- if (basep != 0) {
+ if (basep != 0)
*basep = base;
- }
- if (sizep != 0) {
+ if (sizep != 0)
*sizep = size;
- }
cardbus_free_tag(cc, cf, tag);
- return 0;
+ return (0);
}
-
-
-
-
/*
* int cardbus_mapreg_unmap(struct cardbus_softc *sc, int func, int reg,
* bus_space_tag_t tag, bus_space_handle_t handle,
@@ -348,12 +313,8 @@ cardbus_mapreg_map(sc, func, reg, type, busflags, tagp, handlep, basep, sizep)
* int reg; the offset of BAR register.
*/
int
-cardbus_mapreg_unmap(sc, func, reg, tag, handle, size)
- struct cardbus_softc *sc;
- int func, reg;
- bus_space_tag_t tag;
- bus_space_handle_t handle;
- bus_size_t size;
+cardbus_mapreg_unmap(struct cardbus_softc *sc, int func, int reg,
+ bus_space_tag_t tag, bus_space_handle_t handle, bus_size_t size)
{
cardbus_chipset_tag_t cc = sc->sc_cc;
cardbus_function_tag_t cf = sc->sc_cf;
@@ -370,9 +331,8 @@ cardbus_mapreg_unmap(sc, func, reg, tag, handle, size)
/* bus space is memory space */
DPRINTF(("%s: unmap mem space\n", sc->sc_dev.dv_xname));
rbustag = sc->sc_rbus_memt;
- } else {
- return 1;
- }
+ } else
+ return (1);
#endif
cardbustag = cardbus_make_tag(cc, cf, sc->sc_bus, sc->sc_device, func);
@@ -385,21 +345,17 @@ cardbus_mapreg_unmap(sc, func, reg, tag, handle, size)
cardbus_free_tag(cc, cf, cardbustag);
- return st;
+ return (st);
}
-
-
-
-
/*
* int cardbus_save_bar(cardbus_devfunc_t);
*
* This function saves the Base Address Registers at the CardBus
* function denoted by the argument.
*/
-int cardbus_save_bar(ct)
- cardbus_devfunc_t ct;
+int
+cardbus_save_bar(cardbus_devfunc_t ct)
{
cardbustag_t tag = Cardbus_make_tag(ct);
cardbus_chipset_tag_t cc = ct->ct_cc;
@@ -416,19 +372,17 @@ int cardbus_save_bar(ct)
Cardbus_free_tag(ct, tag);
- return 0;
+ return (0);
}
-
-
/*
* int cardbus_restore_bar(cardbus_devfunc_t);
*
* This function saves the Base Address Registers at the CardBus
* function denoted by the argument.
*/
-int cardbus_restore_bar(ct)
- cardbus_devfunc_t ct;
+int
+cardbus_restore_bar(cardbus_devfunc_t ct)
{
cardbustag_t tag = Cardbus_make_tag(ct);
cardbus_chipset_tag_t cc = ct->ct_cc;
@@ -443,5 +397,5 @@ int cardbus_restore_bar(ct)
Cardbus_free_tag(ct, tag);
- return 0;
+ return (0);
}
diff --git a/sys/dev/cardbus/cardbusvar.h b/sys/dev/cardbus/cardbusvar.h
index 8ec55bdde05..0b903048ed5 100644
--- a/sys/dev/cardbus/cardbusvar.h
+++ b/sys/dev/cardbus/cardbusvar.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: cardbusvar.h,v 1.8 2005/06/27 21:38:27 deraadt Exp $ */
+/* $OpenBSD: cardbusvar.h,v 1.9 2005/09/13 18:44:38 fgsch Exp $ */
/* $NetBSD: cardbusvar.h,v 1.17 2000/04/02 19:11:37 mycroft Exp $ */
/*
@@ -42,12 +42,9 @@
#include <dev/cardbus/rbus.h>
#endif
-
-
typedef void *cardbus_chipset_tag_t;
typedef int cardbus_intr_handle_t;
-
/* XXX they must be in cardbusreg.h */
typedef u_int32_t cardbusreg_t;
typedef pcitag_t cardbustag_t;
@@ -184,38 +181,45 @@ typedef u_int16_t cardbus_product_id_t;
#if rbus
typedef struct cardbus_functions {
- int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
- bus_addr_t addr, bus_size_t size,
- bus_addr_t mask, bus_size_t align,
- int flags, bus_addr_t *addrp,
- bus_space_handle_t *bshp);
- int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
- bus_space_handle_t, bus_size_t);
- void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int irq, int level, int (*ih)(void *), void *sc);
- void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
- int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
- int (*cardbus_power)(cardbus_chipset_tag_t, int);
-
- cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int, int);
- void (*cardbus_free_tag)(cardbus_chipset_tag_t, cardbustag_t);
- cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t, cardbustag_t, int);
- void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t, int, cardbusreg_t);
+ int (*cardbus_space_alloc)(cardbus_chipset_tag_t, rbus_tag_t,
+ bus_addr_t, bus_size_t, bus_addr_t, bus_size_t, int, bus_addr_t *,
+ bus_space_handle_t *);
+ int (*cardbus_space_free)(cardbus_chipset_tag_t, rbus_tag_t,
+ bus_space_handle_t, bus_size_t);
+ void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int, int,
+ int (*)(void *), void *);
+ void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t, void *);
+ int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
+ int (*cardbus_power)(cardbus_chipset_tag_t, int);
+
+ cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int, int);
+ void (*cardbus_free_tag)(cardbus_chipset_tag_t, cardbustag_t);
+ cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t,
+ cardbustag_t, int);
+ void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t, int,
+ cardbusreg_t);
} cardbus_function_t, *cardbus_function_tag_t;
#else
typedef struct cardbus_functions {
- int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
- int (*cardbus_power)(cardbus_chipset_tag_t, int);
- int (*cardbus_mem_open)(cardbus_chipset_tag_t, int, u_int32_t, u_int32_t);
- int (*cardbus_mem_close)(cardbus_chipset_tag_t, int);
- int (*cardbus_io_open)(cardbus_chipset_tag_t, int, u_int32_t, u_int32_t);
- int (*cardbus_io_close)(cardbus_chipset_tag_t, int);
- void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int irq, int level, int (*ih)(void *), void *sc);
- void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
-
- cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int, int); cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t, cardbustag_t, int);
- void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t, int, cardbusreg_t);
+ int (*cardbus_ctrl)(cardbus_chipset_tag_t, int);
+ int (*cardbus_power)(cardbus_chipset_tag_t, int);
+ int (*cardbus_mem_open)(cardbus_chipset_tag_t, int, u_int32_t,
+ u_int32_t);
+ int (*cardbus_mem_close)(cardbus_chipset_tag_t, int);
+ int (*cardbus_io_open)(cardbus_chipset_tag_t, int, u_int32_t,
+ u_int32_t);
+ int (*cardbus_io_close)(cardbus_chipset_tag_t, int);
+ void *(*cardbus_intr_establish)(cardbus_chipset_tag_t, int irq,
+ int level, int (*ih)(void *), void *sc);
+ void (*cardbus_intr_disestablish)(cardbus_chipset_tag_t ct, void *ih);
+
+ cardbustag_t (*cardbus_make_tag)(cardbus_chipset_tag_t, int, int, int);
+ cardbusreg_t (*cardbus_conf_read)(cardbus_chipset_tag_t, cardbustag_t,
+ int);
+ void (*cardbus_conf_write)(cardbus_chipset_tag_t, cardbustag_t, int,
+ cardbusreg_t);
} cardbus_function_t, *cardbus_function_tag_t;
#endif /* rbus */
@@ -223,24 +227,24 @@ typedef struct cardbus_functions {
* struct cbslot_attach_args is the attach argument for cardbus card.
*/
struct cbslot_attach_args {
- char *cba_busname;
- bus_space_tag_t cba_iot; /* cardbus i/o space tag */
- bus_space_tag_t cba_memt; /* cardbus mem space tag */
- bus_dma_tag_t cba_dmat; /* DMA tag */
+ char *cba_busname;
+ bus_space_tag_t cba_iot; /* cardbus i/o space tag */
+ bus_space_tag_t cba_memt; /* cardbus mem space tag */
+ bus_dma_tag_t cba_dmat; /* DMA tag */
- int cba_bus; /* cardbus bus number */
+ int cba_bus; /* cardbus bus number */
- cardbus_chipset_tag_t cba_cc; /* cardbus chipset */
- cardbus_function_tag_t cba_cf; /* cardbus functions */
- int cba_intrline; /* interrupt line */
+ cardbus_chipset_tag_t cba_cc; /* cardbus chipset */
+ cardbus_function_tag_t cba_cf; /* cardbus functions */
+ int cba_intrline; /* interrupt line */
#if rbus
- rbus_tag_t cba_rbus_iot; /* CardBus i/o rbus tag */
- rbus_tag_t cba_rbus_memt; /* CardBus mem rbus tag */
+ rbus_tag_t cba_rbus_iot; /* CardBus i/o rbus tag */
+ rbus_tag_t cba_rbus_memt; /* CardBus mem rbus tag */
#endif
- int cba_cacheline; /* cache line size */
- int cba_lattimer; /* latency timer */
+ int cba_cacheline; /* cache line size */
+ int cba_lattimer; /* latency timer */
};
@@ -256,32 +260,33 @@ struct cardbus_devfunc;
* struct cardbus_softc is the softc for cardbus card.
*/
struct cardbus_softc {
- struct device sc_dev; /* fundamental device structure */
+ struct device sc_dev; /* fundamental device structure */
- int sc_bus; /* cardbus bus number */
- int sc_device; /* cardbus device number */
- int sc_intrline; /* CardBus intrline */
-
- bus_space_tag_t sc_iot; /* CardBus I/O space tag */
- bus_space_tag_t sc_memt; /* CardBus MEM space tag */
- bus_dma_tag_t sc_dmat; /* DMA tag */
+ int sc_bus; /* cardbus bus number */
+ int sc_device; /* cardbus device number */
+ int sc_intrline; /* CardBus intrline */
- cardbus_chipset_tag_t sc_cc; /* CardBus chipset */
- cardbus_function_tag_t sc_cf; /* CardBus function */
+ bus_space_tag_t sc_iot; /* CardBus I/O space tag */
+ bus_space_tag_t sc_memt; /* CardBus MEM space tag */
+ bus_dma_tag_t sc_dmat; /* DMA tag */
+
+ cardbus_chipset_tag_t sc_cc; /* CardBus chipset */
+ cardbus_function_tag_t sc_cf; /* CardBus function */
#if rbus
- rbus_tag_t sc_rbus_iot; /* CardBus i/o rbus tag */
- rbus_tag_t sc_rbus_memt; /* CardBus mem rbus tag */
+ rbus_tag_t sc_rbus_iot; /* CardBus i/o rbus tag */
+ rbus_tag_t sc_rbus_memt; /* CardBus mem rbus tag */
#endif
- int sc_cacheline; /* cache line size */
- int sc_lattimer; /* latency timer */
- int sc_volt; /* applied Vcc voltage */
+ int sc_cacheline; /* cache line size */
+ int sc_lattimer; /* latency timer */
+ int sc_volt; /* applied Vcc voltage */
#define PCCARD_33V 0x02
#define PCCARD_XXV 0x04
#define PCCARD_YYV 0x08
- int sc_poweron_func;
- struct cardbus_devfunc *sc_funcs; /* list of cardbus device functions */
+ int sc_poweron_func;
+ struct cardbus_devfunc *sc_funcs;
+ /* list of cardbus device functions */
};
@@ -293,25 +298,25 @@ struct cardbus_softc {
* disallocation.
*/
typedef struct cardbus_devfunc {
- cardbus_chipset_tag_t ct_cc;
- cardbus_function_tag_t ct_cf;
- struct cardbus_softc *ct_sc; /* pointer to the parent */
- int ct_bus; /* bus number */
- int ct_dev; /* device number */
- int ct_func; /* function number */
+ cardbus_chipset_tag_t ct_cc;
+ cardbus_function_tag_t ct_cf;
+ struct cardbus_softc *ct_sc; /* pointer to the parent */
+ int ct_bus; /* bus number */
+ int ct_dev; /* device number */
+ int ct_func; /* function number */
#if rbus
- rbus_tag_t ct_rbus_iot; /* CardBus i/o rbus tag */
- rbus_tag_t ct_rbus_memt; /* CardBus mem rbus tag */
+ rbus_tag_t ct_rbus_iot; /* CardBus i/o rbus tag */
+ rbus_tag_t ct_rbus_memt; /* CardBus mem rbus tag */
#endif
- u_int32_t ct_bar[6]; /* Base Address Regs 0 to 6 */
- u_int32_t ct_lc; /* Latency timer and cache line size */
- /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */
+ u_int32_t ct_bar[6]; /* Base Address Regs 0 to 6 */
+ u_int32_t ct_lc; /* Latency timer and cache line size */
+ /* u_int32_t ct_cisreg; */ /* CIS reg: is it needed??? */
- struct device *ct_device; /* pointer to the device */
+ struct device *ct_device; /* pointer to the device */
- struct cardbus_devfunc *ct_next;
+ struct cardbus_devfunc *ct_next;
/* some data structure needed for tuple??? */
} *cardbus_devfunc_t;
@@ -319,59 +324,59 @@ typedef struct cardbus_devfunc {
/* XXX various things extracted from CIS */
struct cardbus_cis_info {
- int32_t manufacturer;
- int32_t product;
- char cis1_info_buf[256];
- char *cis1_info[4];
- struct cb_bar_info {
- unsigned int flags;
- unsigned int size;
- } bar[7];
- unsigned int funcid;
- union {
- struct {
- int uart_type;
- int uart_present;
- } serial;
- struct {
- char netid[6];
- char netid_present;
- char __filler;
- } network;
- } funce;
+ int32_t manufacturer;
+ int32_t product;
+ char cis1_info_buf[256];
+ char *cis1_info[4];
+ struct cb_bar_info {
+ unsigned int flags;
+ unsigned int size;
+ } bar[7];
+ unsigned int funcid;
+ union {
+ struct {
+ int uart_type;
+ int uart_present;
+ } serial;
+ struct {
+ char netid[6];
+ char netid_present;
+ char __filler;
+ } network;
+ } funce;
};
struct cardbus_attach_args {
- int ca_unit;
- cardbus_devfunc_t ca_ct;
+ int ca_unit;
+ cardbus_devfunc_t ca_ct;
- bus_space_tag_t ca_iot; /* CardBus I/O space tag */
- bus_space_tag_t ca_memt; /* CardBus MEM space tag */
- bus_dma_tag_t ca_dmat; /* DMA tag */
+ bus_space_tag_t ca_iot; /* CardBus I/O space tag */
+ bus_space_tag_t ca_memt; /* CardBus MEM space tag */
+ bus_dma_tag_t ca_dmat; /* DMA tag */
- u_int ca_bus;
- u_int ca_device;
- u_int ca_function;
- cardbustag_t ca_tag;
- cardbusreg_t ca_id;
- cardbusreg_t ca_class;
+ u_int ca_bus;
+ u_int ca_device;
+ u_int ca_function;
+ cardbustag_t ca_tag;
+ cardbusreg_t ca_id;
+ cardbusreg_t ca_class;
- /* interrupt information */
- cardbus_intr_line_t ca_intrline;
+ /* Interrupt information */
+ cardbus_intr_line_t ca_intrline;
#if rbus
- rbus_tag_t ca_rbus_iot; /* CardBus i/o rbus tag */
- rbus_tag_t ca_rbus_memt; /* CardBus mem rbus tag */
+ rbus_tag_t ca_rbus_iot; /* CardBus i/o rbus tag */
+ rbus_tag_t ca_rbus_memt; /* CardBus mem rbus tag */
#endif
- struct cardbus_cis_info ca_cis;
+ struct cardbus_cis_info ca_cis;
};
#define CARDBUS_ENABLE 1 /* enable the channel */
#define CARDBUS_DISABLE 2 /* disable the channel */
#define CARDBUS_RESET 4
-#define CARDBUS_CD 7
+#define CARDBUS_CD 7
# define CARDBUS_NOCARD 0
# define CARDBUS_5V_CARD 0x01 /* XXX: It must not exist */
# define CARDBUS_3V_CARD 0x02
@@ -411,52 +416,67 @@ struct cardbus_attach_args {
#define cardbuscf_function cf_loc[CARDBUSCF_FUNCTION]
#define CARDBUS_UNK_FUNCTION CARDBUSCF_FUNCTION_DEFAULT
-int cardbus_attach_card(struct cardbus_softc *);
-void cardbus_detach_card(struct cardbus_softc *);
-void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t, cardbus_intr_handle_t irq, int level, int (*func) (void *), void *arg);
-void cardbus_intr_disestablish(cardbus_chipset_tag_t, cardbus_function_tag_t, void *handler);
+int cardbus_attach_card(struct cardbus_softc *);
+void cardbus_detach_card(struct cardbus_softc *);
+void *cardbus_intr_establish(cardbus_chipset_tag_t, cardbus_function_tag_t,
+ cardbus_intr_handle_t irq, int level, int (*func) (void *),
+ void *arg);
+void cardbus_intr_disestablish(cardbus_chipset_tag_t,
+ cardbus_function_tag_t, void *handler);
-int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
- int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *, bus_size_t *);
-int cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
- bus_space_tag_t, bus_space_handle_t, bus_size_t);
+int cardbus_mapreg_map(struct cardbus_softc *, int, int, cardbusreg_t,
+ int, bus_space_tag_t *, bus_space_handle_t *, bus_addr_t *,
+ bus_size_t *);
+int cardbus_mapreg_unmap(struct cardbus_softc *, int, int,
+ bus_space_tag_t, bus_space_handle_t, bus_size_t);
-int cardbus_save_bar(cardbus_devfunc_t);
-int cardbus_restore_bar(cardbus_devfunc_t);
+int cardbus_save_bar(cardbus_devfunc_t);
+int cardbus_restore_bar(cardbus_devfunc_t);
-int cardbus_function_enable(struct cardbus_softc *, int function);
-int cardbus_function_disable(struct cardbus_softc *, int function);
+int cardbus_function_enable(struct cardbus_softc *, int function);
+int cardbus_function_disable(struct cardbus_softc *, int function);
-int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t,
- cardbustag_t, int, int *, cardbusreg_t *);
+int cardbus_get_capability(cardbus_chipset_tag_t, cardbus_function_tag_t,
+ cardbustag_t, int, int *, cardbusreg_t *);
struct cardbus_matchid {
cardbus_vendor_id_t cm_vid;
cardbus_product_id_t cm_pid;
};
-int cardbus_matchbyid(struct cardbus_attach_args *, const struct cardbus_matchid *, int);
-
-#define Cardbus_function_enable(ct) cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
-#define Cardbus_function_disable(ct) cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
-
+int cardbus_matchbyid(struct cardbus_attach_args *,
+ const struct cardbus_matchid *, int);
+#define Cardbus_function_enable(ct) \
+ cardbus_function_enable((ct)->ct_sc, (ct)->ct_func)
+#define Cardbus_function_disable(ct) \
+ cardbus_function_disable((ct)->ct_sc, (ct)->ct_func)
#define Cardbus_mapreg_map(ct, reg, type, busflags, tagp, handlep, basep, sizep) \
- cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), (reg), (type),\
- (busflags), (tagp), (handlep), (basep), (sizep))
-#define Cardbus_mapreg_unmap(ct, reg, tag, handle, size) \
- cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), (reg), (tag), (handle), (size))
-
-#define Cardbus_make_tag(ct) (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, (ct)->ct_bus, (ct)->ct_dev, (ct)->ct_func)
-#define cardbus_make_tag(cc, cf, bus, device, function) ((cf)->cardbus_make_tag)((cc), (bus), (device), (function))
-
-#define Cardbus_free_tag(ct, tag) (*(ct)->ct_cf->cardbus_free_tag)((ct)->ct_cc, (tag))
-#define cardbus_free_tag(cc, cf, tag) (*(cf)->cardbus_free_tag)(cc, (tag))
-
-#define Cardbus_conf_read(ct, tag, offs) (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cf, (tag), (offs))
-#define cardbus_conf_read(cc, cf, tag, offs) ((cf)->cardbus_conf_read)((cc), (tag), (offs))
-#define Cardbus_conf_write(ct, tag, offs, val) (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cf, (tag), (offs), (val))
-#define cardbus_conf_write(cc, cf, tag, offs, val) ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
+ cardbus_mapreg_map((ct)->ct_sc, (ct->ct_func), \
+ (reg), (type), (busflags), (tagp), (handlep), (basep), (sizep))
+#define Cardbus_mapreg_unmap(ct, reg, tag, handle, size)\
+ cardbus_mapreg_unmap((ct)->ct_sc, (ct->ct_func), \
+ (reg), (tag), (handle), (size))
+
+#define Cardbus_make_tag(ct) \
+ (*(ct)->ct_cf->cardbus_make_tag)((ct)->ct_cc, \
+ (ct)->ct_bus, (ct)->ct_dev, (ct)->ct_func)
+#define cardbus_make_tag(cc, cf, bus, device, function) \
+ ((cf)->cardbus_make_tag)((cc), (bus), (device), (function))
+
+#define Cardbus_free_tag(ct, tag) \
+ (*(ct)->ct_cf->cardbus_free_tag)((ct)->ct_cc, (tag))
+#define cardbus_free_tag(cc, cf, tag) \
+ (*(cf)->cardbus_free_tag)(cc, (tag))
+
+#define Cardbus_conf_read(ct, tag, offs) \
+ (*(ct)->ct_cf->cardbus_conf_read)((ct)->ct_cf, (tag), (offs))
+#define cardbus_conf_read(cc, cf, tag, offs) \
+ ((cf)->cardbus_conf_read)((cc), (tag), (offs))
+#define Cardbus_conf_write(ct, tag, offs, val) \
+ (*(ct)->ct_cf->cardbus_conf_write)((ct)->ct_cf, (tag), (offs), (val))
+#define cardbus_conf_write(cc, cf, tag, offs, val) \
+ ((cf)->cardbus_conf_write)((cc), (tag), (offs), (val))
#endif /* !_DEV_CARDBUS_CARDBUSVAR_H_ */
diff --git a/sys/dev/cardbus/rbus.c b/sys/dev/cardbus/rbus.c
index c60c2fa439e..b12f8fd9f7b 100644
--- a/sys/dev/cardbus/rbus.c
+++ b/sys/dev/cardbus/rbus.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rbus.c,v 1.8 2004/07/09 19:12:40 brad Exp $ */
+/* $OpenBSD: rbus.c,v 1.9 2005/09/13 18:44:38 fgsch Exp $ */
/* $NetBSD: rbus.c,v 1.3 1999/11/06 06:20:53 soren Exp $ */
/*
* Copyright (c) 1999
@@ -30,9 +30,6 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-
-
-#include <sys/types.h>
#include <sys/param.h>
#include <sys/systm.h>
#include <sys/device.h>
@@ -55,164 +52,140 @@
#endif
-
static rbus_tag_t rbus_new_body(bus_space_tag_t bt, rbus_tag_t parent,
struct extent *ex, bus_addr_t start,
bus_addr_t end, bus_addr_t offset,
int flags);
-
int
-rbus_space_alloc(rbt, addr, size, mask, align, flags, addrp, bshp)
- rbus_tag_t rbt;
- bus_addr_t addr;
- bus_size_t size;
- bus_addr_t mask, align;
- int flags;
- bus_addr_t *addrp;
- bus_space_handle_t *bshp;
+rbus_space_alloc(rbus_tag_t rbt, bus_addr_t addr, bus_size_t size,
+ bus_addr_t mask, bus_addr_t align, int flags, bus_addr_t *addrp,
+ bus_space_handle_t *bshp)
{
- return rbus_space_alloc_subregion(rbt, rbt->rb_start, rbt->rb_end, addr,
- size, mask, align, flags, addrp, bshp);
+ return (rbus_space_alloc_subregion(rbt, rbt->rb_start, rbt->rb_end,
+ addr, size, mask, align, flags, addrp, bshp));
}
-
-
-
int
-rbus_space_alloc_subregion(rbt, substart, subend, addr, size, mask, align, flags, addrp, bshp)
- rbus_tag_t rbt;
- bus_addr_t addr;
- bus_addr_t substart;
- bus_addr_t subend;
- bus_size_t size;
- bus_addr_t mask, align;
- int flags;
- bus_addr_t *addrp;
- bus_space_handle_t *bshp;
+rbus_space_alloc_subregion(rbus_tag_t rbt, bus_addr_t substart,
+ bus_addr_t subend, bus_addr_t addr, bus_size_t size,
+ bus_addr_t mask, bus_addr_t align, int flags, bus_addr_t *addrp,
+ bus_space_handle_t *bshp)
{
- bus_addr_t decodesize = mask + 1;
- bus_addr_t boundary, search_addr;
- int val;
- u_long result;
- int exflags = EX_FAST | EX_NOWAIT | EX_MALLOCOK;
-
- DPRINTF(("rbus_space_alloc: addr %lx, size %lx, mask %lx, align %lx\n",
- (u_long)addr, (u_long)size, (u_long)mask, (u_long)align));
-
- addr += rbt->rb_offset;
-
- if (mask == 0) {
- /* FULL Decode */
- decodesize = 0;
- }
-
- if (rbt->rb_flags == RBUS_SPACE_ASK_PARENT) {
- return rbus_space_alloc(rbt->rb_parent, addr, size, mask, align, flags,
- addrp, bshp);
- } else if (rbt->rb_flags == RBUS_SPACE_SHARE ||
- rbt->rb_flags == RBUS_SPACE_DEDICATE) {
- /* rbt has its own sh_extent */
-
- /* sanity check: the subregion [substart, subend] should be
- smaller than the region included in sh_extent */
- if (substart < rbt->rb_ext->ex_start || subend > rbt->rb_ext->ex_end) {
- DPRINTF(("rbus: out of range\n"));
- return 1;
- }
-
- if (decodesize == align) {
- if(extent_alloc_subregion(rbt->rb_ext, substart, subend, size, align, 0,
- 0, exflags, &result)) {
- return 1;
- }
- } else if (decodesize == 0) {
- /* maybe, the register is overflowed. */
-
- if (extent_alloc_subregion(rbt->rb_ext, addr, addr + size, size,
- 1, 0, 0, exflags, &result)) {
- return 1;
- }
- } else {
-
- boundary = decodesize > align ? decodesize : align;
-
- search_addr = (substart & ~(boundary - 1)) + addr;
-
- if (search_addr < substart) {
- search_addr += boundary;
- }
-
- val = 1;
- for (; search_addr + size <= subend; search_addr += boundary) {
- val = extent_alloc_subregion(rbt->rb_ext,search_addr, search_addr+size,
- size, align, 0, 0, exflags, &result);
- DPRINTF(("rbus: trying [%lx:%lx] %lx\n",
- (u_long)search_addr,
- (u_long)search_addr+size, (u_long)align));
- if (val == 0) {
- break;
- }
- }
- if (val != 0) {
- /* no space found */
- DPRINTF(("rbus: no space found\n"));
- return 1;
- }
- }
-
- if(md_space_map(rbt->rb_bt, result, size, flags, bshp)) {
- /* map failed */
- extent_free(rbt->rb_ext, result, size, exflags);
- return 1;
- }
-
- if (addrp != NULL) {
- *addrp = result + rbt->rb_offset;
- }
- return 0;
- } else {
- /* error!! */
- DPRINTF(("rbus: no rbus type\n"));
- return 1;
- }
-}
+ bus_addr_t decodesize = mask + 1;
+ bus_addr_t boundary, search_addr;
+ int val;
+ u_long result;
+ int exflags = EX_FAST | EX_NOWAIT | EX_MALLOCOK;
+ DPRINTF(("rbus_space_alloc: addr %lx, size %lx, mask %lx, align %lx\n",
+ (u_long)addr, (u_long)size, (u_long)mask, (u_long)align));
+ addr += rbt->rb_offset;
+ if (mask == 0) {
+ /* FULL Decode */
+ decodesize = 0;
+ }
+ if (rbt->rb_flags == RBUS_SPACE_ASK_PARENT) {
+ return (rbus_space_alloc(rbt->rb_parent, addr, size, mask,
+ align, flags, addrp, bshp));
+ } else if (rbt->rb_flags == RBUS_SPACE_SHARE ||
+ rbt->rb_flags == RBUS_SPACE_DEDICATE) {
+ /* rbt has its own sh_extent */
+
+ /* sanity check: the subregion [substart, subend] should be
+ smaller than the region included in sh_extent */
+ if (substart < rbt->rb_ext->ex_start ||
+ subend > rbt->rb_ext->ex_end) {
+ DPRINTF(("rbus: out of range\n"));
+ return (1);
+ }
+
+ if (decodesize == align) {
+ if (extent_alloc_subregion(rbt->rb_ext, substart,
+ subend, size, align, 0, 0, exflags, &result))
+ return (1);
+ } else if (decodesize == 0) {
+ /* maybe, the register is overflowed. */
+
+ if (extent_alloc_subregion(rbt->rb_ext, addr,
+ addr + size, size, 1, 0, 0, exflags, &result))
+ return (1);
+ } else {
+ boundary = decodesize > align ? decodesize : align;
+
+ search_addr = (substart & ~(boundary - 1)) + addr;
+
+ if (search_addr < substart)
+ search_addr += boundary;
+
+ val = 1;
+ for (; search_addr + size <= subend;
+ search_addr += boundary) {
+ val = extent_alloc_subregion(
+ rbt->rb_ext,search_addr,
+ search_addr + size, size, align, 0, 0,
+ exflags, &result);
+ DPRINTF(("rbus: trying [%lx:%lx] %lx\n",
+ (u_long)search_addr,
+ (u_long)search_addr + size,
+ (u_long)align));
+ if (val == 0)
+ break;
+ }
+
+ if (val != 0) {
+ /* no space found */
+ DPRINTF(("rbus: no space found\n"));
+ return (1);
+ }
+ }
+
+ if (md_space_map(rbt->rb_bt, result, size, flags, bshp)) {
+ /* map failed */
+ extent_free(rbt->rb_ext, result, size, exflags);
+ return (1);
+ }
+
+ if (addrp != NULL)
+ *addrp = result + rbt->rb_offset;
+ return (0);
+ } else {
+ /* error!! */
+ DPRINTF(("rbus: no rbus type\n"));
+ return (1);
+ }
+}
int
-rbus_space_free(rbt, bsh, size, addrp)
- rbus_tag_t rbt;
- bus_space_handle_t bsh;
- bus_size_t size;
- bus_addr_t *addrp;
+rbus_space_free(rbus_tag_t rbt, bus_space_handle_t bsh, bus_size_t size,
+ bus_addr_t *addrp)
{
- int exflags = EX_FAST | EX_NOWAIT;
- bus_addr_t addr;
- int status = 1;
-
- if (rbt->rb_flags == RBUS_SPACE_ASK_PARENT) {
- status = rbus_space_free(rbt->rb_parent, bsh, size, &addr);
- } else if (rbt->rb_flags == RBUS_SPACE_SHARE ||
- rbt->rb_flags == RBUS_SPACE_DEDICATE) {
- md_space_unmap(rbt->rb_bt, bsh, size, &addr);
-
- extent_free(rbt->rb_ext, addr, size, exflags);
-
- status = 0;
- } else {
- /* error. INVALID rbustag */
- status = 1;
- }
- if (addrp != NULL) {
- *addrp = addr;
- }
- return status;
-}
+ int exflags = EX_FAST | EX_NOWAIT;
+ bus_addr_t addr;
+ int status = 1;
+
+ if (rbt->rb_flags == RBUS_SPACE_ASK_PARENT) {
+ status = rbus_space_free(rbt->rb_parent, bsh, size, &addr);
+ } else if (rbt->rb_flags == RBUS_SPACE_SHARE ||
+ rbt->rb_flags == RBUS_SPACE_DEDICATE) {
+ md_space_unmap(rbt->rb_bt, bsh, size, &addr);
+
+ extent_free(rbt->rb_ext, addr, size, exflags);
+
+ status = 0;
+ } else {
+ /* error. INVALID rbustag */
+ status = 1;
+ }
+ if (addrp != NULL)
+ *addrp = addr;
+ return (status);
+}
/*
* static rbus_tag_t
@@ -222,49 +195,45 @@ rbus_space_free(rbt, bsh, size, addrp)
*
*/
static rbus_tag_t
-rbus_new_body(bt, parent, ex, start, end, offset, flags)
- bus_space_tag_t bt;
- rbus_tag_t parent;
- struct extent *ex;
- bus_addr_t start, end, offset;
- int flags;
+rbus_new_body(bus_space_tag_t bt, rbus_tag_t parent, struct extent *ex,
+ bus_addr_t start, bus_addr_t end, bus_addr_t offset, int flags)
{
- rbus_tag_t rb;
-
- /* sanity check */
- if (parent != NULL) {
- if (start < parent->rb_start || end > parent->rb_end) {
- /* out of range: [start, size] should be contained in parent space */
- return 0;
- /* Should I invoke panic? */
- }
- }
-
- if (NULL == (rb = (rbus_tag_t)malloc(sizeof(struct rbustag), M_DEVBUF,
- M_NOWAIT))) {
- panic("no memory for rbus instance");
- }
-
- rb->rb_bt = bt;
- rb->rb_parent = parent;
- rb->rb_start = start;
- rb->rb_end = end;
- rb->rb_offset = offset;
- rb->rb_flags = flags;
- rb->rb_ext = ex;
-
- DPRINTF(("rbus_new_body: [%lx, %lx] type %s name [%s]\n",
- (u_long)start, (u_long)end,
+ rbus_tag_t rb;
+
+ /* sanity check */
+ if (parent != NULL) {
+ if (start < parent->rb_start || end > parent->rb_end) {
+ /* out of range: [start, size] should be contained
+ * in parent space
+ */
+ return (0);
+ /* Should I invoke panic? */
+ }
+ }
+
+ if ((rb = (rbus_tag_t)malloc(sizeof(struct rbustag), M_DEVBUF,
+ M_NOWAIT)) == NULL) {
+ panic("no memory for rbus instance");
+ }
+
+ rb->rb_bt = bt;
+ rb->rb_parent = parent;
+ rb->rb_start = start;
+ rb->rb_end = end;
+ rb->rb_offset = offset;
+ rb->rb_flags = flags;
+ rb->rb_ext = ex;
+
+ DPRINTF(("rbus_new_body: [%lx, %lx] type %s name [%s]\n",
+ (u_long)start, (u_long)end,
flags == RBUS_SPACE_SHARE ? "share" :
flags == RBUS_SPACE_DEDICATE ? "dedicated" :
flags == RBUS_SPACE_ASK_PARENT ? "parent" : "invalid",
ex != NULL ? ex->ex_name : "noname"));
- return rb;
+ return (rb);
}
-
-
/*
* rbus_tag_t rbus_new(rbus_tag_t parent, bus_addr_t start, bus_size_t
* size, bus_addr_t offset, int flags)
@@ -272,43 +241,34 @@ rbus_new_body(bt, parent, ex, start, end, offset, flags)
* This function makes a new child rbus instance.
*/
rbus_tag_t
-rbus_new(parent, start, size, offset, flags)
- rbus_tag_t parent;
- bus_addr_t start;
- bus_size_t size;
- bus_addr_t offset;
- int flags;
+rbus_new(rbus_tag_t parent, bus_addr_t start, bus_size_t size,
+ bus_addr_t offset, int flags)
{
- rbus_tag_t rb;
- struct extent *ex = NULL;
- bus_addr_t end = start + size;
-
- if (flags == RBUS_SPACE_SHARE) {
- ex = parent->rb_ext;
- } else if (flags == RBUS_SPACE_DEDICATE) {
- if (NULL == (ex = extent_create("rbus", start, end, M_DEVBUF, NULL, 0,
- EX_NOCOALESCE|EX_NOWAIT))) {
- return NULL;
- }
- } else if (flags == RBUS_SPACE_ASK_PARENT) {
- ex = NULL;
- } else {
- /* Invalid flag */
- return 0;
- }
-
- rb = rbus_new_body(parent->rb_bt, parent, ex, start, start + size,
- offset, flags);
-
- if ((rb == NULL) && (flags == RBUS_SPACE_DEDICATE)) {
- extent_destroy(ex);
- }
-
- return rb;
-}
+ rbus_tag_t rb;
+ struct extent *ex = NULL;
+ bus_addr_t end = start + size;
+
+ if (flags == RBUS_SPACE_SHARE) {
+ ex = parent->rb_ext;
+ } else if (flags == RBUS_SPACE_DEDICATE) {
+ if ((ex = extent_create("rbus", start, end, M_DEVBUF, NULL, 0,
+ EX_NOCOALESCE|EX_NOWAIT)) == NULL)
+ return (NULL);
+ } else if (flags == RBUS_SPACE_ASK_PARENT) {
+ ex = NULL;
+ } else {
+ /* Invalid flag */
+ return (0);
+ }
+ rb = rbus_new_body(parent->rb_bt, parent, ex, start, start + size,
+ offset, flags);
+ if ((rb == NULL) && (flags == RBUS_SPACE_DEDICATE))
+ extent_destroy(ex);
+ return (rb);
+}
/*
* rbus_tag_t rbus_new_root_delegate(bus_space_tag, bus_addr_t,
@@ -317,31 +277,24 @@ rbus_new(parent, start, size, offset, flags)
* This function makes a root rbus instance.
*/
rbus_tag_t
-rbus_new_root_delegate(bt, start, size, offset)
- bus_space_tag_t bt;
- bus_addr_t start;
- bus_size_t size;
- bus_addr_t offset;
+rbus_new_root_delegate(bus_space_tag_t bt, bus_addr_t start, bus_size_t size,
+ bus_addr_t offset)
{
- rbus_tag_t rb;
- struct extent *ex;
-
- if (NULL == (ex = extent_create("rbus root", start, start + size, M_DEVBUF,
- NULL, 0, EX_NOCOALESCE|EX_NOWAIT))) {
- return NULL;
- }
-
- rb = rbus_new_body(bt, NULL, ex, start, start + size, offset,
- RBUS_SPACE_DEDICATE);
-
- if (rb == NULL) {
- extent_destroy(ex);
- }
-
- return rb;
-}
+ rbus_tag_t rb;
+ struct extent *ex;
+
+ if ((ex = extent_create("rbus root", start, start + size, M_DEVBUF,
+ NULL, 0, EX_NOCOALESCE|EX_NOWAIT)) == NULL)
+ return (NULL);
+ rb = rbus_new_body(bt, NULL, ex, start, start + size, offset,
+ RBUS_SPACE_DEDICATE);
+ if (rb == NULL)
+ extent_destroy(ex);
+
+ return (rb);
+}
/*
* rbus_tag_t rbus_new_root_share(bus_space_tag, struct extent *,
@@ -350,27 +303,21 @@ rbus_new_root_delegate(bt, start, size, offset)
* This function makes a root rbus instance.
*/
rbus_tag_t
-rbus_new_root_share(bt, ex, start, size, offset)
- bus_space_tag_t bt;
- struct extent *ex;
- bus_addr_t start;
- bus_size_t size;
- bus_addr_t offset;
+rbus_new_root_share(bus_space_tag_t bt, struct extent *ex, bus_addr_t start,
+ bus_size_t size, bus_addr_t offset)
{
- /* sanity check */
- if (start < ex->ex_start || start + size > ex->ex_end) {
- /* out of range: [start, size] should be contained in parent space */
- return 0;
- /* Should I invoke panic? */
- }
-
- return rbus_new_body(bt, NULL, ex, start, start + size, offset,
- RBUS_SPACE_SHARE);
-}
-
-
-
+ /* sanity check */
+ if (start < ex->ex_start || start + size > ex->ex_end) {
+ /* out of range: [start, size] should be contained in
+ * parent space
+ */
+ return (0);
+ /* Should I invoke panic? */
+ }
+ return (rbus_new_body(bt, NULL, ex, start, start + size, offset,
+ RBUS_SPACE_SHARE));
+}
/*
* int rbus_delete (rbus_tag_t rb)
@@ -378,16 +325,15 @@ rbus_new_root_share(bt, ex, start, size, offset)
* This function deletes the rbus structure pointed in the argument.
*/
int
-rbus_delete(rb)
- rbus_tag_t rb;
+rbus_delete(rbus_tag_t rb)
{
- DPRINTF(("rbus_delete called [%s]\n",
- rb->rb_ext != NULL ? rb->rb_ext->ex_name : "noname"));
- if (rb->rb_flags == RBUS_SPACE_DEDICATE) {
- extent_destroy(rb->rb_ext);
- }
+ DPRINTF(("rbus_delete called [%s]\n", rb->rb_ext != NULL ?
+ rb->rb_ext->ex_name : "noname"));
+
+ if (rb->rb_flags == RBUS_SPACE_DEDICATE)
+ extent_destroy(rb->rb_ext);
- free(rb, M_DEVBUF);
+ free(rb, M_DEVBUF);
- return 0;
+ return (0);
}
diff --git a/sys/dev/cardbus/rbus.h b/sys/dev/cardbus/rbus.h
index 63cad035686..907f94ab4df 100644
--- a/sys/dev/cardbus/rbus.h
+++ b/sys/dev/cardbus/rbus.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: rbus.h,v 1.3 2002/05/27 23:39:55 tdeval Exp $ */
+/* $OpenBSD: rbus.h,v 1.4 2005/09/13 18:44:38 fgsch Exp $ */
/* $NetBSD: rbus.h,v 1.3 1999/12/15 12:28:55 kleink Exp $ */
/*
* Copyright (c) 1999
@@ -39,7 +39,7 @@
* This file defines rbus (pseudo) class
*
* What is rbus?
- *
+ *
* Ths rbus is a recursive bus-space administrator. This means a
* parent bus-space administrator, which usually belongs to a bus
* bridge, makes some child bus-space administrators and gives
@@ -70,7 +70,6 @@
#define rbus 1
-
struct extent;
@@ -84,56 +83,46 @@ struct extent;
* allocate from rb_ext.
*/
struct rbustag {
- bus_space_tag_t rb_bt;
- struct rbustag *rb_parent;
- struct extent *rb_ext;
- bus_addr_t rb_start;
- bus_addr_t rb_end;
- bus_addr_t rb_offset;
+ bus_space_tag_t rb_bt;
+ struct rbustag *rb_parent;
+ struct extent *rb_ext;
+ bus_addr_t rb_start;
+ bus_addr_t rb_end;
+ bus_addr_t rb_offset;
#if notyet
- int (*rb_space_alloc)(struct rbustag *,
- bus_addr_t start, bus_addr_t end,
- bus_addr_t addr, bus_size_t size,
- bus_addr_t mask, bus_addr_t align,
- int flags,
- bus_addr_t *addrp, bus_space_handle_t *bshp);
- int (*rbus_space_free)(struct rbustag *, bus_space_handle_t,
- bus_size_t size, bus_addr_t *addrp);
+ int (*rb_space_alloc)(struct rbustag *, bus_addr_t, bus_addr_t,
+ bus_addr_t, bus_size_t, bus_addr_t, bus_addr_t,
+ int, bus_addr_t *, bus_space_handle_t *);
+ int (*rbus_space_free)(struct rbustag *, bus_space_handle_t,
+ bus_size_t, bus_addr_t *);
#endif
- int rb_flags;
+ int rb_flags;
#define RBUS_SPACE_INVALID 0x00
#define RBUS_SPACE_SHARE 0x01
#define RBUS_SPACE_DEDICATE 0x02
#define RBUS_SPACE_MASK 0x03
#define RBUS_SPACE_ASK_PARENT 0x04
- /* your own data below */
- void *rb_md;
+ /* your own data below */
+ void *rb_md;
};
typedef struct rbustag *rbus_tag_t;
-
-
/*
* These functions sugarcoat rbus interface to make rbus being used
* easier. These functions should be member functions of rbus
* `class'.
*/
-int rbus_space_alloc(rbus_tag_t,
- bus_addr_t addr, bus_size_t size, bus_addr_t mask,
- bus_addr_t align, int flags,
- bus_addr_t *addrp, bus_space_handle_t *bshp);
+int rbus_space_alloc(rbus_tag_t, bus_addr_t, bus_size_t, bus_addr_t,
+ bus_addr_t, int, bus_addr_t *, bus_space_handle_t *);
-int rbus_space_alloc_subregion(rbus_tag_t,
- bus_addr_t start, bus_addr_t end,
- bus_addr_t addr, bus_size_t size,
- bus_addr_t mask, bus_addr_t align,
- int flags,
- bus_addr_t *addrp, bus_space_handle_t *bshp);
+int rbus_space_alloc_subregion(rbus_tag_t, bus_addr_t, bus_addr_t,
+ bus_addr_t, bus_size_t, bus_addr_t, bus_addr_t, int,
+ bus_addr_t *, bus_space_handle_t *);
-int rbus_space_free(rbus_tag_t, bus_space_handle_t, bus_size_t size,
- bus_addr_t *addrp);
+int rbus_space_free(rbus_tag_t, bus_space_handle_t, bus_size_t,
+ bus_addr_t *);
/*
@@ -143,19 +132,18 @@ int rbus_space_free(rbus_tag_t, bus_space_handle_t, bus_size_t size,
* rbus_new is a constructor which make an rbus instance from a parent
* rbus.
*/
-rbus_tag_t rbus_new(rbus_tag_t parent, bus_addr_t start, bus_size_t size,
- bus_addr_t offset, int flags);
+rbus_tag_t rbus_new(rbus_tag_t, bus_addr_t, bus_size_t, bus_addr_t, int);
-rbus_tag_t rbus_new_root_delegate(bus_space_tag_t, bus_addr_t, bus_size_t,
- bus_addr_t offset);
-rbus_tag_t rbus_new_root_share(bus_space_tag_t, struct extent *,
- bus_addr_t, bus_size_t,bus_addr_t offset);
+rbus_tag_t rbus_new_root_delegate(bus_space_tag_t, bus_addr_t, bus_size_t,
+ bus_addr_t);
+rbus_tag_t rbus_new_root_share(bus_space_tag_t, struct extent *,
+ bus_addr_t, bus_size_t, bus_addr_t);
/*
* This function release bus-space used by the argument. This
* function is so-called-as a destructor.
*/
-int rbus_delete(rbus_tag_t);
+int rbus_delete(rbus_tag_t);
/*