summaryrefslogtreecommitdiffstats
path: root/procedures/p9/cfam_overrides.cpp
blob: a594e0c854dbdecbc28648c7fac353623dfd8657 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <fstream>
#include <sstream>
#include <iostream>
#include "cfam_access.hpp"
#include "p9_cfam.hpp"
#include "registration.hpp"
#include "targeting.hpp"
#include <phosphor-logging/elog.hpp>
#include <phosphor-logging/elog-errors.hpp>
#include <xyz/openbmc_project/Common/error.hpp>

/* File /var/lib/obmc/cfam_overrides requires whitespace-separated parameters
Pos Address Data Mask with one register write per line. For example:
0 0x283F 0x12345678 0xF0F0F0F0
0 0x283F 0x87654321 0x0F0F0F0F
Blank lines and comment lines beginning with # will be ignored. */

namespace openpower
{
namespace p9
{

using namespace openpower::cfam::access;
using namespace openpower::targeting;
using namespace openpower::util;

void CFAMOverride() {
    int pos = 0;
    cfam_address_t address = 0;
    cfam_data_t data = 0;
    cfam_mask_t mask = 0;

    Targeting targets;

    std::string line;

    std::ifstream overrides("/var/lib/obmc/cfam_overrides");

    if (overrides.is_open())
    {
        while (std::getline(overrides,line))
        {
            if (!line.empty())
            {
                line.erase(0, line.find_first_not_of(" \t\r\n"));
                if (!line.empty() && line.at(0) != '#')
                {
                    mask = 0xFFFFFFFF;
                    if (sscanf(line.c_str(), "%x %hx %x %x", &pos, &address,
                        &data, &mask) >= 3)
                    {
                        const auto& target = targets.getTarget(pos);
                        writeRegWithMask(target, address, data, mask);
                    }
                    else
                    {
                        namespace error =
                            sdbusplus::xyz::openbmc_project::Common::Error;
                        namespace metadata =
                            phosphor::logging::xyz::openbmc_project::Common;
                        phosphor::logging::elog<error::InvalidArgument>(
                            metadata::InvalidArgument::ARGUMENT_NAME("line"),
                            metadata::InvalidArgument::ARGUMENT_VALUE(line.c_str()));
                    }
                }
            }
        }
        overrides.close();
    }

    return;
}

REGISTER_PROCEDURE("CFAMOverride", CFAMOverride);

}
}
OpenPOWER on IntegriCloud