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