blob: 6d4b6934b157607a65bf7e475509d0d385d82b6c [file] [log] [blame]
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -07001/*
2 * Copyright 2019 Google Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "p2a.hpp"
18
19#include "pci.hpp"
20
21namespace host_tool
22{
23
24bool P2aDataHandler::sendContents(const std::string& input,
25 std::uint16_t session)
26{
Patrick Venture24141612019-05-03 17:59:18 -070027 PciDevice result;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070028 PciUtilImpl pci;
29 PciFilter filter;
30
31 filter.vid = aspeedVendorId;
32 filter.did = aspeedDeviceId;
33
Patrick Venture24141612019-05-03 17:59:18 -070034 /* Find the ASPEED PCI device entry we want. */
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070035 auto output = pci.getPciDevices(filter);
36 for (const auto& d : output)
37 {
Patrick Venture24141612019-05-03 17:59:18 -070038 std::fprintf(stderr, "[0x%x 0x%x] ", d.vid, d.did);
39
40 /* Verify it's a memory-based bar -- we want bar1. */
41 pciaddr_t bar1 = d.bars[1];
42 if ((bar1 & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
43 {
44 /* We want it to not be IO-based access. */
45 continue;
46 }
47
48 result = d;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070049 }
Patrick Venture24141612019-05-03 17:59:18 -070050 std::fprintf(stderr, "\n");
51
52 /* We sent the open command before this, so the window should be open and
53 * the bridge enabled.
54 */
55 std::uint32_t value;
56 if (!io->read(result.bars[1] | aspeedP2aConfig, sizeof(value), &value))
57 {
58 if (0 == (value & p2ABridgeEnabled))
59 {
60 std::fprintf(stderr, "Bridge not enabled.\n");
61 return false;
62 }
63 }
64
65 std::fprintf(stderr, "The bridge is enabled!\n");
66
67 /* Read the configuration via blobs metadata (stat). */
68
69#if 0
70 /* Configure the mmio to point there. */
71 if (!io->IoWrite(bar | kAspeedP2aBridge, sizeof(phys), &phys)) {
72 // Failed to set it up, so fall back.
73 std::fprintf(stderr, "Failed to update the bridge address\n");
74 return false;
75 }
76#endif
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070077
78 return false;
79}
80
81} // namespace host_tool