Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2018 Facebook, Inc. |
| 5 | * Copyright 2003-2017 Cavium Inc. <support@cavium.com> |
| 6 | * Copyright 2019 9elements Agency GmbH |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * Derived from Cavium's BSD-3 Clause OCTEONTX-SDK-6.2.0. |
| 18 | */ |
| 19 | |
Kyösti Mälkki | 9c0e14e | 2019-01-23 16:46:35 +0200 | [diff] [blame^] | 20 | #define __SIMPLE_DEVICE__ |
| 21 | |
Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
| 23 | #include <device/pci_def.h> |
| 24 | #include <device/pci.h> |
| 25 | #include <soc/addressmap.h> |
| 26 | #include <soc/ecam.h> |
Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Get PCI BAR address from cavium specific extended capability. |
| 30 | * Use regular BAR if not found in extended capability space. |
| 31 | * |
Kyösti Mälkki | 9c0e14e | 2019-01-23 16:46:35 +0200 | [diff] [blame^] | 32 | * @return The physical address of the BAR, zero on error |
Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 33 | */ |
Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 34 | uint64_t ecam0_get_bar_val(pci_devfn_t dev, u8 bar) |
Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 35 | { |
Kyösti Mälkki | 9c0e14e | 2019-01-23 16:46:35 +0200 | [diff] [blame^] | 36 | size_t cap_offset = pci_s_find_capability(dev, 0x14); |
Patrick Rudolph | b94ecc4 | 2019-02-22 12:05:16 +0100 | [diff] [blame] | 37 | uint64_t h, l, ret = 0; |
| 38 | if (cap_offset) { |
| 39 | /* Found EA */ |
| 40 | u8 es, bei; |
| 41 | u8 ne = pci_read_config8(dev, cap_offset + 2) & 0x3f; |
| 42 | |
| 43 | cap_offset += 4; |
| 44 | while (ne) { |
| 45 | uint32_t dw0 = pci_read_config32(dev, cap_offset); |
| 46 | |
| 47 | es = dw0 & 7; |
| 48 | bei = (dw0 >> 4) & 0xf; |
| 49 | if (bei == bar) { |
| 50 | h = 0; |
| 51 | l = pci_read_config32(dev, cap_offset + 4); |
| 52 | if (l & 2) |
| 53 | h = pci_read_config32(dev, |
| 54 | cap_offset + 12); |
| 55 | ret = (h << 32) | (l & ~0xfull); |
| 56 | break; |
| 57 | } |
| 58 | cap_offset += (es + 1) * 4; |
| 59 | ne--; |
| 60 | } |
| 61 | } else { |
| 62 | h = 0; |
| 63 | l = pci_read_config32(dev, bar * 4 + PCI_BASE_ADDRESS_0); |
| 64 | if (l & 4) |
| 65 | h = pci_read_config32(dev, bar * 4 + PCI_BASE_ADDRESS_0 |
| 66 | + 4); |
| 67 | ret = (h << 32) | (l & ~0xfull); |
| 68 | } |
| 69 | return ret; |
| 70 | } |