blob: ea311f578c9eba832ae25a153c3d5244e2ae2c95 [file] [log] [blame]
Michael Tritzbe407162017-03-30 16:52:24 -05001#include "cfam_access.hpp"
2#include "p9_cfam.hpp"
3#include "registration.hpp"
4#include "targeting.hpp"
Patrick Venturef78d9042018-11-01 15:39:53 -07005
6#include <fstream>
7#include <iostream>
Matt Spinlera231ceb2017-10-04 11:26:09 -05008#include <phosphor-logging/elog-errors.hpp>
Patrick Venturef78d9042018-11-01 15:39:53 -07009#include <phosphor-logging/elog.hpp>
10#include <sstream>
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050011#include <xyz/openbmc_project/Common/error.hpp>
Michael Tritzbe407162017-03-30 16:52:24 -050012
13/* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters
14Pos Address Data Mask with one register write per line. For example:
150 0x283F 0x12345678 0xF0F0F0F0
160 0x283F 0x87654321 0x0F0F0F0F
17Blank lines and comment lines beginning with # will be ignored. */
18
19namespace openpower
20{
21namespace p9
22{
23
24using namespace openpower::cfam::access;
25using namespace openpower::targeting;
26using namespace openpower::util;
27
Patrick Venturef78d9042018-11-01 15:39:53 -070028void CFAMOverride()
29{
Brad Bishop63508a72020-10-27 18:55:01 -040030 size_t pos = 0;
Michael Tritzbe407162017-03-30 16:52:24 -050031 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 Venturef78d9042018-11-01 15:39:53 -070043 while (std::getline(overrides, line))
Michael Tritzbe407162017-03-30 16:52:24 -050044 {
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 Bishop63508a72020-10-27 18:55:01 -040051 if (sscanf(line.c_str(), "%zu %hx %x %x", &pos, &address,
Patrick Venturef78d9042018-11-01 15:39:53 -070052 &data, &mask) >= 3)
Michael Tritzbe407162017-03-30 16:52:24 -050053 {
54 const auto& target = targets.getTarget(pos);
55 writeRegWithMask(target, address, data, mask);
56 }
57 else
58 {
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050059 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 Venturef78d9042018-11-01 15:39:53 -070065 metadata::InvalidArgument::ARGUMENT_VALUE(
66 line.c_str()));
Michael Tritzbe407162017-03-30 16:52:24 -050067 }
68 }
69 }
70 }
71 overrides.close();
72 }
73
74 return;
75}
76
Brad Bishop63508a72020-10-27 18:55:01 -040077REGISTER_PROCEDURE("CFAMOverride", CFAMOverride)
Michael Tritzbe407162017-03-30 16:52:24 -050078
Patrick Venturef78d9042018-11-01 15:39:53 -070079} // namespace p9
80} // namespace openpower