c496d487e43909503e724c852cf7bb91d2c8b304
[project/bcm63xx/atf.git] / include / drivers / io / io_storage.h
1 /*
2 * Copyright (c) 2014, 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 #include <uuid.h>
14
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_MMC,
26 IO_TYPE_STM32IMAGE,
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 const 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 /* TODO: Consider whether an explicit "shutdown" API should be included */
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, ssize_t 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 */