xref: /openbmc/linux/drivers/pnp/quirks.c (revision cb171f7a)
11da177e4SLinus Torvalds /*
21da177e4SLinus Torvalds  *  This file contains quirk handling code for PnP devices
31da177e4SLinus Torvalds  *  Some devices do not report all their resources, and need to have extra
41da177e4SLinus Torvalds  *  resources added. This is most easily accomplished at initialisation time
51da177e4SLinus Torvalds  *  when building up the resource structure for the first time.
61da177e4SLinus Torvalds  *
71da177e4SLinus Torvalds  *  Copyright (c) 2000 Peter Denison <peterd@pnd-pc.demon.co.uk>
81f32ca31SBjorn Helgaas  *  Copyright (C) 2008 Hewlett-Packard Development Company, L.P.
91f32ca31SBjorn Helgaas  *	Bjorn Helgaas <bjorn.helgaas@hp.com>
101da177e4SLinus Torvalds  *
111da177e4SLinus Torvalds  *  Heavily based on PCI quirks handling which is
121da177e4SLinus Torvalds  *
131da177e4SLinus Torvalds  *  Copyright (c) 1999 Martin Mares <mj@ucw.cz>
141da177e4SLinus Torvalds  */
151da177e4SLinus Torvalds 
161da177e4SLinus Torvalds #include <linux/types.h>
171da177e4SLinus Torvalds #include <linux/kernel.h>
18cb171f7aSBjorn Helgaas #include <linux/pci.h>
191da177e4SLinus Torvalds #include <linux/string.h>
201da177e4SLinus Torvalds #include <linux/slab.h>
211da177e4SLinus Torvalds #include <linux/pnp.h>
22a1e7e636SBjorn Helgaas #include <linux/io.h>
23a05d0781SBjorn Helgaas #include <linux/kallsyms.h>
241da177e4SLinus Torvalds #include "base.h"
251da177e4SLinus Torvalds 
261f32ca31SBjorn Helgaas static void quirk_awe32_add_ports(struct pnp_dev *dev,
271f32ca31SBjorn Helgaas 				  struct pnp_option *option,
281f32ca31SBjorn Helgaas 				  unsigned int offset)
291da177e4SLinus Torvalds {
301f32ca31SBjorn Helgaas 	struct pnp_option *new_option;
311da177e4SLinus Torvalds 
321f32ca31SBjorn Helgaas 	new_option = kmalloc(sizeof(struct pnp_option), GFP_KERNEL);
331f32ca31SBjorn Helgaas 	if (!new_option) {
341f32ca31SBjorn Helgaas 		dev_err(&dev->dev, "couldn't add ioport region to option set "
351f32ca31SBjorn Helgaas 			"%d\n", pnp_option_set(option));
361da177e4SLinus Torvalds 		return;
371da177e4SLinus Torvalds 	}
381f32ca31SBjorn Helgaas 
391f32ca31SBjorn Helgaas 	*new_option = *option;
401f32ca31SBjorn Helgaas 	new_option->u.port.min += offset;
411f32ca31SBjorn Helgaas 	new_option->u.port.max += offset;
421f32ca31SBjorn Helgaas 	list_add(&new_option->list, &option->list);
431f32ca31SBjorn Helgaas 
441f32ca31SBjorn Helgaas 	dev_info(&dev->dev, "added ioport region %#llx-%#llx to set %d\n",
451f32ca31SBjorn Helgaas 		(unsigned long long) new_option->u.port.min,
461f32ca31SBjorn Helgaas 		(unsigned long long) new_option->u.port.max,
471f32ca31SBjorn Helgaas 		pnp_option_set(option));
481f32ca31SBjorn Helgaas }
491f32ca31SBjorn Helgaas 
501f32ca31SBjorn Helgaas static void quirk_awe32_resources(struct pnp_dev *dev)
511f32ca31SBjorn Helgaas {
521f32ca31SBjorn Helgaas 	struct pnp_option *option;
531f32ca31SBjorn Helgaas 	unsigned int set = ~0;
541f32ca31SBjorn Helgaas 
551f32ca31SBjorn Helgaas 	/*
561f32ca31SBjorn Helgaas 	 * Add two extra ioport regions (at offset 0x400 and 0x800 from the
571f32ca31SBjorn Helgaas 	 * one given) to every dependent option set.
581f32ca31SBjorn Helgaas 	 */
591f32ca31SBjorn Helgaas 	list_for_each_entry(option, &dev->options, list) {
601f32ca31SBjorn Helgaas 		if (pnp_option_is_dependent(option) &&
611f32ca31SBjorn Helgaas 		    pnp_option_set(option) != set) {
621f32ca31SBjorn Helgaas 			set = pnp_option_set(option);
631f32ca31SBjorn Helgaas 			quirk_awe32_add_ports(dev, option, 0x800);
641f32ca31SBjorn Helgaas 			quirk_awe32_add_ports(dev, option, 0x400);
651f32ca31SBjorn Helgaas 		}
661da177e4SLinus Torvalds 	}
671da177e4SLinus Torvalds }
681da177e4SLinus Torvalds 
691da177e4SLinus Torvalds static void quirk_cmi8330_resources(struct pnp_dev *dev)
701da177e4SLinus Torvalds {
711f32ca31SBjorn Helgaas 	struct pnp_option *option;
721da177e4SLinus Torvalds 	struct pnp_irq *irq;
731da177e4SLinus Torvalds 	struct pnp_dma *dma;
741da177e4SLinus Torvalds 
751f32ca31SBjorn Helgaas 	list_for_each_entry(option, &dev->options, list) {
761f32ca31SBjorn Helgaas 		if (!pnp_option_is_dependent(option))
771f32ca31SBjorn Helgaas 			continue;
781da177e4SLinus Torvalds 
791f32ca31SBjorn Helgaas 		if (option->type == IORESOURCE_IRQ) {
801f32ca31SBjorn Helgaas 			irq = &option->u.irq;
811f32ca31SBjorn Helgaas 			bitmap_zero(irq->map.bits, PNP_IRQ_NR);
821f32ca31SBjorn Helgaas 			__set_bit(5, irq->map.bits);
831f32ca31SBjorn Helgaas 			__set_bit(7, irq->map.bits);
841f32ca31SBjorn Helgaas 			__set_bit(10, irq->map.bits);
851f32ca31SBjorn Helgaas 			dev_info(&dev->dev, "set possible IRQs in "
861f32ca31SBjorn Helgaas 				 "option set %d to 5, 7, 10\n",
871f32ca31SBjorn Helgaas 				 pnp_option_set(option));
881f32ca31SBjorn Helgaas 		} else if (option->type == IORESOURCE_DMA) {
891f32ca31SBjorn Helgaas 			dma = &option->u.dma;
909dd78466SBjorn Helgaas 			if ((dma->flags & IORESOURCE_DMA_TYPE_MASK) ==
911f32ca31SBjorn Helgaas 						IORESOURCE_DMA_8BIT &&
921f32ca31SBjorn Helgaas 			    dma->map != 0x0A) {
931f32ca31SBjorn Helgaas 				dev_info(&dev->dev, "changing possible "
941f32ca31SBjorn Helgaas 					 "DMA channel mask in option set %d "
951f32ca31SBjorn Helgaas 					 "from %#02x to 0x0A (1, 3)\n",
961f32ca31SBjorn Helgaas 					 pnp_option_set(option), dma->map);
971f32ca31SBjorn Helgaas 				dma->map = 0x0A;
981da177e4SLinus Torvalds 			}
997aefff51SBjorn Helgaas 		}
1001f32ca31SBjorn Helgaas 	}
1011da177e4SLinus Torvalds }
1021da177e4SLinus Torvalds 
1031da177e4SLinus Torvalds static void quirk_sb16audio_resources(struct pnp_dev *dev)
1041da177e4SLinus Torvalds {
1051f32ca31SBjorn Helgaas 	struct pnp_option *option;
1061f32ca31SBjorn Helgaas 	unsigned int prev_option_flags = ~0, n = 0;
1071da177e4SLinus Torvalds 	struct pnp_port *port;
1081da177e4SLinus Torvalds 
1091da177e4SLinus Torvalds 	/*
1101f32ca31SBjorn Helgaas 	 * The default range on the OPL port for these devices is 0x388-0x388.
1111da177e4SLinus Torvalds 	 * Here we increase that range so that two such cards can be
1121da177e4SLinus Torvalds 	 * auto-configured.
1131da177e4SLinus Torvalds 	 */
1141f32ca31SBjorn Helgaas 	list_for_each_entry(option, &dev->options, list) {
1151f32ca31SBjorn Helgaas 		if (prev_option_flags != option->flags) {
1161f32ca31SBjorn Helgaas 			prev_option_flags = option->flags;
1171f32ca31SBjorn Helgaas 			n = 0;
1181f32ca31SBjorn Helgaas 		}
1191da177e4SLinus Torvalds 
1201f32ca31SBjorn Helgaas 		if (pnp_option_is_dependent(option) &&
1211f32ca31SBjorn Helgaas 		    option->type == IORESOURCE_IO) {
1221f32ca31SBjorn Helgaas 			n++;
1231f32ca31SBjorn Helgaas 			port = &option->u.port;
1241f32ca31SBjorn Helgaas 			if (n == 3 && port->min == port->max) {
1251da177e4SLinus Torvalds 				port->max += 0x70;
1261f32ca31SBjorn Helgaas 				dev_info(&dev->dev, "increased option port "
1271f32ca31SBjorn Helgaas 					 "range from %#llx-%#llx to "
1281f32ca31SBjorn Helgaas 					 "%#llx-%#llx\n",
1291f32ca31SBjorn Helgaas 					 (unsigned long long) port->min,
1301f32ca31SBjorn Helgaas 					 (unsigned long long) port->min,
1311f32ca31SBjorn Helgaas 					 (unsigned long long) port->min,
1321f32ca31SBjorn Helgaas 					 (unsigned long long) port->max);
1331da177e4SLinus Torvalds 			}
1341f32ca31SBjorn Helgaas 		}
1351f32ca31SBjorn Helgaas 	}
1361da177e4SLinus Torvalds }
1371da177e4SLinus Torvalds 
1381f32ca31SBjorn Helgaas static struct pnp_option *pnp_clone_dependent_set(struct pnp_dev *dev,
1391f32ca31SBjorn Helgaas 						  unsigned int set)
1403b73a223SRene Herman {
1411f32ca31SBjorn Helgaas 	struct pnp_option *tail = NULL, *first_new_option = NULL;
1421f32ca31SBjorn Helgaas 	struct pnp_option *option, *new_option;
1431f32ca31SBjorn Helgaas 	unsigned int flags;
1443b73a223SRene Herman 
1451f32ca31SBjorn Helgaas 	list_for_each_entry(option, &dev->options, list) {
1461f32ca31SBjorn Helgaas 		if (pnp_option_is_dependent(option))
1471f32ca31SBjorn Helgaas 			tail = option;
1481f32ca31SBjorn Helgaas 	}
1491f32ca31SBjorn Helgaas 	if (!tail) {
1501f32ca31SBjorn Helgaas 		dev_err(&dev->dev, "no dependent option sets\n");
1511f32ca31SBjorn Helgaas 		return NULL;
1521f32ca31SBjorn Helgaas 	}
1533b73a223SRene Herman 
1541f32ca31SBjorn Helgaas 	flags = pnp_new_dependent_set(dev, PNP_RES_PRIORITY_FUNCTIONAL);
1551f32ca31SBjorn Helgaas 	list_for_each_entry(option, &dev->options, list) {
1561f32ca31SBjorn Helgaas 		if (pnp_option_is_dependent(option) &&
1571f32ca31SBjorn Helgaas 		    pnp_option_set(option) == set) {
1581f32ca31SBjorn Helgaas 			new_option = kmalloc(sizeof(struct pnp_option),
1591f32ca31SBjorn Helgaas 					     GFP_KERNEL);
1601f32ca31SBjorn Helgaas 			if (!new_option) {
1611f32ca31SBjorn Helgaas 				dev_err(&dev->dev, "couldn't clone dependent "
1621f32ca31SBjorn Helgaas 					"set %d\n", set);
1631f32ca31SBjorn Helgaas 				return NULL;
1641f32ca31SBjorn Helgaas 			}
1651f32ca31SBjorn Helgaas 
1661f32ca31SBjorn Helgaas 			*new_option = *option;
1671f32ca31SBjorn Helgaas 			new_option->flags = flags;
1681f32ca31SBjorn Helgaas 			if (!first_new_option)
1691f32ca31SBjorn Helgaas 				first_new_option = new_option;
1701f32ca31SBjorn Helgaas 
1711f32ca31SBjorn Helgaas 			list_add(&new_option->list, &tail->list);
1721f32ca31SBjorn Helgaas 			tail = new_option;
1731f32ca31SBjorn Helgaas 		}
1741f32ca31SBjorn Helgaas 	}
1751f32ca31SBjorn Helgaas 
1761f32ca31SBjorn Helgaas 	return first_new_option;
1771f32ca31SBjorn Helgaas }
1781f32ca31SBjorn Helgaas 
1791f32ca31SBjorn Helgaas 
1801f32ca31SBjorn Helgaas static void quirk_add_irq_optional_dependent_sets(struct pnp_dev *dev)
1811f32ca31SBjorn Helgaas {
1821f32ca31SBjorn Helgaas 	struct pnp_option *new_option;
1831f32ca31SBjorn Helgaas 	unsigned int num_sets, i, set;
184d5ebde6eSBjorn Helgaas 	struct pnp_irq *irq;
1853b73a223SRene Herman 
1861f32ca31SBjorn Helgaas 	num_sets = dev->num_dependent_sets;
1871f32ca31SBjorn Helgaas 	for (i = 0; i < num_sets; i++) {
1881f32ca31SBjorn Helgaas 		new_option = pnp_clone_dependent_set(dev, i);
1891f32ca31SBjorn Helgaas 		if (!new_option)
1901f32ca31SBjorn Helgaas 			return;
1913b73a223SRene Herman 
1921f32ca31SBjorn Helgaas 		set = pnp_option_set(new_option);
1931f32ca31SBjorn Helgaas 		while (new_option && pnp_option_set(new_option) == set) {
1941f32ca31SBjorn Helgaas 			if (new_option->type == IORESOURCE_IRQ) {
1951f32ca31SBjorn Helgaas 				irq = &new_option->u.irq;
1961f32ca31SBjorn Helgaas 				irq->flags |= IORESOURCE_IRQ_OPTIONAL;
1971f32ca31SBjorn Helgaas 			}
1981f32ca31SBjorn Helgaas 			dbg_pnp_show_option(dev, new_option);
1991f32ca31SBjorn Helgaas 			new_option = list_entry(new_option->list.next,
2001f32ca31SBjorn Helgaas 						struct pnp_option, list);
201d5ebde6eSBjorn Helgaas 		}
202d5ebde6eSBjorn Helgaas 
2031f32ca31SBjorn Helgaas 		dev_info(&dev->dev, "added dependent option set %d (same as "
2041f32ca31SBjorn Helgaas 			 "set %d except IRQ optional)\n", set, i);
2053b73a223SRene Herman 	}
2063b73a223SRene Herman }
2073b73a223SRene Herman 
2083b73a223SRene Herman static void quirk_ad1815_mpu_resources(struct pnp_dev *dev)
2093b73a223SRene Herman {
2101f32ca31SBjorn Helgaas 	struct pnp_option *option;
2111f32ca31SBjorn Helgaas 	struct pnp_irq *irq = NULL;
2121f32ca31SBjorn Helgaas 	unsigned int independent_irqs = 0;
2133b73a223SRene Herman 
2141f32ca31SBjorn Helgaas 	list_for_each_entry(option, &dev->options, list) {
2151f32ca31SBjorn Helgaas 		if (option->type == IORESOURCE_IRQ &&
2161f32ca31SBjorn Helgaas 		    !pnp_option_is_dependent(option)) {
2171f32ca31SBjorn Helgaas 			independent_irqs++;
2181f32ca31SBjorn Helgaas 			irq = &option->u.irq;
2191f32ca31SBjorn Helgaas 		}
2201f32ca31SBjorn Helgaas 	}
2213b73a223SRene Herman 
2221f32ca31SBjorn Helgaas 	if (independent_irqs != 1)
2233b73a223SRene Herman 		return;
2243b73a223SRene Herman 
225d5ebde6eSBjorn Helgaas 	irq->flags |= IORESOURCE_IRQ_OPTIONAL;
226d5ebde6eSBjorn Helgaas 	dev_info(&dev->dev, "made independent IRQ optional\n");
2273b73a223SRene Herman }
2283b73a223SRene Herman 
2290509ad5eSBjorn Helgaas #include <linux/pci.h>
2300509ad5eSBjorn Helgaas 
2310509ad5eSBjorn Helgaas static void quirk_system_pci_resources(struct pnp_dev *dev)
2320509ad5eSBjorn Helgaas {
2330509ad5eSBjorn Helgaas 	struct pci_dev *pdev = NULL;
23453052febSBjorn Helgaas 	struct resource *res;
2350509ad5eSBjorn Helgaas 	resource_size_t pnp_start, pnp_end, pci_start, pci_end;
2360509ad5eSBjorn Helgaas 	int i, j;
2370509ad5eSBjorn Helgaas 
2380509ad5eSBjorn Helgaas 	/*
2390509ad5eSBjorn Helgaas 	 * Some BIOSes have PNP motherboard devices with resources that
2400509ad5eSBjorn Helgaas 	 * partially overlap PCI BARs.  The PNP system driver claims these
2410509ad5eSBjorn Helgaas 	 * motherboard resources, which prevents the normal PCI driver from
2420509ad5eSBjorn Helgaas 	 * requesting them later.
2430509ad5eSBjorn Helgaas 	 *
2440509ad5eSBjorn Helgaas 	 * This patch disables the PNP resources that conflict with PCI BARs
2450509ad5eSBjorn Helgaas 	 * so they won't be claimed by the PNP system driver.
2460509ad5eSBjorn Helgaas 	 */
2470509ad5eSBjorn Helgaas 	for_each_pci_dev(pdev) {
2480509ad5eSBjorn Helgaas 		for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
249b563cf59SRene Herman 			unsigned long type;
250999ed65aSRene Herman 
251999ed65aSRene Herman 			type = pci_resource_flags(pdev, i) &
252999ed65aSRene Herman 					(IORESOURCE_IO | IORESOURCE_MEM);
253999ed65aSRene Herman 			if (!type || pci_resource_len(pdev, i) == 0)
2540509ad5eSBjorn Helgaas 				continue;
2550509ad5eSBjorn Helgaas 
2560509ad5eSBjorn Helgaas 			pci_start = pci_resource_start(pdev, i);
2570509ad5eSBjorn Helgaas 			pci_end = pci_resource_end(pdev, i);
25895ab3669SBjorn Helgaas 			for (j = 0;
259999ed65aSRene Herman 			     (res = pnp_get_resource(dev, type, j)); j++) {
260aee3ad81SBjorn Helgaas 				if (res->start == 0 && res->end == 0)
2610509ad5eSBjorn Helgaas 					continue;
2620509ad5eSBjorn Helgaas 
26395ab3669SBjorn Helgaas 				pnp_start = res->start;
26495ab3669SBjorn Helgaas 				pnp_end = res->end;
2650509ad5eSBjorn Helgaas 
2660509ad5eSBjorn Helgaas 				/*
2670509ad5eSBjorn Helgaas 				 * If the PNP region doesn't overlap the PCI
2680509ad5eSBjorn Helgaas 				 * region at all, there's no problem.
2690509ad5eSBjorn Helgaas 				 */
2700509ad5eSBjorn Helgaas 				if (pnp_end < pci_start || pnp_start > pci_end)
2710509ad5eSBjorn Helgaas 					continue;
2720509ad5eSBjorn Helgaas 
2730509ad5eSBjorn Helgaas 				/*
2740509ad5eSBjorn Helgaas 				 * If the PNP region completely encloses (or is
2750509ad5eSBjorn Helgaas 				 * at least as large as) the PCI region, that's
2760509ad5eSBjorn Helgaas 				 * also OK.  For example, this happens when the
2770509ad5eSBjorn Helgaas 				 * PNP device describes a bridge with PCI
2780509ad5eSBjorn Helgaas 				 * behind it.
2790509ad5eSBjorn Helgaas 				 */
2800509ad5eSBjorn Helgaas 				if (pnp_start <= pci_start &&
2810509ad5eSBjorn Helgaas 				    pnp_end >= pci_end)
2820509ad5eSBjorn Helgaas 					continue;
2830509ad5eSBjorn Helgaas 
2840509ad5eSBjorn Helgaas 				/*
2850509ad5eSBjorn Helgaas 				 * Otherwise, the PNP region overlaps *part* of
2860509ad5eSBjorn Helgaas 				 * the PCI region, and that might prevent a PCI
2870509ad5eSBjorn Helgaas 				 * driver from requesting its resources.
2880509ad5eSBjorn Helgaas 				 */
289c7dabef8SBjorn Helgaas 				dev_warn(&dev->dev,
290c7dabef8SBjorn Helgaas 					 "disabling %pR because it overlaps "
291c7dabef8SBjorn Helgaas 					 "%s BAR %d %pR\n", res,
2929a007b37SBjorn Helgaas 					 pci_name(pdev), i, &pdev->resource[i]);
2934b34fe15SBjorn Helgaas 				res->flags |= IORESOURCE_DISABLED;
2940509ad5eSBjorn Helgaas 			}
2950509ad5eSBjorn Helgaas 		}
2960509ad5eSBjorn Helgaas 	}
2970509ad5eSBjorn Helgaas }
2980509ad5eSBjorn Helgaas 
299eb31aae8SBjorn Helgaas #ifdef CONFIG_AMD_NB
300eb31aae8SBjorn Helgaas 
301eb31aae8SBjorn Helgaas #include <asm/amd_nb.h>
302eb31aae8SBjorn Helgaas 
303eb31aae8SBjorn Helgaas static void quirk_amd_mmconfig_area(struct pnp_dev *dev)
304eb31aae8SBjorn Helgaas {
305eb31aae8SBjorn Helgaas 	resource_size_t start, end;
306eb31aae8SBjorn Helgaas 	struct pnp_resource *pnp_res;
307eb31aae8SBjorn Helgaas 	struct resource *res;
308eb31aae8SBjorn Helgaas 	struct resource mmconfig_res, *mmconfig;
309eb31aae8SBjorn Helgaas 
310eb31aae8SBjorn Helgaas 	mmconfig = amd_get_mmconfig_range(&mmconfig_res);
311eb31aae8SBjorn Helgaas 	if (!mmconfig)
312eb31aae8SBjorn Helgaas 		return;
313eb31aae8SBjorn Helgaas 
314eb31aae8SBjorn Helgaas 	list_for_each_entry(pnp_res, &dev->resources, list) {
315eb31aae8SBjorn Helgaas 		res = &pnp_res->res;
316eb31aae8SBjorn Helgaas 		if (res->end < mmconfig->start || res->start > mmconfig->end ||
317eb31aae8SBjorn Helgaas 		    (res->start == mmconfig->start && res->end == mmconfig->end))
318eb31aae8SBjorn Helgaas 			continue;
319eb31aae8SBjorn Helgaas 
320eb31aae8SBjorn Helgaas 		dev_info(&dev->dev, FW_BUG
321eb31aae8SBjorn Helgaas 			 "%pR covers only part of AMD MMCONFIG area %pR; adding more reservations\n",
322eb31aae8SBjorn Helgaas 			 res, mmconfig);
323eb31aae8SBjorn Helgaas 		if (mmconfig->start < res->start) {
324eb31aae8SBjorn Helgaas 			start = mmconfig->start;
325eb31aae8SBjorn Helgaas 			end = res->start - 1;
326eb31aae8SBjorn Helgaas 			pnp_add_mem_resource(dev, start, end, 0);
327eb31aae8SBjorn Helgaas 		}
328eb31aae8SBjorn Helgaas 		if (mmconfig->end > res->end) {
329eb31aae8SBjorn Helgaas 			start = res->end + 1;
330eb31aae8SBjorn Helgaas 			end = mmconfig->end;
331eb31aae8SBjorn Helgaas 			pnp_add_mem_resource(dev, start, end, 0);
332eb31aae8SBjorn Helgaas 		}
333eb31aae8SBjorn Helgaas 		break;
334eb31aae8SBjorn Helgaas 	}
335eb31aae8SBjorn Helgaas }
336eb31aae8SBjorn Helgaas #endif
337eb31aae8SBjorn Helgaas 
338cb171f7aSBjorn Helgaas #ifdef CONFIG_X86
339cb171f7aSBjorn Helgaas /* Device IDs of parts that have 32KB MCH space */
340cb171f7aSBjorn Helgaas static const unsigned int mch_quirk_devices[] = {
341cb171f7aSBjorn Helgaas 	0x0154,	/* Ivy Bridge */
342cb171f7aSBjorn Helgaas 	0x0c00,	/* Haswell */
343cb171f7aSBjorn Helgaas };
344cb171f7aSBjorn Helgaas 
345cb171f7aSBjorn Helgaas static struct pci_dev *get_intel_host(void)
346cb171f7aSBjorn Helgaas {
347cb171f7aSBjorn Helgaas 	int i;
348cb171f7aSBjorn Helgaas 	struct pci_dev *host;
349cb171f7aSBjorn Helgaas 
350cb171f7aSBjorn Helgaas 	for (i = 0; i < ARRAY_SIZE(mch_quirk_devices); i++) {
351cb171f7aSBjorn Helgaas 		host = pci_get_device(PCI_VENDOR_ID_INTEL, mch_quirk_devices[i],
352cb171f7aSBjorn Helgaas 				      NULL);
353cb171f7aSBjorn Helgaas 		if (host)
354cb171f7aSBjorn Helgaas 			return host;
355cb171f7aSBjorn Helgaas 	}
356cb171f7aSBjorn Helgaas 	return NULL;
357cb171f7aSBjorn Helgaas }
358cb171f7aSBjorn Helgaas 
359cb171f7aSBjorn Helgaas static void quirk_intel_mch(struct pnp_dev *dev)
360cb171f7aSBjorn Helgaas {
361cb171f7aSBjorn Helgaas 	struct pci_dev *host;
362cb171f7aSBjorn Helgaas 	u32 addr_lo, addr_hi;
363cb171f7aSBjorn Helgaas 	struct pci_bus_region region;
364cb171f7aSBjorn Helgaas 	struct resource mch;
365cb171f7aSBjorn Helgaas 	struct pnp_resource *pnp_res;
366cb171f7aSBjorn Helgaas 	struct resource *res;
367cb171f7aSBjorn Helgaas 
368cb171f7aSBjorn Helgaas 	host = get_intel_host();
369cb171f7aSBjorn Helgaas 	if (!host)
370cb171f7aSBjorn Helgaas 		return;
371cb171f7aSBjorn Helgaas 
372cb171f7aSBjorn Helgaas 	/*
373cb171f7aSBjorn Helgaas 	 * MCHBAR is not an architected PCI BAR, so MCH space is usually
374cb171f7aSBjorn Helgaas 	 * reported as a PNP0C02 resource.  The MCH space was originally
375cb171f7aSBjorn Helgaas 	 * 16KB, but is 32KB in newer parts.  Some BIOSes still report a
376cb171f7aSBjorn Helgaas 	 * PNP0C02 resource that is only 16KB, which means the rest of the
377cb171f7aSBjorn Helgaas 	 * MCH space is consumed but unreported.
378cb171f7aSBjorn Helgaas 	 */
379cb171f7aSBjorn Helgaas 
380cb171f7aSBjorn Helgaas 	/*
381cb171f7aSBjorn Helgaas 	 * Read MCHBAR for Host Member Mapped Register Range Base
382cb171f7aSBjorn Helgaas 	 * https://www-ssl.intel.com/content/www/us/en/processors/core/4th-gen-core-family-desktop-vol-2-datasheet
383cb171f7aSBjorn Helgaas 	 * Sec 3.1.12.
384cb171f7aSBjorn Helgaas 	 */
385cb171f7aSBjorn Helgaas 	pci_read_config_dword(host, 0x48, &addr_lo);
386cb171f7aSBjorn Helgaas 	region.start = addr_lo & ~0x7fff;
387cb171f7aSBjorn Helgaas 	pci_read_config_dword(host, 0x4c, &addr_hi);
388cb171f7aSBjorn Helgaas 	region.start |= (u64) addr_hi << 32;
389cb171f7aSBjorn Helgaas 	region.end = region.start + 32*1024 - 1;
390cb171f7aSBjorn Helgaas 
391cb171f7aSBjorn Helgaas 	memset(&mch, 0, sizeof(mch));
392cb171f7aSBjorn Helgaas 	mch.flags = IORESOURCE_MEM;
393cb171f7aSBjorn Helgaas 	pcibios_bus_to_resource(host->bus, &mch, &region);
394cb171f7aSBjorn Helgaas 
395cb171f7aSBjorn Helgaas 	list_for_each_entry(pnp_res, &dev->resources, list) {
396cb171f7aSBjorn Helgaas 		res = &pnp_res->res;
397cb171f7aSBjorn Helgaas 		if (res->end < mch.start || res->start > mch.end)
398cb171f7aSBjorn Helgaas 			continue;	/* no overlap */
399cb171f7aSBjorn Helgaas 		if (res->start == mch.start && res->end == mch.end)
400cb171f7aSBjorn Helgaas 			continue;	/* exact match */
401cb171f7aSBjorn Helgaas 
402cb171f7aSBjorn Helgaas 		dev_info(&dev->dev, FW_BUG "PNP resource %pR covers only part of %s Intel MCH; extending to %pR\n",
403cb171f7aSBjorn Helgaas 			 res, pci_name(host), &mch);
404cb171f7aSBjorn Helgaas 		res->start = mch.start;
405cb171f7aSBjorn Helgaas 		res->end = mch.end;
406cb171f7aSBjorn Helgaas 		break;
407cb171f7aSBjorn Helgaas 	}
408cb171f7aSBjorn Helgaas 
409cb171f7aSBjorn Helgaas 	pci_dev_put(host);
410cb171f7aSBjorn Helgaas }
411cb171f7aSBjorn Helgaas #endif
412cb171f7aSBjorn Helgaas 
4131da177e4SLinus Torvalds /*
4141da177e4SLinus Torvalds  *  PnP Quirks
4151da177e4SLinus Torvalds  *  Cards or devices that need some tweaking due to incomplete resource info
4161da177e4SLinus Torvalds  */
4171da177e4SLinus Torvalds 
4181da177e4SLinus Torvalds static struct pnp_fixup pnp_fixups[] = {
4191da177e4SLinus Torvalds 	/* Soundblaster awe io port quirk */
4201da177e4SLinus Torvalds 	{"CTL0021", quirk_awe32_resources},
4211da177e4SLinus Torvalds 	{"CTL0022", quirk_awe32_resources},
4221da177e4SLinus Torvalds 	{"CTL0023", quirk_awe32_resources},
4231da177e4SLinus Torvalds 	/* CMI 8330 interrupt and dma fix */
4241da177e4SLinus Torvalds 	{"@X@0001", quirk_cmi8330_resources},
4251da177e4SLinus Torvalds 	/* Soundblaster audio device io port range quirk */
4261da177e4SLinus Torvalds 	{"CTL0001", quirk_sb16audio_resources},
4271da177e4SLinus Torvalds 	{"CTL0031", quirk_sb16audio_resources},
4281da177e4SLinus Torvalds 	{"CTL0041", quirk_sb16audio_resources},
4291da177e4SLinus Torvalds 	{"CTL0042", quirk_sb16audio_resources},
4301da177e4SLinus Torvalds 	{"CTL0043", quirk_sb16audio_resources},
4311da177e4SLinus Torvalds 	{"CTL0044", quirk_sb16audio_resources},
4321da177e4SLinus Torvalds 	{"CTL0045", quirk_sb16audio_resources},
4331f32ca31SBjorn Helgaas 	/* Add IRQ-optional MPU options */
4343b73a223SRene Herman 	{"ADS7151", quirk_ad1815_mpu_resources},
4351f32ca31SBjorn Helgaas 	{"ADS7181", quirk_add_irq_optional_dependent_sets},
4361f32ca31SBjorn Helgaas 	{"AZT0002", quirk_add_irq_optional_dependent_sets},
4373b73a223SRene Herman 	/* PnP resources that might overlap PCI BARs */
4380509ad5eSBjorn Helgaas 	{"PNP0c01", quirk_system_pci_resources},
4390509ad5eSBjorn Helgaas 	{"PNP0c02", quirk_system_pci_resources},
440eb31aae8SBjorn Helgaas #ifdef CONFIG_AMD_NB
441eb31aae8SBjorn Helgaas 	{"PNP0c01", quirk_amd_mmconfig_area},
442eb31aae8SBjorn Helgaas #endif
443cb171f7aSBjorn Helgaas #ifdef CONFIG_X86
444cb171f7aSBjorn Helgaas 	{"PNP0c02", quirk_intel_mch},
445cb171f7aSBjorn Helgaas #endif
4461da177e4SLinus Torvalds 	{""}
4471da177e4SLinus Torvalds };
4481da177e4SLinus Torvalds 
4491da177e4SLinus Torvalds void pnp_fixup_device(struct pnp_dev *dev)
4501da177e4SLinus Torvalds {
451726a7a3dSRene Herman 	struct pnp_fixup *f;
4521da177e4SLinus Torvalds 
453726a7a3dSRene Herman 	for (f = pnp_fixups; *f->id; f++) {
454726a7a3dSRene Herman 		if (!compare_pnp_id(dev->id, f->id))
455726a7a3dSRene Herman 			continue;
4562f53432cSBjorn Helgaas 		pnp_dbg(&dev->dev, "%s: calling %pF\n", f->id,
457668b21deSBjorn Helgaas 			f->quirk_function);
458726a7a3dSRene Herman 		f->quirk_function(dev);
4591da177e4SLinus Torvalds 	}
4601da177e4SLinus Torvalds }
461