blob: a205769f1d0033caf8d713beffbc709a603d48aa [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Torvalds1da177e2005-04-16 15:20:36 -070027#include <linux/types.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/pci.h>
29#include <linux/acpi.h>
30#include <acpi/acpi_bus.h>
31#include <acpi/acpi_drivers.h>
32
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050034ACPI_MODULE_NAME("pci_bind");
Linus Torvalds1da177e2005-04-16 15:20:36 -070035
36struct acpi_pci_data {
Len Brown4be44fc2005-08-05 00:44:28 -040037 struct acpi_pci_id id;
38 struct pci_bus *bus;
39 struct pci_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040};
41
Alexander Chiangce597bb2009-06-10 19:55:09 +000042static int acpi_pci_bind(struct acpi_device *device);
Adrian Bunke5685b92007-10-24 18:24:42 +020043static int acpi_pci_unbind(struct acpi_device *device);
44
Adrian Bunk8713cbe2005-09-02 17:16:48 -040045static void acpi_pci_data_handler(acpi_handle handle, u32 function,
46 void *context)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
49 /* TBD: Anything we need to do here? */
50
Patrick Mocheld550d982006-06-27 00:41:40 -040051 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -070052}
53
Linus Torvalds1da177e2005-04-16 15:20:36 -070054/**
Rajesh Shah4ce448e2005-04-28 00:25:53 -070055 * acpi_get_pci_id
Linus Torvalds1da177e2005-04-16 15:20:36 -070056 * ------------------
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 Brown4be44fc2005-08-05 00:44:28 -040061acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -070062{
Len Brown4be44fc2005-08-05 00:44:28 -040063 int result = 0;
64 acpi_status status = AE_OK;
65 struct acpi_device *device = NULL;
66 struct acpi_pci_data *data = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
69 if (!id)
Patrick Mocheld550d982006-06-27 00:41:40 -040070 return AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071
72 result = acpi_bus_get_device(handle, &device);
73 if (result) {
Len Brown64684632006-06-26 23:41:38 -040074 printk(KERN_ERR PREFIX
75 "Invalid ACPI Bus context for device %s\n",
76 acpi_device_bid(device));
Patrick Mocheld550d982006-06-27 00:41:40 -040077 return AE_NOT_EXIST;
Linus Torvalds1da177e2005-04-16 15:20:36 -070078 }
79
Len Brown4be44fc2005-08-05 00:44:28 -040080 status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data);
Rajesh Shah4ce448e2005-04-28 00:25:53 -070081 if (ACPI_FAILURE(status) || !data) {
Thomas Renningera6fc6722006-06-26 23:58:43 -040082 ACPI_EXCEPTION((AE_INFO, status,
83 "Invalid ACPI-PCI context for device %s",
84 acpi_device_bid(device)));
Patrick Mocheld550d982006-06-27 00:41:40 -040085 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 }
87
88 *id = data->id;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Len Brown4be44fc2005-08-05 00:44:28 -040090 /*
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 Helgaas21a53282008-12-08 21:30:05 -070098 "Device %s has PCI address %04x:%02x:%02x.%d\n",
Len Brown4be44fc2005-08-05 00:44:28 -040099 acpi_device_bid(device), id->segment, id->bus,
100 id->device, id->function));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Patrick Mocheld550d982006-06-27 00:41:40 -0400102 return AE_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103}
Len Brown4be44fc2005-08-05 00:44:28 -0400104
Rajesh Shah4ce448e2005-04-28 00:25:53 -0700105EXPORT_SYMBOL(acpi_get_pci_id);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000107static int acpi_pci_unbind(struct acpi_device *device)
108{
Alexander Chiang499650d2009-06-10 19:55:30 +0000109 struct pci_dev *dev;
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000110
Alexander Chiang499650d2009-06-10 19:55:30 +0000111 dev = acpi_get_pci_dev(device->handle);
Alexander Chiang97719a82009-06-10 19:55:45 +0000112 if (!dev || !dev->subordinate)
113 goto out;
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000114
Alexander Chiang97719a82009-06-10 19:55:45 +0000115 acpi_pci_irq_del_prt(dev->subordinate);
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000116
Alexander Chiang97719a82009-06-10 19:55:45 +0000117 device->ops.bind = NULL;
118 device->ops.unbind = NULL;
119
120out:
Alexander Chiang499650d2009-06-10 19:55:30 +0000121 pci_dev_put(dev);
122 return 0;
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000123}
124
Alexander Chiangce597bb2009-06-10 19:55:09 +0000125static int acpi_pci_bind(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
Len Brown087da3b2008-12-30 22:44:33 -0500127 acpi_status status;
Len Brown087da3b2008-12-30 22:44:33 -0500128 acpi_handle handle;
Alexander Chiang859a3f82009-06-10 19:55:35 +0000129 struct pci_bus *bus;
Alexander Chiang499650d2009-06-10 19:55:30 +0000130 struct pci_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
Alexander Chiang499650d2009-06-10 19:55:30 +0000132 dev = acpi_get_pci_dev(device->handle);
133 if (!dev)
134 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 /*
Alexander Chiang499650d2009-06-10 19:55:30 +0000137 * Install the 'bind' function to facilitate callbacks for
138 * children of the P2P bridge.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 */
Alexander Chiang499650d2009-06-10 19:55:30 +0000140 if (dev->subordinate) {
Len Brown4be44fc2005-08-05 00:44:28 -0400141 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700142 "Device %04x:%02x:%02x.%d is a PCI bridge\n",
Alexander Chiang499650d2009-06-10 19:55:30 +0000143 pci_domain_nr(dev->bus), dev->bus->number,
144 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 device->ops.bind = acpi_pci_bind;
146 device->ops.unbind = acpi_pci_unbind;
147 }
148
149 /*
Alexander Chiang499650d2009-06-10 19:55:30 +0000150 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700154 *
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 Chiang499650d2009-06-10 19:55:30 +0000158 if (ACPI_FAILURE(status))
159 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Alexander Chiang499650d2009-06-10 19:55:30 +0000161 if (dev->subordinate)
Alexander Chiang859a3f82009-06-10 19:55:35 +0000162 bus = dev->subordinate;
Alexander Chiang499650d2009-06-10 19:55:30 +0000163 else
Alexander Chiang859a3f82009-06-10 19:55:35 +0000164 bus = dev->bus;
Alexander Chiang499650d2009-06-10 19:55:30 +0000165
Alexander Chiang859a3f82009-06-10 19:55:35 +0000166 acpi_pci_irq_add_prt(device->handle, bus);
Alexander Chiang499650d2009-06-10 19:55:30 +0000167
168out:
169 pci_dev_put(dev);
170 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171}
172
Alexander Chiang499650d2009-06-10 19:55:30 +0000173int acpi_pci_bind_root(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 device->ops.bind = acpi_pci_bind;
176 device->ops.unbind = acpi_pci_unbind;
177
Alexander Chiang499650d2009-06-10 19:55:30 +0000178 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}