2021-02-17 12:09:52 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
|
|
|
/* Copyright(c) 2020 Intel Corporation. All rights reserved. */
|
2021-05-14 13:22:05 +08:00
|
|
|
#include <linux/io-64-nonatomic-lo-hi.h>
|
2021-02-17 12:09:52 +08:00
|
|
|
#include <linux/device.h>
|
|
|
|
#include <linux/module.h>
|
2021-06-04 08:50:36 +08:00
|
|
|
#include <linux/pci.h>
|
2021-06-10 00:01:35 +08:00
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/idr.h>
|
2021-08-03 01:29:38 +08:00
|
|
|
#include <cxlmem.h>
|
|
|
|
#include <cxl.h>
|
2021-08-03 01:29:49 +08:00
|
|
|
#include "core.h"
|
2021-02-17 12:09:52 +08:00
|
|
|
|
|
|
|
/**
|
2021-05-14 13:22:00 +08:00
|
|
|
* DOC: cxl core
|
2021-02-17 12:09:52 +08:00
|
|
|
*
|
2021-08-03 01:29:43 +08:00
|
|
|
* The CXL core provides a set of interfaces that can be consumed by CXL aware
|
|
|
|
* drivers. The interfaces allow for creation, modification, and destruction of
|
|
|
|
* regions, memory devices, ports, and decoders. CXL aware drivers must register
|
|
|
|
* with the CXL core via these interfaces in order to be able to participate in
|
|
|
|
* cross-device interleave coordination. The CXL core also establishes and
|
|
|
|
* maintains the bridge to the nvdimm subsystem.
|
|
|
|
*
|
|
|
|
* CXL core introduces sysfs hierarchy to control the devices that are
|
|
|
|
* instantiated by the core.
|
2021-02-17 12:09:52 +08:00
|
|
|
*/
|
2021-05-14 13:22:00 +08:00
|
|
|
|
2021-06-10 00:01:35 +08:00
|
|
|
static DEFINE_IDA(cxl_port_ida);
|
|
|
|
|
|
|
|
static ssize_t devtype_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
return sysfs_emit(buf, "%s\n", dev->type->name);
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(devtype);
|
|
|
|
|
|
|
|
static struct attribute *cxl_base_attributes[] = {
|
|
|
|
&dev_attr_devtype.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
2021-08-03 01:29:49 +08:00
|
|
|
struct attribute_group cxl_base_attribute_group = {
|
2021-06-10 00:01:35 +08:00
|
|
|
.attrs = cxl_base_attributes,
|
|
|
|
};
|
|
|
|
|
2021-06-10 00:43:29 +08:00
|
|
|
static ssize_t start_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct cxl_decoder *cxld = to_cxl_decoder(dev);
|
2022-01-24 08:29:31 +08:00
|
|
|
u64 start;
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2022-01-24 08:29:31 +08:00
|
|
|
if (is_root_decoder(dev))
|
|
|
|
start = cxld->platform_res.start;
|
|
|
|
else
|
|
|
|
start = cxld->decoder_range.start;
|
|
|
|
|
|
|
|
return sysfs_emit(buf, "%#llx\n", start);
|
2021-06-10 00:43:29 +08:00
|
|
|
}
|
2022-01-24 08:29:26 +08:00
|
|
|
static DEVICE_ATTR_ADMIN_RO(start);
|
2021-06-10 00:43:29 +08:00
|
|
|
|
|
|
|
static ssize_t size_show(struct device *dev, struct device_attribute *attr,
|
|
|
|
char *buf)
|
|
|
|
{
|
|
|
|
struct cxl_decoder *cxld = to_cxl_decoder(dev);
|
2022-01-24 08:29:31 +08:00
|
|
|
u64 size;
|
|
|
|
|
|
|
|
if (is_root_decoder(dev))
|
|
|
|
size = resource_size(&cxld->platform_res);
|
|
|
|
else
|
|
|
|
size = range_len(&cxld->decoder_range);
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2022-01-24 08:29:31 +08:00
|
|
|
return sysfs_emit(buf, "%#llx\n", size);
|
2021-06-10 00:43:29 +08:00
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(size);
|
|
|
|
|
|
|
|
#define CXL_DECODER_FLAG_ATTR(name, flag) \
|
|
|
|
static ssize_t name##_show(struct device *dev, \
|
|
|
|
struct device_attribute *attr, char *buf) \
|
|
|
|
{ \
|
|
|
|
struct cxl_decoder *cxld = to_cxl_decoder(dev); \
|
|
|
|
\
|
|
|
|
return sysfs_emit(buf, "%s\n", \
|
|
|
|
(cxld->flags & (flag)) ? "1" : "0"); \
|
|
|
|
} \
|
|
|
|
static DEVICE_ATTR_RO(name)
|
|
|
|
|
|
|
|
CXL_DECODER_FLAG_ATTR(cap_pmem, CXL_DECODER_F_PMEM);
|
|
|
|
CXL_DECODER_FLAG_ATTR(cap_ram, CXL_DECODER_F_RAM);
|
|
|
|
CXL_DECODER_FLAG_ATTR(cap_type2, CXL_DECODER_F_TYPE2);
|
|
|
|
CXL_DECODER_FLAG_ATTR(cap_type3, CXL_DECODER_F_TYPE3);
|
|
|
|
CXL_DECODER_FLAG_ATTR(locked, CXL_DECODER_F_LOCK);
|
|
|
|
|
|
|
|
static ssize_t target_type_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct cxl_decoder *cxld = to_cxl_decoder(dev);
|
|
|
|
|
|
|
|
switch (cxld->target_type) {
|
|
|
|
case CXL_DECODER_ACCELERATOR:
|
|
|
|
return sysfs_emit(buf, "accelerator\n");
|
|
|
|
case CXL_DECODER_EXPANDER:
|
|
|
|
return sysfs_emit(buf, "expander\n");
|
|
|
|
}
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(target_type);
|
|
|
|
|
|
|
|
static ssize_t target_list_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct cxl_decoder *cxld = to_cxl_decoder(dev);
|
|
|
|
ssize_t offset = 0;
|
|
|
|
int i, rc = 0;
|
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_lock(dev);
|
2021-06-10 00:43:29 +08:00
|
|
|
for (i = 0; i < cxld->interleave_ways; i++) {
|
|
|
|
struct cxl_dport *dport = cxld->target[i];
|
|
|
|
struct cxl_dport *next = NULL;
|
|
|
|
|
|
|
|
if (!dport)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (i + 1 < cxld->interleave_ways)
|
|
|
|
next = cxld->target[i + 1];
|
|
|
|
rc = sysfs_emit_at(buf, offset, "%d%s", dport->port_id,
|
|
|
|
next ? "," : "");
|
|
|
|
if (rc < 0)
|
|
|
|
break;
|
|
|
|
offset += rc;
|
|
|
|
}
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_unlock(dev);
|
2021-06-10 00:43:29 +08:00
|
|
|
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = sysfs_emit_at(buf, offset, "\n");
|
|
|
|
if (rc < 0)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
return offset + rc;
|
|
|
|
}
|
|
|
|
static DEVICE_ATTR_RO(target_list);
|
|
|
|
|
|
|
|
static struct attribute *cxl_decoder_base_attrs[] = {
|
|
|
|
&dev_attr_start.attr,
|
|
|
|
&dev_attr_size.attr,
|
|
|
|
&dev_attr_locked.attr,
|
|
|
|
&dev_attr_target_list.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group cxl_decoder_base_attribute_group = {
|
|
|
|
.attrs = cxl_decoder_base_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *cxl_decoder_root_attrs[] = {
|
|
|
|
&dev_attr_cap_pmem.attr,
|
|
|
|
&dev_attr_cap_ram.attr,
|
|
|
|
&dev_attr_cap_type2.attr,
|
|
|
|
&dev_attr_cap_type3.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group cxl_decoder_root_attribute_group = {
|
|
|
|
.attrs = cxl_decoder_root_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group *cxl_decoder_root_attribute_groups[] = {
|
|
|
|
&cxl_decoder_root_attribute_group,
|
|
|
|
&cxl_decoder_base_attribute_group,
|
|
|
|
&cxl_base_attribute_group,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute *cxl_decoder_switch_attrs[] = {
|
|
|
|
&dev_attr_target_type.attr,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static struct attribute_group cxl_decoder_switch_attribute_group = {
|
|
|
|
.attrs = cxl_decoder_switch_attrs,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct attribute_group *cxl_decoder_switch_attribute_groups[] = {
|
|
|
|
&cxl_decoder_switch_attribute_group,
|
|
|
|
&cxl_decoder_base_attribute_group,
|
|
|
|
&cxl_base_attribute_group,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static void cxl_decoder_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct cxl_decoder *cxld = to_cxl_decoder(dev);
|
|
|
|
struct cxl_port *port = to_cxl_port(dev->parent);
|
|
|
|
|
|
|
|
ida_free(&port->decoder_ida, cxld->id);
|
|
|
|
kfree(cxld);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct device_type cxl_decoder_switch_type = {
|
|
|
|
.name = "cxl_decoder_switch",
|
|
|
|
.release = cxl_decoder_release,
|
|
|
|
.groups = cxl_decoder_switch_attribute_groups,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct device_type cxl_decoder_root_type = {
|
|
|
|
.name = "cxl_decoder_root",
|
|
|
|
.release = cxl_decoder_release,
|
|
|
|
.groups = cxl_decoder_root_attribute_groups,
|
|
|
|
};
|
|
|
|
|
2021-06-16 07:18:17 +08:00
|
|
|
bool is_root_decoder(struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->type == &cxl_decoder_root_type;
|
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(is_root_decoder, CXL);
|
2021-06-16 07:18:17 +08:00
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
bool is_cxl_decoder(struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->type->release == cxl_decoder_release;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(is_cxl_decoder, CXL);
|
|
|
|
|
2021-06-10 00:43:29 +08:00
|
|
|
struct cxl_decoder *to_cxl_decoder(struct device *dev)
|
|
|
|
{
|
|
|
|
if (dev_WARN_ONCE(dev, dev->type->release != cxl_decoder_release,
|
|
|
|
"not a cxl_decoder device\n"))
|
|
|
|
return NULL;
|
|
|
|
return container_of(dev, struct cxl_decoder, dev);
|
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(to_cxl_decoder, CXL);
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2021-06-10 00:01:46 +08:00
|
|
|
static void cxl_dport_release(struct cxl_dport *dport)
|
|
|
|
{
|
|
|
|
list_del(&dport->list);
|
|
|
|
put_device(dport->dport);
|
|
|
|
kfree(dport);
|
|
|
|
}
|
|
|
|
|
2021-06-10 00:01:35 +08:00
|
|
|
static void cxl_port_release(struct device *dev)
|
|
|
|
{
|
|
|
|
struct cxl_port *port = to_cxl_port(dev);
|
2021-06-10 00:01:46 +08:00
|
|
|
struct cxl_dport *dport, *_d;
|
2021-06-10 00:01:35 +08:00
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_lock(dev);
|
2021-06-10 00:01:46 +08:00
|
|
|
list_for_each_entry_safe(dport, _d, &port->dports, list)
|
|
|
|
cxl_dport_release(dport);
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_unlock(dev);
|
2021-06-10 00:01:35 +08:00
|
|
|
ida_free(&cxl_port_ida, port->id);
|
|
|
|
kfree(port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct attribute_group *cxl_port_attribute_groups[] = {
|
|
|
|
&cxl_base_attribute_group,
|
|
|
|
NULL,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct device_type cxl_port_type = {
|
|
|
|
.name = "cxl_port",
|
|
|
|
.release = cxl_port_release,
|
|
|
|
.groups = cxl_port_attribute_groups,
|
|
|
|
};
|
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
bool is_cxl_port(struct device *dev)
|
|
|
|
{
|
|
|
|
return dev->type == &cxl_port_type;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(is_cxl_port, CXL);
|
|
|
|
|
2021-06-10 00:01:35 +08:00
|
|
|
struct cxl_port *to_cxl_port(struct device *dev)
|
|
|
|
{
|
|
|
|
if (dev_WARN_ONCE(dev, dev->type != &cxl_port_type,
|
|
|
|
"not a cxl_port device\n"))
|
|
|
|
return NULL;
|
|
|
|
return container_of(dev, struct cxl_port, dev);
|
|
|
|
}
|
2022-02-01 03:50:09 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(to_cxl_port, CXL);
|
2021-06-10 00:01:35 +08:00
|
|
|
|
2021-06-10 00:01:46 +08:00
|
|
|
static void unregister_port(void *_port)
|
2021-06-10 00:01:35 +08:00
|
|
|
{
|
2021-06-10 00:01:46 +08:00
|
|
|
struct cxl_port *port = _port;
|
|
|
|
struct cxl_dport *dport;
|
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_lock(&port->dev);
|
2021-06-10 00:01:46 +08:00
|
|
|
list_for_each_entry(dport, &port->dports, list) {
|
|
|
|
char link_name[CXL_TARGET_STRLEN];
|
|
|
|
|
|
|
|
if (snprintf(link_name, CXL_TARGET_STRLEN, "dport%d",
|
|
|
|
dport->port_id) >= CXL_TARGET_STRLEN)
|
|
|
|
continue;
|
|
|
|
sysfs_remove_link(&port->dev.kobj, link_name);
|
|
|
|
}
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_unlock(&port->dev);
|
2021-06-10 00:01:46 +08:00
|
|
|
device_unregister(&port->dev);
|
2021-06-10 00:01:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void cxl_unlink_uport(void *_port)
|
|
|
|
{
|
|
|
|
struct cxl_port *port = _port;
|
|
|
|
|
|
|
|
sysfs_remove_link(&port->dev.kobj, "uport");
|
|
|
|
}
|
|
|
|
|
|
|
|
static int devm_cxl_link_uport(struct device *host, struct cxl_port *port)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
rc = sysfs_create_link(&port->dev.kobj, &port->uport->kobj, "uport");
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
return devm_add_action_or_reset(host, cxl_unlink_uport, port);
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct cxl_port *cxl_port_alloc(struct device *uport,
|
|
|
|
resource_size_t component_reg_phys,
|
|
|
|
struct cxl_port *parent_port)
|
|
|
|
{
|
|
|
|
struct cxl_port *port;
|
|
|
|
struct device *dev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
port = kzalloc(sizeof(*port), GFP_KERNEL);
|
|
|
|
if (!port)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
rc = ida_alloc(&cxl_port_ida, GFP_KERNEL);
|
|
|
|
if (rc < 0)
|
|
|
|
goto err;
|
|
|
|
port->id = rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The top-level cxl_port "cxl_root" does not have a cxl_port as
|
|
|
|
* its parent and it does not have any corresponding component
|
|
|
|
* registers as its decode is described by a fixed platform
|
|
|
|
* description.
|
|
|
|
*/
|
|
|
|
dev = &port->dev;
|
|
|
|
if (parent_port)
|
|
|
|
dev->parent = &parent_port->dev;
|
|
|
|
else
|
|
|
|
dev->parent = uport;
|
|
|
|
|
|
|
|
port->uport = uport;
|
|
|
|
port->component_reg_phys = component_reg_phys;
|
2021-06-10 00:43:29 +08:00
|
|
|
ida_init(&port->decoder_ida);
|
2021-06-10 00:01:46 +08:00
|
|
|
INIT_LIST_HEAD(&port->dports);
|
2021-06-10 00:01:35 +08:00
|
|
|
|
|
|
|
device_initialize(dev);
|
|
|
|
device_set_pm_not_required(dev);
|
|
|
|
dev->bus = &cxl_bus_type;
|
|
|
|
dev->type = &cxl_port_type;
|
|
|
|
|
|
|
|
return port;
|
|
|
|
|
|
|
|
err:
|
|
|
|
kfree(port);
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* devm_cxl_add_port - register a cxl_port in CXL memory decode hierarchy
|
|
|
|
* @host: host device for devm operations
|
|
|
|
* @uport: "physical" device implementing this upstream port
|
|
|
|
* @component_reg_phys: (optional) for configurable cxl_port instances
|
|
|
|
* @parent_port: next hop up in the CXL memory decode hierarchy
|
|
|
|
*/
|
|
|
|
struct cxl_port *devm_cxl_add_port(struct device *host, struct device *uport,
|
|
|
|
resource_size_t component_reg_phys,
|
|
|
|
struct cxl_port *parent_port)
|
|
|
|
{
|
|
|
|
struct cxl_port *port;
|
|
|
|
struct device *dev;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
port = cxl_port_alloc(uport, component_reg_phys, parent_port);
|
|
|
|
if (IS_ERR(port))
|
|
|
|
return port;
|
|
|
|
|
2022-01-24 08:29:53 +08:00
|
|
|
if (parent_port)
|
|
|
|
port->depth = parent_port->depth + 1;
|
2021-06-10 00:01:35 +08:00
|
|
|
dev = &port->dev;
|
|
|
|
if (parent_port)
|
|
|
|
rc = dev_set_name(dev, "port%d", port->id);
|
|
|
|
else
|
|
|
|
rc = dev_set_name(dev, "root%d", port->id);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
rc = device_add(dev);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
2021-06-10 00:01:46 +08:00
|
|
|
rc = devm_add_action_or_reset(host, unregister_port, port);
|
2021-06-10 00:01:35 +08:00
|
|
|
if (rc)
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
|
|
|
|
rc = devm_cxl_link_uport(host, port);
|
|
|
|
if (rc)
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
|
|
|
|
return port;
|
|
|
|
|
|
|
|
err:
|
|
|
|
put_device(dev);
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(devm_cxl_add_port, CXL);
|
2021-06-10 00:01:35 +08:00
|
|
|
|
2021-06-10 00:01:46 +08:00
|
|
|
static struct cxl_dport *find_dport(struct cxl_port *port, int id)
|
|
|
|
{
|
|
|
|
struct cxl_dport *dport;
|
|
|
|
|
|
|
|
device_lock_assert(&port->dev);
|
|
|
|
list_for_each_entry (dport, &port->dports, list)
|
|
|
|
if (dport->port_id == id)
|
|
|
|
return dport;
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int add_dport(struct cxl_port *port, struct cxl_dport *new)
|
|
|
|
{
|
|
|
|
struct cxl_dport *dup;
|
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_lock(&port->dev);
|
2021-06-10 00:01:46 +08:00
|
|
|
dup = find_dport(port, new->port_id);
|
|
|
|
if (dup)
|
|
|
|
dev_err(&port->dev,
|
|
|
|
"unable to add dport%d-%s non-unique port id (%s)\n",
|
|
|
|
new->port_id, dev_name(new->dport),
|
|
|
|
dev_name(dup->dport));
|
|
|
|
else
|
|
|
|
list_add_tail(&new->list, &port->dports);
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_unlock(&port->dev);
|
2021-06-10 00:01:46 +08:00
|
|
|
|
|
|
|
return dup ? -EEXIST : 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxl_add_dport - append downstream port data to a cxl_port
|
|
|
|
* @port: the cxl_port that references this dport
|
|
|
|
* @dport_dev: firmware or PCI device representing the dport
|
|
|
|
* @port_id: identifier for this dport in a decoder's target list
|
|
|
|
* @component_reg_phys: optional location of CXL component registers
|
|
|
|
*
|
|
|
|
* Note that all allocations and links are undone by cxl_port deletion
|
|
|
|
* and release.
|
|
|
|
*/
|
|
|
|
int cxl_add_dport(struct cxl_port *port, struct device *dport_dev, int port_id,
|
|
|
|
resource_size_t component_reg_phys)
|
|
|
|
{
|
|
|
|
char link_name[CXL_TARGET_STRLEN];
|
|
|
|
struct cxl_dport *dport;
|
|
|
|
int rc;
|
|
|
|
|
|
|
|
if (snprintf(link_name, CXL_TARGET_STRLEN, "dport%d", port_id) >=
|
|
|
|
CXL_TARGET_STRLEN)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
dport = kzalloc(sizeof(*dport), GFP_KERNEL);
|
|
|
|
if (!dport)
|
|
|
|
return -ENOMEM;
|
|
|
|
|
|
|
|
INIT_LIST_HEAD(&dport->list);
|
|
|
|
dport->dport = get_device(dport_dev);
|
|
|
|
dport->port_id = port_id;
|
|
|
|
dport->component_reg_phys = component_reg_phys;
|
|
|
|
dport->port = port;
|
|
|
|
|
|
|
|
rc = add_dport(port, dport);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
rc = sysfs_create_link(&port->dev.kobj, &dport_dev->kobj, link_name);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
err:
|
|
|
|
cxl_dport_release(dport);
|
|
|
|
return rc;
|
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_add_dport, CXL);
|
2021-06-10 00:01:46 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
static int decoder_populate_targets(struct cxl_decoder *cxld,
|
|
|
|
struct cxl_port *port, int *target_map)
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
{
|
|
|
|
int rc = 0, i;
|
|
|
|
|
|
|
|
if (!target_map)
|
|
|
|
return 0;
|
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_lock(&port->dev);
|
2021-09-22 03:22:16 +08:00
|
|
|
if (list_empty(&port->dports)) {
|
|
|
|
rc = -EINVAL;
|
|
|
|
goto out_unlock;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 0; i < cxld->nr_targets; i++) {
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
struct cxl_dport *dport = find_dport(port, target_map[i]);
|
|
|
|
|
|
|
|
if (!dport) {
|
|
|
|
rc = -ENXIO;
|
2021-09-22 03:22:16 +08:00
|
|
|
goto out_unlock;
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
}
|
|
|
|
cxld->target[i] = dport;
|
|
|
|
}
|
2021-09-22 03:22:16 +08:00
|
|
|
|
|
|
|
out_unlock:
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_device_unlock(&port->dev);
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
|
|
|
|
return rc;
|
|
|
|
}
|
|
|
|
|
2022-02-01 05:33:13 +08:00
|
|
|
/**
|
|
|
|
* cxl_decoder_alloc - Allocate a new CXL decoder
|
|
|
|
* @port: owning port of this decoder
|
|
|
|
* @nr_targets: downstream targets accessible by this decoder. All upstream
|
|
|
|
* ports and root ports must have at least 1 target.
|
|
|
|
*
|
|
|
|
* A port should contain one or more decoders. Each of those decoders enable
|
|
|
|
* some address space for CXL.mem utilization. A decoder is expected to be
|
|
|
|
* configured by the caller before registering.
|
|
|
|
*
|
2022-01-24 08:29:47 +08:00
|
|
|
* Return: A new cxl decoder to be registered by cxl_decoder_add(). The decoder
|
|
|
|
* is initialized to be a "passthrough" decoder.
|
2022-02-01 05:33:13 +08:00
|
|
|
*/
|
|
|
|
static struct cxl_decoder *cxl_decoder_alloc(struct cxl_port *port,
|
|
|
|
unsigned int nr_targets)
|
2021-06-10 00:43:29 +08:00
|
|
|
{
|
2021-12-11 05:36:27 +08:00
|
|
|
struct cxl_decoder *cxld;
|
2021-06-10 00:43:29 +08:00
|
|
|
struct device *dev;
|
|
|
|
int rc = 0;
|
|
|
|
|
2022-02-01 05:33:13 +08:00
|
|
|
if (nr_targets > CXL_DECODER_MAX_INTERLEAVE || nr_targets == 0)
|
2021-06-10 00:43:29 +08:00
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
cxld = kzalloc(struct_size(cxld, target, nr_targets), GFP_KERNEL);
|
|
|
|
if (!cxld)
|
|
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
|
|
|
|
rc = ida_alloc(&port->decoder_ida, GFP_KERNEL);
|
|
|
|
if (rc < 0)
|
|
|
|
goto err;
|
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
cxld->id = rc;
|
2021-12-11 05:36:27 +08:00
|
|
|
cxld->nr_targets = nr_targets;
|
2021-06-10 00:43:29 +08:00
|
|
|
dev = &cxld->dev;
|
|
|
|
device_initialize(dev);
|
|
|
|
device_set_pm_not_required(dev);
|
|
|
|
dev->parent = &port->dev;
|
|
|
|
dev->bus = &cxl_bus_type;
|
2022-02-01 05:33:13 +08:00
|
|
|
if (is_cxl_root(port))
|
|
|
|
cxld->dev.type = &cxl_decoder_root_type;
|
2021-06-10 00:43:29 +08:00
|
|
|
else
|
2022-02-01 05:33:13 +08:00
|
|
|
cxld->dev.type = &cxl_decoder_switch_type;
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2022-01-24 08:29:47 +08:00
|
|
|
/* Pre initialize an "empty" decoder */
|
|
|
|
cxld->interleave_ways = 1;
|
|
|
|
cxld->interleave_granularity = PAGE_SIZE;
|
|
|
|
cxld->target_type = CXL_DECODER_EXPANDER;
|
|
|
|
cxld->platform_res = (struct resource)DEFINE_RES_MEM(0, 0);
|
|
|
|
|
2021-06-10 00:43:29 +08:00
|
|
|
return cxld;
|
|
|
|
err:
|
|
|
|
kfree(cxld);
|
|
|
|
return ERR_PTR(rc);
|
|
|
|
}
|
|
|
|
|
2022-02-01 05:33:13 +08:00
|
|
|
/**
|
|
|
|
* cxl_root_decoder_alloc - Allocate a root level decoder
|
|
|
|
* @port: owning CXL root of this decoder
|
|
|
|
* @nr_targets: static number of downstream targets
|
|
|
|
*
|
|
|
|
* Return: A new cxl decoder to be registered by cxl_decoder_add(). A
|
|
|
|
* 'CXL root' decoder is one that decodes from a top-level / static platform
|
|
|
|
* firmware description of CXL resources into a CXL standard decode
|
|
|
|
* topology.
|
|
|
|
*/
|
|
|
|
struct cxl_decoder *cxl_root_decoder_alloc(struct cxl_port *port,
|
|
|
|
unsigned int nr_targets)
|
|
|
|
{
|
|
|
|
if (!is_cxl_root(port))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
return cxl_decoder_alloc(port, nr_targets);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_root_decoder_alloc, CXL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxl_switch_decoder_alloc - Allocate a switch level decoder
|
|
|
|
* @port: owning CXL switch port of this decoder
|
|
|
|
* @nr_targets: max number of dynamically addressable downstream targets
|
|
|
|
*
|
|
|
|
* Return: A new cxl decoder to be registered by cxl_decoder_add(). A
|
|
|
|
* 'switch' decoder is any decoder that can be enumerated by PCIe
|
|
|
|
* topology and the HDM Decoder Capability. This includes the decoders
|
|
|
|
* that sit between Switch Upstream Ports / Switch Downstream Ports and
|
|
|
|
* Host Bridges / Root Ports.
|
|
|
|
*/
|
|
|
|
struct cxl_decoder *cxl_switch_decoder_alloc(struct cxl_port *port,
|
|
|
|
unsigned int nr_targets)
|
|
|
|
{
|
|
|
|
if (is_cxl_root(port))
|
|
|
|
return ERR_PTR(-EINVAL);
|
|
|
|
|
|
|
|
return cxl_decoder_alloc(port, nr_targets);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_switch_decoder_alloc, CXL);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* cxl_decoder_add - Add a decoder with targets
|
|
|
|
* @cxld: The cxl decoder allocated by cxl_decoder_alloc()
|
|
|
|
* @target_map: A list of downstream ports that this decoder can direct memory
|
|
|
|
* traffic to. These numbers should correspond with the port number
|
|
|
|
* in the PCIe Link Capabilities structure.
|
|
|
|
*
|
|
|
|
* Certain types of decoders may not have any targets. The main example of this
|
|
|
|
* is an endpoint device. A more awkward example is a hostbridge whose root
|
|
|
|
* ports get hot added (technically possible, though unlikely).
|
|
|
|
*
|
|
|
|
* Context: Process context. Takes and releases the cxld's device lock.
|
|
|
|
*
|
|
|
|
* Return: Negative error code if the decoder wasn't properly configured; else
|
|
|
|
* returns 0.
|
|
|
|
*/
|
2021-09-22 03:22:16 +08:00
|
|
|
int cxl_decoder_add(struct cxl_decoder *cxld, int *target_map)
|
2021-06-10 00:43:29 +08:00
|
|
|
{
|
2021-09-22 03:22:16 +08:00
|
|
|
struct cxl_port *port;
|
2021-06-10 00:43:29 +08:00
|
|
|
struct device *dev;
|
|
|
|
int rc;
|
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
if (WARN_ON_ONCE(!cxld))
|
|
|
|
return -EINVAL;
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
if (WARN_ON_ONCE(IS_ERR(cxld)))
|
|
|
|
return PTR_ERR(cxld);
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
if (cxld->interleave_ways < 1)
|
|
|
|
return -EINVAL;
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
port = to_cxl_port(cxld->dev.parent);
|
|
|
|
rc = decoder_populate_targets(cxld, port, target_map);
|
2021-06-10 00:43:29 +08:00
|
|
|
if (rc)
|
2021-09-22 03:22:16 +08:00
|
|
|
return rc;
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
dev = &cxld->dev;
|
|
|
|
rc = dev_set_name(dev, "decoder%d.%d", port->id, cxld->id);
|
2021-06-10 00:43:29 +08:00
|
|
|
if (rc)
|
2021-09-22 03:22:16 +08:00
|
|
|
return rc;
|
2021-06-10 00:43:29 +08:00
|
|
|
|
2022-01-24 08:29:31 +08:00
|
|
|
/*
|
|
|
|
* Platform decoder resources should show up with a reasonable name. All
|
|
|
|
* other resources are just sub ranges within the main decoder resource.
|
|
|
|
*/
|
|
|
|
if (is_root_decoder(dev))
|
|
|
|
cxld->platform_res.name = dev_name(dev);
|
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
return device_add(dev);
|
2021-06-10 00:43:29 +08:00
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_decoder_add, CXL);
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
static void cxld_unregister(void *dev)
|
|
|
|
{
|
|
|
|
device_unregister(dev);
|
|
|
|
}
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
|
2021-09-22 03:22:16 +08:00
|
|
|
int cxl_decoder_autoremove(struct device *host, struct cxl_decoder *cxld)
|
|
|
|
{
|
|
|
|
return devm_add_action_or_reset(host, cxld_unregister, &cxld->dev);
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_decoder_autoremove, CXL);
|
cxl/bus: Populate the target list at decoder create
As found by cxl_test, the implementation populated the target_list for
the single dport exceptional case, it missed populating the target_list
for the typical multi-dport case. Root decoders always know their target
list at the beginning of time, and even switch-level decoders should
have a target list of one or more zeros by default, depending on the
interleave-ways setting.
Walk the hosting port's dport list and populate based on the passed in
map.
Move devm_cxl_add_passthrough_decoder() out of line now that it does the
work of generating a target_map.
Before:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0
After:
$ cat /sys/bus/cxl/devices/root2/decoder*/target_list
0
0,1,2,3
0
0,1,2,3
Where root2 is a CXL topology root object generated by 'cxl_test'.
Acked-by: Ben Widawsky <ben.widawsky@intel.com>
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
Link: https://lore.kernel.org/r/163116439000.2460985.11713777051267946018.stgit@dwillia2-desk3.amr.corp.intel.com
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
2021-09-09 13:13:10 +08:00
|
|
|
|
2021-06-16 07:18:11 +08:00
|
|
|
/**
|
|
|
|
* __cxl_driver_register - register a driver for the cxl bus
|
|
|
|
* @cxl_drv: cxl driver structure to attach
|
|
|
|
* @owner: owning module/driver
|
|
|
|
* @modname: KBUILD_MODNAME for parent driver
|
|
|
|
*/
|
|
|
|
int __cxl_driver_register(struct cxl_driver *cxl_drv, struct module *owner,
|
|
|
|
const char *modname)
|
|
|
|
{
|
|
|
|
if (!cxl_drv->probe) {
|
|
|
|
pr_debug("%s ->probe() must be specified\n", modname);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cxl_drv->name) {
|
|
|
|
pr_debug("%s ->name must be specified\n", modname);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!cxl_drv->id) {
|
|
|
|
pr_debug("%s ->id must be specified\n", modname);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
cxl_drv->drv.bus = &cxl_bus_type;
|
|
|
|
cxl_drv->drv.owner = owner;
|
|
|
|
cxl_drv->drv.mod_name = modname;
|
|
|
|
cxl_drv->drv.name = cxl_drv->name;
|
|
|
|
|
|
|
|
return driver_register(&cxl_drv->drv);
|
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(__cxl_driver_register, CXL);
|
2021-06-16 07:18:11 +08:00
|
|
|
|
|
|
|
void cxl_driver_unregister(struct cxl_driver *cxl_drv)
|
|
|
|
{
|
|
|
|
driver_unregister(&cxl_drv->drv);
|
|
|
|
}
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_driver_unregister, CXL);
|
2021-06-16 07:18:11 +08:00
|
|
|
|
|
|
|
static int cxl_device_id(struct device *dev)
|
|
|
|
{
|
2021-06-16 07:18:17 +08:00
|
|
|
if (dev->type == &cxl_nvdimm_bridge_type)
|
|
|
|
return CXL_DEVICE_NVDIMM_BRIDGE;
|
2021-06-16 07:36:31 +08:00
|
|
|
if (dev->type == &cxl_nvdimm_type)
|
|
|
|
return CXL_DEVICE_NVDIMM;
|
2021-06-16 07:18:11 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cxl_bus_uevent(struct device *dev, struct kobj_uevent_env *env)
|
|
|
|
{
|
|
|
|
return add_uevent_var(env, "MODALIAS=" CXL_MODALIAS_FMT,
|
|
|
|
cxl_device_id(dev));
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cxl_bus_match(struct device *dev, struct device_driver *drv)
|
|
|
|
{
|
|
|
|
return cxl_device_id(dev) == to_cxl_drv(drv)->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int cxl_bus_probe(struct device *dev)
|
|
|
|
{
|
2022-02-01 03:50:09 +08:00
|
|
|
int rc;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Take the CXL nested lock since the driver core only holds
|
|
|
|
* @dev->mutex and not @dev->lockdep_mutex.
|
|
|
|
*/
|
|
|
|
cxl_nested_lock(dev);
|
|
|
|
rc = to_cxl_drv(dev->driver)->probe(dev);
|
|
|
|
cxl_nested_unlock(dev);
|
|
|
|
|
|
|
|
return rc;
|
2021-06-16 07:18:11 +08:00
|
|
|
}
|
|
|
|
|
2021-07-14 03:35:22 +08:00
|
|
|
static void cxl_bus_remove(struct device *dev)
|
2021-06-16 07:18:11 +08:00
|
|
|
{
|
|
|
|
struct cxl_driver *cxl_drv = to_cxl_drv(dev->driver);
|
|
|
|
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_nested_lock(dev);
|
2021-06-16 07:18:11 +08:00
|
|
|
if (cxl_drv->remove)
|
|
|
|
cxl_drv->remove(dev);
|
2022-02-01 03:50:09 +08:00
|
|
|
cxl_nested_unlock(dev);
|
2021-06-16 07:18:11 +08:00
|
|
|
}
|
|
|
|
|
2021-02-17 12:09:52 +08:00
|
|
|
struct bus_type cxl_bus_type = {
|
|
|
|
.name = "cxl",
|
2021-06-16 07:18:11 +08:00
|
|
|
.uevent = cxl_bus_uevent,
|
|
|
|
.match = cxl_bus_match,
|
|
|
|
.probe = cxl_bus_probe,
|
|
|
|
.remove = cxl_bus_remove,
|
2021-02-17 12:09:52 +08:00
|
|
|
};
|
2021-11-13 08:32:58 +08:00
|
|
|
EXPORT_SYMBOL_NS_GPL(cxl_bus_type, CXL);
|
2021-02-17 12:09:52 +08:00
|
|
|
|
2021-05-14 13:22:00 +08:00
|
|
|
static __init int cxl_core_init(void)
|
2021-02-17 12:09:52 +08:00
|
|
|
{
|
2021-08-03 01:30:05 +08:00
|
|
|
int rc;
|
|
|
|
|
2021-09-09 13:12:32 +08:00
|
|
|
cxl_mbox_init();
|
|
|
|
|
2021-08-03 01:30:05 +08:00
|
|
|
rc = cxl_memdev_init();
|
|
|
|
if (rc)
|
|
|
|
return rc;
|
|
|
|
|
|
|
|
rc = bus_register(&cxl_bus_type);
|
|
|
|
if (rc)
|
|
|
|
goto err;
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
err:
|
|
|
|
cxl_memdev_exit();
|
2021-09-09 13:12:32 +08:00
|
|
|
cxl_mbox_exit();
|
2021-08-03 01:30:05 +08:00
|
|
|
return rc;
|
2021-02-17 12:09:52 +08:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:22:00 +08:00
|
|
|
static void cxl_core_exit(void)
|
2021-02-17 12:09:52 +08:00
|
|
|
{
|
|
|
|
bus_unregister(&cxl_bus_type);
|
2021-08-03 01:30:05 +08:00
|
|
|
cxl_memdev_exit();
|
2021-09-09 13:12:32 +08:00
|
|
|
cxl_mbox_exit();
|
2021-02-17 12:09:52 +08:00
|
|
|
}
|
|
|
|
|
2021-05-14 13:22:00 +08:00
|
|
|
module_init(cxl_core_init);
|
|
|
|
module_exit(cxl_core_exit);
|
2021-02-17 12:09:52 +08:00
|
|
|
MODULE_LICENSE("GPL v2");
|