1/*-
2 * Copyright (c) 1998,1999 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 52918 1999-11-06 16:50:21Z sos $
29 */
30
31#include "ata.h"
32#include "apm.h"
33#include "isa.h"
34#include "pci.h"
35#include "atadisk.h"
36#include "atapicd.h"
--- 32 unchanged lines hidden (view full) ---
69#include <dev/ata/ata-all.h>
70#include <dev/ata/ata-disk.h>
71#include <dev/ata/atapi-all.h>
72
73/* misc defines */
74#if SMP == 0
75#define isa_apic_irq(x) x
76#endif
77
78/* prototypes */
79static int32_t ata_probe(int32_t, int32_t, int32_t, device_t, int32_t *);
80static void ataintr(void *);
81static int8_t *active2str(int32_t);
82
83/* local vars */
84static int32_t atanlun = 2;
--- 173 unchanged lines hidden (view full) ---
258#endif
259
260 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
261 iobase_1 = IO_WD1;
262 altiobase_1 = iobase_1 + ATA_ALTPORT;
263 irq1 = 14;
264 }
265 else {
266 iobase_1 = pci_read_config(dev, 0x10, 4) & 0xfffc;
267 altiobase_1 = pci_read_config(dev, 0x14, 4) & 0xfffc;
268 bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc;
269 irq1 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
270 }
271
272 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
273 iobase_2 = IO_WD2;
274 altiobase_2 = iobase_2 + ATA_ALTPORT;
275 irq2 = 15;
276 }
277 else {
278 iobase_2 = pci_read_config(dev, 0x18, 4) & 0xfffc;
279 altiobase_2 = pci_read_config(dev, 0x1c, 4) & 0xfffc;
280 bmaddr_2 = (pci_read_config(dev, 0x20, 4) & 0xfffc) + ATA_BM_OFFSET1;
281 irq2 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
282 }
283
284 /* is this controller busmaster DMA capable ? */
285 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
286 /* is busmastering support turned on ? */
287 if ((pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4) & 5) == 5) {
288 /* is there a valid port range to connect to ? */
289 if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
290 bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
291 printf("ata-pci%d: Busmastering DMA supported\n", unit);
292 }
293 else
294 printf("ata-pci%d: Busmastering DMA not configured\n", unit);
295 }
296 else
297 printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
298 }
299 else {
300 /* the Promise controllers need this to support burst mode */
301 if (type == 0x4d33105a || type == 0x4d38105a)
302 outb(bmaddr_1 + 0x1f, inb(bmaddr_1 + 0x1f) | 0x01);
303
304 /* Promise and HPT366 controllers support busmastering DMA */
305 if (type == 0x4d33105a || type == 0x4d38105a || type == 0x00041103)
306 printf("ata-pci%d: Busmastering DMA supported\n", unit);
307
308 /* we dont know this controller, disable busmastering DMA */
309 else {
310 bmaddr_1 = bmaddr_2 = 0;
311 printf("ata-pci%d: Busmastering DMA not supported\n", unit);
312 }
313 }
314
315 /* now probe the addresse found for "real" ATA/ATAPI hardware */
316 lun = 0;
317 if (iobase_1 && ata_probe(iobase_1, altiobase_1, bmaddr_1, dev, &lun)) {
318 scp = atadevices[lun];
319 if (iobase_1 == IO_WD1)
320#ifdef __i386__
321 inthand_add(device_get_nameunit(dev), irq1, ataintr, scp,
--- 185 unchanged lines hidden (view full) ---
507}
508
509static void
510ataintr(void *data)
511{
512 struct ata_softc *scp =(struct ata_softc *)data;
513
514 /* is this interrupt really for this channel */
515 if (scp->flags & ATA_DMA_ACTIVE)
516 if (!(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT))
517 return;
518 if ((scp->status = inb(scp->ioaddr + ATA_STATUS)) == ATA_S_BUSY)
519 return;
520
521 /* find & call the responsible driver to process this interrupt */
522 switch (scp->active) {
523#if NATADISK > 0
524 case ATA_ACTIVE_ATA:
525 if (!scp->running)
526 return;
527 if (ad_interrupt(scp->running) == ATA_OP_CONTINUES)
528 return;
529 break;
530#endif
531#if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
532 case ATA_ACTIVE_ATAPI:
533 if (!scp->running)
534 return;
535 if (atapi_interrupt(scp->running) == ATA_OP_CONTINUES)
536 return;
537 break;
538#endif
539 case ATA_WAIT_INTR:
540 wakeup((caddr_t)scp);
541 break;
--- 362 unchanged lines hidden ---
2 * Copyright (c) 1998,1999 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 52918 1999-11-06 16:50:21Z sos $
29 */
30
31#include "ata.h"
32#include "apm.h"
33#include "isa.h"
34#include "pci.h"
35#include "atadisk.h"
36#include "atapicd.h"
--- 32 unchanged lines hidden (view full) ---
69#include <dev/ata/ata-all.h>
70#include <dev/ata/ata-disk.h>
71#include <dev/ata/atapi-all.h>
72
73/* misc defines */
74#if SMP == 0
75#define isa_apic_irq(x) x
76#endif
77
78/* prototypes */
79static int32_t ata_probe(int32_t, int32_t, int32_t, device_t, int32_t *);
80static void ataintr(void *);
81static int8_t *active2str(int32_t);
82
83/* local vars */
84static int32_t atanlun = 2;
--- 173 unchanged lines hidden (view full) ---
258#endif
259
260 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
261 iobase_1 = IO_WD1;
262 altiobase_1 = iobase_1 + ATA_ALTPORT;
263 irq1 = 14;
264 }
265 else {
266 iobase_1 = pci_read_config(dev, 0x10, 4) & 0xfffc;
267 altiobase_1 = pci_read_config(dev, 0x14, 4) & 0xfffc;
268 bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc;
269 irq1 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
270 }
271
272 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
273 iobase_2 = IO_WD2;
274 altiobase_2 = iobase_2 + ATA_ALTPORT;
275 irq2 = 15;
276 }
277 else {
278 iobase_2 = pci_read_config(dev, 0x18, 4) & 0xfffc;
279 altiobase_2 = pci_read_config(dev, 0x1c, 4) & 0xfffc;
280 bmaddr_2 = (pci_read_config(dev, 0x20, 4) & 0xfffc) + ATA_BM_OFFSET1;
281 irq2 = pci_read_config(dev, PCI_INTERRUPT_REG, 4) & 0xff;
282 }
283
284 /* is this controller busmaster DMA capable ? */
285 if (pci_get_progif(dev) & PCIP_STORAGE_IDE_MASTERDEV) {
286 /* is busmastering support turned on ? */
287 if ((pci_read_config(dev, PCI_COMMAND_STATUS_REG, 4) & 5) == 5) {
288 /* is there a valid port range to connect to ? */
289 if ((bmaddr_1 = pci_read_config(dev, 0x20, 4) & 0xfffc)) {
290 bmaddr_2 = bmaddr_1 + ATA_BM_OFFSET1;
291 printf("ata-pci%d: Busmastering DMA supported\n", unit);
292 }
293 else
294 printf("ata-pci%d: Busmastering DMA not configured\n", unit);
295 }
296 else
297 printf("ata-pci%d: Busmastering DMA not enabled\n", unit);
298 }
299 else {
300 /* the Promise controllers need this to support burst mode */
301 if (type == 0x4d33105a || type == 0x4d38105a)
302 outb(bmaddr_1 + 0x1f, inb(bmaddr_1 + 0x1f) | 0x01);
303
304 /* Promise and HPT366 controllers support busmastering DMA */
305 if (type == 0x4d33105a || type == 0x4d38105a || type == 0x00041103)
306 printf("ata-pci%d: Busmastering DMA supported\n", unit);
307
308 /* we dont know this controller, disable busmastering DMA */
309 else {
310 bmaddr_1 = bmaddr_2 = 0;
311 printf("ata-pci%d: Busmastering DMA not supported\n", unit);
312 }
313 }
314
315 /* now probe the addresse found for "real" ATA/ATAPI hardware */
316 lun = 0;
317 if (iobase_1 && ata_probe(iobase_1, altiobase_1, bmaddr_1, dev, &lun)) {
318 scp = atadevices[lun];
319 if (iobase_1 == IO_WD1)
320#ifdef __i386__
321 inthand_add(device_get_nameunit(dev), irq1, ataintr, scp,
--- 185 unchanged lines hidden (view full) ---
507}
508
509static void
510ataintr(void *data)
511{
512 struct ata_softc *scp =(struct ata_softc *)data;
513
514 /* is this interrupt really for this channel */
515 if (scp->flags & ATA_DMA_ACTIVE)
516 if (!(ata_dmastatus(scp) & ATA_BMSTAT_INTERRUPT))
517 return;
518 if ((scp->status = inb(scp->ioaddr + ATA_STATUS)) == ATA_S_BUSY)
519 return;
520
521 /* find & call the responsible driver to process this interrupt */
522 switch (scp->active) {
523#if NATADISK > 0
524 case ATA_ACTIVE_ATA:
525 if (!scp->running)
526 return;
527 if (ad_interrupt(scp->running) == ATA_OP_CONTINUES)
528 return;
529 break;
530#endif
531#if NATAPICD > 0 || NATAPIFD > 0 || NATAPIST > 0
532 case ATA_ACTIVE_ATAPI:
533 if (!scp->running)
534 return;
535 if (atapi_interrupt(scp->running) == ATA_OP_CONTINUES)
536 return;
537 break;
538#endif
539 case ATA_WAIT_INTR:
540 wakeup((caddr_t)scp);
541 break;
--- 362 unchanged lines hidden ---