mirror of
				https://github.com/RGBCube/serenity
				synced 2025-10-31 19:12:43 +00:00 
			
		
		
		
	 1682f0b760
			
		
	
	
		1682f0b760
		
	
	
	
	
		
			
			SPDX License Identifiers are a more compact / standardized way of representing file license information. See: https://spdx.dev/resources/use/#identifiers This was done with the `ambr` search and replace tool. ambr --no-parent-ignore --key-from-file --rep-from-file key.txt rep.txt *
		
			
				
	
	
		
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			47 lines
		
	
	
	
		
			1.3 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
| /*
 | |
|  * Copyright (c) 2020, Andreas Kling <kling@serenityos.org>
 | |
|  *
 | |
|  * SPDX-License-Identifier: BSD-2-Clause
 | |
|  */
 | |
| 
 | |
| #pragma once
 | |
| 
 | |
| #include <AK/StringView.h>
 | |
| #include <Kernel/VM/MemoryManager.h>
 | |
| 
 | |
| namespace Kernel {
 | |
| 
 | |
| template<typename T>
 | |
| struct TypedMapping {
 | |
|     const T* ptr() const { return reinterpret_cast<const T*>(region->vaddr().offset(offset).as_ptr()); }
 | |
|     T* ptr() { return reinterpret_cast<T*>(region->vaddr().offset(offset).as_ptr()); }
 | |
|     const T* operator->() const { return ptr(); }
 | |
|     T* operator->() { return ptr(); }
 | |
|     const T& operator*() const { return *ptr(); }
 | |
|     T& operator*() { return *ptr(); }
 | |
|     OwnPtr<Region> region;
 | |
|     size_t offset { 0 };
 | |
| };
 | |
| 
 | |
| template<typename T>
 | |
| static TypedMapping<T> map_typed(PhysicalAddress paddr, size_t length, Region::Access access = Region::Access::Read)
 | |
| {
 | |
|     TypedMapping<T> table;
 | |
|     table.region = MM.allocate_kernel_region(paddr.page_base(), page_round_up(length), {}, access);
 | |
|     table.offset = paddr.offset_in_page();
 | |
|     return table;
 | |
| }
 | |
| 
 | |
| template<typename T>
 | |
| static TypedMapping<T> map_typed(PhysicalAddress paddr)
 | |
| {
 | |
|     return map_typed<T>(paddr, sizeof(T));
 | |
| }
 | |
| 
 | |
| template<typename T>
 | |
| static TypedMapping<T> map_typed_writable(PhysicalAddress paddr)
 | |
| {
 | |
|     return map_typed<T>(paddr, sizeof(T), Region::Access::Read | Region::Access::Write);
 | |
| }
 | |
| 
 | |
| }
 |