From dbffaf89dd734b4fa3911c3f421a7340f5fa1864 Mon Sep 17 00:00:00 2001 From: Baptiste Wicht Date: Sun, 3 Jul 2016 18:59:22 +0200 Subject: [PATCH] Publish PCI devices in sysfs --- kernel/src/pci.cpp | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kernel/src/pci.cpp b/kernel/src/pci.cpp index 36352a50..c943f0e5 100644 --- a/kernel/src/pci.cpp +++ b/kernel/src/pci.cpp @@ -9,6 +9,8 @@ #include "kernel_utils.hpp" #include "logging.hpp" +#include "fs/sysfs.hpp" + namespace { std::vector devices; @@ -74,6 +76,9 @@ std::vector devices; auto class_code = get_class_code(bus, device, function); auto sub_class = get_subclass(bus, device, function); + logging::logf(logging::log_level::DEBUG, "Found device pci:%u:%u:%u (vendor:%u class:%u subclass:%u) \n", + uint64_t(bus), uint64_t(device), uint64_t(function), uint64_t(vendor_id), uint64_t(class_code), uint64_t(sub_class)); + devices.emplace_back(); pci::device_descriptor& device_desc = devices.back(); @@ -94,8 +99,12 @@ std::vector devices; device_desc.class_type = pci::device_class_type::UNKNOWN; } - logging::logf(logging::log_level::DEBUG, "Found device pci:%u:%u:%u (vendor:%u class:%u subclass:%u) \n", - uint64_t(bus), uint64_t(device), uint64_t(function), uint64_t(vendor_id), uint64_t(class_code), uint64_t(sub_class)); + std::string path = "/pci/pci:" + std::to_string(bus) + ':' + std::to_string(device) + ':' + std::to_string(function); + + sysfs::set_constant_value("/sys/", path + "/vendor", std::to_string(vendor_id)); + sysfs::set_constant_value("/sys/", path + "/device", std::to_string(device_id)); + sysfs::set_constant_value("/sys/", path + "/class", std::to_string(class_code)); + sysfs::set_constant_value("/sys/", path + "/subclass", std::to_string(sub_class)); } void check_device(uint8_t bus, uint8_t device) {