Skip to content

Commit fcfbc93

Browse files
committed
cxl/port: Reuse 'struct cxl_hdm' context for hdm init
The port driver maps component registers for port operations. Reuse that mapping for HDM Decoder Capability setup / enable. Move devm_cxl_setup_hdm() before cxl_hdm_decode_init() and plumb @cxlhdm through the hdm init helpers. Reviewed-by: Ira Weiny <ira.weiny@intel.com> Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Link: https://lore.kernel.org/r/165291691712.1426646.14336397551571515480.stgit@dwillia2-xfh Signed-off-by: Dan Williams <dan.j.williams@intel.com>
1 parent 5e5f4ad commit fcfbc93

4 files changed

Lines changed: 28 additions & 43 deletions

File tree

drivers/cxl/core/pci.c

Lines changed: 10 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -176,29 +176,14 @@ static int wait_for_valid(struct cxl_dev_state *cxlds)
176176
}
177177

178178
static bool __cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
179+
struct cxl_hdm *cxlhdm,
179180
struct cxl_endpoint_dvsec_info *info)
180181
{
181-
struct cxl_register_map map;
182-
struct cxl_component_reg_map *cmap = &map.component_map;
183-
bool global_enable, retval = false;
184-
void __iomem *crb;
182+
void __iomem *hdm = cxlhdm->regs.hdm_decoder;
183+
bool global_enable;
185184
u32 global_ctrl;
186185

187-
/* map hdm decoder */
188-
crb = ioremap(cxlds->component_reg_phys, CXL_COMPONENT_REG_BLOCK_SIZE);
189-
if (!crb) {
190-
dev_dbg(cxlds->dev, "Failed to map component registers\n");
191-
return false;
192-
}
193-
194-
cxl_probe_component_regs(cxlds->dev, crb, cmap);
195-
if (!cmap->hdm_decoder.valid) {
196-
dev_dbg(cxlds->dev, "Invalid HDM decoder registers\n");
197-
goto out;
198-
}
199-
200-
global_ctrl = readl(crb + cmap->hdm_decoder.offset +
201-
CXL_HDM_DECODER_CTRL_OFFSET);
186+
global_ctrl = readl(hdm + CXL_HDM_DECODER_CTRL_OFFSET);
202187
global_enable = global_ctrl & CXL_HDM_DECODER_ENABLE;
203188

204189
/*
@@ -210,9 +195,7 @@ static bool __cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
210195
* match.
211196
*/
212197
if (!global_enable && info->mem_enabled && info->ranges)
213-
goto out;
214-
215-
retval = true;
198+
return false;
216199

217200
/*
218201
* Permanently (for this boot at least) opt the device into HDM
@@ -222,22 +205,20 @@ static bool __cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
222205
if (!global_enable) {
223206
dev_dbg(cxlds->dev, "Enabling HDM decode\n");
224207
writel(global_ctrl | CXL_HDM_DECODER_ENABLE,
225-
crb + cmap->hdm_decoder.offset +
226-
CXL_HDM_DECODER_CTRL_OFFSET);
208+
hdm + CXL_HDM_DECODER_CTRL_OFFSET);
227209
}
228210

229-
out:
230-
iounmap(crb);
231-
return retval;
211+
return true;
232212
}
233213

234214
/**
235215
* cxl_hdm_decode_init() - Setup HDM decoding for the endpoint
236216
* @cxlds: Device state
217+
* @cxlhdm: Mapped HDM decoder Capability
237218
*
238219
* Try to enable the endpoint's HDM Decoder Capability
239220
*/
240-
int cxl_hdm_decode_init(struct cxl_dev_state *cxlds)
221+
int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm)
241222
{
242223
struct pci_dev *pdev = to_pci_dev(cxlds->dev);
243224
struct cxl_endpoint_dvsec_info info = { 0 };
@@ -331,7 +312,7 @@ int cxl_hdm_decode_init(struct cxl_dev_state *cxlds)
331312
* If DVSEC ranges are being used instead of HDM decoder registers there
332313
* is no use in trying to manage those.
333314
*/
334-
if (!__cxl_hdm_decode_init(cxlds, &info)) {
315+
if (!__cxl_hdm_decode_init(cxlds, cxlhdm, &info)) {
335316
dev_err(dev,
336317
"Legacy range registers configuration prevents HDM operation.\n");
337318
return -EBUSY;

drivers/cxl/cxlpci.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,5 +73,5 @@ static inline resource_size_t cxl_regmap_to_base(struct pci_dev *pdev,
7373

7474
int devm_cxl_port_enumerate_dports(struct cxl_port *port);
7575
struct cxl_dev_state;
76-
int cxl_hdm_decode_init(struct cxl_dev_state *cxlds);
76+
int cxl_hdm_decode_init(struct cxl_dev_state *cxlds, struct cxl_hdm *cxlhdm);
7777
#endif /* __CXL_PCI_H__ */

drivers/cxl/port.c

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,19 @@ static int cxl_port_probe(struct device *dev)
3636
struct cxl_hdm *cxlhdm;
3737
int rc;
3838

39+
40+
if (!is_cxl_endpoint(port)) {
41+
rc = devm_cxl_port_enumerate_dports(port);
42+
if (rc < 0)
43+
return rc;
44+
if (rc == 1)
45+
return devm_cxl_add_passthrough_decoder(port);
46+
}
47+
48+
cxlhdm = devm_cxl_setup_hdm(port);
49+
if (IS_ERR(cxlhdm))
50+
return PTR_ERR(cxlhdm);
51+
3952
if (is_cxl_endpoint(port)) {
4053
struct cxl_memdev *cxlmd = to_cxl_memdev(port->uport);
4154
struct cxl_dev_state *cxlds = cxlmd->cxlds;
@@ -45,7 +58,7 @@ static int cxl_port_probe(struct device *dev)
4558
if (rc)
4659
return rc;
4760

48-
rc = cxl_hdm_decode_init(cxlds);
61+
rc = cxl_hdm_decode_init(cxlds, cxlhdm);
4962
if (rc)
5063
return rc;
5164

@@ -54,18 +67,8 @@ static int cxl_port_probe(struct device *dev)
5467
dev_err(dev, "Media not active (%d)\n", rc);
5568
return rc;
5669
}
57-
} else {
58-
rc = devm_cxl_port_enumerate_dports(port);
59-
if (rc < 0)
60-
return rc;
61-
if (rc == 1)
62-
return devm_cxl_add_passthrough_decoder(port);
6370
}
6471

65-
cxlhdm = devm_cxl_setup_hdm(port);
66-
if (IS_ERR(cxlhdm))
67-
return PTR_ERR(cxlhdm);
68-
6972
rc = devm_cxl_enumerate_decoders(cxlhdm);
7073
if (rc) {
7174
dev_err(dev, "Couldn't enumerate decoders (%d)\n", rc);

tools/testing/cxl/test/mock.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,14 @@ int __wrap_cxl_await_media_ready(struct cxl_dev_state *cxlds)
208208
}
209209
EXPORT_SYMBOL_NS_GPL(__wrap_cxl_await_media_ready, CXL);
210210

211-
bool __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds)
211+
bool __wrap_cxl_hdm_decode_init(struct cxl_dev_state *cxlds,
212+
struct cxl_hdm *cxlhdm)
212213
{
213214
int rc = 0, index;
214215
struct cxl_mock_ops *ops = get_cxl_mock_ops(&index);
215216

216217
if (!ops || !ops->is_mock_dev(cxlds->dev))
217-
rc = cxl_hdm_decode_init(cxlds);
218+
rc = cxl_hdm_decode_init(cxlds, cxlhdm);
218219
put_cxl_mock_ops(index);
219220

220221
return rc;

0 commit comments

Comments
 (0)