quirks.c 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  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) {
  63. /* Valid irqs are 5, 7, 10 */
  64. tmp = 0x04A0;
  65. bitmap_copy(irq->map.bits, &tmp, 16);
  66. }
  67. for (dma = res->dma; dma; dma = dma->next) {
  68. /* Valid 8bit dma channels are 1,3 */
  69. if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
  70. IORESOURCE_DMA_8BIT)
  71. dma->map = 0x000A;
  72. }
  73. }
  74. dev_info(&dev->dev, "CMI8330 quirk - forced possible IRQs to 5, 7, 10 "
  75. "and DMA channels to 1, 3\n");
  76. }
  77. static void quirk_sb16audio_resources(struct pnp_dev *dev)
  78. {
  79. struct pnp_port *port;
  80. struct pnp_option *res = dev->dependent;
  81. int changed = 0;
  82. /*
  83. * The default range on the mpu port for these devices is 0x388-0x388.
  84. * Here we increase that range so that two such cards can be
  85. * auto-configured.
  86. */
  87. for (; res; res = res->next) {
  88. port = res->port;
  89. if (!port)
  90. continue;
  91. port = port->next;
  92. if (!port)
  93. continue;
  94. port = port->next;
  95. if (!port)
  96. continue;
  97. if (port->min != port->max)
  98. continue;
  99. port->max += 0x70;
  100. changed = 1;
  101. }
  102. if (changed)
  103. dev_info(&dev->dev, "SB audio device quirk - increased port range\n");
  104. }
  105. static struct pnp_option *quirk_isapnp_mpu_options(struct pnp_dev *dev)
  106. {
  107. struct pnp_option *head = NULL;
  108. struct pnp_option *prev = NULL;
  109. struct pnp_option *res;
  110. /*
  111. * Build a functional IRQ-optional variant of each MPU option.
  112. */
  113. for (res = dev->dependent; res; res = res->next) {
  114. struct pnp_option *curr;
  115. struct pnp_port *port;
  116. struct pnp_port *copy_port;
  117. struct pnp_irq *irq;
  118. struct pnp_irq *copy_irq;
  119. port = res->port;
  120. irq = res->irq;
  121. if (!port || !irq)
  122. continue;
  123. copy_port = pnp_alloc(sizeof *copy_port);
  124. if (!copy_port)
  125. break;
  126. copy_irq = pnp_alloc(sizeof *copy_irq);
  127. if (!copy_irq) {
  128. kfree(copy_port);
  129. break;
  130. }
  131. *copy_port = *port;
  132. copy_port->next = NULL;
  133. *copy_irq = *irq;
  134. copy_irq->flags |= IORESOURCE_IRQ_OPTIONAL;
  135. copy_irq->next = NULL;
  136. curr = pnp_build_option(PNP_RES_PRIORITY_FUNCTIONAL);
  137. if (!curr) {
  138. kfree(copy_port);
  139. kfree(copy_irq);
  140. break;
  141. }
  142. curr->port = copy_port;
  143. curr->irq = copy_irq;
  144. if (prev)
  145. prev->next = curr;
  146. else
  147. head = curr;
  148. prev = curr;
  149. }
  150. if (head)
  151. dev_info(&dev->dev, "adding IRQ-optional MPU options\n");
  152. return head;
  153. }
  154. static void quirk_ad1815_mpu_resources(struct pnp_dev *dev)
  155. {
  156. struct pnp_option *res;
  157. struct pnp_irq *irq;
  158. res = dev->independent;
  159. if (!res)
  160. return;
  161. irq = res->irq;
  162. if (!irq || irq->next)
  163. return;
  164. irq->flags |= IORESOURCE_IRQ_OPTIONAL;
  165. dev_info(&dev->dev, "made independent IRQ optional\n");
  166. }
  167. static void quirk_isapnp_mpu_resources(struct pnp_dev *dev)
  168. {
  169. struct pnp_option *res;
  170. res = dev->dependent;
  171. if (!res)
  172. return;
  173. while (res->next)
  174. res = res->next;
  175. res->next = quirk_isapnp_mpu_options(dev);
  176. }
  177. #include <linux/pci.h>
  178. static void quirk_system_pci_resources(struct pnp_dev *dev)
  179. {
  180. struct pci_dev *pdev = NULL;
  181. struct resource *res;
  182. resource_size_t pnp_start, pnp_end, pci_start, pci_end;
  183. int i, j;
  184. /*
  185. * Some BIOSes have PNP motherboard devices with resources that
  186. * partially overlap PCI BARs. The PNP system driver claims these
  187. * motherboard resources, which prevents the normal PCI driver from
  188. * requesting them later.
  189. *
  190. * This patch disables the PNP resources that conflict with PCI BARs
  191. * so they won't be claimed by the PNP system driver.
  192. */
  193. for_each_pci_dev(pdev) {
  194. for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
  195. if (!(pci_resource_flags(pdev, i) & IORESOURCE_MEM) ||
  196. pci_resource_len(pdev, i) == 0)
  197. continue;
  198. pci_start = pci_resource_start(pdev, i);
  199. pci_end = pci_resource_end(pdev, i);
  200. for (j = 0;
  201. (res = pnp_get_resource(dev, IORESOURCE_MEM, j));
  202. j++) {
  203. if (res->start == 0 && res->end == 0)
  204. continue;
  205. pnp_start = res->start;
  206. pnp_end = res->end;
  207. /*
  208. * If the PNP region doesn't overlap the PCI
  209. * region at all, there's no problem.
  210. */
  211. if (pnp_end < pci_start || pnp_start > pci_end)
  212. continue;
  213. /*
  214. * If the PNP region completely encloses (or is
  215. * at least as large as) the PCI region, that's
  216. * also OK. For example, this happens when the
  217. * PNP device describes a bridge with PCI
  218. * behind it.
  219. */
  220. if (pnp_start <= pci_start &&
  221. pnp_end >= pci_end)
  222. continue;
  223. /*
  224. * Otherwise, the PNP region overlaps *part* of
  225. * the PCI region, and that might prevent a PCI
  226. * driver from requesting its resources.
  227. */
  228. dev_warn(&dev->dev, "mem resource "
  229. "(0x%llx-0x%llx) overlaps %s BAR %d "
  230. "(0x%llx-0x%llx), disabling\n",
  231. (unsigned long long) pnp_start,
  232. (unsigned long long) pnp_end,
  233. pci_name(pdev), i,
  234. (unsigned long long) pci_start,
  235. (unsigned long long) pci_end);
  236. res->flags |= IORESOURCE_DISABLED;
  237. }
  238. }
  239. }
  240. }
  241. /*
  242. * PnP Quirks
  243. * Cards or devices that need some tweaking due to incomplete resource info
  244. */
  245. static struct pnp_fixup pnp_fixups[] = {
  246. /* Soundblaster awe io port quirk */
  247. {"CTL0021", quirk_awe32_resources},
  248. {"CTL0022", quirk_awe32_resources},
  249. {"CTL0023", quirk_awe32_resources},
  250. /* CMI 8330 interrupt and dma fix */
  251. {"@X@0001", quirk_cmi8330_resources},
  252. /* Soundblaster audio device io port range quirk */
  253. {"CTL0001", quirk_sb16audio_resources},
  254. {"CTL0031", quirk_sb16audio_resources},
  255. {"CTL0041", quirk_sb16audio_resources},
  256. {"CTL0042", quirk_sb16audio_resources},
  257. {"CTL0043", quirk_sb16audio_resources},
  258. {"CTL0044", quirk_sb16audio_resources},
  259. {"CTL0045", quirk_sb16audio_resources},
  260. /* Add IRQ-less MPU options */
  261. {"ADS7151", quirk_ad1815_mpu_resources},
  262. {"ADS7181", quirk_isapnp_mpu_resources},
  263. {"AZT0002", quirk_isapnp_mpu_resources},
  264. /* PnP resources that might overlap PCI BARs */
  265. {"PNP0c01", quirk_system_pci_resources},
  266. {"PNP0c02", quirk_system_pci_resources},
  267. {""}
  268. };
  269. void pnp_fixup_device(struct pnp_dev *dev)
  270. {
  271. struct pnp_fixup *f;
  272. for (f = pnp_fixups; *f->id; f++) {
  273. if (!compare_pnp_id(dev->id, f->id))
  274. continue;
  275. #ifdef DEBUG
  276. dev_dbg(&dev->dev, "%s: calling ", f->id);
  277. print_fn_descriptor_symbol("%s\n", f->quirk_function);
  278. #endif
  279. f->quirk_function(dev);
  280. }
  281. }