boards.h 10.4 KB
Newer Older
P
pbrook 已提交
1 2 3 4 5
/* Declarations for use by board files for creating devices.  */

#ifndef HW_BOARDS_H
#define HW_BOARDS_H

6
#include "sysemu/blockdev.h"
7
#include "sysemu/accel.h"
8
#include "hw/qdev.h"
9
#include "qom/object.h"
10
#include "qom/cpu.h"
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
/**
 * memory_region_allocate_system_memory - Allocate a board's main memory
 * @mr: the #MemoryRegion to be initialized
 * @owner: the object that tracks the region's reference count
 * @name: name of the memory region
 * @ram_size: size of the region in bytes
 *
 * This function allocates the main memory for a board model, and
 * initializes @mr appropriately. It also arranges for the memory
 * to be migrated (by calling vmstate_register_ram_global()).
 *
 * Memory allocated via this function will be backed with the memory
 * backend the user provided using "-mem-path" or "-numa node,memdev=..."
 * if appropriate; this is typically used to cause host huge pages to be
 * used. This function should therefore be called by a board exactly once,
 * for the primary or largest RAM area it implements.
 *
 * For boards where the major RAM is split into two parts in the memory
 * map, you can deal with this by calling memory_region_allocate_system_memory()
 * once to get a MemoryRegion with enough RAM for both parts, and then
 * creating alias MemoryRegions via memory_region_init_alias() which
 * alias into different parts of the RAM MemoryRegion and can be mapped
 * into the memory map in the appropriate places.
 *
 * Smaller pieces of memory (display RAM, static RAMs, etc) don't need
 * to be backed via the -mem-path memory backend and can simply
38 39
 * be created via memory_region_allocate_aux_memory() or
 * memory_region_init_ram().
40
 */
41 42 43 44 45
void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
                                          const char *name,
                                          uint64_t ram_size);

#define TYPE_MACHINE_SUFFIX "-machine"
46 47 48 49 50 51

/* Machine class name that needs to be used for class-name-based machine
 * type lookup to work.
 */
#define MACHINE_TYPE_NAME(machinename) (machinename TYPE_MACHINE_SUFFIX)

52
#define TYPE_MACHINE "machine"
53
#undef MACHINE  /* BSD defines it and QEMU does not use it */
54 55 56 57 58 59 60
#define MACHINE(obj) \
    OBJECT_CHECK(MachineState, (obj), TYPE_MACHINE)
#define MACHINE_GET_CLASS(obj) \
    OBJECT_GET_CLASS(MachineClass, (obj), TYPE_MACHINE)
#define MACHINE_CLASS(klass) \
    OBJECT_CLASS_CHECK(MachineClass, (klass), TYPE_MACHINE)

61 62 63
MachineClass *find_default_machine(void);
extern MachineState *current_machine;

64
void machine_run_board_init(MachineState *machine);
65
bool machine_usb(MachineState *machine);
66 67
bool machine_kernel_irqchip_allowed(MachineState *machine);
bool machine_kernel_irqchip_required(MachineState *machine);
68
bool machine_kernel_irqchip_split(MachineState *machine);
69
int machine_kvm_shadow_mem(MachineState *machine);
70
int machine_phandle_start(MachineState *machine);
71
bool machine_dump_guest_core(MachineState *machine);
72
bool machine_mem_merge(MachineState *machine);
73
void machine_register_compat_props(MachineState *machine);
74
HotpluggableCPUList *machine_query_hotpluggable_cpus(MachineState *machine);
75 76 77
void machine_set_cpu_numa_node(MachineState *machine,
                               const CpuInstanceProperties *props,
                               Error **errp);
78

79 80 81 82
/**
 * CPUArchId:
 * @arch_id - architecture-dependent CPU ID of present or possible CPU
 * @cpu - pointer to corresponding CPU object if it's present on NULL otherwise
83
 * @props - CPU object properties, initialized by board
84
 * #vcpus_count - number of threads provided by @cpu object
85 86 87
 */
