1 #include <linux/proc_fs.h>
2 #include <linux/device.h>
3 #include <linux/platform_device.h>
4 #include <linux/miscdevice.h>
5 #include <linux/module.h>
6 #include <linux/ioctl.h>
7 #include <linux/uaccess.h>
8 #include <linux/ftrace_event.h>
9 #include "mach/mt_mon.h"
11 #define MODULE_NAME "monitor"
13 static struct mtk_monitor
*mtk_mon
;
15 #include <linux/proc_fs.h>
17 #define DEV_IOCTLID 0xD0
19 #define IOCTL_WRITE_PMU _IOW(DEV_IOCTLID, 1, struct pmu_cfg)
20 #define IOCTL_READ_PMU _IOR(DEV_IOCTLID, 2, struct pmu_cfg)
22 #ifdef CONFIG_CACHE_L2X0
23 #define IOCTL_WRITE_L2C _IOW(DEV_IOCTLID, 3, struct l2c_cfg)
24 #define IOCTL_READ_L2C _IOR(DEV_IOCTLID, 4, struct l2c_cfg)
27 #define IOCTL_WRITE_BM _IOR(DEV_IOCTLID, 5, int)
28 #define IOCTL_CTRL _IOW(DEV_IOCTLID, 6, int)
29 #define IOCTL_PRINTLOG _IOR(DEV_IOCTLID, 7, struct mt_mon_log)
32 #define MONITOR_START 1
33 #define MONITOR_STOP 2
36 mpu_dev_open(struct inode
*inode
, struct file
*filp
)
40 ret
= register_monitor(&mtk_mon
, MODE_MANUAL_USER
);
43 printk("MTK Monitor Register Fail\n");
53 mpu_dev_release(struct inode
*inode
, struct file
*filp
)
56 unregister_monitor(&mtk_mon
);
60 static long mpu_dev_ioctl(struct file
*filp
,
61 unsigned int cmd
, unsigned long arg
)
65 #ifdef CONFIG_CACHE_L2X0
70 printk("Don't Have PMU Resource\n");
76 ret
= copy_from_user((void * )&p_cfg
, (const void *)arg
, sizeof(struct pmu_cfg
));
78 printk("ERROR: wrong return value [IOCTL_WRITE_PMU]\n");
81 mtk_mon
->set_pmu(&p_cfg
);
85 mtk_mon
->get_pmu(&p_cfg
);
86 ret
= copy_to_user((void *)arg
, (const void * )&p_cfg
, sizeof(struct pmu_cfg
));
88 printk("ERROR: wrong return value [IOCTL_READ_PMU]\n");
92 #ifdef CONFIG_CACHE_L2X0
94 ret
= copy_from_user((void * )&l_cfg
, (const void *)arg
, sizeof(struct l2c_cfg
));
96 printk("ERROR: wrong return value [IOCTL_WRITE_L2C]\n");
99 mtk_mon
->set_l2c(&l_cfg
);
103 mtk_mon
->get_l2c(&l_cfg
);
104 ret
= copy_to_user((void *)arg
, (const void * )&l_cfg
, sizeof(struct l2c_cfg
));
106 printk("ERROR: wrong return value [IOCTL_READ_L2C]\n");
112 mtk_mon
->set_bm_rw(arg
);
124 printk("Error Number: Start(1), Stop(2)!!!\n");
130 index
= mtk_mon
->mon_log(NULL
);
131 ret
= copy_to_user((void *)arg
, (const void * )&mtk_mon
->log_buff
[index
], sizeof(struct mt_mon_log
));
133 printk("ERROR: wrong return value [IOCTL_PRINTLOG]\n");
146 static struct file_operations dev_fops
= {
147 .owner
= THIS_MODULE
,
148 .open
= mpu_dev_open
,
149 .release
= mpu_dev_release
,
150 .unlocked_ioctl
= mpu_dev_ioctl
,
153 static struct miscdevice mpu_miscdev
= {
154 .minor
= MISC_DYNAMIC_MINOR
,
155 .name
= "mtk_monitor",
160 static int __init
mon_user_init(void)
164 ret
= misc_register(&mpu_miscdev
);
167 printk("PMU MISC Register fail\n");
172 printk(KERN_INFO
"%s initialised\n", MODULE_NAME
);
176 static void __exit
mon_user_exit(void)
178 misc_deregister(&mpu_miscdev
);
179 printk(KERN_INFO
"%s removed\n", MODULE_NAME
);
182 module_init(mon_user_init
);
183 module_exit(mon_user_exit
);