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_FIRMWARE_IMAGE_PACKAGE,
23 	IO_TYPE_BLOCK,
24 	IO_TYPE_MTD,
25 	IO_TYPE_MMC,
26 	IO_TYPE_ENCRYPTED,
27 	IO_TYPE_MAX
28 } io_type_t;
29 
30 
31 /* Modes used when seeking data on a supported device */
32 typedef enum {
33 	IO_SEEK_INVALID,
34 	IO_SEEK_SET,
35 	IO_SEEK_END,
36 	IO_SEEK_CUR,
37 	IO_SEEK_MAX
38 } io_seek_mode_t;
39 
40 
41 /* Connector type, providing a means of identifying a device to open */
42 struct io_dev_connector;
43 
44 
45 /* File specification - used to refer to data on a device supporting file-like
46  * entities */
47 typedef struct io_file_spec {
48 	const char *path;
49 	unsigned int mode;
50 } io_file_spec_t;
51 
52 /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
53  * images) */
54 typedef struct io_uuid_spec {
55 	uuid_t uuid;
56 } io_uuid_spec_t;
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 /* Access modes used when accessing data on a device */
67 #define IO_MODE_INVALID (0)
68 #define IO_MODE_RO	(1 << 0)
69 #define IO_MODE_RW	(1 << 1)
70 
71 
72 /* Open a connection to a device */
73 int io_dev_open(const struct io_dev_connector *dev_con,
74 		const uintptr_t dev_spec,
75 		uintptr_t *handle);
76 
77 
78 /* Initialise a device explicitly - to permit lazy initialisation or
79  * re-initialisation */
80 int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
81 
82 /* Close a connection to a device */
83 int io_dev_close(uintptr_t dev_handle);
84 
85 
86 /* Synchronous operations */
87 int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
88 
89 int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
90 
91 int io_size(uintptr_t handle, size_t *length);
92 
93 int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
94 		size_t *length_read);
95 
96 int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
97 		size_t *length_written);
98 
99 int io_close(uintptr_t handle);
100 
101 
102 #endif /* IO_STORAGE_H */
103