Deleted Added
full compact
ata-all.c (57325) ata-all.c (57477)
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 57325 2000-02-18 20:57:33Z sos $
28 * $FreeBSD: head/sys/dev/ata/ata-all.c 57477 2000-02-25 09:48:23Z 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"

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

70#endif
71#include <dev/ata/ata-all.h>
72#include <dev/ata/ata-disk.h>
73#include <dev/ata/atapi-all.h>
74
75/* misc defines */
76#define IOMASK 0xfffffffc
77#define ATA_IOADDR_RID 0
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"

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

70#endif
71#include <dev/ata/ata-all.h>
72#include <dev/ata/ata-disk.h>
73#include <dev/ata/atapi-all.h>
74
75/* misc defines */
76#define IOMASK 0xfffffffc
77#define ATA_IOADDR_RID 0
78#define ATA_ALTIOADDR_RID 1
78#define ATA_ALTADDR_RID 1
79#define ATA_BMADDR_RID 2
80
81/* prototypes */
82static int ata_probe(device_t);
83static int ata_attach(device_t);
84static int ata_detach(device_t);
85static int ata_resume(device_t);
86static void ata_boot_attach(void);

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

156#endif
157
158#if NCARD > 0
159static int
160ata_pccard_probe(device_t dev)
161{
162 struct ata_softc *scp = device_get_softc(dev);
163 struct resource *port;
79#define ATA_BMADDR_RID 2
80
81/* prototypes */
82static int ata_probe(device_t);
83static int ata_attach(device_t);
84static int ata_detach(device_t);
85static int ata_resume(device_t);
86static void ata_boot_attach(void);

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

156#endif
157
158#if NCARD > 0
159static int
160ata_pccard_probe(device_t dev)
161{
162 struct ata_softc *scp = device_get_softc(dev);
163 struct resource *port;
164 int rid;
165 u_long tmp;
164 int rid, len;
166
167 /* allocate the port range */
168 rid = ATA_IOADDR_RID;
165
166 /* allocate the port range */
167 rid = ATA_IOADDR_RID;
169 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
170 ATA_IOSIZE, RF_ACTIVE);
168 len = bus_get_resource_count(dev, SYS_RES_IOPORT, rid);
169 port = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, len, RF_ACTIVE);
171 if (!port)
172 return ENOMEM;
173
170 if (!port)
171 return ENOMEM;
172
174 /* alloctate the altport range */
175 if (bus_get_resource(dev, SYS_RES_IOPORT, 1, &tmp, &tmp)) {
176 bus_set_resource(dev, SYS_RES_IOPORT, 1,
177 rman_get_start(port) + ATA_ALTPORT_PCCARD,
178 ATA_ALTIOSIZE);
173 /*
174 * if we got more than the default ATA_IOSIZE ports, this is likely
175 * a pccard system where the altio ports are located just after the
176 * normal io ports, so no need to allocate them.
177 */
178 if (len <= ATA_IOSIZE) {
179 bus_set_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,
180 rman_get_start(port) + ATA_ALTPORT, ATA_ALTIOSIZE);
179 }
180 bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
181 scp->unit = device_get_unit(dev);
182 scp->flags |= ATA_USE_16BIT;
183 return ata_probe(dev);
184}
185
186static device_method_t ata_pccard_methods[] = {
187 /* device interface */
188 DEVMETHOD(device_probe, ata_pccard_probe),
189 DEVMETHOD(device_attach, ata_attach),
190 DEVMETHOD(device_detach, ata_detach),
181 }
182 bus_release_resource(dev, SYS_RES_IOPORT, 0, port);
183 scp->unit = device_get_unit(dev);
184 scp->flags |= ATA_USE_16BIT;
185 return ata_probe(dev);
186}
187
188static device_method_t ata_pccard_methods[] = {
189 /* device interface */
190 DEVMETHOD(device_probe, ata_pccard_probe),
191 DEVMETHOD(device_attach, ata_attach),
192 DEVMETHOD(device_detach, ata_detach),
191 DEVMETHOD(device_resume, ata_resume),
192 { 0, 0 }
193};
194
195static driver_t ata_pccard_driver = {
196 "ata",
197 ata_pccard_methods,
198 sizeof(struct ata_softc),
199};

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

271 return "VIA Apollo ATA controller";
272
273 case 0x55131039:
274 return "SiS 5591 ATA33 controller";
275
276 case 0x06461095:
277 return "CMD 646 ATA controller";
278
193 { 0, 0 }
194};
195
196static driver_t ata_pccard_driver = {
197 "ata",
198 ata_pccard_methods,
199 sizeof(struct ata_softc),
200};

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

