[PATCH 2/9] kvm tools: Add basic ioport dynamic allocation

Sasha Levin
2011-05-25T14:24:24Z

Add a very simple allocation of ioports.

This prevents the need to coordinate ioports between different
modules.

Signed-off-by: Sasha Levin <levinsasha928@gmail.com>
---
tools/kvm/include/kvm/ioport.h | 5 +++++
tools/kvm/ioport.c | 7 +++++++
2 files changed, 12 insertions(+), 0 deletions(-)

diff --git a/tools/kvm/include/kvm/ioport.h b/tools/kvm/include/kvm/ioport.h
index 2a8d74d..bc7ea02 100644
--- a/tools/kvm/include/kvm/ioport.h
+++ b/tools/kvm/include/kvm/ioport.h
@@ -7,6 +7,9 @@

/* some ports we reserve for own use */
#define IOPORT_DBG 0xe0
+#define IOPORT_START 0x6200
+#define IOPORT_SIZE 0x400
+
#define IOPORT_VESA 0xa200
#define IOPORT_VESA_SIZE 256
#define IOPORT_VIRTIO_P9 0xb200 /* Virtio 9P device */
@@ -34,6 +37,8 @@ void ioport__setup_legacy(void);
void ioport__register(u16 port, struct ioport_operations *ops, int count);
void ioport__register_param(u16 port, struct ioport_operations *ops, int count, void *param);

+u16 ioport__find_free_range(void);
+
static inline u8 ioport__read8(u8 *data)
{
return *data;
diff --git a/tools/kvm/ioport.c b/tools/kvm/ioport.c
index 159d089..0db5a87 100644
--- a/tools/kvm/ioport.c
+++ b/tools/kvm/ioport.c
@@ -126,6 +126,13 @@ static void ioport_error(u16 port, void *data, int direction, int size, u32 coun
fprintf(stderr, "IO error: %s port=%x, size=%d, count=%u\n", to_direction(direction), port, size, count);
}

+u16 ioport__find_free_range(void)
+{
+ static u16 cur_loc;
+
+ return IOPORT_START + (cur_loc++ * IOPORT_SIZE);
+}
+
bool kvm__emulate_io(struct kvm *kvm, u16 port, void *data, int direction, int size, u32 count)
{
struct ioport_operations *ops;
--
1.7.5.rc3