PNP: change pnp_add_id() to allocate its own pnp_id structures

This moves some of the pnp_id knowledge out of the backends and into
the PNP core.

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>
This commit is contained in:
Bjorn Helgaas 2008-04-28 16:33:52 -06:00 committed by Len Brown
parent 1692b27bf3
commit 772defc629
6 changed files with 36 additions and 48 deletions

View File

@ -1,6 +1,6 @@
extern spinlock_t pnp_lock; extern spinlock_t pnp_lock;
void *pnp_alloc(long size); void *pnp_alloc(long size);
int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev); struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
int pnp_interface_attach_device(struct pnp_dev *dev); int pnp_interface_attach_device(struct pnp_dev *dev);
void pnp_fixup_device(struct pnp_dev *dev); void pnp_fixup_device(struct pnp_dev *dev);
void pnp_free_option(struct pnp_option *option); void pnp_free_option(struct pnp_option *option);

View File

@ -226,22 +226,36 @@ void pnp_unregister_driver(struct pnp_driver *drv)
/** /**
* pnp_add_id - adds an EISA id to the specified device * pnp_add_id - adds an EISA id to the specified device
* @id: pointer to a pnp_id structure
* @dev: pointer to the desired device * @dev: pointer to the desired device
* @id: pointer to an EISA id string
*/ */
int pnp_add_id(struct pnp_id *id, struct pnp_dev *dev) struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id)
{ {
struct pnp_id *ptr; struct pnp_id *dev_id, *ptr;
id->next = NULL; dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!dev_id)
return NULL;
dev_id->id[0] = id[0];
dev_id->id[1] = id[1];
dev_id->id[2] = id[2];
dev_id->id[3] = tolower(id[3]);
dev_id->id[4] = tolower(id[4]);
dev_id->id[5] = tolower(id[5]);
dev_id->id[6] = tolower(id[6]);
dev_id->id[7] = '\0';
dev_id->next = NULL;
ptr = dev->id; ptr = dev->id;
while (ptr && ptr->next) while (ptr && ptr->next)
ptr = ptr->next; ptr = ptr->next;
if (ptr) if (ptr)
ptr->next = id; ptr->next = dev_id;
else else
dev->id = id; dev->id = dev_id;
return 0;
return dev_id;
} }
EXPORT_SYMBOL(pnp_register_driver); EXPORT_SYMBOL(pnp_register_driver);

View File

@ -44,6 +44,8 @@
#include <linux/mutex.h> #include <linux/mutex.h>
#include <asm/io.h> #include <asm/io.h>
#include "../base.h"
#if 0 #if 0
#define ISAPNP_REGION_OK #define ISAPNP_REGION_OK
#endif #endif
@ -401,20 +403,16 @@ static void __init isapnp_skip_bytes(int count)
static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor, static void isapnp_parse_id(struct pnp_dev *dev, unsigned short vendor,
unsigned short device) unsigned short device)
{ {
struct pnp_id *id; char id[8];
if (!dev) sprintf(id, "%c%c%c%x%x%x%x",
return;
id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!id)
return;
sprintf(id->id, "%c%c%c%x%x%x%x",
'A' + ((vendor >> 2) & 0x3f) - 1, 'A' + ((vendor >> 2) & 0x3f) - 1,
'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1, 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1,
'A' + ((vendor >> 8) & 0x1f) - 1, 'A' + ((vendor >> 8) & 0x1f) - 1,
(device >> 4) & 0x0f, (device >> 4) & 0x0f,
device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f); device & 0x0f, (device >> 12) & 0x0f, (device >> 8) & 0x0f);
pnp_add_id(id, dev);
pnp_add_id(dev, id);
} }
/* /*

View File

@ -73,18 +73,6 @@ static int __init ispnpidacpi(char *id)
return 1; return 1;
} }
static void __init pnpidacpi_to_pnpid(char *id, char *str)
{
str[0] = id[0];
str[1] = id[1];
str[2] = id[2];
str[3] = tolower(id[3]);
str[4] = tolower(id[4]);
str[5] = tolower(id[5]);
str[6] = tolower(id[6]);
str[7] = '\0';
}
static int pnpacpi_get_resources(struct pnp_dev *dev, static int pnpacpi_get_resources(struct pnp_dev *dev,
struct pnp_resource_table *res) struct pnp_resource_table *res)
{ {
@ -201,12 +189,9 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
dev->number = num; dev->number = num;
/* set the initial values for the PnP device */ dev_id = pnp_add_id(dev, acpi_device_hid(device));
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!dev_id) if (!dev_id)
goto err; goto err;
pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
pnp_add_id(dev_id, dev);
if (dev->active) { if (dev->active) {
/* parse allocated resource */ /* parse allocated resource */
@ -227,7 +212,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
} }
} }
/* parse compatible ids */
if (device->flags.compatible_ids) { if (device->flags.compatible_ids) {
struct acpi_compatible_id_list *cid_list = device->pnp.cid_list; struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
int i; int i;
@ -235,12 +219,7 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
for (i = 0; i < cid_list->count; i++) { for (i = 0; i < cid_list->count; i++) {
if (!ispnpidacpi(cid_list->id[i].value)) if (!ispnpidacpi(cid_list->id[i].value))
continue; continue;
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); pnp_add_id(dev, cid_list->id[i].value);
if (!dev_id)
continue;
pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
pnp_add_id(dev_id, dev);
} }
} }

View File

@ -332,16 +332,14 @@ static int __init insert_device(struct pnp_bios_node *node)
if (!dev) if (!dev)
return -1; return -1;
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL); pnpid32_to_pnpid(node->eisa_id, id);
dev_id = pnp_add_id(dev, id);
if (!dev_id) { if (!dev_id) {
kfree(dev); kfree(dev);
return -1; return -1;
} }
dev->number = node->handle; dev->number = node->handle;
pnpid32_to_pnpid(node->eisa_id, id);
memcpy(dev_id->id, id, 7);
pnp_add_id(dev_id, dev);
pnpbios_parse_data_stream(dev, node); pnpbios_parse_data_stream(dev, node);
dev->active = pnp_is_active(dev); dev->active = pnp_is_active(dev);
dev->flags = node->flags; dev->flags = node->flags;

View File

@ -16,6 +16,7 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
} }
#endif /* CONFIG_PCI */ #endif /* CONFIG_PCI */
#include "../base.h"
#include "pnpbios.h" #include "pnpbios.h"
/* standard resource tags */ /* standard resource tags */
@ -548,13 +549,11 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
case SMALL_TAG_COMPATDEVID: /* compatible ID */ case SMALL_TAG_COMPATDEVID: /* compatible ID */
if (len != 4) if (len != 4)
goto len_err; goto len_err;
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!dev_id)
return NULL;
pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] << pnpid32_to_pnpid(p[1] | p[2] << 8 | p[3] << 16 | p[4] <<
24, id); 24, id);
memcpy(&dev_id->id, id, 7); dev_id = pnp_add_id(dev, id);
pnp_add_id(dev_id, dev); if (!dev_id)
return NULL;
break; break;
case SMALL_TAG_END: case SMALL_TAG_END: