1 /*
2  * Copyright (c) 2022 Arm Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
6  * Licensed under the Apache License, Version 2.0 (the License); you may
7  * not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 #ifndef __IO_STORAGE_H__
20 #define __IO_STORAGE_H__
21 
22 #include <stddef.h>
23 #include <stdint.h>
24 
25 /* Access modes used when accessing data on a device */
26 #define IO_MODE_INVALID (0)
27 #define IO_MODE_RO (1 << 0)
28 #define IO_MODE_RW (1 << 1)
29 
30 /* Device type which can be used to enable policy decisions about which device
31  * to access */
32 typedef enum {
33     IO_TYPE_INVALID,
34     IO_TYPE_SEMIHOSTING,
35     IO_TYPE_MEMMAP,
36     IO_TYPE_DUMMY,
37     IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
38     IO_TYPE_BLOCK,
39     IO_TYPE_MTD,
40     IO_TYPE_MMC,
41     IO_TYPE_STM32IMAGE,
42     IO_TYPE_ENCRYPTED,
43     IO_TYPE_MAX
44 } io_type_t;
45 
46 /* Modes used when seeking data on a supported device */
47 typedef enum {
48     IO_SEEK_INVALID,
49     IO_SEEK_SET,
50     IO_SEEK_END,
51     IO_SEEK_CUR,
52     IO_SEEK_MAX
53 } io_seek_mode_t;
54 
55 /* Connector type, providing a means of identifying a device to open */
56 struct io_dev_connector;
57 
58 /* Block specification - used to refer to data on a device supporting
59  * block-like entities */
60 typedef struct io_block_spec {
61     size_t offset;
62     size_t length;
63 } io_block_spec_t;
64 
65 
66 /* Open a connection to a device */
67 int io_dev_open(const struct io_dev_connector *dev_con,
68                 const uintptr_t dev_spec, uintptr_t *handle);
69 
70 /* Initialise a device explicitly - to permit lazy initialisation or
71  * re-initialisation */
72 int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
73 
74 /* Close a connection to a device */
75 int io_dev_close(uintptr_t dev_handle);
76 
77 /* Synchronous operations */
78 int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
79 
80 int io_seek(uintptr_t handle, io_seek_mode_t mode, int32_t offset);
81 
82 int io_size(uintptr_t handle, size_t *length);
83 
84 int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
85             size_t *length_read);
86 
87 int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
88              size_t *length_written);
89 
90 int io_close(uintptr_t handle);
91 
92 #endif /* __IO_STORAGE_H__ */
93