aboutsummaryrefslogtreecommitdiff
path: root/hw/esp.c
diff options
context:
space:
mode:
authorPaul Brook <paul@codesourcery.com>2009-05-14 22:35:07 +0100
committerPaul Brook <paul@codesourcery.com>2009-05-14 22:35:07 +0100
commitcfb9de9ce48d108cfc56052dc9bc402a6197c199 (patch)
tree082fc9ead002d62b270d240f4f1eecb25c5572c1 /hw/esp.c
parent418dcf5b7da0efefea33ad4e96434feff57524d5 (diff)
ESP SCSI qdev conversion
Signed-off-by: Paul Brook <paul@codesourcery.com>
Diffstat (limited to 'hw/esp.c')
-rw-r--r--hw/esp.c61
1 files changed, 42 insertions, 19 deletions
diff --git a/hw/esp.c b/hw/esp.c
index 17b8f9635b..302e897f5d 100644
--- a/hw/esp.c
+++ b/hw/esp.c
@@ -22,7 +22,7 @@
* THE SOFTWARE.
*/
-#include "hw.h"
+#include "sysbus.h"
#include "scsi-disk.h"
#include "scsi.h"
@@ -53,6 +53,7 @@
typedef struct ESPState ESPState;
struct ESPState {
+ SysBusDevice busdev;
uint32_t it_shift;
qemu_irq irq;
uint8_t rregs[ESP_REGS];
@@ -617,9 +618,9 @@ static int esp_load(QEMUFile *f, void *opaque, int version_id)
return 0;
}
-void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id)
+static void esp_scsi_attach(DeviceState *host, BlockDriverState *bd, int id)
{
- ESPState *s = (ESPState *)opaque;
+ ESPState *s = FROM_SYSBUS(ESPState, sysbus_from_qdev(host));
if (id < 0) {
for (id = 0; id < ESP_MAX_DEVS; id++) {
@@ -644,31 +645,53 @@ void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id)
s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s);
}
-void *esp_init(target_phys_addr_t espaddr, int it_shift,
- espdma_memory_read_write dma_memory_read,
- espdma_memory_read_write dma_memory_write,
- void *dma_opaque, qemu_irq irq, qemu_irq *reset)
+void esp_init(target_phys_addr_t espaddr, int it_shift,
+ espdma_memory_read_write dma_memory_read,
+ espdma_memory_read_write dma_memory_write,
+ void *dma_opaque, qemu_irq irq, qemu_irq *reset)
{
- ESPState *s;
- int esp_io_memory;
+ DeviceState *dev;
+ SysBusDevice *s;
+
+ dev = qdev_create(NULL, "esp");
+ qdev_set_prop_ptr(dev, "dma_memory_read", dma_memory_read);
+ qdev_set_prop_ptr(dev, "dma_memory_write", dma_memory_write);
+ qdev_set_prop_ptr(dev, "dma_opaque", dma_opaque);
+ qdev_set_prop_int(dev, "it_shift", it_shift);
+ qdev_init(dev);
+ s = sysbus_from_qdev(dev);
+ sysbus_connect_irq(s, 0, irq);
+ sysbus_mmio_map(s, 0, espaddr);
+}
- s = qemu_mallocz(sizeof(ESPState));
+static void esp_init1(SysBusDevice *dev)
+{
+ ESPState *s = FROM_SYSBUS(ESPState, dev);
+ int esp_io_memory;
- s->irq = irq;
- s->it_shift = it_shift;
- s->dma_memory_read = dma_memory_read;
- s->dma_memory_write = dma_memory_write;
- s->dma_opaque = dma_opaque;
+ sysbus_init_irq(dev, &s->irq);
+ s->it_shift = qdev_get_prop_int(&dev->qdev, "it_shift", -1);
+ assert(s->it_shift != -1);
+ s->dma_memory_read = qdev_get_prop_ptr(&dev->qdev, "dma_memory_read");
+ s->dma_memory_write = qdev_get_prop_ptr(&dev->qdev, "dma_memory_write");
+ s->dma_opaque = qdev_get_prop_ptr(&dev->qdev, "dma_opaque");
esp_io_memory = cpu_register_io_memory(0, esp_mem_read, esp_mem_write, s);
- cpu_register_physical_memory(espaddr, ESP_REGS << it_shift, esp_io_memory);
+ sysbus_init_mmio(dev, ESP_REGS << s->it_shift, esp_io_memory);
esp_reset(s);
- register_savevm("esp", espaddr, 3, esp_save, esp_load, s);
+ register_savevm("esp", -1, 3, esp_save, esp_load, s);
qemu_register_reset(esp_reset, s);
- *reset = *qemu_allocate_irqs(parent_esp_reset, s, 1);
+ qdev_init_irq_sink(&dev->qdev, parent_esp_reset, 1);
- return s;
+ scsi_bus_new(&dev->qdev, esp_scsi_attach);
}
+
+static void esp_register_devices(void)
+{
+ sysbus_register_dev("esp", sizeof(ESPState), esp_init1);
+}
+
+device_init(esp_register_devices)