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