Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1763289AbYCZROs (ORCPT ); Wed, 26 Mar 2008 13:14:48 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1760983AbYCZRJG (ORCPT ); Wed, 26 Mar 2008 13:09:06 -0400 Received: from g1t0028.austin.hp.com ([15.216.28.35]:15626 "EHLO g1t0028.austin.hp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1760820AbYCZRI4 (ORCPT ); Wed, 26 Mar 2008 13:08:56 -0400 Message-Id: <20080326171227.337776334@ldl.fc.hp.com> References: <20080326171058.099442579@ldl.fc.hp.com> User-Agent: quilt/0.46-1 Date: Wed, 26 Mar 2008 11:11:18 -0600 From: Bjorn Helgaas To: Len Brown Cc: linux-acpi@vger.kernel.org Cc: linux-kernel@vger.kernel.org Cc: Adam Belay Cc: Li Shaohua Cc: Matthieu Castet Cc: Thomas Renninger Cc: Rene Herman Cc: Jaroslav Kysela Cc: Andrew Morton Subject: [patch 20/37] PNP: make generic pnp_add_irq_resource() Content-Disposition: inline; filename=pnp-common-add-irq-resource Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 7058 Lines: 223 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 --- drivers/pnp/base.h | 2 ++ drivers/pnp/interface.c | 14 ++++---------- drivers/pnp/isapnp/core.c | 4 +--- drivers/pnp/pnpacpi/rsparser.c | 28 +++++----------------------- drivers/pnp/pnpbios/rsparser.c | 23 ++--------------------- drivers/pnp/resource.c | 26 ++++++++++++++++++++++++++ 6 files changed, 40 insertions(+), 57 deletions(-) Index: work7/drivers/pnp/base.h =================================================================== --- work7.orig/drivers/pnp/base.h 2008-03-25 14:48:35.000000000 -0600 +++ work7/drivers/pnp/base.h 2008-03-25 14:48:51.000000000 -0600 @@ -14,3 +14,5 @@ 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_add_irq_resource(struct pnp_dev *dev, int irq, int flags); Index: work7/drivers/pnp/resource.c =================================================================== --- work7.orig/drivers/pnp/resource.c 2008-03-25 14:48:20.000000000 -0600 +++ work7/drivers/pnp/resource.c 2008-03-25 14:48:51.000000000 -0600 @@ -461,6 +461,32 @@ #endif } +#define set(flags) ((flags & IORESOURCE_UNSET) == 0) + +int pnp_add_irq_resource(struct pnp_dev *dev, int irq, int flags) +{ + struct pnp_resource_table *res = &dev->res; + int i = 0; + static unsigned char warned; + + while (set(res->irq_resource[i].flags) && i < PNP_MAX_IRQ) + i++; + if (i >= PNP_MAX_IRQ && !warned) { + dev_err(&dev->dev, "too many IRQs (max %d)\n", PNP_MAX_IRQ); + warned = 1; + return -ENOSPC; + } + + res->irq_resource[i].flags = IORESOURCE_IRQ | flags; + if (irq < 0) { + res->irq_resource[i].flags |= IORESOURCE_DISABLED; + return -EINVAL; + } + res->irq_resource[i].start = irq; + res->irq_resource[i].end = irq; + return 0; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { Index: work7/drivers/pnp/isapnp/core.c =================================================================== --- work7.orig/drivers/pnp/isapnp/core.c 2008-03-25 14:48:47.000000000 -0600 +++ work7/drivers/pnp/isapnp/core.c 2008-03-25 14:48:51.000000000 -0600 @@ -962,9 +962,7 @@ 8); if (!ret) continue; - res->irq_resource[tmp].start = - res->irq_resource[tmp].end = ret; - res->irq_resource[tmp].flags = IORESOURCE_IRQ; + pnp_add_irq_resource(dev, ret, 0); } for (tmp = 0; tmp < ISAPNP_MAX_DMA; tmp++) { ret = isapnp_read_byte(ISAPNP_CFG_DMA + tmp); Index: work7/drivers/pnp/pnpacpi/rsparser.c =================================================================== --- work7.orig/drivers/pnp/pnpacpi/rsparser.c 2008-03-25 14:48:47.000000000 -0600 +++ work7/drivers/pnp/pnpacpi/rsparser.c 2008-03-25 14:48:51.000000000 -0600 @@ -22,6 +22,7 @@ #include #include #include "pnpacpi.h" +#include "../base.h" #ifdef CONFIG_IA64 #define valid_IRQ(i) (1) @@ -80,24 +81,12 @@ u32 gsi, int triggering, int polarity, int shareable) { - struct pnp_resource_table *res = &dev->res; - int i = 0; - int irq; + int irq, flags; int p, t; - static unsigned char warned; if (!valid_IRQ(gsi)) return; - while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) && - i < PNP_MAX_IRQ) - i++; - if (i >= PNP_MAX_IRQ && !warned) { - printk(KERN_ERR "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: * 1. BIOS bug in DSDT @@ -114,18 +103,11 @@ polarity = p; } } + flags = irq_flags(triggering, polarity, shareable); - res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag - res->irq_resource[i].flags |= irq_flags(triggering, polarity, shareable); irq = acpi_register_gsi(gsi, triggering, polarity); - if (irq < 0) { - res->irq_resource[i].flags |= IORESOURCE_DISABLED; - return; - } - - res->irq_resource[i].start = irq; - res->irq_resource[i].end = irq; - pcibios_penalize_isa_irq(irq, 1); + if (pnp_add_irq_resource(dev, irq, flags) == 0) + pcibios_penalize_isa_irq(irq, 1); } static int dma_flags(int type, int bus_master, int transfer) Index: work7/drivers/pnp/pnpbios/rsparser.c =================================================================== --- work7.orig/drivers/pnp/pnpbios/rsparser.c 2008-03-25 14:48:47.000000000 -0600 +++ work7/drivers/pnp/pnpbios/rsparser.c 2008-03-25 14:48:51.000000000 -0600 @@ -54,26 +54,6 @@ * Allocated Resources */ -static void pnpbios_parse_allocated_irqresource(struct pnp_dev *dev, int irq) -{ - struct pnp_resource_table *res = &dev->res; - int i = 0; - - while (!(res->irq_resource[i].flags & IORESOURCE_UNSET) - && i < PNP_MAX_IRQ) - i++; - if (i < PNP_MAX_IRQ) { - res->irq_resource[i].flags = IORESOURCE_IRQ; // Also clears _UNSET flag - if (irq == -1) { - res->irq_resource[i].flags |= IORESOURCE_DISABLED; - return; - } - res->irq_resource[i].start = - res->irq_resource[i].end = (unsigned long)irq; - pcibios_penalize_isa_irq(irq, 1); - } -} - static void pnpbios_parse_allocated_dmaresource(struct pnp_dev *dev, int dma) { struct pnp_resource_table *res = &dev->res; @@ -198,7 +178,8 @@ for (i = 0; i < 16; i++, mask = mask >> 1) if (mask & 0x01) io = i; - pnpbios_parse_allocated_irqresource(dev, io); + if (pnp_add_irq_resource(dev, io, 0) == 0) + pcibios_penalize_isa_irq(io, 1); break; case SMALL_TAG_DMA: Index: work7/drivers/pnp/interface.c =================================================================== --- work7.orig/drivers/pnp/interface.c 2008-03-25 14:48:47.000000000 -0600 +++ work7/drivers/pnp/interface.c 2008-03-25 14:48:51.000000000 -0600 @@ -325,6 +325,7 @@ struct pnp_dev *dev = to_pnp_dev(dmdev); char *buf = (void *)ubuf; int retval = 0; + resource_size_t start; if (dev->status & PNP_ATTACHED) { retval = -EBUSY; @@ -369,7 +370,7 @@ goto done; } if (!strnicmp(buf, "set", 3)) { - int nport = 0, nmem = 0, nirq = 0, ndma = 0; + int nport = 0, nmem = 0, ndma = 0; if (dev->active) goto done; buf += 3; @@ -430,14 +431,8 @@ 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; - nirq++; - if (nirq >= PNP_MAX_IRQ) - break; + start = simple_strtoul(buf, &buf, 0); + pnp_add_irq_resource(dev, start, 0); continue; } if (!strnicmp(buf, "dma", 3)) { -- -- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/