17a9219c1SSimon Glass /* 27a9219c1SSimon Glass * Copyright (c) 2011 The Chromium OS Authors. 37a9219c1SSimon Glass * See file CREDITS for list of people who contributed to this 47a9219c1SSimon Glass * project. 57a9219c1SSimon Glass * 67a9219c1SSimon Glass * This program is free software; you can redistribute it and/or 77a9219c1SSimon Glass * modify it under the terms of the GNU General Public License as 87a9219c1SSimon Glass * published by the Free Software Foundation; either version 2 of 97a9219c1SSimon Glass * the License, or (at your option) any later version. 107a9219c1SSimon Glass * 117a9219c1SSimon Glass * This program is distributed in the hope that it will be useful, 127a9219c1SSimon Glass * but WITHOUT ANY WARRANTY; without even the implied warranty of 137a9219c1SSimon Glass * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 147a9219c1SSimon Glass * GNU General Public License for more details. 157a9219c1SSimon Glass * 167a9219c1SSimon Glass * You should have received a copy of the GNU General Public License 177a9219c1SSimon Glass * along with this program; if not, write to the Free Software 187a9219c1SSimon Glass * Foundation, Inc., 59 Temple Place, Suite 330, Boston, 197a9219c1SSimon Glass * MA 02111-1307 USA 207a9219c1SSimon Glass */ 217a9219c1SSimon Glass 227a9219c1SSimon Glass /* 237a9219c1SSimon Glass * Operating System Interface 247a9219c1SSimon Glass * 257a9219c1SSimon Glass * This provides access to useful OS routines from the sandbox architecture 267a9219c1SSimon Glass */ 277a9219c1SSimon Glass 28*4f345d56SMike Frysinger #ifndef __OS_H__ 29*4f345d56SMike Frysinger #define __OS_H__ 30*4f345d56SMike Frysinger 317a9219c1SSimon Glass /** 327a9219c1SSimon Glass * Access to the OS read() system call 337a9219c1SSimon Glass * 347a9219c1SSimon Glass * \param fd File descriptor as returned by os_open() 357a9219c1SSimon Glass * \param buf Buffer to place data 367a9219c1SSimon Glass * \param count Number of bytes to read 377a9219c1SSimon Glass * \return number of bytes read, or -1 on error 387a9219c1SSimon Glass */ 397a9219c1SSimon Glass ssize_t os_read(int fd, void *buf, size_t count); 407a9219c1SSimon Glass 417a9219c1SSimon Glass /** 427a9219c1SSimon Glass * Access to the OS write() system call 437a9219c1SSimon Glass * 447a9219c1SSimon Glass * \param fd File descriptor as returned by os_open() 457a9219c1SSimon Glass * \param buf Buffer containing data to write 467a9219c1SSimon Glass * \param count Number of bytes to write 477a9219c1SSimon Glass * \return number of bytes written, or -1 on error 487a9219c1SSimon Glass */ 497a9219c1SSimon Glass ssize_t os_write(int fd, const void *buf, size_t count); 507a9219c1SSimon Glass 517a9219c1SSimon Glass /** 527a9219c1SSimon Glass * Access to the OS open() system call 537a9219c1SSimon Glass * 547a9219c1SSimon Glass * \param pathname Pathname of file to open 557a9219c1SSimon Glass * \param flags Flags, like O_RDONLY, O_RDWR 567a9219c1SSimon Glass * \return file descriptor, or -1 on error 577a9219c1SSimon Glass */ 587a9219c1SSimon Glass int os_open(const char *pathname, int flags); 597a9219c1SSimon Glass 607a9219c1SSimon Glass /** 617a9219c1SSimon Glass * Access to the OS close() system call 627a9219c1SSimon Glass * 637a9219c1SSimon Glass * \param fd File descriptor to close 647a9219c1SSimon Glass * \return 0 on success, -1 on error 657a9219c1SSimon Glass */ 667a9219c1SSimon Glass int os_close(int fd); 677a9219c1SSimon Glass 687a9219c1SSimon Glass /** 697a9219c1SSimon Glass * Access to the OS exit() system call 707a9219c1SSimon Glass * 717a9219c1SSimon Glass * This exits with the supplied return code, which should be 0 to indicate 727a9219c1SSimon Glass * success. 737a9219c1SSimon Glass * 747a9219c1SSimon Glass * @param exit_code exit code for U-Boot 757a9219c1SSimon Glass */ 767a9219c1SSimon Glass void os_exit(int exit_code); 77ab06a758SMike Frysinger 78ab06a758SMike Frysinger /** 79ab06a758SMike Frysinger * Put tty into raw mode to mimic serial console better 80ab06a758SMike Frysinger */ 81ab06a758SMike Frysinger void os_tty_raw(int fd); 8221899b10SMatthias Weisser 8321899b10SMatthias Weisser /** 8421899b10SMatthias Weisser * Acquires some memory from the underlying os. 8521899b10SMatthias Weisser * 8621899b10SMatthias Weisser * \param length Number of bytes to be allocated 8721899b10SMatthias Weisser * \return Pointer to length bytes or NULL on error 8821899b10SMatthias Weisser */ 8921899b10SMatthias Weisser void *os_malloc(size_t length); 90d99a6874SMatthias Weisser 91d99a6874SMatthias Weisser /** 92d99a6874SMatthias Weisser * Access to the usleep function of the os 93d99a6874SMatthias Weisser * 94d99a6874SMatthias Weisser * \param usec Time to sleep in micro seconds 95d99a6874SMatthias Weisser */ 96d99a6874SMatthias Weisser void os_usleep(unsigned long usec); 97d99a6874SMatthias Weisser 98d99a6874SMatthias Weisser /** 99d99a6874SMatthias Weisser * Gets a monotonic increasing number of nano seconds from the OS 100d99a6874SMatthias Weisser * 101d99a6874SMatthias Weisser * \return A monotonic increasing time scaled in nano seconds 102d99a6874SMatthias Weisser */ 103d99a6874SMatthias Weisser u64 os_get_nsec(void); 104*4f345d56SMike Frysinger 105*4f345d56SMike Frysinger #endif 106