00001 #include "qos_kernel_dep.h"
00002
00003 #include "qos_debug.h"
00004 #include <linux/kernel.h>
00005 #include <linux/version.h>
00006 #include <linux/module.h>
00007
00008 #if LINUX_VERSION_CODE<KERNEL_VERSION(2,6,0)
00009
00010
00011 int qos_dev_register(
00012 qos_dev_info_t *dev_info,
00013 char *dev_name, int def_major,
00014 struct file_operations *Fops)
00015
00016
00017
00018
00019 {
00020 int ret_val;
00021
00022 dev_info->dev_name = dev_name;
00023
00024 ret_val = register_chrdev(def_major, dev_name, Fops);
00025
00026
00027
00028
00029 if (ret_val < 0) {
00030 printk("Sorry, registering the character device failed with %d\n", ret_val);
00031 return QOS_E_GENERIC;
00032 }
00033
00034 dev_info->dev_num = MKDEV(def_major, 0);
00035 return QOS_OK;
00036 }
00037
00038 int qos_dev_unregister(qos_dev_info_t *dev_info) {
00039 int ret;
00040
00041 ret = unregister_chrdev(MAJOR(dev_info->dev_num), dev_info->dev_name);
00042 if (ret < 0) {
00043 qos_log_crit("Error in module_unregister_chrdev: %d\n", ret);
00044 return QOS_E_GENERIC;
00045 }
00046 return QOS_OK;
00047 }
00048
00049 #else
00050
00051
00052
00053 qos_rv qos_dev_register(
00054 qos_dev_info_t *dev_info,
00055 char *dev_name, int def_major,
00056 struct file_operations *Fops)
00057 {
00058 int ret_val;
00059
00060 dev_info->dev_name = dev_name;
00061
00062 ret_val = alloc_chrdev_region(&dev_info->dev_num, 0, 1, dev_name);
00063 if (ret_val < 0) {
00064 printk("Allocation of device major failed with %d\n", ret_val);
00065 return QOS_E_GENERIC;
00066 }
00067
00068 cdev_init(&dev_info->cdev, Fops);
00069 kobject_set_name(&dev_info->cdev.kobj, "%s", dev_name);
00070 dev_info->cdev.owner = THIS_MODULE;
00071
00072 ret_val = cdev_add(&dev_info->cdev, dev_info->dev_num, 1);
00073 if (ret_val < 0) {
00074 printk("Registration of cdev struct failed with %d\n", ret_val);
00075 return QOS_E_GENERIC;
00076 }
00077
00078 return QOS_OK;
00079 }
00080
00081 qos_rv qos_dev_unregister(qos_dev_info_t *dev_info) {
00082 cdev_del(&dev_info->cdev);
00083 unregister_chrdev_region(dev_info->dev_num, 1);
00084 return QOS_OK;
00085 }
00086
00087 #endif
00088
00089 EXPORT_SYMBOL_GPL(qos_dev_register);
00090 EXPORT_SYMBOL_GPL(qos_dev_unregister);