Commit 8871565764495cfe873b781f52e0d39ecbc3ddf6

Authored by aliguori
1 parent 8b13c4a7

qemu: add cpu_unregister_io_memory and make io mem table index dynamic (Marcelo Tosatti)

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 <mtosatti@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>


git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6601 c046a42c-6fe2-441c-8c8c-71466251a162
Showing 2 changed files with 35 additions and 5 deletions
cpu-all.h
@@ -909,6 +909,7 @@ int cpu_register_io_memory(int io_index, @@ -909,6 +909,7 @@ int cpu_register_io_memory(int io_index,
909 CPUReadMemoryFunc **mem_read, 909 CPUReadMemoryFunc **mem_read,
910 CPUWriteMemoryFunc **mem_write, 910 CPUWriteMemoryFunc **mem_write,
911 void *opaque); 911 void *opaque);
  912 +void cpu_unregister_io_memory(int table_address);
912 CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index); 913 CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index);
913 CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index); 914 CPUReadMemoryFunc **cpu_get_io_memory_read(int io_index);
914 915
@@ -179,7 +179,7 @@ static void io_mem_init(void); @@ -179,7 +179,7 @@ static void io_mem_init(void);
179 CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4]; 179 CPUWriteMemoryFunc *io_mem_write[IO_MEM_NB_ENTRIES][4];
180 CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4]; 180 CPUReadMemoryFunc *io_mem_read[IO_MEM_NB_ENTRIES][4];
181 void *io_mem_opaque[IO_MEM_NB_ENTRIES]; 181 void *io_mem_opaque[IO_MEM_NB_ENTRIES];
182 -static int io_mem_nb; 182 +char io_mem_used[IO_MEM_NB_ENTRIES];
183 static int io_mem_watch; 183 static int io_mem_watch;
184 #endif 184 #endif
185 185
@@ -2799,12 +2799,28 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys, @@ -2799,12 +2799,28 @@ static void *subpage_init (target_phys_addr_t base, ram_addr_t *phys,
2799 return mmio; 2799 return mmio;
2800 } 2800 }
2801 2801
  2802 +static int get_free_io_mem_idx(void)
  2803 +{
  2804 + int i;
  2805 +
  2806 + for (i = 0; i<IO_MEM_NB_ENTRIES; i++)
  2807 + if (!io_mem_used[i]) {
  2808 + io_mem_used[i] = 1;
  2809 + return i;
  2810 + }
  2811 +
  2812 + return -1;
  2813 +}
  2814 +
2802 static void io_mem_init(void) 2815 static void io_mem_init(void)
2803 { 2816 {
  2817 + int i;
  2818 +
2804 cpu_register_io_memory(IO_MEM_ROM >> IO_MEM_SHIFT, error_mem_read, unassigned_mem_write, NULL); 2819 cpu_register_io_memory(IO_MEM_ROM >> IO_MEM_SHIFT, error_mem_read, unassigned_mem_write, NULL);
2805 cpu_register_io_memory(IO_MEM_UNASSIGNED >> IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL); 2820 cpu_register_io_memory(IO_MEM_UNASSIGNED >> IO_MEM_SHIFT, unassigned_mem_read, unassigned_mem_write, NULL);
2806 cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, notdirty_mem_write, NULL); 2821 cpu_register_io_memory(IO_MEM_NOTDIRTY >> IO_MEM_SHIFT, error_mem_read, notdirty_mem_write, NULL);
2807 - io_mem_nb = 5; 2822 + for (i=0; i<5; i++)
  2823 + io_mem_used[i] = 1;
2808 2824
2809 io_mem_watch = cpu_register_io_memory(0, watch_mem_read, 2825 io_mem_watch = cpu_register_io_memory(0, watch_mem_read,
2810 watch_mem_write, NULL); 2826 watch_mem_write, NULL);
@@ -2829,9 +2845,9 @@ int cpu_register_io_memory(int io_index, @@ -2829,9 +2845,9 @@ int cpu_register_io_memory(int io_index,
2829 int i, subwidth = 0; 2845 int i, subwidth = 0;
2830 2846
2831 if (io_index <= 0) { 2847 if (io_index <= 0) {
2832 - if (io_mem_nb >= IO_MEM_NB_ENTRIES)  
2833 - return -1;  
2834 - io_index = io_mem_nb++; 2848 + io_index = get_free_io_mem_idx();
  2849 + if (io_index == -1)
  2850 + return io_index;
2835 } else { 2851 } else {
2836 if (io_index >= IO_MEM_NB_ENTRIES) 2852 if (io_index >= IO_MEM_NB_ENTRIES)
2837 return -1; 2853 return -1;
@@ -2847,6 +2863,19 @@ int cpu_register_io_memory(int io_index, @@ -2847,6 +2863,19 @@ int cpu_register_io_memory(int io_index,
2847 return (io_index << IO_MEM_SHIFT) | subwidth; 2863 return (io_index << IO_MEM_SHIFT) | subwidth;
2848 } 2864 }
2849 2865
  2866 +void cpu_unregister_io_memory(int io_table_address)
  2867 +{
  2868 + int i;
  2869 + int io_index = io_table_address >> IO_MEM_SHIFT;
  2870 +
  2871 + for (i=0;i < 3; i++) {
  2872 + io_mem_read[io_index][i] = unassigned_mem_read[i];
  2873 + io_mem_write[io_index][i] = unassigned_mem_write[i];
  2874 + }
  2875 + io_mem_opaque[io_index] = NULL;
  2876 + io_mem_used[io_index] = 0;
  2877 +}
  2878 +
2850 CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index) 2879 CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index)
2851 { 2880 {
2852 return io_mem_write[io_index >> IO_MEM_SHIFT]; 2881 return io_mem_write[io_index >> IO_MEM_SHIFT];