[b06e68ef] | 1 | /* |
---|
| 2 | * General purpose communication channel for RTEMS to allow UNIX/POSIX |
---|
| 3 | * system call behavior on top of RTEMS IO devices. |
---|
| 4 | * |
---|
| 5 | * TODO |
---|
| 6 | * stat(2) |
---|
| 7 | * unlink(2) |
---|
| 8 | * rename(2) |
---|
| 9 | * |
---|
| 10 | * $Id$ |
---|
| 11 | */ |
---|
| 12 | |
---|
| 13 | #ifndef _RTEMS_LIBIO_H |
---|
| 14 | #define _RTEMS_LIBIO_H |
---|
| 15 | |
---|
[dcec5a4] | 16 | #include <sys/stat.h> |
---|
| 17 | |
---|
[b06e68ef] | 18 | typedef unsigned32 rtems_libio_offset_t; |
---|
| 19 | |
---|
| 20 | /* |
---|
| 21 | * An open file data structure, indexed by 'fd' |
---|
| 22 | * TODO: |
---|
| 23 | * should really have a separate per/file data structure that this |
---|
| 24 | * points to (eg: size, offset, driver, pathname should be in that) |
---|
| 25 | */ |
---|
| 26 | |
---|
| 27 | typedef struct { |
---|
| 28 | rtems_driver_name_t *driver; |
---|
| 29 | rtems_libio_offset_t size; /* size of file */ |
---|
| 30 | rtems_libio_offset_t offset; /* current offset into the file */ |
---|
| 31 | unsigned32 flags; |
---|
| 32 | char *pathname; /* opened pathname */ |
---|
| 33 | Objects_Id sem; |
---|
| 34 | unsigned32 data0; /* private to "driver" */ |
---|
[ae35953d] | 35 | void *data1; /* ... */ |
---|
[b06e68ef] | 36 | } rtems_libio_t; |
---|
| 37 | |
---|
| 38 | |
---|
| 39 | /* |
---|
| 40 | * param block for read/write |
---|
| 41 | * Note: it must include 'offset' instead of using iop's offset since |
---|
| 42 | * we can have multiple outstanding i/o's on a device. |
---|
| 43 | */ |
---|
| 44 | |
---|
| 45 | typedef struct { |
---|
| 46 | rtems_libio_t *iop; |
---|
| 47 | rtems_libio_offset_t offset; |
---|
| 48 | unsigned8 *buffer; |
---|
| 49 | unsigned32 count; |
---|
| 50 | unsigned32 flags; |
---|
| 51 | unsigned32 bytes_moved; |
---|
| 52 | } rtems_libio_rw_args_t; |
---|
| 53 | |
---|
| 54 | /* |
---|
| 55 | * param block for open/close |
---|
| 56 | */ |
---|
| 57 | |
---|
| 58 | typedef struct { |
---|
| 59 | rtems_libio_t *iop; |
---|
| 60 | unsigned32 flags; |
---|
| 61 | unsigned32 mode; |
---|
| 62 | } rtems_libio_open_close_args_t; |
---|
| 63 | |
---|
| 64 | /* |
---|
| 65 | * param block for ioctl |
---|
| 66 | */ |
---|
| 67 | |
---|
| 68 | typedef struct { |
---|
| 69 | rtems_libio_t *iop; |
---|
| 70 | unsigned32 command; |
---|
| 71 | void *buffer; |
---|
| 72 | unsigned32 ioctl_return; |
---|
| 73 | } rtems_libio_ioctl_args_t; |
---|
| 74 | |
---|
| 75 | |
---|
| 76 | /* |
---|
| 77 | * Values for 'flag' |
---|
| 78 | */ |
---|
| 79 | |
---|
| 80 | #define LIBIO_FLAGS_NO_DELAY 0x0001 /* return immediately if no data */ |
---|
| 81 | #define LIBIO_FLAGS_READ 0x0002 /* reading */ |
---|
| 82 | #define LIBIO_FLAGS_WRITE 0x0004 /* writing */ |
---|
| 83 | #define LIBIO_FLAGS_LINE_BUFFERED 0x0008 /* line buffered io (^h, ^u, etc) */ |
---|
| 84 | #define LIBIO_FLAGS_OPEN 0x0100 /* device is open */ |
---|
| 85 | #define LIBIO_FLAGS_APPEND 0x0200 /* all writes append */ |
---|
| 86 | #define LIBIO_FLAGS_CREATE 0x0400 /* create file */ |
---|
| 87 | |
---|
| 88 | #define LIBIO_FLAGS_READ_WRITE (LIBIO_FLAGS_READ | LIBIO_FLAGS_WRITE) |
---|
| 89 | |
---|
| 90 | void rtems_libio_init(void); |
---|
| 91 | |
---|
[dcec5a4] | 92 | int __rtems_open(const char *pathname, unsigned32 flag, unsigned32 mode); |
---|
| 93 | int __rtems_close(int fd); |
---|
| 94 | int __rtems_read(int fd, void *buffer, unsigned32 count); |
---|
| 95 | int __rtems_write(int fd, const void *buffer, unsigned32 count); |
---|
| 96 | int __rtems_ioctl(int fd, unsigned32 command, void *buffer); |
---|
| 97 | int __rtems_lseek(int fd, rtems_libio_offset_t offset, int whence); |
---|
| 98 | int __rtems_fstat(int _fd, struct stat* _sbuf); |
---|
[b06e68ef] | 99 | |
---|
[e2d79559] | 100 | /* |
---|
| 101 | * External I/O handlers |
---|
| 102 | */ |
---|
| 103 | typedef struct { |
---|
| 104 | int (*open)(const char *pathname, unsigned32 flag, unsigned32 mode); |
---|
| 105 | int (*close)(int fd); |
---|
[a307f79] | 106 | int (*read)(int fd, void *buffer, unsigned32 count); |
---|
[e2d79559] | 107 | int (*write)(int fd, const void *buffer, unsigned32 count); |
---|
| 108 | int (*ioctl)(int fd, unsigned32 command, void *buffer); |
---|
| 109 | int (*lseek)(int fd, rtems_libio_offset_t offset, int whence); |
---|
| 110 | } rtems_libio_handler_t; |
---|
| 111 | |
---|
| 112 | void rtems_register_libio_handler(int handler_flag, |
---|
| 113 | const rtems_libio_handler_t *handler); |
---|
| 114 | |
---|
| 115 | #define RTEMS_FILE_DESCRIPTOR_TYPE_FILE 0x0000 |
---|
| 116 | #define RTEMS_FILE_DESCRIPTOR_TYPE_SOCKET 0x1000 |
---|
| 117 | #define rtems_make_file_descriptor(fd,flags) ((fd)|(flags)) |
---|
| 118 | #define rtems_file_descriptor_base(fd) ((fd) & 0x0FFF) |
---|
| 119 | #define rtems_file_descriptor_type(fd) ((fd) & 0xF000) |
---|
| 120 | #define rtems_file_descriptor_type_index(fd) ((((fd) & 0xF000) >> 12) - 1) |
---|
| 121 | |
---|
[9deb5b8b] | 122 | /* |
---|
| 123 | * IOCTL values |
---|
| 124 | */ |
---|
| 125 | |
---|
| 126 | #define RTEMS_IO_GET_ATTRIBUTES 1 |
---|
| 127 | #define RTEMS_IO_SET_ATTRIBUTES 2 |
---|
[603d706] | 128 | #define RTEMS_IO_TCDRAIN 3 |
---|
[9deb5b8b] | 129 | |
---|
[ae35953d] | 130 | /* |
---|
[161e1b3f] | 131 | * Callbacks from TERMIOS routines to device-dependent code |
---|
| 132 | */ |
---|
| 133 | #include <termios.h> |
---|
| 134 | typedef struct rtems_termios_callbacks { |
---|
| 135 | int (*firstOpen)(int major, int minor, void *arg); |
---|
| 136 | int (*lastClose)(int major, int minor, void *arg); |
---|
| 137 | int (*pollRead)(int minor); |
---|
| 138 | int (*write)(int minor, const char *buf, int len); |
---|
| 139 | int (*setAttributes)(int minor, const struct termios *t); |
---|
| 140 | int (*stopRemoteTx)(int minor); |
---|
| 141 | int (*startRemoteTx)(int minor); |
---|
| 142 | int outputUsesInterrupts; |
---|
| 143 | } rtems_termios_callbacks; |
---|
| 144 | |
---|
| 145 | /* |
---|
| 146 | * Device-independent TERMIOS routines |
---|
[ae35953d] | 147 | */ |
---|
| 148 | void rtems_termios_initialize (void); |
---|
| 149 | rtems_status_code rtems_termios_open ( |
---|
[161e1b3f] | 150 | rtems_device_major_number major, |
---|
| 151 | rtems_device_minor_number minor, |
---|
| 152 | void *arg, |
---|
| 153 | const rtems_termios_callbacks *callbacks |
---|
[ae35953d] | 154 | ); |
---|
| 155 | rtems_status_code rtems_termios_close (void *arg); |
---|
| 156 | rtems_status_code rtems_termios_read (void *arg); |
---|
| 157 | rtems_status_code rtems_termios_write (void *arg); |
---|
| 158 | rtems_status_code rtems_termios_ioctl (void *arg); |
---|
[27dccae] | 159 | int rtems_termios_enqueue_raw_characters (void *ttyp, char *buf, int len); |
---|
[608641e] | 160 | void rtems_termios_dequeue_characters (void *ttyp, int len); |
---|
[118a812] | 161 | void rtems_termios_reserve_resources( |
---|
| 162 | rtems_configuration_table *configuration, |
---|
| 163 | rtems_unsigned32 number_of_devices |
---|
| 164 | ); |
---|
[ae35953d] | 165 | |
---|
[b06e68ef] | 166 | #endif /* _RTEMS_LIBIO_H */ |
---|