1 #include "cfam_access.hpp" 2 #include "p9_cfam.hpp" 3 #include "registration.hpp" 4 #include "targeting.hpp" 5 6 #include <phosphor-logging/elog-errors.hpp> 7 #include <phosphor-logging/elog.hpp> 8 #include <xyz/openbmc_project/Common/error.hpp> 9 10 #include <fstream> 11 #include <iostream> 12 #include <sstream> 13 14 /* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters 15 Pos Address Data Mask with one register write per line. For example: 16 0 0x283F 0x12345678 0xF0F0F0F0 17 0 0x283F 0x87654321 0x0F0F0F0F 18 Blank lines and comment lines beginning with # will be ignored. */ 19 20 namespace openpower 21 { 22 namespace p9 23 { 24 25 using namespace openpower::cfam::access; 26 using namespace openpower::targeting; 27 using namespace openpower::util; 28 29 void CFAMOverride() 30 { 31 size_t pos = 0; 32 cfam_address_t address = 0; 33 cfam_data_t data = 0; 34 cfam_mask_t mask = 0; 35 36 Targeting targets; 37 38 std::string line; 39 40 std::ifstream overrides("/var/lib/obmc/cfam_overrides"); 41 42 if (overrides.is_open()) 43 { 44 while (std::getline(overrides, line)) 45 { 46 if (!line.empty()) 47 { 48 line.erase(0, line.find_first_not_of(" \t\r\n")); 49 if (!line.empty() && line.at(0) != '#') 50 { 51 mask = 0xFFFFFFFF; 52 if (sscanf(line.c_str(), "%zu %hx %x %x", &pos, &address, 53 &data, &mask) >= 3) 54 { 55 const auto& target = targets.getTarget(pos); 56 writeRegWithMask(target, address, data, mask); 57 } 58 else 59 { 60 namespace error = 61 sdbusplus::xyz::openbmc_project::Common::Error; 62 namespace metadata = 63 phosphor::logging::xyz::openbmc_project::Common; 64 phosphor::logging::elog<error::InvalidArgument>( 65 metadata::InvalidArgument::ARGUMENT_NAME("line"), 66 metadata::InvalidArgument::ARGUMENT_VALUE( 67 line.c_str())); 68 } 69 } 70 } 71 } 72 overrides.close(); 73 } 74 75 return; 76 } 77 78 REGISTER_PROCEDURE("CFAMOverride", CFAMOverride) 79 80 } // namespace p9 81 } // namespace openpower 82