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-dma.c 55333 2000-01-03 10:26:59Z sos $
29 */
30
31#include "pci.h"
32#include "apm.h"
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/buf.h>
36#include <sys/malloc.h>
--- 56 unchanged lines hidden (view full) ---
93 free(dmatab, M_DEVBUF);
94 return -1;
95 }
96 scp->dmatab[(device == ATA_MASTER) ? 0 : 1] = dmatab;
97
98 switch (scp->chiptype) {
99
100 case 0x71118086: /* Intel PIIX4 */
101 case 0x71998086: /* Intel PIIX4 */
102 if (udmamode >= 2) {
103 int32_t mask48, new48;
104
105 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
106 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
107 if (bootverbose)
108 printf("ata%d-%s: %s setting up UDMA2 mode on PIIX4 chip\n",
109 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
110 (error) ? "failed" : "success");
111 if (!error) {
112 mask48 = (1 << devno) + (3 << (16 + (devno << 2)));
113 new48 = (1 << devno) + (2 << (16 + (devno << 2)));
114 pci_write_config(scp->dev, 0x48,
115 (pci_read_config(scp->dev, 0x48, 4) &
116 ~mask48) | new48, 4);
117 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
118 return 0;
--- 19 unchanged lines hidden (view full) ---
138 }
139 new40 |= 0x40004000;
140 pci_write_config(scp->dev, 0x40, new40, 4);
141 pci_write_config(scp->dev, 0x44, new44, 4);
142 }
143 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
144 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
145 if (bootverbose)
146 printf("ata%d-%s: %s setting up WDMA2 mode on PIIX%s chip\n",
147 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
148 (error) ? "failed" : "success",
149 (scp->chiptype == 0x70108086) ? "3" : "4");
150 if (!error) {
151 if (device == ATA_MASTER) {
152 mask40 = 0x0000330f;
153 new40 = 0x00002307;
154 mask44 = 0;
155 new44 = 0;
156 }
157 else {
--- 88 unchanged lines hidden (view full) ---
246 return 0;
247 }
248 }
249 /* we could set PIO mode timings, but we assume the BIOS did that */
250 break;
251
252 case 0x05711106: /* VIA 82C571, 82C586, 82C596 & 82C686 */
253 case 0x74091022: /* AMD 756 */
254 /* UDMA4 mode only on 82C686 and AMD 756 */
255 if ((udmamode >= 4 && ata_find_dev(scp->dev, 0x06861106)) ||
256 (udmamode >= 4 && scp->chiptype == 0x74091022)) {
257 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
258 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
259 if (bootverbose)
260 printf("ata%d-%s: %s setting up UDMA4 mode on %s chip\n",
261 scp->lun, (device == ATA_MASTER) ? "master":"slave",
262 (error) ? "failed" : "success",
263 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
264 if (!error) {
265 pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1);
266 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
267 return 0;
268 }
269 }
270
271 /* UDMA2 mode only on 82C586 > rev1, 82C596, 82C686, AMD 756 */
272 if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) &&
273 pci_read_config(scp->dev, 0x08, 1) >= 0x01) ||
274 (udmamode >= 2 && ata_find_dev(scp->dev, 0x05961106)) ||
275 (udmamode >= 2 && ata_find_dev(scp->dev, 0x06861106)) ||
276 (udmamode >= 2 && scp->chiptype == 0x74091022)) {
277 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
278 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
279 if (bootverbose)
280 printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
281 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
282 (error) ? "failed" : "success",
283 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
284 if (!error) {
285 pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1);
286 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
287 return 0;
288 }
289 }
290 if (wdmamode >= 2 && apiomode >= 4) {
291 /* set WDMA2 mode timing */
292 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
293 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
294 if (bootverbose)
295 printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
296 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
297 (error) ? "failed" : "success",
298 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
299 if (!error) {
--- 367 unchanged lines hidden ---
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-dma.c 55333 2000-01-03 10:26:59Z sos $
29 */
30
31#include "pci.h"
32#include "apm.h"
33#include <sys/param.h>
34#include <sys/systm.h>
35#include <sys/buf.h>
36#include <sys/malloc.h>
--- 56 unchanged lines hidden (view full) ---
93 free(dmatab, M_DEVBUF);
94 return -1;
95 }
96 scp->dmatab[(device == ATA_MASTER) ? 0 : 1] = dmatab;
97
98 switch (scp->chiptype) {
99
100 case 0x71118086: /* Intel PIIX4 */
101 case 0x71998086: /* Intel PIIX4 */
102 if (udmamode >= 2) {
103 int32_t mask48, new48;
104
105 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
106 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
107 if (bootverbose)
108 printf("ata%d-%s: %s setting up UDMA2 mode on PIIX4 chip\n",
109 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
110 (error) ? "failed" : "success");
111 if (!error) {
112 mask48 = (1 << devno) + (3 << (16 + (devno << 2)));
113 new48 = (1 << devno) + (2 << (16 + (devno << 2)));
114 pci_write_config(scp->dev, 0x48,
115 (pci_read_config(scp->dev, 0x48, 4) &
116 ~mask48) | new48, 4);
117 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
118 return 0;
--- 19 unchanged lines hidden (view full) ---
138 }
139 new40 |= 0x40004000;
140 pci_write_config(scp->dev, 0x40, new40, 4);
141 pci_write_config(scp->dev, 0x44, new44, 4);
142 }
143 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
144 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
145 if (bootverbose)
146 printf("ata%d-%s: %s setting up WDMA2 mode on PIIX%s chip\n",
147 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
148 (error) ? "failed" : "success",
149 (scp->chiptype == 0x70108086) ? "3" : "4");
150 if (!error) {
151 if (device == ATA_MASTER) {
152 mask40 = 0x0000330f;
153 new40 = 0x00002307;
154 mask44 = 0;
155 new44 = 0;
156 }
157 else {
--- 88 unchanged lines hidden (view full) ---
246 return 0;
247 }
248 }
249 /* we could set PIO mode timings, but we assume the BIOS did that */
250 break;
251
252 case 0x05711106: /* VIA 82C571, 82C586, 82C596 & 82C686 */
253 case 0x74091022: /* AMD 756 */
254 /* UDMA4 mode only on 82C686 and AMD 756 */
255 if ((udmamode >= 4 && ata_find_dev(scp->dev, 0x06861106)) ||
256 (udmamode >= 4 && scp->chiptype == 0x74091022)) {
257 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
258 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
259 if (bootverbose)
260 printf("ata%d-%s: %s setting up UDMA4 mode on %s chip\n",
261 scp->lun, (device == ATA_MASTER) ? "master":"slave",
262 (error) ? "failed" : "success",
263 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
264 if (!error) {
265 pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1);
266 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
267 return 0;
268 }
269 }
270
271 /* UDMA2 mode only on 82C586 > rev1, 82C596, 82C686, AMD 756 */
272 if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) &&
273 pci_read_config(scp->dev, 0x08, 1) >= 0x01) ||
274 (udmamode >= 2 && ata_find_dev(scp->dev, 0x05961106)) ||
275 (udmamode >= 2 && ata_find_dev(scp->dev, 0x06861106)) ||
276 (udmamode >= 2 && scp->chiptype == 0x74091022)) {
277 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
278 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
279 if (bootverbose)
280 printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
281 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
282 (error) ? "failed" : "success",
283 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
284 if (!error) {
285 pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1);
286 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
287 return 0;
288 }
289 }
290 if (wdmamode >= 2 && apiomode >= 4) {
291 /* set WDMA2 mode timing */
292 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
293 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
294 if (bootverbose)
295 printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
296 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
297 (error) ? "failed" : "success",
298 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
299 if (!error) {
--- 367 unchanged lines hidden ---