Nicolas Saenz Julienne | 22b7f7e | 2021-01-12 13:55:23 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de> |
| 4 | */ |
| 5 | |
Nicolas Saenz Julienne | 22b7f7e | 2021-01-12 13:55:23 +0100 | [diff] [blame] | 6 | #include <dm.h> |
| 7 | #include <dm/device.h> |
| 8 | #include <dm/ofnode.h> |
| 9 | #include <dm/root.h> |
| 10 | #include <dm/test.h> |
| 11 | #include <dm/uclass-internal.h> |
| 12 | #include <test/ut.h> |
| 13 | |
| 14 | static int dm_test_dma_ranges(struct unit_test_state *uts) |
| 15 | { |
| 16 | struct udevice *dev; |
| 17 | phys_addr_t cpu; |
| 18 | dma_addr_t bus; |
| 19 | ofnode node; |
| 20 | u64 size; |
| 21 | |
| 22 | /* dma-ranges are on the device's node */ |
| 23 | node = ofnode_path("/mmio-bus@0"); |
| 24 | ut_assert(ofnode_valid(node)); |
| 25 | ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); |
| 26 | ut_assertok(dev_get_dma_range(dev, &cpu, &bus, &size)); |
| 27 | ut_asserteq_64(0x40000, size); |
| 28 | ut_asserteq_64(0x0, cpu); |
| 29 | ut_asserteq_64(0x10000000, bus); |
| 30 | |
| 31 | /* dma-ranges are on the bus' node */ |
| 32 | node = ofnode_path("/mmio-bus@0/subnode@0"); |
| 33 | ut_assert(ofnode_valid(node)); |
| 34 | ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev)); |
| 35 | ut_assertok(dev_get_dma_range(dev, &cpu, &bus, &size)); |
| 36 | ut_asserteq_64(0x40000, size); |
| 37 | ut_asserteq_64(0x0, cpu); |
| 38 | ut_asserteq_64(0x10000000, bus); |
| 39 | |
| 40 | /* No dma-ranges available */ |
| 41 | node = ofnode_path("/mmio-bus@1"); |
| 42 | ut_assert(ofnode_valid(node)); |
| 43 | ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev)); |
| 44 | ut_asserteq(-ENOENT, dev_get_dma_range(dev, &cpu, &bus, &size)); |
| 45 | |
| 46 | return 0; |
| 47 | } |
Simon Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame^] | 48 | DM_TEST(dm_test_dma_ranges, UTF_SCAN_PDATA | UTF_SCAN_FDT); |