blob: 342f2fa8ebaa92553312d8f2cd656e012ad09c85 [file] [log] [blame]
Nicolas Saenz Julienne30b20e62021-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
6#include <common.h>
7#include <dm.h>
8#include <mapmem.h>
9#include <phys2bus.h>
10#include <dm/device.h>
11#include <dm/ofnode.h>
12#include <dm/root.h>
13#include <dm/test.h>
14#include <dm/uclass-internal.h>
15#include <test/ut.h>
16
17static int dm_test_phys_to_bus(struct unit_test_state *uts)
18{
19 struct udevice *dev;
20 ofnode node;
21
22 node = ofnode_path("/mmio-bus@0");
23 ut_assert(ofnode_valid(node));
24 ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_BUS, node, &dev));
25 /* In this case it should be transparent, no dma-ranges in parent bus */
26 ut_asserteq_addr((void*)0xfffffULL, (void*)dev_phys_to_bus(dev, 0xfffff));
27 ut_asserteq_addr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0xfffff));
28
29 node = ofnode_path("/mmio-bus@0/subnode@0");
30 ut_assert(ofnode_valid(node));
31 ut_assertok(uclass_get_device_by_ofnode(UCLASS_TEST_FDT, node, &dev));
32 ut_asserteq_addr((void*)0x100fffffULL, (void*)dev_phys_to_bus(dev, 0xfffff));
33 ut_asserteq_addr((void*)0xfffffULL, (void*)(ulong)dev_bus_to_phys(dev, 0x100fffff));
34
35 return 0;
36}
37DM_TEST(dm_test_phys_to_bus, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);