[PATCH 3/3] dm: add Timed GPIO parameter


chenli.wei
 

From: Chenli Wei <chenli.wei@...>

This patch add a Timed GPIO parameter to enable Timed GPIO passthrough
and create a ACPI table for post-launched VM when user enable it by the
launch script.

Tracked-On: #6690
Signed-off-by: Chenli Wei <chenli.wei@...>
---
devicemodel/Makefile | 1 +
devicemodel/core/main.c | 7 +++
devicemodel/hw/platform/acpi/acpi.c | 4 ++
devicemodel/hw/platform/tgpio.c | 82 +++++++++++++++++++++++++++++
devicemodel/include/tgpio.h | 24 +++++++++
5 files changed, 118 insertions(+)
create mode 100644 devicemodel/hw/platform/tgpio.c
create mode 100644 devicemodel/include/tgpio.h

diff --git a/devicemodel/Makefile b/devicemodel/Makefile
index 823265e27..092f9d2c2 100644
--- a/devicemodel/Makefile
+++ b/devicemodel/Makefile
@@ -116,6 +116,7 @@ SRCS += hw/platform/cmos_io.c
SRCS += hw/platform/ioc.c
SRCS += hw/platform/ioc_cbc.c
SRCS += hw/platform/pty_vuart.c
+SRCS += hw/platform/tgpio.c
SRCS += hw/platform/acpi/acpi.c
SRCS += hw/platform/vssram/vssram.c
SRCS += hw/platform/acpi/acpi_pm.c
diff --git a/devicemodel/core/main.c b/devicemodel/core/main.c
index 135a6435c..432eb239f 100644
--- a/devicemodel/core/main.c
+++ b/devicemodel/core/main.c
@@ -71,6 +71,7 @@
#include "cmd_monitor.h"
#include "vdisplay.h"
#include "iothread.h"
+#include "tgpio.h"

#define VM_MAXCPU 16 /* maximum virtual cpus */

@@ -178,6 +179,7 @@ usage(int code)
" --virtio_poll: enable virtio poll mode with poll interval with ns\n"
" --acpidev_pt: acpi device ID args: HID in ACPI Table\n"
" --mmiodev_pt: MMIO resources args: physical MMIO regions\n"
+ " --tgpio_pt: Enable Timed GPIO resources \n"
" --vtpm2: Virtual TPM2 args: sock_path=$PATH_OF_SWTPM_SOCKET\n"
" --lapic_pt: enable local apic passthrough\n"
" --rtvm: indicate that the guest is rtvm\n"
@@ -788,6 +790,7 @@ enum {
CMD_OPT_PM_BY_VUART,
CMD_OPT_WINDOWS,
CMD_OPT_FORCE_VIRTIO_MSI,
+ CMD_TGPIO_ENABLE,
};

