int cxl_port_get_switch_dport_bandwidth(struct cxl_port *port,
struct access_coordinate *c);
+static inline struct device *port_to_host(struct cxl_port *port)
+{
+ struct cxl_port *parent = is_cxl_root(port) ? NULL :
+ to_cxl_port(port->dev.parent);
+
+ /*
+ * The host of CXL root port and the first level of ports is
+ * the platform firmware device, the host of all other ports
+ * is their parent port.
+ */
+ if (!parent)
+ return port->uport_dev;
+ else if (is_cxl_root(parent))
+ return parent->uport_dev;
+ else
+ return &parent->dev;
+}
+
static inline struct device *dport_to_host(struct cxl_dport *dport)
{
struct cxl_port *port = dport->port;
static void unregister_port(void *_port)
{
struct cxl_port *port = _port;
- struct cxl_port *parent = parent_port_of(port);
- struct device *lock_dev;
- /*
- * CXL root port's and the first level of ports are unregistered
- * under the platform firmware device lock, all other ports are
- * unregistered while holding their parent port lock.
- */
- if (!parent)
- lock_dev = port->uport_dev;
- else if (is_cxl_root(parent))
- lock_dev = parent->uport_dev;
- else
- lock_dev = &parent->dev;
-
- device_lock_assert(lock_dev);
+ device_lock_assert(port_to_host(port));
port->dead = true;
device_unregister(&port->dev);
}
return NULL;
}
-static struct device *endpoint_host(struct cxl_port *endpoint)
-{
- struct cxl_port *port = to_cxl_port(endpoint->dev.parent);
-
- if (is_cxl_root(port))
- return port->uport_dev;
- return &port->dev;
-}
-
static void delete_endpoint(void *data)
{
struct cxl_memdev *cxlmd = data;
struct cxl_port *endpoint = cxlmd->endpoint;
- struct device *host = endpoint_host(endpoint);
+ struct device *host = port_to_host(endpoint);
scoped_guard(device, host) {
if (host->driver && !endpoint->dead) {
int cxl_endpoint_autoremove(struct cxl_memdev *cxlmd, struct cxl_port *endpoint)
{
- struct device *host = endpoint_host(endpoint);
+ struct device *host = port_to_host(endpoint);
struct device *dev = &cxlmd->dev;
get_device(host);