X-Git-Url: http://mj.ucw.cz/gitweb/?a=blobdiff_plain;f=lib%2Finit.c;h=04d8638a64ce7569c742d7d8067c13ce0de7b3ff;hb=7cb1afbe8d058688fc20c689edd3f5bb6243b28f;hp=11a9af62cc96d95e28e69da4a446336f26408c4f;hpb=fa1823688adaaf8dc32293b3502da7257cec612c;p=pciutils.git diff --git a/lib/init.c b/lib/init.c index 11a9af6..04d8638 100644 --- a/lib/init.c +++ b/lib/init.c @@ -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; iconfig) - pci_methods[i]->config(a); - return a; -} - void * pci_malloc(struct pci_access *a, int size) { @@ -139,68 +128,45 @@ 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(struct pci_access *acc, char *param, char *value) +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 = 1; - p->value = pci_strdup(acc, value); - return 0; - } + for (i=0; iname, name)) + return i; return -1; } -static void -pci_free_params(struct pci_access *acc) +char * +pci_get_method_name(int index) { - struct pci_param *p; - - while (p = acc->params) - { - acc->params = p->next; - if (p->value_malloced) - pci_mfree(p->value); - pci_mfree(p); - } + if (index < 0 || index >= PCI_ACCESS_MAX) + return NULL; + else if (!pci_methods[index]) + return ""; + else + return pci_methods[index]->name; } -struct pci_param * -pci_walk_params(struct pci_access *acc, struct pci_param *prev) +struct pci_access * +pci_alloc(void) { - /* 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; + 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; iconfig) + pci_methods[i]->config(a); + return a; } void @@ -224,7 +190,7 @@ pci_init(struct pci_access *a) else { unsigned int i; - for(i=0; idebug("Trying method %d...", i); @@ -249,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); @@ -259,7 +225,5 @@ pci_cleanup(struct pci_access *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); }