summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2009-02-14 21:54:44 +0000
committermav <mav@FreeBSD.org>2009-02-14 21:54:44 +0000
commit200ea85159a39d9b59e115227fd3a7c347e9ceaf (patch)
tree83bc5ce5082c66890ae2f7068fd3d5bed3a57594
parent130b8c14ad2ecacb715fe63397e5e867a7a7c7ec (diff)
downloadFreeBSD-src-200ea85159a39d9b59e115227fd3a7c347e9ceaf.zip
FreeBSD-src-200ea85159a39d9b59e115227fd3a7c347e9ceaf.tar.gz
DEVICE_PROBE(9) claims that we must not initialize softc on probe stage.
Move channel softc initialization from ata_XXX_probe() to ata_XXX_attach(). Instead of calculating ata channel number as position in child device list, pass it's real number directly from controller probe routine using ivars. It is simpler and IMHO more correct.
-rw-r--r--sys/dev/ata/ata-cbus.c45
-rw-r--r--sys/dev/ata/ata-pci.c35
-rw-r--r--sys/dev/ata/ata-usb.c32
3 files changed, 53 insertions, 59 deletions
diff --git a/sys/dev/ata/ata-cbus.c b/sys/dev/ata/ata-cbus.c
index 3ca86a3..e0a15ef 100644
--- a/sys/dev/ata/ata-cbus.c
+++ b/sys/dev/ata/ata-cbus.c
@@ -106,7 +106,8 @@ static int
ata_cbus_attach(device_t dev)
{
struct ata_cbus_controller *ctlr = device_get_softc(dev);
- int rid;
+ device_t child;
+ int rid, unit;
/* allocate resources */
rid = ATA_IOADDR_RID;
@@ -159,12 +160,16 @@ ata_cbus_attach(device_t dev)
ctlr->locked_bank = -1;
ctlr->restart_bank = -1;
- if (!device_add_child(dev, "ata", 0))
- return ENOMEM;
- if (!device_add_child(dev, "ata", 1))
- return ENOMEM;
+ for (unit = 0; unit < 2; unit++) {
+ child = device_add_child(dev, "ata", unit);
+ if (child == NULL)
+ device_printf(dev, "failed to add ata child device\n");
+ else
+ device_set_ivars(child, (void *)(intptr_t)unit);
+ }
- return bus_generic_attach(dev);
+ bus_generic_attach(dev);
+ return (0);
}
static struct resource *
@@ -259,19 +264,22 @@ DRIVER_MODULE(atacbus, isa, ata_cbus_driver, ata_cbus_devclass, 0, 0);
static int
ata_cbuschannel_probe(device_t dev)
{
+ char buffer[32];
+
+ sprintf(buffer, "ATA channel %d", (int)(intptr_t)device_get_ivars(dev));
+ device_set_desc_copy(dev, buffer);
+
+ return ata_probe(dev);
+}
+
+static int
+ata_cbuschannel_attach(device_t dev)
+{
struct ata_cbus_controller *ctlr = device_get_softc(device_get_parent(dev));
struct ata_channel *ch = device_get_softc(dev);
- device_t *children;
- int count, i;
-
- /* find channel number on this controller */
- device_get_children(device_get_parent(dev), &children, &count);
- for (i = 0; i < count; i++) {
- if (children[i] == dev)
- ch->unit = i;
- }
- free(children, M_TEMP);
+ int i;
+ ch->unit = (intptr_t)device_get_ivars(dev);
/* setup the resource vectors */
for (i = ATA_DATA; i <= ATA_COMMAND; i ++) {
ch->r_io[i].res = ctlr->io;
@@ -285,7 +293,8 @@ ata_cbuschannel_probe(device_t dev)
/* initialize softc for this channel */
ch->flags |= ATA_USE_16BIT;
ata_generic_hw(dev);
- return ata_probe(dev);
+
+ return ata_attach(dev);
}
static int
@@ -333,7 +342,7 @@ ata_cbuschannel_banking(device_t dev, int flags)
static device_method_t ata_cbuschannel_methods[] = {
/* device interface */
DEVMETHOD(device_probe, ata_cbuschannel_probe),
- DEVMETHOD(device_attach, ata_attach),
+ DEVMETHOD(device_attach, ata_cbuschannel_attach),
DEVMETHOD(device_detach, ata_detach),
DEVMETHOD(device_suspend, ata_suspend),
DEVMETHOD(device_resume, ata_resume),
diff --git a/sys/dev/ata/ata-pci.c b/sys/dev/ata/ata-pci.c
index f2e4805..303a05fd 100644
--- a/sys/dev/ata/ata-pci.c
+++ b/sys/dev/ata/ata-pci.c
@@ -88,6 +88,7 @@ int
ata_pci_attach(device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(dev);
+ device_t child;
u_int32_t cmd;
int unit;
@@ -121,11 +122,13 @@ ata_pci_attach(device_t dev)
/* attach all channels on this controller */
for (unit = 0; unit < ctlr->channels; unit++) {
- if ((unit == 0 || unit == 1) && ctlr->legacy) {
- device_add_child(dev, "ata", unit);
- continue;
- }
- device_add_child(dev, "ata", devclass_find_free_unit(ata_devclass, 2));
+ child = device_add_child(dev, "ata",
+ ((unit == 0 || unit == 1) && ctlr->legacy) ?
+ unit : devclass_find_free_unit(ata_devclass, 2));
+ if (child == NULL)
+ device_printf(dev, "failed to add ata child device\n");
+ else
+ device_set_ivars(child, (void *)(intptr_t)unit);
}
bus_generic_attach(dev);
return 0;
@@ -504,23 +507,9 @@ MODULE_DEPEND(atapci, ata, 1, 1, 1);
static int
ata_pcichannel_probe(device_t dev)
{
- struct ata_channel *ch = device_get_softc(dev);
- device_t *children;
- int count, i;
char buffer[32];
- /* take care of green memory */
- bzero(ch, sizeof(struct ata_channel));
-
- /* find channel number on this controller */
- device_get_children(device_get_parent(dev), &children, &count);
- for (i = 0; i < count; i++) {
- if (children[i] == dev)
- ch->unit = i;
- }
- free(children, M_TEMP);
-
- sprintf(buffer, "ATA channel %d", ch->unit);
+ sprintf(buffer, "ATA channel %d", (int)(intptr_t)device_get_ivars(dev));
device_set_desc_copy(dev, buffer);
return ata_probe(dev);
@@ -530,8 +519,14 @@ static int
ata_pcichannel_attach(device_t dev)
{
struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
+ struct ata_channel *ch = device_get_softc(dev);
int error;
+ /* take care of green memory */
+ bzero(ch, sizeof(struct ata_channel));
+
+ ch->unit = (intptr_t)device_get_ivars(dev);
+
if (ctlr->dmainit)
ctlr->dmainit(dev);
diff --git a/sys/dev/ata/ata-usb.c b/sys/dev/ata/ata-usb.c
index 2cc25d6..f4d7fa0 100644
--- a/sys/dev/ata/ata-usb.c
+++ b/sys/dev/ata/ata-usb.c
@@ -196,6 +196,7 @@ atausb_attach(device_t dev)
usb_endpoint_descriptor_t *ed;
usbd_device_handle udev;
usb_device_request_t request;
+ device_t child;
char devinfo[1024], *proto, *subclass;
u_int8_t maxlun;
int err, i;
@@ -337,12 +338,11 @@ atausb_attach(device_t dev)
/* ata channels are children to this USB control device */
for (i = 0; i <= sc->maxlun; i++) {
- if (!device_add_child(sc->dev, "ata",
- devclass_find_free_unit(ata_devclass, 2))) {
- device_printf(sc->dev, "failed to attach ata child device\n");
- atausb_detach(dev);
- return ENXIO;
- }
+ if ((child = device_add_child(sc->dev, "ata",
+ devclass_find_free_unit(ata_devclass, 2))) == NULL) {
+ device_printf(sc->dev, "failed to add ata child device\n");
+ } else
+ device_set_ivars(child, (void *)(intptr_t)i);
}
bus_generic_attach(sc->dev);
return 0;
@@ -829,23 +829,9 @@ ata_usbchannel_end_transaction(struct ata_request *request)
static int
ata_usbchannel_probe(device_t dev)
{
- struct ata_channel *ch = device_get_softc(dev);
- device_t *children;
- int count, i;
char buffer[32];
- /* take care of green memory */
- bzero(ch, sizeof(struct ata_channel));
-
- /* find channel number on this controller */
- device_get_children(device_get_parent(dev), &children, &count);
- for (i = 0; i < count; i++) {
- if (children[i] == dev)
- ch->unit = i;
- }
- free(children, M_TEMP);
-
- sprintf(buffer, "USB lun %d", ch->unit);
+ sprintf(buffer, "USB lun %d", (int)(intptr_t)device_get_ivars(dev));
device_set_desc_copy(dev, buffer);
return 0;
@@ -856,8 +842,12 @@ ata_usbchannel_attach(device_t dev)
{
struct ata_channel *ch = device_get_softc(dev);
+ /* take care of green memory */
+ bzero(ch, sizeof(struct ata_channel));
+
/* initialize the softc basics */
ch->dev = dev;
+ ch->unit = (intptr_t)device_get_ivars(dev);
ch->state = ATA_IDLE;
ch->hw.begin_transaction = ata_usbchannel_begin_transaction;
ch->hw.end_transaction = ata_usbchannel_end_transaction;
OpenPOWER on IntegriCloud