Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into sta…
Browse files Browse the repository at this point in the history
…ging

pc, pci, tpm, virtio, vhost enhancements and fixes

A bunch of cleanups and fixes all over the place,
enhancements in TPM, virtio and vhost.

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

# gpg: Signature made Mon Jun  1 13:19:48 2015 BST 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: (60 commits)
  vhost-user: add multi queue support
  virtio: make features 64bit wide
  qdev: add 64bit properties
  virtio-mmio: ioeventfd support
  hw/acpi/aml-build: Fix memory leak
  acpi: add aml_while() term
  acpi: add aml_increment() term
  acpi: add aml_shiftright() term
  acpi: add aml_shiftleft() term
  acpi: add aml_index() term
  acpi: add aml_lless() term
  acpi: add aml_add() term
  TPM2 ACPI table support
  tpm: Probe for connected TPM 1.2 or TPM 2
  Extend TPM TIS interface to support TPM 2
  Add stream ID to MSI write
  acpi: Simplify printing to dynamic string
  i386: drop FDC in pc-q35-2.4+ if neither it nor floppy drives are wanted
  i386/pc_q35: don't insist on board FDC if there's no default floppy
  i386/pc: '-drive if=floppy' should imply a board-default FDC
  ...

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
  • Loading branch information
pm215 committed Jun 1, 2015
2 parents 9657caf + 830d70d commit b821cbe
Show file tree
Hide file tree
Showing 62 changed files with 1,651 additions and 1,073 deletions.
14 changes: 14 additions & 0 deletions backends/tpm.c
Expand Up @@ -96,6 +96,20 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
return k->ops->get_tpm_established_flag(s);
}

int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);

return k->ops->reset_tpm_established_flag(s, locty);
}

TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
{
TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);

return k->ops->get_tpm_version(s);
}

