BIOS.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
  3. * Copyright (c) 2021, Liav A. <liavalb@hotmail.co.il>
  4. *
  5. * SPDX-License-Identifier: BSD-2-Clause
  6. */
  7. #pragma once
  8. #include <AK/Types.h>
  9. #include <AK/Vector.h>
  10. #include <Kernel/FileSystem/SysFS.h>
  11. #include <Kernel/KBuffer.h>
  12. #include <Kernel/Memory/MappedROM.h>
  13. #include <Kernel/Memory/Region.h>
  14. #include <Kernel/PhysicalAddress.h>
  15. #include <Kernel/VirtualAddress.h>
  16. namespace Kernel::SMBIOS {
  17. struct [[gnu::packed]] LegacyEntryPoint32bit {
  18. char legacy_sig[5];
  19. u8 checksum2;
  20. u16 smboios_table_length;
  21. u32 smbios_table_ptr;
  22. u16 smbios_tables_count;
  23. u8 smbios_bcd_revision;
  24. };
  25. struct [[gnu::packed]] EntryPoint32bit {
  26. char sig[4];
  27. u8 checksum;
  28. u8 length;
  29. u8 major_version;
  30. u8 minor_version;
  31. u16 maximum_structure_size;
  32. u8 implementation_revision;
  33. char formatted_area[5];
  34. LegacyEntryPoint32bit legacy_structure;
  35. };
  36. struct [[gnu::packed]] EntryPoint64bit {
  37. char sig[5];
  38. u8 checksum;
  39. u8 length;
  40. u8 major_version;
  41. u8 minor_version;
  42. u8 document_revision;
  43. u8 revision;
  44. u8 reserved;
  45. u32 table_maximum_size;
  46. u64 table_ptr;
  47. };
  48. }
  49. namespace Kernel {
  50. Memory::MappedROM map_bios();
  51. Memory::MappedROM map_ebda();
  52. class BIOSSysFSComponent : public SysFSComponent {
  53. public:
  54. virtual KResultOr<size_t> read_bytes(off_t, size_t, UserOrKernelBuffer&, FileDescription*) const override;
  55. protected:
  56. virtual OwnPtr<KBuffer> try_to_generate_buffer() const = 0;
  57. explicit BIOSSysFSComponent(String name);
  58. };
  59. class DMIEntryPointExposedBlob : public BIOSSysFSComponent {
  60. public:
  61. static NonnullRefPtr<DMIEntryPointExposedBlob> create(PhysicalAddress dmi_entry_point, size_t blob_size);
  62. private:
  63. DMIEntryPointExposedBlob(PhysicalAddress dmi_entry_point, size_t blob_size);
  64. virtual OwnPtr<KBuffer> try_to_generate_buffer() const override;
  65. PhysicalAddress m_dmi_entry_point;
  66. size_t m_dmi_entry_point_length;
  67. };
  68. class SMBIOSExposedTable : public BIOSSysFSComponent {
  69. public:
  70. static NonnullRefPtr<SMBIOSExposedTable> create(PhysicalAddress, size_t blob_size);
  71. private:
  72. SMBIOSExposedTable(PhysicalAddress dmi_entry_point, size_t blob_size);
  73. virtual OwnPtr<KBuffer> try_to_generate_buffer() const override;
  74. PhysicalAddress m_smbios_structure_table;
  75. size_t m_smbios_structure_table_length;
  76. };
  77. class BIOSSysFSDirectory : public SysFSDirectory {
  78. public:
  79. static void initialize();
  80. void create_components();
  81. private:
  82. BIOSSysFSDirectory();
  83. void set_dmi_64_bit_entry_initialization_values();
  84. void set_dmi_32_bit_entry_initialization_values();
  85. void initialize_dmi_exposer();
  86. Optional<PhysicalAddress> find_dmi_entry64bit_point();
  87. Optional<PhysicalAddress> find_dmi_entry32bit_point();
  88. PhysicalAddress m_dmi_entry_point;
  89. PhysicalAddress m_smbios_structure_table;
  90. bool m_using_64bit_dmi_entry_point { false };
  91. size_t m_smbios_structure_table_length { 0 };
  92. size_t m_dmi_entry_point_length { 0 };
  93. };
  94. }