Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
0004  */
0005 #ifndef __ND_CORE_H__
0006 #define __ND_CORE_H__
0007 #include <linux/libnvdimm.h>
0008 #include <linux/device.h>
0009 #include <linux/sizes.h>
0010 #include <linux/mutex.h>
0011 #include <linux/nd.h>
0012 #include "nd.h"
0013 
0014 extern struct list_head nvdimm_bus_list;
0015 extern struct mutex nvdimm_bus_list_mutex;
0016 extern int nvdimm_major;
0017 extern struct workqueue_struct *nvdimm_wq;
0018 
0019 struct nvdimm_bus {
0020     struct nvdimm_bus_descriptor *nd_desc;
0021     wait_queue_head_t wait;
0022     struct list_head list;
0023     struct device dev;
0024     int id, probe_active;
0025     atomic_t ioctl_active;
0026     struct list_head mapping_list;
0027     struct mutex reconfig_mutex;
0028     struct badrange badrange;
0029 };
0030 
0031 struct nvdimm {
0032     unsigned long flags;
0033     void *provider_data;
0034     unsigned long cmd_mask;
0035     struct device dev;
0036     atomic_t busy;
0037     int id, num_flush;
0038     struct resource *flush_wpq;
0039     const char *dimm_id;
0040     struct {
0041         const struct nvdimm_security_ops *ops;
0042         unsigned long flags;
0043         unsigned long ext_flags;
0044         unsigned int overwrite_tmo;
0045         struct kernfs_node *overwrite_state;
0046     } sec;
0047     struct delayed_work dwork;
0048     const struct nvdimm_fw_ops *fw_ops;
0049 };
0050 
0051 static inline unsigned long nvdimm_security_flags(
0052         struct nvdimm *nvdimm, enum nvdimm_passphrase_type ptype)
0053 {
0054     u64 flags;
0055     const u64 state_flags = 1UL << NVDIMM_SECURITY_DISABLED
0056         | 1UL << NVDIMM_SECURITY_LOCKED
0057         | 1UL << NVDIMM_SECURITY_UNLOCKED
0058         | 1UL << NVDIMM_SECURITY_OVERWRITE;
0059 
0060     if (!nvdimm->sec.ops)
0061         return 0;
0062 
0063     flags = nvdimm->sec.ops->get_flags(nvdimm, ptype);
0064     /* disabled, locked, unlocked, and overwrite are mutually exclusive */
0065     dev_WARN_ONCE(&nvdimm->dev, hweight64(flags & state_flags) > 1,
0066             "reported invalid security state: %#llx\n",
0067             (unsigned long long) flags);
0068     return flags;
0069 }
0070 int nvdimm_security_freeze(struct nvdimm *nvdimm);
0071 #if IS_ENABLED(CONFIG_NVDIMM_KEYS)
0072 ssize_t nvdimm_security_store(struct device *dev, const char *buf, size_t len);
0073 void nvdimm_security_overwrite_query(struct work_struct *work);
0074 #else
0075 static inline ssize_t nvdimm_security_store(struct device *dev,
0076         const char *buf, size_t len)
0077 {
0078     return -EOPNOTSUPP;
0079 }
0080 static inline void nvdimm_security_overwrite_query(struct work_struct *work)
0081 {
0082 }
0083 #endif
0084 
0085 bool is_nvdimm(struct device *dev);
0086 bool is_nd_pmem(struct device *dev);
0087 bool is_nd_volatile(struct device *dev);
0088 static inline bool is_nd_region(struct device *dev)
0089 {
0090     return is_nd_pmem(dev) || is_nd_volatile(dev);
0091 }
0092 static inline bool is_memory(struct device *dev)
0093 {
0094     return is_nd_pmem(dev) || is_nd_volatile(dev);
0095 }
0096 struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev);
0097 int __init nvdimm_bus_init(void);
0098 void nvdimm_bus_exit(void);
0099 void nvdimm_devs_exit(void);
0100 struct nd_region;
0101 void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
0102 void nd_region_create_ns_seed(struct nd_region *nd_region);
0103 void nd_region_create_btt_seed(struct nd_region *nd_region);
0104 void nd_region_create_pfn_seed(struct nd_region *nd_region);
0105 void nd_region_create_dax_seed(struct nd_region *nd_region);
0106 int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus);
0107 void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus);
0108 void nd_synchronize(void);
0109 void nd_device_register(struct device *dev);
0110 struct nd_label_id;
0111 char *nd_label_gen_id(struct nd_label_id *label_id, const uuid_t *uuid,
0112               u32 flags);
0113 bool nd_is_uuid_unique(struct device *dev, uuid_t *uuid);
0114 struct nd_region;
0115 struct nvdimm_drvdata;
0116 struct nd_mapping;
0117 void nd_mapping_free_labels(struct nd_mapping *nd_mapping);
0118 
0119 int __reserve_free_pmem(struct device *dev, void *data);
0120 void release_free_pmem(struct nvdimm_bus *nvdimm_bus,
0121                struct nd_mapping *nd_mapping);
0122 
0123 resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
0124                        struct nd_mapping *nd_mapping);
0125 resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region);
0126 resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
0127                       struct nd_mapping *nd_mapping);
0128 resource_size_t nd_region_available_dpa(struct nd_region *nd_region);
0129 int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
0130         resource_size_t size);
0131 resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd,
0132         struct nd_label_id *label_id);
0133 int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd);
0134 void get_ndd(struct nvdimm_drvdata *ndd);
0135 resource_size_t __nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
0136 void nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
0137 void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
0138 bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
0139         struct nd_namespace_common **_ndns);
0140 bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
0141         struct nd_namespace_common **_ndns);
0142 ssize_t nd_namespace_store(struct device *dev,
0143         struct nd_namespace_common **_ndns, const char *buf,
0144         size_t len);
0145 struct nd_pfn *to_nd_pfn_safe(struct device *dev);
0146 bool is_nvdimm_bus(struct device *dev);
0147 
0148 #if IS_ENABLED(CONFIG_ND_CLAIM)
0149 int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio,
0150         resource_size_t size);
0151 void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio);
0152 #else
0153 static inline int devm_nsio_enable(struct device *dev,
0154         struct nd_namespace_io *nsio, resource_size_t size)
0155 {
0156     return -ENXIO;
0157 }
0158 
0159 static inline void devm_nsio_disable(struct device *dev,
0160         struct nd_namespace_io *nsio)
0161 {
0162 }
0163 #endif
0164 #endif /* __ND_CORE_H__ */