libnvdimm.h 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*
  2. * libnvdimm - Non-volatile-memory Devices Subsystem
  3. *
  4. * Copyright(c) 2013-2015 Intel Corporation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of version 2 of the GNU General Public License as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. */
  15. #ifndef __LIBNVDIMM_H__
  16. #define __LIBNVDIMM_H__
  17. #include <linux/kernel.h>
  18. #include <linux/sizes.h>
  19. #include <linux/types.h>
  20. enum {
  21. /* when a dimm supports both PMEM and BLK access a label is required */
  22. NDD_ALIASING = 1 << 0,
  23. /* unarmed memory devices may not persist writes */
  24. NDD_UNARMED = 1 << 1,
  25. /* need to set a limit somewhere, but yes, this is likely overkill */
  26. ND_IOCTL_MAX_BUFLEN = SZ_4M,
  27. ND_CMD_MAX_ELEM = 5,
  28. ND_CMD_MAX_ENVELOPE = 256,
  29. ND_MAX_MAPPINGS = 32,
  30. /* region flag indicating to direct-map persistent memory by default */
  31. ND_REGION_PAGEMAP = 0,
  32. /* mark newly adjusted resources as requiring a label update */
  33. DPA_RESOURCE_ADJUSTED = 1 << 0,
  34. };
  35. extern struct attribute_group nvdimm_bus_attribute_group;
  36. extern struct attribute_group nvdimm_attribute_group;
  37. extern struct attribute_group nd_device_attribute_group;
  38. extern struct attribute_group nd_numa_attribute_group;
  39. extern struct attribute_group nd_region_attribute_group;
  40. extern struct attribute_group nd_mapping_attribute_group;
  41. struct nvdimm;
  42. struct nvdimm_bus_descriptor;
  43. typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,
  44. struct nvdimm *nvdimm, unsigned int cmd, void *buf,
  45. unsigned int buf_len, int *cmd_rc);
  46. struct nvdimm_bus_descriptor {
  47. const struct attribute_group **attr_groups;
  48. unsigned long cmd_mask;
  49. struct module *module;
  50. char *provider_name;
  51. ndctl_fn ndctl;
  52. int (*flush_probe)(struct nvdimm_bus_descriptor *nd_desc);
  53. int (*clear_to_send)(struct nvdimm_bus_descriptor *nd_desc,
  54. struct nvdimm *nvdimm, unsigned int cmd);
  55. };
  56. struct nd_cmd_desc {
  57. int in_num;
  58. int out_num;
  59. u32 in_sizes[ND_CMD_MAX_ELEM];
  60. int out_sizes[ND_CMD_MAX_ELEM];
  61. };
  62. struct nd_interleave_set {
  63. u64 cookie;
  64. /* compatibility with initial buggy Linux implementation */
  65. u64 altcookie;
  66. };
  67. struct nd_mapping_desc {
  68. struct nvdimm *nvdimm;
  69. u64 start;
  70. u64 size;
  71. };
  72. struct nd_region_desc {
  73. struct resource *res;
  74. struct nd_mapping_desc *mapping;
  75. u16 num_mappings;
  76. const struct attribute_group **attr_groups;
  77. struct nd_interleave_set *nd_set;
  78. void *provider_data;
  79. int num_lanes;
  80. int numa_node;
  81. unsigned long flags;
  82. };
  83. struct device;
  84. void *devm_nvdimm_memremap(struct device *dev, resource_size_t offset,
  85. size_t size, unsigned long flags);
  86. static inline void __iomem *devm_nvdimm_ioremap(struct device *dev,
  87. resource_size_t offset, size_t size)
  88. {
  89. return (void __iomem *) devm_nvdimm_memremap(dev, offset, size, 0);
  90. }
  91. struct nvdimm_bus;
  92. struct module;
  93. struct device;
  94. struct nd_blk_region;
  95. struct nd_blk_region_desc {
  96. int (*enable)(struct nvdimm_bus *nvdimm_bus, struct device *dev);
  97. int (*do_io)(struct nd_blk_region *ndbr, resource_size_t dpa,
  98. void *iobuf, u64 len, int rw);
  99. struct nd_region_desc ndr_desc;
  100. };
  101. static inline struct nd_blk_region_desc *to_blk_region_desc(
  102. struct nd_region_desc *ndr_desc)
  103. {
  104. return container_of(ndr_desc, struct nd_blk_region_desc, ndr_desc);
  105. }
  106. int nvdimm_bus_add_poison(struct nvdimm_bus *nvdimm_bus, u64 addr, u64 length);
  107. void nvdimm_clear_from_poison_list(struct nvdimm_bus *nvdimm_bus,
  108. phys_addr_t start, unsigned int len);
  109. struct nvdimm_bus *nvdimm_bus_register(struct device *parent,
  110. struct nvdimm_bus_descriptor *nfit_desc);
  111. void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus);
  112. struct nvdimm_bus *to_nvdimm_bus(struct device *dev);
  113. struct nvdimm *to_nvdimm(struct device *dev);
  114. struct nd_region *to_nd_region(struct device *dev);
  115. struct nd_blk_region *to_nd_blk_region(struct device *dev);
  116. struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus);
  117. struct device *to_nvdimm_bus_dev(struct nvdimm_bus *nvdimm_bus);
  118. const char *nvdimm_name(struct nvdimm *nvdimm);
  119. struct kobject *nvdimm_kobj(struct nvdimm *nvdimm);
  120. unsigned long nvdimm_cmd_mask(struct nvdimm *nvdimm);
  121. void *nvdimm_provider_data(struct nvdimm *nvdimm);
  122. struct nvdimm *nvdimm_create(struct nvdimm_bus *nvdimm_bus, void *provider_data,
  123. const struct attribute_group **groups, unsigned long flags,
  124. unsigned long cmd_mask, int num_flush,
  125. struct resource *flush_wpq);
  126. const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd);
  127. const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd);
  128. u32 nd_cmd_in_size(struct nvdimm *nvdimm, int cmd,
  129. const struct nd_cmd_desc *desc, int idx, void *buf);
  130. u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
  131. const struct nd_cmd_desc *desc, int idx, const u32 *in_field,
  132. const u32 *out_field, unsigned long remainder);
  133. int nvdimm_bus_check_dimm_count(struct nvdimm_bus *nvdimm_bus, int dimm_count);
  134. struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus,
  135. struct nd_region_desc *ndr_desc);
  136. struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus,
  137. struct nd_region_desc *ndr_desc);
  138. struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
  139. struct nd_region_desc *ndr_desc);
  140. void *nd_region_provider_data(struct nd_region *nd_region);
  141. void *nd_blk_region_provider_data(struct nd_blk_region *ndbr);
  142. void nd_blk_region_set_provider_data(struct nd_blk_region *ndbr, void *data);
  143. struct nvdimm *nd_blk_region_to_dimm(struct nd_blk_region *ndbr);
  144. unsigned int nd_region_acquire_lane(struct nd_region *nd_region);
  145. void nd_region_release_lane(struct nd_region *nd_region, unsigned int lane);
  146. u64 nd_fletcher64(void *addr, size_t len, bool le);
  147. void nvdimm_flush(struct nd_region *nd_region);
  148. int nvdimm_has_flush(struct nd_region *nd_region);
  149. #endif /* __LIBNVDIMM_H__ */