static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
{
TPMBackend *s = TPM_BACKEND(obj);
Expand Down
5 changes: 5 additions & 0 deletions docs/specs/vhost-user.txt
Expand Up @@ -127,6 +127,11 @@ in the ancillary data:
If Master is unable to send the full message or receives a wrong reply it will
close the connection. An optional reconnection mechanism can be implemented.

Multi queue support
-------------------
The protocol supports multiple queues by setting all index fields in the sent
messages to a properly calculated value.

Message types
-------------

Expand Down
2 changes: 1 addition & 1 deletion hw/9pfs/virtio-9p-device.c
Expand Up @@ -21,7 +21,7 @@
#include "virtio-9p-coth.h"
#include "hw/virtio/virtio-access.h"

static uint32_t virtio_9p_get_features(VirtIODevice *vdev, uint32_t features)
static uint64_t virtio_9p_get_features(VirtIODevice *vdev, uint64_t features)
{
virtio_add_feature(&features, VIRTIO_9P_MOUNT_TAG);
return features;
Expand Down
85 changes: 63 additions & 22 deletions hw/acpi/aml-build.c
Expand Up @@ -19,6 +19,7 @@
* with this program; if not, see <http://www.gnu.org/licenses/>.
*/

#include <glib/gprintf.h>
#include <stdio.h>
#include <stdarg.h>
#include <assert.h>
Expand Down Expand Up @@ -59,7 +60,6 @@ static void build_append_array(GArray *array, GArray *val)
static void
build_append_nameseg(GArray *array, const char *seg)
{
/* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
int len;

len = strlen(seg);
Expand All @@ -73,22 +73,12 @@ build_append_nameseg(GArray *array, const char *seg)
static void GCC_FMT_ATTR(2, 0)
build_append_namestringv(GArray *array, const char *format, va_list ap)
{
/* It would be nicer to use g_string_vprintf but it's only there in 2.22 */
char *s;
int len;
va_list va_len;
char **segs;
char **segs_iter;
int seg_count = 0;

va_copy(va_len, ap);
len = vsnprintf(NULL, 0, format, va_len);
va_end(va_len);
len += 1;
s = g_new(typeof(*s), len);

len = vsnprintf(s, len, format, ap);

s = g_strdup_vprintf(format, ap);
segs = g_strsplit(s, ".", 0);
g_free(s);

Expand Down Expand Up @@ -306,6 +296,7 @@ static void aml_free(gpointer data, gpointer user_data)
{
Aml *var = data;
build_free_array(var->buf);
g_free(var);
}

Aml *init_aml_allocator(void)
Expand Down Expand Up @@ -465,6 +456,63 @@ Aml *aml_or(Aml *arg1, Aml *arg2)
return var;
}

/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefShiftLeft */
Aml *aml_shiftleft(Aml *arg1, Aml *count)
{
Aml *var = aml_opcode(0x79 /* ShiftLeftOp */);
aml_append(var, arg1);
aml_append(var, count);
build_append_byte(var->buf, 0x00); /* NullNameOp */
return var;
}

/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefShiftRight */
Aml *aml_shiftright(Aml *arg1, Aml *count)
{
Aml *var = aml_opcode(0x7A /* ShiftRightOp */);
aml_append(var, arg1);
aml_append(var, count);
build_append_byte(var->buf, 0x00); /* NullNameOp */
return var;
}

/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefLLess */
Aml *aml_lless(Aml *arg1, Aml *arg2)
{
Aml *var = aml_opcode(0x95 /* LLessOp */);
aml_append(var, arg1);
aml_append(var, arg2);
return var;
}

/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefAdd */
Aml *aml_add(Aml *arg1, Aml *arg2)
{
Aml *var = aml_opcode(0x72 /* AddOp */);
aml_append(var, arg1);
aml_append(var, arg2);
build_append_byte(var->buf, 0x00 /* NullNameOp */);
return var;
}

/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIncrement */
Aml *aml_increment(Aml *arg)
{
Aml *var = aml_opcode(0x75 /* IncrementOp */);
aml_append(var, arg);
return var;
}

/* ACPI 1.0b: 16.2.5.4 Type 2 Opcodes Encoding: DefIndex */
Aml *aml_index(Aml *arg1, Aml *idx)
{
Aml *var = aml_opcode(0x88 /* IndexOp */);
aml_append(var, arg1);
aml_append(var, idx);
build_append_byte(var->buf, 0x00 /* NullNameOp */);
return var;
}

/* ACPI 1.0b: 16.2.5.3 Type 1 Opcodes Encoding: DefNotify */
Aml *aml_notify(Aml *arg1, Aml *arg2)
{
Expand Down Expand Up @@ -753,22 +801,15 @@ Aml *aml_create_dword_field(Aml *srcbuf, Aml *index, const char *name)
Aml *aml_string(const char *name_format, ...)
{
Aml *var = aml_opcode(0x0D /* StringPrefix */);
va_list ap, va_len;
va_list ap;
char *s;
int len;

va_start(ap, name_format);
va_copy(va_len, ap);
len = vsnprintf(NULL, 0, name_format, va_len);
va_end(va_len);
len += 1;
s = g_new0(typeof(*s), len);

len = vsnprintf(s, len, name_format, ap);
len = g_vasprintf(&s, name_format, ap);
va_end(ap);

g_array_append_vals(var->buf, s, len);
build_append_byte(var->buf, 0x0); /* NullChar */
g_array_append_vals(var->buf, s, len + 1);
g_free(s);

return var;
Expand Down
2 changes: 1 addition & 1 deletion hw/block/virtio-blk.c
Expand Up @@ -718,7 +718,7 @@ static void virtio_blk_set_config(VirtIODevice *vdev, const uint8_t *config)
aio_context_release(blk_get_aio_context(s->blk));
}

static uint32_t virtio_blk_get_features(VirtIODevice *vdev, uint32_t features)
static uint64_t virtio_blk_get_features(VirtIODevice *vdev, uint64_t features)
{
VirtIOBlock *s = VIRTIO_BLK(vdev);

Expand Down
4 changes: 2 additions & 2 deletions hw/char/virtio-serial-bus.c
Expand Up @@ -498,7 +498,7 @@ static void handle_input(VirtIODevice *vdev, VirtQueue *vq)
}
}

static uint32_t get_features(VirtIODevice *vdev, uint32_t features)
static uint64_t get_features(VirtIODevice *vdev, uint64_t features)
{
VirtIOSerial *vser;

Expand Down Expand Up @@ -973,7 +973,7 @@ static void virtio_serial_device_realize(DeviceState *dev, Error **errp)
}

/* Each port takes 2 queues, and one pair is for the control queue */
max_supported_ports = VIRTIO_PCI_QUEUE_MAX / 2 - 1;
max_supported_ports = VIRTIO_QUEUE_MAX / 2 - 1;

if (vser->serial.max_virtserial_ports > max_supported_ports) {
error_setg(errp, "maximum ports supported: %u", max_supported_ports);
Expand Down
58 changes: 58 additions & 0 deletions hw/core/qdev-properties.c
Expand Up @@ -125,6 +125,64 @@ PropertyInfo qdev_prop_bit = {
.set = prop_set_bit,
};

/* Bit64 */

static uint64_t qdev_get_prop_mask64(Property *prop)
{
assert(prop->info == &qdev_prop_bit);
return 0x1 << prop->bitnr;
}

static void bit64_prop_set(DeviceState *dev, Property *props, bool val)
{
uint64_t *p = qdev_get_prop_ptr(dev, props);
uint64_t mask = qdev_get_prop_mask64(props);
if (val) {
*p |= mask;
} else {
*p &= ~mask;
}
}

static void prop_get_bit64(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
uint64_t *p = qdev_get_prop_ptr(dev, prop);
bool value = (*p & qdev_get_prop_mask64(prop)) != 0;

visit_type_bool(v, &value, name, errp);
}

static void prop_set_bit64(Object *obj, Visitor *v, void *opaque,
const char *name, Error **errp)
{
DeviceState *dev = DEVICE(obj);
Property *prop = opaque;
Error *local_err = NULL;
bool value;

if (dev->realized) {
qdev_prop_set_after_realize(dev, name, errp);
return;
}

visit_type_bool(v, &value, name, &local_err);
if (local_err) {
error_propagate(errp, local_err);
return;
}
bit64_prop_set(dev, prop, value);
}

PropertyInfo qdev_prop_bit64 = {
.name = "bool",
.description = "on/off",
.get = prop_get_bit64,
.set = prop_set_bit64,
};

/* --- bool --- */

static void get_bool(Object *obj, Visitor *v, void *opaque,
Expand Down
2 changes: 1 addition & 1 deletion hw/i386/Makefile.objs
Expand Up @@ -9,7 +9,7 @@ obj-y += kvmvapic.o
obj-y += acpi-build.o
hw/i386/acpi-build.o: hw/i386/acpi-build.c \
hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
hw/i386/ssdt-tpm.hex
hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex

iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
; then echo "$(2)"; else echo "$(3)"; fi ;)
Expand Down
43 changes: 38 additions & 5 deletions hw/i386/acpi-build.c
Expand Up @@ -41,6 +41,7 @@
#include "hw/acpi/memory_hotplug.h"
#include "sysemu/tpm.h"
#include "hw/acpi/tpm.h"
#include "sysemu/tpm_backend.h"

/* Supported chipsets: */
#include "hw/acpi/piix4.h"
Expand Down Expand Up @@ -106,7 +107,7 @@ typedef struct AcpiPmInfo {

typedef struct AcpiMiscInfo {
bool has_hpet;
bool has_tpm;
TPMVersion tpm_version;
const unsigned char *dsdt_code;
unsigned dsdt_size;
uint16_t pvpanic_port;
Expand Down Expand Up @@ -234,7 +235,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
static void acpi_get_misc_info(AcpiMiscInfo *info)
{
info->has_hpet = hpet_find();
info->has_tpm = tpm_find();
info->tpm_version = tpm_get_version();
info->pvpanic_port = pvpanic_port();
info->applesmc_io_base = applesmc_port();
}
Expand Down Expand Up @@ -414,6 +415,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
}

#include "hw/i386/ssdt-tpm.hex"
#include "hw/i386/ssdt-tpm2.hex"

/* Assign BSEL property to all buses. In the future, this can be changed
* to only assign to buses that support hotplug.
Expand Down Expand Up @@ -733,7 +735,7 @@ build_ssdt(GArray *table_data, GArray *linker,
if (misc->pvpanic_port) {
scope = aml_scope("\\_SB.PCI0.ISA");

dev = aml_device("PEVR");
dev = aml_device("PEVT");
aml_append(dev, aml_name_decl("_HID", aml_string("QEMU0001")));

crs = aml_resource_template();
Expand All @@ -748,6 +750,9 @@ build_ssdt(GArray *table_data, GArray *linker,
aml_append(field, aml_named_field("PEPT", 8));
aml_append(dev, field);

/* device present, functioning, decoding, not shown in UI */
aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));

method = aml_method("RDPT", 0);
aml_append(method, aml_store(aml_name("PEPT"), aml_local(0)));
aml_append(method, aml_return(aml_local(0)));
Expand Down Expand Up @@ -1026,6 +1031,25 @@ build_tpm_ssdt(GArray *table_data, GArray *linker)
memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));
}

