aboutsummaryrefslogtreecommitdiff
path: root/include/hw/i386/pc.h
blob: a558705cb9af5efad00c074370e9185cad782b8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
#ifndef HW_PC_H
#define HW_PC_H

#include "qemu/notify.h"
#include "qapi/qapi-types-common.h"
#include "qemu/uuid.h"
#include "hw/boards.h"
#include "hw/block/fdc.h"
#include "hw/block/flash.h"
#include "hw/i386/x86.h"

#include "hw/hotplug.h"
#include "qom/object.h"
#include "hw/i386/sgx-epc.h"
#include "hw/cxl/cxl.h"

#define MAX_IDE_BUS 2

/**
 * PCMachineState:
 * @acpi_dev: link to ACPI PM device that performs ACPI hotplug handling
 * @boot_cpus: number of present VCPUs
 */
typedef struct PCMachineState {
    /*< private >*/
    X86MachineState parent_obj;

    /* <public> */

    /* State for other subsystems/APIs: */
    Notifier machine_done;

    /* Pointers to devices and objects: */
    PCIBus *pcibus;
    I2CBus *smbus;
    PFlashCFI01 *flash[2];
    ISADevice *pcspk;
    DeviceState *iommu;
    BusState *idebus[MAX_IDE_BUS];

    /* Configuration options: */
    uint64_t max_ram_below_4g;
    OnOffAuto vmport;
    SmbiosEntryPointType smbios_entry_point_type;
    const char *south_bridge;

    bool acpi_build_enabled;
    bool smbus_enabled;
    bool sata_enabled;
    bool hpet_enabled;
    bool i8042_enabled;
    bool default_bus_bypass_iommu;
    bool fd_bootchk;
    uint64_t max_fw_size;

    /* ACPI Memory hotplug IO base address */
    hwaddr memhp_io_base;

    SGXEPCState sgx_epc;
    CXLState cxl_devices_state;
} PCMachineState;

#define PC_MACHINE_ACPI_DEVICE_PROP "acpi-device"
#define PC_MACHINE_MAX_RAM_BELOW_4G "max-ram-below-4g"
#define PC_MACHINE_VMPORT           "vmport"
#define PC_MACHINE_SMBUS            "smbus"
#define PC_MACHINE_SATA             "sata"
#define PC_MACHINE_I8042            "i8042"
#define PC_MACHINE_MAX_FW_SIZE      "max-fw-size"
#define PC_MACHINE_SMBIOS_EP        "smbios-entry-point-type"

/**
 * PCMachineClass:
 *
 * Compat fields:
 *
 * @gigabyte_align: Make sure that guest addresses aligned at
 *                  1Gbyte boundaries get mapped to host
 *                  addresses aligned at 1Gbyte boundaries. This
 *                  way we can use 1GByte pages in the host.
 *
 */
struct PCMachineClass {
    /*< private >*/
    X86MachineClass parent_class;

    /*< public >*/

    /* Device configuration: */
    bool pci_enabled;
    const char *default_south_bridge;

    /* Compat options: */

    /* Default CPU model version.  See x86_cpu_set_default_version(). */
    int default_cpu_version;

    /* ACPI compat: */
    bool has_acpi_build;
    int pci_root_uid;

    /* SMBIOS compat: */
    bool smbios_defaults;
    bool smbios_legacy_mode;
    SmbiosEntryPointType default_smbios_ep_type;

    /* RAM / address space compat: */
    bool gigabyte_align;
    bool has_reserved_memory;
    bool broken_reserved_end;
    bool enforce_amd_1tb_hole;
    bool isa_bios_alias;

    /* generate legacy CPU hotplug AML */
    bool legacy_cpu_hotplug;

    /* use PVH to load kernels that support this feature */
    bool pvh_enabled;

    /* create kvmclock device even when KVM PV features are not exposed */
    bool kvmclock_create_always;

    /*
     * whether the machine type implements broken 32-bit address space bound
     * check for memory.
     */
    bool broken_32bit_mem_addr_check;
};

#define TYPE_PC_MACHINE "generic-pc-machine"
OBJECT_DECLARE_TYPE(PCMachineState, PCMachineClass, PC_MACHINE)

/* ioapic.c */

GSIState *pc_gsi_create(qemu_irq **irqs, bool pci_enabled);

/* pc.c */

void pc_acpi_smi_interrupt(void *opaque, int irq, int level);

