PNP: reduce redundancy in pnp_assign_port() and others

Use a temporary "res" pointer to replace repeated lookups in
the pnp resource tables.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>
Acked-By: Rene Herman <rene.herman@gmail.com>
Signed-off-by: Len Brown <len.brown@intel.com>
This commit is contained in:
Bjorn Helgaas 2008-04-28 16:34:18 -06:00 committed by Len Brown
parent ecfa935a2f
commit 28ccffcf02

View File

@ -19,8 +19,7 @@ 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)
{ {
resource_size_t *start, *end; struct resource *res;
unsigned long *flags;
if (idx >= PNP_MAX_PORT) { if (idx >= PNP_MAX_PORT) {
dev_err(&dev->dev, "too many I/O port resources\n"); dev_err(&dev->dev, "too many I/O port resources\n");
@ -28,49 +27,46 @@ static int pnp_assign_port(struct pnp_dev *dev, struct pnp_port *rule, int idx)
return 1; return 1;
} }
start = &dev->res.port_resource[idx].start; res = &dev->res.port_resource[idx];
end = &dev->res.port_resource[idx].end;
flags = &dev->res.port_resource[idx].flags;
/* check if this resource has been manually set, if so skip */ /* check if this resource has been manually set, if so skip */
if (!(dev->res.port_resource[idx].flags & IORESOURCE_AUTO)) { 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) *start, "flags %#lx\n", idx, (unsigned long long) res->start,
(unsigned long long) *end, *flags); (unsigned long long) res->end, res->flags);
return 1; return 1;
} }
/* set the initial values */ /* set the initial values */
*flags |= rule->flags | IORESOURCE_IO; res->flags |= rule->flags | IORESOURCE_IO;
*flags &= ~IORESOURCE_UNSET; res->flags &= ~IORESOURCE_UNSET;
if (!rule->size) { if (!rule->size) {
*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 */ return 1; /* skip disabled resource requests */
} }
*start = rule->min; res->start = rule->min;
*end = *start + rule->size - 1; res->end = res->start + rule->size - 1;
/* run through until pnp_check_port is happy */ /* run through until pnp_check_port is happy */
while (!pnp_check_port(dev, idx)) { while (!pnp_check_port(dev, idx)) {
*start += rule->align; res->start += rule->align;
*end = *start + rule->size - 1; res->end = res->start + rule->size - 1;
if (*start > rule->max || !rule->align) { if (res->start > rule->max || !rule->align) {
dev_dbg(&dev->dev, " couldn't assign io %d\n", idx); dev_dbg(&dev->dev, " couldn't assign io %d\n", idx);
return 0; return 0;
} }
} }
dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx, dev_dbg(&dev->dev, " assign io %d %#llx-%#llx\n", idx,
(unsigned long long) *start, (unsigned long long) *end); (unsigned long long) res->start, (unsigned long long) res->end);
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)
{ {
resource_size_t *start, *end; struct resource *res;
unsigned long *flags;
if (idx >= PNP_MAX_MEM) { if (idx >= PNP_MAX_MEM) {
dev_err(&dev->dev, "too many memory resources\n"); dev_err(&dev->dev, "too many memory resources\n");
@ -78,59 +74,56 @@ static int pnp_assign_mem(struct pnp_dev *dev, struct pnp_mem *rule, int idx)
return 1; return 1;
} }
start = &dev->res.mem_resource[idx].start; res = &dev->res.mem_resource[idx];
end = &dev->res.mem_resource[idx].end;
flags = &dev->res.mem_resource[idx].flags;
/* check if this resource has been manually set, if so skip */ /* check if this resource has been manually set, if so skip */
if (!(dev->res.mem_resource[idx].flags & IORESOURCE_AUTO)) { 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) *start, "flags %#lx\n", idx, (unsigned long long) res->start,
(unsigned long long) *end, *flags); (unsigned long long) res->end, res->flags);
return 1; return 1;
} }
/* set the initial values */ /* set the initial values */
*flags |= rule->flags | IORESOURCE_MEM; res->flags |= rule->flags | IORESOURCE_MEM;
*flags &= ~IORESOURCE_UNSET; res->flags &= ~IORESOURCE_UNSET;
/* convert pnp flags to standard Linux flags */ /* convert pnp flags to standard Linux flags */
if (!(rule->flags & IORESOURCE_MEM_WRITEABLE)) if (!(rule->flags & IORESOURCE_MEM_WRITEABLE))
*flags |= IORESOURCE_READONLY; res->flags |= IORESOURCE_READONLY;
if (rule->flags & IORESOURCE_MEM_CACHEABLE) if (rule->flags & IORESOURCE_MEM_CACHEABLE)
*flags |= IORESOURCE_CACHEABLE; res->flags |= IORESOURCE_CACHEABLE;
if (rule->flags & IORESOURCE_MEM_RANGELENGTH) if (rule->flags & IORESOURCE_MEM_RANGELENGTH)
*flags |= IORESOURCE_RANGELENGTH; res->flags |= IORESOURCE_RANGELENGTH;
if (rule->flags & IORESOURCE_MEM_SHADOWABLE) if (rule->flags & IORESOURCE_MEM_SHADOWABLE)
*flags |= IORESOURCE_SHADOWABLE; res->flags |= IORESOURCE_SHADOWABLE;
if (!rule->size) { if (!rule->size) {
*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 */ return 1; /* skip disabled resource requests */
} }
*start = rule->min; res->start = rule->min;
*end = *start + rule->size - 1; res->end = res->start + rule->size - 1;
/* run through until pnp_check_mem is happy */ /* run through until pnp_check_mem is happy */
while (!pnp_check_mem(dev, idx)) { while (!pnp_check_mem(dev, idx)) {
*start += rule->align; res->start += rule->align;
*end = *start + rule->size - 1; res->end = res->start + rule->size - 1;
if (*start > rule->max || !rule->align) { if (res->start > rule->max || !rule->align) {
dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx); dev_dbg(&dev->dev, " couldn't assign mem %d\n", idx);
return 0; return 0;
} }
} }
dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx, dev_dbg(&dev->dev, " assign mem %d %#llx-%#llx\n", idx,
(unsigned long long) *start, (unsigned long long) *end); (unsigned long long) res->start, (unsigned long long) res->end);
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)
{ {
resource_size_t *start, *end; struct resource *res;
unsigned long *flags;
int i; int i;
/* IRQ priority: this table is good for i386 */ /* IRQ priority: this table is good for i386 */
@ -144,40 +137,39 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
return 1; return 1;
} }
start = &dev->res.irq_resource[idx].start; res = &dev->res.irq_resource[idx];
end = &dev->res.irq_resource[idx].end;
flags = &dev->res.irq_resource[idx].flags;
/* check if this resource has been manually set, if so skip */ /* check if this resource has been manually set, if so skip */
if (!(dev->res.irq_resource[idx].flags & IORESOURCE_AUTO)) { 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) *start, *flags); idx, (int) res->start, res->flags);
return 1; return 1;
} }
/* set the initial values */ /* set the initial values */
*flags |= rule->flags | IORESOURCE_IRQ; res->flags |= rule->flags | IORESOURCE_IRQ;
*flags &= ~IORESOURCE_UNSET; res->flags &= ~IORESOURCE_UNSET;
if (bitmap_empty(rule->map, PNP_IRQ_NR)) { if (bitmap_empty(rule->map, PNP_IRQ_NR)) {
*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 */ return 1; /* skip disabled resource requests */
} }
/* TBD: need check for >16 IRQ */ /* TBD: need check for >16 IRQ */
*start = find_next_bit(rule->map, PNP_IRQ_NR, 16); res->start = find_next_bit(rule->map, PNP_IRQ_NR, 16);
if (*start < PNP_IRQ_NR) { if (res->start < PNP_IRQ_NR) {
*end = *start; res->end = res->start;
dev_dbg(&dev->dev, " assign irq %d %d\n", idx, (int) *start); dev_dbg(&dev->dev, " assign irq %d %d\n", idx,
(int) res->start);
return 1; 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)) {
*start = *end = xtab[i]; res->start = res->end = xtab[i];
if (pnp_check_irq(dev, idx)) { if (pnp_check_irq(dev, idx)) {
dev_dbg(&dev->dev, " assign irq %d %d\n", idx, dev_dbg(&dev->dev, " assign irq %d %d\n", idx,
(int) *start); (int) res->start);
return 1; return 1;
} }
} }
@ -188,8 +180,7 @@ static int pnp_assign_irq(struct pnp_dev *dev, struct pnp_irq *rule, int idx)
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)
{ {
resource_size_t *start, *end; struct resource *res;
unsigned long *flags;
int i; int i;
/* DMA priority: this table is good for i386 */ /* DMA priority: this table is good for i386 */
@ -202,35 +193,33 @@ static void pnp_assign_dma(struct pnp_dev *dev, struct pnp_dma *rule, int idx)
return; return;
} }
start = &dev->res.dma_resource[idx].start; res = &dev->res.dma_resource[idx];
end = &dev->res.dma_resource[idx].end;
flags = &dev->res.dma_resource[idx].flags;
/* check if this resource has been manually set, if so skip */ /* check if this resource has been manually set, if so skip */
if (!(dev->res.dma_resource[idx].flags & IORESOURCE_AUTO)) { 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) *start, *flags); idx, (int) res->start, res->flags);
return; return;
} }
/* set the initial values */ /* set the initial values */
*flags |= rule->flags | IORESOURCE_DMA; res->flags |= rule->flags | IORESOURCE_DMA;
*flags &= ~IORESOURCE_UNSET; res->flags &= ~IORESOURCE_UNSET;
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
if (rule->map & (1 << xtab[i])) { if (rule->map & (1 << xtab[i])) {
*start = *end = xtab[i]; res->start = res->end = xtab[i];
if (pnp_check_dma(dev, idx)) { if (pnp_check_dma(dev, idx)) {
dev_dbg(&dev->dev, " assign dma %d %d\n", idx, dev_dbg(&dev->dev, " assign dma %d %d\n", idx,
(int) *start); (int) res->start);
return; return;
} }
} }
} }
#ifdef MAX_DMA_CHANNELS #ifdef MAX_DMA_CHANNELS
*start = *end = MAX_DMA_CHANNELS; res->start = res->end = MAX_DMA_CHANNELS;
#endif #endif
*flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED; res->flags |= IORESOURCE_UNSET | IORESOURCE_DISABLED;
dev_dbg(&dev->dev, " disable dma %d\n", idx); dev_dbg(&dev->dev, " disable dma %d\n", idx);
} }