Loading...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 | /* * Copyright (C) Eicon Technology Corporation, 2000. * * Eicon File Revision : 1.12 * * This software may be used and distributed according to the terms * of the GNU General Public License, incorporated herein by reference. * */ #define __NO_VERSION__ #include <linux/module.h> #include <linux/kernel.h> #include <linux/poll.h> #include <linux/fs.h> #include <linux/slab.h> #undef N_DATA #include "adapter.h" #include "divas.h" #include "divalog.h" extern int DivasCardNext; void UxPause(long ms); int DivasGetMem(mem_block_t *); #define DIA_IOCTL_UNLOCK 12 void UnlockDivas(void); int do_ioctl(struct inode *pDivasInode, struct file *pDivasFile, unsigned int command, unsigned long arg) { byte *pUserCards, card_i; word wCardNum; switch (command) { case DIA_IOCTL_CONFIG: { dia_config_t DivaConfig; if (copy_from_user(&DivaConfig, (void *)arg, sizeof(dia_config_t))) return -EFAULT; DivasCardConfig(&DivaConfig); return 0; } case DIA_IOCTL_DETECT: pUserCards = (byte *) arg; if (!verify_area(VERIFY_WRITE, pUserCards, 20)) { if(__put_user(DivasCardNext, pUserCards++)) return -EFAULT; for (card_i=1; card_i < 20; card_i++) { if(__put_user((byte) DivasCards[card_i - 1].cfg.card_type, pUserCards++)) return -EFAULT; } } else return -EFAULT; return 0; case DIA_IOCTL_START: { dia_start_t DivaStart; if (copy_from_user(&DivaStart, (void *)arg, sizeof(dia_start_t))) return -EFAULT; return DivasCardStart(DivaStart.card_id); } case DIA_IOCTL_FLAVOUR: return 0; case DIA_IOCTL_LOAD: { dia_load_t DivaLoad; if(copy_from_user(&DivaLoad, (void *)arg, sizeof(dia_load_t))) return -EFAULT; if (!verify_area(VERIFY_READ, DivaLoad.code,DivaLoad.length)) { if (DivasCardLoad(&DivaLoad)) { printk(KERN_WARNING "Divas: Error loading DIVA Server adapter\n"); return -EINVAL; } return 0; } return -EFAULT; } case DIA_IOCTL_LOG: { dia_log_t DivaLog; if (copy_from_user(&DivaLog, (void *) arg, sizeof(dia_log_t))) return -EFAULT; DivasLog(&DivaLog); return 0; } case DIA_IOCTL_XLOG_REQ: if(get_user(wCardNum, (word *) arg)) return -EFAULT; DivasXlogReq(wCardNum); return 0; case DIA_IOCTL_GET_NUM: if(put_user(DivasCardNext, (int *)arg)) return -EFAULT; return 0; case DIA_IOCTL_GET_LIST: { dia_card_list_t cards; DPRINTF(("divas: DIA_IOCTL_GET_LIST")); DivasGetList(&cards); if(copy_to_user((void *)arg, &cards, sizeof(cards))) return -EFAULT; return 0; } case DIA_IOCTL_GET_MEM: { mem_block_t mem_block; if (copy_from_user(&mem_block, (void *)arg, sizeof(mem_block_t))) return -EFAULT; DivasGetMem(&mem_block); return 0; } case DIA_IOCTL_UNLOCK: UnlockDivas(); return 0; default: return -EINVAL; } return -EINVAL; } unsigned int do_poll(struct file *pFile, struct poll_table_struct *pPollTable) { word wMask = 0; if (!DivasLogFifoEmpty()) wMask |= POLLIN | POLLRDNORM; return wMask; } ssize_t do_read(struct file *pFile, char *pUserBuffer, size_t BufferSize, loff_t *pOffset) { klog_t *pClientLogBuffer = (klog_t *) pUserBuffer; klog_t *pHeadItem; if (BufferSize < sizeof(klog_t)) { printk(KERN_WARNING "Divas: Divalog buffer specifed a size that is too small (%d - %d required)\n", BufferSize, sizeof(klog_t)); return -EIO; } pHeadItem = (klog_t *) DivasLogFifoRead(); if (pHeadItem) { memcpy(pClientLogBuffer, pHeadItem, sizeof(klog_t)); kfree(pHeadItem); return sizeof(klog_t); } return 0; } static int private_usage_count; int do_open(struct inode *pInode, struct file *pFile) { MOD_INC_USE_COUNT; #ifdef MODULE private_usage_count++; #endif return 0; } int do_release(struct inode *pInode, struct file *pFile) { MOD_DEC_USE_COUNT; #ifdef MODULE private_usage_count--; #endif return 0; } void UnlockDivas(void) { while (private_usage_count > 0) { private_usage_count--; MOD_DEC_USE_COUNT; } } |