1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 21:57:43 +00:00

Kernel+Userland: Move /sys/firmware/power_state to /sys/kernel directory

Let's put the power_state global node into the /sys/kernel directory,
because that directory represents all global nodes and variables being
related to the Kernel. It's also a mutable node, that is more acceptable
being in the mentioned directory due to the fact that all other files in
the /sys/firmware directory are just firmware blobs and are not mutable
at all.
This commit is contained in:
Liav A 2022-10-15 05:57:20 +03:00 committed by Andrew Kaster
parent 8c21d974b2
commit 75f01692b4
9 changed files with 21 additions and 21 deletions

View file

@ -7,7 +7,6 @@
#include <Kernel/FileSystem/SysFS/Registry.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/BIOS/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h>
#include <Kernel/Firmware/ACPI/Parser.h>
#include <Kernel/Sections.h>
@ -26,7 +25,6 @@ void FirmwareSysFSDirectory::create_components()
list.append(BIOSSysFSDirectory::must_create(*this));
if (ACPI::is_enabled())
list.append(ACPI::ACPISysFSDirectory::must_create(*this));
list.append(PowerStateSwitchNode::must_create(*this));
return {};
}));
}

View file

@ -1,111 +0,0 @@
/*
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <AK/Platform.h>
#if ARCH(I386) || ARCH(X86_64)
# include <Kernel/Arch/x86/common/I8042Reboot.h>
# include <Kernel/Arch/x86/common/Shutdown.h>
#endif
#include <Kernel/FileSystem/FileSystem.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/PowerStateSwitch.h>
#include <Kernel/Firmware/ACPI/Parser.h>
#include <Kernel/Process.h>
#include <Kernel/Sections.h>
#include <Kernel/TTY/ConsoleManagement.h>
namespace Kernel {
mode_t PowerStateSwitchNode::permissions() const
{
return S_IRUSR | S_IRGRP | S_IWUSR | S_IWGRP;
}
UNMAP_AFTER_INIT NonnullLockRefPtr<PowerStateSwitchNode> PowerStateSwitchNode::must_create(FirmwareSysFSDirectory& firmware_directory)
{
return adopt_lock_ref_if_nonnull(new (nothrow) PowerStateSwitchNode(firmware_directory)).release_nonnull();
}
UNMAP_AFTER_INIT PowerStateSwitchNode::PowerStateSwitchNode(FirmwareSysFSDirectory&)
: SysFSComponent()
{
}
ErrorOr<void> PowerStateSwitchNode::truncate(u64 size)
{
// Note: This node doesn't store any useful data anyway, so we can safely
// truncate this to zero (essentially ignoring the request without failing).
if (size != 0)
return EPERM;
return {};
}
ErrorOr<size_t> PowerStateSwitchNode::write_bytes(off_t offset, size_t count, UserOrKernelBuffer const& data, OpenFileDescription*)
{
if (Checked<off_t>::addition_would_overflow(offset, count))
return EOVERFLOW;
if (offset > 0)
return EINVAL;
if (count > 1)
return EINVAL;
char buf[1];
TRY(data.read(buf, 1));
switch (buf[0]) {
case '0':
return EINVAL;
case '1':
reboot();
VERIFY_NOT_REACHED();
case '2':
poweroff();
VERIFY_NOT_REACHED();
default:
return EINVAL;
}
VERIFY_NOT_REACHED();
}
void PowerStateSwitchNode::reboot()
{
MutexLocker locker(Process::current().big_lock());
dbgln("acquiring FS locks...");
FileSystem::lock_all();
dbgln("syncing mounted filesystems...");
FileSystem::sync();
dbgln("attempting reboot via ACPI");
if (ACPI::is_enabled())
ACPI::Parser::the()->try_acpi_reboot();
#if ARCH(I386) || ARCH(X86_64)
i8042_reboot();
#endif
dbgln("reboot attempts failed, applications will stop responding.");
dmesgln("Reboot can't be completed. It's safe to turn off the computer!");
Processor::halt();
}
void PowerStateSwitchNode::poweroff()
{
MutexLocker locker(Process::current().big_lock());
ConsoleManagement::the().switch_to_debug();
dbgln("acquiring FS locks...");
FileSystem::lock_all();
dbgln("syncing mounted filesystems...");
FileSystem::sync();
dbgln("attempting system shutdown...");
#if ARCH(I386) || ARCH(X86_64)
qemu_shutdown();
virtualbox_shutdown();
#endif
dbgln("shutdown attempts failed, applications will stop responding.");
dmesgln("Shutdown can't be completed. It's safe to turn off the computer!");
Processor::halt();
}
}

View file

@ -1,38 +0,0 @@
/*
* Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Types.h>
#include <AK/Vector.h>
#include <Kernel/FileSystem/SysFS.h>
#include <Kernel/FileSystem/SysFS/Subsystems/Firmware/Directory.h>
#include <Kernel/KBuffer.h>
#include <Kernel/Library/LockRefPtr.h>
#include <Kernel/Memory/MappedROM.h>
#include <Kernel/Memory/Region.h>
#include <Kernel/PhysicalAddress.h>
#include <Kernel/VirtualAddress.h>
namespace Kernel {
class PowerStateSwitchNode final : public SysFSComponent {
public:
virtual StringView name() const override { return "power_state"sv; }
static NonnullLockRefPtr<PowerStateSwitchNode> must_create(FirmwareSysFSDirectory&);
virtual mode_t permissions() const override;
virtual ErrorOr<size_t> write_bytes(off_t, size_t, UserOrKernelBuffer const&, OpenFileDescription*) override;
virtual ErrorOr<void> truncate(u64) override;
private:
PowerStateSwitchNode(FirmwareSysFSDirectory&);
void reboot();
void poweroff();
};
}