Lines Matching refs:dev

14 void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns)  in __nd_detach_ndns()  argument
22 nvdimm_bus = walk_to_nvdimm_bus(&ndns->dev); in __nd_detach_ndns()
24 dev_WARN_ONCE(dev, ndns->claim != dev, "%s: invalid claim\n", __func__); in __nd_detach_ndns()
27 put_device(&ndns->dev); in __nd_detach_ndns()
30 void nd_detach_ndns(struct device *dev, in nd_detach_ndns() argument
37 get_device(&ndns->dev); in nd_detach_ndns()
38 nvdimm_bus_lock(&ndns->dev); in nd_detach_ndns()
39 __nd_detach_ndns(dev, _ndns); in nd_detach_ndns()
40 nvdimm_bus_unlock(&ndns->dev); in nd_detach_ndns()
41 put_device(&ndns->dev); in nd_detach_ndns()
44 bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, in __nd_attach_ndns() argument
47 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&attach->dev); in __nd_attach_ndns()
52 dev_WARN_ONCE(dev, *_ndns, "%s: invalid claim\n", __func__); in __nd_attach_ndns()
53 attach->claim = dev; in __nd_attach_ndns()
55 get_device(&attach->dev); in __nd_attach_ndns()
59 bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach, in nd_attach_ndns() argument
64 nvdimm_bus_lock(&attach->dev); in nd_attach_ndns()
65 claimed = __nd_attach_ndns(dev, attach, _ndns); in nd_attach_ndns()
66 nvdimm_bus_unlock(&attach->dev); in nd_attach_ndns()
70 static int namespace_match(struct device *dev, void *data) in namespace_match() argument
74 return strcmp(name, dev_name(dev)) == 0; in namespace_match()
77 static bool is_idle(struct device *dev, struct nd_namespace_common *ndns) in is_idle() argument
79 struct nd_region *nd_region = to_nd_region(dev->parent); in is_idle()
82 if (is_nd_btt(dev)) in is_idle()
84 else if (is_nd_pfn(dev)) in is_idle()
86 else if (is_nd_dax(dev)) in is_idle()
89 if (seed == dev || ndns || dev->driver) in is_idle()
94 struct nd_pfn *to_nd_pfn_safe(struct device *dev) in to_nd_pfn_safe() argument
100 if (is_nd_pfn(dev)) in to_nd_pfn_safe()
101 return to_nd_pfn(dev); in to_nd_pfn_safe()
103 if (is_nd_dax(dev)) { in to_nd_pfn_safe()
104 struct nd_dax *nd_dax = to_nd_dax(dev); in to_nd_pfn_safe()
113 static void nd_detach_and_reset(struct device *dev, in nd_detach_and_reset() argument
117 __nd_detach_ndns(dev, _ndns); in nd_detach_and_reset()
118 if (is_idle(dev, *_ndns)) { in nd_detach_and_reset()
119 nd_device_unregister(dev, ND_ASYNC); in nd_detach_and_reset()
120 } else if (is_nd_btt(dev)) { in nd_detach_and_reset()
121 struct nd_btt *nd_btt = to_nd_btt(dev); in nd_detach_and_reset()
126 } else if (is_nd_pfn(dev) || is_nd_dax(dev)) { in nd_detach_and_reset()
127 struct nd_pfn *nd_pfn = to_nd_pfn_safe(dev); in nd_detach_and_reset()
135 ssize_t nd_namespace_store(struct device *dev, in nd_namespace_store() argument
143 if (dev->driver) { in nd_namespace_store()
144 dev_dbg(dev, "namespace already active\n"); in nd_namespace_store()
162 nd_detach_and_reset(dev, _ndns); in nd_namespace_store()
165 dev_dbg(dev, "namespace already set to: %s\n", in nd_namespace_store()
166 dev_name(&ndns->dev)); in nd_namespace_store()
171 found = device_find_child(dev->parent, name, namespace_match); in nd_namespace_store()
173 dev_dbg(dev, "'%s' not found under %s\n", name, in nd_namespace_store()
174 dev_name(dev->parent)); in nd_namespace_store()
186 if (!is_nd_btt(dev)) { in nd_namespace_store()
192 if (!is_nd_pfn(dev)) { in nd_namespace_store()
198 if (!is_nd_dax(dev)) { in nd_namespace_store()
210 dev_dbg(dev, "%s too small to host\n", name); in nd_namespace_store()
215 WARN_ON_ONCE(!is_nvdimm_bus_locked(dev)); in nd_namespace_store()
216 if (!__nd_attach_ndns(dev, ndns, _ndns)) { in nd_namespace_store()
217 dev_dbg(dev, "%s already claimed\n", in nd_namespace_store()
218 dev_name(&ndns->dev)); in nd_namespace_store()
223 put_device(&ndns->dev); /* from device_find_child */ in nd_namespace_store()
256 struct nd_namespace_io *nsio = to_nd_namespace_io(&ndns->dev); in nsio_rw_bytes()
265 dev_WARN_ONCE(&ndns->dev, 1, "request out of range\n"); in nsio_rw_bytes()
283 cleared = nvdimm_clear_poison(&ndns->dev, in nsio_rw_bytes()
297 ret = nvdimm_flush(to_nd_region(ndns->dev.parent), NULL); in nsio_rw_bytes()
304 int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio, in devm_nsio_enable() argument
314 if (!devm_request_mem_region(dev, range.start, size, in devm_nsio_enable()
315 dev_name(&ndns->dev))) { in devm_nsio_enable()
316 dev_warn(dev, "could not reserve region %pR\n", &nsio->res); in devm_nsio_enable()
321 if (devm_init_badblocks(dev, &nsio->bb)) in devm_nsio_enable()
323 nvdimm_badblocks_populate(to_nd_region(ndns->dev.parent), &nsio->bb, in devm_nsio_enable()
326 nsio->addr = devm_memremap(dev, range.start, size, ARCH_MEMREMAP_PMEM); in devm_nsio_enable()
331 void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio) in devm_nsio_disable() argument
335 devm_memunmap(dev, nsio->addr); in devm_nsio_disable()
336 devm_exit_badblocks(dev, &nsio->bb); in devm_nsio_disable()
337 devm_release_mem_region(dev, res->start, nsio->size); in devm_nsio_disable()