ams: mark ams::Result [[nodiscard]] (partially complete).
NOTE: This work is not yet fully complete; kernel is done, but it was taking an exceedingly long time to get through libstratosphere. Thus, I've temporarily added -Wno-error=unused-result for libstratosphere/stratosphere. All warnings should be fixed to do the same thing Nintendo does as relevant, but this is taking a phenomenally long time and is not actually the most important work to do, so it can be put off for some time to prioritize other tasks for 21.0.0 support.
This commit is contained in:
@@ -53,7 +53,7 @@ namespace ams {
|
||||
return (v >> ofs) & ~(~BaseType() << num);
|
||||
}
|
||||
public:
|
||||
static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType MakeValue(BaseType module, BaseType description) {
|
||||
return (module) | (description << ModuleBits);
|
||||
}
|
||||
|
||||
@@ -63,23 +63,23 @@ namespace ams {
|
||||
static_assert(description < (1 << DescriptionBits), "Invalid Description");
|
||||
};
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetModuleFromValue(BaseType value) {
|
||||
return GetBitsValue(value, 0, ModuleBits);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetDescriptionFromValue(BaseType value) {
|
||||
return GetBitsValue(value, ModuleBits, DescriptionBits);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType GetReservedFromValue(BaseType value) {
|
||||
return GetBitsValue(value, ModuleBits + DescriptionBits, ReservedBits);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType MaskReservedFromValue(BaseType value) {
|
||||
return value & ~(~(~BaseType() << ReservedBits) << (ModuleBits + DescriptionBits));
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE BaseType MergeValueWithReserved(BaseType value, BaseType reserved) {
|
||||
return (value << 0) | (reserved << (ModuleBits + DescriptionBits));
|
||||
}
|
||||
};
|
||||
@@ -90,8 +90,8 @@ namespace ams {
|
||||
using BaseType = typename ResultTraits::BaseType;
|
||||
static constexpr BaseType SuccessValue = ResultTraits::SuccessValue;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); }
|
||||
constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE BaseType GetModule(this auto const &self) { return ResultTraits::GetModuleFromValue(self.GetValue()); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE BaseType GetDescription(this auto const &self) { return ResultTraits::GetDescriptionFromValue(self.GetValue()); }
|
||||
};
|
||||
|
||||
class ResultInternalAccessor;
|
||||
@@ -100,7 +100,7 @@ namespace ams {
|
||||
|
||||
class ResultSuccess;
|
||||
|
||||
class Result final : public result::impl::ResultBase {
|
||||
class [[nodiscard]] Result final : public result::impl::ResultBase {
|
||||
friend class result::impl::ResultInternalAccessor;
|
||||
public:
|
||||
using Base = typename result::impl::ResultBase;
|
||||
@@ -115,16 +115,17 @@ namespace ams {
|
||||
constexpr ALWAYS_INLINE Result(typename Base::BaseType v) : m_value(v) { static_assert(std::is_same<typename Base::BaseType, ::Result>::value); }
|
||||
|
||||
constexpr ALWAYS_INLINE operator ResultSuccess() const;
|
||||
static constexpr ALWAYS_INLINE bool CanAccept(Result) { return true; }
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsSuccess() const { return m_value == Base::SuccessValue; }
|
||||
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); }
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); }
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE bool CanAccept(Result) { return true; }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetInnerValue() const { return ::ams::result::impl::ResultTraits::MaskReservedFromValue(m_value); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return m_value == Base::SuccessValue; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetModule() const { return Base::GetModule(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetDescription() const { return Base::GetDescription(); }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return m_value; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetInnerValue() const { return ::ams::result::impl::ResultTraits::MaskReservedFromValue(m_value); }
|
||||
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return m_value; }
|
||||
};
|
||||
static_assert(sizeof(Result) == sizeof(Result::Base::BaseType), "sizeof(Result) == sizeof(Result::Base::BaseType)");
|
||||
static_assert(std::is_trivially_destructible<Result>::value, "std::is_trivially_destructible<Result>::value");
|
||||
@@ -137,20 +138,20 @@ namespace ams {
|
||||
|
||||
class ResultInternalAccessor {
|
||||
public:
|
||||
static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
return Result(value);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE ResultTraits::BaseType GetReserved(Result result) {
|
||||
return ResultTraits::GetReservedFromValue(result.m_value);
|
||||
}
|
||||
|
||||
static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE Result MergeReserved(Result result, ResultTraits::BaseType reserved) {
|
||||
return Result(ResultTraits::MergeValueWithReserved(ResultTraits::MaskReservedFromValue(result.m_value), reserved));
|
||||
}
|
||||
};
|
||||
|
||||
constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE Result MakeResult(ResultTraits::BaseType value) {
|
||||
return ResultInternalAccessor::MakeResult(value);
|
||||
}
|
||||
|
||||
@@ -161,12 +162,12 @@ namespace ams {
|
||||
using Base = typename result::impl::ResultBase;
|
||||
public:
|
||||
constexpr ALWAYS_INLINE operator Result() const { return result::impl::MakeResult(Base::SuccessValue); }
|
||||
static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); }
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE bool CanAccept(Result result) { return result.IsSuccess(); }
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsSuccess() const { return true; }
|
||||
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return true; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Base::SuccessValue; }
|
||||
};
|
||||
|
||||
namespace result::impl {
|
||||
@@ -203,10 +204,10 @@ namespace ams {
|
||||
return ResultSuccess();
|
||||
}
|
||||
|
||||
constexpr ALWAYS_INLINE bool IsSuccess() const { return false; }
|
||||
constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsSuccess() const { return false; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE bool IsFailure() const { return !this->IsSuccess(); }
|
||||
|
||||
constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Value; }
|
||||
[[nodiscard]] constexpr ALWAYS_INLINE typename Base::BaseType GetValue() const { return Value; }
|
||||
};
|
||||
|
||||
template<ResultTraits::BaseType _Module, ResultTraits::BaseType DescStart, ResultTraits::BaseType DescEnd>
|
||||
@@ -223,7 +224,7 @@ namespace ams {
|
||||
static constexpr typename ResultTraits::BaseType StartValue = ResultTraits::MakeStaticValue<Module, DescriptionStart>::value;
|
||||
static constexpr typename ResultTraits::BaseType EndValue = ResultTraits::MakeStaticValue<Module, DescriptionEnd>::value;
|
||||
public:
|
||||
static constexpr ALWAYS_INLINE bool Includes(Result result) {
|
||||
[[nodiscard]] static constexpr ALWAYS_INLINE bool Includes(Result result) {
|
||||
if constexpr (UseDirectValueComparison) {
|
||||
const auto inner_value = result.GetInnerValue();
|
||||
if constexpr (StartValue == EndValue) {
|
||||
|
||||
@@ -432,7 +432,7 @@ namespace ams::sdmmc::impl {
|
||||
/* If the mmc is manufactured by toshiba, try to enable bkops auto. */
|
||||
if (is_toshiba && !IsBkopAutoEnable(static_cast<const u8 *>(wb))) {
|
||||
/* NOTE: Nintendo does not check the result of this. */
|
||||
this->EnableBkopsAuto();
|
||||
static_cast<void>(this->EnableBkopsAuto());
|
||||
}
|
||||
|
||||
/* Extend the bus speed to as fast as we can. */
|
||||
@@ -689,7 +689,7 @@ namespace ams::sdmmc::impl {
|
||||
m_mmc_device.GetCid(cid, sizeof(cid));
|
||||
if (IsToshibaMmc(cid)) {
|
||||
/* NOTE: Nintendo does not check the result of this operation. */
|
||||
this->CancelToshibaMmcModel();
|
||||
static_cast<void>(this->CancelToshibaMmcModel());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -558,11 +558,11 @@ namespace ams::sdmmc::impl {
|
||||
/* NOTE: Nintendo accepts a failure. */
|
||||
if (R_SUCCEEDED(this->IssueCommandAppCmd(DeviceState_Tran))) {
|
||||
/* NOTE: Nintendo does not check the result of this. */
|
||||
this->IssueCommandClearCardDetect();
|
||||
static_cast<void>(this->IssueCommandClearCardDetect());
|
||||
}
|
||||
|
||||
/* NOTE: Nintendo does not check the result of this. */
|
||||
BaseDeviceAccessor::IssueCommandSendStatus();
|
||||
static_cast<void>(BaseDeviceAccessor::IssueCommandSendStatus());
|
||||
}
|
||||
|
||||
Result SdCardDeviceAccessor::StartupSdCardDevice(BusWidth max_bw, SpeedMode max_sm, void *wb, size_t wb_size) {
|
||||
|
||||
@@ -369,7 +369,7 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
/* Otherwise, check if we've timed out. */
|
||||
if (!timer.Update()) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultCommandInhibitCmdSoftwareTimeout());
|
||||
}
|
||||
}
|
||||
@@ -389,7 +389,7 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
/* Otherwise, check if we've timed out. */
|
||||
if (!timer.Update()) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultCommandInhibitDatSoftwareTimeout());
|
||||
}
|
||||
}
|
||||
@@ -458,7 +458,7 @@ namespace ams::sdmmc::impl {
|
||||
this->ClearInterrupt();
|
||||
|
||||
if (R_FAILED(result)) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
}
|
||||
|
||||
R_RETURN(result);
|
||||
@@ -467,7 +467,7 @@ namespace ams::sdmmc::impl {
|
||||
R_RETURN(result);
|
||||
} else {
|
||||
/* If the device wasn't removed, cancel our transaction. */
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultCommandCompleteSoftwareTimeout());
|
||||
}
|
||||
}
|
||||
@@ -489,12 +489,12 @@ namespace ams::sdmmc::impl {
|
||||
} else if (sdmmc::ResultNoWaitedInterrupt::Includes(result)) {
|
||||
/* Otherwise, if the wait for the interrupt isn't done, update the timer and check for timeout. */
|
||||
if (!timer.Update()) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultCommandCompleteSoftwareTimeout());
|
||||
}
|
||||
} else {
|
||||
/* Otherwise, we have a generic failure. */
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_RETURN(result);
|
||||
}
|
||||
}
|
||||
@@ -537,7 +537,7 @@ namespace ams::sdmmc::impl {
|
||||
}
|
||||
} else {
|
||||
/* Abort the transaction. */
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_RETURN(result);
|
||||
}
|
||||
|
||||
@@ -548,7 +548,7 @@ namespace ams::sdmmc::impl {
|
||||
} else {
|
||||
/* Otherwise, timeout if the transfer hasn't advanced. */
|
||||
if (last_block_count != reg::Read(m_registers->block_count)) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultTransferCompleteSoftwareTimeout());
|
||||
}
|
||||
}
|
||||
@@ -589,14 +589,14 @@ namespace ams::sdmmc::impl {
|
||||
if (!timer.Update()) {
|
||||
/* Only timeout if the transfer hasn't advanced. */
|
||||
if (last_block_count != reg::Read(m_registers->block_count)) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultTransferCompleteSoftwareTimeout());
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
/* Otherwise, we have a generic failure. */
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_RETURN(result);
|
||||
}
|
||||
}
|
||||
@@ -624,7 +624,7 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
/* Otherwise, check if we're timed out. */
|
||||
if (!timer.Update()) {
|
||||
this->AbortTransaction();
|
||||
static_cast<void>(this->AbortTransaction());
|
||||
R_THROW(sdmmc::ResultBusySoftwareTimeout());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,7 +471,7 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
SdHostStandardController::EnsureControl();
|
||||
WaitMicroSeconds(1);
|
||||
SdHostStandardController::AbortTransaction();
|
||||
static_cast<void>(SdHostStandardController::AbortTransaction());
|
||||
}
|
||||
reg::ReadWrite(m_sdmmc_registers->sd_host_standard_registers.clock_control, SD_REG_BITS_ENUM(CLOCK_CONTROL_SD_CLOCK_ENABLE, ENABLE));
|
||||
|
||||
@@ -520,7 +520,7 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
/* Otherwise, check if we timed out. */
|
||||
if (!timer.Update()) {
|
||||
SdHostStandardController::AbortTransaction();
|
||||
static_cast<void>(SdHostStandardController::AbortTransaction());
|
||||
R_THROW(sdmmc::ResultIssueTuningCommandSoftwareTimeout());
|
||||
}
|
||||
}
|
||||
@@ -857,7 +857,8 @@ namespace ams::sdmmc::impl {
|
||||
R_TRY(this->CheckRemoved());
|
||||
|
||||
/* Issue the command. */
|
||||
this->IssueTuningCommand(command_index);
|
||||
/* NOTE: Nintendo does not check the result of this call. */
|
||||
static_cast<void>(this->IssueTuningCommand(command_index));
|
||||
|
||||
/* Check if tuning is done. */
|
||||
if (i >= num_tries) {
|
||||
@@ -902,7 +903,8 @@ namespace ams::sdmmc::impl {
|
||||
/* If we're at 3.3V, lower to 1.8V. */
|
||||
if (m_current_bus_power == BusPower_3_3V) {
|
||||
/* pcv::ChangeVoltage(pcv::PowerControlTarget_SdCard, 1800000); */
|
||||
m_power_controller->LowerBusPower();
|
||||
/* NOTE: Nintendo does not check the result of this call. */
|
||||
static_cast<void>(m_power_controller->LowerBusPower());
|
||||
|
||||
/* Set our bus power. */
|
||||
m_current_bus_power = BusPower_1_8V;
|
||||
@@ -913,7 +915,8 @@ namespace ams::sdmmc::impl {
|
||||
|
||||
|
||||
/* pcv::PowerOff(pcv::PowerControlTarget_SdCard); */
|
||||
m_power_controller->PowerOff();
|
||||
/* NOTE: Nintendo does not check the result of this call. */
|
||||
static_cast<void>(m_power_controller->PowerOff());
|
||||
|
||||
/* Set our bus power. */
|
||||
m_current_bus_power = BusPower_Off;
|
||||
@@ -1276,7 +1279,8 @@ namespace ams::sdmmc::impl {
|
||||
R_UNLESS(m_current_bus_power == BusPower_1_8V, pcv::ResultIllegalRequest());
|
||||
|
||||
/* Disable vddio, and wait 4 ms. */
|
||||
this->ControlVddioSdmmc1(BusPower_Off);
|
||||
/* NOTE: Nintendo does not check the result of this call. */
|
||||
static_cast<void>(this->ControlVddioSdmmc1(BusPower_Off));
|
||||
WaitMicroSeconds(4000);
|
||||
|
||||
/* Set the SD power GPIO to low. */
|
||||
|
||||
Reference in New Issue
Block a user