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