region_devs.c (047fc8a1f9a6330eacc80374dff087e20dc2304b) region_devs.c (581388209405902b56d055f644b4dd124a206112)
1/*
2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but

--- 331 unchanged lines hidden (view full) ---

340 else
341 rc = sprintf(buf, "\n");
342 nvdimm_bus_unlock(dev);
343
344 return rc;
345}
346static DEVICE_ATTR_RO(btt_seed);
347
1/*
2 * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of version 2 of the GNU General Public License as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but

--- 331 unchanged lines hidden (view full) ---

340 else
341 rc = sprintf(buf, "\n");
342 nvdimm_bus_unlock(dev);
343
344 return rc;
345}
346static DEVICE_ATTR_RO(btt_seed);
347
348static ssize_t read_only_show(struct device *dev,
349 struct device_attribute *attr, char *buf)
350{
351 struct nd_region *nd_region = to_nd_region(dev);
352
353 return sprintf(buf, "%d\n", nd_region->ro);
354}
355
356static ssize_t read_only_store(struct device *dev,
357 struct device_attribute *attr, const char *buf, size_t len)
358{
359 bool ro;
360 int rc = strtobool(buf, &ro);
361 struct nd_region *nd_region = to_nd_region(dev);
362
363 if (rc)
364 return rc;
365
366 nd_region->ro = ro;
367 return len;
368}
369static DEVICE_ATTR_RW(read_only);
370
348static struct attribute *nd_region_attributes[] = {
349 &dev_attr_size.attr,
350 &dev_attr_nstype.attr,
351 &dev_attr_mappings.attr,
352 &dev_attr_btt_seed.attr,
371static struct attribute *nd_region_attributes[] = {
372 &dev_attr_size.attr,
373 &dev_attr_nstype.attr,
374 &dev_attr_mappings.attr,
375 &dev_attr_btt_seed.attr,
376 &dev_attr_read_only.attr,
353 &dev_attr_set_cookie.attr,
354 &dev_attr_available_size.attr,
355 &dev_attr_namespace_seed.attr,
356 &dev_attr_init_namespaces.attr,
357 NULL,
358};
359
360static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n)

--- 275 unchanged lines hidden (view full) ---

636static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
637 struct nd_region_desc *ndr_desc, struct device_type *dev_type,
638 const char *caller)
639{
640 struct nd_region *nd_region;
641 struct device *dev;
642 void *region_buf;
643 unsigned int i;
377 &dev_attr_set_cookie.attr,
378 &dev_attr_available_size.attr,
379 &dev_attr_namespace_seed.attr,
380 &dev_attr_init_namespaces.attr,
381 NULL,
382};
383
384static umode_t region_visible(struct kobject *kobj, struct attribute *a, int n)

--- 275 unchanged lines hidden (view full) ---

660static struct nd_region *nd_region_create(struct nvdimm_bus *nvdimm_bus,
661 struct nd_region_desc *ndr_desc, struct device_type *dev_type,
662 const char *caller)
663{
664 struct nd_region *nd_region;
665 struct device *dev;
666 void *region_buf;
667 unsigned int i;
668 int ro = 0;
644
645 for (i = 0; i < ndr_desc->num_mappings; i++) {
646 struct nd_mapping *nd_mapping = &ndr_desc->nd_mapping[i];
647 struct nvdimm *nvdimm = nd_mapping->nvdimm;
648
649 if ((nd_mapping->start | nd_mapping->size) % SZ_4K) {
650 dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
651 caller, dev_name(&nvdimm->dev), i);
652
653 return NULL;
654 }
669
670 for (i = 0; i < ndr_desc->num_mappings; i++) {
671 struct nd_mapping *nd_mapping = &ndr_desc->nd_mapping[i];
672 struct nvdimm *nvdimm = nd_mapping->nvdimm;
673
674 if ((nd_mapping->start | nd_mapping->size) % SZ_4K) {
675 dev_err(&nvdimm_bus->dev, "%s: %s mapping%d is not 4K aligned\n",
676 caller, dev_name(&nvdimm->dev), i);
677
678 return NULL;
679 }
680
681 if (nvdimm->flags & NDD_UNARMED)
682 ro = 1;
655 }
656
657 if (dev_type == &nd_blk_device_type) {
658 struct nd_blk_region_desc *ndbr_desc;
659 struct nd_blk_region *ndbr;
660
661 ndbr_desc = to_blk_region_desc(ndr_desc);
662 ndbr = kzalloc(sizeof(*ndbr) + sizeof(struct nd_mapping)

--- 39 unchanged lines hidden (view full) ---

702 struct nvdimm *nvdimm = nd_mapping->nvdimm;
703
704 get_device(&nvdimm->dev);
705 }
706 nd_region->ndr_mappings = ndr_desc->num_mappings;
707 nd_region->provider_data = ndr_desc->provider_data;
708 nd_region->nd_set = ndr_desc->nd_set;
709 nd_region->num_lanes = ndr_desc->num_lanes;
683 }
684
685 if (dev_type == &nd_blk_device_type) {
686 struct nd_blk_region_desc *ndbr_desc;
687 struct nd_blk_region *ndbr;
688
689 ndbr_desc = to_blk_region_desc(ndr_desc);
690 ndbr = kzalloc(sizeof(*ndbr) + sizeof(struct nd_mapping)

--- 39 unchanged lines hidden (view full) ---

730 struct nvdimm *nvdimm = nd_mapping->nvdimm;
731
732 get_device(&nvdimm->dev);
733 }
734 nd_region->ndr_mappings = ndr_desc->num_mappings;
735 nd_region->provider_data = ndr_desc->provider_data;
736 nd_region->nd_set = ndr_desc->nd_set;
737 nd_region->num_lanes = ndr_desc->num_lanes;
738 nd_region->ro = ro;
710 ida_init(&nd_region->ns_ida);
711 ida_init(&nd_region->btt_ida);
712 dev = &nd_region->dev;
713 dev_set_name(dev, "region%d", nd_region->id);
714 dev->parent = &nvdimm_bus->dev;
715 dev->type = dev_type;
716 dev->groups = ndr_desc->attr_groups;
717 nd_region->ndr_size = resource_size(ndr_desc->res);

--- 40 unchanged lines hidden ---
739 ida_init(&nd_region->ns_ida);
740 ida_init(&nd_region->btt_ida);
741 dev = &nd_region->dev;
742 dev_set_name(dev, "region%d", nd_region->id);
743 dev->parent = &nvdimm_bus->dev;
744 dev->type = dev_type;
745 dev->groups = ndr_desc->attr_groups;
746 nd_region->ndr_size = resource_size(ndr_desc->res);

--- 40 unchanged lines hidden ---