From 283628c412a2b98bdb22093a732aef4d5668e106 Mon Sep 17 00:00:00 2001 From: Nicolas Saenz Julienne Date: Tue, 12 Jan 2021 13:55:23 +0100 Subject: dm: test: Add test case for dev_get_dma_ranges() Introduce some new nodes in sandbox's test device-tree and dm tests in order to validate dev_get_dma_range(). Signed-off-by: Nicolas Saenz Julienne Reviewed-by: Simon Glass Tested-by: Peter Robinson Signed-off-by: Matthias Brugger --- test/dm/Makefile | 1 + test/dm/read.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 test/dm/read.c (limited to 'test') diff --git a/test/dm/Makefile b/test/dm/Makefile index e70e50f4024..c363ca47a61 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -15,6 +15,7 @@ obj-$(CONFIG_UT_DM) += test-fdt.o obj-$(CONFIG_UT_DM) += test-uclass.o obj-$(CONFIG_UT_DM) += core.o +obj-$(CONFIG_UT_DM) += read.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_ACPIGEN) += acpi.o obj-$(CONFIG_ACPIGEN) += acpigen.o diff --git a/test/dm/read.c b/test/dm/read.c new file mode 100644 index 00000000000..7768aa29688 --- /dev/null +++ b/test/dm/read.c @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Nicolas Saenz Julienne + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +static int dm_test_dma_ranges(struct unit_test_state *uts) +{ + struct udevice *dev; + phys_addr_t cpu; + dma_addr_t bus; + ofnode node; + u64 size; + + /* dma-ranges are on the device's node */ + node = ofnode_path("/mmio-bus@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); + ut_assertok(dev_get_dma_range(dev, &cpu, &bus, &size)); + ut_asserteq_64(0x40000, size); + ut_asserteq_64(0x0, cpu); + ut_asserteq_64(0x10000000, bus); + + /* dma-ranges are on the bus' node */ + node = ofnode_path("/mmio-bus@0/subnode@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev)); + ut_assertok(dev_get_dma_range(dev, &cpu, &bus, &size)); + ut_asserteq_64(0x40000, size); + ut_asserteq_64(0x0, cpu); + ut_asserteq_64(0x10000000, bus); + + /* No dma-ranges available */ + node = ofnode_path("/mmio-bus@1"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); + ut_asserteq(-ENOENT, dev_get_dma_range(dev, &cpu, &bus, &size)); + + return 0; +} +DM_TEST(dm_test_dma_ranges, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- cgit v1.3.1 From e88018769cd3ed69d2f1623fe03a02dcb0be073a Mon Sep 17 00:00:00 2001 From: Nicolas Saenz Julienne Date: Tue, 12 Jan 2021 13:55:25 +0100 Subject: dm: test: Add test case for dev->dma_offset Add test to validate dev->dma_offset is properly set on devices. Signed-off-by: Nicolas Saenz Julienne Reviewed-by: Simon Glass Tested-by: Peter Robinson Signed-off-by: Matthias Brugger --- arch/sandbox/dts/test.dts | 4 ++++ configs/sandbox64_defconfig | 1 + configs/sandbox_defconfig | 1 + configs/sandbox_flattree_defconfig | 1 + configs/sandbox_spl_defconfig | 1 + test/dm/core.c | 30 ++++++++++++++++++++++++++++++ 6 files changed, 38 insertions(+) (limited to 'test') diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts index c135881ac33..d4195b45bbd 100644 --- a/arch/sandbox/dts/test.dts +++ b/arch/sandbox/dts/test.dts @@ -365,6 +365,10 @@ #address-cells = <1>; #size-cells = <1>; compatible = "denx,u-boot-test-bus"; + + subnode@0 { + compatible = "denx,u-boot-fdt-test"; + }; }; acpi_test1: acpi-test { diff --git a/configs/sandbox64_defconfig b/configs/sandbox64_defconfig index 4e678195591..634c19502ce 100644 --- a/configs/sandbox64_defconfig +++ b/configs/sandbox64_defconfig @@ -94,6 +94,7 @@ CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0" CONFIG_BOOTP_SEND_HOSTNAME=y CONFIG_NETCONSOLE=y CONFIG_IP_DEFRAG=y +CONFIG_DM_DMA=y CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_DEVRES=y diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig index 0c7674efc97..fc1df3114cb 100644 --- a/configs/sandbox_defconfig +++ b/configs/sandbox_defconfig @@ -108,6 +108,7 @@ CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0" CONFIG_BOOTP_SEND_HOSTNAME=y CONFIG_NETCONSOLE=y CONFIG_IP_DEFRAG=y +CONFIG_DM_DMA=y CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_DEVRES=y diff --git a/configs/sandbox_flattree_defconfig b/configs/sandbox_flattree_defconfig index 96465c56cf1..4401f33f0ba 100644 --- a/configs/sandbox_flattree_defconfig +++ b/configs/sandbox_flattree_defconfig @@ -75,6 +75,7 @@ CONFIG_ENV_EXT4_DEVICE_AND_PART="0:0" CONFIG_BOOTP_SEND_HOSTNAME=y CONFIG_NETCONSOLE=y CONFIG_IP_DEFRAG=y +CONFIG_DM_DMA=y CONFIG_REGMAP=y CONFIG_SYSCON=y CONFIG_DEVRES=y diff --git a/configs/sandbox_spl_defconfig b/configs/sandbox_spl_defconfig index 61dae34a6a2..c0118702a81 100644 --- a/configs/sandbox_spl_defconfig +++ b/configs/sandbox_spl_defconfig @@ -95,6 +95,7 @@ CONFIG_BOOTP_SEND_HOSTNAME=y CONFIG_NETCONSOLE=y CONFIG_IP_DEFRAG=y CONFIG_SPL_DM=y +CONFIG_DM_DMA=y CONFIG_REGMAP=y CONFIG_SPL_REGMAP=y CONFIG_SYSCON=y diff --git a/test/dm/core.c b/test/dm/core.c index ce31d86c7da..35ca689d646 100644 --- a/test/dm/core.c +++ b/test/dm/core.c @@ -1180,3 +1180,33 @@ static int dm_test_all_have_seq(struct unit_test_state *uts) return 0; } DM_TEST(dm_test_all_have_seq, UT_TESTF_SCAN_PDATA); + +static int dm_test_dma_offset(struct unit_test_state *uts) +{ + struct udevice *dev; + ofnode node; + + /* Make sure the bus's dma-ranges aren't taken into account here */ + node = ofnode_path("/mmio-bus@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); + ut_asserteq_64(0, dev->dma_offset); + + /* Device behind a bus with dma-ranges */ + node = ofnode_path("/mmio-bus@0/subnode@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev)); + ut_asserteq_64(-0x10000000ULL, dev->dma_offset); + + /* This one has no dma-ranges */ + node = ofnode_path("/mmio-bus@1"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); + node = ofnode_path("/mmio-bus@1/subnode@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev)); + ut_asserteq_64(0, dev->dma_offset); + + return 0; +} +DM_TEST(dm_test_dma_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- cgit v1.3.1 From 30b20e6b3f041d2a383d5a59303af21108afc1d7 Mon Sep 17 00:00:00 2001 From: Nicolas Saenz Julienne Date: Tue, 12 Jan 2021 13:55:27 +0100 Subject: dm: test: Add test case for dev_phys_to_bus()/dev_bus_to_phys() By reusing DT nodes already available in sandbox's test DT introduce a test to validate dev_phys_to_bus()/dev_bus_to_phys(). Signed-off-by: Nicolas Saenz Julienne Reviewed-by: Simon Glass Tested-by: Peter Robinson Signed-off-by: Matthias Brugger --- test/dm/Makefile | 1 + test/dm/phys2bus.c | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/dm/phys2bus.c (limited to 'test') diff --git a/test/dm/Makefile b/test/dm/Makefile index c363ca47a61..6275ec56eac 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -16,6 +16,7 @@ obj-$(CONFIG_UT_DM) += test-uclass.o obj-$(CONFIG_UT_DM) += core.o obj-$(CONFIG_UT_DM) += read.o +obj-$(CONFIG_UT_DM) += phys2bus.o ifneq ($(CONFIG_SANDBOX),) obj-$(CONFIG_ACPIGEN) += acpi.o obj-$(CONFIG_ACPIGEN) += acpigen.o diff --git a/test/dm/phys2bus.c b/test/dm/phys2bus.c new file mode 100644 index 00000000000..342f2fa8eba --- /dev/null +++ b/test/dm/phys2bus.c @@ -0,0 +1,37 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (c) 2020 Nicolas Saenz Julienne + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +static int dm_test_phys_to_bus(struct unit_test_state *uts) +{ + struct udevice *dev; + ofnode node; + + node = ofnode_path("/mmio-bus@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); + /* In this case it should be transparent, no dma-ranges in parent bus */ + ut_asserteq_addr((void*)0xfffffULL, (void*)dev_phys_to_bus(dev, 0xfffff)); + ut_asserteq_addr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0xfffff)); + + node = ofnode_path("/mmio-bus@0/subnode@0"); + ut_assert(ofnode_valid(node)); + ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev)); + ut_asserteq_addr((void*)0x100fffffULL, (void*)dev_phys_to_bus(dev, 0xfffff)); + ut_asserteq_addr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0x100fffff)); + + return 0; +} +DM_TEST(dm_test_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); -- cgit v1.3.1