unicorn/qemu/include/hw/boards.h

146 lines
5.0 KiB
C
Raw Normal View History

2015-08-21 09:04:50 +02:00
/* Declarations for use by board files for creating devices. */
#ifndef HW_BOARDS_H
#define HW_BOARDS_H
#include "qemu/typedefs.h"
#include "sysemu/accel.h"
#include "hw/qdev.h"
#include "qom/object.h"
#include "qom/cpu.h"
2015-08-21 09:04:50 +02:00
#include "uc_priv.h"
/**
* 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
* be created via memory_region_init_ram().
*/
2015-08-21 09:04:50 +02:00
void memory_region_allocate_system_memory(MemoryRegion *mr, Object *owner,
const char *name,
uint64_t ram_size);
#define TYPE_MACHINE_SUFFIX "-machine"
/* 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)
2015-08-21 09:04:50 +02:00
#define TYPE_MACHINE "machine"
#undef MACHINE /* BSD defines it and QEMU does not use it */
#define MACHINE(uc, obj) \
OBJECT_CHECK(uc, MachineState, (obj), TYPE_MACHINE)
#define MACHINE_GET_CLASS(uc, obj) \
OBJECT_GET_CLASS(uc, MachineClass, (obj), TYPE_MACHINE)
#define MACHINE_CLASS(uc, klass) \
OBJECT_CLASS_CHECK(uc, MachineClass, (klass), TYPE_MACHINE)
MachineClass *find_default_machine(struct uc_struct *uc, int arch);
/**
* MachineClass:
vl.c: convert cpu_model to cpu type and set of global properties before machine_init() All machines that support user specified cpu_model either call cpu_generic_init() or cpu_class_by_name()/CPUClass::parse_features to parse feature string and to get CPU type to create. Which leads to code duplication and hard-codding default CPU model within machine_foo_init() code. Which makes it impossible to get CPU type before machine_init() is run. So instead of setting default CPUs models and doing parsing in target specific machine_foo_init() in various ways, provide a generic data driven cpu_model parsing before machine_init() is called. in follow up per target patches, it will allow to: * define default CPU type in consistent/generic manner per machine type and drop custom code that fallbacks to default if cpu_model is NULL * drop custom features parsing in targets and do it in centralized way. * for cases of cpu_generic_init(TYPE_BASE/DEFAULT_CPU, "some_cpu") replace it with cpu_create(machine->cpu_type) || cpu_create(TYPE_FOO) depending if CPU type is user settable or not. not doing useless parsing and clearly documenting where CPU model is user settable or fixed one. Patch allows machine subclasses to define default CPU type per machine class at class_init() time and if that is set generic code will parse cpu_model into a MachineState::cpu_type which will be used to create CPUs for that machine instance and allows gradual per board conversion. Backports commit 6063d4c0f98b35a27ca018393d328a1825412a7e from qemu
2018-03-20 18:12:37 +01:00
* @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
* @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.
* @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.
2015-08-21 09:04:50 +02:00
*/
struct MachineClass {
/*< private >*/
ObjectClass parent_class;
/*< public >*/
char *name;
2015-08-21 09:04:50 +02:00
int (*init)(struct uc_struct *uc, MachineState *state);
2015-08-21 09:04:50 +02:00
void (*reset)(void);
int max_cpus;
int is_default;
vl.c: convert cpu_model to cpu type and set of global properties before machine_init() All machines that support user specified cpu_model either call cpu_generic_init() or cpu_class_by_name()/CPUClass::parse_features to parse feature string and to get CPU type to create. Which leads to code duplication and hard-codding default CPU model within machine_foo_init() code. Which makes it impossible to get CPU type before machine_init() is run. So instead of setting default CPUs models and doing parsing in target specific machine_foo_init() in various ways, provide a generic data driven cpu_model parsing before machine_init() is called. in follow up per target patches, it will allow to: * define default CPU type in consistent/generic manner per machine type and drop custom code that fallbacks to default if cpu_model is NULL * drop custom features parsing in targets and do it in centralized way. * for cases of cpu_generic_init(TYPE_BASE/DEFAULT_CPU, "some_cpu") replace it with cpu_create(machine->cpu_type) || cpu_create(TYPE_FOO) depending if CPU type is user settable or not. not doing useless parsing and clearly documenting where CPU model is user settable or fixed one. Patch allows machine subclasses to define default CPU type per machine class at class_init() time and if that is set generic code will parse cpu_model into a MachineState::cpu_type which will be used to create CPUs for that machine instance and allows gradual per board conversion. Backports commit 6063d4c0f98b35a27ca018393d328a1825412a7e from qemu
2018-03-20 18:12:37 +01:00
const char *default_cpu_type;
2015-08-21 09:04:50 +02:00
int arch;
int minimum_page_bits;
bool has_hotpluggable_cpus;
bool ignore_memory_transaction_failures;
2015-08-21 09:04:50 +02:00
};
/**
* MachineState:
*/
struct MachineState {
/*< private >*/
Object parent_obj;
/*< public >*/
ram_addr_t ram_size;
ram_addr_t maxram_size;
vl.c: convert cpu_model to cpu type and set of global properties before machine_init() All machines that support user specified cpu_model either call cpu_generic_init() or cpu_class_by_name()/CPUClass::parse_features to parse feature string and to get CPU type to create. Which leads to code duplication and hard-codding default CPU model within machine_foo_init() code. Which makes it impossible to get CPU type before machine_init() is run. So instead of setting default CPUs models and doing parsing in target specific machine_foo_init() in various ways, provide a generic data driven cpu_model parsing before machine_init() is called. in follow up per target patches, it will allow to: * define default CPU type in consistent/generic manner per machine type and drop custom code that fallbacks to default if cpu_model is NULL * drop custom features parsing in targets and do it in centralized way. * for cases of cpu_generic_init(TYPE_BASE/DEFAULT_CPU, "some_cpu") replace it with cpu_create(machine->cpu_type) || cpu_create(TYPE_FOO) depending if CPU type is user settable or not. not doing useless parsing and clearly documenting where CPU model is user settable or fixed one. Patch allows machine subclasses to define default CPU type per machine class at class_init() time and if that is set generic code will parse cpu_model into a MachineState::cpu_type which will be used to create CPUs for that machine instance and allows gradual per board conversion. Backports commit 6063d4c0f98b35a27ca018393d328a1825412a7e from qemu
2018-03-20 18:12:37 +01:00
const char *cpu_type;
2015-08-21 09:04:50 +02:00
struct uc_struct *uc;
AccelState *accelerator;
};
#define DEFINE_MACHINE(namestr, machine_initfn) \
static void machine_initfn##_class_init(struct uc_struct *uc, ObjectClass *oc, void *data) \
{ \
MachineClass *mc = MACHINE_CLASS(uc, oc); \
machine_initfn(uc, mc); \
} \
static const TypeInfo machine_initfn##_typeinfo = { \
MACHINE_TYPE_NAME(namestr), \
TYPE_MACHINE, \
0, \
0, \
NULL, \
NULL, \
NULL, \
NULL, \
NULL, \
machine_initfn##_class_init, \
}; \
void machine_initfn##_register_types(struct uc_struct *uc) \
{ \
type_register_static(uc, &machine_initfn##_typeinfo); \
}
2015-08-21 09:04:50 +02:00
void machine_register_types(struct uc_struct *uc);
#endif