Skip to content

Commit 63d2119

Browse files
committed
Merge remote-tracking branch 'remotes/mst/tags/for_upstream' into staging
virtio,acpi,pci: fixes, cleanups. Fixes, cleanups in ACPI, PCI, virtio. Signed-off-by: Michael S. Tsirkin <[email protected]> # gpg: Signature made Thu 25 Jun 2020 07:48:47 BST # gpg: using RSA key 5D09FD0871C8F85B94CA8A0D281F0DB8D28D5469 # gpg: issuer "[email protected]" # gpg: Good signature from "Michael S. Tsirkin <[email protected]>" [full] # gpg: aka "Michael S. Tsirkin <[email protected]>" [full] # Primary key fingerprint: 0270 606B 6F3C DF3D 0B17 0970 C350 3912 AFBE 8E67 # Subkey fingerprint: 5D09 FD08 71C8 F85B 94CA 8A0D 281F 0DB8 D28D 5469 * remotes/mst/tags/for_upstream: Rename use_acpi_pci_hotplug to more appropriate use_acpi_hotplug_bridge Stop vhost-user sending uninitialized mmap_offsets docs/specs/tpm: ACPI boot now supported for TPM/ARM arm/acpi: Add the TPM2.0 device under the DSDT acpi: Some build_tpm2() code reshape tests/acpi: update expected data files acpi: q35: drop _SB.PCI0.ISA.LPCD opregion. acpi: drop build_piix4_pm() acpi: drop serial/parallel enable bits from dsdt acpi: simplify build_isa_devices_aml() acpi: factor out fw_cfg_add_acpi_dsdt() acpi: move aml builder code for i8042 (kbd+mouse) device floppy: move cmos_get_fd_drive_type() from pc floppy: make isa_fdc_get_drive_max_chs static acpi: move aml builder code for floppy device acpi: bios-tables-test: show more context on asl diffs qtest: allow DSDT acpi table changes Signed-off-by: Peter Maydell <[email protected]>
2 parents beafab8 + 0affda0 commit 63d2119

36 files changed

+286
-290
lines changed

docs/specs/tpm.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,6 @@ In case an Arm virt machine is emulated, use the following command line:
346346
-drive if=pflash,format=raw,file=flash0.img,readonly \
347347
-drive if=pflash,format=raw,file=flash1.img
348348
349-
On Arm, ACPI boot with TPM is not yet supported.
350-
351349
In case SeaBIOS is used as firmware, it should show the TPM menu item
352350
after entering the menu with 'ESC'.
353351

hw/acpi/aml-build.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,48 +1878,61 @@ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
18781878
"FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
18791879
}
18801880

1881+
/*
1882+
* build_tpm2 - Build the TPM2 table as specified in
1883+
* table 7: TCG Hardware Interface Description Table Format for TPM 2.0
1884+
* of TCG ACPI Specification, Family “1.2” and “2.0”, Version 1.2, Rev 8
1885+
*/
18811886
void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
18821887
{
1883-
Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
1884-
unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
1885-
unsigned log_addr_offset =
1886-
(char *)&tpm2_ptr->log_area_start_address - table_data->data;
18871888
uint8_t start_method_params[12] = {};
1889+
unsigned log_addr_offset, tpm2_start;
1890+
uint64_t control_area_start_address;
18881891
TPMIf *tpmif = tpm_find();
1892+
uint32_t start_method;
1893+
void *tpm2_ptr;
1894+
1895+
tpm2_start = table_data->len;
1896+
tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
18891897

1890-
/* platform class */
1898+
/* Platform Class */
18911899
build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2);
1892-
/* reserved */
1900+
/* Reserved */
18931901
build_append_int_noprefix(table_data, 0, 2);
18941902
if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
1895-
/* address of control area */
1896-
build_append_int_noprefix(table_data, 0, 8);
1897-
/* start method */
1898-
build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO, 4);
1903+
control_area_start_address = 0;
1904+
start_method = TPM2_START_METHOD_MMIO;
18991905
} else if (TPM_IS_CRB(tpmif)) {
1900-
build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8);
1901-
build_append_int_noprefix(table_data, TPM2_START_METHOD_CRB, 4);
1906+
control_area_start_address = TPM_CRB_ADDR_CTRL;
1907+
start_method = TPM2_START_METHOD_CRB;
19021908
} else {
1903-
g_warn_if_reached();
1909+
g_assert_not_reached();
19041910
}
1911+
/* Address of Control Area */
1912+
build_append_int_noprefix(table_data, control_area_start_address, 8);
1913+
/* Start Method */
1914+
build_append_int_noprefix(table_data, start_method, 4);
19051915

