pci, pc, virtio fixes and cleanups

A bunch of fixes all over the place.  Also, beginning to generalize acpi build
 code for reuse by ARM.
 
 Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
 -----BEGIN PGP SIGNATURE-----
 Version: GnuPG v1
 
 iQEcBAABAgAGBQJUx465AAoJECgfDbjSjVRpzewIAI/tzV1oCR1D/YDYBYpiK68W
 85JJbyR90DpS9unjrkeUHEnJgkegCk8dMXlWJOlshpwxDw2khC2ol0yS6siwC6Z/
 1peL9E5zHz2H8KWfH6JlhqLETovZxjd5Uv3q1mWULvK+zZcPzeQDCky5I8mbEw4b
 0LGDGX8mcLlDnit9mnAbgHu7cbqGa0jtXoJTFveKdxQtHdyj4cAg0wCjOLhnEo6s
 fJP7K1TJ2Ptiwwlk2cnj8T4Z9AoJkWjpFfr94dST2KqR3z5j8OUZYYhifrZa3e8t
 qxO/UatY4IwSnsmWCn/hvzlHZFa03sc9nPIkAlj96j78sHqPafDJxCdnwlX8pF8=
 =Kfwr
 -----END PGP SIGNATURE-----

Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging

pci, pc, virtio fixes and cleanups

A bunch of fixes all over the place.  Also, beginning to generalize acpi build
code for reuse by ARM.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>

# gpg: Signature made Tue 27 Jan 2015 13:12:25 GMT using RSA key ID D28D5469
# gpg: Good signature from "Michael S. Tsirkin <mst@kernel.org>"
# gpg:                 aka "Michael S. Tsirkin <mst@redhat.com>"

* remotes/mst/tags/for_upstream:
  pc-dimm: Add Error argument to pc_existing_dimms_capacity
  pc-dimm: Make pc_existing_dimms_capacity global
  pc: Fix DIMMs capacity calculation
  smbios: Don't report unknown CPU speed (fix SVVP regression)
  smbios: Fix dimm size calculation when RAM is multiple of 16GB
  bios-linker-loader: move source to common location
  bios-linker-loader: move header to common location
  virtio: fix feature bit checks
  bios-tables-test: split piix4 and q35 tests
  acpi: build_append_nameseg(): add padding if necessary
  acpi: update generated hex files
  acpi-test: update expected DSDT
  pc: acpi: fix WindowsXP BSOD when memory hotplug is enabled
  pci: Split pcie_host_mmcfg_map()
  Add some trace calls to pci.c.
  ich9: add disable_s3, disable_s4, s4_val properties

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Peter Maydell 2015-01-27 13:17:30 +00:00
commit b00c92e3ef
24 changed files with 268 additions and 69 deletions

View file

@ -7,7 +7,6 @@ obj-$(CONFIG_XEN) += ../xenpv/ xen/
obj-y += kvmvapic.o
obj-y += acpi-build.o
obj-y += bios-linker-loader.o
hw/i386/acpi-build.o: hw/i386/acpi-build.c hw/i386/acpi-dsdt.hex \
hw/i386/ssdt-proc.hex hw/i386/ssdt-pcihp.hex hw/i386/ssdt-misc.hex \
hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \

View file

