quirks.c 8.0 KB

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