2 * The PCI Utilities -- Common Functions
4 * Copyright (c) 1997--2008 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
23 fprintf(stderr, "%s: ", program_name);
24 vfprintf(stderr, msg, args);
30 xmalloc(unsigned int howmuch)
32 void *p = malloc(howmuch);
34 die("Unable to allocate %d bytes of memory", howmuch);
39 xrealloc(void *ptr, unsigned int howmuch)
41 void *p = realloc(ptr, howmuch);
43 die("Unable to allocate %d bytes of memory", howmuch);
50 int len = strlen(str) + 1;
51 char *copy = xmalloc(len);
52 memcpy(copy, str, len);
57 set_pci_method(struct pci_access *pacc, char *arg)
62 if (!strcmp(arg, "help"))
64 printf("Known PCI access methods:\n\n");
65 for (i=0; name = pci_get_method_name(i); i++)
72 i = pci_lookup_method(arg);
74 die("No such PCI access method: %s (see `-A help' for a list)", arg);
80 set_pci_option(struct pci_access *pacc, char *arg)
82 if (!strcmp(arg, "help"))
85 printf("Known PCI access parameters:\n\n");
86 for (p=NULL; p=pci_walk_params(pacc, p);)
87 printf("%-20s %s (%s)\n", p->param, p->help, p->value);
92 char *sep = strchr(arg, '=');
94 die("Invalid PCI access parameter syntax: %s", arg);
96 if (pci_set_param(pacc, arg, sep) < 0)
97 die("Unrecognized PCI access parameter: %s (see `-O help' for a list)", arg);
102 parse_generic_option(int i, struct pci_access *pacc, char *optarg)
106 #ifdef PCI_HAVE_PM_INTEL_CONF
108 if (!strcmp(optarg, "1"))
109 pacc->method = PCI_ACCESS_I386_TYPE1;
110 else if (!strcmp(optarg, "2"))
111 pacc->method = PCI_ACCESS_I386_TYPE2;
113 die("Unknown hardware configuration type %s", optarg);
116 #ifdef PCI_HAVE_PM_DUMP
118 pci_set_param(pacc, "dump.name", optarg);
119 pacc->method = PCI_ACCESS_DUMP;
123 set_pci_method(pacc, optarg);
129 set_pci_option(pacc, optarg);