readahead: combine file_ra_state.prev_index/prev_offset into prev_pos
[linux-2.6.git] / drivers / char / sx.c
index 0122b2d..85a2328 100644 (file)
@@ -2485,7 +2485,8 @@ static void __exit sx_release_drivers(void)
        func_exit();
 }
 
-static void __devexit sx_remove_card(struct sx_board *board)
+static void __devexit sx_remove_card(struct sx_board *board,
+               struct pci_dev *pdev)
 {
        if (board->flags & SX_BOARD_INITIALIZED) {
                /* The board should stop messing with us. (actually I mean the
@@ -2496,7 +2497,15 @@ static void __devexit sx_remove_card(struct sx_board *board)
 
                /* It is safe/allowed to del_timer a non-active timer */
                del_timer(&board->timer);
-               iounmap(board->base);
+               if (pdev) {
+#ifdef CONFIG_PCI
+                       pci_iounmap(pdev, board->base);
+                       pci_release_region(pdev, IS_CF_BOARD(board) ? 3 : 2);
+#endif
+               } else {
+                       iounmap(board->base);
+                       release_region(board->hw_base, board->hw_len);
+               }
 
                board->flags &= ~(SX_BOARD_INITIALIZED | SX_BOARD_PRESENT);
        }
@@ -2534,8 +2543,17 @@ static int __devinit sx_eisa_probe(struct device *dev)
 
        board->hw_base = ((inb(eisa_slot + 0xc01) << 8) +
                          inb(eisa_slot + 0xc00)) << 16;
+       board->hw_len = SI2_EISA_WINDOW_LEN;
+       if (!request_region(board->hw_base, board->hw_len, "sx")) {
+               dev_err(dev, "can't request region\n");
+               goto err_flag;
+       }
        board->base2 =
        board->base = ioremap(board->hw_base, SI2_EISA_WINDOW_LEN);
+       if (!board->base) {
+               dev_err(dev, "can't remap memory\n");
+               goto err_reg;
+       }
 
        sx_dprintk(SX_DEBUG_PROBE, "IO hw_base address: %lx\n", board->hw_base);
        sx_dprintk(SX_DEBUG_PROBE, "base: %p\n", board->base);
@@ -2550,6 +2568,9 @@ static int __devinit sx_eisa_probe(struct device *dev)
        return 0;
 err_unmap:
        iounmap(board->base);
+err_reg:
+       release_region(board->hw_base, board->hw_len);
+err_flag:
        board->flags &= ~SX_BOARD_PRESENT;
 err:
        return retval;
@@ -2559,7 +2580,7 @@ static int __devexit sx_eisa_remove(struct device *dev)
 {
        struct sx_board *board = dev_get_drvdata(dev);
 
-       sx_remove_card(board);
+       sx_remove_card(board, NULL);
 
        return 0;
 }
@@ -2582,6 +2603,7 @@ static struct eisa_driver sx_eisadriver = {
 
 #endif
 
+#ifdef CONFIG_PCI
  /******************************************************** 
  * Setting bit 17 in the CNTRL register of the PLX 9050  * 
  * chip forces a retry on writes while a read is pending.*
@@ -2613,12 +2635,14 @@ static void __devinit fix_sx_pci(struct pci_dev *pdev, struct sx_board *board)
        }
        iounmap(rebase);
 }
+#endif
 
 static int __devinit sx_pci_probe(struct pci_dev *pdev,
                                  const struct pci_device_id *ent)
 {
+#ifdef CONFIG_PCI
        struct sx_board *board;
-       unsigned int i;
+       unsigned int i, reg;
        int retval = -EIO;
 
        mutex_lock(&sx_boards_lock);
@@ -2640,15 +2664,18 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev,
                SX_CFPCI_BOARD;
 
        /* CF boards use base address 3.... */
-       if (IS_CF_BOARD(board))
-               board->hw_base = pci_resource_start(pdev, 3);
-       else
-               board->hw_base = pci_resource_start(pdev, 2);
+       reg = IS_CF_BOARD(board) ? 3 : 2;
+       retval = pci_request_region(pdev, reg, "sx");
+       if (retval) {
+               dev_err(&pdev->dev, "can't request region\n");
+               goto err_flag;
+       }
+       board->hw_base = pci_resource_start(pdev, reg);
        board->base2 =
-       board->base = ioremap(board->hw_base, WINDOW_LEN(board));
+       board->base = pci_iomap(pdev, reg, WINDOW_LEN(board));
        if (!board->base) {
                dev_err(&pdev->dev, "ioremap failed\n");
-               goto err_flag;
+               goto err_reg;
        }
 
        /* Most of the stuff on the CF board is offset by 0x18000 ....  */
@@ -2671,27 +2698,32 @@ static int __devinit sx_pci_probe(struct pci_dev *pdev,
 
        return 0;
 err_unmap:
-       iounmap(board->base2);
+       pci_iounmap(pdev, board->base);
+err_reg:
+       pci_release_region(pdev, reg);
 err_flag:
        board->flags &= ~SX_BOARD_PRESENT;
 err:
        return retval;
+#else
+       return -ENODEV;
+#endif
 }
 
 static void __devexit sx_pci_remove(struct pci_dev *pdev)
 {
        struct sx_board *board = pci_get_drvdata(pdev);
 
-       sx_remove_card(board);
+       sx_remove_card(board, pdev);
 }
 
 /* Specialix has a whole bunch of cards with 0x2000 as the device ID. They say
    its because the standard requires it. So check for SUBVENDOR_ID. */
 static struct pci_device_id sx_pci_tbl[] = {
        { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
-               .subvendor = 0x0200,.subdevice = PCI_ANY_ID },
+               .subvendor = PCI_ANY_ID, .subdevice = 0x0200 },
        { PCI_VENDOR_ID_SPECIALIX, PCI_DEVICE_ID_SPECIALIX_SX_XIO_IO8,
-               .subvendor = 0x0300,.subdevice = PCI_ANY_ID },
+               .subvendor = PCI_ANY_ID, .subdevice = 0x0300 },
        { 0 }
 };
 
