hds: count available pci slots
authorJinhyung Choi <jinh0.choi@samsung.com>
Fri, 18 Dec 2015 09:25:43 +0000 (18:25 +0900)
committerJinhyung Choi <jinh0.choi@samsung.com>
Tue, 22 Dec 2015 03:52:46 +0000 (12:52 +0900)
PCI slots are limited as PCI_SLOT_MAX which is 32.
For the stability of using HDS, the max connection should be set.
This function will be used by ECS for it.

Change-Id: Id67a2550ddfffff24feb1df04a7b8b2e912237b8
Signed-off-by: Jinhyung Choi <jinh0.choi@samsung.com>
tizen/src/util/hds.c
tizen/src/util/hds.h

index f1ccec8..de7a33e 100644 (file)
@@ -28,6 +28,8 @@
  */
 
 #include "hds.h"
+#include "qmp-commands.h"
+#include "hw/pci/pci.h"
 #include "debug_ch.h"
 
 MULTI_DEBUG_CHANNEL(qemu, hds);
@@ -235,3 +237,34 @@ char* get_hds_lists(void)
 
     return list_hds;
 }
+
+int hds_get_pci_available_slot_num(void)
+{
+    Error *err = NULL;
+    PciInfoList *info;
+    PciDeviceInfoList *dev;
+    int pci_num = 0;
+
+    info = qmp_query_pci(&err);
+    if (err) {
+        LOG_WARNING("PCI devices not supported\n");
+        error_free(err);
+        return 0;
+    }
+
+    assert(info != NULL);
+    assert(info->value != NULL);
+
+    for (dev = info->value->devices; dev; dev = dev->next) {
+        if (dev->value->function == 0) {
+            pci_num++;
+        }
+    }
+
+    error_free(err);
+    qapi_free_PciInfoList(info);
+
+    LOG_INFO("# of PCI devices: %d, available: %d\n", pci_num, PCI_SLOT_MAX - pci_num);
+
+    return PCI_SLOT_MAX - pci_num;
+}
index dcc8ce2..f49323b 100644 (file)
@@ -51,5 +51,6 @@ bool is_hds_attached(const char* id);
 void set_hds_attached(const char* id, bool attached);
 
 char* get_hds_lists(void);
+int hds_get_pci_available_slot_num(void);
 
 #endif // _HDS_