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