@@ -2734,8 +2766,13 @@ static int __init sx_init(void)
        for (i = 0; i < NR_SX_ADDRS; i++) {
                board = &boards[found];
                board->hw_base = sx_probe_addrs[i];
+               board->hw_len = SX_WINDOW_LEN;
+               if (!request_region(board->hw_base, board->hw_len, "sx"))
+                       continue;
                board->base2 =
-               board->base = ioremap(board->hw_base, SX_WINDOW_LEN);
+               board->base = ioremap(board->hw_base, board->hw_len);
+               if (!board->base)
+                       goto err_sx_reg;
                board->flags &= ~SX_BOARD_TYPE;
                board->flags |= SX_ISA_BOARD;
                board->irq = sx_irqmask ? -1 : 0;
@@ -2745,14 +2782,21 @@ static int __init sx_init(void)
                        found++;
                } else {
                        iounmap(board->base);
+err_sx_reg:
+                       release_region(board->hw_base, board->hw_len);
                }
        }
 
        for (i = 0; i < NR_SI_ADDRS; i++) {
                board = &boards[found];
                board->hw_base = si_probe_addrs[i];
+               board->hw_len = SI2_ISA_WINDOW_LEN;
+               if (!request_region(board->hw_base, board->hw_len, "sx"))
+                       continue;
                board->base2 =
-               board->base = ioremap(board->hw_base, SI2_ISA_WINDOW_LEN);
+               board->base = ioremap(board->hw_base, board->hw_len);
+               if (!board->base)
+                       goto err_si_reg;
                board->flags &= ~SX_BOARD_TYPE;
                board->flags |= SI_ISA_BOARD;
                board->irq = sx_irqmask ? -1 : 0;
@@ -2762,13 +2806,20 @@ static int __init sx_init(void)
                        found++;
                } else {
                        iounmap(board->base);
+err_si_reg:
+                       release_region(board->hw_base, board->hw_len);
                }
        }
        for (i = 0; i < NR_SI1_ADDRS; i++) {
                board = &boards[found];
                board->hw_base = si1_probe_addrs[i];
+               board->hw_len = SI1_ISA_WINDOW_LEN;
+               if (!request_region(board->hw_base, board->hw_len, "sx"))
+                       continue;
                board->base2 =
-               board->base = ioremap(board->hw_base, SI1_ISA_WINDOW_LEN);
+               board->base = ioremap(board->hw_base, board->hw_len);
+               if (!board->base)
+                       goto err_si1_reg;
                board->flags &= ~SX_BOARD_TYPE;
                board->flags |= SI1_ISA_BOARD;
                board->irq = sx_irqmask ? -1 : 0;
@@ -2778,6 +2829,8 @@ static int __init sx_init(void)
                        found++;
                } else {
                        iounmap(board->base);
+err_si1_reg:
+                       release_region(board->hw_base, board->hw_len);
                }
        }
 #endif
@@ -2791,6 +2844,7 @@ static int __init sx_init(void)
                retval = 0;
        } else if (retval) {
 #ifdef CONFIG_EISA
+               retval = retval1;
                if (retval1)
 #endif
                        misc_deregister(&sx_fw_device);
@@ -2811,7 +2865,7 @@ static void __exit sx_exit(void)
        pci_unregister_driver(&sx_pcidriver);
 
        for (i = 0; i < SX_NBOARDS; i++)
-               sx_remove_card(&boards[i]);
+               sx_remove_card(&boards[i], NULL);
 
        if (misc_deregister(&sx_fw_device) < 0) {
                printk(KERN_INFO "sx: couldn't deregister firmware loader "