Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id D38E3C433F5 for ; Tue, 29 Mar 2022 17:01:43 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1572184065; Tue, 29 Mar 2022 19:00:45 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.b="QGm9Tv9+"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C23568403D; Tue, 29 Mar 2022 18:59:50 +0200 (CEST) Received: from mail-wr1-x44a.google.com (mail-wr1-x44a.google.com [IPv6:2a00:1450:4864:20::44a]) (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 31B2384042 for ; Tue, 29 Mar 2022 18:59:46 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=3ATtDYgYKBpw6O8QHHCKKCHA.8KIQ-7KKPHEOPO.9AJT.9A@flex--ascull.bounces.google.com Received: by mail-wr1-x44a.google.com with SMTP id p9-20020adf9589000000b001e333885ac1so5205614wrp.10 for ; Tue, 29 Mar 2022 09:59:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=V2KkT6psXOj8s85adZaSW3yrXeEJBLYJwToWUzQt00I=; b=QGm9Tv9+g75US9muCmt4IBGDwSbHKmNNlwNEuAuuMGjoxaj4XJWrOiNFgs8fivG2vw DUcd+3quGLbyIUHngk83HIBnrdJ9A+ODWUWmv6Q4UJncLoRKKl362t9qMm7SRBmvggr4 D5X6koplSoncsPABINNNnYWvl5R0LDd26KID9OX7u+BJrNgUqabT8hbXgshKWZM13a1u K/Xm60tABh1bXfptJ43m3GbRtcwInoApydlrVktEB0rKH+kW0b/XanDlP+KitZ28umLR akQF8i/V2SW+6uyRhdTb0oWFujTysLvk3kwhjSi57ujaC1iXSejG9cmkeud2BsR1WNRC 0Jng== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=V2KkT6psXOj8s85adZaSW3yrXeEJBLYJwToWUzQt00I=; b=UFq5TdQ2bydhULg1AeruP8jgyajCHvmFJFPRnsDbav56CSYqMDTnMfFO/dLlvMmoK9 fudq4ih+zsg7mHPNbD5Nb5Dd62DPx+fFTY/gi6/doORCWh5+OhhX5AvifIgJFnuAB9wq IzNxrd9Zdut04F/8gzU3z6uNS8BUNlmkQb+t6ojuD78rrnyM95oqepkVmnQvOoxn0SN2 mEq4pTshxJvU8DXFW8WkuW8x6JT2QsoiyyiAXnf26+plYqNj4j82yCvJVhnNnCsoxsxv cm5uU5odstCYp6qBhQEwEDQyncgwApVAaxdBFHGOCYZLtkbI5xjciO8YqsYTZ0d+Xy4p vWbQ== X-Gm-Message-State: AOAM531D8RxWBXAstPAZhek0SBStZH+4yzsW3NjTqTW3W17JSUiLpCrF LmRrtwOgNb87GctYv4/OrSoZqaA4eBT/+skvaTrDAZ4yUgHDRWDjlwONYVovk7HT3n+KmlOV/GJ OVEgClfzHf1ki28m802cmvrj44muAYneZbzgWzaDBzRu0R9eli7bE2XWcw2w= X-Google-Smtp-Source: ABdhPJziircIk9KPQcMRSSMyZLHWQgMA07bZp+25LZynfwbEUB582Nd3Q5lWdqlD8ZdXhcD7+PUrZg/WRag= X-Received: from ascull.c.googlers.com ([fda3:e722:ac3:cc00:28:9cb1:c0a8:1510]) (user=ascull job=sendgmr) by 2002:a05:600c:4e93:b0:38c:92d9:c7bc with SMTP id f19-20020a05600c4e9300b0038c92d9c7bcmr94870wmq.173.1648573185797; Tue, 29 Mar 2022 09:59:45 -0700 (PDT) Date: Tue, 29 Mar 2022 16:58:54 +0000 In-Reply-To: <20220329165900.1139885-1-ascull@google.com> Message-Id: <20220329165900.1139885-13-ascull@google.com> Mime-Version: 1.0 References: <20220329165900.1139885-1-ascull@google.com> X-Mailer: git-send-email 2.35.1.1021.g381101b075-goog Subject: [PATCH v2 12/18] test: pci: Test PCI address conversion functions From: Andrew Scull To: u-boot@lists.denx.de Cc: sjg@chromium.org, bmeng.cn@gmail.com, adelva@google.com, keirf@google.com, ptosi@google.com, Andrew Scull Content-Type: text/plain; charset="UTF-8" X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.103.5 at phobos.denx.de X-Virus-Status: Clean Add tests for the functions dm_pci_bus_to_phys() and dm_pci_phys_to_bus() which convert between PCI bus addresses and physical addresses based on the ranges declared for the PCI controller. The ranges of bus#1 are used for the tests, adding a translation to one of the ranges to cover more cases. Signed-off-by: Andrew Scull --- arch/sandbox/dts/test.dts | 2 +- test/dm/pci.c | 102 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 1 deletion(-) diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index 48ca3e1e47..76c75e08e7 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -979,7 +979,7 @@ #address-cells = <3>; #size-cells = <2>; ranges = <0x02000000 0 0x30000000 0x30000000 0 0x2000 // MEM0 - 0x02000000 0 0x31000000 0x31000000 0 0x2000 // MEM1 + 0x02000000 0 0x31000000 0x3e000000 0 0x2000 // MEM1 0x01000000 0 0x40000000 0x40000000 0 0x2000>; sandbox,dev-info = <0x08 0x00 0x1234 0x5678 0x0c 0x00 0x1234 0x5678 diff --git a/test/dm/pci.c b/test/dm/pci.c index 00e4440a9d..9789103c7d 100644 --- a/test/dm/pci.c +++ b/test/dm/pci.c @@ -376,3 +376,105 @@ static int dm_test_pci_region_multi(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_pci_region_multi, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* + * Test the translation of PCI bus addresses to physical addresses using the + * ranges from bus#1. + */ +static int dm_test_pci_bus_to_phys(struct unit_test_state *uts) +{ + struct udevice *dev; + phys_addr_t phys_addr; + + ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &dev)); + + /* Before any of the ranges. */ + phys_addr = dm_pci_bus_to_phys(dev, 0x20000000, 0x400, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + /* Identity range: whole, start, mid, end */ + phys_addr = dm_pci_bus_to_phys(dev, 0x2fff0000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x30000000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0x30000000, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x30000000, 0x1000, PCI_REGION_MEM); + ut_asserteq(0x30000000, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x30000abc, 0x12, PCI_REGION_MEM); + ut_asserteq(0x30000abc, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x30000800, 0x1800, PCI_REGION_MEM); + ut_asserteq(0x30000800, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x30008000, 0x1801, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + /* Translated range: whole, start, mid, end */ + phys_addr = dm_pci_bus_to_phys(dev, 0x30ff0000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x31000000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0x3e000000, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x31000000, 0x1000, PCI_REGION_MEM); + ut_asserteq(0x3e000000, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x31000abc, 0x12, PCI_REGION_MEM); + ut_asserteq(0x3e000abc, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x31000800, 0x1800, PCI_REGION_MEM); + ut_asserteq(0x3e000800, phys_addr); + phys_addr = dm_pci_bus_to_phys(dev, 0x31008000, 0x1801, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + /* Beyond all of the ranges. */ + phys_addr = dm_pci_bus_to_phys(dev, 0x32000000, 0x400, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + return 0; +} +DM_TEST(dm_test_pci_bus_to_phys, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); + +/* + * Test the translation of physical addresses to PCI bus addresses using the + * ranges from bus#1. + */ +static int dm_test_pci_phys_to_bus(struct unit_test_state *uts) +{ + struct udevice *dev; + phys_addr_t phys_addr; + + ut_assertok(dm_pci_bus_find_bdf(PCI_BDF(1, 0x08, 0), &dev)); + + /* Before any of the ranges. */ + phys_addr = dm_pci_phys_to_bus(dev, 0x20000000, 0x400, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + /* Identity range: whole, start, mid, end */ + phys_addr = dm_pci_phys_to_bus(dev, 0x2fff0000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x30000000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0x30000000, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x30000000, 0x1000, PCI_REGION_MEM); + ut_asserteq(0x30000000, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x30000abc, 0x12, PCI_REGION_MEM); + ut_asserteq(0x30000abc, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x30000800, 0x1800, PCI_REGION_MEM); + ut_asserteq(0x30000800, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x30008000, 0x1801, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + /* Translated range: whole, start, mid, end */ + phys_addr = dm_pci_phys_to_bus(dev, 0x3dff0000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x3e000000, 0x2000, PCI_REGION_MEM); + ut_asserteq(0x31000000, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x3e000000, 0x1000, PCI_REGION_MEM); + ut_asserteq(0x31000000, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x3e000abc, 0x12, PCI_REGION_MEM); + ut_asserteq(0x31000abc, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x3e000800, 0x1800, PCI_REGION_MEM); + ut_asserteq(0x31000800, phys_addr); + phys_addr = dm_pci_phys_to_bus(dev, 0x3e008000, 0x1801, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + /* Beyond all of the ranges. */ + phys_addr = dm_pci_phys_to_bus(dev, 0x3f000000, 0x400, PCI_REGION_MEM); + ut_asserteq(0, phys_addr); + + return 0; +} +DM_TEST(dm_test_pci_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- 2.35.1.1021.g381101b075-goog