Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / pnp / isapnp / core.c
index 5adaac6..ac7c2bb 100644 (file)
@@ -42,6 +42,7 @@
 #include <linux/delay.h>
 #include <linux/init.h>
 #include <linux/isapnp.h>
+#include <linux/mutex.h>
 #include <asm/io.h>
 
 #if 0
 #endif
 
 int isapnp_disable;                    /* Disable ISA PnP */
-int isapnp_rdp;                                /* Read Data Port */
-int isapnp_reset = 1;                  /* reset all PnP cards (deactivate) */
-int isapnp_verbose = 1;                        /* verbose mode */
+static int isapnp_rdp;                 /* Read Data Port */
+static int isapnp_reset = 1;           /* reset all PnP cards (deactivate) */
+static int isapnp_verbose = 1;         /* verbose mode */
 
 MODULE_AUTHOR("Jaroslav Kysela <perex@suse.cz>");
 MODULE_DESCRIPTION("Generic ISA Plug & Play support");
-MODULE_PARM(isapnp_disable, "i");
+module_param(isapnp_disable, int, 0);
 MODULE_PARM_DESC(isapnp_disable, "ISA Plug & Play disable");
-MODULE_PARM(isapnp_rdp, "i");
+module_param(isapnp_rdp, int, 0);
 MODULE_PARM_DESC(isapnp_rdp, "ISA Plug & Play read data port");
-MODULE_PARM(isapnp_reset, "i");
+module_param(isapnp_reset, int, 0);
 MODULE_PARM_DESC(isapnp_reset, "ISA Plug & Play reset all cards");
-MODULE_PARM(isapnp_verbose, "i");
+module_param(isapnp_verbose, int, 0);
 MODULE_PARM_DESC(isapnp_verbose, "ISA Plug & Play verbose mode");
 MODULE_LICENSE("GPL");
 
-#ifdef CONFIG_X86_PC9800
-#define _PIDXR         0x259
-#define _PNPWRP                0xa59
-#else
 #define _PIDXR         0x279
 #define _PNPWRP                0xa79
-#endif
 
 /* short tags */
 #define _STAG_PNPVERNO         0x01
@@ -97,7 +93,7 @@ MODULE_LICENSE("GPL");
 #define _LTAG_FIXEDMEM32RANGE  0x86
 
 static unsigned char isapnp_checksum_value;
-static DECLARE_MUTEX(isapnp_cfg_mutex);
+static DEFINE_MUTEX(isapnp_cfg_mutex);
 static int isapnp_detected;
 static int isapnp_csn_count;
 
@@ -126,7 +122,7 @@ unsigned char isapnp_read_byte(unsigned char idx)
        return read_data();
 }
 
-unsigned short isapnp_read_word(unsigned char idx)
+static unsigned short isapnp_read_word(unsigned char idx)
 {
        unsigned short val;
 
@@ -135,48 +131,18 @@ unsigned short isapnp_read_word(unsigned char idx)
        return val;
 }
 
-unsigned int isapnp_read_dword(unsigned char idx)
-{
-       unsigned int val;
-
-       val = isapnp_read_byte(idx);
-       val = (val << 8) + isapnp_read_byte(idx+1);
-       val = (val << 8) + isapnp_read_byte(idx+2);
-       val = (val << 8) + isapnp_read_byte(idx+3);
-       return val;
-}
-
 void isapnp_write_byte(unsigned char idx, unsigned char val)
 {
        write_address(idx);
        write_data(val);
 }
 
-void isapnp_write_word(unsigned char idx, unsigned short val)
+static void isapnp_write_word(unsigned char idx, unsigned short val)
 {
        isapnp_write_byte(idx, val >> 8);
        isapnp_write_byte(idx+1, val);
 }
 
-void isapnp_write_dword(unsigned char idx, unsigned int val)
-{
-       isapnp_write_byte(idx, val >> 24);
-       isapnp_write_byte(idx+1, val >> 16);
-       isapnp_write_byte(idx+2, val >> 8);
-       isapnp_write_byte(idx+3, val);
-}
-
-void *isapnp_alloc(long size)
-{
-       void *result;
-
-       result = kmalloc(size, GFP_KERNEL);
-       if (!result)
-               return NULL;
-       memset(result, 0, size);
-       return result;
-}
-
 static void isapnp_key(void)
 {
        unsigned char code = 0x6a, msb;
@@ -201,24 +167,24 @@ static void isapnp_wait(void)
        isapnp_write_byte(0x02, 0x02);
 }
 
-void isapnp_wake(unsigned char csn)
+static void isapnp_wake(unsigned char csn)
 {
        isapnp_write_byte(0x03, csn);
 }
 
-void isapnp_device(unsigned char logdev)
+static void isapnp_device(unsigned char logdev)
 {
        isapnp_write_byte(0x07, logdev);
 }
 
-void isapnp_activate(unsigned char logdev)
+static void isapnp_activate(unsigned char logdev)
 {
        isapnp_device(logdev);
        isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 1);
        udelay(250);
 }
 
-void isapnp_deactivate(unsigned char logdev)
+static void isapnp_deactivate(unsigned char logdev)
 {
        isapnp_device(logdev);
        isapnp_write_byte(ISAPNP_CFG_ACTIVATE, 0);
@@ -430,7 +396,7 @@ static void isapnp_parse_id(struct pnp_dev * dev, unsigned short vendor, unsigne
        struct pnp_id * id;
        if (!dev)
                return;
-       id = isapnp_alloc(sizeof(struct pnp_id));
+       id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
        if (!id)
                return;
        sprintf(id->id, "%c%c%c%x%x%x%x",
@@ -454,7 +420,7 @@ static struct pnp_dev * __init isapnp_parse_device(struct pnp_card *card, int si
        struct pnp_dev *dev;
 
        isapnp_peek(tmp, size);
-       dev = isapnp_alloc(sizeof(struct pnp_dev));
+       dev = kcalloc(1, sizeof(struct pnp_dev), GFP_KERNEL);
        if (!dev)
                return NULL;
        dev->number = number;
@@ -482,12 +448,14 @@ static void __init isapnp_parse_irq_resource(struct pnp_option *option,
 {
        unsigned char tmp[3];
        struct pnp_irq *irq;
+       unsigned long bits;
 
        isapnp_peek(tmp, size);
-       irq = isapnp_alloc(sizeof(struct pnp_irq));
+       irq = kcalloc(1, sizeof(struct pnp_irq), GFP_KERNEL);
        if (!irq)
                return;
-       irq->map = (tmp[1] << 8) | tmp[0];
+       bits = (tmp[1] << 8) | tmp[0];
+       bitmap_copy(irq->map, &bits, 16);
        if (size > 2)
                irq->flags = tmp[2];
        else
@@ -507,7 +475,7 @@ static void __init isapnp_parse_dma_resource(struct pnp_option *option,
        struct pnp_dma *dma;
 
        isapnp_peek(tmp, size);
-       dma = isapnp_alloc(sizeof(struct pnp_dma));
+       dma = kcalloc(1, sizeof(struct pnp_dma), GFP_KERNEL);
        if (!dma)
                return;
        dma->map = tmp[0];
@@ -527,7 +495,7 @@ static void __init isapnp_parse_port_resource(struct pnp_option *option,
        struct pnp_port *port;
 
        isapnp_peek(tmp, size);
-       port = isapnp_alloc(sizeof(struct pnp_port));
+       port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
        if (!port)
                return;
        port->min = (tmp[2] << 8) | tmp[1];
@@ -550,7 +518,7 @@ static void __init isapnp_parse_fixed_port_resource(struct pnp_option *option,
        struct pnp_port *port;
 
        isapnp_peek(tmp, size);
-       port = isapnp_alloc(sizeof(struct pnp_port));
+       port = kcalloc(1, sizeof(struct pnp_port), GFP_KERNEL);
        if (!port)
                return;
        port->min = port->max = (tmp[1] << 8) | tmp[0];
@@ -572,7 +540,7 @@ static void __init isapnp_parse_mem_resource(struct pnp_option *option,
        struct pnp_mem *mem;
 
        isapnp_peek(tmp, size);
-       mem = isapnp_alloc(sizeof(struct pnp_mem));
+       mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
        if (!mem)
                return;
        mem->min = ((tmp[2] << 8) | tmp[1]) << 8;
@@ -595,7 +563,7 @@ static void __init isapnp_parse_mem32_resource(struct pnp_option *option,
        struct pnp_mem *mem;
 
        isapnp_peek(tmp, size);
-       mem = isapnp_alloc(sizeof(struct pnp_mem));
+       mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
        if (!mem)
                return;
        mem->min = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
@@ -617,7 +585,7 @@ static void __init isapnp_parse_fixed_mem32_resource(struct pnp_option *option,
        struct pnp_mem *mem;
 
        isapnp_peek(tmp, size);
-       mem = isapnp_alloc(sizeof(struct pnp_mem));
+       mem = kcalloc(1, sizeof(struct pnp_mem), GFP_KERNEL);
        if (!mem)
                return;
        mem->min = mem->max = (tmp[4] << 24) | (tmp[3] << 16) | (tmp[2] << 8) | tmp[1];
@@ -660,8 +628,10 @@ static int __init isapnp_create_device(struct pnp_card *card,
        if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
                return 1;
        option = pnp_register_independent_option(dev);
-       if (!option)
+       if (!option) {
+               kfree(dev);
                return 1;
+       }
        pnp_add_card_device(card,dev);
 
        while (1) {
@@ -677,8 +647,10 @@ static int __init isapnp_create_device(struct pnp_card *card,
                                size = 0;
                                skip = 0;
                                option = pnp_register_independent_option(dev);
-                               if (!option)
+                               if (!option) {
+                                       kfree(dev);
                                        return 1;
+                               }
                                pnp_add_card_device(card,dev);
                        } else {
                                skip = 1;
@@ -858,7 +830,7 @@ static unsigned char __init isapnp_checksum(unsigned char *data)
 
 static void isapnp_parse_card_id(struct pnp_card * card, unsigned short vendor, unsigned short device)
 {
-       struct pnp_id * id = isapnp_alloc(sizeof(struct pnp_id));
+       struct pnp_id * id = kcalloc(1, sizeof(struct pnp_id), GFP_KERNEL);
        if (!id)
                return;
        sprintf(id->id, "%c%c%c%x%x%x%x",
@@ -894,7 +866,7 @@ static int __init isapnp_build_device_list(void)
                        header[4], header[5], header[6], header[7], header[8]);
                printk(KERN_DEBUG "checksum = 0x%x\n", checksum);
 #endif
-               if ((card = isapnp_alloc(sizeof(struct pnp_card))) == NULL)
+               if ((card = kcalloc(1, sizeof(struct pnp_card), GFP_KERNEL)) == NULL)
                        continue;
 
                card->number = csn;
@@ -932,7 +904,7 @@ int isapnp_cfg_begin(int csn, int logdev)
 {
        if (csn < 1 || csn > isapnp_csn_count || logdev > 10)
                return -EINVAL;
-       down(&isapnp_cfg_mutex);
+       mutex_lock(&isapnp_cfg_mutex);
        isapnp_wait();
        isapnp_key();
        isapnp_wake(csn);
@@ -958,7 +930,7 @@ int isapnp_cfg_begin(int csn, int logdev)
 int isapnp_cfg_end(void)
 {
        isapnp_wait();
-       up(&isapnp_cfg_mutex);
+       mutex_unlock(&isapnp_cfg_mutex);
        return 0;
 }
 
@@ -972,14 +944,10 @@ EXPORT_SYMBOL(isapnp_protocol);
 EXPORT_SYMBOL(isapnp_present);
 EXPORT_SYMBOL(isapnp_cfg_begin);
 EXPORT_SYMBOL(isapnp_cfg_end);
+#if 0
 EXPORT_SYMBOL(isapnp_read_byte);
-EXPORT_SYMBOL(isapnp_read_word);
-EXPORT_SYMBOL(isapnp_read_dword);
+#endif
 EXPORT_SYMBOL(isapnp_write_byte);
-EXPORT_SYMBOL(isapnp_write_word);
-EXPORT_SYMBOL(isapnp_write_dword);
-EXPORT_SYMBOL(isapnp_wake);
-EXPORT_SYMBOL(isapnp_device);
 
 static int isapnp_read_resources(struct pnp_dev *dev, struct pnp_resource_table *res)
 {
@@ -1071,7 +1039,7 @@ struct pnp_protocol isapnp_protocol = {
        .disable = isapnp_disable_resources,
 };
 
-int __init isapnp_init(void)
+static int __init isapnp_init(void)
 {
        int cards;
        struct pnp_card *card;