The Pedigree Project  0.1
MemoryRegion.h
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef KERNEL_PROCESSOR_MEMORYREGION_H
21 #define KERNEL_PROCESSOR_MEMORYREGION_H
22 
23 #include "pedigree/kernel/compiler.h"
24 #include "pedigree/kernel/processor/types.h"
25 
36 {
45 
46  public:
48  MemoryRegion(const char *pName);
50  virtual ~MemoryRegion();
51 
52  void free();
53 
58  void *virtualAddress() const;
62  physical_uintptr_t physicalAddress() const;
65  size_t size() const;
68  const char *name() const;
69 
70  operator bool() const;
71 
72  bool physicalBoundsCheck(physical_uintptr_t address);
73  template <typename T>
74  T *convertPhysicalPointer(physical_uintptr_t address);
75 
76  void setNonRamMemory(bool b);
77  bool getNonRamMemory();
78  void setForced(bool b);
79  bool getForced();
80 
81  private:
84  MemoryRegion(const MemoryRegion &);
88 
94  physical_uintptr_t m_PhysicalAddress;
96  size_t m_Size;
98  const char *m_pName;
99 
100  bool m_bNonRamMemory, m_bForced;
101 };
102 
105 template <typename T>
106 T *MemoryRegion::convertPhysicalPointer(physical_uintptr_t address)
107 {
108  return reinterpret_cast<T *>(
109  reinterpret_cast<uintptr_t>(m_VirtualAddress) +
110  (address - m_PhysicalAddress));
111 }
112 
113 #endif
HostedPhysicalMemoryManager & operator=(const HostedPhysicalMemoryManager &)
void * m_VirtualAddress
Definition: MemoryRegion.h:91
physical_uintptr_t m_PhysicalAddress
Definition: MemoryRegion.h:94
size_t m_Size
Definition: MemoryRegion.h:96
uintptr_t physicalAddress(physical_uintptr_t address) PURE
Definition: utils.h:38
const char * m_pName
Definition: MemoryRegion.h:98
Special memory entity in the kernel&#39;s virtual address space.
Definition: MemoryRegion.h:35
Implementation of the PhysicalMemoryManager for common ppc.
Implementation of the PhysicalMemoryManager for common arm.
Implementation of the PhysicalMemoryManager for common x86.
Implementation of the PhysicalMemoryManager for common x86.