root / hw / vga-pci.c @ d8ed79ae
History | View | Annotate | Download (4.8 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 | 47d37dd9 | Juan Quintela | |
32 | 47d37dd9 | Juan Quintela | typedef struct PCIVGAState { |
33 | 47d37dd9 | Juan Quintela | PCIDevice dev; |
34 | 47d37dd9 | Juan Quintela | VGACommonState vga; |
35 | 47d37dd9 | Juan Quintela | } PCIVGAState; |
36 | 47d37dd9 | Juan Quintela | |
37 | 47d37dd9 | Juan Quintela | static void pci_vga_save(QEMUFile *f, void *opaque) |
38 | 47d37dd9 | Juan Quintela | { |
39 | 47d37dd9 | Juan Quintela | PCIVGAState *s = opaque; |
40 | 47d37dd9 | Juan Quintela | |
41 | 47d37dd9 | Juan Quintela | pci_device_save(&s->dev, f); |
42 | 47d37dd9 | Juan Quintela | vga_common_save(f, &s->vga); |
43 | 47d37dd9 | Juan Quintela | } |
44 | 47d37dd9 | Juan Quintela | |
45 | 47d37dd9 | Juan Quintela | static int pci_vga_load(QEMUFile *f, void *opaque, int version_id) |
46 | 47d37dd9 | Juan Quintela | { |
47 | 47d37dd9 | Juan Quintela | PCIVGAState *s = opaque; |
48 | 47d37dd9 | Juan Quintela | int ret;
|
49 | 47d37dd9 | Juan Quintela | |
50 | 47d37dd9 | Juan Quintela | if (version_id > 2) |
51 | 47d37dd9 | Juan Quintela | return -EINVAL;
|
52 | 47d37dd9 | Juan Quintela | |
53 | 47d37dd9 | Juan Quintela | if (version_id >= 2) { |
54 | 47d37dd9 | Juan Quintela | ret = pci_device_load(&s->dev, f); |
55 | 47d37dd9 | Juan Quintela | if (ret < 0) |
56 | 47d37dd9 | Juan Quintela | return ret;
|
57 | 47d37dd9 | Juan Quintela | } |
58 | 47d37dd9 | Juan Quintela | return vga_common_load(f, &s->vga, version_id);
|
59 | 47d37dd9 | Juan Quintela | } |
60 | 47d37dd9 | Juan Quintela | |
61 | 47d37dd9 | Juan Quintela | static void vga_map(PCIDevice *pci_dev, int region_num, |
62 | 47d37dd9 | Juan Quintela | uint32_t addr, uint32_t size, int type)
|
63 | 47d37dd9 | Juan Quintela | { |
64 | 47d37dd9 | Juan Quintela | PCIVGAState *d = (PCIVGAState *)pci_dev; |
65 | 47d37dd9 | Juan Quintela | VGACommonState *s = &d->vga; |
66 | 47d37dd9 | Juan Quintela | if (region_num == PCI_ROM_SLOT) {
|
67 | 47d37dd9 | Juan Quintela | cpu_register_physical_memory(addr, s->bios_size, s->bios_offset); |
68 | 47d37dd9 | Juan Quintela | } else {
|
69 | 47d37dd9 | Juan Quintela | cpu_register_physical_memory(addr, s->vram_size, s->vram_offset); |
70 | 47d37dd9 | Juan Quintela | s->map_addr = addr; |
71 | 47d37dd9 | Juan Quintela | s->map_end = addr + s->vram_size; |
72 | 47d37dd9 | Juan Quintela | vga_dirty_log_start(s); |
73 | 47d37dd9 | Juan Quintela | } |
74 | 47d37dd9 | Juan Quintela | } |
75 | 47d37dd9 | Juan Quintela | |
76 | 47d37dd9 | Juan Quintela | static void pci_vga_write_config(PCIDevice *d, |
77 | 47d37dd9 | Juan Quintela | uint32_t address, uint32_t val, int len)
|
78 | 47d37dd9 | Juan Quintela | { |
79 | 47d37dd9 | Juan Quintela | PCIVGAState *pvs = container_of(d, PCIVGAState, dev); |
80 | 47d37dd9 | Juan Quintela | VGACommonState *s = &pvs->vga; |
81 | 47d37dd9 | Juan Quintela | |
82 | 47d37dd9 | Juan Quintela | pci_default_write_config(d, address, val, len); |
83 | 47d37dd9 | Juan Quintela | if (s->map_addr && pvs->dev.io_regions[0].addr == -1) |
84 | 47d37dd9 | Juan Quintela | s->map_addr = 0;
|
85 | 47d37dd9 | Juan Quintela | } |
86 | 47d37dd9 | Juan Quintela | |
87 | 47d37dd9 | Juan Quintela | static int pci_vga_initfn(PCIDevice *dev) |
88 | 47d37dd9 | Juan Quintela | { |
89 | 47d37dd9 | Juan Quintela | PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev); |
90 | 47d37dd9 | Juan Quintela | VGACommonState *s = &d->vga; |
91 | 47d37dd9 | Juan Quintela | uint8_t *pci_conf = d->dev.config; |
92 | 47d37dd9 | Juan Quintela | |
93 | 47d37dd9 | Juan Quintela | // vga + console init
|
94 | 47d37dd9 | Juan Quintela | vga_common_init(s, VGA_RAM_SIZE); |
95 | 47d37dd9 | Juan Quintela | vga_init(s); |
96 | 47d37dd9 | Juan Quintela | register_savevm("vga", 0, 2, pci_vga_save, pci_vga_load, d); |
97 | 47d37dd9 | Juan Quintela | |
98 | 47d37dd9 | Juan Quintela | s->ds = graphic_console_init(s->update, s->invalidate, |
99 | 47d37dd9 | Juan Quintela | s->screen_dump, s->text_update, s); |
100 | 47d37dd9 | Juan Quintela | |
101 | 47d37dd9 | Juan Quintela | // dummy VGA (same as Bochs ID)
|
102 | 47d37dd9 | Juan Quintela | pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU); |
103 | 47d37dd9 | Juan Quintela | pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA); |
104 | 47d37dd9 | Juan Quintela | pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA); |
105 | 47d37dd9 | Juan Quintela | pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
|
106 | 47d37dd9 | Juan Quintela | |
107 | 47d37dd9 | Juan Quintela | /* XXX: VGA_RAM_SIZE must be a power of two */
|
108 | 47d37dd9 | Juan Quintela | pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
|
109 | 47d37dd9 | Juan Quintela | PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map); |
110 | 47d37dd9 | Juan Quintela | |
111 | 47d37dd9 | Juan Quintela | if (s->bios_size) {
|
112 | 47d37dd9 | Juan Quintela | unsigned int bios_total_size; |
113 | 47d37dd9 | Juan Quintela | /* must be a power of two */
|
114 | 47d37dd9 | Juan Quintela | bios_total_size = 1;
|
115 | 47d37dd9 | Juan Quintela | while (bios_total_size < s->bios_size)
|
116 | 47d37dd9 | Juan Quintela | bios_total_size <<= 1;
|
117 | 47d37dd9 | Juan Quintela | pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size, |
118 | 47d37dd9 | Juan Quintela | PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map); |
119 | 47d37dd9 | Juan Quintela | } |
120 | 47d37dd9 | Juan Quintela | return 0; |
121 | 47d37dd9 | Juan Quintela | } |
122 | 47d37dd9 | Juan Quintela | |
123 | 47d37dd9 | Juan Quintela | int pci_vga_init(PCIBus *bus,
|
124 | 47d37dd9 | Juan Quintela | unsigned long vga_bios_offset, int vga_bios_size) |
125 | 47d37dd9 | Juan Quintela | { |
126 | 47d37dd9 | Juan Quintela | PCIDevice *dev; |
127 | 47d37dd9 | Juan Quintela | |
128 | 499cf102 | Markus Armbruster | dev = pci_create(bus, -1, "VGA"); |
129 | 47d37dd9 | Juan Quintela | qdev_prop_set_uint32(&dev->qdev, "bios-offset", vga_bios_offset);
|
130 | 47d37dd9 | Juan Quintela | qdev_prop_set_uint32(&dev->qdev, "bios-size", vga_bios_offset);
|
131 | e23a1b33 | Markus Armbruster | qdev_init_nofail(&dev->qdev); |
132 | 47d37dd9 | Juan Quintela | |
133 | 47d37dd9 | Juan Quintela | return 0; |
134 | 47d37dd9 | Juan Quintela | } |
135 | 47d37dd9 | Juan Quintela | |
136 | 47d37dd9 | Juan Quintela | static PCIDeviceInfo vga_info = {
|
137 | 47d37dd9 | Juan Quintela | .qdev.name = "VGA",
|
138 | 47d37dd9 | Juan Quintela | .qdev.size = sizeof(PCIVGAState),
|
139 | 47d37dd9 | Juan Quintela | .init = pci_vga_initfn, |
140 | 47d37dd9 | Juan Quintela | .config_write = pci_vga_write_config, |
141 | 47d37dd9 | Juan Quintela | .qdev.props = (Property[]) { |
142 | 47d37dd9 | Juan Quintela | DEFINE_PROP_HEX32("bios-offset", PCIVGAState, vga.bios_offset, 0), |
143 | 47d37dd9 | Juan Quintela | DEFINE_PROP_HEX32("bios-size", PCIVGAState, vga.bios_size, 0), |
144 | 47d37dd9 | Juan Quintela | DEFINE_PROP_END_OF_LIST(), |
145 | 47d37dd9 | Juan Quintela | } |
146 | 47d37dd9 | Juan Quintela | }; |
147 | 47d37dd9 | Juan Quintela | |
148 | 47d37dd9 | Juan Quintela | static void vga_register(void) |
149 | 47d37dd9 | Juan Quintela | { |
150 | 47d37dd9 | Juan Quintela | pci_qdev_register(&vga_info); |
151 | 47d37dd9 | Juan Quintela | } |
152 | 47d37dd9 | Juan Quintela | device_init(vga_register); |