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