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