summaryrefslogtreecommitdiffstats
path: root/sys/dev/ata/ata-pci.c
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 /sys/dev/ata/ata-pci.c
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.
Diffstat (limited to 'sys/dev/ata/ata-pci.c')
-rw-r--r--sys/dev/ata/ata-pci.c35
1 files changed, 15 insertions, 20 deletions
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);
OpenPOWER on IntegriCloud