mirror of
https://github.com/justinian/jsix.git
synced 2025-12-10 08:24:32 -08:00
Add block device management to device manager
This commit is contained in:
@@ -16,13 +16,3 @@ ahci_driver::register_device(pci_device *device)
|
|||||||
|
|
||||||
ahci::hba &hba = m_devices.emplace(device);
|
ahci::hba &hba = m_devices.emplace(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
ahci::port *
|
|
||||||
ahci_driver::find_disk()
|
|
||||||
{
|
|
||||||
for (auto &hba : m_devices) {
|
|
||||||
ahci::port *d = hba.find_disk();
|
|
||||||
if (d) return d;
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -22,9 +22,6 @@ public:
|
|||||||
/// \arg device The PCI device to remove
|
/// \arg device The PCI device to remove
|
||||||
void unregister_device(pci_device *device);
|
void unregister_device(pci_device *device);
|
||||||
|
|
||||||
/// Debug: find the first disk
|
|
||||||
ahci::port * find_disk();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
kutil::vector<ahci::hba> m_devices;
|
kutil::vector<ahci::hba> m_devices;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ void irq_cb(void *data)
|
|||||||
hba::hba(pci_device *device)
|
hba::hba(pci_device *device)
|
||||||
{
|
{
|
||||||
page_manager *pm = page_manager::get();
|
page_manager *pm = page_manager::get();
|
||||||
|
device_manager &dm = device_manager::get();
|
||||||
|
|
||||||
uint32_t bar5 = device->get_bar(5);
|
uint32_t bar5 = device->get_bar(5);
|
||||||
m_data = reinterpret_cast<hba_data *>(bar5 & ~0xfffull);
|
m_data = reinterpret_cast<hba_data *>(bar5 & ~0xfffull);
|
||||||
@@ -83,6 +84,9 @@ hba::hba(pci_device *device)
|
|||||||
port &p = m_ports.emplace(i, kutil::offset_pointer(pd, 0x80 * i), impl);
|
port &p = m_ports.emplace(i, kutil::offset_pointer(pd, 0x80 * i), impl);
|
||||||
if (p.get_state() == port::state::active)
|
if (p.get_state() == port::state::active)
|
||||||
needs_interrupt = true;
|
needs_interrupt = true;
|
||||||
|
|
||||||
|
if (p.get_type() == sata_signature::sata_drive)
|
||||||
|
dm.register_block_device(&p);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (needs_interrupt) {
|
if (needs_interrupt) {
|
||||||
@@ -91,18 +95,6 @@ hba::hba(pci_device *device)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
port *
|
|
||||||
hba::find_disk()
|
|
||||||
{
|
|
||||||
for (auto &port : m_ports) {
|
|
||||||
if (port.get_state() == port::state::active &&
|
|
||||||
port.get_type() == sata_signature::sata_drive)
|
|
||||||
return &port;
|
|
||||||
}
|
|
||||||
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
hba::handle_interrupt()
|
hba::handle_interrupt()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,9 +25,6 @@ public:
|
|||||||
/// Interrupt handler.
|
/// Interrupt handler.
|
||||||
void handle_interrupt();
|
void handle_interrupt();
|
||||||
|
|
||||||
/// Debug: find the first disk
|
|
||||||
port * find_disk();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
pci_device *m_device;
|
pci_device *m_device;
|
||||||
hba_data *m_data;
|
hba_data *m_data;
|
||||||
|
|||||||
@@ -320,3 +320,9 @@ device_manager::allocate_msi(const char *name, pci_device &device, irq_callback
|
|||||||
static_cast<uint16_t>(vector));
|
static_cast<uint16_t>(vector));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
device_manager::register_block_device(block_device *blockdev)
|
||||||
|
{
|
||||||
|
m_blockdevs.append(blockdev);
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,6 +7,7 @@
|
|||||||
struct acpi_xsdt;
|
struct acpi_xsdt;
|
||||||
struct acpi_apic;
|
struct acpi_apic;
|
||||||
struct acpi_mcfg;
|
struct acpi_mcfg;
|
||||||
|
class block_device;
|
||||||
class lapic;
|
class lapic;
|
||||||
class ioapic;
|
class ioapic;
|
||||||
|
|
||||||
@@ -65,6 +66,23 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Register the existance of a block device.
|
||||||
|
/// \arg blockdev Pointer to the block device
|
||||||
|
void register_block_device(block_device *blockdev);
|
||||||
|
|
||||||
|
/// Get the number of block devices in the system
|
||||||
|
/// \returns A count of devices
|
||||||
|
inline unsigned get_num_block_devices() const { return m_blockdevs.count(); }
|
||||||
|
|
||||||
|
/// Get a block device
|
||||||
|
/// \arg i Index of the device to get
|
||||||
|
/// \returns A pointer to the requested device, or nullptr
|
||||||
|
inline block_device * get_block_device(unsigned i)
|
||||||
|
{
|
||||||
|
return i < m_blockdevs.count() ?
|
||||||
|
m_blockdevs[i] : nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/// Parse the ACPI XSDT and load relevant sub-tables.
|
/// Parse the ACPI XSDT and load relevant sub-tables.
|
||||||
/// \arg xsdt Pointer to the XSDT from the firmware
|
/// \arg xsdt Pointer to the XSDT from the firmware
|
||||||
@@ -100,6 +118,8 @@ private:
|
|||||||
};
|
};
|
||||||
kutil::vector<irq_allocation> m_irqs;
|
kutil::vector<irq_allocation> m_irqs;
|
||||||
|
|
||||||
|
kutil::vector<block_device *> m_blockdevs;
|
||||||
|
|
||||||
static device_manager s_instance;
|
static device_manager s_instance;
|
||||||
|
|
||||||
device_manager() = delete;
|
device_manager() = delete;
|
||||||
|
|||||||
@@ -3,10 +3,7 @@
|
|||||||
|
|
||||||
#include "kutil/assert.h"
|
#include "kutil/assert.h"
|
||||||
#include "kutil/memory.h"
|
#include "kutil/memory.h"
|
||||||
|
#include "block_device.h"
|
||||||
#include "ahci/driver.h"
|
|
||||||
#include "ahci/port.h"
|
|
||||||
|
|
||||||
#include "console.h"
|
#include "console.h"
|
||||||
#include "cpu.h"
|
#include "cpu.h"
|
||||||
#include "device_manager.h"
|
#include "device_manager.h"
|
||||||
@@ -27,8 +24,6 @@ extern "C" {
|
|||||||
void *__bss_start, *__bss_end;
|
void *__bss_start, *__bss_end;
|
||||||
}
|
}
|
||||||
|
|
||||||
extern ahci_driver ahcid;
|
|
||||||
|
|
||||||
extern void __kernel_assert(const char *, unsigned, const char *);
|
extern void __kernel_assert(const char *, unsigned, const char *);
|
||||||
|
|
||||||
void
|
void
|
||||||
@@ -98,7 +93,7 @@ kernel_main(popcorn_data *header)
|
|||||||
|
|
||||||
devices->init_drivers();
|
devices->init_drivers();
|
||||||
|
|
||||||
ahci::port *disk = ahcid.find_disk();
|
block_device *disk = devices->get_block_device(0);
|
||||||
if (disk) {
|
if (disk) {
|
||||||
uint8_t buf[512];
|
uint8_t buf[512];
|
||||||
kutil::memset(buf, 0, 512);
|
kutil::memset(buf, 0, 512);
|
||||||
@@ -113,6 +108,8 @@ kernel_main(popcorn_data *header)
|
|||||||
}
|
}
|
||||||
cons->putc('\n');
|
cons->putc('\n');
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
log::warn(logs::boot, "No block devices present.");
|
||||||
}
|
}
|
||||||
|
|
||||||
// do_error_1();
|
// do_error_1();
|
||||||
|
|||||||
Reference in New Issue
Block a user