1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 11:28:12 +00:00

Kernel: Introduce the new SysFS

The intention is to add dynamic mechanism for notifying the userspace
about hotplug events. Currently, the DMI (SMBIOS) blobs and ACPI tables
are exposed in the new filesystem.
This commit is contained in:
Liav A 2021-03-13 12:01:44 +02:00 committed by Andreas Kling
parent dc6defa7af
commit 92c0dab5ab
13 changed files with 839 additions and 202 deletions

View file

@ -27,6 +27,79 @@ Parser* Parser::the()
return s_acpi_parser;
}
UNMAP_AFTER_INIT NonnullRefPtr<ExposedComponent> ExposedComponent::create(String name, PhysicalAddress paddr, size_t table_size)
{
return adopt_ref(*new (nothrow) ExposedComponent(name, paddr, table_size));
}
KResultOr<size_t> ExposedComponent::read_bytes(off_t offset, size_t count, UserOrKernelBuffer& buffer, FileDescription*) const
{
auto blob = try_to_generate_buffer();
if (!blob)
return KResult(EFAULT);
if ((size_t)offset >= blob->size())
return KSuccess;
ssize_t nread = min(static_cast<off_t>(blob->size() - offset), static_cast<off_t>(count));
if (!buffer.write(blob->data() + offset, nread))
return KResult(EFAULT);
return nread;
}
OwnPtr<KBuffer> ExposedComponent::try_to_generate_buffer() const
{
auto acpi_blob = map_typed<u8>((m_paddr), m_length);
return KBuffer::try_create_with_bytes(Span<u8> { acpi_blob.ptr(), m_length });
}
UNMAP_AFTER_INIT ExposedComponent::ExposedComponent(String name, PhysicalAddress paddr, size_t table_size)
: SystemExposedComponent(name)
, m_paddr(paddr)
, m_length(table_size)
{
}
UNMAP_AFTER_INIT void ExposedFolder::initialize()
{
auto acpi_folder = adopt_ref(*new (nothrow) ExposedFolder());
SystemRegistrar::the().register_new_component(acpi_folder);
}
UNMAP_AFTER_INIT ExposedFolder::ExposedFolder()
: SystemExposedFolder("acpi", SystemRegistrar::the().root_folder())
{
NonnullRefPtrVector<SystemExposedComponent> components;
size_t ssdt_count = 0;
ACPI::Parser::the()->enumerate_static_tables([&](const StringView& signature, PhysicalAddress p_table, size_t length) {
if (signature == "SSDT") {
components.append(ExposedComponent::create(String::formatted("{:4s}{}", signature.characters_without_null_termination(), ssdt_count), p_table, length));
ssdt_count++;
return;
}
components.append(ExposedComponent::create(signature, p_table, length));
});
m_components = components;
auto rsdp = map_typed<Structures::RSDPDescriptor20>(ACPI::Parser::the()->rsdp());
m_components.append(ExposedComponent::create("RSDP", ACPI::Parser::the()->rsdp(), rsdp->base.revision == 0 ? sizeof(Structures::RSDPDescriptor) : rsdp->length));
auto main_system_description_table = map_typed<Structures::SDTHeader>(ACPI::Parser::the()->main_system_description_table());
if (ACPI::Parser::the()->is_xsdt_supported()) {
m_components.append(ExposedComponent::create("XSDT", ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length));
} else {
m_components.append(ExposedComponent::create("RSDT", ACPI::Parser::the()->main_system_description_table(), main_system_description_table->length));
}
}
void Parser::enumerate_static_tables(Function<void(const StringView&, PhysicalAddress, size_t)> callback)
{
for (auto& p_table : m_sdt_pointers) {
auto table = map_typed<Structures::SDTHeader>(p_table);
callback({ table->sig, 4 }, p_table, table->length);
}
}
void Parser::set_the(Parser& parser)
{
VERIFY(!s_acpi_parser);