typedef struct {
    uint64_t arch_id;
88
    int64_t vcpus_count;
89
    CpuInstanceProperties props;
90
    Object *cpu;
91 92 93 94 95 96 97 98 99 100 101 102
} CPUArchId;

/**
 * CPUArchIdList:
 * @len - number of @CPUArchId items in @cpus array
 * @cpus - array of present or possible CPUs for current machine configuration
 */
typedef struct {
    int len;
    CPUArchId cpus[0];
} CPUArchIdList;

103 104
/**
 * MachineClass:
105 106 107 108 109
 * @get_hotplug_handler: this function is called during bus-less
 *    device hotplug. If defined it returns pointer to an instance
 *    of HotplugHandler object, which handles hotplug operation
 *    for a given @dev. It may return NULL if @dev doesn't require
 *    any actions to be performed by hotplug handler.
110 111 112 113
 * @cpu_index_to_instance_props:
 *    used to provide @cpu_index to socket/core/thread number mapping, allowing
 *    legacy code to perform maping from cpu_index to topology properties
 *    Returns: tuple of socket/core/thread ids given cpu_index belongs to.
114 115 116
 *    used to provide @cpu_index to socket number mapping, allowing
 *    a machine to group CPU threads belonging to the same socket/package
 *    Returns: socket number given cpu_index belongs to.
117 118 119 120 121
 * @hw_version:
 *    Value of QEMU_VERSION when the machine was added to QEMU.
 *    Set only by old machines because they need to keep
 *    compatibility on code that exposed QEMU_VERSION to guests in
 *    the past (and now use qemu_hw_version()).
122 123 124 125
 * @possible_cpu_arch_ids:
 *    Returns an array of @CPUArchId architecture-dependent CPU IDs
 *    which includes CPU IDs for present and possible to hotplug CPUs.
 *    Caller is responsible for freeing returned list.
126 127 128
 * @get_default_cpu_node_id:
 *    returns default board specific node_id value for CPU slot specified by
 *    index @idx in @ms->possible_cpus[]
129 130
 * @has_hotpluggable_cpus:
 *    If true, board supports CPUs creation with -device/device_add.
131 132 133 134
 * @default_cpu_type:
 *    specifies default CPU_TYPE, which will be used for parsing target
 *    specific features and for creating CPUs if CPU name wasn't provided
 *    explicitly at CLI
135 136 137 138 139 140
 * @minimum_page_bits:
 *    If non-zero, the board promises never to create a CPU with a page size
 *    smaller than this, so QEMU can use a more efficient larger page
 *    size than the target architecture's minimum. (Attempting to create
 *    such a CPU will fail.) Note that changing this is a migration
 *    compatibility break for the machine.
141 142 143 144 145 146 147 148 149 150
 * @ignore_memory_transaction_failures:
 *    If this is flag is true then the CPU will ignore memory transaction
 *    failures which should cause the CPU to take an exception due to an
 *    access to an unassigned physical address; the transaction will instead
 *    return zero (for a read) or be ignored (for a write). This should be
 *    set only by legacy board models which rely on the old RAZ/WI behaviour
 *    for handling devices that QEMU does not yet model. New board models
 *    should instead use "unimplemented-device" for all memory ranges where
 *    the guest will attempt to probe for a device that QEMU doesn't
 *    implement and a stub device is required.
151 152 153 154 155 156
 */
struct MachineClass {
    /*< private >*/
    ObjectClass parent_class;
    /*< public >*/

157
    const char *family; /* NULL iff @name identifies a standalone machtype */
158
    char *name;
159 160 161
    const char *alias;
    const char *desc;

162
    void (*init)(MachineState *state);
163 164 165 166 167
    void (*reset)(void);
    void (*hot_add_cpu)(const int64_t id, Error **errp);
    int (*kvm_type)(const char *arg);

