Commit a350db853f97f3db7f9ebf7af43150d3cb20be79

Authored by Blue Swirl
1 parent f48f6569

Sparc32: convert memory to qdev

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Showing 1 changed file with 56 additions and 36 deletions
hw/sun4m.c
... ... @@ -480,6 +480,56 @@ static void prom_register_devices(void)
480 480  
481 481 device_init(prom_register_devices);
482 482  
  483 +/* System RAM */
  484 +static void ram_init1(SysBusDevice *dev)
  485 +{
  486 + ram_addr_t RAM_size, ram_offset;
  487 +
  488 + RAM_size = qdev_get_prop_int(&dev->qdev, "size", 0);
  489 +
  490 + ram_offset = qemu_ram_alloc(RAM_size);
  491 + sysbus_init_mmio(dev, RAM_size, ram_offset);
  492 +}
  493 +
  494 +static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size,
  495 + uint64_t max_mem)
  496 +{
  497 + DeviceState *dev;
  498 + SysBusDevice *s;
  499 +
  500 + /* allocate RAM */
  501 + if ((uint64_t)RAM_size > max_mem) {
  502 + fprintf(stderr,
  503 + "qemu: Too much memory for this machine: %d, maximum %d\n",
  504 + (unsigned int)(RAM_size / (1024 * 1024)),
  505 + (unsigned int)(max_mem / (1024 * 1024)));
  506 + exit(1);
  507 + }
  508 + dev = qdev_create(NULL, "memory");
  509 + qdev_set_prop_int(dev, "size", RAM_size);
  510 + qdev_init(dev);
  511 + s = sysbus_from_qdev(dev);
  512 +
  513 + sysbus_mmio_map(s, 0, addr);
  514 +}
  515 +
  516 +static SysBusDeviceInfo ram_info = {
  517 + .init = ram_init1,
  518 + .qdev.name = "memory",
  519 + .qdev.size = sizeof(SysBusDevice),
  520 + .qdev.props = (DevicePropList[]) {
  521 + {.name = "size", .type = PROP_TYPE_INT},
  522 + {.name = NULL}
  523 + }
  524 +};
  525 +
  526 +static void ram_register_devices(void)
  527 +{
  528 + sysbus_register_withprop(&ram_info);
  529 +}
  530 +
  531 +device_init(ram_register_devices);
  532 +
483 533 static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
484 534 const char *boot_device,
485 535 const char *kernel_filename,
... ... @@ -495,7 +545,6 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
495 545 qemu_irq *esp_reset, *le_reset;
496 546 qemu_irq fdc_tc;
497 547 qemu_irq *cpu_halt;
498   - ram_addr_t ram_offset;
499 548 unsigned long kernel_size;
500 549 BlockDriverState *fd[MAX_FD];
501 550 int drive_index;
... ... @@ -527,18 +576,9 @@ static void sun4m_hw_init(const struct sun4m_hwdef *hwdef, ram_addr_t RAM_size,
527 576 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
528 577  
529 578  
530   - /* allocate RAM */
531   - if ((uint64_t)RAM_size > hwdef->max_mem) {
532   - fprintf(stderr,
533   - "qemu: Too much memory for this machine: %d, maximum %d\n",
534   - (unsigned int)(RAM_size / (1024 * 1024)),
535   - (unsigned int)(hwdef->max_mem / (1024 * 1024)));
536   - exit(1);
537   - }
538   - ram_offset = qemu_ram_alloc(RAM_size);
539   - cpu_register_physical_memory(0, RAM_size, ram_offset);
540   -
541 579 /* set up devices */
  580 + ram_init(0, RAM_size, hwdef->max_mem);
  581 +
542 582 prom_init(hwdef->slavio_base, bios_name);
543 583  
544 584 slavio_intctl = slavio_intctl_init(hwdef->intctl_base,
... ... @@ -1259,7 +1299,6 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1259 1299 qemu_irq *cpu_irqs[MAX_CPUS], *sbi_irq, *sbi_cpu_irq,
1260 1300 espdma_irq, ledma_irq;
1261 1301 qemu_irq *esp_reset, *le_reset;
1262   - ram_addr_t ram_offset;
1263 1302 unsigned long kernel_size;
1264 1303 void *fw_cfg;
1265 1304  
... ... @@ -1288,18 +1327,9 @@ static void sun4d_hw_init(const struct sun4d_hwdef *hwdef, ram_addr_t RAM_size,
1288 1327 for (i = smp_cpus; i < MAX_CPUS; i++)
1289 1328 cpu_irqs[i] = qemu_allocate_irqs(dummy_cpu_set_irq, NULL, MAX_PILS);
1290 1329  
1291   - /* allocate RAM */
1292   - if ((uint64_t)RAM_size > hwdef->max_mem) {
1293   - fprintf(stderr,
1294   - "qemu: Too much memory for this machine: %d, maximum %d\n",
1295   - (unsigned int)(RAM_size / (1024 * 1024)),
1296   - (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1297   - exit(1);
1298   - }
1299   - ram_offset = qemu_ram_alloc(RAM_size);
1300   - cpu_register_physical_memory(0, RAM_size, ram_offset);
1301   -
1302 1330 /* set up devices */
  1331 + ram_init(0, RAM_size, hwdef->max_mem);
  1332 +
1303 1333 prom_init(hwdef->slavio_base, bios_name);
1304 1334  
1305 1335 sbi = sbi_init(hwdef->sbi_base, &sbi_irq, &sbi_cpu_irq, cpu_irqs);
... ... @@ -1454,7 +1484,6 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1454 1484 qemu_irq *cpu_irqs, *slavio_irq, espdma_irq, ledma_irq;
1455 1485 qemu_irq *esp_reset, *le_reset;
1456 1486 qemu_irq fdc_tc;
1457   - ram_addr_t ram_offset;
1458 1487 unsigned long kernel_size;
1459 1488 BlockDriverState *fd[MAX_FD];
1460 1489 int drive_index;
... ... @@ -1476,18 +1505,9 @@ static void sun4c_hw_init(const struct sun4c_hwdef *hwdef, ram_addr_t RAM_size,
1476 1505 cpu_irqs = qemu_allocate_irqs(cpu_set_irq, env, MAX_PILS);
1477 1506 env->prom_addr = hwdef->slavio_base;
1478 1507  
1479   - /* allocate RAM */
1480   - if ((uint64_t)RAM_size > hwdef->max_mem) {
1481   - fprintf(stderr,
1482   - "qemu: Too much memory for this machine: %d, maximum %d\n",
1483   - (unsigned int)(RAM_size / (1024 * 1024)),
1484   - (unsigned int)(hwdef->max_mem / (1024 * 1024)));
1485   - exit(1);
1486   - }
1487   - ram_offset = qemu_ram_alloc(RAM_size);
1488   - cpu_register_physical_memory(0, RAM_size, ram_offset);
1489   -
1490 1508 /* set up devices */
  1509 + ram_init(0, RAM_size, hwdef->max_mem);
  1510 +
1491 1511 prom_init(hwdef->slavio_base, bios_name);
1492 1512  
1493 1513 slavio_intctl = sun4c_intctl_init(hwdef->intctl_base,
... ...