blob: 89c69dbc2e559f08ed5c9bb1ef65dc8cd4712ef0 [file] [log] [blame]
Patrick Rudolphb94ecc42019-02-22 12:05:16 +01001/*
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älkki9c0e14e2019-01-23 16:46:35 +020020#define __SIMPLE_DEVICE__
21
Patrick Rudolphb94ecc42019-02-22 12:05:16 +010022#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 Rudolphb94ecc42019-02-22 12:05:16 +010027
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älkki9c0e14e2019-01-23 16:46:35 +020032 * @return The physical address of the BAR, zero on error
Patrick Rudolphb94ecc42019-02-22 12:05:16 +010033 */
Patrick Rudolphb94ecc42019-02-22 12:05:16 +010034uint64_t ecam0_get_bar_val(pci_devfn_t dev, u8 bar)
Patrick Rudolphb94ecc42019-02-22 12:05:16 +010035{
Kyösti Mälkki9c0e14e2019-01-23 16:46:35 +020036 size_t cap_offset = pci_s_find_capability(dev, 0x14);
Patrick Rudolphb94ecc42019-02-22 12:05:16 +010037 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}