From 37eec7a1a68b962f5880c2bf24463233ec655428 Mon Sep 17 00:00:00 2001 From: sos Date: Mon, 3 Jan 2000 10:26:59 +0000 Subject: Add support for VIA 82C596 controller Better shared irq handeling for Promise & HPT366 controllers Setup prober PIO mode timings on Promise & HPT366 controllers Update Copyright headers to be Y2K compliant :) --- sys/dev/ata/ata-all.c | 121 +++++++++++++++++++--------- sys/dev/ata/ata-all.h | 23 +++--- sys/dev/ata/ata-disk.c | 3 +- sys/dev/ata/ata-disk.h | 2 +- sys/dev/ata/ata-dma.c | 201 ++++++++++++++++++++++++++++------------------- sys/dev/ata/atapi-all.c | 2 +- sys/dev/ata/atapi-all.h | 2 +- sys/dev/ata/atapi-cd.c | 2 +- sys/dev/ata/atapi-cd.h | 2 +- sys/dev/ata/atapi-fd.c | 2 +- sys/dev/ata/atapi-fd.h | 2 +- sys/dev/ata/atapi-tape.c | 2 +- sys/dev/ata/atapi-tape.h | 2 +- 13 files changed, 225 insertions(+), 141 deletions(-) diff --git a/sys/dev/ata/ata-all.c b/sys/dev/ata/ata-all.c index 53714da..ec08f12 100644 --- a/sys/dev/ata/ata-all.c +++ b/sys/dev/ata/ata-all.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -74,7 +74,7 @@ #if SMP == 0 #define isa_apic_irq(x) x #endif -#define IOMASK 0xfffffffc /* XXX SOS 0xfffc */ +#define IOMASK 0xfffffffc /* prototypes */ static int32_t ata_probe(int32_t, int32_t, int32_t, device_t, int32_t *); @@ -189,41 +189,54 @@ ata_pcimatch(device_t dev) /* supported chipsets */ case 0x12308086: return "Intel PIIX ATA controller"; + case 0x70108086: return "Intel PIIX3 ATA controller"; + case 0x71118086: case 0x71998086: - return "Intel PIIX4 ATA controller"; + return "Intel PIIX4 ATA-33 controller"; + case 0x522910b9: - return "AcerLabs Aladdin ATA controller"; + return "AcerLabs Aladdin ATA-33 controller"; + case 0x05711106: /* 82c586 & 82c686 */ if (ata_find_dev(dev, 0x05861106)) - return "VIA 82C586 ATA controller"; + return "VIA 82C586 ATA-33 controller"; + if (ata_find_dev(dev, 0x05961106)) + return "VIA 82C596 ATA-33 controller"; if (ata_find_dev(dev, 0x06861106)) - return "VIA 82C686 ATA controller"; + return "VIA 82C686 ATA-66 controller"; return "VIA Apollo ATA controller"; + case 0x55131039: - return "SiS 5591 ATA controller"; + return "SiS 5591 ATA-33 controller"; + case 0x74091022: - return "AMD 756 ATA controller"; + return "AMD 756 ATA-66 controller"; + case 0x4d33105a: - return "Promise Ultra/33 ATA controller"; + return "Promise ATA-33 controller"; + case 0x4d38105a: - return "Promise Ultra/66 ATA controller"; + return "Promise ATA-66 controller"; + case 0x00041103: - return "HighPoint HPT366 ATA controller"; + return "HighPoint HPT366 ATA-66 controller"; /* unsupported but known chipsets, generic DMA only */ - case 0x05961106: - return "VIA 82C596 ATA controller (generic mode)"; case 0x06401095: return "CMD 640 ATA controller (generic mode)"; + case 0x06461095: return "CMD 646 ATA controller (generic mode)"; + case 0xc6931080: return "Cypress 82C693 ATA controller (generic mode)"; + case 0x01021078: return "Cyrix 5530 ATA controller (generic mode)"; + default: if (pci_get_class(dev) == PCIC_STORAGE && (pci_get_subclass(dev) == PCIS_STORAGE_IDE)) @@ -321,21 +334,22 @@ ata_pciattach(device_t dev) /* do extra chipset specific setups */ switch (type) { - case 0x522910b9: - /* on the Aladdin activate the ATAPI FIFO */ + case 0x522910b9: /* Aladdin need to activate the ATAPI FIFO */ pci_write_config(dev, 0x53, (pci_read_config(dev, 0x53, 1) & ~0x01) | 0x02, 1); break; case 0x4d33105a: - case 0x4d38105a: - /* the Promise's need burst mode to be turned on explicitly */ + case 0x4d38105a: /* Promise's need burst mode to be turned on */ outb(bmaddr_1 + 0x1f, inb(bmaddr_1 + 0x1f) | 0x01); break; + case 0x00041103: /* HPT366 controller defaults */ + printf("ata: HPT config %08x\n", pci_read_config(dev, 0x50, 4)); + break; + case 0x05711106: - case 0x74091022: - /* the VIA 82C586, VIA 82C686 & AMD 756 needs some sensible defaults */ + case 0x74091022: /* VIA 82C586, 82C596, 82C686 & AMD 756 default setup */ /* set prefetch, postwrite */ pci_write_config(dev, 0x41, pci_read_config(dev, 0x41, 1) | 0xf0, 1); @@ -360,6 +374,7 @@ ata_pciattach(device_t dev) lun = 0; if (iobase_1 && ata_probe(iobase_1, altiobase_1, bmaddr_1, dev, &lun)) { scp = atadevices[lun]; + scp->chiptype = type; if (iobase_1 == IO_WD1) #ifdef __i386__ inthand_add(device_get_nameunit(dev), irq1, ataintr, scp, @@ -383,6 +398,7 @@ ata_pciattach(device_t dev) lun = 1; if (iobase_2 && ata_probe(iobase_2, altiobase_2, bmaddr_2, dev, &lun)) { scp = atadevices[lun]; + scp->chiptype = type; if (iobase_2 == IO_WD2) #ifdef __i386__ inthand_add(device_get_nameunit(dev), irq2, ataintr, scp, @@ -575,14 +591,30 @@ ata_probe(int32_t ioaddr, int32_t altioaddr, int32_t bmaddr, static void ataintr(void *data) { - struct ata_softc *scp =(struct ata_softc *)data; + struct ata_softc *scp = (struct ata_softc *)data; - /* is this interrupt really for this channel */ - if ((scp->flags & ATA_DMA_ACTIVE) && - !(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT)) - return; + /* check if this interrupt is for us (shared PCI interrupts) */ + switch (scp->chiptype) { + case 0x00041103: /* HighPoint HPT366 controller */ + if (scp->active == ATA_IDLE) + return; + if (!(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT)) + return; + break; - if (((scp->status = inb(scp->ioaddr+ATA_STATUS)) & ATA_S_BUSY)==ATA_S_BUSY) + case 0x4d33105a: /* Promise 33's */ + case 0x4d38105a: /* Promise 66's */ + if (!(inl((pci_read_config(scp->dev, 0x20, 4) & IOMASK) + 0x1c) & + ((scp->unit) ? 0x00004000 : 0x00000400))) + return; + break; + + default: + if ((scp->flags & ATA_DMA_ACTIVE) && + !(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT)) + return; + } + if (((scp->status = inb(scp->ioaddr + ATA_STATUS))&ATA_S_BUSY)==ATA_S_BUSY) return; /* find & call the responsible driver to process this interrupt */ @@ -623,7 +655,7 @@ ataintr(void *data) scp->lun, intr_count, scp->status); } #endif - return; + /* return; SOS XXX */ } scp->active = ATA_IDLE; scp->running = NULL; @@ -883,24 +915,36 @@ int8_t * ata_mode2str(int32_t mode) { switch (mode) { - case ATA_MODE_PIO: - return "PIO"; - case ATA_MODE_WDMA2: - return "DMA"; - case ATA_MODE_UDMA2: - return "UDMA33"; - case ATA_MODE_UDMA3: - return "UDMA3"; - case ATA_MODE_UDMA4: - return "UDMA66"; + case ATA_PIO0: return "PIO0"; + case ATA_PIO1: return "PIO1"; + case ATA_PIO2: return "PIO2"; + case ATA_PIO3: return "PIO3"; + case ATA_PIO4: return "PIO4"; + case ATA_WDMA2: return "WDMA2"; + case ATA_UDMA2: return "UDMA33"; + case ATA_UDMA4: return "UDMA66"; + default: return "???"; + } +} + +int8_t +ata_pio2mode(int32_t pio) +{ + switch (pio) { default: - return "???"; + case 0: return ATA_PIO0; + case 1: return ATA_PIO1; + case 2: return ATA_PIO2; + case 3: return ATA_PIO3; + case 4: return ATA_PIO4; } } static int8_t * active2str(int32_t active) { + static char buf[8]; + switch (active) { case ATA_IDLE: return("ATA_IDLE"); @@ -913,7 +957,8 @@ active2str(int32_t active) case ATA_REINITING: return("ATA_REINITING"); default: - return("UNKNOWN"); + sprintf(buf, "0x%02x", active); + return buf; } } diff --git a/sys/dev/ata/ata-all.h b/sys/dev/ata/ata-all.h index 73bfbe2..e6d7c5e 100644 --- a/sys/dev/ata/ata-all.h +++ b/sys/dev/ata/ata-all.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -124,12 +124,6 @@ struct ata_dmaentry { u_int32_t count; }; -/* ATA device DMA access modes */ -#define ATA_WDMA2 0x22 -#define ATA_UDMA2 0x42 -#define ATA_UDMA3 0x43 -#define ATA_UDMA4 0x44 - /* structure describing an ATA device */ struct ata_softc { int32_t unit; /* unit on this controller */ @@ -138,14 +132,18 @@ struct ata_softc { int32_t ioaddr; /* port addr */ int32_t altioaddr; /* alternate port addr */ int32_t bmaddr; /* bus master DMA port */ + int32_t chiptype; /* pciid of controller chip */ void *dev_softc[2]; /* ptr to devices softc's */ struct ata_dmaentry *dmatab[2]; /* DMA transfer tables */ int32_t mode[2]; /* transfer mode for devices */ -#define ATA_MODE_PIO 0x00 -#define ATA_MODE_WDMA2 0x01 -#define ATA_MODE_UDMA2 0x02 -#define ATA_MODE_UDMA3 0x04 -#define ATA_MODE_UDMA4 0x08 +#define ATA_PIO0 0x08 +#define ATA_PIO1 0x09 +#define ATA_PIO2 0x0a +#define ATA_PIO3 0x0b +#define ATA_PIO4 0x0c +#define ATA_WDMA2 0x22 +#define ATA_UDMA2 0x42 +#define ATA_UDMA4 0x44 int32_t flags; /* controller flags */ #define ATA_DMA_ACTIVE 0x01 @@ -193,6 +191,7 @@ void ata_dmastart(struct ata_softc *); int32_t ata_dmastatus(struct ata_softc *); int32_t ata_dmadone(struct ata_softc *); int8_t *ata_mode2str(int32_t); +int8_t ata_pio2mode(int32_t); void bswap(int8_t *, int32_t); void btrim(int8_t *, int32_t); void bpack(int8_t *, int8_t *, int32_t); diff --git a/sys/dev/ata/ata-disk.c b/sys/dev/ata/ata-disk.c index 1361d94..598d6df 100644 --- a/sys/dev/ata/ata-disk.c +++ b/sys/dev/ata/ata-disk.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -462,6 +462,7 @@ ad_transfer(struct ad_request *request) /* does this drive support multi sector transfers ? */ else if (request->currentsize > DEV_BSIZE) cmd = request->flags & AR_F_READ?ATA_C_READ_MULTI:ATA_C_WRITE_MULTI; + /* just plain old single sector transfer */ else cmd = request->flags & AR_F_READ ? ATA_C_READ : ATA_C_WRITE; diff --git a/sys/dev/ata/ata-disk.h b/sys/dev/ata/ata-disk.h index ce101bf..709b1fb 100644 --- a/sys/dev/ata/ata-disk.h +++ b/sys/dev/ata/ata-disk.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/ata-dma.c b/sys/dev/ata/ata-dma.c index 500fd1a..d87a81e 100644 --- a/sys/dev/ata/ata-dma.c +++ b/sys/dev/ata/ata-dma.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -49,6 +49,7 @@ #include /* prototypes */ +static void promise_timing(struct ata_softc *, int32_t, int32_t); static void hpt366_timing(struct ata_softc *, int32_t, int32_t); /* misc defines */ @@ -64,8 +65,8 @@ int32_t ata_dmainit(struct ata_softc *scp, int32_t device, int32_t apiomode, int32_t wdmamode, int32_t udmamode) { - int32_t type, error; int32_t devno = (scp->unit << 1) + ((device == ATA_MASTER) ? 0 : 1); + int32_t error; void *dmatab; if (!scp->bmaddr) @@ -94,7 +95,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, } scp->dmatab[(device == ATA_MASTER) ? 0 : 1] = dmatab; - switch (type = pci_get_devid(scp->dev)) { + switch (scp->chiptype) { case 0x71118086: /* Intel PIIX4 */ case 0x71998086: /* Intel PIIX4 */ @@ -113,7 +114,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, pci_write_config(scp->dev, 0x48, (pci_read_config(scp->dev, 0x48, 4) & ~mask48) | new48, 4); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2; return 0; } } @@ -145,7 +146,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, printf("ata%d-%s: %s setting up WDMA2 mode on PIIX%s chip\n", scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success", - (type == 0x70108086) ? "3" : "4"); + (scp->chiptype == 0x70108086) ? "3" : "4"); if (!error) { if (device == ATA_MASTER) { mask40 = 0x0000330f; @@ -171,7 +172,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, pci_write_config(scp->dev, 0x44, (pci_read_config(scp->dev, 0x44, 4) & ~mask44)| new44, 4); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } @@ -197,7 +198,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } @@ -226,7 +227,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, pci_write_config(scp->dev, 0x53, pci_read_config(scp->dev, 0x53, 1) | 0x03, 1); scp->flags |= ATA_ATAPI_DMA_RO; - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2; return 0; } } @@ -241,64 +242,64 @@ ata_dmainit(struct ata_softc *scp, int32_t device, pci_write_config(scp->dev, 0x53, pci_read_config(scp->dev, 0x53, 1) | 0x03, 1); scp->flags |= ATA_ATAPI_DMA_RO; - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } /* we could set PIO mode timings, but we assume the BIOS did that */ break; - case 0x05711106: /* VIA Apollo 82C571 / 82C586 / 82C686 */ + case 0x05711106: /* VIA 82C571, 82C586, 82C596 & 82C686 */ case 0x74091022: /* AMD 756 */ - /* UDMA4 mode only on 82C686 / AMD 756 hardware */ + /* UDMA4 mode only on 82C686 and AMD 756 */ if ((udmamode >= 4 && ata_find_dev(scp->dev, 0x06861106)) || - (udmamode >= 4 && type == 0x74091022)) { + (udmamode >= 4 && scp->chiptype == 0x74091022)) { error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY); if (bootverbose) printf("ata%d-%s: %s setting up UDMA4 mode on %s chip\n", scp->lun, (device == ATA_MASTER) ? "master":"slave", (error) ? "failed" : "success", - (type == 0x74091022) ? "AMD" : "VIA"); + (scp->chiptype == 0x74091022) ? "AMD" : "VIA"); if (!error) { pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA4; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4; return 0; } } - /* UDMA2 mode only on 82C686 and AMD 756 and rev 1 and better 82C586 */ - if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x06861106)) || - (udmamode >= 2 && type == 0x74091022) || - (udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) && - pci_read_config(scp->dev, 0x08, 1) >= 0x01)) { + /* UDMA2 mode only on 82C586 > rev1, 82C596, 82C686, AMD 756 */ + if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) && + pci_read_config(scp->dev, 0x08, 1) >= 0x01) || + (udmamode >= 2 && ata_find_dev(scp->dev, 0x05961106)) || + (udmamode >= 2 && ata_find_dev(scp->dev, 0x06861106)) || + (udmamode >= 2 && scp->chiptype == 0x74091022)) { error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY); if (bootverbose) printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n", scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success", - (type == 0x74091022) ? "AMD" : "VIA"); + (scp->chiptype == 0x74091022) ? "AMD" : "VIA"); if (!error) { pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2; return 0; } } if (wdmamode >= 2 && apiomode >= 4) { /* set WDMA2 mode timing */ - error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY); if (bootverbose) printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n", scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success", - (type == 0x74091022) ? "AMD" : "VIA"); + (scp->chiptype == 0x74091022) ? "AMD" : "VIA"); if (!error) { pci_write_config(scp->dev, 0x53 - devno, 0x82, 1); pci_write_config(scp->dev, 0x4b - devno, 0x31, 1); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } @@ -315,7 +316,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, (error) ? "failed" : "success"); if (!error) { pci_write_config(scp->dev, 0x40 + (devno << 1), 0xa301, 2); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2; return 0; } } @@ -328,7 +329,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, (error) ? "failed" : "success"); if (!error) { pci_write_config(scp->dev, 0x40 + (devno << 1), 0x0301, 2); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } @@ -342,7 +343,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, (device == ATA_SLAVE && scp->devices & ATA_ATAPI_SLAVE)) break; - if (udmamode >=4 && type == 0x4d38105a && + if (udmamode >=4 && scp->chiptype == 0x4d38105a && !(pci_read_config(scp->dev, 0x50, 2)&(scp->unit ? 1<<11 : 1<<10))) { error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY); @@ -352,8 +353,8 @@ ata_dmainit(struct ata_softc *scp, int32_t device, (error) ? "failed" : "success"); if (!error) { outb(scp->bmaddr+0x11, inl(scp->bmaddr+0x11) | scp->unit ? 8:2); - pci_write_config(scp->dev, 0x60 + (devno << 2), 0x004127f3, 4); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA4; + promise_timing(scp, devno, ATA_UDMA4); + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4; return 0; } } @@ -365,8 +366,8 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - pci_write_config(scp->dev, 0x60 + (devno << 2), 0x004127f3, 4); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA2; + promise_timing(scp, devno, ATA_UDMA2); + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2; return 0; } } @@ -378,15 +379,23 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - pci_write_config(scp->dev, 0x60 + (devno << 2), 0x004367f3, 4); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + promise_timing(scp, devno, ATA_WDMA2); + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } + error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, + ata_pio2mode(apiomode), + ATA_C_F_SETXFER, ATA_WAIT_READY); if (bootverbose) - printf("ata%d-%s: setting PIO mode on Promise chip\n", - scp->lun, (device == ATA_MASTER) ? "master" : "slave"); - pci_write_config(scp->dev, 0x60 + (devno << 2), 0x004fe924, 4); + printf("ata%d-%s: %s setting up PIO%d mode on Promise chip\n", + scp->lun, (device == ATA_MASTER) ? "master" : "slave", + (error) ? "failed" : "success", + (apiomode >= 0) ? apiomode : 0); + if (!error) { + promise_timing(scp, devno, ata_pio2mode(apiomode)); + return 0; + } break; case 0x00041103: /* HighPoint HPT366 controller */ @@ -403,21 +412,8 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - hpt366_timing(scp, device, ATA_MODE_UDMA4); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA4; - return 0; - } - } - if (udmamode >=3 && !(pci_read_config(scp->dev, 0x5a, 1) & 0x2)) { - error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, - ATA_UDMA3, ATA_C_F_SETXFER, ATA_WAIT_READY); - if (bootverbose) - printf("ata%d-%s: %s setting up UDMA3 mode on HPT366 chip\n", - scp->lun, (device == ATA_MASTER) ? "master" : "slave", - (error) ? "failed" : "success"); - if (!error) { - hpt366_timing(scp, device, ATA_MODE_UDMA3); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA3; + hpt366_timing(scp, devno, ATA_UDMA4); + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4; return 0; } } @@ -429,8 +425,8 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - hpt366_timing(scp, device, ATA_MODE_UDMA2); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_UDMA2; + hpt366_timing(scp, devno, ATA_UDMA2); + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2; return 0; } } @@ -442,15 +438,23 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - hpt366_timing(scp, device, ATA_MODE_WDMA2); - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + hpt366_timing(scp, devno, ATA_WDMA2); + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } + error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, + ata_pio2mode(apiomode), + ATA_C_F_SETXFER, ATA_WAIT_READY); if (bootverbose) - printf("ata%d-%s: setting PIO mode on HPT366 chip\n", - scp->lun, (device == ATA_MASTER) ? "master" : "slave"); - hpt366_timing(scp, device, ATA_MODE_PIO); + printf("ata%d-%s: %s setting up PIO%d mode on HPT366 chip\n", + scp->lun, (device == ATA_MASTER) ? "master" : "slave", + (error) ? "failed" : "success", + (apiomode >= 0) ? apiomode : 0); + if (!error) { + hpt366_timing(scp, devno, ata_pio2mode(apiomode)); + return 0; + } break; default: /* unknown controller chip */ @@ -462,7 +466,7 @@ ata_dmainit(struct ata_softc *scp, int32_t device, /* well, we have no support for this, but try anyways */ if ((wdmamode >= 2 && apiomode >= 4) && scp->bmaddr) { #if MAYBE_NOT - && (inb(scp->bmaddr + ATA_BMSTAT_PORT) & + && (inb(scp->bmaddr + ATA_BMSTAT_PORT) & ((device == ATA_MASTER) ? ATA_BMSTAT_DMA_MASTER : ATA_BMSTAT_DMA_SLAVE))) { #endif @@ -473,12 +477,20 @@ ata_dmainit(struct ata_softc *scp, int32_t device, scp->lun, (device == ATA_MASTER) ? "master" : "slave", (error) ? "failed" : "success"); if (!error) { - scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_MODE_WDMA2; + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_WDMA2; return 0; } } } free(dmatab, M_DEVBUF); + error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0, + ata_pio2mode(apiomode), ATA_C_F_SETXFER,ATA_WAIT_READY); + if (bootverbose) + printf("ata%d-%s: %s setting up PIO%d mode on generic chip\n", + scp->lun, (device == ATA_MASTER) ? "master" : "slave", + (error) ? "failed" : "success", (apiomode >= 0) ? apiomode : 0); + if (!error) + scp->mode[(device == ATA_MASTER) ? 0 : 1] = ata_pio2mode(apiomode); return -1; } @@ -552,43 +564,70 @@ ata_dmastatus(struct ata_softc *scp) } static void -hpt366_timing(struct ata_softc *scp, int32_t device, int32_t mode) +promise_timing(struct ata_softc *scp, int32_t devno, int32_t mode) +{ + u_int32_t timing; + switch (mode) { + default: + case ATA_PIO0: timing = 0x004ff329; break; + case ATA_PIO1: timing = 0x004fec25; break; + case ATA_PIO2: timing = 0x004fe823; break; + case ATA_PIO3: timing = 0x004fe622; break; + case ATA_PIO4: timing = 0x004fe421; break; + case ATA_WDMA2: timing = 0x004367f3; break; + case ATA_UDMA2: timing = 0x004127f3; break; + case ATA_UDMA4: timing = 0x004127f3; break; + } + pci_write_config(scp->dev, 0x60 + (devno << 2), timing, 4); +} + +static void +hpt366_timing(struct ata_softc *scp, int32_t devno, int32_t mode) { u_int32_t timing; - switch (pci_read_config(scp->dev, (device == ATA_MASTER) ? 0x41 : 0x45, 1)){ + switch (pci_read_config(scp->dev, 0x41 + (devno << 2), 1)) { case 0x85: /* 25Mhz */ switch (mode) { - case ATA_MODE_PIO: timing = 0xc0ca8521; break; - case ATA_MODE_WDMA2: timing = 0xa0ca8521; break; - case ATA_MODE_UDMA2: - case ATA_MODE_UDMA3: timing = 0x90cf8521; break; - case ATA_MODE_UDMA4: timing = 0x90c98521; break; - default: timing = 0x01208585; + case ATA_PIO0: timing = 0xc0d08585; break; + case ATA_PIO1: timing = 0xc0d08572; break; + case ATA_PIO2: timing = 0xc0ca8542; break; + case ATA_PIO3: timing = 0xc0ca8532; break; + case ATA_PIO4: timing = 0xc0ca8521; break; + case ATA_WDMA2: timing = 0xa0ca8521; break; + case ATA_UDMA2: timing = 0x90cf8521; break; + case ATA_UDMA4: timing = 0x90c98521; break; + default: timing = 0x01208585; } break; default: case 0xa7: /* 33MHz */ switch (mode) { - case ATA_MODE_PIO: timing = 0xc0c8a731; break; - case ATA_MODE_WDMA2: timing = 0xa0c8a731; break; - case ATA_MODE_UDMA2: timing = 0x90caa731; break; - case ATA_MODE_UDMA3: timing = 0x90cfa731; break; - case ATA_MODE_UDMA4: timing = 0x90c9a731; break; - default: timing = 0x0120a7a7; + case ATA_PIO0: timing = 0xc0d0a7aa; break; + case ATA_PIO1: timing = 0xc0d0a7a3; break; + case ATA_PIO2: timing = 0xc0d0a753; break; + case ATA_PIO3: timing = 0xc0c8a742; break; + case ATA_PIO4: timing = 0xc0c8a731; break; + case ATA_WDMA2: timing = 0xa0c8a731; break; + case ATA_UDMA2: timing = 0x90caa731; break; + case ATA_UDMA4: timing = 0x90c9a731; break; + default: timing = 0x0120a7a7; } break; case 0xd9: /* 40Mhz */ switch (mode) { - case ATA_MODE_PIO: timing = 0xc008d963; break; - case ATA_MODE_WDMA2: timing = 0xa008d943; break; - case ATA_MODE_UDMA2: timing = 0x900bd943; break; - case ATA_MODE_UDMA3: timing = 0x900ad943; break; - case ATA_MODE_UDMA4: timing = 0x900fd943; break; - default: timing = 0x0120d9d9; + case ATA_PIO0: timing = 0xc018d9d9; break; + case ATA_PIO1: timing = 0xc010d9c7; break; + case ATA_PIO2: timing = 0xc010d997; break; + case ATA_PIO3: timing = 0xc010d974; break; + case ATA_PIO4: timing = 0xc008d963; break; + case ATA_WDMA2: timing = 0xa008d943; break; + case ATA_UDMA2: timing = 0x900bd943; break; + case ATA_UDMA4: timing = 0x900fd943; break; + default: timing = 0x0120d9d9; } } - pci_write_config(scp->dev, (device==ATA_MASTER ? 0x40 : 0x44), timing, 4); + pci_write_config(scp->dev, 0x40 + (devno << 2) , timing, 4); } #else /* NPCI > 0 */ diff --git a/sys/dev/ata/atapi-all.c b/sys/dev/ata/atapi-all.c index e641019..9033f82 100644 --- a/sys/dev/ata/atapi-all.c +++ b/sys/dev/ata/atapi-all.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-all.h b/sys/dev/ata/atapi-all.h index 7cbcbde..289d1bf 100644 --- a/sys/dev/ata/atapi-all.h +++ b/sys/dev/ata/atapi-all.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-cd.c b/sys/dev/ata/atapi-cd.c index e60d1ad..181afff 100644 --- a/sys/dev/ata/atapi-cd.c +++ b/sys/dev/ata/atapi-cd.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-cd.h b/sys/dev/ata/atapi-cd.h index b8c5fda..e2df22d 100644 --- a/sys/dev/ata/atapi-cd.h +++ b/sys/dev/ata/atapi-cd.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-fd.c b/sys/dev/ata/atapi-fd.c index fa4506f..6c45f6f 100644 --- a/sys/dev/ata/atapi-fd.c +++ b/sys/dev/ata/atapi-fd.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-fd.h b/sys/dev/ata/atapi-fd.h index 7ae6d85..2f4e990 100644 --- a/sys/dev/ata/atapi-fd.h +++ b/sys/dev/ata/atapi-fd.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-tape.c b/sys/dev/ata/atapi-tape.c index 984fa18..6b60f9c 100644 --- a/sys/dev/ata/atapi-tape.c +++ b/sys/dev/ata/atapi-tape.c @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without diff --git a/sys/dev/ata/atapi-tape.h b/sys/dev/ata/atapi-tape.h index 7f67460..b2c00fb 100644 --- a/sys/dev/ata/atapi-tape.h +++ b/sys/dev/ata/atapi-tape.h @@ -1,5 +1,5 @@ /*- - * Copyright (c) 1998,1999 Søren Schmidt + * Copyright (c) 1998,1999,2000 Søren Schmidt * All rights reserved. * * Redistribution and use in source and binary forms, with or without -- cgit v1.1