blob: 40738ac5e391eecdf8c871a098393a9b059fd5f3 [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
Matt Spinlera231ceb2017-10-04 11:26:09 -05006#include <phosphor-logging/elog-errors.hpp>
Patrick Venturef78d9042018-11-01 15:39:53 -07007#include <phosphor-logging/elog.hpp>
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -05008#include <xyz/openbmc_project/Common/error.hpp>
Michael Tritzbe407162017-03-30 16:52:24 -05009
Brad Bishop5e5d4452020-10-27 19:46:13 -040010#include <fstream>
11#include <iostream>
12#include <sstream>
13
Michael Tritzbe407162017-03-30 16:52:24 -050014/* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters
15Pos Address Data Mask with one register write per line. For example:
160 0x283F 0x12345678 0xF0F0F0F0
170 0x283F 0x87654321 0x0F0F0F0F
18Blank lines and comment lines beginning with # will be ignored. */
19
20namespace openpower
21{
22namespace p9
23{
24
25using namespace openpower::cfam::access;
26using namespace openpower::targeting;
27using namespace openpower::util;
28
Patrick Venturef78d9042018-11-01 15:39:53 -070029void CFAMOverride()
30{
Brad Bishop63508a72020-10-27 18:55:01 -040031 size_t pos = 0;
Michael Tritzbe407162017-03-30 16:52:24 -050032 cfam_address_t address = 0;
33 cfam_data_t data = 0;
34 cfam_mask_t mask = 0;
35
36 Targeting targets;
37
38 std::string line;
39
40 std::ifstream overrides("/var/lib/obmc/cfam_overrides");
41
42 if (overrides.is_open())
43 {
Patrick Venturef78d9042018-11-01 15:39:53 -070044 while (std::getline(overrides, line))
Michael Tritzbe407162017-03-30 16:52:24 -050045 {
46 if (!line.empty())
47 {
48 line.erase(0, line.find_first_not_of(" \t\r\n"));
49 if (!line.empty() && line.at(0) != '#')
50 {
51 mask = 0xFFFFFFFF;
Brad Bishop63508a72020-10-27 18:55:01 -040052 if (sscanf(line.c_str(), "%zu %hx %x %x", &pos, &address,
Patrick Venturef78d9042018-11-01 15:39:53 -070053 &data, &mask) >= 3)
Michael Tritzbe407162017-03-30 16:52:24 -050054 {
55 const auto& target = targets.getTarget(pos);
56 writeRegWithMask(target, address, data, mask);
57 }
58 else
59 {
Dhruvaraj Subhashchandran7ce535c2017-05-15 05:06:36 -050060 namespace error =
61 sdbusplus::xyz::openbmc_project::Common::Error;
62 namespace metadata =
63 phosphor::logging::xyz::openbmc_project::Common;
64 phosphor::logging::elog<error::InvalidArgument>(
65 metadata::InvalidArgument::ARGUMENT_NAME("line"),
Patrick Venturef78d9042018-11-01 15:39:53 -070066 metadata::InvalidArgument::ARGUMENT_VALUE(
67 line.c_str()));
Michael Tritzbe407162017-03-30 16:52:24 -050068 }
69 }
70 }
71 }
72 overrides.close();
73 }
74
75 return;
76}
77
Brad Bishop63508a72020-10-27 18:55:01 -040078REGISTER_PROCEDURE("CFAMOverride", CFAMOverride)
Michael Tritzbe407162017-03-30 16:52:24 -050079
Patrick Venturef78d9042018-11-01 15:39:53 -070080} // namespace p9
81} // namespace openpower