Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 6dd4b01 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 7 | #include <dm/device.h> |
Bin Meng | e601ab1 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 8 | #include <dm/ofnode.h> |
Simon Glass | 6dd4b01 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 9 | #include <dm/read.h> |
Masahiro Yamada | 766c28a | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 10 | #include <dm/util.h> |
Masahiro Yamada | b08c8c4 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 11 | #include <linux/libfdt.h> |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 12 | #include <vsprintf.h> |
| 13 | |
Simon Glass | 6494d70 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 14 | int 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übner | 27326c7 | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 24 | |
Simon Glass | 9539738 | 2021-08-07 07:24:04 -0600 | [diff] [blame] | 25 | #if CONFIG_IS_ENABLED(OF_REAL) |
Simon Glass | 6dd4b01 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 26 | int 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 Glass | f69d3d6 | 2023-09-26 08:14:58 -0600 | [diff] [blame] | 33 | "reg", &addr, NULL); |
Simon Glass | 6dd4b01 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 34 | if (ret) { |
| 35 | if (ret != -ENOENT) |
| 36 | return -EINVAL; |
| 37 | } |
| 38 | |
| 39 | return addr.phys_hi & 0xff00; |
| 40 | } |
| 41 | #endif |