[coreboot-gerrit] New patch to review for coreboot: 3619302 resource: Provide interface for indexed resource access
Patrick Georgi (patrick@georgi-clan.de)
gerrit at coreboot.org
Mon Aug 4 19:50:26 CEST 2014
Patrick Georgi (patrick at georgi-clan.de) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/6493
-gerrit
commit 3619302dcc37238826af3087f4384d0048ce45a7
Author: Patrick Georgi <patrick at georgi-clan.de>
Date: Mon Aug 4 17:18:06 2014 +0200
resource: Provide interface for indexed resource access
Provide means to read, write and read/modify/write registers
behind resources.
This is compatible with what reg_scripts is now doing, but
should be replaced with something more efficient.
Change-Id: Ic40f2d9e2e20f22a2a3f9838d5eacca63b0da6b0
Signed-off-by: Patrick Georgi <patrick at georgi-clan.de>
---
src/include/device/resource.h | 115 ++++++++++++++++++++++++++++++++++++++++++
1 file changed, 115 insertions(+)
diff --git a/src/include/device/resource.h b/src/include/device/resource.h
index 2d64c80..88eca81 100644
--- a/src/include/device/resource.h
+++ b/src/include/device/resource.h
@@ -3,6 +3,7 @@
#include <stdint.h>
#include <stddef.h>
+#include <arch/io.h>
#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */
@@ -74,4 +75,118 @@ extern void search_global_resources(
#define RESOURCE_TYPE_MAX 20
extern const char *resource_type(struct resource *resource);
+/* temporary API for simplified resource access
+ FIXME: we should work from struct resource *, instead of
+ resolving these all the time.
+ for now, that's what the ex-reg_script stuff is using,
+ so we'll have to live with it for a while
+*/
+static inline u8 read_res8(struct device *dev, unsigned index, u32 offset)
+{
+ struct resource *res = find_resource(dev, index);
+ if (res == NULL) return 0;
+ if (res->flags & IORESOURCE_IO) {
+ return inb(res->base + offset);
+ } else if (res->flags & IORESOURCE_MEM) {
+ return read8(res->base + offset);
+ }
+ return 0;
+}
+
+static inline u16 read_res16(struct device *dev, unsigned index, u32 offset)
+{
+ struct resource *res = find_resource(dev, index);
+ if (res == NULL) return 0;
+ if (res->flags & IORESOURCE_IO) {
+ return inw(res->base + offset);
+ } else if (res->flags & IORESOURCE_MEM) {
+ return read16(res->base + offset);
+ }
+ return 0;
+}
+
+static inline u32 read_res32(struct device *dev, unsigned index, u32 offset)
+{
+ struct resource *res = find_resource(dev, index);
+ if (res == NULL) return 0;
+ if (res->flags & IORESOURCE_IO) {
+ return inl(res->base + offset);
+ } else if (res->flags & IORESOURCE_MEM) {
+ return read32(res->base + offset);
+ }
+ return 0;
+}
+
+static inline void write_res8(struct device *dev, unsigned index, u32 offset, u8 val)
+{
+ struct resource *res = find_resource(dev, index);
+ if (res == NULL) return;
+ if (res->flags & IORESOURCE_IO) {
+ outb(val, res->base + offset);
+ } else if (res->flags & IORESOURCE_MEM) {
+ write8(res->base + offset, val);
+ }
+}
+
+static inline void write_res16(struct device *dev, unsigned index, u32 offset, u16 val)
+{
+ struct resource *res = find_resource(dev, index);
+ if (res == NULL) return;
+ if (res->flags & IORESOURCE_IO) {
+ outw(val, res->base + offset);
+ } else if (res->flags & IORESOURCE_MEM) {
+ write16(res->base + offset, val);
+ }
+}
+
+static inline void write_res32(struct device *dev, unsigned index, u32 offset, u32 val)
+{
+ struct resource *res = find_resource(dev, index);
+ if (res == NULL) return;
+ if (res->flags & IORESOURCE_IO) {
+ outl(val, res->base + offset);
+ } else if (res->flags & IORESOURCE_MEM) {
+ write32(res->base + offset, val);
+ }
+}
+
+static inline void rmw_res8(struct device *dev, unsigned index, u32 offset, u8 mask, u8 val)
+{
+ u8 tmp = read_res8(dev, index, offset);
+ tmp &= mask;
+ tmp |= val;
+ write_res8(dev, index, offset, tmp);
+}
+
+static inline void rmw_res16(struct device *dev, unsigned index, u32 offset, u16 mask, u16 val)
+{
+ u16 tmp = read_res16(dev, index, offset);
+ tmp &= mask;
+ tmp |= val;
+ write_res16(dev, index, offset, tmp);
+}
+
+static inline void rmw_res32(struct device *dev, unsigned index, u32 offset, u32 mask, u32 val)
+{
+ u32 tmp = read_res32(dev, index, offset);
+ tmp &= mask;
+ tmp |= val;
+ write_res32(dev, index, offset, tmp);
+}
+
+static inline void or_res8(struct device *dev, unsigned index, u32 offset, u8 val)
+{
+ rmw_res8(dev, index, offset, ~0, val);
+}
+
+static inline void or_res16(struct device *dev, unsigned index, u32 offset, u16 val)
+{
+ rmw_res16(dev, index, offset, ~0, val);
+}
+
+static inline void or_res32(struct device *dev, unsigned index, u32 offset, u32 val)
+{
+ rmw_res32(dev, index, offset, ~0, val);
+}
+
#endif /* DEVICE_RESOURCE_H */
More information about the coreboot-gerrit
mailing list