Serenity Operating System
at master 87 lines 2.0 kB view raw
1/* 2 * Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org> 3 * 4 * SPDX-License-Identifier: BSD-2-Clause 5 */ 6 7#pragma once 8 9#include <AK/DeprecatedString.h> 10#include <AK/HashMap.h> 11#include <AK/NonnullOwnPtr.h> 12#include <AK/RefCounted.h> 13#include <AK/RefPtr.h> 14#include <AK/StringView.h> 15#include <LibCore/MappedFile.h> 16 17namespace PCIDB { 18 19struct Subsystem { 20 u16 vendor_id; 21 u16 device_id; 22 StringView name; 23}; 24 25struct Device { 26 u16 id; 27 StringView name; 28 HashMap<int, NonnullOwnPtr<Subsystem>> subsystems; 29}; 30 31struct Vendor { 32 u16 id; 33 StringView name; 34 HashMap<int, NonnullOwnPtr<Device>> devices; 35}; 36 37struct ProgrammingInterface { 38 u8 id { 0 }; 39 StringView name {}; 40}; 41 42struct Subclass { 43 u8 id { 0 }; 44 StringView name {}; 45 HashMap<int, NonnullOwnPtr<ProgrammingInterface>> programming_interfaces; 46}; 47 48struct Class { 49 u8 id { 0 }; 50 StringView name {}; 51 HashMap<int, NonnullOwnPtr<Subclass>> subclasses; 52}; 53 54class Database : public RefCounted<Database> { 55public: 56 static RefPtr<Database> open(DeprecatedString const& filename); 57 static RefPtr<Database> open() { return open("/res/pci.ids"); }; 58 59 const StringView get_vendor(u16 vendor_id) const; 60 const StringView get_device(u16 vendor_id, u16 device_id) const; 61 const StringView get_subsystem(u16 vendor_id, u16 device_id, u16 subvendor_id, u16 subdevice_id) const; 62 const StringView get_class(u8 class_id) const; 63 const StringView get_subclass(u8 class_id, u8 subclass_id) const; 64 const StringView get_programming_interface(u8 class_id, u8 subclass_id, u8 programming_interface_id) const; 65 66private: 67 explicit Database(NonnullRefPtr<Core::MappedFile> file) 68 : m_file(move(file)) 69 { 70 } 71 72 int init(); 73 74 enum ParseMode { 75 UnknownMode, 76 VendorMode, 77 ClassMode, 78 }; 79 80 NonnullRefPtr<Core::MappedFile> m_file; 81 StringView m_view {}; 82 HashMap<int, NonnullOwnPtr<Vendor>> m_vendors; 83 HashMap<int, NonnullOwnPtr<Class>> m_classes; 84 bool m_ready { false }; 85}; 86 87}