blob: 81497df85ffd191c54026ead92cb907f24a4bfc9 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass6494d702014-02-26 15:59:18 -07002/*
3 * Copyright (c) 2013 Google, Inc
Simon Glass6494d702014-02-26 15:59:18 -07004 */
5
6#include <common.h>
Simon Glass6dd4b012019-12-06 21:41:38 -07007#include <dm/device.h>
Bin Menge601ab12018-10-10 22:06:57 -07008#include <dm/ofnode.h>
Simon Glass6dd4b012019-12-06 21:41:38 -07009#include <dm/read.h>
Masahiro Yamada766c28a2017-06-22 16:50:01 +090010#include <dm/util.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090011#include <linux/libfdt.h>
Simon Glass6494d702014-02-26 15:59:18 -070012#include <vsprintf.h>
13
Simon Glass6494d702014-02-26 15:59:18 -070014int list_count_items(struct list_head *head)
15{
16 struct list_head *node;
17 int count = 0;
18
19 list_for_each(node, head)
20 count++;
21
22 return count;
23}
Heiko Stübner27326c72017-02-18 19:46:21 +010024
Simon Glass95397382021-08-07 07:24:04 -060025#if CONFIG_IS_ENABLED(OF_REAL)
Simon Glass6dd4b012019-12-06 21:41:38 -070026int pci_get_devfn(struct udevice *dev)
27{
28 struct fdt_pci_addr addr;
29 int ret;
30
31 /* Extract the devfn from fdt_pci_addr */
32 ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG,
Simon Glassf69d3d62023-09-26 08:14:58 -060033 "reg", &addr, NULL);
Simon Glass6dd4b012019-12-06 21:41:38 -070034 if (ret) {
35 if (ret != -ENOENT)
36 return -EINVAL;
37 }
38
39 return addr.phys_hi & 0xff00;
40}
41#endif