272 return "VIA Apollo ATA controller";
273
274 case 0x55131039:
275 return "SiS 5591 ATA33 controller";
276
277 case 0x06461095:
278 return "CMD 646 ATA controller";
279
280 case 0xc6931080:
281 if (pci_get_subclass(dev) == PCIS_STORAGE_IDE)
282 return "Cypress 82C693 ATA controller";
283 break;
284
279 case 0x74091022:
280 return "AMD 756 ATA66 controller";
281
282 case 0x4d33105a:
283 return "Promise ATA33 controller";
284
285 case 0x4d38105a:
286 return "Promise ATA66 controller";

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

291 /* unsupported but known chipsets, generic DMA only */
292 case 0x10001042:
293 case 0x10011042:
294 return "RZ 100? ATA controller !WARNING! buggy chip data loss possible";
295
296 case 0x06401095:
297 return "CMD 640 ATA controller !WARNING! buggy chip data loss possible";
298
285 case 0x74091022:
286 return "AMD 756 ATA66 controller";
287
288 case 0x4d33105a:
289 return "Promise ATA33 controller";
290
291 case 0x4d38105a:
292 return "Promise ATA66 controller";

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

297 /* unsupported but known chipsets, generic DMA only */
298 case 0x10001042:
299 case 0x10011042:
300 return "RZ 100? ATA controller !WARNING! buggy chip data loss possible";
301
302 case 0x06401095:
303 return "CMD 640 ATA controller !WARNING! buggy chip data loss possible";
304
299 case 0xc6931080:
300 if (pci_get_subclass(dev) == PCIS_STORAGE_IDE)
301 return "Cypress 82C693 ATA controller (generic mode)";
302 break;
303
304 case 0x01021078:
305 return "Cyrix 5530 ATA controller (generic mode)";
306
307 /* unknown chipsets, try generic DMA if it seems possible */
308 default:
309 if (pci_get_class(dev) == PCIC_STORAGE &&
310 (pci_get_subclass(dev) == PCIS_STORAGE_IDE))
311 return "Unknown PCI ATA controller (generic mode)";

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

325 else
326 return ENXIO;
327}
328
329static int
330ata_pci_add_child(device_t dev, int unit)
331{
332 device_t child;
305 case 0x01021078:
306 return "Cyrix 5530 ATA controller (generic mode)";
307
308 /* unknown chipsets, try generic DMA if it seems possible */
309 default:
310 if (pci_get_class(dev) == PCIC_STORAGE &&
311 (pci_get_subclass(dev) == PCIS_STORAGE_IDE))
312 return "Unknown PCI ATA controller (generic mode)";

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

326 else
327 return ENXIO;
328}
329
330static int
331ata_pci_add_child(device_t dev, int unit)
332{
333 device_t child;
333 int lun;
334
335 /* check if this is located at one of the std addresses */
334
335 /* check if this is located at one of the std addresses */
336 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV)
337 lun = unit;
338 else
339 lun = -1;
340
341 if (!(child = device_add_child(dev, "ata", lun)))
342 return ENOMEM;
343
336 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
337 if (!(child = device_add_child(dev, "ata", unit)))
338 return ENOMEM;
339 }
340 else {
341 if (!(child = device_add_child(dev, "ata", 2)))
342 return ENOMEM;
343 }
344 device_set_ivars(child, (void *)(uintptr_t) unit);
345 return 0;
346}
347
348static int
349ata_pci_attach(device_t dev)
350{
351 struct ata_pci_softc *sc = device_get_softc(dev);

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

431 /* prepare for ATA-66 on the 82C686 */
432 if (ata_find_dev(dev, 0x06861106)) {
433 pci_write_config(dev, 0x50,
434 pci_read_config(dev, 0x50, 4) | 0x070f070f, 4);
435 }
436 break;
437 }
438
344 device_set_ivars(child, (void *)(uintptr_t) unit);
345 return 0;
346}
347
348static int
349ata_pci_attach(device_t dev)
350{
351 struct ata_pci_softc *sc = device_get_softc(dev);

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

431 /* prepare for ATA-66 on the 82C686 */
432 if (ata_find_dev(dev, 0x06861106)) {
433 pci_write_config(dev, 0x50,
434 pci_read_config(dev, 0x50, 4) | 0x070f070f, 4);
435 }
436 break;
437 }
438
439 /*
440 * the Cypress chip is a mess, it contains two ATA functions, but
441 * both channels are visible on the first one.
442 * simply ignore the second function for now, as the right
443 * solution (ignoring the second channel on the first function)
444 * doesn't work with the crappy ATA interrupt setup on the alpha.
445 */
446 if (pci_get_devid(dev) == 0xc6931080 && pci_get_function(dev) > 1)
447 return 0;
448
439 ata_pci_add_child(dev, 0);
440
441 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV ||
442 pci_read_config(dev, 0x18, 4) & IOMASK)
443 ata_pci_add_child(dev, 1);
444
445 return bus_generic_attach(dev);
446}

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

