2021-01-29 14:10:18 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
|
|
|
|
*
|
2021-04-22 11:24:48 +03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2021-01-29 14:10:18 +03:00
|
|
|
*/
|
|
|
|
|
2021-03-12 19:29:37 +03:00
|
|
|
#include <AK/Format.h>
|
2021-01-29 14:10:18 +03:00
|
|
|
#include <AK/Singleton.h>
|
|
|
|
#include <AK/StringView.h>
|
|
|
|
#include <AK/Types.h>
|
|
|
|
#include <Kernel/Arch/PC/BIOS.h>
|
|
|
|
#include <Kernel/DMI.h>
|
|
|
|
#include <Kernel/StdLib.h>
|
|
|
|
#include <Kernel/VM/MappedROM.h>
|
|
|
|
#include <Kernel/VM/TypedMapping.h>
|
|
|
|
|
|
|
|
namespace Kernel {
|
|
|
|
|
|
|
|
#define SMBIOS_BASE_SEARCH_ADDR 0xf0000
|
|
|
|
#define SMBIOS_END_SEARCH_ADDR 0xfffff
|
|
|
|
#define SMBIOS_SEARCH_AREA_SIZE (SMBIOS_END_SEARCH_ADDR - SMBIOS_BASE_SEARCH_ADDR)
|
|
|
|
|
|
|
|
AK::Singleton<DMIExpose> s_the;
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT void DMIExpose::set_64_bit_entry_initialization_values()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
2021-03-12 15:52:58 +03:00
|
|
|
dbgln("DMIExpose: SMBIOS 64bit Entry point @ {}", m_entry_point);
|
|
|
|
auto smbios_entry = map_typed<SMBIOS::EntryPoint64bit>(m_entry_point, SMBIOS_SEARCH_AREA_SIZE);
|
2021-01-29 14:10:18 +03:00
|
|
|
m_structure_table = PhysicalAddress(smbios_entry.ptr()->table_ptr);
|
|
|
|
m_entry_point_length = smbios_entry.ptr()->length;
|
|
|
|
m_structure_table_length = smbios_entry.ptr()->table_maximum_size;
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT void DMIExpose::set_32_bit_entry_initialization_values()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
2021-03-12 15:52:58 +03:00
|
|
|
dbgln("DMIExpose: SMBIOS 32bit Entry point @ {}", m_entry_point);
|
|
|
|
auto smbios_entry = map_typed<SMBIOS::EntryPoint32bit>(m_entry_point, SMBIOS_SEARCH_AREA_SIZE);
|
2021-01-29 14:10:18 +03:00
|
|
|
m_structure_table = PhysicalAddress(smbios_entry.ptr()->legacy_structure.smbios_table_ptr);
|
|
|
|
m_entry_point_length = smbios_entry.ptr()->length;
|
|
|
|
m_structure_table_length = smbios_entry.ptr()->legacy_structure.smboios_table_length;
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT void DMIExpose::initialize()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
|
|
|
s_the.ensure_instance();
|
|
|
|
}
|
|
|
|
|
|
|
|
DMIExpose& DMIExpose::the()
|
|
|
|
{
|
|
|
|
return *s_the;
|
|
|
|
}
|
|
|
|
|
2021-01-29 22:01:56 +03:00
|
|
|
size_t DMIExpose::entry_point_length() const
|
|
|
|
{
|
|
|
|
return m_entry_point_length;
|
|
|
|
}
|
|
|
|
size_t DMIExpose::structure_table_length() const
|
|
|
|
{
|
|
|
|
return m_structure_table_length;
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT void DMIExpose::initialize_exposer()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
2021-02-23 22:42:32 +03:00
|
|
|
VERIFY(!(m_entry_point.is_null()));
|
2021-01-29 14:10:18 +03:00
|
|
|
if (m_using_64bit_entry_point) {
|
|
|
|
set_64_bit_entry_initialization_values();
|
|
|
|
} else {
|
|
|
|
set_32_bit_entry_initialization_values();
|
|
|
|
}
|
2021-03-12 15:52:58 +03:00
|
|
|
dbgln("DMIExpose: Data table @ {}", m_structure_table);
|
2021-01-29 14:10:18 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
OwnPtr<KBuffer> DMIExpose::entry_point() const
|
|
|
|
{
|
|
|
|
auto dmi_blob = map_typed<u8>((m_entry_point), m_entry_point_length);
|
|
|
|
return KBuffer::try_create_with_bytes(Span<u8> { dmi_blob.ptr(), m_entry_point_length });
|
|
|
|
}
|
|
|
|
OwnPtr<KBuffer> DMIExpose::structure_table() const
|
|
|
|
{
|
|
|
|
auto dmi_blob = map_typed<u8>(m_structure_table, m_structure_table_length);
|
|
|
|
return KBuffer::try_create_with_bytes(Span<u8> { dmi_blob.ptr(), m_structure_table_length });
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT DMIExpose::DMIExpose()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
|
|
|
auto entry_32bit = find_entry32bit_point();
|
|
|
|
m_entry_point = entry_32bit.value();
|
|
|
|
|
|
|
|
auto entry_64bit = find_entry64bit_point();
|
|
|
|
if (entry_64bit.has_value()) {
|
|
|
|
m_entry_point = entry_64bit.value();
|
|
|
|
m_using_64bit_entry_point = true;
|
|
|
|
}
|
|
|
|
if (m_entry_point.is_null())
|
|
|
|
return;
|
|
|
|
m_available = true;
|
|
|
|
initialize_exposer();
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT Optional<PhysicalAddress> DMIExpose::find_entry64bit_point()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
|
|
|
return map_bios().find_chunk_starting_with("_SM3_", 16);
|
|
|
|
}
|
|
|
|
|
2021-02-19 23:29:46 +03:00
|
|
|
UNMAP_AFTER_INIT Optional<PhysicalAddress> DMIExpose::find_entry32bit_point()
|
2021-01-29 14:10:18 +03:00
|
|
|
{
|
|
|
|
return map_bios().find_chunk_starting_with("_SM_", 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|