1e10416ecSMatt Spinler /** 2e10416ecSMatt Spinler * Copyright © 2017 IBM Corporation 3e10416ecSMatt Spinler * 4e10416ecSMatt Spinler * Licensed under the Apache License, Version 2.0 (the "License"); 5e10416ecSMatt Spinler * you may not use this file except in compliance with the License. 6e10416ecSMatt Spinler * You may obtain a copy of the License at 7e10416ecSMatt Spinler * 8e10416ecSMatt Spinler * http://www.apache.org/licenses/LICENSE-2.0 9e10416ecSMatt Spinler * 10e10416ecSMatt Spinler * Unless required by applicable law or agreed to in writing, software 11e10416ecSMatt Spinler * distributed under the License is distributed on an "AS IS" BASIS, 12e10416ecSMatt Spinler * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13e10416ecSMatt Spinler * See the License for the specific language governing permissions and 14e10416ecSMatt Spinler * limitations under the License. 15e10416ecSMatt Spinler */ 1657352a31SMatt Spinler #include <algorithm> 17ee7f6428SMatt Spinler #include <phosphor-logging/log.hpp> 18ee7f6428SMatt Spinler #include <unistd.h> 19e10416ecSMatt Spinler #include "manager.hpp" 20e10416ecSMatt Spinler 21e10416ecSMatt Spinler namespace phosphor 22e10416ecSMatt Spinler { 23e10416ecSMatt Spinler namespace fan 24e10416ecSMatt Spinler { 25e10416ecSMatt Spinler namespace control 26e10416ecSMatt Spinler { 27e10416ecSMatt Spinler 28ee7f6428SMatt Spinler using namespace phosphor::logging; 29ee7f6428SMatt Spinler 30ee7f6428SMatt Spinler constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; 31ee7f6428SMatt Spinler constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; 32ee7f6428SMatt Spinler constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; 33ee7f6428SMatt Spinler constexpr auto FAN_CONTROL_READY_TARGET = "obmc-fan-control-ready@0.target"; 34ee7f6428SMatt Spinler 35ee7f6428SMatt Spinler //Note: Future code will check 'mode' before starting control algorithm 36ee7f6428SMatt Spinler Manager::Manager(sdbusplus::bus::bus& bus, 37ee7f6428SMatt Spinler Mode mode) : 38e10416ecSMatt Spinler _bus(bus) 39e10416ecSMatt Spinler { 4057352a31SMatt Spinler //Create the appropriate Zone objects based on the 4157352a31SMatt Spinler //actual system configuration. 4257352a31SMatt Spinler 4357352a31SMatt Spinler //Find the 1 ZoneGroup that meets all of its conditions 4457352a31SMatt Spinler for (auto& group : _zoneLayouts) 4557352a31SMatt Spinler { 4657352a31SMatt Spinler auto& conditions = std::get<conditionListPos>(group); 4757352a31SMatt Spinler 4857352a31SMatt Spinler if (std::all_of(conditions.begin(), conditions.end(), 4957352a31SMatt Spinler [](const auto& c) 5057352a31SMatt Spinler { 5157352a31SMatt Spinler //TODO: openbmc/openbmc#1500 5257352a31SMatt Spinler //Still need to actually evaluate the conditions 5357352a31SMatt Spinler return true; 5457352a31SMatt Spinler })) 5557352a31SMatt Spinler { 5657352a31SMatt Spinler //Create a Zone object for each zone in this group 5757352a31SMatt Spinler auto& zones = std::get<zoneListPos>(group); 5857352a31SMatt Spinler 5957352a31SMatt Spinler for (auto& z : zones) 6057352a31SMatt Spinler { 6157352a31SMatt Spinler _zones.emplace(std::get<zoneNumPos>(z), 62*14184131SMatthew Barth std::make_unique<Zone>(mode, _bus, z)); 6357352a31SMatt Spinler } 6457352a31SMatt Spinler 6557352a31SMatt Spinler break; 6657352a31SMatt Spinler } 6757352a31SMatt Spinler } 6857352a31SMatt Spinler 69ee7f6428SMatt Spinler } 70ee7f6428SMatt Spinler 71ee7f6428SMatt Spinler 72ee7f6428SMatt Spinler void Manager::doInit() 73ee7f6428SMatt Spinler { 7457352a31SMatt Spinler for (auto& z: _zones) 7557352a31SMatt Spinler { 7657352a31SMatt Spinler z.second->setFullSpeed(); 7757352a31SMatt Spinler } 78ee7f6428SMatt Spinler 79ee7f6428SMatt Spinler auto delay = _powerOnDelay; 80ee7f6428SMatt Spinler while (delay > 0) 81ee7f6428SMatt Spinler { 82ee7f6428SMatt Spinler delay = sleep(delay); 83e10416ecSMatt Spinler } 84e10416ecSMatt Spinler 85ee7f6428SMatt Spinler startFanControlReadyTarget(); 86ee7f6428SMatt Spinler } 87ee7f6428SMatt Spinler 88ee7f6428SMatt Spinler 89ee7f6428SMatt Spinler void Manager::startFanControlReadyTarget() 90ee7f6428SMatt Spinler { 91ee7f6428SMatt Spinler auto method = _bus.new_method_call(SYSTEMD_SERVICE, 92ee7f6428SMatt Spinler SYSTEMD_OBJ_PATH, 93ee7f6428SMatt Spinler SYSTEMD_INTERFACE, 94ee7f6428SMatt Spinler "StartUnit"); 95ee7f6428SMatt Spinler 96ee7f6428SMatt Spinler method.append(FAN_CONTROL_READY_TARGET); 97ee7f6428SMatt Spinler method.append("replace"); 98ee7f6428SMatt Spinler 99ee7f6428SMatt Spinler auto response = _bus.call(method); 100ee7f6428SMatt Spinler if (response.is_method_error()) 101ee7f6428SMatt Spinler { 102ee7f6428SMatt Spinler //TODO openbmc/openbmc#1555 create an elog 103ee7f6428SMatt Spinler log<level::ERR>("Failed to start fan control ready target"); 104ee7f6428SMatt Spinler throw std::runtime_error("Failed to start fan control ready target"); 105ee7f6428SMatt Spinler } 106ee7f6428SMatt Spinler } 107e10416ecSMatt Spinler 108e10416ecSMatt Spinler } 109e10416ecSMatt Spinler } 110e10416ecSMatt Spinler } 111