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". */
10 /* Edited by thePowersGang (John Hodge) June 2009
11 * - Add #ifdef EDI_MAIN_FILE
16 /*! \file edi_devices.h
17 * \brief Declaration and description of simple classes for implementation by EDI drivers to represent hardware devices.
19 * Data structures and algorithms this header represents:
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.
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
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.
34 * Note that EDI runtimes should not implement these classes. Their declarations are provided for drivers to implement. */
36 #include "edi_objects.h"
38 /* Methods common to all EDI device classes specified in this header. */
40 /*!\brief EAGAIN returned by functions for block and character devices.
42 * Means that the amount of data the device has ready is less than count. */
44 /*!\brief EBADOBJ returned by functions for block and character devices.
46 * Means that the object passed as the method's this point was not a valid object of the needed class. */
48 /*!\brief EINVAL returned by functions for block and character devices.
50 * Means that the method got passed invalid parameters. */
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
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
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.
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};
75 extern edi_function_declaration_t select_declaration; // Declare for non main files
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.
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};
86 extern edi_class_declaration_t ioctl_declaration; // Declare for non main files
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().
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.
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};
106 extern edi_class_declaration_t chardev_class; // Declare for non main files
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().
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.
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};
132 extern edi_class_declaration_t blockdev_class; // Declare for non main files