blob: 2e1d64f26b976672b1a7545c4f4f17d0df8d375b [file] [log] [blame]
/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#pragma once
#include <pldm-oem-google.h>
#include <sdbusplus/bus.hpp>
#include <chrono>
#include <cstddef>
#include <cstdint>
#include <exception>
#include <optional>
#include <string>
namespace pldm_oem_google
{
namespace soc_reset_me
{
// Define the SoC Id
enum class SocId : int
{
cnDefault = 0,
cn1 = 1,
cn2 = 2,
};
// PeerSoCId which can be set with pldmd's command line --instance parameter
// Can only be set once which is expected set by pldmd at startup
// if not set, will be default CN_Default
class PeerSoCId
{
public:
static bool setWithPldmdInstanceParam(const std::string& instance);
static SocId value(void)
{
return socId.value_or(SocId::cnDefault);
}
static bool isDefault(void)
{
return !socId.has_value();
}
private:
friend class PeerSoCIdTest;
static bool Set(SocId id)
{
if (socId)
{
return false;
}
socId.emplace(id);
return true;
}
static std::optional<SocId> socId;
};
struct ResetDBusParams
{
const char* conn;
const char* path;
const char* intf;
const char* prop;
};
const ResetDBusParams* cn1DbusParams(void);
const ResetDBusParams* cn2DbusParams(void);
class SocResetMeHandler
{
public:
SocResetMeHandler(SocId id, sdbusplus::bus_t&& b);
~SocResetMeHandler() = default;
virtual void
handle(uint8_t requesterTid,
const struct pldm_event_oem_google_soc_reset_me* resetMeMsg,
size_t resetMeMsgLen);
protected:
friend class SocResetMeHandlerTest;
using ResetTimeStamp = std::chrono::time_point<std::chrono::steady_clock>;
virtual void resetSoC(uint16_t resetType);
virtual std::string requestedHostTransition(uint16_t resetType);
virtual void logRequest(uint64_t internalInfo, uint16_t resetType,
uint32_t quiescentPeriod,
const std::string& resetReason) const;
virtual void logRequestIgnored(const ResetTimeStamp& requestTime) const;
virtual void logRequestIssued(const ResetTimeStamp& requestTime) const;
const SocId socId;
const ResetDBusParams* dbusParams;
sdbusplus::bus_t bus;
ResetTimeStamp quiescentEnd;
};
class InvalidSoCIdException : public std::exception
{
public:
InvalidSoCIdException(int invalidId) :
errorMessage("SoC ID " + std::to_string(invalidId) + " is invalid")
{}
const char* what() const noexcept override
{
return errorMessage.c_str();
}
private:
std::string errorMessage;
};
} // namespace soc_reset_me
} // namespace pldm_oem_google