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/Atomic.h"
24#include "pedigree/kernel/process/Mutex.h"
25#include "pedigree/kernel/processor/MemoryRegion.h"
26#include "pedigree/kernel/processor/types.h"
27
28class IoBase;
29
34inline constexpr bool BusMasterVerboseLogging = false;
35
37typedef struct {
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
49typedef union {
50 uint8_t reg;
51
54 struct {
55 uint8_t startStop : 1;
56 uint8_t rsvd1 : 2;
57 uint8_t rwCtl : 1;
58 uint8_t rsvd2 : 4;
59 } __attribute__((packed)) bits;
61
63typedef union {
64 uint8_t reg;
65 struct bits {
66 uint8_t bmIdeActive : 1;
67 uint8_t error : 1;
68 uint8_t interrupt : 1;
69 uint8_t rsvd : 2;
70 uint8_t drv0Capable : 1;
71 uint8_t drv1Capable : 1;
72 uint8_t simplexOnly : 1;
73 } __attribute__((packed)) bits;
75
81
91 public:
93 virtual ~BusMasterIde();
94
105 bool initialise(IoBase* pBase);
106
113 bool beginTransaction();
114
126 bool add(uintptr_t buffer, size_t nBytes);
127
139 bool begin(bool bWrite);
140
150 bool hasInterrupt();
151
160 bool hasError();
161
169 bool hasCompleted();
170
183 void commandComplete();
184
192
201 bool isActive() const {
202 return static_cast<bool>(m_bActive);
203 }
204
205 private:
208
211
213 PhysicalRegionDescriptor* m_PrdTable;
214
218
220 physical_uintptr_t m_PrdTablePhys;
221
224
227
230 Command = 0, // R/W
231 DeviceSpecific1 = 1, // --
232 Status = 2, // R/W/C
233 DeviceSpecific2 = 3, // --
234 PrdTableAddr = 4 // R/W
235 };
236};
237
238#endif
bool beginTransaction()
bool add(uintptr_t buffer, size_t nBytes)
Adds a buffer to a DMA transaction.
bool hasError()
Determines if an ERROR has occurred on this channel.
size_t m_LastPrdTableOffset
bool isActive() const
Is there currently a DMA transaction taking place?
bool completeIdleTransaction()
Atomic< bool > m_bActive
IoBase * m_pBase
bool hasCompleted()
Determines if the CURRENT TRANSFER has completed.
bool initialise(IoBase *pBase)
Initialises DMA for a specific channel.
void commandComplete()
Called by drivers when a command completes.
bool hasInterrupt()
Determines if an INTERRUPT has occurred on this channel.
Mutex m_PrdTableLock
MemoryRegion m_PrdTableMemRegion
bool begin(bool bWrite)
Begin a DMA operation.
physical_uintptr_t m_PrdTablePhys
PhysicalRegionDescriptor * m_PrdTable
Abstrace base class for hardware I/O capabilities.
Definition IoBase.h:32
Special memory entity in the kernel's virtual address space.
Definition Mutex.h:56
uint32_t baseAddress
Base address of the table, first two bits must be zero.