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