42 static int device_entries_sorted = 0;
43 static int n_device_entries = 0;
44 static int device_exit_on_error = 1;
46 static struct pci_entry *pci_entries = NULL;
47 static int n_pci_entries = 0;
55 static int device_entry_compar(
const void *a,
const void *b)
69 static void sort_entries(
void)
71 qsort(device_entries, n_device_entries,
sizeof(
struct device_entry),
74 device_entries_sorted = 1;
94 memset(&device_entries[n_device_entries], 0,
98 device_entries[n_device_entries].
initf =
initf;
100 device_entries_sorted = 0;
115 struct pci_device *))
118 sizeof(
struct pci_entry) * (n_pci_entries + 1)));
120 memset(&pci_entries[n_pci_entries], 0,
sizeof(
struct pci_entry));
137 struct memory *mem,
struct pci_device *pd)
142 fprintf(stderr,
"pci_lookup_initf(): name = NULL\n");
146 for (i=0; i<n_pci_entries; i++)
147 if (strcmp(name, pci_entries[i].name) == 0)
148 return pci_entries[i].
initf;
167 fprintf(stderr,
"device_lookup(): NULL ptr\n");
171 if (!device_entries_sorted)
174 if (n_device_entries == 0)
177 lo = 0; hi = n_device_entries - 1;
180 int r, i = (lo + hi) / 2;
186 r = strcmp(
name, device_entries[i].
name);
189 return &device_entries[i];
216 fatal(
"device_unregister(): no such device (\"%s\")\n",
name);
220 i = (size_t)p - (
size_t)device_entries;
223 free(device_entries[i].
name);
224 device_entries[i].
name = NULL;
226 if (i == n_device_entries-1) {
231 device_entries[i] = device_entries[n_device_entries-1];
234 device_entries_sorted = 0;
269 s2 = name_and_params;
270 while (s2[0] !=
',' && s2[0] !=
' ' && s2[0] !=
'\0')
273 len = (size_t)s2 - (
size_t)name_and_params;
280 malloc(interrupt_path_len + 1));
287 if (device_exit_on_error)
294 while (*s2 !=
'\0') {
296 while (*s2 ==
' ' || *s2 ==
',' || *s2 ==
';')
306 while (*s3 !=
'=' && *s3 !=
'\0')
309 fatal(
"weird param: %s\n", s2);
310 if (device_exit_on_error)
318 if (strncmp(s2,
"addr=", 5) == 0) {
320 }
else if (strncmp(s2,
"addr2=", 6) == 0) {
322 }
else if (strncmp(s2,
"len=", 4) == 0) {
324 }
else if (strncmp(s2,
"addr_mult=", 10) == 0) {
326 }
else if (strncmp(s2,
"pci_little_endian=", 18) == 0) {
333 default:
fatal(
"Bad pci_little_endian value.\n");
336 }
else if (strncmp(s2,
"irq=", 4) == 0) {
340 }
else if (strncmp(s2,
"in_use=", 7) == 0) {
342 }
else if (strncmp(s2,
"name2=", 6) == 0) {
343 const char *h = s2 + 6;
350 if (!quoted && *h ==
' ')
359 fatal(
"unknown param: %s\n", s2);
360 if (device_exit_on_error)
369 while (*s2 !=
'\0' && (*s2 !=
' ' || quoted) &&
370 *s2 !=
',' && *s2 !=
';') {
385 fatal(
"error adding device (\"%s\")\n", name_and_params);
386 if (device_exit_on_error)
412 if (!device_entries_sorted)
415 for (i=0; i<n_device_entries; i++) {
435 device_exit_on_error = exit_on_error;
449 device_entries = NULL;
450 device_entries_sorted = 0;
451 n_device_entries = 0;