diff options
author | Liav A <liavalb@gmail.com> | 2022-09-02 13:41:48 +0300 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2022-09-20 18:43:05 +0100 |
commit | 1596ee241ffcbdbabf77f93b5132a782ae730923 (patch) | |
tree | 75a91a52c01243b3c59b905cbc863369eb2c9a6d /Kernel/Arch | |
parent | a02c9c956926bfacd8973624b52573606e9b5341 (diff) | |
download | serenity-1596ee241ffcbdbabf77f93b5132a782ae730923.zip |
Kernel/PCI: Move IO based HostBridge code to x86 arch-specific directory
The simple PCI::HostBridge class implements access to the PCI
configuration space by using x86 IO instructions. Therefore, it should
be put in the Arch/x86/PCI directory so it can be easily omitted for
non-x86 builds.
Diffstat (limited to 'Kernel/Arch')
-rw-r--r-- | Kernel/Arch/x86/PCI/Controller/HostBridge.cpp | 62 | ||||
-rw-r--r-- | Kernel/Arch/x86/PCI/Controller/HostBridge.h | 34 |
2 files changed, 96 insertions, 0 deletions
diff --git a/Kernel/Arch/x86/PCI/Controller/HostBridge.cpp b/Kernel/Arch/x86/PCI/Controller/HostBridge.cpp new file mode 100644 index 0000000000..81c7e34444 --- /dev/null +++ b/Kernel/Arch/x86/PCI/Controller/HostBridge.cpp @@ -0,0 +1,62 @@ +/* + * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include <Kernel/Arch/x86/IO.h> +#include <Kernel/Arch/x86/PCI/Controller/HostBridge.h> +#include <Kernel/Bus/PCI/Access.h> +#include <Kernel/Sections.h> + +namespace Kernel::PCI { + +NonnullOwnPtr<HostBridge> HostBridge::must_create_with_io_access() +{ + PCI::Domain domain { 0, 0, 0xff }; + return adopt_own_if_nonnull(new (nothrow) HostBridge(domain)).release_nonnull(); +} + +HostBridge::HostBridge(PCI::Domain const& domain) + : HostController(domain) +{ +} + +static u32 io_address_for_pci_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u8 field) +{ + return 0x80000000u | (bus.value() << 16u) | (device.value() << 11u) | (function.value() << 8u) | (field & 0xfc); +} + +void HostBridge::write8_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u32 field, u8 value) +{ + IO::out32(PCI::address_port, io_address_for_pci_field(bus, device, function, field)); + IO::out8(PCI::value_port + (field & 3), value); +} +void HostBridge::write16_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u32 field, u16 value) +{ + IO::out32(PCI::address_port, io_address_for_pci_field(bus, device, function, field)); + IO::out16(PCI::value_port + (field & 2), value); +} +void HostBridge::write32_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u32 field, u32 value) +{ + IO::out32(PCI::address_port, io_address_for_pci_field(bus, device, function, field)); + IO::out32(PCI::value_port, value); +} + +u8 HostBridge::read8_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u32 field) +{ + IO::out32(PCI::address_port, io_address_for_pci_field(bus, device, function, field)); + return IO::in8(PCI::value_port + (field & 3)); +} +u16 HostBridge::read16_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u32 field) +{ + IO::out32(PCI::address_port, io_address_for_pci_field(bus, device, function, field)); + return IO::in16(PCI::value_port + (field & 2)); +} +u32 HostBridge::read32_field(BusNumber bus, DeviceNumber device, FunctionNumber function, u32 field) +{ + IO::out32(PCI::address_port, io_address_for_pci_field(bus, device, function, field)); + return IO::in32(PCI::value_port); +} + +} diff --git a/Kernel/Arch/x86/PCI/Controller/HostBridge.h b/Kernel/Arch/x86/PCI/Controller/HostBridge.h new file mode 100644 index 0000000000..32705ea565 --- /dev/null +++ b/Kernel/Arch/x86/PCI/Controller/HostBridge.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il> + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include <AK/Bitmap.h> +#include <AK/NonnullOwnPtr.h> +#include <AK/OwnPtr.h> +#include <AK/Vector.h> +#include <Kernel/Bus/PCI/Controller/HostController.h> +#include <Kernel/Locking/Spinlock.h> + +namespace Kernel::PCI { + +class HostBridge : public HostController { +public: + static NonnullOwnPtr<HostBridge> must_create_with_io_access(); + + virtual void write8_field(BusNumber, DeviceNumber, FunctionNumber, u32 field, u8 value) override; + virtual void write16_field(BusNumber, DeviceNumber, FunctionNumber, u32 field, u16 value) override; + virtual void write32_field(BusNumber, DeviceNumber, FunctionNumber, u32 field, u32 value) override; + + virtual u8 read8_field(BusNumber, DeviceNumber, FunctionNumber, u32 field) override; + virtual u16 read16_field(BusNumber, DeviceNumber, FunctionNumber, u32 field) override; + virtual u32 read32_field(BusNumber, DeviceNumber, FunctionNumber, u32 field) override; + +private: + explicit HostBridge(PCI::Domain const&); +}; + +} |