00001 #include "qres_config.h"
00002 #define QOS_DEBUG_LEVEL QSUP_MOD_DEBUG_LEVEL
00003 #include <linux/aquosa/qos_debug.h>
00004
00005 #include <linux/kernel.h>
00006 #include <linux/version.h>
00007 #include <linux/module.h>
00008 #include <linux/fs.h>
00009 #include <asm/uaccess.h>
00010 #include <linux/proc_fs.h>
00011
00012 #include "qsup_mod.h"
00013 #include "qres_gw_ks.h"
00014 #include "qsup_gw_ks.h"
00015 #include <linux/aquosa/qos_kernel_dep.h>
00016 #include <linux/aquosa/rres_interface.h>
00017
00018 #include <linux/aquosa/rres_proc_fs.h>
00019
00020 #define SUCCESS 0
00021 #define BUF_LEN 80
00022 #define DEBUG
00023
00028 static int qsup_Device_Open = 0;
00029
00030
00031
00032
00033 static int qsup_device_open(struct inode *inode, struct file *file)
00034 {
00035 qos_log_debug("qsup_device_open(%p)", file);
00036 qsup_Device_Open++;
00037 KERN_INCREMENT;
00038 return SUCCESS;
00039 }
00040
00046 static int qsup_device_release(struct inode *inode, struct file *file)
00047 {
00048 qos_log_debug("qsup_device_release(%p,%p)", inode, file);
00049 qsup_Device_Open--;
00050 KERN_DECREMENT;
00051 return SUCCESS;
00052 }
00053
00054
00055
00056
00057
00058 static ssize_t qsup_device_read(struct file *file,
00059 char __user * buffer,
00060
00061 size_t length,
00062 loff_t * offset)
00063 {
00064 qos_log_debug("qsup_device_read(%p,%p,%zu)", file, buffer, length);
00065
00066
00067
00068
00069 return 0;
00070 }
00071
00072
00073
00074
00075
00076 static ssize_t
00077 qsup_device_write(struct file *file,
00078 const char __user * buffer, size_t length, loff_t * offset)
00079 {
00080 qos_log_debug("qsup_device_write(%p,%s,%zu)", file, buffer, length);
00081
00082
00083
00084 return 0;
00085 }
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097 int qsup_device_ioctl(struct inode *inode,
00098 struct file *file,
00099 unsigned int ioctl_num,
00100 unsigned long ioctl_param)
00101 {
00102 qos_rv rv;
00103 qos_log_debug("Starting function");
00104
00105 rv = qsup_gw_ks(_IOC_NR(ioctl_num), (void *) ioctl_param,
00106 _IOC_SIZE(ioctl_num));
00107 qos_log_debug("Returning %d (%s)", qos_rv_int(rv), qos_strerror(rv));
00108 return qos_rv_int(rv);
00109 }
00110
00111 struct file_operations qsup_Fops = {
00112 .read = qsup_device_read,
00113 .write = qsup_device_write,
00114 .ioctl = qsup_device_ioctl,
00115 .open = qsup_device_open,
00116 .release = qsup_device_release,
00117 };
00118
00119 static qos_dev_info_t qsup_dev_info;
00120
00124 qos_rv qsup_dev_register(void) {
00125 qos_rv rv;
00126 if ((rv = qos_dev_register(&qsup_dev_info, QSUP_DEV_NAME, QSUP_MAJOR_NUM, &qsup_Fops)) != QOS_OK) {
00127 qos_log_err("Registration of device %s failed", QSUP_DEV_NAME);
00128 return rv;
00129 }
00130
00131 qos_log_info("Registered QSUP device with major device number %d.", MAJOR(qsup_dev_info.dev_num));
00132 qos_log_info("If you want to talk to the device driver,");
00133 qos_log_info("you'll have to create a device file. ");
00134 qos_log_info("We suggest you use:");
00135 qos_log_info("mknod %s c %d 0", QSUP_DEV_NAME, MAJOR(qsup_dev_info.dev_num));
00136
00137 return QOS_OK;
00138 }
00139
00145 int qsup_init_module(void) {
00146 qos_rv rv;
00147
00148
00149
00150 qos_log_debug("Initing QSUP");
00151 rv = qsup_init_ks();
00152 if (rv != QOS_OK) {
00153 qos_log_crit("qsup_init() failed: %s", qos_strerror(rv));
00154 return -1;
00155 }
00156
00157
00158
00159 qsup_dev_register();
00160
00161 return 0;
00162 }
00163
00167 qos_rv qsup_dev_unregister(void) {
00168 return qos_dev_unregister(&qsup_dev_info);
00169 }
00170
00176 void qsup_cleanup_module(void) {
00177 qos_rv rv;
00178
00179
00180
00181 rv = qsup_cleanup();
00182 if (rv != QOS_OK)
00183 qos_log_err("Error in qsup_cleanup_ks(): %s", qos_strerror(rv));
00184
00185
00186
00187 qsup_dev_unregister();
00188 }
00189
00191 static int rres_read_qsup(char *page, char **start, off_t off, int count,
00192 int *eof, void *data)
00193 {
00194 kal_irq_state flags;
00195 unsigned long long int curr_time;
00196 PROC_PRINT_VARS;
00197
00198 kal_spin_lock_irqsave(rres_get_spinlock(), &flags);
00199
00200 curr_time = sched_read_clock_us();
00201 PROC_PRINT("time (us): %lli\n", curr_time);
00202 qsup_dump();
00203 PROC_PRINT_DONE;
00204
00205 kal_spin_unlock_irqrestore(rres_get_spinlock(), &flags);
00206
00207 PROC_PRINT_END;
00208 }
00209
00210 extern struct proc_dir_entry *qres_proc_root;
00211
00212 int qsup_register_proc(void) {
00213 struct proc_dir_entry *proc_sched_ent;
00214 proc_sched_ent = create_proc_entry("qsup", S_IFREG|S_IRUGO|S_IWUSR, qres_proc_root);
00215 if (!proc_sched_ent) {
00216 printk("Unable to initialize /proc/" OC_PROC_ROOT "/qres/qsup\n");
00217 return -1;
00218 }
00219 proc_sched_ent->read_proc = rres_read_qsup;
00220 return 0;
00221 }
00222
00223 void qsup_proc_unregister(void) {
00224 remove_proc_entry("qsup", qres_proc_root);
00225 }