blob: 6eb58ef366efeb20f6a3f77ad23e6f1afe9fc152 [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);
112 if (!dev)
113 return 0;
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000114
Alexander Chiang499650d2009-06-10 19:55:30 +0000115 if (dev->subordinate)
116 acpi_pci_irq_del_prt(pci_domain_nr(dev->bus),
117 dev->subordinate->number);
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000118
Alexander Chiang499650d2009-06-10 19:55:30 +0000119 pci_dev_put(dev);
120 return 0;
Alexander Chiangc22d7f52009-06-10 19:55:25 +0000121}
122
Alexander Chiangce597bb2009-06-10 19:55:09 +0000123static int acpi_pci_bind(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124{
Len Brown087da3b2008-12-30 22:44:33 -0500125 acpi_status status;
Len Brown087da3b2008-12-30 22:44:33 -0500126 acpi_handle handle;
Alexander Chiang859a3f82009-06-10 19:55:35 +0000127 struct pci_bus *bus;
Alexander Chiang499650d2009-06-10 19:55:30 +0000128 struct pci_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Alexander Chiang499650d2009-06-10 19:55:30 +0000130 dev = acpi_get_pci_dev(device->handle);
131 if (!dev)
132 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133
134 /*
Alexander Chiang499650d2009-06-10 19:55:30 +0000135 * Install the 'bind' function to facilitate callbacks for
136 * children of the P2P bridge.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 */
Alexander Chiang499650d2009-06-10 19:55:30 +0000138 if (dev->subordinate) {
Len Brown4be44fc2005-08-05 00:44:28 -0400139 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -0700140 "Device %04x:%02x:%02x.%d is a PCI bridge\n",
Alexander Chiang499650d2009-06-10 19:55:30 +0000141 pci_domain_nr(dev->bus), dev->bus->number,
142 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 device->ops.bind = acpi_pci_bind;
144 device->ops.unbind = acpi_pci_unbind;
145 }
146
147 /*
Alexander Chiang499650d2009-06-10 19:55:30 +0000148 * Evaluate and parse _PRT, if exists. This code allows parsing of
149 * _PRT objects within the scope of non-bridge devices. Note that
150 * _PRTs within the scope of a PCI bridge assume the bridge's
151 * subordinate bus number.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 *
153 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
154 */
155 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
Alexander Chiang499650d2009-06-10 19:55:30 +0000156 if (ACPI_FAILURE(status))
157 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158
Alexander Chiang499650d2009-06-10 19:55:30 +0000159 if (dev->subordinate)
Alexander Chiang859a3f82009-06-10 19:55:35 +0000160 bus = dev->subordinate;
Alexander Chiang499650d2009-06-10 19:55:30 +0000161 else
Alexander Chiang859a3f82009-06-10 19:55:35 +0000162 bus = dev->bus;
Alexander Chiang499650d2009-06-10 19:55:30 +0000163
Alexander Chiang859a3f82009-06-10 19:55:35 +0000164 acpi_pci_irq_add_prt(device->handle, bus);
Alexander Chiang499650d2009-06-10 19:55:30 +0000165
166out:
167 pci_dev_put(dev);
168 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Alexander Chiang499650d2009-06-10 19:55:30 +0000171int acpi_pci_bind_root(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 device->ops.bind = acpi_pci_bind;
174 device->ops.unbind = acpi_pci_unbind;
175
Alexander Chiang499650d2009-06-10 19:55:30 +0000176 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177}