Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions drivers/cxl/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ int cxl_get_poison_by_endpoint(struct cxl_port *port);
struct cxl_region *cxl_dpa_to_region(const struct cxl_memdev *cxlmd, u64 dpa);
u64 cxl_dpa_to_hpa(struct cxl_region *cxlr, const struct cxl_memdev *cxlmd,
u64 dpa);
void kill_regions(struct cxl_root_decoder *cxlrd);

#else
static inline u64 cxl_dpa_to_hpa(struct cxl_region *cxlr,
Expand Down Expand Up @@ -79,6 +80,7 @@ static inline int cxl_region_init(void)
static inline void cxl_region_exit(void)
{
}
static inline void kill_regions(struct cxl_root_decoder *cxlrd) { };
#define CXL_REGION_ATTR(x) NULL
#define CXL_REGION_TYPE(x) NULL
#define SET_CXL_REGION_ATTR(x)
Expand Down
97 changes: 0 additions & 97 deletions drivers/cxl/core/hdm.c
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,6 @@ int cxl_dpa_free(struct cxl_endpoint_decoder *cxled)
devm_cxl_dpa_release(cxled);
return 0;
}
EXPORT_SYMBOL_NS_GPL(cxl_dpa_free, "CXL");

int cxl_dpa_set_part(struct cxl_endpoint_decoder *cxled,
enum cxl_partition_mode mode)
Expand Down Expand Up @@ -597,64 +596,6 @@ int cxl_dpa_set_part(struct cxl_endpoint_decoder *cxled,
return 0;
}

static int find_free_decoder(struct device *dev, const void *data)
{
struct cxl_endpoint_decoder *cxled;
struct cxl_port *port;

if (!is_endpoint_decoder(dev))
return 0;

cxled = to_cxl_endpoint_decoder(dev);
port = cxled_to_port(cxled);

return cxled->cxld.id == (port->hdm_end + 1);
}

static struct cxl_endpoint_decoder *
cxl_find_free_decoder(struct cxl_memdev *cxlmd)
{
struct cxl_port *endpoint = cxlmd->endpoint;
struct device *dev;

guard(rwsem_read)(&cxl_rwsem.dpa);
dev = device_find_child(&endpoint->dev, NULL, find_free_decoder);
if (!dev)
return NULL;

return to_cxl_endpoint_decoder(dev);
}

struct cxl_endpoint_decoder *cxl_request_dpa(struct cxl_memdev *cxlmd,
enum cxl_partition_mode mode,
resource_size_t alloc)
{
struct cxl_endpoint_decoder *cxled;
int rc;

if (!IS_ALIGNED(alloc, SZ_256M))
return ERR_PTR(-EINVAL);

cxled = cxl_find_free_decoder(cxlmd);
if (!cxled)
return ERR_PTR(-ENODEV);

rc = cxl_dpa_set_part(cxled, mode);
if (rc)
goto err_put;

rc = cxl_dpa_alloc(cxled, alloc);
if (rc)
goto err_put;

return cxled;

err_put:
put_device(&cxled->cxld.dev);
return ERR_PTR(rc);
}
EXPORT_SYMBOL_NS_GPL(cxl_request_dpa, "CXL");

static int __cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size)
{
struct cxl_memdev *cxlmd = cxled_to_memdev(cxled);
Expand Down Expand Up @@ -738,44 +679,6 @@ int cxl_dpa_alloc(struct cxl_endpoint_decoder *cxled, u64 size)
return devm_add_action_or_reset(&port->dev, cxl_dpa_release, cxled);
}

static int find_committed_endpoint_decoder(struct device *dev, const void *data)
{
struct cxl_endpoint_decoder *cxled;
struct cxl_port *port;

if (!is_endpoint_decoder(dev))
return 0;

cxled = to_cxl_endpoint_decoder(dev);
port = cxled_to_port(cxled);

return cxled->cxld.id == port->hdm_end;
}

struct cxl_endpoint_decoder *cxl_get_committed_decoder(struct cxl_memdev *cxlmd,
struct cxl_region **cxlr)
{
struct cxl_port *endpoint = cxlmd->endpoint;
struct cxl_endpoint_decoder *cxled;
struct device *cxled_dev;

if (!endpoint)
return NULL;

guard(rwsem_read)(&cxl_rwsem.dpa);
cxled_dev = device_find_child(&endpoint->dev, NULL,
find_committed_endpoint_decoder);
if (!cxled_dev)
return NULL;

cxled = to_cxl_endpoint_decoder(cxled_dev);
*cxlr = cxled->cxld.region;

put_device(cxled_dev);
return cxled;
}
EXPORT_SYMBOL_NS_GPL(cxl_get_committed_decoder, "CXL");

static void cxld_set_interleave(struct cxl_decoder *cxld, u32 *ctrl)
{
u16 eig;
Expand Down
5 changes: 3 additions & 2 deletions drivers/cxl/core/mbox.c
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ int cxl_enumerate_cmds(struct cxl_memdev_state *mds)
}
EXPORT_SYMBOL_NS_GPL(cxl_enumerate_cmds, "CXL");

