2 * Copyright (C) Eicon Technology Corporation, 2000.
4 * Eicon File Revision : 1.12
6 * This software may be used and distributed according to the terms
7 * of the GNU General Public License, incorporated herein by reference.
11 #define __NO_VERSION__
12 #include <linux/module.h>
14 #include <linux/kernel.h>
15 #include <linux/poll.h>
17 #include <linux/slab.h>
25 extern int DivasCardNext;
26 void UxPause(long ms);
27 int DivasGetMem(mem_block_t *);
29 #define DIA_IOCTL_UNLOCK 12
30 void UnlockDivas(void);
32 int do_ioctl(struct inode *pDivasInode, struct file *pDivasFile,
33 unsigned int command, unsigned long arg)
35 byte *pUserCards, card_i;
40 case DIA_IOCTL_CONFIG:
42 dia_config_t DivaConfig;
43 if (copy_from_user(&DivaConfig, (void *)arg, sizeof(dia_config_t)))
45 DivasCardConfig(&DivaConfig);
49 case DIA_IOCTL_DETECT:
50 pUserCards = (byte *) arg;
52 if (!verify_area(VERIFY_WRITE, pUserCards, 20))
54 if(__put_user(DivasCardNext, pUserCards++))
57 for (card_i=1; card_i < 20; card_i++)
59 if(__put_user((byte) DivasCards[card_i - 1].cfg.card_type, pUserCards++))
69 dia_start_t DivaStart;
70 if (copy_from_user(&DivaStart, (void *)arg, sizeof(dia_start_t)))
72 return DivasCardStart(DivaStart.card_id);
75 case DIA_IOCTL_FLAVOUR:
81 if(copy_from_user(&DivaLoad, (void *)arg, sizeof(dia_load_t)))
83 if (!verify_area(VERIFY_READ, DivaLoad.code,DivaLoad.length))
85 if (DivasCardLoad(&DivaLoad))
87 printk(KERN_WARNING "Divas: Error loading DIVA Server adapter\n");
97 if (copy_from_user(&DivaLog, (void *) arg, sizeof(dia_log_t)))
103 case DIA_IOCTL_XLOG_REQ:
104 if(get_user(wCardNum, (word *) arg))
106 DivasXlogReq(wCardNum);
109 case DIA_IOCTL_GET_NUM:
110 if(put_user(DivasCardNext, (int *)arg))
114 case DIA_IOCTL_GET_LIST:
116 dia_card_list_t cards;
117 DPRINTF(("divas: DIA_IOCTL_GET_LIST"));
118 DivasGetList(&cards);
119 if(copy_to_user((void *)arg, &cards, sizeof(cards)))
123 case DIA_IOCTL_GET_MEM:
125 mem_block_t mem_block;
126 if (copy_from_user(&mem_block, (void *)arg, sizeof(mem_block_t)))
128 DivasGetMem(&mem_block);
132 case DIA_IOCTL_UNLOCK:
142 unsigned int do_poll(struct file *pFile, struct poll_table_struct *pPollTable)
146 if (!DivasLogFifoEmpty())
147 wMask |= POLLIN | POLLRDNORM;
151 ssize_t do_read(struct file *pFile, char *pUserBuffer, size_t BufferSize, loff_t *pOffset)
153 klog_t *pClientLogBuffer = (klog_t *) pUserBuffer;
156 if (BufferSize < sizeof(klog_t))
159 pHeadItem = (klog_t *) DivasLogFifoRead();
163 if(copy_to_user(pClientLogBuffer, pHeadItem, sizeof(klog_t)))
169 return sizeof(klog_t);
174 static int private_usage_count;
176 int do_open(struct inode *pInode, struct file *pFile)
180 private_usage_count++;
185 int do_release(struct inode *pInode, struct file *pFile)
189 private_usage_count--;
194 void UnlockDivas(void)
196 while (private_usage_count > 0)
198 private_usage_count--;