1 #ifndef HW_PC_H 2 #define HW_PC_H 3 4 #include "qemu-common.h" 5 #include "exec/memory.h" 6 #include "exec/ioport.h" 7 #include "hw/isa/isa.h" 8 #include "hw/block/fdc.h" 9 #include "net/net.h" 10 #include "hw/i386/ioapic.h" 11 12 #include "qemu/range.h" 13 14 /* PC-style peripherals (also used by other machines). */ 15 16 typedef struct PcPciInfo { 17 Range w32; 18 Range w64; 19 } PcPciInfo; 20 21 struct PcGuestInfo { 22 PcPciInfo pci_info; 23 FWCfgState *fw_cfg; 24 }; 25 26 /* parallel.c */ 27 static inline bool parallel_init(ISABus *bus, int index, CharDriverState *chr) 28 { 29 DeviceState *dev; 30 ISADevice *isadev; 31 32 isadev = isa_try_create(bus, "isa-parallel"); 33 if (!isadev) { 34 return false; 35 } 36 dev = DEVICE(isadev); 37 qdev_prop_set_uint32(dev, "index", index); 38 qdev_prop_set_chr(dev, "chardev", chr); 39 if (qdev_init(dev) < 0) { 40 return false; 41 } 42 return true; 43 } 44 45 bool parallel_mm_init(MemoryRegion *address_space, 46 hwaddr base, int it_shift, qemu_irq irq, 47 CharDriverState *chr); 48 49 /* i8259.c */ 50 51 extern DeviceState *isa_pic; 52 qemu_irq *i8259_init(ISABus *bus, qemu_irq parent_irq); 53 qemu_irq *kvm_i8259_init(ISABus *bus); 54 int pic_read_irq(DeviceState *d); 55 int pic_get_output(DeviceState *d); 56 void pic_info(Monitor *mon, const QDict *qdict); 57 void irq_info(Monitor *mon, const QDict *qdict); 58 59 /* Global System Interrupts */ 60 61 #define GSI_NUM_PINS IOAPIC_NUM_PINS 62 63 typedef struct GSIState { 64 qemu_irq i8259_irq[ISA_NUM_IRQS]; 65 qemu_irq ioapic_irq[IOAPIC_NUM_PINS]; 66 } GSIState; 67 68 void gsi_handler(void *opaque, int n, int level); 69 70 /* vmport.c */ 71 static inline void vmport_init(ISABus *bus) 72 { 73 isa_create_simple(bus, "vmport"); 74 } 75 void vmport_register(unsigned char command, IOPortReadFunc *func, void *opaque); 76 void vmmouse_get_data(uint32_t *data); 77 void vmmouse_set_data(const uint32_t *data); 78 79 /* pckbd.c */ 80 81 void i8042_init(qemu_irq kbd_irq, qemu_irq mouse_irq, uint32_t io_base); 82 void i8042_mm_init(qemu_irq kbd_irq, qemu_irq mouse_irq, 83 MemoryRegion *region, ram_addr_t size, 84 hwaddr mask); 85 void i8042_isa_mouse_fake_event(void *opaque); 86 void i8042_setup_a20_line(ISADevice *dev, qemu_irq *a20_out); 87 88 /* pc.c */ 89 extern int fd_bootchk; 90 91 void pc_register_ferr_irq(qemu_irq irq); 92 void pc_acpi_smi_interrupt(void *opaque, int irq, int level); 93 94 void pc_cpus_init(const char *cpu_model, DeviceState *icc_bridge); 95 void pc_hot_add_cpu(const int64_t id, Error **errp); 96 void pc_acpi_init(const char *default_dsdt); 97 98 PcGuestInfo *pc_guest_info_init(ram_addr_t below_4g_mem_size, 99 ram_addr_t above_4g_mem_size); 100 101 FWCfgState *pc_memory_init(MemoryRegion *system_memory, 102 const char *kernel_filename, 103 const char *kernel_cmdline, 104 const char *initrd_filename, 105 ram_addr_t below_4g_mem_size, 106 ram_addr_t above_4g_mem_size, 107 MemoryRegion *rom_memory, 108 MemoryRegion **ram_memory, 109 PcGuestInfo *guest_info); 110 qemu_irq *pc_allocate_cpu_irq(void); 111 DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus); 112 void pc_basic_device_init(ISABus *isa_bus, qemu_irq *gsi, 113 ISADevice **rtc_state, 114 ISADevice **floppy, 115 bool no_vmport); 116 void pc_init_ne2k_isa(ISABus *bus, NICInfo *nd); 117 void pc_cmos_init(ram_addr_t ram_size, ram_addr_t above_4g_mem_size, 118 const char *boot_device, 119 ISADevice *floppy, BusState *ide0, BusState *ide1, 120 ISADevice *s); 121 void pc_nic_init(ISABus *isa_bus, PCIBus *pci_bus); 122 void pc_pci_device_init(PCIBus *pci_bus); 123 124 typedef void (*cpu_set_smm_t)(int smm, void *arg); 125 void cpu_smm_register(cpu_set_smm_t callback, void *arg); 126 127 void ioapic_init_gsi(GSIState *gsi_state, const char *parent_name); 128 129 /* acpi_piix.c */ 130 131 i2c_bus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base, 132 qemu_irq sci_irq, qemu_irq smi_irq, 133 int kvm_enabled, FWCfgState *fw_cfg); 134 void piix4_smbus_register_device(SMBusDevice *dev, uint8_t addr); 135 136 /* hpet.c */ 137 extern int no_hpet; 138 139 /* piix_pci.c */ 140 struct PCII440FXState; 141 typedef struct PCII440FXState PCII440FXState; 142 143 PCIBus *i440fx_init(PCII440FXState **pi440fx_state, int *piix_devfn, 144 ISABus **isa_bus, qemu_irq *pic, 145 MemoryRegion *address_space_mem, 146 MemoryRegion *address_space_io, 147 ram_addr_t ram_size, 148 hwaddr pci_hole_start, 149 hwaddr pci_hole_size, 150 hwaddr pci_hole64_start, 151 hwaddr pci_hole64_size, 152 MemoryRegion *pci_memory, 153 MemoryRegion *ram_memory); 154 155 /* piix4.c */ 156 extern PCIDevice *piix4_dev; 157 int piix4_init(PCIBus *bus, ISABus **isa_bus, int devfn); 158 159 /* vga.c */ 160 enum vga_retrace_method { 161 VGA_RETRACE_DUMB, 162 VGA_RETRACE_PRECISE 163 }; 164 165 extern enum vga_retrace_method vga_retrace_method; 166 167 int isa_vga_mm_init(hwaddr vram_base, 168 hwaddr ctrl_base, int it_shift, 169 MemoryRegion *address_space); 170 171 /* ne2000.c */ 172 static inline bool isa_ne2000_init(ISABus *bus, int base, int irq, NICInfo *nd) 173 { 174 DeviceState *dev; 175 ISADevice *isadev; 176 177 qemu_check_nic_model(nd, "ne2k_isa"); 178 179 isadev = isa_try_create(bus, "ne2k_isa"); 180 if (!isadev) { 181 return false; 182 } 183 dev = DEVICE(isadev); 184 qdev_prop_set_uint32(dev, "iobase", base); 185 qdev_prop_set_uint32(dev, "irq", irq); 186 qdev_set_nic_properties(dev, nd); 187 qdev_init_nofail(dev); 188 return true; 189 } 190 191 /* pc_sysfw.c */ 192 void pc_system_firmware_init(MemoryRegion *rom_memory); 193 194 /* pvpanic.c */ 195 int pvpanic_init(ISABus *bus); 196 197 /* e820 types */ 198 #define E820_RAM 1 199 #define E820_RESERVED 2 200 #define E820_ACPI 3 201 #define E820_NVS 4 202 #define E820_UNUSABLE 5 203 204 int e820_add_entry(uint64_t, uint64_t, uint32_t); 205 206 #define PC_COMPAT_1_5 \ 207 {\ 208 .driver = "Conroe-" TYPE_X86_CPU,\ 209 .property = "model",\ 210 .value = stringify(2),\ 211 },{\ 212 .driver = "Conroe-" TYPE_X86_CPU,\ 213 .property = "level",\ 214 .value = stringify(2),\ 215 },{\ 216 .driver = "Penryn-" TYPE_X86_CPU,\ 217 .property = "model",\ 218 .value = stringify(2),\ 219 },{\ 220 .driver = "Penryn-" TYPE_X86_CPU,\ 221 .property = "level",\ 222 .value = stringify(2),\ 223 },{\ 224 .driver = "Nehalem-" TYPE_X86_CPU,\ 225 .property = "model",\ 226 .value = stringify(2),\ 227 },{\ 228 .driver = "Nehalem-" TYPE_X86_CPU,\ 229 .property = "level",\ 230 .value = stringify(2),\ 231 } 232 233 #define PC_COMPAT_1_4 \ 234 PC_COMPAT_1_5, \ 235 {\ 236 .driver = "scsi-hd",\ 237 .property = "discard_granularity",\ 238 .value = stringify(0),\ 239 },{\ 240 .driver = "scsi-cd",\ 241 .property = "discard_granularity",\ 242 .value = stringify(0),\ 243 },{\ 244 .driver = "scsi-disk",\ 245 .property = "discard_granularity",\ 246 .value = stringify(0),\ 247 },{\ 248 .driver = "ide-hd",\ 249 .property = "discard_granularity",\ 250 .value = stringify(0),\ 251 },{\ 252 .driver = "ide-cd",\ 253 .property = "discard_granularity",\ 254 .value = stringify(0),\ 255 },{\ 256 .driver = "ide-drive",\ 257 .property = "discard_granularity",\ 258 .value = stringify(0),\ 259 },{\ 260 .driver = "virtio-blk-pci",\ 261 .property = "discard_granularity",\ 262 .value = stringify(0),\ 263 },{\ 264 .driver = "virtio-serial-pci",\ 265 .property = "vectors",\ 266 /* DEV_NVECTORS_UNSPECIFIED as a uint32_t string */\ 267 .value = stringify(0xFFFFFFFF),\ 268 },{ \ 269 .driver = "virtio-net-pci", \ 270 .property = "ctrl_guest_offloads", \ 271 .value = "off", \ 272 },{\ 273 .driver = "e1000",\ 274 .property = "romfile",\ 275 .value = "pxe-e1000.rom",\ 276 },{\ 277 .driver = "ne2k_pci",\ 278 .property = "romfile",\ 279 .value = "pxe-ne2k_pci.rom",\ 280 },{\ 281 .driver = "pcnet",\ 282 .property = "romfile",\ 283 .value = "pxe-pcnet.rom",\ 284 },{\ 285 .driver = "rtl8139",\ 286 .property = "romfile",\ 287 .value = "pxe-rtl8139.rom",\ 288 },{\ 289 .driver = "virtio-net-pci",\ 290 .property = "romfile",\ 291 .value = "pxe-virtio.rom",\ 292 },{\ 293 .driver = "486-" TYPE_X86_CPU,\ 294 .property = "model",\ 295 .value = stringify(0),\ 296 } 297 298 #endif 299