boot: save 12KB

This commit is contained in:
Michael Scire 2021-10-07 19:33:07 -07:00
parent afccc35e79
commit 888b35833e
7 changed files with 125 additions and 31 deletions

View file

@ -25,9 +25,20 @@ namespace ams::powctl::impl::board::nintendo::nx {
constinit util::optional<BatteryDevice> g_battery_device;
constinit util::TypedStorage<Max17050Driver> g_max17050_driver;
constinit bool g_constructed_max17050_driver;
constinit os::SdkMutex g_max17050_driver_mutex;
Max17050Driver &GetMax17050Driver() {
static Max17050Driver s_max17050_driver;
return s_max17050_driver;
if (AMS_UNLIKELY(!g_constructed_max17050_driver)) {
std::scoped_lock lk(g_max17050_driver_mutex);
if (AMS_LIKELY(!g_constructed_max17050_driver)) {
util::ConstructAt(g_max17050_driver);
}
}
return util::GetReference(g_max17050_driver);
}
constexpr inline const double SenseResistorValue = 0.005;

View file

@ -25,9 +25,20 @@ namespace ams::powctl::impl::board::nintendo::nx {
constinit util::optional<ChargerDevice> g_charger_device;
constinit util::TypedStorage<Bq24193Driver> g_bq24193_driver;
constinit bool g_constructed_bq24193_driver;
constinit os::SdkMutex g_bq24193_driver_mutex;
Bq24193Driver &GetBq24193Driver() {
static Bq24193Driver s_bq24193_driver;
return s_bq24193_driver;
if (AMS_UNLIKELY(!g_constructed_bq24193_driver)) {
std::scoped_lock lk(g_bq24193_driver_mutex);
if (AMS_LIKELY(!g_constructed_bq24193_driver)) {
util::ConstructAt(g_bq24193_driver);
}
}
return util::GetReference(g_bq24193_driver);
}
}

View file

@ -30,28 +30,50 @@ namespace ams::powctl::impl {
constinit sf::UnitHeapMemoryResource g_unit_heap_memory_resource;
IPowerControlDriver::List &GetDriverList() {
static IPowerControlDriver::List s_driver_list;
static constinit IPowerControlDriver::List s_driver_list;
return s_driver_list;
}
ddsf::EventHandlerManager &GetInterruptHandlerManager() {
static ddsf::EventHandlerManager s_interrupt_handler_manager;
return s_interrupt_handler_manager;
static constinit util::TypedStorage<ddsf::EventHandlerManager> s_interrupt_handler_manager;
static constinit bool s_initialized = false;
static constinit os::SdkMutex s_mutex;
if (AMS_UNLIKELY(!s_initialized)) {
std::scoped_lock lk(s_mutex);
if (AMS_LIKELY(!s_initialized)) {
util::ConstructAt(s_interrupt_handler_manager);
s_initialized = true;
}
}
return util::GetReference(s_interrupt_handler_manager);
}
ddsf::DeviceCodeEntryManager &GetDeviceCodeEntryManager() {
static ddsf::DeviceCodeEntryManager s_device_code_entry_manager = [] {
/* Initialize the entry code heap. */
g_unit_heap_handle = lmem::CreateUnitHeap(g_unit_heap_memory, sizeof(g_unit_heap_memory), sizeof(ddsf::DeviceCodeEntryHolder), lmem::CreateOption_ThreadSafe);
static constinit util::TypedStorage<ddsf::DeviceCodeEntryManager> s_device_code_entry_manager;
static constinit bool s_initialized = false;
static constinit os::SdkMutex s_mutex;
/* Initialize the entry code memory resource. */
g_unit_heap_memory_resource.Attach(g_unit_heap_handle);
if (AMS_UNLIKELY(!s_initialized)) {
std::scoped_lock lk(s_mutex);
/* Make the entry manager using the newly initialized memory resource. */
return ddsf::DeviceCodeEntryManager(std::addressof(g_unit_heap_memory_resource));
}();
if (AMS_LIKELY(!s_initialized)) {
/* Initialize the entry code heap. */
g_unit_heap_handle = lmem::CreateUnitHeap(g_unit_heap_memory, sizeof(g_unit_heap_memory), sizeof(ddsf::DeviceCodeEntryHolder), lmem::CreateOption_ThreadSafe);
return s_device_code_entry_manager;
/* Initialize the entry code memory resource. */
g_unit_heap_memory_resource.Attach(g_unit_heap_handle);
/* Make the entry manager using the newly initialized memory resource. */
util::ConstructAt(s_device_code_entry_manager, std::addressof(g_unit_heap_memory_resource));
s_initialized = true;
}
}
return util::GetReference(s_device_code_entry_manager);
}
void InterruptThreadFunction(void *arg) {