ide: remove obsoleted "idex=serialize" kernel parameter
[firefly-linux-kernel-4.4.55.git] / drivers / ide / ide.c
index 7e789c97a8b849216cde328a80c4f6b36d4c0002..3cac96f3b0aa02e51a2c7be7b41311d015a03131 100644 (file)
@@ -100,13 +100,8 @@ int ide_noacpitfs = 1;
 int ide_noacpionboot = 1;
 #endif
 
-/*
- * This is declared extern in ide.h, for access by other IDE modules:
- */
 ide_hwif_t ide_hwifs[MAX_HWIFS];       /* master data repository */
 
-EXPORT_SYMBOL(ide_hwifs);
-
 static void ide_port_init_devices_data(ide_hwif_t *);
 
 /*
@@ -165,20 +160,6 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
        }
 }
 
-
-static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
-{
-       hw_regs_t hw;
-
-       memset(&hw, 0, sizeof(hw_regs_t));
-
-       ide_init_hwif_ports(&hw, ide_default_io_base(index), 0, &hwif->irq);
-
-       memcpy(hwif->io_ports, hw.io_ports, sizeof(hw.io_ports));
-
-       hwif->noprobe = !hwif->io_ports[IDE_DATA_OFFSET];
-}
-
 /*
  * init_ide_data() sets reasonable default values into all fields
  * of all instances of the hwifs and drives, but only on the first call.
@@ -199,7 +180,6 @@ static void init_hwif_default(ide_hwif_t *hwif, unsigned int index)
 #define MAGIC_COOKIE 0x12345678
 static void __init init_ide_data (void)
 {
-       ide_hwif_t *hwif;
        unsigned int index;
        static unsigned long magic_cookie = MAGIC_COOKIE;
 
@@ -209,13 +189,9 @@ static void __init init_ide_data (void)
 
        /* Initialise all interface structures */
        for (index = 0; index < MAX_HWIFS; ++index) {
-               hwif = &ide_hwifs[index];
+               ide_hwif_t *hwif = &ide_hwifs[index];
+
                ide_init_port_data(hwif, index);
-               init_hwif_default(hwif, index);
-#if !defined(CONFIG_PPC32) || !defined(CONFIG_PCI)
-               hwif->irq =
-                       ide_init_default_irq(hwif->io_ports[IDE_DATA_OFFSET]);
-#endif
        }
 }
 
@@ -251,218 +227,6 @@ static int ide_system_bus_speed(void)
        return pci_dev_present(pci_default) ? 33 : 50;
 }
 
