This adds isa bindings for the variable service. Usage: qemu-system-x86_64 -device uefi-vars-isa,jsonfile=/path/to/uefivars.json
Signed-off-by: Gerd Hoffmann <kra...@redhat.com> --- hw/uefi/var-service-isa.c | 88 +++++++++++++++++++++++++++++++++++++++ hw/uefi/Kconfig | 6 +++ hw/uefi/meson.build | 5 +++ 3 files changed, 99 insertions(+) create mode 100644 hw/uefi/var-service-isa.c diff --git a/hw/uefi/var-service-isa.c b/hw/uefi/var-service-isa.c new file mode 100644 index 000000000000..bdb270c2a643 --- /dev/null +++ b/hw/uefi/var-service-isa.c @@ -0,0 +1,88 @@ +/* + * SPDX-License-Identifier: GPL-2.0-or-later + * + * uefi vars device - ISA variant for x64. + */ +#include "qemu/osdep.h" +#include "migration/vmstate.h" + +#include "hw/isa/isa.h" +#include "hw/qdev-properties.h" + +#include "hw/uefi/var-service.h" +#include "hw/uefi/var-service-api.h" + +#define TYPE_UEFI_VARS_ISA "uefi-vars-isa" +OBJECT_DECLARE_SIMPLE_TYPE(uefi_vars_isa_state, UEFI_VARS_ISA) + +struct uefi_vars_isa_state { + ISADevice parent_obj; + struct uefi_vars_state state; +}; + +static const VMStateDescription vmstate_uefi_vars_isa = { + .name = "uefi-vars-isa", + .fields = (VMStateField[]) { + VMSTATE_STRUCT(state, uefi_vars_isa_state, 0, + vmstate_uefi_vars, uefi_vars_state), + VMSTATE_END_OF_LIST() + } +}; + +static Property uefi_vars_isa_properties[] = { + DEFINE_PROP_SIZE("size", uefi_vars_isa_state, state.max_storage, + 256 * 1024), + DEFINE_PROP_STRING("jsonfile", uefi_vars_isa_state, state.jsonfile), + DEFINE_PROP_END_OF_LIST(), +}; + +static void uefi_vars_isa_init(Object *obj) +{ + uefi_vars_isa_state *uv = UEFI_VARS_ISA(obj); + + uefi_vars_init(obj, &uv->state); +} + +static void uefi_vars_isa_reset(DeviceState *dev) +{ + uefi_vars_isa_state *uv = UEFI_VARS_ISA(dev); + + uefi_vars_hard_reset(&uv->state); +} + +static void uefi_vars_isa_realize(DeviceState *dev, Error **errp) +{ + uefi_vars_isa_state *uv = UEFI_VARS_ISA(dev); + ISADevice *isa = ISA_DEVICE(dev); + + isa_register_ioport(isa, &uv->state.mr, UEFI_VARS_IO_BASE); + uefi_vars_realize(&uv->state, errp); +} + +static void uefi_vars_isa_class_init(ObjectClass *klass, void *data) +{ + DeviceClass *dc = DEVICE_CLASS(klass); + + dc->realize = uefi_vars_isa_realize; + dc->reset = uefi_vars_isa_reset; + dc->vmsd = &vmstate_uefi_vars_isa; + device_class_set_props(dc, uefi_vars_isa_properties); + set_bit(DEVICE_CATEGORY_MISC, dc->categories); +} + +static const TypeInfo uefi_vars_isa_info = { + .name = TYPE_UEFI_VARS_ISA, + .parent = TYPE_ISA_DEVICE, + .instance_size = sizeof(uefi_vars_isa_state), + .instance_init = uefi_vars_isa_init, + .class_init = uefi_vars_isa_class_init, +}; +module_obj(TYPE_UEFI_VARS_ISA); +module_dep("hw-uefi-vars"); + +static void uefi_vars_isa_register_types(void) +{ + type_register_static(&uefi_vars_isa_info); +} + +type_init(uefi_vars_isa_register_types) diff --git a/hw/uefi/Kconfig b/hw/uefi/Kconfig index ca6c2bc46a96..feb9f6de5e30 100644 --- a/hw/uefi/Kconfig +++ b/hw/uefi/Kconfig @@ -1,3 +1,9 @@ config UEFI_VARS bool default y if X86_64 || AARCH64 + +config UEFI_VARS_ISA + bool + default y + depends on UEFI_VARS + depends on ISA_BUS diff --git a/hw/uefi/meson.build b/hw/uefi/meson.build index dc363d67cccc..959d2a630bbf 100644 --- a/hw/uefi/meson.build +++ b/hw/uefi/meson.build @@ -8,6 +8,11 @@ uefi_vars_ss.add(when: 'CONFIG_UEFI_VARS', 'var-service-policy.c', 'var-service-sysbus.c')) +uefi_vars_isa_ss = ss.source_set() +uefi_vars_isa_ss.add(when: 'CONFIG_UEFI_VARS_ISA', + if_true: files('var-service-isa.c')) + modules += { 'hw-uefi' : { 'vars' : uefi_vars_ss, + 'vars-isa' : uefi_vars_isa_ss, }} -- 2.41.0