PNP: make generic pnp_add_irq_resource()

Add a pnp_add_irq_resource() that can be used by all the PNP
backends.  This consolidates a little more pnp_resource_table
knowledge into one place.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Bjorn Helgaas 2008-04-28 16:34:34 -06:00 committed by Len Brown
parent a50b6d7b8d
commit dbddd0383c
6 changed files with 51 additions and 66 deletions

View File

@ -40,3 +40,6 @@ struct pnp_resource_table {
struct pnp_resource dma[PNP_MAX_DMA]; struct pnp_resource dma[PNP_MAX_DMA];
struct pnp_resource irq[PNP_MAX_IRQ]; struct pnp_resource irq[PNP_MAX_IRQ];
}; };
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
int flags);

View File

@ -324,6 +324,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
struct resource *res; struct resource *res;
char *buf = (void *)ubuf; char *buf = (void *)ubuf;
int retval = 0; int retval = 0;
resource_size_t start;
if (dev->status & PNP_ATTACHED) { if (dev->status & PNP_ATTACHED) {
retval = -EBUSY; retval = -EBUSY;
@ -429,16 +430,10 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
buf += 3; buf += 3;
while (isspace(*buf)) while (isspace(*buf))
++buf; ++buf;
pnp_res = pnp_get_pnp_resource(dev, start = simple_strtoul(buf, &buf, 0);
IORESOURCE_IRQ, nirq); pnp_res = pnp_add_irq_resource(dev, start, 0);
if (!pnp_res) if (pnp_res)
break; nirq++;
pnp_res->index = nirq;
res = &pnp_res->res;
res->start = res->end =
simple_strtoul(buf, &buf, 0);
res->flags = IORESOURCE_IRQ;
nirq++;
continue; continue;
} }
if (!strnicmp(buf, "dma", 3)) { if (!strnicmp(buf, "dma", 3)) {

View File

@ -965,12 +965,9 @@ static int isapnp_read_resources(struct pnp_dev *dev)
8); 8);
if (!ret) if (!ret)
continue; continue;
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ, pnp_res = pnp_add_irq_resource(dev, ret, 0);
tmp); if (pnp_res)
pnp_res->index = tmp; pnp_res->index = tmp;
res = &pnp_res->res;
res->start = res->end = ret;
res->flags = IORESOURCE_IRQ;
} }
for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp); ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);

View File

@ -82,28 +82,12 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
u32 gsi, int triggering, u32 gsi, int triggering,
int polarity, int shareable) int polarity, int shareable)
{ {
struct resource *res; int irq, flags;
int i;
int irq;
int p, t; int p, t;
static unsigned char warned;
if (!valid_IRQ(gsi)) if (!valid_IRQ(gsi))
return; return;
for (i = 0; i < PNP_MAX_IRQ; i++) {
res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
if (!pnp_resource_valid(res))
break;
}
if (i >= PNP_MAX_IRQ) {
if (!warned) {
printk(KERN_WARNING "pnpacpi: exceeded the max number"
" of IRQ resources: %d\n", PNP_MAX_IRQ);
warned = 1;
}
return;
}
/* /*
* in IO-APIC mode, use overrided attribute. Two reasons: * in IO-APIC mode, use overrided attribute. Two reasons:
* 1. BIOS bug in DSDT * 1. BIOS bug in DSDT
@ -121,17 +105,14 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
} }
} }
res->flags = IORESOURCE_IRQ; // Also clears _UNSET flag flags = irq_flags(triggering, polarity, shareable);
res->flags |= irq_flags(triggering, polarity, shareable);
irq = acpi_register_gsi(gsi, triggering, polarity); irq = acpi_register_gsi(gsi, triggering, polarity);
if (irq < 0) { if (irq >= 0)
res->flags |= IORESOURCE_DISABLED; pcibios_penalize_isa_irq(irq, 1);
return; else
} flags |= IORESOURCE_DISABLED;
res->start = irq; pnp_add_irq_resource(dev, irq, flags);
res->end = irq;
pcibios_penalize_isa_irq(irq, 1);
} }
static int dma_flags(int type, int bus_master, int transfer) static int dma_flags(int type, int bus_master, int transfer)

View File

@ -54,28 +54,6 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
* Allocated Resources * Allocated Resources
*/ */
static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq)
{
struct resource *res;
int i;
for (i = 0; i < PNP_MAX_IRQ; i++) {
res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
if (!pnp_resource_valid(res))
break;
}
if (i < PNP_MAX_IRQ) {
res->flags = IORESOURCE_IRQ; // Also clears _UNSET flag
if (irq == -1) {
res->flags |= IORESOURCE_DISABLED;
return;
}
res->start = res->end = (unsigned long)irq;
pcibios_penalize_isa_irq(irq, 1);
}
}
static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma) static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
{ {
struct resource *res; struct resource *res;
@ -148,7 +126,7 @@ static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
unsigned char *end) unsigned char *end)
{ {
unsigned int len, tag; unsigned int len, tag;
int io, size, mask, i; int io, size, mask, i, flags;
if (!p) if (!p)
return NULL; return NULL;
@ -205,12 +183,17 @@ static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
case SMALL_TAG_IRQ: case SMALL_TAG_IRQ:
if (len < 2 || len > 3) if (len < 2 || len > 3)
goto len_err; goto len_err;
flags = 0;
io = -1; io = -1;
mask = p[1] + p[2] * 256; mask = p[1] + p[2] * 256;
for (i = 0; i < 16; i++, mask = mask >> 1) for (i = 0; i < 16; i++, mask = mask >> 1)
if (mask & 0x01) if (mask & 0x01)
io = i; io = i;
pnpbios_parse_allocated_irqresource(dev, io); if (io != -1)
pcibios_penalize_isa_irq(io, 1);
else
flags = IORESOURCE_DISABLED;
pnp_add_irq_resource(dev, io, flags);
break; break;
case SMALL_TAG_DMA: case SMALL_TAG_DMA:

View File

@ -576,6 +576,32 @@ static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type)
return NULL; return NULL;
} }
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
int flags)
{
struct pnp_resource *pnp_res;
struct resource *res;
static unsigned char warned;
pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ);
if (!pnp_res) {
if (!warned) {
dev_err(&dev->dev, "can't add resource for IRQ %d\n",
irq);
warned = 1;
}
return NULL;
}
res = &pnp_res->res;
res->flags = IORESOURCE_IRQ | flags;
res->start = irq;
res->end = irq;
dev_dbg(&dev->dev, " add irq %d flags %#x\n", irq, flags);
return pnp_res;
}
/* format is: pnp_reserve_irq=irq1[,irq2] .... */ /* format is: pnp_reserve_irq=irq1[,irq2] .... */
static int __init pnp_setup_reserve_irq(char *str) static int __init pnp_setup_reserve_irq(char *str)
{ {