]> Git Repo - qemu.git/blob - hw/vga-pci.c
xilinx_ethlite: use qdev properties for configuration.
[qemu.git] / hw / vga-pci.c
1 /*
2  * QEMU PCI VGA Emulator.
3  *
4  * Copyright (c) 2003 Fabrice Bellard
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a copy
7  * of this software and associated documentation files (the "Software"), to deal
8  * in the Software without restriction, including without limitation the rights
9  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  * copies of the Software, and to permit persons to whom the Software is
11  * furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included in
14  * all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22  * THE SOFTWARE.
23  */
24 #include "hw.h"
25 #include "console.h"
26 #include "pc.h"
27 #include "pci.h"
28 #include "vga_int.h"
29 #include "pixel_ops.h"
30 #include "qemu-timer.h"
31
32 typedef struct PCIVGAState {
33     PCIDevice dev;
34     VGACommonState vga;
35 } PCIVGAState;
36
37 static void pci_vga_save(QEMUFile *f, void *opaque)
38 {
39     PCIVGAState *s = opaque;
40
41     pci_device_save(&s->dev, f);
42     vga_common_save(f, &s->vga);
43 }
44
45 static int pci_vga_load(QEMUFile *f, void *opaque, int version_id)
46 {
47     PCIVGAState *s = opaque;
48     int ret;
49
50     if (version_id > 2)
51         return -EINVAL;
52
53     if (version_id >= 2) {
54         ret = pci_device_load(&s->dev, f);
55         if (ret < 0)
56             return ret;
57     }
58     return vga_common_load(f, &s->vga, version_id);
59 }
60
61 static void vga_map(PCIDevice *pci_dev, int region_num,
62                     uint32_t addr, uint32_t size, int type)
63 {
64     PCIVGAState *d = (PCIVGAState *)pci_dev;
65     VGACommonState *s = &d->vga;
66     if (region_num == PCI_ROM_SLOT) {
67         cpu_register_physical_memory(addr, s->bios_size, s->bios_offset);
68     } else {
69         cpu_register_physical_memory(addr, s->vram_size, s->vram_offset);
70         s->map_addr = addr;
71         s->map_end = addr + s->vram_size;
72         vga_dirty_log_start(s);
73     }
74 }
75
76 static void pci_vga_write_config(PCIDevice *d,
77                                  uint32_t address, uint32_t val, int len)
78 {
79     PCIVGAState *pvs = container_of(d, PCIVGAState, dev);
80     VGACommonState *s = &pvs->vga;
81
82     pci_default_write_config(d, address, val, len);
83     if (s->map_addr && pvs->dev.io_regions[0].addr == -1)
84         s->map_addr = 0;
85 }
86
87 static int pci_vga_initfn(PCIDevice *dev)
88 {
89      PCIVGAState *d = DO_UPCAST(PCIVGAState, dev, dev);
90      VGACommonState *s = &d->vga;
91      uint8_t *pci_conf = d->dev.config;
92
93      // vga + console init
94      vga_common_init(s, VGA_RAM_SIZE);
95      vga_init(s);
96      register_savevm("vga", 0, 2, pci_vga_save, pci_vga_load, d);
97
98      s->ds = graphic_console_init(s->update, s->invalidate,
99                                   s->screen_dump, s->text_update, s);
100
101      // dummy VGA (same as Bochs ID)
102      pci_config_set_vendor_id(pci_conf, PCI_VENDOR_ID_QEMU);
103      pci_config_set_device_id(pci_conf, PCI_DEVICE_ID_QEMU_VGA);
104      pci_config_set_class(pci_conf, PCI_CLASS_DISPLAY_VGA);
105      pci_conf[PCI_HEADER_TYPE] = PCI_HEADER_TYPE_NORMAL; // header_type
106
107      /* XXX: VGA_RAM_SIZE must be a power of two */
108      pci_register_bar(&d->dev, 0, VGA_RAM_SIZE,
109                       PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
110
111      if (s->bios_size) {
112         unsigned int bios_total_size;
113         /* must be a power of two */
114         bios_total_size = 1;
115         while (bios_total_size < s->bios_size)
116             bios_total_size <<= 1;
117         pci_register_bar(&d->dev, PCI_ROM_SLOT, bios_total_size,
118                          PCI_ADDRESS_SPACE_MEM_PREFETCH, vga_map);
119      }
120      return 0;
121 }
122
123 int pci_vga_init(PCIBus *bus,
124                  unsigned long vga_bios_offset, int vga_bios_size)
125 {
126     PCIDevice *dev;
127
128     dev = pci_create(bus, -1, "VGA");
129     qdev_prop_set_uint32(&dev->qdev, "bios-offset", vga_bios_offset);
130     qdev_prop_set_uint32(&dev->qdev, "bios-size", vga_bios_offset);
131     qdev_init_nofail(&dev->qdev);
132
133     return 0;
134 }
135
136 static PCIDeviceInfo vga_info = {
137     .qdev.name    = "VGA",
138     .qdev.size    = sizeof(PCIVGAState),
139     .init         = pci_vga_initfn,
140     .config_write = pci_vga_write_config,
141     .qdev.props   = (Property[]) {
142         DEFINE_PROP_HEX32("bios-offset", PCIVGAState, vga.bios_offset, 0),
143         DEFINE_PROP_HEX32("bios-size",   PCIVGAState, vga.bios_size,   0),
144         DEFINE_PROP_END_OF_LIST(),
145     }
146 };
147
148 static void vga_register(void)
149 {
150     pci_qdev_register(&vga_info);
151 }
152 device_init(vga_register);
This page took 0.033028 seconds and 4 git commands to generate.