Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * pci_bind.c - ACPI PCI Device Binding ($Revision: 2 $) |
| 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 | * |
| 7 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or (at |
| 12 | * your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, but |
| 15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 | * General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License along |
| 20 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 21 | * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. |
| 22 | * |
| 23 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 24 | */ |
| 25 | |
| 26 | #include <linux/kernel.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #include <linux/pci.h> |
| 29 | #include <linux/acpi.h> |
| 30 | #include <acpi/acpi_bus.h> |
| 31 | #include <acpi/acpi_drivers.h> |
| 32 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 34 | ACPI_MODULE_NAME("pci_bind"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | |
| 36 | struct acpi_pci_data { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 37 | struct acpi_pci_id id; |
| 38 | struct pci_bus *bus; |
| 39 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | }; |
| 41 | |
Alexander Chiang | ce597bb | 2009-06-10 19:55:09 +0000 | [diff] [blame] | 42 | static int acpi_pci_bind(struct acpi_device *device); |
Adrian Bunk | e5685b9 | 2007-10-24 18:24:42 +0200 | [diff] [blame] | 43 | static int acpi_pci_unbind(struct acpi_device *device); |
| 44 | |
Adrian Bunk | 8713cbe | 2005-09-02 17:16:48 -0400 | [diff] [blame] | 45 | static void acpi_pci_data_handler(acpi_handle handle, u32 function, |
| 46 | void *context) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* TBD: Anything we need to do here? */ |
| 50 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 51 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | } |
| 53 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | /** |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 55 | * acpi_get_pci_id |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | * ------------------ |
| 57 | * This function is used by the ACPI Interpreter (a.k.a. Core Subsystem) |
| 58 | * to resolve PCI information for ACPI-PCI devices defined in the namespace. |
| 59 | * This typically occurs when resolving PCI operation region information. |
| 60 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 63 | int result = 0; |
| 64 | acpi_status status = AE_OK; |
| 65 | struct acpi_device *device = NULL; |
| 66 | struct acpi_pci_data *data = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
| 69 | if (!id) |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 70 | return AE_BAD_PARAMETER; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
| 72 | result = acpi_bus_get_device(handle, &device); |
| 73 | if (result) { |
Len Brown | 6468463 | 2006-06-26 23:41:38 -0400 | [diff] [blame] | 74 | printk(KERN_ERR PREFIX |
| 75 | "Invalid ACPI Bus context for device %s\n", |
| 76 | acpi_device_bid(device)); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 77 | return AE_NOT_EXIST; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data); |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 81 | if (ACPI_FAILURE(status) || !data) { |
Thomas Renninger | a6fc672 | 2006-06-26 23:58:43 -0400 | [diff] [blame] | 82 | ACPI_EXCEPTION((AE_INFO, status, |
| 83 | "Invalid ACPI-PCI context for device %s", |
| 84 | acpi_device_bid(device))); |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 85 | return status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | } |
| 87 | |
| 88 | *id = data->id; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 90 | /* |
| 91 | id->segment = data->id.segment; |
| 92 | id->bus = data->id.bus; |
| 93 | id->device = data->id.device; |
| 94 | id->function = data->id.function; |
| 95 | */ |
| 96 | |
| 97 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bjorn Helgaas | 21a5328 | 2008-12-08 21:30:05 -0700 | [diff] [blame] | 98 | "Device %s has PCI address %04x:%02x:%02x.%d\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 99 | acpi_device_bid(device), id->segment, id->bus, |
| 100 | id->device, id->function)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | |
Patrick Mochel | d550d98 | 2006-06-27 00:41:40 -0400 | [diff] [blame] | 102 | return AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 104 | |
Rajesh Shah | 4ce448e | 2005-04-28 00:25:53 -0700 | [diff] [blame] | 105 | EXPORT_SYMBOL(acpi_get_pci_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 107 | static int acpi_pci_unbind(struct acpi_device *device) |
| 108 | { |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 109 | struct pci_dev *dev; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 110 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 111 | dev = acpi_get_pci_dev(device->handle); |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame^] | 112 | if (!dev || !dev->subordinate) |
| 113 | goto out; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 114 | |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame^] | 115 | acpi_pci_irq_del_prt(dev->subordinate); |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 116 | |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame^] | 117 | device->ops.bind = NULL; |
| 118 | device->ops.unbind = NULL; |
| 119 | |
| 120 | out: |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 121 | pci_dev_put(dev); |
| 122 | return 0; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 123 | } |
| 124 | |
Alexander Chiang | ce597bb | 2009-06-10 19:55:09 +0000 | [diff] [blame] | 125 | static int acpi_pci_bind(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 126 | { |
Len Brown | 087da3b | 2008-12-30 22:44:33 -0500 | [diff] [blame] | 127 | acpi_status status; |
Len Brown | 087da3b | 2008-12-30 22:44:33 -0500 | [diff] [blame] | 128 | acpi_handle handle; |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 129 | struct pci_bus *bus; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 130 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 132 | dev = acpi_get_pci_dev(device->handle); |
| 133 | if (!dev) |
| 134 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | /* |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 137 | * Install the 'bind' function to facilitate callbacks for |
| 138 | * children of the P2P bridge. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | */ |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 140 | if (dev->subordinate) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bjorn Helgaas | 21a5328 | 2008-12-08 21:30:05 -0700 | [diff] [blame] | 142 | "Device %04x:%02x:%02x.%d is a PCI bridge\n", |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 143 | pci_domain_nr(dev->bus), dev->bus->number, |
| 144 | PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | device->ops.bind = acpi_pci_bind; |
| 146 | device->ops.unbind = acpi_pci_unbind; |
| 147 | } |
| 148 | |
| 149 | /* |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 150 | * Evaluate and parse _PRT, if exists. This code allows parsing of |
| 151 | * _PRT objects within the scope of non-bridge devices. Note that |
| 152 | * _PRTs within the scope of a PCI bridge assume the bridge's |
| 153 | * subordinate bus number. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | * |
| 155 | * TBD: Can _PRTs exist within the scope of non-bridge PCI devices? |
| 156 | */ |
| 157 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 158 | if (ACPI_FAILURE(status)) |
| 159 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 161 | if (dev->subordinate) |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 162 | bus = dev->subordinate; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 163 | else |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 164 | bus = dev->bus; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 165 | |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 166 | acpi_pci_irq_add_prt(device->handle, bus); |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 167 | |
| 168 | out: |
| 169 | pci_dev_put(dev); |
| 170 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 173 | int acpi_pci_bind_root(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | device->ops.bind = acpi_pci_bind; |
| 176 | device->ops.unbind = acpi_pci_unbind; |
| 177 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 178 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | } |