1419b0af8Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 2419b0af8Sopenharmony_ci/* 3419b0af8Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd. 4419b0af8Sopenharmony_ci */ 5419b0af8Sopenharmony_ci#include <linux/fs.h> 6419b0af8Sopenharmony_ci#include <linux/miscdevice.h> 7419b0af8Sopenharmony_ci#include <linux/module.h> 8419b0af8Sopenharmony_ci#include <linux/uaccess.h> 9419b0af8Sopenharmony_ci 10419b0af8Sopenharmony_ci#ifdef CONFIG_COMPAT 11419b0af8Sopenharmony_ci#include <linux/compat.h> 12419b0af8Sopenharmony_ci#endif // CONFIG_COMPAT 13419b0af8Sopenharmony_ci 14419b0af8Sopenharmony_ci#include "ucollection_process_cpu.h" 15419b0af8Sopenharmony_ci 16419b0af8Sopenharmony_cistatic long (*unified_collection_ioctl_cb[])(unsigned int cmd, void __user *argp) = { 17419b0af8Sopenharmony_ci unified_collection_collect_process_cpu /* IOCTRL_COLLECT_CPU */ 18419b0af8Sopenharmony_ci}; 19419b0af8Sopenharmony_ci 20419b0af8Sopenharmony_cistatic long unified_collection_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 21419b0af8Sopenharmony_ci{ 22419b0af8Sopenharmony_ci void __user *argp = u64_to_user_ptr(arg); 23419b0af8Sopenharmony_ci const char *comm = NULL; 24419b0af8Sopenharmony_ci 25419b0af8Sopenharmony_ci if ((_IOC_TYPE(cmd) >= ARRAY_SIZE(unified_collection_ioctl_cb)) || 26419b0af8Sopenharmony_ci (unified_collection_ioctl_cb[_IOC_TYPE(cmd)] == NULL)) { 27419b0af8Sopenharmony_ci pr_err("invalid ioctrl cmd %u, _IOC_TYPE(cmd)=%d", cmd, _IOC_TYPE(cmd)); 28419b0af8Sopenharmony_ci return -EINVAL; 29419b0af8Sopenharmony_ci } 30419b0af8Sopenharmony_ci 31419b0af8Sopenharmony_ci return unified_collection_ioctl_cb[_IOC_TYPE(cmd)](cmd, argp); 32419b0af8Sopenharmony_ci} 33419b0af8Sopenharmony_ci 34419b0af8Sopenharmony_ci#ifdef CONFIG_COMPAT 35419b0af8Sopenharmony_cistatic long unified_collection_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) 36419b0af8Sopenharmony_ci{ 37419b0af8Sopenharmony_ci return unified_collection_ioctl(filp, cmd, (unsigned long) compat_ptr(arg)); 38419b0af8Sopenharmony_ci} 39419b0af8Sopenharmony_ci#endif // CONFIG_COMPAT 40419b0af8Sopenharmony_ci 41419b0af8Sopenharmony_cistatic int unified_collection_open(struct inode *inode, struct file *filp) 42419b0af8Sopenharmony_ci{ 43419b0af8Sopenharmony_ci return 0; 44419b0af8Sopenharmony_ci} 45419b0af8Sopenharmony_ci 46419b0af8Sopenharmony_cistatic int unified_collection_release(struct inode *inode, struct file *filp) 47419b0af8Sopenharmony_ci{ 48419b0af8Sopenharmony_ci return 0; 49419b0af8Sopenharmony_ci} 50419b0af8Sopenharmony_ci 51419b0af8Sopenharmony_cistatic const struct file_operations unified_collection_device_fops = { 52419b0af8Sopenharmony_ci .owner = THIS_MODULE, 53419b0af8Sopenharmony_ci .unlocked_ioctl = unified_collection_ioctl, 54419b0af8Sopenharmony_ci#ifdef CONFIG_COMPAT 55419b0af8Sopenharmony_ci .compat_ioctl = unified_collection_compat_ioctl, 56419b0af8Sopenharmony_ci#endif // CONFIG_COMPAT 57419b0af8Sopenharmony_ci .open = unified_collection_open, 58419b0af8Sopenharmony_ci .release = unified_collection_release, 59419b0af8Sopenharmony_ci}; 60419b0af8Sopenharmony_ci 61419b0af8Sopenharmony_cistatic struct miscdevice unified_collection_device = { 62419b0af8Sopenharmony_ci .name = "ucollection", 63419b0af8Sopenharmony_ci .fops = &unified_collection_device_fops, 64419b0af8Sopenharmony_ci .minor = MISC_DYNAMIC_MINOR, 65419b0af8Sopenharmony_ci}; 66419b0af8Sopenharmony_ci 67419b0af8Sopenharmony_cistatic int __init unified_collection_init(void) 68419b0af8Sopenharmony_ci{ 69419b0af8Sopenharmony_ci int ret = misc_register(&unified_collection_device); 70419b0af8Sopenharmony_ci if (ret) { 71419b0af8Sopenharmony_ci pr_err("failed to register unified collection device"); 72419b0af8Sopenharmony_ci return ret; 73419b0af8Sopenharmony_ci } 74419b0af8Sopenharmony_ci 75419b0af8Sopenharmony_ci pr_info("register unified collection device successful"); 76419b0af8Sopenharmony_ci return 0; 77419b0af8Sopenharmony_ci} 78419b0af8Sopenharmony_ci 79419b0af8Sopenharmony_cistatic void __exit unified_collection_exit(void) 80419b0af8Sopenharmony_ci{ 81419b0af8Sopenharmony_ci pr_info("deregister unified collection device successful"); 82419b0af8Sopenharmony_ci misc_deregister(&unified_collection_device); 83419b0af8Sopenharmony_ci} 84419b0af8Sopenharmony_ci 85419b0af8Sopenharmony_cimodule_init(unified_collection_init); 86419b0af8Sopenharmony_cimodule_exit(unified_collection_exit); 87419b0af8Sopenharmony_ci 88419b0af8Sopenharmony_ciMODULE_AUTHOR("OHOS"); 89419b0af8Sopenharmony_ciMODULE_DESCRIPTION("Unified Collection Driver"); 90419b0af8Sopenharmony_ciMODULE_LICENSE("GPL");