dax-private.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright(c) 2016 Intel Corporation. All rights reserved.
  4. */
  5. #ifndef __DAX_PRIVATE_H__
  6. #define __DAX_PRIVATE_H__
  7. #include <linux/device.h>
  8. #include <linux/cdev.h>
  9. #include <linux/idr.h>
  10. /* private routines between core files */
  11. struct dax_device;
  12. struct dax_device *inode_dax(struct inode *inode);
  13. struct inode *dax_inode(struct dax_device *dax_dev);
  14. int dax_bus_init(void);
  15. void dax_bus_exit(void);
  16. /**
  17. * struct dax_region - mapping infrastructure for dax devices
  18. * @id: kernel-wide unique region for a memory range
  19. * @target_node: effective numa node if this memory range is onlined
  20. * @kref: to pin while other agents have a need to do lookups
  21. * @dev: parent device backing this region
  22. * @align: allocation and mapping alignment for child dax devices
  23. * @ida: instance id allocator
  24. * @res: resource tree to track instance allocations
  25. * @seed: allow userspace to find the first unbound seed device
  26. * @youngest: allow userspace to find the most recently created device
  27. */
  28. struct dax_region {
  29. int id;
  30. int target_node;
  31. struct kref kref;
  32. struct device *dev;
  33. unsigned int align;
  34. struct ida ida;
  35. struct resource res;
  36. struct device *seed;
  37. struct device *youngest;
  38. };
  39. struct dax_mapping {
  40. struct device dev;
  41. int range_id;
  42. int id;
  43. };
  44. /**
  45. * struct dev_dax - instance data for a subdivision of a dax region, and
  46. * data while the device is activated in the driver.
  47. * @region - parent region
  48. * @dax_dev - core dax functionality
  49. * @target_node: effective numa node if dev_dax memory range is onlined
  50. * @dyn_id: is this a dynamic or statically created instance
  51. * @id: ida allocated id when the dax_region is not static
  52. * @ida: mapping id allocator
  53. * @dev - device core
  54. * @pgmap - pgmap for memmap setup / lifetime (driver owned)
  55. * @nr_range: size of @ranges
  56. * @ranges: resource-span + pgoff tuples for the instance
  57. */
  58. struct dev_dax {
  59. struct dax_region *region;
  60. struct dax_device *dax_dev;
  61. unsigned int align;
  62. int target_node;
  63. bool dyn_id;
  64. int id;
  65. struct ida ida;
  66. struct device dev;
  67. struct dev_pagemap *pgmap;
  68. int nr_range;
  69. struct dev_dax_range {
  70. unsigned long pgoff;
  71. struct range range;
  72. struct dax_mapping *mapping;
  73. } *ranges;
  74. };
  75. static inline struct dev_dax *to_dev_dax(struct device *dev)
  76. {
  77. return container_of(dev, struct dev_dax, dev);
  78. }
  79. static inline struct dax_mapping *to_dax_mapping(struct device *dev)
  80. {
  81. return container_of(dev, struct dax_mapping, dev);
  82. }
  83. phys_addr_t dax_pgoff_to_phys(struct dev_dax *dev_dax, pgoff_t pgoff, unsigned long size);
  84. #ifdef CONFIG_TRANSPARENT_HUGEPAGE
  85. static inline bool dax_align_valid(unsigned long align)
  86. {
  87. if (align == PUD_SIZE && IS_ENABLED(CONFIG_HAVE_ARCH_TRANSPARENT_HUGEPAGE_PUD))
  88. return true;
  89. if (align == PMD_SIZE && has_transparent_hugepage())
  90. return true;
  91. if (align == PAGE_SIZE)
  92. return true;
  93. return false;
  94. }
  95. #else
  96. static inline bool dax_align_valid(unsigned long align)
  97. {
  98. return align == PAGE_SIZE;
  99. }
  100. #endif /* CONFIG_TRANSPARENT_HUGEPAGE */
  101. #endif