quirks.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  1. /*
  2. * This file contains quirk handling code for PnP devices
  3. * Some devices do not report all their resources, and need to have extra
  4. * resources added. This is most easily accomplished at initialisation time
  5. * when building up the resource structure for the first time.
  6. *
  7. * Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk>
  8. *
  9. * Heavily based on PCI quirks handling which is
  10. *
  11. * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
  12. */
  13. #include <linux/types.h>
  14. #include <linux/kernel.h>
  15. #include <linux/string.h>
  16. #include <linux/slab.h>
  17. #include <linux/pnp.h>
  18. #include <linux/io.h>
  19. #include <linux/kallsyms.h>
  20. #include "base.h"
  21. static void quirk_awe32_resources(struct pnp_dev *dev)
  22. {
  23. struct pnp_port *port, *port2, *port3;
  24. struct pnp_option *res = dev->dependent;
  25. /*
  26. * Unfortunately the isapnp_add_port_resource is too tightly bound
  27. * into the PnP discovery sequence, and cannot be used. Link in the
  28. * two extra ports (at offset 0x400 and 0x800 from the one given) by
  29. * hand.
  30. */
  31. for (; res; res = res->next) {
  32. port2 = pnp_alloc(sizeof(struct pnp_port));
  33. if (!port2)
  34. return;
  35. port3 = pnp_alloc(sizeof(struct pnp_port));
  36. if (!port3) {
  37. kfree(port2);
  38. return;
  39. }
  40. port = res->port;
  41. memcpy(port2, port, sizeof(struct pnp_port));
  42. memcpy(port3, port, sizeof(struct pnp_port));
  43. port->next = port2;
  44. port2->next = port3;
  45. port2->min += 0x400;
  46. port2->max += 0x400;
  47. port3->min += 0x800;
  48. port3->max += 0x800;
  49. dev_info(&dev->dev,
  50. "AWE32 quirk - added ioports 0x%lx and 0x%lx\n",
  51. (unsigned long)port2->min,
  52. (unsigned long)port3->min);
  53. }
  54. }
  55. static void quirk_cmi8330_resources(struct pnp_dev *dev)
  56. {
  57. struct pnp_option *res = dev->dependent;
  58. unsigned long tmp;
  59. for (; res; res = res->next) {
  60. struct pnp_irq *irq;
  61. struct pnp_dma *dma;
  62. for (irq = res->irq; irq; irq = irq->next) { // Valid irqs are 5, 7, 10
  63. tmp = 0x04A0;
  64. bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000
  65. }
  66. for (dma = res->dma; dma; dma = dma->next) // Valid 8bit dma channels are 1,3
  67. if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
  68. IORESOURCE_DMA_8BIT)
  69. dma->map = 0x000A;
  70. }
  71. dev_info(&dev->dev, "CMI8330 quirk - forced possible IRQs to 5, 7, 10 "
  72. "and DMA channels to 1, 3\n");
  73. }
  74. static void quirk_sb16audio_resources(struct pnp_dev *dev)
  75. {
  76. struct pnp_port *port;
  77. struct pnp_option *res = dev->dependent;
  78. int changed = 0;
  79. /*
  80. * The default range on the mpu port for these devices is 0x388-0x388.
  81. * Here we increase that range so that two such cards can be
  82. * auto-configured.
  83. */
  84. for (; res; res = res->next) {
  85. port = res->port;
  86. if (!port)
  87. continue;
  88. port = port->next;
  89. if (!port)
  90. continue;
  91. port = port->next;
  92. if (!port)
  93. continue;
  94. if (port->min != port->max)
  95. continue;
  96. port->max += 0x70;
  97. changed = 1;
  98. }
  99. if (changed)
  100. dev_info(&dev->dev, "SB audio device quirk - increased port range\n");
  101. }
  102. #include <linux/pci.h>
  103. static void quirk_system_pci_resources(struct pnp_dev *dev)
  104. {
  105. struct pci_dev *pdev = NULL;
  106. struct resource *res;
  107. resource_size_t pnp_start, pnp_end, pci_start, pci_end;
  108. int i, j;
  109. /*
  110. * Some BIOSes have PNP motherboard devices with resources that
  111. * partially overlap PCI BARs. The PNP system driver claims these
  112. * motherboard resources, which prevents the normal PCI driver from
  113. * requesting them later.
  114. *
  115. * This patch disables the PNP resources that conflict with PCI BARs
  116. * so they won't be claimed by the PNP system driver.
  117. */
  118. for_each_pci_dev(pdev) {
  119. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  120. if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM) ||
  121. pci_resource_len(pdev, i) == 0)
  122. continue;
  123. pci_start = pci_resource_start(pdev, i);
  124. pci_end = pci_resource_end(pdev, i);
  125. for (j = 0; j < PNP_MAX_MEM; j++) {
  126. if (!pnp_mem_valid(dev, j) ||
  127. pnp_mem_len(dev, j) == 0)
  128. continue;
  129. pnp_start = pnp_mem_start(dev, j);
  130. pnp_end = pnp_mem_end(dev, j);
  131. /*
  132. * If the PNP region doesn't overlap the PCI
  133. * region at all, there's no problem.
  134. */
  135. if (pnp_end < pci_start || pnp_start > pci_end)
  136. continue;
  137. /*
  138. * If the PNP region completely encloses (or is
  139. * at least as large as) the PCI region, that's
  140. * also OK. For example, this happens when the
  141. * PNP device describes a bridge with PCI
  142. * behind it.
  143. */
  144. if (pnp_start <= pci_start &&
  145. pnp_end >= pci_end)
  146. continue;
  147. /*
  148. * Otherwise, the PNP region overlaps *part* of
  149. * the PCI region, and that might prevent a PCI
  150. * driver from requesting its resources.
  151. */
  152. dev_warn(&dev->dev, "mem resource "
  153. "(0x%llx-0x%llx) overlaps %s BAR %d "
  154. "(0x%llx-0x%llx), disabling\n",
  155. (unsigned long long) pnp_start,
  156. (unsigned long long) pnp_end,
  157. pci_name(pdev), i,
  158. (unsigned long long) pci_start,
  159. (unsigned long long) pci_end);
  160. res = pnp_get_resource(dev, IORESOURCE_MEM, j);
  161. res->flags = 0;
  162. }
  163. }
  164. }
  165. }
  166. /*
  167. * PnP Quirks
  168. * Cards or devices that need some tweaking due to incomplete resource info
  169. */
  170. static struct pnp_fixup pnp_fixups[] = {
  171. /* Soundblaster awe io port quirk */
  172. {"CTL0021", quirk_awe32_resources},
  173. {"CTL0022", quirk_awe32_resources},
  174. {"CTL0023", quirk_awe32_resources},
  175. /* CMI 8330 interrupt and dma fix */
  176. {"@X@0001", quirk_cmi8330_resources},
  177. /* Soundblaster audio device io port range quirk */
  178. {"CTL0001", quirk_sb16audio_resources},
  179. {"CTL0031", quirk_sb16audio_resources},
  180. {"CTL0041", quirk_sb16audio_resources},
  181. {"CTL0042", quirk_sb16audio_resources},
  182. {"CTL0043", quirk_sb16audio_resources},
  183. {"CTL0044", quirk_sb16audio_resources},
  184. {"CTL0045", quirk_sb16audio_resources},
  185. {"PNP0c01", quirk_system_pci_resources},
  186. {"PNP0c02", quirk_system_pci_resources},
  187. {""}
  188. };
  189. void pnp_fixup_device(struct pnp_dev *dev)
  190. {
  191. int i = 0;
  192. void (*quirk)(struct pnp_dev *);
  193. while (*pnp_fixups[i].id) {
  194. if (compare_pnp_id(dev->id, pnp_fixups[i].id)) {
  195. quirk = pnp_fixups[i].quirk_function;
  196. #ifdef DEBUG
  197. dev_dbg(&dev->dev, "calling ");
  198. print_fn_descriptor_symbol("%s()\n",
  199. (unsigned long) *quirk);
  200. #endif
  201. (*quirk)(dev);
  202. }
  203. i++;
  204. }
  205. }