void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
void cxl_event_trace_record(struct cxl_memdev *cxlmd,
enum cxl_event_log_type type,
enum cxl_event_type event_type,
const uuid_t *uuid, union cxl_event *evt)
Expand All @@ -920,6 +920,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
* translations. Take topology mutation locks and lookup
* { HPA, REGION } from { DPA, MEMDEV } in the event record.
*/
guard(device)(&cxlmd->dev);
guard(rwsem_read)(&cxl_rwsem.region);
guard(rwsem_read)(&cxl_rwsem.dpa);

Expand Down Expand Up @@ -968,7 +969,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
}
EXPORT_SYMBOL_NS_GPL(cxl_event_trace_record, "CXL");

static void __cxl_event_trace_record(const struct cxl_memdev *cxlmd,
static void __cxl_event_trace_record(struct cxl_memdev *cxlmd,
enum cxl_event_log_type type,
struct cxl_event_record_raw *record)
{
Expand Down
18 changes: 10 additions & 8 deletions drivers/cxl/core/memdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ static DEFINE_IDA(cxl_memdev_ida);
static void cxl_memdev_release(struct device *dev)
{
struct cxl_memdev *cxlmd = to_cxl_memdev(dev);
struct device *parent = dev->parent;

ida_free(&cxl_memdev_ida, cxlmd->id);
kfree(cxlmd);
put_device(parent);
}

static char *cxl_memdev_devnode(const struct device *dev, umode_t *mode, kuid_t *uid,
Expand Down Expand Up @@ -570,23 +572,23 @@ void cxl_memdev_update_perf(struct cxl_memdev *cxlmd)
}
EXPORT_SYMBOL_NS_GPL(cxl_memdev_update_perf, "CXL");

static const struct device_type cxl_memdev_type = {
static const struct device_type cxl_class_memdev_type = {
.name = "cxl_memdev",
.release = cxl_memdev_release,
.devnode = cxl_memdev_devnode,
.groups = cxl_memdev_attribute_groups,
};

static const struct device_type cxl_accel_memdev_type = {
.name = "cxl_accel_memdev",
static const struct device_type cxl_memdev_type = {
.name = "cxl_memdev",
.release = cxl_memdev_release,
.devnode = cxl_memdev_devnode,
};

bool is_cxl_memdev(const struct device *dev)
{
return (dev->type == &cxl_memdev_type ||
dev->type == &cxl_accel_memdev_type);
return (dev->type == &cxl_class_memdev_type ||
dev->type == &cxl_memdev_type);
}
EXPORT_SYMBOL_NS_GPL(is_cxl_memdev, "CXL");

Expand Down Expand Up @@ -778,13 +780,13 @@ static struct cxl_memdev *cxl_memdev_alloc(struct cxl_dev_state *cxlds,
dev = &cxlmd->dev;
device_initialize(dev);
lockdep_set_class(&dev->mutex, &cxl_memdev_key);
dev->parent = cxlds->dev;
dev->parent = get_device(cxlds->dev);
dev->bus = &cxl_bus_type;
dev->devt = MKDEV(cxl_mem_major, cxlmd->id);
if (cxlds->type == CXL_DEVTYPE_DEVMEM)
dev->type = &cxl_accel_memdev_type;
else
dev->type = &cxl_memdev_type;
else
dev->type = &cxl_class_memdev_type;
device_set_pm_not_required(dev);
INIT_WORK(&cxlmd->detach_work, detach_memdev);

Expand Down
7 changes: 6 additions & 1 deletion drivers/cxl/core/port.c
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,8 @@ static void cxl_root_decoder_release(struct device *dev)

if (atomic_read(&cxlrd->region_id) >= 0)
memregion_free(atomic_read(&cxlrd->region_id));
mutex_destroy(&cxlrd->regions_lock);
xa_destroy(&cxlrd->regions);
__cxl_decoder_release(&cxlrd->cxlsd.cxld);
kfree(cxlrd);
}
Expand Down Expand Up @@ -2017,7 +2019,8 @@ struct cxl_root_decoder *cxl_root_decoder_alloc(struct cxl_port *port,
return ERR_PTR(rc);
}

mutex_init(&cxlrd->range_lock);
mutex_init(&cxlrd->regions_lock);
xa_init(&cxlrd->regions);

cxld = &cxlsd->cxld;
cxld->dev.type = &cxl_decoder_root_type;
Expand Down Expand Up @@ -2193,6 +2196,8 @@ static void cxld_unregister(void *dev)
if (is_endpoint_decoder(dev))
cxl_decoder_detach(NULL, to_cxl_endpoint_decoder(dev), -1,
DETACH_INVALIDATE);
if (is_root_decoder(dev))
kill_regions(to_cxl_root_decoder(dev));

device_unregister(dev);
}
Expand Down
Loading