Skip to content

Commit dbddd03

Browse files
Bjorn Helgaaslenb
authored andcommitted
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>
1 parent a50b6d7 commit dbddd03

6 files changed

Lines changed: 51 additions & 66 deletions

File tree

‎drivers/pnp/base.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,6 @@ struct pnp_resource_table {
4040
struct pnp_resource dma[PNP_MAX_DMA];
4141
struct pnp_resource irq[PNP_MAX_IRQ];
4242
};
43+
44+
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
45+
int flags);

‎drivers/pnp/interface.c‎

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,7 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
324324
struct resource *res;
325325
char *buf = (void *)ubuf;
326326
int retval = 0;
327+
resource_size_t start;
327328

328329
if (dev->status & PNP_ATTACHED) {
329330
retval = -EBUSY;
@@ -429,16 +430,10 @@ pnp_set_current_resources(struct device *dmdev, struct device_attribute *attr,
429430
buf += 3;
430431
while (isspace(*buf))
431432
++buf;
432-
pnp_res = pnp_get_pnp_resource(dev,
433-
IORESOURCE_IRQ, nirq);
434-
if (!pnp_res)
435-
break;
436-
pnp_res->index = nirq;
437-
res = &pnp_res->res;
438-
res->start = res->end =
439-
simple_strtoul(buf, &buf, 0);
440-
res->flags = IORESOURCE_IRQ;
441-
nirq++;
433+
start = simple_strtoul(buf, &buf, 0);
434+
pnp_res = pnp_add_irq_resource(dev, start, 0);
435+
if (pnp_res)
436+
nirq++;
442437
continue;
443438
}
444439
if (!strnicmp(buf, "dma", 3)) {

‎drivers/pnp/isapnp/core.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -965,12 +965,9 @@ static int isapnp_read_resources(struct pnp_dev *dev)
965965
8);
966966
if (!ret)
967967
continue;
968-
pnp_res = pnp_get_pnp_resource(dev, IORESOURCE_IRQ,
969-
tmp);
970-
pnp_res->index = tmp;
971-
res = &pnp_res->res;
972-
res->start = res->end = ret;
973-
res->flags = IORESOURCE_IRQ;
968+
pnp_res = pnp_add_irq_resource(dev, ret, 0);
969+
if (pnp_res)
970+
pnp_res->index = tmp;
974971
}
975972
for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) {
976973
ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp);

‎drivers/pnp/pnpacpi/rsparser.c‎

Lines changed: 7 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,12 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
8282
u32 gsi, int triggering,
8383
int polarity, int shareable)
8484
{
85-
struct resource *res;
86-
int i;
87-
int irq;
85+
int irq, flags;
8886
int p, t;
89-
static unsigned char warned;
9087

9188
if (!valid_IRQ(gsi))
9289
return;
9390

94-
for (i = 0; i < PNP_MAX_IRQ; i++) {
95-
res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
96-
if (!pnp_resource_valid(res))
97-
break;
98-
}
99-
if (i >= PNP_MAX_IRQ) {
100-
if (!warned) {
101-
printk(KERN_WARNING "pnpacpi: exceeded the max number"
102-
" of IRQ resources: %d\n", PNP_MAX_IRQ);
103-
warned = 1;
104-
}
105-
return;
106-
}
10791
/*
10892
* in IO-APIC mode, use overrided attribute. Two reasons:
10993
* 1. BIOS bug in DSDT
@@ -121,17 +105,14 @@ static void pnpacpi_parse_allocated_irqresource(struct pnp_dev *dev,
121105
}
122106
}
123107

124-
res->flags = IORESOURCE_IRQ; // Also clears _UNSET flag
125-
res->flags |= irq_flags(triggering, polarity, shareable);
108+
flags = irq_flags(triggering, polarity, shareable);
126109
irq = acpi_register_gsi(gsi, triggering, polarity);
127-
if (irq < 0) {
128-
res->flags |= IORESOURCE_DISABLED;
129-
return;
130-
}
110+
if (irq >= 0)
111+
pcibios_penalize_isa_irq(irq, 1);
112+
else
113+
flags |= IORESOURCE_DISABLED;
131114

132-
res->start = irq;
133-
res->end = irq;
134-
pcibios_penalize_isa_irq(irq, 1);
115+
pnp_add_irq_resource(dev, irq, flags);
135116
}
136117

137118
static int dma_flags(int type, int bus_master, int transfer)

‎drivers/pnp/pnpbios/rsparser.c‎

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,6 @@ inline void pcibios_penalize_isa_irq(int irq, int active)
5454
* Allocated Resources
5555
*/
5656

57-
static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq)
58-
{
59-
struct resource *res;
60-
int i;
61-
62-
for (i = 0; i < PNP_MAX_IRQ; i++) {
63-
res = pnp_get_resource(dev, IORESOURCE_IRQ, i);
64-
if (!pnp_resource_valid(res))
65-
break;
66-
}
67-
68-
if (i < PNP_MAX_IRQ) {
69-
res->flags = IORESOURCE_IRQ; // Also clears _UNSET flag
70-
if (irq == -1) {
71-
res->flags |= IORESOURCE_DISABLED;
72-
return;
73-
}
74-
res->start = res->end = (unsigned long)irq;
75-
pcibios_penalize_isa_irq(irq, 1);
76-
}
77-
}
78-
7957
static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma)
8058
{
8159
struct resource *res;
@@ -148,7 +126,7 @@ static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
148126
unsigned char *end)
149127
{
150128
unsigned int len, tag;
151-
int io, size, mask, i;
129+
int io, size, mask, i, flags;
152130

153131
if (!p)
154132
return NULL;
@@ -205,12 +183,17 @@ static unsigned char *pnpbios_parse_allocated_resource_data(struct pnp_dev *dev,
205183
case SMALL_TAG_IRQ:
206184
if (len < 2 || len > 3)
207185
goto len_err;
186+
flags = 0;
208187
io = -1;
209188
mask = p[1] + p[2] * 256;
210189
for (i = 0; i < 16; i++, mask = mask >> 1)
211190
if (mask & 0x01)
212191
io = i;
213-
pnpbios_parse_allocated_irqresource(dev, io);
192+
if (io != -1)
193+
pcibios_penalize_isa_irq(io, 1);
194+
else
195+
flags = IORESOURCE_DISABLED;
196+
pnp_add_irq_resource(dev, io, flags);
214197
break;
215198

216199
case SMALL_TAG_DMA:

‎drivers/pnp/resource.c‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -576,6 +576,32 @@ static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type)
576576
return NULL;
577577
}
578578

579+
struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq,
580+
int flags)
581+
{
582+
struct pnp_resource *pnp_res;
583+
struct resource *res;
584+
static unsigned char warned;
585+
586+
pnp_res = pnp_new_resource(dev, IORESOURCE_IRQ);
587+
if (!pnp_res) {
588+
if (!warned) {
589+
dev_err(&dev->dev, "can't add resource for IRQ %d\n",
590+
irq);
591+
warned = 1;
592+
}
593+
return NULL;
594+
}
595+
596+
res = &pnp_res->res;
597+
res->flags = IORESOURCE_IRQ | flags;
598+
res->start = irq;
599+
res->end = irq;
600+
601+
dev_dbg(&dev->dev, " add irq %d flags %#x\n", irq, flags);
602+
return pnp_res;
603+
}
604+
579605
/* format is: pnp_reserve_irq=irq1[,irq2] .... */
580606
static int __init pnp_setup_reserve_irq(char *str)
581607
{

0 commit comments

Comments
 (0)