Deleted Added
sdiff udiff text old ( 56686 ) new ( 56744 )
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-dma.c 56686 2000-01-27 19:00:51Z 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>

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

55/* misc defines */
56#ifdef __alpha__
57#undef vtophys
58#define vtophys(va) alpha_XXX_dmamap((vm_offset_t)va)
59#endif
60
61#if NPCI > 0
62
63int32_t
64ata_dmainit(struct ata_softc *scp, int32_t device,
65 int32_t apiomode, int32_t wdmamode, int32_t udmamode)
66{
67 int32_t devno = (scp->unit << 1) + ATA_DEV(device);
68 int32_t error;
69
70 if (!scp->bmaddr)
71 return -1;
72
73 /* if simplex controller, only allow DMA on primary channel */
74 if (scp->unit == 1) {
75 outb(scp->bmaddr + ATA_BMSTAT_PORT, inb(scp->bmaddr + ATA_BMSTAT_PORT) &
76 (ATA_BMSTAT_DMA_MASTER | ATA_BMSTAT_DMA_SLAVE));
77 if (inb(scp->bmaddr + ATA_BMSTAT_PORT) & ATA_BMSTAT_DMA_SIMPLEX) {
78 ata_printf(scp, device, "simplex device, DMA on primary only\n");
79 return -1;
80 }
81 }
82
83 if (!scp->dmatab[ATA_DEV(device)]) {
84 void *dmatab;
85
86 if (!(dmatab = malloc(PAGE_SIZE, M_DEVBUF, M_NOWAIT)))
87 return -1;
88 if (((uintptr_t)dmatab >> PAGE_SHIFT) ^
89 (((uintptr_t)dmatab + PAGE_SIZE - 1) >> PAGE_SHIFT)) {
90 ata_printf(scp, device, "dmatab crosses page boundary, no DMA\n");
91 free(dmatab, M_DEVBUF);
92 return -1;
93 }
94 scp->dmatab[ATA_DEV(device)] = dmatab;
95 }
96
97 switch (scp->chiptype) {
98
99 case 0x71118086: /* Intel PIIX4 */
100 case 0x71998086: /* Intel PIIX4e */

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

112 (scp->chiptype == 0x24218086) ? "ICH0" :"PIIX4");
113 if (!error) {
114 mask48 = (1 << devno) + (3 << (16 + (devno << 2)));
115 new48 = (1 << devno) + (2 << (16 + (devno << 2)));
116 pci_write_config(scp->dev, 0x48,
117 (pci_read_config(scp->dev, 0x48, 4) &
118 ~mask48) | new48, 4);
119 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
120 return 0;
121 }
122 }
123 /* FALLTHROUGH */
124
125 case 0x70108086: /* Intel PIIX3 */
126 if (wdmamode >= 2 && apiomode >= 4) {
127 int32_t mask40, new40, mask44, new44;
128

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

171 }
172 pci_write_config(scp->dev, 0x40,
173 (pci_read_config(scp->dev, 0x40, 4) & ~mask40)|
174 new40, 4);
175 pci_write_config(scp->dev, 0x44,
176 (pci_read_config(scp->dev, 0x44, 4) & ~mask44)|
177 new44, 4);
178 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
179 return 0;
180 }
181 }
182 /* we could set PIO mode timings, but we assume the BIOS did that */
183 break;
184
185 case 0x12308086: /* Intel PIIX */
186 if (wdmamode >= 2 && apiomode >= 4) {
187 int32_t word40;

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

197 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
198 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
199 if (bootverbose)
200 ata_printf(scp, device,
201 "%s setting up WDMA2 mode on PIIX chip\n",
202 (error) ? "failed" : "success");
203 if (!error) {
204 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
205 return 0;
206 }
207 }
208 break;
209
210 case 0x522910b9: /* AcerLabs Aladdin IV/V */
211 /* the Aladdin doesn't support ATAPI DMA on both master & slave */
212 if (scp->devices & ATA_ATAPI_MASTER && scp->devices & ATA_ATAPI_SLAVE) {
213 ata_printf(scp, device,

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

226 if (!error) {
227 word54 |= 0x5555;
228 word54 |= (0x0a << (16 + (scp->unit << 3) + (device << 2)));
229 pci_write_config(scp->dev, 0x54, word54, 4);
230 pci_write_config(scp->dev, 0x53,
231 pci_read_config(scp->dev, 0x53, 1) | 0x03, 1);
232 scp->flags |= ATA_ATAPI_DMA_RO;
233 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
234 return 0;
235 }
236 }
237 if (wdmamode >= 2 && apiomode >= 4) {
238 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
239 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
240 if (bootverbose)
241 ata_printf(scp, device,
242 "%s setting up WDMA2 mode on Aladdin chip\n",
243 (error) ? "failed" : "success");
244 if (!error) {
245 pci_write_config(scp->dev, 0x53,
246 pci_read_config(scp->dev, 0x53, 1) | 0x03, 1);
247 scp->flags |= ATA_ATAPI_DMA_RO;
248 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
249 return 0;
250 }
251 }
252 /* we could set PIO mode timings, but we assume the BIOS did that */
253 break;
254
255 case 0x05711106: /* VIA 82C571, 82C586, 82C596 & 82C686 */
256 case 0x74091022: /* AMD 756 */
257 /* UDMA modes on 82C686 */
258 if (ata_find_dev(scp->dev, 0x06861106)) {
259 if (udmamode >= 4) {
260 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
261 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
262 if (bootverbose)
263 ata_printf(scp, device,
264 "%s setting up UDMA4 mode on VIA chip\n",
265 (error) ? "failed" : "success");
266 if (!error) {
267 pci_write_config(scp->dev, 0x53 - devno, 0xe8, 1);
268 scp->mode[ATA_DEV(device)] = ATA_UDMA4;
269 return 0;
270 }
271 }
272 if (udmamode >= 2) {
273 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
274 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
275 if (bootverbose)
276 ata_printf(scp, device,
277 "%s setting up UDMA2 mode on VIA chip\n",
278 (error) ? "failed" : "success");
279 if (!error) {
280 pci_write_config(scp->dev, 0x53 - devno, 0xea, 1);
281 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
282 return 0;
283 }
284 }
285 }
286
287 /* UDMA4 mode on AMD 756 */
288 if (udmamode >= 4 && scp->chiptype == 0x74091022) {
289 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
290 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
291 if (bootverbose)
292 ata_printf(scp, device,
293 "%s setting up UDMA4 mode on AMD chip\n",
294 (error) ? "failed" : "success");
295 if (!error) {
296 pci_write_config(scp->dev, 0x53 - devno, 0xc3, 1);
297 scp->mode[ATA_DEV(device)] = ATA_UDMA4;
298 return 0;
299 }
300 }
301
302 /* UDMA2 mode only on 82C586 > rev1, 82C596, AMD 756 */
303 if ((udmamode >= 2 && ata_find_dev(scp->dev, 0x05861106) &&
304 pci_read_config(scp->dev, 0x08, 1) >= 0x01) ||
305 (udmamode >= 2 && ata_find_dev(scp->dev, 0x05961106)) ||
306 (udmamode >= 2 && scp->chiptype == 0x74091022)) {
307 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
308 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
309 if (bootverbose)
310 ata_printf(scp, device, "%s setting up UDMA2 mode on %s chip\n",
311 (error) ? "failed" : "success",
312 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
313 if (!error) {
314 pci_write_config(scp->dev, 0x53 - devno, 0xc0, 1);
315 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
316 return 0;
317 }
318 }
319 if (wdmamode >= 2 && apiomode >= 4) {
320 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
321 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
322 if (bootverbose)
323 ata_printf(scp, device, "%s setting up WDMA2 mode on %s chip\n",
324 (error) ? "failed" : "success",
325 (scp->chiptype == 0x74091022) ? "AMD" : "VIA");
326 if (!error) {
327 pci_write_config(scp->dev, 0x53 - devno, 0x82, 1);
328 pci_write_config(scp->dev, 0x4b - devno, 0x31, 1);
329 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
330 return 0;
331 }
332 }
333 /* we could set PIO mode timings, but we assume the BIOS did that */
334 break;
335
336 case 0x55131039: /* SiS 5591 */
337 if (udmamode >= 2) {
338 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
339 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
340 if (bootverbose)
341 ata_printf(scp, device,
342 "%s setting up UDMA2 mode on SiS chip\n",
343 (error) ? "failed" : "success");
344 if (!error) {
345 pci_write_config(scp->dev, 0x40 + (devno << 1), 0xa301, 2);
346 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
347 return 0;
348 }
349 }
350 if (wdmamode >=2 && apiomode >= 4) {
351 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
352 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
353 if (bootverbose)
354 ata_printf(scp, device,
355 "%s setting up WDMA2 mode on SiS chip\n",
356 (error) ? "failed" : "success");
357 if (!error) {
358 pci_write_config(scp->dev, 0x40 + (devno << 1), 0x0301, 2);
359 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
360 return 0;
361 }
362 }
363 /* we could set PIO mode timings, but we assume the BIOS did that */
364 break;
365
366 case 0x4d33105a: /* Promise Ultra33 / FastTrak33 controllers */
367 case 0x4d38105a: /* Promise Ultra66 / FastTrak66 controllers */
368 /* the Promise can only do DMA on ATA disks not on ATAPI devices */

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

377 if (bootverbose)
378 ata_printf(scp, device,
379 "%s setting up UDMA4 mode on Promise chip\n",
380 (error) ? "failed" : "success");
381 if (!error) {
382 outb(scp->bmaddr+0x11, inl(scp->bmaddr+0x11) | scp->unit ? 8:2);
383 promise_timing(scp, devno, ATA_UDMA4);
384 scp->mode[ATA_DEV(device)] = ATA_UDMA4;
385 return 0;
386 }
387 }
388 if (udmamode >= 2) {
389 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
390 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
391 if (bootverbose)
392 ata_printf(scp, device,
393 "%s setting up UDMA2 mode on Promise chip\n",
394 (error) ? "failed" : "success");
395 if (!error) {
396 promise_timing(scp, devno, ATA_UDMA2);
397 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
398 return 0;
399 }
400 }
401 if (wdmamode >= 2 && apiomode >= 4) {
402 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
403 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
404 if (bootverbose)
405 ata_printf(scp, device,
406 "%s setting up WDMA2 mode on Promise chip\n",
407 (error) ? "failed" : "success");
408 if (!error) {
409 promise_timing(scp, devno, ATA_WDMA2);
410 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
411 return 0;
412 }
413 }
414 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
415 ata_pio2mode(apiomode),
416 ATA_C_F_SETXFER, ATA_WAIT_READY);
417 if (bootverbose)
418 ata_printf(scp, device,
419 "%s setting up PIO%d mode on Promise chip\n",
420 (error) ? "failed" : "success",
421 (apiomode >= 0) ? apiomode : 0);
422 promise_timing(scp, devno, ata_pio2mode(apiomode));
423 scp->mode[ATA_DEV(device)] = ata_pio2mode(apiomode);
424 return -1;
425
426 case 0x00041103: /* HighPoint HPT366 controller */
427 /* no ATAPI devices for now */
428 if ((device == ATA_MASTER && scp->devices & ATA_ATAPI_MASTER) ||
429 (device == ATA_SLAVE && scp->devices & ATA_ATAPI_SLAVE))
430 break;
431
432 if (udmamode >=4 && !(pci_read_config(scp->dev, 0x5a, 1) & 0x2)) {
433 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
434 ATA_UDMA4, ATA_C_F_SETXFER, ATA_WAIT_READY);
435 if (bootverbose)
436 ata_printf(scp, device,
437 "%s setting up UDMA4 mode on HPT366 chip\n",
438 (error) ? "failed" : "success");
439 if (!error) {
440 hpt366_timing(scp, devno, ATA_UDMA4);
441 scp->mode[ATA_DEV(device)] = ATA_UDMA4;
442 return 0;
443 }
444 }
445 if (udmamode >= 2) {
446 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
447 ATA_UDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
448 if (bootverbose)
449 ata_printf(scp, device,
450 "%s setting up UDMA2 mode on HPT366 chip\n",
451 (error) ? "failed" : "success");
452 if (!error) {
453 hpt366_timing(scp, devno, ATA_UDMA2);
454 scp->mode[ATA_DEV(device)] = ATA_UDMA2;
455 return 0;
456 }
457 }
458 if (wdmamode >= 2 && apiomode >= 4) {
459 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
460 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
461 if (bootverbose)
462 ata_printf(scp, device,
463 "%s setting up WDMA2 mode on HPT366 chip\n",
464 (error) ? "failed" : "success");
465 if (!error) {
466 hpt366_timing(scp, devno, ATA_WDMA2);
467 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
468 return 0;
469 }
470 }
471 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
472 ata_pio2mode(apiomode),
473 ATA_C_F_SETXFER, ATA_WAIT_READY);
474 if (bootverbose)
475 ata_printf(scp, device, "%s setting up PIO%d mode on HPT366 chip\n",
476 (error) ? "failed" : "success",
477 (apiomode >= 0) ? apiomode : 0);
478 hpt366_timing(scp, devno, ata_pio2mode(apiomode));
479 scp->mode[ATA_DEV(device)] = ata_pio2mode(apiomode);
480 return -1;
481
482 default: /* unknown controller chip */
483 /* better not try generic DMA on ATAPI devices it almost never works */
484 if ((device == ATA_MASTER && scp->devices & ATA_ATAPI_MASTER) ||
485 (device == ATA_SLAVE && scp->devices & ATA_ATAPI_SLAVE))
486 break;
487
488 /* well, we have no support for this, but try anyways */
489 if ((wdmamode >= 2 && apiomode >= 4) && scp->bmaddr) {
490 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
491 ATA_WDMA2, ATA_C_F_SETXFER, ATA_WAIT_READY);
492 if (bootverbose)
493 ata_printf(scp, device,
494 "%s setting up WDMA2 mode on generic chip\n",
495 (error) ? "failed" : "success");
496 if (!error) {
497 scp->mode[ATA_DEV(device)] = ATA_WDMA2;
498 return 0;
499 }
500 }
501 }
502 error = ata_command(scp, device, ATA_C_SETFEATURES, 0, 0, 0,
503 ata_pio2mode(apiomode), ATA_C_F_SETXFER,ATA_WAIT_READY);
504 if (bootverbose)
505 ata_printf(scp, device, "%s setting up PIO%d mode on generic chip\n",
506 (error) ? "failed" : "success",(apiomode>=0) ? apiomode : 0);
507 scp->mode[ATA_DEV(device)] = ata_pio2mode(apiomode);
508 return -1;
509}
510
511int32_t
512ata_dmasetup(struct ata_softc *scp, int32_t device,
513 int8_t *data, int32_t count, int32_t flags)
514{
515 struct ata_dmaentry *dmatab;
516 u_int32_t dma_count, dma_base;

--- 162 unchanged lines hidden ---