support.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /*
  2. * support.c - standard functions for the use of pnp protocol drivers
  3. *
  4. * Copyright 2003 Adam Belay <ambx1@neo.rr.com>
  5. */
  6. #include <linux/module.h>
  7. #include <linux/ctype.h>
  8. #include <linux/pnp.h>
  9. #include "base.h"
  10. /**
  11. * pnp_is_active - Determines if a device is active based on its current
  12. * resources
  13. * @dev: pointer to the desired PnP device
  14. */
  15. int pnp_is_active(struct pnp_dev *dev)
  16. {
  17. /*
  18. * I don't think this is very reliable because pnp_disable_dev()
  19. * only clears out auto-assigned resources.
  20. */
  21. if (!pnp_port_start(dev, 0) && pnp_port_len(dev, 0) <= 1 &&
  22. !pnp_mem_start(dev, 0) && pnp_mem_len(dev, 0) <= 1 &&
  23. pnp_irq(dev, 0) == -1 && pnp_dma(dev, 0) == -1)
  24. return 0;
  25. else
  26. return 1;
  27. }
  28. EXPORT_SYMBOL(pnp_is_active);
  29. /*
  30. * Functionally similar to acpi_ex_eisa_id_to_string(), but that's
  31. * buried in the ACPI CA, and we can't depend on it being present.
  32. */
  33. void pnp_eisa_id_to_string(u32 id, char *str)
  34. {
  35. id = be32_to_cpu(id);
  36. /*
  37. * According to the specs, the first three characters are five-bit
  38. * compressed ASCII, and the left-over high order bit should be zero.
  39. * However, the Linux ISAPNP code historically used six bits for the
  40. * first character, and there seem to be IDs that depend on that,
  41. * e.g., "nEC8241" in the Linux 8250_pnp serial driver and the
  42. * FreeBSD sys/pc98/cbus/sio_cbus.c driver.
  43. */
  44. str[0] = 'A' + ((id >> 26) & 0x3f) - 1;
  45. str[1] = 'A' + ((id >> 21) & 0x1f) - 1;
  46. str[2] = 'A' + ((id >> 16) & 0x1f) - 1;
  47. str[3] = hex_asc_hi(id >> 8);
  48. str[4] = hex_asc_lo(id >> 8);
  49. str[5] = hex_asc_hi(id);
  50. str[6] = hex_asc_lo(id);
  51. str[7] = '\0';
  52. }
  53. char *pnp_resource_type_name(struct resource *res)
  54. {
  55. switch (pnp_resource_type(res)) {
  56. case IORESOURCE_IO:
  57. return "io";
  58. case IORESOURCE_MEM:
  59. return "mem";
  60. case IORESOURCE_IRQ:
  61. return "irq";
  62. case IORESOURCE_DMA:
  63. return "dma";
  64. }
  65. return NULL;
  66. }
  67. void dbg_pnp_show_resources(struct pnp_dev *dev, char *desc)
  68. {
  69. #ifdef DEBUG
  70. char buf[128];
  71. int len = 0;
  72. struct pnp_resource *pnp_res;
  73. struct resource *res;
  74. if (list_empty(&dev->resources)) {
  75. dev_dbg(&dev->dev, "%s: no current resources\n", desc);
  76. return;
  77. }
  78. dev_dbg(&dev->dev, "%s: current resources:\n", desc);
  79. list_for_each_entry(pnp_res, &dev->resources, list) {
  80. res = &pnp_res->res;
  81. len += snprintf(buf + len, sizeof(buf) - len, " %-3s ",
  82. pnp_resource_type_name(res));
  83. if (res->flags & IORESOURCE_DISABLED) {
  84. dev_dbg(&dev->dev, "%sdisabled\n", buf);
  85. continue;
  86. }
  87. switch (pnp_resource_type(res)) {
  88. case IORESOURCE_IO:
  89. case IORESOURCE_MEM:
  90. len += snprintf(buf + len, sizeof(buf) - len,
  91. "%#llx-%#llx flags %#lx",
  92. (unsigned long long) res->start,
  93. (unsigned long long) res->end,
  94. res->flags);
  95. break;
  96. case IORESOURCE_IRQ:
  97. case IORESOURCE_DMA:
  98. len += snprintf(buf + len, sizeof(buf) - len,
  99. "%lld flags %#lx",
  100. (unsigned long long) res->start,
  101. res->flags);
  102. break;
  103. }
  104. dev_dbg(&dev->dev, "%s\n", buf);
  105. }
  106. #endif
  107. }