Lines Matching refs:dev_dax
153 bool static_dev_dax(struct dev_dax *dev_dax) in static_dev_dax() argument
155 return is_static(dev_dax->region); in static_dev_dax()
159 static u64 dev_dax_size(struct dev_dax *dev_dax) in dev_dax_size() argument
164 device_lock_assert(&dev_dax->dev); in dev_dax_size()
166 for (i = 0; i < dev_dax->nr_range; i++) in dev_dax_size()
167 size += range_len(&dev_dax->ranges[i].range); in dev_dax_size()
175 struct dev_dax *dev_dax = to_dev_dax(dev); in dax_bus_probe() local
176 struct dax_region *dax_region = dev_dax->region; in dax_bus_probe()
179 if (dev_dax_size(dev_dax) == 0 || dev_dax->id < 0) in dax_bus_probe()
182 rc = dax_drv->probe(dev_dax); in dax_bus_probe()
200 struct dev_dax *dev_dax = to_dev_dax(dev); in dax_bus_remove() local
203 dax_drv->remove(dev_dax); in dax_bus_remove()
357 struct dev_dax *dev_dax = devm_create_dev_dax(&data); in create_store() local
359 if (IS_ERR(dev_dax)) in create_store()
360 rc = PTR_ERR(dev_dax); in create_store()
370 dax_region->seed = &dev_dax->dev; in create_store()
371 dax_region->youngest = &dev_dax->dev; in create_store()
381 void kill_dev_dax(struct dev_dax *dev_dax) in kill_dev_dax() argument
383 struct dax_device *dax_dev = dev_dax->dax_dev; in kill_dev_dax()
394 if (!static_dev_dax(dev_dax)) in kill_dev_dax()
395 dev_dax->pgmap = NULL; in kill_dev_dax()
399 static void trim_dev_dax_range(struct dev_dax *dev_dax) in trim_dev_dax_range() argument
401 int i = dev_dax->nr_range - 1; in trim_dev_dax_range()
402 struct range *range = &dev_dax->ranges[i].range; in trim_dev_dax_range()
403 struct dax_region *dax_region = dev_dax->region; in trim_dev_dax_range()
406 dev_dbg(&dev_dax->dev, "delete range[%d]: %#llx:%#llx\n", i, in trim_dev_dax_range()
411 if (--dev_dax->nr_range == 0) { in trim_dev_dax_range()
412 kfree(dev_dax->ranges); in trim_dev_dax_range()
413 dev_dax->ranges = NULL; in trim_dev_dax_range()
417 static void free_dev_dax_ranges(struct dev_dax *dev_dax) in free_dev_dax_ranges() argument
419 while (dev_dax->nr_range) in free_dev_dax_ranges()
420 trim_dev_dax_range(dev_dax); in free_dev_dax_ranges()
425 struct dev_dax *dev_dax = to_dev_dax(dev); in unregister_dev_dax() local
429 kill_dev_dax(dev_dax); in unregister_dev_dax()
430 free_dev_dax_ranges(dev_dax); in unregister_dev_dax()
436 static int __free_dev_dax_id(struct dev_dax *dev_dax) in __free_dev_dax_id() argument
438 struct dax_region *dax_region = dev_dax->region; in __free_dev_dax_id()
439 struct device *dev = &dev_dax->dev; in __free_dev_dax_id()
440 int rc = dev_dax->id; in __free_dev_dax_id()
444 if (is_static(dax_region) || dev_dax->id < 0) in __free_dev_dax_id()
446 ida_free(&dax_region->ida, dev_dax->id); in __free_dev_dax_id()
447 dev_dax->id = -1; in __free_dev_dax_id()
451 static int free_dev_dax_id(struct dev_dax *dev_dax) in free_dev_dax_id() argument
453 struct device *dev = &dev_dax->dev; in free_dev_dax_id()
457 rc = __free_dev_dax_id(dev_dax); in free_dev_dax_id()
466 struct dev_dax *dev_dax; in delete_store() local
480 dev_dax = to_dev_dax(victim); in delete_store()
481 if (victim->driver || dev_dax_size(dev_dax)) in delete_store()
490 if (dev_dax->id > 0) { in delete_store()
491 do_del = __free_dev_dax_id(dev_dax) >= 0; in delete_store()
624 struct dev_dax *dev_dax = to_dev_dax(dev->parent); in dax_mapping_release() local
626 ida_free(&dev_dax->ida, mapping->id); in dax_mapping_release()
634 struct dev_dax *dev_dax = to_dev_dax(dev->parent); in unregister_dax_mapping() local
635 struct dax_region *dax_region = dev_dax->region; in unregister_dax_mapping()
641 dev_dax->ranges[mapping->range_id].mapping = NULL; in unregister_dax_mapping()
651 struct dev_dax *dev_dax = to_dev_dax(dev->parent); in get_dax_range() local
652 struct dax_region *dax_region = dev_dax->region; in get_dax_range()
660 return &dev_dax->ranges[mapping->range_id]; in get_dax_range()
666 struct dev_dax *dev_dax = to_dev_dax(mapping->dev.parent); in put_dax_range() local
667 struct dax_region *dax_region = dev_dax->region; in put_dax_range()
741 static int devm_register_dax_mapping(struct dev_dax *dev_dax, int range_id) in devm_register_dax_mapping() argument
743 struct dax_region *dax_region = dev_dax->region; in devm_register_dax_mapping()
750 if (dev_WARN_ONCE(&dev_dax->dev, !dax_region->dev->driver, in devm_register_dax_mapping()
758 mapping->id = ida_alloc(&dev_dax->ida, GFP_KERNEL); in devm_register_dax_mapping()
763 dev_dax->ranges[range_id].mapping = mapping; in devm_register_dax_mapping()
766 dev->parent = &dev_dax->dev; in devm_register_dax_mapping()
782 static int alloc_dev_dax_range(struct dev_dax *dev_dax, u64 start, in alloc_dev_dax_range() argument
785 struct dax_region *dax_region = dev_dax->region; in alloc_dev_dax_range()
787 struct device *dev = &dev_dax->dev; in alloc_dev_dax_range()
797 if (dev_WARN_ONCE(dev, dev_dax->nr_range, in alloc_dev_dax_range()
808 ranges = krealloc(dev_dax->ranges, sizeof(*ranges) in alloc_dev_dax_range()
809 * (dev_dax->nr_range + 1), GFP_KERNEL); in alloc_dev_dax_range()
815 for (i = 0; i < dev_dax->nr_range; i++) in alloc_dev_dax_range()
817 dev_dax->ranges = ranges; in alloc_dev_dax_range()
818 ranges[dev_dax->nr_range++] = (struct dev_dax_range) { in alloc_dev_dax_range()
826 dev_dbg(dev, "alloc range[%d]: %pa:%pa\n", dev_dax->nr_range - 1, in alloc_dev_dax_range()
833 if (!device_is_registered(&dev_dax->dev)) in alloc_dev_dax_range()
836 rc = devm_register_dax_mapping(dev_dax, dev_dax->nr_range - 1); in alloc_dev_dax_range()
838 trim_dev_dax_range(dev_dax); in alloc_dev_dax_range()
843 static int adjust_dev_dax_range(struct dev_dax *dev_dax, struct resource *res, resource_size_t size) in adjust_dev_dax_range() argument
845 int last_range = dev_dax->nr_range - 1; in adjust_dev_dax_range()
846 struct dev_dax_range *dax_range = &dev_dax->ranges[last_range]; in adjust_dev_dax_range()
847 struct dax_region *dax_region = dev_dax->region; in adjust_dev_dax_range()
850 struct device *dev = &dev_dax->dev; in adjust_dev_dax_range()
877 struct dev_dax *dev_dax = to_dev_dax(dev); in size_show() local
881 size = dev_dax_size(dev_dax); in size_show()
887 static bool alloc_is_aligned(struct dev_dax *dev_dax, resource_size_t size) in alloc_is_aligned() argument
893 return IS_ALIGNED(size, max_t(unsigned long, dev_dax->align, memremap_compat_align())); in alloc_is_aligned()
896 static int dev_dax_shrink(struct dev_dax *dev_dax, resource_size_t size) in dev_dax_shrink() argument
898 resource_size_t to_shrink = dev_dax_size(dev_dax) - size; in dev_dax_shrink()
899 struct dax_region *dax_region = dev_dax->region; in dev_dax_shrink()
900 struct device *dev = &dev_dax->dev; in dev_dax_shrink()
903 for (i = dev_dax->nr_range - 1; i >= 0; i--) { in dev_dax_shrink()
904 struct range *range = &dev_dax->ranges[i].range; in dev_dax_shrink()
905 struct dax_mapping *mapping = dev_dax->ranges[i].mapping; in dev_dax_shrink()
913 trim_dev_dax_range(dev_dax); in dev_dax_shrink()
927 if (dev_WARN_ONCE(dev, !adjust || i != dev_dax->nr_range - 1, in dev_dax_shrink()
930 return adjust_dev_dax_range(dev_dax, adjust, range_len(range) in dev_dax_shrink()
940 static bool adjust_ok(struct dev_dax *dev_dax, struct resource *res) in adjust_ok() argument
945 if (dev_dax->nr_range == 0) in adjust_ok()
947 if (strcmp(res->name, dev_name(&dev_dax->dev)) != 0) in adjust_ok()
949 last = &dev_dax->ranges[dev_dax->nr_range - 1]; in adjust_ok()
952 for (i = 0; i < dev_dax->nr_range - 1; i++) { in adjust_ok()
953 struct dev_dax_range *dax_range = &dev_dax->ranges[i]; in adjust_ok()
963 struct dev_dax *dev_dax, resource_size_t size) in dev_dax_resize() argument
966 resource_size_t dev_size = dev_dax_size(dev_dax); in dev_dax_resize()
968 struct device *dev = &dev_dax->dev; in dev_dax_resize()
980 return dev_dax_shrink(dev_dax, size); in dev_dax_resize()
983 if (dev_WARN_ONCE(dev, !alloc_is_aligned(dev_dax, to_alloc), in dev_dax_resize()
995 return alloc_dev_dax_range(dev_dax, dax_region->res.start, to_alloc); in dev_dax_resize()
1004 rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, alloc); in dev_dax_resize()
1020 if (adjust_ok(dev_dax, res)) { in dev_dax_resize()
1021 rc = adjust_dev_dax_range(dev_dax, res, resource_size(res) + alloc); in dev_dax_resize()
1024 rc = alloc_dev_dax_range(dev_dax, res->end + 1, alloc); in dev_dax_resize()
1040 struct dev_dax *dev_dax = to_dev_dax(dev); in size_store() local
1041 struct dax_region *dax_region = dev_dax->region; in size_store()
1047 if (!alloc_is_aligned(dev_dax, val)) { in size_store()
1058 rc = dev_dax_resize(dax_region, dev_dax, val); in size_store()
1099 struct dev_dax *dev_dax = to_dev_dax(dev); in mapping_store() local
1100 struct dax_region *dax_region = dev_dax->region; in mapping_store()
1118 if (alloc_is_aligned(dev_dax, to_alloc)) in mapping_store()
1119 rc = alloc_dev_dax_range(dev_dax, r.start, to_alloc); in mapping_store()
1130 struct dev_dax *dev_dax = to_dev_dax(dev); in align_show() local
1132 return sprintf(buf, "%d\n", dev_dax->align); in align_show()
1135 static ssize_t dev_dax_validate_align(struct dev_dax *dev_dax) in dev_dax_validate_align() argument
1137 struct device *dev = &dev_dax->dev; in dev_dax_validate_align()
1140 for (i = 0; i < dev_dax->nr_range; i++) { in dev_dax_validate_align()
1141 size_t len = range_len(&dev_dax->ranges[i].range); in dev_dax_validate_align()
1143 if (!alloc_is_aligned(dev_dax, len)) { in dev_dax_validate_align()
1145 __func__, dev_dax->align, i); in dev_dax_validate_align()
1156 struct dev_dax *dev_dax = to_dev_dax(dev); in align_store() local
1157 struct dax_region *dax_region = dev_dax->region; in align_store()
1180 align_save = dev_dax->align; in align_store()
1181 dev_dax->align = val; in align_store()
1182 rc = dev_dax_validate_align(dev_dax); in align_store()
1184 dev_dax->align = align_save; in align_store()
1192 static int dev_dax_target_node(struct dev_dax *dev_dax) in dev_dax_target_node() argument
1194 struct dax_region *dax_region = dev_dax->region; in dev_dax_target_node()
1202 struct dev_dax *dev_dax = to_dev_dax(dev); in target_node_show() local
1204 return sprintf(buf, "%d\n", dev_dax_target_node(dev_dax)); in target_node_show()
1211 struct dev_dax *dev_dax = to_dev_dax(dev); in resource_show() local
1212 struct dax_region *dax_region = dev_dax->region; in resource_show()
1215 if (dev_dax->nr_range < 1) in resource_show()
1218 start = dev_dax->ranges[0].range.start; in resource_show()
1245 struct dev_dax *dev_dax = to_dev_dax(dev); in dev_dax_visible() local
1246 struct dax_region *dax_region = dev_dax->region; in dev_dax_visible()
1248 if (a == &dev_attr_target_node.attr && dev_dax_target_node(dev_dax) < 0) in dev_dax_visible()
1283 struct dev_dax *dev_dax = to_dev_dax(dev); in dev_dax_release() local
1284 struct dax_region *dax_region = dev_dax->region; in dev_dax_release()
1285 struct dax_device *dax_dev = dev_dax->dax_dev; in dev_dax_release()
1288 free_dev_dax_id(dev_dax); in dev_dax_release()
1290 kfree(dev_dax->pgmap); in dev_dax_release()
1291 kfree(dev_dax); in dev_dax_release()
1299 struct dev_dax *devm_create_dev_dax(struct dev_dax_data *data) in devm_create_dev_dax()
1304 struct dev_dax *dev_dax; in devm_create_dev_dax() local
1309 dev_dax = kzalloc(sizeof(*dev_dax), GFP_KERNEL); in devm_create_dev_dax()
1310 if (!dev_dax) in devm_create_dev_dax()
1320 dev_dax->id = data->id; in devm_create_dev_dax()
1331 dev_dax->id = rc; in devm_create_dev_dax()
1334 dev_dax->region = dax_region; in devm_create_dev_dax()
1335 dev = &dev_dax->dev; in devm_create_dev_dax()
1337 dev_set_name(dev, "dax%d.%d", dax_region->id, dev_dax->id); in devm_create_dev_dax()
1339 rc = alloc_dev_dax_range(dev_dax, dax_region->res.start, data->size); in devm_create_dev_dax()
1347 dev_dax->pgmap = kmemdup(data->pgmap, in devm_create_dev_dax()
1349 if (!dev_dax->pgmap) { in devm_create_dev_dax()
1359 dax_dev = alloc_dax(dev_dax, NULL); in devm_create_dev_dax()
1371 dev_dax->dax_dev = dax_dev; in devm_create_dev_dax()
1372 dev_dax->target_node = dax_region->target_node; in devm_create_dev_dax()
1373 dev_dax->align = dax_region->align; in devm_create_dev_dax()
1374 ida_init(&dev_dax->ida); in devm_create_dev_dax()
1385 kill_dev_dax(dev_dax); in devm_create_dev_dax()
1395 if (dev_dax->nr_range && range_len(&dev_dax->ranges[0].range)) { in devm_create_dev_dax()
1396 rc = devm_register_dax_mapping(dev_dax, 0); in devm_create_dev_dax()
1401 return dev_dax; in devm_create_dev_dax()
1404 kfree(dev_dax->pgmap); in devm_create_dev_dax()
1406 free_dev_dax_ranges(dev_dax); in devm_create_dev_dax()
1408 free_dev_dax_id(dev_dax); in devm_create_dev_dax()
1410 kfree(dev_dax); in devm_create_dev_dax()