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 56138 2000-01-17 02:04:19Z 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 PIIX4e */
102 case 0x24118086: /* Intel ICH */
103 case 0x24218086: /* Intel ICH0 */
104 if (udmamode >= 2) {
105 int32_t mask48, new48;
106
107 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
108 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
109 if (bootverbose)
110 printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
111 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
112 (error) ? "failed" : "success",
113 (scp->chiptype == 0x24118086) ? "ICH" :
114 (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
115 if (!error) {
116 mask48 = (1 << devno) + (3 << (16 + (devno << 2)));
117 new48 = (1 << devno) + (2 << (16 + (devno << 2)));
118 pci_write_config(scp->dev, 0x48,
119 (pci_read_config(scp->dev, 0x48, 4) &
120 ~mask48) | new48, 4);
121 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
122 return 0;
--- 19 unchanged lines hidden (view full) ---
142 }
143 new40 |= 0x40004000;
144 pci_write_config(scp->dev, 0x40, new40, 4);
145 pci_write_config(scp->dev, 0x44, new44, 4);
146 }
147 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
148 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
149 if (bootverbose)
150 printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
151 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
152 (error) ? "failed" : "success",
153 (scp->chiptype == 0x70108086) ? "PIIX3" :
154 (scp->chiptype == 0x24118086) ? "ICH" :
155 (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
156 if (!error) {
157 if (device == ATA_MASTER) {
158 mask40 = 0x0000330f;
159 new40 = 0x00002307;
160 mask44 = 0;
161 new44 = 0;
162 }
163 else {
--- 88 unchanged lines hidden (view full) ---
252 return 0;
253 }
254 }
255 /* we could set PIO mode timings, but we assume the BIOS did that */
256 break;
257
258 case 0x05711106: /* VIA 82C571, 82C586, 82C596 & 82C686 */
259 case 0x74091022: /* AMD 756 */
260 /* UDMA modes on 82C686 */
261 if (ata_find_dev(scp->dev, 0x06861106)) {
262 if (udmamode >= 4) {
263 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
264 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
265 if (bootverbose)
266 printf("ata%d-%s: %s setting up UDMA4 mode on VIA chip\n",
267 scp->lun, (device == ATA_MASTER) ? "master":"slave",
268 (error) ? "failed" : "success");
269 if (!error) {
270 pci_write_config(scp->dev, 0x53 - devno, 0xe8, 1);
271 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
272 return 0;
273 }
274 }
275 if (udmamode >= 2) {
276 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
277 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
278 if (bootverbose)
279 printf("ata%d-%s: %s setting up UDMA2 mode on VIA chip\n",
280 scp->lun, (device == ATA_MASTER) ? "master":"slave",
281 (error) ? "failed" : "success");
282 if (!error) {
283 pci_write_config(scp->dev, 0x53 - devno, 0xea, 1);
284 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
285 return 0;
286 }
287 }
288 }
289
290 /* UDMA4 mode on AMD 756 */
291 if (udmamode >= 4 && scp->chiptype == 0x74091022) {
292 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
293 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
294 if (bootverbose)
295 printf("ata%d-%s: %s setting up UDMA4 mode on AMD chip\n",
296 scp->lun, (device == ATA_MASTER) ? "master":"slave",
297 (error) ? "failed" : "success");
298 if (!error) {
299 pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1);
300 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
301 return 0;
302 }
303 }
304
305 /* UDMA2 mode only on 82C586 > rev1, 82C596, AMD 756 */
306 if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) &&
307 pci_read_config(scp->dev, 0x08, 1) >= 0x01) ||
308 (udmamode >= 2 && ata_find_dev(scp->dev, 0x05961106)) ||
309 (udmamode >= 2 && scp->chiptype == 0x74091022)) {
310 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
311 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
312 if (bootverbose)
313 printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
314 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
315 (error) ? "failed" : "success",
316 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
317 if (!error) {
318 pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1);
319 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
320 return 0;
321 }
322 }
323 if (wdmamode >= 2 && apiomode >= 4) {
324 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
325 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
326 if (bootverbose)
327 printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
328 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
329 (error) ? "failed" : "success",
330 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
331 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 56138 2000-01-17 02:04:19Z 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 PIIX4e */
102 case 0x24118086: /* Intel ICH */
103 case 0x24218086: /* Intel ICH0 */
104 if (udmamode >= 2) {
105 int32_t mask48, new48;
106
107 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
108 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
109 if (bootverbose)
110 printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
111 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
112 (error) ? "failed" : "success",
113 (scp->chiptype == 0x24118086) ? "ICH" :
114 (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
115 if (!error) {
116 mask48 = (1 << devno) + (3 << (16 + (devno << 2)));
117 new48 = (1 << devno) + (2 << (16 + (devno << 2)));
118 pci_write_config(scp->dev, 0x48,
119 (pci_read_config(scp->dev, 0x48, 4) &
120 ~mask48) | new48, 4);
121 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
122 return 0;
--- 19 unchanged lines hidden (view full) ---
142 }
143 new40 |= 0x40004000;
144 pci_write_config(scp->dev, 0x40, new40, 4);
145 pci_write_config(scp->dev, 0x44, new44, 4);
146 }
147 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
148 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
149 if (bootverbose)
150 printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
151 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
152 (error) ? "failed" : "success",
153 (scp->chiptype == 0x70108086) ? "PIIX3" :
154 (scp->chiptype == 0x24118086) ? "ICH" :
155 (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
156 if (!error) {
157 if (device == ATA_MASTER) {
158 mask40 = 0x0000330f;
159 new40 = 0x00002307;
160 mask44 = 0;
161 new44 = 0;
162 }
163 else {
--- 88 unchanged lines hidden (view full) ---
252 return 0;
253 }
254 }
255 /* we could set PIO mode timings, but we assume the BIOS did that */
256 break;
257
258 case 0x05711106: /* VIA 82C571, 82C586, 82C596 & 82C686 */
259 case 0x74091022: /* AMD 756 */
260 /* UDMA modes on 82C686 */
261 if (ata_find_dev(scp->dev, 0x06861106)) {
262 if (udmamode >= 4) {
263 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
264 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
265 if (bootverbose)
266 printf("ata%d-%s: %s setting up UDMA4 mode on VIA chip\n",
267 scp->lun, (device == ATA_MASTER) ? "master":"slave",
268 (error) ? "failed" : "success");
269 if (!error) {
270 pci_write_config(scp->dev, 0x53 - devno, 0xe8, 1);
271 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
272 return 0;
273 }
274 }
275 if (udmamode >= 2) {
276 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
277 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
278 if (bootverbose)
279 printf("ata%d-%s: %s setting up UDMA2 mode on VIA chip\n",
280 scp->lun, (device == ATA_MASTER) ? "master":"slave",
281 (error) ? "failed" : "success");
282 if (!error) {
283 pci_write_config(scp->dev, 0x53 - devno, 0xea, 1);
284 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
285 return 0;
286 }
287 }
288 }
289
290 /* UDMA4 mode on AMD 756 */
291 if (udmamode >= 4 && scp->chiptype == 0x74091022) {
292 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
293 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
294 if (bootverbose)
295 printf("ata%d-%s: %s setting up UDMA4 mode on AMD chip\n",
296 scp->lun, (device == ATA_MASTER) ? "master":"slave",
297 (error) ? "failed" : "success");
298 if (!error) {
299 pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1);
300 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA4;
301 return 0;
302 }
303 }
304
305 /* UDMA2 mode only on 82C586 > rev1, 82C596, AMD 756 */
306 if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) &&
307 pci_read_config(scp->dev, 0x08, 1) >= 0x01) ||
308 (udmamode >= 2 && ata_find_dev(scp->dev, 0x05961106)) ||
309 (udmamode >= 2 && scp->chiptype == 0x74091022)) {
310 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
311 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
312 if (bootverbose)
313 printf("ata%d-%s: %s setting up UDMA2 mode on %s chip\n",
314 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
315 (error) ? "failed" : "success",
316 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
317 if (!error) {
318 pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1);
319 scp->mode[(device == ATA_MASTER) ? 0 : 1] = ATA_UDMA2;
320 return 0;
321 }
322 }
323 if (wdmamode >= 2 && apiomode >= 4) {
324 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
325 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
326 if (bootverbose)
327 printf("ata%d-%s: %s setting up WDMA2 mode on %s chip\n",
328 scp->lun, (device == ATA_MASTER) ? "master" : "slave",
329 (error) ? "failed" : "success",
330 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
331 if (!error) {
--- 367 unchanged lines hidden ---