| 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" | 
|  | 20 |  | 
|  | 21 | namespace host_tool | 
|  | 22 | { | 
|  | 23 |  | 
|  | 24 | bool P2aDataHandler::sendContents(const std::string& input, | 
|  | 25 | std::uint16_t session) | 
|  | 26 | { | 
| Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame^] | 27 | PciDevice result; | 
| Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 28 | PciUtilImpl pci; | 
|  | 29 | PciFilter filter; | 
|  | 30 |  | 
|  | 31 | filter.vid = aspeedVendorId; | 
|  | 32 | filter.did = aspeedDeviceId; | 
|  | 33 |  | 
| Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame^] | 34 | /* Find the ASPEED PCI device entry we want. */ | 
| Patrick Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 35 | auto output = pci.getPciDevices(filter); | 
|  | 36 | for (const auto& d : output) | 
|  | 37 | { | 
| Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame^] | 38 | 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 Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 49 | } | 
| Patrick Venture | 2414161 | 2019-05-03 17:59:18 -0700 | [diff] [blame^] | 50 | 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 Venture | b5bf0fc | 2019-05-03 14:33:49 -0700 | [diff] [blame] | 77 |  | 
|  | 78 | return false; | 
|  | 79 | } | 
|  | 80 |  | 
|  | 81 | } // namespace host_tool |