irq_parse.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* irq_parse.c
  2. * Parse IRQ-related files.
  3. */
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <sys/types.h>
  8. #include <dirent.h>
  9. #include <limits.h>
  10. #include "lub/list.h"
  11. #include "irq.h"
  12. static int irqs_populate_pci(lub_list_t *irqs)
  13. {
  14. DIR *dir;
  15. DIR *msi;
  16. struct dirent *dent;
  17. struct dirent *ment;
  18. char path[PATH_MAX];
  19. int num;
  20. /* Now we can parse PCI devices only */
  21. /* Get info from /sys/bus/pci/devices */
  22. dir = opendir(SYSFS_PCI_PATH);
  23. if (!dir)
  24. return -1;
  25. while((dent = readdir(dir))) {
  26. if (!strcmp(dent->d_name, ".") ||
  27. !strcmp(dent->d_name, ".."))
  28. continue;
  29. /* Search for MSI IRQs. Since linux-3.2 */
  30. sprintf(path, "%s/%s/msi_irqs", SYSFS_PCI_PATH, dent->d_name);
  31. if ((msi = opendir(path))) {
  32. while((ment = readdir(msi))) {
  33. if (!strcmp(ment->d_name, ".") ||
  34. !strcmp(ment->d_name, ".."))
  35. continue;
  36. num = strtol(ment->d_name, NULL, 10);
  37. if (!num)
  38. continue;
  39. printf("%d\n", num);
  40. }
  41. closedir(msi);
  42. continue;
  43. }
  44. /* Try to get IRQ number from irq file */
  45. sprintf(path, "%s/%s/irq", SYSFS_PCI_PATH, dent->d_name);
  46. }
  47. closedir(dir);
  48. return 0;
  49. }
  50. int irqs_populate(lub_list_t *irqs)
  51. {
  52. irqs_populate_pci(irqs);
  53. // irqs_populate_proc(irqs);
  54. return 0;
  55. }