ACPI: simplify acpi_pci_irq_del_prt() API
[safe/jmp/linux-2.6] / drivers / acpi / pci_bind.c
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>
27 #include <linux/types.h>
28 #include <linux/pci.h>
29 #include <linux/acpi.h>
30 #include <acpi/acpi_bus.h>
31 #include <acpi/acpi_drivers.h>
32
33 #define _COMPONENT              ACPI_PCI_COMPONENT
34 ACPI_MODULE_NAME("pci_bind");
35
36 struct acpi_pci_data {
37         struct acpi_pci_id id;
38         struct pci_bus *bus;
39         struct pci_dev *dev;
40 };
41
42 static int acpi_pci_bind(struct acpi_device *device);
43 static int acpi_pci_unbind(struct acpi_device *device);
44
45 static void acpi_pci_data_handler(acpi_handle handle, u32 function,
46                                   void *context)
47 {
48
49         /* TBD: Anything we need to do here? */
50
51         return;
52 }
53
54 /**
55  * acpi_get_pci_id
56  * ------------------
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  */
61 acpi_status acpi_get_pci_id(acpi_handle handle, struct acpi_pci_id *id)
62 {
63         int result = 0;
64         acpi_status status = AE_OK;
65         struct acpi_device *device = NULL;
66         struct acpi_pci_data *data = NULL;
67
68
69         if (!id)
70                 return AE_BAD_PARAMETER;
71
72         result = acpi_bus_get_device(handle, &device);
73         if (result) {
74                 printk(KERN_ERR PREFIX
75                             "Invalid ACPI Bus context for device %s\n",
76                             acpi_device_bid(device));
77                 return AE_NOT_EXIST;
78         }
79
80         status = acpi_get_data(handle, acpi_pci_data_handler, (void **)&data);
81         if (ACPI_FAILURE(status) || !data) {
82                 ACPI_EXCEPTION((AE_INFO, status,
83                                 "Invalid ACPI-PCI context for device %s",
84                                 acpi_device_bid(device)));
85                 return status;
86         }
87
88         *id = data->id;
89
90         /*
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,
98                           "Device %s has PCI address %04x:%02x:%02x.%d\n",
99                           acpi_device_bid(device), id->segment, id->bus,
100                           id->device, id->function));
101
102         return AE_OK;
103 }
104
105 EXPORT_SYMBOL(acpi_get_pci_id);
106
107 static int acpi_pci_unbind(struct acpi_device *device)
108 {
109         struct pci_dev *dev;
110
111         dev = acpi_get_pci_dev(device->handle);
112         if (!dev)
113                 return 0;
114
115         if (dev->subordinate)
116                 acpi_pci_irq_del_prt(dev->subordinate);
117
118         pci_dev_put(dev);
119         return 0;
120 }
121
122 static int acpi_pci_bind(struct acpi_device *device)
123 {
124         acpi_status status;
125         acpi_handle handle;
126         struct pci_bus *bus;
127         struct pci_dev *dev;
128
129         dev = acpi_get_pci_dev(device->handle);
130         if (!dev)
131                 return 0;
132
133         /*
134          * Install the 'bind' function to facilitate callbacks for
135          * children of the P2P bridge.
136          */
137         if (dev->subordinate) {
138                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
139                                   "Device %04x:%02x:%02x.%d is a PCI bridge\n",
140                                   pci_domain_nr(dev->bus), dev->bus->number,
141                                   PCI_SLOT(dev->devfn), PCI_FUNC(dev->devfn)));
142                 device->ops.bind = acpi_pci_bind;
143                 device->ops.unbind = acpi_pci_unbind;
144         }
145
146         /*
147          * Evaluate and parse _PRT, if exists.  This code allows parsing of
148          * _PRT objects within the scope of non-bridge devices.  Note that
149          * _PRTs within the scope of a PCI bridge assume the bridge's
150          * subordinate bus number.
151          *
152          * TBD: Can _PRTs exist within the scope of non-bridge PCI devices?
153          */
154         status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
155         if (ACPI_FAILURE(status))
156                 goto out;
157
158         if (dev->subordinate)
159                 bus = dev->subordinate;
160         else
161                 bus = dev->bus;
162
163         acpi_pci_irq_add_prt(device->handle, bus);
164
165 out:
166         pci_dev_put(dev);
167         return 0;
168 }
169
170 int acpi_pci_bind_root(struct acpi_device *device)
171 {
172         device->ops.bind = acpi_pci_bind;
173         device->ops.unbind = acpi_pci_unbind;
174
175         return 0;
176 }