0001
0002
0003
0004
0005 #ifndef __LINUX_ND_H__
0006 #define __LINUX_ND_H__
0007 #include <linux/fs.h>
0008 #include <linux/ndctl.h>
0009 #include <linux/device.h>
0010 #include <linux/badblocks.h>
0011 #include <linux/perf_event.h>
0012
0013 enum nvdimm_event {
0014 NVDIMM_REVALIDATE_POISON,
0015 NVDIMM_REVALIDATE_REGION,
0016 };
0017
0018 enum nvdimm_claim_class {
0019 NVDIMM_CCLASS_NONE,
0020 NVDIMM_CCLASS_BTT,
0021 NVDIMM_CCLASS_BTT2,
0022 NVDIMM_CCLASS_PFN,
0023 NVDIMM_CCLASS_DAX,
0024 NVDIMM_CCLASS_UNKNOWN,
0025 };
0026
0027 #define NVDIMM_EVENT_VAR(_id) event_attr_##_id
0028 #define NVDIMM_EVENT_PTR(_id) (&event_attr_##_id.attr.attr)
0029
0030 #define NVDIMM_EVENT_ATTR(_name, _id) \
0031 PMU_EVENT_ATTR(_name, NVDIMM_EVENT_VAR(_id), _id, \
0032 nvdimm_events_sysfs_show)
0033
0034
0035 #define NVDIMM_PMU_FORMAT_ATTR 0
0036 #define NVDIMM_PMU_EVENT_ATTR 1
0037 #define NVDIMM_PMU_CPUMASK_ATTR 2
0038 #define NVDIMM_PMU_NULL_ATTR 3
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 struct nvdimm_pmu {
0050 struct pmu pmu;
0051 struct device *dev;
0052 int cpu;
0053 struct hlist_node node;
0054 enum cpuhp_state cpuhp_state;
0055
0056 struct cpumask arch_cpumask;
0057 };
0058
0059 struct platform_device;
0060
0061 #ifdef CONFIG_PERF_EVENTS
0062 extern ssize_t nvdimm_events_sysfs_show(struct device *dev,
0063 struct device_attribute *attr,
0064 char *page);
0065
0066 int register_nvdimm_pmu(struct nvdimm_pmu *nvdimm, struct platform_device *pdev);
0067 void unregister_nvdimm_pmu(struct nvdimm_pmu *nd_pmu);
0068
0069 #else
0070 static inline int register_nvdimm_pmu(struct nvdimm_pmu *nvdimm, struct platform_device *pdev)
0071 {
0072 return -ENXIO;
0073 }
0074
0075 static inline void unregister_nvdimm_pmu(struct nvdimm_pmu *nd_pmu) { }
0076 #endif
0077
0078 struct nd_device_driver {
0079 struct device_driver drv;
0080 unsigned long type;
0081 int (*probe)(struct device *dev);
0082 void (*remove)(struct device *dev);
0083 void (*shutdown)(struct device *dev);
0084 void (*notify)(struct device *dev, enum nvdimm_event event);
0085 };
0086
0087 static inline struct nd_device_driver *to_nd_device_driver(
0088 struct device_driver *drv)
0089 {
0090 return container_of(drv, struct nd_device_driver, drv);
0091 };
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 struct nd_namespace_common {
0102 int force_raw;
0103 struct device dev;
0104 struct device *claim;
0105 enum nvdimm_claim_class claim_class;
0106 int (*rw_bytes)(struct nd_namespace_common *, resource_size_t offset,
0107 void *buf, size_t size, int rw, unsigned long flags);
0108 };
0109
0110 static inline struct nd_namespace_common *to_ndns(struct device *dev)
0111 {
0112 return container_of(dev, struct nd_namespace_common, dev);
0113 }
0114
0115
0116
0117
0118
0119
0120
0121
0122
0123 struct nd_namespace_io {
0124 struct nd_namespace_common common;
0125 struct resource res;
0126 resource_size_t size;
0127 void *addr;
0128 struct badblocks bb;
0129 };
0130
0131
0132
0133
0134
0135
0136
0137
0138
0139 struct nd_namespace_pmem {
0140 struct nd_namespace_io nsio;
0141 unsigned long lbasize;
0142 char *alt_name;
0143 uuid_t *uuid;
0144 int id;
0145 };
0146
0147 static inline struct nd_namespace_io *to_nd_namespace_io(const struct device *dev)
0148 {
0149 return container_of(dev, struct nd_namespace_io, common.dev);
0150 }
0151
0152 static inline struct nd_namespace_pmem *to_nd_namespace_pmem(const struct device *dev)
0153 {
0154 struct nd_namespace_io *nsio = to_nd_namespace_io(dev);
0155
0156 return container_of(nsio, struct nd_namespace_pmem, nsio);
0157 }
0158
0159
0160
0161
0162
0163
0164
0165
0166
0167
0168 static inline int nvdimm_read_bytes(struct nd_namespace_common *ndns,
0169 resource_size_t offset, void *buf, size_t size,
0170 unsigned long flags)
0171 {
0172 return ndns->rw_bytes(ndns, offset, buf, size, READ, flags);
0173 }
0174
0175
0176
0177
0178
0179
0180
0181
0182
0183
0184
0185
0186
0187 static inline int nvdimm_write_bytes(struct nd_namespace_common *ndns,
0188 resource_size_t offset, void *buf, size_t size,
0189 unsigned long flags)
0190 {
0191 return ndns->rw_bytes(ndns, offset, buf, size, WRITE, flags);
0192 }
0193
0194 #define MODULE_ALIAS_ND_DEVICE(type) \
0195 MODULE_ALIAS("nd:t" __stringify(type) "*")
0196 #define ND_DEVICE_MODALIAS_FMT "nd:t%d"
0197
0198 struct nd_region;
0199 void nvdimm_region_notify(struct nd_region *nd_region, enum nvdimm_event event);
0200 int __must_check __nd_driver_register(struct nd_device_driver *nd_drv,
0201 struct module *module, const char *mod_name);
0202 static inline void nd_driver_unregister(struct nd_device_driver *drv)
0203 {
0204 driver_unregister(&drv->drv);
0205 }
0206 #define nd_driver_register(driver) \
0207 __nd_driver_register(driver, THIS_MODULE, KBUILD_MODNAME)
0208 #define module_nd_driver(driver) \
0209 module_driver(driver, nd_driver_register, nd_driver_unregister)
0210 #endif