arm: smh: Use numeric modes for smh_open
[platform/kernel/u-boot.git] / include / semihosting.h
1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2022 Sean Anderson <sean.anderson@seco.com>
4  */
5
6 #ifndef _SEMIHOSTING_H
7 #define _SEMIHOSTING_H
8
9 /**
10  * enum smh_open_mode - Numeric file modes for use with smh_open()
11  * MODE_READ: 'r'
12  * MODE_BINARY: 'b'
13  * MODE_PLUS: '+'
14  * MODE_WRITE: 'w'
15  * MODE_APPEND: 'a'
16  *
17  * These modes represent the mode string used by fopen(3) in a form which can
18  * be passed to smh_open(). These do NOT correspond directly to %O_RDONLY,
19  * %O_CREAT, etc; see fopen(3) for details. In particular, @MODE_PLUS
20  * effectively results in adding %O_RDWR, and @MODE_WRITE will add %O_TRUNC.
21  * For compatibility, @MODE_BINARY should be added when opening non-text files
22  * (such as images).
23  */
24 enum smh_open_mode {
25         MODE_READ       = 0x0,
26         MODE_BINARY     = 0x1,
27         MODE_PLUS       = 0x2,
28         MODE_WRITE      = 0x4,
29         MODE_APPEND     = 0x8,
30 };
31
32 long smh_open(const char *fname, enum smh_open_mode mode);
33 long smh_read(long fd, void *memp, size_t len);
34 long smh_close(long fd);
35 long smh_flen(long fd);
36
37 #endif /* _SEMIHOSTING_H */