1b5bf0fc2SPatrick Venture /* 2b5bf0fc2SPatrick Venture * Copyright 2019 Google Inc. 3b5bf0fc2SPatrick Venture * 4b5bf0fc2SPatrick Venture * Licensed under the Apache License, Version 2.0 (the "License"); 5b5bf0fc2SPatrick Venture * you may not use this file except in compliance with the License. 6b5bf0fc2SPatrick Venture * You may obtain a copy of the License at 7b5bf0fc2SPatrick Venture * 8b5bf0fc2SPatrick Venture * http://www.apache.org/licenses/LICENSE-2.0 9b5bf0fc2SPatrick Venture * 10b5bf0fc2SPatrick Venture * Unless required by applicable law or agreed to in writing, software 11b5bf0fc2SPatrick Venture * distributed under the License is distributed on an "AS IS" BASIS, 12b5bf0fc2SPatrick Venture * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13b5bf0fc2SPatrick Venture * See the License for the specific language governing permissions and 14b5bf0fc2SPatrick Venture * limitations under the License. 15b5bf0fc2SPatrick Venture */ 16b5bf0fc2SPatrick Venture 17b5bf0fc2SPatrick Venture #include "p2a.hpp" 18b5bf0fc2SPatrick Venture 19b5bf0fc2SPatrick Venture #include "pci.hpp" 20b5bf0fc2SPatrick Venture 21b5bf0fc2SPatrick Venture namespace host_tool 22b5bf0fc2SPatrick Venture { 23b5bf0fc2SPatrick Venture 24b5bf0fc2SPatrick Venture bool P2aDataHandler::sendContents(const std::string& input, 25b5bf0fc2SPatrick Venture std::uint16_t session) 26b5bf0fc2SPatrick Venture { 2724141611SPatrick Venture PciDevice result; 28b5bf0fc2SPatrick Venture PciUtilImpl pci; 29b5bf0fc2SPatrick Venture PciFilter filter; 30*36bb4670SPatrick Venture bool found = false; 31b5bf0fc2SPatrick Venture 32b5bf0fc2SPatrick Venture filter.vid = aspeedVendorId; 33b5bf0fc2SPatrick Venture filter.did = aspeedDeviceId; 34b5bf0fc2SPatrick Venture 3524141611SPatrick Venture /* Find the ASPEED PCI device entry we want. */ 36b5bf0fc2SPatrick Venture auto output = pci.getPciDevices(filter); 37b5bf0fc2SPatrick Venture for (const auto& d : output) 38b5bf0fc2SPatrick Venture { 3924141611SPatrick Venture std::fprintf(stderr, "[0x%x 0x%x] ", d.vid, d.did); 4024141611SPatrick Venture 4124141611SPatrick Venture /* Verify it's a memory-based bar -- we want bar1. */ 4224141611SPatrick Venture pciaddr_t bar1 = d.bars[1]; 4324141611SPatrick Venture if ((bar1 & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO) 4424141611SPatrick Venture { 4524141611SPatrick Venture /* We want it to not be IO-based access. */ 4624141611SPatrick Venture continue; 47b5bf0fc2SPatrick Venture } 48b5bf0fc2SPatrick Venture 4924141611SPatrick Venture result = d; 50*36bb4670SPatrick Venture found = true; 51*36bb4670SPatrick Venture break; 5224141611SPatrick Venture } 53*36bb4670SPatrick Venture 54*36bb4670SPatrick Venture if (!found) 55*36bb4670SPatrick Venture { 56*36bb4670SPatrick Venture return false; 57*36bb4670SPatrick Venture } 58*36bb4670SPatrick Venture 5924141611SPatrick Venture std::fprintf(stderr, "\n"); 6024141611SPatrick Venture 6124141611SPatrick Venture /* We sent the open command before this, so the window should be open and 6224141611SPatrick Venture * the bridge enabled. 6324141611SPatrick Venture */ 6424141611SPatrick Venture std::uint32_t value; 6524141611SPatrick Venture if (!io->read(result.bars[1] | aspeedP2aConfig, sizeof(value), &value)) 6624141611SPatrick Venture { 6724141611SPatrick Venture if (0 == (value & p2ABridgeEnabled)) 6824141611SPatrick Venture { 6924141611SPatrick Venture std::fprintf(stderr, "Bridge not enabled.\n"); 7024141611SPatrick Venture return false; 7124141611SPatrick Venture } 7224141611SPatrick Venture } 7324141611SPatrick Venture 7424141611SPatrick Venture std::fprintf(stderr, "The bridge is enabled!\n"); 7524141611SPatrick Venture 7624141611SPatrick Venture /* Read the configuration via blobs metadata (stat). */ 7724141611SPatrick Venture 7824141611SPatrick Venture #if 0 7924141611SPatrick Venture /* Configure the mmio to point there. */ 8024141611SPatrick Venture if (!io->IoWrite(bar | kAspeedP2aBridge, sizeof(phys), &phys)) { 8124141611SPatrick Venture // Failed to set it up, so fall back. 8224141611SPatrick Venture std::fprintf(stderr, "Failed to update the bridge address\n"); 8324141611SPatrick Venture return false; 8424141611SPatrick Venture } 8524141611SPatrick Venture #endif 8624141611SPatrick Venture 87b5bf0fc2SPatrick Venture return false; 88b5bf0fc2SPatrick Venture } 89b5bf0fc2SPatrick Venture 90b5bf0fc2SPatrick Venture } // namespace host_tool 91