2 * This file is part of the coreboot project.
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * Derived from Cavium's BSD-3 Clause OCTEONTX-SDK-6.2.0.
17 #define __SIMPLE_DEVICE__
19 #include <device/pci_ops.h>
20 #include <device/pci_def.h>
21 #include <device/pci.h>
22 #include <soc/addressmap.h>
26 * Get PCI BAR address from cavium specific extended capability.
27 * Use regular BAR if not found in extended capability space.
29 * @return The physical address of the BAR, zero on error
31 uint64_t ecam0_get_bar_val(pci_devfn_t dev
, u8 bar
)
33 size_t cap_offset
= pci_s_find_capability(dev
, 0x14);
34 uint64_t h
, l
, ret
= 0;
38 u8 ne
= pci_read_config8(dev
, cap_offset
+ 2) & 0x3f;
42 uint32_t dw0
= pci_read_config32(dev
, cap_offset
);
45 bei
= (dw0
>> 4) & 0xf;
48 l
= pci_read_config32(dev
, cap_offset
+ 4);
50 h
= pci_read_config32(dev
,
52 ret
= (h
<< 32) | (l
& ~0xfull
);
55 cap_offset
+= (es
+ 1) * 4;
60 l
= pci_read_config32(dev
, bar
* 4 + PCI_BASE_ADDRESS_0
);
62 h
= pci_read_config32(dev
, bar
* 4 + PCI_BASE_ADDRESS_0
64 ret
= (h
<< 32) | (l
& ~0xfull
);