Commit aee3ad81 authored by Bjorn Helgaas's avatar Bjorn Helgaas Committed by Andi Kleen

PNP: replace pnp_resource_table with dynamically allocated resources

PNP used to have a fixed-size pnp_resource_table for tracking the
resources used by a device.  This table often overflowed, so we've
had to increase the table size, which wastes memory because most
devices have very few resources.

This patch replaces the table with a linked list of resources where
the entries are allocated on demand.

This removes messages like these:

    pnpacpi: exceeded the max number of IO resources
    00:01: too many I/O port resources

References:

    http://bugzilla.kernel.org/show_bug.cgi?id=9535
    http://bugzilla.kernel.org/show_bug.cgi?id=9740
    http://lkml.org/lkml/2007/11/30/110

This patch also changes the way PNP uses the IORESOURCE_UNSET,
IORESOURCE_AUTO, and IORESOURCE_DISABLED flags.

Prior to this patch, the pnp_resource_table entries used the flags
like this:

    IORESOURCE_UNSET
	This table entry is unused and available for use.  When this flag
	is set, we shouldn't look at anything else in the resource structure.
	This flag is set when a resource table entry is initialized.

    IORESOURCE_AUTO
	This resource was assigned automatically by pnp_assign_{io,mem,etc}().

	This flag is set when a resource table entry is initialized and
	cleared whenever we discover a resource setting by reading an ISAPNP
	config register, parsing a PNPBIOS resource data stream, parsing an
	ACPI _CRS list, or interpreting a sysfs "set" command.

	Resources marked IORESOURCE_AUTO are reinitialized and marked as
	IORESOURCE_UNSET by pnp_clean_resource_table() in these cases:

	    - before we attempt to assign resources automatically,
	    - if we fail to assign resources automatically,
	    - after disabling a device

    IORESOURCE_DISABLED
	Set by pnp_assign_{io,mem,etc}() when automatic assignment fails.
	Also set by PNPBIOS and PNPACPI for:

	    - invalid IRQs or GSI registration failures
	    - invalid DMA channels
	    - I/O ports above 0x10000
	    - mem ranges with negative length

After this patch, there is no pnp_resource_table, and the resource list
entries use the flags like this:

    IORESOURCE_UNSET
	This flag is no longer used in PNP.  Instead of keeping
	IORESOURCE_UNSET entries in the resource list, we remove
	entries from the list and free them.

    IORESOURCE_AUTO
	No change in meaning: it still means the resource was assigned
	automatically by pnp_assign_{port,mem,etc}(), but these functions
	now set the bit explicitly.

	We still "clean" a device's resource list in the same places,
	but rather than reinitializing IORESOURCE_AUTO entries, we
	just remove them from the list.

	Note that IORESOURCE_AUTO entries are always at the end of the
	list, so removing them doesn't reorder other list entries.
	This is because non-IORESOURCE_AUTO entries are added by the
	ISAPNP, PNPBIOS, or PNPACPI "get resources" methods and by the
	sysfs "set" command.  In each of these cases, we completely free
	the resource list first.

    IORESOURCE_DISABLED
	In addition to the cases where we used to set this flag, ISAPNP now
	adds an IORESOURCE_DISABLED resource when it reads a configuration
	register with a "disabled" value.
