Commit cfb9de9ce48d108cfc56052dc9bc402a6197c199

Authored by Paul Brook
1 parent 418dcf5b

ESP SCSI qdev conversion

Signed-off-by: Paul Brook <paul@codesourcery.com>
hw/esp.c
@@ -22,7 +22,7 @@ @@ -22,7 +22,7 @@
22 * THE SOFTWARE. 22 * THE SOFTWARE.
23 */ 23 */
24 24
25 -#include "hw.h" 25 +#include "sysbus.h"
26 #include "scsi-disk.h" 26 #include "scsi-disk.h"
27 #include "scsi.h" 27 #include "scsi.h"
28 28
@@ -53,6 +53,7 @@ @@ -53,6 +53,7 @@
53 typedef struct ESPState ESPState; 53 typedef struct ESPState ESPState;
54 54
55 struct ESPState { 55 struct ESPState {
  56 + SysBusDevice busdev;
56 uint32_t it_shift; 57 uint32_t it_shift;
57 qemu_irq irq; 58 qemu_irq irq;
58 uint8_t rregs[ESP_REGS]; 59 uint8_t rregs[ESP_REGS];
@@ -617,9 +618,9 @@ static int esp_load(QEMUFile *f, void *opaque, int version_id) @@ -617,9 +618,9 @@ static int esp_load(QEMUFile *f, void *opaque, int version_id)
617 return 0; 618 return 0;
618 } 619 }
619 620
620 -void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id) 621 +static void esp_scsi_attach(DeviceState *host, BlockDriverState *bd, int id)
621 { 622 {
622 - ESPState *s = (ESPState *)opaque; 623 + ESPState *s = FROM_SYSBUS(ESPState, sysbus_from_qdev(host));
623 624
624 if (id < 0) { 625 if (id < 0) {
625 for (id = 0; id < ESP_MAX_DEVS; id++) { 626 for (id = 0; id < ESP_MAX_DEVS; id++) {
@@ -644,31 +645,53 @@ void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id) @@ -644,31 +645,53 @@ void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id)
644 s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s); 645 s->scsi_dev[id] = scsi_disk_init(bd, 0, esp_command_complete, s);
645 } 646 }
646 647
647 -void *esp_init(target_phys_addr_t espaddr, int it_shift,  
648 - espdma_memory_read_write dma_memory_read,  
649 - espdma_memory_read_write dma_memory_write,  
650 - void *dma_opaque, qemu_irq irq, qemu_irq *reset) 648 +void esp_init(target_phys_addr_t espaddr, int it_shift,
  649 + espdma_memory_read_write dma_memory_read,
  650 + espdma_memory_read_write dma_memory_write,
  651 + void *dma_opaque, qemu_irq irq, qemu_irq *reset)
651 { 652 {
652 - ESPState *s;  
653 - int esp_io_memory; 653 + DeviceState *dev;
  654 + SysBusDevice *s;
  655 +
  656 + dev = qdev_create(NULL, "esp");
  657 + qdev_set_prop_ptr(dev, "dma_memory_read", dma_memory_read);
  658 + qdev_set_prop_ptr(dev, "dma_memory_write", dma_memory_write);
  659 + qdev_set_prop_ptr(dev, "dma_opaque", dma_opaque);
  660 + qdev_set_prop_int(dev, "it_shift", it_shift);
  661 + qdev_init(dev);
  662 + s = sysbus_from_qdev(dev);
  663 + sysbus_connect_irq(s, 0, irq);
  664 + sysbus_mmio_map(s, 0, espaddr);
  665 +}
654 666
655 - s = qemu_mallocz(sizeof(ESPState)); 667 +static void esp_init1(SysBusDevice *dev)
  668 +{
  669 + ESPState *s = FROM_SYSBUS(ESPState, dev);
  670 + int esp_io_memory;
656 671
657 - s->irq = irq;  
658 - s->it_shift = it_shift;  
659 - s->dma_memory_read = dma_memory_read;  
660 - s->dma_memory_write = dma_memory_write;  
661 - s->dma_opaque = dma_opaque; 672 + sysbus_init_irq(dev, &s->irq);
  673 + s->it_shift = qdev_get_prop_int(&dev->qdev, "it_shift", -1);
  674 + assert(s->it_shift != -1);
  675 + s->dma_memory_read = qdev_get_prop_ptr(&dev->qdev, "dma_memory_read");
  676 + s->dma_memory_write = qdev_get_prop_ptr(&dev->qdev, "dma_memory_write");
  677 + s->dma_opaque = qdev_get_prop_ptr(&dev->qdev, "dma_opaque");
662 678
663 esp_io_memory = cpu_register_io_memory(0, esp_mem_read, esp_mem_write, s); 679 esp_io_memory = cpu_register_io_memory(0, esp_mem_read, esp_mem_write, s);
664 - cpu_register_physical_memory(espaddr, ESP_REGS << it_shift, esp_io_memory); 680 + sysbus_init_mmio(dev, ESP_REGS << s->it_shift, esp_io_memory);
665 681
666 esp_reset(s); 682 esp_reset(s);
667 683
668 - register_savevm("esp", espaddr, 3, esp_save, esp_load, s); 684 + register_savevm("esp", -1, 3, esp_save, esp_load, s);
669 qemu_register_reset(esp_reset, s); 685 qemu_register_reset(esp_reset, s);
670 686
671 - *reset = *qemu_allocate_irqs(parent_esp_reset, s, 1); 687 + qdev_init_irq_sink(&dev->qdev, parent_esp_reset, 1);
672 688
673 - return s; 689 + scsi_bus_new(&dev->qdev, esp_scsi_attach);
674 } 690 }
  691 +
  692 +static void esp_register_devices(void)
  693 +{
  694 + sysbus_register_dev("esp", sizeof(ESPState), esp_init1);
  695 +}
  696 +
  697 +device_init(esp_register_devices)
hw/mips_jazz.c
@@ -129,8 +129,6 @@ void mips_jazz_init (ram_addr_t ram_size, @@ -129,8 +129,6 @@ void mips_jazz_init (ram_addr_t ram_size,
129 qemu_irq *rc4030, *i8259; 129 qemu_irq *rc4030, *i8259;
130 rc4030_dma *dmas; 130 rc4030_dma *dmas;
131 void* rc4030_opaque; 131 void* rc4030_opaque;
132 - void *scsi_hba;  
133 - int hd;  
134 int s_rtc, s_dma_dummy; 132 int s_rtc, s_dma_dummy;
135 NICInfo *nd; 133 NICInfo *nd;
136 PITState *pit; 134 PITState *pit;
@@ -226,15 +224,9 @@ void mips_jazz_init (ram_addr_t ram_size, @@ -226,15 +224,9 @@ void mips_jazz_init (ram_addr_t ram_size,
226 } 224 }
227 225
228 /* SCSI adapter */ 226 /* SCSI adapter */
229 - scsi_hba = esp_init(0x80002000, 0,  
230 - rc4030_dma_read, rc4030_dma_write, dmas[0],  
231 - rc4030[5], &esp_reset);  
232 - for (n = 0; n < ESP_MAX_DEVS; n++) {  
233 - hd = drive_get_index(IF_SCSI, 0, n);  
234 - if (hd != -1) {  
235 - esp_scsi_attach(scsi_hba, drives_table[hd].bdrv, n);  
236 - }  
237 - } 227 + esp_init(0x80002000, 0,
  228 + rc4030_dma_read, rc4030_dma_write, dmas[0],
  229 + rc4030[5], &esp_reset);
238 230
239 /* Floppy */ 231 /* Floppy */
240 if (drive_get_max_bus(IF_FLOPPY) >= MAX_FD) { 232 if (drive_get_max_bus(IF_FLOPPY) >= MAX_FD) {
hw/scsi.h
1 /* esp.c */ 1 /* esp.c */
2 #define ESP_MAX_DEVS 7 2 #define ESP_MAX_DEVS 7
3 typedef void (*espdma_memory_read_write)(void *opaque, uint8_t *buf, int len); 3 typedef void (*espdma_memory_read_write)(void *opaque, uint8_t *buf, int len);
4 -void esp_scsi_attach(void *opaque, BlockDriverState *bd, int id);  
5 -void *esp_init(target_phys_addr_t espaddr, int it_shift,  
6 - espdma_memory_read_write dma_memory_read,  
7 - espdma_memory_read_write dma_memory_write,  
8 - void *dma_opaque, qemu_irq irq, qemu_irq *reset); 4 +void esp_init(target_phys_addr_t espaddr, int it_shift,
  5 + espdma_memory_read_write dma_memory_read,
  6 + espdma_memory_read_write dma_memory_write,
  7 + void *dma_opaque, qemu_irq irq, qemu_irq *reset);
hw/sun4m.c
@@ -391,7 +391,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, @@ -391,7 +391,7 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
391 { 391 {
392 CPUState *env, *envs[MAX_CPUS]; 392 CPUState *env, *envs[MAX_CPUS];
393 unsigned int i; 393 unsigned int i;
394 - void *iommu, *espdma, *ledma, *main_esp, *nvram; 394 + void *iommu, *espdma, *ledma, *nvram;
395 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq, 395 qemu_irq *cpu_irqs[MAX_CPUS], *slavio_irq, *slavio_cpu_irq,
396 *espdma_irq, *ledma_irq; 396 *espdma_irq, *ledma_irq;
397 qemu_irq *esp_reset, *le_reset; 397 qemu_irq *esp_reset, *le_reset;
@@ -533,16 +533,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size, @@ -533,16 +533,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
533 exit(1); 533 exit(1);
534 } 534 }
535 535
536 - main_esp = esp_init(hwdef->esp_base, 2,  
537 - espdma_memory_read, espdma_memory_write,  
538 - espdma, *espdma_irq, esp_reset);  
539 -  
540 - for (i = 0; i < ESP_MAX_DEVS; i++) {  
541 - drive_index = drive_get_index(IF_SCSI, 0, i);  
542 - if (drive_index == -1)  
543 - continue;  
544 - esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);  
545 - } 536 + esp_init(hwdef->esp_base, 2,
  537 + espdma_memory_read, espdma_memory_write,
  538 + espdma, *espdma_irq, esp_reset);
546 539
547 if (hwdef->cs_base) 540 if (hwdef->cs_base)
548 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl); 541 cs_init(hwdef->cs_base, hwdef->cs_irq, slavio_intctl);
@@ -1184,7 +1177,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, @@ -1184,7 +1177,7 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1184 { 1177 {
1185 CPUState *env, *envs[MAX_CPUS]; 1178 CPUState *env, *envs[MAX_CPUS];
1186 unsigned int i; 1179 unsigned int i;
1187 - void *iounits[MAX_IOUNITS], *espdma, *ledma, *main_esp, *nvram, *sbi; 1180 + void *iounits[MAX_IOUNITS], *espdma, *ledma, *nvram, *sbi;
1188 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq, 1181 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1189 *espdma_irq, *ledma_irq; 1182 *espdma_irq, *ledma_irq;
1190 qemu_irq *esp_reset, *le_reset; 1183 qemu_irq *esp_reset, *le_reset;
@@ -1192,7 +1185,6 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, @@ -1192,7 +1185,6 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1192 unsigned long kernel_size; 1185 unsigned long kernel_size;
1193 int ret; 1186 int ret;
1194 char buf[1024]; 1187 char buf[1024];
1195 - int drive_index;  
1196 void *fw_cfg; 1188 void *fw_cfg;
1197 1189
1198 /* init CPUs */ 1190 /* init CPUs */
@@ -1292,16 +1284,9 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size, @@ -1292,16 +1284,9 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1292 exit(1); 1284 exit(1);
1293 } 1285 }
1294 1286
1295 - main_esp = esp_init(hwdef->esp_base, 2,  
1296 - espdma_memory_read, espdma_memory_write,  
1297 - espdma, *espdma_irq, esp_reset);  
1298 -  
1299 - for (i = 0; i < ESP_MAX_DEVS; i++) {  
1300 - drive_index = drive_get_index(IF_SCSI, 0, i);  
1301 - if (drive_index == -1)  
1302 - continue;  
1303 - esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);  
1304 - } 1287 + esp_init(hwdef->esp_base, 2,
  1288 + espdma_memory_read, espdma_memory_write,
  1289 + espdma, *espdma_irq, esp_reset);
1305 1290
1306 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename, 1291 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1307 RAM_size); 1292 RAM_size);
@@ -1406,8 +1391,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, @@ -1406,8 +1391,7 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1406 const char *initrd_filename, const char *cpu_model) 1391 const char *initrd_filename, const char *cpu_model)
1407 { 1392 {
1408 CPUState *env; 1393 CPUState *env;
1409 - unsigned int i;  
1410 - void *iommu, *espdma, *ledma, *main_esp, *nvram; 1394 + void *iommu, *espdma, *ledma, *nvram;
1411 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq; 1395 qemu_irq *cpu_irqs, *slavio_irq, *espdma_irq, *ledma_irq;
1412 qemu_irq *esp_reset, *le_reset; 1396 qemu_irq *esp_reset, *le_reset;
1413 qemu_irq *fdc_tc; 1397 qemu_irq *fdc_tc;
@@ -1518,16 +1502,9 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size, @@ -1518,16 +1502,9 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1518 exit(1); 1502 exit(1);
1519 } 1503 }
1520 1504
1521 - main_esp = esp_init(hwdef->esp_base, 2,  
1522 - espdma_memory_read, espdma_memory_write,  
1523 - espdma, *espdma_irq, esp_reset);  
1524 -  
1525 - for (i = 0; i < ESP_MAX_DEVS; i++) {  
1526 - drive_index = drive_get_index(IF_SCSI, 0, i);  
1527 - if (drive_index == -1)  
1528 - continue;  
1529 - esp_scsi_attach(main_esp, drives_table[drive_index].bdrv, i);  
1530 - } 1505 + esp_init(hwdef->esp_base, 2,
  1506 + espdma_memory_read, espdma_memory_write,
  1507 + espdma, *espdma_irq, esp_reset);
1531 1508
1532 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename, 1509 kernel_size = sun4m_load_kernel(kernel_filename, initrd_filename,
1533 RAM_size); 1510 RAM_size);