#define PCI_HOST_PROP_RAM_MEM          "ram-mem"
#define PCI_HOST_PROP_PCI_MEM          "pci-mem"
#define PCI_HOST_PROP_SYSTEM_MEM       "system-mem"
#define PCI_HOST_PROP_IO_MEM           "io-mem"
#define PCI_HOST_PROP_PCI_HOLE_START   "pci-hole-start"
#define PCI_HOST_PROP_PCI_HOLE_END     "pci-hole-end"
#define PCI_HOST_PROP_PCI_HOLE64_START "pci-hole64-start"
#define PCI_HOST_PROP_PCI_HOLE64_END   "pci-hole64-end"
#define PCI_HOST_PROP_PCI_HOLE64_SIZE  "pci-hole64-size"
#define PCI_HOST_BELOW_4G_MEM_SIZE     "below-4g-mem-size"
#define PCI_HOST_ABOVE_4G_MEM_SIZE     "above-4g-mem-size"
#define PCI_HOST_PROP_SMM_RANGES       "smm-ranges"

typedef enum {
    SEV_DESC_TYPE_UNDEF,
    /* The section contains the region that must be validated by the VMM. */
    SEV_DESC_TYPE_SNP_SEC_MEM,
    /* The section contains the SNP secrets page */
    SEV_DESC_TYPE_SNP_SECRETS,
    /* The section contains address that can be used as a CPUID page */
    SEV_DESC_TYPE_CPUID,
    /* The section contains the region for kernel hashes for measured direct boot */
    SEV_DESC_TYPE_SNP_KERNEL_HASHES = 0x10,

} ovmf_sev_metadata_desc_type;

typedef struct __attribute__((__packed__)) OvmfSevMetadataDesc {
    uint32_t base;
    uint32_t len;
    ovmf_sev_metadata_desc_type type;
} OvmfSevMetadataDesc;

typedef struct __attribute__((__packed__)) OvmfSevMetadata {
    uint8_t signature[4];
    uint32_t len;
    uint32_t version;
    uint32_t num_desc;
    OvmfSevMetadataDesc descs[];
} OvmfSevMetadata;

OvmfSevMetadata *pc_system_get_ovmf_sev_metadata_ptr(void);

void pc_pci_as_mapping_init(MemoryRegion *system_memory,
                            MemoryRegion *pci_address_space);

void xen_load_linux(PCMachineState *pcms);
void pc_memory_init(PCMachineState *pcms,
                    MemoryRegion *system_memory,
                    MemoryRegion *rom_memory,
                    uint64_t pci_hole64_size);
uint64_t pc_pci_hole64_start(void);
DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus);
void pc_basic_device_init(struct PCMachineState *pcms,
                          ISABus *isa_bus, qemu_irq *gsi,
                          ISADevice *rtc_state,
                          bool create_fdctrl,
                          uint32_t hpet_irqs);
void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus);

void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs);

/* port92.c */
#define PORT92_A20_LINE "a20"

#define TYPE_PORT92 "port92"

/* pc_sysfw.c */
void pc_system_flash_create(PCMachineState *pcms);
void pc_system_flash_cleanup_unused(PCMachineState *pcms);
void pc_system_firmware_init(PCMachineState *pcms, MemoryRegion *rom_memory);
bool pc_system_ovmf_table_find(const char *entry, uint8_t **data,
                               int *data_len);
void pc_system_parse_ovmf_flash(uint8_t *flash_ptr, size_t flash_size);

/* sgx.c */
void pc_machine_init_sgx_epc(PCMachineState *pcms);

extern GlobalProperty pc_compat_9_2[];
extern const size_t pc_compat_9_2_len;

extern GlobalProperty pc_compat_9_1[];
extern const size_t pc_compat_9_1_len;

extern GlobalProperty pc_compat_9_0[];
extern const size_t pc_compat_9_0_len;

extern GlobalProperty pc_compat_8_2[];
extern const size_t pc_compat_8_2_len;

extern GlobalProperty pc_compat_8_1[];
extern const size_t pc_compat_8_1_len;

extern GlobalProperty pc_compat_8_0[];
extern const size_t pc_compat_8_0_len;

extern GlobalProperty pc_compat_7_2[];
extern const size_t pc_compat_7_2_len;

extern GlobalProperty pc_compat_7_1[];
extern const size_t pc_compat_7_1_len;

extern GlobalProperty pc_compat_7_0[];
extern const size_t pc_compat_7_0_len;

