Statistics
| Branch: | Revision:

root / hw / vga-pci.c @ 32902772

History | View | Annotate | Download (3.7 kB)

1 47d37dd9 Juan Quintela
/*
2 47d37dd9 Juan Quintela
 * QEMU PCI VGA Emulator.
3 47d37dd9 Juan Quintela
 *
4 47d37dd9 Juan Quintela
 * Copyright (c) 2003 Fabrice Bellard
5 47d37dd9 Juan Quintela
 *
6 47d37dd9 Juan Quintela
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 47d37dd9 Juan Quintela
 * of this software and associated documentation files (the "Software"), to deal
8 47d37dd9 Juan Quintela
 * in the Software without restriction, including without limitation the rights
9 47d37dd9 Juan Quintela
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 47d37dd9 Juan Quintela
 * copies of the Software, and to permit persons to whom the Software is
11 47d37dd9 Juan Quintela
 * furnished to do so, subject to the following conditions:
12 47d37dd9 Juan Quintela
 *
13 47d37dd9 Juan Quintela
 * The above copyright notice and this permission notice shall be included in
14 47d37dd9 Juan Quintela
 * all copies or substantial portions of the Software.
15 47d37dd9 Juan Quintela
 *
16 47d37dd9 Juan Quintela
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 47d37dd9 Juan Quintela
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 47d37dd9 Juan Quintela
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 47d37dd9 Juan Quintela
 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 47d37dd9 Juan Quintela
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 47d37dd9 Juan Quintela
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22 47d37dd9 Juan Quintela
 * THE SOFTWARE.
23 47d37dd9 Juan Quintela
 */
24 47d37dd9 Juan Quintela
#include "hw.h"
25 47d37dd9 Juan Quintela
#include "console.h"
26 47d37dd9 Juan Quintela
#include "pc.h"
27 47d37dd9 Juan Quintela
#include "pci.h"
28 47d37dd9 Juan Quintela
#include "vga_int.h"
29 47d37dd9 Juan Quintela
#include "pixel_ops.h"
30 47d37dd9 Juan Quintela
#include "qemu-timer.h"
31 5245d57a Gerd Hoffmann
#include "loader.h"
32 47d37dd9 Juan Quintela
33 47d37dd9 Juan Quintela
typedef struct PCIVGAState {
34 47d37dd9 Juan Quintela
    PCIDevice dev;
35 47d37dd9 Juan Quintela
    VGACommonState vga;
36 47d37dd9 Juan Quintela
} PCIVGAState;
37 47d37dd9 Juan Quintela
38 a4f9631c Juan Quintela
static const VMStateDescription vmstate_vga_pci = {
39 a4f9631c Juan Quintela
    .name = "vga",
40 a4f9631c Juan Quintela
    .version_id = 2,
41 a4f9631c Juan Quintela
    .minimum_version_id = 2,
42 a4f9631c Juan Quintela
    .minimum_version_id_old = 2,
43 a4f9631c Juan Quintela
    .fields      = (VMStateField []) {
44 a4f9631c Juan Quintela
        VMSTATE_PCI_DEVICE(dev, PCIVGAState),
45 a4f9631c Juan Quintela
        VMSTATE_STRUCT(vga, PCIVGAState, 0, vmstate_vga_common, VGACommonState),
46 a4f9631c Juan Quintela
        VMSTATE_END_OF_LIST()
47 47d37dd9 Juan Quintela
    }
48 a4f9631c Juan Quintela
};
49 47d37dd9 Juan Quintela
50 47d37dd9 Juan Quintela
static void vga_map(PCIDevice *pci_dev, int region_num,
51 6e355d90 Isaku Yamahata
                    pcibus_t addr, pcibus_t size, int type)
52 47d37dd9 Juan Quintela
{
53 47d37dd9 Juan Quintela
    PCIVGAState *d = (PCIVGAState *)pci_dev;
54 47d37dd9 Juan Quintela
    VGACommonState *s = &d->vga;
55 78895427 Gerd Hoffmann
56 78895427 Gerd Hoffmann
    cpu_register_physical_memory(addr, s->vram_size, s->vram_offset);
57 78895427 Gerd Hoffmann
    s->map_addr = addr;
58 78895427 Gerd Hoffmann
    s->map_end = addr + s->vram_size;
59 78895427 Gerd Hoffmann
    vga_dirty_log_start(s);
60 47d37dd9 Juan Quintela
}
61 47d37dd9 Juan Quintela
62 47d37dd9 Juan Quintela
static void pci_vga_write_config(PCIDevice *d,
63 47d37dd9 Juan Quintela
                                 uint32_t address, uint32_t val, int len)
