blob: 5f9880a948d86028276e1d1d470605aaa759d2c7 [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;
Patrick Venture36bb4672019-05-07 09:42:56 -070030 bool found = false;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070031
32 filter.vid = aspeedVendorId;
33 filter.did = aspeedDeviceId;
34
Patrick Venture24141612019-05-03 17:59:18 -070035 /* Find the ASPEED PCI device entry we want. */
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070036 auto output = pci.getPciDevices(filter);
37 for (const auto& d : output)
38 {
Patrick Venture24141612019-05-03 17:59:18 -070039 std::fprintf(stderr, "[0x%x 0x%x] ", d.vid, d.did);
40
41 /* Verify it's a memory-based bar -- we want bar1. */
42 pciaddr_t bar1 = d.bars[1];
43 if ((bar1 & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
44 {
45 /* We want it to not be IO-based access. */
46 continue;
47 }
48
49 result = d;
Patrick Venture36bb4672019-05-07 09:42:56 -070050 found = true;
51 break;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070052 }
Patrick Venture36bb4672019-05-07 09:42:56 -070053
54 if (!found)
55 {
56 return false;
57 }
58
Patrick Venture24141612019-05-03 17:59:18 -070059 std::fprintf(stderr, "\n");
60
61 /* We sent the open command before this, so the window should be open and
62 * the bridge enabled.
63 */
64 std::uint32_t value;
65 if (!io->read(result.bars[1] | aspeedP2aConfig, sizeof(value), &value))
66 {
67 if (0 == (value & p2ABridgeEnabled))
68 {
69 std::fprintf(stderr, "Bridge not enabled.\n");
70 return false;
71 }
72 }
73
74 std::fprintf(stderr, "The bridge is enabled!\n");
75
76 /* Read the configuration via blobs metadata (stat). */
77
78#if 0
79 /* Configure the mmio to point there. */
80 if (!io->IoWrite(bar | kAspeedP2aBridge, sizeof(phys), &phys)) {
81 // Failed to set it up, so fall back.
82 std::fprintf(stderr, "Failed to update the bridge address\n");
83 return false;
84 }
85#endif
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070086
87 return false;
88}
89
90} // namespace host_tool