NeKernel dev
Loading...
Searching...
No Matches
DeviceMgr.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/* ========================================
8
9 Revision History:
10
11 31/01/24: Add kDeviceCnt (amlel)
12 15/11/24: Add NE_DEVICE macro, to inherit from device object.
13
14 ======================================== */
15
16#pragma once
17
18/* @note Device Mgr. */
19/* @file KernelKit/DeviceMgr.h */
20/* @brief Device abstraction and I/O buffer. */
21
22#include <NeKit/ErrorOr.h>
23#include <NeKit/Ref.h>
24
25#define kDeviceMgrRootDirPath "/devices/"
26
27#define NE_DEVICE : public ::Kernel::DeviceInterface
28
29// Last Rev: Wed, May 27, 2025 6:22 PM
30
31namespace Kernel {
32template <typename T>
33class DeviceInterface;
34
35template <typename T>
36class IOBuf;
37
38/***********************************************************************************/
40/***********************************************************************************/
41template <typename T>
43 public:
44 DeviceInterface() = default;
45
46 explicit DeviceInterface(void (*Out)(DeviceInterface<T>*, T), void (*In)(DeviceInterface<T>*, T))
47 : fOut(Out), fIn(In) {}
48
49 virtual ~DeviceInterface() = default;
50
51 public:
54
55 public:
56 virtual DeviceInterface<T>& operator<<(T Data) {
57 fOut(this, Data);
58 return *this;
59 }
60
61 virtual DeviceInterface<T>& operator>>(T Data) {
62 fIn(this, Data);
63 return *this;
64 }
65
66 virtual const char* Name() const { return "/devices/null"; }
67
68 operator bool() { return fOut && fIn; }
69
70 Bool operator!() { return !fOut || !fIn; }
71
72 protected:
73 Void (*fOut)(DeviceInterface<T>*, T Data) = {nullptr};
74 Void (*fIn)(DeviceInterface<T>*, T Data) = {nullptr};
75};
76
81template <typename T>
82class IOBuf final {
83 public:
84 explicit IOBuf(T dma_addr) : fData(dma_addr) {
85 // At least pass something valid when instancating this struct.
87 }
88
89 IOBuf& operator=(const IOBuf<T>&) = default;
90 IOBuf(const IOBuf<T>&) = default;
91
92 ~IOBuf() = default;
93
94 public:
95 template <typename R>
96 R operator->() const {
97 return fData;
98 }
99
100 template <typename R>
101 R& operator[](Size index) const {
102 return fData[index];
103 }
104
105 private:
107};
108
110enum {
123 kDeviceTypeAPM, // Adv. Pwr. Mgmt.
128};
129} // namespace Kernel
#define MUST_PASS(EXPR)
Definition KernelPanic.h:37
Void(* fOut)(DeviceInterface< T > *, T Data)
Definition DeviceMgr.h:73
virtual ~DeviceInterface()=default
virtual DeviceInterface< T > & operator<<(T Data)
Definition DeviceMgr.h:56
DeviceInterface(void(*Out)(DeviceInterface< T > *, T), void(*In)(DeviceInterface< T > *, T))
Definition DeviceMgr.h:46
Bool operator!()
Definition DeviceMgr.h:70
Void(* fIn)(DeviceInterface< T > *, T Data)
Definition DeviceMgr.h:74
DeviceInterface & operator=(const DeviceInterface< T > &)=default
virtual const char * Name() const
Definition DeviceMgr.h:66
virtual DeviceInterface< T > & operator>>(T Data)
Definition DeviceMgr.h:61
DeviceInterface(const DeviceInterface< T > &)=default
R & operator[](Size index) const
Definition DeviceMgr.h:101
IOBuf & operator=(const IOBuf< T > &)=default
R operator->() const
Definition DeviceMgr.h:96
~IOBuf()=default
T fData
Definition DeviceMgr.h:106
IOBuf(const IOBuf< T > &)=default
IOBuf(T dma_addr)
Definition DeviceMgr.h:84
UPS inline definitions.
Definition Device.h:12
void Void
Definition Config.h:87
@ kDeviceTypeBT
Definition DeviceMgr.h:116
@ kDeviceTypeAHCI
Definition DeviceMgr.h:119
@ kDeviceTypeIDE
Definition DeviceMgr.h:112
@ kDeviceTypeVGA
Definition DeviceMgr.h:125
@ kDeviceTypeUSB
Definition DeviceMgr.h:122
@ kDeviceTypeMBCI
Definition DeviceMgr.h:120
@ kDeviceTypeInvalid
Definition DeviceMgr.h:111
@ kDeviceTypeCount
Definition DeviceMgr.h:127
@ kDeviceTypeEthernet
Definition DeviceMgr.h:113
@ kDeviceTypeAPM
Definition DeviceMgr.h:123
@ kDeviceTypePCI
Definition DeviceMgr.h:124
@ kDeviceTypeATA
Definition DeviceMgr.h:121
@ kDeviceTypeFW
Definition DeviceMgr.h:115
@ kDeviceTypeWiFi
Definition DeviceMgr.h:114
@ kDeviceTypeGPU
Definition DeviceMgr.h:126
@ kDeviceTypeRS232
Definition DeviceMgr.h:117
@ kDeviceTypeSCSI
Definition DeviceMgr.h:118
__SIZE_TYPE__ Size
Definition Config.h:59
bool Bool
Definition Config.h:50