aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/block
diff options
context:
space:
mode:
authorJeff Garzik <jeff@garzik.org>2007-09-27 07:40:33 -0400
committerJens Axboe <axboe@carl.home.kernel.dk>2007-10-10 03:25:59 -0400
commitee4a7b6874469244ed0e3b8fde20028e0bb52642 (patch)
treec5643ff2221c502676529fea7a7748b10951cc23 /drivers/block
parent4e0af881afee2b399854b1cdfdbe37e6ab6a09ca (diff)
drivers/block/umem: minor cleanups
* tab-align DRIVER_*, pci_driver entries * reduced wasted memory by killing unused struct cardinfo members * move free_irq() call above resource unmap, to fix tiny window where irq handler may access recently-unmapped memory * propagate pci_enable_device() return value * use pci_request_regions, pci_release_regions() for resource reservation * call pci_disable_device() in pci_driver::remove() Signed-off-by: Jeff Garzik <jeff@garzik.org>
Diffstat (limited to 'drivers/block')
-rw-r--r--drivers/block/umem.c59
1 files changed, 29 insertions, 30 deletions
diff --git a/drivers/block/umem.c b/drivers/block/umem.c
index 32060b84c0fd..97c5dc9436a9 100644
--- a/drivers/block/umem.c
+++ b/drivers/block/umem.c
@@ -67,9 +67,10 @@
67 * Version Information 67 * Version Information
68 */ 68 */
69 69
70#define DRIVER_VERSION "v2.3" 70#define DRIVER_NAME "umem"
71#define DRIVER_AUTHOR "San Mehat, Johannes Erdfelt, NeilBrown" 71#define DRIVER_VERSION "v2.3"
72#define DRIVER_DESC "Micro Memory(tm) PCI memory board block driver" 72#define DRIVER_AUTHOR "San Mehat, Johannes Erdfelt, NeilBrown"
73#define DRIVER_DESC "Micro Memory(tm) PCI memory board block driver"
73 74
74static int debug; 75static int debug;
75/* #define HW_TRACE(x) writeb(x,cards[0].csr_remap + MEMCTRLSTATUS_MAGIC) */ 76/* #define HW_TRACE(x) writeb(x,cards[0].csr_remap + MEMCTRLSTATUS_MAGIC) */
@@ -99,12 +100,7 @@ static int major_nr;
99struct cardinfo { 100struct cardinfo {
100 struct pci_dev *dev; 101 struct pci_dev *dev;
101 102
102 int irq;
103
104 unsigned long csr_base;
105 unsigned char __iomem *csr_remap; 103 unsigned char __iomem *csr_remap;
106 unsigned long csr_len;
107 unsigned int win_size; /* PCI window size */
108 unsigned int mm_size; /* size in kbytes */ 104 unsigned int mm_size; /* size in kbytes */
109 105
110 unsigned int init_size; /* initial segment, in sectors, 106 unsigned int init_size; /* initial segment, in sectors,
@@ -869,22 +865,27 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
869 unsigned char mem_present; 865 unsigned char mem_present;
870 unsigned char batt_status; 866 unsigned char batt_status;
871 unsigned int saved_bar, data; 867 unsigned int saved_bar, data;
868 unsigned long csr_base;
869 unsigned long csr_len;
872 int magic_number; 870 int magic_number;
873 static int printed_version; 871 static int printed_version;
874 872
875 if (!printed_version++) 873 if (!printed_version++)
876 printk(KERN_INFO DRIVER_VERSION " : " DRIVER_DESC "\n"); 874 printk(KERN_INFO DRIVER_VERSION " : " DRIVER_DESC "\n");
877 875
878 if (pci_enable_device(dev) < 0) 876 ret = pci_enable_device(dev);
879 return -ENODEV; 877 if (ret)
878 return ret;
880 879
881 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF8); 880 pci_write_config_byte(dev, PCI_LATENCY_TIMER, 0xF8);
882 pci_set_master(dev); 881 pci_set_master(dev);
883 882
884 card->dev = dev; 883 card->dev = dev;
885 884
886 card->csr_base = pci_resource_start(dev, 0); 885 csr_base = pci_resource_start(dev, 0);
887 card->csr_len = pci_resource_len(dev, 0); 886 csr_len = pci_resource_len(dev, 0);
887 if (!csr_base || !csr_len)
888 return -ENODEV;
888 889
889 dev_printk(KERN_INFO, &dev->dev, 890 dev_printk(KERN_INFO, &dev->dev,
890 "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n"); 891 "Micro Memory(tm) controller found (PCI Mem Module (Battery Backup))\n");
@@ -894,15 +895,15 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
894 dev_printk(KERN_WARNING, &dev->dev, "NO suitable DMA found\n"); 895 dev_printk(KERN_WARNING, &dev->dev, "NO suitable DMA found\n");
895 return -ENOMEM; 896 return -ENOMEM;
896 } 897 }
897 if (!request_mem_region(card->csr_base, card->csr_len, "Micro Memory")) { 898
899 ret = pci_request_regions(dev, DRIVER_NAME);
900 if (ret) {
898 dev_printk(KERN_ERR, &card->dev->dev, 901 dev_printk(KERN_ERR, &card->dev->dev,
899 "Unable to request memory region\n"); 902 "Unable to request memory region\n");
900 ret = -ENOMEM;
901
902 goto failed_req_csr; 903 goto failed_req_csr;
903 } 904 }
904 905
905 card->csr_remap = ioremap_nocache(card->csr_base, card->csr_len); 906 card->csr_remap = ioremap_nocache(csr_base, csr_len);
906 if (!card->csr_remap) { 907 if (!card->csr_remap) {
907 dev_printk(KERN_ERR, &card->dev->dev, 908 dev_printk(KERN_ERR, &card->dev->dev,
908 "Unable to remap memory region\n"); 909 "Unable to remap memory region\n");
@@ -913,7 +914,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
913 914
914 dev_printk(KERN_INFO, &card->dev->dev, 915 dev_printk(KERN_INFO, &card->dev->dev,
915 "CSR 0x%08lx -> 0x%p (0x%lx)\n", 916 "CSR 0x%08lx -> 0x%p (0x%lx)\n",
916 card->csr_base, card->csr_remap, card->csr_len); 917 csr_base, card->csr_remap, csr_len);
917 918
918 switch(card->dev->device) { 919 switch(card->dev->device) {
919 case 0x5415: 920 case 0x5415:
@@ -1028,9 +1029,6 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1028 data = ~data; 1029 data = ~data;
1029 data += 1; 1030 data += 1;
1030 1031
1031 card->win_size = data;
1032
1033
1034 if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, "pci-umem", card)) { 1032 if (request_irq(dev->irq, mm_interrupt, IRQF_SHARED, "pci-umem", card)) {
1035 dev_printk(KERN_ERR, &card->dev->dev, 1033 dev_printk(KERN_ERR, &card->dev->dev,
1036 "Unable to allocate IRQ\n"); 1034 "Unable to allocate IRQ\n");
@@ -1039,10 +1037,8 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1039 goto failed_req_irq; 1037 goto failed_req_irq;
1040 } 1038 }
1041 1039
1042 card->irq = dev->irq;
1043 dev_printk(KERN_INFO, &card->dev->dev, 1040 dev_printk(KERN_INFO, &card->dev->dev,
1044 "Window size %d bytes, IRQ %d\n", 1041 "Window size %d bytes, IRQ %d\n", data, dev->irq);
1045 card->win_size, card->irq);
1046 1042
1047 spin_lock_init(&card->lock); 1043 spin_lock_init(&card->lock);
1048 1044
@@ -1089,7 +1085,7 @@ static int __devinit mm_pci_probe(struct pci_dev *dev, const struct pci_device_i
1089 failed_magic: 1085 failed_magic:
1090 iounmap(card->csr_remap); 1086 iounmap(card->csr_remap);
1091 failed_remap_csr: 1087 failed_remap_csr:
1092 release_mem_region(card->csr_base, card->csr_len); 1088 pci_release_regions(dev);
1093 failed_req_csr: 1089 failed_req_csr:
1094 1090
1095 return ret; 1091 return ret;
@@ -1104,9 +1100,8 @@ static void mm_pci_remove(struct pci_dev *dev)
1104 struct cardinfo *card = pci_get_drvdata(dev); 1100 struct cardinfo *card = pci_get_drvdata(dev);
1105 1101
1106 tasklet_kill(&card->tasklet); 1102 tasklet_kill(&card->tasklet);
1103 free_irq(dev->irq, card);
1107 iounmap(card->csr_remap); 1104 iounmap(card->csr_remap);
1108 release_mem_region(card->csr_base, card->csr_len);
1109 free_irq(card->irq, card);
1110 1105
1111 if (card->mm_pages[0].desc) 1106 if (card->mm_pages[0].desc)
1112 pci_free_consistent(card->dev, PAGE_SIZE*2, 1107 pci_free_consistent(card->dev, PAGE_SIZE*2,
@@ -1117,6 +1112,9 @@ static void mm_pci_remove(struct pci_dev *dev)
1117 card->mm_pages[1].desc, 1112 card->mm_pages[1].desc,
1118 card->mm_pages[1].page_dma); 1113 card->mm_pages[1].page_dma);
1119 blk_cleanup_queue(card->queue); 1114 blk_cleanup_queue(card->queue);
1115
1116 pci_release_regions(dev);
1117 pci_disable_device(dev);
1120} 1118}
1121 1119
1122static const struct pci_device_id mm_pci_ids[] = { 1120static const struct pci_device_id mm_pci_ids[] = {
@@ -1136,11 +1134,12 @@ static const struct pci_device_id mm_pci_ids[] = {
1136MODULE_DEVICE_TABLE(pci, mm_pci_ids); 1134MODULE_DEVICE_TABLE(pci, mm_pci_ids);
1137 1135
1138static struct pci_driver mm_pci_driver = { 1136static struct pci_driver mm_pci_driver = {
1139 .name = "umem", 1137 .name = DRIVER_NAME,
1140 .id_table = mm_pci_ids, 1138 .id_table = mm_pci_ids,
1141 .probe = mm_pci_probe, 1139 .probe = mm_pci_probe,
1142 .remove = mm_pci_remove, 1140 .remove = mm_pci_remove,
1143}; 1141};
1142
1144/* 1143/*
1145----------------------------------------------------------------------------------- 1144-----------------------------------------------------------------------------------
1146-- mm_init 1145-- mm_init