PhysicalRegion.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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_ETERNAL;
  13. AK_MAKE_NONCOPYABLE(PhysicalRegion);
  14. AK_MAKE_NONMOVABLE(PhysicalRegion);
  15. public:
  16. static OwnPtr<PhysicalRegion> try_create(PhysicalAddress lower, PhysicalAddress upper)
  17. {
  18. return adopt_own_if_nonnull(new PhysicalRegion { lower, upper });
  19. }
  20. ~PhysicalRegion();
  21. void initialize_zones();
  22. PhysicalAddress lower() const { return m_lower; }
  23. PhysicalAddress upper() const { return m_upper; }
  24. unsigned size() const { return m_pages; }
  25. bool contains(PhysicalAddress paddr) const { return paddr >= m_lower && paddr < m_upper; }
  26. OwnPtr<PhysicalRegion> try_take_pages_from_beginning(unsigned);
  27. RefPtr<PhysicalPage> take_free_page();
  28. NonnullRefPtrVector<PhysicalPage> take_contiguous_free_pages(size_t count);
  29. void return_page(PhysicalAddress);
  30. private:
  31. PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper);
  32. NonnullOwnPtrVector<PhysicalZone> m_zones;
  33. PhysicalZone::List m_usable_zones;
  34. PhysicalZone::List m_full_zones;
  35. PhysicalAddress m_lower;
  36. PhysicalAddress m_upper;
  37. unsigned m_pages { 0 };
  38. };
  39. }