summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjhb <jhb@FreeBSD.org>2009-06-10 13:56:42 +0000
committerjhb <jhb@FreeBSD.org>2009-06-10 13:56:42 +0000
commitff56813d72ced1434a2e9649783a322834dc196f (patch)
tree3e66921001b9c30ba2a86d2c4091684ba41bf425
parent6e0d8393e5e1691a18a3eef76f6b2470f4f3b975 (diff)
downloadFreeBSD-src-ff56813d72ced1434a2e9649783a322834dc196f.zip
FreeBSD-src-ff56813d72ced1434a2e9649783a322834dc196f.tar.gz
Preallocate the four BARs in ALI SATA controllers during the chipinit
routine and save the resources using a chipset-data structure. Use these preallocated resources to setup resources for the SATA channels to avoid asking the PCI bus to allocate the same BAR multiple times. Tested by: bms MFC after: 1 week
-rw-r--r--sys/dev/ata/chipsets/ata-acerlabs.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/sys/dev/ata/chipsets/ata-acerlabs.c b/sys/dev/ata/chipsets/ata-acerlabs.c
index 82e1aab4..a888989 100644
--- a/sys/dev/ata/chipsets/ata-acerlabs.c
+++ b/sys/dev/ata/chipsets/ata-acerlabs.c
@@ -63,6 +63,9 @@ static void ata_ali_setmode(device_t dev, int mode);
#define ALI_NEW 0x02
#define ALI_SATA 0x04
+struct ali_sata_resources {
+ struct resource *bars[4];
+};
/*
* Acer Labs Inc (ALI) chipset support functions
@@ -98,6 +101,8 @@ static int
ata_ali_chipinit(device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(dev);
+ struct ali_sata_resources *res;
+ int i, rid;
if (ata_setup_interrupt(dev, ata_generic_intr))
return ENXIO;
@@ -113,6 +118,22 @@ ata_ali_chipinit(device_t dev)
if ((ctlr->chip->chipid == ATA_ALI_5288) &&
(ata_ahci_chipinit(dev) != ENXIO))
return 0;
+
+ /* Allocate resources for later use by channel attach routines. */
+ res = malloc(sizeof(struct ali_sata_resources), M_TEMP, M_WAITOK);
+ for (i = 0; i < 4; i++) {
+ rid = PCIR_BAR(i);
+ res->bars[i] = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &rid,
+ RF_ACTIVE);
+ if (res->bars[i] == NULL) {
+ device_printf(dev, "Failed to allocate BAR %d\n", i);
+ for (i--; i >=0; i--)
+ bus_release_resource(dev, SYS_RES_IOPORT,
+ PCIR_BAR(i), res->bars[i]);
+ free(res, M_TEMP);
+ }
+ }
+ ctlr->chipset_data = res;
break;
case ALI_NEW:
@@ -168,20 +189,18 @@ ata_ali_sata_ch_attach(device_t dev)
device_t parent = device_get_parent(dev);
struct ata_pci_controller *ctlr = device_get_softc(parent);
struct ata_channel *ch = device_get_softc(dev);
+ struct ali_sata_resources *res;
struct resource *io = NULL, *ctlio = NULL;
int unit01 = (ch->unit & 1), unit10 = (ch->unit & 2);
- int i, rid;
-
- rid = PCIR_BAR(0) + (unit01 ? 8 : 0);
- io = bus_alloc_resource_any(parent, SYS_RES_IOPORT, &rid, RF_ACTIVE);
- if (!io)
- return ENXIO;
-
- rid = PCIR_BAR(1) + (unit01 ? 8 : 0);
- ctlio = bus_alloc_resource_any(parent, SYS_RES_IOPORT, &rid, RF_ACTIVE);
- if (!ctlio) {
- bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
- return ENXIO;
+ int i;
+
+ res = ctlr->chipset_data;
+ if (unit01) {
+ io = res->bars[2];
+ ctlio = res->bars[3];
+ } else {
+ io = res->bars[0];
+ ctlio = res->bars[1];
}
for (i = ATA_DATA; i <= ATA_COMMAND; i ++) {
OpenPOWER on IntegriCloud