summaryrefslogtreecommitdiffhomepage
path: root/dev/kernel/KernelKit/PCI/IO.h
blob: 78fcef7690f805e287365e927ebdae0e670358b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* -------------------------------------------

	Copyright (C) 2024-2025, Amlal El Mahrouss, all rights reserved.

------------------------------------------- */

#pragma once

#include <ArchKit/ArchKit.h>
#include <NewKit/Array.h>
#include <NewKit/Defines.h>
#include <NewKit/Ref.h>

namespace Kernel
{
	template <SizeT Sz>
	class IOArray final
	{
	public:
		IOArray() = delete;

		IOArray(nullPtr) = delete;

		explicit IOArray(Array<UShort, Sz>& ports)
			: fPorts(ports)
		{
		}

		~IOArray()
		{
		}

		IOArray& operator=(const IOArray&) = default;

		IOArray(const IOArray&) = default;

		operator bool()
		{
			return !fPorts.Empty();
		}

	public:
		template <typename T>
		T In(SizeT index);

		template <typename T>
		void Out(SizeT index, T value);

	private:
		Array<UShort, Sz> fPorts;
	};

	inline constexpr UInt16 kMaxPorts = 16;

	using IOArray16 = IOArray<kMaxPorts>;

	template <SizeT Sz>
	inline Array<UShort, Sz> make_ports(UShort base)
	{
		Array<UShort, Sz> ports;

		for (UShort i = 0; i < Sz; ++i)
		{
			ports[i] = base + i;
		}

		return ports;
	}
} // namespace Kernel

#ifdef __x86_64__
#include <KernelKit/PCI/IOArray+AMD64.inl>
#else
#error Please provide platform specific code for the I/O
#endif // ifdef __x86_64__