region_devs.c (1f7df6f88b9245a7f2d0f8ecbc97dc88c8d0d8e1) | region_devs.c (3d88002e4a7bd40f355550284c6cd140e6fe29dc) |
---|---|
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 --- 33 unchanged lines hidden (view full) --- 42 .release = nd_region_release, 43}; 44 45static struct device_type nd_volatile_device_type = { 46 .name = "nd_volatile", 47 .release = nd_region_release, 48}; 49 | 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 --- 33 unchanged lines hidden (view full) --- 42 .release = nd_region_release, 43}; 44 45static struct device_type nd_volatile_device_type = { 46 .name = "nd_volatile", 47 .release = nd_region_release, 48}; 49 |
50static bool is_nd_pmem(struct device *dev) | 50bool is_nd_pmem(struct device *dev) |
51{ 52 return dev ? dev->type == &nd_pmem_device_type : false; 53} 54 | 51{ 52 return dev ? dev->type == &nd_pmem_device_type : false; 53} 54 |
55bool is_nd_blk(struct device *dev) 56{ 57 return dev ? dev->type == &nd_blk_device_type : false; 58} 59 |
|
55struct nd_region *to_nd_region(struct device *dev) 56{ 57 struct nd_region *nd_region = container_of(dev, struct nd_region, dev); 58 59 WARN_ON(dev->type->release != nd_region_release); 60 return nd_region; 61} 62EXPORT_SYMBOL_GPL(to_nd_region); 63 | 60struct nd_region *to_nd_region(struct device *dev) 61{ 62 struct nd_region *nd_region = container_of(dev, struct nd_region, dev); 63 64 WARN_ON(dev->type->release != nd_region_release); 65 return nd_region; 66} 67EXPORT_SYMBOL_GPL(to_nd_region); 68 |
69/** 70 * nd_region_to_nstype() - region to an integer namespace type 71 * @nd_region: region-device to interrogate 72 * 73 * This is the 'nstype' attribute of a region as well, an input to the 74 * MODALIAS for namespace devices, and bit number for a nvdimm_bus to match 75 * namespace devices with namespace drivers. 76 */ 77int nd_region_to_nstype(struct nd_region *nd_region) 78{ 79 if (is_nd_pmem(&nd_region->dev)) { 80 u16 i, alias; 81 82 for (i = 0, alias = 0; i < nd_region->ndr_mappings; i++) { 83 struct nd_mapping *nd_mapping = &nd_region->mapping[i]; 84 struct nvdimm *nvdimm = nd_mapping->nvdimm; 85 86 if (nvdimm->flags & NDD_ALIASING) 87 alias++; 88 } 89 if (alias) 90 return ND_DEVICE_NAMESPACE_PMEM; 91 else 92 return ND_DEVICE_NAMESPACE_IO; 93 } else if (is_nd_blk(&nd_region->dev)) { 94 return ND_DEVICE_NAMESPACE_BLK; 95 } 96 97 return 0; 98} 99 |
|
64static ssize_t size_show(struct device *dev, 65 struct device_attribute *attr, char *buf) 66{ 67 struct nd_region *nd_region = to_nd_region(dev); 68 unsigned long long size = 0; 69 70 if (is_nd_pmem(dev)) { 71 size = nd_region->ndr_size; --- 11 unchanged lines hidden (view full) --- 83 struct device_attribute *attr, char *buf) 84{ 85 struct nd_region *nd_region = to_nd_region(dev); 86 87 return sprintf(buf, "%d\n", nd_region->ndr_mappings); 88} 89static DEVICE_ATTR_RO(mappings); 90 | 100static ssize_t size_show(struct device *dev, 101 struct device_attribute *attr, char *buf) 102{ 103 struct nd_region *nd_region = to_nd_region(dev); 104 unsigned long long size = 0; 105 106 if (is_nd_pmem(dev)) { 107 size = nd_region->ndr_size; --- 11 unchanged lines hidden (view full) --- 119 struct device_attribute *attr, char *buf) 120{ 121 struct nd_region *nd_region = to_nd_region(dev); 122 123 return sprintf(buf, "%d\n", nd_region->ndr_mappings); 124} 125static DEVICE_ATTR_RO(mappings); 126 |
127static ssize_t nstype_show(struct device *dev, 128 struct device_attribute *attr, char *buf) 129{ 130 struct nd_region *nd_region = to_nd_region(dev); 131 132 return sprintf(buf, "%d\n", nd_region_to_nstype(nd_region)); 133} 134static DEVICE_ATTR_RO(nstype); 135 136static ssize_t init_namespaces_show(struct device *dev, 137 struct device_attribute *attr, char *buf) 138{ 139 struct nd_region_namespaces *num_ns = dev_get_drvdata(dev); 140 ssize_t rc; 141 142 nvdimm_bus_lock(dev); 143 if (num_ns) 144 rc = sprintf(buf, "%d/%d\n", num_ns->active, num_ns->count); 145 else 146 rc = -ENXIO; 147 nvdimm_bus_unlock(dev); 148 149 return rc; 150} 151static DEVICE_ATTR_RO(init_namespaces); 152 |
|
91static struct attribute *nd_region_attributes[] = { 92 &dev_attr_size.attr, | 153static struct attribute *nd_region_attributes[] = { 154 &dev_attr_size.attr, |
155 &dev_attr_nstype.attr, |
|
93 &dev_attr_mappings.attr, | 156 &dev_attr_mappings.attr, |
157 &dev_attr_init_namespaces.attr, |
|
94 NULL, 95}; 96 97struct attribute_group nd_region_attribute_group = { 98 .attrs = nd_region_attributes, 99}; 100EXPORT_SYMBOL_GPL(nd_region_attribute_group); 101 --- 196 unchanged lines hidden --- | 158 NULL, 159}; 160 161struct attribute_group nd_region_attribute_group = { 162 .attrs = nd_region_attributes, 163}; 164EXPORT_SYMBOL_GPL(nd_region_attribute_group); 165 --- 196 unchanged lines hidden --- |