Commit 008238b5 authored by Len Brown's avatar Len Brown

Merge branch 'pnp' into release

parents 96916090 dfd2e1b4
extern spinlock_t pnp_lock;
void *pnp_alloc(long size);
int pnp_register_protocol(struct pnp_protocol *protocol);
void pnp_unregister_protocol(struct pnp_protocol *protocol);
#define PNP_EISA_ID_MASK 0x7fffffff
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_card *pnp_alloc_card(struct pnp_protocol *, int id, char *pnpid);
int pnp_add_device(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_add_card(struct pnp_card *card);
struct pnp_id *pnp_add_card_id(struct pnp_card *card, char *id);
void pnp_remove_card(struct pnp_card *card);
int pnp_add_card_device(struct pnp_card *card, struct pnp_dev *dev);
void pnp_remove_card_device(struct pnp_dev *dev);
struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev);
struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev,
int priority);
int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option,
struct pnp_irq *data);
int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option,
struct pnp_dma *data);
int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option,
struct pnp_port *data);
int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option,
struct pnp_mem *data);
void pnp_init_resources(struct pnp_dev *dev);
void pnp_fixup_device(struct pnp_dev *dev);
void pnp_free_option(struct pnp_option *option);
int __pnp_add_device(struct pnp_dev *dev);
void __pnp_remove_device(struct pnp_dev *dev);
int pnp_check_port(struct pnp_dev * dev, int idx);
int pnp_check_mem(struct pnp_dev * dev, int idx);
int pnp_check_irq(struct pnp_dev * dev, int idx);
int pnp_check_dma(struct pnp_dev * dev, int idx);
int pnp_check_port(struct pnp_dev *dev, struct resource *res);
int pnp_check_mem(struct pnp_dev *dev, struct resource *res);
int pnp_check_irq(struct pnp_dev *dev, struct resource *res);
int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
void pnp_init_resource(struct resource *res);
struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
unsigned int type, unsigned int num);
#define PNP_MAX_PORT 40
#define PNP_MAX_MEM 24
#define PNP_MAX_IRQ 2
#define PNP_MAX_DMA 2
struct pnp_resource {
struct resource res;
unsigned int index; /* ISAPNP config register index */
};
struct pnp_resource_table {
struct pnp_resource port[PNP_MAX_PORT];
struct pnp_resource mem[PNP_MAX_MEM];
struct pnp_resource dma[PNP_MAX_DMA];
struct pnp_resource irq[PNP_MAX_IRQ];
};
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
int flags);
struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
int flags);
struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
resource_size_t start,
resource_size_t end, int flags);
struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
resource_size_t start,
resource_size_t end, int flags);
......@@ -5,6 +5,7 @@
*/
#include <linux/module.h>
#include <linux/ctype.h>
#include <linux/slab.h>
#include <linux/pnp.h>
#include "base.h"
......@@ -100,19 +101,33 @@ static int card_probe(struct pnp_card *card, struct pnp_card_driver *drv)
* @id: pointer to a pnp_id structure
* @card: pointer to the desired card
*/
int pnp_add_card_id(struct pnp_id *id, struct pnp_card *card)
struct pnp_id *pnp_add_card_id(struct pnp_card *card, 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 = card->id;
while (ptr && ptr->next)
ptr = ptr->next;
if (ptr)
ptr->next = id;
ptr->next = dev_id;
else
card->id = id;
return 0;
card->id = dev_id;
return dev_id;
}
static void pnp_free_card_ids(struct pnp_card *card)
......@@ -136,6 +151,31 @@ static void pnp_release_card(struct device *dmdev)
kfree(card);
}
struct pnp_card *pnp_alloc_card(struct pnp_protocol *protocol, int id, char *pnpid)
{
struct pnp_card *card;
struct pnp_id *dev_id;
card = kzalloc(sizeof(struct pnp_card), GFP_KERNEL);
if (!card)
return NULL;
card->protocol = protocol;
card->number = id;
card->dev.parent = &card->protocol->dev;
sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
card->number);
dev_id = pnp_add_card_id(card, pnpid);
if (!dev_id) {
kfree(card);
return NULL;
}
return card;
}
static ssize_t pnp_show_card_name(struct device *dmdev,
struct device_attribute *attr, char *buf)
{
......@@ -191,9 +231,6 @@ int pnp_add_card(struct pnp_card *card)
int error;
struct list_head *pos, *temp;
sprintf(card->dev.bus_id, "%02x:%02x", card->protocol->number,
card->number);
card->dev.parent = &card->protocol->dev;
card->dev.bus = NULL;
card->dev.release = &pnp_release_card;
error = device_register(&card->dev);
......
......@@ -106,18 +106,53 @@ static void pnp_release_device(struct device *dmdev)
pnp_free_option(dev->independent);
pnp_free_option(dev->dependent);
pnp_free_ids(dev);
kfree(dev->res);
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->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL);
if (!dev->res) {
kfree(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.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;
sprintf(dev->dev.bus_id, "%02x:%02x", dev->protocol->number,
dev->number);
dev_id = pnp_add_id(dev, pnpid);
if (!dev_id) {
kfree(dev->res);
kfree(dev);
return NULL;
}
return dev;
}
int __pnp_add_device(struct pnp_dev *dev)
{
int ret;
pnp_fixup_device(dev);
dev->status = PNP_READY;
spin_lock(&pnp_lock);
list_add_tail(&dev->global_list, &pnp_global);
......@@ -145,9 +180,6 @@ int pnp_add_device(struct pnp_dev *dev)
if (dev->card)
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);
if (ret)
return ret;
......
......@@ -226,22 +226,36 @@ void pnp_unregister_driver(struct pnp_driver *drv)
/**
* pnp_add_id - adds an EISA id to the specified device
* @id: pointer to a pnp_id structure
* @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;
while (ptr && ptr->next)
ptr = ptr->next;
if (ptr)
ptr->next = id;
ptr->next = dev_id;
else
dev->id = id;
return 0;
dev->id = dev_id;
return dev_id;
}
EXPORT_SYMBOL(pnp_register_driver);
......
......@@ -248,6 +248,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
char *buf)
{
struct pnp_dev *dev = to_pnp_dev(dmdev);
struct resource *res;
int i, ret;
pnp_info_buffer_t *buffer;
......@@ -267,50 +268,46 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
else
pnp_printf(buffer, "disabled\n");
for (i = 0; i < PNP_MAX_PORT; i++) {
if (pnp_port_valid(dev, i)) {
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "io");
if (pnp_port_flags(dev, i) & IORESOURCE_DISABLED)
if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n");
else
pnp_printf(buffer, " 0x%llx-0x%llx\n",
(unsigned long long)
pnp_port_start(dev, i),
(unsigned long long)pnp_port_end(dev,
i));
(unsigned long long) res->start,
(unsigned long long) res->end);
}
}
for (i = 0; i < PNP_MAX_MEM; i++) {
if (pnp_mem_valid(dev, i)) {
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "mem");
if (pnp_mem_flags(dev, i) & IORESOURCE_DISABLED)
if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n");
else
pnp_printf(buffer, " 0x%llx-0x%llx\n",
(unsigned long long)
pnp_mem_start(dev, i),
(unsigned long long)pnp_mem_end(dev,
i));
(unsigned long long) res->start,
(unsigned long long) res->end);
}
}
for (i = 0; i < PNP_MAX_IRQ; i++) {
if (pnp_irq_valid(dev, i)) {
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "irq");
if (pnp_irq_flags(dev, i) & IORESOURCE_DISABLED)
if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n");
else
pnp_printf(buffer, " %lld\n",
(unsigned long long)pnp_irq(dev, i));
(unsigned long long) res->start);
}
}
for (i = 0; i < PNP_MAX_DMA; i++) {
if (pnp_dma_valid(dev, i)) {
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "dma");
if (pnp_dma_flags(dev, i) & IORESOURCE_DISABLED)
if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n");
else
pnp_printf(buffer, " %lld\n",
(unsigned long long)pnp_dma(dev, i));
(unsigned long long) res->start);
}
}
ret = (buffer->curr - buf);
......@@ -323,8 +320,10 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
const char *ubuf, size_t count)
{
struct pnp_dev *dev = to_pnp_dev(dmdev);
struct pnp_resource *pnp_res;
char *buf = (void *)ubuf;
int retval = 0;
resource_size_t start, end;
if (dev->status & PNP_ATTACHED) {
retval = -EBUSY;
......@@ -351,20 +350,20 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
if (!strnicmp(buf, "auto", 4)) {
if (dev->active)
goto done;
pnp_init_resource_table(&dev->res);
pnp_init_resources(dev);
retval = pnp_auto_config_dev(dev);
goto done;
}
if (!strnicmp(buf, "clear", 5)) {
if (dev->active)
goto done;
pnp_init_resource_table(&dev->res);
pnp_init_resources(dev);
goto done;
}
if (!strnicmp(buf, "get", 3)) {
mutex_lock(&pnp_res_mutex);
if (pnp_can_read(dev))
dev->protocol->get(dev, &dev->res);
dev->protocol->get(dev);
mutex_unlock(&pnp_res_mutex);
goto done;
}
......@@ -373,7 +372,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
if (dev->active)
goto done;
buf += 3;
pnp_init_resource_table(&dev->res);
pnp_init_resources(dev);
mutex_lock(&pnp_res_mutex);
while (1) {
while (isspace(*buf))
......@@ -382,76 +381,60 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
buf += 2;
while (isspace(*buf))
++buf;
dev->res.port_resource[nport].start =
simple_strtoul(buf, &buf, 0);
start = simple_strtoul(buf, &buf, 0);
while (isspace(*buf))
++buf;
if (*buf == '-') {
buf += 1;
while (isspace(*buf))
++buf;
dev->res.port_resource[nport].end =
simple_strtoul(buf, &buf, 0);
end = simple_strtoul(buf, &buf, 0);
} else
dev->res.port_resource[nport].end =
dev->res.port_resource[nport].start;
dev->res.port_resource[nport].flags =
IORESOURCE_IO;
nport++;
if (nport >= PNP_MAX_PORT)
break;
end = start;
pnp_res = pnp_add_io_resource(dev, start, end,
0);
if (pnp_res)
pnp_res->index = nport++;
continue;
}
if (!strnicmp(buf, "mem", 3)) {
buf += 3;
while (isspace(*buf))
++buf;
dev->res.mem_resource[nmem].start =
simple_strtoul(buf, &buf, 0);
start = simple_strtoul(buf, &buf, 0);
while (isspace(*buf))
++buf;
if (*buf == '-') {
buf += 1;
while (isspace(*buf))
++buf;
dev->res.mem_resource[nmem].end =
simple_strtoul(buf, &buf, 0);
end = simple_strtoul(buf, &buf, 0);
} else
dev->res.mem_resource[nmem].end =
dev->res.mem_resource[nmem].start;
dev->res.mem_resource[nmem].flags =
IORESOURCE_MEM;
nmem++;
if (nmem >= PNP_MAX_MEM)
break;
end = start;
pnp_res = pnp_add_mem_resource(dev, start, end,
0);
if (pnp_res)
pnp_res->index = nmem++;
continue;
}
if (!strnicmp(buf, "irq", 3)) {
buf += 3;
while (isspace(*buf))
++buf;
dev->res.irq_resource[nirq].start =
dev->res.irq_resource[nirq].end =
simple_strtoul(buf, &buf, 0);
dev->res.irq_resource[nirq].flags =
IORESOURCE_IRQ;
start = simple_strtoul(buf, &buf, 0);
pnp_res = pnp_add_irq_resource(dev, start, 0);
if (pnp_res)
nirq++;
if (nirq >= PNP_MAX_IRQ)
break;
continue;
}
if (!strnicmp(buf, "dma", 3)) {
buf += 3;
while (isspace(*buf))
++buf;
dev->res.dma_resource[ndma].start =
dev->res.dma_resource[ndma].end =
simple_strtoul(buf, &buf, 0);
dev->res.dma_resource[ndma].flags =
IORESOURCE_DMA;
ndma++;
if (ndma >= PNP_MAX_DMA)
break;
start = simple_strtoul(buf, &buf, 0);
pnp_res = pnp_add_dma_resource(dev, start, 0);
if (pnp_res)
pnp_res->index = ndma++;
continue;
}
break;
......
......@@ -5,3 +5,7 @@
isapnp-proc-$(CONFIG_PROC_FS) = proc.o
obj-y := core.o compat.o $(isapnp-proc-y)
ifeq ($(CONFIG_PNP_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
This diff is collapsed.
This diff is collapsed.
......@@ -3,3 +3,7 @@
#
obj-y := core.o rsparser.o
ifeq ($(CONFIG_PNP_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
......@@ -25,6 +25,7 @@
#include <acpi/acpi_bus.h>
#include <acpi/actypes.h>
#include "../base.h"
#include "pnpacpi.h"
static int num = 0;
......@@ -72,40 +73,24 @@ static int __init ispnpidacpi(char *id)
return 1;
}
static void __init pnpidacpi_to_pnpid(char *id, char *str)
static int pnpacpi_get_resources(struct pnp_dev *dev)
{
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';
dev_dbg(&dev->dev, "get resources\n");
return pnpacpi_parse_allocated_resource(dev);
}
static int pnpacpi_get_resources(struct pnp_dev *dev,
struct pnp_resource_table *res)
{
acpi_status status;
status = pnpacpi_parse_allocated_resource((acpi_handle) dev->data,
&dev->res);
return ACPI_FAILURE(status) ? -ENODEV : 0;
}
static int pnpacpi_set_resources(struct pnp_dev *dev,
struct pnp_resource_table *res)
static int pnpacpi_set_resources(struct pnp_dev *dev)
{
acpi_handle handle = dev->data;
struct acpi_buffer buffer;
int ret = 0;
int ret;
acpi_status status;
ret = pnpacpi_build_resource_template(handle, &buffer);
dev_dbg(&dev->dev, "set resources\n");
ret = pnpacpi_build_resource_template(dev, &buffer);
if (ret)
return ret;
ret = pnpacpi_encode_resources(res, &buffer);
ret = pnpacpi_encode_resources(dev, &buffer);
if (ret) {
kfree(buffer.pointer);
return ret;
......@@ -163,7 +148,6 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
{
acpi_handle temp = NULL;
acpi_status status;
struct pnp_id *dev_id;
struct pnp_dev *dev;
status = acpi_get_handle(device->handle, "_CRS", &temp);
......@@ -171,11 +155,10 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
is_exclusive_device(device))
return 0;
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
if (!dev) {
pnp_err("Out of memory");
dev = pnp_alloc_dev(&pnpacpi_protocol, num, acpi_device_hid(device));
if (!dev)
return -ENOMEM;
}
dev->data = device->handle;
/* .enabled means the device can decode the resources */
dev->active = device->status.enabled;
......@@ -191,44 +174,17 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
if (ACPI_SUCCESS(status))
dev->capabilities |= PNP_DISABLE;
dev->protocol = &pnpacpi_protocol;
if (strlen(acpi_device_name(device)))
strncpy(dev->name, acpi_device_name(device), sizeof(dev->name));
else
strncpy(dev->name, acpi_device_bid(device), sizeof(dev->name));
dev->number = num;
/* set the initial values for the PnP device */
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!dev_id)
goto err;
pnpidacpi_to_pnpid(acpi_device_hid(device), dev_id->id);
pnp_add_id(dev_id, dev);
if (dev->active) {
/* parse allocated resource */
status = pnpacpi_parse_allocated_resource(device->handle,
&dev->res);
if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
pnp_err("PnPACPI: METHOD_NAME__CRS failure for %s",
dev_id->id);
goto err1;
}
}
if (dev->active)
pnpacpi_parse_allocated_resource(dev);
if (dev->capabilities & PNP_CONFIGURABLE) {
status = pnpacpi_parse_resource_option_data(device->handle,
dev);
if (ACPI_FAILURE(status) && (status != AE_NOT_FOUND)) {
pnp_err("PnPACPI: METHOD_NAME__PRS failure for %s",
dev_id->id);
goto err1;
}
}
if (dev->capabilities & PNP_CONFIGURABLE)
pnpacpi_parse_resource_option_data(dev);
/* parse compatible ids */
if (device->flags.compatible_ids) {
struct acpi_compatible_id_list *cid_list = device->pnp.cid_list;
int i;
......@@ -236,27 +192,17 @@ static int __init pnpacpi_add_device(struct acpi_device *device)
for (i = 0; i < cid_list->count; i++) {
if (!ispnpidacpi(cid_list->id[i].value))
continue;
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!dev_id)
continue;
pnpidacpi_to_pnpid(cid_list->id[i].value, dev_id->id);
pnp_add_id(dev_id, dev);
pnp_add_id(dev, cid_list->id[i].value);
}
}
/* clear out the damaged flags */
if (!dev->active)
pnp_init_resource_table(&dev->res);
pnp_init_resources(dev);
pnp_add_device(dev);
num++;
return AE_OK;
err1:
kfree(dev_id);
err:
kfree(dev);
return -EINVAL;
}
static acpi_status __init pnpacpi_add_device_handler(acpi_handle handle,
......
......@@ -5,8 +5,8 @@
#include <linux/acpi.h>
#include <linux/pnp.h>
acpi_status pnpacpi_parse_allocated_resource(acpi_handle, struct pnp_resource_table*);
acpi_status pnpacpi_parse_resource_option_data(acpi_handle, struct pnp_dev*);
int pnpacpi_encode_resources(struct pnp_resource_table *, struct acpi_buffer *);
int pnpacpi_build_resource_template(acpi_handle, struct acpi_buffer*);
int pnpacpi_parse_allocated_resource(struct pnp_dev *);
int pnpacpi_parse_resource_option_data(struct pnp_dev *);
int pnpacpi_encode_resources(struct pnp_dev *, struct acpi_buffer *);
int pnpacpi_build_resource_template(struct pnp_dev *, struct acpi_buffer *);
#endif
This diff is collapsed.
......@@ -5,3 +5,7 @@
pnpbios-proc-$(CONFIG_PNPBIOS_PROC_FS) = proc.o
obj-y := core.o bioscalls.o rsparser.o $(pnpbios-proc-y)
ifeq ($(CONFIG_PNP_DEBUG),y)
EXTRA_CFLAGS += -DDEBUG
endif
......@@ -7,7 +7,6 @@
#include <linux/init.h>
#include <linux/linkage.h>
#include <linux/kernel.h>
#include <linux/pnpbios.h>
#include <linux/device.h>
#include <linux/pnp.h>
#include <linux/mm.h>
......
......@@ -50,7 +50,6 @@
#include <linux/init.h>
#include <linux/linkage.h>
#include <linux/kernel.h>
#include <linux/pnpbios.h>
#include <linux/device.h>
#include <linux/pnp.h>
#include <linux/mm.h>
......@@ -69,6 +68,7 @@
#include <asm/system.h>
#include <asm/byteorder.h>
#include "../base.h"
#include "pnpbios.h"
/*
......@@ -203,8 +203,7 @@ static int pnp_dock_thread(void *unused)
#endif /* CONFIG_HOTPLUG */
static int pnpbios_get_resources(struct pnp_dev *dev,
struct pnp_resource_table *res)
static int pnpbios_get_resources(struct pnp_dev *dev)
{
u8 nodenum = dev->number;
struct pnp_bios_node *node;
......@@ -212,6 +211,7 @@ static int pnpbios_get_resources(struct pnp_dev *dev,
if (!pnpbios_is_dynamic(dev))
return -EPERM;
dev_dbg(&dev->dev, "get resources\n");
node = kzalloc(node_info.max_node_size, GFP_KERNEL);
if (!node)
return -1;
......@@ -219,14 +219,13 @@ static int pnpbios_get_resources(struct pnp_dev *dev,
kfree(node);
return -ENODEV;
}
pnpbios_read_resources_from_node(res, node);
pnpbios_read_resources_from_node(dev, node);
dev->active = pnp_is_active(dev);
kfree(node);
return 0;
}
static int pnpbios_set_resources(struct pnp_dev *dev,
struct pnp_resource_table *res)
static int pnpbios_set_resources(struct pnp_dev *dev)
{
u8 nodenum = dev->number;
struct pnp_bios_node *node;
......@@ -235,6 +234,7 @@ static int pnpbios_set_resources(struct pnp_dev *dev,
if (!pnpbios_is_dynamic(dev))
return -EPERM;
dev_dbg(&dev->dev, "set resources\n");
node = kzalloc(node_info.max_node_size, GFP_KERNEL);
if (!node)
return -1;
......@@ -242,7 +242,7 @@ static int pnpbios_set_resources(struct pnp_dev *dev,
kfree(node);
return -ENODEV;
}
if (pnpbios_write_resources_to_node(res, node) < 0) {
if (pnpbios_write_resources_to_node(dev, node) < 0) {
kfree(node);
return -1;
}
......@@ -317,7 +317,6 @@ static int __init insert_device(struct pnp_bios_node *node)
{
struct list_head *pos;
struct pnp_dev *dev;
struct pnp_id *dev_id;
char id[8];
/* check if the device is already added */
......@@ -327,20 +326,11 @@ static int __init insert_device(struct pnp_bios_node *node)
return -1;
}
dev = kzalloc(sizeof(struct pnp_dev), GFP_KERNEL);
pnp_eisa_id_to_string(node->eisa_id & PNP_EISA_ID_MASK, id);
dev = pnp_alloc_dev(&pnpbios_protocol, node->handle, id);
if (!dev)
return -1;
dev_id = kzalloc(sizeof(struct pnp_id), GFP_KERNEL);
if (!dev_id) {
kfree(dev);
return -1;
}
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);
dev->active = pnp_is_active(dev);
dev->flags = node->flags;
......@@ -353,11 +343,10 @@ static int __init insert_device(struct pnp_bios_node *node)
dev->capabilities |= PNP_WRITE;
if (dev->flags & PNPBIOS_REMOVABLE)
dev->capabilities |= PNP_REMOVABLE;
dev->protocol = &pnpbios_protocol;
/* clear out the damaged flags */
if (!dev->active)
pnp_init_resource_table(&dev->res);
pnp_init_resources(dev);
pnp_add_device(dev);
pnpbios_interface_attach_device(node);
......
......@@ -2,6 +2,142 @@
* pnpbios.h - contains local definitions
*/
/*
* Include file for the interface to a PnP BIOS
*
* Original BIOS code (C) 1998 Christian Schmidt (chr.schmidt@tu-bs.de)
* PnP handler parts (c) 1998 Tom Lees <tom@lpsg.demon.co.uk>
* Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
/*
* Return codes
*/
#define PNP_SUCCESS 0x00
#define PNP_NOT_SET_STATICALLY 0x7f
#define PNP_UNKNOWN_FUNCTION 0x81
#define PNP_FUNCTION_NOT_SUPPORTED 0x82
#define PNP_INVALID_HANDLE 0x83
#define PNP_BAD_PARAMETER 0x84
#define PNP_SET_FAILED 0x85
#define PNP_EVENTS_NOT_PENDING 0x86
#define PNP_SYSTEM_NOT_DOCKED 0x87
#define PNP_NO_ISA_PNP_CARDS 0x88
#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
#define PNP_BUFFER_TOO_SMALL 0x8c
#define PNP_USE_ESCD_SUPPORT 0x8d
#define PNP_MESSAGE_NOT_SUPPORTED 0x8e
#define PNP_HARDWARE_ERROR 0x8f
#define ESCD_SUCCESS 0x00
#define ESCD_IO_ERROR_READING 0x55
#define ESCD_INVALID 0x56
#define ESCD_BUFFER_TOO_SMALL 0x59
#define ESCD_NVRAM_TOO_SMALL 0x5a
#define ESCD_FUNCTION_NOT_SUPPORTED 0x81
/*
* Events that can be received by "get event"
*/
#define PNPEV_ABOUT_TO_CHANGE_CONFIG 0x0001
#define PNPEV_DOCK_CHANGED 0x0002
#define PNPEV_SYSTEM_DEVICE_CHANGED 0x0003
#define PNPEV_CONFIG_CHANGED_FAILED 0x0004
#define PNPEV_UNKNOWN_SYSTEM_EVENT 0xffff
/* 0x8000 through 0xfffe are OEM defined */
/*
* Messages that should be sent through "send message"
*/
#define PNPMSG_OK 0x00
#define PNPMSG_ABORT 0x01
#define PNPMSG_UNDOCK_DEFAULT_ACTION 0x40
#define PNPMSG_POWER_OFF 0x41
#define PNPMSG_PNP_OS_ACTIVE 0x42
#define PNPMSG_PNP_OS_INACTIVE 0x43
/*
* Plug and Play BIOS flags
*/
#define PNPBIOS_NO_DISABLE 0x0001
#define PNPBIOS_NO_CONFIG 0x0002
#define PNPBIOS_OUTPUT 0x0004
#define PNPBIOS_INPUT 0x0008
#define PNPBIOS_BOOTABLE 0x0010
#define PNPBIOS_DOCK 0x0020
#define PNPBIOS_REMOVABLE 0x0040
#define pnpbios_is_static(x) (((x)->flags & 0x0100) == 0x0000)
#define pnpbios_is_dynamic(x) ((x)->flags & 0x0080)
/*
* Function Parameters
*/
#define PNPMODE_STATIC 1
#define PNPMODE_DYNAMIC 0
/* 0x8000 through 0xffff are OEM defined */
#pragma pack(1)
struct pnp_dev_node_info {
__u16 no_nodes;
__u16 max_node_size;
};
struct pnp_docking_station_info {
__u32 location_id;
__u32 serial;
__u16 capabilities;
};
struct pnp_isa_config_struc {
__u8 revision;
__u8 no_csns;
__u16 isa_rd_data_port;
__u16 reserved;
};
struct escd_info_struc {
__u16 min_escd_write_size;
__u16 escd_size;
__u32 nv_storage_base;
};
struct pnp_bios_node {
__u16 size;
__u8 handle;
__u32 eisa_id;
__u8 type_code[3];
__u16 flags;
__u8 data[0];
};
#pragma pack()
/* non-exported */
extern struct pnp_dev_node_info node_info;
extern int pnp_bios_dev_node_info(struct pnp_dev_node_info *data);
extern int pnp_bios_get_dev_node(u8 *nodenum, char config,
struct pnp_bios_node *data);
extern int pnp_bios_set_dev_node(u8 nodenum, char config,
struct pnp_bios_node *data);
extern int pnp_bios_get_stat_res(char *info);
extern int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data);
extern int pnp_bios_escd_info(struct escd_info_struc *data);
extern int pnp_bios_read_escd(char *data, u32 nvram_base);
extern int pnp_bios_dock_station_info(struct pnp_docking_station_info *data);
#pragma pack(1)
union pnp_bios_install_struct {
struct {
......@@ -28,8 +164,8 @@ extern int pnp_bios_present(void);
extern int pnpbios_dont_use_current_config;
extern int pnpbios_parse_data_stream(struct pnp_dev *dev, struct pnp_bios_node * node);
extern int pnpbios_read_resources_from_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
extern int pnpbios_write_resources_to_node(struct pnp_resource_table *res, struct pnp_bios_node * node);
extern int pnpbios_read_resources_from_node(struct pnp_dev *dev, struct pnp_bios_node *node);
extern int pnpbios_write_resources_to_node(struct pnp_dev *dev, struct pnp_bios_node *node);
extern void pnpid32_to_pnpid(u32 id, char *str);
extern void pnpbios_print_status(const char * module, u16 status);
......
......@@ -23,7 +23,7 @@
#include <linux/slab.h>
#include <linux/types.h>
#include <linux/proc_fs.h>
#include <linux/pnpbios.h>
#include <linux/pnp.h>
#include <linux/init.h>
#include <asm/uaccess.h>
......
This diff is collapsed.
......@@ -117,6 +117,7 @@ static void quirk_sb16audio_resources(struct pnp_dev *dev)
static void quirk_system_pci_resources(struct pnp_dev *dev)
{
struct pci_dev *pdev = NULL;
struct resource *res;
resource_size_t pnp_start, pnp_end, pci_start, pci_end;
int i, j;
......@@ -137,13 +138,15 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
pci_start = pci_resource_start(pdev, i);
pci_end = pci_resource_end(pdev, i);
for (j = 0; j < PNP_MAX_MEM; j++) {
if (!pnp_mem_valid(dev, j) ||
pnp_mem_len(dev, j) == 0)
for (j = 0;
(res = pnp_get_resource(dev, IORESOURCE_MEM, j));
j++) {
if (res->flags & IORESOURCE_UNSET ||
(res->start == 0 && res->end == 0))
continue;
pnp_start = pnp_mem_start(dev, j);
pnp_end = pnp_mem_end(dev, j);
pnp_start = res->start;
pnp_end = res->end;
/*
* If the PNP region doesn't overlap the PCI
......@@ -176,7 +179,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
pci_name(pdev), i,
(unsigned long long) pci_start,
(unsigned long long) pci_end);
pnp_mem_flags(dev, j) = 0;
res->flags = 0;
}
}
}
......
This diff is collapsed.
......@@ -25,3 +25,66 @@ 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';
}
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
{
#ifdef DEBUG
struct resource *res;
int i;
dev_dbg(&dev->dev, "current resources: %s\n", desc);
for (i = 0; i < PNP_MAX_IRQ; i++) {
res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
if (res && !(res->flags & IORESOURCE_UNSET))
dev_dbg(&dev->dev, " irq %lld flags %#lx\n",
(unsigned long long) res->start, res->flags);
}
for (i = 0; i < PNP_MAX_DMA; i++) {
res = pnp_get_resource(dev, IORESOURCE_DMA, i);
if (res && !(res->flags & IORESOURCE_UNSET))
dev_dbg(&dev->dev, " dma %lld flags %#lx\n",
(unsigned long long) res->start, res->flags);
}
for (i = 0; i < PNP_MAX_PORT; i++) {
res = pnp_get_resource(dev, IORESOURCE_IO, i);
if (res && !(res->flags & IORESOURCE_UNSET))
dev_dbg(&dev->dev, " io %#llx-%#llx flags %#lx\n",
(unsigned long long) res->start,
(unsigned long long) res->end, res->flags);
}
for (i = 0; i < PNP_MAX_MEM; i++) {
res = pnp_get_resource(dev, IORESOURCE_MEM, i);
if (res && !(res->flags & IORESOURCE_UNSET))
dev_dbg(&dev->dev, " mem %#llx-%#llx flags %#lx\n",
(unsigned long long) res->start,
(unsigned long long) res->end, res->flags);
}
#endif
}
......@@ -56,14 +56,15 @@ static void reserve_range(struct pnp_dev *dev, resource_size_t start,
static void reserve_resources_of_dev(struct pnp_dev *dev)
{
struct resource *res;
int i;
for (i = 0; i < PNP_MAX_PORT; i++) {
if (!pnp_port_valid(dev, i))
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
if (res->flags & IORESOURCE_UNSET)
continue;
if (pnp_port_start(dev, i) == 0)
if (res->start == 0)
continue; /* disabled */
if (pnp_port_start(dev, i) < 0x100)
if (res->start < 0x100)
/*
* Below 0x100 is only standard PC hardware
* (pics, kbd, timer, dma, ...)
......@@ -73,19 +74,17 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
* So, do nothing
*/
continue;
if (pnp_port_end(dev, i) < pnp_port_start(dev, i))
if (res->end < res->start)
continue; /* invalid */
reserve_range(dev, pnp_port_start(dev, i),
pnp_port_end(dev, i), 1);
reserve_range(dev, res->start, res->end, 1);
}
for (i = 0; i < PNP_MAX_MEM; i++) {
if (!pnp_mem_valid(dev, i))
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
if (res->flags & IORESOURCE_UNSET)
continue;
reserve_range(dev, pnp_mem_start(dev, i),
pnp_mem_end(dev, i), 0);
reserve_range(dev, res->start, res->end, 0);
}
}
......
......@@ -854,11 +854,12 @@ cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
* don't define the IRQ. It should always be safe to
* hardcode it in these cases
*/
return cmos_do_probe(&pnp->dev, &pnp->res.port_resource[0], 8);
return cmos_do_probe(&pnp->dev,
pnp_get_resource(pnp, IORESOURCE_IO, 0), 8);
else
return cmos_do_probe(&pnp->dev,
&pnp->res.port_resource[0],
pnp->res.irq_resource[0].start);
pnp_get_resource(pnp, IORESOURCE_IO, 0),
pnp_irq(pnp, 0));
}
static void __exit cmos_pnp_remove(struct pnp_dev *pnp)
......
......@@ -25,16 +25,6 @@
#include <linux/errno.h>
#include <linux/pnp.h>
/*
* Configuration registers (TODO: change by specification)
*/
#define ISAPNP_CFG_ACTIVATE 0x30 /* byte */
#define ISAPNP_CFG_MEM 0x40 /* 4 * dword */
#define ISAPNP_CFG_PORT 0x60 /* 8 * word */
#define ISAPNP_CFG_IRQ 0x70 /* 2 * word */
#define ISAPNP_CFG_DMA 0x74 /* 2 * byte */
/*
*
*/
......
This diff is collapsed.
/*
* Include file for the interface to a PnP BIOS
*
* Original BIOS code (C) 1998 Christian Schmidt (chr.schmidt@tu-bs.de)
* PnP handler parts (c) 1998 Tom Lees <tom@lpsg.demon.co.uk>
* Minor reorganizations by David Hinds <dahinds@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2, or (at your option) any
* later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef _LINUX_PNPBIOS_H
#define _LINUX_PNPBIOS_H
#ifdef __KERNEL__
#include <linux/types.h>
#include <linux/pnp.h>
/*
* Return codes
*/
#define PNP_SUCCESS 0x00
#define PNP_NOT_SET_STATICALLY 0x7f
#define PNP_UNKNOWN_FUNCTION 0x81
#define PNP_FUNCTION_NOT_SUPPORTED 0x82
#define PNP_INVALID_HANDLE 0x83
#define PNP_BAD_PARAMETER 0x84
#define PNP_SET_FAILED 0x85
#define PNP_EVENTS_NOT_PENDING 0x86
#define PNP_SYSTEM_NOT_DOCKED 0x87
#define PNP_NO_ISA_PNP_CARDS 0x88
#define PNP_UNABLE_TO_DETERMINE_DOCK_CAPABILITIES 0x89
#define PNP_CONFIG_CHANGE_FAILED_NO_BATTERY 0x8a
#define PNP_CONFIG_CHANGE_FAILED_RESOURCE_CONFLICT 0x8b
#define PNP_BUFFER_TOO_SMALL 0x8c
#define PNP_USE_ESCD_SUPPORT 0x8d
#define PNP_MESSAGE_NOT_SUPPORTED 0x8e
#define PNP_HARDWARE_ERROR 0x8f
#define ESCD_SUCCESS 0x00
#define ESCD_IO_ERROR_READING 0x55
#define ESCD_INVALID 0x56
#define ESCD_BUFFER_TOO_SMALL 0x59
#define ESCD_NVRAM_TOO_SMALL 0x5a
#define ESCD_FUNCTION_NOT_SUPPORTED 0x81
/*
* Events that can be received by "get event"
*/
#define PNPEV_ABOUT_TO_CHANGE_CONFIG 0x0001
#define PNPEV_DOCK_CHANGED 0x0002
#define PNPEV_SYSTEM_DEVICE_CHANGED 0x0003
#define PNPEV_CONFIG_CHANGED_FAILED 0x0004
#define PNPEV_UNKNOWN_SYSTEM_EVENT 0xffff
/* 0x8000 through 0xfffe are OEM defined */
/*
* Messages that should be sent through "send message"
*/
#define PNPMSG_OK 0x00
#define PNPMSG_ABORT 0x01
#define PNPMSG_UNDOCK_DEFAULT_ACTION 0x40
#define PNPMSG_POWER_OFF 0x41
#define PNPMSG_PNP_OS_ACTIVE 0x42
#define PNPMSG_PNP_OS_INACTIVE 0x43
/*
* Plug and Play BIOS flags
*/
#define PNPBIOS_NO_DISABLE 0x0001
#define PNPBIOS_NO_CONFIG 0x0002
#define PNPBIOS_OUTPUT 0x0004
#define PNPBIOS_INPUT 0x0008
#define PNPBIOS_BOOTABLE 0x0010
#define PNPBIOS_DOCK 0x0020
#define PNPBIOS_REMOVABLE 0x0040
#define pnpbios_is_static(x) (((x)->flags & 0x0100) == 0x0000)
#define pnpbios_is_dynamic(x) ((x)->flags & 0x0080)
/*
* Function Parameters
*/
#define PNPMODE_STATIC 1
#define PNPMODE_DYNAMIC 0
/* 0x8000 through 0xffff are OEM defined */
#pragma pack(1)
struct pnp_dev_node_info {
__u16 no_nodes;
__u16 max_node_size;
};
struct pnp_docking_station_info {
__u32 location_id;
__u32 serial;
__u16 capabilities;
};
struct pnp_isa_config_struc {
__u8 revision;
__u8 no_csns;
__u16 isa_rd_data_port;
__u16 reserved;
};
struct escd_info_struc {
__u16 min_escd_write_size;
__u16 escd_size;
__u32 nv_storage_base;
};
struct pnp_bios_node {
__u16 size;
__u8 handle;
__u32 eisa_id;
__u8 type_code[3];
__u16 flags;
__u8 data[0];
};
#pragma pack()
#ifdef CONFIG_PNPBIOS
/* non-exported */
extern struct pnp_dev_node_info node_info;
extern int pnp_bios_dev_node_info(struct pnp_dev_node_info *data);
extern int pnp_bios_get_dev_node(u8 *nodenum, char config,
struct pnp_bios_node *data);
extern int pnp_bios_set_dev_node(u8 nodenum, char config,
struct pnp_bios_node *data);
extern int pnp_bios_get_stat_res(char *info);
extern int pnp_bios_isapnp_config(struct pnp_isa_config_struc *data);
extern int pnp_bios_escd_info(struct escd_info_struc *data);
extern int pnp_bios_read_escd(char *data, u32 nvram_base);
extern int pnp_bios_dock_station_info(struct pnp_docking_station_info *data);
#endif /* CONFIG_PNPBIOS */
#endif /* __KERNEL__ */
#endif /* _LINUX_PNPBIOS_H */
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