480 start = (unit == 0 ? IO_WD1 : IO_WD2);
481 end = start + ATA_IOSIZE - 1;
482 count = ATA_IOSIZE;
483 }
484 else
485 myrid = 0x10 + 8 * unit;
486 break;
487
449 ata_pci_add_child(dev, 0);
450
451 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV ||
452 pci_read_config(dev, 0x18, 4) & IOMASK)
453 ata_pci_add_child(dev, 1);
454
455 return bus_generic_attach(dev);
456}

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

490 start = (unit == 0 ? IO_WD1 : IO_WD2);
491 end = start + ATA_IOSIZE - 1;
492 count = ATA_IOSIZE;
493 }
494 else
495 myrid = 0x10 + 8 * unit;
496 break;
497
488 case ATA_ALTIOADDR_RID:
498 case ATA_ALTADDR_RID:
489 if (masterdev) {
490 myrid = 0;
491 start = (unit == 0 ? IO_WD1 : IO_WD2) + ATA_ALTPORT;
492 end = start + ATA_ALTIOSIZE - 1;
493 count = ATA_ALTIOSIZE;
494 }
495 else
496 myrid = 0x14 + 8 * unit;

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

567 switch (rid) {
568 case ATA_IOADDR_RID:
569 if (masterdev)
570 myrid = 0;
571 else
572 myrid = 0x10 + 8 * unit;
573 break;
574
499 if (masterdev) {
500 myrid = 0;
501 start = (unit == 0 ? IO_WD1 : IO_WD2) + ATA_ALTPORT;
502 end = start + ATA_ALTIOSIZE - 1;
503 count = ATA_ALTIOSIZE;
504 }
505 else
506 myrid = 0x14 + 8 * unit;

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

577 switch (rid) {
578 case ATA_IOADDR_RID:
579 if (masterdev)
580 myrid = 0;
581 else
582 myrid = 0x10 + 8 * unit;
583 break;
584
575 case ATA_ALTIOADDR_RID:
585 case ATA_ALTADDR_RID:
576 if (masterdev)
577 myrid = 0;
578 else
579 myrid = 0x14 + 8 * unit;
580 break;
581
582 case ATA_BMADDR_RID:
583 return 0;

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

732 return ENXIO;
733
734 /* initialize the softc basics */
735 scp->active = ATA_IDLE;
736 scp->dev = dev;
737 scp->devices = 0;
738
739 rid = ATA_IOADDR_RID;
586 if (masterdev)
587 myrid = 0;
588 else
589 myrid = 0x14 + 8 * unit;
590 break;
591
592 case ATA_BMADDR_RID:
593 return 0;

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

742 return ENXIO;
743
744 /* initialize the softc basics */
745 scp->active = ATA_IDLE;
746 scp->dev = dev;
747 scp->devices = 0;
748
749 rid = ATA_IOADDR_RID;
740 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
750 io = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
751 ATA_IOSIZE, RF_ACTIVE);
741 if (!io)
742 goto failure;
743 ioaddr = rman_get_start(io);
744
752 if (!io)
753 goto failure;
754 ioaddr = rman_get_start(io);
755
745 rid = ATA_ALTIOADDR_RID;
746 altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
747 if (!altio)
748 goto failure;
749 altioaddr = rman_get_start(altio);
756 rid = ATA_ALTADDR_RID;
757 altio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0,
758 ATA_ALTIOSIZE, RF_ACTIVE);
759 if (altio)
760 altioaddr = rman_get_start(altio);
761 else
762 altioaddr = ioaddr + ATA_IOSIZE;
750
751 rid = ATA_BMADDR_RID;
752 bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
753 bmaddr = bmio ? rman_get_start(bmio) : 0;
754
755 /* store the IO resources for eventual later release */
756 scp->r_io = io;
757 scp->r_altio = altio;

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

831 TAILQ_INIT(&scp->ata_queue);
832 TAILQ_INIT(&scp->atapi_queue);
833 return 0;
834
835failure:
836 if (io)
837 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
838 if (altio)
763
764 rid = ATA_BMADDR_RID;
765 bmio = bus_alloc_resource(dev, SYS_RES_IOPORT, &rid, 0, ~0, 1, RF_ACTIVE);
766 bmaddr = bmio ? rman_get_start(bmio) : 0;
767
768 /* store the IO resources for eventual later release */
769 scp->r_io = io;
770 scp->r_altio = altio;

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

