munmap(dev->msix->phys_iomem_base, dev->msix->total_entries * 16);
}
+ if (dev->msix->mmio_index > 0)
+ {
+ cpu_unregister_io_memory(dev->msix->mmio_index);
+ }
+
+
free(dev->msix);
}
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 = 1;
+char io_mem_used[IO_MEM_NB_ENTRIES];
/* log support */
FILE *logfile;
mmio[mmio_cnt++].size = size;
}
+static int get_free_io_mem_idx(void)
+{
+ int i;
+
+ /* Leave 1st element empty */
+ for (i = 1; i<IO_MEM_NB_ENTRIES; i++)
+ if (!io_mem_used[i]) {
+ io_mem_used[i] = 1;
+ return i;
+ }
+
+ return -1;
+}
+
/* mem_read and mem_write are arrays of functions containing the
function to access byte (index 0), word (index 1) and dword (index
2). All functions must be supplied. If io_index is non zero, the
int i;
if (io_index <= 0) {
- if (io_index >= 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;
io_mem_write[io_index][i] = NULL;
}
io_mem_opaque[io_index] = NULL;
+ io_mem_used[io_index] = 0;
}
CPUWriteMemoryFunc **cpu_get_io_memory_write(int io_index)