blob: 258fef272ea7d6b61faa565260c8fc7b7a4f995d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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>
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -06008 * Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
9 * Bjorn Helgaas <bjorn.helgaas@hp.com>
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 *
11 * Heavily based on PCI quirks handling which is
12 *
13 * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
14 */
15
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#include <linux/types.h>
17#include <linux/kernel.h>
18#include <linux/string.h>
19#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <linux/pnp.h>
Bjorn Helgaasa1e7e632007-05-08 00:36:00 -070021#include <linux/io.h>
Bjorn Helgaasa05d0782007-10-16 23:31:10 -070022#include <linux/kallsyms.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#include "base.h"
24
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060025static void quirk_awe32_add_ports(struct pnp_dev *dev,
26 struct pnp_option *option,
27 unsigned int offset)
28{
29 struct pnp_option *new_option;
30
31 new_option = kmalloc(sizeof(struct pnp_option), GFP_KERNEL);
32 if (!new_option) {
33 dev_err(&dev->dev, "couldn't add ioport region to option set "
34 "%d\n", pnp_option_set(option));
35 return;
36 }
37
38 *new_option = *option;
39 new_option->u.port.min += offset;
40 new_option->u.port.max += offset;
41 list_add(&new_option->list, &option->list);
42
43 dev_info(&dev->dev, "added ioport region %#llx-%#llx to set %d\n",
44 (unsigned long long) new_option->u.port.min,
45 (unsigned long long) new_option->u.port.max,
46 pnp_option_set(option));
47}
48
Linus Torvalds1da177e2005-04-16 15:20:36 -070049static void quirk_awe32_resources(struct pnp_dev *dev)
50{
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060051 struct pnp_option *option;
52 unsigned int set = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070053
54 /*
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060055 * Add two extra ioport regions (at offset 0x400 and 0x800 from the
56 * one given) to every dependent option set.
Linus Torvalds1da177e2005-04-16 15:20:36 -070057 */
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060058 list_for_each_entry(option, &dev->options, list) {
59 if (pnp_option_is_dependent(option) &&
60 pnp_option_set(option) != set) {
61 set = pnp_option_set(option);
62 quirk_awe32_add_ports(dev, option, 0x800);
63 quirk_awe32_add_ports(dev, option, 0x400);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070066}
67
68static void quirk_cmi8330_resources(struct pnp_dev *dev)
69{
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060070 struct pnp_option *option;
71 struct pnp_irq *irq;
72 struct pnp_dma *dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -070073
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060074 list_for_each_entry(option, &dev->options, list) {
75 if (!pnp_option_is_dependent(option))
76 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060078 if (option->type == IORESOURCE_IRQ) {
79 irq = &option->u.irq;
80 bitmap_zero(irq->map.bits, PNP_IRQ_NR);
81 __set_bit(5, irq->map.bits);
82 __set_bit(7, irq->map.bits);
83 __set_bit(10, irq->map.bits);
84 dev_info(&dev->dev, "set possible IRQs in "
85 "option set %d to 5, 7, 10\n",
86 pnp_option_set(option));
87 } else if (option->type == IORESOURCE_DMA) {
88 dma = &option->u.dma;
Bjorn Helgaas9dd78462007-07-26 10:41:20 -070089 if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -060090 IORESOURCE_DMA_8BIT &&
91 dma->map != 0x0A) {
92 dev_info(&dev->dev, "changing possible "
93 "DMA channel mask in option set %d "
94 "from %#02x to 0x0A (1, 3)\n",
95 pnp_option_set(option), dma->map);
96 dma->map = 0x0A;
97 }
Bjorn Helgaas7aefff52008-06-27 16:57:05 -060098 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070099 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100}
101
102static void quirk_sb16audio_resources(struct pnp_dev *dev)
103{
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600104 struct pnp_option *option;
105 unsigned int prev_option_flags = ~0, n = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 struct pnp_port *port;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /*
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600109 * The default range on the OPL port for these devices is 0x388-0x388.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 * Here we increase that range so that two such cards can be
111 * auto-configured.
112 */
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600113 list_for_each_entry(option, &dev->options, list) {
114 if (prev_option_flags != option->flags) {
115 prev_option_flags = option->flags;
116 n = 0;
117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600119 if (pnp_option_is_dependent(option) &&
120 option->type == IORESOURCE_IO) {
121 n++;
122 port = &option->u.port;
123 if (n == 3 && port->min == port->max) {
124 port->max += 0x70;
125 dev_info(&dev->dev, "increased option port "
126 "range from %#llx-%#llx to "
127 "%#llx-%#llx\n",
128 (unsigned long long) port->min,
129 (unsigned long long) port->min,
130 (unsigned long long) port->min,
131 (unsigned long long) port->max);
132 }
133 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135}
136
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600137static struct pnp_option *pnp_clone_dependent_set(struct pnp_dev *dev,
138 unsigned int set)
Rene Herman3b73a222008-05-14 16:05:36 -0700139{
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600140 struct pnp_option *tail = NULL, *first_new_option = NULL;
141 struct pnp_option *option, *new_option;
142 unsigned int flags;
Rene Herman3b73a222008-05-14 16:05:36 -0700143
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600144 list_for_each_entry(option, &dev->options, list) {
145 if (pnp_option_is_dependent(option))
146 tail = option;
Rene Herman3b73a222008-05-14 16:05:36 -0700147 }
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600148 if (!tail) {
149 dev_err(&dev->dev, "no dependent option sets\n");
150 return NULL;
151 }
Rene Herman3b73a222008-05-14 16:05:36 -0700152
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600153 flags = pnp_new_dependent_set(dev, PNP_RES_PRIORITY_FUNCTIONAL);
154 list_for_each_entry(option, &dev->options, list) {
155 if (pnp_option_is_dependent(option) &&
156 pnp_option_set(option) == set) {
157 new_option = kmalloc(sizeof(struct pnp_option),
158 GFP_KERNEL);
159 if (!new_option) {
160 dev_err(&dev->dev, "couldn't clone dependent "
161 "set %d\n", set);
162 return NULL;
163 }
164
165 *new_option = *option;
166 new_option->flags = flags;
167 if (!first_new_option)
168 first_new_option = new_option;
169
170 list_add(&new_option->list, &tail->list);
171 tail = new_option;
172 }
173 }
174
175 return first_new_option;
176}
177
178
179static void quirk_add_irq_optional_dependent_sets(struct pnp_dev *dev)
180{
181 struct pnp_option *new_option;
182 unsigned int num_sets, i, set;
183 struct pnp_irq *irq;
184
185 num_sets = dev->num_dependent_sets;
186 for (i = 0; i < num_sets; i++) {
187 new_option = pnp_clone_dependent_set(dev, i);
188 if (!new_option)
189 return;
190
191 set = pnp_option_set(new_option);
192 while (new_option && pnp_option_set(new_option) == set) {
193 if (new_option->type == IORESOURCE_IRQ) {
194 irq = &new_option->u.irq;
195 irq->flags |= IORESOURCE_IRQ_OPTIONAL;
196 }
197 dbg_pnp_show_option(dev, new_option);
198 new_option = list_entry(new_option->list.next,
199 struct pnp_option, list);
200 }
201
202 dev_info(&dev->dev, "added dependent option set %d (same as "
203 "set %d except IRQ optional)\n", set, i);
204 }
Rene Herman3b73a222008-05-14 16:05:36 -0700205}
206
207static void quirk_ad1815_mpu_resources(struct pnp_dev *dev)
208{
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600209 struct pnp_option *option;
210 struct pnp_irq *irq = NULL;
211 unsigned int independent_irqs = 0;
Rene Herman3b73a222008-05-14 16:05:36 -0700212
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600213 list_for_each_entry(option, &dev->options, list) {
214 if (option->type == IORESOURCE_IRQ &&
215 !pnp_option_is_dependent(option)) {
216 independent_irqs++;
217 irq = &option->u.irq;
218 }
219 }
Rene Herman3b73a222008-05-14 16:05:36 -0700220
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600221 if (independent_irqs != 1)
Rene Herman3b73a222008-05-14 16:05:36 -0700222 return;
223
Bjorn Helgaasd5ebde62008-06-27 16:57:14 -0600224 irq->flags |= IORESOURCE_IRQ_OPTIONAL;
225 dev_info(&dev->dev, "made independent IRQ optional\n");
Rene Herman3b73a222008-05-14 16:05:36 -0700226}
227
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600228#include <linux/pci.h>
229
230static void quirk_system_pci_resources(struct pnp_dev *dev)
231{
232 struct pci_dev *pdev = NULL;
Bjorn Helgaas53052fe2008-04-28 16:34:15 -0600233 struct resource *res;
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600234 resource_size_t pnp_start, pnp_end, pci_start, pci_end;
235 int i, j;
236
237 /*
238 * Some BIOSes have PNP motherboard devices with resources that
239 * partially overlap PCI BARs. The PNP system driver claims these
240 * motherboard resources, which prevents the normal PCI driver from
241 * requesting them later.
242 *
243 * This patch disables the PNP resources that conflict with PCI BARs
244 * so they won't be claimed by the PNP system driver.
245 */
246 for_each_pci_dev(pdev) {
247 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
Rene Hermanb563cf52008-10-15 22:03:58 -0700248 unsigned long type;
Rene Herman999ed652008-07-25 19:44:47 -0700249
250 type = pci_resource_flags(pdev, i) &
251 (IORESOURCE_IO | IORESOURCE_MEM);
252 if (!type || pci_resource_len(pdev, i) == 0)
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600253 continue;
254
255 pci_start = pci_resource_start(pdev, i);
256 pci_end = pci_resource_end(pdev, i);
Bjorn Helgaas95ab3662008-04-28 16:34:26 -0600257 for (j = 0;
Rene Herman999ed652008-07-25 19:44:47 -0700258 (res = pnp_get_resource(dev, type, j)); j++) {
Bjorn Helgaasaee3ad82008-06-27 16:56:57 -0600259 if (res->start == 0 && res->end == 0)
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600260 continue;
261
Bjorn Helgaas95ab3662008-04-28 16:34:26 -0600262 pnp_start = res->start;
263 pnp_end = res->end;
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600264
265 /*
266 * If the PNP region doesn't overlap the PCI
267 * region at all, there's no problem.
268 */
269 if (pnp_end < pci_start || pnp_start > pci_end)
270 continue;
271
272 /*
273 * If the PNP region completely encloses (or is
274 * at least as large as) the PCI region, that's
275 * also OK. For example, this happens when the
276 * PNP device describes a bridge with PCI
277 * behind it.
278 */
279 if (pnp_start <= pci_start &&
280 pnp_end >= pci_end)
281 continue;
282
283 /*
284 * Otherwise, the PNP region overlaps *part* of
285 * the PCI region, and that might prevent a PCI
286 * driver from requesting its resources.
287 */
Bjorn Helgaasc7dabef2009-10-27 13:26:47 -0600288 dev_warn(&dev->dev,
289 "disabling %pR because it overlaps "
290 "%s BAR %d %pR\n", res,
Bjorn Helgaas9a007b32009-10-06 15:34:00 -0600291 pci_name(pdev), i, &pdev->resource[i]);
Bjorn Helgaas4b34fe12008-06-02 16:42:49 -0600292 res->flags |= IORESOURCE_DISABLED;
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600293 }
294 }
295 }
296}
297
Bjorn Helgaaseb31aae2012-01-05 14:27:24 -0700298#ifdef CONFIG_AMD_NB
299
300#include <asm/amd_nb.h>
301
302static void quirk_amd_mmconfig_area(struct pnp_dev *dev)
303{
304 resource_size_t start, end;
305 struct pnp_resource *pnp_res;
306 struct resource *res;
307 struct resource mmconfig_res, *mmconfig;
308
309 mmconfig = amd_get_mmconfig_range(&mmconfig_res);
310 if (!mmconfig)
311 return;
312
313 list_for_each_entry(pnp_res, &dev->resources, list) {
314 res = &pnp_res->res;
315 if (res->end < mmconfig->start || res->start > mmconfig->end ||
316 (res->start == mmconfig->start && res->end == mmconfig->end))
317 continue;
318
319 dev_info(&dev->dev, FW_BUG
320 "%pR covers only part of AMD MMCONFIG area %pR; adding more reservations\n",
321 res, mmconfig);
322 if (mmconfig->start < res->start) {
323 start = mmconfig->start;
324 end = res->start - 1;
325 pnp_add_mem_resource(dev, start, end, 0);
326 }
327 if (mmconfig->end > res->end) {
328 start = res->end + 1;
329 end = mmconfig->end;
330 pnp_add_mem_resource(dev, start, end, 0);
331 }
332 break;
333 }
334}
335#endif
336
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337/*
338 * PnP Quirks
339 * Cards or devices that need some tweaking due to incomplete resource info
340 */
341
342static struct pnp_fixup pnp_fixups[] = {
343 /* Soundblaster awe io port quirk */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700344 {"CTL0021", quirk_awe32_resources},
345 {"CTL0022", quirk_awe32_resources},
346 {"CTL0023", quirk_awe32_resources},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 /* CMI 8330 interrupt and dma fix */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700348 {"@X@0001", quirk_cmi8330_resources},
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 /* Soundblaster audio device io port range quirk */
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700350 {"CTL0001", quirk_sb16audio_resources},
351 {"CTL0031", quirk_sb16audio_resources},
352 {"CTL0041", quirk_sb16audio_resources},
353 {"CTL0042", quirk_sb16audio_resources},
354 {"CTL0043", quirk_sb16audio_resources},
355 {"CTL0044", quirk_sb16audio_resources},
356 {"CTL0045", quirk_sb16audio_resources},
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600357 /* Add IRQ-optional MPU options */
Rene Herman3b73a222008-05-14 16:05:36 -0700358 {"ADS7151", quirk_ad1815_mpu_resources},
Bjorn Helgaas1f32ca32008-06-27 16:57:17 -0600359 {"ADS7181", quirk_add_irq_optional_dependent_sets},
360 {"AZT0002", quirk_add_irq_optional_dependent_sets},
Rene Herman3b73a222008-05-14 16:05:36 -0700361 /* PnP resources that might overlap PCI BARs */
Bjorn Helgaas0509ad52008-03-11 15:24:41 -0600362 {"PNP0c01", quirk_system_pci_resources},
363 {"PNP0c02", quirk_system_pci_resources},
Bjorn Helgaaseb31aae2012-01-05 14:27:24 -0700364#ifdef CONFIG_AMD_NB
365 {"PNP0c01", quirk_amd_mmconfig_area},
366#endif
Bjorn Helgaas9dd78462007-07-26 10:41:20 -0700367 {""}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368};
369
370void pnp_fixup_device(struct pnp_dev *dev)
371{
Rene Herman726a7a32008-05-14 16:05:33 -0700372 struct pnp_fixup *f;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373
Rene Herman726a7a32008-05-14 16:05:33 -0700374 for (f = pnp_fixups; *f->id; f++) {
375 if (!compare_pnp_id(dev->id, f->id))
376 continue;
Bjorn Helgaas2f534322008-08-19 16:53:47 -0600377 pnp_dbg(&dev->dev, "%s: calling %pF\n", f->id,
Bjorn Helgaas668b21d2008-08-19 16:53:31 -0600378 f->quirk_function);
Rene Herman726a7a32008-05-14 16:05:33 -0700379 f->quirk_function(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700380 }
381}