0e593a203ff8307cf0e1ee8f361ad4a71b688ded
[platform/adaptation/renesas_rcar/renesas_kernel.git] / drivers / acpi / pci_root.c
1 /*
2  *  pci_root.c - ACPI PCI Root Bridge Driver ($Revision: 40 $)
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/module.h>
28 #include <linux/init.h>
29 #include <linux/types.h>
30 #include <linux/mutex.h>
31 #include <linux/pm.h>
32 #include <linux/pm_runtime.h>
33 #include <linux/pci.h>
34 #include <linux/pci-acpi.h>
35 #include <linux/pci-aspm.h>
36 #include <linux/acpi.h>
37 #include <linux/slab.h>
38 #include <acpi/acpi_bus.h>
39 #include <acpi/acpi_drivers.h>
40 #include <acpi/apei.h>
41
42 #define PREFIX "ACPI: "
43
44 #define _COMPONENT              ACPI_PCI_COMPONENT
45 ACPI_MODULE_NAME("pci_root");
46 #define ACPI_PCI_ROOT_CLASS             "pci_bridge"
47 #define ACPI_PCI_ROOT_DEVICE_NAME       "PCI Root Bridge"
48 static int acpi_pci_root_add(struct acpi_device *device);
49 static int acpi_pci_root_remove(struct acpi_device *device, int type);
50
51 #define ACPI_PCIE_REQ_SUPPORT (OSC_EXT_PCI_CONFIG_SUPPORT \
52                                 | OSC_ACTIVE_STATE_PWR_SUPPORT \
53                                 | OSC_CLOCK_PWR_CAPABILITY_SUPPORT \
54                                 | OSC_MSI_SUPPORT)
55
56 static const struct acpi_device_id root_device_ids[] = {
57         {"PNP0A03", 0},
58         {"", 0},
59 };
60 MODULE_DEVICE_TABLE(acpi, root_device_ids);
61
62 static struct acpi_driver acpi_pci_root_driver = {
63         .name = "pci_root",
64         .class = ACPI_PCI_ROOT_CLASS,
65         .ids = root_device_ids,
66         .ops = {
67                 .add = acpi_pci_root_add,
68                 .remove = acpi_pci_root_remove,
69                 },
70 };
71
72 /* Lock to protect both acpi_pci_roots and acpi_pci_drivers lists */
73 static DEFINE_MUTEX(acpi_pci_root_lock);
74 static LIST_HEAD(acpi_pci_roots);
75 static LIST_HEAD(acpi_pci_drivers);
76
77 static DEFINE_MUTEX(osc_lock);
78
79 int acpi_pci_register_driver(struct acpi_pci_driver *driver)
80 {
81         int n = 0;
82         struct acpi_pci_root *root;
83
84         mutex_lock(&acpi_pci_root_lock);
85         list_add_tail(&driver->node, &acpi_pci_drivers);
86         if (driver->add)
87                 list_for_each_entry(root, &acpi_pci_roots, node) {
88                         driver->add(root);
89                         n++;
90                 }
91         mutex_unlock(&acpi_pci_root_lock);
92
93         return n;
94 }
95 EXPORT_SYMBOL(acpi_pci_register_driver);
96
97 void acpi_pci_unregister_driver(struct acpi_pci_driver *driver)
98 {
99         struct acpi_pci_root *root;
100
101         mutex_lock(&acpi_pci_root_lock);
102         list_del(&driver->node);
103         if (driver->remove)
104                 list_for_each_entry(root, &acpi_pci_roots, node)
105                         driver->remove(root);
106         mutex_unlock(&acpi_pci_root_lock);
107 }
108 EXPORT_SYMBOL(acpi_pci_unregister_driver);
109
110 acpi_handle acpi_get_pci_rootbridge_handle(unsigned int seg, unsigned int bus)
111 {
112         struct acpi_pci_root *root;
113         acpi_handle handle = NULL;
114         
115         mutex_lock(&acpi_pci_root_lock);
116         list_for_each_entry(root, &acpi_pci_roots, node)
117                 if ((root->segment == (u16) seg) &&
118                     (root->secondary.start == (u16) bus)) {
119                         handle = root->device->handle;
120                         break;
121                 }
122         mutex_unlock(&acpi_pci_root_lock);
123         return handle;
124 }
125
126 EXPORT_SYMBOL_GPL(acpi_get_pci_rootbridge_handle);
127
128 /**
129  * acpi_is_root_bridge - determine whether an ACPI CA node is a PCI root bridge
130  * @handle - the ACPI CA node in question.
131  *
132  * Note: we could make this API take a struct acpi_device * instead, but
133  * for now, it's more convenient to operate on an acpi_handle.
134  */
135 int acpi_is_root_bridge(acpi_handle handle)
136 {
137         int ret;
138         struct acpi_device *device;
139
140         ret = acpi_bus_get_device(handle, &device);
141         if (ret)
142                 return 0;
143
144         ret = acpi_match_device_ids(device, root_device_ids);
145         if (ret)
146                 return 0;
147         else
148                 return 1;
149 }
150 EXPORT_SYMBOL_GPL(acpi_is_root_bridge);
151
152 static acpi_status
153 get_root_bridge_busnr_callback(struct acpi_resource *resource, void *data)
154 {
155         struct resource *res = data;
156         struct acpi_resource_address64 address;
157
158         if (resource->type != ACPI_RESOURCE_TYPE_ADDRESS16 &&
159             resource->type != ACPI_RESOURCE_TYPE_ADDRESS32 &&
160             resource->type != ACPI_RESOURCE_TYPE_ADDRESS64)
161                 return AE_OK;
162
163         acpi_resource_to_address64(resource, &address);
164         if ((address.address_length > 0) &&
165             (address.resource_type == ACPI_BUS_NUMBER_RANGE)) {
166                 res->start = address.minimum;
167                 res->end = address.minimum + address.address_length - 1;
168         }
169
170         return AE_OK;
171 }
172
173 static acpi_status try_get_root_bridge_busnr(acpi_handle handle,
174                                              struct resource *res)
175 {
176         acpi_status status;
177
178         res->start = -1;
179         status =
180             acpi_walk_resources(handle, METHOD_NAME__CRS,
181                                 get_root_bridge_busnr_callback, res);
182         if (ACPI_FAILURE(status))
183                 return status;
184         if (res->start == -1)
185                 return AE_ERROR;
186         return AE_OK;
187 }
188
189 static void acpi_pci_bridge_scan(struct acpi_device *device)
190 {
191         int status;
192         struct acpi_device *child = NULL;
193
194         if (device->flags.bus_address)
195                 if (device->parent && device->parent->ops.bind) {
196                         status = device->parent->ops.bind(device);
197                         if (!status) {
198                                 list_for_each_entry(child, &device->children, node)
199                                         acpi_pci_bridge_scan(child);
200                         }
201                 }
202 }
203
204 static u8 pci_osc_uuid_str[] = "33DB4D5B-1FF7-401C-9657-7441C03DD766";
205
206 static acpi_status acpi_pci_run_osc(acpi_handle handle,
207                                     const u32 *capbuf, u32 *retval)
208 {
209         struct acpi_osc_context context = {
210                 .uuid_str = pci_osc_uuid_str,
211                 .rev = 1,
212                 .cap.length = 12,
213                 .cap.pointer = (void *)capbuf,
214         };
215         acpi_status status;
216
217         status = acpi_run_osc(handle, &context);
218         if (ACPI_SUCCESS(status)) {
219                 *retval = *((u32 *)(context.ret.pointer + 8));
220                 kfree(context.ret.pointer);
221         }
222         return status;
223 }
224
225 static acpi_status acpi_pci_query_osc(struct acpi_pci_root *root,
226                                         u32 support,
227                                         u32 *control)
228 {
229         acpi_status status;
230         u32 result, capbuf[3];
231
232         support &= OSC_PCI_SUPPORT_MASKS;
233         support |= root->osc_support_set;
234
235         capbuf[OSC_QUERY_TYPE] = OSC_QUERY_ENABLE;
236         capbuf[OSC_SUPPORT_TYPE] = support;
237         if (control) {
238                 *control &= OSC_PCI_CONTROL_MASKS;
239                 capbuf[OSC_CONTROL_TYPE] = *control | root->osc_control_set;
240         } else {
241                 /* Run _OSC query for all possible controls. */
242                 capbuf[OSC_CONTROL_TYPE] = OSC_PCI_CONTROL_MASKS;
243         }
244
245         status = acpi_pci_run_osc(root->device->handle, capbuf, &result);
246         if (ACPI_SUCCESS(status)) {
247                 root->osc_support_set = support;
248                 if (control)
249                         *control = result;
250         }
251         return status;
252 }
253
254 static acpi_status acpi_pci_osc_support(struct acpi_pci_root *root, u32 flags)
255 {
256         acpi_status status;
257         acpi_handle tmp;
258
259         status = acpi_get_handle(root->device->handle, "_OSC", &tmp);
260         if (ACPI_FAILURE(status))
261                 return status;
262         mutex_lock(&osc_lock);
263         status = acpi_pci_query_osc(root, flags, NULL);
264         mutex_unlock(&osc_lock);
265         return status;
266 }
267
268 struct acpi_pci_root *acpi_pci_find_root(acpi_handle handle)
269 {
270         struct acpi_pci_root *root;
271         struct acpi_device *device;
272
273         if (acpi_bus_get_device(handle, &device) ||
274             acpi_match_device_ids(device, root_device_ids))
275                 return NULL;
276
277         root = acpi_driver_data(device);
278
279         return root;
280 }
281 EXPORT_SYMBOL_GPL(acpi_pci_find_root);
282
283 struct acpi_handle_node {
284         struct list_head node;
285         acpi_handle handle;
286 };
287
288 /**
289  * acpi_get_pci_dev - convert ACPI CA handle to struct pci_dev
290  * @handle: the handle in question
291  *
292  * Given an ACPI CA handle, the desired PCI device is located in the
293  * list of PCI devices.
294  *
295  * If the device is found, its reference count is increased and this
296  * function returns a pointer to its data structure.  The caller must
297  * decrement the reference count by calling pci_dev_put().
298  * If no device is found, %NULL is returned.
299  */
300 struct pci_dev *acpi_get_pci_dev(acpi_handle handle)
301 {
302         int dev, fn;
303         unsigned long long adr;
304         acpi_status status;
305         acpi_handle phandle;
306         struct pci_bus *pbus;
307         struct pci_dev *pdev = NULL;
308         struct acpi_handle_node *node, *tmp;
309         struct acpi_pci_root *root;
310         LIST_HEAD(device_list);
311
312         /*
313          * Walk up the ACPI CA namespace until we reach a PCI root bridge.
314          */
315         phandle = handle;
316         while (!acpi_is_root_bridge(phandle)) {
317                 node = kzalloc(sizeof(struct acpi_handle_node), GFP_KERNEL);
318                 if (!node)
319                         goto out;
320
321                 INIT_LIST_HEAD(&node->node);
322                 node->handle = phandle;
323                 list_add(&node->node, &device_list);
324
325                 status = acpi_get_parent(phandle, &phandle);
326                 if (ACPI_FAILURE(status))
327                         goto out;
328         }
329
330         root = acpi_pci_find_root(phandle);
331         if (!root)
332                 goto out;
333
334         pbus = root->bus;
335
336         /*
337          * Now, walk back down the PCI device tree until we return to our
338          * original handle. Assumes that everything between the PCI root
339          * bridge and the device we're looking for must be a P2P bridge.
340          */
341         list_for_each_entry(node, &device_list, node) {
342                 acpi_handle hnd = node->handle;
343                 status = acpi_evaluate_integer(hnd, "_ADR", NULL, &adr);
344                 if (ACPI_FAILURE(status))
345                         goto out;
346                 dev = (adr >> 16) & 0xffff;
347                 fn  = adr & 0xffff;
348
349                 pdev = pci_get_slot(pbus, PCI_DEVFN(dev, fn));
350                 if (!pdev || hnd == handle)
351                         break;
352
353                 pbus = pdev->subordinate;
354                 pci_dev_put(pdev);
355
356                 /*
357                  * This function may be called for a non-PCI device that has a
358                  * PCI parent (eg. a disk under a PCI SATA controller).  In that
359                  * case pdev->subordinate will be NULL for the parent.
360                  */
361                 if (!pbus) {
362                         dev_dbg(&pdev->dev, "Not a PCI-to-PCI bridge\n");
363                         pdev = NULL;
364                         break;
365                 }
366         }
367 out:
368         list_for_each_entry_safe(node, tmp, &device_list, node)
369                 kfree(node);
370
371         return pdev;
372 }
373 EXPORT_SYMBOL_GPL(acpi_get_pci_dev);
374
375 /**
376  * acpi_pci_osc_control_set - Request control of PCI root _OSC features.
377  * @handle: ACPI handle of a PCI root bridge (or PCIe Root Complex).
378  * @mask: Mask of _OSC bits to request control of, place to store control mask.
379  * @req: Mask of _OSC bits the control of is essential to the caller.
380  *
381  * Run _OSC query for @mask and if that is successful, compare the returned
382  * mask of control bits with @req.  If all of the @req bits are set in the
383  * returned mask, run _OSC request for it.
384  *
385  * The variable at the @mask address may be modified regardless of whether or
386  * not the function returns success.  On success it will contain the mask of
387  * _OSC bits the BIOS has granted control of, but its contents are meaningless
388  * on failure.
389  **/
390 acpi_status acpi_pci_osc_control_set(acpi_handle handle, u32 *mask, u32 req)
391 {
392         struct acpi_pci_root *root;
393         acpi_status status;
394         u32 ctrl, capbuf[3];
395         acpi_handle tmp;
396
397         if (!mask)
398                 return AE_BAD_PARAMETER;
399
400         ctrl = *mask & OSC_PCI_CONTROL_MASKS;
401         if ((ctrl & req) != req)
402                 return AE_TYPE;
403
404         root = acpi_pci_find_root(handle);
405         if (!root)
406                 return AE_NOT_EXIST;
407
408         status = acpi_get_handle(handle, "_OSC", &tmp);
409         if (ACPI_FAILURE(status))
410                 return status;
411
412         mutex_lock(&osc_lock);
413
414         *mask = ctrl | root->osc_control_set;
415         /* No need to evaluate _OSC if the control was already granted. */
416         if ((root->osc_control_set & ctrl) == ctrl)
417                 goto out;
418
419         /* Need to check the available controls bits before requesting them. */
420         while (*mask) {
421                 status = acpi_pci_query_osc(root, root->osc_support_set, mask);
422                 if (ACPI_FAILURE(status))
423                         goto out;
424                 if (ctrl == *mask)
425                         break;
426                 ctrl = *mask;
427         }
428
429         if ((ctrl & req) != req) {
430                 status = AE_SUPPORT;
431                 goto out;
432         }
433
434         capbuf[OSC_QUERY_TYPE] = 0;
435         capbuf[OSC_SUPPORT_TYPE] = root->osc_support_set;
436         capbuf[OSC_CONTROL_TYPE] = ctrl;
437         status = acpi_pci_run_osc(handle, capbuf, mask);
438         if (ACPI_SUCCESS(status))
439                 root->osc_control_set = *mask;
440 out:
441         mutex_unlock(&osc_lock);
442         return status;
443 }
444 EXPORT_SYMBOL(acpi_pci_osc_control_set);
445
446 static int acpi_pci_root_add(struct acpi_device *device)
447 {
448         unsigned long long segment, bus;
449         acpi_status status;
450         int result;
451         struct acpi_pci_root *root;
452         acpi_handle handle;
453         struct acpi_device *child;
454         struct acpi_pci_driver *driver;
455         u32 flags, base_flags;
456         bool is_osc_granted = false;
457
458         root = kzalloc(sizeof(struct acpi_pci_root), GFP_KERNEL);
459         if (!root)
460                 return -ENOMEM;
461
462         segment = 0;
463         status = acpi_evaluate_integer(device->handle, METHOD_NAME__SEG, NULL,
464                                        &segment);
465         if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
466                 printk(KERN_ERR PREFIX "can't evaluate _SEG\n");
467                 result = -ENODEV;
468                 goto end;
469         }
470
471         /* Check _CRS first, then _BBN.  If no _BBN, default to zero. */
472         root->secondary.flags = IORESOURCE_BUS;
473         status = try_get_root_bridge_busnr(device->handle, &root->secondary);
474         if (ACPI_FAILURE(status)) {
475                 /*
476                  * We need both the start and end of the downstream bus range
477                  * to interpret _CBA (MMCONFIG base address), so it really is
478                  * supposed to be in _CRS.  If we don't find it there, all we
479                  * can do is assume [_BBN-0xFF] or [0-0xFF].
480                  */
481                 root->secondary.end = 0xFF;
482                 printk(KERN_WARNING FW_BUG PREFIX
483                        "no secondary bus range in _CRS\n");
484                 status = acpi_evaluate_integer(device->handle, METHOD_NAME__BBN,
485                                                NULL, &bus);
486                 if (ACPI_SUCCESS(status))
487                         root->secondary.start = bus;
488                 else if (status == AE_NOT_FOUND)
489                         root->secondary.start = 0;
490                 else {
491                         printk(KERN_ERR PREFIX "can't evaluate _BBN\n");
492                         result = -ENODEV;
493                         goto end;
494                 }
495         }
496
497         INIT_LIST_HEAD(&root->node);
498         root->device = device;
499         root->segment = segment & 0xFFFF;
500         strcpy(acpi_device_name(device), ACPI_PCI_ROOT_DEVICE_NAME);
501         strcpy(acpi_device_class(device), ACPI_PCI_ROOT_CLASS);
502         device->driver_data = root;
503
504         printk(KERN_INFO PREFIX "%s [%s] (domain %04x %pR)\n",
505                acpi_device_name(device), acpi_device_bid(device),
506                root->segment, &root->secondary);
507
508         /*
509          * PCI Routing Table
510          * -----------------
511          * Evaluate and parse _PRT, if exists.
512          */
513         status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
514         if (ACPI_SUCCESS(status))
515                 result = acpi_pci_irq_add_prt(device->handle, root->segment,
516                                               root->secondary.start);
517
518         root->mcfg_addr = acpi_pci_root_get_mcfg_addr(device->handle);
519
520         /*
521          * All supported architectures that use ACPI have support for
522          * PCI domains, so we indicate this in _OSC support capabilities.
523          */
524         flags = base_flags = OSC_PCI_SEGMENT_GROUPS_SUPPORT;
525         acpi_pci_osc_support(root, flags);
526
527         /* Indicate support for various _OSC capabilities. */
528         if (pci_ext_cfg_avail())
529                 flags |= OSC_EXT_PCI_CONFIG_SUPPORT;
530         if (pcie_aspm_support_enabled()) {
531                 flags |= OSC_ACTIVE_STATE_PWR_SUPPORT |
532                 OSC_CLOCK_PWR_CAPABILITY_SUPPORT;
533         }
534         if (pci_msi_enabled())
535                 flags |= OSC_MSI_SUPPORT;
536         if (flags != base_flags) {
537                 status = acpi_pci_osc_support(root, flags);
538                 if (ACPI_FAILURE(status)) {
539                         dev_info(&device->dev, "ACPI _OSC support "
540                                 "notification failed, disabling PCIe ASPM\n");
541                         pcie_no_aspm();
542                         flags = base_flags;
543                 }
544         }
545         if (!pcie_ports_disabled
546             && (flags & ACPI_PCIE_REQ_SUPPORT) == ACPI_PCIE_REQ_SUPPORT) {
547                 flags = OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL
548                         | OSC_PCI_EXPRESS_NATIVE_HP_CONTROL
549                         | OSC_PCI_EXPRESS_PME_CONTROL;
550
551                 if (pci_aer_available()) {
552                         if (aer_acpi_firmware_first())
553                                 dev_dbg(&device->dev,
554                                         "PCIe errors handled by BIOS.\n");
555                         else
556                                 flags |= OSC_PCI_EXPRESS_AER_CONTROL;
557                 }
558
559                 dev_info(&device->dev,
560                         "Requesting ACPI _OSC control (0x%02x)\n", flags);
561
562                 status = acpi_pci_osc_control_set(device->handle, &flags,
563                                        OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL);
564                 if (ACPI_SUCCESS(status)) {
565                         is_osc_granted = true;
566                         dev_info(&device->dev,
567                                 "ACPI _OSC control (0x%02x) granted\n", flags);
568                 } else {
569                         is_osc_granted = false;
570                         dev_info(&device->dev,
571                                 "ACPI _OSC request failed (%s), "
572                                 "returned control mask: 0x%02x\n",
573                                 acpi_format_exception(status), flags);
574                 }
575         } else {
576                 dev_info(&device->dev,
577                         "Unable to request _OSC control "
578                         "(_OSC support mask: 0x%02x)\n", flags);
579         }
580
581         /*
582          * TBD: Need PCI interface for enumeration/configuration of roots.
583          */
584
585         mutex_lock(&acpi_pci_root_lock);
586         list_add_tail(&root->node, &acpi_pci_roots);
587         mutex_unlock(&acpi_pci_root_lock);
588
589         /*
590          * Scan the Root Bridge
591          * --------------------
592          * Must do this prior to any attempt to bind the root device, as the
593          * PCI namespace does not get created until this call is made (and 
594          * thus the root bridge's pci_dev does not exist).
595          */
596         root->bus = pci_acpi_scan_root(root);
597         if (!root->bus) {
598                 printk(KERN_ERR PREFIX
599                             "Bus %04x:%02x not present in PCI namespace\n",
600                             root->segment, (unsigned int)root->secondary.start);
601                 result = -ENODEV;
602                 goto out_del_root;
603         }
604
605         /*
606          * Attach ACPI-PCI Context
607          * -----------------------
608          * Thus binding the ACPI and PCI devices.
609          */
610         result = acpi_pci_bind_root(device);
611         if (result)
612                 goto out_del_root;
613
614         /*
615          * Scan and bind all _ADR-Based Devices
616          */
617         list_for_each_entry(child, &device->children, node)
618                 acpi_pci_bridge_scan(child);
619
620         /* ASPM setting */
621         if (is_osc_granted) {
622                 if (acpi_gbl_FADT.boot_flags & ACPI_FADT_NO_ASPM)
623                         pcie_clear_aspm(root->bus);
624         } else {
625                 pr_info("ACPI _OSC control for PCIe not granted, "
626                         "disabling ASPM\n");
627                 pcie_no_aspm();
628         }
629
630         pci_acpi_add_bus_pm_notifier(device, root->bus);
631         if (device->wakeup.flags.run_wake)
632                 device_set_run_wake(root->bus->bridge, true);
633
634         if (system_state != SYSTEM_BOOTING)
635                 pci_assign_unassigned_bus_resources(root->bus);
636
637         mutex_lock(&acpi_pci_root_lock);
638         list_for_each_entry(driver, &acpi_pci_drivers, node)
639                 if (driver->add)
640                         driver->add(root);
641         mutex_unlock(&acpi_pci_root_lock);
642
643         /* need to after hot-added ioapic is registered */
644         if (system_state != SYSTEM_BOOTING)
645                 pci_enable_bridges(root->bus);
646
647         pci_bus_add_devices(root->bus);
648         return 0;
649
650 out_del_root:
651         mutex_lock(&acpi_pci_root_lock);
652         list_del(&root->node);
653         mutex_unlock(&acpi_pci_root_lock);
654
655         acpi_pci_irq_del_prt(root->segment, root->secondary.start);
656 end:
657         kfree(root);
658         return result;
659 }
660
661 static int acpi_pci_root_remove(struct acpi_device *device, int type)
662 {
663         acpi_status status;
664         acpi_handle handle;
665         struct acpi_pci_root *root = acpi_driver_data(device);
666         struct acpi_pci_driver *driver;
667
668         pci_stop_root_bus(root->bus);
669
670         mutex_lock(&acpi_pci_root_lock);
671         list_for_each_entry_reverse(driver, &acpi_pci_drivers, node)
672                 if (driver->remove)
673                         driver->remove(root);
674         mutex_unlock(&acpi_pci_root_lock);
675
676         device_set_run_wake(root->bus->bridge, false);
677         pci_acpi_remove_bus_pm_notifier(device);
678
679         status = acpi_get_handle(device->handle, METHOD_NAME__PRT, &handle);
680         if (ACPI_SUCCESS(status))
681                 acpi_pci_irq_del_prt(root->segment, root->secondary.start);
682
683         pci_remove_root_bus(root->bus);
684
685         mutex_lock(&acpi_pci_root_lock);
686         list_del(&root->node);
687         mutex_unlock(&acpi_pci_root_lock);
688         kfree(root);
689         return 0;
690 }
691
692 int __init acpi_pci_root_init(void)
693 {
694         acpi_hest_init();
695
696         if (acpi_pci_disabled)
697                 return 0;
698
699         pci_acpi_crs_quirks();
700         if (acpi_bus_register_driver(&acpi_pci_root_driver) < 0)
701                 return -ENODEV;
702
703         return 0;
704 }