hw/nvram/fw_cfg: Remove legacy FW_CFG_ORDER_OVERRIDE

The MachineClass::legacy_fw_cfg_order boolean was only used
by the pc-q35-2.5 and pc-i440fx-2.5 machines, which got
removed. Remove it along with:

- FW_CFG_ORDER_OVERRIDE_* definitions
- fw_cfg_set_order_override()
- fw_cfg_reset_order_override()
- fw_cfg_order[]
- rom_set_order_override()
- rom_reset_order_override()

Simplify CLI and pc_vga_init() / pc_nic_init().

Signed-off-by: Philippe Mathieu-Daudé <philmd@linaro.org>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Reviewed-by: Xiaoyao Li <xiaoyao.li@intel.com>
Message-ID: <20250512083948.39294-12-philmd@linaro.org>
[thuth: Fix error from check_patch.pl wrt to an empty "for" loop]
Signed-off-by: Thomas Huth <thuth@redhat.com>
This commit is contained in:
Philippe Mathieu-Daudé 2025-05-12 10:39:40 +02:00 committed by Thomas Huth
parent 42cbccfcb0
commit 6160ce2084
7 changed files with 10 additions and 141 deletions

View file

@ -1333,20 +1333,6 @@ void rom_set_fw(FWCfgState *f)
fw_cfg = f; fw_cfg = f;
} }
void rom_set_order_override(int order)
{
if (!fw_cfg)
return;
fw_cfg_set_order_override(fw_cfg, order);
}
void rom_reset_order_override(void)
{
if (!fw_cfg)
return;
fw_cfg_reset_order_override(fw_cfg);
}
void rom_transaction_begin(void) void rom_transaction_begin(void)
{ {
Rom *rom; Rom *rom;

View file

@ -1033,7 +1033,6 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
{ {
DeviceState *dev = NULL; DeviceState *dev = NULL;
rom_set_order_override(FW_CFG_ORDER_OVERRIDE_VGA);
if (pci_bus) { if (pci_bus) {
PCIDevice *pcidev = pci_vga_init(pci_bus); PCIDevice *pcidev = pci_vga_init(pci_bus);
dev = pcidev ? &pcidev->qdev : NULL; dev = pcidev ? &pcidev->qdev : NULL;
@ -1041,7 +1040,7 @@ DeviceState *pc_vga_init(ISABus *isa_bus, PCIBus *pci_bus)
ISADevice *isadev = isa_vga_init(isa_bus); ISADevice *isadev = isa_vga_init(isa_bus);
dev = isadev ? DEVICE(isadev) : NULL; dev = isadev ? DEVICE(isadev) : NULL;
} }
rom_reset_order_override();
return dev; return dev;
} }
@ -1231,8 +1230,6 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
bool default_is_ne2k = g_str_equal(mc->default_nic, TYPE_ISA_NE2000); bool default_is_ne2k = g_str_equal(mc->default_nic, TYPE_ISA_NE2000);
NICInfo *nd; NICInfo *nd;
rom_set_order_override(FW_CFG_ORDER_OVERRIDE_NIC);
while ((nd = qemu_find_nic_info(TYPE_ISA_NE2000, default_is_ne2k, NULL))) { while ((nd = qemu_find_nic_info(TYPE_ISA_NE2000, default_is_ne2k, NULL))) {
pc_init_ne2k_isa(isa_bus, nd, &error_fatal); pc_init_ne2k_isa(isa_bus, nd, &error_fatal);
} }
@ -1241,8 +1238,6 @@ void pc_nic_init(PCMachineClass *pcmc, ISABus *isa_bus, PCIBus *pci_bus)
if (pci_bus) { if (pci_bus) {
pci_init_nic_devices(pci_bus, mc->default_nic); pci_init_nic_devices(pci_bus, mc->default_nic);
} }
rom_reset_order_override();
} }
void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs) void pc_i8259_create(ISABus *isa_bus, qemu_irq *i8259_irqs)

View file