1906-
/* platform specific parameters */
1907-
g_array_append_vals(table_data, &start_method_params, 12);
1916+
/* Platform Specific Parameters */
1917+
g_array_append_vals(table_data, &start_method_params,
1918+
ARRAY_SIZE(start_method_params));
19081919

1909-
/* log area minimum length */
1920+
/* Log Area Minimum Length */
19101921
build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4);
19111922

19121923
acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
19131924
bios_linker_loader_alloc(linker, ACPI_BUILD_TPMLOG_FILE, tcpalog, 1,
19141925
false);
19151926

1916-
/* log area start address to be filled by Guest linker */
1927+
log_addr_offset = table_data->len;
1928+
1929+
/* Log Area Start Address to be filled by Guest linker */
19171930
build_append_int_noprefix(table_data, 0, 8);
19181931
bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
1919-
log_addr_offset, log_addr_size,
1932+
log_addr_offset, 8,
19201933
ACPI_BUILD_TPMLOG_FILE, 0);
19211934
build_header(linker, table_data,
1922-
(void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
1935+
tpm2_ptr, "TPM2", table_data->len - tpm2_start, 4, NULL, NULL);
19231936
}
19241937

19251938
/* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */

hw/acpi/piix4.c

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ typedef struct PIIX4PMState {
7777
Notifier powerdown_notifier;
7878

7979
AcpiPciHpState acpi_pci_hotplug;
80-
bool use_acpi_pci_hotplug;
80+
bool use_acpi_hotplug_bridge;
8181

8282
uint8_t disable_s3;
8383
uint8_t disable_s4;
@@ -204,16 +204,17 @@ static const VMStateDescription vmstate_pci_status = {
204204
}
205205
};
206206

207-
static bool vmstate_test_use_acpi_pci_hotplug(void *opaque, int version_id)
207+
static bool vmstate_test_use_acpi_hotplug_bridge(void *opaque, int version_id)
208208
{
209209
PIIX4PMState *s = opaque;
210-
return s->use_acpi_pci_hotplug;
210+
return s->use_acpi_hotplug_bridge;
211211
}
212212

213-
static bool vmstate_test_no_use_acpi_pci_hotplug(void *opaque, int version_id)
213+
static bool vmstate_test_no_use_acpi_hotplug_bridge(void *opaque,
214+
int version_id)
214215
{
215216
PIIX4PMState *s = opaque;
216-
return !s->use_acpi_pci_hotplug;
217+
return !s->use_acpi_hotplug_bridge;
217218
}
218219