extern GlobalProperty pc_compat_6_2[];
extern const size_t pc_compat_6_2_len;

extern GlobalProperty pc_compat_6_1[];
extern const size_t pc_compat_6_1_len;

extern GlobalProperty pc_compat_6_0[];
extern const size_t pc_compat_6_0_len;

extern GlobalProperty pc_compat_5_2[];
extern const size_t pc_compat_5_2_len;

extern GlobalProperty pc_compat_5_1[];
extern const size_t pc_compat_5_1_len;

extern GlobalProperty pc_compat_5_0[];
extern const size_t pc_compat_5_0_len;

extern GlobalProperty pc_compat_4_2[];
extern const size_t pc_compat_4_2_len;

extern GlobalProperty pc_compat_4_1[];
extern const size_t pc_compat_4_1_len;

extern GlobalProperty pc_compat_4_0[];
extern const size_t pc_compat_4_0_len;

extern GlobalProperty pc_compat_3_1[];
extern const size_t pc_compat_3_1_len;

extern GlobalProperty pc_compat_3_0[];
extern const size_t pc_compat_3_0_len;

extern GlobalProperty pc_compat_2_12[];
extern const size_t pc_compat_2_12_len;

extern GlobalProperty pc_compat_2_11[];
extern const size_t pc_compat_2_11_len;

extern GlobalProperty pc_compat_2_10[];
extern const size_t pc_compat_2_10_len;

extern GlobalProperty pc_compat_2_9[];
extern const size_t pc_compat_2_9_len;

extern GlobalProperty pc_compat_2_8[];
extern const size_t pc_compat_2_8_len;

extern GlobalProperty pc_compat_2_7[];
extern const size_t pc_compat_2_7_len;

extern GlobalProperty pc_compat_2_6[];
extern const size_t pc_compat_2_6_len;

extern GlobalProperty pc_compat_2_5[];
extern const size_t pc_compat_2_5_len;

extern GlobalProperty pc_compat_2_4[];
extern const size_t pc_compat_2_4_len;

extern GlobalProperty pc_compat_2_3[];
extern const size_t pc_compat_2_3_len;

#define DEFINE_PC_MACHINE(suffix, namestr, initfn, optsfn) \
    static void pc_machine_##suffix##_class_init(ObjectClass *oc, void *data) \
    { \
        MachineClass *mc = MACHINE_CLASS(oc); \
        optsfn(mc); \
        mc->init = initfn; \
    } \
    static const TypeInfo pc_machine_type_##suffix = { \
        .name       = namestr TYPE_MACHINE_SUFFIX, \
        .parent     = TYPE_PC_MACHINE, \
        .class_init = pc_machine_##suffix##_class_init, \
    }; \
    static void pc_machine_init_##suffix(void) \
    { \
        type_register_static(&pc_machine_type_##suffix); \
    } \
    type_init(pc_machine_init_##suffix)

#define DEFINE_PC_VER_MACHINE(namesym, namestr, initfn, isdefault, malias, ...) \
    static void MACHINE_VER_SYM(init, namesym, __VA_ARGS__)( \
        MachineState *machine) \
    { \
        initfn(machine); \
    } \
    static void MACHINE_VER_SYM(class_init, namesym, __VA_ARGS__)( \
        ObjectClass *oc, \
        void *data) \
    { \
        MachineClass *mc = MACHINE_CLASS(oc); \
        MACHINE_VER_SYM(options, namesym, __VA_ARGS__)(mc); \
        mc->init = MACHINE_VER_SYM(init, namesym, __VA_ARGS__); \
        MACHINE_VER_DEPRECATION(__VA_ARGS__); \
        mc->is_default = isdefault; \
        mc->alias = malias; \
    } \
    static const TypeInfo MACHINE_VER_SYM(info, namesym, __VA_ARGS__) = \
    { \
        .name       = MACHINE_VER_TYPE_NAME(namestr, __VA_ARGS__), \
        .parent     = TYPE_PC_MACHINE, \
        .class_init = MACHINE_VER_SYM(class_init, namesym, __VA_ARGS__), \
    }; \
    static void MACHINE_VER_SYM(register, namesym, __VA_ARGS__)(void) \
    { \
        MACHINE_VER_DELETION(__VA_ARGS__); \
        type_register_static(&MACHINE_VER_SYM(info, namesym, __VA_ARGS__)); \
    } \
    type_init(MACHINE_VER_SYM(register, namesym, __VA_ARGS__));

#endif