Deleted Added
full compact
28c28
< * $FreeBSD: head/sys/dev/ata/ata-all.c 56988 2000-02-04 10:20:22Z sos $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 57325 2000-02-18 20:57:33Z sos $
32d31
< #include "apm.h"
33a33
> #include "card.h"
68,69c68,69
< #if NAPM > 0
< #include <machine/apm_bios.h>
---
> #ifdef __alpha__
> #include <machine/md_var.h>
76,79c76,79
< #if SMP == 0
< #define isa_apic_irq(x) x
< #endif
< #define IOMASK 0xfffffffc
---
> #define IOMASK 0xfffffffc
> #define ATA_IOADDR_RID 0
> #define ATA_ALTIOADDR_RID 1
> #define ATA_BMADDR_RID 2
82,83c82,87
< static int32_t ata_probe(int32_t, int32_t, int32_t, device_t, int32_t *);
< static void ata_attach(void *);
---
> static int ata_probe(device_t);
> static int ata_attach(device_t);
> static int ata_detach(device_t);
> static int ata_resume(device_t);
> static void ata_boot_attach(void);
> static void ata_intr(void *);
85d88
< static void ataintr(void *);
92,93d94
< static int32_t atanlun = 2;
< static struct intr_config_hook *ata_attach_hook = NULL;
95c96,98
< struct ata_softc *atadevices[MAXATA];
---
> static devclass_t ata_pci_devclass;
> static struct intr_config_hook *ata_delayed_attach = NULL;
> static char ata_conf[256];
108c111
< ata_isaprobe(device_t dev)
---
> ata_isa_probe(device_t dev)
109a113
> struct ata_softc *scp = device_get_softc(dev);
112,113c116
< int32_t ctlr, res;
< int32_t lun;
---
> u_long tmp;
115c118
< /* Check isapnp ids */
---
> /* check isapnp ids */
119,121c122,125
< /* Allocate the port range */
< rid = 0;
< port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
---
> /* allocate the port range */
> rid = ATA_IOADDR_RID;
> port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
125,132c129,133
< /* check if allready in use by a PCI device */
< for (ctlr = 0; ctlr < atanlun; ctlr++) {
< if (atadevices[ctlr] && atadevices[ctlr]->ioaddr==rman_get_start(port)){
< printf("ata-isa%d: already registered as ata%d\n",
< device_get_unit(dev), ctlr);
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
< return ENXIO;
< }
---
> /* alloctate the altport range */
> if (bus_get_resource(dev, SYS_RES_IOPORT, 1, &tmp, &tmp)) {
> bus_set_resource(dev, SYS_RES_IOPORT, 1,
> rman_get_start(port) + ATA_ALTPORT,
> ATA_ALTIOSIZE);
133a135,139
> bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
> scp->unit = device_get_unit(dev);
> scp->flags |= ATA_USE_16BIT;
> return ata_probe(dev);
> }
135,137c141,147
< lun = 0;
< res = ata_probe(rman_get_start(port), rman_get_start(port) + ATA_ALTPORT,
< 0, dev, &lun);
---
> static device_method_t ata_isa_methods[] = {
> /* device interface */
> DEVMETHOD(device_probe, ata_isa_probe),
> DEVMETHOD(device_attach, ata_attach),
> DEVMETHOD(device_resume, ata_resume),
> { 0, 0 }
> };
139c149,153
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
---
> static driver_t ata_isa_driver = {
> "ata",
> ata_isa_methods,
> sizeof(struct ata_softc),
> };
141,148c155,156
< if (res) {
< isa_set_portsize(dev, res);
< *(int *)device_get_softc(dev) = lun;
< atadevices[lun]->flags |= ATA_USE_16BIT;
< return 0;
< }
< return ENXIO;
< }
---
> DRIVER_MODULE(ata, isa, ata_isa_driver, ata_devclass, 0, 0);
> #endif
149a158
> #if NCARD > 0
151c160
< ata_isaattach(device_t dev)
---
> ata_pccard_probe(device_t dev)
152a162
> struct ata_softc *scp = device_get_softc(dev);
154,155d163
< struct resource *irq;
< void *ih;
156a165
> u_long tmp;
158,160c167,170
< /* Allocate the port range and interrupt */
< rid = 0;
< port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
---
> /* allocate the port range */
> rid = ATA_IOADDR_RID;
> port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
162c172
< return (ENOMEM);
---
> return ENOMEM;
164,168c174,178
< rid = 0;
< irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1, RF_ACTIVE);
< if (!irq) {
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
< return (ENOMEM);
---
> /* alloctate the altport range */
> if (bus_get_resource(dev, SYS_RES_IOPORT, 1, &tmp, &tmp)) {
> bus_set_resource(dev, SYS_RES_IOPORT, 1,
> rman_get_start(port) + ATA_ALTPORT_PCCARD,
> ATA_ALTIOSIZE);
170,171c180,183
< return bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr,
< atadevices[*(int *)device_get_softc(dev)], &ih);
---
> bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
> scp->unit = device_get_unit(dev);
> scp->flags |= ATA_USE_16BIT;
> return ata_probe(dev);
174,177c186,191
< static device_method_t ata_isa_methods[] = {
< /* Device interface */
< DEVMETHOD(device_probe, ata_isaprobe),
< DEVMETHOD(device_attach, ata_isaattach),
---
> static device_method_t ata_pccard_methods[] = {
> /* device interface */
> DEVMETHOD(device_probe, ata_pccard_probe),
> DEVMETHOD(device_attach, ata_attach),
> DEVMETHOD(device_detach, ata_detach),
> DEVMETHOD(device_resume, ata_resume),
181c195
< static driver_t ata_isa_driver = {
---
> static driver_t ata_pccard_driver = {
183,184c197,198
< ata_isa_methods,
< sizeof(int),
---
> ata_pccard_methods,
> sizeof(struct ata_softc),
187c201
< DRIVER_MODULE(ata, isa, ata_isa_driver, ata_devclass, 0, 0);
---
> DRIVER_MODULE(ata, pccard, ata_pccard_driver, ata_devclass, 0, 0);
190a205,236
> struct ata_pci_softc {
> struct resource *bmio;
> struct resource bmio_1;
> struct resource bmio_2;
> struct resource *irq;
> int32_t irqcnt;
> };
>
> static int32_t
> ata_find_dev(device_t dev, int32_t type)
> {
> device_t *children, child;
> int nchildren, i;
>
> if (device_get_children(device_get_parent(dev), &children, &nchildren))
> return 0;
>
> for (i = 0; i < nchildren; i++) {
> child = children[i];
>
> /* check that it's on the same silicon and the device we want */
> if (pci_get_slot(dev) == pci_get_slot(child) &&
> pci_get_vendor(child) == (type & 0xffff) &&
> pci_get_device(child) == ((type & 0xffff0000) >> 16)) {
> free(children, M_TEMP);
> return 1;
> }
> }
> free(children, M_TEMP);
> return 0;
> }
>
192c238
< ata_pcimatch(device_t dev)
---
> ata_pci_match(device_t dev)
207c253
< return "Intel PIIX4 ATA-33 controller";
---
> return "Intel PIIX4 ATA33 controller";
210c256
< return "Intel ICH ATA-66 controller";
---
> return "Intel ICH ATA66 controller";
213c259
< return "Intel ICH0 ATA-33 controller";
---
> return "Intel ICH0 ATA33 controller";
216c262
< return "AcerLabs Aladdin ATA-33 controller";
---
> return "AcerLabs Aladdin ATA33 controller";
218c264
< case 0x05711106: /* 82c586 & 82c686 */
---
> case 0x05711106:
220c266
< return "VIA 82C586 ATA-33 controller";
---
> return "VIA 82C586 ATA33 controller";
222c268
< return "VIA 82C596 ATA-33 controller";
---
> return "VIA 82C596 ATA33 controller";
224c270
< return "VIA 82C686 ATA-66 controller";
---
> return "VIA 82C686 ATA66 controller";
228c274
< return "SiS 5591 ATA-33 controller";
---
> return "SiS 5591 ATA33 controller";
229a276,278
> case 0x06461095:
> return "CMD 646 ATA controller";
>
231c280
< return "AMD 756 ATA-66 controller";
---
> return "AMD 756 ATA66 controller";
234c283
< return "Promise ATA-33 controller";
---
> return "Promise ATA33 controller";
237c286
< return "Promise ATA-66 controller";
---
> return "Promise ATA66 controller";
240c289
< return "HighPoint HPT366 ATA-66 controller";
---
> return "HighPoint HPT366 ATA66 controller";
242a292,295
> case 0x10001042:
> case 0x10011042:
> return "RZ 100? ATA controller !WARNING! buggy chip data loss possible";
>
244c297
< return "CMD 640 ATA controller (generic mode)";
---
> return "CMD 640 ATA controller !WARNING! buggy chip data loss possible";
246,248d298
< case 0x06461095:
< return "CMD 646 ATA controller (generic mode)";
<
250c300,302
< return "Cypress 82C693 ATA controller (generic mode)";
---
> if (pci_get_subclass(dev) == PCIS_STORAGE_IDE)
> return "Cypress 82C693 ATA controller (generic mode)";
> break;
254a307
> /* unknown chipsets, try generic DMA if it seems possible */
264c317
< ata_pciprobe(device_t dev)
---
> ata_pci_probe(device_t dev)
266c319
< const char *desc = ata_pcimatch(dev);
---
> const char *desc = ata_pci_match(dev);
277c330
< ata_pciattach(device_t dev)
---
> ata_pci_add_child(device_t dev, int unit)
279,281c332,351
< int unit = device_get_unit(dev);
< struct ata_softc *scp;
< u_int32_t type;
---
> device_t child;
> int lun;
>
> /* check if this is located at one of the std addresses */
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV)
> lun = unit;
> else
> lun = -1;
>
> if (!(child = device_add_child(dev, "ata", lun)))
> return ENOMEM;
>
> device_set_ivars(child, (void *)(uintptr_t) unit);
> return 0;
> }
>
> static int
> ata_pci_attach(device_t dev)
> {
> struct ata_pci_softc *sc = device_get_softc(dev);
283,287c353,354
< u_int32_t cmd;
< int32_t iobase_1, iobase_2, altiobase_1, altiobase_2;
< int32_t bmaddr_1 = 0, bmaddr_2 = 0, irq1, irq2;
< struct resource *irq = NULL;
< int32_t lun;
---
> u_int32_t type, cmd;
> int rid;
295,327d361
< #ifdef ATA_DEBUG
< printf("ata-pci%d: type=%08x class=%02x subclass=%02x cmd=%08x if=%02x\n",
< unit, type, class, subclass, cmd, pci_get_progif(dev));
< #endif
<
< if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
< iobase_1 = IO_WD1;
< altiobase_1 = iobase_1 + ATA_ALTPORT;
< irq1 = 14;
< }
< else {
< iobase_1 = pci_read_config(dev, 0x10, 4) & IOMASK;
< altiobase_1 = pci_read_config(dev, 0x14, 4) & IOMASK;
< irq1 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
< /* this is needed for old non-std systems */
< if (iobase_1 == IO_WD1 && irq1 == 0x00)
< irq1 = 14;
< }
<
< if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
< iobase_2 = IO_WD2;
< altiobase_2 = iobase_2 + ATA_ALTPORT;
< irq2 = 15;
< }
< else {
< iobase_2 = pci_read_config(dev, 0x18, 4) & IOMASK;
< altiobase_2 = pci_read_config(dev, 0x1c, 4) & IOMASK;
< irq2 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
< /* this is needed for old non-std systems */
< if (iobase_2 == IO_WD2 && irq2 == 0x00)
< irq2 = 15;
< }
<
332a367
>
334,337c369,373
< if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & IOMASK))
< bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
< else
< printf("ata-pci%d: Busmastering DMA not configured\n", unit);
---
> rid = 0x20;
> sc->bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> 0, ~0, 1, RF_ACTIVE);
> if (!sc->bmio)
> device_printf(dev, "Busmastering DMA not configured\n");
340c376
< printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
---
> device_printf(dev, "Busmastering DMA not enabled\n");
345,346c381,383
< bmaddr_1 = pci_read_config(dev, 0x20, 4) & IOMASK;
< bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
---
> rid = 0x20;
> sc->bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> 0, ~0, 1, RF_ACTIVE);
350c387
< printf("ata-pci%d: Busmastering DMA not supported\n", unit);
---
> device_printf(dev, "Busmastering DMA not supported\n");
358a396
>
360c398,399
< outb(bmaddr_1 + 0x11, inb(bmaddr_1 + 0x11) | 0x0a);
---
> outb(rman_get_start(sc->bmio) + 0x11,
> inb(rman_get_start(sc->bmio) + 0x11) | 0x0a);
364c403,404
< outb(bmaddr_1 + 0x1f, inb(bmaddr_1 + 0x1f) | 0x01);
---
> outb(rman_get_start(sc->bmio) + 0x1f,
> inb(rman_get_start(sc->bmio) + 0x1f) | 0x01);
391,395c431
< /* set the chiptype to the hostchip ID, makes life easier */
< if (ata_find_dev(dev, 0x05861106))
< type = 0x05861106;
< if (ata_find_dev(dev, 0x05961106))
< type = 0x05961106;
---
> /* prepare for ATA-66 on the 82C686 */
397,398d432
< type = 0x06861106;
< /* prepare for ATA-66 on the 82C686 */
404,409d437
<
< /* now probe the addresse found for "real" ATA/ATAPI hardware */
< lun = 0;
< if (iobase_1 && ata_probe(iobase_1, altiobase_1, bmaddr_1, dev, &lun)) {
< int rid;
< void *ih;
411,426c439,516
< scp = atadevices[lun];
< scp->chiptype = type;
< rid = 0;
< if (iobase_1 == IO_WD1) {
< #ifdef __alpha__
< alpha_platform_setup_ide_intr(0, ataintr, scp);
< #else
< bus_set_resource(dev, SYS_RES_IRQ, rid, irq1, 1);
< if (!(irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
< RF_SHAREABLE | RF_ACTIVE)))
< printf("ata_pciattach: Unable to alloc interrupt\n");
< #endif
< } else {
< if (!(irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
< RF_SHAREABLE | RF_ACTIVE)))
< printf("ata_pciattach: Unable to alloc interrupt\n");
---
> ata_pci_add_child(dev, 0);
>
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV ||
> pci_read_config(dev, 0x18, 4) & IOMASK)
> ata_pci_add_child(dev, 1);
>
> return bus_generic_attach(dev);
> }
>
> static int
> ata_pci_print_child(device_t dev, device_t child)
> {
> struct ata_softc *scp = device_get_softc(child);
> int unit = (uintptr_t) device_get_ivars(child);
> int retval = 0;
>
> retval += bus_print_child_header(dev, child);
> retval += printf(": at 0x%x", scp->ioaddr);
>
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV)
> retval += printf(" irq %d", 14 + unit);
>
> retval += bus_print_child_footer(dev, child);
>
> return retval;
> }
>
> static struct resource *
> ata_pci_alloc_resource(device_t dev, device_t child, int type, int *rid,
> u_long start, u_long end, u_long count, u_int flags)
> {
> struct ata_pci_softc *sc = device_get_softc(dev);
> int masterdev = pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV;
> int unit = (int)device_get_ivars(child);
> int myrid;
>
> if (type == SYS_RES_IOPORT) {
> switch (*rid) {
> case ATA_IOADDR_RID:
> if (masterdev) {
> myrid = 0;
> start = (unit == 0 ? IO_WD1 : IO_WD2);
> end = start + ATA_IOSIZE - 1;
> count = ATA_IOSIZE;
> }
> else
> myrid = 0x10 + 8 * unit;
> break;
>
> case ATA_ALTIOADDR_RID:
> if (masterdev) {
> myrid = 0;
> start = (unit == 0 ? IO_WD1 : IO_WD2) + ATA_ALTPORT;
> end = start + ATA_ALTIOSIZE - 1;
> count = ATA_ALTIOSIZE;
> }
> else
> myrid = 0x14 + 8 * unit;
> break;
>
> case ATA_BMADDR_RID:
> /* the busmaster resource is shared between the two channels */
> if (sc->bmio) {
> if (unit == 0) {
> sc->bmio_1 = *sc->bmio;
> sc->bmio_1.r_end = sc->bmio->r_start + ATA_BM_OFFSET1;
> return &sc->bmio_1;
> } else {
> sc->bmio_2 = *sc->bmio;
> sc->bmio_2.r_start = sc->bmio->r_start + ATA_BM_OFFSET1;
> sc->bmio_2.r_end = sc->bmio_2.r_start + ATA_BM_OFFSET1;
> return &sc->bmio_2;
> }
> }
> break;
>
> default:
> return 0;
428,431c518,528
< if (irq)
< bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, scp, &ih);
< printf("ata%d at 0x%04x irq %d on ata-pci%d\n",
< lun, iobase_1, isa_apic_irq(irq1), unit);
---
>
> if (masterdev)
> /* make the parent just pass through the allocation. */
> return BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> else
> /* we are using the parent resource directly. */
> return BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
433,436d529
< lun = 1;
< if (iobase_2 && ata_probe(iobase_2, altiobase_2, bmaddr_2, dev, &lun)) {
< int rid;
< void *ih;
438,442c531,541
< scp = atadevices[lun];
< scp->chiptype = type;
< if (iobase_2 == IO_WD2) {
< #ifdef __alpha__
< alpha_platform_setup_ide_intr(1, ataintr, scp);
---
> if (type == SYS_RES_IRQ) {
> if (*rid != 0)
> return 0;
>
> if (masterdev) {
> #ifdef __i386__
> int irq = (unit == 0 ? 14 : 15);
>
> return BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IRQ, rid,
> irq, irq, 1, flags & ~RF_SHAREABLE);
444,448c543
< rid = 1;
< bus_set_resource(dev, SYS_RES_IRQ, rid, irq2, 1);
< if (!(irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
< RF_SHAREABLE | RF_ACTIVE)))
< printf("ata_pciattach: Unable to alloc interrupt\n");
---
> return alpha_platform_alloc_ide_intr(unit);
451,456c546,551
< rid = 0;
< if (irq1 != irq2 || irq == NULL) {
< if (!(irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
< RF_SHAREABLE | RF_ACTIVE)))
< printf("ata_pciattach: Unable to alloc interrupt\n");
< }
---
> /* primary and secondary channels share the same interrupt */
> sc->irqcnt++;
> if (!sc->irq)
> sc->irq = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IRQ, rid, 0, ~0, 1, flags);
> return sc->irq;
458,461d552
< if (irq)
< bus_setup_intr(dev, irq, INTR_TYPE_BIO, ataintr, scp, &ih);
< printf("ata%d at 0x%04x irq %d on ata-pci%d\n",
< lun, iobase_2, isa_apic_irq(irq2), unit);
466,467c557,559
< int32_t
< ata_find_dev(device_t dev, int32_t type)
---
> static int
> ata_pci_release_resource(device_t dev, device_t child, int type, int rid,
> struct resource *r)
469,470c561,564
< device_t *children, child;
< int nchildren, i;
---
> struct ata_pci_softc *sc = device_get_softc(dev);
> int unit = (uintptr_t) device_get_ivars(child);
> int masterdev = pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV;
> int myrid = 0;
472,473c566,573
< if (device_get_children(device_get_parent(dev), &children, &nchildren))
< return 0;
---
> if (type == SYS_RES_IOPORT) {
> switch (rid) {
> case ATA_IOADDR_RID:
> if (masterdev)
> myrid = 0;
> else
> myrid = 0x10 + 8 * unit;
> break;
475,476c575,580
< for (i = 0; i < nchildren; i++) {
< child = children[i];
---
> case ATA_ALTIOADDR_RID:
> if (masterdev)
> myrid = 0;
> else
> myrid = 0x14 + 8 * unit;
> break;
478,483c582,586
< /* check that it's on the same silicon and the device we want */
< if (pci_get_slot(dev) == pci_get_slot(child) &&
< pci_get_vendor(child) == (type & 0xffff) &&
< pci_get_device(child) == ((type & 0xffff0000)>>16)) {
< free(children, M_TEMP);
< return 1;
---
> case ATA_BMADDR_RID:
> return 0;
>
> default:
> return ENOENT;
484a588,596
>
> if (masterdev)
> /* make the parent just pass through the allocation. */
> return BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, myrid, r);
> else
> /* we are using the parent resource directly. */
> return BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, myrid, r);
486,487c598,618
< free(children, M_TEMP);
< return 0;
---
> if (type == SYS_RES_IRQ) {
> if (rid != 0)
> return ENOENT;
>
> if (masterdev) {
> #ifdef __i386__
> return BUS_RELEASE_RESOURCE(device_get_parent(dev),
> child, SYS_RES_IRQ, rid, r);
> #else
> return alpha_platform_release_ide_intr(unit, r);
> #endif
> }
> else {
> if (--sc->irqcnt)
> return 0;
>
> return BUS_RELEASE_RESOURCE(device_get_parent(dev),
> dev, SYS_RES_IRQ, rid, r);
> }
> }
> return EINVAL;
489a621,653
> static int
> ata_pci_setup_intr(device_t dev, device_t child, struct resource *irq,
> int flags, driver_intr_t *intr, void *arg,
> void **cookiep)
> {
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
> #ifdef __i386__
> return BUS_SETUP_INTR(device_get_parent(dev), child, irq,
> flags, intr, arg, cookiep);
> #else
> return alpha_platform_setup_ide_intr(irq, intr, arg, cookiep);
> #endif
> }
> else
> return BUS_SETUP_INTR(device_get_parent(dev), dev, irq,
> flags, intr, arg, cookiep);
> }
>
> static int
> ata_pci_teardown_intr(device_t dev, device_t child, struct resource *irq,
> void *cookie)
> {
> if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
> #ifdef __i386__
> return BUS_TEARDOWN_INTR(device_get_parent(dev), child, irq, cookie);
> #else
> return alpha_platform_teardown_ide_intr(irq, cookie);
> #endif
> }
> else
> return BUS_TEARDOWN_INTR(device_get_parent(dev), dev, irq, cookie);
> }
>
491,493c655,669
< /* Device interface */
< DEVMETHOD(device_probe, ata_pciprobe),
< DEVMETHOD(device_attach, ata_pciattach),
---
> /* device interface */
> DEVMETHOD(device_probe, ata_pci_probe),
> DEVMETHOD(device_attach, ata_pci_attach),
> DEVMETHOD(device_shutdown, bus_generic_shutdown),
> DEVMETHOD(device_suspend, bus_generic_suspend),
> DEVMETHOD(device_resume, bus_generic_resume),
>
> /* bus methods */
> DEVMETHOD(bus_print_child, ata_pci_print_child),
> DEVMETHOD(bus_alloc_resource, ata_pci_alloc_resource),
> DEVMETHOD(bus_release_resource, ata_pci_release_resource),
> DEVMETHOD(bus_activate_resource, bus_generic_activate_resource),
> DEVMETHOD(bus_deactivate_resource, bus_generic_deactivate_resource),
> DEVMETHOD(bus_setup_intr, ata_pci_setup_intr),
> DEVMETHOD(bus_teardown_intr, ata_pci_teardown_intr),
498c674
< "ata-pci",
---
> "atapci",
500c676
< sizeof(int),
---
> sizeof(struct ata_pci_softc),
503c679,716
< DRIVER_MODULE(ata, pci, ata_pci_driver, ata_devclass, 0, 0);
---
> DRIVER_MODULE(atapci, pci, ata_pci_driver, ata_devclass, 0, 0);
>
> static int
> ata_pcisub_probe(device_t dev)
> {
> struct ata_softc *scp = device_get_softc(dev);
>
> /* kids of pci ata chipsets has their physical unit number in ivars */
> scp->unit = (uintptr_t) device_get_ivars(dev);
>
> /* set the chiptype to the hostchip ID, makes life easier */
> if (ata_find_dev(device_get_parent(dev), 0x05861106))
> scp->chiptype = 0x05861106;
> else if (ata_find_dev(device_get_parent(dev), 0x05961106))
> scp->chiptype = 0x05961106;
> else if (ata_find_dev(device_get_parent(dev), 0x06861106))
> scp->chiptype = 0x06861106;
> else
> scp->chiptype = pci_get_devid(device_get_parent(dev));
> return ata_probe(dev);
> }
>
> static device_method_t ata_pcisub_methods[] = {
> /* device interface */
> DEVMETHOD(device_probe, ata_pcisub_probe),
> DEVMETHOD(device_attach, ata_attach),
> DEVMETHOD(device_detach, ata_detach),
> DEVMETHOD(device_resume, ata_resume),
> { 0, 0 }
> };
>
> static driver_t ata_pcisub_driver = {
> "ata",
> ata_pcisub_methods,
> sizeof(struct ata_softc),
> };
>
> DRIVER_MODULE(ata, atapci, ata_pcisub_driver, ata_pci_devclass, 0, 0);
506,508c719,720
< static int32_t
< ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr,
< device_t dev, int32_t *unit)
---
> static int
> ata_probe(device_t dev)
510,511c722,728
< struct ata_softc *scp;
< int32_t lun, mask = 0;
---
> struct ata_softc *scp = device_get_softc(dev);
> struct resource *io = 0;
> struct resource *altio = 0;
> struct resource *bmio = 0;
> int rid;
> int32_t ioaddr, altioaddr, bmaddr;
> int32_t mask = 0;
514,517c731,732
< if (atanlun > MAXATA) {
< printf("ata: unit out of range(%d)\n", atanlun);
< return 0;
< }
---
> if (!scp || scp->flags & ATA_ATTACHED)
> return ENXIO;
519,525c734,737
< /* check if this is located at one of the std addresses */
< if (ioaddr == IO_WD1)
< lun = 0;
< else if (ioaddr == IO_WD2)
< lun = 1;
< else
< lun = atanlun++;
---
> /* initialize the softc basics */
> scp->active = ATA_IDLE;
> scp->dev = dev;
> scp->devices = 0;
527,536c739,743
< if ((scp = atadevices[lun])) {
< ata_printf(scp, -1, "unit already attached\n");
< return 0;
< }
< scp = malloc(sizeof(struct ata_softc), M_ATA, M_NOWAIT);
< if (scp == NULL) {
< ata_printf(scp, -1, "failed to allocate driver storage\n");
< return 0;
< }
< bzero(scp, sizeof(struct ata_softc));
---
> rid = ATA_IOADDR_RID;
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
> if (!io)
> goto failure;
> ioaddr = rman_get_start(io);
537a745,760
> rid = ATA_ALTIOADDR_RID;
> altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
> if (!altio)
> goto failure;
> altioaddr = rman_get_start(altio);
>
> rid = ATA_BMADDR_RID;
> bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
> bmaddr = bmio ? rman_get_start(bmio) : 0;
>
> /* store the IO resources for eventual later release */
> scp->r_io = io;
> scp->r_altio = altio;
> scp->r_bmio = bmio;
>
> /* store the physical IO addresse for easy access */
541,543d763
< scp->lun = lun;
< scp->unit = *unit;
< scp->active = ATA_IDLE;
556c776
< if ((status0 & 0xf8) != 0xf8)
---
> if ((status0 & 0xf8) != 0xf8 && status0 != 0xa5)
558c778
< if ((status1 & 0xf8) != 0xf8)
---
> if ((status1 & 0xf8) != 0xf8 && status1 != 0xa5)
563,566c783,785
< if (!mask) {
< free(scp, M_DEVBUF);
< return 0;
< }
---
> if (!mask)
> goto failure;
>
568,571c787,789
< if (!mask) {
< free(scp, M_DEVBUF);
< return 0;
< }
---
> if (!mask)
> goto failure;
>
573,575c791,792
< * OK, we have at least one device on the chain,
< * check for ATAPI signatures, if none check if its
< * a good old ATA device.
---
> * OK, we have at least one device on the chain, check for ATAPI
> * signatures, if none check if its a good old ATA device.
612,613c829
< free(scp, M_DEVBUF);
< return 0;
---
> goto failure;
617,644c833,844
< *unit = scp->lun;
< scp->dev = dev;
< atadevices[scp->lun] = scp;
<
< /* register callback for when interrupts are enabled */
< if (!ata_attach_hook) {
< if (!(ata_attach_hook = (struct intr_config_hook *)
< malloc(sizeof(struct intr_config_hook),
< M_TEMP, M_NOWAIT))) {
< ata_printf(scp, -1, "ERROR malloc attach_hook failed\n");
< return 0;
< }
< bzero(ata_attach_hook, sizeof(struct intr_config_hook));
<
< ata_attach_hook->ich_func = ata_attach;
< if (config_intrhook_establish(ata_attach_hook) != 0) {
< ata_printf(scp, -1, "config_intrhook_establish failed\n");
< free(ata_attach_hook, M_TEMP);
< }
< }
< #if NAPM > 0
< scp->resume_hook.ah_fun = (void *)ata_reinit;
< scp->resume_hook.ah_arg = scp;
< scp->resume_hook.ah_name = "ATA driver";
< scp->resume_hook.ah_order = APM_MID_ORDER;
< apm_hook_establish(APM_HOOK_RESUME, &scp->resume_hook);
< #endif
< return ATA_IOSIZE;
---
> return 0;
>
> failure:
> if (io)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
> if (altio)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTIOADDR_RID, altio);
> if (bmio)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, bmio);
> if (bootverbose)
> ata_printf(scp, -1, "probe allocation failed\n");
> return ENXIO;
647,648c847,848
< void
< ata_attach(void *dummy)
---
> static int
> ata_attach(device_t dev)
650c850,852
< int32_t ctlr;
---
> struct ata_softc *scp = device_get_softc(dev);
> int rid = 0;
> void *ih;
651a854,864
> if (!scp || scp->flags & ATA_ATTACHED)
> return ENXIO;
>
> scp->r_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
> RF_SHAREABLE | RF_ACTIVE);
> if (!scp->r_irq) {
> ata_printf(scp, -1, "unable to allocate interrupt\n");
> return ENXIO;
> }
> bus_setup_intr(dev, scp->r_irq, INTR_TYPE_BIO, ata_intr, scp, &ih);
>
653,655c866,868
< * run through atadevices[] and look for real ATA & ATAPI devices
< * using the hints we found in the early probe to avoid probing
< * of non-exsistent devices and thereby long delays
---
> * do not attach devices if we are in early boot, this is done later
> * when interrupts are enabled by a hook into the boot process.
> * otherwise attach what the probe has found in scp->devices.
657,670c870,894
< for (ctlr=0; ctlr<MAXATA; ctlr++) {
< if (!atadevices[ctlr]) continue;
< if (atadevices[ctlr]->devices & ATA_ATA_SLAVE)
< if (ata_getparam(atadevices[ctlr], ATA_SLAVE, ATA_C_ATA_IDENTIFY))
< atadevices[ctlr]->devices &= ~ATA_ATA_SLAVE;
< if (atadevices[ctlr]->devices & ATA_ATAPI_SLAVE)
< if (ata_getparam(atadevices[ctlr], ATA_SLAVE, ATA_C_ATAPI_IDENTIFY))
< atadevices[ctlr]->devices &= ~ATA_ATAPI_SLAVE;
< if (atadevices[ctlr]->devices & ATA_ATA_MASTER)
< if (ata_getparam(atadevices[ctlr], ATA_MASTER, ATA_C_ATA_IDENTIFY))
< atadevices[ctlr]->devices &= ~ATA_ATA_MASTER;
< if (atadevices[ctlr]->devices & ATA_ATAPI_MASTER)
< if (ata_getparam(atadevices[ctlr], ATA_MASTER,ATA_C_ATAPI_IDENTIFY))
< atadevices[ctlr]->devices &= ~ATA_ATAPI_MASTER;
---
> if (!ata_delayed_attach) {
> if (scp->devices & ATA_ATA_SLAVE)
> if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATA_IDENTIFY))
> scp->devices &= ~ATA_ATA_SLAVE;
> if (scp->devices & ATA_ATAPI_SLAVE)
> if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATAPI_IDENTIFY))
> scp->devices &= ~ATA_ATAPI_SLAVE;
> if (scp->devices & ATA_ATA_MASTER)
> if (ata_getparam(scp, ATA_MASTER, ATA_C_ATA_IDENTIFY))
> scp->devices &= ~ATA_ATA_MASTER;
> if (scp->devices & ATA_ATAPI_MASTER)
> if (ata_getparam(scp, ATA_MASTER,ATA_C_ATAPI_IDENTIFY))
> scp->devices &= ~ATA_ATAPI_MASTER;
> #if NATADISK > 0
> if (scp->devices & ATA_ATA_MASTER)
> ad_attach(scp, ATA_MASTER);
> if (scp->devices & ATA_ATA_SLAVE)
> ad_attach(scp, ATA_SLAVE);
> #endif
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
> if (scp->devices & ATA_ATAPI_MASTER)
> atapi_attach(scp, ATA_MASTER);
> if (scp->devices & ATA_ATAPI_SLAVE)
> atapi_attach(scp, ATA_SLAVE);
> #endif
671a896,898
> scp->flags |= ATA_ATTACHED;
> return 0;
> }
672a900,907
> static int
> ata_detach(device_t dev)
> {
> struct ata_softc *scp = device_get_softc(dev);
>
> if (!scp || !(scp->flags & ATA_ATTACHED))
> return ENXIO;
>
674,681c909,912
< /* now we know whats there, do the real attach, first the ATA disks */
< for (ctlr=0; ctlr<MAXATA; ctlr++) {
< if (!atadevices[ctlr]) continue;
< if (atadevices[ctlr]->devices & ATA_ATA_MASTER)
< ad_attach(atadevices[ctlr], ATA_MASTER);
< if (atadevices[ctlr]->devices & ATA_ATA_SLAVE)
< ad_attach(atadevices[ctlr], ATA_SLAVE);
< }
---
> if (scp->devices & ATA_ATA_MASTER)
> ad_detach(scp, ATA_MASTER);
> if (scp->devices & ATA_ATA_SLAVE)
> ad_detach(scp, ATA_SLAVE);
684,691c915,918
< /* then the atapi devices */
< for (ctlr=0; ctlr<MAXATA; ctlr++) {
< if (!atadevices[ctlr]) continue;
< if (atadevices[ctlr]->devices & ATA_ATAPI_MASTER)
< atapi_attach(atadevices[ctlr], ATA_MASTER);
< if (atadevices[ctlr]->devices & ATA_ATAPI_SLAVE)
< atapi_attach(atadevices[ctlr], ATA_SLAVE);
< }
---
> if (scp->devices & ATA_ATAPI_MASTER)
> atapi_detach(scp, ATA_MASTER);
> if (scp->devices & ATA_ATAPI_SLAVE)
> atapi_detach(scp, ATA_SLAVE);
693,696c920,922
< if (ata_attach_hook) {
< config_intrhook_disestablish(ata_attach_hook);
< free(ata_attach_hook, M_ATA);
< ata_attach_hook = NULL;
---
> if (scp->dev_param[ATA_DEV(ATA_MASTER)]) {
> free(scp->dev_param[ATA_DEV(ATA_MASTER)], M_ATA);
> scp->dev_param[ATA_DEV(ATA_MASTER)] = NULL;
697a924,935
> if (scp->dev_param[ATA_DEV(ATA_SLAVE)]) {
> free(scp->dev_param[ATA_DEV(ATA_SLAVE)], M_ATA);
> scp->dev_param[ATA_DEV(ATA_SLAVE)] = NULL;
> }
> scp->mode[ATA_DEV(ATA_MASTER)] = ATA_PIO;
> scp->mode[ATA_DEV(ATA_SLAVE)] = ATA_PIO;
> bus_release_resource(dev, SYS_RES_IRQ, 0, scp->r_irq);
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio);
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTIOADDR_RID, scp->r_altio);
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io);
> scp->flags &= ~ATA_ATTACHED;
> return 0;
699a938,946
> static int
> ata_resume(device_t dev)
> {
> struct ata_softc *scp = device_get_softc(dev);
>
> ata_reinit(scp);
> return 0;
> }
>
711c958
< /* enable interrupts */
---
> /* enable interrupt */
722c969
< ata_printf(scp, device, "drive wont come ready after identify\n");
---
> ata_printf(scp, device, "identify retries exceeded\n");
732c979
< ata_printf(scp, device, "malloc for ata_param failed\n");
---
> ata_printf(scp, device, "malloc for identify data failed\n");
748a996,1052
> static void
> ata_boot_attach(void)
> {
> struct ata_softc *scp;
> int32_t ctlr;
>
> /*
> * run through all ata devices and look for real ATA & ATAPI devices
> * using the hints we found in the early probe, this avoids some of
> * the delays probing of non-exsistent devices can cause.
> */
> for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
> if (!(scp = devclass_get_softc(ata_devclass, ctlr)))
> continue;
> if (scp->devices & ATA_ATA_SLAVE)
> if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATA_IDENTIFY))
> scp->devices &= ~ATA_ATA_SLAVE;
> if (scp->devices & ATA_ATAPI_SLAVE)
> if (ata_getparam(scp, ATA_SLAVE, ATA_C_ATAPI_IDENTIFY))
> scp->devices &= ~ATA_ATAPI_SLAVE;
> if (scp->devices & ATA_ATA_MASTER)
> if (ata_getparam(scp, ATA_MASTER, ATA_C_ATA_IDENTIFY))
> scp->devices &= ~ATA_ATA_MASTER;
> if (scp->devices & ATA_ATAPI_MASTER)
> if (ata_getparam(scp, ATA_MASTER,ATA_C_ATAPI_IDENTIFY))
> scp->devices &= ~ATA_ATAPI_MASTER;
> }
>
> #if NATADISK > 0
> /* now we know whats there, do the real attach, first the ATA disks */
> for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
> if (!(scp = devclass_get_softc(ata_devclass, ctlr)))
> continue;
> if (scp->devices & ATA_ATA_MASTER)
> ad_attach(scp, ATA_MASTER);
> if (scp->devices & ATA_ATA_SLAVE)
> ad_attach(scp, ATA_SLAVE);
> }
> #endif
> #if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
> /* then the atapi devices */
> for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
> if (!(scp = devclass_get_softc(ata_devclass, ctlr)))
> continue;
> if (scp->devices & ATA_ATAPI_MASTER)
> atapi_attach(scp, ATA_MASTER);
> if (scp->devices & ATA_ATAPI_SLAVE)
> atapi_attach(scp, ATA_SLAVE);
> }
> #endif
> if (ata_delayed_attach) {
> config_intrhook_disestablish(ata_delayed_attach);
> free(ata_delayed_attach, M_ATA);
> ata_delayed_attach = NULL;
> }
> }
>
750c1054
< ataintr(void *data)
---
> ata_intr(void *data)
757c1061
< * case with our twin channel, we only want to process interrupts
---
> * cases with our twin channel, we only want to process interrupts
770c1074,1077
< if (!(inl((pci_read_config(scp->dev, 0x20, 4) & IOMASK) + 0x1c) &
---
> {
> struct ata_pci_softc *sc=device_get_softc(device_get_parent(scp->dev));
>
> if (!(inl(rman_get_start(sc->bmio) + 0x1c) &
772a1080
> }
907c1215
< int8_t status0, status1;
---
> u_int8_t status0 = 0, status1 = 0;
957d1264
< ata_printf(scp, -1, "resetting devices .. ");
962,965c1269,1274
< omask = mask;
< ata_reset(scp, &mask);
< if (omask != mask)
< printf(" device dissapeared! %d ", omask & ~mask);
---
> if (mask) {
> omask = mask;
> ata_printf(scp, -1, "resetting devices .. ");
> ata_reset(scp, &mask);
> if (omask != mask)
> printf(" device dissapeared! %d ", omask & ~mask);
968,971c1277,1280
< if (scp->devices & (ATA_ATA_MASTER) && scp->dev_softc[0])
< ad_reinit((struct ad_softc *)scp->dev_softc[0]);
< if (scp->devices & (ATA_ATA_SLAVE) && scp->dev_softc[1])
< ad_reinit((struct ad_softc *)scp->dev_softc[1]);
---
> if (scp->devices & (ATA_ATA_MASTER) && scp->dev_softc[0])
> ad_reinit((struct ad_softc *)scp->dev_softc[0]);
> if (scp->devices & (ATA_ATA_SLAVE) && scp->dev_softc[1])
> ad_reinit((struct ad_softc *)scp->dev_softc[1]);
974,977c1283,1286
< if (scp->devices & (ATA_ATAPI_MASTER) && scp->dev_softc[0])
< atapi_reinit((struct atapi_softc *)scp->dev_softc[0]);
< if (scp->devices & (ATA_ATAPI_SLAVE) && scp->dev_softc[1])
< atapi_reinit((struct atapi_softc *)scp->dev_softc[1]);
---
> if (scp->devices & (ATA_ATAPI_MASTER) && scp->dev_softc[0])
> atapi_reinit((struct atapi_softc *)scp->dev_softc[0]);
> if (scp->devices & (ATA_ATAPI_SLAVE) && scp->dev_softc[1])
> atapi_reinit((struct atapi_softc *)scp->dev_softc[1]);
979c1288,1289
< printf("done\n");
---
> printf("done\n");
> }
1105a1416,1447
> int
> ata_printf(struct ata_softc *scp, int32_t device, const char * fmt, ...)
> {
> va_list ap;
> int ret;
>
> if (device == -1)
> ret = printf("ata%d: ", device_get_unit(scp->dev));
> else
> ret = printf("ata%d-%s: ", device_get_unit(scp->dev),
> (device == ATA_MASTER) ? "master" : "slave");
> va_start(ap, fmt);
> ret += vprintf(fmt, ap);
> va_end(ap);
> return ret;
> }
>
> int
> ata_get_lun(u_int32_t *map)
> {
> int lun = ffs(~*map) - 1;
>
> *map |= (1 << lun);
> return lun;
> }
>
> void
> ata_free_lun(u_int32_t *map, int lun)
> {
> *map &= ~(1 << lun);
> }
>
1136a1479,1526
> int
> ata_pmode(struct ata_params *ap)
> {
> if (ap->atavalid & ATA_FLAG_64_70) {
> if (ap->apiomodes & 2)
> return 4;
> if (ap->apiomodes & 1)
> return 3;
> }
> if (ap->opiomode == 2)
> return 2;
> if (ap->opiomode == 1)
> return 1;
> if (ap->opiomode == 0)
> return 0;
> return -1;
> }
>
> int
> ata_wmode(struct ata_params *ap)
> {
> if (ap->wdmamodes & 4)
> return 2;
> if (ap->wdmamodes & 2)
> return 1;
> if (ap->wdmamodes & 1)
> return 0;
> return -1;
> }
>
> int
> ata_umode(struct ata_params *ap)
> {
> if (ap->atavalid & ATA_FLAG_88) {
> if (ap->udmamodes & 0x10)
> return (ap->cblid ? 4 : 2);
> if (ap->udmamodes & 0x08)
> return (ap->cblid ? 3 : 2);
> if (ap->udmamodes & 0x04)
> return 2;
> if (ap->udmamodes & 0x02)
> return 1;
> if (ap->udmamodes & 0x01)
> return 0;
> }
> return -1;
> }
>
1165,1199d1554
< int32_t
< ata_pmode(struct ata_params *ap)
< {
< if (ap->atavalid & ATA_FLAG_64_70) {
< if (ap->apiomodes & 2) return 4;
< if (ap->apiomodes & 1) return 3;
< }
< if (ap->opiomode == 2) return 2;
< if (ap->opiomode == 1) return 1;
< if (ap->opiomode == 0) return 0;
< return -1;
< }
<
< int32_t
< ata_wmode(struct ata_params *ap)
< {
< if (ap->wdmamodes & 4) return 2;
< if (ap->wdmamodes & 2) return 1;
< if (ap->wdmamodes & 1) return 0;
< return -1;
< }
<
< int32_t
< ata_umode(struct ata_params *ap)
< {
< if (ap->atavalid & ATA_FLAG_88) {
< if (ap->udmamodes & 0x10) return (ap->cblid ? 4 : 2);
< if (ap->udmamodes & 0x08) return (ap->cblid ? 3 : 2);
< if (ap->udmamodes & 0x04) return 2;
< if (ap->udmamodes & 0x02) return 1;
< if (ap->udmamodes & 0x01) return 0;
< }
< return -1;
< }
<
1203c1558
< u_int16_t *p = (u_int16_t*)(buf + len);
---
> u_int16_t *ptr = (u_int16_t*)(buf + len);
1205,1206c1560,1561
< while (--p >= (u_int16_t*)buf)
< *p = ntohs(*p);
---
> while (--ptr >= (u_int16_t*)buf)
> *ptr = ntohs(*ptr);
1212c1567
< int8_t *p;
---
> int8_t *ptr;
1214,1218c1569,1573
< for (p = buf; p < buf+len; ++p)
< if (!*p)
< *p = ' ';
< for (p = buf + len - 1; p >= buf && *p == ' '; --p)
< *p = 0;
---
> for (ptr = buf; ptr < buf+len; ++ptr)
> if (!*ptr)
> *ptr = ' ';
> for (ptr = buf + len - 1; ptr >= buf && *ptr == ' '; --ptr)
> *ptr = 0;
1244,1262d1598
< int32_t
< ata_printf(struct ata_softc *scp, int32_t device, const char * fmt, ...)
< {
< va_list ap;
< int ret;
<
< if (device == -1)
< ret = printf("ata%d: ", scp->lun);
< else
< ret = printf("ata%d-%s: ", scp->lun,
< (device == ATA_MASTER) ? "master" : "slave");
< va_start(ap, fmt);
< ret += vprintf(fmt, ap);
< va_end(ap);
< return ret;
< }
<
< static char ata_conf[1024];
<
1282c1618,1619
< int error, i;
---
> struct ata_softc *scp;
> int ctlr, error, i;
1286,1292c1623,1633
< for (i = 0; i < (atanlun << 1); i++) {
< if (!atadevices[i >> 1] || !atadevices[ i >> 1]->dev_softc[i & 1])
< strcat(ata_conf, "---,");
< else if (atadevices[i >> 1]->mode[i & 1] >= ATA_DMA)
< strcat(ata_conf, "dma,");
< else
< strcat(ata_conf, "pio,");
---
> for (ctlr=0; ctlr<devclass_get_maxunit(ata_devclass); ctlr++) {
> if (!(scp = devclass_get_softc(ata_devclass, ctlr)))
> continue;
> for (i = 0; i < 2; i++) {
> if (!scp->dev_softc[i])
> strcat(ata_conf, "---,");
> else if (scp->mode[i] >= ATA_DMA)
> strcat(ata_conf, "dma,");
> else
> strcat(ata_conf, "pio,");
> }
1302,1306c1643,1645
< if (atadevices[i >> 1] &&
< atadevices[i >> 1]->dev_softc[i & 1] &&
< atadevices[i >>1 ]->mode[i & 1] >= ATA_DMA)
< ata_change_mode(atadevices[i >> 1],
< (i & 1) ? ATA_SLAVE : ATA_MASTER, ATA_PIO);
---
> if ((scp = devclass_get_softc(ata_devclass, i >> 1)) &&
> scp->dev_softc[i & 1] && scp->mode[i & 1] >= ATA_DMA)
> ata_change_mode(scp, (i & 1)?ATA_SLAVE:ATA_MASTER, ATA_PIO);
1309,1313c1648,1650
< if (atadevices[i >> 1] &&
< atadevices[i >> 1]->dev_softc[i & 1] &&
< atadevices[i >> 1]->mode[i & 1] < ATA_DMA)
< ata_change_mode(atadevices[i >> 1],
< (i & 1) ? ATA_SLAVE : ATA_MASTER, ATA_DMA);
---
> if ((scp = devclass_get_softc(ata_devclass, i >> 1)) &&
> scp->dev_softc[i & 1] && scp->mode[i & 1] < ATA_DMA)
> ata_change_mode(scp, (i & 1)?ATA_SLAVE:ATA_MASTER, ATA_DMA);
1318c1655,1656
< if (*ptr++ != ',' || ++i > (atanlun << 1))
---
> if (*ptr++ != ',' ||
> ++i > (devclass_get_maxunit(ata_devclass) << 1))
1324d1661
<
1326a1664,1683
>
> static void
> ata_init(void)
> {
> /* register boot attach to be run when interrupts are enabled */
> if (!(ata_delayed_attach = (struct intr_config_hook *)
> malloc(sizeof(struct intr_config_hook),
> M_TEMP, M_NOWAIT))) {
> printf("ata: malloc of delayed attach hook failed\n");
> return;
> }
> bzero(ata_delayed_attach, sizeof(struct intr_config_hook));
>
> ata_delayed_attach->ich_func = (void*)ata_boot_attach;
> if (config_intrhook_establish(ata_delayed_attach) != 0) {
> printf("ata: config_intrhook_establish failed\n");
> free(ata_delayed_attach, M_TEMP);
> }
> }
> SYSINIT(atadev, SI_SUB_DRIVERS, SI_ORDER_SECOND, ata_init, NULL)