1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright(c) 2021 Intel Corporation. All rights reserved. */
3 #include <linux/platform_device.h>
4 #include <linux/module.h>
5 #include <linux/device.h>
6 #include <linux/kernel.h>
7 #include <linux/acpi.h>
9 #include <linux/node.h>
10 #include <asm/div64.h>
14 #define CXL_RCRB_SIZE SZ_8K
16 struct cxl_cxims_data
{
18 u64 xormaps
[] __counted_by(nr_maps
);
21 static const guid_t acpi_cxl_qtg_id_guid
=
22 GUID_INIT(0xF365F9A6, 0xA7DE, 0x4071,
23 0xA6, 0x6A, 0xB4, 0x0C, 0x0B, 0x4F, 0x8E, 0x52);
26 static u64
cxl_xor_hpa_to_spa(struct cxl_root_decoder
*cxlrd
, u64 hpa
)
28 struct cxl_cxims_data
*cximsd
= cxlrd
->platform_data
;
29 int hbiw
= cxlrd
->cxlsd
.nr_targets
;
33 /* No xormaps for host bridge interleave ways of 1 or 3 */
34 if (hbiw
== 1 || hbiw
== 3)
38 * For root decoders using xormaps (hbiw: 2,4,6,8,12,16) restore
39 * the position bit to its value before the xormap was applied at
40 * HPA->DPA translation.
42 * pos is the lowest set bit in an XORMAP
43 * val is the XORALLBITS(HPA & XORMAP)
45 * XORALLBITS: The CXL spec (3.1 Table 9-22) defines XORALLBITS
46 * as an operation that outputs a single bit by XORing all the
47 * bits in the input (hpa & xormap). Implement XORALLBITS using
48 * hweight64(). If the hamming weight is even the XOR of those
49 * bits results in val==0, if odd the XOR result is val==1.
52 for (int i
= 0; i
< cximsd
->nr_maps
; i
++) {
53 if (!cximsd
->xormaps
[i
])
55 pos
= __ffs(cximsd
->xormaps
[i
]);
56 val
= (hweight64(hpa
& cximsd
->xormaps
[i
]) & 1);
57 hpa
= (hpa
& ~(1ULL << pos
)) | (val
<< pos
);
63 struct cxl_cxims_context
{
65 struct cxl_root_decoder
*cxlrd
;
68 static int cxl_parse_cxims(union acpi_subtable_headers
*header
, void *arg
,
69 const unsigned long end
)
71 struct acpi_cedt_cxims
*cxims
= (struct acpi_cedt_cxims
*)header
;
72 struct cxl_cxims_context
*ctx
= arg
;
73 struct cxl_root_decoder
*cxlrd
= ctx
->cxlrd
;
74 struct cxl_decoder
*cxld
= &cxlrd
->cxlsd
.cxld
;
75 struct device
*dev
= ctx
->dev
;
76 struct cxl_cxims_data
*cximsd
;
77 unsigned int hbig
, nr_maps
;
80 rc
= eig_to_granularity(cxims
->hbig
, &hbig
);
84 /* Does this CXIMS entry apply to the given CXL Window? */
85 if (hbig
!= cxld
->interleave_granularity
)
88 /* IW 1,3 do not use xormaps and skip this parsing entirely */
89 if (is_power_of_2(cxld
->interleave_ways
))
91 nr_maps
= ilog2(cxld
->interleave_ways
);
94 nr_maps
= ilog2(cxld
->interleave_ways
/ 3);
96 if (cxims
->nr_xormaps
< nr_maps
) {
97 dev_dbg(dev
, "CXIMS nr_xormaps[%d] expected[%d]\n",
98 cxims
->nr_xormaps
, nr_maps
);
102 cximsd
= devm_kzalloc(dev
, struct_size(cximsd
, xormaps
, nr_maps
),
106 cximsd
->nr_maps
= nr_maps
;
107 memcpy(cximsd
->xormaps
, cxims
->xormap_list
,
108 nr_maps
* sizeof(*cximsd
->xormaps
));
109 cxlrd
->platform_data
= cximsd
;
114 static unsigned long cfmws_to_decoder_flags(int restrictions
)
116 unsigned long flags
= CXL_DECODER_F_ENABLE
;
118 if (restrictions
& ACPI_CEDT_CFMWS_RESTRICT_TYPE2
)
119 flags
|= CXL_DECODER_F_TYPE2
;
120 if (restrictions
& ACPI_CEDT_CFMWS_RESTRICT_TYPE3
)
121 flags
|= CXL_DECODER_F_TYPE3
;
122 if (restrictions
& ACPI_CEDT_CFMWS_RESTRICT_VOLATILE
)
123 flags
|= CXL_DECODER_F_RAM
;
124 if (restrictions
& ACPI_CEDT_CFMWS_RESTRICT_PMEM
)
125 flags
|= CXL_DECODER_F_PMEM
;
126 if (restrictions
& ACPI_CEDT_CFMWS_RESTRICT_FIXED
)
127 flags
|= CXL_DECODER_F_LOCK
;
132 static int cxl_acpi_cfmws_verify(struct device
*dev
,
133 struct acpi_cedt_cfmws
*cfmws
)
135 int rc
, expected_len
;
138 if (cfmws
->interleave_arithmetic
!= ACPI_CEDT_CFMWS_ARITHMETIC_MODULO
&&
139 cfmws
->interleave_arithmetic
!= ACPI_CEDT_CFMWS_ARITHMETIC_XOR
) {
140 dev_err(dev
, "CFMWS Unknown Interleave Arithmetic: %d\n",
141 cfmws
->interleave_arithmetic
);
145 if (!IS_ALIGNED(cfmws
->base_hpa
, SZ_256M
)) {
146 dev_err(dev
, "CFMWS Base HPA not 256MB aligned\n");
150 if (!IS_ALIGNED(cfmws
->window_size
, SZ_256M
)) {
151 dev_err(dev
, "CFMWS Window Size not 256MB aligned\n");
155 rc
= eiw_to_ways(cfmws
->interleave_ways
, &ways
);
157 dev_err(dev
, "CFMWS Interleave Ways (%d) invalid\n",
158 cfmws
->interleave_ways
);
162 expected_len
= struct_size(cfmws
, interleave_targets
, ways
);
164 if (cfmws
->header
.length
< expected_len
) {
165 dev_err(dev
, "CFMWS length %d less than expected %d\n",
166 cfmws
->header
.length
, expected_len
);
170 if (cfmws
->header
.length
> expected_len
)
171 dev_dbg(dev
, "CFMWS length %d greater than expected %d\n",
172 cfmws
->header
.length
, expected_len
);
178 * Note, @dev must be the first member, see 'struct cxl_chbs_context'
179 * and mock_acpi_table_parse_cedt()
181 struct cxl_cfmws_context
{
183 struct cxl_port
*root_port
;
184 struct resource
*cxl_res
;
189 * cxl_acpi_evaluate_qtg_dsm - Retrieve QTG ids via ACPI _DSM
190 * @handle: ACPI handle
191 * @coord: performance access coordinates
192 * @entries: number of QTG IDs to return
193 * @qos_class: int array provided by caller to return QTG IDs
195 * Return: number of QTG IDs returned, or -errno for errors
197 * Issue QTG _DSM with accompanied bandwidth and latency data in order to get
198 * the QTG IDs that are suitable for the performance point in order of most
199 * suitable to least suitable. Write back array of QTG IDs and return the
200 * actual number of QTG IDs written back.
203 cxl_acpi_evaluate_qtg_dsm(acpi_handle handle
, struct access_coordinate
*coord
,
204 int entries
, int *qos_class
)
206 union acpi_object
*out_obj
, *out_buf
, *obj
;
207 union acpi_object in_array
[4] = {
208 [0].integer
= { ACPI_TYPE_INTEGER
, coord
->read_latency
},
209 [1].integer
= { ACPI_TYPE_INTEGER
, coord
->write_latency
},
210 [2].integer
= { ACPI_TYPE_INTEGER
, coord
->read_bandwidth
},
211 [3].integer
= { ACPI_TYPE_INTEGER
, coord
->write_bandwidth
},
213 union acpi_object in_obj
= {
215 .type
= ACPI_TYPE_PACKAGE
,
217 .elements
= in_array
,
220 int count
, pkg_entries
, i
;
227 out_obj
= acpi_evaluate_dsm(handle
, &acpi_cxl_qtg_id_guid
, 1, 1, &in_obj
);
231 if (out_obj
->type
!= ACPI_TYPE_PACKAGE
) {
236 /* Check Max QTG ID */
237 obj
= &out_obj
->package
.elements
[0];
238 if (obj
->type
!= ACPI_TYPE_INTEGER
) {
243 max_qtg
= obj
->integer
.value
;
245 /* It's legal to have 0 QTG entries */
246 pkg_entries
= out_obj
->package
.count
;
247 if (pkg_entries
<= 1) {
252 /* Retrieve QTG IDs package */
253 obj
= &out_obj
->package
.elements
[1];
254 if (obj
->type
!= ACPI_TYPE_PACKAGE
) {
259 pkg_entries
= obj
->package
.count
;
260 count
= min(entries
, pkg_entries
);
261 for (i
= 0; i
< count
; i
++) {
264 out_buf
= &obj
->package
.elements
[i
];
265 if (out_buf
->type
!= ACPI_TYPE_INTEGER
) {
270 qtg_id
= out_buf
->integer
.value
;
271 if (qtg_id
> max_qtg
)
272 pr_warn("QTG ID %u greater than MAX %u\n",
275 qos_class
[i
] = qtg_id
;
284 static int cxl_acpi_qos_class(struct cxl_root
*cxl_root
,
285 struct access_coordinate
*coord
, int entries
,
288 struct device
*dev
= cxl_root
->port
.uport_dev
;
291 if (!dev_is_platform(dev
))
294 handle
= ACPI_HANDLE(dev
);
298 return cxl_acpi_evaluate_qtg_dsm(handle
, coord
, entries
, qos_class
);
301 static const struct cxl_root_ops acpi_root_ops
= {
302 .qos_class
= cxl_acpi_qos_class
,
305 static void del_cxl_resource(struct resource
*res
)
313 static struct resource
*alloc_cxl_resource(resource_size_t base
,
314 resource_size_t n
, int id
)
316 struct resource
*res
__free(kfree
) = kzalloc(sizeof(*res
), GFP_KERNEL
);
322 res
->end
= base
+ n
- 1;
323 res
->flags
= IORESOURCE_MEM
;
324 res
->name
= kasprintf(GFP_KERNEL
, "CXL Window %d", id
);
328 return no_free_ptr(res
);
331 static int add_or_reset_cxl_resource(struct resource
*parent
, struct resource
*res
)
333 int rc
= insert_resource(parent
, res
);
336 del_cxl_resource(res
);
340 DEFINE_FREE(put_cxlrd
, struct cxl_root_decoder
*,
341 if (!IS_ERR_OR_NULL(_T
)) put_device(&_T
->cxlsd
.cxld
.dev
))
342 DEFINE_FREE(del_cxl_resource
, struct resource
*, if (_T
) del_cxl_resource(_T
))
343 static int __cxl_parse_cfmws(struct acpi_cedt_cfmws
*cfmws
,
344 struct cxl_cfmws_context
*ctx
)
346 int target_map
[CXL_DECODER_MAX_INTERLEAVE
];
347 struct cxl_port
*root_port
= ctx
->root_port
;
348 struct cxl_cxims_context cxims_ctx
;
349 struct device
*dev
= ctx
->dev
;
350 struct cxl_decoder
*cxld
;
351 unsigned int ways
, i
, ig
;
354 rc
= cxl_acpi_cfmws_verify(dev
, cfmws
);
358 rc
= eiw_to_ways(cfmws
->interleave_ways
, &ways
);
361 rc
= eig_to_granularity(cfmws
->granularity
, &ig
);
364 for (i
= 0; i
< ways
; i
++)
365 target_map
[i
] = cfmws
->interleave_targets
[i
];
367 struct resource
*res
__free(del_cxl_resource
) = alloc_cxl_resource(
368 cfmws
->base_hpa
, cfmws
->window_size
, ctx
->id
++);
372 /* add to the local resource tracking to establish a sort order */
373 rc
= add_or_reset_cxl_resource(ctx
->cxl_res
, no_free_ptr(res
));
377 struct cxl_root_decoder
*cxlrd
__free(put_cxlrd
) =
378 cxl_root_decoder_alloc(root_port
, ways
);
381 return PTR_ERR(cxlrd
);
383 cxld
= &cxlrd
->cxlsd
.cxld
;
384 cxld
->flags
= cfmws_to_decoder_flags(cfmws
->restrictions
);
385 cxld
->target_type
= CXL_DECODER_HOSTONLYMEM
;
386 cxld
->hpa_range
= (struct range
) {
387 .start
= cfmws
->base_hpa
,
388 .end
= cfmws
->base_hpa
+ cfmws
->window_size
- 1,
390 cxld
->interleave_ways
= ways
;
392 * Minimize the x1 granularity to advertise support for any
393 * valid region granularity
396 ig
= CXL_DECODER_MIN_GRANULARITY
;
397 cxld
->interleave_granularity
= ig
;
399 if (cfmws
->interleave_arithmetic
== ACPI_CEDT_CFMWS_ARITHMETIC_XOR
) {
400 if (ways
!= 1 && ways
!= 3) {
401 cxims_ctx
= (struct cxl_cxims_context
) {
405 rc
= acpi_table_parse_cedt(ACPI_CEDT_TYPE_CXIMS
,
406 cxl_parse_cxims
, &cxims_ctx
);
409 if (!cxlrd
->platform_data
) {
410 dev_err(dev
, "No CXIMS for HBIG %u\n", ig
);
416 cxlrd
->qos_class
= cfmws
->qtg_id
;
418 if (cfmws
->interleave_arithmetic
== ACPI_CEDT_CFMWS_ARITHMETIC_XOR
)
419 cxlrd
->hpa_to_spa
= cxl_xor_hpa_to_spa
;
421 rc
= cxl_decoder_add(cxld
, target_map
);
424 return cxl_root_decoder_autoremove(dev
, no_free_ptr(cxlrd
));
427 static int cxl_parse_cfmws(union acpi_subtable_headers
*header
, void *arg
,
428 const unsigned long end
)
430 struct acpi_cedt_cfmws
*cfmws
= (struct acpi_cedt_cfmws
*)header
;
431 struct cxl_cfmws_context
*ctx
= arg
;
432 struct device
*dev
= ctx
->dev
;
435 rc
= __cxl_parse_cfmws(cfmws
, ctx
);
438 "Failed to add decode range: [%#llx - %#llx] (%d)\n",
440 cfmws
->base_hpa
+ cfmws
->window_size
- 1, rc
);
442 dev_dbg(dev
, "decode range: node: %d range [%#llx - %#llx]\n",
443 phys_to_target_node(cfmws
->base_hpa
), cfmws
->base_hpa
,
444 cfmws
->base_hpa
+ cfmws
->window_size
- 1);
446 /* never fail cxl_acpi load for a single window failure */
450 __mock
struct acpi_device
*to_cxl_host_bridge(struct device
*host
,
453 struct acpi_device
*adev
= to_acpi_device(dev
);
455 if (!acpi_pci_find_root(adev
->handle
))
458 if (strcmp(acpi_device_hid(adev
), "ACPI0016") == 0)
463 /* Note, @dev is used by mock_acpi_table_parse_cedt() */
464 struct cxl_chbs_context
{
466 unsigned long long uid
;
467 resource_size_t base
;
473 static int cxl_get_chbs_iter(union acpi_subtable_headers
*header
, void *arg
,
474 const unsigned long end
)
476 struct cxl_chbs_context
*ctx
= arg
;
477 struct acpi_cedt_chbs
*chbs
;
479 chbs
= (struct acpi_cedt_chbs
*) header
;
481 if (chbs
->cxl_version
== ACPI_CEDT_CHBS_VERSION_CXL11
&&
482 chbs
->length
!= CXL_RCRB_SIZE
)
488 if (ctx
->saved_version
!= chbs
->cxl_version
) {
490 * cxl_version cannot be overwritten before the next two
491 * checks, then use saved_version
493 ctx
->saved_version
= chbs
->cxl_version
;
497 if (ctx
->base
!= CXL_RESOURCE_NONE
)
500 if (ctx
->uid
!= chbs
->uid
)
503 ctx
->cxl_version
= chbs
->cxl_version
;
504 ctx
->base
= chbs
->base
;
509 static int cxl_get_chbs(struct device
*dev
, struct acpi_device
*hb
,
510 struct cxl_chbs_context
*ctx
)
512 unsigned long long uid
;
515 rc
= acpi_evaluate_integer(hb
->handle
, METHOD_NAME__UID
, NULL
, &uid
);
517 dev_err(dev
, "unable to retrieve _UID\n");
521 dev_dbg(dev
, "UID found: %lld\n", uid
);
522 *ctx
= (struct cxl_chbs_context
) {
525 .base
= CXL_RESOURCE_NONE
,
526 .cxl_version
= UINT_MAX
,
527 .saved_version
= UINT_MAX
,
530 acpi_table_parse_cedt(ACPI_CEDT_TYPE_CHBS
, cxl_get_chbs_iter
, ctx
);
532 if (ctx
->nr_versions
> 1) {
534 * Disclaim eRCD support given some component register may
535 * only be found via CHBCR
537 dev_info(dev
, "Unsupported platform config, mixed Virtual Host and Restricted CXL Host hierarchy.");
543 static int get_genport_coordinates(struct device
*dev
, struct cxl_dport
*dport
)
545 struct acpi_device
*hb
= to_cxl_host_bridge(NULL
, dev
);
548 if (kstrtou32(acpi_device_uid(hb
), 0, &uid
))
551 return acpi_get_genport_coordinates(uid
, dport
->coord
);
554 static int add_host_bridge_dport(struct device
*match
, void *arg
)
558 struct device
*bridge
;
559 struct cxl_dport
*dport
;
560 struct cxl_chbs_context ctx
;
561 struct acpi_pci_root
*pci_root
;
562 struct cxl_port
*root_port
= arg
;
563 struct device
*host
= root_port
->dev
.parent
;
564 struct acpi_device
*hb
= to_cxl_host_bridge(host
, match
);
569 rc
= cxl_get_chbs(match
, hb
, &ctx
);
573 if (ctx
.cxl_version
== UINT_MAX
) {
574 dev_warn(match
, "No CHBS found for Host Bridge (UID %lld)\n",
579 if (ctx
.base
== CXL_RESOURCE_NONE
) {
580 dev_warn(match
, "CHBS invalid for Host Bridge (UID %lld)\n",
585 pci_root
= acpi_pci_find_root(hb
->handle
);
586 bridge
= pci_root
->bus
->bridge
;
589 * In RCH mode, bind the component regs base to the dport. In
590 * VH mode it will be bound to the CXL host bridge's port
591 * object later in add_host_bridge_uport().
593 if (ctx
.cxl_version
== ACPI_CEDT_CHBS_VERSION_CXL11
) {
594 dev_dbg(match
, "RCRB found for UID %lld: %pa\n", ctx
.uid
,
596 dport
= devm_cxl_add_rch_dport(root_port
, bridge
, ctx
.uid
,
599 dport
= devm_cxl_add_dport(root_port
, bridge
, ctx
.uid
,
604 return PTR_ERR(dport
);
606 ret
= get_genport_coordinates(match
, dport
);
608 dev_dbg(match
, "Failed to get generic port perf coordinates.\n");
614 * A host bridge is a dport to a CFMWS decode and it is a uport to the
615 * dport (PCIe Root Ports) in the host bridge.
617 static int add_host_bridge_uport(struct device
*match
, void *arg
)
619 struct cxl_port
*root_port
= arg
;
620 struct device
*host
= root_port
->dev
.parent
;
621 struct acpi_device
*hb
= to_cxl_host_bridge(host
, match
);
622 struct acpi_pci_root
*pci_root
;
623 struct cxl_dport
*dport
;
624 struct cxl_port
*port
;
625 struct device
*bridge
;
626 struct cxl_chbs_context ctx
;
627 resource_size_t component_reg_phys
;
633 pci_root
= acpi_pci_find_root(hb
->handle
);
634 bridge
= pci_root
->bus
->bridge
;
635 dport
= cxl_find_dport_by_dev(root_port
, bridge
);
637 dev_dbg(host
, "host bridge expected and not found\n");
642 dev_info(bridge
, "host supports CXL (restricted)\n");
646 rc
= cxl_get_chbs(match
, hb
, &ctx
);
650 if (ctx
.cxl_version
== ACPI_CEDT_CHBS_VERSION_CXL11
) {
652 "CXL CHBS version mismatch, skip port registration\n");
656 component_reg_phys
= ctx
.base
;
657 if (component_reg_phys
!= CXL_RESOURCE_NONE
)
658 dev_dbg(match
, "CHBCR found for UID %lld: %pa\n",
659 ctx
.uid
, &component_reg_phys
);
661 rc
= devm_cxl_register_pci_bus(host
, bridge
, pci_root
->bus
);
665 port
= devm_cxl_add_port(host
, bridge
, component_reg_phys
, dport
);
667 return PTR_ERR(port
);
669 dev_info(bridge
, "host supports CXL\n");
674 static int add_root_nvdimm_bridge(struct device
*match
, void *data
)
676 struct cxl_decoder
*cxld
;
677 struct cxl_port
*root_port
= data
;
678 struct cxl_nvdimm_bridge
*cxl_nvb
;
679 struct device
*host
= root_port
->dev
.parent
;
681 if (!is_root_decoder(match
))
684 cxld
= to_cxl_decoder(match
);
685 if (!(cxld
->flags
& CXL_DECODER_F_PMEM
))
688 cxl_nvb
= devm_cxl_add_nvdimm_bridge(host
, root_port
);
689 if (IS_ERR(cxl_nvb
)) {
690 dev_dbg(host
, "failed to register pmem\n");
691 return PTR_ERR(cxl_nvb
);
693 dev_dbg(host
, "%s: add: %s\n", dev_name(&root_port
->dev
),
694 dev_name(&cxl_nvb
->dev
));
698 static struct lock_class_key cxl_root_key
;
700 static void cxl_acpi_lock_reset_class(void *dev
)
702 device_lock_reset_class(dev
);
705 static void cxl_set_public_resource(struct resource
*priv
, struct resource
*pub
)
707 priv
->desc
= (unsigned long) pub
;
710 static struct resource
*cxl_get_public_resource(struct resource
*priv
)
712 return (struct resource
*) priv
->desc
;
715 static void remove_cxl_resources(void *data
)
717 struct resource
*res
, *next
, *cxl
= data
;
719 for (res
= cxl
->child
; res
; res
= next
) {
720 struct resource
*victim
= cxl_get_public_resource(res
);
723 remove_resource(res
);
726 remove_resource(victim
);
730 del_cxl_resource(res
);
735 * add_cxl_resources() - reflect CXL fixed memory windows in iomem_resource
736 * @cxl_res: A standalone resource tree where each CXL window is a sibling
738 * Walk each CXL window in @cxl_res and add it to iomem_resource potentially
739 * expanding its boundaries to ensure that any conflicting resources become
740 * children. If a window is expanded it may then conflict with a another window
741 * entry and require the window to be truncated or trimmed. Consider this
744 * |-- "CXL Window 0" --||----- "CXL Window 1" -----|
745 * |--------------- "System RAM" -------------|
747 * ...where platform firmware has established as System RAM resource across 2
748 * windows, but has left some portion of window 1 for dynamic CXL region
749 * provisioning. In this case "Window 0" will span the entirety of the "System
750 * RAM" span, and "CXL Window 1" is truncated to the remaining tail past the end
751 * of that "System RAM" resource.
753 static int add_cxl_resources(struct resource
*cxl_res
)
755 struct resource
*res
, *new, *next
;
757 for (res
= cxl_res
->child
; res
; res
= next
) {
758 new = kzalloc(sizeof(*new), GFP_KERNEL
);
761 new->name
= res
->name
;
762 new->start
= res
->start
;
764 new->flags
= IORESOURCE_MEM
;
765 new->desc
= IORES_DESC_CXL
;
768 * Record the public resource in the private cxl_res tree for
771 cxl_set_public_resource(res
, new);
773 insert_resource_expand_to_fit(&iomem_resource
, new);
776 while (next
&& resource_overlaps(new, next
)) {
777 if (resource_contains(new, next
)) {
778 struct resource
*_next
= next
->sibling
;
780 remove_resource(next
);
781 del_cxl_resource(next
);
784 next
->start
= new->end
+ 1;
790 static int pair_cxl_resource(struct device
*dev
, void *data
)
792 struct resource
*cxl_res
= data
;
795 if (!is_root_decoder(dev
))
798 for (p
= cxl_res
->child
; p
; p
= p
->sibling
) {
799 struct cxl_root_decoder
*cxlrd
= to_cxl_root_decoder(dev
);
800 struct cxl_decoder
*cxld
= &cxlrd
->cxlsd
.cxld
;
801 struct resource res
= {
802 .start
= cxld
->hpa_range
.start
,
803 .end
= cxld
->hpa_range
.end
,
804 .flags
= IORESOURCE_MEM
,
807 if (resource_contains(p
, &res
)) {
808 cxlrd
->res
= cxl_get_public_resource(p
);
816 static int cxl_acpi_probe(struct platform_device
*pdev
)
819 struct resource
*cxl_res
;
820 struct cxl_root
*cxl_root
;
821 struct cxl_port
*root_port
;
822 struct device
*host
= &pdev
->dev
;
823 struct acpi_device
*adev
= ACPI_COMPANION(host
);
824 struct cxl_cfmws_context ctx
;
826 device_lock_set_class(&pdev
->dev
, &cxl_root_key
);
827 rc
= devm_add_action_or_reset(&pdev
->dev
, cxl_acpi_lock_reset_class
,
832 cxl_res
= devm_kzalloc(host
, sizeof(*cxl_res
), GFP_KERNEL
);
835 cxl_res
->name
= "CXL mem";
838 cxl_res
->flags
= IORESOURCE_MEM
;
840 cxl_root
= devm_cxl_add_root(host
, &acpi_root_ops
);
841 if (IS_ERR(cxl_root
))
842 return PTR_ERR(cxl_root
);
843 root_port
= &cxl_root
->port
;
845 rc
= bus_for_each_dev(adev
->dev
.bus
, NULL
, root_port
,
846 add_host_bridge_dport
);
850 rc
= devm_add_action_or_reset(host
, remove_cxl_resources
, cxl_res
);
854 ctx
= (struct cxl_cfmws_context
) {
856 .root_port
= root_port
,
859 rc
= acpi_table_parse_cedt(ACPI_CEDT_TYPE_CFMWS
, cxl_parse_cfmws
, &ctx
);
863 rc
= add_cxl_resources(cxl_res
);
868 * Populate the root decoders with their related iomem resource,
871 device_for_each_child(&root_port
->dev
, cxl_res
, pair_cxl_resource
);
874 * Root level scanned with host-bridge as dports, now scan host-bridges
875 * for their role as CXL uports to their CXL-capable PCIe Root Ports.
877 rc
= bus_for_each_dev(adev
->dev
.bus
, NULL
, root_port
,
878 add_host_bridge_uport
);
882 if (IS_ENABLED(CONFIG_CXL_PMEM
))
883 rc
= device_for_each_child(&root_port
->dev
, root_port
,
884 add_root_nvdimm_bridge
);
888 /* In case PCI is scanned before ACPI re-trigger memdev attach */
893 static const struct acpi_device_id cxl_acpi_ids
[] = {
897 MODULE_DEVICE_TABLE(acpi
, cxl_acpi_ids
);
899 static const struct platform_device_id cxl_test_ids
[] = {
903 MODULE_DEVICE_TABLE(platform
, cxl_test_ids
);
905 static struct platform_driver cxl_acpi_driver
= {
906 .probe
= cxl_acpi_probe
,
908 .name
= KBUILD_MODNAME
,
909 .acpi_match_table
= cxl_acpi_ids
,
911 .id_table
= cxl_test_ids
,
914 static int __init
cxl_acpi_init(void)
916 return platform_driver_register(&cxl_acpi_driver
);
919 static void __exit
cxl_acpi_exit(void)
921 platform_driver_unregister(&cxl_acpi_driver
);
925 /* load before dax_hmem sees 'Soft Reserved' CXL ranges */
926 subsys_initcall(cxl_acpi_init
);
929 * Arrange for host-bridge ports to be active synchronous with
930 * cxl_acpi_probe() exit.
932 MODULE_SOFTDEP("pre: cxl_port");
934 module_exit(cxl_acpi_exit
);
935 MODULE_DESCRIPTION("CXL ACPI: Platform Support");
936 MODULE_LICENSE("GPL v2");
937 MODULE_IMPORT_NS("CXL");
938 MODULE_IMPORT_NS("ACPI");