static void
build_tpm2(GArray *table_data, GArray *linker)
{
Acpi20TPM2 *tpm2_ptr;
void *tpm_ptr;

tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));

tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);

tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
tpm2_ptr->control_area_address = cpu_to_le64(0);
tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);

build_header(linker, table_data,
(void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
}

typedef enum {
MEM_AFFINITY_NOFLAGS = 0,
MEM_AFFINITY_ENABLED = (1 << 0),
Expand Down Expand Up @@ -1340,12 +1364,21 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
acpi_add_table(table_offsets, tables_blob);
build_hpet(tables_blob, tables->linker);
}
if (misc.has_tpm) {
if (misc.tpm_version != TPM_VERSION_UNSPEC) {
acpi_add_table(table_offsets, tables_blob);
build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);

acpi_add_table(table_offsets, tables_blob);
build_tpm_ssdt(tables_blob, tables->linker);
switch (misc.tpm_version) {
case TPM_VERSION_1_2:
build_tpm_ssdt(tables_blob, tables->linker);
break;
case TPM_VERSION_2_0:
build_tpm2(tables_blob, tables->linker);
break;
default:
assert(false);
}
}
if (guest_info->numa_nodes) {
acpi_add_table(table_offsets, tables_blob);
Expand Down

0 comments on commit b821cbe

Please sign in to comment.