1 |
/* |
/* |
2 |
* Copyright (C) 2005 Anders Gavare. All rights reserved. |
* Copyright (C) 2005-2006 Anders Gavare. All rights reserved. |
3 |
* |
* |
4 |
* Redistribution and use in source and binary forms, with or without |
* Redistribution and use in source and binary forms, with or without |
5 |
* modification, are permitted provided that the following conditions are met: |
* modification, are permitted provided that the following conditions are met: |
25 |
* SUCH DAMAGE. |
* SUCH DAMAGE. |
26 |
* |
* |
27 |
* |
* |
28 |
* $Id: device.c,v 1.20 2005/11/22 16:26:35 debug Exp $ |
* $Id: device.c,v 1.25 2006/02/18 21:03:11 debug Exp $ |
29 |
* |
* |
30 |
* Device registry framework. |
* Device registry framework. |
31 |
*/ |
*/ |
142 |
* |
* |
143 |
* Return value is a function pointer, or NULL if the name was not found. |
* Return value is a function pointer, or NULL if the name was not found. |
144 |
*/ |
*/ |
145 |
void (*pci_lookup_initf(char *name))(struct machine *machine, |
void (*pci_lookup_initf(const char *name))(struct machine *machine, |
146 |
struct memory *mem, struct pci_device *pd) |
struct memory *mem, struct pci_device *pd) |
147 |
{ |
{ |
148 |
int i; |
int i; |
264 |
struct devinit devinit; |
struct devinit devinit; |
265 |
char *s2, *s3; |
char *s2, *s3; |
266 |
size_t len; |
size_t len; |
267 |
|
int quoted; |
268 |
|
|
269 |
memset(&devinit, 0, sizeof(struct devinit)); |
memset(&devinit, 0, sizeof(struct devinit)); |
270 |
devinit.machine = machine; |
devinit.machine = machine; |
286 |
} |
} |
287 |
memcpy(devinit.name, name_and_params, len); |
memcpy(devinit.name, name_and_params, len); |
288 |
devinit.name[len] = '\0'; |
devinit.name[len] = '\0'; |
289 |
|
devinit.dma_irq_nr = -1; |
290 |
|
|
291 |
p = device_lookup(devinit.name); |
p = device_lookup(devinit.name); |
292 |
if (p == NULL) { |
if (p == NULL) { |
342 |
} |
} |
343 |
} else if (strncmp(s2, "irq=", 4) == 0) { |
} else if (strncmp(s2, "irq=", 4) == 0) { |
344 |
devinit.irq_nr = mystrtoull(s3, NULL, 0); |
devinit.irq_nr = mystrtoull(s3, NULL, 0); |
345 |
|
} else if (strncmp(s2, "dma_irq=", 8) == 0) { |
346 |
|
devinit.dma_irq_nr = mystrtoull(s3, NULL, 0); |
347 |
} else if (strncmp(s2, "in_use=", 7) == 0) { |
} else if (strncmp(s2, "in_use=", 7) == 0) { |
348 |
devinit.in_use = mystrtoull(s3, NULL, 0); |
devinit.in_use = mystrtoull(s3, NULL, 0); |
349 |
} else if (strncmp(s2, "name2=", 6) == 0) { |
} else if (strncmp(s2, "name2=", 6) == 0) { |
350 |
char *h = s2 + 6; |
char *h = s2 + 6; |
351 |
size_t len = 0; |
size_t len = 0; |
352 |
while (*h && *h != ' ') |
quoted = 0; |
353 |
|
while (*h) { |
354 |
|
if (*h == '\'') |
355 |
|
quoted = !quoted; |
356 |
h++, len++; |
h++, len++; |
357 |
|
if (!quoted && *h == ' ') |
358 |
|
break; |
359 |
|
} |
360 |
devinit.name2 = malloc(len + 1); |
devinit.name2 = malloc(len + 1); |
361 |
if (devinit.name2 == NULL) { |
if (devinit.name2 == NULL) { |
362 |
fprintf(stderr, "out of memory\n"); |
fprintf(stderr, "out of memory\n"); |
363 |
exit(1); |
exit(1); |
364 |
} |
} |
365 |
snprintf(devinit.name2, len + 1, s2 + 6); |
h = s2 + 6; |
366 |
|
if (*h == '\'') |
367 |
|
len -= 2, h++; |
368 |
|
snprintf(devinit.name2, len + 1, h); |
369 |
} else { |
} else { |
370 |
fatal("unknown param: %s\n", s2); |
fatal("unknown param: %s\n", s2); |
371 |
if (device_exit_on_error) |
if (device_exit_on_error) |
376 |
|
|
377 |
/* skip to the next param: */ |
/* skip to the next param: */ |
378 |
s2 = s3; |
s2 = s3; |
379 |
while (*s2 != '\0' && *s2 != ' ' && *s2 != ',' && *s2 != ';') |
quoted = 0; |
380 |
|
while (*s2 != '\0' && (*s2 != ' ' || quoted) && |
381 |
|
*s2 != ',' && *s2 != ';') { |
382 |
|
if (*s2 == '\'') |
383 |
|
quoted = !quoted; |
384 |
s2 ++; |
s2 ++; |
385 |
|
} |
386 |
} |
} |
387 |
|
|
388 |
|
|