aboutsummaryrefslogtreecommitdiff
path: root/iorange.h
diff options
context:
space:
mode:
authorAvi Kivity <avi@redhat.com>2010-11-17 11:50:09 +0200
committerAnthony Liguori <aliguori@us.ibm.com>2010-11-21 09:16:57 -0600
commitacd1c812b5548c8426e093075362b6d4119db6ac (patch)
tree0cc07f3a9b3d7dbeb29c95d4e56754a8d4a77afa /iorange.h
parent94b0b5ff5f5c3ab946fa926d464738edb3713ed4 (diff)
Type-safe ioport callbacks
The current ioport callbacks are not type-safe, in that they accept an "opaque" pointer as an argument whose type must match the argument to the registration function; this is not checked by the compiler. This patch adds an alternative that is type-safe. Instead of an opaque argument, both registation and the callback use a new IOPort type. The callback then uses container_of() to access its main structures. Currently the old and new methods exist side by side; once the old way is gone, we can also save a bunch of memory since the new method requires one pointer per ioport instead of 6. Acked-by: Anthony Liguori <aliguori@us.ibm.com> Signed-off-by: Avi Kivity <avi@redhat.com> Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Diffstat (limited to 'iorange.h')
-rw-r--r--iorange.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/iorange.h b/iorange.h
new file mode 100644
index 0000000000..97831683f0
--- /dev/null
+++ b/iorange.h
@@ -0,0 +1,30 @@
+#ifndef IORANGE_H
+#define IORANGE_H
+
+#include <stdint.h>
+
+typedef struct IORange IORange;
+typedef struct IORangeOps IORangeOps;
+
+struct IORangeOps {
+ void (*read)(IORange *iorange, uint64_t offset, unsigned width,
+ uint64_t *data);
+ void (*write)(IORange *iorange, uint64_t offset, unsigned width,
+ uint64_t data);
+};
+
+struct IORange {
+ const IORangeOps *ops;
+ uint64_t base;
+ uint64_t len;
+};
+
+static inline void iorange_init(IORange *iorange, const IORangeOps *ops,
+ uint64_t base, uint64_t len)
+{
+ iorange->ops = ops;
+ iorange->base = base;
+ iorange->len = len;
+}
+
+#endif