coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
ecam.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 /*
4  * Derived from Cavium's BSD-3 Clause OCTEONTX-SDK-6.2.0.
5  */
6 
7 #define __SIMPLE_DEVICE__
8 
9 #include <device/pci_ops.h>
10 #include <device/pci_def.h>
11 #include <device/pci.h>
12 #include <soc/addressmap.h>
13 #include <soc/ecam.h>
14 
15 /**
16  * Get PCI BAR address from cavium specific extended capability.
17  * Use regular BAR if not found in extended capability space.
18  *
19  * @return The physical address of the BAR, zero on error
20  */
22 {
23  size_t cap_offset = pci_s_find_capability(dev, 0x14);
24  uint64_t h, l, ret = 0;
25  if (cap_offset) {
26  /* Found EA */
27  u8 es, bei;
28  u8 ne = pci_read_config8(dev, cap_offset + 2) & 0x3f;
29 
30  cap_offset += 4;
31  while (ne) {
32  uint32_t dw0 = pci_read_config32(dev, cap_offset);
33 
34  es = dw0 & 7;
35  bei = (dw0 >> 4) & 0xf;
36  if (bei == bar) {
37  h = 0;
38  l = pci_read_config32(dev, cap_offset + 4);
39  if (l & 2)
40  h = pci_read_config32(dev,
41  cap_offset + 12);
42  ret = (h << 32) | (l & ~0xfull);
43  break;
44  }
45  cap_offset += (es + 1) * 4;
46  ne--;
47  }
48  } else {
49  h = 0;
50  l = pci_read_config32(dev, bar * 4 + PCI_BASE_ADDRESS_0);
51  if (l & 4)
52  h = pci_read_config32(dev, bar * 4 + PCI_BASE_ADDRESS_0
53  + 4);
54  ret = (h << 32) | (l & ~0xfull);
55  }
56  return ret;
57 }
uint64_t ecam0_get_bar_val(pci_devfn_t dev, u8 bar)
Get PCI BAR address from cavium specific extended capability.
Definition: ecam.c:21
static __always_inline u32 pci_read_config32(const struct device *dev, u16 reg)
Definition: pci_ops.h:58
static __always_inline u8 pci_read_config8(const struct device *dev, u16 reg)
Definition: pci_ops.h:46
#define PCI_BASE_ADDRESS_0
Definition: pci_def.h:63
u16 pci_s_find_capability(pci_devfn_t dev, u16 cap)
Given a device, and a capability type, return the next matching capability.
Definition: pci_ops.c:72
u32 pci_devfn_t
Definition: pci_type.h:8
unsigned int uint32_t
Definition: stdint.h:14
unsigned long long uint64_t
Definition: stdint.h:17
uint8_t u8
Definition: stdint.h:45