nd-core.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  4. */
  5. #ifndef __ND_CORE_H__
  6. #define __ND_CORE_H__
  7. #include <linux/libnvdimm.h>
  8. #include <linux/device.h>
  9. #include <linux/sizes.h>
  10. #include <linux/mutex.h>
  11. #include <linux/nd.h>
  12. #include "nd.h"
  13. extern struct list_head nvdimm_bus_list;
  14. extern struct mutex nvdimm_bus_list_mutex;
  15. extern int nvdimm_major;
  16. extern struct workqueue_struct *nvdimm_wq;
  17. struct nvdimm_bus {
  18. struct nvdimm_bus_descriptor *nd_desc;
  19. wait_queue_head_t wait;
  20. struct list_head list;
  21. struct device dev;
  22. int id, probe_active;
  23. atomic_t ioctl_active;
  24. struct list_head mapping_list;
  25. struct mutex reconfig_mutex;
  26. struct badrange badrange;
  27. };
  28. struct nvdimm {
  29. unsigned long flags;
  30. void *provider_data;
  31. unsigned long cmd_mask;
  32. struct device dev;
  33. atomic_t busy;
  34. int id, num_flush;
  35. struct resource *flush_wpq;
  36. const char *dimm_id;
  37. struct {
  38. const struct nvdimm_security_ops *ops;
  39. unsigned long flags;
  40. unsigned long ext_flags;
  41. unsigned int overwrite_tmo;
  42. struct kernfs_node *overwrite_state;
  43. } sec;
  44. struct delayed_work dwork;
  45. const struct nvdimm_fw_ops *fw_ops;
  46. };
  47. static inline unsigned long nvdimm_security_flags(
  48. struct nvdimm *nvdimm, enum nvdimm_passphrase_type ptype)
  49. {
  50. u64 flags;
  51. const u64 state_flags = 1UL << NVDIMM_SECURITY_DISABLED
  52. | 1UL << NVDIMM_SECURITY_LOCKED
  53. | 1UL << NVDIMM_SECURITY_UNLOCKED
  54. | 1UL << NVDIMM_SECURITY_OVERWRITE;
  55. if (!nvdimm->sec.ops)
  56. return 0;
  57. flags = nvdimm->sec.ops->get_flags(nvdimm, ptype);
  58. /* disabled, locked, unlocked, and overwrite are mutually exclusive */
  59. dev_WARN_ONCE(&nvdimm->dev, hweight64(flags & state_flags) > 1,
  60. "reported invalid security state: %#llx\n",
  61. (unsigned long long) flags);
  62. return flags;
  63. }
  64. int nvdimm_security_freeze(struct nvdimm *nvdimm);
  65. #if IS_ENABLED(CONFIG_NVDIMM_KEYS)
  66. ssize_t nvdimm_security_store(struct device *dev, const char *buf, size_t len);
  67. void nvdimm_security_overwrite_query(struct work_struct *work);
  68. #else
  69. static inline ssize_t nvdimm_security_store(struct device *dev,
  70. const char *buf, size_t len)
  71. {
  72. return -EOPNOTSUPP;
  73. }
  74. static inline void nvdimm_security_overwrite_query(struct work_struct *work)
  75. {
  76. }
  77. #endif
  78. bool is_nvdimm(struct device *dev);
  79. bool is_nd_pmem(struct device *dev);
  80. bool is_nd_volatile(struct device *dev);
  81. static inline bool is_nd_region(struct device *dev)
  82. {
  83. return is_nd_pmem(dev) || is_nd_volatile(dev);
  84. }
  85. static inline bool is_memory(struct device *dev)
  86. {
  87. return is_nd_pmem(dev) || is_nd_volatile(dev);
  88. }
  89. struct nvdimm_bus *walk_to_nvdimm_bus(struct device *nd_dev);
  90. int __init nvdimm_bus_init(void);
  91. void nvdimm_bus_exit(void);
  92. void nvdimm_devs_exit(void);
  93. struct nd_region;
  94. void nd_region_advance_seeds(struct nd_region *nd_region, struct device *dev);
  95. void nd_region_create_ns_seed(struct nd_region *nd_region);
  96. void nd_region_create_btt_seed(struct nd_region *nd_region);
  97. void nd_region_create_pfn_seed(struct nd_region *nd_region);
  98. void nd_region_create_dax_seed(struct nd_region *nd_region);
  99. int nvdimm_bus_create_ndctl(struct nvdimm_bus *nvdimm_bus);
  100. void nvdimm_bus_destroy_ndctl(struct nvdimm_bus *nvdimm_bus);
  101. void nd_synchronize(void);
  102. void nd_device_register(struct device *dev);
  103. void nd_device_register_sync(struct device *dev);
  104. struct nd_label_id;
  105. char *nd_label_gen_id(struct nd_label_id *label_id, const uuid_t *uuid,
  106. u32 flags);
  107. bool nd_is_uuid_unique(struct device *dev, uuid_t *uuid);
  108. struct nd_region;
  109. struct nvdimm_drvdata;
  110. struct nd_mapping;
  111. void nd_mapping_free_labels(struct nd_mapping *nd_mapping);
  112. int __reserve_free_pmem(struct device *dev, void *data);
  113. void release_free_pmem(struct nvdimm_bus *nvdimm_bus,
  114. struct nd_mapping *nd_mapping);
  115. resource_size_t nd_pmem_max_contiguous_dpa(struct nd_region *nd_region,
  116. struct nd_mapping *nd_mapping);
  117. resource_size_t nd_region_allocatable_dpa(struct nd_region *nd_region);
  118. resource_size_t nd_pmem_available_dpa(struct nd_region *nd_region,
  119. struct nd_mapping *nd_mapping);
  120. resource_size_t nd_region_available_dpa(struct nd_region *nd_region);
  121. int nd_region_conflict(struct nd_region *nd_region, resource_size_t start,
  122. resource_size_t size);
  123. resource_size_t nvdimm_allocated_dpa(struct nvdimm_drvdata *ndd,
  124. struct nd_label_id *label_id);
  125. int nvdimm_num_label_slots(struct nvdimm_drvdata *ndd);
  126. void get_ndd(struct nvdimm_drvdata *ndd);
  127. resource_size_t __nvdimm_namespace_capacity(struct nd_namespace_common *ndns);
  128. void nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
  129. void __nd_detach_ndns(struct device *dev, struct nd_namespace_common **_ndns);
  130. bool nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
  131. struct nd_namespace_common **_ndns);
  132. bool __nd_attach_ndns(struct device *dev, struct nd_namespace_common *attach,
  133. struct nd_namespace_common **_ndns);
  134. ssize_t nd_namespace_store(struct device *dev,
  135. struct nd_namespace_common **_ndns, const char *buf,
  136. size_t len);
  137. struct nd_pfn *to_nd_pfn_safe(struct device *dev);
  138. bool is_nvdimm_bus(struct device *dev);
  139. #if IS_ENABLED(CONFIG_ND_CLAIM)
  140. int devm_nsio_enable(struct device *dev, struct nd_namespace_io *nsio,
  141. resource_size_t size);
  142. void devm_nsio_disable(struct device *dev, struct nd_namespace_io *nsio);
  143. #else
  144. static inline int devm_nsio_enable(struct device *dev,
  145. struct nd_namespace_io *nsio, resource_size_t size)
  146. {
  147. return -ENXIO;
  148. }
  149. static inline void devm_nsio_disable(struct device *dev,
  150. struct nd_namespace_io *nsio)
  151. {
  152. }
  153. #endif
  154. #endif /* __ND_CORE_H__ */