]> mj.ucw.cz Git - pciutils.git/blobdiff - lib/init.c
NUMA node scanning is now done in an ABI-compatible way
[pciutils.git] / lib / init.c
index 167c893131ac04e63a1fe7c2382866bb41b7a90b..064c9324a4e3f49cdfbc7cb3ba202f61912a6d68 100644 (file)
@@ -57,26 +57,12 @@ static struct pci_methods *pci_methods[PCI_ACCESS_MAX] = {
 #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);
-#ifdef PCI_USE_DNS
-  pci_define_param(a, "net.domain", PCI_ID_DOMAIN);
-  pci_define_param(a, "net.cache_path", "~/.pciids-cache");
-  a->id_lookup_mode = PCI_LOOKUP_CACHE;
+#ifdef PCI_HAVE_PM_DARWIN_DEVICE
+  &pm_darwin,
+#else
+  NULL,
 #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_malloc(struct pci_access *a, int size)
@@ -96,7 +82,7 @@ pci_mfree(void *x)
 }
 
 char *
-pci_strdup(struct pci_access *a, char *s)
+pci_strdup(struct pci_access *a, const char *s)
 {
   int len = strlen(s) + 1;
   char *t = pci_malloc(a, len);
@@ -142,77 +128,48 @@ pci_null_debug(char *msg UNUSED, ...)
 {
 }
 
-char *
-pci_get_param(struct pci_access *acc, char *param)
-{
-  struct pci_param *p;
-
-  for (p=acc->params; p; p=p->next)
-    if (!strcmp(p->param, param))
-      return p->value;
-  return NULL;
-}
-
-void
-pci_define_param(struct pci_access *acc, char *param, char *value)
-{
-  struct pci_param *p = pci_malloc(acc, sizeof(*p));
-
-  p->next = acc->params;
-  acc->params = p;
-  p->param = param;
-  p->value = value;
-  p->value_malloced = 0;
-}
-
 int
-pci_set_param_internal(struct pci_access *acc, char *param, char *value, int copy)
+pci_lookup_method(char *name)
 {
-  struct pci_param *p;
+  int i;
 
-  for (p=acc->params; p; p=p->next)
-    if (!strcmp(p->param, param))
-      {
-       if (p->value_malloced)
-         pci_mfree(p->value);
-       p->value_malloced = copy;
-       if (copy)
-         p->value = pci_strdup(acc, value);
-       else
-         p->value = value;
-       return 0;
-      }
+  for (i=0; i<PCI_ACCESS_MAX; i++)
+    if (pci_methods[i] && !strcmp(pci_methods[i]->name, name))
+      return i;
   return -1;
 }
 
-int
-pci_set_param(struct pci_access *acc, char *param, char *value)
+char *
+pci_get_method_name(int index)
 {
-  return pci_set_param_internal(acc, param, value, 1);
+  if (index < 0 || index >= PCI_ACCESS_MAX)
+    return NULL;
+  else if (!pci_methods[index])
+    return "";
+  else
+    return pci_methods[index]->name;
 }
 
-static void
-pci_free_params(struct pci_access *acc)
+struct pci_access *
+pci_alloc(void)
 {
-  struct pci_param *p;
-
-  while (p = acc->params)
-    {
-      acc->params = p->next;
-      if (p->value_malloced)
-       pci_mfree(p->value);
-      pci_mfree(p);
-    }
-}
+  struct pci_access *a = malloc(sizeof(struct pci_access));
+  int i;
 
-struct pci_param *
-pci_walk_params(struct pci_access *acc, struct pci_param *prev)
-{
-  /* So far, the params form a simple linked list, but this can change in the future */
-  if (!prev)
-    return acc->params;
-  else
-    return prev->next;
+  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
+#ifdef PCI_HAVE_HWDB
+  pci_define_param(a, "hwdb.disable", "0", "Do not look up names in UDEV's HWDB if non-zero");
+#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
@@ -236,7 +193,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);
@@ -261,7 +218,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);