From c1caf06ccfd3a4efd4b489f89bcdabd2362f31d0 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:04 -0600 Subject: PNP: add debug output to option registration Add debug output to resource option registration functions (enabled by CONFIG_PNP_DEBUG). This uses dev_printk, so I had to add pnp_dev arguments at the same time. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 34 ++++++++++++++++++++++++++++++---- 1 file changed, 30 insertions(+), 4 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index e50ebcffb962..eee6d8eddcb4 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -53,6 +53,8 @@ struct pnp_option *pnp_register_independent_option(struct pnp_dev *dev) if (dev->independent) dev_err(&dev->dev, "independent resource already registered\n"); dev->independent = option; + + dev_dbg(&dev->dev, "new independent option\n"); return option; } @@ -70,12 +72,18 @@ struct pnp_option *pnp_register_dependent_option(struct pnp_dev *dev, parent->next = option; } else dev->dependent = option; + + dev_dbg(&dev->dev, "new dependent option (priority %#x)\n", priority); return option; } -int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) +int pnp_register_irq_resource(struct pnp_dev *dev, struct pnp_option *option, + struct pnp_irq *data) { struct pnp_irq *ptr; +#ifdef DEBUG + char buf[PNP_IRQ_NR]; /* hex-encoded, so this is overkill but safe */ +#endif ptr = option->irq; while (ptr && ptr->next) @@ -94,10 +102,17 @@ int pnp_register_irq_resource(struct pnp_option *option, struct pnp_irq *data) pcibios_penalize_isa_irq(i, 0); } #endif + +#ifdef DEBUG + bitmap_scnprintf(buf, sizeof(buf), data->map, PNP_IRQ_NR); + dev_dbg(&dev->dev, " irq bitmask %s flags %#x\n", buf, + data->flags); +#endif return 0; } -int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) +int pnp_register_dma_resource(struct pnp_dev *dev, struct pnp_option *option, + struct pnp_dma *data) { struct pnp_dma *ptr; @@ -109,10 +124,13 @@ int pnp_register_dma_resource(struct pnp_option *option, struct pnp_dma *data) else option->dma = data; + dev_dbg(&dev->dev, " dma bitmask %#x flags %#x\n", data->map, + data->flags); return 0; } -int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) +int pnp_register_port_resource(struct pnp_dev *dev, struct pnp_option *option, + struct pnp_port *data) { struct pnp_port *ptr; @@ -124,10 +142,14 @@ int pnp_register_port_resource(struct pnp_option *option, struct pnp_port *data) else option->port = data; + dev_dbg(&dev->dev, " io " + "min %#x max %#x align %d size %d flags %#x\n", + data->min, data->max, data->align, data->size, data->flags); return 0; } -int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) +int pnp_register_mem_resource(struct pnp_dev *dev, struct pnp_option *option, + struct pnp_mem *data) { struct pnp_mem *ptr; @@ -138,6 +160,10 @@ int pnp_register_mem_resource(struct pnp_option *option, struct pnp_mem *data) ptr->next = data; else option->mem = data; + + dev_dbg(&dev->dev, " mem " + "min %#x max %#x align %d size %d flags %#x\n", + data->min, data->max, data->align, data->size, data->flags); return 0; } -- cgit v1.2.3 From b90eca0a61ebd010036242e29610bc6a909e3f19 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:14 -0600 Subject: PNP: add pnp_get_resource() interface This adds a pnp_get_resource() that works the same way as platform_get_resource(). This will enable us to consolidate many pnp_resource_table references in one place, which will make it easier to make the table dynamic. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index eee6d8eddcb4..ef8835ec5778 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -487,6 +487,33 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) #endif } +struct resource *pnp_get_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_resource[num]; + case IORESOURCE_MEM: + if (num >= PNP_MAX_MEM) + return NULL; + return &res->mem_resource[num]; + case IORESOURCE_IRQ: + if (num >= PNP_MAX_IRQ) + return NULL; + return &res->irq_resource[num]; + case IORESOURCE_DMA: + if (num >= PNP_MAX_DMA) + return NULL; + return &res->dma_resource[num]; + } + return NULL; +} +EXPORT_SYMBOL(pnp_get_resource); + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { -- cgit v1.2.3 From ecfa935a2f7ef89543608f3ca05340c158c9a236 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:17 -0600 Subject: PNP: use conventional "i" for loop indices Cosmetic only: just use "i" instead of "tmp". Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 92 +++++++++++++++++++++++++------------------------- 1 file changed, 46 insertions(+), 46 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index ef8835ec5778..15995f9f8b7c 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -241,7 +241,7 @@ void pnp_free_option(struct pnp_option *option) int pnp_check_port(struct pnp_dev *dev, int idx) { - int tmp; + int i; struct pnp_dev *tdev; resource_size_t *port, *end, *tport, *tend; @@ -260,18 +260,18 @@ int pnp_check_port(struct pnp_dev *dev, int idx) } /* check if the resource is reserved */ - for (tmp = 0; tmp < 8; tmp++) { - int rport = pnp_reserve_io[tmp << 1]; - int rend = pnp_reserve_io[(tmp << 1) + 1] + rport - 1; + for (i = 0; i < 8; i++) { + int rport = pnp_reserve_io[i << 1]; + int rend = pnp_reserve_io[(i << 1) + 1] + rport - 1; if (ranged_conflict(port, end, &rport, &rend)) return 0; } /* check for internal conflicts */ - for (tmp = 0; tmp < PNP_MAX_PORT && tmp != idx; tmp++) { - if (dev->res.port_resource[tmp].flags & IORESOURCE_IO) { - tport = &dev->res.port_resource[tmp].start; - tend = &dev->res.port_resource[tmp].end; + for (i = 0; i < PNP_MAX_PORT && i != idx; i++) { + if (dev->res.port_resource[i].flags & IORESOURCE_IO) { + tport = &dev->res.port_resource[i].start; + tend = &dev->res.port_resource[i].end; if (ranged_conflict(port, end, tport, tend)) return 0; } @@ -281,13 +281,13 @@ int pnp_check_port(struct pnp_dev *dev, int idx) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (tmp = 0; tmp < PNP_MAX_PORT; tmp++) { - if (tdev->res.port_resource[tmp].flags & IORESOURCE_IO) { + for (i = 0; i < PNP_MAX_PORT; i++) { + if (tdev->res.port_resource[i].flags & IORESOURCE_IO) { if (cannot_compare - (tdev->res.port_resource[tmp].flags)) + (tdev->res.port_resource[i].flags)) continue; - tport = &tdev->res.port_resource[tmp].start; - tend = &tdev->res.port_resource[tmp].end; + tport = &tdev->res.port_resource[i].start; + tend = &tdev->res.port_resource[i].end; if (ranged_conflict(port, end, tport, tend)) return 0; } @@ -299,7 +299,7 @@ int pnp_check_port(struct pnp_dev *dev, int idx) int pnp_check_mem(struct pnp_dev *dev, int idx) { - int tmp; + int i; struct pnp_dev *tdev; resource_size_t *addr, *end, *taddr, *tend; @@ -318,18 +318,18 @@ int pnp_check_mem(struct pnp_dev *dev, int idx) } /* check if the resource is reserved */ - for (tmp = 0; tmp < 8; tmp++) { - int raddr = pnp_reserve_mem[tmp << 1]; - int rend = pnp_reserve_mem[(tmp << 1) + 1] + raddr - 1; + for (i = 0; i < 8; i++) { + int raddr = pnp_reserve_mem[i << 1]; + int rend = pnp_reserve_mem[(i << 1) + 1] + raddr - 1; if (ranged_conflict(addr, end, &raddr, &rend)) return 0; } /* check for internal conflicts */ - for (tmp = 0; tmp < PNP_MAX_MEM && tmp != idx; tmp++) { - if (dev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { - taddr = &dev->res.mem_resource[tmp].start; - tend = &dev->res.mem_resource[tmp].end; + for (i = 0; i < PNP_MAX_MEM && i != idx; i++) { + if (dev->res.mem_resource[i].flags & IORESOURCE_MEM) { + taddr = &dev->res.mem_resource[i].start; + tend = &dev->res.mem_resource[i].end; if (ranged_conflict(addr, end, taddr, tend)) return 0; } @@ -339,13 +339,13 @@ int pnp_check_mem(struct pnp_dev *dev, int idx) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (tmp = 0; tmp < PNP_MAX_MEM; tmp++) { - if (tdev->res.mem_resource[tmp].flags & IORESOURCE_MEM) { + for (i = 0; i < PNP_MAX_MEM; i++) { + if (tdev->res.mem_resource[i].flags & IORESOURCE_MEM) { if (cannot_compare - (tdev->res.mem_resource[tmp].flags)) + (tdev->res.mem_resource[i].flags)) continue; - taddr = &tdev->res.mem_resource[tmp].start; - tend = &tdev->res.mem_resource[tmp].end; + taddr = &tdev->res.mem_resource[i].start; + tend = &tdev->res.mem_resource[i].end; if (ranged_conflict(addr, end, taddr, tend)) return 0; } @@ -362,7 +362,7 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id) int pnp_check_irq(struct pnp_dev *dev, int idx) { - int tmp; + int i; struct pnp_dev *tdev; resource_size_t *irq = &dev->res.irq_resource[idx].start; @@ -375,15 +375,15 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) return 0; /* check if the resource is reserved */ - for (tmp = 0; tmp < 16; tmp++) { - if (pnp_reserve_irq[tmp] == *irq) + for (i = 0; i < 16; i++) { + if (pnp_reserve_irq[i] == *irq) return 0; } /* check for internal conflicts */ - for (tmp = 0; tmp < PNP_MAX_IRQ && tmp != idx; tmp++) { - if (dev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) { - if (dev->res.irq_resource[tmp].start == *irq) + for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) { + if (dev->res.irq_resource[i].flags & IORESOURCE_IRQ) { + if (dev->res.irq_resource[i].start == *irq) return 0; } } @@ -414,12 +414,12 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (tmp = 0; tmp < PNP_MAX_IRQ; tmp++) { - if (tdev->res.irq_resource[tmp].flags & IORESOURCE_IRQ) { + for (i = 0; i < PNP_MAX_IRQ; i++) { + if (tdev->res.irq_resource[i].flags & IORESOURCE_IRQ) { if (cannot_compare - (tdev->res.irq_resource[tmp].flags)) + (tdev->res.irq_resource[i].flags)) continue; - if ((tdev->res.irq_resource[tmp].start == *irq)) + if ((tdev->res.irq_resource[i].start == *irq)) return 0; } } @@ -431,7 +431,7 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) int pnp_check_dma(struct pnp_dev *dev, int idx) { #ifndef CONFIG_IA64 - int tmp; + int i; struct pnp_dev *tdev; resource_size_t *dma = &dev->res.dma_resource[idx].start; @@ -444,15 +444,15 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) return 0; /* check if the resource is reserved */ - for (tmp = 0; tmp < 8; tmp++) { - if (pnp_reserve_dma[tmp] == *dma) + for (i = 0; i < 8; i++) { + if (pnp_reserve_dma[i] == *dma) return 0; } /* check for internal conflicts */ - for (tmp = 0; tmp < PNP_MAX_DMA && tmp != idx; tmp++) { - if (dev->res.dma_resource[tmp].flags & IORESOURCE_DMA) { - if (dev->res.dma_resource[tmp].start == *dma) + for (i = 0; i < PNP_MAX_DMA && i != idx; i++) { + if (dev->res.dma_resource[i].flags & IORESOURCE_DMA) { + if (dev->res.dma_resource[i].start == *dma) return 0; } } @@ -469,12 +469,12 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (tmp = 0; tmp < PNP_MAX_DMA; tmp++) { - if (tdev->res.dma_resource[tmp].flags & IORESOURCE_DMA) { + for (i = 0; i < PNP_MAX_DMA; i++) { + if (tdev->res.dma_resource[i].flags & IORESOURCE_DMA) { if (cannot_compare - (tdev->res.dma_resource[tmp].flags)) + (tdev->res.dma_resource[i].flags)) continue; - if ((tdev->res.dma_resource[tmp].start == *dma)) + if ((tdev->res.dma_resource[i].start == *dma)) return 0; } } -- cgit v1.2.3 From 30c016a0c8d2aae10be6a87bb98f0e85db8b09d5 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:19 -0600 Subject: PNP: reduce redundancy in pnp_check_port() and others Use a temporary "res" pointer to replace repeated lookups in the pnp resource tables. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 92 +++++++++++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 38 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 15995f9f8b7c..f89945ebd8b6 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -243,13 +243,15 @@ int pnp_check_port(struct pnp_dev *dev, int idx) { int i; struct pnp_dev *tdev; + struct resource *res, *tres; resource_size_t *port, *end, *tport, *tend; - port = &dev->res.port_resource[idx].start; - end = &dev->res.port_resource[idx].end; + res = &dev->res.port_resource[idx]; + port = &res->start; + end = &res->end; /* if the resource doesn't exist, don't complain about it */ - if (cannot_compare(dev->res.port_resource[idx].flags)) + if (cannot_compare(res->flags)) return 1; /* check if the resource is already in use, skip if the @@ -269,9 +271,10 @@ int pnp_check_port(struct pnp_dev *dev, int idx) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_PORT && i != idx; i++) { - if (dev->res.port_resource[i].flags & IORESOURCE_IO) { - tport = &dev->res.port_resource[i].start; - tend = &dev->res.port_resource[i].end; + tres = &dev->res.port_resource[i]; + if (tres->flags & IORESOURCE_IO) { + tport = &tres->start; + tend = &tres->end; if (ranged_conflict(port, end, tport, tend)) return 0; } @@ -282,12 +285,12 @@ int pnp_check_port(struct pnp_dev *dev, int idx) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_PORT; i++) { - if (tdev->res.port_resource[i].flags & IORESOURCE_IO) { - if (cannot_compare - (tdev->res.port_resource[i].flags)) + tres = &tdev->res.port_resource[i]; + if (tres->flags & IORESOURCE_IO) { + if (cannot_compare(tres->flags)) continue; - tport = &tdev->res.port_resource[i].start; - tend = &tdev->res.port_resource[i].end; + tport = &tres->start; + tend = &tres->end; if (ranged_conflict(port, end, tport, tend)) return 0; } @@ -301,13 +304,15 @@ int pnp_check_mem(struct pnp_dev *dev, int idx) { int i; struct pnp_dev *tdev; + struct resource *res, *tres; resource_size_t *addr, *end, *taddr, *tend; - addr = &dev->res.mem_resource[idx].start; - end = &dev->res.mem_resource[idx].end; + res = &dev->res.mem_resource[idx]; + addr = &res->start; + end = &res->end; /* if the resource doesn't exist, don't complain about it */ - if (cannot_compare(dev->res.mem_resource[idx].flags)) + if (cannot_compare(res->flags)) return 1; /* check if the resource is already in use, skip if the @@ -327,9 +332,10 @@ int pnp_check_mem(struct pnp_dev *dev, int idx) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_MEM && i != idx; i++) { - if (dev->res.mem_resource[i].flags & IORESOURCE_MEM) { - taddr = &dev->res.mem_resource[i].start; - tend = &dev->res.mem_resource[i].end; + tres = &dev->res.mem_resource[i]; + if (tres->flags & IORESOURCE_MEM) { + taddr = &tres->start; + tend = &tres->end; if (ranged_conflict(addr, end, taddr, tend)) return 0; } @@ -340,12 +346,12 @@ int pnp_check_mem(struct pnp_dev *dev, int idx) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_MEM; i++) { - if (tdev->res.mem_resource[i].flags & IORESOURCE_MEM) { - if (cannot_compare - (tdev->res.mem_resource[i].flags)) + tres = &tdev->res.mem_resource[i]; + if (tres->flags & IORESOURCE_MEM) { + if (cannot_compare(tres->flags)) continue; - taddr = &tdev->res.mem_resource[i].start; - tend = &tdev->res.mem_resource[i].end; + taddr = &tres->start; + tend = &tres->end; if (ranged_conflict(addr, end, taddr, tend)) return 0; } @@ -364,10 +370,14 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) { int i; struct pnp_dev *tdev; - resource_size_t *irq = &dev->res.irq_resource[idx].start; + struct resource *res, *tres; + resource_size_t *irq; + + res = &dev->res.irq_resource[idx]; + irq = &res->start; /* if the resource doesn't exist, don't complain about it */ - if (cannot_compare(dev->res.irq_resource[idx].flags)) + if (cannot_compare(res->flags)) return 1; /* check if the resource is valid */ @@ -382,8 +392,9 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) { - if (dev->res.irq_resource[i].flags & IORESOURCE_IRQ) { - if (dev->res.irq_resource[i].start == *irq) + tres = &dev->res.irq_resource[i]; + if (tres->flags & IORESOURCE_IRQ) { + if (tres->start == *irq) return 0; } } @@ -415,11 +426,11 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_IRQ; i++) { - if (tdev->res.irq_resource[i].flags & IORESOURCE_IRQ) { - if (cannot_compare - (tdev->res.irq_resource[i].flags)) + tres = &tdev->res.irq_resource[i]; + if (tres->flags & IORESOURCE_IRQ) { + if (cannot_compare(tres->flags)) continue; - if ((tdev->res.irq_resource[i].start == *irq)) + if (tres->start == *irq) return 0; } } @@ -433,10 +444,14 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) #ifndef CONFIG_IA64 int i; struct pnp_dev *tdev; - resource_size_t *dma = &dev->res.dma_resource[idx].start; + struct resource *res, *tres; + resource_size_t *dma; + + res = &dev->res.dma_resource[idx]; + dma = &res->start; /* if the resource doesn't exist, don't complain about it */ - if (cannot_compare(dev->res.dma_resource[idx].flags)) + if (cannot_compare(res->flags)) return 1; /* check if the resource is valid */ @@ -451,8 +466,9 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_DMA && i != idx; i++) { - if (dev->res.dma_resource[i].flags & IORESOURCE_DMA) { - if (dev->res.dma_resource[i].start == *dma) + tres = &dev->res.dma_resource[i]; + if (tres->flags & IORESOURCE_DMA) { + if (tres->start == *dma) return 0; } } @@ -470,11 +486,11 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_DMA; i++) { - if (tdev->res.dma_resource[i].flags & IORESOURCE_DMA) { - if (cannot_compare - (tdev->res.dma_resource[i].flags)) + tres = &tdev->res.dma_resource[i]; + if (tres->flags & IORESOURCE_DMA) { + if (cannot_compare(tres->flags)) continue; - if ((tdev->res.dma_resource[i].start == *dma)) + if (tres->start == *dma) return 0; } } -- cgit v1.2.3 From db9eaeab3e7ab72d773820820f1ba33960ad24c4 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:21 -0600 Subject: PNP: check for conflicts with all resources, not just earlier ones This patch removes a use of "idx" in pnp_check_port() and similar functions, in preparation for replacing idx with a pointer to the resource itself. I split this out because it changes the behavior slightly: we used to check for conflicts only with earlier resources, e.g., we checked resource 2 against resources 0 and 1 but not against 3, 4, etc. Now we will check against all resources except 2. Since resources are assigned in ascending order, the old behavior was probably safe, but I don't like to depend on that ordering. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index f89945ebd8b6..eab16e5520ae 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -270,9 +270,9 @@ int pnp_check_port(struct pnp_dev *dev, int idx) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_PORT && i != idx; i++) { + for (i = 0; i < PNP_MAX_PORT; i++) { tres = &dev->res.port_resource[i]; - if (tres->flags & IORESOURCE_IO) { + if (tres != res && tres->flags & IORESOURCE_IO) { tport = &tres->start; tend = &tres->end; if (ranged_conflict(port, end, tport, tend)) @@ -331,9 +331,9 @@ int pnp_check_mem(struct pnp_dev *dev, int idx) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_MEM && i != idx; i++) { + for (i = 0; i < PNP_MAX_MEM; i++) { tres = &dev->res.mem_resource[i]; - if (tres->flags & IORESOURCE_MEM) { + if (tres != res && tres->flags & IORESOURCE_MEM) { taddr = &tres->start; tend = &tres->end; if (ranged_conflict(addr, end, taddr, tend)) @@ -391,9 +391,9 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_IRQ && i != idx; i++) { + for (i = 0; i < PNP_MAX_IRQ; i++) { tres = &dev->res.irq_resource[i]; - if (tres->flags & IORESOURCE_IRQ) { + if (tres != res && tres->flags & IORESOURCE_IRQ) { if (tres->start == *irq) return 0; } @@ -465,9 +465,9 @@ int pnp_check_dma(struct pnp_dev *dev, int idx) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_DMA && i != idx; i++) { + for (i = 0; i < PNP_MAX_DMA; i++) { tres = &dev->res.dma_resource[i]; - if (tres->flags & IORESOURCE_DMA) { + if (tres != res && tres->flags & IORESOURCE_DMA) { if (tres->start == *dma) return 0; } -- cgit v1.2.3 From f5d94ff014cb7e6212f40fc6644f3fd68507df33 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:22 -0600 Subject: PNP: pass resources, not indexes, to pnp_check_port(), et al The caller already has the struct resource pointer, so no need for pnp_check_port(), pnp_check_mem(), etc., to look it up again. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index eab16e5520ae..93bf45e01f2c 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -239,14 +239,13 @@ void pnp_free_option(struct pnp_option *option) #define cannot_compare(flags) \ ((flags) & (IORESOURCE_UNSET | IORESOURCE_DISABLED)) -int pnp_check_port(struct pnp_dev *dev, int idx) +int pnp_check_port(struct pnp_dev *dev, struct resource *res) { int i; struct pnp_dev *tdev; - struct resource *res, *tres; + struct resource *tres; resource_size_t *port, *end, *tport, *tend; - res = &dev->res.port_resource[idx]; port = &res->start; end = &res->end; @@ -300,14 +299,13 @@ int pnp_check_port(struct pnp_dev *dev, int idx) return 1; } -int pnp_check_mem(struct pnp_dev *dev, int idx) +int pnp_check_mem(struct pnp_dev *dev, struct resource *res) { int i; struct pnp_dev *tdev; - struct resource *res, *tres; + struct resource *tres; resource_size_t *addr, *end, *taddr, *tend; - res = &dev->res.mem_resource[idx]; addr = &res->start; end = &res->end; @@ -366,14 +364,13 @@ static irqreturn_t pnp_test_handler(int irq, void *dev_id) return IRQ_HANDLED; } -int pnp_check_irq(struct pnp_dev *dev, int idx) +int pnp_check_irq(struct pnp_dev *dev, struct resource *res) { int i; struct pnp_dev *tdev; - struct resource *res, *tres; + struct resource *tres; resource_size_t *irq; - res = &dev->res.irq_resource[idx]; irq = &res->start; /* if the resource doesn't exist, don't complain about it */ @@ -439,15 +436,14 @@ int pnp_check_irq(struct pnp_dev *dev, int idx) return 1; } -int pnp_check_dma(struct pnp_dev *dev, int idx) +int pnp_check_dma(struct pnp_dev *dev, struct resource *res) { #ifndef CONFIG_IA64 int i; struct pnp_dev *tdev; - struct resource *res, *tres; + struct resource *tres; resource_size_t *dma; - res = &dev->res.dma_resource[idx]; dma = &res->start; /* if the resource doesn't exist, don't complain about it */ -- cgit v1.2.3 From be81b4a4838ce329b9f3978c7fc007b047c23722 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:23 -0600 Subject: PNP: convert resource checks to use pnp_get_resource(), not pnp_resource_table This removes more direct references to pnp_resource_table. Signed-off-by: Bjorn Helgaas Acked-By: Rene Herman Signed-off-by: Len Brown --- drivers/pnp/resource.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 93bf45e01f2c..b2516d62fcf6 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -270,8 +270,8 @@ int pnp_check_port(struct pnp_dev *dev, struct resource *res) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_PORT; i++) { - tres = &dev->res.port_resource[i]; - if (tres != res && tres->flags & IORESOURCE_IO) { + tres = pnp_get_resource(dev, IORESOURCE_IO, i); + if (tres && tres != res && tres->flags & IORESOURCE_IO) { tport = &tres->start; tend = &tres->end; if (ranged_conflict(port, end, tport, tend)) @@ -284,8 +284,8 @@ int pnp_check_port(struct pnp_dev *dev, struct resource *res) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_PORT; i++) { - tres = &tdev->res.port_resource[i]; - if (tres->flags & IORESOURCE_IO) { + tres = pnp_get_resource(tdev, IORESOURCE_IO, i); + if (tres && tres->flags & IORESOURCE_IO) { if (cannot_compare(tres->flags)) continue; tport = &tres->start; @@ -330,8 +330,8 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_MEM; i++) { - tres = &dev->res.mem_resource[i]; - if (tres != res && tres->flags & IORESOURCE_MEM) { + tres = pnp_get_resource(dev, IORESOURCE_MEM, i); + if (tres && tres != res && tres->flags & IORESOURCE_MEM) { taddr = &tres->start; tend = &tres->end; if (ranged_conflict(addr, end, taddr, tend)) @@ -344,8 +344,8 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_MEM; i++) { - tres = &tdev->res.mem_resource[i]; - if (tres->flags & IORESOURCE_MEM) { + tres = pnp_get_resource(tdev, IORESOURCE_MEM, i); + if (tres && tres->flags & IORESOURCE_MEM) { if (cannot_compare(tres->flags)) continue; taddr = &tres->start; @@ -389,8 +389,8 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_IRQ; i++) { - tres = &dev->res.irq_resource[i]; - if (tres != res && tres->flags & IORESOURCE_IRQ) { + tres = pnp_get_resource(dev, IORESOURCE_IRQ, i); + if (tres && tres != res && tres->flags & IORESOURCE_IRQ) { if (tres->start == *irq) return 0; } @@ -423,8 +423,8 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_IRQ; i++) { - tres = &tdev->res.irq_resource[i]; - if (tres->flags & IORESOURCE_IRQ) { + tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i); + if (tres && tres->flags & IORESOURCE_IRQ) { if (cannot_compare(tres->flags)) continue; if (tres->start == *irq) @@ -462,8 +462,8 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) /* check for internal conflicts */ for (i = 0; i < PNP_MAX_DMA; i++) { - tres = &dev->res.dma_resource[i]; - if (tres != res && tres->flags & IORESOURCE_DMA) { + tres = pnp_get_resource(dev, IORESOURCE_DMA, i); + if (tres && tres != res && tres->flags & IORESOURCE_DMA) { if (tres->start == *dma) return 0; } @@ -482,8 +482,8 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) if (tdev == dev) continue; for (i = 0; i < PNP_MAX_DMA; i++) { - tres = &tdev->res.dma_resource[i]; - if (tres->flags & IORESOURCE_DMA) { + tres = pnp_get_resource(tdev, IORESOURCE_DMA, i); + if (tres && tres->flags & IORESOURCE_DMA) { if (cannot_compare(tres->flags)) continue; if (tres->start == *dma) -- cgit v1.2.3 From 95ab3669f7830682c7762e9c305a0c1dd44454cc Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:26 -0600 Subject: PNP: remove PNP_MAX_* uses Remove some PNP_MAX_* uses. The pnp_resource_table isn't dynamic yet, but with pnp_get_resource(), we can start moving away from the table size constants. Signed-off-by: Bjorn Helgaas Signed-off-by: Len Brown --- drivers/pnp/resource.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index b2516d62fcf6..84362818fa8b 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -269,9 +269,8 @@ int pnp_check_port(struct pnp_dev *dev, struct resource *res) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_PORT; i++) { - tres = pnp_get_resource(dev, IORESOURCE_IO, i); - if (tres && tres != res && tres->flags & IORESOURCE_IO) { + for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_IO, i)); i++) { + if (tres != res && tres->flags & IORESOURCE_IO) { tport = &tres->start; tend = &tres->end; if (ranged_conflict(port, end, tport, tend)) @@ -283,9 +282,10 @@ int pnp_check_port(struct pnp_dev *dev, struct resource *res) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (i = 0; i < PNP_MAX_PORT; i++) { - tres = pnp_get_resource(tdev, IORESOURCE_IO, i); - if (tres && tres->flags & IORESOURCE_IO) { + for (i = 0; + (tres = pnp_get_resource(tdev, IORESOURCE_IO, i)); + i++) { + if (tres->flags & IORESOURCE_IO) { if (cannot_compare(tres->flags)) continue; tport = &tres->start; @@ -329,9 +329,8 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_MEM; i++) { - tres = pnp_get_resource(dev, IORESOURCE_MEM, i); - if (tres && tres != res && tres->flags & IORESOURCE_MEM) { + for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_MEM, i)); i++) { + if (tres != res && tres->flags & IORESOURCE_MEM) { taddr = &tres->start; tend = &tres->end; if (ranged_conflict(addr, end, taddr, tend)) @@ -343,9 +342,10 @@ int pnp_check_mem(struct pnp_dev *dev, struct resource *res) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (i = 0; i < PNP_MAX_MEM; i++) { - tres = pnp_get_resource(tdev, IORESOURCE_MEM, i); - if (tres && tres->flags & IORESOURCE_MEM) { + for (i = 0; + (tres = pnp_get_resource(tdev, IORESOURCE_MEM, i)); + i++) { + if (tres->flags & IORESOURCE_MEM) { if (cannot_compare(tres->flags)) continue; taddr = &tres->start; @@ -388,9 +388,8 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_IRQ; i++) { - tres = pnp_get_resource(dev, IORESOURCE_IRQ, i); - if (tres && tres != res && tres->flags & IORESOURCE_IRQ) { + for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_IRQ, i)); i++) { + if (tres != res && tres->flags & IORESOURCE_IRQ) { if (tres->start == *irq) return 0; } @@ -422,9 +421,10 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (i = 0; i < PNP_MAX_IRQ; i++) { - tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i); - if (tres && tres->flags & IORESOURCE_IRQ) { + for (i = 0; + (tres = pnp_get_resource(tdev, IORESOURCE_IRQ, i)); + i++) { + if (tres->flags & IORESOURCE_IRQ) { if (cannot_compare(tres->flags)) continue; if (tres->start == *irq) @@ -461,9 +461,8 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) } /* check for internal conflicts */ - for (i = 0; i < PNP_MAX_DMA; i++) { - tres = pnp_get_resource(dev, IORESOURCE_DMA, i); - if (tres && tres != res && tres->flags & IORESOURCE_DMA) { + for (i = 0; (tres = pnp_get_resource(dev, IORESOURCE_DMA, i)); i++) { + if (tres != res && tres->flags & IORESOURCE_DMA) { if (tres->start == *dma) return 0; } @@ -481,9 +480,10 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) pnp_for_each_dev(tdev) { if (tdev == dev) continue; - for (i = 0; i < PNP_MAX_DMA; i++) { - tres = pnp_get_resource(tdev, IORESOURCE_DMA, i); - if (tres && tres->flags & IORESOURCE_DMA) { + for (i = 0; + (tres = pnp_get_resource(tdev, IORESOURCE_DMA, i)); + i++) { + if (tres->flags & IORESOURCE_DMA) { if (cannot_compare(tres->flags)) continue; if (tres->start == *dma) -- cgit v1.2.3 From 02d83b5da3efa3c278ce87db2637f3dd6837166d Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:28 -0600 Subject: PNP: make pnp_resource_table private to PNP core There are no remaining references to the PNP_MAX_* constants or the pnp_resource_table structure outside of the PNP core. Make them private to the PNP core. Signed-off-by: Bjorn Helgaas Signed-off-by: Len Brown --- drivers/pnp/resource.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 84362818fa8b..f7adc7eefbf8 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -502,7 +502,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) struct resource *pnp_get_resource(struct pnp_dev *dev, unsigned int type, unsigned int num) { - struct pnp_resource_table *res = &dev->res; + struct pnp_resource_table *res = dev->res; switch (type) { case IORESOURCE_IO: -- cgit v1.2.3 From 784f01d5bdeae7d7005ede17305306b042ba2617 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:30 -0600 Subject: PNP: add struct pnp_resource This patch adds a "struct pnp_resource". This currently contains only a struct resource, but we will soon need additional PNP-specific information. Signed-off-by: Bjorn Helgaas Signed-off-by: Len Brown --- drivers/pnp/resource.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index f7adc7eefbf8..7e9f4300e5f6 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -508,19 +508,19 @@ struct resource *pnp_get_resource(struct pnp_dev *dev, case IORESOURCE_IO: if (num >= PNP_MAX_PORT) return NULL; - return &res->port_resource[num]; + return &res->port[num].res; case IORESOURCE_MEM: if (num >= PNP_MAX_MEM) return NULL; - return &res->mem_resource[num]; + return &res->mem[num].res; case IORESOURCE_IRQ: if (num >= PNP_MAX_IRQ) return NULL; - return &res->irq_resource[num]; + return &res->irq[num].res; case IORESOURCE_DMA: if (num >= PNP_MAX_DMA) return NULL; - return &res->dma_resource[num]; + return &res->dma[num].res; } return NULL; } -- cgit v1.2.3 From 0a977f15469457d9a19eed992caf71995c674064 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:31 -0600 Subject: PNP: add pnp_get_pnp_resource() In some places, we need to get the struct pnp_resource, not just the struct resource, because ISAPNP needs to store the register index in the pnp_resource. I don't like pnp_get_pnp_resource() and hope that it is temporary, but we need it for a little while. Signed-off-by: Bjorn Helgaas Signed-off-by: Len Brown --- drivers/pnp/resource.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 7e9f4300e5f6..c57cfe51d52a 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -499,8 +499,8 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res) #endif } -struct resource *pnp_get_resource(struct pnp_dev *dev, - unsigned int type, unsigned int num) +struct pnp_resource *pnp_get_pnp_resource(struct pnp_dev *dev, + unsigned int type, unsigned int num) { struct pnp_resource_table *res = dev->res; @@ -508,22 +508,34 @@ struct resource *pnp_get_resource(struct pnp_dev *dev, case IORESOURCE_IO: if (num >= PNP_MAX_PORT) return NULL; - return &res->port[num].res; + return &res->port[num]; case IORESOURCE_MEM: if (num >= PNP_MAX_MEM) return NULL; - return &res->mem[num].res; + return &res->mem[num]; case IORESOURCE_IRQ: if (num >= PNP_MAX_IRQ) return NULL; - return &res->irq[num].res; + return &res->irq[num]; case IORESOURCE_DMA: if (num >= PNP_MAX_DMA) return NULL; - return &res->dma[num].res; + return &res->dma[num]; } return NULL; } + +struct resource *pnp_get_resource(struct pnp_dev *dev, + unsigned int type, unsigned int num) +{ + struct pnp_resource *pnp_res; + + pnp_res = pnp_get_pnp_resource(dev, type, num); + if (pnp_res) + return &pnp_res->res; + + return NULL; +} EXPORT_SYMBOL(pnp_get_resource); /* format is: pnp_reserve_irq=irq1[,irq2] .... */ -- cgit v1.2.3 From a50b6d7b8d7e1a8b13bd1be65a865b115e1190d9 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:33 -0600 Subject: PNP: add pnp_new_resource() to find a new unset pnp_resource This encapsulates the code to locate a new pnp_resource of the desired type. Currently this uses the pnp_resource_table, but it will soon change to find a resource in a linked list. Signed-off-by: Bjorn Helgaas Signed-off-by: Len Brown --- drivers/pnp/resource.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index c57cfe51d52a..1f4134eea7b7 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -538,6 +538,44 @@ struct resource *pnp_get_resource(struct pnp_dev *dev, } EXPORT_SYMBOL(pnp_get_resource); +static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type) +{ + struct pnp_resource *pnp_res; + int i; + + switch (type) { + case IORESOURCE_IO: + 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; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { -- cgit v1.2.3 From dbddd0383c59d588f8db5e773b062756e39117ec Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:34 -0600 Subject: 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 Signed-off-by: Len Brown --- drivers/pnp/resource.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 1f4134eea7b7..082a556b9dcc 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -576,6 +576,32 @@ static struct pnp_resource *pnp_new_resource(struct pnp_dev *dev, int type) 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] .... */ static int __init pnp_setup_reserve_irq(char *str) { -- cgit v1.2.3 From dc16f5f2ede8cc2acf8ac22857a7fecf3a4296c2 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:35 -0600 Subject: PNP: make generic pnp_add_dma_resource() Add a pnp_add_dma_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 Signed-off-by: Len Brown --- drivers/pnp/resource.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 082a556b9dcc..2a8612e31ab7 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -602,6 +602,32 @@ struct pnp_resource *pnp_add_irq_resource(struct pnp_dev *dev, int irq, return pnp_res; } +struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, + int flags) +{ + struct pnp_resource *pnp_res; + struct resource *res; + static unsigned char warned; + + pnp_res = pnp_new_resource(dev, IORESOURCE_DMA); + if (!pnp_res) { + if (!warned) { + dev_err(&dev->dev, "can't add resource for DMA %d\n", + dma); + warned = 1; + } + return NULL; + } + + res = &pnp_res->res; + res->flags = IORESOURCE_DMA | flags; + res->start = dma; + res->end = dma; + + dev_dbg(&dev->dev, " add dma %d flags %#x\n", dma, flags); + return pnp_res; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { -- cgit v1.2.3 From cc8c2e308194f0997c718c7c735550ff06754d20 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:36 -0600 Subject: PNP: make generic pnp_add_io_resource() Add a pnp_add_io_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 Signed-off-by: Len Brown --- drivers/pnp/resource.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 2a8612e31ab7..64387b70026a 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -628,6 +628,35 @@ struct pnp_resource *pnp_add_dma_resource(struct pnp_dev *dev, int dma, return pnp_res; } +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_res; + struct resource *res; + static unsigned char warned; + + pnp_res = pnp_new_resource(dev, IORESOURCE_IO); + if (!pnp_res) { + if (!warned) { + dev_err(&dev->dev, "can't add resource for IO " + "%#llx-%#llx\n",(unsigned long long) start, + (unsigned long long) end); + warned = 1; + } + return NULL; + } + + res = &pnp_res->res; + res->flags = IORESOURCE_IO | flags; + res->start = start; + res->end = end; + + dev_dbg(&dev->dev, " add io %#llx-%#llx flags %#x\n", + (unsigned long long) start, (unsigned long long) end, flags); + return pnp_res; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { -- cgit v1.2.3 From d6180f36617953990bf90d4c1ff85b77e9995cd1 Mon Sep 17 00:00:00 2001 From: Bjorn Helgaas Date: Mon, 28 Apr 2008 16:34:37 -0600 Subject: PNP: make generic pnp_add_mem_resource() Add a pnp_add_mem_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 Signed-off-by: Len Brown --- drivers/pnp/resource.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'drivers/pnp/resource.c') diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c index 64387b70026a..2041620d5682 100644 --- a/drivers/pnp/resource.c +++ b/drivers/pnp/resource.c @@ -657,6 +657,35 @@ struct pnp_resource *pnp_add_io_resource(struct pnp_dev *dev, return pnp_res; } +struct pnp_resource *pnp_add_mem_resource(struct pnp_dev *dev, + resource_size_t start, + resource_size_t end, int flags) +{ + struct pnp_resource *pnp_res; + struct resource *res; + static unsigned char warned; + + pnp_res = pnp_new_resource(dev, IORESOURCE_MEM); + if (!pnp_res) { + if (!warned) { + dev_err(&dev->dev, "can't add resource for MEM " + "%#llx-%#llx\n",(unsigned long long) start, + (unsigned long long) end); + warned = 1; + } + return NULL; + } + + res = &pnp_res->res; + res->flags = IORESOURCE_MEM | flags; + res->start = start; + res->end = end; + + dev_dbg(&dev->dev, " add mem %#llx-%#llx flags %#x\n", + (unsigned long long) start, (unsigned long long) end, flags); + return pnp_res; +} + /* format is: pnp_reserve_irq=irq1[,irq2] .... */ static int __init pnp_setup_reserve_irq(char *str) { -- cgit v1.2.3