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