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
33void 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 {
53 m_range.access &= ~Memory::User;
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 {
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}
@ Success
Definition API.h:70
void setBase(const Address base)
Set memory I/O base offset.
Definition IO.cpp:33
IO()
Constructor.
Definition IO.cpp:23
Address m_base
memory I/O base offset is added to each I/O address.
Definition IO.h:90
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
Address getBase() const
Get memory I/O base offset.
Definition IO.cpp:28
Result
Result codes.
Definition IO.h:43
@ OutOfMemory
Definition IO.h:46
@ MapFailure
Definition IO.h:45
@ Success
Definition IO.h:44
Result unmap()
Unmap I/O address space.
Definition IO.cpp:70
Memory::Range m_range
Memory range for performing I/O mappings.
Definition IO.h:93
Virtual memory abstract interface.
virtual Result findFree(Size size, MemoryMap::Region region, Address *virt) const
Find unused memory.
virtual Result map(Address virt, Address phys, Memory::Access access)=0
Map a physical page to a virtual address.
virtual Result unmapRange(Memory::Range *range)
Unmaps a range of virtual memory.
static MemoryContext * getCurrent()
Get currently active MemoryContext.
@ KernelPrivate
< Kernel dynamic memory mappings
Definition MemoryMap.h:55
#define SELF
Definition ProcessID.h:35
API::Result VMCtl(const ProcessID procID, const MemoryOperation op, Memory::Range *range=ZERO)
Prototype for user applications.
Definition VMCtl.h:61
@ UnMap
Definition VMCtl.h:39
@ MapContiguous
Definition VMCtl.h:37
C uint isKernel
Non-zero if this executable is linked as the kernel.
unsigned long Address
A memory address.
Definition Types.h:131
unsigned int Size
Any sane size indicator cannot go negative.
Definition Types.h:128
Access
Memory access flags.
Definition Memory.h:39
Size size
Size in number of bytes.
Definition Memory.h:59
Address phys
Physical address.
Definition Memory.h:58
Address virt
Virtual address.
Definition Memory.h:57
Access access
Page access flags.
Definition Memory.h:60