Skip to content

Commit 25eb846

Browse files
Bjorn Helgaaslenb
authored andcommitted
PNP: add pnp_eisa_id_to_string()
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 <[email protected]> Acked-By: Rene Herman <[email protected]> Signed-off-by: Len Brown <[email protected]>
1 parent 772defc commit 25eb846

File tree

5 files changed

+43
-45
lines changed

5 files changed

+43
-45
lines changed

drivers/pnp/base.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
extern spinlock_t pnp_lock;
22
void *pnp_alloc(long size);
3+
#define PNP_EISA_ID_MASK 0x7fffffff
4+
void pnp_eisa_id_to_string(u32 id, char *str);
35
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
46
int pnp_interface_attach_device(struct pnp_dev *dev);
57
void pnp_fixup_device(struct pnp_dev *dev);

drivers/pnp/isapnp/core.c

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -397,24 +397,6 @@ static void __init isapnp_skip_bytes(int count)
397397
isapnp_peek(NULL, count);
398398
}
399399

400-
/*
401-
* Parse EISA id.
402-
*/
403-
static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
404-
unsigned short device)
405-
{
406-
char id[8];
407-
408-
sprintf(id, "%c%c%c%x%x%x%x",
409-
'A' + ((vendor >> 2) & 0x3f) - 1,
410-
'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
411-
'A' + ((vendor >> 8) & 0x1f) - 1,
412-
(device >> 4) & 0x0f,
413-
device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
414-
415-
pnp_add_id(dev, id);
416-
}
417-
418400
/*
419401
* Parse logical device tag.
420402
*/
@@ -423,13 +405,17 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
423405
{
424406
unsigned char tmp[6];
425407
struct pnp_dev *dev;
408+
u32 eisa_id;
409+
char id[8];
426410

427411
isapnp_peek(tmp, size);
428412
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
429413
if (!dev)
430414
return NULL;
431415
dev->number = number;
432-
isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0], (tmp[3] << 8) | tmp[2]);
416+
eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
417+
pnp_eisa_id_to_string(eisa_id, id);
418+
pnp_add_id(dev, id);
433419
dev->regs = tmp[4];
434420
dev->card = card;
435421
if (size > 5)
@@ -619,6 +605,8 @@ static int __init isapnp_create_device(struct pnp_card *card,
619605
unsigned char type, tmp[17];
620606
struct pnp_option *option;
621607
struct pnp_dev *dev;
608+
u32 eisa_id;
609+
char id[8];
622610

623611
if ((dev = isapnp_parse_device(card, size, number++)) == NULL)
624612
return 1;
@@ -658,8 +646,10 @@ static int __init isapnp_create_device(struct pnp_card *card,
658646
case _STAG_COMPATDEVID:
659647
if (size == 4 && compat < DEVICE_COUNT_COMPATIBLE) {
660648
isapnp_peek(tmp, 4);
661-
isapnp_parse_id(dev, (tmp[1] << 8) | tmp[0],
662-
(tmp[3] << 8) | tmp[2]);
649+
eisa_id = tmp[0] | tmp[1] << 8 |
650+
tmp[2] << 16 | tmp[3] << 24;
651+
pnp_eisa_id_to_string(eisa_id, id);
652+
pnp_add_id(dev, id);
663653
compat++;
664654
size = 0;
665655
}

drivers/pnp/pnpbios/core.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -332,7 +332,7 @@ static int __init insert_device(struct pnp_bios_node *node)
332332
if (!dev)
333333
return -1;
334334

335-
pnpid32_to_pnpid(node->eisa_id, id);
335+
pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
336336
dev_id = pnp_add_id(dev, id);
337337
if (!dev_id) {
338338
kfree(dev);

drivers/pnp/pnpbios/rsparser.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -494,32 +494,12 @@ pnpbios_parse_resource_option_data(unsigned char *p, unsigned char *end,
494494
* Compatible Device IDs
495495
*/
496496

497-
#define HEX(id,a) hex[((id)>>a) & 15]
498-
#define CHAR(id,a) (0x40 + (((id)>>a) & 31))
499-
500-
void pnpid32_to_pnpid(u32 id, char *str)
501-
{
502-
const char *hex = "0123456789abcdef";
503-
504-
id = be32_to_cpu(id);
505-
str[0] = CHAR(id, 26);
506-
str[1] = CHAR(id, 21);
507-
str[2] = CHAR(id, 16);
508-
str[3] = HEX(id, 12);
509-
str[4] = HEX(id, 8);
510-
str[5] = HEX(id, 4);
511-
str[6] = HEX(id, 0);
512-
str[7] = '\0';
513-
}
514-
515-
#undef CHAR
516-
#undef HEX
517-
518497
static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
519498
unsigned char *end,
520499
struct pnp_dev *dev)
521500
{
522501
int len, tag;
502+
u32 eisa_id;
523503
char id[8];
524504
struct pnp_id *dev_id;
525505

@@ -549,8 +529,8 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
549529
case SMALL_TAG_COMPATDEVID: /* compatible ID */
550530
if (len != 4)
551531
goto len_err;
552-
pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
553-
24, id);
532+
eisa_id = p[1] | p[2] << 8 | p[3] << 16 | p[4] << 24;
533+
pnp_eisa_id_to_string(eisa_id & PNP_EISA_ID_MASK, id);
554534
dev_id = pnp_add_id(dev, id);
555535
if (!dev_id)
556536
return NULL;

drivers/pnp/support.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,29 @@ int pnp_is_active(struct pnp_dev *dev)
2525
}
2626

2727
EXPORT_SYMBOL(pnp_is_active);
28+
29+
/*
30+
* Functionally similar to acpi_ex_eisa_id_to_string(), but that's
31+
* buried in the ACPI CA, and we can't depend on it being present.
32+
*/
33+
void pnp_eisa_id_to_string(u32 id, char *str)
34+
{
35+
id = be32_to_cpu(id);
36+
37+
/*
38+
* According to the specs, the first three characters are five-bit
39+
* compressed ASCII, and the left-over high order bit should be zero.
40+
* However, the Linux ISAPNP code historically used six bits for the
41+
* first character, and there seem to be IDs that depend on that,
42+
* e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
43+
* FreeBSD sys/pc98/cbus/sio_cbus.c driver.
44+
*/
45+
str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
46+
str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
47+
str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
48+
str[3] = hex_asc((id >> 12) & 0xf);
49+
str[4] = hex_asc((id >> 8) & 0xf);
50+
str[5] = hex_asc((id >> 4) & 0xf);
51+
str[6] = hex_asc((id >> 0) & 0xf);
52+
str[7] = '\0';
53+
}

0 commit comments

Comments
 (0)