1/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * File pci-acpi.h
4 *
5 * Copyright (C) 2004 Intel
6 * Copyright (C) Tom Long Nguyen (tom.l.nguyen@intel.com)
7 */
8
9#ifndef _PCI_ACPI_H_
10#define _PCI_ACPI_H_
11
12#include <linux/acpi.h>
13
14#ifdef CONFIG_ACPI
15extern acpi_status pci_acpi_add_bus_pm_notifier(struct acpi_device *dev);
16static inline acpi_status pci_acpi_remove_bus_pm_notifier(struct acpi_device *dev)
17{
18 return acpi_remove_pm_notifier(dev);
19}
20extern acpi_status pci_acpi_add_pm_notifier(struct acpi_device *dev,
21 struct pci_dev *pci_dev);
22static inline acpi_status pci_acpi_remove_pm_notifier(struct acpi_device *dev)
23{
24 return acpi_remove_pm_notifier(dev);
25}
26extern phys_addr_t acpi_pci_root_get_mcfg_addr(acpi_handle handle);
27
28struct pci_ecam_ops;
29extern int pci_mcfg_lookup(struct acpi_pci_root *root, struct resource *cfgres,
30 struct pci_ecam_ops **ecam_ops);
31
32static inline acpi_handle acpi_find_root_bridge_handle(struct pci_dev *pdev)
33{
34 struct pci_bus *pbus = pdev->bus;
35
36 /* Find a PCI root bus */
37 while (!pci_is_root_bus(pbus))
38 pbus = pbus->parent;
39
40 return ACPI_HANDLE(pbus->bridge);
41}
42
43static inline acpi_handle acpi_pci_get_bridge_handle(struct pci_bus *pbus)
44{
45 struct device *dev;
46
47 if (pci_is_root_bus(pbus))
48 dev = pbus->bridge;
49 else {
50 /* If pbus is a virtual bus, there is no bridge to it */
51 if (!pbus->self)
52 return NULL;
53
54 dev = &pbus->self->dev;
55 }
56
57 return ACPI_HANDLE(dev);
58}
59
60struct acpi_pci_root;
61struct acpi_pci_root_ops;
62
63struct acpi_pci_root_info {
64 struct acpi_pci_root *root;
65 struct acpi_device *bridge;
66 struct acpi_pci_root_ops *ops;
67 struct list_head resources;
68 char name[16];
69};
70
71struct acpi_pci_root_ops {
72 struct pci_ops *pci_ops;
73 int (*init_info)(struct acpi_pci_root_info *info);
74 void (*release_info)(struct acpi_pci_root_info *info);
75 int (*prepare_resources)(struct acpi_pci_root_info *info);
76};
77
78extern int acpi_pci_probe_root_resources(struct acpi_pci_root_info *info);
79extern struct pci_bus *acpi_pci_root_create(struct acpi_pci_root *root,
80 struct acpi_pci_root_ops *ops,
81 struct acpi_pci_root_info *info,
82 void *sd);
83
84void acpi_pci_add_bus(struct pci_bus *bus);
85void acpi_pci_remove_bus(struct pci_bus *bus);
86
87#ifdef CONFIG_ACPI_PCI_SLOT
88void acpi_pci_slot_init(void);
89void acpi_pci_slot_enumerate(struct pci_bus *bus);
90void acpi_pci_slot_remove(struct pci_bus *bus);
91#else
92static inline void acpi_pci_slot_init(void) { }
93static inline void acpi_pci_slot_enumerate(struct pci_bus *bus) { }
94static inline void acpi_pci_slot_remove(struct pci_bus *bus) { }
95#endif
96
97#ifdef CONFIG_HOTPLUG_PCI_ACPI
98void acpiphp_init(void);
99void acpiphp_enumerate_slots(struct pci_bus *bus);
100void acpiphp_remove_slots(struct pci_bus *bus);
101void acpiphp_check_host_bridge(struct acpi_device *adev);
102#else
103static inline void acpiphp_init(void) { }
104static inline void acpiphp_enumerate_slots(struct pci_bus *bus) { }
105static inline void acpiphp_remove_slots(struct pci_bus *bus) { }
106static inline void acpiphp_check_host_bridge(struct acpi_device *adev) { }
107#endif
108
109extern const guid_t pci_acpi_dsm_guid;
110#define DEVICE_LABEL_DSM 0x07
111#define RESET_DELAY_DSM 0x08
112#define FUNCTION_DELAY_DSM 0x09
113
114#else /* CONFIG_ACPI */
115static inline void acpi_pci_add_bus(struct pci_bus *bus) { }
116static inline void acpi_pci_remove_bus(struct pci_bus *bus) { }
117#endif /* CONFIG_ACPI */
118
119#ifdef CONFIG_ACPI_APEI
120extern bool aer_acpi_firmware_first(void);
121#else
122static inline bool aer_acpi_firmware_first(void) { return false; }
123#endif
124
125#endif /* _PCI_ACPI_H_ */
126