1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-18 16:05:06 +00:00
serenity/Kernel/Bus/PCI/Controller/HostController.h
Liav A ac2c01320b Kernel/PCI: Split host bridge code from the Access singleton
Two classes are added - HostBridge and MemoryBackedHostBridge, which
both derive from HostController class. This allows the kernel to map
different busses from different PCI domains in the same time. Each
HostController implementation doesn't take the Address object to address
PCI devices but instead we take distinct numbers of the PCI bus, device
and function as it allows us to specify arbitrary PCI domains in the
Address structure and still to get the correct PCI devices. This also
matches the hardware behavior of PCI domains - the host bridge merely
takes memory operations or IO operations and translates them to
addressing of three components - PCI bus, device and function.

These changes also greatly simplify how enumeration of Host Bridges work
now - scanning of the hardware depends on what the Host bridges can do
for us, so in case we have multiple host bridges that expose a memory
mapped region or IO ports to access PCI configuration space, we simply
let the code of the host bridge to figure out how to fetch data for us.

Another semantical change is that a PCI domain structure is no longer
attached to a PhysicalAddress, so even in the case that the machine
doesn't implement PCI domains, we still treat that machine to contain 1
PCI domain to treat that one host bridge in the same way, like with a
machine with one or more PCI domains.
2022-01-08 23:49:26 +01:00

45 lines
1.3 KiB
C++

/*
* Copyright (c) 2022, Liav A. <liavalb@hotmail.co.il>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Bitmap.h>
#include <AK/Vector.h>
#include <Kernel/Bus/PCI/Definitions.h>
#include <Kernel/Locking/Spinlock.h>
namespace Kernel::PCI {
TYPEDEF_DISTINCT_ORDERED_ID(u8, BusNumber);
TYPEDEF_DISTINCT_ORDERED_ID(u8, DeviceNumber);
TYPEDEF_DISTINCT_ORDERED_ID(u8, FunctionNumber);
class HostController {
public:
virtual ~HostController() = default;
virtual void write8_field(BusNumber, DeviceNumber, FunctionNumber, u32 field, u8 value) = 0;
virtual void write16_field(BusNumber, DeviceNumber, FunctionNumber, u32 field, u16 value) = 0;
virtual void write32_field(BusNumber, DeviceNumber, FunctionNumber, u32 field, u32 value) = 0;
virtual u8 read8_field(BusNumber, DeviceNumber, FunctionNumber, u32 field) = 0;
virtual u16 read16_field(BusNumber, DeviceNumber, FunctionNumber, u32 field) = 0;
virtual u32 read32_field(BusNumber, DeviceNumber, FunctionNumber, u32 field) = 0;
u32 domain_number() const { return m_domain.domain_number(); }
virtual void enumerate_attached_devices(Function<void(DeviceIdentifier)> callback) = 0;
protected:
explicit HostController(PCI::Domain const& domain)
: m_domain(domain)
{
}
const PCI::Domain m_domain;
};
}