summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKyösti Mälkki <kyosti.malkki@gmail.com>2021-06-13 10:09:51 +0300
committerKyösti Mälkki <kyosti.malkki@gmail.com>2022-06-26 21:40:17 +0000
commitd0525d424876ce5c4345ab2c73983915be2efb32 (patch)
tree26e3fc85d05d66c17b2640391e566bea13fd11f9
parentad5fab23620a25d53d358dbde5f005bbe955e77b (diff)
downloadcoreboot-d0525d424876ce5c4345ab2c73983915be2efb32.tar.gz
coreboot-d0525d424876ce5c4345ab2c73983915be2efb32.tar.bz2
coreboot-d0525d424876ce5c4345ab2c73983915be2efb32.zip
resource: Add helpers for memory resources
These should help to make the reviews as platforms remove KiB scaling. Change-Id: I40644f873c0ea993353753c0ef40df4c83233355 Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/55474 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Nico Huber <nico.h@gmx.de>
-rw-r--r--src/device/device_util.c15
-rw-r--r--src/include/device/device.h56
2 files changed, 71 insertions, 0 deletions
diff --git a/src/device/device_util.c b/src/device/device_util.c
index 383e17b0f6b0..7e31b43495c2 100644
--- a/src/device/device_util.c
+++ b/src/device/device_util.c
@@ -841,6 +841,21 @@ const struct resource *fixed_resource_range_idx(struct device *dev, unsigned lon
return resource;
}
+const struct resource *lower_ram_end(struct device *dev, unsigned long index, uint64_t end)
+{
+ return ram_from_to(dev, index, 0, end);
+}
+
+const struct resource *upper_ram_end(struct device *dev, unsigned long index, uint64_t end)
+{
+ if (end <= 4ull * GiB)
+ return NULL;
+
+ printk(BIOS_INFO, "Available memory above 4GB: %lluM\n", (end - 4ull * GiB) / MiB);
+
+ return ram_from_to(dev, index, 4ull * GiB, end);
+}
+
void mmconf_resource(struct device *dev, unsigned long index)
{
struct resource *resource = new_resource(dev, index);
diff --git a/src/include/device/device.h b/src/include/device/device.h
index 8f5407dcfc63..536b77730ef7 100644
--- a/src/include/device/device.h
+++ b/src/include/device/device.h
@@ -334,6 +334,62 @@ const struct resource *fixed_mem_from_to_flags(struct device *dev, unsigned long
}
static inline
+const struct resource *ram_range(struct device *dev, unsigned long index, uint64_t base,
+ uint64_t size)
+{
+ return fixed_mem_range_flags(dev, index, base, size, IORESOURCE_CACHEABLE | IORESOURCE_STORED);
+}
+
+static inline
+const struct resource *ram_from_to(struct device *dev, unsigned long index, uint64_t base,
+ uint64_t end)
+{
+ if (end <= base)
+ return NULL;
+ return ram_range(dev, index, base, end - base);
+}
+
+static inline
+const struct resource *reserved_ram_range(struct device *dev, unsigned long index,
+ uint64_t base, uint64_t size)
+{
+ return fixed_mem_range_flags(dev, index, base, size, IORESOURCE_CACHEABLE |
+ IORESOURCE_RESERVE | IORESOURCE_STORED);
+}
+
+static inline
+const struct resource *reserved_ram_from_to(struct device *dev, unsigned long index,
+ uint64_t base, uint64_t end)
+{
+ if (end <= base)
+ return NULL;
+ return reserved_ram_range(dev, index, base, end - base);
+}
+
+static inline
+const struct resource *mmio_range(struct device *dev, unsigned long index, uint64_t base,
+ uint64_t size)
+{
+ return fixed_mem_range_flags(dev, index, base, size, IORESOURCE_RESERVE | IORESOURCE_STORED);
+}
+
+static inline
+const struct resource *mmio_from_to(struct device *dev, unsigned long index, uint64_t base,
+ uint64_t end)
+{
+ if (end <= base)
+ return NULL;
+ return mmio_range(dev, index, base, end - base);
+}
+
+const struct resource *lower_ram_end(struct device *dev, unsigned long index, uint64_t end);
+const struct resource *upper_ram_end(struct device *dev, unsigned long index, uint64_t end);
+
+#define bad_ram_range(...) reserved_ram_range(__VA_ARGS__)
+#define uma_range(...) mmio_range(__VA_ARGS__)
+#define uma_from_to(...) mmio_from_to(__VA_ARGS__)
+
+static inline
const struct resource *fixed_io_range_flags(struct device *dev, unsigned long index,
uint16_t base, uint16_t size, unsigned long flags)
{