2 * IOCTL calls for the CED1401 driver
3 * Copyright (C) 2010 Cambridge Electronic Design Ltd
4 * Author Greg P Smith (greg@ced.co.uk)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 #ifndef __CED_IOCTL_H__
17 #define __CED_IOCTL_H__
19 #include <linux/ioctl.h>
21 /* dma modes, only MODE_CHAR and MODE_LINEAR are used in this driver */
25 /****************************************************************************
27 *****************************************************************************/
29 typedef struct TransferDesc {
30 long long lpvBuff; /* address of transfer area (for 64 or 32 bit) */
31 unsigned int dwLength; /* length of the area */
32 unsigned short wAreaNum; /* number of transfer area to set up */
33 short eSize; /* element size - is tohost flag for circular */
36 typedef TRANSFERDESC *LPTRANSFERDESC;
38 typedef struct TransferEvent {
39 unsigned int dwStart; /* offset into the area */
40 unsigned int dwLength; /* length of the region */
41 unsigned short wAreaNum; /* the area number */
42 unsigned short wFlags; /* bit 0 set for toHost */
43 int iSetEvent; /* could be dummy in LINUX */
46 #define MAX_TRANSFER_SIZE 0x4000 /* Maximum data bytes per IRP */
47 #define MAX_AREA_LENGTH 0x100000 /* Maximum size of transfer area */
48 #define MAX_TRANSAREAS 8 /* definitions for dma set up */
50 typedef struct TGetSelfTest {
51 int code; /* self-test error code */
52 int x, y; /* additional information */
55 /* Debug block used for several commands. Not all fields are used for all commands. */
56 typedef struct TDbgBlock {
57 int iAddr; /* the address in the 1401 */
58 int iRepeats; /* number of repeats */
59 int iWidth; /* width in bytes 1, 2, 4 */
60 int iDefault; /* default value */
61 int iMask; /* mask to apply */
62 int iData; /* data for poke, result for peek */
65 /* Used to collect information about a circular block from the device driver */
66 typedef struct TCircBlock {
67 unsigned int nArea; /* the area to collect information from */
68 unsigned int dwOffset; /* offset into the area to the available block */
69 unsigned int dwSize; /* size of the area */
72 /* Used to clollect the 1401 status */
73 typedef struct TCSBlock {
79 * As seen by the user, an ioctl call looks like: int ioctl(int fd, unsigned
80 * long cmd, char* argp); We will then have all sorts of variants on this that
81 * can be used to pass stuff to our driver. We will generate macros for each
82 * type of call so as to provide some sort of type safety in the calling:
84 #define CED_MAGIC_IOC 0xce
86 /* NBNB: READ and WRITE are from the point of view of the device, not user. */
87 typedef struct ced_ioc_string {
92 #define IOCTL_CED_SENDSTRING(n) _IOC(_IOC_WRITE, CED_MAGIC_IOC, 2, n)
94 #define IOCTL_CED_RESET1401 _IO(CED_MAGIC_IOC, 3)
95 #define IOCTL_CED_GETCHAR _IO(CED_MAGIC_IOC, 4)
96 #define IOCTL_CED_SENDCHAR _IO(CED_MAGIC_IOC, 5)
97 #define IOCTL_CED_STAT1401 _IO(CED_MAGIC_IOC, 6)
98 #define IOCTL_CED_LINECOUNT _IO(CED_MAGIC_IOC, 7)
99 #define IOCTL_CED_GETSTRING(nMax) _IOC(_IOC_READ, CED_MAGIC_IOC, 8, nMax)
101 #define IOCTL_CED_SETTRANSFER _IOW(CED_MAGIC_IOC, 11, TRANSFERDESC)
102 #define IOCTL_CED_UNSETTRANSFER _IO(CED_MAGIC_IOC, 12)
103 #define IOCTL_CED_SETEVENT _IOW(CED_MAGIC_IOC, 13, TRANSFEREVENT)
104 #define IOCTL_CED_GETOUTBUFSPACE _IO(CED_MAGIC_IOC, 14)
105 #define IOCTL_CED_GETBASEADDRESS _IO(CED_MAGIC_IOC, 15)
106 #define IOCTL_CED_GETDRIVERREVISION _IO(CED_MAGIC_IOC, 16)
108 #define IOCTL_CED_GETTRANSFER _IOR(CED_MAGIC_IOC, 17, TGET_TX_BLOCK)
109 #define IOCTL_CED_KILLIO1401 _IO(CED_MAGIC_IOC, 18)
110 #define IOCTL_CED_BLKTRANSSTATE _IO(CED_MAGIC_IOC, 19)
112 #define IOCTL_CED_STATEOF1401 _IO(CED_MAGIC_IOC, 23)
113 #define IOCTL_CED_GRAB1401 _IO(CED_MAGIC_IOC, 25)
114 #define IOCTL_CED_FREE1401 _IO(CED_MAGIC_IOC, 26)
115 #define IOCTL_CED_STARTSELFTEST _IO(CED_MAGIC_IOC, 31)
116 #define IOCTL_CED_CHECKSELFTEST _IOR(CED_MAGIC_IOC, 32, TGET_SELFTEST)
117 #define IOCTL_CED_TYPEOF1401 _IO(CED_MAGIC_IOC, 33)
118 #define IOCTL_CED_TRANSFERFLAGS _IO(CED_MAGIC_IOC, 34)
120 #define IOCTL_CED_DBGPEEK _IOW(CED_MAGIC_IOC, 35, TDBGBLOCK)
121 #define IOCTL_CED_DBGPOKE _IOW(CED_MAGIC_IOC, 36, TDBGBLOCK)
122 #define IOCTL_CED_DBGRAMPDATA _IOW(CED_MAGIC_IOC, 37, TDBGBLOCK)
123 #define IOCTL_CED_DBGRAMPADDR _IOW(CED_MAGIC_IOC, 38, TDBGBLOCK)
124 #define IOCTL_CED_DBGGETDATA _IOR(CED_MAGIC_IOC, 39, TDBGBLOCK)
125 #define IOCTL_CED_DBGSTOPLOOP _IO(CED_MAGIC_IOC, 40)
126 #define IOCTL_CED_FULLRESET _IO(CED_MAGIC_IOC, 41)
127 #define IOCTL_CED_SETCIRCULAR _IOW(CED_MAGIC_IOC, 42, TRANSFERDESC)
128 #define IOCTL_CED_GETCIRCBLOCK _IOWR(CED_MAGIC_IOC, 43, TCIRCBLOCK)
129 #define IOCTL_CED_FREECIRCBLOCK _IOWR(CED_MAGIC_IOC, 44, TCIRCBLOCK)
130 #define IOCTL_CED_WAITEVENT _IO(CED_MAGIC_IOC, 45)
131 #define IOCTL_CED_TESTEVENT _IO(CED_MAGIC_IOC, 46)
135 * If nothing said about return value, it is a U14ERR_... error code
136 * (U14ERR_NOERROR for none)
138 inline int CED_SendString(int fh, const char *szText, int n)
140 return ioctl(fh, IOCTL_CED_SENDSTRING(n), szText);
143 inline int CED_Reset1401(int fh)
145 return ioctl(fh, IOCTL_CED_RESET1401);
148 /* Return the singe character or a -ve error code. */
149 inline int CED_GetChar(int fh)
151 return ioctl(fh, IOCTL_CED_GETCHAR);
154 /* Return character count in input buffer */
155 inline int CED_Stat1401(int fh)
157 return ioctl(fh, IOCTL_CED_STAT1401);
160 inline int CED_SendChar(int fh, char c)
162 return ioctl(fh, IOCTL_CED_SENDCHAR, c);
165 inline int CED_LineCount(int fh)
167 return ioctl(fh, IOCTL_CED_LINECOUNT);
171 * return the count of characters returned. If the string was terminated by CR
172 * or 0, then the 0 is part of the count. Otherwise, we will add a zero if
173 * there is room, but it is not included in the count. The return value is 0
174 * if there was nothing to read.
176 inline int CED_GetString(int fh, char *szText, int nMax)
178 return ioctl(fh, IOCTL_CED_GETSTRING(nMax), szText);
181 /* returns space in the output buffer. */
182 inline int CED_GetOutBufSpace(int fh)
184 return ioctl(fh, IOCTL_CED_GETOUTBUFSPACE);
187 /* This always returns -1 as not implemented. */
188 inline int CED_GetBaseAddress(int fh)
190 return ioctl(fh, IOCTL_CED_GETBASEADDRESS);
193 /* returns the major revision <<16 | minor revision. */
194 inline int CED_GetDriverRevision(int fh)
196 return ioctl(fh, IOCTL_CED_GETDRIVERREVISION);
199 inline int CED_SetTransfer(int fh, TRANSFERDESC *pTD)
201 return ioctl(fh, IOCTL_CED_SETTRANSFER, pTD);
204 inline int CED_UnsetTransfer(int fh, int nArea)
206 return ioctl(fh, IOCTL_CED_UNSETTRANSFER, nArea);
209 inline int CED_SetEvent(int fh, TRANSFEREVENT *pTE)
211 return ioctl(fh, IOCTL_CED_SETEVENT, pTE);
214 inline int CED_GetTransfer(int fh, TGET_TX_BLOCK *pTX)
216 return ioctl(fh, IOCTL_CED_GETTRANSFER, pTX);
219 inline int CED_KillIO1401(int fh)
221 return ioctl(fh, IOCTL_CED_KILLIO1401);
224 /* returns 0 if no active DMA, 1 if active */
225 inline int CED_BlkTransState(int fh)
227 return ioctl(fh, IOCTL_CED_BLKTRANSSTATE);
230 inline int CED_StateOf1401(int fh)
232 return ioctl(fh, IOCTL_CED_STATEOF1401);
235 inline int CED_Grab1401(int fh)
237 return ioctl(fh, IOCTL_CED_GRAB1401);
240 inline int CED_Free1401(int fh)
242 return ioctl(fh, IOCTL_CED_FREE1401);
245 inline int CED_StartSelfTest(int fh)
247 return ioctl(fh, IOCTL_CED_STARTSELFTEST);
250 inline int CED_CheckSelfTest(int fh, TGET_SELFTEST *pGST)
252 return ioctl(fh, IOCTL_CED_CHECKSELFTEST, pGST);
255 inline int CED_TypeOf1401(int fh)
257 return ioctl(fh, IOCTL_CED_TYPEOF1401);
260 inline int CED_TransferFlags(int fh)
262 return ioctl(fh, IOCTL_CED_TRANSFERFLAGS);
265 inline int CED_DbgPeek(int fh, TDBGBLOCK *pDB)
267 return ioctl(fh, IOCTL_CED_DBGPEEK, pDB);
270 inline int CED_DbgPoke(int fh, TDBGBLOCK *pDB)
272 return ioctl(fh, IOCTL_CED_DBGPOKE, pDB);
275 inline int CED_DbgRampData(int fh, TDBGBLOCK *pDB)
277 return ioctl(fh, IOCTL_CED_DBGRAMPDATA, pDB);
280 inline int CED_DbgRampAddr(int fh, TDBGBLOCK *pDB)
282 return ioctl(fh, IOCTL_CED_DBGRAMPADDR, pDB);
285 inline int CED_DbgGetData(int fh, TDBGBLOCK *pDB)
287 return ioctl(fh, IOCTL_CED_DBGGETDATA, pDB);
290 inline int CED_DbgStopLoop(int fh)
292 return ioctl(fh, IOCTL_CED_DBGSTOPLOOP);
295 inline int CED_FullReset(int fh)
297 return ioctl(fh, IOCTL_CED_FULLRESET);
300 inline int CED_SetCircular(int fh, TRANSFERDESC *pTD)
302 return ioctl(fh, IOCTL_CED_SETCIRCULAR, pTD);
305 inline int CED_GetCircBlock(int fh, TCIRCBLOCK *pCB)
307 return ioctl(fh, IOCTL_CED_GETCIRCBLOCK, pCB);
310 inline int CED_FreeCircBlock(int fh, TCIRCBLOCK *pCB)
312 return ioctl(fh, IOCTL_CED_FREECIRCBLOCK, pCB);
315 inline int CED_WaitEvent(int fh, int nArea, int msTimeOut)
317 return ioctl(fh, IOCTL_CED_WAITEVENT, (nArea & 0xff)|(msTimeOut << 8));
320 inline int CED_TestEvent(int fh, int nArea)
322 return ioctl(fh, IOCTL_CED_TESTEVENT, nArea);
327 #define IOCTL_CED_REGCALLBACK _IO(CED_MAGIC_IOC, 9) /* Not used */
328 #define IOCTL_CED_GETMONITORBUF _IO(CED_MAGIC_IOC, 10) /* Not used */
330 #define IOCTL_CED_BYTECOUNT _IO(CED_MAGIC_IOC, 20) /* Not used */
331 #define IOCTL_CED_ZEROBLOCKCOUNT _IO(CED_MAGIC_IOC, 21) /* Not used */
332 #define IOCTL_CED_STOPCIRCULAR _IO(CED_MAGIC_IOC, 22) /* Not used */
334 #define IOCTL_CED_REGISTERS1401 _IO(CED_MAGIC_IOC, 24) /* Not used */
335 #define IOCTL_CED_STEP1401 _IO(CED_MAGIC_IOC, 27) /* Not used */
336 #define IOCTL_CED_SET1401REGISTERS _IO(CED_MAGIC_IOC, 28) /* Not used */
337 #define IOCTL_CED_STEPTILL1401 _IO(CED_MAGIC_IOC, 29) /* Not used */
338 #define IOCTL_CED_SETORIN _IO(CED_MAGIC_IOC, 30) /* Not used */
342 /* __CED_IOCTL_H__ */