xref: /OK3568_Linux_fs/kernel/Documentation/PCI/acpi-info.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun========================================
4*4882a593SmuzhiyunACPI considerations for PCI host bridges
5*4882a593Smuzhiyun========================================
6*4882a593Smuzhiyun
7*4882a593SmuzhiyunThe general rule is that the ACPI namespace should describe everything the
8*4882a593SmuzhiyunOS might use unless there's another way for the OS to find it [1, 2].
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunFor example, there's no standard hardware mechanism for enumerating PCI
11*4882a593Smuzhiyunhost bridges, so the ACPI namespace must describe each host bridge, the
12*4882a593Smuzhiyunmethod for accessing PCI config space below it, the address space windows
13*4882a593Smuzhiyunthe host bridge forwards to PCI (using _CRS), and the routing of legacy
14*4882a593SmuzhiyunINTx interrupts (using _PRT).
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunPCI devices, which are below the host bridge, generally do not need to be
17*4882a593Smuzhiyundescribed via ACPI.  The OS can discover them via the standard PCI
18*4882a593Smuzhiyunenumeration mechanism, using config accesses to discover and identify
19*4882a593Smuzhiyundevices and read and size their BARs.  However, ACPI may describe PCI
20*4882a593Smuzhiyundevices if it provides power management or hotplug functionality for them
21*4882a593Smuzhiyunor if the device has INTx interrupts connected by platform interrupt
22*4882a593Smuzhiyuncontrollers and a _PRT is needed to describe those connections.
23*4882a593Smuzhiyun
24*4882a593SmuzhiyunACPI resource description is done via _CRS objects of devices in the ACPI
25*4882a593Smuzhiyunnamespace [2].   The _CRS is like a generalized PCI BAR: the OS can read
26*4882a593Smuzhiyun_CRS and figure out what resource is being consumed even if it doesn't have
27*4882a593Smuzhiyuna driver for the device [3].  That's important because it means an old OS
28*4882a593Smuzhiyuncan work correctly even on a system with new devices unknown to the OS.
29*4882a593SmuzhiyunThe new devices might not do anything, but the OS can at least make sure no
30*4882a593Smuzhiyunresources conflict with them.
31*4882a593Smuzhiyun
32*4882a593SmuzhiyunStatic tables like MCFG, HPET, ECDT, etc., are *not* mechanisms for
33*4882a593Smuzhiyunreserving address space.  The static tables are for things the OS needs to
34*4882a593Smuzhiyunknow early in boot, before it can parse the ACPI namespace.  If a new table
35*4882a593Smuzhiyunis defined, an old OS needs to operate correctly even though it ignores the
36*4882a593Smuzhiyuntable.  _CRS allows that because it is generic and understood by the old
37*4882a593SmuzhiyunOS; a static table does not.
38*4882a593Smuzhiyun
39*4882a593SmuzhiyunIf the OS is expected to manage a non-discoverable device described via
40*4882a593SmuzhiyunACPI, that device will have a specific _HID/_CID that tells the OS what
41*4882a593Smuzhiyundriver to bind to it, and the _CRS tells the OS and the driver where the
42*4882a593Smuzhiyundevice's registers are.
43*4882a593Smuzhiyun
44*4882a593SmuzhiyunPCI host bridges are PNP0A03 or PNP0A08 devices.  Their _CRS should
45*4882a593Smuzhiyundescribe all the address space they consume.  This includes all the windows
46*4882a593Smuzhiyunthey forward down to the PCI bus, as well as registers of the host bridge
47*4882a593Smuzhiyunitself that are not forwarded to PCI.  The host bridge registers include
48*4882a593Smuzhiyunthings like secondary/subordinate bus registers that determine the bus
49*4882a593Smuzhiyunrange below the bridge, window registers that describe the apertures, etc.
50*4882a593SmuzhiyunThese are all device-specific, non-architected things, so the only way a
51*4882a593SmuzhiyunPNP0A03/PNP0A08 driver can manage them is via _PRS/_CRS/_SRS, which contain
52*4882a593Smuzhiyunthe device-specific details.  The host bridge registers also include ECAM
53*4882a593Smuzhiyunspace, since it is consumed by the host bridge.
54*4882a593Smuzhiyun
55*4882a593SmuzhiyunACPI defines a Consumer/Producer bit to distinguish the bridge registers
56*4882a593Smuzhiyun("Consumer") from the bridge apertures ("Producer") [4, 5], but early
57*4882a593SmuzhiyunBIOSes didn't use that bit correctly.  The result is that the current ACPI
58*4882a593Smuzhiyunspec defines Consumer/Producer only for the Extended Address Space
59*4882a593Smuzhiyundescriptors; the bit should be ignored in the older QWord/DWord/Word
60*4882a593SmuzhiyunAddress Space descriptors.  Consequently, OSes have to assume all
61*4882a593SmuzhiyunQWord/DWord/Word descriptors are windows.
62*4882a593Smuzhiyun
63*4882a593SmuzhiyunPrior to the addition of Extended Address Space descriptors, the failure of
64*4882a593SmuzhiyunConsumer/Producer meant there was no way to describe bridge registers in
65*4882a593Smuzhiyunthe PNP0A03/PNP0A08 device itself.  The workaround was to describe the
66*4882a593Smuzhiyunbridge registers (including ECAM space) in PNP0C02 catch-all devices [6].
67*4882a593SmuzhiyunWith the exception of ECAM, the bridge register space is device-specific
68*4882a593Smuzhiyunanyway, so the generic PNP0A03/PNP0A08 driver (pci_root.c) has no need to
69*4882a593Smuzhiyunknow about it.  
70*4882a593Smuzhiyun
71*4882a593SmuzhiyunNew architectures should be able to use "Consumer" Extended Address Space
72*4882a593Smuzhiyundescriptors in the PNP0A03 device for bridge registers, including ECAM,
73*4882a593Smuzhiyunalthough a strict interpretation of [6] might prohibit this.  Old x86 and
74*4882a593Smuzhiyunia64 kernels assume all address space descriptors, including "Consumer"
75*4882a593SmuzhiyunExtended Address Space ones, are windows, so it would not be safe to
76*4882a593Smuzhiyundescribe bridge registers this way on those architectures.
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunPNP0C02 "motherboard" devices are basically a catch-all.  There's no
79*4882a593Smuzhiyunprogramming model for them other than "don't use these resources for
80*4882a593Smuzhiyunanything else."  So a PNP0C02 _CRS should claim any address space that is
81*4882a593Smuzhiyun(1) not claimed by _CRS under any other device object in the ACPI namespace
82*4882a593Smuzhiyunand (2) should not be assigned by the OS to something else.
83*4882a593Smuzhiyun
84*4882a593SmuzhiyunThe PCIe spec requires the Enhanced Configuration Access Method (ECAM)
85*4882a593Smuzhiyununless there's a standard firmware interface for config access, e.g., the
86*4882a593Smuzhiyunia64 SAL interface [7].  A host bridge consumes ECAM memory address space
87*4882a593Smuzhiyunand converts memory accesses into PCI configuration accesses.  The spec
88*4882a593Smuzhiyundefines the ECAM address space layout and functionality; only the base of
89*4882a593Smuzhiyunthe address space is device-specific.  An ACPI OS learns the base address
90*4882a593Smuzhiyunfrom either the static MCFG table or a _CBA method in the PNP0A03 device.
91*4882a593Smuzhiyun
92*4882a593SmuzhiyunThe MCFG table must describe the ECAM space of non-hot pluggable host
93*4882a593Smuzhiyunbridges [8].  Since MCFG is a static table and can't be updated by hotplug,
94*4882a593Smuzhiyuna _CBA method in the PNP0A03 device describes the ECAM space of a
95*4882a593Smuzhiyunhot-pluggable host bridge [9].  Note that for both MCFG and _CBA, the base
96*4882a593Smuzhiyunaddress always corresponds to bus 0, even if the bus range below the bridge
97*4882a593Smuzhiyun(which is reported via _CRS) doesn't start at 0.
98*4882a593Smuzhiyun
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun[1] ACPI 6.2, sec 6.1:
101*4882a593Smuzhiyun    For any device that is on a non-enumerable type of bus (for example, an
102*4882a593Smuzhiyun    ISA bus), OSPM enumerates the devices' identifier(s) and the ACPI
103*4882a593Smuzhiyun    system firmware must supply an _HID object ... for each device to
104*4882a593Smuzhiyun    enable OSPM to do that.
105*4882a593Smuzhiyun
106*4882a593Smuzhiyun[2] ACPI 6.2, sec 3.7:
107*4882a593Smuzhiyun    The OS enumerates motherboard devices simply by reading through the
108*4882a593Smuzhiyun    ACPI Namespace looking for devices with hardware IDs.
109*4882a593Smuzhiyun
110*4882a593Smuzhiyun    Each device enumerated by ACPI includes ACPI-defined objects in the
111*4882a593Smuzhiyun    ACPI Namespace that report the hardware resources the device could
112*4882a593Smuzhiyun    occupy [_PRS], an object that reports the resources that are currently
113*4882a593Smuzhiyun    used by the device [_CRS], and objects for configuring those resources
114*4882a593Smuzhiyun    [_SRS].  The information is used by the Plug and Play OS (OSPM) to
115*4882a593Smuzhiyun    configure the devices.
116*4882a593Smuzhiyun
117*4882a593Smuzhiyun[3] ACPI 6.2, sec 6.2:
118*4882a593Smuzhiyun    OSPM uses device configuration objects to configure hardware resources
119*4882a593Smuzhiyun    for devices enumerated via ACPI.  Device configuration objects provide
120*4882a593Smuzhiyun    information about current and possible resource requirements, the
121*4882a593Smuzhiyun    relationship between shared resources, and methods for configuring
122*4882a593Smuzhiyun    hardware resources.
123*4882a593Smuzhiyun
124*4882a593Smuzhiyun    When OSPM enumerates a device, it calls _PRS to determine the resource
125*4882a593Smuzhiyun    requirements of the device.  It may also call _CRS to find the current
126*4882a593Smuzhiyun    resource settings for the device.  Using this information, the Plug and
127*4882a593Smuzhiyun    Play system determines what resources the device should consume and
128*4882a593Smuzhiyun    sets those resources by calling the device’s _SRS control method.
129*4882a593Smuzhiyun
130*4882a593Smuzhiyun    In ACPI, devices can consume resources (for example, legacy keyboards),
131*4882a593Smuzhiyun    provide resources (for example, a proprietary PCI bridge), or do both.
132*4882a593Smuzhiyun    Unless otherwise specified, resources for a device are assumed to be
133*4882a593Smuzhiyun    taken from the nearest matching resource above the device in the device
134*4882a593Smuzhiyun    hierarchy.
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun[4] ACPI 6.2, sec 6.4.3.5.1, 2, 3, 4:
137*4882a593Smuzhiyun    QWord/DWord/Word Address Space Descriptor (.1, .2, .3)
138*4882a593Smuzhiyun      General Flags: Bit [0] Ignored
139*4882a593Smuzhiyun
140*4882a593Smuzhiyun    Extended Address Space Descriptor (.4)
141*4882a593Smuzhiyun      General Flags: Bit [0] Consumer/Producer:
142*4882a593Smuzhiyun
143*4882a593Smuzhiyun        * 1 – This device consumes this resource
144*4882a593Smuzhiyun        * 0 – This device produces and consumes this resource
145*4882a593Smuzhiyun
146*4882a593Smuzhiyun[5] ACPI 6.2, sec 19.6.43:
147*4882a593Smuzhiyun    ResourceUsage specifies whether the Memory range is consumed by
148*4882a593Smuzhiyun    this device (ResourceConsumer) or passed on to child devices
149*4882a593Smuzhiyun    (ResourceProducer).  If nothing is specified, then
150*4882a593Smuzhiyun    ResourceConsumer is assumed.
151*4882a593Smuzhiyun
152*4882a593Smuzhiyun[6] PCI Firmware 3.2, sec 4.1.2:
153*4882a593Smuzhiyun    If the operating system does not natively comprehend reserving the
154*4882a593Smuzhiyun    MMCFG region, the MMCFG region must be reserved by firmware.  The
155*4882a593Smuzhiyun    address range reported in the MCFG table or by _CBA method (see Section
156*4882a593Smuzhiyun    4.1.3) must be reserved by declaring a motherboard resource.  For most
157*4882a593Smuzhiyun    systems, the motherboard resource would appear at the root of the ACPI
158*4882a593Smuzhiyun    namespace (under \_SB) in a node with a _HID of EISAID (PNP0C02), and
159*4882a593Smuzhiyun    the resources in this case should not be claimed in the root PCI bus’s
160*4882a593Smuzhiyun    _CRS.  The resources can optionally be returned in Int15 E820 or
161*4882a593Smuzhiyun    EFIGetMemoryMap as reserved memory but must always be reported through
162*4882a593Smuzhiyun    ACPI as a motherboard resource.
163*4882a593Smuzhiyun
164*4882a593Smuzhiyun[7] PCI Express 4.0, sec 7.2.2:
165*4882a593Smuzhiyun    For systems that are PC-compatible, or that do not implement a
166*4882a593Smuzhiyun    processor-architecture-specific firmware interface standard that allows
167*4882a593Smuzhiyun    access to the Configuration Space, the ECAM is required as defined in
168*4882a593Smuzhiyun    this section.
169*4882a593Smuzhiyun
170*4882a593Smuzhiyun[8] PCI Firmware 3.2, sec 4.1.2:
171*4882a593Smuzhiyun    The MCFG table is an ACPI table that is used to communicate the base
172*4882a593Smuzhiyun    addresses corresponding to the non-hot removable PCI Segment Groups
173*4882a593Smuzhiyun    range within a PCI Segment Group available to the operating system at
174*4882a593Smuzhiyun    boot. This is required for the PC-compatible systems.
175*4882a593Smuzhiyun
176*4882a593Smuzhiyun    The MCFG table is only used to communicate the base addresses
177*4882a593Smuzhiyun    corresponding to the PCI Segment Groups available to the system at
178*4882a593Smuzhiyun    boot.
179*4882a593Smuzhiyun
180*4882a593Smuzhiyun[9] PCI Firmware 3.2, sec 4.1.3:
181*4882a593Smuzhiyun    The _CBA (Memory mapped Configuration Base Address) control method is
182*4882a593Smuzhiyun    an optional ACPI object that returns the 64-bit memory mapped
183*4882a593Smuzhiyun    configuration base address for the hot plug capable host bridge. The
184*4882a593Smuzhiyun    base address returned by _CBA is processor-relative address. The _CBA
185*4882a593Smuzhiyun    control method evaluates to an Integer.
186*4882a593Smuzhiyun
187*4882a593Smuzhiyun    This control method appears under a host bridge object. When the _CBA
188*4882a593Smuzhiyun    method appears under an active host bridge object, the operating system
189*4882a593Smuzhiyun    evaluates this structure to identify the memory mapped configuration
190*4882a593Smuzhiyun    base address corresponding to the PCI Segment Group for the bus number
191*4882a593Smuzhiyun    range specified in _CRS method. An ACPI name space object that contains
192*4882a593Smuzhiyun    the _CBA method must also contain a corresponding _SEG method.
193