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) // SPDX-License-Identifier: GPL-2.0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * Base infrastructure for Linux-z/VM Monitor Stream, Stage 1.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  * Exports appldata_register_ops() and appldata_unregister_ops() for the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * data gathering modules.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  * Copyright IBM Corp. 2003, 2009
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  * Author: Gerald Schaefer <gerald.schaefer@de.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #define KMSG_COMPONENT	"appldata"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/sched/stat.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/interrupt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/proc_fs.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/mm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include <linux/swap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #include <linux/pagemap.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #include <linux/sysctl.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) #include <linux/notifier.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) #include <linux/cpu.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #include <linux/workqueue.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #include <linux/suspend.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #include <linux/platform_device.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #include <asm/appldata.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #include <asm/vtimer.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #include <linux/uaccess.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #include <asm/io.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #include <asm/smp.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #include "appldata.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define APPLDATA_CPU_INTERVAL	10000		/* default (CPU) time for
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 						   sampling interval in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 						   milliseconds */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #define TOD_MICRO	0x01000			/* nr. of TOD clock units
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 						   for 1 microsecond */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static struct platform_device *appldata_pdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50)  * /proc entries (sysctl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static const char appldata_proc_name[APPLDATA_PROC_NAME_LENGTH] = "appldata";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static int appldata_timer_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 				  void *buffer, size_t *lenp, loff_t *ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) static int appldata_interval_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 				     void *buffer, size_t *lenp, loff_t *ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static struct ctl_table_header *appldata_sysctl_header;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) static struct ctl_table appldata_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 		.procname	= "timer",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		.mode		= S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		.proc_handler	= appldata_timer_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 		.procname	= "interval",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 		.mode		= S_IRUGO | S_IWUSR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		.proc_handler	= appldata_interval_handler,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	{ },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) static struct ctl_table appldata_dir_table[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 		.procname	= appldata_proc_name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		.maxlen		= 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 		.mode		= S_IRUGO | S_IXUGO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		.child		= appldata_table,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	{ },
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) static struct vtimer_list appldata_timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) static DEFINE_SPINLOCK(appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) static int appldata_interval = APPLDATA_CPU_INTERVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) static int appldata_timer_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) static int appldata_timer_suspended = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94)  * Work queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) static struct workqueue_struct *appldata_wq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) static void appldata_work_fn(struct work_struct *work);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) static DECLARE_WORK(appldata_work, appldata_work_fn);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  * Ops list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) static DEFINE_MUTEX(appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static LIST_HEAD(appldata_ops_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) /*************************** timer, work, DIAG *******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * appldata_timer_function()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  * schedule work and reschedule timer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void appldata_timer_function(unsigned long data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	queue_work(appldata_wq, (struct work_struct *) data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)  * appldata_work_fn()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)  * call data gathering function for each (active) module
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static void appldata_work_fn(struct work_struct *work)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 	struct list_head *lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct appldata_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	list_for_each(lh, &appldata_ops_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		ops = list_entry(lh, struct appldata_ops, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		if (ops->active == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 			ops->callback(ops->data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static struct appldata_product_id appldata_id = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	.prod_nr    = {0xD3, 0xC9, 0xD5, 0xE4,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 		       0xE7, 0xD2, 0xD9},	/* "LINUXKR" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	.prod_fn    = 0xD5D3,			/* "NL" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	.version_nr = 0xF2F6,			/* "26" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	.release_nr = 0xF0F1,			/* "01" */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148)  * appldata_diag()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)  * prepare parameter list, issue DIAG 0xDC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) int appldata_diag(char record_nr, u16 function, unsigned long buffer,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 			u16 length, char *mod_lvl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	struct appldata_parameter_list *parm_list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	struct appldata_product_id *id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 	parm_list = kmalloc(sizeof(*parm_list), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	id = kmemdup(&appldata_id, sizeof(appldata_id), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	if (parm_list && id) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		id->record_nr = record_nr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		id->mod_lvl = (mod_lvl[0]) << 8 | mod_lvl[1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 		rc = appldata_asm(parm_list, id, function,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 				  (void *) buffer, length);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	kfree(id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	kfree(parm_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) /************************ timer, work, DIAG <END> ****************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /****************************** /proc stuff **********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) #define APPLDATA_ADD_TIMER	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) #define APPLDATA_DEL_TIMER	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) #define APPLDATA_MOD_TIMER	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * __appldata_vtimer_setup()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)  * Add, delete or modify virtual timers on all online cpus.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)  * The caller needs to get the appldata_timer_lock spinlock.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) static void __appldata_vtimer_setup(int cmd)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	u64 timer_interval = (u64) appldata_interval * 1000 * TOD_MICRO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	switch (cmd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	case APPLDATA_ADD_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (appldata_timer_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 		appldata_timer.expires = timer_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		add_virt_timer_periodic(&appldata_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		appldata_timer_active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	case APPLDATA_DEL_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		del_virt_timer(&appldata_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		if (!appldata_timer_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 		appldata_timer_active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	case APPLDATA_MOD_TIMER:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		if (!appldata_timer_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 		mod_virt_timer_periodic(&appldata_timer, timer_interval);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) }
^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)  * appldata_timer_handler()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)  * Start/Stop timer, show status of timer (0 = not active, 1 = active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) appldata_timer_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			   void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	int timer_active = appldata_timer_active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct ctl_table ctl_entry = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		.procname	= ctl->procname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 		.data		= &timer_active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 		.extra1		= SYSCTL_ZERO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		.extra2		= SYSCTL_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 	if (rc < 0 || !write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	spin_lock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	if (timer_active)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 		__appldata_vtimer_setup(APPLDATA_ADD_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 		__appldata_vtimer_setup(APPLDATA_DEL_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	spin_unlock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)  * appldata_interval_handler()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  * Set (CPU) timer interval for collection of data (in milliseconds), show
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)  * current timer interval.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) appldata_interval_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 			   void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	int interval = appldata_interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct ctl_table ctl_entry = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 		.procname	= ctl->procname,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		.data		= &interval,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 		.extra1		= SYSCTL_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	rc = proc_dointvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	if (rc < 0 || !write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	spin_lock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 	appldata_interval = interval;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	__appldata_vtimer_setup(APPLDATA_MOD_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	spin_unlock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)  * appldata_generic_handler()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * Generic start/stop monitoring and DIAG, show status of
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * monitoring (0 = not in process, 1 = in process)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) appldata_generic_handler(struct ctl_table *ctl, int write,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 			   void *buffer, size_t *lenp, loff_t *ppos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	struct appldata_ops *ops = NULL, *tmp_ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	struct list_head *lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int rc, found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	struct ctl_table ctl_entry = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		.data		= &active,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		.maxlen		= sizeof(int),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		.extra1		= SYSCTL_ZERO,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		.extra2		= SYSCTL_ONE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	list_for_each(lh, &appldata_ops_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		tmp_ops = list_entry(lh, struct appldata_ops, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		if (&tmp_ops->ctl_table[2] == ctl) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	if (!found) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	ops = ctl->data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	if (!try_module_get(ops->owner)) {	// protect this function
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 		mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	active = ops->active;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 	rc = proc_douintvec_minmax(&ctl_entry, write, buffer, lenp, ppos);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	if (rc < 0 || !write) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 	if (active && (ops->active == 0)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		// protect work queue callback
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 		if (!try_module_get(ops->owner)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 			mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 			module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 			return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		ops->callback(ops->data);	// init record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 		rc = appldata_diag(ops->record_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 					APPLDATA_START_INTERVAL_REC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 					(unsigned long) ops->data, ops->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) 					ops->mod_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) 		if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 			pr_err("Starting the data collection for %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 			       "failed with rc=%d\n", ops->name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 			module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) 		} else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 			ops->active = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) 	} else if (!active && (ops->active == 1)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) 		ops->active = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 		rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 				(unsigned long) ops->data, ops->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 				ops->mod_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 		if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 			pr_err("Stopping the data collection for %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 			       "failed with rc=%d\n", ops->name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) 		module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	module_put(ops->owner);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) /*************************** /proc stuff <END> *******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) /************************* module-ops management *****************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360)  * appldata_register_ops()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362)  * update ops list, register /proc/sys entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) int appldata_register_ops(struct appldata_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) 	if (ops->size > APPLDATA_MAX_REC_SIZE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) 	ops->ctl_table = kcalloc(4, sizeof(struct ctl_table), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) 	if (!ops->ctl_table)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) 	list_add(&ops->list, &appldata_ops_list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) 	ops->ctl_table[0].procname = appldata_proc_name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) 	ops->ctl_table[0].maxlen   = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) 	ops->ctl_table[0].mode     = S_IRUGO | S_IXUGO;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) 	ops->ctl_table[0].child    = &ops->ctl_table[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) 	ops->ctl_table[2].procname = ops->name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) 	ops->ctl_table[2].mode     = S_IRUGO | S_IWUSR;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) 	ops->ctl_table[2].proc_handler = appldata_generic_handler;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) 	ops->ctl_table[2].data = ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) 	ops->sysctl_header = register_sysctl_table(ops->ctl_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) 	if (!ops->sysctl_header)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) 	list_del(&ops->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) 	kfree(ops->ctl_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) 	return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)  * appldata_unregister_ops()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402)  * update ops list, unregister /proc entries, stop DIAG if necessary
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) void appldata_unregister_ops(struct appldata_ops *ops)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) 	list_del(&ops->list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) 	unregister_sysctl_table(ops->sysctl_header);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) 	kfree(ops->ctl_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) /********************** module-ops management <END> **************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) /**************************** suspend / resume *******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) static int appldata_freeze(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) 	struct appldata_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) 	struct list_head *lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) 	spin_lock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) 	if (appldata_timer_active) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) 		__appldata_vtimer_setup(APPLDATA_DEL_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) 		appldata_timer_suspended = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) 	spin_unlock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) 	list_for_each(lh, &appldata_ops_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) 		ops = list_entry(lh, struct appldata_ops, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432) 		if (ops->active == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) 			rc = appldata_diag(ops->record_nr, APPLDATA_STOP_REC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434) 					(unsigned long) ops->data, ops->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) 					ops->mod_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) 			if (rc != 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) 				pr_err("Stopping the data collection for %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438) 				       "failed with rc=%d\n", ops->name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) static int appldata_restore(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) 	struct appldata_ops *ops;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) 	struct list_head *lh;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) 	spin_lock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) 	if (appldata_timer_suspended) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453) 		__appldata_vtimer_setup(APPLDATA_ADD_TIMER);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) 		appldata_timer_suspended = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 	spin_unlock(&appldata_timer_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) 	mutex_lock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) 	list_for_each(lh, &appldata_ops_list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) 		ops = list_entry(lh, struct appldata_ops, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) 		if (ops->active == 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) 			ops->callback(ops->data);	// init record
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) 			rc = appldata_diag(ops->record_nr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) 					APPLDATA_START_INTERVAL_REC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465) 					(unsigned long) ops->data, ops->size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) 					ops->mod_lvl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) 			if (rc != 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) 				pr_err("Starting the data collection for %s "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) 				       "failed with rc=%d\n", ops->name, rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) 	mutex_unlock(&appldata_ops_mutex);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) static int appldata_thaw(struct device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479) 	return appldata_restore(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) static const struct dev_pm_ops appldata_pm_ops = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) 	.freeze		= appldata_freeze,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) 	.thaw		= appldata_thaw,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) 	.restore	= appldata_restore,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) static struct platform_driver appldata_pdrv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) 	.driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490) 		.name	= "appldata",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) 		.pm	= &appldata_pm_ops,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) /************************* suspend / resume <END> ****************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) /******************************* init / exit *********************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500)  * appldata_init()
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502)  * init timer, register /proc entries
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) static int __init appldata_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) 	init_virt_timer(&appldata_timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) 	appldata_timer.function = appldata_timer_function;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) 	appldata_timer.data = (unsigned long) &appldata_work;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) 	rc = platform_driver_register(&appldata_pdrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) 	if (rc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) 		return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) 	appldata_pdev = platform_device_register_simple("appldata", -1, NULL,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) 							0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) 	if (IS_ERR(appldata_pdev)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) 		rc = PTR_ERR(appldata_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) 		goto out_driver;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) 	appldata_wq = alloc_ordered_workqueue("appldata", 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) 	if (!appldata_wq) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) 		rc = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) 		goto out_device;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) 	appldata_sysctl_header = register_sysctl_table(appldata_dir_table);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) out_device:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) 	platform_device_unregister(appldata_pdev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) out_driver:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) 	platform_driver_unregister(&appldata_pdrv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 536) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 537) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 538) __initcall(appldata_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 539) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 540) /**************************** init / exit <END> ******************************/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 541) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 542) EXPORT_SYMBOL_GPL(appldata_register_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 543) EXPORT_SYMBOL_GPL(appldata_unregister_ops);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 544) EXPORT_SYMBOL_GPL(appldata_diag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 545) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 546) #ifdef CONFIG_SWAP
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 547) EXPORT_SYMBOL_GPL(si_swapinfo);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 548) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 549) EXPORT_SYMBOL_GPL(nr_threads);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 550) EXPORT_SYMBOL_GPL(nr_running);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 551) EXPORT_SYMBOL_GPL(nr_iowait);