blob: 108a3bc4dac14c41ae22466fe195595ab2b8babb [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
Simon Glass0b591e02019-12-06 21:41:38 -07006#include <dm/device.h>
Bin Mengdddc3a82018-10-10 22:06:57 -07007#include <dm/ofnode.h>
Simon Glass0b591e02019-12-06 21:41:38 -07008#include <dm/read.h>
Masahiro Yamada3247fdb2017-06-22 16:50:01 +09009#include <dm/util.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Simon Glassdd6ab882014-02-26 15:59:18 -070011#include <vsprintf.h>
12
Simon Glassdd6ab882014-02-26 15:59:18 -070013int list_count_items(struct list_head *head)
14{
15 struct list_head *node;
16 int count = 0;
17
18 list_for_each(node, head)
19 count++;
20
21 return count;
22}
Heiko Stübner9a2cdca2017-02-18 19:46:21 +010023
Simon Glass92882652021-08-07 07:24:04 -060024#if CONFIG_IS_ENABLED(OF_REAL)
Simon Glass0b591e02019-12-06 21:41:38 -070025int pci_get_devfn(struct udevice *dev)
26{
27 struct fdt_pci_addr addr;
28 int ret;
29
30 /* Extract the devfn from fdt_pci_addr */
31 ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
Simon Glass4289c262023-09-26 08:14:58 -060032 "reg", &addr, NULL);
Simon Glass0b591e02019-12-06 21:41:38 -070033 if (ret) {
34 if (ret != -ENOENT)
35 return -EINVAL;
36 }
37
38 return addr.phys_hi & 0xff00;
39}
40#endif