219220
static bool vmstate_test_use_memhp(void *opaque)
@@ -290,11 +291,11 @@ static const VMStateDescription vmstate_acpi = {
290291
VMSTATE_STRUCT_TEST(
291292
acpi_pci_hotplug.acpi_pcihp_pci_status[ACPI_PCIHP_BSEL_DEFAULT],
292293
PIIX4PMState,
293-
vmstate_test_no_use_acpi_pci_hotplug,
294+
vmstate_test_no_use_acpi_hotplug_bridge,
294295
2, vmstate_pci_status,
295296
struct AcpiPciHpPciStatus),
296297
VMSTATE_PCI_HOTPLUG(acpi_pci_hotplug, PIIX4PMState,
297-
vmstate_test_use_acpi_pci_hotplug),
298+
vmstate_test_use_acpi_hotplug_bridge),
298299
VMSTATE_END_OF_LIST()
299300
},
300301
.subsections = (const VMStateDescription*[]) {
@@ -530,7 +531,7 @@ I2CBus *piix4_pm_init(PCIBus *bus, int devfn, uint32_t smb_io_base,
530531
s->smi_irq = smi_irq;
531532
s->smm_enabled = smm_enabled;
532533
if (xen_enabled()) {
533-
s->use_acpi_pci_hotplug = false;
534+
s->use_acpi_hotplug_bridge = false;
534535
}
535536

536537
pci_realize_and_unref(pci_dev, bus, &error_fatal);
@@ -595,7 +596,7 @@ static void piix4_acpi_system_hot_add_init(MemoryRegion *parent,
595596
memory_region_add_subregion(parent, GPE_BASE, &s->io_gpe);
596597

597598
acpi_pcihp_init(OBJECT(s), &s->acpi_pci_hotplug, bus, parent,
598-
s->use_acpi_pci_hotplug);
599+
s->use_acpi_hotplug_bridge);
599600

600601
s->cpu_hotplug_legacy = true;
601602
object_property_add_bool(OBJECT(s), "cpu-hotplug-legacy",
@@ -633,7 +634,7 @@ static Property piix4_pm_properties[] = {
633634
DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_DISABLED, PIIX4PMState, disable_s4, 0),
634635
DEFINE_PROP_UINT8(ACPI_PM_PROP_S4_VAL, PIIX4PMState, s4_val, 2),
635636
DEFINE_PROP_BOOL("acpi-pci-hotplug-with-bridge-support", PIIX4PMState,
636-
use_acpi_pci_hotplug, true),
637+
use_acpi_hotplug_bridge, true),
637638
DEFINE_PROP_BOOL("memory-hotplug-support", PIIX4PMState,
638639
acpi_memory_hotplug.is_enabled, true),
639640
DEFINE_PROP_END_OF_LIST(),

hw/arm/virt-acpi-build.c

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
#include "hw/pci/pci.h"
4747
#include "hw/arm/virt.h"
4848
#include "hw/mem/nvdimm.h"
49+
#include "hw/platform-bus.h"
4950
#include "sysemu/numa.h"
5051
#include "sysemu/reset.h"
5152
#include "sysemu/tpm.h"
@@ -364,6 +365,38 @@ static void acpi_dsdt_add_power_button(Aml *scope)
364365
aml_append(scope, dev);
365366
}
366367

368+
static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
369+
{
370+
PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
371+
hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
372+
SysBusDevice *sbdev = SYS_BUS_DEVICE(tpm_find());
373+
MemoryRegion *sbdev_mr;
374+
hwaddr tpm_base;
375+
376+
if (!sbdev) {
377+
return;
378+
}
379+
380+
tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
381+
assert(tpm_base != -1);
382+
383+
tpm_base += pbus_base;
384+
385+
sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
386+
387+
Aml *dev = aml_device("TPM0");
388+
aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
389+
aml_append(dev, aml_name_decl("_UID", aml_int(0)));
390+
391+
Aml *crs = aml_resource_template();
392+
aml_append(crs,
393+
aml_memory32_fixed(tpm_base,
394+
(uint32_t)memory_region_size(sbdev_mr),
395+
AML_READ_WRITE));
396+
aml_append(dev, aml_name_decl("_CRS", crs));
397+
aml_append(scope, dev);
398+
}
399+
367400
static void
368401
build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
369402
{
@@ -762,6 +795,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
762795
}
763796

764797
acpi_dsdt_add_power_button(scope);
798+
acpi_dsdt_add_tpm(scope, vms);
765799

766800
aml_append(dsdt, scope);
767801

hw/block/fdc.c

Lines changed: 109 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "qapi/error.h"
3333
#include "qemu/error-report.h"
3434
#include "qemu/timer.h"
35+
#include "hw/acpi/aml-build.h"
3536
#include "hw/irq.h"
3637
#include "hw/isa/isa.h"
3738
#include "hw/qdev-properties.h"
@@ -2753,8 +2754,8 @@ FloppyDriveType isa_fdc_get_drive_type(ISADevice *fdc, int i)
27532754
return isa->state.drives[i].drive;
27542755
}
27552756

