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