Lines Matching refs:dev_dax
139 static u64 dev_dax_size(struct dev_dax *dev_dax) in dev_dax_size() argument
144 device_lock_assert(&dev_dax->dev); in dev_dax_size()
146 for (i = 0; i < dev_dax->nr_range; i++) in dev_dax_size()
147 size += range_len(&dev_dax->ranges[i].range); in dev_dax_size()
155 struct dev_dax *dev_dax = to_dev_dax(dev); in dax_bus_probe() local
156 struct dax_region *dax_region = dev_dax->region; in dax_bus_probe()
159 if (dev_dax_size(dev_dax) == 0 || dev_dax->id < 0) in dax_bus_probe()
162 rc = dax_drv->probe(dev_dax); in dax_bus_probe()
180 struct dev_dax *dev_dax = to_dev_dax(dev); in dax_bus_remove() local
182 return dax_drv->remove(dev_dax); in dax_bus_remove()
336 struct dev_dax *dev_dax = devm_create_dev_dax(&data); in create_store() local
338 if (IS_ERR(dev_dax)) in create_store()
339 rc = PTR_ERR(dev_dax); in create_store()
349 dax_region->seed = &dev_dax->dev; in create_store()
350 dax_region->youngest = &dev_dax->dev; in create_store()
360 void kill_dev_dax(struct dev_dax *dev_dax) in kill_dev_dax() argument
362 struct dax_device *dax_dev = dev_dax->dax_dev; in kill_dev_dax()
370 static void trim_dev_dax_range(struct dev_dax *dev_dax) in trim_dev_dax_range() argument
372 int i = dev_dax->nr_range - 1; in trim_dev_dax_range()
373 struct range *range = &dev_dax->ranges[i].range; in trim_dev_dax_range()
374 struct dax_region *dax_region = dev_dax->region; in trim_dev_dax_range()
377 dev_dbg(&dev_dax->dev, "delete range[%d]: %#llx:%#llx\n", i, in trim_dev_dax_range()
382 if (--dev_dax->nr_range == 0) { in trim_dev_dax_range()
383 kfree(dev_dax->ranges); in trim_dev_dax_range()
384 dev_dax->ranges = NULL; in trim_dev_dax_range()
388 static void free_dev_dax_ranges(struct dev_dax *dev_dax) in free_dev_dax_ranges() argument
390 while (dev_dax->nr_range) in free_dev_dax_ranges()
391 trim_dev_dax_range(dev_dax); in free_dev_dax_ranges()
396 struct dev_dax *dev_dax = to_dev_dax(dev); in unregister_dev_dax() local
400 kill_dev_dax(dev_dax); in unregister_dev_dax()
401 free_dev_dax_ranges(dev_dax); in unregister_dev_dax()
407 static int __free_dev_dax_id(struct dev_dax *dev_dax) in __free_dev_dax_id() argument
409 struct dax_region *dax_region = dev_dax->region; in __free_dev_dax_id()
410 struct device *dev = &dev_dax->dev; in __free_dev_dax_id()
411 int rc = dev_dax->id; in __free_dev_dax_id()
415 if (is_static(dax_region) || dev_dax->id < 0) in __free_dev_dax_id()
417 ida_free(&dax_region->ida, dev_dax->id); in __free_dev_dax_id()
418 dev_dax->id = -1; in __free_dev_dax_id()
422 static int free_dev_dax_id(struct dev_dax *dev_dax) in free_dev_dax_id() argument
424 struct device *dev = &dev_dax->dev; in free_dev_dax_id()
428 rc = __free_dev_dax_id(dev_dax); in free_dev_dax_id()
437 struct dev_dax *dev_dax; in delete_store() local
451 dev_dax = to_dev_dax(victim); in delete_store()
452 if (victim->driver || dev_dax_size(dev_dax)) in delete_store()
461 if (dev_dax->id > 0) { in delete_store()
462 do_del = __free_dev_dax_id(dev_dax) >= 0; in delete_store()
595 struct dev_dax *dev_dax = to_dev_dax(dev->parent); in dax_mapping_release() local
597 ida_free(&dev_dax->ida, mapping->id); in dax_mapping_release()
605 struct dev_dax *dev_dax = to_dev_dax(dev->parent); in unregister_dax_mapping() local
606 struct dax_region *dax_region = dev_dax->region; in unregister_dax_mapping()
612 dev_dax->ranges[mapping->range_id].mapping = NULL; in unregister_dax_mapping()
622 struct dev_dax *dev_dax = to_dev_dax(dev->parent); in get_dax_range() local
623 struct dax_region *dax_region = dev_dax->region; in get_dax_range()
631 return &dev_dax->ranges[mapping->range_id]; in get_dax_range()
637 struct dev_dax *dev_dax = to_dev_dax(mapping->dev.parent); in put_dax_range() local
638 struct dax_region *dax_region = dev_dax->region; in put_dax_range()
712 static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id) in devm_register_dax_mapping() argument
714 struct dax_region *dax_region = dev_dax->region; in devm_register_dax_mapping()
721 if (dev_WARN_ONCE(&dev_dax->dev, !dax_region->dev->driver, in devm_register_dax_mapping()
729 mapping->id = ida_alloc(&dev_dax->ida, GFP_KERNEL); in devm_register_dax_mapping()
734 dev_dax->ranges[range_id].mapping = mapping; in devm_register_dax_mapping()
737 dev->parent = &dev_dax->dev; in devm_register_dax_mapping()
753 static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, in alloc_dev_dax_range() argument
756 struct dax_region *dax_region = dev_dax->region; in alloc_dev_dax_range()
758 struct device *dev = &dev_dax->dev; in alloc_dev_dax_range()
768 if (dev_WARN_ONCE(dev, dev_dax->nr_range, in alloc_dev_dax_range()
775 ranges = krealloc(dev_dax->ranges, sizeof(*ranges) in alloc_dev_dax_range()
776 * (dev_dax->nr_range + 1), GFP_KERNEL); in alloc_dev_dax_range()
786 if (!dev_dax->nr_range) { in alloc_dev_dax_range()
790 dev_dax->ranges = ranges; in alloc_dev_dax_range()
794 for (i = 0; i < dev_dax->nr_range; i++) in alloc_dev_dax_range()
796 dev_dax->ranges = ranges; in alloc_dev_dax_range()
797 ranges[dev_dax->nr_range++] = (struct dev_dax_range) { in alloc_dev_dax_range()
805 dev_dbg(dev, "alloc range[%d]: %pa:%pa\n", dev_dax->nr_range - 1, in alloc_dev_dax_range()
812 if (!device_is_registered(&dev_dax->dev)) in alloc_dev_dax_range()
815 rc = devm_register_dax_mapping(dev_dax, dev_dax->nr_range - 1); in alloc_dev_dax_range()
817 trim_dev_dax_range(dev_dax); in alloc_dev_dax_range()
822 static int adjust_dev_dax_range(struct dev_dax *dev_dax, struct resource *res, resource_size_t size) in adjust_dev_dax_range() argument
824 int last_range = dev_dax->nr_range - 1; in adjust_dev_dax_range()
825 struct dev_dax_range *dax_range = &dev_dax->ranges[last_range]; in adjust_dev_dax_range()
826 struct dax_region *dax_region = dev_dax->region; in adjust_dev_dax_range()
829 struct device *dev = &dev_dax->dev; in adjust_dev_dax_range()
856 struct dev_dax *dev_dax = to_dev_dax(dev); in size_show() local
860 size = dev_dax_size(dev_dax); in size_show()
866 static bool alloc_is_aligned(struct dev_dax *dev_dax, resource_size_t size) in alloc_is_aligned() argument
872 return IS_ALIGNED(size, max_t(unsigned long, dev_dax->align, memremap_compat_align())); in alloc_is_aligned()
875 static int dev_dax_shrink(struct dev_dax *dev_dax, resource_size_t size) in dev_dax_shrink() argument
877 resource_size_t to_shrink = dev_dax_size(dev_dax) - size; in dev_dax_shrink()
878 struct dax_region *dax_region = dev_dax->region; in dev_dax_shrink()
879 struct device *dev = &dev_dax->dev; in dev_dax_shrink()
882 for (i = dev_dax->nr_range - 1; i >= 0; i--) { in dev_dax_shrink()
883 struct range *range = &dev_dax->ranges[i].range; in dev_dax_shrink()
884 struct dax_mapping *mapping = dev_dax->ranges[i].mapping; in dev_dax_shrink()
892 trim_dev_dax_range(dev_dax); in dev_dax_shrink()
906 if (dev_WARN_ONCE(dev, !adjust || i != dev_dax->nr_range - 1, in dev_dax_shrink()
909 return adjust_dev_dax_range(dev_dax, adjust, range_len(range) in dev_dax_shrink()
919 static bool adjust_ok(struct dev_dax *dev_dax, struct resource *res) in adjust_ok() argument
924 if (dev_dax->nr_range == 0) in adjust_ok()
926 if (strcmp(res->name, dev_name(&dev_dax->dev)) != 0) in adjust_ok()
928 last = &dev_dax->ranges[dev_dax->nr_range - 1]; in adjust_ok()
931 for (i = 0; i < dev_dax->nr_range - 1; i++) { in adjust_ok()
932 struct dev_dax_range *dax_range = &dev_dax->ranges[i]; in adjust_ok()
942 struct dev_dax *dev_dax, resource_size_t size) in dev_dax_resize() argument
945 resource_size_t dev_size = dev_dax_size(dev_dax); in dev_dax_resize()
947 struct device *dev = &dev_dax->dev; in dev_dax_resize()
959 return dev_dax_shrink(dev_dax, size); in dev_dax_resize()
962 if (dev_WARN_ONCE(dev, !alloc_is_aligned(dev_dax, to_alloc), in dev_dax_resize()
974 return alloc_dev_dax_range(dev_dax, dax_region->res.start, to_alloc); in dev_dax_resize()
983 rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, alloc); in dev_dax_resize()
999 if (adjust_ok(dev_dax, res)) { in dev_dax_resize()
1000 rc = adjust_dev_dax_range(dev_dax, res, resource_size(res) + alloc); in dev_dax_resize()
1003 rc = alloc_dev_dax_range(dev_dax, res->end + 1, alloc); in dev_dax_resize()
1019 struct dev_dax *dev_dax = to_dev_dax(dev); in size_store() local
1020 struct dax_region *dax_region = dev_dax->region; in size_store()
1026 if (!alloc_is_aligned(dev_dax, val)) { in size_store()
1037 rc = dev_dax_resize(dax_region, dev_dax, val); in size_store()
1078 struct dev_dax *dev_dax = to_dev_dax(dev); in mapping_store() local
1079 struct dax_region *dax_region = dev_dax->region; in mapping_store()
1097 if (alloc_is_aligned(dev_dax, to_alloc)) in mapping_store()
1098 rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc); in mapping_store()
1109 struct dev_dax *dev_dax = to_dev_dax(dev); in align_show() local
1111 return sprintf(buf, "%d\n", dev_dax->align); in align_show()
1114 static ssize_t dev_dax_validate_align(struct dev_dax *dev_dax) in dev_dax_validate_align() argument
1116 resource_size_t dev_size = dev_dax_size(dev_dax); in dev_dax_validate_align()
1117 struct device *dev = &dev_dax->dev; in dev_dax_validate_align()
1120 if (dev_size > 0 && !alloc_is_aligned(dev_dax, dev_size)) { in dev_dax_validate_align()
1122 __func__, dev_dax->align, &dev_size); in dev_dax_validate_align()
1126 for (i = 0; i < dev_dax->nr_range; i++) { in dev_dax_validate_align()
1127 size_t len = range_len(&dev_dax->ranges[i].range); in dev_dax_validate_align()
1129 if (!alloc_is_aligned(dev_dax, len)) { in dev_dax_validate_align()
1131 __func__, dev_dax->align, i); in dev_dax_validate_align()
1142 struct dev_dax *dev_dax = to_dev_dax(dev); in align_store() local
1143 struct dax_region *dax_region = dev_dax->region; in align_store()
1166 align_save = dev_dax->align; in align_store()
1167 dev_dax->align = val; in align_store()
1168 rc = dev_dax_validate_align(dev_dax); in align_store()
1170 dev_dax->align = align_save; in align_store()
1178 static int dev_dax_target_node(struct dev_dax *dev_dax) in dev_dax_target_node() argument
1180 struct dax_region *dax_region = dev_dax->region; in dev_dax_target_node()
1188 struct dev_dax *dev_dax = to_dev_dax(dev); in target_node_show() local
1190 return sprintf(buf, "%d\n", dev_dax_target_node(dev_dax)); in target_node_show()
1197 struct dev_dax *dev_dax = to_dev_dax(dev); in resource_show() local
1198 struct dax_region *dax_region = dev_dax->region; in resource_show()
1201 if (dev_dax->nr_range < 1) in resource_show()
1204 start = dev_dax->ranges[0].range.start; in resource_show()
1231 struct dev_dax *dev_dax = to_dev_dax(dev); in dev_dax_visible() local
1232 struct dax_region *dax_region = dev_dax->region; in dev_dax_visible()
1234 if (a == &dev_attr_target_node.attr && dev_dax_target_node(dev_dax) < 0) in dev_dax_visible()
1269 struct dev_dax *dev_dax = to_dev_dax(dev); in dev_dax_release() local
1270 struct dax_region *dax_region = dev_dax->region; in dev_dax_release()
1271 struct dax_device *dax_dev = dev_dax->dax_dev; in dev_dax_release()
1274 free_dev_dax_id(dev_dax); in dev_dax_release()
1276 kfree(dev_dax->pgmap); in dev_dax_release()
1277 kfree(dev_dax); in dev_dax_release()
1285 struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data) in devm_create_dev_dax()
1290 struct dev_dax *dev_dax; in devm_create_dev_dax() local
1295 dev_dax = kzalloc(sizeof(*dev_dax), GFP_KERNEL); in devm_create_dev_dax()
1296 if (!dev_dax) in devm_create_dev_dax()
1306 dev_dax->id = data->id; in devm_create_dev_dax()
1317 dev_dax->id = rc; in devm_create_dev_dax()
1320 dev_dax->region = dax_region; in devm_create_dev_dax()
1321 dev = &dev_dax->dev; in devm_create_dev_dax()
1323 dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id); in devm_create_dev_dax()
1325 rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, data->size); in devm_create_dev_dax()
1333 dev_dax->pgmap = kmemdup(data->pgmap, in devm_create_dev_dax()
1335 if (!dev_dax->pgmap) { in devm_create_dev_dax()
1345 dax_dev = alloc_dax(dev_dax, NULL, NULL, DAXDEV_F_SYNC); in devm_create_dev_dax()
1354 dev_dax->dax_dev = dax_dev; in devm_create_dev_dax()
1355 dev_dax->target_node = dax_region->target_node; in devm_create_dev_dax()
1356 dev_dax->align = dax_region->align; in devm_create_dev_dax()
1357 ida_init(&dev_dax->ida); in devm_create_dev_dax()
1371 kill_dev_dax(dev_dax); in devm_create_dev_dax()
1381 if (dev_dax->nr_range && range_len(&dev_dax->ranges[0].range)) { in devm_create_dev_dax()
1382 rc = devm_register_dax_mapping(dev_dax, 0); in devm_create_dev_dax()
1387 return dev_dax; in devm_create_dev_dax()
1390 kfree(dev_dax->pgmap); in devm_create_dev_dax()
1392 free_dev_dax_ranges(dev_dax); in devm_create_dev_dax()
1394 free_dev_dax_id(dev_dax); in devm_create_dev_dax()
1396 kfree(dev_dax); in devm_create_dev_dax()