FreeNOS
IO.cpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2015 Niek Linnenbank
3  *
4  * This program is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation, either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program. If not, see <http://www.gnu.org/licenses/>.
16  */
17 
18 #include <FreeNOS/System.h>
19 #include "MemoryContext.h"
20 #include "CoreInfo.h"
21 #include "IO.h"
22 
24 {
25  m_base = IO_BASE;
26 }
27 
29 {
30  return m_base;
31 }
32 
33 void IO::setBase(const Address base)
34 {
35  m_base = base;
36 }
37 
39 {
40 #ifndef __HOST__
41  m_range.virt = 0;
42  m_range.phys = phys;
43  m_range.access = access;
44  m_range.size = size;
45 
46  if (!isKernel)
47  {
49  return MapFailure;
50  }
51  else
52  {
54 
56  if (!ctx)
57  return MapFailure;
58 
60  return OutOfMemory;
61 
63  return MapFailure;
64  }
66 #endif /* __HOST__ */
67  return Success;
68 }
69 
71 {
72 #ifndef __HOST__
73  if (!isKernel)
74  {
75  if (VMCtl(SELF, UnMap, &m_range) != API::Success)
76  return MapFailure;
77  }
78  else
79  {
81  if (!ctx)
82  return MapFailure;
83 
85  return MapFailure;
86  }
87 #endif /* __HOST__ */
88  return Success;
89 }
IO::unmap
Result unmap()
Unmap I/O address space.
Definition: IO.cpp:70
MemoryContext
Virtual memory abstract interface.
Definition: MemoryContext.h:42
MemoryContext::unmapRange
virtual Result unmapRange(Memory::Range *range)
Unmaps a range of virtual memory.
Definition: MemoryContext.cpp:95
IO::OutOfMemory
@ OutOfMemory
Definition: IO.h:46
IO::map
Result map(Address phys, Size size=4096, Memory::Access access=Memory::Readable|Memory::Writable|Memory::User)
Map I/O address space.
Definition: IO.cpp:38
IO::m_base
Address m_base
memory I/O base offset is added to each I/O address.
Definition: IO.h:90
Memory::User
@ User
Definition: Memory.h:44
MemoryContext::map
virtual Result map(Address virt, Address phys, Memory::Access access)=0
Map a physical page to a virtual address.
isKernel
C uint isKernel
Non-zero if this executable is linked as the kernel.
Address
unsigned long Address
A memory address.
Definition: Types.h:131
VMCtl
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition: VMCtl.h:61
UnMap
@ UnMap
Definition: VMCtl.h:39
SELF
#define SELF
Definition: ProcessID.h:35
IO::setBase
void setBase(const Address base)
Set memory I/O base offset.
Definition: IO.cpp:33
Memory::Range::phys
Address phys
Physical address.
Definition: Memory.h:58
IO::IO
IO()
Constructor.
Definition: IO.cpp:23
IO::Result
Result
Result codes.
Definition: IO.h:42
Memory
Definition: Memory.h:33
MemoryContext::Success
@ Success
Definition: MemoryContext.h:51
MemoryContext::findFree
virtual Result findFree(Size size, MemoryMap::Region region, Address *virt) const
Find unused memory.
Definition: MemoryContext.cpp:117
Size
unsigned int Size
Any sane size indicator cannot go negative.
Definition: Types.h:128
MemoryMap::KernelPrivate
@ KernelPrivate
< Kernel dynamic memory mappings
Definition: MemoryMap.h:55
Memory::Access
Access
Memory access flags.
Definition: Memory.h:38
MemoryContext::getCurrent
static MemoryContext * getCurrent()
Get currently active MemoryContext.
Definition: MemoryContext.cpp:41
IO::Success
@ Success
Definition: IO.h:44
API::Success
@ Success
Definition: API.h:70
IO::getBase
Address getBase() const
Get memory I/O base offset.
Definition: IO.cpp:28
Memory::Range::virt
Address virt
Virtual address.
Definition: Memory.h:57
CoreInfo.h
MemoryContext.h
Memory::Range::size
Size size
Size in number of bytes.
Definition: Memory.h:59
IO.h
Memory::Range::access
Access access
Page access flags.
Definition: Memory.h:60
MapContiguous
@ MapContiguous
Definition: VMCtl.h:37
IO::MapFailure
@ MapFailure
Definition: IO.h:45
IO::m_range
Memory::Range m_range
Memory range for performing I/O mappings.
Definition: IO.h:93