Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 1 | /* |
| 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 Venture | c73dce9 | 2019-05-07 11:32:44 -0700 | [diff] [blame] | 20 | #include "pci_handler.hpp" |
| 21 | |
| 22 | #include <cstring> |
Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 23 | |
| 24 | namespace host_tool |
| 25 | { |
| 26 | |
| 27 | bool P2aDataHandler::sendContents(const std::string& input, |
| 28 | std::uint16_t session) |
| 29 | { |
Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame] | 30 | PciDevice result; |
Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 31 | PciUtilImpl pci; |
| 32 | PciFilter filter; |
Patrick Venture | 36bb467 | 2019-05-07 09:42:56 -0700 | [diff] [blame] | 33 | bool found = false; |
Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 34 | |
| 35 | filter.vid = aspeedVendorId; |
| 36 | filter.did = aspeedDeviceId; |
| 37 | |
Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame] | 38 | /* Find the ASPEED PCI device entry we want. */ |
Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 39 | auto output = pci.getPciDevices(filter); |
| 40 | for (const auto& d : output) |
| 41 | { |
Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame] | 42 | 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 Venture | 36bb467 | 2019-05-07 09:42:56 -0700 | [diff] [blame] | 53 | found = true; |
| 54 | break; |
Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 55 | } |
Patrick Venture | 36bb467 | 2019-05-07 09:42:56 -0700 | [diff] [blame] | 56 | |
| 57 | if (!found) |
| 58 | { |
| 59 | return false; |
| 60 | } |
| 61 | |
Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame] | 62 | 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 Venture | c73dce9 | 2019-05-07 11:32:44 -0700 | [diff] [blame] | 80 | 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 Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame] | 91 | |
| 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 Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 100 | |
| 101 | return false; |
| 102 | } |
| 103 | |
| 104 | } // namespace host_tool |