28c28
< * $FreeBSD: head/sys/dev/ata/ata-all.c 72096 2001-02-06 12:49:33Z sos $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 72106 2001-02-06 16:44:25Z sos $
68c68
< #if NPCI > 0
---
> #define ATA_IRQ_RID 0
71,73d70
< #else
< #define ATA_MASTERDEV(dev) (1)
< #endif
109c106
< struct resource *port;
---
> struct resource *io;
117c114
< /* allocate the port range */
---
> /* allocate the io port range to get the start address */
119,121c116,118
< port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
< ATA_IOSIZE, RF_ACTIVE);
< if (!port)
---
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
> if (!io)
124,128c121,124
< /* 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_ALTOFFSET,
< ATA_ALTIOSIZE);
---
> /* set the altport range */
> if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) {
> bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
> rman_get_start(io) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
130c126,127
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
---
>
> bus_release_resource(dev, SYS_RES_IOPORT, rid, io);
158,159c155,157
< struct resource *port;
< int rid, len;
---
> struct resource *io;
> int rid, len, start, end;
> u_long tmp;
161c159
< /* allocate the port range */
---
> /* allocate the io range to get start and length */
164,165c162,164
< port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, len, RF_ACTIVE);
< if (!port)
---
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
> if (!io)
167a167,174
> /* reallocate the io address to only cover the io ports */
> start = rman_get_start(io);
> end = start + ATA_IOSIZE - 1;
> bus_release_resource(dev, SYS_RES_IOPORT, rid, io);
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> start, end, ATA_IOSIZE, RF_ACTIVE);
> bus_release_resource(dev, SYS_RES_IOPORT, rid, io);
>
170,171c177,178
< * a pccard system where the altio ports are located just after the
< * normal io ports, so no need to allocate them.
---
> * a pccard system where the altio ports are located at offset 14
> * otherwise its the normal altio offset
173,175c180,188
< if (len <= ATA_IOSIZE) {
< bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
< rman_get_start(port) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
---
> if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) {
> if (len > ATA_IOSIZE) {
> bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
> start + ATA_PCCARD_ALTOFFSET, ATA_ALTIOSIZE);
> }
> else {
> bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
> start + ATA_ALTOFFSET, ATA_ALTIOSIZE);
> }
177c190,192
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
---
> else
> return ENOMEM;
>
203,204c218
< struct resource bmio_1;
< struct resource bmio_2;
---
> int bmaddr;
415,416c429
< outb(rman_get_start(sc->bmio) + 0x11,
< inb(rman_get_start(sc->bmio) + 0x11) | 0x0a);
---
> ATA_OUTB(sc->bmio, 0x11, ATA_INB(sc->bmio, 0x11) | 0x0a);
420,421c433
< outb(rman_get_start(sc->bmio) + 0x1f,
< inb(rman_get_start(sc->bmio) + 0x1f) | 0x01);
---
> ATA_OUTB(sc->bmio, 0x1f, ATA_INB(sc->bmio, 0x1f) | 0x01);
480c492
< sc->bmio = 0x0;
---
> sc->bmio = NULL;
483a496,502
> if (sc->bmio) {
> sc->bmaddr = rman_get_start(sc->bmio);
> BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, rid, sc->bmio);
> sc->bmio = NULL;
> }
>
509c528
< retval += printf(": at 0x%x", scp->ioaddr);
---
> retval += printf(": at 0x%lx", rman_get_start(scp->r_io));
523a543
> struct resource *res = NULL;
534a555,557
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
536c559
< else
---
> else {
537a561,564
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> }
545a573,575
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
547c577
< else
---
> else {
548a579,592
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> if (res) {
> start = rman_get_start(res) + 2;
> end = start + ATA_ALTIOSIZE - 1;
> count = ATA_ALTIOSIZE;
> BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, myrid, res);
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> }
> }
552,563c596,603
< /* the busmaster resource is shared between the two channels */
< if (sc->bmio) {
< if (channel == 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;
< }
---
> if (sc->bmaddr) {
> myrid = 0x20;
> start = (channel == 0 ? sc->bmaddr : sc->bmaddr + ATA_BMIOSIZE);
> end = start + ATA_BMIOSIZE - 1;
> count = ATA_BMIOSIZE;
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
565,568d604
< return 0;
<
< default:
< return 0;
570,580c606
<
< if (ATA_MASTERDEV(dev))
< /* 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);
---
> return res;
583,586c609
< if (type == SYS_RES_IRQ) {
< if (*rid != 0)
< return 0;
<
---
> if (type == SYS_RES_IRQ && *rid == ATA_IRQ_RID) {
597c620,621
< } else {
---
> }
> else {
634c658,659
< return 0;
---
> myrid = 0x20;
> break;
650c675
< if (rid != 0)
---
> if (rid != ATA_IRQ_RID)
773,775d797
< struct resource *io = 0;
< struct resource *altio = 0;
< struct resource *bmio = 0;
777d798
< u_int32_t ioaddr, altioaddr, bmaddr;
790,792c811,813
< io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
< ATA_IOSIZE, RF_ACTIVE);
< if (!io)
---
> scp->r_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
> if (!scp->r_io)
794d814
< ioaddr = rman_get_start(io);
797,806c817,820
< altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
< ATA_ALTIOSIZE, RF_ACTIVE);
< if (altio) {
< if (scp->flags & ATA_USE_16BIT || ATA_MASTERDEV(device_get_parent(dev)))
< altioaddr = rman_get_start(altio);
< else
< altioaddr = rman_get_start(altio) + 0x02;
< }
< else
< altioaddr = ioaddr + ATA_PCCARD_ALTOFFSET;
---
> scp->r_altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_ALTIOSIZE, RF_ACTIVE);
> if (!scp->r_altio)
> goto failure;
809,810c823,824
< bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
< bmaddr = bmio ? rman_get_start(bmio) : 0;
---
> scp->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_BMIOSIZE, RF_ACTIVE);
812,821d825
< /* 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 */
< scp->ioaddr = ioaddr;
< scp->altioaddr = altioaddr;
< scp->bmaddr = bmaddr;
<
824c828,830
< scp->ioaddr, scp->altioaddr, scp->bmaddr);
---
> (int)rman_get_start(scp->r_io),
> (int)rman_get_start(scp->r_altio),
> (scp->r_bmio) ? (int)rman_get_start(scp->r_bmio) : 0);
827c833
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
829c835
< status0 = inb(scp->ioaddr + ATA_STATUS);
---
> status0 = ATA_INB(scp->r_io, ATA_STATUS);
832c838
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
834c840
< status1 = inb(scp->ioaddr + ATA_STATUS);
---
> status1 = ATA_INB(scp->r_io, ATA_STATUS);
854,859c860,865
< if (io)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
< if (altio)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, altio);
< if (bmio)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, bmio);
---
> if (scp->r_io)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io);
> if (scp->r_altio)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,scp->r_altio);
> if (scp->r_bmio)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio);
869c875
< int error, rid = 0;
---
> int error, rid;
873a880
> rid = ATA_IRQ_RID;
926a934,939
> /* disable interrupts on devices */
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT);
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT);
>
938a952
>
950a965
>
952c967
< bus_release_resource(dev, SYS_RES_IRQ, 0, scp->r_irq);
---
> bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, scp->r_irq);
955,956c970
< if (scp->r_altio)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,scp->r_altio);
---
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, scp->r_altio);
979c993
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device);
983c997
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
1000c1014,1015
< insw(scp->ioaddr + ATA_DATA, buffer, sizeof(buffer)/sizeof(int16_t));
---
> ATA_INSW(scp->r_io, ATA_DATA, (int16_t *)buffer,
> sizeof(buffer)/sizeof(int16_t));
1081d1095
< struct ata_pci_softc *sc = device_get_softc(device_get_parent(scp->dev));
1095c1109
< outb(scp->bmaddr + ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
---
> ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
1109c1123
< if (!(inl(rman_get_start(sc->bmio) + 0x1c) &
---
> if (!(ATA_INL(scp->r_bmio, (scp->channel ? 0x14 : 0x1c)) &
1119c1133,1134
< outb(scp->bmaddr + ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
---
> ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
> dmastat | ATA_BMSTAT_INTERRUPT);
1125c1140
< if (inb(scp->altioaddr) & ATA_S_BUSY)
---
> if (ATA_INB(scp->r_altio, ATA_ALTSTAT) & ATA_S_BUSY)
1129c1144
< scp->status = inb(scp->ioaddr + ATA_STATUS);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1132c1147
< scp->error = inb(scp->ioaddr + ATA_ERROR);
---
> scp->error = ATA_INB(scp->r_io, ATA_ERROR);
1240c1255
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1242,1243c1257,1258
< ostat1 = inb(scp->ioaddr + ATA_STATUS);
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ostat1 = ATA_INB(scp->r_io, ATA_STATUS);
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1245c1260
< ostat0 = inb(scp->ioaddr + ATA_STATUS);
---
> ostat0 = ATA_INB(scp->r_io, ATA_STATUS);
1256c1271
< outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_RESET);
1258c1273
< outb(scp->altioaddr, ATA_A_IDS);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS);
1260c1275
< inb(scp->ioaddr + ATA_ERROR);
---
> ATA_INB(scp->r_io, ATA_ERROR);
1266c1281
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1268c1283
< status0 = inb(scp->ioaddr + ATA_STATUS);
---
> status0 = ATA_INB(scp->r_io, ATA_STATUS);
1271,1272c1286,1287
< a = inb(scp->ioaddr + ATA_CYL_LSB);
< b = inb(scp->ioaddr + ATA_CYL_MSB);
---
> a = ATA_INB(scp->r_io, ATA_CYL_LSB);
> b = ATA_INB(scp->r_io, ATA_CYL_MSB);
1281c1296
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1283c1298
< status1 = inb(scp->ioaddr + ATA_STATUS);
---
> status1 = ATA_INB(scp->r_io, ATA_STATUS);
1286,1287c1301,1302
< a = inb(scp->ioaddr + ATA_CYL_LSB);
< b = inb(scp->ioaddr + ATA_CYL_MSB);
---
> a = ATA_INB(scp->r_io, ATA_CYL_LSB);
> b = ATA_INB(scp->r_io, ATA_CYL_MSB);
1307c1322
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
1320c1335
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1322,1325c1337,1340
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< a = inb(scp->ioaddr + ATA_ERROR);
< b = inb(scp->ioaddr + ATA_CYL_LSB);
---
> ATA_OUTB(scp->r_io, ATA_ERROR, 0x58);
> ATA_OUTB(scp->r_io, ATA_CYL_LSB, 0xa5);
> a = ATA_INB(scp->r_io, ATA_ERROR);
> b = ATA_INB(scp->r_io, ATA_CYL_LSB);
1332c1347
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1334,1337c1349,1352
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< a = inb(scp->ioaddr + ATA_ERROR);
< b = inb(scp->ioaddr + ATA_CYL_LSB);
---
> ATA_OUTB(scp->r_io, ATA_ERROR, 0x58);
> ATA_OUTB(scp->r_io, ATA_CYL_LSB, 0xa5);
> a = ATA_INB(scp->r_io, ATA_ERROR);
> b = ATA_INB(scp->r_io, ATA_CYL_LSB);
1389c1404,1405
< outb(scp->bmaddr + ATA_BMSTAT_PORT, ata_dmastatus(scp) | ATA_BMSTAT_INTERRUPT);
---
> ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
> ata_dmastatus(scp) | ATA_BMSTAT_INTERRUPT);
1391c1407
< if ((inb(scp->ioaddr + ATA_DRIVE) & ATA_SLAVE) == ATA_MASTER) {
---
> if ((ATA_INB(scp->r_io, ATA_DRIVE) & ATA_SLAVE) == ATA_MASTER) {
1408d1423
< int statio = scp->ioaddr + ATA_STATUS;
1412c1427
< scp->status = inb(statio);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1417c1432
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device);
1419c1434
< scp->status = inb(statio);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1436c1451
< scp->error = inb(scp->ioaddr + ATA_ERROR);
---
> scp->error = ATA_INB(scp->r_io, ATA_ERROR);
1445c1460
< scp->status = inb(statio);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1448c1463
< scp->error = inb(scp->ioaddr + ATA_ERROR);
---
> scp->error = ATA_INB(scp->r_io, ATA_ERROR);
1465c1480
< scp->ioaddr, command, cylinder, head, sector,
---
> rman_get_start(scp->r_io), command, cylinder, head, sector,
1471c1486
< outb(scp->altioaddr, ATA_A_IDS | ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT);
1474c1489
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device);
1484,1489c1499,1504
< outb(scp->ioaddr + ATA_FEATURE, feature);
< outb(scp->ioaddr + ATA_COUNT, count);
< outb(scp->ioaddr + ATA_SECTOR, sector);
< outb(scp->ioaddr + ATA_CYL_MSB, cylinder >> 8);
< outb(scp->ioaddr + ATA_CYL_LSB, cylinder);
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device | head);
---
> ATA_OUTB(scp->r_io, ATA_FEATURE, feature);
> ATA_OUTB(scp->r_io, ATA_COUNT, count);
> ATA_OUTB(scp->r_io, ATA_SECTOR, sector);
> ATA_OUTB(scp->r_io, ATA_CYL_MSB, cylinder >> 8);
> ATA_OUTB(scp->r_io, ATA_CYL_LSB, cylinder);
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device | head);
1495c1510
< outb(scp->ioaddr + ATA_CMD, command);
---
> ATA_OUTB(scp->r_io, ATA_CMD, command);
1499c1514
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
1511c1526
< outb(scp->ioaddr + ATA_CMD, command);
---
> ATA_OUTB(scp->r_io, ATA_CMD, command);
1523c1538
< outb(scp->ioaddr + ATA_CMD, command);
---
> ATA_OUTB(scp->r_io, ATA_CMD, command);
1532c1547
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
< * $FreeBSD: head/sys/dev/ata/ata-all.c 72096 2001-02-06 12:49:33Z sos $
---
> * $FreeBSD: head/sys/dev/ata/ata-all.c 72106 2001-02-06 16:44:25Z sos $
68c68
< #if NPCI > 0
---
> #define ATA_IRQ_RID 0
71,73d70
< #else
< #define ATA_MASTERDEV(dev) (1)
< #endif
109c106
< struct resource *port;
---
> struct resource *io;
117c114
< /* allocate the port range */
---
> /* allocate the io port range to get the start address */
119,121c116,118
< port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
< ATA_IOSIZE, RF_ACTIVE);
< if (!port)
---
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
> if (!io)
124,128c121,124
< /* 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_ALTOFFSET,
< ATA_ALTIOSIZE);
---
> /* set the altport range */
> if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) {
> bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
> rman_get_start(io) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
130c126,127
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
---
>
> bus_release_resource(dev, SYS_RES_IOPORT, rid, io);
158,159c155,157
< struct resource *port;
< int rid, len;
---
> struct resource *io;
> int rid, len, start, end;
> u_long tmp;
161c159
< /* allocate the port range */
---
> /* allocate the io range to get start and length */
164,165c162,164
< port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, len, RF_ACTIVE);
< if (!port)
---
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
> if (!io)
167a167,174
> /* reallocate the io address to only cover the io ports */
> start = rman_get_start(io);
> end = start + ATA_IOSIZE - 1;
> bus_release_resource(dev, SYS_RES_IOPORT, rid, io);
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> start, end, ATA_IOSIZE, RF_ACTIVE);
> bus_release_resource(dev, SYS_RES_IOPORT, rid, io);
>
170,171c177,178
< * a pccard system where the altio ports are located just after the
< * normal io ports, so no need to allocate them.
---
> * a pccard system where the altio ports are located at offset 14
> * otherwise its the normal altio offset
173,175c180,188
< if (len <= ATA_IOSIZE) {
< bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
< rman_get_start(port) + ATA_ALTOFFSET, ATA_ALTIOSIZE);
---
> if (bus_get_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, &tmp, &tmp)) {
> if (len > ATA_IOSIZE) {
> bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
> start + ATA_PCCARD_ALTOFFSET, ATA_ALTIOSIZE);
> }
> else {
> bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
> start + ATA_ALTOFFSET, ATA_ALTIOSIZE);
> }
177c190,192
< bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
---
> else
> return ENOMEM;
>
203,204c218
< struct resource bmio_1;
< struct resource bmio_2;
---
> int bmaddr;
415,416c429
< outb(rman_get_start(sc->bmio) + 0x11,
< inb(rman_get_start(sc->bmio) + 0x11) | 0x0a);
---
> ATA_OUTB(sc->bmio, 0x11, ATA_INB(sc->bmio, 0x11) | 0x0a);
420,421c433
< outb(rman_get_start(sc->bmio) + 0x1f,
< inb(rman_get_start(sc->bmio) + 0x1f) | 0x01);
---
> ATA_OUTB(sc->bmio, 0x1f, ATA_INB(sc->bmio, 0x1f) | 0x01);
480c492
< sc->bmio = 0x0;
---
> sc->bmio = NULL;
483a496,502
> if (sc->bmio) {
> sc->bmaddr = rman_get_start(sc->bmio);
> BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, rid, sc->bmio);
> sc->bmio = NULL;
> }
>
509c528
< retval += printf(": at 0x%x", scp->ioaddr);
---
> retval += printf(": at 0x%lx", rman_get_start(scp->r_io));
523a543
> struct resource *res = NULL;
534a555,557
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
536c559
< else
---
> else {
537a561,564
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> }
545a573,575
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
547c577
< else
---
> else {
548a579,592
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> if (res) {
> start = rman_get_start(res) + 2;
> end = start + ATA_ALTIOSIZE - 1;
> count = ATA_ALTIOSIZE;
> BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, myrid, res);
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), dev,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
> }
> }
552,563c596,603
< /* the busmaster resource is shared between the two channels */
< if (sc->bmio) {
< if (channel == 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;
< }
---
> if (sc->bmaddr) {
> myrid = 0x20;
> start = (channel == 0 ? sc->bmaddr : sc->bmaddr + ATA_BMIOSIZE);
> end = start + ATA_BMIOSIZE - 1;
> count = ATA_BMIOSIZE;
> res = BUS_ALLOC_RESOURCE(device_get_parent(dev), child,
> SYS_RES_IOPORT, &myrid,
> start, end, count, flags);
565,568d604
< return 0;
<
< default:
< return 0;
570,580c606
<
< if (ATA_MASTERDEV(dev))
< /* 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);
---
> return res;
583,586c609
< if (type == SYS_RES_IRQ) {
< if (*rid != 0)
< return 0;
<
---
> if (type == SYS_RES_IRQ && *rid == ATA_IRQ_RID) {
597c620,621
< } else {
---
> }
> else {
634c658,659
< return 0;
---
> myrid = 0x20;
> break;
650c675
< if (rid != 0)
---
> if (rid != ATA_IRQ_RID)
773,775d797
< struct resource *io = 0;
< struct resource *altio = 0;
< struct resource *bmio = 0;
777d798
< u_int32_t ioaddr, altioaddr, bmaddr;
790,792c811,813
< io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
< ATA_IOSIZE, RF_ACTIVE);
< if (!io)
---
> scp->r_io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_IOSIZE, RF_ACTIVE);
> if (!scp->r_io)
794d814
< ioaddr = rman_get_start(io);
797,806c817,820
< altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
< ATA_ALTIOSIZE, RF_ACTIVE);
< if (altio) {
< if (scp->flags & ATA_USE_16BIT || ATA_MASTERDEV(device_get_parent(dev)))
< altioaddr = rman_get_start(altio);
< else
< altioaddr = rman_get_start(altio) + 0x02;
< }
< else
< altioaddr = ioaddr + ATA_PCCARD_ALTOFFSET;
---
> scp->r_altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_ALTIOSIZE, RF_ACTIVE);
> if (!scp->r_altio)
> goto failure;
809,810c823,824
< bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
< bmaddr = bmio ? rman_get_start(bmio) : 0;
---
> scp->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
> ATA_BMIOSIZE, RF_ACTIVE);
812,821d825
< /* 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 */
< scp->ioaddr = ioaddr;
< scp->altioaddr = altioaddr;
< scp->bmaddr = bmaddr;
<
824c828,830
< scp->ioaddr, scp->altioaddr, scp->bmaddr);
---
> (int)rman_get_start(scp->r_io),
> (int)rman_get_start(scp->r_altio),
> (scp->r_bmio) ? (int)rman_get_start(scp->r_bmio) : 0);
827c833
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
829c835
< status0 = inb(scp->ioaddr + ATA_STATUS);
---
> status0 = ATA_INB(scp->r_io, ATA_STATUS);
832c838
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
834c840
< status1 = inb(scp->ioaddr + ATA_STATUS);
---
> status1 = ATA_INB(scp->r_io, ATA_STATUS);
854,859c860,865
< if (io)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
< if (altio)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, altio);
< if (bmio)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, bmio);
---
> if (scp->r_io)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io);
> if (scp->r_altio)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,scp->r_altio);
> if (scp->r_bmio)
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio);
869c875
< int error, rid = 0;
---
> int error, rid;
873a880
> rid = ATA_IRQ_RID;
926a934,939
> /* disable interrupts on devices */
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT);
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT);
>
938a952
>
950a965
>
952c967
< bus_release_resource(dev, SYS_RES_IRQ, 0, scp->r_irq);
---
> bus_release_resource(dev, SYS_RES_IRQ, ATA_IRQ_RID, scp->r_irq);
955,956c970
< if (scp->r_altio)
< bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,scp->r_altio);
---
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, scp->r_altio);
979c993
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device);
983c997
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
1000c1014,1015
< insw(scp->ioaddr + ATA_DATA, buffer, sizeof(buffer)/sizeof(int16_t));
---
> ATA_INSW(scp->r_io, ATA_DATA, (int16_t *)buffer,
> sizeof(buffer)/sizeof(int16_t));
1081d1095
< struct ata_pci_softc *sc = device_get_softc(device_get_parent(scp->dev));
1095c1109
< outb(scp->bmaddr + ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
---
> ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
1109c1123
< if (!(inl(rman_get_start(sc->bmio) + 0x1c) &
---
> if (!(ATA_INL(scp->r_bmio, (scp->channel ? 0x14 : 0x1c)) &
1119c1133,1134
< outb(scp->bmaddr + ATA_BMSTAT_PORT, dmastat | ATA_BMSTAT_INTERRUPT);
---
> ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
> dmastat | ATA_BMSTAT_INTERRUPT);
1125c1140
< if (inb(scp->altioaddr) & ATA_S_BUSY)
---
> if (ATA_INB(scp->r_altio, ATA_ALTSTAT) & ATA_S_BUSY)
1129c1144
< scp->status = inb(scp->ioaddr + ATA_STATUS);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1132c1147
< scp->error = inb(scp->ioaddr + ATA_ERROR);
---
> scp->error = ATA_INB(scp->r_io, ATA_ERROR);
1240c1255
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1242,1243c1257,1258
< ostat1 = inb(scp->ioaddr + ATA_STATUS);
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ostat1 = ATA_INB(scp->r_io, ATA_STATUS);
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1245c1260
< ostat0 = inb(scp->ioaddr + ATA_STATUS);
---
> ostat0 = ATA_INB(scp->r_io, ATA_STATUS);
1256c1271
< outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_RESET);
1258c1273
< outb(scp->altioaddr, ATA_A_IDS);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS);
1260c1275
< inb(scp->ioaddr + ATA_ERROR);
---
> ATA_INB(scp->r_io, ATA_ERROR);
1266c1281
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1268c1283
< status0 = inb(scp->ioaddr + ATA_STATUS);
---
> status0 = ATA_INB(scp->r_io, ATA_STATUS);
1271,1272c1286,1287
< a = inb(scp->ioaddr + ATA_CYL_LSB);
< b = inb(scp->ioaddr + ATA_CYL_MSB);
---
> a = ATA_INB(scp->r_io, ATA_CYL_LSB);
> b = ATA_INB(scp->r_io, ATA_CYL_MSB);
1281c1296
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1283c1298
< status1 = inb(scp->ioaddr + ATA_STATUS);
---
> status1 = ATA_INB(scp->r_io, ATA_STATUS);
1286,1287c1301,1302
< a = inb(scp->ioaddr + ATA_CYL_LSB);
< b = inb(scp->ioaddr + ATA_CYL_MSB);
---
> a = ATA_INB(scp->r_io, ATA_CYL_LSB);
> b = ATA_INB(scp->r_io, ATA_CYL_MSB);
1307c1322
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
1320c1335
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1322,1325c1337,1340
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< a = inb(scp->ioaddr + ATA_ERROR);
< b = inb(scp->ioaddr + ATA_CYL_LSB);
---
> ATA_OUTB(scp->r_io, ATA_ERROR, 0x58);
> ATA_OUTB(scp->r_io, ATA_CYL_LSB, 0xa5);
> a = ATA_INB(scp->r_io, ATA_ERROR);
> b = ATA_INB(scp->r_io, ATA_CYL_LSB);
1332c1347
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1334,1337c1349,1352
< outb(scp->ioaddr + ATA_ERROR, 0x58);
< outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
< a = inb(scp->ioaddr + ATA_ERROR);
< b = inb(scp->ioaddr + ATA_CYL_LSB);
---
> ATA_OUTB(scp->r_io, ATA_ERROR, 0x58);
> ATA_OUTB(scp->r_io, ATA_CYL_LSB, 0xa5);
> a = ATA_INB(scp->r_io, ATA_ERROR);
> b = ATA_INB(scp->r_io, ATA_CYL_LSB);
1389c1404,1405
< outb(scp->bmaddr + ATA_BMSTAT_PORT, ata_dmastatus(scp) | ATA_BMSTAT_INTERRUPT);
---
> ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
> ata_dmastatus(scp) | ATA_BMSTAT_INTERRUPT);
1391c1407
< if ((inb(scp->ioaddr + ATA_DRIVE) & ATA_SLAVE) == ATA_MASTER) {
---
> if ((ATA_INB(scp->r_io, ATA_DRIVE) & ATA_SLAVE) == ATA_MASTER) {
1408d1423
< int statio = scp->ioaddr + ATA_STATUS;
1412c1427
< scp->status = inb(statio);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1417c1432
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device);
1419c1434
< scp->status = inb(statio);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1436c1451
< scp->error = inb(scp->ioaddr + ATA_ERROR);
---
> scp->error = ATA_INB(scp->r_io, ATA_ERROR);
1445c1460
< scp->status = inb(statio);
---
> scp->status = ATA_INB(scp->r_io, ATA_STATUS);
1448c1463
< scp->error = inb(scp->ioaddr + ATA_ERROR);
---
> scp->error = ATA_INB(scp->r_io, ATA_ERROR);
1465c1480
< scp->ioaddr, command, cylinder, head, sector,
---
> rman_get_start(scp->r_io), command, cylinder, head, sector,
1471c1486
< outb(scp->altioaddr, ATA_A_IDS | ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_IDS | ATA_A_4BIT);
1474c1489
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device);
---
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device);
1484,1489c1499,1504
< outb(scp->ioaddr + ATA_FEATURE, feature);
< outb(scp->ioaddr + ATA_COUNT, count);
< outb(scp->ioaddr + ATA_SECTOR, sector);
< outb(scp->ioaddr + ATA_CYL_MSB, cylinder >> 8);
< outb(scp->ioaddr + ATA_CYL_LSB, cylinder);
< outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | device | head);
---
> ATA_OUTB(scp->r_io, ATA_FEATURE, feature);
> ATA_OUTB(scp->r_io, ATA_COUNT, count);
> ATA_OUTB(scp->r_io, ATA_SECTOR, sector);
> ATA_OUTB(scp->r_io, ATA_CYL_MSB, cylinder >> 8);
> ATA_OUTB(scp->r_io, ATA_CYL_LSB, cylinder);
> ATA_OUTB(scp->r_io, ATA_DRIVE, ATA_D_IBM | device | head);
1495c1510
< outb(scp->ioaddr + ATA_CMD, command);
---
> ATA_OUTB(scp->r_io, ATA_CMD, command);
1499c1514
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);
1511c1526
< outb(scp->ioaddr + ATA_CMD, command);
---
> ATA_OUTB(scp->r_io, ATA_CMD, command);
1523c1538
< outb(scp->ioaddr + ATA_CMD, command);
---
> ATA_OUTB(scp->r_io, ATA_CMD, command);
1532c1547
< outb(scp->altioaddr, ATA_A_4BIT);
---
> ATA_OUTB(scp->r_altio, ATA_ALTSTAT, ATA_A_4BIT);