Commit bda1e4e5 authored by Bjorn Helgaas's avatar Bjorn Helgaas Committed by Len Brown

PNP: add pnp_alloc_dev()

Add pnp_alloc_dev() to allocate a struct pnp_dev and fill in the
protocol, instance number, and initial PNP ID.  Now it is always
valid to use dev_printk() on any pnp_dev pointer.
Signed-off-by: default avatarBjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: default avatarRene Herman <rene.herman@gmail.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
parent 25eb8461
...@@ -2,6 +2,7 @@ extern spinlock_t pnp_lock; ...@@ -2,6 +2,7 @@ extern spinlock_t pnp_lock;
void *pnp_alloc(long size); void *pnp_alloc(long size);
#define PNP_EISA_ID_MASK 0x7fffffff #define PNP_EISA_ID_MASK 0x7fffffff
void pnp_eisa_id_to_string(u32 id, char *str); void pnp_eisa_id_to_string(u32 id, char *str);
struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id); 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);
......
...@@ -109,15 +109,42 @@ static void pnp_release_device(struct device *dmdev) ...@@ -109,15 +109,42 @@ static void pnp_release_device(struct device *dmdev)
kfree(dev); kfree(dev);
} }
int __pnp_add_device(struct pnp_dev *dev) struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
{ {
int ret; struct pnp_dev *dev;
struct pnp_id *dev_id;
pnp_fixup_device(dev); dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
if (!dev)
return NULL;
dev->protocol = protocol;
dev->number = id;
dev->dma_mask = DMA_24BIT_MASK;
dev->dev.parent = &dev->protocol->dev;
dev->dev.bus = &pnp_bus_type; dev->dev.bus = &pnp_bus_type;
dev->dev.dma_mask = &dev->dma_mask; dev->dev.dma_mask = &dev->dma_mask;
dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK; dev->dev.coherent_dma_mask = dev->dma_mask;
dev->dev.release = &pnp_release_device; dev->dev.release = &pnp_release_device;
sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
dev->number);
dev_id = pnp_add_id(dev, pnpid);
if (!dev_id) {
kfree(dev);
return NULL;
}
return dev;
}
int __pnp_add_device(struct pnp_dev *dev)
{
int ret;
pnp_fixup_device(dev);
dev->status = PNP_READY; dev->status = PNP_READY;
spin_lock(&pnp_lock); spin_lock(&pnp_lock);
list_add_tail(&dev->global_list, &pnp_global); list_add_tail(&dev->global_list, &pnp_global);
...@@ -145,9 +172,6 @@ int pnp_add_device(struct pnp_dev *dev) ...@@ -145,9 +172,6 @@ int pnp_add_device(struct pnp_dev *dev)
if (dev->card) if (dev->card)
return -EINVAL; return -EINVAL;
dev->dev.parent = &dev->protocol->dev;
sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
dev->number);
ret = __pnp_add_device(dev); ret = __pnp_add_device(dev);
if (ret) if (ret)
return ret; return ret;
......
...@@ -409,18 +409,17 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card, ...@@ -409,18 +409,17 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
char id[8]; char id[8];
isapnp_peek(tmp, size); isapnp_peek(tmp, size);
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
if (!dev)
return NULL;
dev->number = number;
eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24; eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
pnp_eisa_id_to_string(eisa_id, id); pnp_eisa_id_to_string(eisa_id, id);
pnp_add_id(dev, id);
dev = pnp_alloc_dev(&isapnp_protocol, number, id);
if (!dev)
return NULL;
dev->regs = tmp[4]; dev->regs = tmp[4];
dev->card = card; dev->card = card;
if (size > 5) if (size > 5)
dev->regs |= tmp[5] << 8; dev->regs |= tmp[5] << 8;
dev->protocol = &isapnp_protocol;
dev->capabilities |= PNP_CONFIGURABLE; dev->capabilities |= PNP_CONFIGURABLE;
dev->capabilities |= PNP_READ; dev->capabilities |= PNP_READ;
dev->capabilities |= PNP_WRITE; dev->capabilities |= PNP_WRITE;
......
...@@ -152,7 +152,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device) ...@@ -152,7 +152,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
{ {
acpi_handle temp = NULL; acpi_handle temp = NULL;
acpi_status status; acpi_status status;
struct pnp_id *dev_id;
struct pnp_dev *dev; struct pnp_dev *dev;
status = acpi_get_handle(device->handle, "_CRS", &temp); status = acpi_get_handle(device->handle, "_CRS", &temp);
...@@ -160,11 +159,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device) ...@@ -160,11 +159,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
is_exclusive_device(device)) is_exclusive_device(device))
return 0; return 0;
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
if (!dev) { if (!dev)
pnp_err("Out of memory");
return -ENOMEM; return -ENOMEM;
}
dev->data = device->handle; dev->data = device->handle;
/* .enabled means the device can decode the resources */ /* .enabled means the device can decode the resources */
dev->active = device->status.enabled; dev->active = device->status.enabled;
...@@ -180,19 +178,11 @@ static int __init pnpacpi_add_device(struct acpi_device *device) ...@@ -180,19 +178,11 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
if (ACPI_SUCCESS(status)) if (ACPI_SUCCESS(status))
dev->capabilities |= PNP_DISABLE; dev->capabilities |= PNP_DISABLE;
dev->protocol = &pnpacpi_protocol;
if (strlen(acpi_device_name(device))) if (strlen(acpi_device_name(device)))
strncpy(dev->name, acpi_device_name(device), sizeof(dev->name)); strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
else else
strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name)); strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
dev->number = num;
dev_id = pnp_add_id(dev, acpi_device_hid(device));
if (!dev_id)
goto err;
if (dev->active) { if (dev->active) {
/* parse allocated resource */ /* parse allocated resource */
status = pnpacpi_parse_allocated_resource(device->handle, status = pnpacpi_parse_allocated_resource(device->handle,
...@@ -230,9 +220,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device) ...@@ -230,9 +220,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
num++; num++;
return AE_OK; return AE_OK;
err:
kfree(dev);
return -EINVAL;
} }
static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
......
...@@ -318,7 +318,6 @@ static int __init insert_device(struct pnp_bios_node *node) ...@@ -318,7 +318,6 @@ static int __init insert_device(struct pnp_bios_node *node)
{ {
struct list_head *pos; struct list_head *pos;
struct pnp_dev *dev; struct pnp_dev *dev;
struct pnp_id *dev_id;
char id[8]; char id[8];
/* check if the device is already added */ /* check if the device is already added */
...@@ -328,18 +327,11 @@ static int __init insert_device(struct pnp_bios_node *node) ...@@ -328,18 +327,11 @@ static int __init insert_device(struct pnp_bios_node *node)
return -1; return -1;
} }
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
if (!dev)
return -1;
pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id); pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
dev_id = pnp_add_id(dev, id); dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
if (!dev_id) { if (!dev)
kfree(dev);
return -1; return -1;
}
dev->number = node->handle;
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;
...@@ -352,7 +344,6 @@ static int __init insert_device(struct pnp_bios_node *node) ...@@ -352,7 +344,6 @@ static int __init insert_device(struct pnp_bios_node *node)
dev->capabilities |= PNP_WRITE; dev->capabilities |= PNP_WRITE;
if (dev->flags & PNPBIOS_REMOVABLE) if (dev->flags & PNPBIOS_REMOVABLE)
dev->capabilities |= PNP_REMOVABLE; dev->capabilities |= PNP_REMOVABLE;
dev->protocol = &pnpbios_protocol;
/* clear out the damaged flags */ /* clear out the damaged flags */
if (!dev->active) if (!dev->active)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment