PNP: add pnp_eisa_id_to_string()
authorBjorn Helgaas <bjorn.helgaas@hp.com>
Mon, 28 Apr 2008 22:33:53 +0000 (16:33 -0600)
committerLen Brown <len.brown@intel.com>
Tue, 29 Apr 2008 07:22:16 +0000 (03:22 -0400)
Converting the EISA ID to a string is messy and error-prone, and
we might as well use the same code for ISAPNP and PNPBIOS.

PNPACPI uses the conversion done by the ACPI core with
acpi_ex_eisa_id_to_string().

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
drivers/pnp/base.h
drivers/pnp/isapnp/core.c
drivers/pnp/pnpbios/core.c
drivers/pnp/pnpbios/rsparser.c
drivers/pnp/support.c

index ba55b0623f7e69792a50019f2965493dda21c663..9af0a6c7dd414fd45e8396ad0711bdcd41d0d45f 100644 (file)
@@ -1,5 +1,7 @@
 extern spinlock_t pnp_lock;
 void *pnp_alloc(long size);
+#define PNP_EISA_ID_MASK 0x7fffffff
+void pnp_eisa_id_to_string(u32 id, char *str);
 struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
 int pnp_interface_attach_device(struct pnp_dev *dev);
 void pnp_fixup_device(struct pnp_dev *dev);
index 10cade831433b15a159a38707c1c8b55e0d675b7..ccb04190044ba631967c46a828deaa8a67caff38 100644 (file)
@@ -397,24 +397,6 @@ static void __init isapnp_skip_bytes(int count)
        isapnp_peek(NULL, count);
 }
 
-/*
- *  Parse EISA id.
- */
-static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
-                           unsigned short device)
-{
-       char id[8];
-
-       sprintf(id, "%c%c%c%x%x%x%x",
-               'A' + ((vendor >> 2) & 0x3f) - 1,
-               'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
-               'A' + ((vendor >> 8) & 0x1f) - 1,
-               (device >> 4) & 0x0f,
-               device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
-
-       pnp_add_id(dev, id);
-}
-
 /*
  *  Parse logical device tag.
  */
@@ -423,13 +405,17 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
 {
        unsigned char tmp[6];
        struct pnp_dev *dev;
+       u32 eisa_id;
+       char id[8];
 
        isapnp_peek(tmp, size);
        dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
        if (!dev)
                return NULL;
        dev->number = number;
-       isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
+       eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
+       pnp_eisa_id_to_string(eisa_id, id);
+       pnp_add_id(dev, id);
        dev->regs = tmp[4];
        dev->card = card;
        if (size > 5)
@@ -619,6 +605,8 @@ static int __init isapnp_create_device(struct pnp_card *card,
        unsigned char type, tmp[17];
        struct pnp_option *option;
        struct pnp_dev *dev;
+       u32 eisa_id;
+       char id[8];
 
        if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
                return 1;
@@ -658,8 +646,10 @@ static int __init isapnp_create_device(struct pnp_card *card,
                case _STAG_COMPATDEVID:
                        if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
                                isapnp_peek(tmp, 4);
-                               isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0],
-                                               (tmp[3] << 8) | tmp[2]);
+                               eisa_id = tmp[0] | tmp[1] << 8 |
+                                         tmp[2] << 16 | tmp[3] << 24;
+                               pnp_eisa_id_to_string(eisa_id, id);
+                               pnp_add_id(dev, id);
                                compat++;
                                size = 0;
                        }
index 2d592aea0aa773c8ffb0bee76465017d5009e785..3ee5ed4373857baee11c8d3b6db9b40f8e1792bc 100644 (file)
@@ -332,7 +332,7 @@ static int __init insert_device(struct pnp_bios_node *node)
        if (!dev)
                return -1;
 
-       pnpid32_to_pnpid(node->eisa_id, id);
+       pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
        dev_id = pnp_add_id(dev, id);
        if (!dev_id) {
                kfree(dev);
index dbc88412c12efcca8631028bf9bbf913fd3806da..948a661280d767cd7b56f353d91fea8dd3d8fe74 100644 (file)
@@ -494,32 +494,12 @@ len_err:
  * Compatible Device IDs
  */
 
-#define HEX(id,a) hex[((id)>>a) & 15]
-#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
-
-void pnpid32_to_pnpid(u32 id, char *str)
-{
-       const char *hex = "0123456789abcdef";
-
-       id = be32_to_cpu(id);
-       str[0] = CHAR(id, 26);
-       str[1] = CHAR(id, 21);
-       str[2] = CHAR(id, 16);
-       str[3] = HEX(id, 12);
-       str[4] = HEX(id, 8);
-       str[5] = HEX(id, 4);
-       str[6] = HEX(id, 0);
-       str[7] = '\0';
-}
-
-#undef CHAR
-#undef HEX
-
 static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
                                                   unsigned char *end,
                                                   struct pnp_dev *dev)
 {
        int len, tag;
+       u32 eisa_id;
        char id[8];
        struct pnp_id *dev_id;
 
@@ -549,8 +529,8 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
                case SMALL_TAG_COMPATDEVID:     /* compatible ID */
                        if (len != 4)
                                goto len_err;
-                       pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
-                                        24, id);
+                       eisa_id = p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24;
+                       pnp_eisa_id_to_string(eisa_id & PNP_EISA_ID_MASK, id);
                        dev_id = pnp_add_id(dev, id);
                        if (!dev_id)
                                return NULL;
index 13c608f5fb302864b7bae16defaf2d95365ea815..e848b794e31293c0591c5e728309bc41cf5c2be9 100644 (file)
@@ -25,3 +25,29 @@ int pnp_is_active(struct pnp_dev *dev)
 }
 
 EXPORT_SYMBOL(pnp_is_active);
+
+/*
+ * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
+ * buried in the ACPI CA, and we can't depend on it being present.
+ */
+void pnp_eisa_id_to_string(u32 id, char *str)
+{
+       id = be32_to_cpu(id);
+
+       /*
+        * According to the specs, the first three characters are five-bit
+        * compressed ASCII, and the left-over high order bit should be zero.
+        * However, the Linux ISAPNP code historically used six bits for the
+        * first character, and there seem to be IDs that depend on that,
+        * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
+        * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
+        */
+       str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
+       str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
+       str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
+       str[3] = hex_asc((id >> 12) & 0xf);
+       str[4] = hex_asc((id >>  8) & 0xf);
+       str[5] = hex_asc((id >>  4) & 0xf);
+       str[6] = hex_asc((id >>  0) & 0xf);
+       str[7] = '\0';
+}