The Pedigree Project 0.1
IoPortManager.cc
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#include "pedigree/kernel/LockGuard.h"
21#include "pedigree/kernel/processor/IoPort.h"
22#include "pedigree/kernel/processor/IoPortManager.h"
23#include "pedigree/kernel/processor/Processor.h"
24#include "pedigree/kernel/utilities/new"
25
27
28bool IoPortManager::allocate(IoPort* Port, io_port_t ioPort, size_t size) {
29 if (Processor::isInitialised() == 0)
31
32 // Acquire the lock untill the end of the function
34
35 // Remove the I/O ports from the list of free I/O ports
36 if (m_FreeIoPorts.allocateSpecific(ioPort, size) == false)
37 return false;
38
39 // Add information to the list of used I/O ports
41 return true;
42}
43
45 if (Processor::isInitialised() == 0)
47
48 // Acquire the lock untill the end of the function
50
51 // Remove from the used I/O ports list
54 for (; i != end; i++)
55 if ((*i) == Port) {
57 break;
58 }
59
60 // Add to the free I/O ports list
61 m_FreeIoPorts.free(Port->base(), Port->size());
62}
63
65 // Acquire the lock untill the end of the function
67
68 for (size_t i = 0; i < m_UsedIoPorts.count(); i++) {
69 IoPortInfo* pIoPortInfo = new IoPortInfo(m_UsedIoPorts[i]->base(), m_UsedIoPorts[i]->size(),
70 m_UsedIoPorts[i]->name());
71 IoPorts.pushBack(pIoPortInfo);
72 }
73}
74
76 while (IoPorts.count() != 0) {
77 IoPortInfo* pIoPortInfo = IoPorts.popBack();
78 delete pIoPortInfo;
79 }
80}
81
82//
83// Functions only usable in the kernel initialisation phase
84//
85
86void IoPortManager::initialise(io_port_t ioPortBase, size_t size) {
87 m_FreeIoPorts.free(ioPortBase, size);
88}
89
90IoPortManager::IoPortManager() : m_Lock(), m_FreeIoPorts(), m_UsedIoPorts() {}
Manages hardware I/O port (de)allocations.
bool allocate(IoPort *Port, io_port_t ioPort, size_t size)
void initialise(io_port_t ioPortBase, size_t size) INITIALISATION_ONLY
void allocateIoPortList(Vector< IoPortInfo * > &IoPorts)
void freeIoPortList(Vector< IoPortInfo * > &IoPorts)
Vector< IoPort * > m_UsedIoPorts
RangeList< uint32_t > m_FreeIoPorts
static IoPortManager m_Instance
IoPortManager() INITIALISATION_ONLY
void free(IoPort *Port)
virtual ~IoPortManager()
I/O port range.
Definition IoPort.h:33
virtual size_t size() const
Definition IoPort.cc:51
io_port_t base() const
Definition IoPort.cc:55
static void halt()
static size_t isInitialised()
Definition Processor.cc:105
void free(T address, T length, bool merge=true)
Definition RangeList.h:157
bool allocateSpecific(T address, T length)
Definition RangeList.h:363
A vector / dynamic array.
Definition Vector.h:33
Iterator end()
Definition Vector.h:172
Iterator begin()
Definition Vector.h:162
void erase(size_t index)
Definition Vector.h:389
T popBack()
Definition Vector.h:303
void pushBack(const T &value)
Definition Vector.h:275
size_t count() const
Definition Vector.h:270