diff --git a/src/kernel/ahci/hba.cpp b/src/kernel/ahci/hba.cpp index 017dc3d..9226dd8 100644 --- a/src/kernel/ahci/hba.cpp +++ b/src/kernel/ahci/hba.cpp @@ -62,6 +62,8 @@ hba::hba(pci_device *device) device_manager &dm = device_manager::get(); uint32_t bar5 = device->get_bar(5); + log::debug(logs::driver, "HBA raw BAR5 is %08lx", bar5); + m_data = reinterpret_cast(bar5 & ~0xfffull); pm->map_offset_pointer(reinterpret_cast(&m_data), 0x2000); @@ -93,6 +95,7 @@ hba::hba(pci_device *device) m_data->host_control |= 0x02; // enable interrupts } + dump(); for (auto &p : m_ports) { if (!p.active()) continue; diff --git a/src/kernel/ahci/port.cpp b/src/kernel/ahci/port.cpp index 49b3007..467527d 100644 --- a/src/kernel/ahci/port.cpp +++ b/src/kernel/ahci/port.cpp @@ -301,11 +301,17 @@ port::read_async(uint64_t offset, size_t length, void *dest) size_t port::read(uint64_t offset, size_t length, void *dest) { + dump(); int slot = read_async(offset, length, dest); + dump(); int timeout = 0; while (m_pending[slot].type == command_type::read) { - if (timeout++ > 10) return 0; + if (timeout++ > 5) { + m_hba->dump(); + dump(); + return 0; + } asm("hlt"); } kassert(m_pending[slot].type == command_type::finished, diff --git a/src/kernel/pci.cpp b/src/kernel/pci.cpp index cb5338b..8871113 100644 --- a/src/kernel/pci.cpp +++ b/src/kernel/pci.cpp @@ -97,21 +97,25 @@ pci_device::pci_device(pci_group &group, uint8_t bus, uint8_t device, uint8_t fu uint16_t *command = reinterpret_cast(&m_base[1]); *command |= 0x400; // Mask old INTx style interrupts + uint16_t *status = command + 1; + log::info(logs::device, "Found PCIe device at %02d:%02d:%d of type %d.%d id %04x:%04x", bus, device, func, m_class, m_subclass, m_vendor, m_device); - // Walk the extended capabilities list - uint8_t next = m_base[13] & 0xff; - while (next) { - pci_cap *cap = reinterpret_cast(kutil::offset_pointer(m_base, next)); - next = cap->next; - log::debug(logs::device, " - found PCI cap type %02x", cap->id); + if (*status & 0x0010) { + // Walk the extended capabilities list + uint8_t next = m_base[13] & 0xff; + while (next) { + pci_cap *cap = reinterpret_cast(kutil::offset_pointer(m_base, next)); + next = cap->next; + log::debug(logs::device, " - found PCI cap type %02x", cap->id); - if (cap->id == pci_cap::type::msi) { - m_msi = cap; - pci_cap_msi *mcap = reinterpret_cast(cap); - mcap->control &= ~0x70; // at most 1 vector allocated - mcap->control |= 0x01; // Enable interrupts, at most 1 vector allocated + if (cap->id == pci_cap::type::msi) { + m_msi = cap; + pci_cap_msi *mcap = reinterpret_cast(cap); + mcap->control &= ~0x70; // at most 1 vector allocated + mcap->control |= 0x01; // Enable interrupts, at most 1 vector allocated + } } } }