blob: 6c773a7a80fc8fe52287bf7ef0ddbc86acda4853 [file] [log] [blame]
Matt Spinlere10416e2017-04-10 14:15:53 -05001/**
2 * Copyright © 2017 IBM Corporation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
Matt Spinler57352a32017-04-10 14:48:35 -050016#include <algorithm>
Matt Spinleree7f6422017-05-09 11:03:14 -050017#include <phosphor-logging/log.hpp>
18#include <unistd.h>
Matt Spinlere10416e2017-04-10 14:15:53 -050019#include "manager.hpp"
20
21namespace phosphor
22{
23namespace fan
24{
25namespace control
26{
27
Matt Spinleree7f6422017-05-09 11:03:14 -050028using namespace phosphor::logging;
29
30constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1";
31constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1";
32constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager";
33constexpr auto FAN_CONTROL_READY_TARGET = "obmc-fan-control-ready@0.target";
34
35//Note: Future code will check 'mode' before starting control algorithm
36Manager::Manager(sdbusplus::bus::bus& bus,
37 Mode mode) :
Matt Spinlere10416e2017-04-10 14:15:53 -050038 _bus(bus)
39{
Matt Spinler57352a32017-04-10 14:48:35 -050040 //Create the appropriate Zone objects based on the
41 //actual system configuration.
42
43 //Find the 1 ZoneGroup that meets all of its conditions
44 for (auto& group : _zoneLayouts)
45 {
46 auto& conditions = std::get<conditionListPos>(group);
47
48 if (std::all_of(conditions.begin(), conditions.end(),
49 [](const auto& c)
50 {
51 //TODO: openbmc/openbmc#1500
52 //Still need to actually evaluate the conditions
53 return true;
54 }))
55 {
56 //Create a Zone object for each zone in this group
57 auto& zones = std::get<zoneListPos>(group);
58
59 for (auto& z : zones)
60 {
61 _zones.emplace(std::get<zoneNumPos>(z),
62 std::make_unique<Zone>(_bus, z));
63 }
64
65 break;
66 }
67 }
68
Matt Spinleree7f6422017-05-09 11:03:14 -050069}
70
71
72void Manager::doInit()
73{
Matt Spinler57352a32017-04-10 14:48:35 -050074 for (auto& z: _zones)
75 {
76 z.second->setFullSpeed();
77 }
Matt Spinleree7f6422017-05-09 11:03:14 -050078
79 auto delay = _powerOnDelay;
80 while (delay > 0)
81 {
82 delay = sleep(delay);
83 }
84
85 startFanControlReadyTarget();
Matt Spinlere10416e2017-04-10 14:15:53 -050086}
87
88
Matt Spinleree7f6422017-05-09 11:03:14 -050089void Manager::startFanControlReadyTarget()
90{
91 auto method = _bus.new_method_call(SYSTEMD_SERVICE,
92 SYSTEMD_OBJ_PATH,
93 SYSTEMD_INTERFACE,
94 "StartUnit");
95
96 method.append(FAN_CONTROL_READY_TARGET);
97 method.append("replace");
98
99 auto response = _bus.call(method);
100 if (response.is_method_error())
101 {
102 //TODO openbmc/openbmc#1555 create an elog
103 log<level::ERR>("Failed to start fan control ready target");
104 throw std::runtime_error("Failed to start fan control ready target");
105 }
106}
107
Matt Spinlere10416e2017-04-10 14:15:53 -0500108}
109}
110}