PNPACPI: use temporaries to reduce repetition

No functional change, just fewer words and fewer chances for
transcription errors.

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:00 -06:00 committed by Len Brown
parent f7e8466a04
commit 9570a20e9d

View File

@ -280,6 +280,14 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
void *data) void *data)
{ {
struct pnp_resource_table *res_table = data; struct pnp_resource_table *res_table = data;
struct acpi_resource_irq *irq;
struct acpi_resource_dma *dma;
struct acpi_resource_io *io;
struct acpi_resource_fixed_io *fixed_io;
struct acpi_resource_memory24 *memory24;
struct acpi_resource_memory32 *memory32;
struct acpi_resource_fixed_memory32 *fixed_memory32;
struct acpi_resource_extended_irq *extended_irq;
int i; int i;
switch (res->type) { switch (res->type) {
@ -288,29 +296,32 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
* Per spec, only one interrupt per descriptor is allowed in * Per spec, only one interrupt per descriptor is allowed in
* _CRS, but some firmware violates this, so parse them all. * _CRS, but some firmware violates this, so parse them all.
*/ */
for (i = 0; i < res->data.irq.interrupt_count; i++) { irq = &res->data.irq;
for (i = 0; i < irq->interrupt_count; i++) {
pnpacpi_parse_allocated_irqresource(res_table, pnpacpi_parse_allocated_irqresource(res_table,
res->data.irq.interrupts[i], irq->interrupts[i],
res->data.irq.triggering, irq->triggering,
res->data.irq.polarity, irq->polarity,
res->data.irq.sharable); irq->sharable);
} }
break; break;
case ACPI_RESOURCE_TYPE_DMA: case ACPI_RESOURCE_TYPE_DMA:
if (res->data.dma.channel_count > 0) dma = &res->data.dma;
if (dma->channel_count > 0)
pnpacpi_parse_allocated_dmaresource(res_table, pnpacpi_parse_allocated_dmaresource(res_table,
res->data.dma.channels[0], dma->channels[0],
res->data.dma.type, dma->type,
res->data.dma.bus_master, dma->bus_master,
res->data.dma.transfer); dma->transfer);
break; break;
case ACPI_RESOURCE_TYPE_IO: case ACPI_RESOURCE_TYPE_IO:
io = &res->data.io;
pnpacpi_parse_allocated_ioresource(res_table, pnpacpi_parse_allocated_ioresource(res_table,
res->data.io.minimum, io->minimum,
res->data.io.address_length, io->address_length,
res->data.io.io_decode); io->io_decode);
break; break;
case ACPI_RESOURCE_TYPE_START_DEPENDENT: case ACPI_RESOURCE_TYPE_START_DEPENDENT:
@ -318,9 +329,10 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
break; break;
case ACPI_RESOURCE_TYPE_FIXED_IO: case ACPI_RESOURCE_TYPE_FIXED_IO:
fixed_io = &res->data.fixed_io;
pnpacpi_parse_allocated_ioresource(res_table, pnpacpi_parse_allocated_ioresource(res_table,
res->data.fixed_io.address, fixed_io->address,
res->data.fixed_io.address_length, fixed_io->address_length,
ACPI_DECODE_10); ACPI_DECODE_10);
break; break;
@ -331,22 +343,25 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
break; break;
case ACPI_RESOURCE_TYPE_MEMORY24: case ACPI_RESOURCE_TYPE_MEMORY24:
memory24 = &res->data.memory24;
pnpacpi_parse_allocated_memresource(res_table, pnpacpi_parse_allocated_memresource(res_table,
res->data.memory24.minimum, memory24->minimum,
res->data.memory24.address_length, memory24->address_length,
res->data.memory24.write_protect); memory24->write_protect);
break; break;
case ACPI_RESOURCE_TYPE_MEMORY32: case ACPI_RESOURCE_TYPE_MEMORY32:
memory32 = &res->data.memory32;
pnpacpi_parse_allocated_memresource(res_table, pnpacpi_parse_allocated_memresource(res_table,
res->data.memory32.minimum, memory32->minimum,
res->data.memory32.address_length, memory32->address_length,
res->data.memory32.write_protect); memory32->write_protect);
break; break;
case ACPI_RESOURCE_TYPE_FIXED_MEMORY32: case ACPI_RESOURCE_TYPE_FIXED_MEMORY32:
fixed_memory32 = &res->data.fixed_memory32;
pnpacpi_parse_allocated_memresource(res_table, pnpacpi_parse_allocated_memresource(res_table,
res->data.fixed_memory32.address, fixed_memory32->address,
res->data.fixed_memory32.address_length, fixed_memory32->address_length,
res->data.fixed_memory32.write_protect); fixed_memory32->write_protect);
break; break;
case ACPI_RESOURCE_TYPE_ADDRESS16: case ACPI_RESOURCE_TYPE_ADDRESS16:
case ACPI_RESOURCE_TYPE_ADDRESS32: case ACPI_RESOURCE_TYPE_ADDRESS32:
@ -360,15 +375,16 @@ static acpi_status pnpacpi_allocated_resource(struct acpi_resource *res,
break; break;
case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: case ACPI_RESOURCE_TYPE_EXTENDED_IRQ:
if (res->data.extended_irq.producer_consumer == ACPI_PRODUCER) extended_irq = &res->data.extended_irq;
if (extended_irq->producer_consumer == ACPI_PRODUCER)
return AE_OK; return AE_OK;
for (i = 0; i < res->data.extended_irq.interrupt_count; i++) { for (i = 0; i < extended_irq->interrupt_count; i++) {
pnpacpi_parse_allocated_irqresource(res_table, pnpacpi_parse_allocated_irqresource(res_table,
res->data.extended_irq.interrupts[i], extended_irq->interrupts[i],
res->data.extended_irq.triggering, extended_irq->triggering,
res->data.extended_irq.polarity, extended_irq->polarity,
res->data.extended_irq.sharable); extended_irq->sharable);
} }
break; break;
@ -797,122 +813,136 @@ int pnpacpi_build_resource_template(acpi_handle handle,
static void pnpacpi_encode_irq(struct acpi_resource *resource, static void pnpacpi_encode_irq(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
struct acpi_resource_irq *irq = &resource->data.irq;
int triggering, polarity; int triggering, polarity;
decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity); decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
resource->data.irq.triggering = triggering; irq->triggering = triggering;
resource->data.irq.polarity = polarity; irq->polarity = polarity;
if (triggering == ACPI_EDGE_SENSITIVE) if (triggering == ACPI_EDGE_SENSITIVE)
resource->data.irq.sharable = ACPI_EXCLUSIVE; irq->sharable = ACPI_EXCLUSIVE;
else else
resource->data.irq.sharable = ACPI_SHARED; irq->sharable = ACPI_SHARED;
resource->data.irq.interrupt_count = 1; irq->interrupt_count = 1;
resource->data.irq.interrupts[0] = p->start; irq->interrupts[0] = p->start;
} }
static void pnpacpi_encode_ext_irq(struct acpi_resource *resource, static void pnpacpi_encode_ext_irq(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
struct acpi_resource_extended_irq *extended_irq = &resource->data.extended_irq;
int triggering, polarity; int triggering, polarity;
decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity); decode_irq_flags(p->flags & IORESOURCE_BITS, &triggering, &polarity);
resource->data.extended_irq.producer_consumer = ACPI_CONSUMER; extended_irq->producer_consumer = ACPI_CONSUMER;
resource->data.extended_irq.triggering = triggering; extended_irq->triggering = triggering;
resource->data.extended_irq.polarity = polarity; extended_irq->polarity = polarity;
if (triggering == ACPI_EDGE_SENSITIVE) if (triggering == ACPI_EDGE_SENSITIVE)
resource->data.extended_irq.sharable = ACPI_EXCLUSIVE; extended_irq->sharable = ACPI_EXCLUSIVE;
else else
resource->data.extended_irq.sharable = ACPI_SHARED; extended_irq->sharable = ACPI_SHARED;
resource->data.extended_irq.interrupt_count = 1; extended_irq->interrupt_count = 1;
resource->data.extended_irq.interrupts[0] = p->start; extended_irq->interrupts[0] = p->start;
} }
static void pnpacpi_encode_dma(struct acpi_resource *resource, static void pnpacpi_encode_dma(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
struct acpi_resource_dma *dma = &resource->data.dma;
/* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */ /* Note: pnp_assign_dma will copy pnp_dma->flags into p->flags */
switch (p->flags & IORESOURCE_DMA_SPEED_MASK) { switch (p->flags & IORESOURCE_DMA_SPEED_MASK) {
case IORESOURCE_DMA_TYPEA: case IORESOURCE_DMA_TYPEA:
resource->data.dma.type = ACPI_TYPE_A; dma->type = ACPI_TYPE_A;
break; break;
case IORESOURCE_DMA_TYPEB: case IORESOURCE_DMA_TYPEB:
resource->data.dma.type = ACPI_TYPE_B; dma->type = ACPI_TYPE_B;
break; break;
case IORESOURCE_DMA_TYPEF: case IORESOURCE_DMA_TYPEF:
resource->data.dma.type = ACPI_TYPE_F; dma->type = ACPI_TYPE_F;
break; break;
default: default:
resource->data.dma.type = ACPI_COMPATIBILITY; dma->type = ACPI_COMPATIBILITY;
} }
switch (p->flags & IORESOURCE_DMA_TYPE_MASK) { switch (p->flags & IORESOURCE_DMA_TYPE_MASK) {
case IORESOURCE_DMA_8BIT: case IORESOURCE_DMA_8BIT:
resource->data.dma.transfer = ACPI_TRANSFER_8; dma->transfer = ACPI_TRANSFER_8;
break; break;
case IORESOURCE_DMA_8AND16BIT: case IORESOURCE_DMA_8AND16BIT:
resource->data.dma.transfer = ACPI_TRANSFER_8_16; dma->transfer = ACPI_TRANSFER_8_16;
break; break;
default: default:
resource->data.dma.transfer = ACPI_TRANSFER_16; dma->transfer = ACPI_TRANSFER_16;
} }
resource->data.dma.bus_master = !!(p->flags & IORESOURCE_DMA_MASTER); dma->bus_master = !!(p->flags & IORESOURCE_DMA_MASTER);
resource->data.dma.channel_count = 1; dma->channel_count = 1;
resource->data.dma.channels[0] = p->start; dma->channels[0] = p->start;
} }
static void pnpacpi_encode_io(struct acpi_resource *resource, static void pnpacpi_encode_io(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
struct acpi_resource_io *io = &resource->data.io;
/* Note: pnp_assign_port will copy pnp_port->flags into p->flags */ /* Note: pnp_assign_port will copy pnp_port->flags into p->flags */
resource->data.io.io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ? io->io_decode = (p->flags & PNP_PORT_FLAG_16BITADDR) ?
ACPI_DECODE_16 : ACPI_DECODE_10; ACPI_DECODE_16 : ACPI_DECODE_10;
resource->data.io.minimum = p->start; io->minimum = p->start;
resource->data.io.maximum = p->end; io->maximum = p->end;
resource->data.io.alignment = 0; /* Correct? */ io->alignment = 0; /* Correct? */
resource->data.io.address_length = p->end - p->start + 1; io->address_length = p->end - p->start + 1;
} }
static void pnpacpi_encode_fixed_io(struct acpi_resource *resource, static void pnpacpi_encode_fixed_io(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
resource->data.fixed_io.address = p->start; struct acpi_resource_fixed_io *fixed_io = &resource->data.fixed_io;
resource->data.fixed_io.address_length = p->end - p->start + 1;
fixed_io->address = p->start;
fixed_io->address_length = p->end - p->start + 1;
} }
static void pnpacpi_encode_mem24(struct acpi_resource *resource, static void pnpacpi_encode_mem24(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
struct acpi_resource_memory24 *memory24 = &resource->data.memory24;
/* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */ /* Note: pnp_assign_mem will copy pnp_mem->flags into p->flags */
resource->data.memory24.write_protect = memory24->write_protect =
(p->flags & IORESOURCE_MEM_WRITEABLE) ? (p->flags & IORESOURCE_MEM_WRITEABLE) ?
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
resource->data.memory24.minimum = p->start; memory24->minimum = p->start;
resource->data.memory24.maximum = p->end; memory24->maximum = p->end;
resource->data.memory24.alignment = 0; memory24->alignment = 0;
resource->data.memory24.address_length = p->end - p->start + 1; memory24->address_length = p->end - p->start + 1;
} }
static void pnpacpi_encode_mem32(struct acpi_resource *resource, static void pnpacpi_encode_mem32(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
resource->data.memory32.write_protect = struct acpi_resource_memory32 *memory32 = &resource->data.memory32;
memory32->write_protect =
(p->flags & IORESOURCE_MEM_WRITEABLE) ? (p->flags & IORESOURCE_MEM_WRITEABLE) ?
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
resource->data.memory32.minimum = p->start; memory32->minimum = p->start;
resource->data.memory32.maximum = p->end; memory32->maximum = p->end;
resource->data.memory32.alignment = 0; memory32->alignment = 0;
resource->data.memory32.address_length = p->end - p->start + 1; memory32->address_length = p->end - p->start + 1;
} }
static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource, static void pnpacpi_encode_fixed_mem32(struct acpi_resource *resource,
struct resource *p) struct resource *p)
{ {
resource->data.fixed_memory32.write_protect = struct acpi_resource_fixed_memory32 *fixed_memory32 = &resource->data.fixed_memory32;
fixed_memory32->write_protect =
(p->flags & IORESOURCE_MEM_WRITEABLE) ? (p->flags & IORESOURCE_MEM_WRITEABLE) ?
ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY; ACPI_READ_WRITE_MEMORY : ACPI_READ_ONLY_MEMORY;
resource->data.fixed_memory32.address = p->start; fixed_memory32->address = p->start;
resource->data.fixed_memory32.address_length = p->end - p->start + 1; fixed_memory32->address_length = p->end - p->start + 1;
} }
int pnpacpi_encode_resources(struct pnp_resource_table *res_table, int pnpacpi_encode_resources(struct pnp_resource_table *res_table,