blob: 2ef04098cc1d5f4d01942d3e4de79014c4911efe [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>
Rafael J. Wysockib67ea762010-02-17 23:44:09 +010029#include <linux/pci-acpi.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/acpi.h>
Rafael J. Wysockib67ea762010-02-17 23:44:09 +010031#include <linux/pm_runtime.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070032#include <acpi/acpi_bus.h>
33#include <acpi/acpi_drivers.h>
34
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#define _COMPONENT ACPI_PCI_COMPONENT
Len Brownf52fd662007-02-12 22:42:12 -050036ACPI_MODULE_NAME("pci_bind");
Linus Torvalds1da177e2005-04-16 15:20:36 -070037
Alexander Chiangc22d7f52009-06-10 19:55:25 +000038static int acpi_pci_unbind(struct acpi_device *device)
39{
Alexander Chiang499650d2009-06-10 19:55:30 +000040 struct pci_dev *dev;
Alexander Chiangc22d7f52009-06-10 19:55:25 +000041
Alexander Chiang499650d2009-06-10 19:55:30 +000042 dev = acpi_get_pci_dev(device->handle);
Rafael J. Wysockib67ea762010-02-17 23:44:09 +010043 if (!dev)
44 goto out;
45
46 device_set_run_wake(&dev->dev, false);
47 pci_acpi_remove_pm_notifier(device);
48
49 if (!dev->subordinate)
Alexander Chiang97719a82009-06-10 19:55:45 +000050 goto out;
Alexander Chiangc22d7f52009-06-10 19:55:25 +000051
Alexander Chiang97719a82009-06-10 19:55:45 +000052 acpi_pci_irq_del_prt(dev->subordinate);
Alexander Chiangc22d7f52009-06-10 19:55:25 +000053
Alexander Chiang97719a82009-06-10 19:55:45 +000054 device->ops.bind = NULL;
55 device->ops.unbind = NULL;
56
57out:
Alexander Chiang499650d2009-06-10 19:55:30 +000058 pci_dev_put(dev);
59 return 0;
Alexander Chiangc22d7f52009-06-10 19:55:25 +000060}
61
Alexander Chiangce597bb2009-06-10 19:55:09 +000062static int acpi_pci_bind(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -070063{
Len Brown087da3b2008-12-30 22:44:33 -050064 acpi_status status;
Len Brown087da3b2008-12-30 22:44:33 -050065 acpi_handle handle;
Alexander Chiang859a3f82009-06-10 19:55:35 +000066 struct pci_bus *bus;
Alexander Chiang499650d2009-06-10 19:55:30 +000067 struct pci_dev *dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -070068
Alexander Chiang499650d2009-06-10 19:55:30 +000069 dev = acpi_get_pci_dev(device->handle);
70 if (!dev)
71 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Rafael J. Wysockib67ea762010-02-17 23:44:09 +010073 pci_acpi_add_pm_notifier(device, dev);
74 if (device->wakeup.flags.run_wake)
75 device_set_run_wake(&dev->dev, true);
76
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 /*
Alexander Chiang499650d2009-06-10 19:55:30 +000078 * Install the 'bind' function to facilitate callbacks for
79 * children of the P2P bridge.
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 */
Alexander Chiang499650d2009-06-10 19:55:30 +000081 if (dev->subordinate) {
Len Brown4be44fc2005-08-05 00:44:28 -040082 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
Bjorn Helgaas21a53282008-12-08 21:30:05 -070083 "Device %04x:%02x:%02x.%d is a PCI bridge\n",
Alexander Chiang499650d2009-06-10 19:55:30 +000084 pci_domain_nr(dev->bus), dev->bus->number,
85 PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070086 device->ops.bind = acpi_pci_bind;
87 device->ops.unbind = acpi_pci_unbind;
88 }
89
90 /*
Alexander Chiang499650d2009-06-10 19:55:30 +000091 * Evaluate and parse _PRT, if exists. This code allows parsing of
92 * _PRT objects within the scope of non-bridge devices. Note that
93 * _PRTs within the scope of a PCI bridge assume the bridge's
94 * subordinate bus number.
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 *
96 * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
97 */
98 status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
Alexander Chiang499650d2009-06-10 19:55:30 +000099 if (ACPI_FAILURE(status))
100 goto out;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
Alexander Chiang499650d2009-06-10 19:55:30 +0000102 if (dev->subordinate)
Alexander Chiang859a3f82009-06-10 19:55:35 +0000103 bus = dev->subordinate;
Alexander Chiang499650d2009-06-10 19:55:30 +0000104 else
Alexander Chiang859a3f82009-06-10 19:55:35 +0000105 bus = dev->bus;
Alexander Chiang499650d2009-06-10 19:55:30 +0000106
Alexander Chiang859a3f82009-06-10 19:55:35 +0000107 acpi_pci_irq_add_prt(device->handle, bus);
Alexander Chiang499650d2009-06-10 19:55:30 +0000108
109out:
110 pci_dev_put(dev);
111 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112}
113
Alexander Chiang499650d2009-06-10 19:55:30 +0000114int acpi_pci_bind_root(struct acpi_device *device)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 device->ops.bind = acpi_pci_bind;
117 device->ops.unbind = acpi_pci_unbind;
118
Alexander Chiang499650d2009-06-10 19:55:30 +0000119 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120}