245e01f3ba4bbb16526d532936a1aa62ed7254b7
[tpg/acess2.git] / Modules / Interfaces / EDI / edi / edi_devices.h
1 #ifndef EDI_DEVICES_H
2
3 /* Copyright (c)  2006  Eli Gottlieb.
4  * Permission is granted to copy, distribute and/or modify this document
5  * under the terms of the GNU Free Documentation License, Version 1.2
6  * or any later version published by the Free Software Foundation;
7  * with no Invariant Sections, no Front-Cover Texts, and no Back-Cover
8  * Texts.  A copy of the license is included in the file entitled "COPYING". */
9
10 /* Edited by thePowersGang (John Hodge) June 2009
11  * - Add #ifdef EDI_MAIN_FILE
12  */
13
14 #define EDI_DEVICES_H
15
16 /*! \file edi_devices.h
17  * \brief Declaration and description of simple classes for implementation by EDI drivers to represent hardware devices.
18  *
19  * Data structures and algorithms this header represents:
20  *
21  *      DATA STRUCTURE AND ALGORITHM: BASIC DEVICES - There are two functions, select() for waiting on devices and ioctl() for
22  * controlling them, common to many POSIX devices.  Implementations of EDI-CHARACTER-DEVICE or EDI-BLOCK-DEVICE may implement either of
23  * these or both, and users of such objects much query for the methods to see if they're supported.  Obviously, runtime or driver
24  * developers don't *need* to support these.
25  *
26  *      DATA STRUCTURE AND ALGORITHM: CHARACTER DEVICES - The class EDI-CHARACTER-DEVICE provides a very basic interface to character
27  * devices, which read and write streams of characters.  As such, this class only provides read() and write().  The calls attempt a
28  * likeness to POSIX.
29  *
30  *      DATA STRUCTURE AND ALGORITHM: BLOCK DEVICES - The class EDI-BLOCK-DEVICE provides a very basic interface to block devices, which
31  * can read(), write() and seek() to blocks of a specific size in an array of blocks with a specific size.  Its declarations and
32  * semantics should behave like those of most POSIX operating systems.
33  *
34  * Note that EDI runtimes should not implement these classes.  Their declarations are provided for drivers to implement. */
35
36 #include "edi_objects.h"
37
38 /* Methods common to all EDI device classes specified in this header. */
39
40 /*!\brief EAGAIN returned by functions for block and character devices.
41  *
42  * Means that the amount of data the device has ready is less than count. */
43 #define EAGAIN -1
44 /*!\brief EBADOBJ returned by functions for block and character devices.
45  *
46  * Means that the object passed as the method's this point was not a valid object of the needed class. */
47 #define EBADOBJ -2
48 /*!\brief EINVAL returned by functions for block and character devices.
49  *
50  * Means that the method got passed invalid parameters. */
51 #ifdef EINVAL
52 # undef EINVAL
53 #endif
54 #define EINVAL -3
55
56 /*!\brief select() type to wait until device is writable. */
57 #define EDI_SELECT_WRITABLE 0
58 /*!\brief select() type to wait until device is readable. */
59 #define EDI_SELECT_READABLE 1
60
61 /*!\brief Argument to seek().  Sets the block offset (ie: the "current block" index) to the given whence value. */
62 #define EDI_SEEK_SET 0
63 /*!\brief Argument to seek().  Sets the block offset (ie: the "current block" index) to its current value + whence. */
64 #define EDI_SEEK_CURRENT 1
65
66 #ifdef EDI_MAIN_FILE
67 /*!\brief Arguments to EDI's basic select() function. */
68 edi_variable_declaration_t select_arguments[2] = {{"pointer void","device",1},
69                                                  {"unsigned int32_t","select_type",1}};
70 /*!\brief Declaration of EDI's basic select() function. 
71  *
72  * Contrary to the POSIX version, this select() puts its error codes in its return value. */
73 edi_function_declaration_t select_declaration = {"int32_t","edi_device_select",0,2,select_arguments,NULL};
74 #else
75 extern edi_function_declaration_t select_declaration;   // Declare for non main files
76 #endif
77
78 #ifdef EDI_MAIN_FILE
79 /*!\brief Arguments to EDI's basic ioctl() function. */
80 edi_variable_declaration_t ioctl_arguments[3] = {{"pointer void","device",1},{"int32_t","request",1},{"pointer void","argp",1}};
81 /*!\brief Declaration of EDI's basic ioctl() function. 
82  *
83  * Contrary to the POSIX version, this ioctl() puts its error codes in its return value. */
84 edi_function_declaration_t ioctl_declaration = {"int32_t","edi_device_ioctl",0,3,ioctl_arguments,NULL};
85 #else
86 extern edi_class_declaration_t ioctl_declaration;       // Declare for non main files
87 #endif
88
89 #ifdef EDI_MAIN_FILE
90 /*!\brief Declaration of the arguments EDI-CHARACTER-DEVICE's read() and write() methods. */
91 edi_variable_declaration_t chardev_read_write_arguments[3] = {{"pointer void","chardev",1},
92                                                               {"pointer void","buffer",1},
93                                                               {"unsigned int32_t","char_count",1}};
94 /*!\brief Declarations of the methods of EDI-CHARACTER-DEVICE, read() and write().
95  *
96  * The code pointers of these function declarations are all given as NULL.  Driver developers implementing EDI-CHARACTER-DEVICE should
97  * fill in these entries with pointers to their own functions. */
98 EDI_DEFVAR edi_function_declaration_t chardev_methods[2]= {{"int32_t","edi_chardev_read",0,3,chardev_read_write_arguments,NULL},
99                                                 {"int32_t","edi_chardev_write",0,3,chardev_read_write_arguments,NULL}};
100 /*!\brief Declaration of the EDI-CHARACTER-DEVICE class.
101  *
102  * Driver developers implementing this class should fill in their own values for constructor, destructor, and possibly even parent
103  * before passing the filled-in structure to the EDI runtime. */
104 EDI_DEFVAR edi_class_declaration_t chardev_class = {"EDI-CHARACTER-DEVICE",0,2,chardev_methods,NULL,NULL,NULL};
105 #else
106 extern edi_class_declaration_t chardev_class;   // Declare for non main files
107 #endif
108
109 #ifdef EDI_MAIN_FILE
110 /*!\brief Arguments to EDI-BLOCK-DEVICE's read() and write() methods. */
111 edi_variable_declaration_t blockdev_read_write_arguments[3] = {{"pointer void","blockdev",1},
112                                                                {"pointer void","buffer",1},
113                                                                {"unsigned int32_t","blocks",1}};
114 /*!\brief Arguments to EDI-BLOCK-DEVICE's seek() method. */
115 edi_variable_declaration_t blockdev_seek_arguments[3] = {{"pointer void","blockdev",1},
116                                                          {"int32_t","offset",1},
117                                                          {"int32_t","whence",1}};
118 /*!\brief Declaration of the methods of EDI-BLOCK-DEVICE, read(), write(), seek(), and get_block_size(). 
119  *
120  * The code pointers of these function declarations are all given as NULL.  Driver developers implementing EDI-BLOCK-DEVICE should fill
121  * these entries in with pointers to their own functions. */
122 edi_function_declaration_t blockdev_methods[4] = {{"int32_t","edi_blockdev_read",0,3,blockdev_read_write_arguments,NULL},
123                                                   {"int32_t","edi_blockdev_write",0,3,blockdev_read_write_arguments,NULL},
124                                                   {"int32_t","edi_blockdev_seek",0,3,blockdev_seek_arguments,NULL},
125                                                   {"unsigned int32_t","edi_blockdev_get_block_size",0,0,NULL,NULL}};
126 /*!\brief Declaration of the EDI-BLOCK-DEVICE class.
127  *
128  * Driver developers implementing this class should fill in their own values for constructor, destructor, and possibly even parent
129  * before passing the filled-in structure to the EDI runtime. */
130 edi_class_declaration_t blockdev_class = {"EDI-BLOCK-DEVICE",0,4,blockdev_methods,NULL,NULL,NULL};
131 #else
132 extern edi_class_declaration_t blockdev_class;  // Declare for non main files
133 #endif
134
135 #endif

UCC git Repository :: git.ucc.asn.au