From owner-svn-src-head@FreeBSD.ORG Sat Feb 14 21:54:45 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 3FA011065670; Sat, 14 Feb 2009 21:54:45 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 2D1D18FC18; Sat, 14 Feb 2009 21:54:45 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n1ELsjq6031278; Sat, 14 Feb 2009 21:54:45 GMT (envelope-from mav@svn.freebsd.org) Received: (from mav@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n1ELsi2o031275; Sat, 14 Feb 2009 21:54:44 GMT (envelope-from mav@svn.freebsd.org) Message-Id: <200902142154.n1ELsi2o031275@svn.freebsd.org> From: Alexander Motin Date: Sat, 14 Feb 2009 21:54:44 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r188615 - head/sys/dev/ata X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 14 Feb 2009 21:54:45 -0000 Author: mav Date: Sat Feb 14 21:54:44 2009 New Revision: 188615 URL: http://svn.freebsd.org/changeset/base/188615 Log: 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. Modified: head/sys/dev/ata/ata-cbus.c head/sys/dev/ata/ata-pci.c head/sys/dev/ata/ata-usb.c Modified: head/sys/dev/ata/ata-cbus.c ============================================================================== --- head/sys/dev/ata/ata-cbus.c Sat Feb 14 21:12:58 2009 (r188614) +++ head/sys/dev/ata/ata-cbus.c Sat Feb 14 21:54:44 2009 (r188615) @@ -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_dri 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, in 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), Modified: head/sys/dev/ata/ata-pci.c ============================================================================== --- head/sys/dev/ata/ata-pci.c Sat Feb 14 21:12:58 2009 (r188614) +++ head/sys/dev/ata/ata-pci.c Sat Feb 14 21:54:44 2009 (r188615) @@ -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); Modified: head/sys/dev/ata/ata-usb.c ============================================================================== --- head/sys/dev/ata/ata-usb.c Sat Feb 14 21:12:58 2009 (r188614) +++ head/sys/dev/ata/ata-usb.c Sat Feb 14 21:54:44 2009 (r188615) @@ -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 at 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;