Lines Matching refs:nd_region

63 static int nd_region_invalidate_memregion(struct nd_region *nd_region)  in nd_region_invalidate_memregion()  argument
67 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_invalidate_memregion()
68 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_invalidate_memregion()
83 &nd_region->dev, in nd_region_invalidate_memregion()
87 dev_err(&nd_region->dev, in nd_region_invalidate_memregion()
95 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_invalidate_memregion()
96 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_invalidate_memregion()
105 int nd_region_activate(struct nd_region *nd_region) in nd_region_activate() argument
109 struct device *dev = &nd_region->dev; in nd_region_activate()
112 nvdimm_bus_lock(&nd_region->dev); in nd_region_activate()
113 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_activate()
114 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_activate()
118 nvdimm_bus_unlock(&nd_region->dev); in nd_region_activate()
129 nvdimm_bus_unlock(&nd_region->dev); in nd_region_activate()
131 rc = nd_region_invalidate_memregion(nd_region); in nd_region_activate()
144 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_activate()
145 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_activate()
147 int rc = nvdimm_map_flush(&nd_region->dev, nvdimm, i, ndrd); in nd_region_activate()
157 for (i = 0; i < nd_region->ndr_mappings - 1; i++) { in nd_region_activate()
162 for (j = i + 1; j < nd_region->ndr_mappings; j++) in nd_region_activate()
173 struct nd_region *nd_region = to_nd_region(dev); in nd_region_release() local
176 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_release()
177 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_release()
182 free_percpu(nd_region->lane); in nd_region_release()
183 if (!test_bit(ND_REGION_CXL, &nd_region->flags)) in nd_region_release()
184 memregion_free(nd_region->id); in nd_region_release()
185 kfree(nd_region); in nd_region_release()
188 struct nd_region *to_nd_region(struct device *dev) in to_nd_region()
190 struct nd_region *nd_region = container_of(dev, struct nd_region, dev); in to_nd_region() local
193 return nd_region; in to_nd_region()
197 struct device *nd_region_dev(struct nd_region *nd_region) in nd_region_dev() argument
199 if (!nd_region) in nd_region_dev()
201 return &nd_region->dev; in nd_region_dev()
205 void *nd_region_provider_data(struct nd_region *nd_region) in nd_region_provider_data() argument
207 return nd_region->provider_data; in nd_region_provider_data()
219 int nd_region_to_nstype(struct nd_region *nd_region) in nd_region_to_nstype() argument
221 if (is_memory(&nd_region->dev)) { in nd_region_to_nstype()
224 for (i = 0, label = 0; i < nd_region->ndr_mappings; i++) { in nd_region_to_nstype()
225 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_to_nstype()
241 static unsigned long long region_size(struct nd_region *nd_region) in region_size() argument
243 if (is_memory(&nd_region->dev)) { in region_size()
244 return nd_region->ndr_size; in region_size()
245 } else if (nd_region->ndr_mappings == 1) { in region_size()
246 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in region_size()
257 struct nd_region *nd_region = to_nd_region(dev); in size_show() local
259 return sprintf(buf, "%llu\n", region_size(nd_region)); in size_show()
266 struct nd_region *nd_region = to_nd_region(dev); in deep_flush_show() local
272 return sprintf(buf, "%d\n", nvdimm_has_flush(nd_region)); in deep_flush_show()
280 struct nd_region *nd_region = to_nd_region(dev); in deep_flush_store() local
286 rc = nvdimm_flush(nd_region, NULL); in deep_flush_store()
297 struct nd_region *nd_region = to_nd_region(dev); in mappings_show() local
299 return sprintf(buf, "%d\n", nd_region->ndr_mappings); in mappings_show()
306 struct nd_region *nd_region = to_nd_region(dev); in nstype_show() local
308 return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region)); in nstype_show()
315 struct nd_region *nd_region = to_nd_region(dev); in set_cookie_show() local
316 struct nd_interleave_set *nd_set = nd_region->nd_set; in set_cookie_show()
333 if (nd_region->ndr_mappings) { in set_cookie_show()
334 struct nd_mapping *nd_mapping = &nd_region->mapping[0]; in set_cookie_show()
342 nd_region_interleave_set_cookie(nd_region, in set_cookie_show()
355 resource_size_t nd_region_available_dpa(struct nd_region *nd_region) in nd_region_available_dpa() argument
360 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_available_dpa()
363 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_available_dpa()
364 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_available_dpa()
371 available += nd_pmem_available_dpa(nd_region, nd_mapping); in nd_region_available_dpa()
377 resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region) in nd_region_allocatable_dpa() argument
382 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev)); in nd_region_allocatable_dpa()
383 for (i = 0; i < nd_region->ndr_mappings; i++) { in nd_region_allocatable_dpa()
384 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nd_region_allocatable_dpa()
387 nd_region, nd_mapping)); in nd_region_allocatable_dpa()
389 return avail * nd_region->ndr_mappings; in nd_region_allocatable_dpa()
395 struct nd_region *nd_region = to_nd_region(dev); in available_size_show() local
407 available = nd_region_available_dpa(nd_region); in available_size_show()
418 struct nd_region *nd_region = to_nd_region(dev); in max_available_extent_show() local
424 available = nd_region_allocatable_dpa(nd_region); in max_available_extent_show()
452 struct nd_region *nd_region = to_nd_region(dev); in namespace_seed_show() local
456 if (nd_region->ns_seed) in namespace_seed_show()
457 rc = sprintf(buf, "%s\n", dev_name(nd_region->ns_seed)); in namespace_seed_show()
468 struct nd_region *nd_region = to_nd_region(dev); in btt_seed_show() local
472 if (nd_region->btt_seed) in btt_seed_show()
473 rc = sprintf(buf, "%s\n", dev_name(nd_region->btt_seed)); in btt_seed_show()
485 struct nd_region *nd_region = to_nd_region(dev); in pfn_seed_show() local
489 if (nd_region->pfn_seed) in pfn_seed_show()
490 rc = sprintf(buf, "%s\n", dev_name(nd_region->pfn_seed)); in pfn_seed_show()
502 struct nd_region *nd_region = to_nd_region(dev); in dax_seed_show() local
506 if (nd_region->dax_seed) in dax_seed_show()
507 rc = sprintf(buf, "%s\n", dev_name(nd_region->dax_seed)); in dax_seed_show()
519 struct nd_region *nd_region = to_nd_region(dev); in read_only_show() local
521 return sprintf(buf, "%d\n", nd_region->ro); in read_only_show()
535 struct nd_region *nd_region = to_nd_region(dev); in read_only_store() local
540 nd_region->ro = ro; in read_only_store()
549 struct nd_region *nd_region = to_nd_region(dev); in align_show() local
551 return sprintf(buf, "%#lx\n", nd_region->align); in align_show()
557 struct nd_region *nd_region = to_nd_region(dev); in align_store() local
573 mappings = max_t(u32, 1, nd_region->ndr_mappings); in align_store()
576 || val > region_size(nd_region) || remainder) in align_store()
585 nd_region->align = val; in align_store()
595 struct nd_region *nd_region = to_nd_region(dev); in region_badblocks_show() local
600 rc = badblocks_show(&nd_region->bb, buf, 0); in region_badblocks_show()
612 struct nd_region *nd_region = to_nd_region(dev); in resource_show() local
614 return sprintf(buf, "%#llx\n", nd_region->ndr_start); in resource_show()
621 struct nd_region *nd_region = to_nd_region(dev); in persistence_domain_show() local
623 if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags)) in persistence_domain_show()
625 else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags)) in persistence_domain_show()
656 struct nd_region *nd_region = to_nd_region(dev); in region_visible() local
657 struct nd_interleave_set *nd_set = nd_region->nd_set; in region_visible()
658 int type = nd_region_to_nstype(nd_region); in region_visible()
673 int has_flush = nvdimm_has_flush(nd_region); in region_visible()
684 if ((nd_region->flags & (BIT(ND_REGION_PERSIST_CACHE) in region_visible()
708 struct nd_region *nd_region = to_nd_region(dev); in mappingN() local
712 if (n >= nd_region->ndr_mappings) in mappingN()
714 nd_mapping = &nd_region->mapping[n]; in mappingN()
770 struct nd_region *nd_region = to_nd_region(dev); in mapping_visible() local
772 if (n < nd_region->ndr_mappings) in mapping_visible()
853 u64 nd_region_interleave_set_cookie(struct nd_region *nd_region, in nd_region_interleave_set_cookie() argument
856 struct nd_interleave_set *nd_set = nd_region->nd_set; in nd_region_interleave_set_cookie()
867 u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region) in nd_region_interleave_set_altcookie() argument
869 struct nd_interleave_set *nd_set = nd_region->nd_set; in nd_region_interleave_set_altcookie()
891 void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev) in nd_region_advance_seeds() argument
894 if (nd_region->ns_seed == dev) { in nd_region_advance_seeds()
895 nd_region_create_ns_seed(nd_region); in nd_region_advance_seeds()
899 if (nd_region->btt_seed == dev) in nd_region_advance_seeds()
900 nd_region_create_btt_seed(nd_region); in nd_region_advance_seeds()
901 if (nd_region->ns_seed == &nd_btt->ndns->dev) in nd_region_advance_seeds()
902 nd_region_create_ns_seed(nd_region); in nd_region_advance_seeds()
906 if (nd_region->pfn_seed == dev) in nd_region_advance_seeds()
907 nd_region_create_pfn_seed(nd_region); in nd_region_advance_seeds()
908 if (nd_region->ns_seed == &nd_pfn->ndns->dev) in nd_region_advance_seeds()
909 nd_region_create_ns_seed(nd_region); in nd_region_advance_seeds()
913 if (nd_region->dax_seed == dev) in nd_region_advance_seeds()
914 nd_region_create_dax_seed(nd_region); in nd_region_advance_seeds()
915 if (nd_region->ns_seed == &nd_dax->nd_pfn.ndns->dev) in nd_region_advance_seeds()
916 nd_region_create_ns_seed(nd_region); in nd_region_advance_seeds()
938 unsigned int nd_region_acquire_lane(struct nd_region *nd_region) in nd_region_acquire_lane() argument
944 if (nd_region->num_lanes < nr_cpu_ids) { in nd_region_acquire_lane()
947 lane = cpu % nd_region->num_lanes; in nd_region_acquire_lane()
948 ndl_count = per_cpu_ptr(nd_region->lane, cpu); in nd_region_acquire_lane()
949 ndl_lock = per_cpu_ptr(nd_region->lane, lane); in nd_region_acquire_lane()
959 void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane) in nd_region_release_lane() argument
961 if (nd_region->num_lanes < nr_cpu_ids) { in nd_region_release_lane()
965 ndl_count = per_cpu_ptr(nd_region->lane, cpu); in nd_region_release_lane()
966 ndl_lock = per_cpu_ptr(nd_region->lane, lane); in nd_region_release_lane()
980 static unsigned long default_align(struct nd_region *nd_region) in default_align() argument
987 if (nd_region->ndr_size < MEMREMAP_COMPAT_ALIGN_MAX) in default_align()
990 mappings = max_t(u16, 1, nd_region->ndr_mappings); in default_align()
1000 static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus, in nd_region_create()
1004 struct nd_region *nd_region; in nd_region_create() local
1025 nd_region = in nd_region_create()
1026 kzalloc(struct_size(nd_region, mapping, ndr_desc->num_mappings), in nd_region_create()
1029 if (!nd_region) in nd_region_create()
1033 nd_region->id = ndr_desc->memregion; in nd_region_create()
1035 nd_region->id = memregion_alloc(GFP_KERNEL); in nd_region_create()
1036 if (nd_region->id < 0) in nd_region_create()
1040 nd_region->lane = alloc_percpu(struct nd_percpu_lane); in nd_region_create()
1041 if (!nd_region->lane) in nd_region_create()
1047 ndl = per_cpu_ptr(nd_region->lane, i); in nd_region_create()
1056 nd_region->mapping[i].nvdimm = nvdimm; in nd_region_create()
1057 nd_region->mapping[i].start = mapping->start; in nd_region_create()
1058 nd_region->mapping[i].size = mapping->size; in nd_region_create()
1059 nd_region->mapping[i].position = mapping->position; in nd_region_create()
1060 INIT_LIST_HEAD(&nd_region->mapping[i].labels); in nd_region_create()
1061 mutex_init(&nd_region->mapping[i].lock); in nd_region_create()
1065 nd_region->ndr_mappings = ndr_desc->num_mappings; in nd_region_create()
1066 nd_region->provider_data = ndr_desc->provider_data; in nd_region_create()
1067 nd_region->nd_set = ndr_desc->nd_set; in nd_region_create()
1068 nd_region->num_lanes = ndr_desc->num_lanes; in nd_region_create()
1069 nd_region->flags = ndr_desc->flags; in nd_region_create()
1070 nd_region->ro = ro; in nd_region_create()
1071 nd_region->numa_node = ndr_desc->numa_node; in nd_region_create()
1072 nd_region->target_node = ndr_desc->target_node; in nd_region_create()
1073 ida_init(&nd_region->ns_ida); in nd_region_create()
1074 ida_init(&nd_region->btt_ida); in nd_region_create()
1075 ida_init(&nd_region->pfn_ida); in nd_region_create()
1076 ida_init(&nd_region->dax_ida); in nd_region_create()
1077 dev = &nd_region->dev; in nd_region_create()
1078 dev_set_name(dev, "region%d", nd_region->id); in nd_region_create()
1083 nd_region->ndr_size = resource_size(ndr_desc->res); in nd_region_create()
1084 nd_region->ndr_start = ndr_desc->res->start; in nd_region_create()
1085 nd_region->align = default_align(nd_region); in nd_region_create()
1087 nd_region->flush = ndr_desc->flush; in nd_region_create()
1089 nd_region->flush = NULL; in nd_region_create()
1095 return nd_region; in nd_region_create()
1099 memregion_free(nd_region->id); in nd_region_create()
1101 kfree(nd_region); in nd_region_create()
1105 struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus, in nvdimm_pmem_region_create()
1114 struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus, in nvdimm_volatile_region_create()
1123 void nvdimm_region_delete(struct nd_region *nd_region) in nvdimm_region_delete() argument
1125 if (nd_region) in nvdimm_region_delete()
1126 nd_device_unregister(&nd_region->dev, ND_SYNC); in nvdimm_region_delete()
1130 int nvdimm_flush(struct nd_region *nd_region, struct bio *bio) in nvdimm_flush() argument
1134 if (!nd_region->flush) in nvdimm_flush()
1135 rc = generic_nvdimm_flush(nd_region); in nvdimm_flush()
1137 if (nd_region->flush(nd_region, bio)) in nvdimm_flush()
1147 int generic_nvdimm_flush(struct nd_region *nd_region) in generic_nvdimm_flush() argument
1149 struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev); in generic_nvdimm_flush()
1167 for (i = 0; i < nd_region->ndr_mappings; i++) in generic_nvdimm_flush()
1184 int nvdimm_has_flush(struct nd_region *nd_region) in nvdimm_has_flush() argument
1189 if (nd_region->ndr_mappings == 0 in nvdimm_has_flush()
1194 if (test_bit(ND_REGION_ASYNC, &nd_region->flags) && nd_region->flush) in nvdimm_has_flush()
1198 for (i = 0; i < nd_region->ndr_mappings; i++) { in nvdimm_has_flush()
1199 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; in nvdimm_has_flush()
1215 int nvdimm_has_cache(struct nd_region *nd_region) in nvdimm_has_cache() argument
1217 return is_nd_pmem(&nd_region->dev) && in nvdimm_has_cache()
1218 !test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags); in nvdimm_has_cache()
1222 bool is_nvdimm_sync(struct nd_region *nd_region) in is_nvdimm_sync() argument
1224 if (is_nd_volatile(&nd_region->dev)) in is_nvdimm_sync()
1227 return is_nd_pmem(&nd_region->dev) && in is_nvdimm_sync()
1228 !test_bit(ND_REGION_ASYNC, &nd_region->flags); in is_nvdimm_sync()
1233 struct nd_region *nd_region; member
1239 struct nd_region *nd_region; in region_conflict() local
1246 nd_region = to_nd_region(dev); in region_conflict()
1247 if (nd_region == ctx->nd_region) in region_conflict()
1251 region_start = nd_region->ndr_start; in region_conflict()
1252 region_end = region_start + nd_region->ndr_size; in region_conflict()
1260 int nd_region_conflict(struct nd_region *nd_region, resource_size_t start, in nd_region_conflict() argument
1263 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev); in nd_region_conflict()
1265 .nd_region = nd_region, in nd_region_conflict()