summaryrefslogtreecommitdiff
path: root/Kernel/Bus/PCI/Controller/HostController.h
blob: 9089fde3e9eddd27ecbf1b98110e7afa7d1b0d3e (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
/*
 * 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<IterationDecision(DeviceIdentifier)> callback) = 0;

protected:
    explicit HostController(PCI::Domain const& domain)
        : m_domain(domain)
    {
    }

    const PCI::Domain m_domain;
};

}