Commit bda42033253c0615cf8d3d4db9ad2fc38bfe5403

Authored by Blue Swirl
1 parent 1baffa46

Sparc64: convert memory to qdev

Signed-off-by: Blue Swirl <blauwirbel@gmail.com>
Showing 1 changed file with 59 additions and 4 deletions
hw/sun4u.c
... ... @@ -401,6 +401,63 @@ static void prom_register_devices(void)
401 401  
402 402 device_init(prom_register_devices);
403 403  
  404 +
  405 +typedef struct RamDevice
  406 +{
  407 + SysBusDevice busdev;
  408 + uint32_t size; // XXX
  409 +} RamDevice;
  410 +
  411 +/* System RAM */
  412 +static void ram_init1(SysBusDevice *dev)
  413 +{
  414 + ram_addr_t RAM_size, ram_offset;
  415 + RamDevice *d = FROM_SYSBUS(RamDevice, dev);
  416 +
  417 + RAM_size = d->size;
  418 +
  419 + ram_offset = qemu_ram_alloc(RAM_size);
  420 + sysbus_init_mmio(dev, RAM_size, ram_offset);
  421 +}
  422 +
  423 +static void ram_init(target_phys_addr_t addr, ram_addr_t RAM_size)
  424 +{
  425 + DeviceState *dev;
  426 + SysBusDevice *s;
  427 + RamDevice *d;
  428 +
  429 + /* allocate RAM */
  430 + dev = qdev_create(NULL, "memory");
  431 + s = sysbus_from_qdev(dev);
  432 +
  433 + d = FROM_SYSBUS(RamDevice, s);
  434 + d->size = RAM_size;
  435 + qdev_init(dev);
  436 +
  437 + sysbus_mmio_map(s, 0, addr);
  438 +}
  439 +
  440 +static SysBusDeviceInfo ram_info = {
  441 + .init = ram_init1,
  442 + .qdev.name = "memory",
  443 + .qdev.size = sizeof(RamDevice),
  444 + .qdev.props = (Property[]) {
  445 + {
  446 + .name = "size",
  447 + .info = &qdev_prop_uint32,
  448 + .offset = offsetof(RamDevice, size),
  449 + },
  450 + {/* end of property list */}
  451 + }
  452 +};
  453 +
  454 +static void ram_register_devices(void)
  455 +{
  456 + sysbus_register_withprop(&ram_info);
  457 +}
  458 +
  459 +device_init(ram_register_devices);
  460 +
404 461 static void sun4uv_init(ram_addr_t RAM_size,
405 462 const char *boot_devices,
406 463 const char *kernel_filename, const char *kernel_cmdline,
... ... @@ -411,7 +468,6 @@ static void sun4uv_init(ram_addr_t RAM_size,
411 468 m48t59_t *nvram;
412 469 int linux_boot;
413 470 unsigned int i;
414   - ram_addr_t ram_offset;
415 471 long initrd_size, kernel_size;
416 472 PCIBus *pci_bus, *pci_bus2, *pci_bus3;
417 473 QEMUBH *bh;
... ... @@ -454,9 +510,8 @@ static void sun4uv_init(ram_addr_t RAM_size,
454 510 env->pc = hwdef->prom_addr + 0x20ULL;
455 511 env->npc = env->pc + 4;
456 512  
457   - /* allocate RAM */
458   - ram_offset = qemu_ram_alloc(RAM_size);
459   - cpu_register_physical_memory(0, RAM_size, ram_offset);
  513 + /* set up devices */
  514 + ram_init(0, RAM_size);
460 515  
461 516 prom_init(hwdef->prom_addr, bios_name);
462 517  
... ...