-ide_hwif_t * ide_find_port(unsigned long base)
-{
-       ide_hwif_t *hwif;
-       int i;
-
-       for (i = 0; i < MAX_HWIFS; i++) {
-               hwif = &ide_hwifs[i];
-               if (hwif->io_ports[IDE_DATA_OFFSET] == base)
-                       goto found;
-       }
-
-       for (i = 0; i < MAX_HWIFS; i++) {
-               hwif = &ide_hwifs[i];
-               if (hwif->chipset == ide_unknown)
-                       goto found;
-       }
-
-       hwif = NULL;
-found:
-       return hwif;
-}
-
-EXPORT_SYMBOL_GPL(ide_find_port);
-
-static struct resource* hwif_request_region(ide_hwif_t *hwif,
-                                           unsigned long addr, int num)
-{
-       struct resource *res = request_region(addr, num, hwif->name);
-
-       if (!res)
-               printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX not free.\n",
-                               hwif->name, addr, addr+num-1);
-       return res;
-}
-
-/**
- *     ide_hwif_request_regions - request resources for IDE
- *     @hwif: interface to use
- *
- *     Requests all the needed resources for an interface.
- *     Right now core IDE code does this work which is deeply wrong.
- *     MMIO leaves it to the controller driver,
- *     PIO will migrate this way over time.
- */
-
-int ide_hwif_request_regions(ide_hwif_t *hwif)
-{
-       unsigned long addr;
-       unsigned int i;
-
-       if (hwif->mmio)
-               return 0;
-       addr = hwif->io_ports[IDE_CONTROL_OFFSET];
-       if (addr && !hwif_request_region(hwif, addr, 1))
-               goto control_region_busy;
-       hwif->straight8 = 0;
-       addr = hwif->io_ports[IDE_DATA_OFFSET];
-       if ((addr | 7) == hwif->io_ports[IDE_STATUS_OFFSET]) {
-               if (!hwif_request_region(hwif, addr, 8))
-                       goto data_region_busy;
-               hwif->straight8 = 1;
-               return 0;
-       }
-       for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++) {
-               addr = hwif->io_ports[i];
-               if (!hwif_request_region(hwif, addr, 1)) {
-                       while (--i)
-                               release_region(addr, 1);
-                       goto data_region_busy;
-               }
-       }
-       return 0;
-
-data_region_busy:
-       addr = hwif->io_ports[IDE_CONTROL_OFFSET];
-       if (addr)
-               release_region(addr, 1);
-control_region_busy:
-       /* If any errors are return, we drop the hwif interface. */
-       return -EBUSY;
-}
-
-/**
- *     ide_hwif_release_regions - free IDE resources
- *
- *     Note that we only release the standard ports,
- *     and do not even try to handle any extra ports
- *     allocated for weird IDE interface chipsets.
- *
- *     Note also that we don't yet handle mmio resources here. More
- *     importantly our caller should be doing this so we need to 
- *     restructure this as a helper function for drivers.
- */
-
-void ide_hwif_release_regions(ide_hwif_t *hwif)
-{
-       u32 i = 0;
-
-       if (hwif->mmio)
-               return;
-       if (hwif->io_ports[IDE_CONTROL_OFFSET])
-               release_region(hwif->io_ports[IDE_CONTROL_OFFSET], 1);
-       if (hwif->straight8) {
-               release_region(hwif->io_ports[IDE_DATA_OFFSET], 8);
-               return;
-       }
-       for (i = IDE_DATA_OFFSET; i <= IDE_STATUS_OFFSET; i++)
-               if (hwif->io_ports[i])
-                       release_region(hwif->io_ports[i], 1);
-}
-
-/**
- *     ide_hwif_restore        -       restore hwif to template
- *     @hwif: hwif to update
- *     @tmp_hwif: template
- *
- *     Restore hwif to a previous state by copying most settings
- *     from the template.
- */
-
-static void ide_hwif_restore(ide_hwif_t *hwif, ide_hwif_t *tmp_hwif)
-{
-       hwif->hwgroup                   = tmp_hwif->hwgroup;
-
-       hwif->gendev.parent             = tmp_hwif->gendev.parent;
-
-       hwif->proc                      = tmp_hwif->proc;
-
-       hwif->major                     = tmp_hwif->major;
-       hwif->straight8                 = tmp_hwif->straight8;
-       hwif->bus_state                 = tmp_hwif->bus_state;
-
-       hwif->host_flags                = tmp_hwif->host_flags;
-
-       hwif->pio_mask                  = tmp_hwif->pio_mask;
-
-       hwif->ultra_mask                = tmp_hwif->ultra_mask;
-       hwif->mwdma_mask                = tmp_hwif->mwdma_mask;
-       hwif->swdma_mask                = tmp_hwif->swdma_mask;
-
-       hwif->cbl                       = tmp_hwif->cbl;
-
-       hwif->chipset                   = tmp_hwif->chipset;
-       hwif->hold                      = tmp_hwif->hold;
-
-       hwif->dev                       = tmp_hwif->dev;
-
-#ifdef CONFIG_BLK_DEV_IDEPCI
-       hwif->cds                       = tmp_hwif->cds;
-#endif
-
-       hwif->set_pio_mode              = tmp_hwif->set_pio_mode;
-       hwif->set_dma_mode              = tmp_hwif->set_dma_mode;
-       hwif->mdma_filter               = tmp_hwif->mdma_filter;
-       hwif->udma_filter               = tmp_hwif->udma_filter;
-       hwif->selectproc                = tmp_hwif->selectproc;
-       hwif->reset_poll                = tmp_hwif->reset_poll;
-       hwif->pre_reset                 = tmp_hwif->pre_reset;
-       hwif->resetproc                 = tmp_hwif->resetproc;
-       hwif->maskproc                  = tmp_hwif->maskproc;
-       hwif->quirkproc                 = tmp_hwif->quirkproc;
-
-       hwif->ata_input_data            = tmp_hwif->ata_input_data;
-       hwif->ata_output_data           = tmp_hwif->ata_output_data;
-       hwif->atapi_input_bytes         = tmp_hwif->atapi_input_bytes;
-       hwif->atapi_output_bytes        = tmp_hwif->atapi_output_bytes;
-
-       hwif->dma_host_set              = tmp_hwif->dma_host_set;
-       hwif->dma_setup                 = tmp_hwif->dma_setup;
-       hwif->dma_exec_cmd              = tmp_hwif->dma_exec_cmd;
-       hwif->dma_start                 = tmp_hwif->dma_start;
-       hwif->ide_dma_end               = tmp_hwif->ide_dma_end;
-       hwif->ide_dma_test_irq          = tmp_hwif->ide_dma_test_irq;
-       hwif->ide_dma_clear_irq         = tmp_hwif->ide_dma_clear_irq;
-       hwif->dma_lost_irq              = tmp_hwif->dma_lost_irq;
-       hwif->dma_timeout               = tmp_hwif->dma_timeout;
-
-       hwif->OUTB                      = tmp_hwif->OUTB;
-       hwif->OUTBSYNC                  = tmp_hwif->OUTBSYNC;
-       hwif->OUTW                      = tmp_hwif->OUTW;
-       hwif->OUTSW                     = tmp_hwif->OUTSW;
-       hwif->OUTSL                     = tmp_hwif->OUTSL;
-
-       hwif->INB                       = tmp_hwif->INB;
-       hwif->INW                       = tmp_hwif->INW;
-       hwif->INSW                      = tmp_hwif->INSW;
-       hwif->INSL                      = tmp_hwif->INSL;
-
-       hwif->sg_max_nents              = tmp_hwif->sg_max_nents;
-
-       hwif->mmio                      = tmp_hwif->mmio;
-       hwif->rqsize                    = tmp_hwif->rqsize;
-
-#ifndef CONFIG_BLK_DEV_IDECS
-       hwif->irq                       = tmp_hwif->irq;
-#endif
-
-       hwif->dma_base                  = tmp_hwif->dma_base;
-       hwif->dma_command               = tmp_hwif->dma_command;
-       hwif->dma_vendor1               = tmp_hwif->dma_vendor1;
-       hwif->dma_status                = tmp_hwif->dma_status;
-       hwif->dma_vendor3               = tmp_hwif->dma_vendor3;
-       hwif->dma_prdtable              = tmp_hwif->dma_prdtable;
-
-       hwif->config_data               = tmp_hwif->config_data;
-       hwif->select_data               = tmp_hwif->select_data;
-       hwif->extra_base                = tmp_hwif->extra_base;
-       hwif->extra_ports               = tmp_hwif->extra_ports;
-
-       hwif->hwif_data                 = tmp_hwif->hwif_data;
-}
-
 void ide_remove_port_from_hwgroup(ide_hwif_t *hwif)
 {
        ide_hwgroup_t *hwgroup = hwif->hwgroup;
@@ -530,8 +294,6 @@ EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
 /**
  *     ide_unregister          -       free an IDE interface
  *     @index: index of interface (will change soon to a pointer)
- *     @init_default: init default hwif flag
- *     @restore: restore hwif flag
  *
  *     Perform the final unregister of an IDE interface. At the moment
  *     we don't refcount interfaces so this will also get split up.
@@ -551,10 +313,9 @@ EXPORT_SYMBOL_GPL(ide_port_unregister_devices);
  *     This is raving bonkers.
  */
 
-void ide_unregister(unsigned int index, int init_default, int restore)
+void ide_unregister(unsigned int index)
 {
        ide_hwif_t *hwif, *g;
-       static ide_hwif_t tmp_hwif; /* protected by ide_cfg_mtx */
        ide_hwgroup_t *hwgroup;
        int irq_count = 0;
 
@@ -601,34 +362,12 @@ void ide_unregister(unsigned int index, int init_default, int restore)
        unregister_blkdev(hwif->major, hwif->name);
        spin_lock_irq(&ide_lock);
 
-       if (hwif->dma_base) {
-               (void) ide_release_dma(hwif);
-
-               hwif->dma_base = 0;
-               hwif->dma_command = 0;
-               hwif->dma_vendor1 = 0;
-               hwif->dma_status = 0;
-               hwif->dma_vendor3 = 0;
-               hwif->dma_prdtable = 0;
-
-               hwif->extra_base  = 0;
-               hwif->extra_ports = 0;
-       }
-
-       ide_hwif_release_regions(hwif);
-
-       /* copy original settings */
-       tmp_hwif = *hwif;
+       if (hwif->dma_base)
+               ide_release_dma_engine(hwif);
 
        /* restore hwif data to pristine status */
        ide_init_port_data(hwif, index);
 
-       if (init_default)
-               init_hwif_default(hwif, index);
-
-       if (restore)
-               ide_hwif_restore(hwif, &tmp_hwif);
-
 abort:
        spin_unlock_irq(&ide_lock);
        mutex_unlock(&ide_cfg_mtx);
@@ -640,59 +379,12 @@ void ide_init_port_hw(ide_hwif_t *hwif, hw_regs_t *hw)
 {
        memcpy(hwif->io_ports, hw->io_ports, sizeof(hwif->io_ports));
        hwif->irq = hw->irq;
-       hwif->noprobe = 0;
        hwif->chipset = hw->chipset;
        hwif->gendev.parent = hw->dev;
        hwif->ack_intr = hw->ack_intr;
 }
 EXPORT_SYMBOL_GPL(ide_init_port_hw);
 
-/**
- *     ide_register_hw         -       register IDE interface
- *     @hw: hardware registers
- *     @quirkproc: quirkproc function
- *     @hwifp: pointer to returned hwif
- *
- *     Register an IDE interface, specifying exactly the registers etc.
- *
- *     Returns -1 on error.
- */
-
-static int ide_register_hw(hw_regs_t *hw, void (*quirkproc)(ide_drive_t *),
-                          ide_hwif_t **hwifp)
-{
-       int index, retry = 1;
-       ide_hwif_t *hwif;
-       u8 idx[4] = { 0xff, 0xff, 0xff, 0xff };
-
-       do {
-               hwif = ide_find_port(hw->io_ports[IDE_DATA_OFFSET]);
-               if (hwif)
-                       goto found;
-               for (index = 0; index < MAX_HWIFS; index++)
-                       ide_unregister(index, 1, 1);
-       } while (retry--);
-       return -1;
-found:
-       index = hwif->index;
-       if (hwif->present)
-               ide_unregister(index, 0, 1);
-       else if (!hwif->hold)
-               ide_init_port_data(hwif, index);
-
-       ide_init_port_hw(hwif, hw);
-       hwif->quirkproc = quirkproc;
-
-       idx[0] = index;
-
-       ide_device_add(idx, NULL);
-
-       if (hwifp)
-               *hwifp = hwif;
-
-       return hwif->present ? index : -1;
-}
-
 /*
  *     Locks for IDE setting functionality
  */
@@ -777,7 +469,7 @@ int set_using_dma(ide_drive_t *drive, int arg)
        if (!drive->id || !(drive->id->capability & 1))
                goto out;
 
-       if (hwif->dma_host_set == NULL)
+       if (hwif->dma_ops == NULL)
                goto out;
 
        err = -EBUSY;
@@ -816,11 +508,14 @@ out:
 int set_pio_mode(ide_drive_t *drive, int arg)
 {
        struct request rq;
+       ide_hwif_t *hwif = drive->hwif;
+       const struct ide_port_ops *port_ops = hwif->port_ops;
 
        if (arg < 0 || arg > 255)
                return -EINVAL;
 
-       if (drive->hwif->set_pio_mode == NULL)
+       if (port_ops == NULL || port_ops->set_pio_mode == NULL ||
+           (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
                return -ENOSYS;
 
        if (drive->special.b.set_tune)
@@ -995,27 +690,6 @@ int generic_ide_ioctl(ide_drive_t *drive, struct file *file, struct block_device
                        if (!capable(CAP_SYS_RAWIO))
                                return -EACCES;
                        return ide_task_ioctl(drive, cmd, arg);
-
-               case HDIO_SCAN_HWIF:
-               {
-                       hw_regs_t hw;
-                       int args[3];
-                       if (!capable(CAP_SYS_RAWIO)) return -EACCES;
-                       if (copy_from_user(args, p, 3 * sizeof(int)))
-                               return -EFAULT;
-                       memset(&hw, 0, sizeof(hw));
-                       ide_init_hwif_ports(&hw, (unsigned long) args[0],
-                                           (unsigned long) args[1], NULL);
-                       hw.irq = args[2];
-                       if (ide_register_hw(&hw, NULL, NULL) == -1)
-                               return -EIO;
-                       return 0;
-               }
-               case HDIO_UNREGISTER_HWIF:
-                       if (!capable(CAP_SYS_RAWIO)) return -EACCES;
-                       /* (arg > MAX_HWIFS) checked in function */
-                       ide_unregister(arg, 1, 1);
-                       return 0;
                case HDIO_SET_NICE:
                        if (!capable(CAP_SYS_ADMIN)) return -EACCES;
                        if (arg != (arg & ((1 << IDE_NICE_DSC_OVERLAP) | (1 << IDE_NICE_1))))
@@ -1169,6 +843,7 @@ extern int probe_dtc2278;
 extern int probe_ht6560b;
 extern int probe_qd65xx;
 extern int cmd640_vlb;
+extern int probe_4drives;
 
 static int __initdata is_chipset_set;
 
@@ -1255,14 +930,12 @@ static int __init ide_setup(char *s)
                                goto done;
                        case -3: /* "nowerr" */
                                drive->bad_wstat = BAD_R_STAT;
-                               hwif->noprobe = 0;
                                goto done;
                        case -4: /* "cdrom" */
                                drive->present = 1;
                                drive->media = ide_cdrom;
                                /* an ATAPI device ignores DRDY */
                                drive->ready_stat = 0;
-                               hwif->noprobe = 0;
                                goto done;
                        case -5: /* nodma */
                                drive->nodma = 1;
@@ -1293,7 +966,6 @@ static int __init ide_setup(char *s)
                                drive->sect     = drive->bios_sect = vals[2];
                                drive->present  = 1;
                                drive->forced_geom = 1;
-                               hwif->noprobe = 0;
                                goto done;
                        default:
                                goto bad_option;
@@ -1323,7 +995,7 @@ static int __init ide_setup(char *s)
                 * (-8, -9, -10) are reserved to ease the hardcoding.
                 */
                static const char *ide_words[] = {
-                       "noprobe", "serialize", "minus3", "minus4",
+                       "minus1", "minus2", "minus3", "minus4",
                        "reset", "minus6", "ata66", "minus8", "minus9",
                        "minus10", "four", "qd65xx", "ht6560b", "cmd640_vlb",
                        "dtc2278", "umc8672", "ali14xx", NULL };
@@ -1380,19 +1052,9 @@ static int __init ide_setup(char *s)
 #endif
 #ifdef CONFIG_BLK_DEV_4DRIVES
                        case -11: /* "four" drives on one set of ports */
-                       {
-                               ide_hwif_t *mate = &ide_hwifs[hw^1];
-                               mate->drives[0].select.all ^= 0x20;
-                               mate->drives[1].select.all ^= 0x20;
-                               hwif->chipset = mate->chipset = ide_4drives;
-                               mate->irq = hwif->irq;
-                               memcpy(mate->io_ports, hwif->io_ports, sizeof(hwif->io_ports));
-                               hwif->mate = mate;
-                               mate->mate = hwif;
-                               hwif->serialized = mate->serialized = 1;
+                               probe_4drives = 1;
                                goto obsolete_option;
-                       }
-#endif /* CONFIG_BLK_DEV_4DRIVES */
+#endif
                        case -10: /* minus10 */
                        case -9: /* minus9 */
                        case -8: /* minus8 */
@@ -1414,15 +1076,8 @@ static int __init ide_setup(char *s)
                        case -5: /* "reset" */
                                hwif->reset = 1;
                                goto obsolete_option;
-                       case -2: /* "serialize" */
-                               hwif->mate = &ide_hwifs[hw^1];
-                               hwif->mate->mate = hwif;
-                               hwif->serialized = hwif->mate->serialized = 1;
-                               goto obsolete_option;
-
-                       case -1: /* "noprobe" */
-                               hwif->noprobe = 1;
-                               goto obsolete_option;
+                       case -2:
+                       case -1:
                        case 0:
                        case 1:
                        case 2:
@@ -1579,6 +1234,38 @@ static void ide_port_class_release(struct device *portdev)
        put_device(&hwif->gendev);
 }
 
+static unsigned int ide_ignore_cable;
+
+static int ide_set_ignore_cable(const char *s, struct kernel_param *kp)
+{
+       int i, j = 1;
+
+       if (sscanf(s, "%d:%d", &i, &j) != 2 && sscanf(s, "%d", &i) != 1)
+               return -EINVAL;
+
+       if (i >= MAX_HWIFS || j < 0 || j > 1)
+               return -EINVAL;
+
+       if (j)
+               ide_ignore_cable |= (1 << i);
+       else
+               ide_ignore_cable &= (1 << i);
+
+       return 0;
+}
+
+module_param_call(ignore_cable, ide_set_ignore_cable, NULL, NULL, 0);
+MODULE_PARM_DESC(ignore_cable, "ignore cable detection");
+
+void ide_port_apply_params(ide_hwif_t *hwif)
+{
+       if (ide_ignore_cable & (1 << hwif->index)) {
+               printk(KERN_INFO "ide: ignoring cable detection for %s\n",
+                                hwif->name);
+               hwif->cbl = ATA_CBL_PATA40_SHORT;
+       }
+}
+
 /*
  * This is gets invoked once during initialization, to set *everything* up
  */
@@ -1648,7 +1335,7 @@ void __exit cleanup_module (void)
        int index;
 
        for (index = 0; index < MAX_HWIFS; ++index)
-               ide_unregister(index, 0, 0);
+               ide_unregister(index);
 
        proc_ide_destroy();