Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) /******************************************************************************
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2)  * Xen balloon driver - enables returning/claiming memory to/from Xen.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Copyright (c) 2003, B Dragovic
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (c) 2003-2004, M Williamson, K Fraser
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  * Copyright (c) 2005 Dan M. Smith, IBM Corporation
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  * This program is free software; you can redistribute it and/or
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * modify it under the terms of the GNU General Public License version 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  * as published by the Free Software Foundation; or, when distributed
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  * separately from the Linux kernel or incorporated into other
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  * software packages, subject to the following license:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  * Permission is hereby granted, free of charge, to any person obtaining a copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15)  * of this source file (the "Software"), to deal in the Software without
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16)  * restriction, including without limitation the rights to use, copy, modify,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17)  * merge, publish, distribute, sublicense, and/or sell copies of the Software,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18)  * and to permit persons to whom the Software is furnished to do so, subject to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19)  * the following conditions:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21)  * The above copyright notice and this permission notice shall be included in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22)  * all copies or substantial portions of the Software.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24)  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25)  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26)  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * IN THE SOFTWARE.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include <linux/mm_types.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #include <linux/capability.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #include <linux/memory_hotplug.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #include <xen/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #include <xen/interface/xen.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #include <xen/balloon.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #include <xen/xenbus.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include <xen/features.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #include <xen/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #include <xen/mem-reservation.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define PAGES2KB(_p) ((_p)<<(PAGE_SHIFT-10))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) #define BALLOON_CLASS_NAME "xen_memory"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #ifdef CONFIG_MEMORY_HOTPLUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) u64 xen_saved_max_mem_size = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static struct device balloon_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static int register_balloon(struct device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) /* React to a change in the target key */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) static void watch_target(struct xenbus_watch *watch,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			 const char *path, const char *token)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	unsigned long long new_target, static_max;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	static bool watch_fired;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	static long target_diff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) #ifdef CONFIG_MEMORY_HOTPLUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 	/* The balloon driver will take care of adding memory now. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 	if (xen_saved_max_mem_size)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		max_mem_size = xen_saved_max_mem_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	err = xenbus_scanf(XBT_NIL, "memory", "target", "%llu", &new_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	if (err != 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 		/* This is ok (for domain0 at least) - so just return */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	/* The given memory/target value is in KiB, so it needs converting to
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	 * pages. PAGE_SHIFT converts bytes to pages, hence PAGE_SHIFT - 10.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	new_target >>= PAGE_SHIFT - 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	if (!watch_fired) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		watch_fired = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		if ((xenbus_scanf(XBT_NIL, "memory", "static-max",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 				  "%llu", &static_max) == 1) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		    (xenbus_scanf(XBT_NIL, "memory", "memory_static_max",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 				  "%llu", &static_max) == 1))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			static_max >>= PAGE_SHIFT - 10;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			static_max = balloon_stats.current_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 		target_diff = (xen_pv_domain() || xen_initial_domain()) ? 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 				: static_max - balloon_stats.target_pages;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	balloon_set_new_target(new_target - target_diff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static struct xenbus_watch target_watch = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	.node = "memory/target",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	.callback = watch_target,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) static int balloon_init_watcher(struct notifier_block *notifier,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 				unsigned long event,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 				void *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	err = register_xenbus_watch(&target_watch);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 		pr_err("Failed to set balloon watcher\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	return NOTIFY_DONE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static struct notifier_block xenstore_notifier = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	.notifier_call = balloon_init_watcher,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) void xen_balloon_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	register_balloon(&balloon_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	register_xenstore_notifier(&xenstore_notifier);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) EXPORT_SYMBOL_GPL(xen_balloon_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) #define BALLOON_SHOW(name, format, args...)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	static ssize_t show_##name(struct device *dev,			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 				   struct device_attribute *attr,	\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				   char *buf)				\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	{								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		return sprintf(buf, format, ##args);			\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	}								\
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	static DEVICE_ATTR(name, S_IRUGO, show_##name, NULL)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) BALLOON_SHOW(current_kb, "%lu\n", PAGES2KB(balloon_stats.current_pages));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) BALLOON_SHOW(low_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_low));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) BALLOON_SHOW(high_kb, "%lu\n", PAGES2KB(balloon_stats.balloon_high));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static DEVICE_ULONG_ATTR(schedule_delay, 0444, balloon_stats.schedule_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static DEVICE_ULONG_ATTR(max_schedule_delay, 0644, balloon_stats.max_schedule_delay);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) static DEVICE_ULONG_ATTR(retry_count, 0444, balloon_stats.retry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) static DEVICE_ULONG_ATTR(max_retry_count, 0644, balloon_stats.max_retry_count);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static DEVICE_BOOL_ATTR(scrub_pages, 0644, xen_scrub_pages);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) static ssize_t show_target_kb(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	return sprintf(buf, "%lu\n", PAGES2KB(balloon_stats.target_pages));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static ssize_t store_target_kb(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 			       struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 			       const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 			       size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	char *endchar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	unsigned long long target_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	target_bytes = simple_strtoull(buf, &endchar, 0) * 1024;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	balloon_set_new_target(target_bytes >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static DEVICE_ATTR(target_kb, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		   show_target_kb, store_target_kb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) static ssize_t show_target(struct device *dev, struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 			      char *buf)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	return sprintf(buf, "%llu\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		       (unsigned long long)balloon_stats.target_pages
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 		       << PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) static ssize_t store_target(struct device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 			    struct device_attribute *attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 			    const char *buf,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			    size_t count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	char *endchar;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 	unsigned long long target_bytes;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	if (!capable(CAP_SYS_ADMIN))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		return -EPERM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 	target_bytes = memparse(buf, &endchar);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	balloon_set_new_target(target_bytes >> PAGE_SHIFT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	return count;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) static DEVICE_ATTR(target, S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		   show_target, store_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) static struct attribute *balloon_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	&dev_attr_target_kb.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	&dev_attr_target.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	&dev_attr_schedule_delay.attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	&dev_attr_max_schedule_delay.attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	&dev_attr_retry_count.attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 	&dev_attr_max_retry_count.attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	&dev_attr_scrub_pages.attr.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static const struct attribute_group balloon_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	.attrs = balloon_attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) static struct attribute *balloon_info_attrs[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	&dev_attr_current_kb.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	&dev_attr_low_kb.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	&dev_attr_high_kb.attr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static const struct attribute_group balloon_info_group = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	.name = "info",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	.attrs = balloon_info_attrs
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) static const struct attribute_group *balloon_groups[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	&balloon_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	&balloon_info_group,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	NULL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static struct bus_type balloon_subsys = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 	.name = BALLOON_CLASS_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	.dev_name = BALLOON_CLASS_NAME,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) static int register_balloon(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	error = subsys_system_register(&balloon_subsys, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	dev->id = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	dev->bus = &balloon_subsys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	dev->groups = balloon_groups;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	error = device_register(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (error) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		bus_unregister(&balloon_subsys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) }