xref: /rk3399_rockchip-uboot/include/os.h (revision d9165153caea9f342410ed3ac87cb68768ebec78)
17a9219c1SSimon Glass /*
2*d9165153SSimon Glass  * Operating System Interface
3*d9165153SSimon Glass  *
4*d9165153SSimon Glass  * This provides access to useful OS routines for the sandbox architecture.
5*d9165153SSimon Glass  * They are kept in a separate file so we can include system headers.
6*d9165153SSimon Glass  *
77a9219c1SSimon Glass  * Copyright (c) 2011 The Chromium OS Authors.
87a9219c1SSimon Glass  * See file CREDITS for list of people who contributed to this
97a9219c1SSimon Glass  * project.
107a9219c1SSimon Glass  *
117a9219c1SSimon Glass  * This program is free software; you can redistribute it and/or
127a9219c1SSimon Glass  * modify it under the terms of the GNU General Public License as
137a9219c1SSimon Glass  * published by the Free Software Foundation; either version 2 of
147a9219c1SSimon Glass  * the License, or (at your option) any later version.
157a9219c1SSimon Glass  *
167a9219c1SSimon Glass  * This program is distributed in the hope that it will be useful,
177a9219c1SSimon Glass  * but WITHOUT ANY WARRANTY; without even the implied warranty of
187a9219c1SSimon Glass  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
197a9219c1SSimon Glass  * GNU General Public License for more details.
207a9219c1SSimon Glass  *
217a9219c1SSimon Glass  * You should have received a copy of the GNU General Public License
227a9219c1SSimon Glass  * along with this program; if not, write to the Free Software
237a9219c1SSimon Glass  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
247a9219c1SSimon Glass  * MA 02111-1307 USA
257a9219c1SSimon Glass  */
267a9219c1SSimon Glass 
274f345d56SMike Frysinger #ifndef __OS_H__
284f345d56SMike Frysinger #define __OS_H__
294f345d56SMike Frysinger 
307a9219c1SSimon Glass /**
317a9219c1SSimon Glass  * Access to the OS read() system call
327a9219c1SSimon Glass  *
337a9219c1SSimon Glass  * \param fd	File descriptor as returned by os_open()
347a9219c1SSimon Glass  * \param buf	Buffer to place data
357a9219c1SSimon Glass  * \param count	Number of bytes to read
367a9219c1SSimon Glass  * \return number of bytes read, or -1 on error
377a9219c1SSimon Glass  */
387a9219c1SSimon Glass ssize_t os_read(int fd, void *buf, size_t count);
397a9219c1SSimon Glass 
407a9219c1SSimon Glass /**
417a9219c1SSimon Glass  * Access to the OS write() system call
427a9219c1SSimon Glass  *
437a9219c1SSimon Glass  * \param fd	File descriptor as returned by os_open()
447a9219c1SSimon Glass  * \param buf	Buffer containing data to write
457a9219c1SSimon Glass  * \param count	Number of bytes to write
467a9219c1SSimon Glass  * \return number of bytes written, or -1 on error
477a9219c1SSimon Glass  */
487a9219c1SSimon Glass ssize_t os_write(int fd, const void *buf, size_t count);
497a9219c1SSimon Glass 
507a9219c1SSimon Glass /**
51e2dcefcbSMike Frysinger  * Access to the OS lseek() system call
52e2dcefcbSMike Frysinger  *
53e2dcefcbSMike Frysinger  * \param fd	File descriptor as returned by os_open()
54e2dcefcbSMike Frysinger  * \param offset	File offset (based on whence)
55e2dcefcbSMike Frysinger  * \param whence	Position offset is relative to (see below)
56e2dcefcbSMike Frysinger  * \return new file offset
57e2dcefcbSMike Frysinger  */
58e2dcefcbSMike Frysinger off_t os_lseek(int fd, off_t offset, int whence);
59e2dcefcbSMike Frysinger 
60e2dcefcbSMike Frysinger /* Defines for "whence" in os_lseek() */
61e2dcefcbSMike Frysinger #define OS_SEEK_SET	0
62e2dcefcbSMike Frysinger #define OS_SEEK_CUR	1
63e2dcefcbSMike Frysinger #define OS_SEEK_END	2
64e2dcefcbSMike Frysinger 
65e2dcefcbSMike Frysinger /**
667a9219c1SSimon Glass  * Access to the OS open() system call
677a9219c1SSimon Glass  *
687a9219c1SSimon Glass  * \param pathname	Pathname of file to open
697a9219c1SSimon Glass  * \param flags		Flags, like O_RDONLY, O_RDWR
707a9219c1SSimon Glass  * \return file descriptor, or -1 on error
717a9219c1SSimon Glass  */
727a9219c1SSimon Glass int os_open(const char *pathname, int flags);
737a9219c1SSimon Glass 
74*d9165153SSimon Glass #define OS_O_RDONLY	0
75*d9165153SSimon Glass #define OS_O_WRONLY	1
76*d9165153SSimon Glass #define OS_O_RDWR	2
77*d9165153SSimon Glass #define OS_O_MASK	3	/* Mask for read/write flags */
78*d9165153SSimon Glass #define OS_O_CREAT	0100
79*d9165153SSimon Glass 
807a9219c1SSimon Glass /**
817a9219c1SSimon Glass  * Access to the OS close() system call
827a9219c1SSimon Glass  *
837a9219c1SSimon Glass  * \param fd	File descriptor to close
847a9219c1SSimon Glass  * \return 0 on success, -1 on error
857a9219c1SSimon Glass  */
867a9219c1SSimon Glass int os_close(int fd);
877a9219c1SSimon Glass 
887a9219c1SSimon Glass /**
897a9219c1SSimon Glass  * Access to the OS exit() system call
907a9219c1SSimon Glass  *
917a9219c1SSimon Glass  * This exits with the supplied return code, which should be 0 to indicate
927a9219c1SSimon Glass  * success.
937a9219c1SSimon Glass  *
947a9219c1SSimon Glass  * @param exit_code	exit code for U-Boot
957a9219c1SSimon Glass  */
967a9219c1SSimon Glass void os_exit(int exit_code);
97ab06a758SMike Frysinger 
98ab06a758SMike Frysinger /**
99ab06a758SMike Frysinger  * Put tty into raw mode to mimic serial console better
100ab06a758SMike Frysinger  */
101ab06a758SMike Frysinger void os_tty_raw(int fd);
10221899b10SMatthias Weisser 
10321899b10SMatthias Weisser /**
10421899b10SMatthias Weisser  * Acquires some memory from the underlying os.
10521899b10SMatthias Weisser  *
10621899b10SMatthias Weisser  * \param length	Number of bytes to be allocated
10721899b10SMatthias Weisser  * \return Pointer to length bytes or NULL on error
10821899b10SMatthias Weisser  */
10921899b10SMatthias Weisser void *os_malloc(size_t length);
110d99a6874SMatthias Weisser 
111d99a6874SMatthias Weisser /**
112d99a6874SMatthias Weisser  * Access to the usleep function of the os
113d99a6874SMatthias Weisser  *
114d99a6874SMatthias Weisser  * \param usec Time to sleep in micro seconds
115d99a6874SMatthias Weisser  */
116d99a6874SMatthias Weisser void os_usleep(unsigned long usec);
117d99a6874SMatthias Weisser 
118d99a6874SMatthias Weisser /**
119d99a6874SMatthias Weisser  * Gets a monotonic increasing number of nano seconds from the OS
120d99a6874SMatthias Weisser  *
121d99a6874SMatthias Weisser  * \return A monotonic increasing time scaled in nano seconds
122d99a6874SMatthias Weisser  */
123d99a6874SMatthias Weisser u64 os_get_nsec(void);
1244f345d56SMike Frysinger 
1254f345d56SMike Frysinger #endif
126