The Pedigree Project  0.1
BusMasterIde.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 BUSMASTERIDE_H
21 #define BUSMASTERIDE_H
22 
23 #include "pedigree/kernel/process/Mutex.h"
24 #include "pedigree/kernel/processor/MemoryRegion.h"
25 #include "pedigree/kernel/processor/types.h"
26 
27 class IoBase;
28 
33 #define BUSMASTER_VERBOSE_LOGGING 0
34 
36 typedef struct
37 {
38  // First bit = zero
39  uint32_t physAddr;
40 
41  // First bit = zero
42  uint16_t byteCount;
43 
44  // Last bit = EOT
45  uint16_t rsvdEot;
46 } __attribute__((packed)) PhysicalRegionDescriptor;
47 
49 typedef union
50 {
51  uint8_t reg;
52 
55  struct
56  {
57  uint8_t startStop : 1;
58  uint8_t rsvd1 : 2;
59  uint8_t rwCtl : 1;
60  uint8_t rsvd2 : 4;
61  } __attribute__((packed)) bits;
63 
65 typedef union
66 {
67  uint8_t reg;
68  struct bits
69  {
70  uint8_t bmIdeActive : 1;
71  uint8_t error : 1;
72  uint8_t interrupt : 1;
73  uint8_t rsvd : 2;
74  uint8_t drv0Capable : 1;
75  uint8_t drv1Capable : 1;
76  uint8_t simplexOnly : 1;
77  } __attribute__((packed)) bits;
79 
81 typedef struct
82 {
84  uint32_t baseAddress;
86 
96 {
97  public:
98  BusMasterIde();
99  virtual ~BusMasterIde();
100 
111  bool initialise(IoBase *pBase);
112 
124  bool add(uintptr_t buffer, size_t nBytes);
125 
137  bool begin(bool bWrite);
138 
148  bool hasInterrupt();
149 
158  bool hasError();
159 
167  bool hasCompleted();
168 
181  void commandComplete();
182 
191  bool isActive() const
192  {
193  return m_bActive;
194  }
195 
196  private:
199 
202 
204  PhysicalRegionDescriptor *m_PrdTable;
205 
209 
211  physical_uintptr_t m_PrdTablePhys;
212 
215 
217  bool m_bActive;
218 
221  {
222  Command = 0, // R/W
223  DeviceSpecific1 = 1, // --
224  Status = 2, // R/W/C
225  DeviceSpecific2 = 3, // --
226  PrdTableAddr = 4 // R/W
227  };
228 };
229 
230 #endif
uint32_t baseAddress
Base address of the table, first two bits must be zero.
Definition: BusMasterIde.h:84
size_t m_LastPrdTableOffset
Definition: BusMasterIde.h:208
IoBase * m_pBase
Definition: BusMasterIde.h:198
Mutex m_PrdTableLock
Definition: BusMasterIde.h:201
Definition: Mutex.h:58
MemoryRegion m_PrdTableMemRegion
Definition: BusMasterIde.h:214
Abstrace base class for hardware I/O capabilities.
Definition: IoBase.h:31
PhysicalRegionDescriptor * m_PrdTable
Definition: BusMasterIde.h:204
physical_uintptr_t m_PrdTablePhys
Definition: BusMasterIde.h:211
Special memory entity in the kernel's virtual address space.
Definition: MemoryRegion.h:35
bool isActive() const
Is there currently a DMA transaction taking place?
Definition: BusMasterIde.h:191