2015-07-15 08:37:44 +03:00
|
|
|
/*
|
|
|
|
* This is splited from hw/i386/kvm/pci-assign.c
|
|
|
|
*/
|
2016-01-26 21:17:03 +03:00
|
|
|
#include "qemu/osdep.h"
|
include/qemu/osdep.h: Don't include qapi/error.h
Commit 57cb38b included qapi/error.h into qemu/osdep.h to get the
Error typedef. Since then, we've moved to include qemu/osdep.h
everywhere. Its file comment explains: "To avoid getting into
possible circular include dependencies, this file should not include
any other QEMU headers, with the exceptions of config-host.h,
compiler.h, os-posix.h and os-win32.h, all of which are doing a
similar job to this file and are under similar constraints."
qapi/error.h doesn't do a similar job, and it doesn't adhere to
similar constraints: it includes qapi-types.h. That's in excess of
100KiB of crap most .c files don't actually need.
Add the typedef to qemu/typedefs.h, and include that instead of
qapi/error.h. Include qapi/error.h in .c files that need it and don't
get it now. Include qapi-types.h in qom/object.h for uint16List.
Update scripts/clean-includes accordingly. Update it further to match
reality: replace config.h by config-target.h, add sysemu/os-posix.h,
sysemu/os-win32.h. Update the list of includes in the qemu/osdep.h
comment quoted above similarly.
This reduces the number of objects depending on qapi/error.h from "all
of them" to less than a third. Unfortunately, the number depending on
qapi-types.h shrinks only a little. More work is needed for that one.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
[Fix compilation without the spice devel packages. - Paolo]
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
2016-03-14 11:01:28 +03:00
|
|
|
#include "qapi/error.h"
|
2015-07-15 08:37:44 +03:00
|
|
|
#include "qemu/error-report.h"
|
|
|
|
#include "hw/loader.h"
|
|
|
|
#include "hw/pci/pci.h"
|
2017-10-20 11:17:50 +03:00
|
|
|
#include "xen_pt.h"
|
2015-07-15 08:37:44 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Scan the assigned devices for the devices that have an option ROM, and then
|
|
|
|
* load the corresponding ROM data to RAM. If an error occurs while loading an
|
|
|
|
* option ROM, we just ignore that option ROM and continue with the next one.
|
|
|
|
*/
|
2018-06-22 15:28:42 +03:00
|
|
|
void *pci_assign_dev_load_option_rom(PCIDevice *dev,
|
2015-07-15 08:37:44 +03:00
|
|
|
int *size, unsigned int domain,
|
|
|
|
unsigned int bus, unsigned int slot,
|
|
|
|
unsigned int function)
|
|
|
|
{
|
|
|
|
char name[32], rom_file[64];
|
|
|
|
FILE *fp;
|
|
|
|
uint8_t val;
|
|
|
|
struct stat st;
|
|
|
|
void *ptr = NULL;
|
2018-06-22 15:28:42 +03:00
|
|
|
Object *owner = OBJECT(dev);
|
2015-07-15 08:37:44 +03:00
|
|
|
|
|
|
|
/* If loading ROM from file, pci handles it */
|
|
|
|
if (dev->romfile || !dev->rom_bar) {
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
snprintf(rom_file, sizeof(rom_file),
|
|
|
|
"/sys/bus/pci/devices/%04x:%02x:%02x.%01x/rom",
|
|
|
|
domain, bus, slot, function);
|
|
|
|
|
|
|
|
/* Write "1" to the ROM file to enable it */
|
|
|
|
fp = fopen(rom_file, "r+");
|
|
|
|
if (fp == NULL) {
|
2017-01-04 18:05:25 +03:00
|
|
|
if (errno != ENOENT) {
|
|
|
|
error_report("pci-assign: Cannot open %s: %s", rom_file, strerror(errno));
|
|
|
|
}
|
2015-07-15 08:37:44 +03:00
|
|
|
return NULL;
|
|
|
|
}
|
2017-01-04 18:05:25 +03:00
|
|
|
if (fstat(fileno(fp), &st) == -1) {
|
|
|
|
error_report("pci-assign: Cannot stat %s: %s", rom_file, strerror(errno));
|
|
|
|
goto close_rom;
|
|
|
|
}
|
|
|
|
|
2015-07-15 08:37:44 +03:00
|
|
|
val = 1;
|
|
|
|
if (fwrite(&val, 1, 1, fp) != 1) {
|
|
|
|
goto close_rom;
|
|
|
|
}
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
|
2024-06-27 09:07:59 +03:00
|
|
|
if (dev->romsize != UINT_MAX) {
|
2021-02-03 16:18:28 +03:00
|
|
|
if (st.st_size > dev->romsize) {
|
|
|
|
error_report("ROM BAR \"%s\" (%ld bytes) is too large for ROM size %u",
|
|
|
|
rom_file, (long) st.st_size, dev->romsize);
|
|
|
|
goto close_rom;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dev->romsize = st.st_size;
|
|
|
|
}
|
|
|
|
|
2015-07-15 08:37:44 +03:00
|
|
|
snprintf(name, sizeof(name), "%s.rom", object_get_typename(owner));
|
2021-02-03 16:18:28 +03:00
|
|
|
memory_region_init_ram(&dev->rom, owner, name, dev->romsize, &error_abort);
|
2015-07-15 08:37:44 +03:00
|
|
|
ptr = memory_region_get_ram_ptr(&dev->rom);
|
2021-02-03 16:18:28 +03:00
|
|
|
memset(ptr, 0xff, dev->romsize);
|
2015-07-15 08:37:44 +03:00
|
|
|
|
|
|
|
if (!fread(ptr, 1, st.st_size, fp)) {
|
|
|
|
error_report("pci-assign: Cannot read from host %s", rom_file);
|
|
|
|
error_printf("Device option ROM contents are probably invalid "
|
|
|
|
"(check dmesg).\nSkip option ROM probe with rombar=0, "
|
|
|
|
"or load from file with romfile=\n");
|
|
|
|
goto close_rom;
|
|
|
|
}
|
|
|
|
|
|
|
|
pci_register_bar(dev, PCI_ROM_SLOT, 0, &dev->rom);
|
|
|
|
dev->has_rom = true;
|
|
|
|
*size = st.st_size;
|
|
|
|
close_rom:
|
|
|
|
/* Write "0" to disable ROM */
|
|
|
|
fseek(fp, 0, SEEK_SET);
|
|
|
|
val = 0;
|
|
|
|
if (!fwrite(&val, 1, 1, fp)) {
|
2017-10-20 11:17:50 +03:00
|
|
|
XEN_PT_WARN(dev, "%s\n", "Failed to disable pci-sysfs rom file");
|
2015-07-15 08:37:44 +03:00
|
|
|
}
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return ptr;
|
|
|
|
}
|