Lines Matching refs:nd_region
62 int nd_region_activate(struct nd_region *nd_region)
66 struct device *dev = &nd_region->dev;
69 nvdimm_bus_lock(&nd_region->dev);
70 for (i = 0; i < nd_region->ndr_mappings; i++) {
71 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
75 nvdimm_bus_unlock(&nd_region->dev);
86 nvdimm_bus_unlock(&nd_region->dev);
97 for (i = 0; i < nd_region->ndr_mappings; i++) {
98 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
100 int rc = nvdimm_map_flush(&nd_region->dev, nvdimm, i, ndrd);
110 for (i = 0; i < nd_region->ndr_mappings - 1; i++) {
115 for (j = i + 1; j < nd_region->ndr_mappings; j++)
126 struct nd_region *nd_region = to_nd_region(dev);
129 for (i = 0; i < nd_region->ndr_mappings; i++) {
130 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
135 free_percpu(nd_region->lane);
136 memregion_free(nd_region->id);
140 kfree(nd_region);
143 struct nd_region *to_nd_region(struct device *dev)
145 struct nd_region *nd_region = container_of(dev, struct nd_region, dev);
148 return nd_region;
152 struct device *nd_region_dev(struct nd_region *nd_region)
154 if (!nd_region)
156 return &nd_region->dev;
162 struct nd_region *nd_region = to_nd_region(dev);
165 return container_of(nd_region, struct nd_blk_region, nd_region);
169 void *nd_region_provider_data(struct nd_region *nd_region)
171 return nd_region->provider_data;
189 * @nd_region: region-device to interrogate
195 int nd_region_to_nstype(struct nd_region *nd_region)
197 if (is_memory(&nd_region->dev)) {
200 for (i = 0, label = 0; i < nd_region->ndr_mappings; i++) {
201 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
211 } else if (is_nd_blk(&nd_region->dev)) {
219 static unsigned long long region_size(struct nd_region *nd_region)
221 if (is_memory(&nd_region->dev)) {
222 return nd_region->ndr_size;
223 } else if (nd_region->ndr_mappings == 1) {
224 struct nd_mapping *nd_mapping = &nd_region->mapping[0];
235 struct nd_region *nd_region = to_nd_region(dev);
237 return sprintf(buf, "%llu\n", region_size(nd_region));
244 struct nd_region *nd_region = to_nd_region(dev);
250 return sprintf(buf, "%d\n", nvdimm_has_flush(nd_region));
258 struct nd_region *nd_region = to_nd_region(dev);
264 rc = nvdimm_flush(nd_region, NULL);
275 struct nd_region *nd_region = to_nd_region(dev);
277 return sprintf(buf, "%d\n", nd_region->ndr_mappings);
284 struct nd_region *nd_region = to_nd_region(dev);
286 return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region));
293 struct nd_region *nd_region = to_nd_region(dev);
294 struct nd_interleave_set *nd_set = nd_region->nd_set;
311 if (nd_region->ndr_mappings) {
312 struct nd_mapping *nd_mapping = &nd_region->mapping[0];
320 nd_region_interleave_set_cookie(nd_region,
333 resource_size_t nd_region_available_dpa(struct nd_region *nd_region)
338 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
343 for (i = 0; i < nd_region->ndr_mappings; i++) {
344 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
351 if (is_memory(&nd_region->dev)) {
352 available += nd_pmem_available_dpa(nd_region,
358 } else if (is_nd_blk(&nd_region->dev))
359 available += nd_blk_available_dpa(nd_region);
365 resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region)
370 if (is_memory(&nd_region->dev))
373 WARN_ON(!is_nvdimm_bus_locked(&nd_region->dev));
374 for (i = 0; i < nd_region->ndr_mappings; i++) {
375 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
377 if (is_memory(&nd_region->dev))
379 nd_pmem_max_contiguous_dpa(nd_region,
381 else if (is_nd_blk(&nd_region->dev))
382 available += nd_blk_available_dpa(nd_region);
384 if (is_memory(&nd_region->dev))
385 return available * nd_region->ndr_mappings;
392 struct nd_region *nd_region = to_nd_region(dev);
404 available = nd_region_available_dpa(nd_region);
415 struct nd_region *nd_region = to_nd_region(dev);
421 available = nd_region_allocatable_dpa(nd_region);
449 struct nd_region *nd_region = to_nd_region(dev);
453 if (nd_region->ns_seed)
454 rc = sprintf(buf, "%s\n", dev_name(nd_region->ns_seed));
465 struct nd_region *nd_region = to_nd_region(dev);
469 if (nd_region->btt_seed)
470 rc = sprintf(buf, "%s\n", dev_name(nd_region->btt_seed));
482 struct nd_region *nd_region = to_nd_region(dev);
486 if (nd_region->pfn_seed)
487 rc = sprintf(buf, "%s\n", dev_name(nd_region->pfn_seed));
499 struct nd_region *nd_region = to_nd_region(dev);
503 if (nd_region->dax_seed)
504 rc = sprintf(buf, "%s\n", dev_name(nd_region->dax_seed));
516 struct nd_region *nd_region = to_nd_region(dev);
518 return sprintf(buf, "%d\n", nd_region->ro);
526 struct nd_region *nd_region = to_nd_region(dev);
531 nd_region->ro = ro;
539 struct nd_region *nd_region = to_nd_region(dev);
541 return sprintf(buf, "%#lx\n", nd_region->align);
547 struct nd_region *nd_region = to_nd_region(dev);
556 if (!nd_region->ndr_mappings)
566 dpa = div_u64_rem(val, nd_region->ndr_mappings, &remainder);
568 || val > region_size(nd_region) || remainder)
577 nd_region->align = val;
587 struct nd_region *nd_region = to_nd_region(dev);
592 rc = badblocks_show(&nd_region->bb, buf, 0);
604 struct nd_region *nd_region = to_nd_region(dev);
606 return sprintf(buf, "%#llx\n", nd_region->ndr_start);
613 struct nd_region *nd_region = to_nd_region(dev);
615 if (test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags))
617 else if (test_bit(ND_REGION_PERSIST_MEMCTRL, &nd_region->flags))
648 struct nd_region *nd_region = to_nd_region(dev);
649 struct nd_interleave_set *nd_set = nd_region->nd_set;
650 int type = nd_region_to_nstype(nd_region);
665 int has_flush = nvdimm_has_flush(nd_region);
676 if ((nd_region->flags & (BIT(ND_REGION_PERSIST_CACHE)
701 struct nd_region *nd_region = to_nd_region(dev);
705 if (n >= nd_region->ndr_mappings)
707 nd_mapping = &nd_region->mapping[n];
763 struct nd_region *nd_region = to_nd_region(dev);
765 if (n < nd_region->ndr_mappings)
857 u64 nd_region_interleave_set_cookie(struct nd_region *nd_region,
860 struct nd_interleave_set *nd_set = nd_region->nd_set;
871 u64 nd_region_interleave_set_altcookie(struct nd_region *nd_region)
873 struct nd_interleave_set *nd_set = nd_region->nd_set;
895 void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev)
898 if (nd_region->ns_seed == dev) {
899 nd_region_create_ns_seed(nd_region);
903 if (nd_region->btt_seed == dev)
904 nd_region_create_btt_seed(nd_region);
905 if (nd_region->ns_seed == &nd_btt->ndns->dev)
906 nd_region_create_ns_seed(nd_region);
910 if (nd_region->pfn_seed == dev)
911 nd_region_create_pfn_seed(nd_region);
912 if (nd_region->ns_seed == &nd_pfn->ndns->dev)
913 nd_region_create_ns_seed(nd_region);
917 if (nd_region->dax_seed == dev)
918 nd_region_create_dax_seed(nd_region);
919 if (nd_region->ns_seed == &nd_dax->nd_pfn.ndns->dev)
920 nd_region_create_ns_seed(nd_region);
925 int nd_blk_region_init(struct nd_region *nd_region)
927 struct device *dev = &nd_region->dev;
933 if (nd_region->ndr_mappings < 1) {
943 * @nd_region: region id and number of lanes possible
958 unsigned int nd_region_acquire_lane(struct nd_region *nd_region)
964 if (nd_region->num_lanes < nr_cpu_ids) {
967 lane = cpu % nd_region->num_lanes;
968 ndl_count = per_cpu_ptr(nd_region->lane, cpu);
969 ndl_lock = per_cpu_ptr(nd_region->lane, lane);
979 void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane)
981 if (nd_region->num_lanes < nr_cpu_ids) {
985 ndl_count = per_cpu_ptr(nd_region->lane, cpu);
986 ndl_lock = per_cpu_ptr(nd_region->lane, lane);
1000 static unsigned long default_align(struct nd_region *nd_region)
1006 if (is_nd_blk(&nd_region->dev))
1011 for (i = 0; i < nd_region->ndr_mappings; i++) {
1012 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
1021 if (nd_region->ndr_size < MEMREMAP_COMPAT_ALIGN_MAX)
1024 mappings = max_t(u16, 1, nd_region->ndr_mappings);
1032 static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
1036 struct nd_region *nd_region;
1073 nd_region = &ndbr->nd_region;
1079 nd_region = kzalloc(struct_size(nd_region, mapping,
1082 region_buf = nd_region;
1087 nd_region->id = memregion_alloc(GFP_KERNEL);
1088 if (nd_region->id < 0)
1091 nd_region->lane = alloc_percpu(struct nd_percpu_lane);
1092 if (!nd_region->lane)
1098 ndl = per_cpu_ptr(nd_region->lane, i);
1107 nd_region->mapping[i].nvdimm = nvdimm;
1108 nd_region->mapping[i].start = mapping->start;
1109 nd_region->mapping[i].size = mapping->size;
1110 nd_region->mapping[i].position = mapping->position;
1111 INIT_LIST_HEAD(&nd_region->mapping[i].labels);
1112 mutex_init(&nd_region->mapping[i].lock);
1116 nd_region->ndr_mappings = ndr_desc->num_mappings;
1117 nd_region->provider_data = ndr_desc->provider_data;
1118 nd_region->nd_set = ndr_desc->nd_set;
1119 nd_region->num_lanes = ndr_desc->num_lanes;
1120 nd_region->flags = ndr_desc->flags;
1121 nd_region->ro = ro;
1122 nd_region->numa_node = ndr_desc->numa_node;
1123 nd_region->target_node = ndr_desc->target_node;
1124 ida_init(&nd_region->ns_ida);
1125 ida_init(&nd_region->btt_ida);
1126 ida_init(&nd_region->pfn_ida);
1127 ida_init(&nd_region->dax_ida);
1128 dev = &nd_region->dev;
1129 dev_set_name(dev, "region%d", nd_region->id);
1134 nd_region->ndr_size = resource_size(ndr_desc->res);
1135 nd_region->ndr_start = ndr_desc->res->start;
1136 nd_region->align = default_align(nd_region);
1138 nd_region->flush = ndr_desc->flush;
1140 nd_region->flush = NULL;
1144 return nd_region;
1147 memregion_free(nd_region->id);
1153 struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus,
1162 struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus,
1173 struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
1182 int nvdimm_flush(struct nd_region *nd_region, struct bio *bio)
1186 if (!nd_region->flush)
1187 rc = generic_nvdimm_flush(nd_region);
1189 if (nd_region->flush(nd_region, bio))
1197 * @nd_region: blk or interleaved pmem region
1199 int generic_nvdimm_flush(struct nd_region *nd_region)
1201 struct nd_region_data *ndrd = dev_get_drvdata(&nd_region->dev);
1219 for (i = 0; i < nd_region->ndr_mappings; i++)
1230 * @nd_region: blk or interleaved pmem region
1236 int nvdimm_has_flush(struct nd_region *nd_region)
1241 if (nd_region->ndr_mappings == 0
1246 if (test_bit(ND_REGION_ASYNC, &nd_region->flags) && nd_region->flush)
1250 for (i = 0; i < nd_region->ndr_mappings; i++) {
1251 struct nd_mapping *nd_mapping = &nd_region->mapping[i];
1267 int nvdimm_has_cache(struct nd_region *nd_region)
1269 return is_nd_pmem(&nd_region->dev) &&
1270 !test_bit(ND_REGION_PERSIST_CACHE, &nd_region->flags);
1274 bool is_nvdimm_sync(struct nd_region *nd_region)
1276 if (is_nd_volatile(&nd_region->dev))
1279 return is_nd_pmem(&nd_region->dev) &&
1280 !test_bit(ND_REGION_ASYNC, &nd_region->flags);
1285 struct nd_region *nd_region;
1291 struct nd_region *nd_region;
1298 nd_region = to_nd_region(dev);
1299 if (nd_region == ctx->nd_region)
1303 region_start = nd_region->ndr_start;
1304 region_end = region_start + nd_region->ndr_size;
1312 int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
1315 struct nvdimm_bus *nvdimm_bus = walk_to_nvdimm_bus(&nd_region->dev);
1317 .nd_region = nd_region,