memory-devices.rst 12 KB

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