Deleted Added
full compact
ata-all.c (64534) ata-all.c (64695)
1/*-
2 * Copyright (c) 1998,1999,2000 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
1/*-
2 * Copyright (c) 1998,1999,2000 S�ren Schmidt
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/sys/dev/ata/ata-all.c 64534 2000-08-11 10:34:22Z sos $
28 * $FreeBSD: head/sys/dev/ata/ata-all.c 64695 2000-08-16 07:09:04Z sos $
29 */
30
31#include "ata.h"
32#include "isa.h"
33#include "card.h"
34#include "pci.h"
35#include "atadisk.h"
36#include "atapicd.h"

--- 228 unchanged lines hidden (view full) ---

265
266 case 0x522910b9:
267 return "AcerLabs Aladdin ATA33 controller";
268
269 case 0x05711106:
270 if (ata_find_dev(dev, 0x05861106, 0))
271 return "VIA 82C586 ATA33 controller";
272 if (ata_find_dev(dev, 0x05961106, 0x12))
29 */
30
31#include "ata.h"
32#include "isa.h"
33#include "card.h"
34#include "pci.h"
35#include "atadisk.h"
36#include "atapicd.h"

--- 228 unchanged lines hidden (view full) ---

265
266 case 0x522910b9:
267 return "AcerLabs Aladdin ATA33 controller";
268
269 case 0x05711106:
270 if (ata_find_dev(dev, 0x05861106, 0))
271 return "VIA 82C586 ATA33 controller";
272 if (ata_find_dev(dev, 0x05961106, 0x12))
273 return "VIA 82C596B ATA66 controller";
273 return "VIA 82C596 ATA66 controller";
274 if (ata_find_dev(dev, 0x05961106, 0))
275 return "VIA 82C596 ATA33 controller";
276 if (ata_find_dev(dev, 0x06861106, 0))
277 return "VIA 82C686 ATA66 controller";
278 return "VIA Apollo ATA controller";
279
280 case 0x55131039:
281 return "SiS 5591 ATA33 controller";

--- 129 unchanged lines hidden (view full) ---

