quirks.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  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/dmi.h>
  20. #include <linux/kallsyms.h>
  21. #include "base.h"
  22. static void quirk_awe32_resources(struct pnp_dev *dev)
  23. {
  24. struct pnp_port *port, *port2, *port3;
  25. struct pnp_option *res = dev->dependent;
  26. /*
  27. * Unfortunately the isapnp_add_port_resource is too tightly bound
  28. * into the PnP discovery sequence, and cannot be used. Link in the
  29. * two extra ports (at offset 0x400 and 0x800 from the one given) by
  30. * hand.
  31. */
  32. for (; res; res = res->next) {
  33. port2 = pnp_alloc(sizeof(struct pnp_port));
  34. if (!port2)
  35. return;
  36. port3 = pnp_alloc(sizeof(struct pnp_port));
  37. if (!port3) {
  38. kfree(port2);
  39. return;
  40. }
  41. port = res->port;
  42. memcpy(port2, port, sizeof(struct pnp_port));
  43. memcpy(port3, port, sizeof(struct pnp_port));
  44. port->next = port2;
  45. port2->next = port3;
  46. port2->min += 0x400;
  47. port2->max += 0x400;
  48. port3->min += 0x800;
  49. port3->max += 0x800;
  50. }
  51. printk(KERN_INFO "pnp: AWE32 quirk - adding two ports\n");
  52. }
  53. static void quirk_cmi8330_resources(struct pnp_dev *dev)
  54. {
  55. struct pnp_option *res = dev->dependent;
  56. unsigned long tmp;
  57. for (; res; res = res->next) {
  58. struct pnp_irq *irq;
  59. struct pnp_dma *dma;
  60. for (irq = res->irq; irq; irq = irq->next) { // Valid irqs are 5, 7, 10
  61. tmp = 0x04A0;
  62. bitmap_copy(irq->map, &tmp, 16); // 0000 0100 1010 0000
  63. }
  64. for (dma = res->dma; dma; dma = dma->next) // Valid 8bit dma channels are 1,3
  65. if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
  66. IORESOURCE_DMA_8BIT)
  67. dma->map = 0x000A;
  68. }
  69. printk(KERN_INFO "pnp: CMI8330 quirk - fixing interrupts and dma\n");
  70. }
  71. static void quirk_sb16audio_resources(struct pnp_dev *dev)
  72. {
  73. struct pnp_port *port;
  74. struct pnp_option *res = dev->dependent;
  75. int changed = 0;
  76. /*
  77. * The default range on the mpu port for these devices is 0x388-0x388.
  78. * Here we increase that range so that two such cards can be
  79. * auto-configured.
  80. */
  81. for (; res; res = res->next) {
  82. port = res->port;
  83. if (!port)
  84. continue;
  85. port = port->next;
  86. if (!port)
  87. continue;
  88. port = port->next;
  89. if (!port)
  90. continue;
  91. if (port->min != port->max)
  92. continue;
  93. port->max += 0x70;
  94. changed = 1;
  95. }
  96. if (changed)
  97. printk(KERN_INFO
  98. "pnp: SB audio device quirk - increasing port range\n");
  99. }
  100. static void quirk_supermicro_h8dce_system(struct pnp_dev *dev)
  101. {
  102. int i;
  103. static struct dmi_system_id supermicro_h8dce[] = {
  104. {
  105. .ident = "Supermicro H8DCE",
  106. .matches = {
  107. DMI_MATCH(DMI_SYS_VENDOR, "Supermicro"),
  108. DMI_MATCH(DMI_PRODUCT_NAME, "H8DCE"),
  109. },
  110. },
  111. { }
  112. };
  113. if (!dmi_check_system(supermicro_h8dce))
  114. return;
  115. /*
  116. * On the Supermicro H8DCE, there's a system device with resources
  117. * that overlap BAR 6 of the built-in SATA PCI adapter. If the PNP
  118. * system device claims them, the sata_nv driver won't be able to.
  119. * More details at:
  120. * https://bugzilla.redhat.com/show_bug.cgi?id=280641
  121. * https://bugzilla.redhat.com/show_bug.cgi?id=313491
  122. * http://lkml.org/lkml/2008/1/9/449
  123. * http://thread.gmane.org/gmane.linux.acpi.devel/27312
  124. */
  125. for (i = 0; i < PNP_MAX_MEM; i++) {
  126. if (pnp_mem_valid(dev, i) && pnp_mem_len(dev, i) &&
  127. (pnp_mem_start(dev, i) & 0xdfef0000) == 0xdfef0000) {
  128. dev_warn(&dev->dev, "disabling 0x%llx-0x%llx to prevent"
  129. " conflict with sata_nv PCI device\n",
  130. (unsigned long long) pnp_mem_start(dev, i),
  131. (unsigned long long) (pnp_mem_start(dev, i) +
  132. pnp_mem_len(dev, i) - 1));
  133. pnp_mem_flags(dev, i) = 0;
  134. }
  135. }
  136. }
  137. /*
  138. * PnP Quirks
  139. * Cards or devices that need some tweaking due to incomplete resource info
  140. */
  141. static struct pnp_fixup pnp_fixups[] = {
  142. /* Soundblaster awe io port quirk */
  143. {"CTL0021", quirk_awe32_resources},
  144. {"CTL0022", quirk_awe32_resources},
  145. {"CTL0023", quirk_awe32_resources},
  146. /* CMI 8330 interrupt and dma fix */
  147. {"@X@0001", quirk_cmi8330_resources},
  148. /* Soundblaster audio device io port range quirk */
  149. {"CTL0001", quirk_sb16audio_resources},
  150. {"CTL0031", quirk_sb16audio_resources},
  151. {"CTL0041", quirk_sb16audio_resources},
  152. {"CTL0042", quirk_sb16audio_resources},
  153. {"CTL0043", quirk_sb16audio_resources},
  154. {"CTL0044", quirk_sb16audio_resources},
  155. {"CTL0045", quirk_sb16audio_resources},
  156. {"PNP0c01", quirk_supermicro_h8dce_system},
  157. {"PNP0c02", quirk_supermicro_h8dce_system},
  158. {""}
  159. };
  160. void pnp_fixup_device(struct pnp_dev *dev)
  161. {
  162. int i = 0;
  163. void (*quirk)(struct pnp_dev *);
  164. while (*pnp_fixups[i].id) {
  165. if (compare_pnp_id(dev->id, pnp_fixups[i].id)) {
  166. quirk = pnp_fixups[i].quirk_function;
  167. #ifdef DEBUG
  168. dev_dbg(&dev->dev, "calling quirk 0x%p", quirk);
  169. print_fn_descriptor_symbol(": %s()\n",
  170. (unsigned long) *quirk);
  171. #endif
  172. (*quirk)(dev);
  173. }
  174. i++;
  175. }
  176. }