The Pedigree Project  0.1
IoPort.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/processor/IoPort.h"
21 #include "pedigree/kernel/processor/IoPortManager.h"
22 
23 #if !defined(KERNEL_PROCESSOR_NO_PORT_IO)
24 
25 IoPort::IoPort(const char *name) : m_IoPort(0), m_Size(0), m_Name(name)
26 {
27 }
28 
30 {
31  free();
32 }
33 
34 bool IoPort::allocate(io_port_t ioPort, size_t size)
35 {
36  // Free any allocated I/O ports
37  if (m_Size != 0)
38  free();
39 
40  if (IoPortManager::instance().allocate(this, ioPort, size) == true)
41  {
42  m_IoPort = ioPort;
43  m_Size = size;
44  return true;
45  }
46  return false;
47 }
48 
50 {
51  if (m_Size != 0)
52  {
54 
55  m_IoPort = 0;
56  m_Size = 0;
57  }
58 }
59 
60 size_t IoPort::size() const
61 {
62  return m_Size;
63 }
64 
65 io_port_t IoPort::base() const
66 {
67  return m_IoPort;
68 }
69 
70 IoPort::operator bool() const
71 {
72  return (m_Size != 0);
73 }
74 
75 const char *IoPort::name() const
76 {
77  return m_Name;
78 }
79 
80 #endif
io_port_t m_IoPort
Definition: IoPort.h:82
io_port_t base() const
Definition: IoPort.cc:65
void free(IoPort *Port)
static IoPortManager & instance()
Definition: IoPortManager.h:44
const char * m_Name
Definition: IoPort.h:86
void free()
Definition: IoPort.cc:49
IoPort(const char *name)
Definition: IoPort.cc:25
virtual ~IoPort()
Definition: IoPort.cc:29
const char * name() const
Definition: IoPort.cc:75
bool allocate(io_port_t ioPort, size_t size)
Definition: IoPort.cc:34
virtual size_t size() const
Definition: IoPort.cc:60
size_t m_Size
Definition: IoPort.h:84