The Pedigree Project  0.1
IoPortManager.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_IOPORTMANAGER_H
21 #define KERNEL_PROCESSOR_IOPORTMANAGER_H
22 
23 #include "pedigree/kernel/Spinlock.h"
24 #include "pedigree/kernel/compiler.h"
25 #include "pedigree/kernel/processor/types.h"
26 #include "pedigree/kernel/utilities/RangeList.h"
27 #include "pedigree/kernel/utilities/Vector.h"
28 
29 class IoPort;
30 
34 #if !defined(KERNEL_PROCESSOR_NO_PORT_IO)
35 
39 {
40  friend class Processor;
41 
42  public:
44  inline static IoPortManager &instance()
45  {
46  return m_Instance;
47  }
48 
50  struct IoPortInfo
51  {
56  inline IoPortInfo(io_port_t IoPort, size_t size, const char *Name)
57  : ioPort(IoPort), sIoPort(size), name(Name)
58  {
59  }
60 
62  io_port_t ioPort;
64  size_t sIoPort;
66  const char *name;
67  };
68 
76  bool allocate(IoPort *Port, io_port_t ioPort, size_t size);
80  void free(IoPort *Port);
81 
87  void freeIoPortList(Vector<IoPortInfo *> &IoPorts);
88 
92  void initialise(io_port_t ioPortBase, size_t size) INITIALISATION_ONLY;
93 
94  private:
96  IoPortManager() INITIALISATION_ONLY;
98  virtual ~IoPortManager();
101  IoPortManager(const IoPortManager &);
104  IoPortManager &operator=(const IoPortManager &);
105 
108 
113 
115  static IoPortManager m_Instance;
116 };
117 
118 #endif
119 
122 #endif
IoPortInfo(io_port_t IoPort, size_t size, const char *Name)
Definition: IoPortManager.h:56
Vector< IoPort * > m_UsedIoPorts
A vector / dynamic array.
void free(IoPort *Port)
static IoPortManager & instance()
Definition: IoPortManager.h:44
Spinlock m_Lock
bool allocate(IoPort *Port, io_port_t ioPort, size_t size)
Manages hardware I/O port (de)allocations.
Definition: IoPortManager.h:38
static IoPortManager m_Instance
void initialise(io_port_t ioPortBase, size_t size) INITIALISATION_ONLY
I/O port range.
Definition: IoPort.h:34
void allocateIoPortList(Vector< IoPortInfo * > &IoPorts)
The exception was caused by a hardware task switch.
Definition: Processor.h:80
IoPortManager() INITIALISATION_ONLY
RangeList< uint32_t > m_FreeIoPorts
void freeIoPortList(Vector< IoPortInfo * > &IoPorts)