PhysicalRegion.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /*
  2. * Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
  3. *
  4. * SPDX-License-Identifier: BSD-2-Clause
  5. */
  6. #pragma once
  7. #include <AK/OwnPtr.h>
  8. #include <Kernel/Memory/PhysicalPage.h>
  9. #include <Kernel/Memory/PhysicalZone.h>
  10. namespace Kernel::Memory {
  11. class PhysicalRegion {
  12. AK_MAKE_NONCOPYABLE(PhysicalRegion);
  13. AK_MAKE_NONMOVABLE(PhysicalRegion);
  14. public:
  15. static OwnPtr<PhysicalRegion> try_create(PhysicalAddress lower, PhysicalAddress upper)
  16. {
  17. return adopt_own_if_nonnull(new PhysicalRegion { lower, upper });
  18. }
  19. ~PhysicalRegion();
  20. void initialize_zones();
  21. PhysicalAddress lower() const { return m_lower; }
  22. PhysicalAddress upper() const { return m_upper; }
  23. unsigned size() const { return m_pages; }
  24. bool contains(PhysicalAddress paddr) const { return paddr >= m_lower && paddr < m_upper; }
  25. OwnPtr<PhysicalRegion> try_take_pages_from_beginning(unsigned);
  26. RefPtr<PhysicalPage> take_free_page();
  27. NonnullRefPtrVector<PhysicalPage> take_contiguous_free_pages(size_t count);
  28. void return_page(PhysicalAddress);
  29. private:
  30. PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper);
  31. static constexpr size_t large_zone_size = 16 * MiB;
  32. static constexpr size_t small_zone_size = 1 * MiB;
  33. NonnullOwnPtrVector<PhysicalZone> m_zones;
  34. size_t m_large_zones { 0 };
  35. PhysicalZone::List m_usable_zones;
  36. PhysicalZone::List m_full_zones;
  37. PhysicalAddress m_lower;
  38. PhysicalAddress m_upper;
  39. unsigned m_pages { 0 };
  40. };
  41. }