NeKernel dev
Loading...
Searching...
No Matches
DMA.h
Go to the documentation of this file.
1/* ========================================
2
3 Copyright (C) 2024-2025, Amlal El Mahrouss, licensed under the Apache 2.0 license.
4
5======================================== */
6
7#pragma once
8
11#include <NeKit/Array.h>
12#include <NeKit/OwnPtr.h>
13#include <NeKit/Ref.h>
14
15namespace Kernel {
16enum class DmaKind {
17 PCI = 10, // Bus mastering is required to be turned on. Basiaclly a request
18 // control system. 64-Bit access depends on the PAE bit and the device
19 // (if Double Address Cycle is available)
20 ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM.
21 Count = 2,
23};
24
25class DMAWrapper final {
26 public:
27 explicit DMAWrapper() = delete;
28
29 public:
30 explicit DMAWrapper(nullPtr) = delete;
31 explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI) : fAddress(Ptr), fKind(Kind) {}
32
33 public:
35
36 public:
37 DMAWrapper& operator=(const DMAWrapper&) = default;
38 DMAWrapper(const DMAWrapper&) = default;
39
40 public:
41 ~DMAWrapper() = default;
42
43 template <class T>
44 T* operator->();
45
46 template <class T>
47 T* Get(UIntPtr off = 0);
48
49 public:
50 operator bool();
51 bool operator!();
52
53 public:
54 bool Write(UIntPtr& bit, const UInt32& offset);
55 UIntPtr Read(const UInt32& offset);
56 Boolean Check(UIntPtr offset) const;
57
58 public:
59 UIntPtr operator[](UIntPtr& offset);
60
61 private:
62 voidPtr fAddress{nullptr};
64
65 private:
66 friend class DMAFactory;
67};
68
69class DMAFactory final {
70 public:
72};
73} // namespace Kernel
74
75#include <KernelKit/PCI/DMA.inl>
Definition DMA.h:69
static OwnPtr< IOBuf< Char * > > Construct(OwnPtr< DMAWrapper > &dma)
Definition DMA.cc:56
Definition DMA.h:25
bool operator!()
Definition DMA.cc:15
DMAWrapper & operator=(voidPtr Ptr)
Definition DMA.cc:68
UIntPtr Read(const UInt32 &offset)
Definition DMA.cc:41
DMAWrapper & operator=(const DMAWrapper &)=default
bool Write(UIntPtr &bit, const UInt32 &offset)
Definition DMA.cc:28
DMAWrapper(voidPtr Ptr, DmaKind Kind=DmaKind::PCI)
Definition DMA.h:31
Boolean Check(UIntPtr offset) const
Definition DMA.cc:19
~DMAWrapper()=default
friend class DMAFactory
Definition DMA.h:66
DmaKind fKind
Definition DMA.h:63
voidPtr fAddress
Definition DMA.h:62
T * operator->()
Definition DMA.inl:9
T * Get(UIntPtr off=0)
Definition DMA.inl:14
DMAWrapper(nullPtr)=delete
UIntPtr operator[](UIntPtr &offset)
Definition DMA.cc:52
DMAWrapper(const DMAWrapper &)=default
Definition OwnPtr.h:23
Definition Device.cc:38
UPS inline definitions.
Definition Device.h:12
void * voidPtr
Definition Config.h:32
decltype(nullptr) nullPtr
Definition Config.h:34
__UINT32_TYPE__ UInt32
Definition Config.h:44
bool Boolean
Definition Config.h:49
__UINTPTR_TYPE__ UIntPtr
Definition Config.h:62
DmaKind
Definition DMA.h:16
@ Invalid
Definition DMA.h:22
@ ISA
Definition DMA.h:20
@ PCI
Definition DMA.h:17
@ Count
Definition DMA.h:21