1 /* 2 * Copyright (c) 2011 The Chromium OS Authors. 3 * See file CREDITS for list of people who contributed to this 4 * project. 5 * 6 * This program is free software; you can redistribute it and/or 7 * modify it under the terms of the GNU General Public License as 8 * published by the Free Software Foundation; either version 2 of 9 * the License, or (at your option) any later version. 10 * 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. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program; if not, write to the Free Software 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 19 * MA 02111-1307 USA 20 */ 21 22 /* 23 * Operating System Interface 24 * 25 * This provides access to useful OS routines from the sandbox architecture 26 */ 27 28 #ifndef __OS_H__ 29 #define __OS_H__ 30 31 /** 32 * Access to the OS read() system call 33 * 34 * \param fd File descriptor as returned by os_open() 35 * \param buf Buffer to place data 36 * \param count Number of bytes to read 37 * \return number of bytes read, or -1 on error 38 */ 39 ssize_t os_read(int fd, void *buf, size_t count); 40 41 /** 42 * Access to the OS write() system call 43 * 44 * \param fd File descriptor as returned by os_open() 45 * \param buf Buffer containing data to write 46 * \param count Number of bytes to write 47 * \return number of bytes written, or -1 on error 48 */ 49 ssize_t os_write(int fd, const void *buf, size_t count); 50 51 /** 52 * Access to the OS open() system call 53 * 54 * \param pathname Pathname of file to open 55 * \param flags Flags, like O_RDONLY, O_RDWR 56 * \return file descriptor, or -1 on error 57 */ 58 int os_open(const char *pathname, int flags); 59 60 /** 61 * Access to the OS close() system call 62 * 63 * \param fd File descriptor to close 64 * \return 0 on success, -1 on error 65 */ 66 int os_close(int fd); 67 68 /** 69 * Access to the OS exit() system call 70 * 71 * This exits with the supplied return code, which should be 0 to indicate 72 * success. 73 * 74 * @param exit_code exit code for U-Boot 75 */ 76 void os_exit(int exit_code); 77 78 /** 79 * Put tty into raw mode to mimic serial console better 80 */ 81 void os_tty_raw(int fd); 82 83 /** 84 * Acquires some memory from the underlying os. 85 * 86 * \param length Number of bytes to be allocated 87 * \return Pointer to length bytes or NULL on error 88 */ 89 void *os_malloc(size_t length); 90 91 /** 92 * Access to the usleep function of the os 93 * 94 * \param usec Time to sleep in micro seconds 95 */ 96 void os_usleep(unsigned long usec); 97 98 /** 99 * Gets a monotonic increasing number of nano seconds from the OS 100 * 101 * \return A monotonic increasing time scaled in nano seconds 102 */ 103 u64 os_get_nsec(void); 104 105 #endif 106