Max OS 0.3
Loading...
Searching...
No Matches
pci.h
Go to the documentation of this file.
1
9#ifndef MAX_OS_HARDWARECOMMUNICATION_PCI_H
10#define MAX_OS_HARDWARECOMMUNICATION_PCI_H
11
12#include <cstdint>
13#include <common/string.h>
14#include <drivers/driver.h>
18#include <drivers/video/vga.h>
19
20
21namespace MaxOS::hardwarecommunication {
22
27 enum class BARType {
28 MemoryMapped,
29 InputOutput
30 };
31
39 public:
41 uint8_t* address;
42 uint32_t size;
44
45 };
46
47
55 public:
56 bool has_port_base = false;
57 uint32_t port_base = 0;
58
59 bool has_memory_base = false;
60 uint32_t memory_base = 0;
61
62 uint32_t interrupt = 0;
63
64 uint16_t bus = 0;
65 uint16_t device = 0;
66 uint16_t function = 0;
67
68 uint16_t vendor_id = 0;
69 uint16_t device_id = 0;
70
71 uint8_t class_id = 0;
72 uint8_t subclass_id = 0;
73 uint8_t interface_id = 0;
74
75 uint8_t revision = 0;
76
79
80 [[nodiscard]] string get_type() const;
81 };
82
83
89 private:
90 // Ports
91 Port32Bit m_data_port;
92 Port32Bit m_command_port;
93
94 // I/O
95 uint32_t read(uint16_t bus, uint16_t device, uint16_t function, uint32_t register_offset);
96 void write(uint16_t bus, uint16_t device, uint16_t function, uint32_t register_offset, uint32_t value);
97
98 // Device
99 PCIDeviceDescriptor get_device_descriptor(uint16_t bus, uint16_t device, uint16_t function);
100 BaseAddressRegister get_base_address_register(uint16_t bus, uint16_t device, uint16_t function, uint16_t bar);
101 bool device_has_functions(uint16_t bus, uint16_t device);
102
103 public:
105 ~PCIController() final;
106
109 static void list_known_device(const PCIDeviceDescriptor& dev);
110 };
111}
112
113
114#endif //MAX_OS_HARDWARECOMMUNICATION_PCI_H
Event handler for the DriverSelector class, handles the event when a driver is selected.
Definition driver.h:47
Selects the drivers to be used.
Definition driver.h:58
base class for all drivers, handles the activation, deactivation, initialisation and reset of the dri...
Definition driver.h:27
Used to store the Base Address Register (BAR) of a PCI device.
Definition pci.h:38
bool pre_fetchable
Reading from this address wont change the state of the device and data can be cached by the CPU.
Definition pci.h:40
uint8_t * address
The address of the device (IO port or memory address, can be 32 or 64 bit)
Definition pci.h:41
BARType type
Where to access the device.
Definition pci.h:43
Handles the selecting and loading of drivers for PCI devices.
Definition pci.h:88
static void list_known_device(const PCIDeviceDescriptor &dev)
Print the vednor and device id of known devices, or "Unknown" + their ids if not known.
Definition pci.cpp:310
PCIController()
Construct a new PCI Controller object.
Definition pci.cpp:99
static drivers::Driver * get_driver(PCIDeviceDescriptor dev)
Get the driver for the device.
Definition pci.cpp:251
void select_drivers(drivers::DriverSelectorEventHandler *handler) override
Select the driver for the device.
Definition pci.cpp:176
Stores information about a PCI device.
Definition pci.h:54
bool has_memory_base
Whether the device has a memory base address.
Definition pci.h:59
bool has_port_base
Whether the device has an IO port base address.
Definition pci.h:56
uint16_t device
The device number on the PCI bus.
Definition pci.h:65
uint8_t class_id
The class type of the device.
Definition pci.h:71
uint32_t interrupt
The interrupt number the device uses to communicate with the CPU.
Definition pci.h:62
uint8_t revision
The device version number.
Definition pci.h:75
uint32_t memory_base
The memory base address.
Definition pci.h:60
uint16_t device_id
The device's unique identifier.
Definition pci.h:69
uint32_t port_base
The IO port base address.
Definition pci.h:57
uint8_t subclass_id
The subclass type of the device.
Definition pci.h:72
uint16_t bus
The PCI bus the device is connected to.
Definition pci.h:64
string get_type() const
Get the type of the device.
Definition pci.cpp:37
uint16_t function
The function number of the device.
Definition pci.h:66
uint8_t interface_id
The interface type of the device.
Definition pci.h:73
uint16_t vendor_id
The company's that made the device unique identifier.
Definition pci.h:68
Handles 32 bit ports.
Definition port.h:70
Defines a base Driver class and DriverManager for managing drivers.
Defines a InterruptManager and InterruptHandler for managing hardware and software interrupts.
Defines a MemoryManager class for handling memory allocation and deallocation.
BARType
Determines whether the PCI device communicates via IO ports or memory.
Definition pci.h:27
Defines classes for handling hardware communication ports (8, 16, and 32 bit)
Defines a String class for dynamically sized strings with various operations.
Defines a Video Graphics Array (VGA) driver for rendering graphics to the screen.