2 * The PCI Utilities -- Common Functions
4 * Copyright (c) 1997--2016 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
22 fprintf(stderr, "%s: ", program_name);
23 vfprintf(stderr, msg, args);
29 xmalloc(size_t howmuch)
31 void *p = malloc(howmuch);
33 die("Unable to allocate %d bytes of memory", (int) howmuch);
38 xrealloc(void *ptr, size_t howmuch)
40 void *p = realloc(ptr, howmuch);
42 die("Unable to allocate %d bytes of memory", (int) howmuch);
47 xstrdup(const char *str)
49 int len = strlen(str) + 1;
50 char *copy = xmalloc(len);
51 memcpy(copy, str, len);
56 set_pci_method(struct pci_access *pacc, char *arg)
61 if (!strcmp(arg, "help"))
63 printf("Known PCI access methods:\n\n");
64 for (i=0; name = pci_get_method_name(i); i++)
71 i = pci_lookup_method(arg);
73 die("No such PCI access method: %s (see `-A help' for a list)", arg);
79 set_pci_option(struct pci_access *pacc, char *arg)
81 if (!strcmp(arg, "help"))
84 printf("Known PCI access parameters:\n\n");
85 for (p=NULL; p=pci_walk_params(pacc, p);)
86 printf("%-20s %s (%s)\n", p->param, p->help, p->value);
91 char *sep = strchr(arg, '=');
93 die("Invalid PCI access parameter syntax: %s", arg);
95 if (pci_set_param(pacc, arg, sep) < 0)
96 die("Unrecognized PCI access parameter: %s (see `-O help' for a list)", arg);
101 parse_generic_option(int i, struct pci_access *pacc, char *arg)
105 #ifdef PCI_HAVE_PM_INTEL_CONF
107 if (!strcmp(arg, "1"))
108 pacc->method = PCI_ACCESS_I386_TYPE1;
109 else if (!strcmp(arg, "2"))
110 pacc->method = PCI_ACCESS_I386_TYPE2;
112 die("Unknown hardware configuration type %s", arg);
115 #ifdef PCI_HAVE_PM_DUMP
117 pci_set_param(pacc, "dump.name", arg);
118 pacc->method = PCI_ACCESS_DUMP;
122 set_pci_method(pacc, arg);
128 set_pci_option(pacc, arg);