xref: /linux/Documentation/driver-api/cxl/theory-of-operation.rst (revision 29e9359005dd1ac5f9683608891718e6a32a20a3)
1a7706472SGregory Price.. SPDX-License-Identifier: GPL-2.0
2a7706472SGregory Price.. include:: <isonum.txt>
3a7706472SGregory Price
4a7706472SGregory Price===============================================
5a7706472SGregory PriceCompute Express Link Driver Theory of Operation
6a7706472SGregory Price===============================================
7a7706472SGregory Price
8a7706472SGregory PriceA Compute Express Link Memory Device is a CXL component that implements the
9a7706472SGregory PriceCXL.mem protocol. It contains some amount of volatile memory, persistent memory,
10a7706472SGregory Priceor both. It is enumerated as a PCI device for configuration and passing
11a7706472SGregory Pricemessages over an MMIO mailbox. Its contribution to the System Physical
12a7706472SGregory PriceAddress space is handled via HDM (Host Managed Device Memory) decoders
13a7706472SGregory Pricethat optionally define a device's contribution to an interleaved address
14a7706472SGregory Pricerange across multiple devices underneath a host-bridge or interleaved
15a7706472SGregory Priceacross host-bridges.
16a7706472SGregory Price
17a7706472SGregory PriceThe CXL Bus
18a7706472SGregory Price===========
19a7706472SGregory PriceSimilar to how a RAID driver takes disk objects and assembles them into a new
20a7706472SGregory Pricelogical device, the CXL subsystem is tasked to take PCIe and ACPI objects and
21a7706472SGregory Priceassemble them into a CXL.mem decode topology. The need for runtime configuration
22a7706472SGregory Priceof the CXL.mem topology is also similar to RAID in that different environments
23a7706472SGregory Pricewith the same hardware configuration may decide to assemble the topology in
24a7706472SGregory Pricecontrasting ways. One may choose performance (RAID0) striping memory across
25a7706472SGregory Pricemultiple Host Bridges and endpoints while another may opt for fault tolerance
26a7706472SGregory Priceand disable any striping in the CXL.mem topology.
27a7706472SGregory Price
28a7706472SGregory PricePlatform firmware enumerates a menu of interleave options at the "CXL root port"
29a7706472SGregory Price(Linux term for the top of the CXL decode topology). From there, PCIe topology
30a7706472SGregory Pricedictates which endpoints can participate in which Host Bridge decode regimes.
31a7706472SGregory PriceEach PCIe Switch in the path between the root and an endpoint introduces a point
32a7706472SGregory Priceat which the interleave can be split. For example platform firmware may say at a
33a7706472SGregory Pricegiven range only decodes to 1 one Host Bridge, but that Host Bridge may in turn
34a7706472SGregory Priceinterleave cycles across multiple Root Ports. An intervening Switch between a
35a7706472SGregory Priceport and an endpoint may interleave cycles across multiple Downstream Switch
36a7706472SGregory PricePorts, etc.
37a7706472SGregory Price
38a7706472SGregory PriceHere is a sample listing of a CXL topology defined by 'cxl_test'. The 'cxl_test'
39a7706472SGregory Pricemodule generates an emulated CXL topology of 2 Host Bridges each with 2 Root
40a7706472SGregory PricePorts. Each of those Root Ports are connected to 2-way switches with endpoints
41a7706472SGregory Priceconnected to those downstream ports for a total of 8 endpoints::
42a7706472SGregory Price
43a7706472SGregory Price    # cxl list -BEMPu -b cxl_test
44a7706472SGregory Price    {
45a7706472SGregory Price      "bus":"root3",
46a7706472SGregory Price      "provider":"cxl_test",
47a7706472SGregory Price      "ports:root3":[
48a7706472SGregory Price        {
49a7706472SGregory Price          "port":"port5",
50a7706472SGregory Price          "host":"cxl_host_bridge.1",
51a7706472SGregory Price          "ports:port5":[
52a7706472SGregory Price            {
53a7706472SGregory Price              "port":"port8",
54a7706472SGregory Price              "host":"cxl_switch_uport.1",
55a7706472SGregory Price              "endpoints:port8":[
56a7706472SGregory Price                {
57a7706472SGregory Price                  "endpoint":"endpoint9",
58a7706472SGregory Price                  "host":"mem2",
59a7706472SGregory Price                  "memdev":{
60a7706472SGregory Price                    "memdev":"mem2",
61a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
62a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
63a7706472SGregory Price                    "serial":"0x1",
64a7706472SGregory Price                    "numa_node":1,
65a7706472SGregory Price                    "host":"cxl_mem.1"
66a7706472SGregory Price                  }
67a7706472SGregory Price                },
68a7706472SGregory Price                {
69a7706472SGregory Price                  "endpoint":"endpoint15",
70a7706472SGregory Price                  "host":"mem6",
71a7706472SGregory Price                  "memdev":{
72a7706472SGregory Price                    "memdev":"mem6",
73a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
74a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
75a7706472SGregory Price                    "serial":"0x5",
76a7706472SGregory Price                    "numa_node":1,
77a7706472SGregory Price                    "host":"cxl_mem.5"
78a7706472SGregory Price                  }
79a7706472SGregory Price                }
80a7706472SGregory Price              ]
81a7706472SGregory Price            },
82a7706472SGregory Price            {
83a7706472SGregory Price              "port":"port12",
84a7706472SGregory Price              "host":"cxl_switch_uport.3",
85a7706472SGregory Price              "endpoints:port12":[
86a7706472SGregory Price                {
87a7706472SGregory Price                  "endpoint":"endpoint17",
88a7706472SGregory Price                  "host":"mem8",
89a7706472SGregory Price                  "memdev":{
90a7706472SGregory Price                    "memdev":"mem8",
91a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
92a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
93a7706472SGregory Price                    "serial":"0x7",
94a7706472SGregory Price                    "numa_node":1,
95a7706472SGregory Price                    "host":"cxl_mem.7"
96a7706472SGregory Price                  }
97a7706472SGregory Price                },
98a7706472SGregory Price                {
99a7706472SGregory Price                  "endpoint":"endpoint13",
100a7706472SGregory Price                  "host":"mem4",
101a7706472SGregory Price                  "memdev":{
102a7706472SGregory Price                    "memdev":"mem4",
103a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
104a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
105a7706472SGregory Price                    "serial":"0x3",
106a7706472SGregory Price                    "numa_node":1,
107a7706472SGregory Price                    "host":"cxl_mem.3"
108a7706472SGregory Price                  }
109a7706472SGregory Price                }
110a7706472SGregory Price              ]
111a7706472SGregory Price            }
112a7706472SGregory Price          ]
113a7706472SGregory Price        },
114a7706472SGregory Price        {
115a7706472SGregory Price          "port":"port4",
116a7706472SGregory Price          "host":"cxl_host_bridge.0",
117a7706472SGregory Price          "ports:port4":[
118a7706472SGregory Price            {
119a7706472SGregory Price              "port":"port6",
120a7706472SGregory Price              "host":"cxl_switch_uport.0",
121a7706472SGregory Price              "endpoints:port6":[
122a7706472SGregory Price                {
123a7706472SGregory Price                  "endpoint":"endpoint7",
124a7706472SGregory Price                  "host":"mem1",
125a7706472SGregory Price                  "memdev":{
126a7706472SGregory Price                    "memdev":"mem1",
127a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
128a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
129a7706472SGregory Price                    "serial":"0",
130a7706472SGregory Price                    "numa_node":0,
131a7706472SGregory Price                    "host":"cxl_mem.0"
132a7706472SGregory Price                  }
133a7706472SGregory Price                },
134a7706472SGregory Price                {
135a7706472SGregory Price                  "endpoint":"endpoint14",
136a7706472SGregory Price                  "host":"mem5",
137a7706472SGregory Price                  "memdev":{
138a7706472SGregory Price                    "memdev":"mem5",
139a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
140a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
141a7706472SGregory Price                    "serial":"0x4",
142a7706472SGregory Price                    "numa_node":0,
143a7706472SGregory Price                    "host":"cxl_mem.4"
144a7706472SGregory Price                  }
145a7706472SGregory Price                }
146a7706472SGregory Price              ]
147a7706472SGregory Price            },
148a7706472SGregory Price            {
149a7706472SGregory Price              "port":"port10",
150a7706472SGregory Price              "host":"cxl_switch_uport.2",
151a7706472SGregory Price              "endpoints:port10":[
152a7706472SGregory Price                {
153a7706472SGregory Price                  "endpoint":"endpoint16",
154a7706472SGregory Price                  "host":"mem7",
155a7706472SGregory Price                  "memdev":{
156a7706472SGregory Price                    "memdev":"mem7",
157a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
158a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
159a7706472SGregory Price                    "serial":"0x6",
160a7706472SGregory Price                    "numa_node":0,
161a7706472SGregory Price                    "host":"cxl_mem.6"
162a7706472SGregory Price                  }
163a7706472SGregory Price                },
164a7706472SGregory Price                {
165a7706472SGregory Price                  "endpoint":"endpoint11",
166a7706472SGregory Price                  "host":"mem3",
167a7706472SGregory Price                  "memdev":{
168a7706472SGregory Price                    "memdev":"mem3",
169a7706472SGregory Price                    "pmem_size":"256.00 MiB (268.44 MB)",
170a7706472SGregory Price                    "ram_size":"256.00 MiB (268.44 MB)",
171a7706472SGregory Price                    "serial":"0x2",
172a7706472SGregory Price                    "numa_node":0,
173a7706472SGregory Price                    "host":"cxl_mem.2"
174a7706472SGregory Price                  }
175a7706472SGregory Price                }
176a7706472SGregory Price              ]
177a7706472SGregory Price            }
178a7706472SGregory Price          ]
179a7706472SGregory Price        }
180a7706472SGregory Price      ]
181a7706472SGregory Price    }
182a7706472SGregory Price
183a7706472SGregory PriceIn that listing each "root", "port", and "endpoint" object correspond a kernel
184a7706472SGregory Price'struct cxl_port' object. A 'cxl_port' is a device that can decode CXL.mem to
185a7706472SGregory Priceits descendants. So "root" claims non-PCIe enumerable platform decode ranges and
186a7706472SGregory Pricedecodes them to "ports", "ports" decode to "endpoints", and "endpoints"
187a7706472SGregory Pricerepresent the decode from SPA (System Physical Address) to DPA (Device Physical
188a7706472SGregory PriceAddress).
189a7706472SGregory Price
190a7706472SGregory PriceContinuing the RAID analogy, disks have both topology metadata and on device
191a7706472SGregory Pricemetadata that determine RAID set assembly. CXL Port topology and CXL Port link
192a7706472SGregory Pricestatus is metadata for CXL.mem set assembly. The CXL Port topology is enumerated
193a7706472SGregory Priceby the arrival of a CXL.mem device. I.e. unless and until the PCIe core attaches
194a7706472SGregory Pricethe cxl_pci driver to a CXL Memory Expander there is no role for CXL Port
195a7706472SGregory Priceobjects. Conversely for hot-unplug / removal scenarios, there is no need for
196a7706472SGregory Pricethe Linux PCI core to tear down switch-level CXL resources because the endpoint
197a7706472SGregory Price->remove() event cleans up the port data that was established to support that
198a7706472SGregory PriceMemory Expander.
199a7706472SGregory Price
200a7706472SGregory PriceThe port metadata and potential decode schemes that a give memory device may
201a7706472SGregory Priceparticipate can be determined via a command like::
202a7706472SGregory Price
203a7706472SGregory Price    # cxl list -BDMu -d root -m mem3
204a7706472SGregory Price    {
205a7706472SGregory Price      "bus":"root3",
206a7706472SGregory Price      "provider":"cxl_test",
207a7706472SGregory Price      "decoders:root3":[
208a7706472SGregory Price        {
209a7706472SGregory Price          "decoder":"decoder3.1",
210a7706472SGregory Price          "resource":"0x8030000000",
211a7706472SGregory Price          "size":"512.00 MiB (536.87 MB)",
212a7706472SGregory Price          "volatile_capable":true,
213a7706472SGregory Price          "nr_targets":2
214a7706472SGregory Price        },
215a7706472SGregory Price        {
216a7706472SGregory Price          "decoder":"decoder3.3",
217a7706472SGregory Price          "resource":"0x8060000000",
218a7706472SGregory Price          "size":"512.00 MiB (536.87 MB)",
219a7706472SGregory Price          "pmem_capable":true,
220a7706472SGregory Price          "nr_targets":2
221a7706472SGregory Price        },
222a7706472SGregory Price        {
223a7706472SGregory Price          "decoder":"decoder3.0",
224a7706472SGregory Price          "resource":"0x8020000000",
225a7706472SGregory Price          "size":"256.00 MiB (268.44 MB)",
226a7706472SGregory Price          "volatile_capable":true,
227a7706472SGregory Price          "nr_targets":1
228a7706472SGregory Price        },
229a7706472SGregory Price        {
230a7706472SGregory Price          "decoder":"decoder3.2",
231a7706472SGregory Price          "resource":"0x8050000000",
232a7706472SGregory Price          "size":"256.00 MiB (268.44 MB)",
233a7706472SGregory Price          "pmem_capable":true,
234a7706472SGregory Price          "nr_targets":1
235a7706472SGregory Price        }
236a7706472SGregory Price      ],
237a7706472SGregory Price      "memdevs:root3":[
238a7706472SGregory Price        {
239a7706472SGregory Price          "memdev":"mem3",
240a7706472SGregory Price          "pmem_size":"256.00 MiB (268.44 MB)",
241a7706472SGregory Price          "ram_size":"256.00 MiB (268.44 MB)",
242a7706472SGregory Price          "serial":"0x2",
243a7706472SGregory Price          "numa_node":0,
244a7706472SGregory Price          "host":"cxl_mem.2"
245a7706472SGregory Price        }
246a7706472SGregory Price      ]
247a7706472SGregory Price    }
248a7706472SGregory Price
249a7706472SGregory Price...which queries the CXL topology to ask "given CXL Memory Expander with a kernel
250a7706472SGregory Pricedevice name of 'mem3' which platform level decode ranges may this device
251a7706472SGregory Priceparticipate". A given expander can participate in multiple CXL.mem interleave
252a7706472SGregory Pricesets simultaneously depending on how many decoder resource it has. In this
253a7706472SGregory Priceexample mem3 can participate in one or more of a PMEM interleave that spans to
254a7706472SGregory PriceHost Bridges, a PMEM interleave that targets a single Host Bridge, a Volatile
255a7706472SGregory Pricememory interleave that spans 2 Host Bridges, and a Volatile memory interleave
256a7706472SGregory Pricethat only targets a single Host Bridge.
257a7706472SGregory Price
258a7706472SGregory PriceConversely the memory devices that can participate in a given platform level
259a7706472SGregory Pricedecode scheme can be determined via a command like the following::
260a7706472SGregory Price
261a7706472SGregory Price    # cxl list -MDu -d 3.2
262a7706472SGregory Price    [
263a7706472SGregory Price      {
264a7706472SGregory Price        "memdevs":[
265a7706472SGregory Price          {
266a7706472SGregory Price            "memdev":"mem1",
267a7706472SGregory Price            "pmem_size":"256.00 MiB (268.44 MB)",
268a7706472SGregory Price            "ram_size":"256.00 MiB (268.44 MB)",
269a7706472SGregory Price            "serial":"0",
270a7706472SGregory Price            "numa_node":0,
271a7706472SGregory Price            "host":"cxl_mem.0"
272a7706472SGregory Price          },
273a7706472SGregory Price          {
274a7706472SGregory Price            "memdev":"mem5",
275a7706472SGregory Price            "pmem_size":"256.00 MiB (268.44 MB)",
276a7706472SGregory Price            "ram_size":"256.00 MiB (268.44 MB)",
277a7706472SGregory Price            "serial":"0x4",
278a7706472SGregory Price            "numa_node":0,
279a7706472SGregory Price            "host":"cxl_mem.4"
280a7706472SGregory Price          },
281a7706472SGregory Price          {
282a7706472SGregory Price            "memdev":"mem7",
283a7706472SGregory Price            "pmem_size":"256.00 MiB (268.44 MB)",
284a7706472SGregory Price            "ram_size":"256.00 MiB (268.44 MB)",
285a7706472SGregory Price            "serial":"0x6",
286a7706472SGregory Price            "numa_node":0,
287a7706472SGregory Price            "host":"cxl_mem.6"
288a7706472SGregory Price          },
289a7706472SGregory Price          {
290a7706472SGregory Price            "memdev":"mem3",
291a7706472SGregory Price            "pmem_size":"256.00 MiB (268.44 MB)",
292a7706472SGregory Price            "ram_size":"256.00 MiB (268.44 MB)",
293a7706472SGregory Price            "serial":"0x2",
294a7706472SGregory Price            "numa_node":0,
295a7706472SGregory Price            "host":"cxl_mem.2"
296a7706472SGregory Price          }
297a7706472SGregory Price        ]
298a7706472SGregory Price      },
299a7706472SGregory Price      {
300a7706472SGregory Price        "root decoders":[
301a7706472SGregory Price          {
302a7706472SGregory Price            "decoder":"decoder3.2",
303a7706472SGregory Price            "resource":"0x8050000000",
304a7706472SGregory Price            "size":"256.00 MiB (268.44 MB)",
305a7706472SGregory Price            "pmem_capable":true,
306a7706472SGregory Price            "nr_targets":1
307a7706472SGregory Price          }
308a7706472SGregory Price        ]
309a7706472SGregory Price      }
310a7706472SGregory Price    ]
311a7706472SGregory Price
312a7706472SGregory Price...where the naming scheme for decoders is "decoder<port_id>.<instance_id>".
313a7706472SGregory Price
314a7706472SGregory PriceDriver Infrastructure
315a7706472SGregory Price=====================
316a7706472SGregory Price
317a7706472SGregory PriceThis section covers the driver infrastructure for a CXL memory device.
318a7706472SGregory Price
319a7706472SGregory PriceCXL Memory Device
320a7706472SGregory Price-----------------
321a7706472SGregory Price
322a7706472SGregory Price.. kernel-doc:: drivers/cxl/pci.c
323a7706472SGregory Price   :doc: cxl pci
324a7706472SGregory Price
325a7706472SGregory Price.. kernel-doc:: drivers/cxl/pci.c
326a7706472SGregory Price   :internal:
327a7706472SGregory Price
328a7706472SGregory Price.. kernel-doc:: drivers/cxl/mem.c
329a7706472SGregory Price   :doc: cxl mem
330a7706472SGregory Price
331a7706472SGregory Price.. kernel-doc:: drivers/cxl/cxlmem.h
332a7706472SGregory Price   :internal:
333a7706472SGregory Price
334a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/memdev.c
335a7706472SGregory Price   :identifiers:
336a7706472SGregory Price
337a7706472SGregory PriceCXL Port
338a7706472SGregory Price--------
339a7706472SGregory Price.. kernel-doc:: drivers/cxl/port.c
340a7706472SGregory Price   :doc: cxl port
341a7706472SGregory Price
342a7706472SGregory PriceCXL Core
343a7706472SGregory Price--------
344a7706472SGregory Price.. kernel-doc:: drivers/cxl/cxl.h
345a7706472SGregory Price   :doc: cxl objects
346a7706472SGregory Price
347a7706472SGregory Price.. kernel-doc:: drivers/cxl/cxl.h
348a7706472SGregory Price   :internal:
349a7706472SGregory Price
350d5424612SAlison Schofield.. kernel-doc:: drivers/cxl/acpi.c
351d5424612SAlison Schofield   :identifiers: add_cxl_resources
352d5424612SAlison Schofield
353a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/hdm.c
354a7706472SGregory Price   :doc: cxl core hdm
355a7706472SGregory Price
356a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/hdm.c
357a7706472SGregory Price   :identifiers:
358a7706472SGregory Price
359a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/cdat.c
360a7706472SGregory Price   :identifiers:
361a7706472SGregory Price
362a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/port.c
363a7706472SGregory Price   :doc: cxl core
364a7706472SGregory Price
365a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/port.c
366a7706472SGregory Price   :identifiers:
367a7706472SGregory Price
368a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/pci.c
369a7706472SGregory Price   :doc: cxl core pci
370a7706472SGregory Price
371a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/pci.c
372a7706472SGregory Price   :identifiers:
373a7706472SGregory Price
374a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/pmem.c
375a7706472SGregory Price   :doc: cxl pmem
376a7706472SGregory Price
377d5424612SAlison Schofield.. kernel-doc:: drivers/cxl/core/pmem.c
378d5424612SAlison Schofield   :identifiers:
379d5424612SAlison Schofield
380a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/regs.c
381a7706472SGregory Price   :doc: cxl registers
382a7706472SGregory Price
383d5424612SAlison Schofield.. kernel-doc:: drivers/cxl/core/regs.c
384d5424612SAlison Schofield   :identifiers:
385d5424612SAlison Schofield
386a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/mbox.c
387a7706472SGregory Price   :doc: cxl mbox
388a7706472SGregory Price
389d5424612SAlison Schofield.. kernel-doc:: drivers/cxl/core/mbox.c
390d5424612SAlison Schofield   :identifiers:
391d5424612SAlison Schofield
392d5424612SAlison Schofield.. kernel-doc:: drivers/cxl/core/features.c
393d5424612SAlison Schofield   :doc: cxl features
394d5424612SAlison Schofield
395*f97bdc61SAlison SchofieldSee :c:func:`devm_cxl_setup_features` for API details.
396d5424612SAlison Schofield
397a7706472SGregory PriceCXL Regions
398a7706472SGregory Price-----------
399a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/region.c
400a7706472SGregory Price   :doc: cxl core region
401a7706472SGregory Price
402a7706472SGregory Price.. kernel-doc:: drivers/cxl/core/region.c
403a7706472SGregory Price   :identifiers:
404a7706472SGregory Price
405a7706472SGregory PriceExternal Interfaces
406a7706472SGregory Price===================
407a7706472SGregory Price
408a7706472SGregory PriceCXL IOCTL Interface
409a7706472SGregory Price-------------------
410a7706472SGregory Price
411a7706472SGregory Price.. kernel-doc:: include/uapi/linux/cxl_mem.h
412a7706472SGregory Price   :doc: UAPI
413a7706472SGregory Price
414a7706472SGregory Price.. kernel-doc:: include/uapi/linux/cxl_mem.h
415a7706472SGregory Price   :internal:
416