Deleted Added
sdiff udiff text old ( 71335 ) new ( 72106 )
full compact
1/*-
2 * Copyright (c) 1998,1999,2000,2001 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-dma.c 72106 2001-02-06 16:44:25Z sos $
29 */
30
31#include "pci.h"
32#include <sys/param.h>
33#include <sys/systm.h>
34#include <sys/bio.h>
35#include <sys/malloc.h>
36#include <sys/bus.h>
37#include <sys/disk.h>
38#include <sys/devicestat.h>
39#include <vm/vm.h>
40#include <vm/pmap.h>
41#if NPCI > 0
42#include <pci/pcivar.h>
43#endif
44#include <machine/bus.h>
45#include <sys/rman.h>
46#include <dev/ata/ata-all.h>
47
48#if NPCI > 0
49
50/* prototypes */
51static void cyrix_timing(struct ata_softc *, int, int);
52static void promise_timing(struct ata_softc *, int, int);
53static void hpt_timing(struct ata_softc *, int, int);

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

80{
81 device_t parent = device_get_parent(scp->dev);
82 int devno = (scp->channel << 1) + ATA_DEV(device);
83 int error;
84
85 /* set our most pessimistic default mode */
86 scp->mode[ATA_DEV(device)] = ATA_PIO;
87
88 if (!scp->r_bmio)
89 return;
90
91 /* if simplex controller, only allow DMA on primary channel */
92 if (scp->channel == 1) {
93 ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
94 ATA_INB(scp->r_bmio, ATA_BMSTAT_PORT) &
95 (ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
96 if (ATA_INB(scp->r_bmio, ATA_BMSTAT_PORT) & ATA_BMSTAT_DMA_SIMPLEX) {
97 ata_printf(scp, device, "simplex device, DMA on primary only\n");
98 return;
99 }
100 }
101
102 /* DMA engine address alignment is usually 1 word (2 bytes) */
103 scp->alignment = 0x1;
104

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

820 /* better not try generic DMA on ATAPI devices it almost never works */
821 if ((device == ATA_MASTER && scp->devices & ATA_ATAPI_MASTER) ||
822 (device == ATA_SLAVE && scp->devices & ATA_ATAPI_SLAVE))
823 break;
824
825 /* if controller says its setup for DMA take the easy way out */
826 /* the downside is we dont know what DMA mode we are in */
827 if ((udmamode >= 0 || wdmamode > 1) &&
828 (ATA_INB(scp->r_bmio, ATA_BMSTAT_PORT) &
829 ((device==ATA_MASTER) ?
830 ATA_BMSTAT_DMA_MASTER : ATA_BMSTAT_DMA_SLAVE))) {
831 scp->mode[ATA_DEV(device)] = ATA_DMA;
832 return;
833 }
834
835 /* well, we have no support for this, but try anyways */
836 if ((wdmamode >= 2 && apiomode >= 4) && scp->r_bmio) {
837 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
838 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
839 if (bootverbose)
840 ata_printf(scp, device,
841 "%s setting WDMA2 on generic chip\n",
842 (error) ? "failed" : "success");
843 if (!error) {
844 scp->mode[ATA_DEV(device)] = ATA_WDMA2;

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

900 return 0;
901}
902
903void
904ata_dmastart(struct ata_softc *scp, int device,
905 struct ata_dmaentry *dmatab, int dir)
906{
907 scp->flags |= ATA_DMA_ACTIVE;
908 ATA_OUTL(scp->r_bmio, ATA_BMDTP_PORT, vtophys(dmatab));
909 ATA_OUTB(scp->r_bmio, ATA_BMCMD_PORT, dir ? ATA_BMCMD_WRITE_READ : 0);
910 ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
911 (ATA_INB(scp->r_bmio, ATA_BMSTAT_PORT) |
912 (ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR)));
913 ATA_OUTB(scp->r_bmio, ATA_BMCMD_PORT,
914 ATA_INB(scp->r_bmio, ATA_BMCMD_PORT) | ATA_BMCMD_START_STOP);
915}
916
917int
918ata_dmadone(struct ata_softc *scp)
919{
920 int error;
921
922 ATA_OUTB(scp->r_bmio, ATA_BMCMD_PORT,
923 ATA_INB(scp->r_bmio, ATA_BMCMD_PORT) & ~ATA_BMCMD_START_STOP);
924 scp->flags &= ~ATA_DMA_ACTIVE;
925 error = ATA_INB(scp->r_bmio, ATA_BMSTAT_PORT);
926 ATA_OUTB(scp->r_bmio, ATA_BMSTAT_PORT,
927 error | ATA_BMSTAT_INTERRUPT | ATA_BMSTAT_ERROR);
928 return error & ATA_BMSTAT_MASK;
929}
930
931int
932ata_dmastatus(struct ata_softc *scp)
933{
934 return ATA_INB(scp->r_bmio, ATA_BMSTAT_PORT) & ATA_BMSTAT_MASK;
935}
936
937static void
938cyrix_timing(struct ata_softc *scp, int devno, int mode)
939{
940 u_int32_t reg20 = 0x0000e132;
941 u_int32_t reg24 = 0x00017771;
942
943 switch (mode) {
944 case ATA_PIO0: reg20 = 0x0000e132; break;
945 case ATA_PIO1: reg20 = 0x00018121; break;
946 case ATA_PIO2: reg20 = 0x00024020; break;
947 case ATA_PIO3: reg20 = 0x00032010; break;
948 case ATA_PIO4: reg20 = 0x00040010; break;
949 case ATA_WDMA2: reg24 = 0x00002020; break;
950 case ATA_UDMA2: reg24 = 0x00911030; break;
951 }
952 ATA_OUTL(scp->r_bmio, (devno << 3) + 0x20, reg20);
953 ATA_OUTL(scp->r_bmio, (devno << 3) + 0x24, reg24);
954}
955
956static void
957promise_timing(struct ata_softc *scp, int devno, int mode)
958{
959 u_int32_t timing = 0;
960 struct promise_timing {
961 u_int8_t pa:4;

--- 161 unchanged lines hidden ---