Add simple vector implementation to kutil for device_manager

This commit is contained in:
Justin C. Miller
2018-05-07 09:47:34 -07:00
parent abb347e1a8
commit ff3bd640f0
6 changed files with 205 additions and 63 deletions

View File

@@ -36,15 +36,6 @@ struct acpi2_rsdp
uint8_t reserved[3];
} __attribute__ ((packed));
struct pci_group
{
uint16_t group;
uint16_t bus_start;
uint16_t bus_end;
uint32_t *base;
};
uint8_t
acpi_checksum(const void *p, size_t len, size_t off = 0)
{
@@ -63,12 +54,7 @@ acpi_table_header::validate(uint32_t expected_type) const
device_manager::device_manager(const void *root_table) :
m_lapic(nullptr),
m_num_ioapics(0),
m_pci(nullptr),
m_num_pci_groups(0),
m_devices(nullptr),
m_num_devices(0),
m_num_device_entries(0)
m_num_ioapics(0)
{
kassert(root_table != 0, "ACPI root table pointer is null.");
@@ -280,9 +266,7 @@ void
device_manager::load_mcfg(const acpi_mcfg *mcfg)
{
size_t count = acpi_table_entries(mcfg, sizeof(acpi_mcfg_entry));
m_pci = new pci_group[count];
m_num_pci_groups = count;
m_pci.set_size(count);
page_manager *pm = page_manager::get();

View File

@@ -2,6 +2,7 @@
/// \file device_manager.h
/// The device manager and related device classes.
#include <stdint.h>
#include "kutil/vector.h"
struct acpi_xsdt;
struct acpi_apic;
@@ -9,12 +10,54 @@ struct acpi_mcfg;
class lapic;
class ioapic;
class pci_device;
struct pci_group;
enum class isr : uint8_t;
/// Information about a discovered PCIe device
class pci_device
{
public:
/// Default constructor creates an empty object.
pci_device();
/// Constructor
/// \arg group The group number of this device's bus
/// \arg bus The bus number this device is on
/// \arg device The device number of this device
/// \arg func The function number of this device
pci_device(uint16_t group, uint8_t bus, uint8_t device, uint8_t func);
private:
uint32_t *m_base;
/// Bus address: 15:8 bus, 7:3 device, 2:0 device
uint16_t m_bus_addr;
uint16_t m_vendor;
uint16_t m_device;
uint8_t m_class;
uint8_t m_subclass;
uint8_t m_prog_if;
uint8_t m_revision;
// Might as well cache these to fill out the struct align
isr m_irq;
uint8_t m_header_type;
};
/// Represents data about a PCI bus group from the ACPI MCFG
struct pci_group
{
uint16_t group;
uint16_t bus_start;
uint16_t bus_end;
uint32_t *base;
};
/// Manager for all system hardware devices
class device_manager
{
@@ -56,47 +99,9 @@ private:
ioapic *m_ioapics[16];
int m_num_ioapics;
pci_group *m_pci;
int m_num_pci_groups;
pci_device *m_devices;
int m_num_devices;
int m_num_device_entries;
kutil::vector<pci_group> m_pci;
kutil::vector<pci_device> m_devices;
device_manager() = delete;
device_manager(const device_manager &) = delete;
};
/// Information about a discovered PCIe device
class pci_device
{
public:
/// Default constructor creates an empty object.
pci_device();
/// Constructor
/// \arg group The group number of this device's bus
/// \arg bus The bus number this device is on
/// \arg device The device number of this device
/// \arg func The function number of this device
pci_device(uint16_t group, uint8_t bus, uint8_t device, uint8_t func);
private:
uint32_t *m_base;
/// Bus address: 15:8 bus, 7:3 device, 2:0 device
uint16_t m_bus_addr;
uint16_t m_vendor;
uint16_t m_device;
uint8_t m_class;
uint8_t m_subclass;
uint8_t m_prog_if;
uint8_t m_revision;
// Might as well cache these to fill out the struct align
isr m_irq;
uint8_t m_header_type;
};

View File

@@ -47,7 +47,7 @@ init_console(const popcorn_data *header)
log::init(cons);
log::enable(logs::apic, log::level::info);
log::enable(logs::devices, log::level::info);
log::enable(logs::devices, log::level::debug);
log::enable(logs::memory, log::level::debug);
}