Deleted Added
full compact
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
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;
164 int rid;
165 u_long tmp;
164 int rid, len;
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);
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);
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),
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
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
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 */
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
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
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:
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:
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);
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;
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);
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;
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;
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);
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);
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 ---