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> |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 29 | #include <linux/pci-acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/acpi.h> |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 31 | #include <linux/pm_runtime.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <acpi/acpi_bus.h> |
| 33 | #include <acpi/acpi_drivers.h> |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define _COMPONENT ACPI_PCI_COMPONENT |
Len Brown | f52fd66 | 2007-02-12 22:42:12 -0500 | [diff] [blame] | 36 | ACPI_MODULE_NAME("pci_bind"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 38 | static int acpi_pci_unbind(struct acpi_device *device) |
| 39 | { |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 40 | struct pci_dev *dev; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 41 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 42 | dev = acpi_get_pci_dev(device->handle); |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 43 | if (!dev) |
| 44 | goto out; |
| 45 | |
| 46 | device_set_run_wake(&dev->dev, false); |
| 47 | pci_acpi_remove_pm_notifier(device); |
Huang Ying | 71fbad6 | 2012-11-07 08:57:59 +0800 | [diff] [blame] | 48 | acpi_power_resource_unregister_device(&dev->dev, device->handle); |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 49 | |
| 50 | if (!dev->subordinate) |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame] | 51 | goto out; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 52 | |
Bjorn Helgaas | 79c4412 | 2012-10-30 15:24:06 +0900 | [diff] [blame] | 53 | acpi_pci_irq_del_prt(pci_domain_nr(dev->bus), dev->subordinate->number); |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 54 | |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame] | 55 | device->ops.bind = NULL; |
| 56 | device->ops.unbind = NULL; |
| 57 | |
| 58 | out: |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 59 | pci_dev_put(dev); |
| 60 | return 0; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 61 | } |
| 62 | |
Alexander Chiang | ce597bb | 2009-06-10 19:55:09 +0000 | [diff] [blame] | 63 | static int acpi_pci_bind(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | { |
Len Brown | 087da3b | 2008-12-30 22:44:33 -0500 | [diff] [blame] | 65 | acpi_status status; |
Len Brown | 087da3b | 2008-12-30 22:44:33 -0500 | [diff] [blame] | 66 | acpi_handle handle; |
Bjorn Helgaas | 79c4412 | 2012-10-30 15:24:06 +0900 | [diff] [blame] | 67 | unsigned char bus; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 68 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 70 | dev = acpi_get_pci_dev(device->handle); |
| 71 | if (!dev) |
| 72 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 74 | pci_acpi_add_pm_notifier(device, dev); |
Huang Ying | 71fbad6 | 2012-11-07 08:57:59 +0800 | [diff] [blame] | 75 | acpi_power_resource_register_device(&dev->dev, device->handle); |
Rafael J. Wysocki | b67ea76 | 2010-02-17 23:44:09 +0100 | [diff] [blame] | 76 | if (device->wakeup.flags.run_wake) |
| 77 | device_set_run_wake(&dev->dev, true); |
| 78 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | /* |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 80 | * Install the 'bind' function to facilitate callbacks for |
| 81 | * children of the P2P bridge. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | */ |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 83 | if (dev->subordinate) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 84 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bjorn Helgaas | 21a5328 | 2008-12-08 21:30:05 -0700 | [diff] [blame] | 85 | "Device %04x:%02x:%02x.%d is a PCI bridge\n", |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 86 | pci_domain_nr(dev->bus), dev->bus->number, |
| 87 | PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | device->ops.bind = acpi_pci_bind; |
| 89 | device->ops.unbind = acpi_pci_unbind; |
| 90 | } |
| 91 | |
| 92 | /* |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 93 | * Evaluate and parse _PRT, if exists. This code allows parsing of |
| 94 | * _PRT objects within the scope of non-bridge devices. Note that |
| 95 | * _PRTs within the scope of a PCI bridge assume the bridge's |
| 96 | * subordinate bus number. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | * |
| 98 | * TBD: Can _PRTs exist within the scope of non-bridge PCI devices? |
| 99 | */ |
| 100 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 101 | if (ACPI_FAILURE(status)) |
| 102 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 104 | if (dev->subordinate) |
Bjorn Helgaas | 79c4412 | 2012-10-30 15:24:06 +0900 | [diff] [blame] | 105 | bus = dev->subordinate->number; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 106 | else |
Bjorn Helgaas | 79c4412 | 2012-10-30 15:24:06 +0900 | [diff] [blame] | 107 | bus = dev->bus->number; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 108 | |
Bjorn Helgaas | 79c4412 | 2012-10-30 15:24:06 +0900 | [diff] [blame] | 109 | acpi_pci_irq_add_prt(device->handle, pci_domain_nr(dev->bus), bus); |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 110 | |
| 111 | out: |
| 112 | pci_dev_put(dev); |
| 113 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | } |
| 115 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 116 | int acpi_pci_bind_root(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | device->ops.bind = acpi_pci_bind; |
| 119 | device->ops.unbind = acpi_pci_unbind; |
| 120 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 121 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | } |