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