memory.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * include/linux/memory.h - generic memory definition
  4. *
  5. * This is mainly for topological representation. We define the
  6. * basic "struct memory_block" here, which can be embedded in per-arch
  7. * definitions or NUMA information.
  8. *
  9. * Basic handling of the devices is done in drivers/base/memory.c
  10. * and system devices are handled in drivers/base/sys.c.
  11. *
  12. * Memory block are exported via sysfs in the class/memory/devices/
  13. * directory.
  14. *
  15. */
  16. #ifndef _LINUX_MEMORY_H_
  17. #define _LINUX_MEMORY_H_
  18. #include <linux/node.h>
  19. #include <linux/compiler.h>
  20. #include <linux/mutex.h>
  21. #include <linux/notifier.h>
  22. #define MIN_MEMORY_BLOCK_SIZE (1UL << SECTION_SIZE_BITS)
  23. struct memory_block {
  24. unsigned long start_section_nr;
  25. unsigned long state; /* serialized by the dev->lock */
  26. int online_type; /* for passing data to online routine */
  27. int nid; /* NID for this memory block */
  28. struct device dev;
  29. };
  30. int arch_get_memory_phys_device(unsigned long start_pfn);
  31. unsigned long memory_block_size_bytes(void);
  32. int set_memory_block_size_order(unsigned int order);
  33. /* These states are exposed to userspace as text strings in sysfs */
  34. #define MEM_ONLINE (1<<0) /* exposed to userspace */
  35. #define MEM_GOING_OFFLINE (1<<1) /* exposed to userspace */
  36. #define MEM_OFFLINE (1<<2) /* exposed to userspace */
  37. #define MEM_GOING_ONLINE (1<<3)
  38. #define MEM_CANCEL_ONLINE (1<<4)
  39. #define MEM_CANCEL_OFFLINE (1<<5)
  40. struct memory_notify {
  41. unsigned long start_pfn;
  42. unsigned long nr_pages;
  43. int status_change_nid_normal;
  44. int status_change_nid_high;
  45. int status_change_nid;
  46. };
  47. struct notifier_block;
  48. struct mem_section;
  49. /*
  50. * Priorities for the hotplug memory callback routines (stored in decreasing
  51. * order in the callback chain)
  52. */
  53. #define SLAB_CALLBACK_PRI 1
  54. #define IPC_CALLBACK_PRI 10
  55. #ifndef CONFIG_MEMORY_HOTPLUG_SPARSE
  56. static inline void memory_dev_init(void)
  57. {
  58. return;
  59. }
  60. static inline int register_memory_notifier(struct notifier_block *nb)
  61. {
  62. return 0;
  63. }
  64. static inline void unregister_memory_notifier(struct notifier_block *nb)
  65. {
  66. }
  67. static inline int memory_notify(unsigned long val, void *v)
  68. {
  69. return 0;
  70. }
  71. #else
  72. extern int register_memory_notifier(struct notifier_block *nb);
  73. extern void unregister_memory_notifier(struct notifier_block *nb);
  74. int create_memory_block_devices(unsigned long start, unsigned long size);
  75. void remove_memory_block_devices(unsigned long start, unsigned long size);
  76. extern void memory_dev_init(void);
  77. extern int memory_notify(unsigned long val, void *v);
  78. extern struct memory_block *find_memory_block(struct mem_section *);
  79. typedef int (*walk_memory_blocks_func_t)(struct memory_block *, void *);
  80. extern int walk_memory_blocks(unsigned long start, unsigned long size,
  81. void *arg, walk_memory_blocks_func_t func);
  82. extern int for_each_memory_block(void *arg, walk_memory_blocks_func_t func);
  83. #define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<<PAGE_SHIFT)
  84. #endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
  85. #ifdef CONFIG_MEMORY_HOTPLUG
  86. #define hotplug_memory_notifier(fn, pri) ({ \
  87. static __meminitdata struct notifier_block fn##_mem_nb =\
  88. { .notifier_call = fn, .priority = pri };\
  89. register_memory_notifier(&fn##_mem_nb); \
  90. })
  91. #define register_hotmemory_notifier(nb) register_memory_notifier(nb)
  92. #define unregister_hotmemory_notifier(nb) unregister_memory_notifier(nb)
  93. #else
  94. #define hotplug_memory_notifier(fn, pri) ({ 0; })
  95. /* These aren't inline functions due to a GCC bug. */
  96. #define register_hotmemory_notifier(nb) ({ (void)(nb); 0; })
  97. #define unregister_hotmemory_notifier(nb) ({ (void)(nb); })
  98. #endif
  99. /*
  100. * Kernel text modification mutex, used for code patching. Users of this lock
  101. * can sleep.
  102. */
  103. extern struct mutex text_mutex;
  104. #endif /* _LINUX_MEMORY_H_ */