summaryrefslogtreecommitdiff
path: root/meta-ibs/meta-cp2-5422/recipes-phosphor/peci-pcie/peci-pcie/0002-add-caching-devices.patch
blob: cee5217df04723a8e228e10000eaa302c609bf8a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
From 178f1440b841657d9ff68e05fd4abb014b0f6317 Mon Sep 17 00:00:00 2001
From: claiff <claiff@mail.ru>
Date: Fri, 14 Oct 2022 12:37:53 +0300
Subject: [PATCH] add caching devices

---
 src/peci_pcie.cpp                        |  91 +++++++++++---
 vendor_storage/CMakeLists.txt            |  10 ++
 vendor_storage/cache_devices.cpp         |  76 ++++++++++++
 vendor_storage/cache_devices.hpp         |  31 +++++
 vendor_storage/cache_file/cache_data.cpp |  98 +++++++++++++++
 vendor_storage/cache_file/cache_data.hpp |  65 ++++++++++
 vendor_storage/cache_file/file.cpp       |  71 +++++++++++
 vendor_storage/cache_file/file.hpp       |  23 ++++
 vendor_storage/cache_file/parser.cpp     | 152 +++++++++++++++++++++++
 vendor_storage/cache_file/parser.hpp     |  28 +++++
 vendor_storage/vendor_data_getter.cpp    |   1 +
 11 files changed, 628 insertions(+), 18 deletions(-)
 create mode 100644 vendor_storage/cache_devices.cpp
 create mode 100644 vendor_storage/cache_devices.hpp
 create mode 100644 vendor_storage/cache_file/cache_data.cpp
 create mode 100644 vendor_storage/cache_file/cache_data.hpp
 create mode 100644 vendor_storage/cache_file/file.cpp
 create mode 100644 vendor_storage/cache_file/file.hpp
 create mode 100644 vendor_storage/cache_file/parser.cpp
 create mode 100644 vendor_storage/cache_file/parser.hpp

diff --git a/src/peci_pcie.cpp b/src/peci_pcie.cpp
index 070c717..8e85d73 100644
--- a/src/peci_pcie.cpp
+++ b/src/peci_pcie.cpp
@@ -19,6 +19,7 @@
 #include "pciDeviceClass.hpp"
 #include "pciVendors.hpp"
 #include "vendor_storage/vendor_data_getter.hpp"
+#include "vendor_storage/cache_devices.hpp"
 
 #include <boost/asio/io_service.hpp>
 #include <boost/asio/steady_timer.hpp>
@@ -85,6 +86,9 @@ struct CPUInfo
 };
 
 storage::VendorStorage mVendorStorage;
+storage::CacheDevices mCacheDevice;
+std::list<std::shared_ptr<sdbusplus::asio::dbus_interface>> mCacheIface;
+bool mFoundPCIE = false;
 
 // PECI Client Address Map
 static resCode getCPUBusMap(std::vector<CPUInfo>& cpuInfo)