2756-
void isa_fdc_get_drive_max_chs(FloppyDriveType type,
2757-
uint8_t *maxc, uint8_t *maxh, uint8_t *maxs)
2757+
static void isa_fdc_get_drive_max_chs(FloppyDriveType type, uint8_t *maxc,
2758+
uint8_t *maxh, uint8_t *maxs)
27582759
{
27592760
const FDFormat *fdf;
27602761

@@ -2776,6 +2777,110 @@ void isa_fdc_get_drive_max_chs(FloppyDriveType type,
27762777
(*maxc)--;
27772778
}
27782779

2780+
static Aml *build_fdinfo_aml(int idx, FloppyDriveType type)
2781+
{
2782+
Aml *dev, *fdi;
2783+
uint8_t maxc, maxh, maxs;
2784+
2785+
isa_fdc_get_drive_max_chs(type, &maxc, &maxh, &maxs);
2786+
2787+
dev = aml_device("FLP%c", 'A' + idx);
2788+
2789+
aml_append(dev, aml_name_decl("_ADR", aml_int(idx)));
2790+
2791+
fdi = aml_package(16);
2792+
aml_append(fdi, aml_int(idx)); /* Drive Number */
2793+
aml_append(fdi,
2794+
aml_int(cmos_get_fd_drive_type(type))); /* Device Type */
2795+
/*
2796+
* the values below are the limits of the drive, and are thus independent
2797+
* of the inserted media
2798+
*/
2799+
aml_append(fdi, aml_int(maxc)); /* Maximum Cylinder Number */
2800+
aml_append(fdi, aml_int(maxs)); /* Maximum Sector Number */
2801+
aml_append(fdi, aml_int(maxh)); /* Maximum Head Number */
2802+
/*
2803+
* SeaBIOS returns the below values for int 0x13 func 0x08 regardless of
2804+
* the drive type, so shall we
2805+
*/
2806+
aml_append(fdi, aml_int(0xAF)); /* disk_specify_1 */
2807+
aml_append(fdi, aml_int(0x02)); /* disk_specify_2 */
2808+
aml_append(fdi, aml_int(0x25)); /* disk_motor_wait */
2809+
aml_append(fdi, aml_int(0x02)); /* disk_sector_siz */
2810+
aml_append(fdi, aml_int(0x12)); /* disk_eot */
2811+
aml_append(fdi, aml_int(0x1B)); /* disk_rw_gap */
2812+
aml_append(fdi, aml_int(0xFF)); /* disk_dtl */
2813+
aml_append(fdi, aml_int(0x6C)); /* disk_formt_gap */
2814+
aml_append(fdi, aml_int(0xF6)); /* disk_fill */
2815+
aml_append(fdi, aml_int(0x0F)); /* disk_head_sttl */
2816+
aml_append(fdi, aml_int(0x08)); /* disk_motor_strt */
2817+
2818+
aml_append(dev, aml_name_decl("_FDI", fdi));
2819+
return dev;
2820+
}
2821+
2822+
int cmos_get_fd_drive_type(FloppyDriveType fd0)
2823+
{
2824+
int val;
2825+
2826+
switch (fd0) {
2827+
case FLOPPY_DRIVE_TYPE_144:
2828+
/* 1.44 Mb 3"5 drive */
2829+
val = 4;
2830+
break;
2831+
case FLOPPY_DRIVE_TYPE_288:
2832+
/* 2.88 Mb 3"5 drive */
2833+
val = 5;
2834+
break;
2835+
case FLOPPY_DRIVE_TYPE_120:
2836+
/* 1.2 Mb 5"5 drive */
2837+
val = 2;
2838+
break;
2839+
case FLOPPY_DRIVE_TYPE_NONE:
2840+
default:
2841+
val = 0;
2842+
break;
2843+
}
2844+
return val;
2845+
}
2846+
2847+
static void fdc_isa_build_aml(ISADevice *isadev, Aml *scope)
2848+
{
2849+
Aml *dev;
2850+
Aml *crs;
2851+
int i;
2852+
2853+
#define ACPI_FDE_MAX_FD 4
2854+
uint32_t fde_buf[5] = {
2855+
0, 0, 0, 0, /* presence of floppy drives #0 - #3 */
2856+
cpu_to_le32(2) /* tape presence (2 == never present) */
2857+
};
2858+
2859+
crs = aml_resource_template();
2860+
aml_append(crs, aml_io(AML_DECODE16, 0x03F2, 0x03F2, 0x00, 0x04));
2861+
aml_append(crs, aml_io(AML_DECODE16, 0x03F7, 0x03F7, 0x00, 0x01));
2862+
aml_append(crs, aml_irq_no_flags(6));
2863+
aml_append(crs,
2864+
aml_dma(AML_COMPATIBILITY, AML_NOTBUSMASTER, AML_TRANSFER8, 2));
2865+
2866+
dev = aml_device("FDC0");
2867+
aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0700")));
2868+
aml_append(dev, aml_name_decl("_CRS", crs));
2869+
2870+
for (i = 0; i < MIN(MAX_FD, ACPI_FDE_MAX_FD); i++) {
2871+
FloppyDriveType type = isa_fdc_get_drive_type(isadev, i);
2872+
2873+
if (type < FLOPPY_DRIVE_TYPE_NONE) {
2874+
fde_buf[i] = cpu_to_le32(1); /* drive present */
2875+
aml_append(dev, build_fdinfo_aml(i, type));
2876+
}
2877+
}
2878+
aml_append(dev, aml_name_decl("_FDE",
2879+
aml_buffer(sizeof(fde_buf), (uint8_t *)fde_buf)));
2880+
2881+
aml_append(scope, dev);
2882+
}
2883+
27792884
static const VMStateDescription vmstate_isa_fdc ={
27802885
.name = "fdc",
27812886
.version_id = 2,
@@ -2809,11 +2914,13 @@ static Property isa_fdc_properties[] = {
28092914
static void isabus_fdc_class_init(ObjectClass *klass, void *data)
28102915
{
28112916
DeviceClass *dc = DEVICE_CLASS(klass);
2917+
ISADeviceClass *isa = ISA_DEVICE_CLASS(klass);
28122918

28132919
dc->realize = isabus_fdc_realize;
28142920
dc->fw_name = "fdc";
28152921
dc->reset = fdctrl_external_reset_isa;
28162922
dc->vmsd = &vmstate_isa_fdc;
2923+
isa->build_aml = fdc_isa_build_aml;
28172924
device_class_set_props(dc, isa_fdc_properties);
28182925
set_bit(DEVICE_CATEGORY_STORAGE, dc->categories);
28192926
}

0 commit comments

Comments
 (0)