os.h 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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. * Operating System Interface
  23. *
  24. * This provides access to useful OS routines from the sandbox architecture
  25. */
  26. #ifndef __OS_H__
  27. #define __OS_H__
  28. /**
  29. * Access to the OS read() system call
  30. *
  31. * \param fd File descriptor as returned by os_open()
  32. * \param buf Buffer to place data
  33. * \param count Number of bytes to read
  34. * \return number of bytes read, or -1 on error
  35. */
  36. ssize_t os_read(int fd, void *buf, size_t count);
  37. /**
  38. * Access to the OS write() system call
  39. *
  40. * \param fd File descriptor as returned by os_open()
  41. * \param buf Buffer containing data to write
  42. * \param count Number of bytes to write
  43. * \return number of bytes written, or -1 on error
  44. */
  45. ssize_t os_write(int fd, const void *buf, size_t count);
  46. /**
  47. * Access to the OS lseek() system call
  48. *
  49. * \param fd File descriptor as returned by os_open()
  50. * \param offset File offset (based on whence)
  51. * \param whence Position offset is relative to (see below)
  52. * \return new file offset
  53. */
  54. off_t os_lseek(int fd, off_t offset, int whence);
  55. /* Defines for "whence" in os_lseek() */
  56. #define OS_SEEK_SET 0
  57. #define OS_SEEK_CUR 1
  58. #define OS_SEEK_END 2
  59. /**
  60. * Access to the OS open() system call
  61. *
  62. * \param pathname Pathname of file to open
  63. * \param flags Flags, like O_RDONLY, O_RDWR
  64. * \return file descriptor, or -1 on error
  65. */
  66. int os_open(const char *pathname, int flags);
  67. /**
  68. * Access to the OS close() system call
  69. *
  70. * \param fd File descriptor to close
  71. * \return 0 on success, -1 on error
  72. */
  73. int os_close(int fd);
  74. /**
  75. * Access to the OS exit() system call
  76. *
  77. * This exits with the supplied return code, which should be 0 to indicate
  78. * success.
  79. *
  80. * @param exit_code exit code for U-Boot
  81. */
  82. void os_exit(int exit_code);
  83. /**
  84. * Put tty into raw mode to mimic serial console better
  85. */
  86. void os_tty_raw(int fd);
  87. /**
  88. * Acquires some memory from the underlying os.
  89. *
  90. * \param length Number of bytes to be allocated
  91. * \return Pointer to length bytes or NULL on error
  92. */
  93. void *os_malloc(size_t length);
  94. /**
  95. * Access to the usleep function of the os
  96. *
  97. * \param usec Time to sleep in micro seconds
  98. */
  99. void os_usleep(unsigned long usec);
  100. /**
  101. * Gets a monotonic increasing number of nano seconds from the OS
  102. *
  103. * \return A monotonic increasing time scaled in nano seconds
  104. */
  105. u64 os_get_nsec(void);
  106. #endif