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 | |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 36 | static int acpi_pci_unbind(struct acpi_device *device) |
| 37 | { |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 38 | struct pci_dev *dev; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 39 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 40 | dev = acpi_get_pci_dev(device->handle); |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame] | 41 | if (!dev || !dev->subordinate) |
| 42 | goto out; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 43 | |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame] | 44 | acpi_pci_irq_del_prt(dev->subordinate); |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 45 | |
Alexander Chiang | 97719a8 | 2009-06-10 19:55:45 +0000 | [diff] [blame] | 46 | device->ops.bind = NULL; |
| 47 | device->ops.unbind = NULL; |
| 48 | |
| 49 | out: |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 50 | pci_dev_put(dev); |
| 51 | return 0; |
Alexander Chiang | c22d7f5 | 2009-06-10 19:55:25 +0000 | [diff] [blame] | 52 | } |
| 53 | |
Alexander Chiang | ce597bb | 2009-06-10 19:55:09 +0000 | [diff] [blame] | 54 | static int acpi_pci_bind(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | { |
Len Brown | 087da3b | 2008-12-30 22:44:33 -0500 | [diff] [blame] | 56 | acpi_status status; |
Len Brown | 087da3b | 2008-12-30 22:44:33 -0500 | [diff] [blame] | 57 | acpi_handle handle; |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 58 | struct pci_bus *bus; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 59 | struct pci_dev *dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 61 | dev = acpi_get_pci_dev(device->handle); |
| 62 | if (!dev) |
| 63 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | /* |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 66 | * Install the 'bind' function to facilitate callbacks for |
| 67 | * children of the P2P bridge. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | */ |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 69 | if (dev->subordinate) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 70 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bjorn Helgaas | 21a5328 | 2008-12-08 21:30:05 -0700 | [diff] [blame] | 71 | "Device %04x:%02x:%02x.%d is a PCI bridge\n", |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 72 | pci_domain_nr(dev->bus), dev->bus->number, |
| 73 | PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | device->ops.bind = acpi_pci_bind; |
| 75 | device->ops.unbind = acpi_pci_unbind; |
| 76 | } |
| 77 | |
| 78 | /* |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 79 | * Evaluate and parse _PRT, if exists. This code allows parsing of |
| 80 | * _PRT objects within the scope of non-bridge devices. Note that |
| 81 | * _PRTs within the scope of a PCI bridge assume the bridge's |
| 82 | * subordinate bus number. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * |
| 84 | * TBD: Can _PRTs exist within the scope of non-bridge PCI devices? |
| 85 | */ |
| 86 | status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle); |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 87 | if (ACPI_FAILURE(status)) |
| 88 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 90 | if (dev->subordinate) |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 91 | bus = dev->subordinate; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 92 | else |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 93 | bus = dev->bus; |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 94 | |
Alexander Chiang | 859a3f8 | 2009-06-10 19:55:35 +0000 | [diff] [blame] | 95 | acpi_pci_irq_add_prt(device->handle, bus); |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 96 | |
| 97 | out: |
| 98 | pci_dev_put(dev); |
| 99 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | } |
| 101 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 102 | int acpi_pci_bind_root(struct acpi_device *device) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | device->ops.bind = acpi_pci_bind; |
| 105 | device->ops.unbind = acpi_pci_unbind; |
| 106 | |
Alexander Chiang | 499650d | 2009-06-10 19:55:30 +0000 | [diff] [blame] | 107 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | } |