2020-01-18 08:38:21 +00:00
|
|
|
/*
|
2021-07-12 20:52:17 +00:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2020-01-18 08:38:21 +00:00
|
|
|
*
|
2021-04-22 08:24:48 +00:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 08:38:21 +00:00
|
|
|
*/
|
|
|
|
|
2019-06-11 11:13:02 +00:00
|
|
|
#pragma once
|
|
|
|
|
2021-07-12 20:52:17 +00:00
|
|
|
#include <AK/OwnPtr.h>
|
2021-08-06 08:45:34 +00:00
|
|
|
#include <Kernel/Memory/PhysicalPage.h>
|
|
|
|
#include <Kernel/Memory/PhysicalZone.h>
|
2019-06-11 11:13:02 +00:00
|
|
|
|
2021-08-06 11:49:36 +00:00
|
|
|
namespace Kernel::Memory {
|
2020-02-16 00:27:42 +00:00
|
|
|
|
2021-07-11 12:29:02 +00:00
|
|
|
class PhysicalRegion {
|
2021-07-13 21:17:02 +00:00
|
|
|
AK_MAKE_NONCOPYABLE(PhysicalRegion);
|
|
|
|
AK_MAKE_NONMOVABLE(PhysicalRegion);
|
|
|
|
|
2019-06-11 11:13:02 +00:00
|
|
|
public:
|
2021-07-12 20:52:17 +00:00
|
|
|
static OwnPtr<PhysicalRegion> try_create(PhysicalAddress lower, PhysicalAddress upper)
|
2021-07-11 12:29:02 +00:00
|
|
|
{
|
2021-07-12 20:52:17 +00:00
|
|
|
return adopt_own_if_nonnull(new PhysicalRegion { lower, upper });
|
2021-07-11 12:29:02 +00:00
|
|
|
}
|
2019-06-11 11:13:02 +00:00
|
|
|
|
2021-07-12 20:52:17 +00:00
|
|
|
~PhysicalRegion();
|
|
|
|
|
|
|
|
void initialize_zones();
|
2019-06-11 11:13:02 +00:00
|
|
|
|
|
|
|
PhysicalAddress lower() const { return m_lower; }
|
|
|
|
PhysicalAddress upper() const { return m_upper; }
|
|
|
|
unsigned size() const { return m_pages; }
|
2021-07-13 22:13:18 +00:00
|
|
|
bool contains(PhysicalAddress paddr) const { return paddr >= m_lower && paddr < m_upper; }
|
2019-06-11 11:13:02 +00:00
|
|
|
|
2021-07-12 20:52:17 +00:00
|
|
|
OwnPtr<PhysicalRegion> try_take_pages_from_beginning(unsigned);
|
2021-07-08 01:50:05 +00:00
|
|
|
|
2021-07-11 21:12:32 +00:00
|
|
|
RefPtr<PhysicalPage> take_free_page();
|
2021-07-13 14:10:48 +00:00
|
|
|
NonnullRefPtrVector<PhysicalPage> take_contiguous_free_pages(size_t count);
|
2021-07-08 02:28:51 +00:00
|
|
|
void return_page(PhysicalAddress);
|
2019-06-11 11:13:02 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
PhysicalRegion(PhysicalAddress lower, PhysicalAddress upper);
|
|
|
|
|
2021-12-11 18:00:47 +00:00
|
|
|
static constexpr size_t large_zone_size = 16 * MiB;
|
|
|
|
static constexpr size_t small_zone_size = 1 * MiB;
|
|
|
|
|
2021-07-12 20:52:17 +00:00
|
|
|
NonnullOwnPtrVector<PhysicalZone> m_zones;
|
|
|
|
|
2021-12-22 09:26:35 +00:00
|
|
|
size_t m_large_zones { 0 };
|
2021-12-12 21:00:29 +00:00
|
|
|
|
2021-07-13 17:52:42 +00:00
|
|
|
PhysicalZone::List m_usable_zones;
|
|
|
|
PhysicalZone::List m_full_zones;
|
|
|
|
|
2019-06-11 11:13:02 +00:00
|
|
|
PhysicalAddress m_lower;
|
|
|
|
PhysicalAddress m_upper;
|
|
|
|
unsigned m_pages { 0 };
|
|
|
|
};
|
2020-02-16 00:27:42 +00:00
|
|
|
|
|
|
|
}
|