libnvdimm.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  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/sizes.h>
  18. #include <linux/types.h>
  19. enum {
  20. /* when a dimm supports both PMEM and BLK access a label is required */
  21. NDD_ALIASING = 1 << 0,
  22. /* need to set a limit somewhere, but yes, this is likely overkill */
  23. ND_IOCTL_MAX_BUFLEN = SZ_4M,
  24. ND_CMD_MAX_ELEM = 4,
  25. ND_CMD_MAX_ENVELOPE = 16,
  26. ND_CMD_ARS_STATUS_MAX = SZ_4K,
  27. ND_MAX_MAPPINGS = 32,
  28. /* mark newly adjusted resources as requiring a label update */
  29. DPA_RESOURCE_ADJUSTED = 1 << 0,
  30. };
  31. extern struct attribute_group nvdimm_bus_attribute_group;
  32. extern struct attribute_group nvdimm_attribute_group;
  33. extern struct attribute_group nd_device_attribute_group;
  34. extern struct attribute_group nd_region_attribute_group;
  35. extern struct attribute_group nd_mapping_attribute_group;
  36. struct nvdimm;
  37. struct nvdimm_bus_descriptor;
  38. typedef int (*ndctl_fn)(struct nvdimm_bus_descriptor *nd_desc,
  39. struct nvdimm *nvdimm, unsigned int cmd, void *buf,
  40. unsigned int buf_len);
  41. struct nd_namespace_label;
  42. struct nvdimm_drvdata;
  43. struct nd_mapping {
  44. struct nvdimm *nvdimm;
  45. struct nd_namespace_label **labels;
  46. u64 start;
  47. u64 size;
  48. /*
  49. * @ndd is for private use at region enable / disable time for
  50. * get_ndd() + put_ndd(), all other nd_mapping to ndd
  51. * conversions use to_ndd() which respects enabled state of the
  52. * nvdimm.
  53. */
  54. struct nvdimm_drvdata *ndd;
  55. };
  56. struct nvdimm_bus_descriptor {
  57. const struct attribute_group **attr_groups;
  58. unsigned long dsm_mask;
  59. char *provider_name;
  60. ndctl_fn ndctl;
  61. };
  62. struct nd_cmd_desc {
  63. int in_num;
  64. int out_num;
  65. u32 in_sizes[ND_CMD_MAX_ELEM];
  66. int out_sizes[ND_CMD_MAX_ELEM];
  67. };
  68. struct nd_interleave_set {
  69. u64 cookie;
  70. };
  71. struct nd_region_desc {
  72. struct resource *res;
  73. struct nd_mapping *nd_mapping;
  74. u16 num_mappings;
  75. const struct attribute_group **attr_groups;
  76. struct nd_interleave_set *nd_set;
  77. void *provider_data;
  78. };
  79. struct nvdimm_bus;
  80. struct device;
  81. struct module;
  82. struct nvdimm_bus *__nvdimm_bus_register(struct device *parent,
  83. struct nvdimm_bus_descriptor *nfit_desc, struct module *module);
  84. #define nvdimm_bus_register(parent, desc) \
  85. __nvdimm_bus_register(parent, desc, THIS_MODULE)
  86. void nvdimm_bus_unregister(struct nvdimm_bus *nvdimm_bus);
  87. struct nvdimm_bus *to_nvdimm_bus(struct device *dev);
  88. struct nvdimm *to_nvdimm(struct device *dev);
  89. struct nd_region *to_nd_region(struct device *dev);
  90. struct nvdimm_bus_descriptor *to_nd_desc(struct nvdimm_bus *nvdimm_bus);
  91. const char *nvdimm_name(struct nvdimm *nvdimm);
  92. void *nvdimm_provider_data(struct nvdimm *nvdimm);
  93. void *nd_region_provider_data(struct nd_region *nd_region);
  94. struct nvdimm *nvdimm_create(struct nvdimm_bus *nvdimm_bus, void *provider_data,
  95. const struct attribute_group **groups, unsigned long flags,
  96. unsigned long *dsm_mask);
  97. const struct nd_cmd_desc *nd_cmd_dimm_desc(int cmd);
  98. const struct nd_cmd_desc *nd_cmd_bus_desc(int cmd);
  99. u32 nd_cmd_in_size(struct nvdimm *nvdimm, int cmd,
  100. const struct nd_cmd_desc *desc, int idx, void *buf);
  101. u32 nd_cmd_out_size(struct nvdimm *nvdimm, int cmd,
  102. const struct nd_cmd_desc *desc, int idx, const u32 *in_field,
  103. const u32 *out_field);
  104. int nvdimm_bus_check_dimm_count(struct nvdimm_bus *nvdimm_bus, int dimm_count);
  105. struct nd_region *nvdimm_pmem_region_create(struct nvdimm_bus *nvdimm_bus,
  106. struct nd_region_desc *ndr_desc);
  107. struct nd_region *nvdimm_blk_region_create(struct nvdimm_bus *nvdimm_bus,
  108. struct nd_region_desc *ndr_desc);
  109. struct nd_region *nvdimm_volatile_region_create(struct nvdimm_bus *nvdimm_bus,
  110. struct nd_region_desc *ndr_desc);
  111. u64 nd_fletcher64(void *addr, size_t len, bool le);
  112. #endif /* __LIBNVDIMM_H__ */