| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  *  pci_link.c - ACPI PCI Interrupt Link Device Driver ($Revision: 34 $) | 
 | 3 |  * | 
 | 4 |  *  Copyright (C) 2001, 2002 Andy Grover <andrew.grover@intel.com> | 
 | 5 |  *  Copyright (C) 2001, 2002 Paul Diefenbaugh <paul.s.diefenbaugh@intel.com> | 
 | 6 |  *  Copyright (C) 2002       Dominik Brodowski <devel@brodo.de> | 
 | 7 |  * | 
 | 8 |  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
 | 9 |  * | 
 | 10 |  *  This program is free software; you can redistribute it and/or modify | 
 | 11 |  *  it under the terms of the GNU General Public License as published by | 
 | 12 |  *  the Free Software Foundation; either version 2 of the License, or (at | 
 | 13 |  *  your option) any later version. | 
 | 14 |  * | 
 | 15 |  *  This program is distributed in the hope that it will be useful, but | 
 | 16 |  *  WITHOUT ANY WARRANTY; without even the implied warranty of | 
 | 17 |  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU | 
 | 18 |  *  General Public License for more details. | 
 | 19 |  * | 
 | 20 |  *  You should have received a copy of the GNU General Public License along | 
 | 21 |  *  with this program; if not, write to the Free Software Foundation, Inc., | 
 | 22 |  *  59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | 
 | 23 |  * | 
 | 24 |  * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ | 
 | 25 |  * | 
 | 26 |  * TBD:  | 
 | 27 |  *      1. Support more than one IRQ resource entry per link device (index). | 
 | 28 |  *	2. Implement start/stop mechanism and use ACPI Bus Driver facilities | 
 | 29 |  *	   for IRQ management (e.g. start()->_SRS). | 
 | 30 |  */ | 
 | 31 |  | 
 | 32 | #include <linux/sysdev.h> | 
 | 33 | #include <linux/kernel.h> | 
 | 34 | #include <linux/module.h> | 
 | 35 | #include <linux/init.h> | 
 | 36 | #include <linux/types.h> | 
 | 37 | #include <linux/proc_fs.h> | 
 | 38 | #include <linux/spinlock.h> | 
 | 39 | #include <linux/pm.h> | 
 | 40 | #include <linux/pci.h> | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 41 | #include <linux/mutex.h> | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 |  | 
 | 43 | #include <acpi/acpi_bus.h> | 
 | 44 | #include <acpi/acpi_drivers.h> | 
 | 45 |  | 
| Len Brown | a192a95 | 2009-07-28 16:45:54 -0400 | [diff] [blame] | 46 | #define PREFIX "ACPI: " | 
 | 47 |  | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 48 | #define _COMPONENT			ACPI_PCI_COMPONENT | 
| Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 49 | ACPI_MODULE_NAME("pci_link"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 50 | #define ACPI_PCI_LINK_CLASS		"pci_irq_routing" | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | #define ACPI_PCI_LINK_DEVICE_NAME	"PCI Interrupt Link" | 
 | 52 | #define ACPI_PCI_LINK_FILE_INFO		"info" | 
 | 53 | #define ACPI_PCI_LINK_FILE_STATUS	"state" | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 54 | #define ACPI_PCI_LINK_MAX_POSSIBLE	16 | 
 | 55 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | static int acpi_pci_link_add(struct acpi_device *device); | 
 | 57 | static int acpi_pci_link_remove(struct acpi_device *device, int type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 |  | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 59 | static struct acpi_device_id link_device_ids[] = { | 
 | 60 | 	{"PNP0C0F", 0}, | 
 | 61 | 	{"", 0}, | 
 | 62 | }; | 
 | 63 | MODULE_DEVICE_TABLE(acpi, link_device_ids); | 
 | 64 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | static struct acpi_driver acpi_pci_link_driver = { | 
| Len Brown | c2b6705 | 2007-02-12 23:33:40 -0500 | [diff] [blame] | 66 | 	.name = "pci_link", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 67 | 	.class = ACPI_PCI_LINK_CLASS, | 
| Thomas Renninger | 1ba90e3 | 2007-07-23 14:44:41 +0200 | [diff] [blame] | 68 | 	.ids = link_device_ids, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | 	.ops = { | 
 | 70 | 		.add = acpi_pci_link_add, | 
 | 71 | 		.remove = acpi_pci_link_remove, | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 72 | 	}, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | }; | 
 | 74 |  | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 75 | /* | 
 | 76 |  * If a link is initialized, we never change its active and initialized | 
 | 77 |  * later even the link is disable. Instead, we just repick the active irq | 
 | 78 |  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | struct acpi_pci_link_irq { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | 	u8 active;		/* Current IRQ */ | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 81 | 	u8 triggering;		/* All IRQs */ | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 82 | 	u8 polarity;		/* All IRQs */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 83 | 	u8 resource_type; | 
 | 84 | 	u8 possible_count; | 
 | 85 | 	u8 possible[ACPI_PCI_LINK_MAX_POSSIBLE]; | 
 | 86 | 	u8 initialized:1; | 
 | 87 | 	u8 reserved:7; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | }; | 
 | 89 |  | 
 | 90 | struct acpi_pci_link { | 
| Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 91 | 	struct list_head		list; | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 92 | 	struct acpi_device		*device; | 
 | 93 | 	struct acpi_pci_link_irq	irq; | 
 | 94 | 	int				refcnt; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | }; | 
 | 96 |  | 
| Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 97 | static LIST_HEAD(acpi_link_list); | 
| Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 98 | static DEFINE_MUTEX(acpi_link_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | /* -------------------------------------------------------------------------- | 
 | 101 |                             PCI Link Device Management | 
 | 102 |    -------------------------------------------------------------------------- */ | 
 | 103 |  | 
 | 104 | /* | 
 | 105 |  * set context (link) possible list from resource list | 
 | 106 |  */ | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 107 | static acpi_status acpi_pci_link_check_possible(struct acpi_resource *resource, | 
 | 108 | 						void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | { | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 110 | 	struct acpi_pci_link *link = context; | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 111 | 	u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 |  | 
| Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 113 | 	switch (resource->type) { | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 114 | 	case ACPI_RESOURCE_TYPE_START_DEPENDENT: | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 115 | 	case ACPI_RESOURCE_TYPE_END_TAG: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 116 | 		return AE_OK; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 117 | 	case ACPI_RESOURCE_TYPE_IRQ: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | 		{ | 
 | 119 | 			struct acpi_resource_irq *p = &resource->data.irq; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 120 | 			if (!p || !p->interrupt_count) { | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 121 | 				ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 122 | 						  "Blank _PRS IRQ resource\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 123 | 				return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | 			} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 125 | 			for (i = 0; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 126 | 			     (i < p->interrupt_count | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 127 | 			      && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { | 
 | 128 | 				if (!p->interrupts[i]) { | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 129 | 					printk(KERN_WARNING PREFIX | 
 | 130 | 					       "Invalid _PRS IRQ %d\n", | 
 | 131 | 					       p->interrupts[i]); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | 					continue; | 
 | 133 | 				} | 
 | 134 | 				link->irq.possible[i] = p->interrupts[i]; | 
 | 135 | 				link->irq.possible_count++; | 
 | 136 | 			} | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 137 | 			link->irq.triggering = p->triggering; | 
 | 138 | 			link->irq.polarity = p->polarity; | 
 | 139 | 			link->irq.resource_type = ACPI_RESOURCE_TYPE_IRQ; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | 		} | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 142 | 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | 		{ | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 144 | 			struct acpi_resource_extended_irq *p = | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | 			    &resource->data.extended_irq; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 146 | 			if (!p || !p->interrupt_count) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 147 | 				printk(KERN_WARNING PREFIX | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 148 | 					      "Blank _PRS EXT IRQ resource\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 149 | 				return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | 			} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | 			for (i = 0; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 152 | 			     (i < p->interrupt_count | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 153 | 			      && i < ACPI_PCI_LINK_MAX_POSSIBLE); i++) { | 
 | 154 | 				if (!p->interrupts[i]) { | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 155 | 					printk(KERN_WARNING PREFIX | 
 | 156 | 					       "Invalid _PRS IRQ %d\n", | 
 | 157 | 					       p->interrupts[i]); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | 					continue; | 
 | 159 | 				} | 
 | 160 | 				link->irq.possible[i] = p->interrupts[i]; | 
 | 161 | 				link->irq.possible_count++; | 
 | 162 | 			} | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 163 | 			link->irq.triggering = p->triggering; | 
 | 164 | 			link->irq.polarity = p->polarity; | 
 | 165 | 			link->irq.resource_type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 166 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | 		} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | 	default: | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 169 | 		printk(KERN_ERR PREFIX "_PRS resource type 0x%x isn't an IRQ\n", | 
 | 170 | 		       resource->type); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 171 | 		return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | 	} | 
 | 173 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 174 | 	return AE_CTRL_TERMINATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | } | 
 | 176 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 177 | static int acpi_pci_link_get_possible(struct acpi_pci_link *link) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 |  | 
| Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 181 | 	status = acpi_walk_resources(link->device->handle, METHOD_NAME__PRS, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 182 | 				     acpi_pci_link_check_possible, link); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | 	if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 184 | 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating _PRS")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 185 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | 	} | 
 | 187 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 188 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 189 | 			  "Found %d possible IRQs\n", | 
 | 190 | 			  link->irq.possible_count)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 192 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | } | 
 | 194 |  | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 195 | static acpi_status acpi_pci_link_check_current(struct acpi_resource *resource, | 
 | 196 | 					       void *context) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 198 | 	int *irq = context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 |  | 
| Len Brown | eca008c | 2005-09-22 00:25:18 -0400 | [diff] [blame] | 200 | 	switch (resource->type) { | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 201 | 	case ACPI_RESOURCE_TYPE_START_DEPENDENT: | 
 | 202 | 	case ACPI_RESOURCE_TYPE_END_TAG: | 
 | 203 | 		return AE_OK; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 204 | 	case ACPI_RESOURCE_TYPE_IRQ: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 205 | 		{ | 
 | 206 | 			struct acpi_resource_irq *p = &resource->data.irq; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 207 | 			if (!p || !p->interrupt_count) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 208 | 				/* | 
 | 209 | 				 * IRQ descriptors may have no IRQ# bits set, | 
 | 210 | 				 * particularly those those w/ _STA disabled | 
 | 211 | 				 */ | 
 | 212 | 				ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 213 | 						  "Blank _CRS IRQ resource\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 214 | 				return AE_OK; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | 			} | 
 | 216 | 			*irq = p->interrupts[0]; | 
 | 217 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | 		} | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 219 | 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | 		{ | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 221 | 			struct acpi_resource_extended_irq *p = | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | 			    &resource->data.extended_irq; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 223 | 			if (!p || !p->interrupt_count) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 224 | 				/* | 
 | 225 | 				 * extended IRQ descriptors must | 
 | 226 | 				 * return at least 1 IRQ | 
 | 227 | 				 */ | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 228 | 				printk(KERN_WARNING PREFIX | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 229 | 					      "Blank _CRS EXT IRQ resource\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 230 | 				return AE_OK; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 231 | 			} | 
 | 232 | 			*irq = p->interrupts[0]; | 
 | 233 | 			break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | 		} | 
| Len Brown | d4ec6c7 | 2006-01-26 17:23:38 -0500 | [diff] [blame] | 235 | 		break; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | 	default: | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 237 | 		printk(KERN_ERR PREFIX "_CRS resource type 0x%x isn't an IRQ\n", | 
 | 238 | 		       resource->type); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 239 | 		return AE_OK; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | 	} | 
| Bjorn Helgaas | 4a5e363 | 2008-07-15 09:42:57 -0600 | [diff] [blame] | 241 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 242 | 	return AE_CTRL_TERMINATE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | } | 
 | 244 |  | 
 | 245 | /* | 
 | 246 |  * Run _CRS and set link->irq.active | 
 | 247 |  * | 
 | 248 |  * return value: | 
 | 249 |  * 0 - success | 
 | 250 |  * !0 - failure | 
 | 251 |  */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | static int acpi_pci_link_get_current(struct acpi_pci_link *link) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 254 | 	int result = 0; | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 255 | 	acpi_status status; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 256 | 	int irq = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | 	link->irq.active = 0; | 
 | 259 |  | 
 | 260 | 	/* in practice, status disabled is meaningless, ignore it */ | 
 | 261 | 	if (acpi_strict) { | 
 | 262 | 		/* Query _STA, set link->device->status */ | 
 | 263 | 		result = acpi_bus_get_status(link->device); | 
 | 264 | 		if (result) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 265 | 			printk(KERN_ERR PREFIX "Unable to read status\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 266 | 			goto end; | 
 | 267 | 		} | 
 | 268 |  | 
 | 269 | 		if (!link->device->status.enabled) { | 
 | 270 | 			ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link disabled\n")); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 271 | 			return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | 		} | 
 | 273 | 	} | 
 | 274 |  | 
 | 275 | 	/*  | 
 | 276 | 	 * Query and parse _CRS to get the current IRQ assignment.  | 
 | 277 | 	 */ | 
 | 278 |  | 
| Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 279 | 	status = acpi_walk_resources(link->device->handle, METHOD_NAME__CRS, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | 				     acpi_pci_link_check_current, &irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | 	if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 282 | 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating _CRS")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | 		result = -ENODEV; | 
 | 284 | 		goto end; | 
 | 285 | 	} | 
 | 286 |  | 
 | 287 | 	if (acpi_strict && !irq) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 288 | 		printk(KERN_ERR PREFIX "_CRS returned 0\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | 		result = -ENODEV; | 
 | 290 | 	} | 
 | 291 |  | 
 | 292 | 	link->irq.active = irq; | 
 | 293 |  | 
 | 294 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Link at IRQ %d \n", link->irq.active)); | 
 | 295 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 296 |       end: | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 297 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | } | 
 | 299 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 300 | static int acpi_pci_link_set(struct acpi_pci_link *link, int irq) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 302 | 	int result; | 
 | 303 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | 	struct { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 305 | 		struct acpi_resource res; | 
 | 306 | 		struct acpi_resource end; | 
 | 307 | 	} *resource; | 
 | 308 | 	struct acpi_buffer buffer = { 0, NULL }; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 |  | 
| Bjorn Helgaas | 6eca4b4 | 2009-02-17 14:00:50 -0700 | [diff] [blame] | 310 | 	if (!irq) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 311 | 		return -EINVAL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 |  | 
| Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 313 | 	resource = kzalloc(sizeof(*resource) + 1, irqs_disabled() ? GFP_ATOMIC: GFP_KERNEL); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | 	if (!resource) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 315 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | 	buffer.length = sizeof(*resource) + 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | 	buffer.pointer = resource; | 
 | 319 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | 	switch (link->irq.resource_type) { | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 321 | 	case ACPI_RESOURCE_TYPE_IRQ: | 
 | 322 | 		resource->res.type = ACPI_RESOURCE_TYPE_IRQ; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | 		resource->res.length = sizeof(struct acpi_resource); | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 324 | 		resource->res.data.irq.triggering = link->irq.triggering; | 
 | 325 | 		resource->res.data.irq.polarity = | 
 | 326 | 		    link->irq.polarity; | 
 | 327 | 		if (link->irq.triggering == ACPI_EDGE_SENSITIVE) | 
 | 328 | 			resource->res.data.irq.sharable = | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 329 | 			    ACPI_EXCLUSIVE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | 		else | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 331 | 			resource->res.data.irq.sharable = ACPI_SHARED; | 
 | 332 | 		resource->res.data.irq.interrupt_count = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | 		resource->res.data.irq.interrupts[0] = irq; | 
 | 334 | 		break; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 335 |  | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 336 | 	case ACPI_RESOURCE_TYPE_EXTENDED_IRQ: | 
 | 337 | 		resource->res.type = ACPI_RESOURCE_TYPE_EXTENDED_IRQ; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | 		resource->res.length = sizeof(struct acpi_resource); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 339 | 		resource->res.data.extended_irq.producer_consumer = | 
 | 340 | 		    ACPI_CONSUMER; | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 341 | 		resource->res.data.extended_irq.triggering = | 
 | 342 | 		    link->irq.triggering; | 
 | 343 | 		resource->res.data.extended_irq.polarity = | 
 | 344 | 		    link->irq.polarity; | 
 | 345 | 		if (link->irq.triggering == ACPI_EDGE_SENSITIVE) | 
 | 346 | 			resource->res.data.irq.sharable = | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 347 | 			    ACPI_EXCLUSIVE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 		else | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 349 | 			resource->res.data.irq.sharable = ACPI_SHARED; | 
 | 350 | 		resource->res.data.extended_irq.interrupt_count = 1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | 		resource->res.data.extended_irq.interrupts[0] = irq; | 
 | 352 | 		/* ignore resource_source, it's optional */ | 
 | 353 | 		break; | 
 | 354 | 	default: | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 355 | 		printk(KERN_ERR PREFIX "Invalid Resource_type %d\n", link->irq.resource_type); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | 		result = -EINVAL; | 
 | 357 | 		goto end; | 
 | 358 |  | 
 | 359 | 	} | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 360 | 	resource->end.type = ACPI_RESOURCE_TYPE_END_TAG; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 |  | 
 | 362 | 	/* Attempt to set the resource */ | 
| Patrick Mochel | 67a7136 | 2006-05-19 16:54:42 -0400 | [diff] [blame] | 363 | 	status = acpi_set_current_resources(link->device->handle, &buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 |  | 
 | 365 | 	/* check for total failure */ | 
 | 366 | 	if (ACPI_FAILURE(status)) { | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 367 | 		ACPI_EXCEPTION((AE_INFO, status, "Evaluating _SRS")); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | 		result = -ENODEV; | 
 | 369 | 		goto end; | 
 | 370 | 	} | 
 | 371 |  | 
 | 372 | 	/* Query _STA, set device->status */ | 
 | 373 | 	result = acpi_bus_get_status(link->device); | 
 | 374 | 	if (result) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 375 | 		printk(KERN_ERR PREFIX "Unable to read status\n"); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | 		goto end; | 
 | 377 | 	} | 
 | 378 | 	if (!link->device->status.enabled) { | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 379 | 		printk(KERN_WARNING PREFIX | 
 | 380 | 			      "%s [%s] disabled and referenced, BIOS bug\n", | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 381 | 			      acpi_device_name(link->device), | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 382 | 			      acpi_device_bid(link->device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | 	} | 
 | 384 |  | 
 | 385 | 	/* Query _CRS, set link->irq.active */ | 
 | 386 | 	result = acpi_pci_link_get_current(link); | 
 | 387 | 	if (result) { | 
 | 388 | 		goto end; | 
 | 389 | 	} | 
 | 390 |  | 
 | 391 | 	/* | 
 | 392 | 	 * Is current setting not what we set? | 
 | 393 | 	 * set link->irq.active | 
 | 394 | 	 */ | 
 | 395 | 	if (link->irq.active != irq) { | 
 | 396 | 		/* | 
 | 397 | 		 * policy: when _CRS doesn't return what we just _SRS | 
 | 398 | 		 * assume _SRS worked and override _CRS value. | 
 | 399 | 		 */ | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 400 | 		printk(KERN_WARNING PREFIX | 
 | 401 | 			      "%s [%s] BIOS reported IRQ %d, using IRQ %d\n", | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 402 | 			      acpi_device_name(link->device), | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 403 | 			      acpi_device_bid(link->device), link->irq.active, irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | 		link->irq.active = irq; | 
 | 405 | 	} | 
 | 406 |  | 
 | 407 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, "Set IRQ %d\n", link->irq.active)); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 |  | 
 | 409 |       end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | 	kfree(resource); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 411 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } | 
 | 413 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | /* -------------------------------------------------------------------------- | 
 | 415 |                             PCI Link IRQ Management | 
 | 416 |    -------------------------------------------------------------------------- */ | 
 | 417 |  | 
 | 418 | /* | 
 | 419 |  * "acpi_irq_balance" (default in APIC mode) enables ACPI to use PIC Interrupt | 
 | 420 |  * Link Devices to move the PIRQs around to minimize sharing. | 
 | 421 |  *  | 
 | 422 |  * "acpi_irq_nobalance" (default in PIC mode) tells ACPI not to move any PIC IRQs | 
 | 423 |  * that the BIOS has already set to active.  This is necessary because | 
 | 424 |  * ACPI has no automatic means of knowing what ISA IRQs are used.  Note that | 
 | 425 |  * if the BIOS doesn't set a Link Device active, ACPI needs to program it | 
 | 426 |  * even if acpi_irq_nobalance is set. | 
 | 427 |  * | 
 | 428 |  * A tables of penalties avoids directing PCI interrupts to well known | 
 | 429 |  * ISA IRQs. Boot params are available to over-ride the default table: | 
 | 430 |  * | 
 | 431 |  * List interrupts that are free for PCI use. | 
 | 432 |  * acpi_irq_pci=n[,m] | 
 | 433 |  * | 
 | 434 |  * List interrupts that should not be used for PCI: | 
 | 435 |  * acpi_irq_isa=n[,m] | 
 | 436 |  * | 
 | 437 |  * Note that PCI IRQ routers have a list of possible IRQs, | 
 | 438 |  * which may not include the IRQs this table says are available. | 
 | 439 |  *  | 
 | 440 |  * Since this heuristic can't tell the difference between a link | 
 | 441 |  * that no device will attach to, vs. a link which may be shared | 
 | 442 |  * by multiple active devices -- it is not optimal. | 
 | 443 |  * | 
 | 444 |  * If interrupt performance is that important, get an IO-APIC system | 
 | 445 |  * with a pin dedicated to each device.  Or for that matter, an MSI | 
 | 446 |  * enabled system. | 
 | 447 |  */ | 
 | 448 |  | 
 | 449 | #define ACPI_MAX_IRQS		256 | 
 | 450 | #define ACPI_MAX_ISA_IRQ	16 | 
 | 451 |  | 
 | 452 | #define PIRQ_PENALTY_PCI_AVAILABLE	(0) | 
 | 453 | #define PIRQ_PENALTY_PCI_POSSIBLE	(16*16) | 
 | 454 | #define PIRQ_PENALTY_PCI_USING		(16*16*16) | 
 | 455 | #define PIRQ_PENALTY_ISA_TYPICAL	(16*16*16*16) | 
 | 456 | #define PIRQ_PENALTY_ISA_USED		(16*16*16*16*16) | 
 | 457 | #define PIRQ_PENALTY_ISA_ALWAYS		(16*16*16*16*16*16) | 
 | 458 |  | 
 | 459 | static int acpi_irq_penalty[ACPI_MAX_IRQS] = { | 
 | 460 | 	PIRQ_PENALTY_ISA_ALWAYS,	/* IRQ0 timer */ | 
 | 461 | 	PIRQ_PENALTY_ISA_ALWAYS,	/* IRQ1 keyboard */ | 
 | 462 | 	PIRQ_PENALTY_ISA_ALWAYS,	/* IRQ2 cascade */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 463 | 	PIRQ_PENALTY_ISA_TYPICAL,	/* IRQ3 serial */ | 
 | 464 | 	PIRQ_PENALTY_ISA_TYPICAL,	/* IRQ4 serial */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | 	PIRQ_PENALTY_ISA_TYPICAL,	/* IRQ5 sometimes SoundBlaster */ | 
 | 466 | 	PIRQ_PENALTY_ISA_TYPICAL,	/* IRQ6 */ | 
 | 467 | 	PIRQ_PENALTY_ISA_TYPICAL,	/* IRQ7 parallel, spurious */ | 
 | 468 | 	PIRQ_PENALTY_ISA_TYPICAL,	/* IRQ8 rtc, sometimes */ | 
 | 469 | 	PIRQ_PENALTY_PCI_AVAILABLE,	/* IRQ9  PCI, often acpi */ | 
 | 470 | 	PIRQ_PENALTY_PCI_AVAILABLE,	/* IRQ10 PCI */ | 
 | 471 | 	PIRQ_PENALTY_PCI_AVAILABLE,	/* IRQ11 PCI */ | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 472 | 	PIRQ_PENALTY_ISA_USED,		/* IRQ12 mouse */ | 
 | 473 | 	PIRQ_PENALTY_ISA_USED,		/* IRQ13 fpe, sometimes */ | 
 | 474 | 	PIRQ_PENALTY_ISA_USED,		/* IRQ14 ide0 */ | 
 | 475 | 	PIRQ_PENALTY_ISA_USED,		/* IRQ15 ide1 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 476 | 	/* >IRQ15 */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | }; | 
 | 478 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | int __init acpi_irq_penalty_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 481 | 	struct acpi_pci_link *link; | 
 | 482 | 	int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | 	/* | 
 | 485 | 	 * Update penalties to facilitate IRQ balancing. | 
 | 486 | 	 */ | 
| Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 487 | 	list_for_each_entry(link, &acpi_link_list, list) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 |  | 
 | 489 | 		/* | 
 | 490 | 		 * reflect the possible and active irqs in the penalty table -- | 
 | 491 | 		 * useful for breaking ties. | 
 | 492 | 		 */ | 
 | 493 | 		if (link->irq.possible_count) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 494 | 			int penalty = | 
 | 495 | 			    PIRQ_PENALTY_PCI_POSSIBLE / | 
 | 496 | 			    link->irq.possible_count; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 497 |  | 
 | 498 | 			for (i = 0; i < link->irq.possible_count; i++) { | 
 | 499 | 				if (link->irq.possible[i] < ACPI_MAX_ISA_IRQ) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 500 | 					acpi_irq_penalty[link->irq. | 
 | 501 | 							 possible[i]] += | 
 | 502 | 					    penalty; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | 			} | 
 | 504 |  | 
 | 505 | 		} else if (link->irq.active) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 506 | 			acpi_irq_penalty[link->irq.active] += | 
 | 507 | 			    PIRQ_PENALTY_PCI_POSSIBLE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | 		} | 
 | 509 | 	} | 
 | 510 | 	/* Add a penalty for the SCI */ | 
| Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 511 | 	acpi_irq_penalty[acpi_gbl_FADT.sci_interrupt] += PIRQ_PENALTY_PCI_USING; | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 512 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } | 
 | 514 |  | 
| Bjorn Helgaas | 3283625 | 2008-11-05 16:17:52 -0700 | [diff] [blame] | 515 | static int acpi_irq_balance = -1;	/* 0: static, 1: balance */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | static int acpi_pci_link_allocate(struct acpi_pci_link *link) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 519 | 	int irq; | 
 | 520 | 	int i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 |  | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 522 | 	if (link->irq.initialized) { | 
 | 523 | 		if (link->refcnt == 0) | 
 | 524 | 			/* This means the link is disabled but initialized */ | 
 | 525 | 			acpi_pci_link_set(link, link->irq.active); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 526 | 		return 0; | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 527 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 |  | 
 | 529 | 	/* | 
 | 530 | 	 * search for active IRQ in list of possible IRQs. | 
 | 531 | 	 */ | 
 | 532 | 	for (i = 0; i < link->irq.possible_count; ++i) { | 
 | 533 | 		if (link->irq.active == link->irq.possible[i]) | 
 | 534 | 			break; | 
 | 535 | 	} | 
 | 536 | 	/* | 
 | 537 | 	 * forget active IRQ that is not in possible list | 
 | 538 | 	 */ | 
 | 539 | 	if (i == link->irq.possible_count) { | 
 | 540 | 		if (acpi_strict) | 
| Len Brown | cece929 | 2006-06-26 23:04:31 -0400 | [diff] [blame] | 541 | 			printk(KERN_WARNING PREFIX "_CRS %d not found" | 
 | 542 | 				      " in _PRS\n", link->irq.active); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | 		link->irq.active = 0; | 
 | 544 | 	} | 
 | 545 |  | 
 | 546 | 	/* | 
 | 547 | 	 * if active found, use it; else pick entry from end of possible list. | 
 | 548 | 	 */ | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 549 | 	if (link->irq.active) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | 		irq = link->irq.active; | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 551 | 	else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | 		irq = link->irq.possible[link->irq.possible_count - 1]; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 |  | 
 | 554 | 	if (acpi_irq_balance || !link->irq.active) { | 
 | 555 | 		/* | 
 | 556 | 		 * Select the best IRQ.  This is done in reverse to promote | 
 | 557 | 		 * the use of IRQs 9, 10, 11, and >15. | 
 | 558 | 		 */ | 
 | 559 | 		for (i = (link->irq.possible_count - 1); i >= 0; i--) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | 			if (acpi_irq_penalty[irq] > | 
 | 561 | 			    acpi_irq_penalty[link->irq.possible[i]]) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | 				irq = link->irq.possible[i]; | 
 | 563 | 		} | 
 | 564 | 	} | 
 | 565 |  | 
 | 566 | 	/* Attempt to enable the link device at this IRQ. */ | 
 | 567 | 	if (acpi_pci_link_set(link, irq)) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 568 | 		printk(KERN_ERR PREFIX "Unable to set IRQ for %s [%s]. " | 
 | 569 | 			    "Try pci=noacpi or acpi=off\n", | 
| Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 570 | 			    acpi_device_name(link->device), | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 571 | 			    acpi_device_bid(link->device)); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 572 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | 	} else { | 
 | 574 | 		acpi_irq_penalty[link->irq.active] += PIRQ_PENALTY_PCI_USING; | 
| Frank Seidel | 4d93915 | 2009-02-04 17:03:07 +0100 | [diff] [blame] | 575 | 		printk(KERN_WARNING PREFIX "%s [%s] enabled at IRQ %d\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 576 | 		       acpi_device_name(link->device), | 
 | 577 | 		       acpi_device_bid(link->device), link->irq.active); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | 	} | 
 | 579 |  | 
 | 580 | 	link->irq.initialized = 1; | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 581 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | } | 
 | 583 |  | 
 | 584 | /* | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 585 |  * acpi_pci_link_allocate_irq | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 |  * success: return IRQ >= 0 | 
 | 587 |  * failure: return -1 | 
 | 588 |  */ | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 589 | int acpi_pci_link_allocate_irq(acpi_handle handle, int index, int *triggering, | 
 | 590 | 			       int *polarity, char **name) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 591 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 592 | 	int result; | 
 | 593 | 	struct acpi_device *device; | 
 | 594 | 	struct acpi_pci_link *link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 596 | 	result = acpi_bus_get_device(handle, &device); | 
 | 597 | 	if (result) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 598 | 		printk(KERN_ERR PREFIX "Invalid link device\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 599 | 		return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | 	} | 
 | 601 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 602 | 	link = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | 	if (!link) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 604 | 		printk(KERN_ERR PREFIX "Invalid link context\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 605 | 		return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | 	} | 
 | 607 |  | 
 | 608 | 	/* TBD: Support multiple index (IRQ) entries per Link Device */ | 
 | 609 | 	if (index) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 610 | 		printk(KERN_ERR PREFIX "Invalid index %d\n", index); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 611 | 		return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | 	} | 
 | 613 |  | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 614 | 	mutex_lock(&acpi_link_lock); | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 615 | 	if (acpi_pci_link_allocate(link)) { | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 616 | 		mutex_unlock(&acpi_link_lock); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 617 | 		return -1; | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 618 | 	} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 619 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | 	if (!link->irq.active) { | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 621 | 		mutex_unlock(&acpi_link_lock); | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 622 | 		printk(KERN_ERR PREFIX "Link active IRQ is 0!\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 623 | 		return -1; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | 	} | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 625 | 	link->refcnt++; | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 626 | 	mutex_unlock(&acpi_link_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 |  | 
| Bob Moore | 50eca3e | 2005-09-30 19:03:00 -0400 | [diff] [blame] | 628 | 	if (triggering) | 
 | 629 | 		*triggering = link->irq.triggering; | 
 | 630 | 	if (polarity) | 
 | 631 | 		*polarity = link->irq.polarity; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 632 | 	if (name) | 
 | 633 | 		*name = acpi_device_bid(link->device); | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 634 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 635 | 			  "Link %s is referenced\n", | 
 | 636 | 			  acpi_device_bid(link->device))); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 637 | 	return (link->irq.active); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | } | 
 | 639 |  | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 640 | /* | 
 | 641 |  * We don't change link's irq information here.  After it is reenabled, we | 
 | 642 |  * continue use the info | 
 | 643 |  */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | int acpi_pci_link_free_irq(acpi_handle handle) | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 645 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 646 | 	struct acpi_device *device; | 
 | 647 | 	struct acpi_pci_link *link; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 648 | 	acpi_status result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 649 |  | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 650 | 	result = acpi_bus_get_device(handle, &device); | 
 | 651 | 	if (result) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 652 | 		printk(KERN_ERR PREFIX "Invalid link device\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 653 | 		return -1; | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 654 | 	} | 
 | 655 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 656 | 	link = acpi_driver_data(device); | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 657 | 	if (!link) { | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 658 | 		printk(KERN_ERR PREFIX "Invalid link context\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 659 | 		return -1; | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 660 | 	} | 
 | 661 |  | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 662 | 	mutex_lock(&acpi_link_lock); | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 663 | 	if (!link->irq.initialized) { | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 664 | 		mutex_unlock(&acpi_link_lock); | 
| Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 665 | 		printk(KERN_ERR PREFIX "Link isn't initialized\n"); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 666 | 		return -1; | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 667 | 	} | 
| David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 668 | #ifdef	FUTURE_USE | 
 | 669 | 	/* | 
 | 670 | 	 * The Link reference count allows us to _DISable an unused link | 
 | 671 | 	 * and suspend time, and set it again  on resume. | 
 | 672 | 	 * However, 2.6.12 still has irq_router.resume | 
 | 673 | 	 * which blindly restores the link state. | 
 | 674 | 	 * So we disable the reference count method | 
 | 675 | 	 * to prevent duplicate acpi_pci_link_set() | 
 | 676 | 	 * which would harm some systems | 
 | 677 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | 	link->refcnt--; | 
| David Shaohua Li | ecc21eb | 2005-08-03 11:00:11 -0400 | [diff] [blame] | 679 | #endif | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 680 | 	ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 681 | 			  "Link %s is dereferenced\n", | 
 | 682 | 			  acpi_device_bid(link->device))); | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 683 |  | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 684 | 	if (link->refcnt == 0) | 
| donald.d.dugger@intel.com | 383d7a1 | 2008-10-17 07:49:50 -0700 | [diff] [blame] | 685 | 		acpi_evaluate_object(link->device->handle, "_DIS", NULL, NULL); | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 686 |  | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 687 | 	mutex_unlock(&acpi_link_lock); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 688 | 	return (link->irq.active); | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 689 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 690 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 691 | /* -------------------------------------------------------------------------- | 
 | 692 |                                  Driver Interface | 
 | 693 |    -------------------------------------------------------------------------- */ | 
 | 694 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 695 | static int acpi_pci_link_add(struct acpi_device *device) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 697 | 	int result; | 
 | 698 | 	struct acpi_pci_link *link; | 
 | 699 | 	int i; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 700 | 	int found = 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 |  | 
| Burman Yan | 36bcbec | 2006-12-19 12:56:11 -0800 | [diff] [blame] | 702 | 	link = kzalloc(sizeof(struct acpi_pci_link), GFP_KERNEL); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | 	if (!link) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 704 | 		return -ENOMEM; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 |  | 
 | 706 | 	link->device = device; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 707 | 	strcpy(acpi_device_name(device), ACPI_PCI_LINK_DEVICE_NAME); | 
 | 708 | 	strcpy(acpi_device_class(device), ACPI_PCI_LINK_CLASS); | 
| Pavel Machek | db89b4f | 2008-09-22 14:37:34 -0700 | [diff] [blame] | 709 | 	device->driver_data = link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 710 |  | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 711 | 	mutex_lock(&acpi_link_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | 	result = acpi_pci_link_get_possible(link); | 
 | 713 | 	if (result) | 
 | 714 | 		goto end; | 
 | 715 |  | 
 | 716 | 	/* query and set link->irq.active */ | 
 | 717 | 	acpi_pci_link_get_current(link); | 
 | 718 |  | 
| Dan Aloni | 0dc070b | 2007-07-09 11:33:18 -0700 | [diff] [blame] | 719 | 	printk(KERN_INFO PREFIX "%s [%s] (IRQs", acpi_device_name(device), | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 720 | 	       acpi_device_bid(device)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 721 | 	for (i = 0; i < link->irq.possible_count; i++) { | 
 | 722 | 		if (link->irq.active == link->irq.possible[i]) { | 
 | 723 | 			printk(" *%d", link->irq.possible[i]); | 
 | 724 | 			found = 1; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 725 | 		} else | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | 			printk(" %d", link->irq.possible[i]); | 
 | 727 | 	} | 
 | 728 |  | 
 | 729 | 	printk(")"); | 
 | 730 |  | 
 | 731 | 	if (!found) | 
 | 732 | 		printk(" *%d", link->irq.active); | 
 | 733 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 734 | 	if (!link->device->status.enabled) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | 		printk(", disabled."); | 
 | 736 |  | 
 | 737 | 	printk("\n"); | 
 | 738 |  | 
| Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 739 | 	list_add_tail(&link->list, &acpi_link_list); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 741 |       end: | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | 	/* disable all links -- to be activated on use */ | 
| donald.d.dugger@intel.com | 383d7a1 | 2008-10-17 07:49:50 -0700 | [diff] [blame] | 743 | 	acpi_evaluate_object(device->handle, "_DIS", NULL, NULL); | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 744 | 	mutex_unlock(&acpi_link_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 |  | 
 | 746 | 	if (result) | 
 | 747 | 		kfree(link); | 
 | 748 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 749 | 	return result; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | } | 
 | 751 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 752 | static int acpi_pci_link_resume(struct acpi_pci_link *link) | 
| Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 753 | { | 
| Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 754 | 	if (link->refcnt && link->irq.active && link->irq.initialized) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 755 | 		return (acpi_pci_link_set(link, link->irq.active)); | 
| Bjorn Helgaas | 1c9ca3a | 2009-02-17 14:00:40 -0700 | [diff] [blame] | 756 |  | 
 | 757 | 	return 0; | 
| Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 758 | } | 
 | 759 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 760 | static int irqrouter_resume(struct sys_device *dev) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 762 | 	struct acpi_pci_link *link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 |  | 
| Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 764 | 	list_for_each_entry(link, &acpi_link_list, list) { | 
| Linus Torvalds | 697a2d6 | 2005-08-01 12:37:54 -0700 | [diff] [blame] | 765 | 		acpi_pci_link_resume(link); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | 	} | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 767 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | } | 
 | 769 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 770 | static int acpi_pci_link_remove(struct acpi_device *device, int type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | { | 
| Bjorn Helgaas | c9d6244 | 2009-02-17 14:00:45 -0700 | [diff] [blame] | 772 | 	struct acpi_pci_link *link; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 |  | 
| Jan Engelhardt | 50dd096 | 2006-10-01 00:28:50 +0200 | [diff] [blame] | 774 | 	link = acpi_driver_data(device); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 |  | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 776 | 	mutex_lock(&acpi_link_lock); | 
| Bjorn Helgaas | 5f0dcca | 2009-02-17 14:00:55 -0700 | [diff] [blame] | 777 | 	list_del(&link->list); | 
| Ingo Molnar | 36e4309 | 2006-04-27 05:25:00 -0400 | [diff] [blame] | 778 | 	mutex_unlock(&acpi_link_lock); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 |  | 
 | 780 | 	kfree(link); | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 781 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | } | 
 | 783 |  | 
 | 784 | /* | 
 | 785 |  * modify acpi_irq_penalty[] from cmdline | 
 | 786 |  */ | 
 | 787 | static int __init acpi_irq_penalty_update(char *str, int used) | 
 | 788 | { | 
 | 789 | 	int i; | 
 | 790 |  | 
 | 791 | 	for (i = 0; i < 16; i++) { | 
 | 792 | 		int retval; | 
 | 793 | 		int irq; | 
 | 794 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 795 | 		retval = get_option(&str, &irq); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 |  | 
 | 797 | 		if (!retval) | 
 | 798 | 			break;	/* no number found */ | 
 | 799 |  | 
 | 800 | 		if (irq < 0) | 
 | 801 | 			continue; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 802 |  | 
| Bjorn Helgaas | fa46d35 | 2008-08-01 15:58:17 -0600 | [diff] [blame] | 803 | 		if (irq >= ARRAY_SIZE(acpi_irq_penalty)) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | 			continue; | 
 | 805 |  | 
 | 806 | 		if (used) | 
 | 807 | 			acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; | 
 | 808 | 		else | 
 | 809 | 			acpi_irq_penalty[irq] = PIRQ_PENALTY_PCI_AVAILABLE; | 
 | 810 |  | 
 | 811 | 		if (retval != 2)	/* no next number */ | 
 | 812 | 			break; | 
 | 813 | 	} | 
 | 814 | 	return 1; | 
 | 815 | } | 
 | 816 |  | 
 | 817 | /* | 
 | 818 |  * We'd like PNP to call this routine for the | 
 | 819 |  * single ISA_USED value for each legacy device. | 
 | 820 |  * But instead it calls us with each POSSIBLE setting. | 
 | 821 |  * There is no ISA_POSSIBLE weight, so we simply use | 
 | 822 |  * the (small) PCI_USING penalty. | 
 | 823 |  */ | 
| David Shaohua Li | c9c3e45 | 2005-04-01 00:07:31 -0500 | [diff] [blame] | 824 | void acpi_penalize_isa_irq(int irq, int active) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | { | 
| Bjorn Helgaas | fa46d35 | 2008-08-01 15:58:17 -0600 | [diff] [blame] | 826 | 	if (irq >= 0 && irq < ARRAY_SIZE(acpi_irq_penalty)) { | 
 | 827 | 		if (active) | 
 | 828 | 			acpi_irq_penalty[irq] += PIRQ_PENALTY_ISA_USED; | 
 | 829 | 		else | 
 | 830 | 			acpi_irq_penalty[irq] += PIRQ_PENALTY_PCI_USING; | 
 | 831 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | } | 
 | 833 |  | 
 | 834 | /* | 
 | 835 |  * Over-ride default table to reserve additional IRQs for use by ISA | 
 | 836 |  * e.g. acpi_irq_isa=5 | 
 | 837 |  * Useful for telling ACPI how not to interfere with your ISA sound card. | 
 | 838 |  */ | 
 | 839 | static int __init acpi_irq_isa(char *str) | 
 | 840 | { | 
 | 841 | 	return acpi_irq_penalty_update(str, 1); | 
 | 842 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | __setup("acpi_irq_isa=", acpi_irq_isa); | 
 | 845 |  | 
 | 846 | /* | 
 | 847 |  * Over-ride default table to free additional IRQs for use by PCI | 
 | 848 |  * e.g. acpi_irq_pci=7,15 | 
 | 849 |  * Used for acpi_irq_balance to free up IRQs to reduce PCI IRQ sharing. | 
 | 850 |  */ | 
 | 851 | static int __init acpi_irq_pci(char *str) | 
 | 852 | { | 
 | 853 | 	return acpi_irq_penalty_update(str, 0); | 
 | 854 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 855 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | __setup("acpi_irq_pci=", acpi_irq_pci); | 
 | 857 |  | 
 | 858 | static int __init acpi_irq_nobalance_set(char *str) | 
 | 859 | { | 
 | 860 | 	acpi_irq_balance = 0; | 
 | 861 | 	return 1; | 
 | 862 | } | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 863 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | __setup("acpi_irq_nobalance", acpi_irq_nobalance_set); | 
 | 865 |  | 
| Roel Kluin | 8a383ef | 2008-12-09 20:45:30 +0100 | [diff] [blame] | 866 | static int __init acpi_irq_balance_set(char *str) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | { | 
 | 868 | 	acpi_irq_balance = 1; | 
 | 869 | 	return 1; | 
 | 870 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 872 | __setup("acpi_irq_balance", acpi_irq_balance_set); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 |  | 
| David Shaohua Li | 87bec66 | 2005-07-27 23:02:00 -0400 | [diff] [blame] | 874 | /* FIXME: we will remove this interface after all drivers call pci_disable_device */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 875 | static struct sysdev_class irqrouter_sysdev_class = { | 
| Kay Sievers | af5ca3f | 2007-12-20 02:09:39 +0100 | [diff] [blame] | 876 | 	.name = "irqrouter", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 877 | 	.resume = irqrouter_resume, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 878 | }; | 
 | 879 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 880 | static struct sys_device device_irqrouter = { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 881 | 	.id = 0, | 
 | 882 | 	.cls = &irqrouter_sysdev_class, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 883 | }; | 
 | 884 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 885 | static int __init irqrouter_init_sysfs(void) | 
 | 886 | { | 
 | 887 | 	int error; | 
 | 888 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 889 | 	if (acpi_disabled || acpi_noirq) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 890 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 |  | 
 | 892 | 	error = sysdev_class_register(&irqrouter_sysdev_class); | 
 | 893 | 	if (!error) | 
 | 894 | 		error = sysdev_register(&device_irqrouter); | 
 | 895 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 896 | 	return error; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 897 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 |  | 
 | 899 | device_initcall(irqrouter_init_sysfs); | 
 | 900 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 901 | static int __init acpi_pci_link_init(void) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 903 | 	if (acpi_noirq) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 904 | 		return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 |  | 
| Bjorn Helgaas | 3283625 | 2008-11-05 16:17:52 -0700 | [diff] [blame] | 906 | 	if (acpi_irq_balance == -1) { | 
 | 907 | 		/* no command line switch: enable balancing in IOAPIC mode */ | 
 | 908 | 		if (acpi_irq_model == ACPI_IRQ_MODEL_IOAPIC) | 
 | 909 | 			acpi_irq_balance = 1; | 
 | 910 | 		else | 
 | 911 | 			acpi_irq_balance = 0; | 
 | 912 | 	} | 
 | 913 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | 	if (acpi_bus_register_driver(&acpi_pci_link_driver) < 0) | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 915 | 		return -ENODEV; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 |  | 
| Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 917 | 	return 0; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 918 | } | 
 | 919 |  | 
 | 920 | subsys_initcall(acpi_pci_link_init); |