Signed-off-by: default avatarBjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: default avatarLen Brown <len.brown@intel.com>
Signed-off-by: default avatarAndi Kleen <ak@linux.intel.com>
parent 20bfdbba
...@@ -46,27 +46,15 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res); ...@@ -46,27 +46,15 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res);
char *pnp_resource_type_name(struct resource *res); char *pnp_resource_type_name(struct resource *res);
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc); void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc);
void pnp_init_resource(struct resource *res); void pnp_free_resources(struct pnp_dev *dev);
int pnp_resource_type(struct resource *res); int pnp_resource_type(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 pnp_resource {
struct list_head list;
struct resource res; struct resource res;
}; };
struct pnp_resource_table { void pnp_free_resource(struct pnp_resource *pnp_res);
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, struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
int flags); int flags);
......
...@@ -99,6 +99,21 @@ static void pnp_free_ids(struct pnp_dev *dev) ...@@ -99,6 +99,21 @@ static void pnp_free_ids(struct pnp_dev *dev)
} }
} }
void pnp_free_resource(struct pnp_resource *pnp_res)
{
list_del(&pnp_res->list);
kfree(pnp_res);
}
void pnp_free_resources(struct pnp_dev *dev)
{
struct pnp_resource *pnp_res, *tmp;
list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
pnp_free_resource(pnp_res);
}
}
static void pnp_release_device(struct device *dmdev) static void pnp_release_device(struct device *dmdev)
{ {
struct pnp_dev *dev = to_pnp_dev(dmdev); struct pnp_dev *dev = to_pnp_dev(dmdev);
...@@ -106,7 +121,7 @@ static void pnp_release_device(struct device *dmdev) ...@@ -106,7 +121,7 @@ static void pnp_release_device(struct device *dmdev)
pnp_free_option(dev->independent); pnp_free_option(dev->independent);
pnp_free_option(dev->dependent); pnp_free_option(dev->dependent);
pnp_free_ids(dev); pnp_free_ids(dev);
kfree(dev->res); pnp_free_resources(dev);
kfree(dev); kfree(dev);
} }
...@@ -119,12 +134,7 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid ...@@ -119,12 +134,7 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid
if (!dev) if (!dev)
return NULL; return NULL;
dev->res = kzalloc(sizeof(struct pnp_resource_table), GFP_KERNEL); INIT_LIST_HEAD(&dev->resources);
if (!dev->res) {
kfree(dev);
return NULL;
}
dev->protocol = protocol; dev->protocol = protocol;
dev->number = id; dev->number = id;
dev->dma_mask = DMA_24BIT_MASK; dev->dma_mask = DMA_24BIT_MASK;
...@@ -140,7 +150,6 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid ...@@ -140,7 +150,6 @@ struct pnp_dev *pnp_alloc_dev(struct pnp_protocol *protocol, int id, char *pnpid
dev_id = pnp_add_id(dev, pnpid); dev_id = pnp_add_id(dev, pnpid);
if (!dev_id) { if (!dev_id) {
kfree(dev->res);
kfree(dev); kfree(dev);
return NULL; return NULL;
} }
......
...@@ -269,7 +269,6 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, ...@@ -269,7 +269,6 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
pnp_printf(buffer, "disabled\n"); pnp_printf(buffer, "disabled\n");
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "io"); pnp_printf(buffer, "io");
if (res->flags & IORESOURCE_DISABLED) if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n"); pnp_printf(buffer, " disabled\n");
...@@ -278,9 +277,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, ...@@ -278,9 +277,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
(unsigned long long) res->start, (unsigned long long) res->start,
(unsigned long long) res->end); (unsigned long long) res->end);
} }
}
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "mem"); pnp_printf(buffer, "mem");
if (res->flags & IORESOURCE_DISABLED) if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n"); pnp_printf(buffer, " disabled\n");
...@@ -289,9 +286,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, ...@@ -289,9 +286,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
(unsigned long long) res->start, (unsigned long long) res->start,
(unsigned long long) res->end); (unsigned long long) res->end);
} }
}
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) { for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "irq"); pnp_printf(buffer, "irq");
if (res->flags & IORESOURCE_DISABLED) if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n"); pnp_printf(buffer, " disabled\n");
...@@ -299,9 +294,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, ...@@ -299,9 +294,7 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
pnp_printf(buffer, " %lld\n", pnp_printf(buffer, " %lld\n",
(unsigned long long) res->start); (unsigned long long) res->start);
} }
}
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) { for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) {
if (pnp_resource_valid(res)) {
pnp_printf(buffer, "dma"); pnp_printf(buffer, "dma");
if (res->flags & IORESOURCE_DISABLED) if (res->flags & IORESOURCE_DISABLED)
pnp_printf(buffer, " disabled\n"); pnp_printf(buffer, " disabled\n");
...@@ -309,7 +302,6 @@ static ssize_t pnp_show_current_resources(struct device *dmdev, ...@@ -309,7 +302,6 @@ static ssize_t pnp_show_current_resources(struct device *dmdev,
pnp_printf(buffer, " %lld\n", pnp_printf(buffer, " %lld\n",
(unsigned long long) res->start); (unsigned long long) res->start);
} }
}
ret = (buffer->curr - buf); ret = (buffer->curr - buf);
kfree(buffer); kfree(buffer);
return ret; return ret;
......
...@@ -973,8 +973,7 @@ static int isapnp_set_resources(struct pnp_dev *dev) ...@@ -973,8 +973,7 @@ static int isapnp_set_resources(struct pnp_dev *dev)
dev->active = 1; dev->active = 1;
for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) { for (tmp = 0; tmp < ISAPNP_MAX_PORT; tmp++) {
res = pnp_get_resource(dev, IORESOURCE_IO, tmp); res = pnp_get_resource(dev, IORESOURCE_IO, tmp);
if (res && pnp_resource_valid(res) && if (pnp_resource_enabled(res)) {
!(res->flags & IORESOURCE_DISABLED)) {
dev_dbg(&dev->dev, " set io %d to %#llx\n", dev_dbg(&dev->dev, " set io %d to %#llx\n",
tmp, (unsigned long long) res->start); tmp, (unsigned long long) res->start);
isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1), isapnp_write_word(ISAPNP_CFG_PORT + (tmp << 1),
...@@ -983,8 +982,7 @@ static int isapnp_set_resources(struct pnp_dev *dev) ...@@ -983,8 +982,7 @@ static int isapnp_set_resources(struct pnp_dev *dev)
} }
for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) { for (tmp = 0; tmp < ISAPNP_MAX_IRQ; tmp++) {
res = pnp_get_resource(dev, IORESOURCE_IRQ, tmp); res = pnp_get_resource(dev, IORESOURCE_IRQ, tmp);
if (res && pnp_resource_valid(res) && if (pnp_resource_enabled(res)) {
!(res->flags & IORESOURCE_DISABLED)) {
int irq = res->start; int irq = res->start;
if (irq == 2) if (irq == 2)
irq = 9; irq = 9;
...@@ -994,8 +992,7 @@ static int isapnp_set_resources(struct pnp_dev *dev) ...@@ -994,8 +992,7 @@ static int isapnp_set_resources(struct pnp_dev *dev)
} }
for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
res = pnp_get_resource(dev, IORESOURCE_DMA, tmp); res = pnp_get_resource(dev, IORESOURCE_DMA, tmp);
if (res && pnp_resource_valid(res) && if (pnp_resource_enabled(res)) {
!(res->flags & IORESOURCE_DISABLED)) {
dev_dbg(&dev->dev, " set dma %d to %lld\n", dev_dbg(&dev->dev, " set dma %d to %lld\n",
tmp, (unsigned long long) res->start); tmp, (unsigned long long) res->start);
isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start); isapnp_write_byte(ISAPNP_CFG_DMA + tmp, res->start);
...@@ -1003,8 +1000,7 @@ static int isapnp_set_resources(struct pnp_dev *dev) ...@@ -1003,8 +1000,7 @@ static int isapnp_set_resources(struct pnp_dev *dev)
} }
for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) { for (tmp = 0; tmp < ISAPNP_MAX_MEM; tmp++) {
res = pnp_get_resource(dev, IORESOURCE_MEM, tmp); res = pnp_get_resource(dev, IORESOURCE_MEM, tmp);
if (res && pnp_resource_valid(res) && if (pnp_resource_enabled(res)) {
!(res->flags & IORESOURCE_DISABLED)) {
dev_dbg(&dev->dev, " set mem %d to %#llx\n", dev_dbg(&dev->dev, " set mem %d to %#llx\n",
tmp, (unsigned long long) res->start); tmp, (unsigned long long) res->start);
isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3), isapnp_write_word(ISAPNP_CFG_MEM + (tmp << 3),
......
...@@ -19,40 +19,30 @@ DEFINE_MUTEX(pnp_res_mutex); ...@@ -19,40 +19,30 @@ DEFINE_MUTEX(pnp_res_mutex);
static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
{ {
struct pnp_resource *pnp_res; struct resource *res, local_res;
struct resource *res;
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, idx); res = pnp_get_resource(dev, IORESOURCE_IO, idx);
if (!pnp_res) { if (res) {
dev_err(&dev->dev, "too many I/O port resources\n");
/* pretend we were successful so at least the manager won't try again */
return 1;
}
res = &pnp_res->res;
/* check if this resource has been manually set, if so skip */
if (!(res->flags & IORESOURCE_AUTO)) {
dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx " dev_dbg(&dev->dev, " io %d already set to %#llx-%#llx "
"flags %#lx\n", idx, (unsigned long long) res->start, "flags %#lx\n", idx, (unsigned long long) res->start,
(unsigned long long) res->end, res->flags); (unsigned long long) res->end, res->flags);
return 1; return 1;
} }
/* set the initial values */ res = &local_res;
res->flags |= rule->flags | IORESOURCE_IO; res->flags = rule->flags | IORESOURCE_AUTO;
res->flags &= ~IORESOURCE_UNSET; res->start = 0;
res->end = 0;
if (!rule->size) { if (!rule->size) {
res->flags |= IORESOURCE_DISABLED; res->flags |= IORESOURCE_DISABLED;
dev_dbg(&dev->dev, " io %d disabled\n", idx); dev_dbg(&dev->dev, " io %d disabled\n", idx);
return 1; /* skip disabled resource requests */ goto __add;
} }
res->start = rule->min; res->start = rule->min;
res->end = res->start + rule->size - 1; res->end = res->start + rule->size - 1;
/* run through until pnp_check_port is happy */
while (!pnp_check_port(dev, res)) { while (!pnp_check_port(dev, res)) {
res->start += rule->align; res->start += rule->align;
res->end = res->start + rule->size - 1; res->end = res->start + rule->size - 1;
...@@ -61,38 +51,29 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx) ...@@ -61,38 +51,29 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
return 0; return 0;
} }
} }
dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx,
(unsigned long long) res->start, (unsigned long long) res->end); __add:
pnp_add_io_resource(dev, res->start, res->end, res->flags);
return 1; return 1;
} }
static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
{ {
struct pnp_resource *pnp_res; struct resource *res, local_res;
struct resource *res;
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, idx); res = pnp_get_resource(dev, IORESOURCE_MEM, idx);
if (!pnp_res) { if (res) {
dev_err(&dev->dev, "too many memory resources\n");
/* pretend we were successful so at least the manager won't try again */
return 1;
}
res = &pnp_res->res;
/* check if this resource has been manually set, if so skip */
if (!(res->flags & IORESOURCE_AUTO)) {
dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx " dev_dbg(&dev->dev, " mem %d already set to %#llx-%#llx "
"flags %#lx\n", idx, (unsigned long long) res->start, "flags %#lx\n", idx, (unsigned long long) res->start,
(unsigned long long) res->end, res->flags); (unsigned long long) res->end, res->flags);
return 1; return 1;
} }
/* set the initial values */ res = &local_res;
res->flags |= rule->flags | IORESOURCE_MEM; res->flags = rule->flags | IORESOURCE_AUTO;
res->flags &= ~IORESOURCE_UNSET; res->start = 0;
res->end = 0;
/* convert pnp flags to standard Linux flags */
if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
res->flags |= IORESOURCE_READONLY; res->flags |= IORESOURCE_READONLY;
if (rule->flags & IORESOURCE_MEM_CACHEABLE) if (rule->flags & IORESOURCE_MEM_CACHEABLE)
...@@ -105,13 +86,12 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) ...@@ -105,13 +86,12 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
if (!rule->size) { if (!rule->size) {
res->flags |= IORESOURCE_DISABLED; res->flags |= IORESOURCE_DISABLED;
dev_dbg(&dev->dev, " mem %d disabled\n", idx); dev_dbg(&dev->dev, " mem %d disabled\n", idx);
return 1; /* skip disabled resource requests */ goto __add;
} }
res->start = rule->min; res->start = rule->min;
res->end = res->start + rule->size - 1; res->end = res->start + rule->size - 1;
/* run through until pnp_check_mem is happy */
while (!pnp_check_mem(dev, res)) { while (!pnp_check_mem(dev, res)) {
res->start += rule->align; res->start += rule->align;
res->end = res->start + rule->size - 1; res->end = res->start + rule->size - 1;
...@@ -120,15 +100,15 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx) ...@@ -120,15 +100,15 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
return 0; return 0;
} }
} }
dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx,
(unsigned long long) res->start, (unsigned long long) res->end); __add:
pnp_add_mem_resource(dev, res->start, res->end, res->flags);
return 1; return 1;
} }
static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
{ {
struct pnp_resource *pnp_res; struct resource *res, local_res;
struct resource *res;
int i; int i;
/* IRQ priority: this table is good for i386 */ /* IRQ priority: this table is good for i386 */
...@@ -136,58 +116,48 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx) ...@@ -136,58 +116,48 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2 5, 10, 11, 12, 9, 14, 15, 7, 3, 4, 13, 0, 1, 6, 8, 2
}; };
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, idx); res = pnp_get_resource(dev, IORESOURCE_IRQ, idx);
if (!pnp_res) { if (res) {
dev_err(&dev->dev, "too many IRQ resources\n");
/* pretend we were successful so at least the manager won't try again */
return 1;
}
res = &pnp_res->res;
/* check if this resource has been manually set, if so skip */
if (!(res->flags & IORESOURCE_AUTO)) {
dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n", dev_dbg(&dev->dev, " irq %d already set to %d flags %#lx\n",
idx, (int) res->start, res->flags); idx, (int) res->start, res->flags);
return 1; return 1;
} }
/* set the initial values */ res = &local_res;
res->flags |= rule->flags | IORESOURCE_IRQ; res->flags = rule->flags | IORESOURCE_AUTO;
res->flags &= ~IORESOURCE_UNSET; res->start = -1;
res->end = -1;
if (bitmap_empty(rule->map, PNP_IRQ_NR)) { if (bitmap_empty(rule->map, PNP_IRQ_NR)) {
res->flags |= IORESOURCE_DISABLED; res->flags |= IORESOURCE_DISABLED;
dev_dbg(&dev->dev, " irq %d disabled\n", idx); dev_dbg(&dev->dev, " irq %d disabled\n", idx);
return 1; /* skip disabled resource requests */ goto __add;
} }
/* TBD: need check for >16 IRQ */ /* TBD: need check for >16 IRQ */
res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16); res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16);
if (res->start < PNP_IRQ_NR) { if (res->start < PNP_IRQ_NR) {
res->end = res->start; res->end = res->start;
dev_dbg(&dev->dev, " assign irq %d %d\n", idx, goto __add;
(int) res->start);
return 1;
} }
for (i = 0; i < 16; i++) { for (i = 0; i < 16; i++) {
if (test_bit(xtab[i], rule->map)) { if (test_bit(xtab[i], rule->map)) {
res->start = res->end = xtab[i]; res->start = res->end = xtab[i];
if (pnp_check_irq(dev, res)) { if (pnp_check_irq(dev, res))
dev_dbg(&dev->dev, " assign irq %d %d\n", idx, goto __add;
(int) res->start);
return 1;
}
} }
} }
dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx); dev_dbg(&dev->dev, " couldn't assign irq %d\n", idx);
return 0; return 0;
__add:
pnp_add_irq_resource(dev, res->start, res->flags);
return 1;
} }
static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
{ {
struct pnp_resource *pnp_res; struct resource *res, local_res;
struct resource *res;
int i; int i;
/* DMA priority: this table is good for i386 */ /* DMA priority: this table is good for i386 */
...@@ -195,127 +165,47 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx) ...@@ -195,127 +165,47 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
1, 3, 5, 6, 7, 0, 2, 4 1, 3, 5, 6, 7, 0, 2, 4
}; };
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, idx); res = pnp_get_resource(dev, IORESOURCE_DMA, idx);
if (!pnp_res) { if (res) {
dev_err(&dev->dev, "too many DMA resources\n");
return;
}
res = &pnp_res->res;
/* check if this resource has been manually set, if so skip */
if (!(res->flags & IORESOURCE_AUTO)) {
dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n", dev_dbg(&dev->dev, " dma %d already set to %d flags %#lx\n",
idx, (int) res->start, res->flags); idx, (int) res->start, res->flags);
return; return;
} }
/* set the initial values */ res = &local_res;
res->flags |= rule->flags | IORESOURCE_DMA; res->flags = rule->flags | IORESOURCE_AUTO;
res->flags &= ~IORESOURCE_UNSET; res->start = -1;
res->end = -1;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (rule->map & (1 << xtab[i])) { if (rule->map & (1 << xtab[i])) {
res->start = res->end = xtab[i]; res->start = res->end = xtab[i];
if (pnp_check_dma(dev, res)) { if (pnp_check_dma(dev, res))
dev_dbg(&dev->dev, " assign dma %d %d\n", idx, goto __add;
(int) res->start);
return;
}
} }
} }
#ifdef MAX_DMA_CHANNELS #ifdef MAX_DMA_CHANNELS
res->start = res->end = MAX_DMA_CHANNELS; res->start = res->end = MAX_DMA_CHANNELS;
#endif #endif
res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; res->flags |= IORESOURCE_DISABLED;
dev_dbg(&dev->dev, " disable dma %d\n", idx); dev_dbg(&dev->dev, " disable dma %d\n", idx);
}
void pnp_init_resource(struct resource *res)
{
unsigned long type;
type = res->flags & (IORESOURCE_IO | IORESOURCE_MEM |
IORESOURCE_IRQ | IORESOURCE_DMA);
res->name = NULL; __add:
res->flags = type | IORESOURCE_AUTO | IORESOURCE_UNSET; pnp_add_dma_resource(dev, res->start, res->flags);
if (type == IORESOURCE_IRQ || type == IORESOURCE_DMA) {
res->start = -1;
res->end = -1;
} else {
res->start = 0;
res->end = 0;
}
} }
/**
* pnp_init_resources - Resets a resource table to default values.
* @table: pointer to the desired resource table
*/
void pnp_init_resources(struct pnp_dev *dev) void pnp_init_resources(struct pnp_dev *dev)
{ {
struct resource *res; pnp_free_resources(dev);
int idx;
for (idx = 0; idx < PNP_MAX_IRQ; idx++) {
res = &dev->res->irq[idx].res;
res->flags = IORESOURCE_IRQ;
pnp_init_resource(res);
}
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
res = &dev->res->dma[idx].res;
res->flags = IORESOURCE_DMA;
pnp_init_resource(res);
}
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
res = &dev->res->port[idx].res;
res->flags = IORESOURCE_IO;
pnp_init_resource(res);
}
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
res = &dev->res->mem[idx].res;
res->flags = IORESOURCE_MEM;
pnp_init_resource(res);
}
} }
/**
* pnp_clean_resources - clears resources that were not manually set
* @res: the resources to clean
*/
static void pnp_clean_resource_table(struct pnp_dev *dev) static void pnp_clean_resource_table(struct pnp_dev *dev)
{ {
struct resource *res; struct pnp_resource *pnp_res, *tmp;
int idx;
for (idx = 0; idx < PNP_MAX_IRQ; idx++) { list_for_each_entry_safe(pnp_res, tmp, &dev->resources, list) {
res = &dev->res->irq[idx].res; if (pnp_res->res.flags & IORESOURCE_AUTO)
if (res->flags & IORESOURCE_AUTO) { pnp_free_resource(pnp_res);
res->flags = IORESOURCE_IRQ;
pnp_init_resource(res);
}
}
for (idx = 0; idx < PNP_MAX_DMA; idx++) {
res = &dev->res->dma[idx].res;
if (res->flags & IORESOURCE_AUTO) {
res->flags = IORESOURCE_DMA;
pnp_init_resource(res);
}
}
for (idx = 0; idx < PNP_MAX_PORT; idx++) {
res = &dev->res->port[idx].res;
if (res->flags & IORESOURCE_AUTO) {
res->flags = IORESOURCE_IO;
pnp_init_resource(res);
}
}
for (idx = 0; idx < PNP_MAX_MEM; idx++) {
res = &dev->res->mem[idx].res;
if (res->flags & IORESOURCE_AUTO) {
res->flags = IORESOURCE_MEM;
pnp_init_resource(res);
}
} }
} }
......
...@@ -806,6 +806,13 @@ static void pnpacpi_encode_irq(struct pnp_dev *dev, ...@@ -806,6 +806,13 @@ static void pnpacpi_encode_irq(struct pnp_dev *dev,
struct acpi_resource_irq *irq = &resource->data.irq; struct acpi_resource_irq *irq = &resource->data.irq;
int triggering, polarity, shareable; int triggering, polarity, shareable;
if (!pnp_resource_enabled(p)) {
irq->interrupt_count = 0;
dev_dbg(&dev->dev, " encode irq (%s)\n",
p ? "disabled" : "missing");
return;
}
decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable);
irq->triggering = triggering; irq->triggering = triggering;
irq->polarity = polarity; irq->polarity = polarity;
...@@ -828,6 +835,13 @@ static void pnpacpi_encode_ext_irq(struct pnp_dev *dev, ...@@ -828,6 +835,13 @@ static void pnpacpi_encode_ext_irq(struct pnp_dev *dev,
struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq; struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
int triggering, polarity, shareable; int triggering, polarity, shareable;
if (!pnp_resource_enabled(p)) {
extended_irq->interrupt_count = 0;
dev_dbg(&dev->dev, " encode extended irq (%s)\n",
p ? "disabled" : "missing");
return;
}
decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable); decode_irq_flags(dev, p->flags, &triggering, &polarity, &shareable);
extended_irq->producer_consumer = ACPI_CONSUMER; extended_irq->producer_consumer = ACPI_CONSUMER;
extended_irq->triggering = triggering; extended_irq->triggering = triggering;
...@@ -848,6 +862,13 @@ static void pnpacpi_encode_dma(struct pnp_dev *dev, ...@@ -848,6 +862,13 @@ static void pnpacpi_encode_dma(struct pnp_dev *dev,
{ {
struct acpi_resource_dma *dma = &resource->data.dma; struct acpi_resource_dma *dma = &resource->data.dma;
if (!pnp_resource_enabled(p)) {
dma->channel_count = 0;
dev_dbg(&dev->dev, " encode dma (%s)\n",
p ? "disabled" : "missing");
return;
}
/* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
case IORESOURCE_DMA_TYPEA: case IORESOURCE_DMA_TYPEA:
...@@ -889,17 +910,21 @@ static void pnpacpi_encode_io(struct pnp_dev *dev, ...@@ -889,17 +910,21 @@ static void pnpacpi_encode_io(struct pnp_dev *dev,
{ {
struct acpi_resource_io *io = &resource->data.io; struct acpi_resource_io *io = &resource->data.io;
/* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ if (pnp_resource_enabled(p)) {
/* Note: pnp_assign_port copies pnp_port->flags into p->flags */
io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ? io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
ACPI_DECODE_16 : ACPI_DECODE_10; ACPI_DECODE_16 : ACPI_DECODE_10;
io->minimum = p->start; io->minimum = p->start;
io->maximum = p->end; io->maximum = p->end;
io->alignment = 0; /* Correct? */ io->alignment = 0; /* Correct? */
io->address_length = p->end - p->start + 1; io->address_length = p->end - p->start + 1;
} else {
io->minimum = 0;
io->address_length = 0;
}
dev_dbg(&dev->dev, " encode io %#llx-%#llx decode %#x\n", dev_dbg(&dev->dev, " encode io %#x-%#x decode %#x\n", io->minimum,
(unsigned long long) p->start, (unsigned long long) p->end, io->minimum + io->address_length - 1, io->io_decode);
io->io_decode);
} }
static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
...@@ -908,11 +933,16 @@ static void pnpacpi_encode_fixed_io(struct pnp_dev *dev, ...@@ -908,11 +933,16 @@ static void pnpacpi_encode_fixed_io(struct pnp_dev *dev,
{ {
struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io; struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
if (pnp_resource_enabled(p)) {
fixed_io->address = p->start; fixed_io->address = p->start;
fixed_io->address_length = p->end - p->start + 1; fixed_io->address_length = p->end - p->start + 1;
} else {
fixed_io->address = 0;
fixed_io->address_length = 0;
}
dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", dev_dbg(&dev->dev, " encode fixed_io %#x-%#x\n", fixed_io->address,
(unsigned long long) p->start, (unsigned long long) p->end); fixed_io->address + fixed_io->address_length - 1);
} }
static void pnpacpi_encode_mem24(struct pnp_dev *dev, static void pnpacpi_encode_mem24(struct pnp_dev *dev,
...@@ -921,17 +951,22 @@ static void pnpacpi_encode_mem24(struct pnp_dev *dev, ...@@ -921,17 +951,22 @@ static void pnpacpi_encode_mem24(struct pnp_dev *dev,
{ {
struct acpi_resource_memory24 *memory24 = &resource->data.memory24; struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
/* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ if (pnp_resource_enabled(p)) {
memory24->write_protect = /* Note: pnp_assign_mem copies pnp_mem->flags into p->flags */
(p->flags & IORESOURCE_MEM_WRITEABLE) ? memory24->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ?
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
memory24->minimum = p->start; memory24->minimum = p->start;
memory24->maximum = p->end; memory24->maximum = p->end;
memory24->alignment = 0; memory24->alignment = 0;
memory24->address_length = p->end - p->start + 1; memory24->address_length = p->end - p->start + 1;
} else {
memory24->minimum = 0;
memory24->address_length = 0;
}
dev_dbg(&dev->dev, " encode mem24 %#llx-%#llx write_protect %#x\n", dev_dbg(&dev->dev, " encode mem24 %#x-%#x write_protect %#x\n",
(unsigned long long) p->start, (unsigned long long) p->end, memory24->minimum,
memory24->minimum + memory24->address_length - 1,
memory24->write_protect); memory24->write_protect);
} }
...@@ -941,16 +976,21 @@ static void pnpacpi_encode_mem32(struct pnp_dev *dev, ...@@ -941,16 +976,21 @@ static void pnpacpi_encode_mem32(struct pnp_dev *dev,
{ {
struct acpi_resource_memory32 *memory32 = &resource->data.memory32; struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
memory32->write_protect = if (pnp_resource_enabled(p)) {
(p->flags & IORESOURCE_MEM_WRITEABLE) ? memory32->write_protect = p->flags & IORESOURCE_MEM_WRITEABLE ?
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
memory32->minimum = p->start; memory32->minimum = p->start;
memory32->maximum = p->end; memory32->maximum = p->end;
memory32->alignment = 0; memory32->alignment = 0;
memory32->address_length = p->end - p->start + 1; memory32->address_length = p->end - p->start + 1;
} else {
memory32->minimum = 0;
memory32->alignment = 0;
}
dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx write_protect %#x\n", dev_dbg(&dev->dev, " encode mem32 %#x-%#x write_protect %#x\n",
(unsigned long long) p->start, (unsigned long long) p->end, memory32->minimum,
memory32->minimum + memory32->address_length - 1,
memory32->write_protect); memory32->write_protect);
} }
...@@ -960,15 +1000,20 @@ static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev, ...@@ -960,15 +1000,20 @@ static void pnpacpi_encode_fixed_mem32(struct pnp_dev *dev,
{ {
struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32; struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
if (pnp_resource_enabled(p)) {
fixed_memory32->write_protect = fixed_memory32->write_protect =
(p->flags & IORESOURCE_MEM_WRITEABLE) ? p->flags & IORESOURCE_MEM_WRITEABLE ?
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
fixed_memory32->address = p->start; fixed_memory32->address = p->start;
fixed_memory32->address_length = p->end - p->start + 1; fixed_memory32->address_length = p->end - p->start + 1;
} else {
fixed_memory32->address = 0;
fixed_memory32->address_length = 0;
}
dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx " dev_dbg(&dev->dev, " encode fixed_mem32 %#x-%#x write_protect %#x\n",
"write_protect %#x\n", fixed_memory32->address,
(unsigned long long) p->start, (unsigned long long) p->end, fixed_memory32->address + fixed_memory32->address_length - 1,
fixed_memory32->write_protect); fixed_memory32->write_protect);
} }
......
...@@ -526,8 +526,16 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p, ...@@ -526,8 +526,16 @@ static unsigned char *pnpbios_parse_compatible_ids(unsigned char *p,
static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
struct resource *res) struct resource *res)
{ {
unsigned long base = res->start; unsigned long base;
unsigned long len = res->end - res->start + 1; unsigned long len;
if (pnp_resource_enabled(res)) {
base = res->start;
len = res->end - res->start + 1;
} else {
base = 0;
len = 0;
}
p[4] = (base >> 8) & 0xff; p[4] = (base >> 8) & 0xff;
p[5] = ((base >> 8) >> 8) & 0xff; p[5] = ((base >> 8) >> 8) & 0xff;
...@@ -536,15 +544,22 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p, ...@@ -536,15 +544,22 @@ static void pnpbios_encode_mem(struct pnp_dev *dev, unsigned char *p,
p[10] = (len >> 8) & 0xff; p[10] = (len >> 8) & 0xff;
p[11] = ((len >> 8) >> 8) & 0xff; p[11] = ((len >> 8) >> 8) & 0xff;
dev_dbg(&dev->dev, " encode mem %#llx-%#llx\n", dev_dbg(&dev->dev, " encode mem %#lx-%#lx\n", base, base + len - 1);
(unsigned long long) res->start, (unsigned long long) res->end);
} }
static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
struct resource *res) struct resource *res)
{ {
unsigned long base = res->start; unsigned long base;
unsigned long len = res->end - res->start + 1; unsigned long len;
if (pnp_resource_enabled(res)) {
base = res->start;
len = res->end - res->start + 1;
} else {
base = 0;
len = 0;
}
p[4] = base & 0xff; p[4] = base & 0xff;
p[5] = (base >> 8) & 0xff; p[5] = (base >> 8) & 0xff;
...@@ -559,15 +574,22 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p, ...@@ -559,15 +574,22 @@ static void pnpbios_encode_mem32(struct pnp_dev *dev, unsigned char *p,
p[18] = (len >> 16) & 0xff; p[18] = (len >> 16) & 0xff;
p[19] = (len >> 24) & 0xff; p[19] = (len >> 24) & 0xff;
dev_dbg(&dev->dev, " encode mem32 %#llx-%#llx\n", dev_dbg(&dev->dev, " encode mem32 %#lx-%#lx\n", base, base + len - 1);
(unsigned long long) res->start, (unsigned long long) res->end);
} }
static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
struct resource *res) struct resource *res)
{ {
unsigned long base = res->start; unsigned long base;
unsigned long len = res->end - res->start + 1; unsigned long len;
if (pnp_resource_enabled(res)) {
base = res->start;
len = res->end - res->start + 1;
} else {
base = 0;
len = 0;
}
p[4] = base & 0xff; p[4] = base & 0xff;
p[5] = (base >> 8) & 0xff; p[5] = (base >> 8) & 0xff;
...@@ -578,40 +600,54 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p, ...@@ -578,40 +600,54 @@ static void pnpbios_encode_fixed_mem32(struct pnp_dev *dev, unsigned char *p,
p[10] = (len >> 16) & 0xff; p[10] = (len >> 16) & 0xff;
p[11] = (len >> 24) & 0xff; p[11] = (len >> 24) & 0xff;
dev_dbg(&dev->dev, " encode fixed_mem32 %#llx-%#llx\n", dev_dbg(&dev->dev, " encode fixed_mem32 %#lx-%#lx\n", base,
(unsigned long long) res->start, (unsigned long long) res->end); base + len - 1);
} }
static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_irq(struct pnp_dev *dev, unsigned char *p,
struct resource *res) struct resource *res)
{ {
unsigned long map = 0; unsigned long map;
if (pnp_resource_enabled(res))
map = 1 << res->start; map = 1 << res->start;
else
map = 0;
p[1] = map & 0xff; p[1] = map & 0xff;
p[2] = (map >> 8) & 0xff; p[2] = (map >> 8) & 0xff;
dev_dbg(&dev->dev, " encode irq %llu\n", dev_dbg(&dev->dev, " encode irq mask %#lx\n", map);
(unsigned long long)res->start);
} }
static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_dma(struct pnp_dev *dev, unsigned char *p,
struct resource *res) struct resource *res)
{ {
unsigned long map = 0; unsigned long map;
if (pnp_resource_enabled(res))
map = 1 << res->start; map = 1 << res->start;
else
map = 0;
p[1] = map & 0xff; p[1] = map & 0xff;
dev_dbg(&dev->dev, " encode dma %llu\n", dev_dbg(&dev->dev, " encode dma mask %#lx\n", map);
(unsigned long long)res->start);
} }
static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
struct resource *res) struct resource *res)
{ {
unsigned long base = res->start; unsigned long base;
unsigned long len = res->end - res->start + 1; unsigned long len;
if (pnp_resource_enabled(res)) {
base = res->start;
len = res->end - res->start + 1;
} else {
base = 0;
len = 0;
}
p[2] = base & 0xff; p[2] = base & 0xff;
p[3] = (base >> 8) & 0xff; p[3] = (base >> 8) & 0xff;
...@@ -619,8 +655,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p, ...@@ -619,8 +655,7 @@ static void pnpbios_encode_port(struct pnp_dev *dev, unsigned char *p,
p[5] = (base >> 8) & 0xff; p[5] = (base >> 8) & 0xff;
p[7] = len & 0xff; p[7] = len & 0xff;
dev_dbg(&dev->dev, " encode io %#llx-%#llx\n", dev_dbg(&dev->dev, " encode io %#lx-%#lx\n", base, base + len - 1);
(unsigned long long) res->start, (unsigned long long) res->end);
} }
static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
...@@ -629,12 +664,20 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p, ...@@ -629,12 +664,20 @@ static void pnpbios_encode_fixed_port(struct pnp_dev *dev, unsigned char *p,
unsigned long base = res->start; unsigned long base = res->start;
unsigned long len = res->end - res->start + 1; unsigned long len = res->end - res->start + 1;
if (pnp_resource_enabled(res)) {
base = res->start;
len = res->end - res->start + 1;
} else {
base = 0;
len = 0;
}
p[1] = base & 0xff; p[1] = base & 0xff;
p[2] = (base >> 8) & 0xff; p[2] = (base >> 8) & 0xff;
p[3] = len & 0xff; p[3] = len & 0xff;
dev_dbg(&dev->dev, " encode fixed_io %#llx-%#llx\n", dev_dbg(&dev->dev, " encode fixed_io %#lx-%#lx\n", base,
(unsigned long long) res->start, (unsigned long long) res->end); base + len - 1);
} }
static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev static unsigned char *pnpbios_encode_allocated_resource_data(struct pnp_dev
......
...@@ -248,8 +248,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev) ...@@ -248,8 +248,7 @@ static void quirk_system_pci_resources(struct pnp_dev *dev)
for (j = 0; for (j = 0;
(res = pnp_get_resource(dev, IORESOURCE_MEM, j)); (res = pnp_get_resource(dev, IORESOURCE_MEM, j));
j++) { j++) {
if (res->flags & IORESOURCE_UNSET || if (res->start == 0 && res->end == 0)
(res->start == 0 && res->end == 0))
continue; continue;
pnp_start = res->start; pnp_start = res->start;
......
...@@ -237,7 +237,7 @@ void pnp_free_option(struct pnp_option *option) ...@@ -237,7 +237,7 @@ void pnp_free_option(struct pnp_option *option)
!((*(enda) < *(startb)) || (*(endb) < *(starta))) !((*(enda) < *(startb)) || (*(endb) < *(starta)))
#define cannot_compare(flags) \ #define cannot_compare(flags) \
((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) ((flags) & IORESOURCE_DISABLED)
int pnp_check_port(struct pnp_dev *dev, struct resource *res) int pnp_check_port(struct pnp_dev *dev, struct resource *res)
{ {
...@@ -505,81 +505,31 @@ int pnp_resource_type(struct resource *res) ...@@ -505,81 +505,31 @@ int pnp_resource_type(struct resource *res)
IORESOURCE_IRQ | IORESOURCE_DMA); IORESOURCE_IRQ | IORESOURCE_DMA);
} }
struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev,
unsigned int type, unsigned int num)
{
struct pnp_resource_table *res = dev->res;
switch (type) {
case IORESOURCE_IO:
if (num >= PNP_MAX_PORT)
return NULL;
return &res->port[num];
case IORESOURCE_MEM:
if (num >= PNP_MAX_MEM)
return NULL;
return &res->mem[num];
case IORESOURCE_IRQ:
if (num >= PNP_MAX_IRQ)
return NULL;
return &res->irq[num];
case IORESOURCE_DMA:
if (num >= PNP_MAX_DMA)
return NULL;
return &res->dma[num];
}
return NULL;
}
struct resource *pnp_get_resource(struct pnp_dev *dev, struct resource *pnp_get_resource(struct pnp_dev *dev,
unsigned int type, unsigned int num) unsigned int type, unsigned int num)
{ {
struct pnp_resource *pnp_res; struct pnp_resource *pnp_res;
struct resource *res;
pnp_res = pnp_get_pnp_resource(dev, type, num); list_for_each_entry(pnp_res, &dev->resources, list) {
if (pnp_res) res = &pnp_res->res;
return &pnp_res->res; if (pnp_resource_type(res) == type && num-- == 0)
return res;
}
return NULL; return NULL;
} }
EXPORT_SYMBOL(pnp_get_resource); EXPORT_SYMBOL(pnp_get_resource);
static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type) static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev)
{ {
struct pnp_resource *pnp_res; struct pnp_resource *pnp_res;
int i;
switch (type) { pnp_res = kzalloc(sizeof(struct pnp_resource), GFP_KERNEL);
case IORESOURCE_IO: if (!pnp_res)
for (i = 0; i < PNP_MAX_PORT; i++) {
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IO, i);
if (pnp_res && !pnp_resource_valid(&pnp_res->res))
return pnp_res;
}
break;
case IORESOURCE_MEM:
for (i = 0; i < PNP_MAX_MEM; i++) {
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_MEM, i);
if (pnp_res && !pnp_resource_valid(&pnp_res->res))
return pnp_res;
}
break;
case IORESOURCE_IRQ:
for (i = 0; i < PNP_MAX_IRQ; i++) {
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, i);
if (pnp_res && !pnp_resource_valid(&pnp_res->res))
return pnp_res;
}
break;
case IORESOURCE_DMA:
for (i = 0; i < PNP_MAX_DMA; i++) {
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_DMA, i);
if (pnp_res && !pnp_resource_valid(&pnp_res->res))
return pnp_res;
}
break;
}
return NULL; return NULL;
list_add_tail(&pnp_res->list, &dev->resources);
return pnp_res;
} }
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
...@@ -589,7 +539,7 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, ...@@ -589,7 +539,7 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
struct resource *res; struct resource *res;
static unsigned char warned; static unsigned char warned;
pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ); pnp_res = pnp_new_resource(dev);
if (!pnp_res) { if (!pnp_res) {
if (!warned) { if (!warned) {
dev_err(&dev->dev, "can't add resource for IRQ %d\n", dev_err(&dev->dev, "can't add resource for IRQ %d\n",
...@@ -615,7 +565,7 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, ...@@ -615,7 +565,7 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma,
struct resource *res; struct resource *res;
static unsigned char warned; static unsigned char warned;
pnp_res = pnp_new_resource(dev, IORESOURCE_DMA); pnp_res = pnp_new_resource(dev);
if (!pnp_res) { if (!pnp_res) {
if (!warned) { if (!warned) {
dev_err(&dev->dev, "can't add resource for DMA %d\n", dev_err(&dev->dev, "can't add resource for DMA %d\n",
...@@ -642,7 +592,7 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, ...@@ -642,7 +592,7 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev,
struct resource *res; struct resource *res;
static unsigned char warned; static unsigned char warned;
pnp_res = pnp_new_resource(dev, IORESOURCE_IO); pnp_res = pnp_new_resource(dev);
if (!pnp_res) { if (!pnp_res) {
if (!warned) { if (!warned) {
dev_err(&dev->dev, "can't add resource for IO " dev_err(&dev->dev, "can't add resource for IO "
...@@ -671,7 +621,7 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, ...@@ -671,7 +621,7 @@ struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev,
struct resource *res; struct resource *res;
static unsigned char warned; static unsigned char warned;
pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); pnp_res = pnp_new_resource(dev);
if (!pnp_res) { if (!pnp_res) {
if (!warned) { if (!warned) {
dev_err(&dev->dev, "can't add resource for MEM " dev_err(&dev->dev, "can't add resource for MEM "
......
...@@ -16,6 +16,10 @@ ...@@ -16,6 +16,10 @@
*/ */
int pnp_is_active(struct pnp_dev *dev) int pnp_is_active(struct pnp_dev *dev)
{ {
/*
* I don't think this is very reliable because pnp_disable_dev()
* only clears out auto-assigned resources.
*/
if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 && if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
!pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 && !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1) pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
...@@ -70,54 +74,41 @@ char *pnp_resource_type_name(struct resource *res) ...@@ -70,54 +74,41 @@ char *pnp_resource_type_name(struct resource *res)
void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc) void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
{ {
#ifdef DEBUG #ifdef DEBUG
char buf[128];
int len = 0;
struct pnp_resource *pnp_res;
struct resource *res; struct resource *res;
int i;
dev_dbg(&dev->dev, "current resources: %s\n", desc); dev_dbg(&dev->dev, "current resources: %s\n", desc);
list_for_each_entry(pnp_res, &dev->resources, list) {
res = &pnp_res->res;
for (i = 0; i < PNP_MAX_IRQ; i++) { len += snprintf(buf + len, sizeof(buf) - len, " %-3s ",
res = pnp_get_resource(dev, IORESOURCE_IRQ, i); pnp_resource_type_name(res));
if (res && !(res->flags & IORESOURCE_UNSET))
dev_dbg(&dev->dev, " irq %lld flags %#lx%s%s\n", if (res->flags & IORESOURCE_DISABLED) {
(unsigned long long) res->start, res->flags, dev_dbg(&dev->dev, "%sdisabled\n", buf);
res->flags & IORESOURCE_DISABLED ? continue;
" DISABLED" : "",
res->flags & IORESOURCE_AUTO ?
" AUTO" : "");
}
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%s%s\n",
(unsigned long long) res->start, res->flags,
res->flags & IORESOURCE_DISABLED ?
" DISABLED" : "",
res->flags & IORESOURCE_AUTO ?
" AUTO" : "");
} }
for (i = 0; i < PNP_MAX_PORT; i++) {
res = pnp_get_resource(dev, IORESOURCE_IO, i); switch (pnp_resource_type(res)) {
if (res && !(res->flags & IORESOURCE_UNSET)) case IORESOURCE_IO:
dev_dbg(&dev->dev, " io %#llx-%#llx flags %#lx" case IORESOURCE_MEM:
"%s%s\n", len += snprintf(buf + len, sizeof(buf) - len,
"%#llx-%#llx flags %#lx",
(unsigned long long) res->start, (unsigned long long) res->start,
(unsigned long long) res->end, res->flags, (unsigned long long) res->end,
res->flags & IORESOURCE_DISABLED ? res->flags);
" DISABLED" : "", break;
res->flags & IORESOURCE_AUTO ? case IORESOURCE_IRQ:
" AUTO" : ""); case IORESOURCE_DMA:
} len += snprintf(buf + len, sizeof(buf) - len,
for (i = 0; i < PNP_MAX_MEM; i++) { "%lld flags %#lx",
res = pnp_get_resource(dev, IORESOURCE_MEM, i);
if (res && !(res->flags & IORESOURCE_UNSET))
dev_dbg(&dev->dev, " mem %#llx-%#llx flags %#lx"
"%s%s\n",
(unsigned long long) res->start, (unsigned long long) res->start,
(unsigned long long) res->end, res->flags, res->flags);
res->flags & IORESOURCE_DISABLED ? break;
" DISABLED" : "", }
res->flags & IORESOURCE_AUTO ? dev_dbg(&dev->dev, "%s\n", buf);
" AUTO" : "");
} }
#endif #endif
} }
...@@ -60,7 +60,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev) ...@@ -60,7 +60,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
int i; int i;
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) {
if (res->flags & IORESOURCE_UNSET) if (res->flags & IORESOURCE_DISABLED)
continue; continue;
if (res->start == 0) if (res->start == 0)
continue; /* disabled */ continue; /* disabled */
...@@ -81,7 +81,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev) ...@@ -81,7 +81,7 @@ static void reserve_resources_of_dev(struct pnp_dev *dev)
} }
for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { for (i = 0; (res = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) {
if (res->flags & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) if (res->flags & IORESOURCE_DISABLED)
continue; continue;
reserve_range(dev, res->start, res->end, 0); reserve_range(dev, res->start, res->end, 0);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
struct pnp_protocol; struct pnp_protocol;
struct pnp_dev; struct pnp_dev;
struct pnp_resource_table;
/* /*
* Resource Management * Resource Management
...@@ -24,7 +23,14 @@ struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int); ...@@ -24,7 +23,14 @@ struct resource *pnp_get_resource(struct pnp_dev *, unsigned int, unsigned int);
static inline int pnp_resource_valid(struct resource *res) static inline int pnp_resource_valid(struct resource *res)
{ {
if (res && !(res->flags & IORESOURCE_UNSET)) if (res)
return 1;
return 0;
}
static inline int pnp_resource_enabled(struct resource *res)
{
if (res && !(res->flags & IORESOURCE_DISABLED))
return 1; return 1;
return 0; return 0;
} }
...@@ -64,7 +70,7 @@ static inline unsigned long pnp_port_flags(struct pnp_dev *dev, ...@@ -64,7 +70,7 @@ static inline unsigned long pnp_port_flags(struct pnp_dev *dev,
if (pnp_resource_valid(res)) if (pnp_resource_valid(res))
return res->flags; return res->flags;
return IORESOURCE_IO | IORESOURCE_AUTO | IORESOURCE_UNSET; return IORESOURCE_IO | IORESOURCE_AUTO;
} }
static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar) static inline int pnp_port_valid(struct pnp_dev *dev, unsigned int bar)
...@@ -109,7 +115,7 @@ static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar) ...@@ -109,7 +115,7 @@ static inline unsigned long pnp_mem_flags(struct pnp_dev *dev, unsigned int bar)
if (pnp_resource_valid(res)) if (pnp_resource_valid(res))
return res->flags; return res->flags;
return IORESOURCE_MEM | IORESOURCE_AUTO | IORESOURCE_UNSET; return IORESOURCE_MEM | IORESOURCE_AUTO;
} }
static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar) static inline int pnp_mem_valid(struct pnp_dev *dev, unsigned int bar)
...@@ -143,7 +149,7 @@ static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar) ...@@ -143,7 +149,7 @@ static inline unsigned long pnp_irq_flags(struct pnp_dev *dev, unsigned int bar)
if (pnp_resource_valid(res)) if (pnp_resource_valid(res))
return res->flags; return res->flags;
return IORESOURCE_IRQ | IORESOURCE_AUTO | IORESOURCE_UNSET; return IORESOURCE_IRQ | IORESOURCE_AUTO;
} }
static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar) static inline int pnp_irq_valid(struct pnp_dev *dev, unsigned int bar)
...@@ -167,7 +173,7 @@ static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar) ...@@ -167,7 +173,7 @@ static inline unsigned long pnp_dma_flags(struct pnp_dev *dev, unsigned int bar)
if (pnp_resource_valid(res)) if (pnp_resource_valid(res))
return res->flags; return res->flags;
return IORESOURCE_DMA | IORESOURCE_AUTO | IORESOURCE_UNSET; return IORESOURCE_DMA | IORESOURCE_AUTO;
} }
static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar) static inline int pnp_dma_valid(struct pnp_dev *dev, unsigned int bar)
...@@ -296,7 +302,7 @@ struct pnp_dev { ...@@ -296,7 +302,7 @@ struct pnp_dev {
int capabilities; int capabilities;
struct pnp_option *independent; struct pnp_option *independent;
struct pnp_option *dependent; struct pnp_option *dependent;
struct pnp_resource_table *res; struct list_head resources;
char name[PNP_NAME_LEN]; /* contains a human-readable name */ char name[PNP_NAME_LEN]; /* contains a human-readable name */
int flags; /* used by protocols */ int flags; /* used by protocols */
......
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