Received: by 2002:a17:906:fc07:b0:9bd:85f7:2662 with SMTP id ov7csp3002126ejb; Wed, 25 Oct 2023 13:13:52 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFpvI4ItMb7SzJJlMnimPW0YcTGSAiaI+tdl4RoSAGjL+yD9+9OtKvzXMR09B+MZBhsIeSx X-Received: by 2002:adf:9dcb:0:b0:32d:a29a:b6ef with SMTP id q11-20020adf9dcb000000b0032da29ab6efmr12237040wre.23.1698264832626; Wed, 25 Oct 2023 13:13:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698264832; cv=none; d=google.com; s=arc-20160816; b=PWo5e78fxSbj/P6Eb/WoO8eaJYyU61eDrO5Bn9JFl7u6xdS97L2mTKggXKMg8kABaI dpb05kIdoNZc4pdvDi9iIjncnF205nUMzc7Lmpl0BJbcpsYIxS5/fNMIbH6z7zzEfVpN 1vsf0DqJVlZhJQtThffrQ8W5yDREeeJNBqvuJkQoLkLjQSzbZCnF89ALuyZUFNQsQbMw ZpO6hkh38gpc2DjdICy3NkqLgvQyLmuN9RSWOY4PkFtBNJnZNCfAVT8A093KZ+53nbgS e50n6covM8c1avCtNp+U6yyTRgIefyBYzqP5/YBWCawWS32uZip02oPm/oNsbfkv4gTv ErwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=FYH31waZkSbzs3YHigOqBOLA8Lr0Cc+Fy05oGkCwsy8=; fh=ieNWTeoXViVzjD3GbjL7nI2u2Tkk33Uc9BsQY+9ivz0=; b=RgXicUOh5je0xXjYzen/OBIBpbcEqfKxBSKkZdaijP51mxnp1W8d3PEDUBKeKkrMmW YSGTBi7NxxZ+yG36/dQN1JLrL4bGm9iH4chCqyhHy9WcYSLQZlJup3nsyyICK8kTsv36 qhP8Z9gYyei1qUblE4ae0bDo2kXAL4cYurF6nDxZ8LrTrd+Xq66SRdu5RviA0xRLQrSX b7cUmZG6bxCgWrjSuiJz1Q2rugXLg0pWDqQnMmVvkWAgTHn8m1Ux1JPEb4eRcwWApqmA MtDG2SIvC/NtfQrAKYJJExtWjyc0iHp0hPNHuQqvaFm7gX9NKpYYScNOy/WLSql2H3a8 rbHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=GhBIYkn5; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id z16-20020adff750000000b0032d9756f644si8167120wrp.148.2023.10.25.13.13.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 25 Oct 2023 13:13:52 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=GhBIYkn5; spf=pass (google.com: domain of qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org" Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1qvkBY-0000C7-EF; Wed, 25 Oct 2023 16:09:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1qvkBF-0008P0-1Q for qemu-arm@nongnu.org; Wed, 25 Oct 2023 16:08:41 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1qvkBC-0003by-3F for qemu-arm@nongnu.org; Wed, 25 Oct 2023 16:08:40 -0400 Received: by mail-pf1-x42c.google.com with SMTP id d2e1a72fcca58-6ba172c5f3dso125518b3a.0 for ; Wed, 25 Oct 2023 13:08:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1698264516; x=1698869316; darn=nongnu.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=FYH31waZkSbzs3YHigOqBOLA8Lr0Cc+Fy05oGkCwsy8=; b=GhBIYkn5mcmJkqmlE9ln1ciq9LnYlmOPvbHoEknU4qV0xCrQ8sQB8s3y0TWUN8hhER r9eXgsa38iyqjsapx1iKspBJBJflb8Dl0lmUS/LosAhB2+nGXZ87XNfPswr37NUYEeIS yk0qs294rztTTotJ4jJQsRsnipgcWnYCYSDfUJWQLS2tbHsOrE/1j475o2bF+0RPd3QX 20OU1/oEoEME8qcgHjvPf/aIsJyIvHgUN8qiSoub17zapTeCJYolOI7sV2KCydixnPeX AGFWsYDZ79w8nJbApPIWAHhzy85V6XJJRLxbc0k9t4LVamLtDBBWNKaYwUKXbe7pHsRV 98TA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1698264516; x=1698869316; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FYH31waZkSbzs3YHigOqBOLA8Lr0Cc+Fy05oGkCwsy8=; b=GmvkCyuevlnBGOtMvU6vhR7tpMy+44kqVdfjP/IJS6mPacA/l/TXCZ1jqcamlG7fhv AEiR66lTd15H/Pl/WAxKCK8jz6oie2E33F0K6KM5Tkpu9N0NycWiL/a18XprwvtJymAF k9fYyXhkIJ78//WxV6FYOPaaQRLTp2d5EstOkEgEIp1qpRdTBMIdX8dSu3Vo99yWma5d DpCxMMEMwyi8mAgMU/Etc7p8bpSMcFclcfnTSEehEz8/Rt7lZToFnrcBok0j6CvKs2F6 +Stvq+IHy45vGCmgfXBmwC8rQhXUmcFu0rHppc4UVmHSachP9BRptqRrW749g+7SI+tp 8Jyw== X-Gm-Message-State: AOJu0YxP7xVYjbJC2u3/Ki7qd/ah3JLw8grM7OJcVXB+UyUsD9dQfELb YZmUxSw7l/JKSCLGolweuBKZfatS0TbSpsfP6VypBA== X-Received: by 2002:a05:6a00:1ad1:b0:68a:4261:ab7f with SMTP id f17-20020a056a001ad100b0068a4261ab7fmr15817994pfv.31.1698264516454; Wed, 25 Oct 2023 13:08:36 -0700 (PDT) Received: from sunil-pc.Dlink ([106.51.188.78]) by smtp.gmail.com with ESMTPSA id f1-20020aa79681000000b0068fe7c4148fsm9696768pfk.57.2023.10.25.13.08.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Oct 2023 13:08:35 -0700 (PDT) From: Sunil V L To: qemu-arm@nongnu.org, qemu-devel@nongnu.org, qemu-riscv@nongnu.org Cc: Peter Maydell , Shannon Zhao , "Michael S . Tsirkin" , Igor Mammedov , Ani Sinha , Marcel Apfelbaum , Paolo Bonzini , Richard Henderson , Eduardo Habkost , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , Gerd Hoffmann , Palmer Dabbelt , Alistair Francis , Bin Meng , Weiwei Li , Daniel Henrique Barboza , Liu Zhiwei , Anup Patel , Atish Kumar Patra , Haibo Xu , Sunil V L Subject: [PATCH v4 12/13] hw/riscv/virt-acpi-build.c: Add IO controllers and devices Date: Thu, 26 Oct 2023 01:37:12 +0530 Message-Id: <20231025200713.580814-13-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231025200713.580814-1-sunilvl@ventanamicro.com> References: <20231025200713.580814-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=sunilvl@ventanamicro.com; helo=mail-pf1-x42c.google.com X-Spam_score_int: 12 X-Spam_score: 1.2 X-Spam_bar: + X-Spam_report: (1.2 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, RCVD_IN_SBL_CSS=3.335, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-arm@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org Sender: qemu-arm-bounces+alex.bennee=linaro.org@nongnu.org X-TUID: EWkbFn3rgEvk Add basic IO controllers and devices like PCI, VirtIO and UART in the ACPI namespace. Signed-off-by: Sunil V L Reviewed-by: Daniel Henrique Barboza --- hw/riscv/Kconfig | 1 + hw/riscv/virt-acpi-build.c | 79 ++++++++++++++++++++++++++++++++++++-- 2 files changed, 76 insertions(+), 4 deletions(-) diff --git a/hw/riscv/Kconfig b/hw/riscv/Kconfig index b6a5eb4452..a50717be87 100644 --- a/hw/riscv/Kconfig +++ b/hw/riscv/Kconfig @@ -45,6 +45,7 @@ config RISCV_VIRT select FW_CFG_DMA select PLATFORM_BUS select ACPI + select ACPI_PCI config SHAKTI_C bool diff --git a/hw/riscv/virt-acpi-build.c b/hw/riscv/virt-acpi-build.c index dc7c0213f5..c410fe7d5c 100644 --- a/hw/riscv/virt-acpi-build.c +++ b/hw/riscv/virt-acpi-build.c @@ -27,15 +27,18 @@ #include "hw/acpi/acpi-defs.h" #include "hw/acpi/acpi.h" #include "hw/acpi/aml-build.h" +#include "hw/acpi/pci.h" #include "hw/acpi/utils.h" +#include "hw/intc/riscv_aclint.h" #include "hw/nvram/fw_cfg_acpi.h" +#include "hw/pci-host/gpex.h" +#include "hw/riscv/virt.h" +#include "hw/riscv/numa.h" +#include "hw/virtio/virtio-acpi.h" +#include "migration/vmstate.h" #include "qapi/error.h" #include "qemu/error-report.h" #include "sysemu/reset.h" -#include "migration/vmstate.h" -#include "hw/riscv/virt.h" -#include "hw/riscv/numa.h" -#include "hw/intc/riscv_aclint.h" #define ACPI_BUILD_TABLE_SIZE 0x20000 #define ACPI_BUILD_INTC_ID(socket, index) ((socket << 24) | (index)) @@ -139,6 +142,39 @@ static void acpi_dsdt_add_cpus(Aml *scope, RISCVVirtState *s) } } +static void +acpi_dsdt_add_uart(Aml *scope, const MemMapEntry *uart_memmap, + uint32_t uart_irq) +{ + Aml *dev = aml_device("COM0"); + aml_append(dev, aml_name_decl("_HID", aml_string("PNP0501"))); + aml_append(dev, aml_name_decl("_UID", aml_int(0))); + + Aml *crs = aml_resource_template(); + aml_append(crs, aml_memory32_fixed(uart_memmap->base, + uart_memmap->size, AML_READ_WRITE)); + aml_append(crs, + aml_interrupt(AML_CONSUMER, AML_LEVEL, AML_ACTIVE_HIGH, + AML_EXCLUSIVE, &uart_irq, 1)); + aml_append(dev, aml_name_decl("_CRS", crs)); + + Aml *pkg = aml_package(2); + aml_append(pkg, aml_string("clock-frequency")); + aml_append(pkg, aml_int(3686400)); + + Aml *UUID = aml_touuid("DAFFD814-6EBA-4D8C-8A91-BC9BBF4AA301"); + + Aml *pkg1 = aml_package(1); + aml_append(pkg1, pkg); + + Aml *package = aml_package(2); + aml_append(package, UUID); + aml_append(package, pkg1); + + aml_append(dev, aml_name_decl("_DSD", package)); + aml_append(scope, dev); +} + /* RHCT Node[N] starts at offset 56 */ #define RHCT_NODE_ARRAY_OFFSET 56 @@ -318,6 +354,8 @@ static void build_dsdt(GArray *table_data, RISCVVirtState *s) { Aml *scope, *dsdt; + MachineState *ms = MACHINE(s); + uint8_t socket_count; const MemMapEntry *memmap = s->memmap; AcpiTable table = { .sig = "DSDT", .rev = 2, .oem_id = s->oem_id, .oem_table_id = s->oem_table_id }; @@ -337,6 +375,29 @@ static void build_dsdt(GArray *table_data, fw_cfg_acpi_dsdt_add(scope, &memmap[VIRT_FW_CFG]); + socket_count = riscv_socket_count(ms); + + acpi_dsdt_add_uart(scope, &memmap[VIRT_UART0], UART0_IRQ); + + if (socket_count == 1) { + virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base, + memmap[VIRT_VIRTIO].size, + VIRTIO_IRQ, 0, VIRTIO_COUNT); + acpi_dsdt_add_gpex_host(scope, PCIE_IRQ); + } else if (socket_count == 2) { + virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base, + memmap[VIRT_VIRTIO].size, + VIRTIO_IRQ + VIRT_IRQCHIP_NUM_SOURCES, 0, + VIRTIO_COUNT); + acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + VIRT_IRQCHIP_NUM_SOURCES); + } else { + virtio_acpi_dsdt_add(scope, memmap[VIRT_VIRTIO].base, + memmap[VIRT_VIRTIO].size, + VIRTIO_IRQ + VIRT_IRQCHIP_NUM_SOURCES, 0, + VIRTIO_COUNT); + acpi_dsdt_add_gpex_host(scope, PCIE_IRQ + VIRT_IRQCHIP_NUM_SOURCES * 2); + } + aml_append(dsdt, scope); /* copy AML table into ACPI tables blob and patch header there */ @@ -486,6 +547,16 @@ static void virt_acpi_build(RISCVVirtState *s, AcpiBuildTables *tables) acpi_add_table(table_offsets, tables_blob); build_rhct(tables_blob, tables->linker, s); + acpi_add_table(table_offsets, tables_blob); + { + AcpiMcfgInfo mcfg = { + .base = s->memmap[VIRT_PCIE_MMIO].base, + .size = s->memmap[VIRT_PCIE_MMIO].size, + }; + build_mcfg(tables_blob, tables->linker, &mcfg, s->oem_id, + s->oem_table_id); + } + /* XSDT is pointed to by RSDP */ xsdt = tables_blob->len; build_xsdt(tables_blob, tables->linker, table_offsets, s->oem_id, -- 2.39.2