@ -817,62 +817,6 @@ void fw_cfg_modify_i64(FWCfgState *s, uint16_t key, uint64_t value)
g_free(old); g_free(old);
} }
void fw_cfg_set_order_override(FWCfgState *s, int order)
{
assert(s->fw_cfg_order_override == 0);
s->fw_cfg_order_override = order;
}
void fw_cfg_reset_order_override(FWCfgState *s)
{
assert(s->fw_cfg_order_override != 0);
s->fw_cfg_order_override = 0;
}
/*
* This is the legacy order list. For legacy systems, files are in
* the fw_cfg in the order defined below, by the "order" value. Note
* that some entries (VGA ROMs, NIC option ROMS, etc.) go into a
* specific area, but there may be more than one and they occur in the
* order that the user specifies them on the command line. Those are
* handled in a special manner, using the order override above.
*
* For non-legacy, the files are sorted by filename to avoid this kind
* of complexity in the future.
*
* This is only for x86, other arches don't implement versioning so
* they won't set legacy mode.
*/
static struct {
const char *name;
int order;
} fw_cfg_order[] = {
{ "etc/boot-menu-wait", 10 },
{ "bootsplash.jpg", 11 },
{ "bootsplash.bmp", 12 },
{ "etc/boot-fail-wait", 15 },
{ "etc/smbios/smbios-tables", 20 },
{ "etc/smbios/smbios-anchor", 30 },
{ "etc/e820", 40 },
{ "etc/reserved-memory-end", 50 },
{ "genroms/kvmvapic.bin", 55 },
{ "genroms/linuxboot.bin", 60 },
{ }, /* VGA ROMs from pc_vga_init come here, 70. */
{ }, /* NIC option ROMs from pc_nic_init come here, 80. */
{ "etc/system-states", 90 },
{ }, /* User ROMs come here, 100. */
{ }, /* Device FW comes here, 110. */
{ "etc/extra-pci-roots", 120 },
{ "etc/acpi/tables", 130 },
{ "etc/table-loader", 140 },
{ "etc/tpm/log", 150 },
{ "etc/acpi/rsdp", 160 },
{ "bootorder", 170 },
{ "etc/msr_feature_control", 180 },
#define FW_CFG_ORDER_OVERRIDE_LAST 200
};
/* /*
* Any sub-page size update to these table MRs will be lost during migration, * Any sub-page size update to these table MRs will be lost during migration,
* as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path. * as we use aligned size in ram_load_precopy() -> qemu_ram_resize() path.
@ -890,29 +834,6 @@ static void fw_cfg_acpi_mr_save(FWCfgState *s, const char *filename, size_t len)
} }
} }
static int get_fw_cfg_order(FWCfgState *s, const char *name)
{
int i;
if (s->fw_cfg_order_override > 0) {
return s->fw_cfg_order_override;
}
for (i = 0; i < ARRAY_SIZE(fw_cfg_order); i++) {
if (fw_cfg_order[i].name == NULL) {
continue;
}
if (strcmp(name, fw_cfg_order[i].name) == 0) {
return fw_cfg_order[i].order;
}
}
/* Stick unknown stuff at the end. */
warn_report("Unknown firmware file in legacy mode: %s", name);
return FW_CFG_ORDER_OVERRIDE_LAST;
}
void fw_cfg_add_file_callback(FWCfgState *s, const char *filename, void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
FWCfgCallback select_cb, FWCfgCallback select_cb,
FWCfgWriteCallback write_cb, FWCfgWriteCallback write_cb,
@ -921,7 +842,6 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
{ {
int i, index, count; int i, index, count;
size_t dsize; size_t dsize;
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
int order = 0; int order = 0;
if (!s->files) { if (!s->files) {
@ -933,22 +853,11 @@ void fw_cfg_add_file_callback(FWCfgState *s, const char *filename,
count = be32_to_cpu(s->files->count); count = be32_to_cpu(s->files->count);
assert(count < fw_cfg_file_slots(s)); assert(count < fw_cfg_file_slots(s));
/* Find the insertion point. */ /* Find the insertion point, sorting by file name. */
if (mc->legacy_fw_cfg_order) { for (index = count;
/* index > 0 && strcmp(filename, s->files->f[index - 1].name) < 0;
* Sort by order. For files with the same order, we keep them index--)
* in the sequence in which they were added. ;
*/
order = get_fw_cfg_order(s, filename);
for (index = count;
index > 0 && order < s->entry_order[index - 1];
index--);
} else {
/* Sort by file name. */
for (index = count;
index > 0 && strcmp(filename, s->files->f[index - 1].name) < 0;
index--);
}
/* /*
* Move all the entries from the index point and after down one * Move all the entries from the index point and after down one
@ -1058,7 +967,6 @@ bool fw_cfg_add_file_from_generator(FWCfgState *s,
static void fw_cfg_machine_reset(void *opaque) static void fw_cfg_machine_reset(void *opaque)
{ {
MachineClass *mc = MACHINE_GET_CLASS(qdev_get_machine());
FWCfgState *s = opaque; FWCfgState *s = opaque;
void *ptr; void *ptr;
size_t len; size_t len;
@ -1068,11 +976,9 @@ static void fw_cfg_machine_reset(void *opaque)
ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)buf, len); ptr = fw_cfg_modify_file(s, "bootorder", (uint8_t *)buf, len);
g_free(ptr); g_free(ptr);
if (!mc->legacy_fw_cfg_order) { buf = get_boot_devices_lchs_list(&len);
buf = get_boot_devices_lchs_list(&len); ptr = fw_cfg_modify_file(s, "bios-geometry", (uint8_t *)buf, len);
ptr = fw_cfg_modify_file(s, "bios-geometry", (uint8_t *)buf, len); g_free(ptr);
g_free(ptr);
}
} }
static void fw_cfg_machine_ready(struct Notifier *n, void *data) static void fw_cfg_machine_ready(struct Notifier *n, void *data)

View file

@ -286,8 +286,7 @@ struct MachineClass {
no_parallel:1, no_parallel:1,
no_floppy:1, no_floppy:1,
no_cdrom:1, no_cdrom:1,
pci_allow_0_address:1, pci_allow_0_address:1;
legacy_fw_cfg_order:1;
bool auto_create_sdcard; bool auto_create_sdcard;
bool is_default; bool is_default;
const char *default_machine_opts; const char *default_machine_opts;

View file

@ -270,8 +270,6 @@ int rom_add_elf_program(const char *name, GMappedFile *mapped_file, void *data,
AddressSpace *as); AddressSpace *as);
int rom_check_and_register_reset(void); int rom_check_and_register_reset(void);
void rom_set_fw(FWCfgState *f); void rom_set_fw(FWCfgState *f);
void rom_set_order_override(int order);
void rom_reset_order_override(void);
/** /**
* rom_transaction_begin: * rom_transaction_begin:

View file

@ -42,14 +42,6 @@ struct FWCfgDataGeneratorClass {
typedef struct fw_cfg_file FWCfgFile; typedef struct fw_cfg_file FWCfgFile;
#define FW_CFG_ORDER_OVERRIDE_VGA 70
#define FW_CFG_ORDER_OVERRIDE_NIC 80
#define FW_CFG_ORDER_OVERRIDE_USER 100
#define FW_CFG_ORDER_OVERRIDE_DEVICE 110
void fw_cfg_set_order_override(FWCfgState *fw_cfg, int order);
void fw_cfg_reset_order_override(FWCfgState *fw_cfg);
typedef struct FWCfgFiles { typedef struct FWCfgFiles {
uint32_t count; uint32_t count;
FWCfgFile f[]; FWCfgFile f[];
@ -75,8 +67,6 @@ struct FWCfgState {
uint32_t cur_offset; uint32_t cur_offset;
Notifier machine_ready; Notifier machine_ready;
int fw_cfg_order_override;
bool dma_enabled; bool dma_enabled;
dma_addr_t dma_addr; dma_addr_t dma_addr;
AddressSpace *dma_as; AddressSpace *dma_as;

View file

@ -1192,10 +1192,7 @@ static int parse_fw_cfg(void *opaque, QemuOpts *opts, Error **errp)
return -1; return -1;
} }
} }
/* For legacy, keep user files in a specific global order. */
fw_cfg_set_order_override(fw_cfg, FW_CFG_ORDER_OVERRIDE_USER);
fw_cfg_add_file(fw_cfg, name, buf, size); fw_cfg_add_file(fw_cfg, name, buf, size);
fw_cfg_reset_order_override(fw_cfg);
return 0; return 0;
} }
@ -2745,7 +2742,6 @@ static void qemu_create_cli_devices(void)
} }
/* init generic devices */ /* init generic devices */
rom_set_order_override(FW_CFG_ORDER_OVERRIDE_DEVICE);
qemu_opts_foreach(qemu_find_opts("device"), qemu_opts_foreach(qemu_find_opts("device"),
device_init_func, NULL, &error_fatal); device_init_func, NULL, &error_fatal);
QTAILQ_FOREACH(opt, &device_opts, next) { QTAILQ_FOREACH(opt, &device_opts, next) {
@ -2756,7 +2752,6 @@ static void qemu_create_cli_devices(void)
assert(ret_data == NULL); /* error_fatal aborts */ assert(ret_data == NULL); /* error_fatal aborts */
loc_pop(&opt->loc); loc_pop(&opt->loc);
} }
rom_reset_order_override();
} }
static bool qemu_machine_creation_done(Error **errp) static bool qemu_machine_creation_done(Error **errp)