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" |
| 8 | |
| 9 | /* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters |
| 10 | Pos Address Data Mask with one register write per line. For example: |
| 11 | 0 0x283F 0x12345678 0xF0F0F0F0 |
| 12 | 0 0x283F 0x87654321 0x0F0F0F0F |
| 13 | Blank lines and comment lines beginning with # will be ignored. */ |
| 14 | |
| 15 | namespace openpower |
| 16 | { |
| 17 | namespace p9 |
| 18 | { |
| 19 | |
| 20 | using namespace openpower::cfam::access; |
| 21 | using namespace openpower::targeting; |
| 22 | using namespace openpower::util; |
| 23 | |
| 24 | void CFAMOverride() { |
| 25 | int pos = 0; |
| 26 | cfam_address_t address = 0; |
| 27 | cfam_data_t data = 0; |
| 28 | cfam_mask_t mask = 0; |
| 29 | |
| 30 | Targeting targets; |
| 31 | |
| 32 | std::string line; |
| 33 | |
| 34 | std::ifstream overrides("/var/lib/obmc/cfam_overrides"); |
| 35 | |
| 36 | if (overrides.is_open()) |
| 37 | { |
| 38 | while (std::getline(overrides,line)) |
| 39 | { |
| 40 | if (!line.empty()) |
| 41 | { |
| 42 | line.erase(0, line.find_first_not_of(" \t\r\n")); |
| 43 | if (!line.empty() && line.at(0) != '#') |
| 44 | { |
| 45 | mask = 0xFFFFFFFF; |
| 46 | if (sscanf(line.c_str(), "%x %hx %x %x", &pos, &address, |
| 47 | &data, &mask) >= 3) |
| 48 | { |
| 49 | const auto& target = targets.getTarget(pos); |
| 50 | writeRegWithMask(target, address, data, mask); |
| 51 | } |
| 52 | else |
| 53 | { |
| 54 | throw std::runtime_error("Cannot write to register - " |
| 55 | "not enough parameters given."); |
| 56 | } |
| 57 | } |
| 58 | } |
| 59 | } |
| 60 | overrides.close(); |
| 61 | } |
| 62 | |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | REGISTER_PROCEDURE("CFAMOverride", CFAMOverride); |
| 67 | |
| 68 | } |
| 69 | } |