dm: core: remove the duplicated function dm_ofnode_pre_reloc
[oweals/u-boot.git] / drivers / core / util.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * Copyright (c) 2013 Google, Inc
4  */
5
6 #include <common.h>
7 #include <dm/device.h>
8 #include <dm/ofnode.h>
9 #include <dm/read.h>
10 #include <dm/util.h>
11 #include <linux/libfdt.h>
12 #include <vsprintf.h>
13
14 #ifdef CONFIG_DM_WARN
15 void dm_warn(const char *fmt, ...)
16 {
17         va_list args;
18
19         va_start(args, fmt);
20         vprintf(fmt, args);
21         va_end(args);
22 }
23 #endif
24
25 int list_count_items(struct list_head *head)
26 {
27         struct list_head *node;
28         int count = 0;
29
30         list_for_each(node, head)
31                 count++;
32
33         return count;
34 }
35
36 #if !CONFIG_IS_ENABLED(OF_PLATDATA)
37 int pci_get_devfn(struct udevice *dev)
38 {
39         struct fdt_pci_addr addr;
40         int ret;
41
42         /* Extract the devfn from fdt_pci_addr */
43         ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
44                                    "reg", &addr);
45         if (ret) {
46                 if (ret != -ENOENT)
47                         return -EINVAL;
48         }
49
50         return addr.phys_hi & 0xff00;
51 }
52 #endif