1 /*
2  * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef IO_STORAGE_H
8 #define IO_STORAGE_H
9 
10 #include <errno.h>
11 #include <stdint.h>
12 #include <stdio.h> /* For ssize_t */
13 
14 #include <tools_share/uuid.h>
15 
16 /* Device type which can be used to enable policy decisions about which device
17  * to access */
18 typedef enum {
19 	IO_TYPE_INVALID,
20 	IO_TYPE_SEMIHOSTING,
21 	IO_TYPE_MEMMAP,
22 	IO_TYPE_DUMMY,
23 	IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
24 	IO_TYPE_BLOCK,
25 	IO_TYPE_MTD,
26 	IO_TYPE_MMC,
27 	IO_TYPE_ENCRYPTED,
28 	IO_TYPE_MAX
29 } io_type_t;
30 
31 
32 /* Modes used when seeking data on a supported device */
33 typedef enum {
34 	IO_SEEK_INVALID,
35 	IO_SEEK_SET,
36 	IO_SEEK_END,
37 	IO_SEEK_CUR,
38 	IO_SEEK_MAX
39 } io_seek_mode_t;
40 
41 
42 /* Connector type, providing a means of identifying a device to open */
43 struct io_dev_connector;
44 
45 
46 /* File specification - used to refer to data on a device supporting file-like
47  * entities */
48 typedef struct io_file_spec {
49 	const char *path;
50 	unsigned int mode;
51 } io_file_spec_t;
52 
53 /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
54  * images) */
55 typedef struct io_uuid_spec {
56 	uuid_t uuid;
57 } io_uuid_spec_t;
58 
59 /* Block specification - used to refer to data on a device supporting
60  * block-like entities */
61 typedef struct io_block_spec {
62 	size_t offset;
63 	size_t length;
64 } io_block_spec_t;
65 
66 
67 /* Access modes used when accessing data on a device */
68 #define IO_MODE_INVALID (0)
69 #define IO_MODE_RO	(1 << 0)
70 #define IO_MODE_RW	(1 << 1)
71 
72 
73 /* Open a connection to a device */
74 int io_dev_open(const struct io_dev_connector *dev_con,
75 		const uintptr_t dev_spec,
76 		uintptr_t *handle);
77 
78 
79 /* Initialise a device explicitly - to permit lazy initialisation or
80  * re-initialisation */
81 int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
82 
83 /* Close a connection to a device */
84 int io_dev_close(uintptr_t dev_handle);
85 
86 
87 /* Synchronous operations */
88 int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
89 
90 int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
91 
92 int io_size(uintptr_t handle, size_t *length);
93 
94 int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
95 		size_t *length_read);
96 
97 int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
98 		size_t *length_written);
99 
100 int io_close(uintptr_t handle);
101 
102 
103 #endif /* IO_STORAGE_H */
104