Skip to content

Commit 5ed826f

Browse files
Robert Richterdavejiang
authored andcommitted
cxl/region: Move find_cxl_root() to cxl_add_to_region()
When adding an endpoint to a region, the root port is determined first. Move this directly into cxl_add_to_region(). This is in preparation of the initialization of endpoints that iterates the port hierarchy from the endpoint up to the root port. As a side-effect the root argument is removed from the argument lists of cxl_add_to_region() and related functions. Now, the endpoint is the only parameter to add a region. This simplifies the function interface. Signed-off-by: Robert Richter <[email protected]> Reviewed-by: Gregory Price <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Reviewed-by: Dave Jiang <[email protected]> Reviewed-by: Dan Williams <[email protected]> Reviewed-by: Alison Schofield <[email protected]> Reviewed-by: "Fabio M. De Francesco" <[email protected]> Tested-by: Gregory Price <[email protected]> Acked-by: Dan Williams <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Dave Jiang <[email protected]>
1 parent 0ee2d97 commit 5ed826f

File tree

3 files changed

+9
-18
lines changed

3 files changed

+9
-18
lines changed

drivers/cxl/core/region.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3382,9 +3382,11 @@ static struct cxl_region *construct_region(struct cxl_root_decoder *cxlrd,
33823382
return cxlr;
33833383
}
33843384

3385-
int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
3385+
int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
33863386
{
33873387
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
3388+
struct cxl_port *port = cxled_to_port(cxled);
3389+
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
33883390
struct range *hpa = &cxled->cxld.hpa_range;
33893391
struct cxl_decoder *cxld = &cxled->cxld;
33903392
struct device *cxlrd_dev, *region_dev;
@@ -3394,7 +3396,7 @@ int cxl_add_to_region(struct cxl_port *root, struct cxl_endpoint_decoder *cxled)
33943396
bool attach = false;
33953397
int rc;
33963398

3397-
cxlrd_dev = device_find_child(&root->dev, &cxld->hpa_range,
3399+
cxlrd_dev = device_find_child(&cxl_root->port.dev, &cxld->hpa_range,
33983400
match_root_decoder_by_range);
33993401
if (!cxlrd_dev) {
34003402
dev_err(cxlmd->dev.parent,

drivers/cxl/cxl.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -857,8 +857,7 @@ struct cxl_nvdimm_bridge *cxl_find_nvdimm_bridge(struct cxl_port *port);
857857
#ifdef CONFIG_CXL_REGION
858858
bool is_cxl_pmem_region(struct device *dev);
859859
struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev);
860-
int cxl_add_to_region(struct cxl_port *root,
861-
struct cxl_endpoint_decoder *cxled);
860+
int cxl_add_to_region(struct cxl_endpoint_decoder *cxled);
862861
struct cxl_dax_region *to_cxl_dax_region(struct device *dev);
863862
u64 cxl_port_get_spa_cache_alias(struct cxl_port *endpoint, u64 spa);
864863
#else
@@ -870,8 +869,7 @@ static inline struct cxl_pmem_region *to_cxl_pmem_region(struct device *dev)
870869
{
871870
return NULL;
872871
}
873-
static inline int cxl_add_to_region(struct cxl_port *root,
874-
struct cxl_endpoint_decoder *cxled)
872+
static inline int cxl_add_to_region(struct cxl_endpoint_decoder *cxled)
875873
{
876874
return 0;
877875
}

drivers/cxl/port.c

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ static void schedule_detach(void *cxlmd)
3030
schedule_cxl_memdev_detach(cxlmd);
3131
}
3232

33-
static int discover_region(struct device *dev, void *root)
33+
static int discover_region(struct device *dev, void *unused)
3434
{
3535
struct cxl_endpoint_decoder *cxled;
3636
int rc;
@@ -49,7 +49,7 @@ static int discover_region(struct device *dev, void *root)
4949
* Region enumeration is opportunistic, if this add-event fails,
5050
* continue to the next endpoint decoder.
5151
*/
52-
rc = cxl_add_to_region(root, cxled);
52+
rc = cxl_add_to_region(cxled);
5353
if (rc)
5454
dev_dbg(dev, "failed to add to region: %#llx-%#llx\n",
5555
cxled->cxld.hpa_range.start, cxled->cxld.hpa_range.end);
@@ -95,7 +95,6 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
9595
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport_dev);
9696
struct cxl_dev_state *cxlds = cxlmd->cxlds;
9797
struct cxl_hdm *cxlhdm;
98-
struct cxl_port *root;
9998
int rc;
10099

101100
rc = cxl_dvsec_rr_decode(cxlds, &info);
@@ -126,19 +125,11 @@ static int cxl_endpoint_port_probe(struct cxl_port *port)
126125
if (rc)
127126
return rc;
128127

129-
/*
130-
* This can't fail in practice as CXL root exit unregisters all
131-
* descendant ports and that in turn synchronizes with cxl_port_probe()
132-
*/
133-
struct cxl_root *cxl_root __free(put_cxl_root) = find_cxl_root(port);
134-
135-
root = &cxl_root->port;
136-
137128
/*
138129
* Now that all endpoint decoders are successfully enumerated, try to
139130
* assemble regions from committed decoders
140131
*/
141-
device_for_each_child(&port->dev, root, discover_region);
132+
device_for_each_child(&port->dev, NULL, discover_region);
142133

143134
return 0;
144135
}

0 commit comments

Comments
 (0)