Deleted Added
full compact
28c28
< * $FreeBSD: head/sys/dev/ata/ata-pci.c 111485 2003-02-25 14:46:30Z sos $
---
> * $FreeBSD: head/sys/dev/ata/ata-pci.c 112791 2003-03-29 13:37:09Z sos $
57c57,58
< static int ata_pci_add_child(device_t, int);
---
> static int ata_pci_allocate(device_t, struct ata_channel *);
> static int ata_pci_dmainit(struct ata_channel *);
95a97
> ata_generic_ident(dev);
102a105
> ata_generic_ident(dev);
121c124
< struct ata_pci_controller *controller = device_get_softc(dev);
---
> struct ata_pci_controller *ctlr = device_get_softc(dev);
124c127
< int rid;
---
> int unit;
136a140,149
> /* do chipset specific setups only needed once */
> if (ATA_MASTERDEV(dev) || pci_read_config(dev, 0x18, 4) & IOMASK)
> ctlr->channels = 2;
> else
> ctlr->channels = 1;
> ctlr->allocate = ata_pci_allocate;
> ctlr->dmainit = ata_pci_dmainit;
> ctlr->locking = ata_pci_locknoop;
> ctlr->chipinit(dev);
>
143,145c156,158
< /* is busmastering supported ? */
< if ((cmd & (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN)) ==
< (PCIM_CMD_PORTEN | PCIM_CMD_BUSMASTEREN)) {
---
> /* is busmastering supported and configured ? */
> if ((cmd & PCIM_CMD_BUSMASTEREN) == PCIM_CMD_BUSMASTEREN) {
> int rid = ATA_BMADDR_RID;
147,152c160,164
< /* is there a valid port range to connect to ? */
< rid = 0x20;
< controller->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
< 0, ~0, 1, RF_ACTIVE);
< if (!controller->r_bmio)
< device_printf(dev, "Busmastering DMA not configured\n");
---
> if (!ctlr->r_mem) {
> if (!(ctlr->r_bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> 0, ~0, 1, RF_ACTIVE)))
> device_printf(dev, "Busmastering DMA not configured\n");
> }
157,160c169,172
< /* do chipset specific setups only needed once */
< controller->dmainit = ata_dmainit;
< controller->locking = ata_pci_locknoop;
< controller->chipinit(dev);
---
> /* attach all channels on this controller */
> for (unit = 0; unit < ctlr->channels; unit++)
> device_add_child(dev, "ata", ATA_MASTERDEV(dev) ?
> unit : devclass_find_free_unit(ata_devclass, 2));
162,173d173
< if (controller->r_bmio) {
< controller->bmaddr = rman_get_start(controller->r_bmio);
< BUS_RELEASE_RESOURCE(device_get_parent(dev), dev,
< SYS_RES_IOPORT, rid, controller->r_bmio);
< controller->r_bmio = NULL;
< }
<
< ata_pci_add_child(dev, 0);
<
< if (ATA_MASTERDEV(dev) || pci_read_config(dev, 0x18, 4) & IOMASK)
< ata_pci_add_child(dev, 1);
<
177,191d176
< static int
< ata_pci_add_child(device_t dev, int unit)
< {
< /* check if this is located at one of the std addresses */
< if (ATA_MASTERDEV(dev)) {
< if (!device_add_child(dev, "ata", unit))
< return ENOMEM;
< }
< else {
< if (!device_add_child(dev, "ata",
< devclass_find_free_unit(ata_devclass, 2)))
< return ENOMEM;
< }
< return 0;
< }
200c185
< retval += printf(": at 0x%lx", rman_get_start(ch->r_io));
---
> retval += printf(": at 0x%lx", rman_get_start(ch->r_io[0].res));
266,277d250
<
< case ATA_BMADDR_RID:
< if (controller->bmaddr) {
< myrid = 0x20;
< start = (unit == 0 ?
< controller->bmaddr : controller->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);
< }
325,328d297
<
< case ATA_BMADDR_RID:
< return BUS_RELEASE_RESOURCE(device_get_parent(dev), child,
< SYS_RES_IOPORT, 0x20, r);
395a365,371
>
> static int
> ata_pci_allocate(device_t dev, struct ata_channel *ch)
> {
> struct ata_pci_controller *ctlr = device_get_softc(device_get_parent(dev));
> struct resource *io = NULL, *altio = NULL;
> int i, rid;
396a373,463
> rid = ATA_IOADDR_RID;
> io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> 0, ~0, ATA_IOSIZE, RF_ACTIVE);
> if (!io)
> return ENXIO;
>
> rid = ATA_ALTADDR_RID;
> altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid,
> 0, ~0, ATA_ALTIOSIZE, RF_ACTIVE);
> if (!altio) {
> bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
> return ENXIO;
> }
>
> for (i = ATA_DATA; i <= ATA_STATUS; i ++) {
> ch->r_io[i].res = io;
> ch->r_io[i].offset = i;
> }
> ch->r_io[ATA_ALTSTAT].res = altio;
> ch->r_io[ATA_ALTSTAT].offset = 0;
>
> if (ctlr->r_bmio) {
> for (i = ATA_BMCMD_PORT; i <= ATA_BMDTP_PORT; i++) {
> ch->r_io[i].res = ctlr->r_bmio;
> ch->r_io[i].offset = (i - ATA_BMCMD_PORT)+(ch->unit * ATA_BMIOSIZE);
> }
>
> /* if simplex controller, only allow DMA on primary channel */
> ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, ATA_IDX_INB(ch, ATA_BMSTAT_PORT) &
> (ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
> if (ch->unit > 0 &&
> (ATA_IDX_INB(ch, ATA_BMSTAT_PORT) & ATA_BMSTAT_DMA_SIMPLEX))
> device_printf(dev, "simplex device, DMA on primary only\n");
> else
> ctlr->dmainit(ch);
> }
> return 0;
> }
>
> static int
> ata_pci_dmastart(struct ata_channel *ch, caddr_t data, int32_t count, int dir)
> {
> int error;
>
> if ((error = ata_dmastart(ch, data, count, dir)))
> return error;
>
> ATA_IDX_OUTL(ch, ATA_BMDTP_PORT, ch->dma->mdmatab);
> ATA_IDX_OUTB(ch, ATA_BMCMD_PORT, dir ? ATA_BMCMD_WRITE_READ : 0);
> ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, (ATA_IDX_INB(ch, ATA_BMSTAT_PORT) |
> (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR)));
> ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
> ATA_IDX_INB(ch, ATA_BMCMD_PORT) | ATA_BMCMD_START_STOP);
> return 0;
> }
>
> static int
> ata_pci_dmastop(struct ata_channel *ch)
> {
> int error;
>
> error = ATA_IDX_INB(ch, ATA_BMSTAT_PORT);
> ATA_IDX_OUTB(ch, ATA_BMCMD_PORT,
> ATA_IDX_INB(ch, ATA_BMCMD_PORT) & ~ATA_BMCMD_START_STOP);
> ATA_IDX_OUTB(ch, ATA_BMSTAT_PORT, ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR);
>
> ata_dmastop(ch);
>
> return (error & ATA_BMSTAT_MASK);
> }
>
> static int
> ata_pci_dmastatus(struct ata_channel *ch)
> {
> return ATA_IDX_INB(ch, ATA_BMSTAT_PORT) & ATA_BMSTAT_MASK;
> }
>
> static int
> ata_pci_dmainit(struct ata_channel *ch)
> {
> int error;
>
> if ((error = ata_dmainit(ch)))
> return error;
>
> ch->dma->start = ata_pci_dmastart;
> ch->dma->stop = ata_pci_dmastop;
> ch->dma->status = ata_pci_dmastatus;
> return 0;
> }
>
402d468
<
406a473
> DEVMETHOD(device_detach, ata_pci_attach),
447a515,517
> if ((error = ctlr->allocate(dev, ch)))
> return error;
>
451,465c521,522
< ch->chiptype = pci_get_devid(device_get_parent(dev));
<
< if (!(error = ata_probe(dev)) && ch->r_bmio) {
< /* if simplex controller, only allow DMA on primary channel */
< ATA_OUTB(ch->r_bmio, ATA_BMSTAT_PORT,
< ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) &
< (ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
< if (ch->unit == 1 && ATA_INB(ch->r_bmio, ATA_BMSTAT_PORT) &
< ATA_BMSTAT_DMA_SIMPLEX) {
< ata_printf(ch, -1, "simplex device, DMA on primary only\n");
< return error;
< }
< error = ctlr->dmainit(ch);
< }
< return error;
---
> ch->chiptype = ctlr->chip->chipid;
> return ata_probe(dev);