summaryrefslogtreecommitdiffhomepage
path: root/dev/Kernel/KernelKit/PCI/IO.h
blob: 3e8e8ff3eee6f3f7b94bd120afdd1848d14dc9a8 (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
/* -------------------------------------------

	Copyright (C) 2024, MediaSwirl, 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;
	};

	using IOArray16 = IOArray<16>;
} // namespace Kernel

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