1 /* SPDX-License-Identifier: GPL-2.0-only */ << 2 /* 1 /* 3 * Copyright(c) 2013-2015 Intel Corporation. A 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 >> 9 * WITHOUT ANY WARRANTY; without even the implied warranty of >> 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU >> 11 * General Public License for more details. 4 */ 12 */ 5 #ifndef __LINUX_ND_H__ 13 #ifndef __LINUX_ND_H__ 6 #define __LINUX_ND_H__ 14 #define __LINUX_ND_H__ 7 #include <linux/fs.h> 15 #include <linux/fs.h> 8 #include <linux/ndctl.h> 16 #include <linux/ndctl.h> 9 #include <linux/device.h> 17 #include <linux/device.h> 10 #include <linux/badblocks.h> 18 #include <linux/badblocks.h> 11 #include <linux/perf_event.h> << 12 19 13 enum nvdimm_event { 20 enum nvdimm_event { 14 NVDIMM_REVALIDATE_POISON, 21 NVDIMM_REVALIDATE_POISON, 15 NVDIMM_REVALIDATE_REGION, << 16 }; << 17 << 18 enum nvdimm_claim_class { << 19 NVDIMM_CCLASS_NONE, << 20 NVDIMM_CCLASS_BTT, << 21 NVDIMM_CCLASS_BTT2, << 22 NVDIMM_CCLASS_PFN, << 23 NVDIMM_CCLASS_DAX, << 24 NVDIMM_CCLASS_UNKNOWN, << 25 }; << 26 << 27 #define NVDIMM_EVENT_VAR(_id) event_attr_##_i << 28 #define NVDIMM_EVENT_PTR(_id) (&event_attr_## << 29 << 30 #define NVDIMM_EVENT_ATTR(_name, _id) << 31 PMU_EVENT_ATTR(_name, NVDIMM_EVENT_VAR << 32 nvdimm_events_sysfs_sh << 33 << 34 /* Event attribute array index */ << 35 #define NVDIMM_PMU_FORMAT_ATTR 0 << 36 #define NVDIMM_PMU_EVENT_ATTR 1 << 37 #define NVDIMM_PMU_CPUMASK_ATTR 2 << 38 #define NVDIMM_PMU_NULL_ATTR 3 << 39 << 40 /** << 41 * struct nvdimm_pmu - data structure for nvdi << 42 * @pmu: pmu data structure for nvdimm perform << 43 * @dev: nvdimm device pointer. << 44 * @cpu: designated cpu for counter access. << 45 * @node: node for cpu hotplug notifier link. << 46 * @cpuhp_state: state for cpu hotplug notific << 47 * @arch_cpumask: cpumask to get designated cp << 48 */ << 49 struct nvdimm_pmu { << 50 struct pmu pmu; << 51 struct device *dev; << 52 int cpu; << 53 struct hlist_node node; << 54 enum cpuhp_state cpuhp_state; << 55 /* cpumask provided by arch/platform s << 56 struct cpumask arch_cpumask; << 57 }; 22 }; 58 23 59 struct platform_device; << 60 << 61 #ifdef CONFIG_PERF_EVENTS << 62 extern ssize_t nvdimm_events_sysfs_show(struct << 63 struct << 64 char * << 65 << 66 int register_nvdimm_pmu(struct nvdimm_pmu *nvd << 67 void unregister_nvdimm_pmu(struct nvdimm_pmu * << 68 << 69 #else << 70 static inline int register_nvdimm_pmu(struct n << 71 { << 72 return -ENXIO; << 73 } << 74 << 75 static inline void unregister_nvdimm_pmu(struc << 76 #endif << 77 << 78 struct nd_device_driver { 24 struct nd_device_driver { 79 struct device_driver drv; 25 struct device_driver drv; 80 unsigned long type; 26 unsigned long type; 81 int (*probe)(struct device *dev); 27 int (*probe)(struct device *dev); 82 void (*remove)(struct device *dev); !! 28 int (*remove)(struct device *dev); 83 void (*shutdown)(struct device *dev); 29 void (*shutdown)(struct device *dev); 84 void (*notify)(struct device *dev, enu 30 void (*notify)(struct device *dev, enum nvdimm_event event); 85 }; 31 }; 86 32 87 #define to_nd_device_driver(__drv) contai !! 33 static inline struct nd_device_driver *to_nd_device_driver( >> 34 struct device_driver *drv) >> 35 { >> 36 return container_of(drv, struct nd_device_driver, drv); >> 37 }; 88 38 89 /** 39 /** 90 * struct nd_namespace_common - core infrastru 40 * struct nd_namespace_common - core infrastructure of a namespace 91 * @force_raw: ignore other personalities for 41 * @force_raw: ignore other personalities for the namespace (e.g. btt) 92 * @dev: device model node 42 * @dev: device model node 93 * @claim: when set a another personality has 43 * @claim: when set a another personality has taken ownership of the namespace 94 * @claim_class: restrict claim type to a give << 95 * @rw_bytes: access the raw namespace capacit 44 * @rw_bytes: access the raw namespace capacity with byte-aligned transfers 96 */ 45 */ 97 struct nd_namespace_common { 46 struct nd_namespace_common { 98 int force_raw; 47 int force_raw; 99 struct device dev; 48 struct device dev; 100 struct device *claim; 49 struct device *claim; 101 enum nvdimm_claim_class claim_class; << 102 int (*rw_bytes)(struct nd_namespace_co 50 int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset, 103 void *buf, size_t size !! 51 void *buf, size_t size, int rw); 104 }; 52 }; 105 53 106 static inline struct nd_namespace_common *to_n 54 static inline struct nd_namespace_common *to_ndns(struct device *dev) 107 { 55 { 108 return container_of(dev, struct nd_nam 56 return container_of(dev, struct nd_namespace_common, dev); 109 } 57 } 110 58 111 /** 59 /** 112 * struct nd_namespace_io - device representat 60 * struct nd_namespace_io - device representation of a persistent memory range 113 * @dev: namespace device created by the nd re 61 * @dev: namespace device created by the nd region driver 114 * @res: struct resource conversion of a NFIT 62 * @res: struct resource conversion of a NFIT SPA table 115 * @size: cached resource_size(@res) for fast 63 * @size: cached resource_size(@res) for fast path size checks 116 * @addr: virtual address to access the namesp 64 * @addr: virtual address to access the namespace range 117 * @bb: badblocks list for the namespace range 65 * @bb: badblocks list for the namespace range 118 */ 66 */ 119 struct nd_namespace_io { 67 struct nd_namespace_io { 120 struct nd_namespace_common common; 68 struct nd_namespace_common common; 121 struct resource res; 69 struct resource res; 122 resource_size_t size; 70 resource_size_t size; 123 void *addr; 71 void *addr; 124 struct badblocks bb; 72 struct badblocks bb; 125 }; 73 }; 126 74 127 /** 75 /** 128 * struct nd_namespace_pmem - namespace device 76 * struct nd_namespace_pmem - namespace device for dimm-backed interleaved memory 129 * @nsio: device and system physical address r 77 * @nsio: device and system physical address range to drive 130 * @lbasize: logical sector size for the names << 131 * @alt_name: namespace name supplied in the d 78 * @alt_name: namespace name supplied in the dimm label 132 * @uuid: namespace name supplied in the dimm 79 * @uuid: namespace name supplied in the dimm label 133 * @id: ida allocated id 80 * @id: ida allocated id 134 */ 81 */ 135 struct nd_namespace_pmem { 82 struct nd_namespace_pmem { 136 struct nd_namespace_io nsio; 83 struct nd_namespace_io nsio; 137 unsigned long lbasize; << 138 char *alt_name; 84 char *alt_name; 139 uuid_t *uuid; !! 85 u8 *uuid; 140 int id; 86 int id; 141 }; 87 }; 142 88 >> 89 /** >> 90 * struct nd_namespace_blk - namespace for dimm-bounded persistent memory >> 91 * @alt_name: namespace name supplied in the dimm label >> 92 * @uuid: namespace name supplied in the dimm label >> 93 * @id: ida allocated id >> 94 * @lbasize: blk namespaces have a native sector size when btt not present >> 95 * @size: sum of all the resource ranges allocated to this namespace >> 96 * @num_resources: number of dpa extents to claim >> 97 * @res: discontiguous dpa extents for given dimm >> 98 */ >> 99 struct nd_namespace_blk { >> 100 struct nd_namespace_common common; >> 101 char *alt_name; >> 102 u8 *uuid; >> 103 int id; >> 104 unsigned long lbasize; >> 105 resource_size_t size; >> 106 int num_resources; >> 107 struct resource **res; >> 108 }; >> 109 143 static inline struct nd_namespace_io *to_nd_na 110 static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev) 144 { 111 { 145 return container_of(dev, struct nd_nam 112 return container_of(dev, struct nd_namespace_io, common.dev); 146 } 113 } 147 114 148 static inline struct nd_namespace_pmem *to_nd_ 115 static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev) 149 { 116 { 150 struct nd_namespace_io *nsio = to_nd_n 117 struct nd_namespace_io *nsio = to_nd_namespace_io(dev); 151 118 152 return container_of(nsio, struct nd_na 119 return container_of(nsio, struct nd_namespace_pmem, nsio); 153 } 120 } 154 121 >> 122 static inline struct nd_namespace_blk *to_nd_namespace_blk(const struct device *dev) >> 123 { >> 124 return container_of(dev, struct nd_namespace_blk, common.dev); >> 125 } >> 126 155 /** 127 /** 156 * nvdimm_read_bytes() - synchronously read by 128 * nvdimm_read_bytes() - synchronously read bytes from an nvdimm namespace 157 * @ndns: device to read 129 * @ndns: device to read 158 * @offset: namespace-relative starting offset 130 * @offset: namespace-relative starting offset 159 * @buf: buffer to fill 131 * @buf: buffer to fill 160 * @size: transfer length 132 * @size: transfer length 161 * 133 * 162 * @buf is up-to-date upon return from this ro 134 * @buf is up-to-date upon return from this routine. 163 */ 135 */ 164 static inline int nvdimm_read_bytes(struct nd_ 136 static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns, 165 resource_size_t offset, void * !! 137 resource_size_t offset, void *buf, size_t size) 166 unsigned long flags) << 167 { 138 { 168 return ndns->rw_bytes(ndns, offset, bu !! 139 return ndns->rw_bytes(ndns, offset, buf, size, READ); 169 } 140 } 170 141 171 /** 142 /** 172 * nvdimm_write_bytes() - synchronously write 143 * nvdimm_write_bytes() - synchronously write bytes to an nvdimm namespace 173 * @ndns: device to write !! 144 * @ndns: device to read 174 * @offset: namespace-relative starting offset 145 * @offset: namespace-relative starting offset 175 * @buf: buffer to drain 146 * @buf: buffer to drain 176 * @size: transfer length 147 * @size: transfer length 177 * 148 * 178 * NVDIMM Namepaces disks do not implement sec 149 * NVDIMM Namepaces disks do not implement sectors internally. Depending on 179 * the @ndns, the contents of @buf may be in c 150 * the @ndns, the contents of @buf may be in cpu cache, platform buffers, 180 * or on backing memory media upon return from 151 * or on backing memory media upon return from this routine. Flushing 181 * to media is handled internal to the @ndns d 152 * to media is handled internal to the @ndns driver, if at all. 182 */ 153 */ 183 static inline int nvdimm_write_bytes(struct nd 154 static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns, 184 resource_size_t offset, void * !! 155 resource_size_t offset, void *buf, size_t size) 185 unsigned long flags) << 186 { 156 { 187 return ndns->rw_bytes(ndns, offset, bu !! 157 return ndns->rw_bytes(ndns, offset, buf, size, WRITE); 188 } 158 } 189 159 190 #define MODULE_ALIAS_ND_DEVICE(type) \ 160 #define MODULE_ALIAS_ND_DEVICE(type) \ 191 MODULE_ALIAS("nd:t" __stringify(type) 161 MODULE_ALIAS("nd:t" __stringify(type) "*") 192 #define ND_DEVICE_MODALIAS_FMT "nd:t%d" 162 #define ND_DEVICE_MODALIAS_FMT "nd:t%d" 193 163 194 struct nd_region; 164 struct nd_region; 195 void nvdimm_region_notify(struct nd_region *nd 165 void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event); 196 int __must_check __nd_driver_register(struct n 166 int __must_check __nd_driver_register(struct nd_device_driver *nd_drv, 197 struct module *module, const c 167 struct module *module, const char *mod_name); 198 static inline void nd_driver_unregister(struct << 199 { << 200 driver_unregister(&drv->drv); << 201 } << 202 #define nd_driver_register(driver) \ 168 #define nd_driver_register(driver) \ 203 __nd_driver_register(driver, THIS_MODU 169 __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME) 204 #define module_nd_driver(driver) \ << 205 module_driver(driver, nd_driver_regist << 206 #endif /* __LINUX_ND_H__ */ 170 #endif /* __LINUX_ND_H__ */ 207 171
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.