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> 17*ee7f6428SMatt Spinler #include <phosphor-logging/log.hpp> 18*ee7f6428SMatt 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 28*ee7f6428SMatt Spinler using namespace phosphor::logging; 29*ee7f6428SMatt Spinler 30*ee7f6428SMatt Spinler constexpr auto SYSTEMD_SERVICE = "org.freedesktop.systemd1"; 31*ee7f6428SMatt Spinler constexpr auto SYSTEMD_OBJ_PATH = "/org/freedesktop/systemd1"; 32*ee7f6428SMatt Spinler constexpr auto SYSTEMD_INTERFACE = "org.freedesktop.systemd1.Manager"; 33*ee7f6428SMatt Spinler constexpr auto FAN_CONTROL_READY_TARGET = "obmc-fan-control-ready@0.target"; 34*ee7f6428SMatt Spinler 35*ee7f6428SMatt Spinler //Note: Future code will check 'mode' before starting control algorithm 36*ee7f6428SMatt Spinler Manager::Manager(sdbusplus::bus::bus& bus, 37*ee7f6428SMatt 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), 6257352a31SMatt Spinler std::make_unique<Zone>(_bus, z)); 6357352a31SMatt Spinler } 6457352a31SMatt Spinler 6557352a31SMatt Spinler break; 6657352a31SMatt Spinler } 6757352a31SMatt Spinler } 6857352a31SMatt Spinler 69*ee7f6428SMatt Spinler } 70*ee7f6428SMatt Spinler 71*ee7f6428SMatt Spinler 72*ee7f6428SMatt Spinler void Manager::doInit() 73*ee7f6428SMatt Spinler { 7457352a31SMatt Spinler for (auto& z: _zones) 7557352a31SMatt Spinler { 7657352a31SMatt Spinler z.second->setFullSpeed(); 7757352a31SMatt Spinler } 78*ee7f6428SMatt Spinler 79*ee7f6428SMatt Spinler auto delay = _powerOnDelay; 80*ee7f6428SMatt Spinler while (delay > 0) 81*ee7f6428SMatt Spinler { 82*ee7f6428SMatt Spinler delay = sleep(delay); 83e10416ecSMatt Spinler } 84e10416ecSMatt Spinler 85*ee7f6428SMatt Spinler startFanControlReadyTarget(); 86*ee7f6428SMatt Spinler } 87*ee7f6428SMatt Spinler 88*ee7f6428SMatt Spinler 89*ee7f6428SMatt Spinler void Manager::startFanControlReadyTarget() 90*ee7f6428SMatt Spinler { 91*ee7f6428SMatt Spinler auto method = _bus.new_method_call(SYSTEMD_SERVICE, 92*ee7f6428SMatt Spinler SYSTEMD_OBJ_PATH, 93*ee7f6428SMatt Spinler SYSTEMD_INTERFACE, 94*ee7f6428SMatt Spinler "StartUnit"); 95*ee7f6428SMatt Spinler 96*ee7f6428SMatt Spinler method.append(FAN_CONTROL_READY_TARGET); 97*ee7f6428SMatt Spinler method.append("replace"); 98*ee7f6428SMatt Spinler 99*ee7f6428SMatt Spinler auto response = _bus.call(method); 100*ee7f6428SMatt Spinler if (response.is_method_error()) 101*ee7f6428SMatt Spinler { 102*ee7f6428SMatt Spinler //TODO openbmc/openbmc#1555 create an elog 103*ee7f6428SMatt Spinler log<level::ERR>("Failed to start fan control ready target"); 104*ee7f6428SMatt Spinler throw std::runtime_error("Failed to start fan control ready target"); 105*ee7f6428SMatt Spinler } 106*ee7f6428SMatt Spinler } 107e10416ecSMatt Spinler 108e10416ecSMatt Spinler } 109e10416ecSMatt Spinler } 110e10416ecSMatt Spinler } 111