411 /* do extra chipset specific setups */
412 switch (type) {
413 case 0x522910b9: /* Aladdin need to activate the ATAPI FIFO */
414 pci_write_config(dev, 0x53,
415 (pci_read_config(dev, 0x53, 1) & ~0x01) | 0x02, 1);
416 break;
417
418 case 0x4d38105a: /* Promise 66's need their clock changed */
274 if (ata_find_dev(dev, 0x05961106, 0))
275 return "VIA 82C596 ATA33 controller";
276 if (ata_find_dev(dev, 0x06861106, 0))
277 return "VIA 82C686 ATA66 controller";
278 return "VIA Apollo ATA controller";
279
280 case 0x55131039:
281 return "SiS 5591 ATA33 controller";

--- 129 unchanged lines hidden (view full) ---

411 /* do extra chipset specific setups */
412 switch (type) {
413 case 0x522910b9: /* Aladdin need to activate the ATAPI FIFO */
414 pci_write_config(dev, 0x53,
415 (pci_read_config(dev, 0x53, 1) & ~0x01) | 0x02, 1);
416 break;
417
418 case 0x4d38105a: /* Promise 66's need their clock changed */
419 case 0x4d30105a: /* Promise 100 too */
419 case 0x4d30105a: /* Promise 100's too */
420 outb(rman_get_start(sc->bmio) + 0x11,
421 inb(rman_get_start(sc->bmio) + 0x11) | 0x0a);
422 /* FALLTHROUGH */
423
424 case 0x4d33105a: /* Promise's need burst mode to be turned on */
425 outb(rman_get_start(sc->bmio) + 0x1f,
426 inb(rman_get_start(sc->bmio) + 0x1f) | 0x01);
427 break;

--- 302 unchanged lines hidden (view full) ---

730
731static int
732ata_pcisub_probe(device_t dev)
733{
734 struct ata_softc *scp = device_get_softc(dev);
735
736 /* kids of pci ata chipsets has their physical unit number in ivars */
737 scp->unit = (uintptr_t) device_get_ivars(dev);
420 outb(rman_get_start(sc->bmio) + 0x11,
421 inb(rman_get_start(sc->bmio) + 0x11) | 0x0a);
422 /* FALLTHROUGH */
423
424 case 0x4d33105a: /* Promise's need burst mode to be turned on */
425 outb(rman_get_start(sc->bmio) + 0x1f,
426 inb(rman_get_start(sc->bmio) + 0x1f) | 0x01);
427 break;

--- 302 unchanged lines hidden (view full) ---

730
731static int
732ata_pcisub_probe(device_t dev)
733{
734 struct ata_softc *scp = device_get_softc(dev);
735
736 /* kids of pci ata chipsets has their physical unit number in ivars */
737 scp->unit = (uintptr_t) device_get_ivars(dev);
738
739 /* set the chiptype to the hostchip ID, makes life easier */
740 if (ata_find_dev(device_get_parent(dev), 0x05861106, 0))
741 scp->chiptype = 0x05861106;
742 else if (ata_find_dev(device_get_parent(dev), 0x05961106, 0))
743 scp->chiptype = 0x05961106;
744 else if (ata_find_dev(device_get_parent(dev), 0x06861106, 0))
745 scp->chiptype = 0x06861106;
746 else
747 scp->chiptype = pci_get_devid(device_get_parent(dev));
738 scp->chiptype = pci_get_devid(device_get_parent(dev));
748 return ata_probe(dev);
749}
750
751static device_method_t ata_pcisub_methods[] = {
752 /* device interface */
753 DEVMETHOD(device_probe, ata_pcisub_probe),
754 DEVMETHOD(device_attach, ata_attach),
755 DEVMETHOD(device_detach, ata_detach),

--- 76 unchanged lines hidden (view full) ---

832 mask |= 0x02;
833 if (bootverbose)
834 ata_printf(scp, -1, "mask=%02x status0=%02x status1=%02x\n",
835 mask, status0, status1);
836 if (!mask)
837 goto failure;
838
839 ata_reset(scp, &mask);
739 return ata_probe(dev);
740}
741
742static device_method_t ata_pcisub_methods[] = {
743 /* device interface */
744 DEVMETHOD(device_probe, ata_pcisub_probe),
745 DEVMETHOD(device_attach, ata_attach),
746 DEVMETHOD(device_detach, ata_detach),

--- 76 unchanged lines hidden (view full) ---

823 mask |= 0x02;
824 if (bootverbose)
825 ata_printf(scp, -1, "mask=%02x status0=%02x status1=%02x\n",
826 mask, status0, status1);
827 if (!mask)
828 goto failure;
829
830 ata_reset(scp, &mask);
840 if (!mask)
841 goto failure;
842
831
843 /*
844 * OK, we have at least one device on the chain, check for ATAPI
845 * signatures, if none check if its a good old ATA device.
846 */
847 outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
848 DELAY(1);
849 if (inb(scp->ioaddr + ATA_CYL_LSB) == ATAPI_MAGIC_LSB &&
850 inb(scp->ioaddr + ATA_CYL_MSB) == ATAPI_MAGIC_MSB) {
851 scp->devices |= ATA_ATAPI_MASTER;
852 }
853 outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
854 DELAY(1);
855 if (inb(scp->ioaddr + ATA_CYL_LSB) == ATAPI_MAGIC_LSB &&
856 inb(scp->ioaddr + ATA_CYL_MSB) == ATAPI_MAGIC_MSB) {
857 scp->devices |= ATA_ATAPI_SLAVE;
858 }
859 if (status0 != 0x00 && !(scp->devices & ATA_ATAPI_MASTER)) {
860 outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
861 DELAY(1);
862 outb(scp->ioaddr + ATA_ERROR, 0x58);
863 outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
864 if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
865 inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
866 scp->devices |= ATA_ATA_MASTER;
867 }
868 }
869 if (status1 != 0x00 && !(scp->devices & ATA_ATAPI_SLAVE)) {
870 outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
871 DELAY(1);
872 outb(scp->ioaddr + ATA_ERROR, 0x58);
873 outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
874 if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
875 inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
876 scp->devices |= ATA_ATA_SLAVE;
877 }
878 }
879 if (bootverbose)
880 ata_printf(scp, -1, "devices = 0x%x\n", scp->devices);
832 if (bootverbose)
833 ata_printf(scp, -1, "devices = 0x%x\n", scp->devices);
881 if (!scp->devices) {
834
835 if (!mask)
882 goto failure;
836 goto failure;
883 }
837
884 TAILQ_INIT(&scp->ata_queue);
885 TAILQ_INIT(&scp->atapi_queue);
886 return 0;
887
888failure:
889 if (io)
890 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
891 if (altio)

--- 354 unchanged lines hidden (view full) ---

1246#endif
1247 scp->active = ATA_IDLE;
1248}
1249
1250void
1251ata_reset(struct ata_softc *scp, int32_t *mask)
1252{
1253 int32_t timeout;
838 TAILQ_INIT(&scp->ata_queue);
839 TAILQ_INIT(&scp->atapi_queue);
840 return 0;
841
842failure:
843 if (io)
844 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
845 if (altio)

--- 354 unchanged lines hidden (view full) ---

1200#endif
1201 scp->active = ATA_IDLE;
1202}
1203
1204void
1205ata_reset(struct ata_softc *scp, int32_t *mask)
1206{
1207 int32_t timeout;
1254 u_int8_t status0 = 0, status1 = 0;
1208 u_int8_t status0 = ATA_S_BUSY, status1 = ATA_S_BUSY;
1255
1256 /* reset channel */
1257 outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1258 DELAY(1);
1259 inb(scp->ioaddr + ATA_STATUS);
1260 outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
1261 DELAY(10000);
1262 outb(scp->altioaddr, ATA_A_IDS);
1263 DELAY(10000);
1264 inb(scp->ioaddr + ATA_ERROR);
1265 DELAY(3000);
1266
1267 /* wait for BUSY to go inactive */
1268 for (timeout = 0; timeout < 310000; timeout++) {
1209
1210 /* reset channel */
1211 outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1212 DELAY(1);
1213 inb(scp->ioaddr + ATA_STATUS);
1214 outb(scp->altioaddr, ATA_A_IDS | ATA_A_RESET);
1215 DELAY(10000);
1216 outb(scp->altioaddr, ATA_A_IDS);
1217 DELAY(10000);
1218 inb(scp->ioaddr + ATA_ERROR);
1219 DELAY(3000);
1220
1221 /* wait for BUSY to go inactive */
1222 for (timeout = 0; timeout < 310000; timeout++) {
1269 outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1270 DELAY(1);
1271 status0 = inb(scp->ioaddr + ATA_STATUS);
1272 outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1273 DELAY(1);
1274 status1 = inb(scp->ioaddr + ATA_STATUS);
1223 if (status0 & ATA_S_BUSY) {
1224 outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_MASTER);
1225 DELAY(1);
1226 status0 = inb(scp->ioaddr + ATA_STATUS);
1227 if (!(status0 & ATA_S_BUSY)) {
1228 /* check for ATAPI signature while its still there */
1229 if (inb(scp->ioaddr + ATA_CYL_LSB) == ATAPI_MAGIC_LSB &&
1230 inb(scp->ioaddr + ATA_CYL_MSB) == ATAPI_MAGIC_MSB)
1231 scp->devices |= ATA_ATAPI_MASTER;
1232 }
1233 }
1234 if (status1 & ATA_S_BUSY) {
1235 outb(scp->ioaddr + ATA_DRIVE, ATA_D_IBM | ATA_SLAVE);
1236 DELAY(1);
1237 status1 = inb(scp->ioaddr + ATA_STATUS);
1238 if (!(status1 & ATA_S_BUSY)) {
1239 /* check for ATAPI signature while its still there */
1240 if (inb(scp->ioaddr + ATA_CYL_LSB) == ATAPI_MAGIC_LSB &&
1241 inb(scp->ioaddr + ATA_CYL_MSB) == ATAPI_MAGIC_MSB)
1242 scp->devices |= ATA_ATAPI_SLAVE;
1243 }
1244 }
1275 if (*mask == 0x01) /* wait for master only */
1276 if (!(status0 & ATA_S_BUSY))
1277 break;
1278 if (*mask == 0x02) /* wait for slave only */
1279 if (!(status1 & ATA_S_BUSY))
1280 break;
1281 if (*mask == 0x03) /* wait for both master & slave */
1282 if (!(status0 & ATA_S_BUSY) && !(status1 & ATA_S_BUSY))

--- 4 unchanged lines hidden (view full) ---

1287 outb(scp->altioaddr, ATA_A_4BIT);
1288 if (status0 & ATA_S_BUSY)
1289 *mask &= ~0x01;
1290 if (status1 & ATA_S_BUSY)
1291 *mask &= ~0x02;
1292 if (bootverbose)
1293 ata_printf(scp, -1, "mask=%02x status0=%02x status1=%02x\n",
1294 *mask, status0, status1);
1245 if (*mask == 0x01) /* wait for master only */
1246 if (!(status0 & ATA_S_BUSY))
1247 break;
1248 if (*mask == 0x02) /* wait for slave only */
1249 if (!(status1 & ATA_S_BUSY))
1250 break;
1251 if (*mask == 0x03) /* wait for both master & slave */
1252 if (!(status0 & ATA_S_BUSY) && !(status1 & ATA_S_BUSY))

--- 4 unchanged lines hidden (view full) ---

1257 outb(scp->altioaddr, ATA_A_4BIT);
1258 if (status0 & ATA_S_BUSY)
1259 *mask &= ~0x01;
1260 if (status1 & ATA_S_BUSY)
1261 *mask &= ~0x02;
1262 if (bootverbose)
1263 ata_printf(scp, -1, "mask=%02x status0=%02x status1=%02x\n",
1264 *mask, status0, status1);
1265 if (!mask) {
1266 scp->devices = 0;
1267 return;
1268 }
1269 /*
1270 * OK, we have at least one device on the chain, checks for ATAPI
1271 * already done, if none check if its a good old ATA device.
1272 */
1273 if (status0 != 0x00 && !(scp->devices & ATA_ATAPI_MASTER)) {
1274 outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_MASTER));
1275 DELAY(1);
1276 outb(scp->ioaddr + ATA_ERROR, 0x58);
1277 outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
1278 if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
1279 inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
1280 scp->devices |= ATA_ATA_MASTER;
1281 }
1282 }
1283 if (status1 != 0x00 && !(scp->devices & ATA_ATAPI_SLAVE)) {
1284 outb(scp->ioaddr + ATA_DRIVE, (ATA_D_IBM | ATA_SLAVE));
1285 DELAY(1);
1286 outb(scp->ioaddr + ATA_ERROR, 0x58);
1287 outb(scp->ioaddr + ATA_CYL_LSB, 0xa5);
1288 if (inb(scp->ioaddr + ATA_ERROR) != 0x58 &&
1289 inb(scp->ioaddr + ATA_CYL_LSB) == 0xa5) {
1290 scp->devices |= ATA_ATA_SLAVE;
1291 }
1292 }
1295}
1296
1297int32_t
1298ata_reinit(struct ata_softc *scp)
1299{
1300 int32_t mask = 0, omask;
1301
1302 scp->active = ATA_REINITING;

--- 423 unchanged lines hidden ---
1293}
1294
1295int32_t
1296ata_reinit(struct ata_softc *scp)
1297{
1298 int32_t mask = 0, omask;
1299
1300 scp->active = ATA_REINITING;

--- 423 unchanged lines hidden ---