blob: 935699b30b7c0c5266282fa6fe2b45968e828cb0 [file] [log] [blame]
Dave Hansen3947be12005-10-29 18:16:54 -07001/*
2 * include/linux/memory.h - generic memory definition
3 *
4 * This is mainly for topological representation. We define the
5 * basic "struct memory_block" here, which can be embedded in per-arch
6 * definitions or NUMA information.
7 *
8 * Basic handling of the devices is done in drivers/base/memory.c
9 * and system devices are handled in drivers/base/sys.c.
10 *
11 * Memory block are exported via sysfs in the class/memory/devices/
12 * directory.
13 *
14 */
15#ifndef _LINUX_MEMORY_H_
16#define _LINUX_MEMORY_H_
17
18#include <linux/sysdev.h>
19#include <linux/node.h>
20#include <linux/compiler.h>
Daniel Walkerda19cbc2008-02-04 23:35:47 -080021#include <linux/mutex.h>
Dave Hansen3947be12005-10-29 18:16:54 -070022
Benjamin Herrenschmidta63fdc52011-06-14 10:57:50 +100023#define MIN_MEMORY_BLOCK_SIZE (1 << SECTION_SIZE_BITS)
24
Dave Hansen3947be12005-10-29 18:16:54 -070025struct memory_block {
Nathan Fontenotd3360162011-01-20 10:44:29 -060026 unsigned long start_section_nr;
27 unsigned long end_section_nr;
Dave Hansen3947be12005-10-29 18:16:54 -070028 unsigned long state;
Nathan Fontenot07681212010-10-19 12:46:19 -050029 int section_count;
30
Dave Hansen3947be12005-10-29 18:16:54 -070031 /*
32 * This serializes all state change requests. It isn't
33 * held during creation because the control files are
34 * created long after the critical areas during
35 * initialization.
36 */
Daniel Walkerda19cbc2008-02-04 23:35:47 -080037 struct mutex state_mutex;
Dave Hansen3947be12005-10-29 18:16:54 -070038 int phys_device; /* to which fru does this belong? */
39 void *hw; /* optional pointer to fw/hw data */
40 int (*phys_callback)(struct memory_block *);
41 struct sys_device sysdev;
42};
43
Heiko Carstensbc32df02010-03-15 00:35:03 -040044int arch_get_memory_phys_device(unsigned long start_pfn);
45
Dave Hansen3947be12005-10-29 18:16:54 -070046/* These states are exposed to userspace as text strings in sysfs */
47#define MEM_ONLINE (1<<0) /* exposed to userspace */
48#define MEM_GOING_OFFLINE (1<<1) /* exposed to userspace */
49#define MEM_OFFLINE (1<<2) /* exposed to userspace */
Yasunori Goto7b78d332007-10-21 16:41:36 -070050#define MEM_GOING_ONLINE (1<<3)
51#define MEM_CANCEL_ONLINE (1<<4)
52#define MEM_CANCEL_OFFLINE (1<<5)
Dave Hansen3947be12005-10-29 18:16:54 -070053
Yasunori Goto7b78d332007-10-21 16:41:36 -070054struct memory_notify {
55 unsigned long start_pfn;
56 unsigned long nr_pages;
57 int status_change_nid;
58};
Dave Hansen3947be12005-10-29 18:16:54 -070059
Robert Jennings925cc712009-12-17 14:44:38 +000060/*
61 * During pageblock isolation, count the number of pages within the
62 * range [start_pfn, start_pfn + nr_pages) which are owned by code
63 * in the notifier chain.
64 */
65#define MEM_ISOLATE_COUNT (1<<0)
66
67struct memory_isolate_notify {
68 unsigned long start_pfn; /* Start of range to check */
69 unsigned int nr_pages; /* # pages in range to check */
70 unsigned int pages_found; /* # pages owned found by callbacks */
71};
72
Tim Schmielau8c65b4a2005-11-07 00:59:43 -080073struct notifier_block;
74struct mem_section;
75
Nadia Derbey0c40ba42008-04-29 01:00:41 -070076/*
77 * Priorities for the hotplug memory callback routines (stored in decreasing
78 * order in the callback chain)
79 */
80#define SLAB_CALLBACK_PRI 1
Nadia Derbeyb6b337a2008-04-29 01:00:42 -070081#define IPC_CALLBACK_PRI 10
Nadia Derbey0c40ba42008-04-29 01:00:41 -070082
Keith Mannthey53947022006-09-30 23:27:08 -070083#ifndef CONFIG_MEMORY_HOTPLUG_SPARSE
Dave Hansen3947be12005-10-29 18:16:54 -070084static inline int memory_dev_init(void)
85{
86 return 0;
87}
88static inline int register_memory_notifier(struct notifier_block *nb)
89{
90 return 0;
91}
92static inline void unregister_memory_notifier(struct notifier_block *nb)
93{
94}
Yasunori Goto7b78d332007-10-21 16:41:36 -070095static inline int memory_notify(unsigned long val, void *v)
96{
97 return 0;
98}
Robert Jennings925cc712009-12-17 14:44:38 +000099static inline int register_memory_isolate_notifier(struct notifier_block *nb)
100{
101 return 0;
102}
103static inline void unregister_memory_isolate_notifier(struct notifier_block *nb)
104{
105}
106static inline int memory_isolate_notify(unsigned long val, void *v)
107{
108 return 0;
109}
Dave Hansen3947be12005-10-29 18:16:54 -0700110#else
Yasunori Goto7b78d332007-10-21 16:41:36 -0700111extern int register_memory_notifier(struct notifier_block *nb);
112extern void unregister_memory_notifier(struct notifier_block *nb);
Robert Jennings925cc712009-12-17 14:44:38 +0000113extern int register_memory_isolate_notifier(struct notifier_block *nb);
114extern void unregister_memory_isolate_notifier(struct notifier_block *nb);
Gary Hadec04fc582009-01-06 14:39:14 -0800115extern int register_new_memory(int, struct mem_section *);
Dave Hansen3947be12005-10-29 18:16:54 -0700116extern int unregister_memory_section(struct mem_section *);
117extern int memory_dev_init(void);
Olaf Heringb792de32006-01-08 01:00:32 -0800118extern int remove_memory_block(unsigned long, struct mem_section *, int);
Yasunori Goto7b78d332007-10-21 16:41:36 -0700119extern int memory_notify(unsigned long val, void *v);
Robert Jennings925cc712009-12-17 14:44:38 +0000120extern int memory_isolate_notify(unsigned long val, void *v);
Robin Holt98383032010-09-29 14:00:55 -0500121extern struct memory_block *find_memory_block_hinted(struct mem_section *,
122 struct memory_block *);
Gary Hadec04fc582009-01-06 14:39:14 -0800123extern struct memory_block *find_memory_block(struct mem_section *);
Dave Hansen3947be12005-10-29 18:16:54 -0700124#define CONFIG_MEM_BLOCK_SIZE (PAGES_PER_SECTION<<PAGE_SHIFT)
Gary Hadec04fc582009-01-06 14:39:14 -0800125enum mem_add_context { BOOT, HOTPLUG };
Keith Mannthey53947022006-09-30 23:27:08 -0700126#endif /* CONFIG_MEMORY_HOTPLUG_SPARSE */
Dave Hansen3947be12005-10-29 18:16:54 -0700127
Yasunori Gotob9049e22007-10-21 16:41:37 -0700128#ifdef CONFIG_MEMORY_HOTPLUG
Dave Hansen3947be12005-10-29 18:16:54 -0700129#define hotplug_memory_notifier(fn, pri) { \
Al Viro02d0e672008-11-22 17:38:34 +0000130 static __meminitdata struct notifier_block fn##_mem_nb =\
Dave Hansen3947be12005-10-29 18:16:54 -0700131 { .notifier_call = fn, .priority = pri }; \
132 register_memory_notifier(&fn##_mem_nb); \
133}
Yasunori Gotob9049e22007-10-21 16:41:37 -0700134#else
135#define hotplug_memory_notifier(fn, pri) do { } while (0)
136#endif
Dave Hansen3947be12005-10-29 18:16:54 -0700137
Kevin Hilman06c421e2009-04-02 16:56:56 -0700138/*
139 * 'struct memory_accessor' is a generic interface to provide
140 * in-kernel access to persistent memory such as i2c or SPI EEPROMs
141 */
142struct memory_accessor {
143 ssize_t (*read)(struct memory_accessor *, char *buf, off_t offset,
144 size_t count);
145 ssize_t (*write)(struct memory_accessor *, const char *buf,
146 off_t offset, size_t count);
147};
148
Linus Torvalds714f83d2009-04-05 11:04:19 -0700149/*
Mathieu Desnoyers0e39ac42009-03-06 10:35:52 -0500150 * Kernel text modification mutex, used for code patching. Users of this lock
151 * can sleep.
152 */
153extern struct mutex text_mutex;
154
Dave Hansen3947be12005-10-29 18:16:54 -0700155#endif /* _LINUX_MEMORY_H_ */