Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2013 Google, Inc |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 0b591e0 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 7 | #include <dm/device.h> |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 8 | #include <dm/ofnode.h> |
Simon Glass | 0b591e0 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 9 | #include <dm/read.h> |
Masahiro Yamada | 3247fdb | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 10 | #include <dm/util.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 11 | #include <linux/libfdt.h> |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 12 | #include <vsprintf.h> |
| 13 | |
Masahiro Yamada | 3247fdb | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 14 | #ifdef CONFIG_DM_WARN |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 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 | } |
Masahiro Yamada | 3247fdb | 2017-06-22 16:50:01 +0900 | [diff] [blame] | 23 | #endif |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 24 | |
Simon Glass | dd6ab88 | 2014-02-26 15:59:18 -0700 | [diff] [blame] | 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 | } |
Heiko Stübner | 9a2cdca | 2017-02-18 19:46:21 +0100 | [diff] [blame] | 35 | |
Marek Vasut | 7f18c34 | 2019-08-31 18:03:28 +0200 | [diff] [blame] | 36 | #if CONFIG_IS_ENABLED(OF_CONTROL) && !CONFIG_IS_ENABLED(OF_PLATDATA) |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 37 | bool dm_ofnode_pre_reloc(ofnode node) |
| 38 | { |
Patrick Delaunay | 0b025b8 | 2019-02-11 12:49:57 +0100 | [diff] [blame] | 39 | #if defined(CONFIG_SPL_BUILD) || defined(CONFIG_TPL_BUILD) |
| 40 | /* for SPL and TPL the remaining nodes after the fdtgrep 1st pass |
| 41 | * had property dm-pre-reloc or u-boot,dm-spl/tpl. |
| 42 | * They are removed in final dtb (fdtgrep 2nd pass) |
| 43 | */ |
| 44 | return true; |
| 45 | #else |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 46 | if (ofnode_read_bool(node, "u-boot,dm-pre-reloc")) |
| 47 | return true; |
Patrick Delaunay | d193718 | 2019-05-21 19:19:12 +0200 | [diff] [blame] | 48 | if (ofnode_read_bool(node, "u-boot,dm-pre-proper")) |
| 49 | return true; |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 50 | |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 51 | /* |
| 52 | * In regular builds individual spl and tpl handling both |
| 53 | * count as handled pre-relocation for later second init. |
| 54 | */ |
| 55 | if (ofnode_read_bool(node, "u-boot,dm-spl") || |
| 56 | ofnode_read_bool(node, "u-boot,dm-tpl")) |
| 57 | return true; |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 58 | |
| 59 | return false; |
Patrick Delaunay | 0b025b8 | 2019-02-11 12:49:57 +0100 | [diff] [blame] | 60 | #endif |
Bin Meng | dddc3a8 | 2018-10-10 22:06:57 -0700 | [diff] [blame] | 61 | } |
Marek Vasut | 7f18c34 | 2019-08-31 18:03:28 +0200 | [diff] [blame] | 62 | #endif |
Simon Glass | 0b591e0 | 2019-12-06 21:41:38 -0700 | [diff] [blame] | 63 | |
| 64 | #if !CONFIG_IS_ENABLED(OF_PLATDATA) |
| 65 | int pci_get_devfn(struct udevice *dev) |
| 66 | { |
| 67 | struct fdt_pci_addr addr; |
| 68 | int ret; |
| 69 | |
| 70 | /* Extract the devfn from fdt_pci_addr */ |
| 71 | ret = ofnode_read_pci_addr(dev_ofnode(dev), FDT_PCI_SPACE_CONFIG, |
| 72 | "reg", &addr); |
| 73 | if (ret) { |
| 74 | if (ret != -ENOENT) |
| 75 | return -EINVAL; |
| 76 | } |
| 77 | |
| 78 | return addr.phys_hi & 0xff00; |
| 79 | } |
| 80 | #endif |