@ -36,7 +36,7 @@
#include "hw/i386/acpi-defs.h"
#include "hw/acpi/acpi.h"
#include "hw/nvram/fw_cfg.h"
#include "bios-linker-loader.h"
#include "hw/acpi/bios-linker-loader.h"
#include "hw/loader.h"
#include "hw/isa/isa.h"
#include "hw/acpi/memory_hotplug.h"
@ -305,6 +305,8 @@ static inline void build_append_array(GArray *array, GArray *val)
g_array_append_vals(array, val->data, val->len);
}
#define ACPI_NAMESEG_LEN 4
static void GCC_FMT_ATTR(2, 3)
build_append_nameseg(GArray *array, const char *format, ...)
{
@ -317,8 +319,11 @@ build_append_nameseg(GArray *array, const char *format, ...)
len = vsnprintf(s, sizeof s, format, args);
va_end(args);
assert(len == 4);
assert(len <= ACPI_NAMESEG_LEN);
g_array_append_vals(array, s, len);
/* Pad up to ACPI_NAMESEG_LEN characters if necessary. */
g_array_append_vals(array, "____", ACPI_NAMESEG_LEN - len);
}
/* 5.4 Definition Block Encoding */
@ -859,7 +864,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
if (bus->parent_dev) {
op = 0x82; /* DeviceOp */
build_append_nameseg(bus_table, "S%.02X_",
build_append_nameseg(bus_table, "S%.02X",
bus->parent_dev->devfn);
build_append_byte(bus_table, 0x08); /* NameOp */
build_append_nameseg(bus_table, "_SUN");
@ -979,7 +984,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
build_append_int(notify, 0x1U << i);
build_append_byte(notify, 0x00); /* NullName */
build_append_byte(notify, 0x86); /* NotifyOp */
build_append_nameseg(notify, "S%.02X_", PCI_DEVFN(i, 0));
build_append_nameseg(notify, "S%.02X", PCI_DEVFN(i, 0));
build_append_byte(notify, 0x69); /* Arg1Op */
/* Pack it up */
@ -1036,7 +1041,7 @@ static void build_pci_bus_end(PCIBus *bus, void *bus_state)
if (bus->parent_dev) {
build_append_byte(parent->notify_table, '^'); /* ParentPrefixChar */
build_append_byte(parent->notify_table, 0x2E); /* DualNamePrefix */
build_append_nameseg(parent->notify_table, "S%.02X_",
build_append_nameseg(parent->notify_table, "S%.02X",
bus->parent_dev->devfn);
build_append_nameseg(parent->notify_table, "PCNT");
}
@ -1106,7 +1111,7 @@ build_ssdt(GArray *table_data, GArray *linker,
GArray *sb_scope = build_alloc_array();
uint8_t op = 0x10; /* ScopeOp */
build_append_nameseg(sb_scope, "_SB_");
build_append_nameseg(sb_scope, "_SB");
/* build Processor object for each processor */
for (i = 0; i < acpi_cpus; i++) {

View file

@ -94,6 +94,7 @@ Scope(\_SB) {
Device(CPU_HOTPLUG_RESOURCE_DEVICE) {
Name(_HID, EisaId("PNP0A06"))
Name(_UID, "CPU hotplug resources")
Name(_CRS, ResourceTemplate() {
IO(Decode16, CPU_STATUS_BASE, CPU_STATUS_BASE, 0, CPU_STATUS_LEN)

View file

@ -3,12 +3,12 @@ static unsigned char AcpiDsdtAmlCode[] = {
0x53,
0x44,
0x54,
0x8,
0x25,
0xe,
0x0,
0x0,
0x1,
0xfc,
0x6c,
0x42,
0x58,
0x50,
@ -31,8 +31,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
0x4e,
0x54,
0x4c,
0x28,
0x8,
0x7,
0x11,
0x14,
0x20,
0x10,
@ -2318,8 +2318,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
0x53,
0x1,
0x10,
0x42,
0x11,
0x4f,
0x12,
0x5f,
0x53,
0x42,
@ -2551,7 +2551,8 @@ static unsigned char AcpiDsdtAmlCode[] = {
0x60,
0x5b,
0x82,
0x29,
0x46,
0x4,
0x50,
0x52,
0x45,
@ -2568,6 +2569,34 @@ static unsigned char AcpiDsdtAmlCode[] = {
0x6,
0x8,
0x5f,
0x55,
0x49,
0x44,
0xd,
0x43,
0x50,
0x55,
0x20,
0x68,
0x6f,
0x74,
0x70,
0x6c,
0x75,
0x67,
0x20,
0x72,
0x65,
0x73,
0x6f,
0x75,
0x72,
0x63,
0x65,
0x73,
0x0,
0x8,
0x5f,
0x43,
0x52,
0x53,

View file

@ -1,157 +0,0 @@
/* Dynamic linker/loader of ACPI tables
*
* Copyright (C) 2013 Red Hat Inc
*
* Author: Michael S. Tsirkin <mst@redhat.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* You should have received a copy of the GNU General Public License along
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/
#include "qemu-common.h"
#include "bios-linker-loader.h"
#include "hw/nvram/fw_cfg.h"
#include "qemu/bswap.h"
#define BIOS_LINKER_LOADER_FILESZ FW_CFG_MAX_FILE_PATH
struct BiosLinkerLoaderEntry {
uint32_t command;
union {
/*
* COMMAND_ALLOCATE - allocate a table from @alloc.file
* subject to @alloc.align alignment (must be power of 2)
* and @alloc.zone (can be HIGH or FSEG) requirements.
*
* Must appear exactly once for each file, and before
* this file is referenced by any other command.
*/
struct {
char file[BIOS_LINKER_LOADER_FILESZ];
uint32_t align;
uint8_t zone;
} alloc;
/*
* COMMAND_ADD_POINTER - patch the table (originating from
* @dest_file) at @pointer.offset, by adding a pointer to the table
* originating from @src_file. 1,2,4 or 8 byte unsigned
* addition is used depending on @pointer.size.
*/
struct {
char dest_file[BIOS_LINKER_LOADER_FILESZ];
char src_file[BIOS_LINKER_LOADER_FILESZ];
uint32_t offset;
uint8_t size;
} pointer;
/*
* COMMAND_ADD_CHECKSUM - calculate checksum of the range specified by
* @cksum_start and @cksum_length fields,
* and then add the value at @cksum.offset.
* Checksum simply sums -X for each byte X in the range
* using 8-bit math.
*/
struct {
char file[BIOS_LINKER_LOADER_FILESZ];
uint32_t offset;
uint32_t start;
uint32_t length;
} cksum;
/* padding */
char pad[124];
};
} QEMU_PACKED;
typedef struct BiosLinkerLoaderEntry BiosLinkerLoaderEntry;
enum {
BIOS_LINKER_LOADER_COMMAND_ALLOCATE = 0x1,
BIOS_LINKER_LOADER_COMMAND_ADD_POINTER = 0x2,
BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM = 0x3,
};
enum {
BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH = 0x1,
BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG = 0x2,
};
GArray *bios_linker_loader_init(void)
{
return g_array_new(false, true /* clear */, 1);
}
/* Free linker wrapper and return the linker array. */
void *bios_linker_loader_cleanup(GArray *linker)
{
return g_array_free(linker, false);
}
void bios_linker_loader_alloc(GArray *linker,
const char *file,
uint32_t alloc_align,
bool alloc_fseg)
{
BiosLinkerLoaderEntry entry;
memset(&entry, 0, sizeof entry);
strncpy(entry.alloc.file, file, sizeof entry.alloc.file - 1);
entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ALLOCATE);
entry.alloc.align = cpu_to_le32(alloc_align);
entry.alloc.zone = cpu_to_le32(alloc_fseg ?
BIOS_LINKER_LOADER_ALLOC_ZONE_FSEG :
BIOS_LINKER_LOADER_ALLOC_ZONE_HIGH);
/* Alloc entries must come first, so prepend them */
g_array_prepend_vals(linker, &entry, sizeof entry);
}
void bios_linker_loader_add_checksum(GArray *linker, const char *file,
void *table,
void *start, unsigned size,
uint8_t *checksum)
{
BiosLinkerLoaderEntry entry;
memset(&entry, 0, sizeof entry);
strncpy(entry.cksum.file, file, sizeof entry.cksum.file - 1);
entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_CHECKSUM);
entry.cksum.offset = cpu_to_le32(checksum - (uint8_t *)table);
entry.cksum.start = cpu_to_le32((uint8_t *)start - (uint8_t *)table);
entry.cksum.length = cpu_to_le32(size);
g_array_append_vals(linker, &entry, sizeof entry);
}
void bios_linker_loader_add_pointer(GArray *linker,
const char *dest_file,
const char *src_file,
GArray *table, void *pointer,
uint8_t pointer_size)
{
BiosLinkerLoaderEntry entry;
memset(&entry, 0, sizeof entry);
strncpy(entry.pointer.dest_file, dest_file,
sizeof entry.pointer.dest_file - 1);
strncpy(entry.pointer.src_file, src_file,
sizeof entry.pointer.src_file - 1);
entry.command = cpu_to_le32(BIOS_LINKER_LOADER_COMMAND_ADD_POINTER);
entry.pointer.offset = cpu_to_le32((gchar *)pointer - table->data);
entry.pointer.size = pointer_size;
assert(pointer_size == 1 || pointer_size == 2 ||
pointer_size == 4 || pointer_size == 8);
g_array_append_vals(linker, &entry, sizeof entry);
}

View file

@ -1,27 +0,0 @@
#ifndef BIOS_LINKER_LOADER_H
#define BIOS_LINKER_LOADER_H
#include <glib.h>
#include <stdbool.h>
#include <inttypes.h>
GArray *bios_linker_loader_init(void);
void bios_linker_loader_alloc(GArray *linker,
const char *file,
uint32_t alloc_align,
bool alloc_fseg);
void bios_linker_loader_add_checksum(GArray *linker, const char *file,
void *table,
void *start, unsigned size,
uint8_t *checksum);
void bios_linker_loader_add_pointer(GArray *linker,
const char *dest_file,
const char *src_file,
GArray *table, void *pointer,
uint8_t pointer_size);
void *bios_linker_loader_cleanup(GArray *linker);
#endif

View file

@ -1552,37 +1552,6 @@ void qemu_register_pc_machine(QEMUMachine *m)
g_free(name);
}
static int pc_dimm_count(Object *obj, void *opaque)
{
int *count = opaque;
if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
(*count)++;
}
object_child_foreach(obj, pc_dimm_count, opaque);
return 0;
}
static int pc_existing_dimms_capacity(Object *obj, void *opaque)
{
Error *local_err = NULL;
uint64_t *size = opaque;
if (object_dynamic_cast(obj, TYPE_PC_DIMM)) {
(*size) += object_property_get_int(obj, PC_DIMM_SIZE_PROP, &local_err);
if (local_err) {
qerror_report_err(local_err);
error_free(local_err);
return 1;
}
}
object_child_foreach(obj, pc_dimm_count, opaque);
return 0;
}
static void pc_dimm_plug(HotplugHandler *hotplug_dev,
DeviceState *dev, Error **errp)
{
@ -1615,16 +1584,17 @@ static void pc_dimm_plug(HotplugHandler *hotplug_dev,
goto out;
}
if (pc_existing_dimms_capacity(OBJECT(machine), &existing_dimms_capacity)) {
error_setg(&local_err, "failed to get total size of existing DIMMs");
existing_dimms_capacity = pc_existing_dimms_capacity(&local_err);
if (local_err) {
goto out;
}
if (existing_dimms_capacity + memory_region_size(mr) >
machine->maxram_size - machine->ram_size) {
error_setg(&local_err, "not enough space, currently 0x%" PRIx64
" in use of total 0x" RAM_ADDR_FMT,
existing_dimms_capacity, machine->maxram_size);
" in use of total hot pluggable 0x" RAM_ADDR_FMT,
existing_dimms_capacity,
machine->maxram_size - machine->ram_size);
goto out;
}

View file

@ -3,12 +3,12 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
0x53,
0x44,
0x54,
0xf6,
0x1f,
0x13,
0x20,
0x0,
0x0,
0x1,
0x91,
0x0,
0x42,
0x58,
0x50,
@ -31,8 +31,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
0x4e,
0x54,
0x4c,
0x28,
0x8,
0x7,
0x11,
0x14,
0x20,
0x10,
@ -6959,8 +6959,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
0x53,
0x1,
0x10,
0x42,
0x11,
0x4f,
0x12,
0x5f,
0x53,
0x42,
@ -7192,7 +7192,8 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
0x60,
0x5b,
0x82,
0x29,
0x46,
0x4,
0x50,
0x52,
0x45,
@ -7209,6 +7210,34 @@ static unsigned char Q35AcpiDsdtAmlCode[] = {
0x6,
0x8,
0x5f,
0x55,
0x49,
0x44,
0xd,
0x43,
0x50,
0x55,
0x20,
0x68,
0x6f,
0x74,
0x70,
0x6c,
0x75,
0x67,
0x20,
0x72,
0x65,
0x73,
0x6f,
0x75,
0x72,
0x63,
0x65,
0x73,
0x0,
0x8,
0x5f,
0x43,
0x52,
0x53,

View file

@ -618,8 +618,9 @@ static void smbios_build_type_4_table(unsigned instance)
SMBIOS_TABLE_SET_STR(4, processor_version_str, type4.version);
t->voltage = 0;
t->external_clock = cpu_to_le16(0); /* Unknown */
t->max_speed = cpu_to_le16(0); /* Unknown */
t->current_speed = cpu_to_le16(0); /* Unknown */
/* SVVP requires max_speed and current_speed to not be unknown. */
t->max_speed = cpu_to_le16(2000); /* 2000 MHz */
t->current_speed = cpu_to_le16(2000); /* 2000 MHz */
t->status = 0x41; /* Socket populated, CPU enabled */
t->processor_upgrade = 0x01; /* Other */
t->l1_cache_handle = cpu_to_le16(0xFFFF); /* N/A */
@ -850,7 +851,8 @@ void smbios_get_tables(uint8_t **tables, size_t *tables_len,
}
#define MAX_DIMM_SZ (16ll * ONE_GB)
#define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ : ram_size % MAX_DIMM_SZ)
#define GET_DIMM_SZ ((i < dimm_cnt - 1) ? MAX_DIMM_SZ \
: ((ram_size - 1) % MAX_DIMM_SZ) + 1)
dimm_cnt = QEMU_ALIGN_UP(ram_size, MAX_DIMM_SZ) / MAX_DIMM_SZ;