The Pedigree Project  0.1
X86IsaDma.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 X86_ISA_DMA_H
21 #define X86_ISA_DMA_H
22 
23 #include "../IsaDma.h"
24 #include "pedigree/kernel/Log.h"
25 #include "pedigree/kernel/processor/IoPort.h"
26 #include "pedigree/kernel/processor/types.h"
27 
29 namespace MasterChip
30 {
31 enum MasterRegs
32 {
33  Status = 0xD0, // Read
34  Command = 0xD0, // Write
35  Request = 0xD2, // Write
36  ChannelMask = 0xD4, // Write
37  Mode = 0xD6, // Write
38  ByteWord = 0xD8, // Read
39  Intermediate = 0xDA, // Read
40  Mask = 0xDE, // Write
41 };
42 
43 enum BaseRegisters
44 {
45  AddressChannel0_4 = 0xC0,
46  CountChannel0_4 = 0xC1,
47 
48  AddressChannel1_5 = 0xC2,
49  CountChannel1_5 = 0xC3,
50 
51  AddressChannel2_6 = 0xC4,
52  CountChannel2_6 = 0xC5,
53 
54  AddressChannel3_7 = 0xC6,
55  CountChannel3_7 = 0xC7,
56 };
57 } // namespace MasterChip
58 
60 namespace SlaveChip
61 {
62 enum SlaveRegs
63 {
64  Status = 0x08, // Read
65  Command = 0x08, // Write
66  Request = 0x09, // Write
67  ChannelMask = 0x0A, // Write
68  Mode = 0x0B, // Write
69  ByteWord = 0x0C, // Read
70  Intermediate = 0x0D, // Read
71  Mask = 0x0F, // Write
72 };
73 
74 enum BaseRegisters
75 {
76  AddressChannel0_4 = 0x00,
77  CountChannel0_4 = 0x01,
78 
79  AddressChannel1_5 = 0x02,
80  CountChannel1_5 = 0x03,
81 
82  AddressChannel2_6 = 0x04,
83  CountChannel2_6 = 0x05,
84 
85  AddressChannel3_7 = 0x05,
86  CountChannel3_7 = 0x07,
87 };
88 } // namespace SlaveChip
89 
91 namespace PageRegisters
92 {
93 enum PageAddressRegister
94 {
95  Channel0 = 0x87,
96  Channel1 = 0x83,
97  Channel2 = 0x81,
98  Channel3 = 0x82,
99  Channel4 = 0x8F,
100  Channel5 = 0x8B,
101  Channel6 = 0x89,
102  Channel7 = 0x8A,
103 };
104 }
105 
111 class X86IsaDma : public IsaDma
112 {
113  public:
114  enum TransferModes
115  {
116  SelfTest = 0,
117  Write = (1 << 2),
118  Read = (2 << 2),
119  Cascade = (3 << 2),
120  AutoInit = (1 << 4),
121  Increment = 0,
122  Decrement = (1 << 5),
123  OnDemand = 0,
124  Single = (1 << 6),
125  Block = (2 << 6)
126  };
127 
128  X86IsaDma() : m_Io("isa-dma")
129  {
130  if (!m_Io.allocate(0, 0x100))
131  ERROR("X86IsaDma: Couldn't allocate port range");
132  }
133  virtual ~X86IsaDma()
134  {
135  }
136 
137  static X86IsaDma &instance()
138  {
139  return m_Instance;
140  }
141 
143  virtual bool
144  initTransfer(uint8_t channel, uint8_t mode, size_t length, uintptr_t addr);
145 
146  private:
147  void resetFlipFlop(uint8_t chan);
148 
149  void resetHard(uint8_t chan);
150 
151  void unmaskAll();
152 
153  bool internalSetup(uint8_t channel, size_t length, uintptr_t addr);
154 
155  IoPort m_Io;
156 
157  static X86IsaDma m_Instance;
158 };
159 
160 #endif
I/O port range.
Definition: IoPort.h:34
Definition: IsaDma.h:35
#define ERROR(text)
Definition: Log.h:82