From patchwork Mon Mar 30 23:12:56 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1264388 X-Patchwork-Delegate: bmeng.cn@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=bEo7T9Gi; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 48rpLH5444z9sSL for ; Tue, 31 Mar 2020 10:18:47 +1100 (AEDT) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 01D4B8197B; Tue, 31 Mar 2020 01:15:48 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="bEo7T9Gi"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 22A4381930; Tue, 31 Mar 2020 01:14:52 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.2 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x142.google.com (mail-il1-x142.google.com [IPv6:2607:f8b0:4864:20::142]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 22C908191A for ; Tue, 31 Mar 2020 01:14:41 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x142.google.com with SMTP id k29so17599433ilg.0 for ; Mon, 30 Mar 2020 16:14:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cgxy4imEHvIupss3H9uZYI7w0AXc59t0EIRuVhKLOJI=; b=bEo7T9GipWT8ybSCMzwldj1Q6PG/00grNaeXz+8vpKPKnv9jX9mIhrLFQlQzjU5AoB VMMf07qmELl3+TFZ3+gpBzsaUtqQxVXZ2W1ZyUKRxrxNCvdJo3atpNp2Rnv5oOEUn+8o l804s/uxxtIyvlVX31hlpYmvDU8T/aQwwoeCs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cgxy4imEHvIupss3H9uZYI7w0AXc59t0EIRuVhKLOJI=; b=Yt12wA6w3vpKdq0Nkt3Pt4hU4vNpFAh8cTH8wd91+Vshv3LKdvc3PYvQOWq2Yp0JKB v9Mof5rf3BjBPPODO06eez4JhidSVy+jmQ7gpjnu3Eco+2RFDk9Q6UQaDGzOOOe1v0xt ZGD4Y+qw4hb8ehBZ1qbljygzD74ZFZL8hhTLwZGS8fu7u9vp/D5e2W33qWDvXY4xvv1Q 2Wdv1npY5ZvKBSePO8tnvxAc2i8gIiBqFT/qXV4sSJI2rhW50xBdHfR1QSesHLeNb/Ol YZFLb7cySOjS8DIf3kmAcVWrlh9+vpC6YzROOI5SB7UVrtQaTSrs0AT6tTH5g1UvKJ0g peZg== X-Gm-Message-State: ANhLgQ3DIDQZWj4dluoBpUjGMBMvTLPYDPlYX9JwKquKwF/hyCDkw+Ks yRXMhZFlc8CdnixvWsy+2kI2vBccP848lg== X-Google-Smtp-Source: ADFU+vuwC3EDp2Q/PYZIUjyxQpOM8fbpgOy3cJWdsQxo4tQMS+H3rqoqJ1UsAw6/qFJXAR2qBCTQtg== X-Received: by 2002:a92:8bc2:: with SMTP id i185mr13998964ild.273.1585610075386; Mon, 30 Mar 2020 16:14:35 -0700 (PDT) Received: from localhost.localdomain (c-73-14-175-90.hsd1.co.comcast.net. [73.14.175.90]) by smtp.gmail.com with ESMTPSA id c28sm5357898ilf.26.2020.03.30.16.14.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 30 Mar 2020 16:14:35 -0700 (PDT) From: Simon Glass To: u-boot@lists.denx.de Cc: Andy Shevchenko , Wolfgang Wallner , Leif Lindholm , Simon Glass , Bin Meng Subject: [PATCH v3 20/29] acpi: Add support for DMAR Date: Mon, 30 Mar 2020 17:12:56 -0600 Message-Id: <20200330171226.v3.20.Iffd9fd365ee53abc99a8f1e85c40d30c9368c19d@changeid> X-Mailer: git-send-email 2.26.0.rc2.310.g2932bb562d-goog In-Reply-To: <20200330231305.130488-1-sjg@chromium.org> References: <20200330231305.130488-1-sjg@chromium.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.30rc1 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.2 at phobos.denx.de X-Virus-Status: Clean The DMA Remapping Reporting (DMAR) table contains information about DMA remapping. Add a version simple version of this table with only the minimum fields filled out. i.e. no entries. Reviewed-by: Bin Meng Signed-off-by: Simon Glass Reviewed-by: Wolfgang Wallner --- Changes in v3: - Add missing error check in acpi_create_dmar() - Drop duplicate assert - Fix DMA_ typo - Make use of BIT() Changes in v2: - Drop two unnecessary __packed - Move __packed to after struct include/acpi/acpi_table.h | 57 +++++++++++++++++++++++++++++++++++++++ lib/acpi/acpi_table.c | 28 +++++++++++++++++++ test/dm/acpi.c | 13 +++++++++ 3 files changed, 98 insertions(+) diff --git a/include/acpi/acpi_table.h b/include/acpi/acpi_table.h index ccf6fa04dbe..10d6ccdf090 100644 --- a/include/acpi/acpi_table.h +++ b/include/acpi/acpi_table.h @@ -21,6 +21,9 @@ #define ACPI_RSDP_REV_ACPI_1_0 0 #define ACPI_RSDP_REV_ACPI_2_0 2 +/* TODO(sjg@chromium.org): Figure out how to get compiler revision */ +#define ASL_REVISION 0 + #if !defined(__ACPI__) /* @@ -360,6 +363,51 @@ struct acpi_csrt_shared_info { u32 max_block_size; }; +enum dmar_type { + DMAR_DRHD = 0, + DMAR_RMRR = 1, + DMAR_ATSR = 2, + DMAR_RHSA = 3, + DMAR_ANDD = 4 +}; + +enum { + DRHD_INCLUDE_PCI_ALL = BIT(0) +}; + +enum dmar_flags { + DMAR_INTR_REMAP = BIT(0), + DMAR_X2APIC_OPT_OUT = BIT(1), + DMAR_CTRL_PLATFORM_OPT_IN_FLAG = BIT(2), +}; + +struct dmar_entry { + u16 type; + u16 length; + u8 flags; + u8 reserved; + u16 segment; + u64 bar; +}; + +struct dmar_rmrr_entry { + u16 type; + u16 length; + u16 reserved; + u16 segment; + u64 bar; + u64 limit; +}; + +/* DMAR (DMA Remapping Reporting Structure) */ +struct __packed acpi_dmar { + struct acpi_table_header header; + u8 host_address_width; + u8 flags; + u8 reserved[10]; + struct dmar_entry structure[0]; +}; + /* DBG2 definitions are partially used for SPCR interface_type */ /* Types for port_type field */ @@ -452,6 +500,15 @@ enum acpi_tables { */ int acpi_get_table_revision(enum acpi_tables table); +/** + * acpi_create_dmar() - Create a DMA Remapping Reporting (DMAR) table + * + * @dmar: Place to put the table + * @flags: DMAR flags to use + * @return 0 if OK, -ve on error + */ +int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags); + #endif /* !__ACPI__*/ #include diff --git a/lib/acpi/acpi_table.c b/lib/acpi/acpi_table.c index 30639e4dfbd..3156fb93503 100644 --- a/lib/acpi/acpi_table.c +++ b/lib/acpi/acpi_table.c @@ -7,6 +7,34 @@ #include #include +#include +#include + +int acpi_create_dmar(struct acpi_dmar *dmar, enum dmar_flags flags) +{ + struct acpi_table_header *header = &dmar->header; + struct cpu_info info; + struct udevice *cpu; + int ret; + + ret = uclass_first_device(UCLASS_CPU, &cpu); + if (ret) + return log_msg_ret("cpu", ret); + ret = cpu_get_info(cpu, &info); + if (ret) + return log_msg_ret("info", ret); + memset((void *)dmar, 0, sizeof(struct acpi_dmar)); + + /* Fill out header fields. */ + acpi_fill_header(&dmar->header, "DMAR"); + header->length = sizeof(struct acpi_dmar); + header->revision = acpi_get_table_revision(ACPITAB_DMAR); + + dmar->host_address_width = info.address_width - 1; + dmar->flags = flags; + + return 0; +} int acpi_get_table_revision(enum acpi_tables table) { diff --git a/test/dm/acpi.c b/test/dm/acpi.c index e5510e4323b..21ed7c74409 100644 --- a/test/dm/acpi.c +++ b/test/dm/acpi.c @@ -67,3 +67,16 @@ static int dm_test_acpi_get_table_revision(struct unit_test_state *uts) } DM_TEST(dm_test_acpi_get_table_revision, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test acpi_create_dmar() */ +static int dm_test_acpi_create_dmar(struct unit_test_state *uts) +{ + struct acpi_dmar dmar; + + ut_assertok(acpi_create_dmar(&dmar, DMAR_INTR_REMAP)); + ut_asserteq(DMAR_INTR_REMAP, dmar.flags); + ut_asserteq(32 - 1, dmar.host_address_width); + + return 0; +} +DM_TEST(dm_test_acpi_create_dmar, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);