blob: 91e93b0cf14a4a9aa7feddf20414437cad3fe33c [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassdd6ab882014-02-26 15:59:18 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glassdd6ab882014-02-26 15:59:18 -07004 */
5
6#include <common.h>
Simon Glass0b591e02019-12-06 21:41:38 -07007#include <dm/device.h>
Bin Mengdddc3a82018-10-10 22:06:57 -07008#include <dm/ofnode.h>
Simon Glass0b591e02019-12-06 21:41:38 -07009#include <dm/read.h>
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090010#include <dm/util.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070012#include <vsprintf.h>
13
Simon Glass85bf4f22020-10-03 11:31:26 -060014#if CONFIG_IS_ENABLED(DM_WARN)
Simon Glassdd6ab882014-02-26 15:59:18 -070015void 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}
Masahiro Yamada3247fdb2017-06-22 16:50:01 +090023#endif
Simon Glassdd6ab882014-02-26 15:59:18 -070024
Simon Glassdd6ab882014-02-26 15:59:18 -070025int 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}
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010035
Simon Glass0b591e02019-12-06 21:41:38 -070036#if !CONFIG_IS_ENABLED(OF_PLATDATA)
37int 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