Samuel Holland has uploaded this change for review. ( https://review.coreboot.org/20095
Change subject: device/pnp: simplify pnp_get_ioresource ......................................................................
device/pnp: simplify pnp_get_ioresource
This also fixes the limit for single I/O ports: - PNP: 002e.5 resource base 60 size 1 align 0 gran 0 limit ffffffff flags c0000100 index 60 + PNP: 002e.5 resource base 60 size 1 align 0 gran 0 limit fff flags c0000100 index 60 - PNP: 002e.5 resource base 64 size 1 align 0 gran 0 limit ffffffff flags c0000100 index 62 + PNP: 002e.5 resource base 64 size 1 align 0 gran 0 limit fff flags c0000100 index 62
Change-Id: Ia99b785dcd9cf56fb236ad7ade54656851f88a5e Signed-off-by: Samuel Holland samuel@sholland.org --- M src/device/pnp_device.c 1 file changed, 14 insertions(+), 28 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/95/20095/1
diff --git a/src/device/pnp_device.c b/src/device/pnp_device.c index e7839de..5f69a76 100644 --- a/src/device/pnp_device.c +++ b/src/device/pnp_device.c @@ -194,7 +194,7 @@ static void pnp_get_ioresource(device_t dev, u8 index, u16 mask) { struct resource *resource; - unsigned moving, gran, step; + u16 gran, limit;
if (!mask) { printk(BIOS_ERR, "ERROR: device %s index %d has no mask.\n", @@ -205,40 +205,26 @@ resource = new_resource(dev, index);
/* Initilize the resource. */ - resource->limit = 0xffff; resource->flags |= IORESOURCE_IO;
- /* Get the resource size... */ + /* Get the resource limit (all writiable bits set to one). */ + limit = mask; + limit |= limit >> 1; + limit |= limit >> 2; + limit |= limit >> 4; + limit |= limit >> 8;
- moving = mask; - gran = 15; - step = 1 << gran; - - /* Find the first bit that moves. */ - while ((moving & step) == 0) { - gran--; - step >>= 1; - } - - /* Now find the first bit that does not move. */ - while ((moving & step) != 0) { - gran--; - step >>= 1; - } - - /* - * Of the moving bits the last bit in the first group, - * tells us the size of this resource. - */ - if ((moving & step) == 0) { - gran++; - step <<= 1; + /* Get the resource granularity (unwritable bits at the low end). */ + gran = 0; + while ((mask & 1) == 0) { + gran += 1; + mask >>= 1; }
/* Set the resource size and alignment. */ - resource->gran = gran; resource->align = gran; - resource->limit = mask | (step - 1); + resource->gran = gran; + resource->limit = limit; resource->size = 1 << gran; }