Lines Matching refs:dev

31 static int to_nd_device_type(const struct device *dev)  in to_nd_device_type()  argument
33 if (is_nvdimm(dev)) in to_nd_device_type()
35 else if (is_memory(dev)) in to_nd_device_type()
37 else if (is_nd_dax(dev)) in to_nd_device_type()
39 else if (is_nd_region(dev->parent)) in to_nd_device_type()
40 return nd_region_to_nstype(to_nd_region(dev->parent)); in to_nd_device_type()
45 static int nvdimm_bus_uevent(const struct device *dev, struct kobj_uevent_env *env) in nvdimm_bus_uevent() argument
48 to_nd_device_type(dev)); in nvdimm_bus_uevent()
51 static struct module *to_bus_provider(struct device *dev) in to_bus_provider() argument
54 if (is_nd_region(dev)) { in to_bus_provider()
55 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); in to_bus_provider()
64 nvdimm_bus_lock(&nvdimm_bus->dev); in nvdimm_bus_probe_start()
66 nvdimm_bus_unlock(&nvdimm_bus->dev); in nvdimm_bus_probe_start()
71 nvdimm_bus_lock(&nvdimm_bus->dev); in nvdimm_bus_probe_end()
74 nvdimm_bus_unlock(&nvdimm_bus->dev); in nvdimm_bus_probe_end()
77 static int nvdimm_bus_probe(struct device *dev) in nvdimm_bus_probe() argument
79 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); in nvdimm_bus_probe()
80 struct module *provider = to_bus_provider(dev); in nvdimm_bus_probe()
81 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); in nvdimm_bus_probe()
87 dev_dbg(&nvdimm_bus->dev, "START: %s.probe(%s)\n", in nvdimm_bus_probe()
88 dev->driver->name, dev_name(dev)); in nvdimm_bus_probe()
91 rc = nd_drv->probe(dev); in nvdimm_bus_probe()
93 dev->parent && is_nd_region(dev->parent)) in nvdimm_bus_probe()
94 nd_region_advance_seeds(to_nd_region(dev->parent), dev); in nvdimm_bus_probe()
97 dev_dbg(&nvdimm_bus->dev, "END: %s.probe(%s) = %d\n", dev->driver->name, in nvdimm_bus_probe()
98 dev_name(dev), rc); in nvdimm_bus_probe()
105 static void nvdimm_bus_remove(struct device *dev) in nvdimm_bus_remove() argument
107 struct nd_device_driver *nd_drv = to_nd_device_driver(dev->driver); in nvdimm_bus_remove()
108 struct module *provider = to_bus_provider(dev); in nvdimm_bus_remove()
109 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); in nvdimm_bus_remove()
112 nd_drv->remove(dev); in nvdimm_bus_remove()
114 dev_dbg(&nvdimm_bus->dev, "%s.remove(%s)\n", dev->driver->name, in nvdimm_bus_remove()
115 dev_name(dev)); in nvdimm_bus_remove()
119 static void nvdimm_bus_shutdown(struct device *dev) in nvdimm_bus_shutdown() argument
121 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); in nvdimm_bus_shutdown()
124 if (dev->driver) in nvdimm_bus_shutdown()
125 nd_drv = to_nd_device_driver(dev->driver); in nvdimm_bus_shutdown()
128 nd_drv->shutdown(dev); in nvdimm_bus_shutdown()
129 dev_dbg(&nvdimm_bus->dev, "%s.shutdown(%s)\n", in nvdimm_bus_shutdown()
130 dev->driver->name, dev_name(dev)); in nvdimm_bus_shutdown()
134 void nd_device_notify(struct device *dev, enum nvdimm_event event) in nd_device_notify() argument
136 device_lock(dev); in nd_device_notify()
137 if (dev->driver) { in nd_device_notify()
140 nd_drv = to_nd_device_driver(dev->driver); in nd_device_notify()
142 nd_drv->notify(dev, event); in nd_device_notify()
144 device_unlock(dev); in nd_device_notify()
150 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); in nvdimm_region_notify()
156 nd_device_notify(&nd_region->dev, event); in nvdimm_region_notify()
164 static int nvdimm_clear_badblocks_region(struct device *dev, void *data) in nvdimm_clear_badblocks_region() argument
172 if (!is_memory(dev)) in nvdimm_clear_badblocks_region()
175 nd_region = to_nd_region(dev); in nvdimm_clear_badblocks_region()
200 device_for_each_child(&nvdimm_bus->dev, &ctx, in nvdimm_clear_badblocks_regions()
214 long nvdimm_clear_poison(struct device *dev, phys_addr_t phys, in nvdimm_clear_poison() argument
217 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); in nvdimm_clear_poison()
272 static int nvdimm_bus_match(struct device *dev, struct device_driver *drv);
283 static void nvdimm_bus_release(struct device *dev) in nvdimm_bus_release() argument
287 nvdimm_bus = container_of(dev, struct nvdimm_bus, dev); in nvdimm_bus_release()
297 bool is_nvdimm_bus(struct device *dev) in is_nvdimm_bus() argument
299 return dev->type == &nvdimm_bus_dev_type; in is_nvdimm_bus()
304 struct device *dev; in walk_to_nvdimm_bus() local
306 for (dev = nd_dev; dev; dev = dev->parent) in walk_to_nvdimm_bus()
307 if (is_nvdimm_bus(dev)) in walk_to_nvdimm_bus()
309 dev_WARN_ONCE(nd_dev, !dev, "invalid dev, not on nd bus\n"); in walk_to_nvdimm_bus()
310 if (dev) in walk_to_nvdimm_bus()
311 return to_nvdimm_bus(dev); in walk_to_nvdimm_bus()
315 struct nvdimm_bus *to_nvdimm_bus(struct device *dev) in to_nvdimm_bus() argument
319 nvdimm_bus = container_of(dev, struct nvdimm_bus, dev); in to_nvdimm_bus()
320 WARN_ON(!is_nvdimm_bus(dev)); in to_nvdimm_bus()
327 return to_nvdimm_bus(nvdimm->dev.parent); in nvdimm_to_bus()
353 nvdimm_bus->dev.parent = parent; in nvdimm_bus_register()
354 nvdimm_bus->dev.type = &nvdimm_bus_dev_type; in nvdimm_bus_register()
355 nvdimm_bus->dev.groups = nd_desc->attr_groups; in nvdimm_bus_register()
356 nvdimm_bus->dev.bus = &nvdimm_bus_type; in nvdimm_bus_register()
357 nvdimm_bus->dev.of_node = nd_desc->of_node; in nvdimm_bus_register()
358 device_initialize(&nvdimm_bus->dev); in nvdimm_bus_register()
359 lockdep_set_class(&nvdimm_bus->dev.mutex, &nvdimm_bus_key); in nvdimm_bus_register()
360 device_set_pm_not_required(&nvdimm_bus->dev); in nvdimm_bus_register()
361 rc = dev_set_name(&nvdimm_bus->dev, "ndbus%d", nvdimm_bus->id); in nvdimm_bus_register()
365 rc = device_add(&nvdimm_bus->dev); in nvdimm_bus_register()
367 dev_dbg(&nvdimm_bus->dev, "registration failed: %d\n", rc); in nvdimm_bus_register()
373 put_device(&nvdimm_bus->dev); in nvdimm_bus_register()
382 device_unregister(&nvdimm_bus->dev); in nvdimm_bus_unregister()
386 static int child_unregister(struct device *dev, void *data) in child_unregister() argument
394 if (dev->class) in child_unregister()
397 if (is_nvdimm(dev)) in child_unregister()
398 nvdimm_delete(to_nvdimm(dev)); in child_unregister()
400 nd_device_unregister(dev, ND_SYNC); in child_unregister()
416 static void nd_bus_remove(struct device *dev) in nd_bus_remove() argument
418 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); in nd_bus_remove()
428 device_for_each_child(&nvdimm_bus->dev, NULL, child_unregister); in nd_bus_remove()
437 static int nd_bus_probe(struct device *dev) in nd_bus_probe() argument
439 struct nvdimm_bus *nvdimm_bus = to_nvdimm_bus(dev); in nd_bus_probe()
451 dev_set_drvdata(dev, nvdimm_bus->nd_desc); in nd_bus_probe()
468 static int nvdimm_bus_match(struct device *dev, struct device_driver *drv) in nvdimm_bus_match() argument
472 if (is_nvdimm_bus(dev) && nd_drv == &nd_bus_driver) in nvdimm_bus_match()
475 return !!test_bit(to_nd_device_type(dev), &nd_drv->type); in nvdimm_bus_match()
488 struct device *dev = d; in nd_async_device_register() local
490 if (device_add(dev) != 0) { in nd_async_device_register()
491 dev_err(dev, "%s: failed\n", __func__); in nd_async_device_register()
492 put_device(dev); in nd_async_device_register()
494 put_device(dev); in nd_async_device_register()
495 if (dev->parent) in nd_async_device_register()
496 put_device(dev->parent); in nd_async_device_register()
501 struct device *dev = d; in nd_async_device_unregister() local
504 nvdimm_bus_lock(dev); in nd_async_device_unregister()
505 nvdimm_bus_unlock(dev); in nd_async_device_unregister()
507 device_unregister(dev); in nd_async_device_unregister()
508 put_device(dev); in nd_async_device_unregister()
511 static void __nd_device_register(struct device *dev, bool sync) in __nd_device_register() argument
513 if (!dev) in __nd_device_register()
522 if (is_nd_region(dev)) in __nd_device_register()
523 set_dev_node(dev, to_nd_region(dev)->numa_node); in __nd_device_register()
525 dev->bus = &nvdimm_bus_type; in __nd_device_register()
526 device_set_pm_not_required(dev); in __nd_device_register()
527 if (dev->parent) { in __nd_device_register()
528 get_device(dev->parent); in __nd_device_register()
529 if (dev_to_node(dev) == NUMA_NO_NODE) in __nd_device_register()
530 set_dev_node(dev, dev_to_node(dev->parent)); in __nd_device_register()
532 get_device(dev); in __nd_device_register()
535 nd_async_device_register(dev, 0); in __nd_device_register()
537 async_schedule_dev_domain(nd_async_device_register, dev, in __nd_device_register()
541 void nd_device_register(struct device *dev) in nd_device_register() argument
543 __nd_device_register(dev, false); in nd_device_register()
547 void nd_device_register_sync(struct device *dev) in nd_device_register_sync() argument
549 __nd_device_register(dev, true); in nd_device_register_sync()
552 void nd_device_unregister(struct device *dev, enum nd_async_mode mode) in nd_device_unregister() argument
564 if (!kill_device(dev)) in nd_device_unregister()
567 get_device(dev); in nd_device_unregister()
568 async_schedule_domain(nd_async_device_unregister, dev, in nd_device_unregister()
579 device_lock(dev); in nd_device_unregister()
580 killed = kill_device(dev); in nd_device_unregister()
581 device_unlock(dev); in nd_device_unregister()
587 device_unregister(dev); in nd_device_unregister()
625 struct device *dev = disk_to_dev(disk)->parent; in nvdimm_check_and_set_ro() local
626 struct nd_region *nd_region = to_nd_region(dev->parent); in nvdimm_check_and_set_ro()
633 dev_info(dev, "%s read-%s, marking %s read-%s\n", in nvdimm_check_and_set_ro()
634 dev_name(&nd_region->dev), nd_region->ro ? "only" : "write", in nvdimm_check_and_set_ro()
640 static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, in modalias_show() argument
644 to_nd_device_type(dev)); in modalias_show()
648 static ssize_t devtype_show(struct device *dev, struct device_attribute *attr, in devtype_show() argument
651 return sprintf(buf, "%s\n", dev->type->name); in devtype_show()
668 static ssize_t numa_node_show(struct device *dev, in numa_node_show() argument
671 return sprintf(buf, "%d\n", dev_to_node(dev)); in numa_node_show()
675 static int nvdimm_dev_to_target_node(struct device *dev) in nvdimm_dev_to_target_node() argument
677 struct device *parent = dev->parent; in nvdimm_dev_to_target_node()
680 if (is_nd_region(dev)) in nvdimm_dev_to_target_node()
681 nd_region = to_nd_region(dev); in nvdimm_dev_to_target_node()
690 static ssize_t target_node_show(struct device *dev, in target_node_show() argument
693 return sprintf(buf, "%d\n", nvdimm_dev_to_target_node(dev)); in target_node_show()
706 struct device *dev = container_of(kobj, typeof(*dev), kobj); in nd_numa_attr_visible() local
712 nvdimm_dev_to_target_node(dev) == NUMA_NO_NODE) in nd_numa_attr_visible()
726 static void ndctl_release(struct device *dev) in ndctl_release() argument
728 kfree(dev); in ndctl_release()
736 struct device *dev; in nvdimm_bus_create_ndctl() local
739 dev = kzalloc(sizeof(*dev), GFP_KERNEL); in nvdimm_bus_create_ndctl()
740 if (!dev) in nvdimm_bus_create_ndctl()
742 device_initialize(dev); in nvdimm_bus_create_ndctl()
743 lockdep_set_class(&dev->mutex, &nvdimm_ndctl_key); in nvdimm_bus_create_ndctl()
744 device_set_pm_not_required(dev); in nvdimm_bus_create_ndctl()
745 dev->class = nd_class; in nvdimm_bus_create_ndctl()
746 dev->parent = &nvdimm_bus->dev; in nvdimm_bus_create_ndctl()
747 dev->devt = devt; in nvdimm_bus_create_ndctl()
748 dev->release = ndctl_release; in nvdimm_bus_create_ndctl()
749 rc = dev_set_name(dev, "ndctl%d", nvdimm_bus->id); in nvdimm_bus_create_ndctl()
753 rc = device_add(dev); in nvdimm_bus_create_ndctl()
755 dev_dbg(&nvdimm_bus->dev, "failed to register ndctl%d: %d\n", in nvdimm_bus_create_ndctl()
762 put_device(dev); in nvdimm_bus_create_ndctl()
932 void wait_nvdimm_bus_probe_idle(struct device *dev) in wait_nvdimm_bus_probe_idle() argument
934 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(dev); in wait_nvdimm_bus_probe_idle()
939 nvdimm_bus_unlock(dev); in wait_nvdimm_bus_probe_idle()
940 device_unlock(dev); in wait_nvdimm_bus_probe_idle()
943 device_lock(dev); in wait_nvdimm_bus_probe_idle()
944 nvdimm_bus_lock(dev); in wait_nvdimm_bus_probe_idle()
948 static int nd_pmem_forget_poison_check(struct device *dev, void *data) in nd_pmem_forget_poison_check() argument
952 struct nd_btt *nd_btt = is_nd_btt(dev) ? to_nd_btt(dev) : NULL; in nd_pmem_forget_poison_check()
953 struct nd_pfn *nd_pfn = is_nd_pfn(dev) ? to_nd_pfn(dev) : NULL; in nd_pmem_forget_poison_check()
954 struct nd_dax *nd_dax = is_nd_dax(dev) ? to_nd_dax(dev) : NULL; in nd_pmem_forget_poison_check()
959 if (nd_dax || !dev->driver) in nd_pmem_forget_poison_check()
976 ndns = to_ndns(dev); in nd_pmem_forget_poison_check()
978 nsio = to_nd_namespace_io(&ndns->dev); in nd_pmem_forget_poison_check()
989 static int nd_ns_forget_poison_check(struct device *dev, void *data) in nd_ns_forget_poison_check() argument
991 return device_for_each_child(dev, data, nd_pmem_forget_poison_check); in nd_ns_forget_poison_check()
1010 return device_for_each_child(&nvdimm_bus->dev, data, in nd_cmd_clear_to_send()
1017 wait_nvdimm_bus_probe_idle(&nvdimm_bus->dev); in nd_cmd_clear_to_send()
1029 struct device *dev = &nvdimm_bus->dev; in __nd_ioctl() local
1045 dimm_name = dev_name(&nvdimm->dev); in __nd_ioctl()
1088 dev_dbg(dev, "'%s' command while read-only.\n", in __nd_ioctl()
1105 dev_err(dev, "%s:%s unknown input size cmd: %s field: %d\n", in __nd_ioctl()
1123 dev_dbg(dev, "%s, idx: %llu, in: %u, out: %u, len %llu\n", in __nd_ioctl()
1141 dev_dbg(dev, "%s unknown output size cmd: %s field: %d\n", in __nd_ioctl()
1160 dev_dbg(dev, "%s cmd: %s buf_len: %llu > %d\n", dimm_name, in __nd_ioctl()
1177 device_lock(dev); in __nd_ioctl()
1178 nvdimm_bus_lock(dev); in __nd_ioctl()
1198 nvdimm_bus_unlock(dev); in __nd_ioctl()
1199 device_unlock(dev); in __nd_ioctl()
1212 static int match_dimm(struct device *dev, void *data) in match_dimm() argument
1216 if (is_nvdimm(dev)) { in match_dimm()
1217 struct nvdimm *nvdimm = to_nvdimm(dev); in match_dimm()
1238 struct device *dev; in nd_ioctl() local
1240 dev = device_find_child(&nvdimm_bus->dev, in nd_ioctl()
1242 if (!dev) in nd_ioctl()
1244 nvdimm = to_nvdimm(dev); in nd_ioctl()
1264 put_device(&nvdimm->dev); in nd_ioctl()