aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/pnp
diff options
context:
space:
mode:
authorBjorn Helgaas <bjorn.helgaas@hp.com>2008-04-28 18:33:54 -0400
committerLen Brown <len.brown@intel.com>2008-04-29 03:22:16 -0400
commitbda1e4e5a3d976046378cd495a63e1ee0847deec (patch)
treed646e0057940116440d8f2c53ea7fc225d97a0a0 /drivers/pnp
parent25eb846189d20db4114cebf14fee96d69bef4667 (diff)
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: Bjorn Helgaas <bjorn.helgaas@hp.com> Acked-By: Rene Herman <rene.herman@gmail.com> Signed-off-by: Len Brown <len.brown@intel.com>
Diffstat (limited to 'drivers/pnp')
-rw-r--r--drivers/pnp/base.h1
-rw-r--r--drivers/pnp/core.c38
-rw-r--r--drivers/pnp/isapnp/core.c11
-rw-r--r--drivers/pnp/pnpacpi/core.c19
-rw-r--r--drivers/pnp/pnpbios/core.c13
5 files changed, 42 insertions, 40 deletions
diff --git a/drivers/pnp/base.h b/drivers/pnp/base.h
index 9af0a6c7dd41..ff435bd1ca18 100644
--- a/drivers/pnp/base.h
+++ b/drivers/pnp/base.h
@@ -2,6 +2,7 @@ extern spinlock_t pnp_lock;
2void *pnp_alloc(long size); 2void *pnp_alloc(long size);
3#define PNP_EISA_ID_MASK 0x7fffffff 3#define PNP_EISA_ID_MASK 0x7fffffff
4void pnp_eisa_id_to_string(u32 id, char *str); 4void pnp_eisa_id_to_string(u32 id, char *str);
5struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *, int id, char *pnpid);
5struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id); 6struct pnp_id *pnp_add_id(struct pnp_dev *dev, char *id);
6int pnp_interface_attach_device(struct pnp_dev *dev); 7int pnp_interface_attach_device(struct pnp_dev *dev);
7void pnp_fixup_device(struct pnp_dev *dev); 8void pnp_fixup_device(struct pnp_dev *dev);
diff --git a/drivers/pnp/core.c b/drivers/pnp/core.c
index 7d366ca672d3..cf37701a4f9e 100644
--- a/drivers/pnp/core.c
+++ b/drivers/pnp/core.c
@@ -109,15 +109,42 @@ static void pnp_release_device(struct device *dmdev)
109 kfree(dev); 109 kfree(dev);
110} 110}
111 111
112int __pnp_add_device(struct pnp_dev *dev) 112struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid)
113{ 113{
114 int ret; 114 struct pnp_dev *dev;
115 struct pnp_id *dev_id;
115 116
116 pnp_fixup_device(dev); 117 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
118 if (!dev)
119 return NULL;
120
121 dev->protocol = protocol;
122 dev->number = id;
123 dev->dma_mask = DMA_24BIT_MASK;
124
125 dev->dev.parent = &dev->protocol->dev;
117 dev->dev.bus = &pnp_bus_type; 126 dev->dev.bus = &pnp_bus_type;
118 dev->dev.dma_mask = &dev->dma_mask; 127 dev->dev.dma_mask = &dev->dma_mask;
119 dev->dma_mask = dev->dev.coherent_dma_mask = DMA_24BIT_MASK; 128 dev->dev.coherent_dma_mask = dev->dma_mask;
120 dev->dev.release = &pnp_release_device; 129 dev->dev.release = &pnp_release_device;
130
131 sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
132 dev->number);
133
134 dev_id = pnp_add_id(dev, pnpid);
135 if (!dev_id) {
136 kfree(dev);
137 return NULL;
138 }
139
140 return dev;
141}
142
143int __pnp_add_device(struct pnp_dev *dev)
144{
145 int ret;
146
147 pnp_fixup_device(dev);
121 dev->status = PNP_READY; 148 dev->status = PNP_READY;
122 spin_lock(&pnp_lock); 149 spin_lock(&pnp_lock);
123 list_add_tail(&dev->global_list, &pnp_global); 150 list_add_tail(&dev->global_list, &pnp_global);
@@ -145,9 +172,6 @@ int pnp_add_device(struct pnp_dev *dev)
145 if (dev->card) 172 if (dev->card)
146 return -EINVAL; 173 return -EINVAL;
147 174
148 dev->dev.parent = &dev->protocol->dev;
149 sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
150 dev->number);
151 ret = __pnp_add_device(dev); 175 ret = __pnp_add_device(dev);
152 if (ret) 176 if (ret)
153 return ret; 177 return ret;
diff --git a/drivers/pnp/isapnp/core.c b/drivers/pnp/isapnp/core.c
index ccb04190044b..727936a6befb 100644
--- a/drivers/pnp/isapnp/core.c
+++ b/drivers/pnp/isapnp/core.c
@@ -409,18 +409,17 @@ static struct pnp_dev *__init isapnp_parse_device(struct pnp_card *card,
409 char id[8]; 409 char id[8];
410 410
411 isapnp_peek(tmp, size); 411 isapnp_peek(tmp, size);
412 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
413 if (!dev)
414 return NULL;
415 dev->number = number;
416 eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24; 412 eisa_id = tmp[0] | tmp[1] << 8 | tmp[2] << 16 | tmp[3] << 24;
417 pnp_eisa_id_to_string(eisa_id, id); 413 pnp_eisa_id_to_string(eisa_id, id);
418 pnp_add_id(dev, id); 414
415 dev = pnp_alloc_dev(&isapnp_protocol, number, id);
416 if (!dev)
417 return NULL;
418
419 dev->regs = tmp[4]; 419 dev->regs = tmp[4];
420 dev->card = card; 420 dev->card = card;
421 if (size > 5) 421 if (size > 5)
422 dev->regs |= tmp[5] << 8; 422 dev->regs |= tmp[5] << 8;
423 dev->protocol = &isapnp_protocol;
424 dev->capabilities |= PNP_CONFIGURABLE; 423 dev->capabilities |= PNP_CONFIGURABLE;
425 dev->capabilities |= PNP_READ; 424 dev->capabilities |= PNP_READ;
426 dev->capabilities |= PNP_WRITE; 425 dev->capabilities |= PNP_WRITE;
diff --git a/drivers/pnp/pnpacpi/core.c b/drivers/pnp/pnpacpi/core.c
index 86aea1ebfee7..fd3fca6dddd3 100644
--- a/drivers/pnp/pnpacpi/core.c
+++ b/drivers/pnp/pnpacpi/core.c
@@ -152,7 +152,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
152{ 152{
153 acpi_handle temp = NULL; 153 acpi_handle temp = NULL;
154 acpi_status status; 154 acpi_status status;
155 struct pnp_id *dev_id;
156 struct pnp_dev *dev; 155 struct pnp_dev *dev;
157 156
158 status = acpi_get_handle(device->handle, "_CRS", &temp); 157 status = acpi_get_handle(device->handle, "_CRS", &temp);
@@ -160,11 +159,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
160 is_exclusive_device(device)) 159 is_exclusive_device(device))
161 return 0; 160 return 0;
162 161
163 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL); 162 dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
164 if (!dev) { 163 if (!dev)
165 pnp_err("Out of memory");
166 return -ENOMEM; 164 return -ENOMEM;
167 } 165
168 dev->data = device->handle; 166 dev->data = device->handle;
169 /* .enabled means the device can decode the resources */ 167 /* .enabled means the device can decode the resources */
170 dev->active = device->status.enabled; 168 dev->active = device->status.enabled;
@@ -180,19 +178,11 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
180 if (ACPI_SUCCESS(status)) 178 if (ACPI_SUCCESS(status))
181 dev->capabilities |= PNP_DISABLE; 179 dev->capabilities |= PNP_DISABLE;
182 180
183 dev->protocol = &pnpacpi_protocol;
184
185 if (strlen(acpi_device_name(device))) 181 if (strlen(acpi_device_name(device)))
186 strncpy(dev->name, acpi_device_name(device), sizeof(dev->name)); 182 strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
187 else 183 else
188 strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name)); 184 strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
189 185
190 dev->number = num;
191
192 dev_id = pnp_add_id(dev, acpi_device_hid(device));
193 if (!dev_id)
194 goto err;
195
196 if (dev->active) { 186 if (dev->active) {
197 /* parse allocated resource */ 187 /* parse allocated resource */
198 status = pnpacpi_parse_allocated_resource(device->handle, 188 status = pnpacpi_parse_allocated_resource(device->handle,
@@ -230,9 +220,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
230 num++; 220 num++;
231 221
232 return AE_OK; 222 return AE_OK;
233err:
234 kfree(dev);
235 return -EINVAL;
236} 223}
237 224
238static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle, 225static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
diff --git a/drivers/pnp/pnpbios/core.c b/drivers/pnp/pnpbios/core.c
index 3ee5ed437385..6af2be2c1d67 100644
--- a/drivers/pnp/pnpbios/core.c
+++ b/drivers/pnp/pnpbios/core.c
@@ -318,7 +318,6 @@ static int __init insert_device(struct pnp_bios_node *node)
318{ 318{
319 struct list_head *pos; 319 struct list_head *pos;
320 struct pnp_dev *dev; 320 struct pnp_dev *dev;
321 struct pnp_id *dev_id;
322 char id[8]; 321 char id[8];
323 322
324 /* check if the device is already added */ 323 /* check if the device is already added */
@@ -328,18 +327,11 @@ static int __init insert_device(struct pnp_bios_node *node)
328 return -1; 327 return -1;
329 } 328 }
330 329
331 dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
332 if (!dev)
333 return -1;
334
335 pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id); 330 pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
336 dev_id = pnp_add_id(dev, id); 331 dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
337 if (!dev_id) { 332 if (!dev)
338 kfree(dev);
339 return -1; 333 return -1;
340 }
341 334
342 dev->number = node->handle;
343 pnpbios_parse_data_stream(dev, node); 335 pnpbios_parse_data_stream(dev, node);
344 dev->active = pnp_is_active(dev); 336 dev->active = pnp_is_active(dev);
345 dev->flags = node->flags; 337 dev->flags = node->flags;
@@ -352,7 +344,6 @@ static int __init insert_device(struct pnp_bios_node *node)
352 dev->capabilities |= PNP_WRITE; 344 dev->capabilities |= PNP_WRITE;
353 if (dev->flags & PNPBIOS_REMOVABLE) 345 if (dev->flags & PNPBIOS_REMOVABLE)
354 dev->capabilities |= PNP_REMOVABLE; 346 dev->capabilities |= PNP_REMOVABLE;
355 dev->protocol = &pnpbios_protocol;
356 347
357 /* clear out the damaged flags */ 348 /* clear out the damaged flags */
358 if (!dev->active) 349 if (!dev->active)