blob: a594e0c854dbdecbc28648c7fac353623dfd8657 [file] [log] [blame]
Michael Tritzbe407162017-03-30 16:52:24 -05001#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 Spinlera231ceb2017-10-04 11:26:09 -05008#include <phosphor-logging/elog.hpp>
9#include <phosphor-logging/elog-errors.hpp>
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050010#include <xyz/openbmc_project/Common/error.hpp>
Michael Tritzbe407162017-03-30 16:52:24 -050011
12/* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters
13Pos Address Data Mask with one register write per line. For example:
140 0x283F 0x12345678 0xF0F0F0F0
150 0x283F 0x87654321 0x0F0F0F0F
16Blank lines and comment lines beginning with # will be ignored. */
17
18namespace openpower
19{
20namespace p9
21{
22
23using namespace openpower::cfam::access;
24using namespace openpower::targeting;
25using namespace openpower::util;
26
27void 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 Subhashchandran7ce535c2017-05-15 05:06:36 -050057 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 Tritzbe407162017-03-30 16:52:24 -050064 }
65 }
66 }
67 }
68 overrides.close();
69 }
70
71 return;
72}
73
74REGISTER_PROCEDURE("CFAMOverride", CFAMOverride);
75
76}
77}