blob: 5dcf6c9fc2fbe81a7f44562bc39f4edb4f686866 [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"
Patrick Venturec73dce92019-05-07 11:32:44 -070020#include "pci_handler.hpp"
21
22#include <cstring>
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070023
24namespace host_tool
25{
26
27bool P2aDataHandler::sendContents(const std::string& input,
28 std::uint16_t session)
29{
Patrick Venture24141612019-05-03 17:59:18 -070030 PciDevice result;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070031 PciUtilImpl pci;
32 PciFilter filter;
Patrick Venture36bb4672019-05-07 09:42:56 -070033 bool found = false;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070034
35 filter.vid = aspeedVendorId;
36 filter.did = aspeedDeviceId;
37
Patrick Venture24141612019-05-03 17:59:18 -070038 /* Find the ASPEED PCI device entry we want. */
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070039 auto output = pci.getPciDevices(filter);
40 for (const auto& d : output)
41 {
Patrick Venture24141612019-05-03 17:59:18 -070042 std::fprintf(stderr, "[0x%x 0x%x] ", d.vid, d.did);
43
44 /* Verify it's a memory-based bar -- we want bar1. */
45 pciaddr_t bar1 = d.bars[1];
46 if ((bar1 & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
47 {
48 /* We want it to not be IO-based access. */
49 continue;
50 }
51
52 result = d;
Patrick Venture36bb4672019-05-07 09:42:56 -070053 found = true;
54 break;
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -070055 }
Patrick Venture36bb4672019-05-07 09:42:56 -070056
57 if (!found)
58 {
59 return false;
60 }
61
Patrick Venture24141612019-05-03 17:59:18 -070062 std::fprintf(stderr, "\n");
63
64 /* We sent the open command before this, so the window should be open and
65 * the bridge enabled.
66 */
67 std::uint32_t value;
68 if (!io->read(result.bars[1] | aspeedP2aConfig, sizeof(value), &value))
69 {
70 if (0 == (value & p2ABridgeEnabled))
71 {
72 std::fprintf(stderr, "Bridge not enabled.\n");
73 return false;
74 }
75 }
76
77 std::fprintf(stderr, "The bridge is enabled!\n");
78
79 /* Read the configuration via blobs metadata (stat). */
Patrick Venturec73dce92019-05-07 11:32:44 -070080 ipmiblob::StatResponse stat = blob->getStat(session);
81 if (stat.metadata.size() != sizeof(blobs::PciConfigResponse))
82 {
83 std::fprintf(stderr, "Didn't receive expected size of metadata for "
84 "PCI Configuration response\n");
85 return false;
86 }
87
88 blobs::PciConfigResponse pciResp;
89 std::memcpy(&pciResp, stat.metadata.data(), sizeof(pciResp));
90 std::fprintf(stderr, "Received address: 0x%x\n", pciResp.address);
Patrick Venture24141612019-05-03 17:59:18 -070091
92#if 0
93 /* Configure the mmio to point there. */
94 if (!io->IoWrite(bar | kAspeedP2aBridge, sizeof(phys), &phys)) {
95 // Failed to set it up, so fall back.
96 std::fprintf(stderr, "Failed to update the bridge address\n");
97 return false;
98 }
99#endif
Patrick Ventureb5bf0fc2019-05-03 14:33:49 -0700100
101 return false;
102}
103
104} // namespace host_tool