64 47d37dd9 Juan Quintela
{
65 47d37dd9 Juan Quintela
    PCIVGAState *pvs = container_of(d, PCIVGAState, dev);
66 47d37dd9 Juan Quintela
    VGACommonState *s = &pvs->vga;
67 47d37dd9 Juan Quintela
68 47d37dd9 Juan Quintela
    pci_default_write_config(d, address, val, len);
69 47d37dd9 Juan Quintela
    if (s->map_addr && pvs->dev.io_regions[0].addr == -1)
70 47d37dd9 Juan Quintela
        s->map_addr = 0;
71 47d37dd9 Juan Quintela
}
72 47d37dd9 Juan Quintela
73 47d37dd9 Juan Quintela
static int pci_vga_initfn(PCIDevice *dev)
74 47d37dd9 Juan Quintela
{
75 47d37dd9 Juan Quintela
     PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
76 47d37dd9 Juan Quintela
     VGACommonState *s = &d->vga;
77 47d37dd9 Juan Quintela
78 47d37dd9 Juan Quintela
     // vga + console init
79 47d37dd9 Juan Quintela
     vga_common_init(s, VGA_RAM_SIZE);
80 47d37dd9 Juan Quintela
     vga_init(s);
81 47d37dd9 Juan Quintela
82 47d37dd9 Juan Quintela
     s->ds = graphic_console_init(s->update, s->invalidate,
83 47d37dd9 Juan Quintela
                                  s->screen_dump, s->text_update, s);
84 47d37dd9 Juan Quintela
85 47d37dd9 Juan Quintela
     /* XXX: VGA_RAM_SIZE must be a power of two */
86 47d37dd9 Juan Quintela
     pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
87 0392a017 Isaku Yamahata
                      PCI_BASE_ADDRESS_MEM_PREFETCH, vga_map);
88 47d37dd9 Juan Quintela
89 281a26b1 Gerd Hoffmann
     if (!dev->rom_bar) {
90 281a26b1 Gerd Hoffmann
         /* compatibility with pc-0.13 and older */
91 281a26b1 Gerd Hoffmann
         vga_init_vbe(s);
92 281a26b1 Gerd Hoffmann
     }
93 281a26b1 Gerd Hoffmann
94 47d37dd9 Juan Quintela
     return 0;
95 47d37dd9 Juan Quintela
}
96 47d37dd9 Juan Quintela
97 78895427 Gerd Hoffmann
int pci_vga_init(PCIBus *bus)
98 47d37dd9 Juan Quintela
{
99 78895427 Gerd Hoffmann
    pci_create_simple(bus, -1, "VGA");
100 47d37dd9 Juan Quintela
    return 0;
101 47d37dd9 Juan Quintela
}
102 47d37dd9 Juan Quintela
103 47d37dd9 Juan Quintela
static PCIDeviceInfo vga_info = {
104 47d37dd9 Juan Quintela
    .qdev.name    = "VGA",
105 47d37dd9 Juan Quintela
    .qdev.size    = sizeof(PCIVGAState),
106 be73cfe2 Juan Quintela
    .qdev.vmsd    = &vmstate_vga_pci,
107 be92bbf7 Gerd Hoffmann
    .no_hotplug   = 1,
108 47d37dd9 Juan Quintela
    .init         = pci_vga_initfn,
109 47d37dd9 Juan Quintela
    .config_write = pci_vga_write_config,
110 78895427 Gerd Hoffmann
    .romfile      = "vgabios-stdvga.bin",
111 32902772 Isaku Yamahata
112 32902772 Isaku Yamahata
    /* dummy VGA (same as Bochs ID) */
113 32902772 Isaku Yamahata
    .vendor_id    = PCI_VENDOR_ID_QEMU,
114 32902772 Isaku Yamahata
    .device_id    = PCI_DEVICE_ID_QEMU_VGA,
115 32902772 Isaku Yamahata
    .class_id     = PCI_CLASS_DISPLAY_VGA,
116 47d37dd9 Juan Quintela
};
117 47d37dd9 Juan Quintela
118 47d37dd9 Juan Quintela
static void vga_register(void)
119 47d37dd9 Juan Quintela
{
120 47d37dd9 Juan Quintela
    pci_qdev_register(&vga_info);
121 47d37dd9 Juan Quintela
}
122 47d37dd9 Juan Quintela
device_init(vga_register);