    BlockInterfaceType block_default_type;
168
    int units_per_default_bus;
169 170 171 172 173 174 175
    int max_cpus;
    unsigned int no_serial:1,
        no_parallel:1,
        use_virtcon:1,
        use_sclp:1,
        no_floppy:1,
        no_cdrom:1,
176
        no_sdcard:1,
177
        has_dynamic_sysbus:1,
G
Gerd Hoffmann 已提交
178 179
        pci_allow_0_address:1,
        legacy_fw_cfg_order:1;
180 181 182
    int is_default;
    const char *default_machine_opts;
    const char *default_boot_order;
183
    const char *default_display;
184
    GArray *compat_props;
185
    const char *hw_version;
186
    ram_addr_t default_ram_size;
187
    const char *default_cpu_type;
188 189
    bool option_rom_has_mr;
    bool rom_file_has_mr;
190
    int minimum_page_bits;
191
    bool has_hotpluggable_cpus;
192
    bool ignore_memory_transaction_failures;
193
    int numa_mem_align_shift;
194
    const char **valid_cpu_types;
195 196
    void (*numa_auto_assign_ram)(MachineClass *mc, NodeInfo *nodes,
                                 int nb_nodes, ram_addr_t size);
197 198 199

    HotplugHandler *(*get_hotplug_handler)(MachineState *machine,
                                           DeviceState *dev);
200 201
    CpuInstanceProperties (*cpu_index_to_instance_props)(MachineState *machine,
                                                         unsigned cpu_index);
202
    const CPUArchIdList *(*possible_cpu_arch_ids)(MachineState *machine);
203
    int64_t (*get_default_cpu_node_id)(const MachineState *ms, int idx);
204 205 206 207 208 209 210 211
};

/**
 * MachineState:
 */
struct MachineState {
    /*< private >*/
    Object parent_obj;
212 213
    Notifier sysbus_notifier;

214 215 216
    /*< public >*/

    char *accel;
217 218
    bool kernel_irqchip_allowed;
    bool kernel_irqchip_required;
219
    bool kernel_irqchip_split;
220 221 222 223 224 225 226 227
    int kvm_shadow_mem;
    char *dtb;
    char *dumpdtb;
    int phandle_start;
    char *dt_compatible;
    bool dump_guest_core;
    bool mem_merge;
    bool usb;
228
    bool usb_disabled;
229
    bool igd_gfx_passthru;
230
    char *firmware;
231
    bool iommu;
232
    bool suppress_vmdesc;
233
    bool enforce_config_section;
234
    bool enable_graphics;
235

236
    ram_addr_t ram_size;
237 238
    ram_addr_t maxram_size;
    uint64_t   ram_slots;
239
    const char *boot_order;
240 241 242
    char *kernel_filename;
    char *kernel_cmdline;
    char *initrd_filename;
243
    const char *cpu_model;
244
    const char *cpu_type;
245
    AccelState *accelerator;
246
    CPUArchIdList *possible_cpus;
247 248
};

249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
#define DEFINE_MACHINE(namestr, machine_initfn) \
    static void machine_initfn##_class_init(ObjectClass *oc, void *data) \
    { \
        MachineClass *mc = MACHINE_CLASS(oc); \
        machine_initfn(mc); \
    } \
    static const TypeInfo machine_initfn##_typeinfo = { \
        .name       = MACHINE_TYPE_NAME(namestr), \
        .parent     = TYPE_MACHINE, \
        .class_init = machine_initfn##_class_init, \
    }; \
    static void machine_initfn##_register_types(void) \
    { \
        type_register_static(&machine_initfn##_typeinfo); \
    } \
264
    type_init(machine_initfn##_register_types)
265

266 267
#define SET_MACHINE_COMPAT(m, COMPAT) \
    do {                              \
268
        int i;                        \
269 270 271 272
        static GlobalProperty props[] = {       \
            COMPAT                              \
            { /* end of list */ }               \
        };                                      \
273 274 275 276 277 278 279
        if (!m->compat_props) { \
            m->compat_props = g_array_new(false, false, sizeof(void *)); \
        } \
        for (i = 0; props[i].driver != NULL; i++) {    \
            GlobalProperty *prop = &props[i];          \
            g_array_append_val(m->compat_props, prop); \
        }                                              \
280 281
    } while (0)

P
pbrook 已提交
282
#endif