Simon Glass | 7a9219c | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 1 | /* |
Simon Glass | d916515 | 2012-02-20 23:56:58 -0500 | [diff] [blame^] | 2 | * Operating System Interface |
| 3 | * |
| 4 | * This provides access to useful OS routines for the sandbox architecture. |
| 5 | * They are kept in a separate file so we can include system headers. |
| 6 | * |
Simon Glass | 7a9219c | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 7 | * Copyright (c) 2011 The Chromium OS Authors. |
| 8 | * See file CREDITS for list of people who contributed to this |
| 9 | * project. |
| 10 | * |
| 11 | * This program is free software; you can redistribute it and/or |
| 12 | * modify it under the terms of the GNU General Public License as |
| 13 | * published by the Free Software Foundation; either version 2 of |
| 14 | * the License, or (at your option) any later version. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, |
| 24 | * MA 02111-1307 USA |
| 25 | */ |
| 26 | |
Mike Frysinger | 4f345d5 | 2012-01-19 22:57:29 -0500 | [diff] [blame] | 27 | #ifndef __OS_H__ |
| 28 | #define __OS_H__ |
| 29 | |
Simon Glass | 7a9219c | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 30 | /** |
| 31 | * Access to the OS read() system call |
| 32 | * |
| 33 | * \param fd File descriptor as returned by os_open() |
| 34 | * \param buf Buffer to place data |
| 35 | * \param count Number of bytes to read |
| 36 | * \return number of bytes read, or -1 on error |
| 37 | */ |
| 38 | ssize_t os_read(int fd, void *buf, size_t count); |
| 39 | |
| 40 | /** |
| 41 | * Access to the OS write() system call |
| 42 | * |
| 43 | * \param fd File descriptor as returned by os_open() |
| 44 | * \param buf Buffer containing data to write |
| 45 | * \param count Number of bytes to write |
| 46 | * \return number of bytes written, or -1 on error |
| 47 | */ |
| 48 | ssize_t os_write(int fd, const void *buf, size_t count); |
| 49 | |
| 50 | /** |
Mike Frysinger | e2dcefc | 2011-10-25 13:02:58 +0200 | [diff] [blame] | 51 | * Access to the OS lseek() system call |
| 52 | * |
| 53 | * \param fd File descriptor as returned by os_open() |
| 54 | * \param offset File offset (based on whence) |
| 55 | * \param whence Position offset is relative to (see below) |
| 56 | * \return new file offset |
| 57 | */ |
| 58 | off_t os_lseek(int fd, off_t offset, int whence); |
| 59 | |
| 60 | /* Defines for "whence" in os_lseek() */ |
| 61 | #define OS_SEEK_SET 0 |
| 62 | #define OS_SEEK_CUR 1 |
| 63 | #define OS_SEEK_END 2 |
| 64 | |
| 65 | /** |
Simon Glass | 7a9219c | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 66 | * Access to the OS open() system call |
| 67 | * |
| 68 | * \param pathname Pathname of file to open |
| 69 | * \param flags Flags, like O_RDONLY, O_RDWR |
| 70 | * \return file descriptor, or -1 on error |
| 71 | */ |
| 72 | int os_open(const char *pathname, int flags); |
| 73 | |
Simon Glass | d916515 | 2012-02-20 23:56:58 -0500 | [diff] [blame^] | 74 | #define OS_O_RDONLY 0 |
| 75 | #define OS_O_WRONLY 1 |
| 76 | #define OS_O_RDWR 2 |
| 77 | #define OS_O_MASK 3 /* Mask for read/write flags */ |
| 78 | #define OS_O_CREAT 0100 |
| 79 | |
Simon Glass | 7a9219c | 2011-10-03 19:26:44 +0000 | [diff] [blame] | 80 | /** |
| 81 | * Access to the OS close() system call |
| 82 | * |
| 83 | * \param fd File descriptor to close |
| 84 | * \return 0 on success, -1 on error |
| 85 | */ |
| 86 | int os_close(int fd); |
| 87 | |
| 88 | /** |
| 89 | * Access to the OS exit() system call |
| 90 | * |
| 91 | * This exits with the supplied return code, which should be 0 to indicate |
| 92 | * success. |
| 93 | * |
| 94 | * @param exit_code exit code for U-Boot |
| 95 | */ |
| 96 | void os_exit(int exit_code); |
Mike Frysinger | ab06a75 | 2011-10-26 00:21:29 +0000 | [diff] [blame] | 97 | |
| 98 | /** |
| 99 | * Put tty into raw mode to mimic serial console better |
| 100 | */ |
| 101 | void os_tty_raw(int fd); |
Matthias Weisser | 21899b1 | 2011-11-05 11:40:34 +0100 | [diff] [blame] | 102 | |
| 103 | /** |
| 104 | * Acquires some memory from the underlying os. |
| 105 | * |
| 106 | * \param length Number of bytes to be allocated |
| 107 | * \return Pointer to length bytes or NULL on error |
| 108 | */ |
| 109 | void *os_malloc(size_t length); |
Matthias Weisser | d99a687 | 2011-11-29 12:16:40 +0100 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Access to the usleep function of the os |
| 113 | * |
| 114 | * \param usec Time to sleep in micro seconds |
| 115 | */ |
| 116 | void os_usleep(unsigned long usec); |
| 117 | |
| 118 | /** |
| 119 | * Gets a monotonic increasing number of nano seconds from the OS |
| 120 | * |
| 121 | * \return A monotonic increasing time scaled in nano seconds |
| 122 | */ |
| 123 | u64 os_get_nsec(void); |
Mike Frysinger | 4f345d5 | 2012-01-19 22:57:29 -0500 | [diff] [blame] | 124 | |
| 125 | #endif |