From 01136c194406e69c93defe70f4d71bf865920837 Mon Sep 17 00:00:00 2001 From: Marcelo Tosatti Date: Tue, 11 Mar 2008 17:12:08 -0300 Subject: [PATCH] kvm: qemu: add cpu_unregister_io_memory and make io mem table index dynamic So drivers can clear their mem io table entries on exit back to unassigned state. Also make the io mem index allocation dynamic. Signed-off-by: Marcelo Tosatti Signed-off-by: Avi Kivity --- qemu/cpu-all.h | 1 + qemu/exec.c | 39 ++++++++++++++++++++++++++++++++++----- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/qemu/cpu-all.h b/qemu/cpu-all.h index 89589b04..a0e99bf6 100644 --- a/qemu/cpu-all.h +++ b/qemu/cpu-all.h @@ -837,6 +837,7 @@ int cpu_register_io_memory(int io_index, CPUReadMemoryFunc **mem_read, CPUWriteMemoryFunc **mem_write, void *opaque); +void cpu_unregister_io_memory(int table_address); CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index); CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index); diff --git a/qemu/exec.c b/qemu/exec.c index b82d26d5..edeb21aa 100644 --- a/qemu/exec.c +++ b/qemu/exec.c @@ -158,7 +158,7 @@ PhysPageDesc **l1_phys_map; CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; void *io_mem_opaque[IO_MEM_NB_ENTRIES]; -static int io_mem_nb; +char io_mem_used[IO_MEM_NB_ENTRIES]; #if defined(CONFIG_SOFTMMU) static int io_mem_watch; #endif @@ -2498,12 +2498,28 @@ static void *subpage_init (target_phys_addr_t base, uint32_t *phys, return mmio; } +static int get_free_io_mem_idx(void) +{ + int i; + + for (i = 0; i> IO_MEM_SHIFT, error_mem_read, unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_UNASSIGNED >> IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, notdirty_mem_write, NULL); - io_mem_nb = 5; + for (i=0; i<5; i++) + io_mem_used[i] = 0; #if defined(CONFIG_SOFTMMU) io_mem_watch = cpu_register_io_memory(-1, watch_mem_read, @@ -2530,9 +2546,9 @@ int cpu_register_io_memory(int io_index, int i, subwidth = 0; if (io_index <= 0) { - if (io_mem_nb >= IO_MEM_NB_ENTRIES) - return -1; - io_index = io_mem_nb++; + io_index = get_free_io_mem_idx(); + if (io_index == -1) + return io_index; } else { if (io_index >= IO_MEM_NB_ENTRIES) return -1; @@ -2548,6 +2564,19 @@ int cpu_register_io_memory(int io_index, return (io_index << IO_MEM_SHIFT) | subwidth; } +void cpu_unregister_io_memory(int io_table_address) +{ + int i; + int io_index = io_table_address >> IO_MEM_SHIFT; + + for (i=0;i < 3; i++) { + io_mem_read[io_index][i] = unassigned_mem_read[i]; + io_mem_write[io_index][i] = unassigned_mem_write[i]; + } + io_mem_opaque[io_index] = NULL; + io_mem_used[io_index] = 0; +} + CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index) { return io_mem_write[io_index >> IO_MEM_SHIFT]; -- 2.11.4.GIT