844 TAILQ_INIT(&scp->ata_queue);
845 TAILQ_INIT(&scp->atapi_queue);
846 return 0;
847
848failure:
849 if (io)
850 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, io);
851 if (altio)
839 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTIOADDR_RID, altio);
852 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID, altio);
840 if (bmio)
841 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, bmio);
842 if (bootverbose)
843 ata_printf(scp, -1, "probe allocation failed\n");
844 return ENXIO;
845}
846
847static int
848ata_attach(device_t dev)
849{
850 struct ata_softc *scp = device_get_softc(dev);
853 if (bmio)
854 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, bmio);
855 if (bootverbose)
856 ata_printf(scp, -1, "probe allocation failed\n");
857 return ENXIO;
858}
859
860static int
861ata_attach(device_t dev)
862{
863 struct ata_softc *scp = device_get_softc(dev);
851 int rid = 0;
852 void *ih;
864 int error, rid = 0;
853
854 if (!scp || scp->flags & ATA_ATTACHED)
855 return ENXIO;
856
857 scp->r_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
858 RF_SHAREABLE | RF_ACTIVE);
859 if (!scp->r_irq) {
860 ata_printf(scp, -1, "unable to allocate interrupt\n");
861 return ENXIO;
862 }
865
866 if (!scp || scp->flags & ATA_ATTACHED)
867 return ENXIO;
868
869 scp->r_irq = bus_alloc_resource(dev, SYS_RES_IRQ, &rid, 0, ~0, 1,
870 RF_SHAREABLE | RF_ACTIVE);
871 if (!scp->r_irq) {
872 ata_printf(scp, -1, "unable to allocate interrupt\n");
873 return ENXIO;
874 }
863 bus_setup_intr(dev, scp->r_irq, INTR_TYPE_BIO, ata_intr, scp, &ih);
875 if ((error = bus_setup_intr(dev, scp->r_irq, INTR_TYPE_BIO, ata_intr,
876 scp, &scp->ih)))
877 return error;
864
865 /*
866 * do not attach devices if we are in early boot, this is done later
867 * when interrupts are enabled by a hook into the boot process.
868 * otherwise attach what the probe has found in scp->devices.
869 */
870 if (!ata_delayed_attach) {
871 if (scp->devices & ATA_ATA_SLAVE)

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

922 scp->dev_param[ATA_DEV(ATA_MASTER)] = NULL;
923 }
924 if (scp->dev_param[ATA_DEV(ATA_SLAVE)]) {
925 free(scp->dev_param[ATA_DEV(ATA_SLAVE)], M_ATA);
926 scp->dev_param[ATA_DEV(ATA_SLAVE)] = NULL;
927 }
928 scp->mode[ATA_DEV(ATA_MASTER)] = ATA_PIO;
929 scp->mode[ATA_DEV(ATA_SLAVE)] = ATA_PIO;
878
879 /*
880 * do not attach devices if we are in early boot, this is done later
881 * when interrupts are enabled by a hook into the boot process.
882 * otherwise attach what the probe has found in scp->devices.
883 */
884 if (!ata_delayed_attach) {
885 if (scp->devices & ATA_ATA_SLAVE)

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

936 scp->dev_param[ATA_DEV(ATA_MASTER)] = NULL;
937 }
938 if (scp->dev_param[ATA_DEV(ATA_SLAVE)]) {
939 free(scp->dev_param[ATA_DEV(ATA_SLAVE)], M_ATA);
940 scp->dev_param[ATA_DEV(ATA_SLAVE)] = NULL;
941 }
942 scp->mode[ATA_DEV(ATA_MASTER)] = ATA_PIO;
943 scp->mode[ATA_DEV(ATA_SLAVE)] = ATA_PIO;
944 bus_teardown_intr(dev, scp->r_irq, scp->ih);
930 bus_release_resource(dev, SYS_RES_IRQ, 0, scp->r_irq);
945 bus_release_resource(dev, SYS_RES_IRQ, 0, scp->r_irq);
931 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio);
932 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTIOADDR_RID, scp->r_altio);
946 if (scp->r_bmio)
947 bus_release_resource(dev, SYS_RES_IOPORT, ATA_BMADDR_RID, scp->r_bmio);
948 if (scp->r_altio)
949 bus_release_resource(dev, SYS_RES_IOPORT, ATA_ALTADDR_RID,scp->r_altio);
933 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io);
934 scp->flags &= ~ATA_ATTACHED;
935 return 0;
936}
937
938static int
939ata_resume(device_t dev)
940{

--- 743 unchanged lines hidden ---
950 bus_release_resource(dev, SYS_RES_IOPORT, ATA_IOADDR_RID, scp->r_io);
951 scp->flags &= ~ATA_ATTACHED;
952 return 0;
953}
954
955static int
956ata_resume(device_t dev)
957{

--- 743 unchanged lines hidden ---