From d48cbe75ef29a9c67c9d176bf58e56ea6448fb9e Mon Sep 17 00:00:00 2001 From: Amlal El Mahrouss Date: Mon, 21 Oct 2024 20:23:36 +0200 Subject: IMP: Major refactor of header and source files extensions. Signed-off-by: Amlal El Mahrouss --- dev/zka/KernelKit/PCI/DMA.h | 81 ++++++++++++++++++++++++++++++++++++++ dev/zka/KernelKit/PCI/DMA.hxx | 81 -------------------------------------- dev/zka/KernelKit/PCI/Database.h | 38 ++++++++++++++++++ dev/zka/KernelKit/PCI/Database.hxx | 38 ------------------ dev/zka/KernelKit/PCI/Device.h | 80 +++++++++++++++++++++++++++++++++++++ dev/zka/KernelKit/PCI/Device.hxx | 80 ------------------------------------- dev/zka/KernelKit/PCI/Express.h | 11 ++++++ dev/zka/KernelKit/PCI/Express.hxx | 11 ------ dev/zka/KernelKit/PCI/IO.h | 59 +++++++++++++++++++++++++++ dev/zka/KernelKit/PCI/IO.hxx | 59 --------------------------- dev/zka/KernelKit/PCI/Iterator.h | 43 ++++++++++++++++++++ dev/zka/KernelKit/PCI/Iterator.hxx | 43 -------------------- dev/zka/KernelKit/PCI/PCI.h | 59 +++++++++++++++++++++++++++ dev/zka/KernelKit/PCI/PCI.hxx | 59 --------------------------- 14 files changed, 371 insertions(+), 371 deletions(-) create mode 100644 dev/zka/KernelKit/PCI/DMA.h delete mode 100644 dev/zka/KernelKit/PCI/DMA.hxx create mode 100644 dev/zka/KernelKit/PCI/Database.h delete mode 100644 dev/zka/KernelKit/PCI/Database.hxx create mode 100644 dev/zka/KernelKit/PCI/Device.h delete mode 100644 dev/zka/KernelKit/PCI/Device.hxx create mode 100644 dev/zka/KernelKit/PCI/Express.h delete mode 100644 dev/zka/KernelKit/PCI/Express.hxx create mode 100644 dev/zka/KernelKit/PCI/IO.h delete mode 100644 dev/zka/KernelKit/PCI/IO.hxx create mode 100644 dev/zka/KernelKit/PCI/Iterator.h delete mode 100644 dev/zka/KernelKit/PCI/Iterator.hxx create mode 100644 dev/zka/KernelKit/PCI/PCI.h delete mode 100644 dev/zka/KernelKit/PCI/PCI.hxx (limited to 'dev/zka/KernelKit/PCI') diff --git a/dev/zka/KernelKit/PCI/DMA.h b/dev/zka/KernelKit/PCI/DMA.h new file mode 100644 index 00000000..d13f2c05 --- /dev/null +++ b/dev/zka/KernelKit/PCI/DMA.h @@ -0,0 +1,81 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include +#include + +namespace Kernel +{ + enum class DmaKind + { + PCI, // Bus mastering is required to be turned on. Basiaclly a request + // control system. 64-Bit access depends on the PAE bit and the device + // (if Double Address Cycle is available) + ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. + Invalid, + }; + + class DMAWrapper final + { + public: + explicit DMAWrapper() = delete; + + public: + explicit DMAWrapper(nullPtr) = delete; + explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI) + : fAddress(Ptr), fKind(Kind) + { + } + + public: + DMAWrapper& operator=(voidPtr Ptr); + + public: + DMAWrapper& operator=(const DMAWrapper&) = default; + DMAWrapper(const DMAWrapper&) = default; + + public: + ~DMAWrapper() = default; + + template + T* operator->(); + + template + T* Get(const UIntPtr off = 0); + + public: + operator bool(); + bool operator!(); + + public: + bool Write(const UIntPtr& bit, const UIntPtr& offset); + UIntPtr Read(const UIntPtr& offset); + Boolean Check(UIntPtr offset) const; + + public: + UIntPtr operator[](const UIntPtr& offset); + + private: + voidPtr fAddress{nullptr}; + DmaKind fKind{DmaKind::Invalid}; + + private: + friend class DMAFactory; + }; + + class DMAFactory final + { + public: + static OwnPtr> Construct(OwnPtr& dma); + }; +} // namespace Kernel + +#include diff --git a/dev/zka/KernelKit/PCI/DMA.hxx b/dev/zka/KernelKit/PCI/DMA.hxx deleted file mode 100644 index 94dd5ad5..00000000 --- a/dev/zka/KernelKit/PCI/DMA.hxx +++ /dev/null @@ -1,81 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include -#include - -namespace Kernel -{ - enum class DmaKind - { - PCI, // Bus mastering is required to be turned on. Basiaclly a request - // control system. 64-Bit access depends on the PAE bit and the device - // (if Double Address Cycle is available) - ISA, // Four DMA channels 0-3; 8 bit transfers and only a megabyte of RAM. - Invalid, - }; - - class DMAWrapper final - { - public: - explicit DMAWrapper() = delete; - - public: - explicit DMAWrapper(nullPtr) = delete; - explicit DMAWrapper(voidPtr Ptr, DmaKind Kind = DmaKind::PCI) - : fAddress(Ptr), fKind(Kind) - { - } - - public: - DMAWrapper& operator=(voidPtr Ptr); - - public: - DMAWrapper& operator=(const DMAWrapper&) = default; - DMAWrapper(const DMAWrapper&) = default; - - public: - ~DMAWrapper() = default; - - template - T* operator->(); - - template - T* Get(const UIntPtr off = 0); - - public: - operator bool(); - bool operator!(); - - public: - bool Write(const UIntPtr& bit, const UIntPtr& offset); - UIntPtr Read(const UIntPtr& offset); - Boolean Check(UIntPtr offset) const; - - public: - UIntPtr operator[](const UIntPtr& offset); - - private: - voidPtr fAddress{nullptr}; - DmaKind fKind{DmaKind::Invalid}; - - private: - friend class DMAFactory; - }; - - class DMAFactory final - { - public: - static OwnPtr> Construct(OwnPtr& dma); - }; -} // namespace Kernel - -#include diff --git a/dev/zka/KernelKit/PCI/Database.h b/dev/zka/KernelKit/PCI/Database.h new file mode 100644 index 00000000..4985049a --- /dev/null +++ b/dev/zka/KernelKit/PCI/Database.h @@ -0,0 +1,38 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ +#pragma once + +#include +#include + +namespace Kernel +{ + namespace Types + { + // https://wiki.osdev.org/PCI + enum class PciDeviceKind : UChar + { + MassStorageController = 0x1, + NetworkController = 0x2, + DisplayController = 0x3, + MultimediaController = 0x4, + MemoryController = 0x5, + Bridge = 0x6, + CommunicationController = 0x7, + GenericSystemPeripheral = 0x8, + InputDeviceController = 0x9, + DockingStation = 0xa, + Processor = 0xb, + SerialBusController = 0xc, + WirelessController = 0xd, + IntelligentController = 0xe, + SatelliteCommunicationsController = 0xf, + CoProcessor = 0x40, + Unassgined = 0xf, + Invalid = Unassgined, + }; + } // namespace Types +} // namespace Kernel diff --git a/dev/zka/KernelKit/PCI/Database.hxx b/dev/zka/KernelKit/PCI/Database.hxx deleted file mode 100644 index 16b5c787..00000000 --- a/dev/zka/KernelKit/PCI/Database.hxx +++ /dev/null @@ -1,38 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ -#pragma once - -#include -#include - -namespace Kernel -{ - namespace Types - { - // https://wiki.osdev.org/PCI - enum class PciDeviceKind : UChar - { - MassStorageController = 0x1, - NetworkController = 0x2, - DisplayController = 0x3, - MultimediaController = 0x4, - MemoryController = 0x5, - Bridge = 0x6, - CommunicationController = 0x7, - GenericSystemPeripheral = 0x8, - InputDeviceController = 0x9, - DockingStation = 0xa, - Processor = 0xb, - SerialBusController = 0xc, - WirelessController = 0xd, - IntelligentController = 0xe, - SatelliteCommunicationsController = 0xf, - CoProcessor = 0x40, - Unassgined = 0xf, - Invalid = Unassgined, - }; - } // namespace Types -} // namespace Kernel diff --git a/dev/zka/KernelKit/PCI/Device.h b/dev/zka/KernelKit/PCI/Device.h new file mode 100644 index 00000000..cdedb92b --- /dev/null +++ b/dev/zka/KernelKit/PCI/Device.h @@ -0,0 +1,80 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ +#pragma once + +#include + +namespace Kernel::PCI +{ + enum class PciConfigKind : UShort + { + ConfigAddress = 0xCF8, + ConfigData = 0xCFC, + Invalid = 0xFFF + }; + + class Device final + { + public: + Device() = default; + + public: + explicit Device(UShort bus, UShort device, UShort function, UInt32 bar); + + Device& operator=(const Device&) = default; + + Device(const Device&) = default; + + ~Device(); + + public: + UInt Read(UInt bar, Size szData); + void Write(UInt bar, UIntPtr data, Size szData); + + public: + operator bool(); + + public: + template + UInt Read(UInt bar) + { + static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported"); + return Read(bar, sizeof(T)); + } + + template + void Write(UInt bar, UIntPtr data) + { + static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported"); + Write(bar, data, sizeof(T)); + } + + public: + UShort DeviceId(); + UShort VendorId(); + UShort InterfaceId(); + UChar Class(); + UChar Subclass(); + UChar ProgIf(); + UChar HeaderType(); + UInt32 Bar(UInt32 bar_in); + + public: + void EnableMmio(UInt32 bar_in); + void BecomeBusMaster(UInt32 bar_in); // for PCI-DMA, PC-DMA does not need that. + + UShort Vendor(); + + private: + UShort fBus; + UShort fDevice; + UShort fFunction; + UInt32 fBar; + }; +} // namespace Kernel::PCI + +EXTERN_C void NewOSPCISetCfgTarget(Kernel::UInt bar); +EXTERN_C Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar); diff --git a/dev/zka/KernelKit/PCI/Device.hxx b/dev/zka/KernelKit/PCI/Device.hxx deleted file mode 100644 index bc1b4eb7..00000000 --- a/dev/zka/KernelKit/PCI/Device.hxx +++ /dev/null @@ -1,80 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ -#pragma once - -#include - -namespace Kernel::PCI -{ - enum class PciConfigKind : UShort - { - ConfigAddress = 0xCF8, - ConfigData = 0xCFC, - Invalid = 0xFFF - }; - - class Device final - { - public: - Device() = default; - - public: - explicit Device(UShort bus, UShort device, UShort function, UInt32 bar); - - Device& operator=(const Device&) = default; - - Device(const Device&) = default; - - ~Device(); - - public: - UInt Read(UInt bar, Size szData); - void Write(UInt bar, UIntPtr data, Size szData); - - public: - operator bool(); - - public: - template - UInt Read(UInt bar) - { - static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported"); - return Read(bar, sizeof(T)); - } - - template - void Write(UInt bar, UIntPtr data) - { - static_assert(sizeof(T) <= 4, "64-bit PCI addressing is unsupported"); - Write(bar, data, sizeof(T)); - } - - public: - UShort DeviceId(); - UShort VendorId(); - UShort InterfaceId(); - UChar Class(); - UChar Subclass(); - UChar ProgIf(); - UChar HeaderType(); - UInt32 Bar(UInt32 bar_in); - - public: - void EnableMmio(UInt32 bar_in); - void BecomeBusMaster(UInt32 bar_in); // for PCI-DMA, PC-DMA does not need that. - - UShort Vendor(); - - private: - UShort fBus; - UShort fDevice; - UShort fFunction; - UInt32 fBar; - }; -} // namespace Kernel::PCI - -EXTERN_C void NewOSPCISetCfgTarget(Kernel::UInt bar); -EXTERN_C Kernel::UInt NewOSPCIReadRaw(Kernel::UInt bar); diff --git a/dev/zka/KernelKit/PCI/Express.h b/dev/zka/KernelKit/PCI/Express.h new file mode 100644 index 00000000..57962631 --- /dev/null +++ b/dev/zka/KernelKit/PCI/Express.h @@ -0,0 +1,11 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include + +#define PCI_EXPRESS_BUS_COUNT (4096) diff --git a/dev/zka/KernelKit/PCI/Express.hxx b/dev/zka/KernelKit/PCI/Express.hxx deleted file mode 100644 index 1e7ce5bc..00000000 --- a/dev/zka/KernelKit/PCI/Express.hxx +++ /dev/null @@ -1,11 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include - -#define PCI_EXPRESS_BUS_COUNT (4096) diff --git a/dev/zka/KernelKit/PCI/IO.h b/dev/zka/KernelKit/PCI/IO.h new file mode 100644 index 00000000..d42119f2 --- /dev/null +++ b/dev/zka/KernelKit/PCI/IO.h @@ -0,0 +1,59 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include +#include +#include +#include + +namespace Kernel +{ + template + class IOArray final + { + public: + IOArray() = delete; + + IOArray(nullPtr) = delete; + + explicit IOArray(Array& ports) + : fPorts(ports) + { + } + ~IOArray() + { + } + + IOArray& operator=(const IOArray&) = default; + + IOArray(const IOArray&) = default; + + operator bool() + { + return !fPorts.Empty(); + } + + public: + template + T In(SizeT index); + + template + void Out(SizeT index, T value); + + private: + Array fPorts; + }; + + using IOArray16 = IOArray<16>; +} // namespace Kernel + +#ifdef __x86_64__ +#include +#else +#error Please provide platform specific code for the I/O +#endif // ifdef __x86_64__ diff --git a/dev/zka/KernelKit/PCI/IO.hxx b/dev/zka/KernelKit/PCI/IO.hxx deleted file mode 100644 index 58287a9b..00000000 --- a/dev/zka/KernelKit/PCI/IO.hxx +++ /dev/null @@ -1,59 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include -#include -#include -#include - -namespace Kernel -{ - template - class IOArray final - { - public: - IOArray() = delete; - - IOArray(nullPtr) = delete; - - explicit IOArray(Array& ports) - : fPorts(ports) - { - } - ~IOArray() - { - } - - IOArray& operator=(const IOArray&) = default; - - IOArray(const IOArray&) = default; - - operator bool() - { - return !fPorts.Empty(); - } - - public: - template - T In(SizeT index); - - template - void Out(SizeT index, T value); - - private: - Array fPorts; - }; - - using IOArray16 = IOArray<16>; -} // namespace Kernel - -#ifdef __x86_64__ -#include -#else -#error Please provide platform specific code for the I/O -#endif // ifdef __x86_64__ diff --git a/dev/zka/KernelKit/PCI/Iterator.h b/dev/zka/KernelKit/PCI/Iterator.h new file mode 100644 index 00000000..232a4671 --- /dev/null +++ b/dev/zka/KernelKit/PCI/Iterator.h @@ -0,0 +1,43 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#ifndef __PCI_ITERATOR_HPP__ +#define __PCI_ITERATOR_HPP__ + +#include +#include +#include +#include +#include + +#define ZKA_BUS_COUNT (256) +#define ZKA_DEVICE_COUNT (33) +#define ZKA_FUNCTION_COUNT (8) + +namespace Kernel::PCI +{ + class Iterator final + { + public: + Iterator() = delete; + + public: + explicit Iterator(const Types::PciDeviceKind& deviceType); + + Iterator& operator=(const Iterator&) = default; + Iterator(const Iterator&) = default; + + ~Iterator(); + + public: + Ref operator[](const Size& sz); + + private: + Array fDevices; + }; +} // namespace Kernel::PCI + +#endif // __PCI_ITERATOR_HPP__ diff --git a/dev/zka/KernelKit/PCI/Iterator.hxx b/dev/zka/KernelKit/PCI/Iterator.hxx deleted file mode 100644 index a065f9de..00000000 --- a/dev/zka/KernelKit/PCI/Iterator.hxx +++ /dev/null @@ -1,43 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#ifndef __PCI_ITERATOR_HPP__ -#define __PCI_ITERATOR_HPP__ - -#include -#include -#include -#include -#include - -#define ZKA_BUS_COUNT (256) -#define ZKA_DEVICE_COUNT (33) -#define ZKA_FUNCTION_COUNT (8) - -namespace Kernel::PCI -{ - class Iterator final - { - public: - Iterator() = delete; - - public: - explicit Iterator(const Types::PciDeviceKind& deviceType); - - Iterator& operator=(const Iterator&) = default; - Iterator(const Iterator&) = default; - - ~Iterator(); - - public: - Ref operator[](const Size& sz); - - private: - Array fDevices; - }; -} // namespace Kernel::PCI - -#endif // __PCI_ITERATOR_HPP__ diff --git a/dev/zka/KernelKit/PCI/PCI.h b/dev/zka/KernelKit/PCI/PCI.h new file mode 100644 index 00000000..b445074f --- /dev/null +++ b/dev/zka/KernelKit/PCI/PCI.h @@ -0,0 +1,59 @@ +/* ------------------------------------------- + + Copyright ZKA Web Services Co. + +------------------------------------------- */ + +#pragma once + +#include + +#define cPCIConfigAddressPort (0xCF8) +#define cPCIConfigDataPort (0xCFC) + +#define cPCIDeviceCount (32) +#define cPCIFuncCount (8) +#define cPCIBusCount (255) + +namespace Kernel::PCI +{ + // model + struct DeviceHeader + { + UInt16 VendorId; + UInt16 DeviceId; + UInt8 Command; + UInt8 Status; + UInt8 RevisionId; + UInt8 ProgIf; + UInt8 SubClass; + UInt8 Class; + UInt8 CacheLineSz; + UInt8 LatencyTimer; + UInt8 HeaderType; + UInt8 Bist; + UInt8 Bus; + UInt8 Device; + UInt8 Function; + }; + + namespace Detail + { + class BAR + { + public: + UIntPtr BAR; + SizeT Size; + }; + } // namespace Detail + + class BAR + { + public: + Detail::BAR BAR1; + Detail::BAR BAR2; + Detail::BAR BAR3; + Detail::BAR BAR4; + Detail::BAR BAR5; + }; +} // namespace Kernel::PCI diff --git a/dev/zka/KernelKit/PCI/PCI.hxx b/dev/zka/KernelKit/PCI/PCI.hxx deleted file mode 100644 index 2433be43..00000000 --- a/dev/zka/KernelKit/PCI/PCI.hxx +++ /dev/null @@ -1,59 +0,0 @@ -/* ------------------------------------------- - - Copyright ZKA Web Services Co. - -------------------------------------------- */ - -#pragma once - -#include - -#define cPCIConfigAddressPort (0xCF8) -#define cPCIConfigDataPort (0xCFC) - -#define cPCIDeviceCount (32) -#define cPCIFuncCount (8) -#define cPCIBusCount (255) - -namespace Kernel::PCI -{ - // model - struct DeviceHeader - { - UInt16 VendorId; - UInt16 DeviceId; - UInt8 Command; - UInt8 Status; - UInt8 RevisionId; - UInt8 ProgIf; - UInt8 SubClass; - UInt8 Class; - UInt8 CacheLineSz; - UInt8 LatencyTimer; - UInt8 HeaderType; - UInt8 Bist; - UInt8 Bus; - UInt8 Device; - UInt8 Function; - }; - - namespace Detail - { - class BAR - { - public: - UIntPtr BAR; - SizeT Size; - }; - } // namespace Detail - - class BAR - { - public: - Detail::BAR BAR1; - Detail::BAR BAR2; - Detail::BAR BAR3; - Detail::BAR BAR4; - Detail::BAR BAR5; - }; -} // namespace Kernel::PCI -- cgit v1.2.3