diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2021-06-11 19:31:22 +0300 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2022-06-26 15:19:14 +0000 |
commit | ce34596f74aa1b2b9865061c6d2cdfa223f33222 (patch) | |
tree | 65f4dfbb97e1d53f9ede2d23c56ae7b6e6d7db4c /src | |
parent | 508c290bb58f845384d1de6d9fb0619d3d46098f (diff) |
device: Add fixed_mem_range_flags() and helpers
Unlike fixed_mem_resource_kb() the arguments are not in KiB.
This allows coccinelle script to assign the base and size
without applying the KiB division or 10 bit right-shift.
Unlike with fixed_mem_resource_kb() the IORESOURCE_STORED flag is
passed in the flags parameter until some inconsistencies in the tree
get resolved.
Change-Id: I2cc9ef94b60d62aaf4374f400b7e05b86e4664d2
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/55436
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Nico Huber <nico.h@gmx.de>
Diffstat (limited to 'src')
-rw-r--r-- | src/device/device_util.c | 23 | ||||
-rw-r--r-- | src/include/device/device.h | 37 |
2 files changed, 46 insertions, 14 deletions
diff --git a/src/device/device_util.c b/src/device/device_util.c index c377b859c6..9e2c3d5d9b 100644 --- a/src/device/device_util.c +++ b/src/device/device_util.c @@ -822,22 +822,23 @@ void show_all_devs_resources(int debug_level, const char *msg) } } -void fixed_mem_resource_kb(struct device *dev, unsigned long index, - unsigned long basek, unsigned long sizek, - unsigned long type) +const struct resource *fixed_resource_range_idx(struct device *dev, unsigned long index, + uint64_t base, uint64_t size, unsigned long flags) { struct resource *resource; - - if (!sizek) - return; + if (!size) + return NULL; resource = new_resource(dev, index); - resource->base = ((resource_t)basek) << 10; - resource->size = ((resource_t)sizek) << 10; - resource->flags = IORESOURCE_MEM | IORESOURCE_FIXED | - IORESOURCE_STORED | IORESOURCE_ASSIGNED; + resource->base = base; + resource->size = size; + resource->flags = IORESOURCE_FIXED | IORESOURCE_ASSIGNED; + resource->flags |= flags; - resource->flags |= type; + printk(BIOS_SPEW, "dev: %s, index: 0x%lx, base: 0x%llx, size: 0x%llx\n", + dev_path(dev), resource->index, resource->base, resource->size); + + return resource; } void fixed_io_resource(struct device *dev, unsigned long index, diff --git a/src/include/device/device.h b/src/include/device/device.h index 7bcff80e00..c01830693b 100644 --- a/src/include/device/device.h +++ b/src/include/device/device.h @@ -310,11 +310,42 @@ void pci_domain_scan_bus(struct device *dev); void fixed_io_resource(struct device *dev, unsigned long index, unsigned long base, unsigned long size); -void fixed_mem_resource_kb(struct device *dev, unsigned long index, - unsigned long basek, unsigned long sizek, unsigned long type); - void mmconf_resource(struct device *dev, unsigned long index); +/* These are temporary resource constructors to get us through the + migration away from open-coding all the IORESOURCE_FLAGS. */ + +const struct resource *fixed_resource_range_idx(struct device *dev, unsigned long index, + uint64_t base, uint64_t size, + unsigned long flags); + +static inline +const struct resource *fixed_mem_range_flags(struct device *dev, unsigned long index, + uint64_t base, uint64_t size, + unsigned long flags) +{ + return fixed_resource_range_idx(dev, index, base, size, IORESOURCE_MEM | flags); +} + +static inline +const struct resource *fixed_mem_from_to_flags(struct device *dev, unsigned long index, + uint64_t base, uint64_t end, unsigned long flags) +{ + if (end <= base) + return NULL; + return fixed_mem_range_flags(dev, index, base, end - base, flags); +} + +/* Compatibility code */ + +static inline void fixed_mem_resource_kb(struct device *dev, unsigned long index, + unsigned long basek, unsigned long sizek, + unsigned long flags) +{ + fixed_mem_range_flags(dev, index, ((uint64_t)basek) << 10, + ((uint64_t)sizek) << 10, IORESOURCE_STORED | flags); +} + /* It is the caller's responsibility to adjust regions such that ram_resource_kb() * and mmio_resource_kb() do not overlap. */ |