fedora core 6 1.2949 + vserver 2.2.0
[linux-2.6.git] / drivers / ide / ide-dma.c
index 1179a31..56efed6 100644 (file)
@@ -74,7 +74,6 @@
  *
  */
 
-#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
 #include <asm/io.h>
 #include <asm/irq.h>
 
-struct drive_list_entry {
-       const char *id_model;
-       const char *id_firmware;
-};
-
 static const struct drive_list_entry drive_whitelist [] = {
 
        { "Micropolis 2112A"    ,       "ALL"           },
@@ -132,7 +126,6 @@ static const struct drive_list_entry drive_blacklist [] = {
        { "SAMSUNG CD-ROM SC-148C",     "ALL"           },
        { "SAMSUNG CD-ROM SC",  "ALL"           },
        { "SanDisk SDP3B-64"    ,       "ALL"           },
-       { "SAMSUNG CD-ROM SN-124",      "ALL"           },
        { "ATAPI CD-ROM DRIVE 40X MAXIMUM",     "ALL"           },
        { "_NEC DV5800A",               "ALL"           },  
        { NULL                  ,       NULL            }
@@ -140,7 +133,7 @@ static const struct drive_list_entry drive_blacklist [] = {
 };
 
 /**
- *     in_drive_list   -       look for drive in black/white list
+ *     ide_in_drive_list       -       look for drive in black/white list
  *     @id: drive identifier
  *     @drive_table: list to inspect
  *
@@ -148,11 +141,11 @@ static const struct drive_list_entry drive_blacklist [] = {
  *     Returns 1 if the drive is found in the table.
  */
 
-static int in_drive_list(struct hd_driveid *id, const struct drive_list_entry *drive_table)
+int ide_in_drive_list(struct hd_driveid *id, const struct drive_list_entry *drive_table)
 {
        for ( ; drive_table->id_model ; drive_table++)
                if ((!strcmp(drive_table->id_model, id->model)) &&
-                   ((strstr(drive_table->id_firmware, id->fw_rev)) ||
+                   ((strstr(id->fw_rev, drive_table->id_firmware)) ||
                     (!strcmp(drive_table->id_firmware, "ALL"))))
                        return 1;
        return 0;
@@ -176,7 +169,13 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
                if (!dma_stat) {
                        struct request *rq = HWGROUP(drive)->rq;
 
-                       DRIVER(drive)->end_request(drive, 1, rq->nr_sectors);
+                       if (rq->rq_disk) {
+                               ide_driver_t *drv;
+
+                               drv = *(ide_driver_t **)rq->rq_disk->private_data;
+                               drv->end_request(drive, 1, rq->nr_sectors);
+                       } else
+                               ide_end_request(drive, 1, rq->nr_sectors);
                        return ide_stopped;
                }
                printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", 
@@ -204,8 +203,7 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
        ide_hwif_t *hwif = HWIF(drive);
        struct scatterlist *sg = hwif->sg_table;
 
-       if ((rq->flags & REQ_DRIVE_TASKFILE) && rq->nr_sectors > 256)
-               BUG();
+       BUG_ON((rq->cmd_type == REQ_TYPE_ATA_TASKFILE) && rq->nr_sectors > 256);
 
        ide_map_sg(drive, rq);
 
@@ -658,7 +656,7 @@ int __ide_dma_bad_drive (ide_drive_t *drive)
 {
        struct hd_driveid *id = drive->id;
 
-       int blacklist = in_drive_list(id, drive_blacklist);
+       int blacklist = ide_in_drive_list(id, drive_blacklist);
        if (blacklist) {
                printk(KERN_WARNING "%s: Disabling (U)DMA for %s (blacklisted)\n",
                                    drive->name, id->model);
@@ -672,7 +670,7 @@ EXPORT_SYMBOL(__ide_dma_bad_drive);
 int __ide_dma_good_drive (ide_drive_t *drive)
 {
        struct hd_driveid *id = drive->id;
-       return in_drive_list(id, drive_whitelist);
+       return ide_in_drive_list(id, drive_whitelist);
 }
 
 EXPORT_SYMBOL(__ide_dma_good_drive);
@@ -750,7 +748,7 @@ void ide_dma_verbose(ide_drive_t *drive)
                        goto bug_dma_off;
                printk(", DMA");
        } else if (id->field_valid & 1) {
-               printk(", BUG");
+               goto bug_dma_off;
        }
        return;
 bug_dma_off:
@@ -798,26 +796,23 @@ static int ide_release_dma_engine(ide_hwif_t *hwif)
 
 static int ide_release_iomio_dma(ide_hwif_t *hwif)
 {
-       if ((hwif->dma_extra) && (hwif->channel == 0))
-               release_region((hwif->dma_base + 16), hwif->dma_extra);
        release_region(hwif->dma_base, 8);
-       if (hwif->dma_base2)
-               release_region(hwif->dma_base, 8);
+       if (hwif->extra_ports)
+               release_region(hwif->extra_base, hwif->extra_ports);
        return 1;
 }
 
 /*
  * Needed for allowing full modular support of ide-driver
  */
-int ide_release_dma (ide_hwif_t *hwif)
+int ide_release_dma(ide_hwif_t *hwif)
 {
+       ide_release_dma_engine(hwif);
+
        if (hwif->mmio == 2)
                return 1;
-       if (hwif->chipset == ide_etrax100)
-               return 1;
-
-       ide_release_dma_engine(hwif);
-       return ide_release_iomio_dma(hwif);
+       else
+               return ide_release_iomio_dma(hwif);
 }
 
 static int ide_allocate_dma_engine(ide_hwif_t *hwif)
@@ -829,10 +824,9 @@ static int ide_allocate_dma_engine(ide_hwif_t *hwif)
        if (hwif->dmatable_cpu)
                return 0;
 
-       printk(KERN_ERR "%s: -- Error, unable to allocate%s DMA table(s).\n",
-                       hwif->cds->name, !hwif->dmatable_cpu ? " CPU" : "");
+       printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n",
+              hwif->cds->name);
 
-       ide_release_dma_engine(hwif);
        return 1;
 }
 
@@ -840,9 +834,7 @@ static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned in
 {
        printk(KERN_INFO "    %s: MMIO-DMA ", hwif->name);
 
-       hwif->dma_base = base;
-       if (hwif->cds->extra && hwif->channel == 0)
-               hwif->dma_extra = hwif->cds->extra;
+       hwif->dma_base = base;
 
        if(hwif->mate)
                hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base;
@@ -854,29 +846,33 @@ static int ide_mapped_mmio_dma(ide_hwif_t *hwif, unsigned long base, unsigned in
 static int ide_iomio_dma(ide_hwif_t *hwif, unsigned long base, unsigned int ports)
 {
        printk(KERN_INFO "    %s: BM-DMA at 0x%04lx-0x%04lx",
-               hwif->name, base, base + ports - 1);
+              hwif->name, base, base + ports - 1);
+
        if (!request_region(base, ports, hwif->name)) {
                printk(" -- Error, ports in use.\n");
                return 1;
        }
+
        hwif->dma_base = base;
-       if ((hwif->cds->extra) && (hwif->channel == 0)) {
-               request_region(base+16, hwif->cds->extra, hwif->cds->name);
-               hwif->dma_extra = hwif->cds->extra;
+
+       if (hwif->cds->extra) {
+               hwif->extra_base = base + (hwif->channel ? 8 : 16);
+
+               if (!hwif->mate || !hwif->mate->extra_ports) {
+                       if (!request_region(hwif->extra_base,
+                                           hwif->cds->extra, hwif->cds->name)) {
+                               printk(" -- Error, extra ports in use.\n");
+                               release_region(base, ports);
+                               return 1;
+                       }
+                       hwif->extra_ports = hwif->cds->extra;
+               }
        }
-       
+
        if(hwif->mate)
-               hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base : base;
+               hwif->dma_master = (hwif->channel) ? hwif->mate->dma_base:base;
        else
                hwif->dma_master = base;
-       if (hwif->dma_base2) {
-               if (!request_region(hwif->dma_base2, ports, hwif->name))
-               {
-                       printk(" -- Error, secondary ports in use.\n");
-                       release_region(base, ports);
-                       return 1;
-               }
-       }
        return 0;
 }
 
@@ -945,8 +941,7 @@ void ide_setup_dma (ide_hwif_t *hwif, unsigned long dma_base, unsigned int num_p
        }
        printk("\n");
 
-       if (!(hwif->dma_master))
-               BUG();
+       BUG_ON(!hwif->dma_master);
 }
 
 EXPORT_SYMBOL_GPL(ide_setup_dma);