Commit a414c306c06c4ee9cb05af645b9fee6f8ea34038

Authored by Gerd Hoffmann
Committed by Anthony Liguori
1 parent 9316d30f

qdev: convert all vga devices.

Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/cirrus_vga.c
... ... @@ -3302,46 +3302,55 @@ static void pci_cirrus_write_config(PCIDevice *d,
3302 3302 cirrus_update_memory_access(s);
3303 3303 }
3304 3304  
  3305 +static void pci_cirrus_vga_initfn(PCIDevice *dev)
  3306 +{
  3307 + PCICirrusVGAState *d = DO_UPCAST(PCICirrusVGAState, dev, dev);
  3308 + CirrusVGAState *s = &d->cirrus_vga;
  3309 + uint8_t *pci_conf = d->dev.config;
  3310 + int device_id = CIRRUS_ID_CLGD5446;
  3311 +
  3312 + /* setup VGA */
  3313 + vga_common_init(&s->vga, VGA_RAM_SIZE);
  3314 + cirrus_init_common(s, device_id, 1);
  3315 + s->vga.pci_dev = (PCIDevice *)d;
  3316 + s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
  3317 + s->vga.screen_dump, s->vga.text_update,
  3318 + &s->vga);
  3319 +
  3320 + /* setup PCI */
  3321 + pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
  3322 + pci_config_set_device_id(pci_conf, device_id);
  3323 + pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
  3324 + pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
  3325 + pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
  3326 +
  3327 + /* setup memory space */
  3328 + /* memory #0 LFB */
  3329 + /* memory #1 memory-mapped I/O */
  3330 + /* XXX: s->vga.vram_size must be a power of two */
  3331 + pci_register_bar((PCIDevice *)d, 0, 0x2000000,
  3332 + PCI_ADDRESS_SPACE_MEM_PREFETCH, cirrus_pci_lfb_map);
  3333 + if (device_id == CIRRUS_ID_CLGD5446) {
  3334 + pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
  3335 + PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
  3336 + }
  3337 + /* XXX: ROM BIOS */
  3338 +}
  3339 +
3305 3340 void pci_cirrus_vga_init(PCIBus *bus)
3306 3341 {
3307   - PCICirrusVGAState *d;
3308   - uint8_t *pci_conf;
3309   - CirrusVGAState *s;
3310   - int device_id;
3311   -
3312   - device_id = CIRRUS_ID_CLGD5446;
3313   -
3314   - /* setup PCI configuration registers */
3315   - d = (PCICirrusVGAState *)pci_register_device(bus, "Cirrus VGA",
3316   - sizeof(PCICirrusVGAState),
3317   - -1, NULL, pci_cirrus_write_config);
3318   - pci_conf = d->dev.config;
3319   - pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_CIRRUS);
3320   - pci_config_set_device_id(pci_conf, device_id);
3321   - pci_conf[0x04] = PCI_COMMAND_IOACCESS | PCI_COMMAND_MEMACCESS;
3322   - pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
3323   - pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL;
3324   -
3325   - /* setup VGA */
3326   - s = &d->cirrus_vga;
3327   - vga_common_init(&s->vga, VGA_RAM_SIZE);
3328   - cirrus_init_common(s, device_id, 1);
3329   -
3330   - s->vga.ds = graphic_console_init(s->vga.update, s->vga.invalidate,
3331   - s->vga.screen_dump, s->vga.text_update,
3332   - &s->vga);
  3342 + pci_create_simple(bus, -1, "Cirrus VGA");
  3343 +}
3333 3344  
3334   - s->vga.pci_dev = (PCIDevice *)d;
  3345 +static PCIDeviceInfo cirrus_vga_info = {
  3346 + .qdev.name = "Cirrus VGA",
  3347 + .qdev.size = sizeof(PCICirrusVGAState),
  3348 + .init = pci_cirrus_vga_initfn,
  3349 + .config_write = pci_cirrus_write_config,
  3350 +};
