blob: 1ee2150482c6003aea12a52afd44ff15e0658ad6 [file] [log] [blame]
Nicolas Saenz Julienne3524a5e2021-01-12 13:55:27 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright (c) 2020 Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
4 */
5
Nicolas Saenz Julienne3524a5e2021-01-12 13:55:27 +01006#include <dm.h>
7#include <mapmem.h>
8#include <phys2bus.h>
9#include <dm/device.h>
10#include <dm/ofnode.h>
11#include <dm/root.h>
12#include <dm/test.h>
13#include <dm/uclass-internal.h>
14#include <test/ut.h>
15
16static int dm_test_phys_to_bus(struct unit_test_state *uts)
17{
18 struct udevice *dev;
19 ofnode node;
20
21 node = ofnode_path("/mmio-bus@0");
22 ut_assert(ofnode_valid(node));
23 ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
24 /* In this case it should be transparent, no dma-ranges in parent bus */
25 ut_asserteq_addr((void*)0xfffffULL, (void*)dev_phys_to_bus(dev, 0xfffff));
26 ut_asserteq_addr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0xfffff));
27
28 node = ofnode_path("/mmio-bus@0/subnode@0");
29 ut_assert(ofnode_valid(node));
30 ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
31 ut_asserteq_addr((void*)0x100fffffULL, (void*)dev_phys_to_bus(dev, 0xfffff));
32 ut_asserteq_addr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0x100fffff));
33
34 return 0;
35}
36DM_TEST(dm_test_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);