static struct option long_options[] = {
@@ -822,6 +825,7 @@ static struct option long_options[] = {
{"cmd_monitor", required_argument, 0, CMD_OPT_CMD_MONITOR},
{"acpidev_pt", required_argument, 0, CMD_OPT_ACPIDEV_PT},
{"mmiodev_pt", required_argument, 0, CMD_OPT_MMIODEV_PT},
+ {"tgpio_pt", no_argument, 0, CMD_TGPIO_ENABLE},
{"vtpm2", required_argument, 0, CMD_OPT_VTPM2},
{"lapic_pt", no_argument, 0, CMD_OPT_LAPIC_PT},
{"rtvm", no_argument, 0, CMD_OPT_RTVM},
@@ -1041,6 +1045,9 @@ main(int argc, char *argv[])
case CMD_OPT_FORCE_VIRTIO_MSI:
virtio_msix = 0;
break;
+ case CMD_TGPIO_ENABLE:
+ enable_timed_gpio();
+ break;
case 'h':
usage(0);
default:
diff --git a/devicemodel/hw/platform/acpi/acpi.c b/devicemodel/hw/platform/acpi/acpi.c
index c5f6a40af..f5ece7653 100644
--- a/devicemodel/hw/platform/acpi/acpi.c
+++ b/devicemodel/hw/platform/acpi/acpi.c
@@ -74,6 +74,7 @@
#include "vssram.h"
#include "vmmapi.h"
#include "mmio_dev.h"
+#include "tgpio.h"

/*
* Define the base address of the ACPI tables, and the offsets to
@@ -881,6 +882,9 @@ basl_fwrite_dsdt(FILE *fp, struct vmctx *ctx)

pm_write_dsdt(ctx, basl_ncpu);

+ if(is_tgpio_enabled())
+ dsdt_fwrite_tgpio();
+
dsdt_line("}");

if (dsdt_error != 0)
diff --git a/devicemodel/hw/platform/tgpio.c b/devicemodel/hw/platform/tgpio.c
new file mode 100644
index 000000000..6d39181d4
--- /dev/null
+++ b/devicemodel/hw/platform/tgpio.c
@@ -0,0 +1,82 @@
+/*
+ * Copyright (C) 2018-2022 Intel Corporation.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <errno.h>
+
+#include "acpi.h"
+#include "log.h"
+#include "dm.h"
+
+static bool tgpio_enabled = false;
+
+int dsdt_fwrite_tgpio()
+{
+ dsdt_line("Scope (_SB)");
+ dsdt_line("{");
+ dsdt_line(" Device (TGI0)");
+ dsdt_line(" {");
+ dsdt_line(" Name (_HID, \"INTC1023\") // _HID: Hardware ID");
+ dsdt_line(" Name (_STR, Unicode (\"Timed GPIO 1\")) // _STR: Description String");
+ dsdt_line(" Method (_STA, 0, NotSerialized) // _STA: Status");
+ dsdt_line(" {");
+ dsdt_line(" Return (Zero)");
+ dsdt_line(" }");
+ dsdt_line("");
+ dsdt_line(" Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings");
+ dsdt_line(" {");
+ dsdt_line(" Name (TGRA, ResourceTemplate ()");
+ dsdt_line(" {");
+ dsdt_line(" Memory32Fixed (ReadWrite,");
+ dsdt_line(" 0x00000000, // Address Base");
+ dsdt_line(" 0x00000038, // Address Length");
+ dsdt_line(" _Y39)");
+ dsdt_line(" })");
+ dsdt_line(" CreateDWordField (TGRA, \\_SB.TGI0._CRS._Y39._BAS, TMH1) // _BAS: Base Address");
+ dsdt_line(" TMH1 = (32 + 0x1210)");
+ dsdt_line(" Return (TGRA) /* \\_SB_.TGI0._CRS.TGRA */");
+ dsdt_line(" }");
+ dsdt_line(" }");
+ dsdt_line("");
+ dsdt_line(" Device (TGI1)");
+ dsdt_line(" {");
+ dsdt_line(" Name (_HID, \"INTC1024\") // _HID: Hardware ID");
+ dsdt_line(" Name (_STR, Unicode (\"Timed GPIO 2\")) // _STR: Description String");
+ dsdt_line(" Method (_STA, 0, NotSerialized) // _STA: Status");
+ dsdt_line(" {");
+ dsdt_line(" Return (Zero)");
+ dsdt_line(" }");
+ dsdt_line("");
+ dsdt_line(" Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings");
+ dsdt_line(" {");
+ dsdt_line(" Name (TGRB, ResourceTemplate ()");
+ dsdt_line(" {");
+ dsdt_line(" Memory32Fixed (ReadWrite,");
+ dsdt_line(" 0x00000000, // Address Base");
+ dsdt_line(" 0x00000038, // Address Length");
+ dsdt_line(" _Y3A)");
+ dsdt_line(" })");
+ dsdt_line(" CreateDWordField (TGRB, \\_SB.TGI1._CRS._Y3A._BAS, TMH2) // _BAS: Base Address");
+ dsdt_line(" TMH2 = (32 + 0x1310)");
+ dsdt_line(" Return (TGRB) /* \\_SB_.TGI1._CRS.TGRB */");
+ dsdt_line(" }");
+ dsdt_line(" }");
+ dsdt_line("}");
+ return 0;
+}
+
+void enable_timed_gpio()
+{
+ tgpio_enabled = true;
+}
+
+bool is_tgpio_enabled()
+{
+ return tgpio_enabled;
+}
diff --git a/devicemodel/include/tgpio.h b/devicemodel/include/tgpio.h
new file mode 100644
index 000000000..8e69693eb
--- /dev/null
+++ b/devicemodel/include/tgpio.h
@@ -0,0 +1,24 @@
+/*
+ * Copyright (C) 2018-2022 Intel Corporation.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _TGPIO_H_
+#define _TGPIO_H_
+
+#include "mmio_dev.h"
+#include "acpi.h"
+
+/* write the dsdt of Timed GPIO */
+int dsdt_fwrite_tgpio();
+
+/* Parse Virtual TGPIO option from command line */
+int acrn_parse_vtgpio(char *arg);
+
+/* Enable timed GPIO */
+void enable_timed_gpio();
+
+/* Get whether timed GPIO Enable */
+bool is_tgpio_enabled();
+#endif
--
2.25.1