@@ -461,6 +465,19 @@ static resCode setPCIeFunctionProperties(const int& clientAddr, const int& bus,
     resCode error;
     std::optional<uint32_t> vendor_id;
     std::optional<uint32_t> device_id;
+    std::string class_name;
+
+    // Set the function Device Class
+    error = getDeviceClass(clientAddr, bus, dev, func, res);
+    if (error != resCode::resOk)
+    {
+        return error;
+    }
+    setPCIeProperty(clientAddr, bus, dev,
+                    "Function" + std::to_string(func) +
+                        std::string(peci_pcie::function::deviceClassName),
+                    res);
+    class_name = res;
 
     for (const auto& [name, offset, size] : peci_pcie::pciConfigInfo)
     {
@@ -490,7 +507,6 @@ static resCode setPCIeFunctionProperties(const int& clientAddr, const int& bus,
     }
     if( vendor_id && device_id )
     {
-        std::cout << " vendor " << *vendor_id << " device " << *device_id << std::endl;
         auto vendor_data = mVendorStorage.ConvertVendorData(*vendor_id, *device_id);
 
         setPCIeProperty(clientAddr, bus, dev,
@@ -501,7 +517,10 @@ static resCode setPCIeFunctionProperties(const int& clientAddr, const int& bus,
                         "Function" + std::to_string(func) +
                             std::string(peci_pcie::function::deviceName),
                         vendor_data.device_id);
+        auto device = storage::cache_file::DeviceData{clientAddr, bus, dev};
 
+        mCacheDevice.AddDevice(device);
+        mCacheDevice.AddFunctionData(device, func, vendor_data.device_id, class_name);
         if(func == 0)
         {
             setPCIeProperty(clientAddr, bus, dev, "Device", vendor_data.device_id);
@@ -514,18 +533,6 @@ static resCode setPCIeFunctionProperties(const int& clientAddr, const int& bus,
                         std::string(peci_pcie::function::functionTypeName),
                     "Physical");
 
-
-
-    // Set the function Device Class
-    error = getDeviceClass(clientAddr, bus, dev, func, res);
-    if (error != resCode::resOk)
-    {
-        return error;
-    }
-    setPCIeProperty(clientAddr, bus, dev,
-                    "Function" + std::to_string(func) +
-                        std::string(peci_pcie::function::deviceClassName),
-                    res);
     return resCode::resOk;
 }
 
@@ -540,6 +547,7 @@ static resCode setPCIeDeviceProperties(const int& clientAddr, const int& bus,
         return error;
     }
     setPCIeProperty(clientAddr, bus, dev, "Manufacturer", manuf);
+    mCacheDevice.SetManufacturing({clientAddr, bus, dev}, manuf);
 
     // Set the device type
     constexpr char const* deviceTypeName = "DeviceType";
@@ -552,10 +560,12 @@ static resCode setPCIeDeviceProperties(const int& clientAddr, const int& bus,
     if (multiFunc)
     {
         setPCIeProperty(clientAddr, bus, dev, deviceTypeName, "MultiFunction");
+        mCacheDevice.SetDeviceType({clientAddr, bus, dev}, "MultiFunction");
     }
     else
     {
         setPCIeProperty(clientAddr, bus, dev, deviceTypeName, "SingleFunction");
+        mCacheDevice.SetDeviceType({clientAddr, bus, dev}, "SingleFunction");
     }
 
     // Set PCIe Generation
@@ -581,11 +591,6 @@ static resCode setPCIeDeviceProperties(const int& clientAddr, const int& bus,
 static resCode updatePCIeDevice(const int& clientAddr, const int& bus,
                                 const int& dev)
 {
-    if (setPCIeDeviceProperties(clientAddr, bus, dev) != resCode::resOk)
-    {
-        return resCode::resErr;
-    }
-
     // Walk through and populate the functions for this device
     for (int func = 0; func < peci_pcie::maxPCIFunctions; func++)
     {
@@ -610,6 +615,10 @@ static resCode updatePCIeDevice(const int& clientAddr, const int& bus,
             setDefaultPCIeFunctionProperties(clientAddr, bus, dev, func);
         }
     }
+    if (setPCIeDeviceProperties(clientAddr, bus, dev) != resCode::resOk)
+    {
+        return resCode::resErr;
+    }
     return resCode::resOk;
 }
 
@@ -655,6 +664,34 @@ static resCode addPCIeDevice(sdbusplus::asio::object_server& objServer,
     return resCode::resOk;
 }
 
+static resCode addPCIeDeviceForce(sdbusplus::asio::object_server& objServer,
+                                  storage::cache_file::DeviceData const& device_data )
+{
+    std::string pathName = std::string(peci_pcie::peciPCIePath) + "/S" +
+                           std::to_string(device_data.GetCpu()) + "B" + std::to_string(device_data.GetBus()) +
+                           "D" + std::to_string(device_data.GetDev());
+    auto iface =
+        objServer.add_interface(pathName, peci_pcie::peciPCIeDeviceInterface);
+    iface->register_property("DeviceType", device_data.GetDeviceType());
+    iface->register_property("Manufacturer", device_data.GetManufacturing());
+    auto functions = device_data.GetFunctionData();
+
+    for( const auto& function : functions )
+    {
+        auto class_field = "Function" + std::to_string(function.func) + "Class";
+        auto device_field = "Function" + std::to_string(function.func) + "DeviceName";
+        iface->register_property(class_field, function.class_name);
+        iface->register_property(device_field, function.device_name);
+    }
+    if(!functions.empty())
+    {
+        iface->register_property("Device", functions.front().device_name);
+    }
+    iface->initialize();
+    mCacheIface.push_back(iface);
+    return resCode::resOk;
+}
+
 static bool pcieDeviceInDBusMap(const int& clientAddr, const int& bus,
                                 const int& dev)
 {
@@ -689,6 +726,16 @@ static resCode probePCIeDevice(boost::asio::io_service& io,
     }
     if (res)
     {
+        if(!mFoundPCIE)
+        {
+            mCacheDevice.ClearDevices();
+            for(const auto& iface : mCacheIface)
+            {
+                auto result = objServer.remove_interface(iface);
+            }
+            mCacheIface.clear();
+            mFoundPCIE = true;
+        }
         if (pcieDeviceInDBusMap(addr, bus, dev))
         {
             // This device is already in D-Bus, so update it
@@ -988,6 +1035,14 @@ int main(int argc, char* argv[])
     // CPU map
     std::vector<CPUInfo> cpuInfo;
 
+    if(!mCacheDevice.IsEmpty())
+    {
+        for(auto it = mCacheDevice.CBegin(); it != mCacheDevice.CEnd(); ++it)
+        {
+            addPCIeDeviceForce(server, *it);
+        }
+    }
+
 #ifdef WAIT_FOR_OS_STANDBY
     boost::asio::steady_timer osStandbyTimer(io);
     monitorOSStandby(io, conn, server, osStandbyTimer, cpuInfo);
diff --git a/vendor_storage/CMakeLists.txt b/vendor_storage/CMakeLists.txt
index 0797a06..44a7dad 100644
--- a/vendor_storage/CMakeLists.txt
+++ b/vendor_storage/CMakeLists.txt
@@ -8,12 +8,15 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(STORAGE_DIR .)
 set(PARSER_DIR ${STORAGE_DIR}/parser)
 set(RESULT_DIR ${STORAGE_DIR}/result)
+set(CACHE_FILE_DIR ${STORAGE_DIR}/cache_file)
 
 include_directories(${STORAGE_DIR})
 
 add_library(vendor_storage
                 ${STORAGE_DIR}/vendor_data_getter.cpp
                 ${STORAGE_DIR}/vendor_data_getter.hpp
+                ${STORAGE_DIR}/cache_devices.cpp
+                ${STORAGE_DIR}/cache_devices.hpp
 
                 ${PARSER_DIR}/empty.hpp
                 ${PARSER_DIR}/empty.cpp
@@ -44,4 +47,11 @@ add_library(vendor_storage
                 ${RESULT_DIR}/device_id.hpp
                 ${RESULT_DIR}/device_id.cpp
                 ${RESULT_DIR}/types/iresult.hpp
+
+                ${CACHE_FILE_DIR}/file.hpp
+                ${CACHE_FILE_DIR}/file.cpp
+                ${CACHE_FILE_DIR}/parser.hpp
+                ${CACHE_FILE_DIR}/parser.cpp
+                ${CACHE_FILE_DIR}/cache_data.hpp
+                ${CACHE_FILE_DIR}/cache_data.cpp
                 )
diff --git a/vendor_storage/cache_devices.cpp b/vendor_storage/cache_devices.cpp
new file mode 100644
index 0000000..8c257ff
--- /dev/null
+++ b/vendor_storage/cache_devices.cpp
@@ -0,0 +1,76 @@
+#include <algorithm>
+
+#include "cache_devices.hpp"
+
+namespace storage
+{
+    CacheDevices::CacheDevices()
+    {
+        mDevices = mFile.Read();
+    }
+
+    void CacheDevices::AddDevice( cache_file::DeviceData const& device )
+    {
+        auto find = std::find_if(mDevices.begin(), mDevices.end(), [device]( cache_file::DeviceData const& device_in_set ){return device_in_set == device;});
+        if(find != mDevices.end())
+        {
+            return;
+        }
+        mDevices.push_back( device );
+        mFile.Write( mDevices );
+    }
+
+    void CacheDevices::ClearDevices()
+    {
+        mDevices.clear();
+        mFile.Write( mDevices );
+    }
+
+    void CacheDevices::AddFunctionData(const cache_file::DeviceData &device, int func, const std::string &device_name, const std::string &class_name)
+    {
+        auto find = std::find_if(mDevices.begin(), mDevices.end(), [device]( cache_file::DeviceData const& device_in_set ){return device_in_set == device;});
+        if( find == mDevices.end())
+        {
+            return;
+        }
+        find->AddFunctionData(func, device_name, class_name);
+        mFile.Write( mDevices );
+    }
+
+    void CacheDevices::SetDeviceType(const cache_file::DeviceData &device, const std::string &device_type)
+    {
+        auto find = std::find_if(mDevices.begin(), mDevices.end(), [device]( cache_file::DeviceData const& device_in_set ){return device_in_set == device;});
+        if( find == mDevices.end())
+        {
+            return;
+        }
+        find->SetDeviceType( device_type);
+        mFile.Write( mDevices );
+    }
+
+    void CacheDevices::SetManufacturing(const cache_file::DeviceData &device, const std::string &manufacturing)
+    {
+        auto find = std::find_if(mDevices.begin(), mDevices.end(), [device]( cache_file::DeviceData const& device_in_set ){return device_in_set == device;});
+        if( find == mDevices.end())
+        {
+            return;
+        }
+        find->SetManufactoring( manufacturing );
+        mFile.Write( mDevices );
+    }
+
+    bool CacheDevices::IsEmpty() const noexcept
+    {
+        return mDevices.empty();
+    }
+
+    std::list<cache_file::DeviceData>::const_iterator CacheDevices::CBegin() const
+    {
+        return mDevices.cbegin();
+    }
+
+    std::list<cache_file::DeviceData>::const_iterator CacheDevices::CEnd() const
+    {
+        return mDevices.cend();
+    }
+}
diff --git a/vendor_storage/cache_devices.hpp b/vendor_storage/cache_devices.hpp
new file mode 100644
index 0000000..ea1038b
--- /dev/null
+++ b/vendor_storage/cache_devices.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <list>
+
+#include "cache_file/cache_data.hpp"
+#include "cache_file/file.hpp"
+
+namespace storage
+{
+    class CacheDevices
+    {
+    public:
+        CacheDevices();
+        ~CacheDevices() = default;
+
+        void AddDevice( cache_file::DeviceData const& device );
+        void ClearDevices();
+        void AddFunctionData(cache_file::DeviceData const& device, int func, std::string const& device_name, std::string const& class_name);
+        void SetDeviceType( cache_file::DeviceData const& device, std::string const& device_type );
+        void SetManufacturing( cache_file::DeviceData const& device, std::string const& manufacturing );
+
+
+        bool IsEmpty() const noexcept;
+
+        std::list<cache_file::DeviceData>::const_iterator CBegin() const;
+        std::list<cache_file::DeviceData>::const_iterator CEnd() const;
+    private:
+        std::list<cache_file::DeviceData> mDevices;
+        cache_file::File mFile;
+    };
+}
diff --git a/vendor_storage/cache_file/cache_data.cpp b/vendor_storage/cache_file/cache_data.cpp
new file mode 100644
index 0000000..84b9a0d
--- /dev/null
+++ b/vendor_storage/cache_file/cache_data.cpp
@@ -0,0 +1,98 @@
+#include <algorithm>
+
+#include "cache_data.hpp"
+
+namespace storage::cache_file
+{
+
+    DeviceData::DeviceData(int addr, int bus, int dev)
+        : mAddr( addr )
+        , mBus( bus )
+        , mDev( dev )
+        , mCpu( 0 )
+    {
+
+    }
+
+    size_t DeviceData::GetAddr() const noexcept
+    {
+        return mAddr;
+    }
+
+    void DeviceData::SetAddr(int addr)
+    {
+        mAddr = addr;
+    }
+
+    int DeviceData::GetCpu() const noexcept
+    {
+        return mCpu;
+    }
+
+    void DeviceData::SetCpu(int cpu)
+    {
+        mCpu = cpu;
+    }
+
+    int DeviceData::GetBus() const noexcept
+    {
+        return mBus;
+    }
+
+    void DeviceData::SetBus(int bus)
+    {
+        mBus = bus;
+    }
+
+    int DeviceData::GetDev() const noexcept
+    {
+        return mDev;
+    }
+
+    void DeviceData::SetDev(int dev)
+    {
+        mDev = dev;
+    }
+
+    std::string DeviceData::GetManufacturing() const noexcept
+    {
+        return mManufacturing;
+    }
+
+    void DeviceData::SetManufactoring(const std::string &manufactoring)
+    {
+        mManufacturing = manufactoring;
+    }
+
+    std::string DeviceData::GetDeviceType() const noexcept
+    {
+        return mDeviceType;
+    }
+
+    void DeviceData::SetDeviceType(const std::string &device_type)
+    {
+        mDeviceType = device_type;
+    }
+
+    std::list<FunctionInfo> DeviceData::GetFunctionData() const noexcept
+    {
+        return mFunctionSet;
+    }
+
+    void DeviceData::AddFunctionData(int func, const std::string &device_name, const std::string &class_name)
+    {
+        mFunctionSet.push_back({class_name, device_name, func});
+    }
+
+    void DeviceData::AddFunctionData(const std::list<FunctionInfo> &functions)
+    {
+        for(const auto& function : functions)
+        {
+            auto find = std::find_if(mFunctionSet.begin(), mFunctionSet.end(), [function](FunctionInfo const& functions_from_set){ return functions_from_set == function;});
+            if(find == mFunctionSet.end())
+            {
+                mFunctionSet.push_back(function);
+            }
+        }
+    }
+}
diff --git a/vendor_storage/cache_file/cache_data.hpp b/vendor_storage/cache_file/cache_data.hpp
new file mode 100644
index 0000000..2cc70f4
--- /dev/null
+++ b/vendor_storage/cache_file/cache_data.hpp
@@ -0,0 +1,65 @@
+#pragma once
+
+#include <cstddef>
+#include <string>
+#include <list>
+
+namespace storage::cache_file
+{
+    struct FunctionInfo
+    {
+        std::string class_name;
+        std::string device_name;
+        int func;
+
+        bool operator==(FunctionInfo const& right) const
+        {
+            return class_name == right.class_name &&
+                   device_name == right.device_name &&
+                   func == right.func;
+        }
+    };
+
+    class DeviceData
+    {
+    public:
+        DeviceData( int addr, int bus, int dev );
+
+        size_t GetAddr() const noexcept;
+        void SetAddr( int addr );
+
+        int GetCpu() const noexcept;
+        void SetCpu( int cpu );
+
+        int GetBus() const noexcept;
+        void SetBus( int bus );
+
+        int GetDev() const noexcept;
+        void SetDev( int dev );
+
+        std::string GetManufacturing() const noexcept;
+        void SetManufactoring( std::string const& manufactoring );
+
+        std::string GetDeviceType( ) const noexcept;
+        void SetDeviceType( std::string const& device_type );
+
+        std::list<FunctionInfo> GetFunctionData() const noexcept;
+        void AddFunctionData( int func, std::string const& device_name, std::string const& class_name );
+        void AddFunctionData( std::list<FunctionInfo> const& functions );
+
+        bool operator==(DeviceData const& right) const
+        {
+            return mAddr == right.mAddr &&
+                   mBus == right.mBus &&
+                   mDev == right.mDev;
+        }
+    private:
+        int mAddr;
+        int mBus;
+        int mDev;
+        int mCpu;
+        std::string mManufacturing;
+        std::string mDeviceType;
+        std::list<FunctionInfo> mFunctionSet;
+    };
+}
diff --git a/vendor_storage/cache_file/file.cpp b/vendor_storage/cache_file/file.cpp
new file mode 100644
index 0000000..d3e580a
--- /dev/null
+++ b/vendor_storage/cache_file/file.cpp
@@ -0,0 +1,71 @@
+#include <fstream>
+
+#include "cache_devices.hpp"
+#include "parser.hpp"
+
+namespace storage::cache_file
+{
+    std::list<DeviceData> cache_file::File::Read()
+    {
+        std::ifstream file_reader{ GetPath(), std::fstream::in };
+        if ( !file_reader.is_open() )
+        {
+            CreateFile();
+            return {};
+        }
+        return ReadFile(file_reader);
+    }
+
+    void File::Write( std::list<DeviceData> const& device_data )
+    {
+        Parser parser;
+
+        std::ofstream file_writer{ GetPath(), std::fstream::out };
+        if ( !file_writer.is_open() )
+        {
+            return;
+        }
+        for(const auto& line : device_data)
+        {
+            auto line_as_string = parser.InvertParse( line );
+            file_writer << line_as_string << "\n";
+        }
+
+        file_writer.close();
+    }
+
+    void File::CreateFile() const
+    {
+        std::fstream file_writer;
+        file_writer.open( GetPath(), std::fstream::out );
+        if( !file_writer.is_open() )
+        {
+            return;
+        }
+        file_writer.close();
+    }
+
+    std::list<DeviceData> File::ReadFile( std::ifstream& file_reader ) const
+    {
+        std::string line{};
+        Parser parser;
+        std::list<DeviceData> result;
+
+        while ( std::getline( file_reader, line ) )
+        {
+            auto data_parsed = parser.Parse(line);
+            if( data_parsed )
+            {
+                result.push_back(*data_parsed);
+            }
+        }
+        file_reader.close();
+        return result;
+    }
+
+    std::string File::GetPath() const noexcept
+    {
+        static const std::string PATH_CACHE = "/usr/share/misc/cache.txt";
+        return PATH_CACHE;
+    }
+}
diff --git a/vendor_storage/cache_file/file.hpp b/vendor_storage/cache_file/file.hpp
new file mode 100644
index 0000000..865fcb7
--- /dev/null
+++ b/vendor_storage/cache_file/file.hpp
@@ -0,0 +1,23 @@
+#pragma once
+
+#include <string>
+#include <list>
+
+#include "cache_data.hpp"
+
+namespace storage::cache_file
+{
+    class File
+    {
+    public:
+        File() = default;
+        ~File() = default;
+
+        std::list<DeviceData> Read();
+        void Write( std::list<DeviceData> const& device_data );
+    private:
+        void CreateFile() const;
+        std::list<DeviceData> ReadFile( std::ifstream& file_reader ) const;
+        std::string GetPath() const noexcept;
+    };
+}
diff --git a/vendor_storage/cache_file/parser.cpp b/vendor_storage/cache_file/parser.cpp
new file mode 100644
index 0000000..549ca57
--- /dev/null
+++ b/vendor_storage/cache_file/parser.cpp
@@ -0,0 +1,152 @@
+#include <list>
+
+#include "parser.hpp"
+
+
+namespace storage::cache_file
+{
+    std::optional<DeviceData> Parser::Parse( std::string const& line)
+    {
+        static const std::string DELIMITER = "&";
+        auto params = BuildParams( ParseLine( line, DELIMITER ) );
+
+        auto result = GetDataFromParams( params );
+        return result;
+    }
+
+    std::string Parser::InvertParse( DeviceData const& device_data)
+    {
+        std::string result;
+
+        ApplyToString(result, "addr", std::to_string( device_data.GetAddr() ));
+        ApplyToString(result, "cpu", std::to_string(device_data.GetCpu()));
+        ApplyToString(result, "bus", std::to_string(device_data.GetBus()));
+        ApplyToString(result, "dev", std::to_string(device_data.GetDev()));
+        ApplyToString(result, "dev_type", device_data.GetDeviceType());
+        ApplyToString(result, "manuf", device_data.GetManufacturing());
+
+        auto function_set = device_data.GetFunctionData();
+        for(const auto& function : function_set)
+        {
+            ApplyToString(result, "Function" + std::to_string(function.func) +"Class", function.class_name);
+            ApplyToString(result, "Function" + std::to_string(function.func) +"DeviceName", function.device_name);
+        }
+
+        return result;
+    }
+
+    std::list<std::string> Parser::ParseLine( std::string const& line, std::string const& delimiter ) const
+    {
+        std::list<std::string> result;
+
+        auto start = 0U;
+        auto end = line.find(delimiter);
+        while(end != std::string::npos)
+        {
+            auto parsed = line.substr(start, end - start);
+            result.push_back(parsed);
+            start = end + delimiter.length();
+            end = line.find(delimiter, start);
+        }
+        auto parsed = line.substr(start, end);
+        result.push_back( parsed );
+        return result;
+    }
+
+    std::unordered_map<std::string, std::string> Parser::BuildParams(std::list<std::string> const& parsed_data) const
+    {
+        static const std::string DELIMITER_ON_PARAMETER = "=";
+
+        std::unordered_map<std::string, std::string> result;
+        for(const auto& not_parsed_param : parsed_data)
+        {
+            auto param_pair = ParseLine( not_parsed_param, DELIMITER_ON_PARAMETER );
+            result.insert( {param_pair.front(), param_pair.back()} );
+        }
+        return result;
+    }
+
+    DeviceData Parser::GetDataFromParams( std::unordered_map<std::string, std::string> const& params ) const
+    {
+        DeviceData result{0,0,0};
+
+        auto addr = params.find("addr");
+        if(addr != params.end())
+        {
+            result.SetAddr( ConvertToInt( (*addr).second ));
+        }
+        auto cpu = params.find("cpu");
+        if(cpu != params.end())
+        {
+            result.SetCpu( ConvertToInt( (*cpu).second ));
+        }
+        auto bus = params.find("bus");
+        if(bus != params.end())
+        {
+            result.SetBus( ConvertToInt( (*bus).second ));
+        }
+        auto dev = params.find("dev");
+        if(dev != params.end())
+        {
+            result.SetDev( ConvertToInt( (*dev).second ));
+        }
+        auto device_type = params.find("dev_type");
+        if(device_type != params.end())
+        {
+            result.SetDeviceType((*device_type).second );
+        }
+        auto manufactoring = params.find("manuf");
+        if(manufactoring != params.end())
+        {
+            result.SetManufactoring((*manufactoring).second);
+        }
+        result.AddFunctionData( GetFunctionSet( params ) );
+        return result;
+    }
+
+    int Parser::ConvertToInt( std::string const& number_as_string) const
+    {
+        int result = 0;
+        try
+        {
+            result = std::stoi(number_as_string);
+        }
+        catch (...)
+        {
+
+        }
+        return result;
+    }
+
+    void Parser::ApplyToString(std::string &result, std::string const& field, std::string const& value ) const
+    {
+        result += field;
+        result += "=";
+        result += value;
+        result += "&";
+    }
+
+    std::list<FunctionInfo> Parser::GetFunctionSet( std::unordered_map<std::string, std::string> const& params ) const
+    {
+        std::list<FunctionInfo> result;
+        int i = 0;
+        auto find_class = params.end();
+        auto find_name = params.end();
+        do
+        {
+            find_class = params.find("Function" + std::to_string(i) + "Class");
+            find_name = params.find("Function" + std::to_string(i) +"DeviceName");
+            if(find_class != params.end() && find_name != params.end())
+            {
+                FunctionInfo function;
+                function.class_name = (*find_class).second;
+                function.device_name = (*find_name).second;
+                function.func = i;
+                result.push_back(function);
+            }
+            ++i;
+        }
+        while(find_class != params.end() || find_name != params.end());
+        return result;
+    }
+}
diff --git a/vendor_storage/cache_file/parser.hpp b/vendor_storage/cache_file/parser.hpp
new file mode 100644
index 0000000..f84ee6b
--- /dev/null
+++ b/vendor_storage/cache_file/parser.hpp
@@ -0,0 +1,28 @@
+#pragma once
+
+#include <string>
+#include <optional>
+#include <list>
+#include <unordered_map>
+
+#include "cache_data.hpp"
+
+namespace storage::cache_file
+{
+    class Parser
+    {
+    public:
+        Parser() = default;
+        ~Parser() = default;
+
+        std::optional<DeviceData> Parse( std::string const& line );
+        std::string InvertParse( DeviceData const& device_data );
+    private:
+        std::list<std::string> ParseLine( std::string const& line, std::string const& delimiter ) const;
+        std::unordered_map<std::string, std::string> BuildParams( std::list<std::string> const& parsed_data ) const;
+        DeviceData GetDataFromParams( std::unordered_map<std::string, std::string> const& params ) const;
+        int ConvertToInt( std::string const& number_as_string ) const;
+        void ApplyToString( std::string& result, std::string const& field, std::string const& value) const;
+        std::list<FunctionInfo> GetFunctionSet( std::unordered_map<std::string, std::string> const& params ) const;
+    };
+}
diff --git a/vendor_storage/vendor_data_getter.cpp b/vendor_storage/vendor_data_getter.cpp
index 44d6e1c..71ce91e 100644
--- a/vendor_storage/vendor_data_getter.cpp
+++ b/vendor_storage/vendor_data_getter.cpp
@@ -34,6 +34,7 @@ namespace storage
         {
             ProcessLine( line );
         }
+        idfile.close();
     }
 
     //