3335 3351  
3336   - /* setup memory space */
3337   - /* memory #0 LFB */
3338   - /* memory #1 memory-mapped I/O */
3339   - /* XXX: s->vga.vram_size must be a power of two */
3340   - pci_register_bar((PCIDevice *)d, 0, 0x2000000,
3341   - PCI_ADDRESS_SPACE_MEM_PREFETCH, cirrus_pci_lfb_map);
3342   - if (device_id == CIRRUS_ID_CLGD5446) {
3343   - pci_register_bar((PCIDevice *)d, 1, CIRRUS_PNPMMIO_SIZE,
3344   - PCI_ADDRESS_SPACE_MEM, cirrus_pci_mmio_map);
3345   - }
3346   - /* XXX: ROM BIOS */
  3352 +static void cirrus_vga_register(void)
  3353 +{
  3354 + pci_qdev_register(&cirrus_vga_info);
3347 3355 }
  3356 +device_init(cirrus_vga_register);
... ...
hw/vga.c
... ... @@ -2480,52 +2480,78 @@ static void pci_vga_write_config(PCIDevice *d,
2480 2480 s->map_addr = 0;
2481 2481 }
2482 2482  
2483   -int pci_vga_init(PCIBus *bus,
2484   - unsigned long vga_bios_offset, int vga_bios_size)
2485   -{
2486   - PCIVGAState *d;
2487   - VGAState *s;
2488   - uint8_t *pci_conf;
2489   -
2490   - d = (PCIVGAState *)pci_register_device(bus, "VGA",
2491   - sizeof(PCIVGAState),
2492   - -1, NULL, pci_vga_write_config);
2493   - if (!d)
2494   - return -1;
2495   - s = &d->vga_state;
2496   -
2497   - vga_common_init(s, VGA_RAM_SIZE);
2498   - vga_init(s);
2499   -
2500   - s->ds = graphic_console_init(s->update, s->invalidate,
2501   - s->screen_dump, s->text_update, s);
2502   -
2503   - s->pci_dev = &d->dev;
2504   -
2505   - pci_conf = d->dev.config;
2506   - // dummy VGA (same as Bochs ID)
2507   - pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
2508   - pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
2509   - pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
2510   - pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
2511   -
2512   - /* XXX: VGA_RAM_SIZE must be a power of two */
2513   - pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
2514   - PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
2515   - if (vga_bios_size != 0) {
  2483 +static void pci_vga_initfn(PCIDevice *dev)
  2484 +{
  2485 + PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
  2486 + VGAState *s = &d->vga_state;
  2487 + uint8_t *pci_conf = d->dev.config;
  2488 +
  2489 + // vga + console init
  2490 + vga_common_init(s, VGA_RAM_SIZE);
  2491 + vga_init(s);
  2492 + s->pci_dev = &d->dev;
  2493 + s->ds = graphic_console_init(s->update, s->invalidate,
  2494 + s->screen_dump, s->text_update, s);
  2495 +
  2496 + // dummy VGA (same as Bochs ID)
  2497 + pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
  2498 + pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
  2499 + pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
  2500 + pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
  2501 +
  2502 + /* XXX: VGA_RAM_SIZE must be a power of two */
  2503 + pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
  2504 + PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
  2505 +
  2506 + if (s->bios_size) {
2516 2507 unsigned int bios_total_size;
2517   - s->bios_offset = vga_bios_offset;
2518   - s->bios_size = vga_bios_size;
2519 2508 /* must be a power of two */
2520 2509 bios_total_size = 1;
2521   - while (bios_total_size < vga_bios_size)
  2510 + while (bios_total_size < s->bios_size)
2522 2511 bios_total_size <<= 1;
2523 2512 pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size,
2524   - PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
  2513 + PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
2525 2514 }
  2515 +}
  2516 +
  2517 +int pci_vga_init(PCIBus *bus,
  2518 + unsigned long vga_bios_offset, int vga_bios_size)
  2519 +{
  2520 + PCIDevice *dev;
  2521 +
  2522 + dev = pci_create("VGA", NULL);
  2523 + qdev_prop_set_uint32(&dev->qdev, "bios-offset", vga_bios_offset);
  2524 + qdev_prop_set_uint32(&dev->qdev, "bios-size", vga_bios_offset);
  2525 + qdev_init(&dev->qdev);
  2526 +
2526 2527 return 0;
2527 2528 }
2528 2529  
  2530 +static PCIDeviceInfo vga_info = {
  2531 + .qdev.name = "VGA",
  2532 + .qdev.size = sizeof(PCIVGAState),
  2533 + .init = pci_vga_initfn,
  2534 + .config_write = pci_vga_write_config,
  2535 + .qdev.props = (Property[]) {
  2536 + {
  2537 + .name = "bios-offset",
  2538 + .info = &qdev_prop_hex32,
  2539 + .offset = offsetof(PCIVGAState, vga_state.bios_offset),
  2540 + },{
  2541 + .name = "bios-size",
  2542 + .info = &qdev_prop_hex32,
  2543 + .offset = offsetof(PCIVGAState, vga_state.bios_size),
  2544 + },
  2545 + {/* end of list */}
  2546 + }
  2547 +};
  2548 +
  2549 +static void vga_register(void)
  2550 +{
  2551 + pci_qdev_register(&vga_info);
  2552 +}
  2553 +device_init(vga_register);
  2554 +
2529 2555 /********************************************************/
2530 2556 /* vga screen dump */
2531 2557  
... ...
hw/vmware_vga.c
... ... @@ -1210,14 +1210,11 @@ static void pci_vmsvga_map_mem(PCIDevice *pci_dev, int region_num,
1210 1210 iomemtype);
1211 1211 }
1212 1212  
1213   -void pci_vmsvga_init(PCIBus *bus)
  1213 +static void pci_vmsvga_initfn(PCIDevice *dev)
1214 1214 {
1215   - struct pci_vmsvga_state_s *s;
  1215 + struct pci_vmsvga_state_s *s =
  1216 + DO_UPCAST(struct pci_vmsvga_state_s, card, dev);
1216 1217  
1217   - /* Setup PCI configuration */
1218   - s = (struct pci_vmsvga_state_s *)
1219   - pci_register_device(bus, "QEMUware SVGA",
1220   - sizeof(struct pci_vmsvga_state_s), -1, NULL, NULL);
1221 1218 pci_config_set_vendor_id(s->card.config, PCI_VENDOR_ID_VMWARE);
1222 1219 pci_config_set_device_id(s->card.config, SVGA_PCI_DEVICE_ID);
1223 1220 s->card.config[PCI_COMMAND] = 0x07; /* I/O + Memory */
... ... @@ -1240,3 +1237,20 @@ void pci_vmsvga_init(PCIBus *bus)
1240 1237  
1241 1238 register_savevm("vmware_vga", 0, 0, pci_vmsvga_save, pci_vmsvga_load, s);
1242 1239 }
  1240 +
  1241 +void pci_vmsvga_init(PCIBus *bus)
  1242 +{
  1243 + pci_create_simple(bus, -1, "QEMUware SVGA");
  1244 +}
  1245 +
  1246 +static PCIDeviceInfo vmsvga_info = {
  1247 + .qdev.name = "QEMUware SVGA",
  1248 + .qdev.size = sizeof(struct pci_vmsvga_state_s),
  1249 + .init = pci_vmsvga_initfn,
  1250 +};
  1251 +
  1252 +static void vmsvga_register(void)
  1253 +{
  1254 + pci_qdev_register(&vmsvga_info);
  1255 +}
  1256 +device_init(vmsvga_register);
... ...