]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/init.c
Import initial Darwin Support from Apple
[pciutils.git] / lib / init.c
index 6366762680be8a694bc5b9626f2a6305b03597b5..04d8638a64ce7569c742d7d8067c13ce0de7b3ff 100644 (file)
@@ -57,24 +57,13 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
 #else
   NULL,
 #endif
+#ifdef PCI_HAVE_PM_DARWIN_DEVICE
+  &pm_darwin_device,
+#else
+  NULL,
+#endif
 };
 
-struct pci_access *
-pci_alloc(void)
-{
-  struct pci_access *a = malloc(sizeof(struct pci_access));
-  int i;
-
-  memset(a, 0, sizeof(*a));
-  pci_set_name_list_path(a, PCI_PATH_IDS_DIR "/" PCI_IDS, 0);
-  pci_set_net_domain(a, PCI_ID_DOMAIN, 0);
-  a->id_lookup_mode = PCI_LOOKUP_CACHE;
-  for(i=0; i<PCI_ACCESS_MAX; i++)
-    if (pci_methods[i] && pci_methods[i]->config)
-      pci_methods[i]->config(a);
-  return a;
-}
-
 void *
 pci_malloc(struct pci_access *a, int size)
 {
@@ -92,6 +81,15 @@ pci_mfree(void *x)
     free(x);
 }
 
+char *
+pci_strdup(struct pci_access *a, char *s)
+{
+  int len = strlen(s) + 1;
+  char *t = pci_malloc(a, len);
+  memcpy(t, s, len);
+  return t;
+}
+
 static void
 pci_generic_error(char *msg, ...)
 {
@@ -130,6 +128,47 @@ pci_null_debug(char *msg UNUSED, ...)
 {
 }
 
+int
+pci_lookup_method(char *name)
+{
+  int i;
+
+  for (i=0; i<PCI_ACCESS_MAX; i++)
+    if (pci_methods[i] && !strcmp(pci_methods[i]->name, name))
+      return i;
+  return -1;
+}
+
+char *
+pci_get_method_name(int index)
+{
+  if (index < 0 || index >= PCI_ACCESS_MAX)
+    return NULL;
+  else if (!pci_methods[index])
+    return "";
+  else
+    return pci_methods[index]->name;
+}
+
+struct pci_access *
+pci_alloc(void)
+{
+  struct pci_access *a = malloc(sizeof(struct pci_access));
+  int i;
+
+  memset(a, 0, sizeof(*a));
+  pci_set_name_list_path(a, PCI_PATH_IDS_DIR "/" PCI_IDS, 0);
+#ifdef PCI_USE_DNS
+  pci_define_param(a, "net.domain", PCI_ID_DOMAIN, "DNS domain used for resolving of ID's");
+  pci_define_param(a, "net.cache_name", "~/.pciids-cache", "Name of the ID cache file");
+  a->id_lookup_mode = PCI_LOOKUP_CACHE;
+#endif
+  for (i=0; i<PCI_ACCESS_MAX; i++)
+    if (pci_methods[i] && pci_methods[i]->config)
+      pci_methods[i]->config(a);
+  return a;
+}
+
 void
 pci_init(struct pci_access *a)
 {
@@ -151,7 +190,7 @@ pci_init(struct pci_access *a)
   else
     {
       unsigned int i;
-      for(i=0; i<PCI_ACCESS_MAX; i++)
+      for (i=0; i<PCI_ACCESS_MAX; i++)
        if (pci_methods[i])
          {
            a->debug("Trying method %d...", i);
@@ -176,7 +215,7 @@ pci_cleanup(struct pci_access *a)
 {
   struct pci_dev *d, *e;
 
-  for(d=a->devices; d; d=e)
+  for (d=a->devices; d; d=e)
     {
       e = d->next;
       pci_free_dev(d);
@@ -184,9 +223,7 @@ pci_cleanup(struct pci_access *a)
   if (a->methods)
     a->methods->cleanup(a);
   pci_free_name_list(a);
+  pci_free_params(a);
   pci_set_name_list_path(a, NULL, 0);
-  pci_set_net_domain(a, NULL, 0);
-  pci_set_id_cache(a, NULL, 0);
   pci_mfree(a);
 }
-