Lines Matching refs:dev
47 static ssize_t devtype_show(struct device *dev, struct device_attribute *attr, in devtype_show() argument
50 return sysfs_emit(buf, "%s\n", dev->type->name); in devtype_show()
54 static int cxl_device_id(const struct device *dev) in cxl_device_id() argument
56 if (dev->type == &cxl_nvdimm_bridge_type) in cxl_device_id()
58 if (dev->type == &cxl_nvdimm_type) in cxl_device_id()
60 if (dev->type == CXL_PMEM_REGION_TYPE()) in cxl_device_id()
62 if (dev->type == CXL_DAX_REGION_TYPE()) in cxl_device_id()
64 if (is_cxl_port(dev)) { in cxl_device_id()
65 if (is_cxl_root(to_cxl_port(dev))) in cxl_device_id()
69 if (is_cxl_memdev(dev)) in cxl_device_id()
71 if (dev->type == CXL_REGION_TYPE()) in cxl_device_id()
73 if (dev->type == &cxl_pmu_type) in cxl_device_id()
78 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, in modalias_show() argument
81 return sysfs_emit(buf, CXL_MODALIAS_FMT "\n", cxl_device_id(dev)); in modalias_show()
95 static ssize_t start_show(struct device *dev, struct device_attribute *attr, in start_show() argument
98 struct cxl_decoder *cxld = to_cxl_decoder(dev); in start_show()
104 static ssize_t size_show(struct device *dev, struct device_attribute *attr, in size_show() argument
107 struct cxl_decoder *cxld = to_cxl_decoder(dev); in size_show()
114 static ssize_t name##_show(struct device *dev, \
117 struct cxl_decoder *cxld = to_cxl_decoder(dev); \
130 static ssize_t target_type_show(struct device *dev, in target_type_show() argument
133 struct cxl_decoder *cxld = to_cxl_decoder(dev); in target_type_show()
170 static ssize_t target_list_show(struct device *dev, in target_list_show() argument
173 struct cxl_switch_decoder *cxlsd = to_cxl_switch_decoder(dev); in target_list_show()
191 static ssize_t mode_show(struct device *dev, struct device_attribute *attr, in mode_show() argument
194 struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev); in mode_show()
199 static ssize_t mode_store(struct device *dev, struct device_attribute *attr, in mode_store() argument
202 struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev); in mode_store()
221 static ssize_t dpa_resource_show(struct device *dev, struct device_attribute *attr, in dpa_resource_show() argument
224 struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev); in dpa_resource_show()
231 static ssize_t dpa_size_show(struct device *dev, struct device_attribute *attr, in dpa_size_show() argument
234 struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev); in dpa_size_show()
240 static ssize_t dpa_size_store(struct device *dev, struct device_attribute *attr, in dpa_size_store() argument
243 struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev); in dpa_size_store()
269 static ssize_t interleave_granularity_show(struct device *dev, in interleave_granularity_show() argument
273 struct cxl_decoder *cxld = to_cxl_decoder(dev); in interleave_granularity_show()
280 static ssize_t interleave_ways_show(struct device *dev, in interleave_ways_show() argument
283 struct cxl_decoder *cxld = to_cxl_decoder(dev); in interleave_ways_show()
331 struct device *dev = kobj_to_dev(kobj); in cxl_root_decoder_visible() local
332 struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev); in cxl_root_decoder_visible()
399 struct cxl_port *port = to_cxl_port(cxld->dev.parent); in __cxl_decoder_release()
402 put_device(&port->dev); in __cxl_decoder_release()
405 static void cxl_endpoint_decoder_release(struct device *dev) in cxl_endpoint_decoder_release() argument
407 struct cxl_endpoint_decoder *cxled = to_cxl_endpoint_decoder(dev); in cxl_endpoint_decoder_release()
413 static void cxl_switch_decoder_release(struct device *dev) in cxl_switch_decoder_release() argument
415 struct cxl_switch_decoder *cxlsd = to_cxl_switch_decoder(dev); in cxl_switch_decoder_release()
421 struct cxl_root_decoder *to_cxl_root_decoder(struct device *dev) in to_cxl_root_decoder() argument
423 if (dev_WARN_ONCE(dev, !is_root_decoder(dev), in to_cxl_root_decoder()
426 return container_of(dev, struct cxl_root_decoder, cxlsd.cxld.dev); in to_cxl_root_decoder()
430 static void cxl_root_decoder_release(struct device *dev) in cxl_root_decoder_release() argument
432 struct cxl_root_decoder *cxlrd = to_cxl_root_decoder(dev); in cxl_root_decoder_release()
458 bool is_endpoint_decoder(struct device *dev) in is_endpoint_decoder() argument
460 return dev->type == &cxl_decoder_endpoint_type; in is_endpoint_decoder()
464 bool is_root_decoder(struct device *dev) in is_root_decoder() argument
466 return dev->type == &cxl_decoder_root_type; in is_root_decoder()
470 bool is_switch_decoder(struct device *dev) in is_switch_decoder() argument
472 return is_root_decoder(dev) || dev->type == &cxl_decoder_switch_type; in is_switch_decoder()
476 struct cxl_decoder *to_cxl_decoder(struct device *dev) in to_cxl_decoder() argument
478 if (dev_WARN_ONCE(dev, in to_cxl_decoder()
479 !is_switch_decoder(dev) && !is_endpoint_decoder(dev), in to_cxl_decoder()
482 return container_of(dev, struct cxl_decoder, dev); in to_cxl_decoder()
486 struct cxl_endpoint_decoder *to_cxl_endpoint_decoder(struct device *dev) in to_cxl_endpoint_decoder() argument
488 if (dev_WARN_ONCE(dev, !is_endpoint_decoder(dev), in to_cxl_endpoint_decoder()
491 return container_of(dev, struct cxl_endpoint_decoder, cxld.dev); in to_cxl_endpoint_decoder()
495 struct cxl_switch_decoder *to_cxl_switch_decoder(struct device *dev) in to_cxl_switch_decoder() argument
497 if (dev_WARN_ONCE(dev, !is_switch_decoder(dev), in to_cxl_switch_decoder()
500 return container_of(dev, struct cxl_switch_decoder, cxld.dev); in to_cxl_switch_decoder()
518 static void cxl_port_release(struct device *dev) in cxl_port_release() argument
520 struct cxl_port *port = to_cxl_port(dev); in cxl_port_release()
544 bool is_cxl_port(const struct device *dev) in is_cxl_port() argument
546 return dev->type == &cxl_port_type; in is_cxl_port()
550 struct cxl_port *to_cxl_port(const struct device *dev) in to_cxl_port() argument
552 if (dev_WARN_ONCE(dev, dev->type != &cxl_port_type, in to_cxl_port()
555 return container_of(dev, struct cxl_port, dev); in to_cxl_port()
568 parent = to_cxl_port(port->dev.parent); in unregister_port()
580 lock_dev = &parent->dev; in unregister_port()
584 device_unregister(&port->dev); in unregister_port()
591 sysfs_remove_link(&port->dev.kobj, "uport"); in cxl_unlink_uport()
598 rc = sysfs_create_link(&port->dev.kobj, &port->uport_dev->kobj, in devm_cxl_link_uport()
609 sysfs_remove_link(&port->dev.kobj, "parent_dport"); in cxl_unlink_parent_dport()
621 rc = sysfs_create_link(&port->dev.kobj, &parent_dport->dport_dev->kobj, in devm_cxl_link_parent_dport()
635 struct device *dev; in cxl_port_alloc() local
654 dev = &port->dev; in cxl_port_alloc()
659 dev->parent = &parent_port->dev; in cxl_port_alloc()
669 !is_cxl_root(to_cxl_port(iter->dev.parent))) in cxl_port_alloc()
670 iter = to_cxl_port(iter->dev.parent); in cxl_port_alloc()
680 dev->parent = uport_dev; in cxl_port_alloc()
690 device_initialize(dev); in cxl_port_alloc()
691 lockdep_set_class_and_subclass(&dev->mutex, &cxl_port_key, port->depth); in cxl_port_alloc()
692 device_set_pm_not_required(dev); in cxl_port_alloc()
693 dev->bus = &cxl_bus_type; in cxl_port_alloc()
694 dev->type = &cxl_port_type; in cxl_port_alloc()
724 return cxl_setup_comp_regs(&port->dev, &port->comp_map, in cxl_port_setup_regs()
753 struct device *dev; in __devm_cxl_add_port() local
760 dev = &port->dev; in __devm_cxl_add_port()
762 rc = dev_set_name(dev, "endpoint%d", port->id); in __devm_cxl_add_port()
764 rc = dev_set_name(dev, "port%d", port->id); in __devm_cxl_add_port()
766 rc = dev_set_name(dev, "root%d", port->id); in __devm_cxl_add_port()
774 rc = device_add(dev); in __devm_cxl_add_port()
793 put_device(dev); in __devm_cxl_add_port()
818 parent_port ? dev_name(&parent_port->dev) : "", in devm_cxl_add_port()
823 dev_name(&port->dev), in devm_cxl_add_port()
825 parent_port ? dev_name(&parent_port->dev) : "", in devm_cxl_add_port()
870 static bool dev_is_cxl_root_child(struct device *dev) in dev_is_cxl_root_child() argument
874 if (!is_cxl_port(dev)) in dev_is_cxl_root_child()
877 port = to_cxl_port(dev); in dev_is_cxl_root_child()
881 parent = to_cxl_port(port->dev.parent); in dev_is_cxl_root_child()
893 iter = to_cxl_port(iter->dev.parent); in find_cxl_root()
897 get_device(&iter->dev); in find_cxl_root()
907 device_lock_assert(&port->dev); in find_dport()
919 device_lock_assert(&port->dev); in add_dport()
922 dev_err(&port->dev, in add_dport()
948 device_lock(&port->dev); in cond_cxl_root_lock()
954 device_unlock(&port->dev); in cond_cxl_root_unlock()
973 sysfs_remove_link(&port->dev.kobj, link_name); in cxl_dport_unlink()
989 host = &port->dev; in __devm_cxl_add_dport()
992 dev_WARN_ONCE(&port->dev, 1, "dport:%s bad devm context\n", in __devm_cxl_add_dport()
1010 rc = cxl_dport_setup_regs(&port->dev, dport, in __devm_cxl_add_dport()
1049 rc = sysfs_create_link(&port->dev.kobj, &dport_dev->kobj, link_name); in __devm_cxl_add_dport()
1081 dev_name(&port->dev), PTR_ERR(dport)); in devm_cxl_add_dport()
1084 dev_name(&port->dev)); in devm_cxl_add_dport()
1107 dev_dbg(&port->dev, "failed to add RCH dport, missing RCRB\n"); in devm_cxl_add_rch_dport()
1115 dev_name(&port->dev), PTR_ERR(dport)); in devm_cxl_add_rch_dport()
1118 dev_name(&port->dev)); in devm_cxl_add_rch_dport()
1130 device_lock(&port->dev); in add_ep()
1132 device_unlock(&port->dev); in add_ep()
1137 device_unlock(&port->dev); in add_ep()
1175 static int match_port_by_dport(struct device *dev, const void *data) in match_port_by_dport() argument
1181 if (!is_cxl_port(dev)) in match_port_by_dport()
1183 if (ctx->parent_port && dev->parent != &ctx->parent_port->dev) in match_port_by_dport()
1186 port = to_cxl_port(dev); in match_port_by_dport()
1195 struct device *dev; in __find_cxl_port() local
1200 dev = bus_find_device(&cxl_bus_type, NULL, ctx, match_port_by_dport); in __find_cxl_port()
1201 if (dev) in __find_cxl_port()
1202 return to_cxl_port(dev); in __find_cxl_port()
1241 static struct device *grandparent(struct device *dev) in grandparent() argument
1243 if (dev && dev->parent) in grandparent()
1244 return dev->parent->parent; in grandparent()
1250 struct cxl_port *port = to_cxl_port(endpoint->dev.parent); in endpoint_host()
1254 return &port->dev; in endpoint_host()
1271 put_device(&endpoint->dev); in delete_endpoint()
1278 struct device *dev = &cxlmd->dev; in cxl_endpoint_autoremove() local
1281 get_device(&endpoint->dev); in cxl_endpoint_autoremove()
1284 return devm_add_action_or_reset(dev, delete_endpoint, cxlmd); in cxl_endpoint_autoremove()
1299 devm_release_action(port->dev.parent, cxl_unlink_parent_dport, port); in delete_switch_port()
1300 devm_release_action(port->dev.parent, cxl_unlink_uport, port); in delete_switch_port()
1301 devm_release_action(port->dev.parent, unregister_port, port); in delete_switch_port()
1309 device_lock_assert(&port->dev); in reap_dports()
1312 devm_release_action(&port->dev, cxl_dport_unlink, dport); in reap_dports()
1313 devm_release_action(&port->dev, cxl_dport_remove, dport); in reap_dports()
1314 devm_kfree(&port->dev, dport); in reap_dports()
1323 static int port_has_memdev(struct device *dev, const void *data) in port_has_memdev() argument
1328 if (!is_cxl_port(dev)) in port_has_memdev()
1331 port = to_cxl_port(dev); in port_has_memdev()
1348 struct device *dev; in cxl_detach_ep() local
1352 dev = bus_find_device(&cxl_bus_type, NULL, &ctx, in cxl_detach_ep()
1354 if (!dev) in cxl_detach_ep()
1356 port = to_cxl_port(dev); in cxl_detach_ep()
1358 parent_port = to_cxl_port(port->dev.parent); in cxl_detach_ep()
1359 device_lock(&parent_port->dev); in cxl_detach_ep()
1360 device_lock(&port->dev); in cxl_detach_ep()
1362 dev_dbg(&cxlmd->dev, "disconnect %s from %s\n", in cxl_detach_ep()
1363 ep ? dev_name(ep->ep) : "", dev_name(&port->dev)); in cxl_detach_ep()
1366 !is_cxl_root(parent_port) && parent_port->dev.driver) { in cxl_detach_ep()
1376 device_unlock(&port->dev); in cxl_detach_ep()
1379 dev_dbg(&cxlmd->dev, "delete %s\n", in cxl_detach_ep()
1380 dev_name(&port->dev)); in cxl_detach_ep()
1383 put_device(&port->dev); in cxl_detach_ep()
1384 device_unlock(&parent_port->dev); in cxl_detach_ep()
1388 static resource_size_t find_component_registers(struct device *dev) in find_component_registers() argument
1397 if (!dev_is_pci(dev)) in find_component_registers()
1400 pdev = to_pci_dev(dev); in find_component_registers()
1422 dev_dbg(&cxlmd->dev, "%s is a root dport\n", in add_port_attach_ep()
1433 device_lock(&parent_port->dev); in add_port_attach_ep()
1434 if (!parent_port->dev.driver) { in add_port_attach_ep()
1435 dev_warn(&cxlmd->dev, in add_port_attach_ep()
1437 dev_name(&parent_port->dev), dev_name(uport_dev)); in add_port_attach_ep()
1445 port = devm_cxl_add_port(&parent_port->dev, uport_dev, in add_port_attach_ep()
1452 device_unlock(&parent_port->dev); in add_port_attach_ep()
1457 dev_dbg(&cxlmd->dev, "add to new port %s:%s\n", in add_port_attach_ep()
1458 dev_name(&port->dev), dev_name(port->uport_dev)); in add_port_attach_ep()
1459 rc = cxl_add_ep(dport, &cxlmd->dev); in add_port_attach_ep()
1467 put_device(&port->dev); in add_port_attach_ep()
1470 put_device(&parent_port->dev); in add_port_attach_ep()
1476 struct device *dev = &cxlmd->dev; in devm_cxl_enumerate_ports() local
1487 rc = devm_add_action_or_reset(&cxlmd->dev, cxl_detach_ep, cxlmd); in devm_cxl_enumerate_ports()
1497 for (iter = dev; iter; iter = grandparent(iter)) { in devm_cxl_enumerate_ports()
1508 dev_warn(dev, "at %s no parent for dport: %s\n", in devm_cxl_enumerate_ports()
1513 dev_dbg(dev, "scan: iter: %s dport_dev: %s parent: %s\n", in devm_cxl_enumerate_ports()
1518 dev_dbg(&cxlmd->dev, in devm_cxl_enumerate_ports()
1520 dev_name(&port->dev), in devm_cxl_enumerate_ports()
1522 rc = cxl_add_ep(dport, &cxlmd->dev); in devm_cxl_enumerate_ports()
1532 put_device(&port->dev); in devm_cxl_enumerate_ports()
1537 if (!dev_is_cxl_root_child(&port->dev)) { in devm_cxl_enumerate_ports()
1538 put_device(&port->dev); in devm_cxl_enumerate_ports()
1542 put_device(&port->dev); in devm_cxl_enumerate_ports()
1564 return find_cxl_port(pdev->dev.parent, dport); in cxl_pci_find_port()
1571 return find_cxl_port(grandparent(&cxlmd->dev), dport); in cxl_mem_find_port()
1583 device_lock_assert(&port->dev); in decoder_populate_targets()
1607 if (dev_WARN_ONCE(&cxld->dev, iw != cxlsd->nr_targets, in cxl_hb_modulo()
1629 struct device *dev; in cxl_decoder_init() local
1637 get_device(&port->dev); in cxl_decoder_init()
1640 dev = &cxld->dev; in cxl_decoder_init()
1641 device_initialize(dev); in cxl_decoder_init()
1642 lockdep_set_class(&dev->mutex, &cxl_decoder_key); in cxl_decoder_init()
1643 device_set_pm_not_required(dev); in cxl_decoder_init()
1644 dev->parent = &port->dev; in cxl_decoder_init()
1645 dev->bus = &cxl_bus_type; in cxl_decoder_init()
1709 cxld->dev.type = &cxl_decoder_root_type; in cxl_root_decoder_alloc()
1717 put_device(&cxld->dev); in cxl_root_decoder_alloc()
1758 cxld->dev.type = &cxl_decoder_switch_type; in cxl_switch_decoder_alloc()
1790 cxld->dev.type = &cxl_decoder_endpoint_type; in cxl_endpoint_decoder_alloc()
1817 struct device *dev; in cxl_decoder_add_locked() local
1829 dev = &cxld->dev; in cxl_decoder_add_locked()
1831 port = to_cxl_port(cxld->dev.parent); in cxl_decoder_add_locked()
1832 if (!is_endpoint_decoder(dev)) { in cxl_decoder_add_locked()
1833 struct cxl_switch_decoder *cxlsd = to_cxl_switch_decoder(dev); in cxl_decoder_add_locked()
1837 dev_err(&port->dev, in cxl_decoder_add_locked()
1843 rc = dev_set_name(dev, "decoder%d.%d", port->id, cxld->id); in cxl_decoder_add_locked()
1847 return device_add(dev); in cxl_decoder_add_locked()
1875 port = to_cxl_port(cxld->dev.parent); in cxl_decoder_add()
1877 device_lock(&port->dev); in cxl_decoder_add()
1879 device_unlock(&port->dev); in cxl_decoder_add()
1885 static void cxld_unregister(void *dev) in cxld_unregister() argument
1889 if (is_endpoint_decoder(dev)) { in cxld_unregister()
1890 cxled = to_cxl_endpoint_decoder(dev); in cxld_unregister()
1894 device_unregister(dev); in cxld_unregister()
1899 return devm_add_action_or_reset(host, cxld_unregister, &cxld->dev); in cxl_decoder_autoremove()
1942 static int cxl_bus_uevent(const struct device *dev, struct kobj_uevent_env *env) in cxl_bus_uevent() argument
1945 cxl_device_id(dev)); in cxl_bus_uevent()
1948 static int cxl_bus_match(struct device *dev, struct device_driver *drv) in cxl_bus_match() argument
1950 return cxl_device_id(dev) == to_cxl_drv(drv)->id; in cxl_bus_match()
1953 static int cxl_bus_probe(struct device *dev) in cxl_bus_probe() argument
1957 rc = to_cxl_drv(dev->driver)->probe(dev); in cxl_bus_probe()
1958 dev_dbg(dev, "probe: %d\n", rc); in cxl_bus_probe()
1962 static void cxl_bus_remove(struct device *dev) in cxl_bus_remove() argument
1964 struct cxl_driver *cxl_drv = to_cxl_drv(dev->driver); in cxl_bus_remove()
1967 cxl_drv->remove(dev); in cxl_bus_remove()