blob: c496d487e43909503e724c852cf7bb91d2c8b304 [file] [log] [blame]
James Morrisseyf2f9bb52014-02-10 16:18:59 +00001/*
2 * Copyright (c) 2014, ARM Limited and Contributors. All rights reserved.
3 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
James Morrisseyf2f9bb52014-02-10 16:18:59 +00005 */
6
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +00007#ifndef IO_STORAGE_H
8#define IO_STORAGE_H
James Morrisseyf2f9bb52014-02-10 16:18:59 +00009
Juan Castilloadd146f2015-10-01 17:55:11 +010010#include <errno.h>
Dan Handleya4cb68e2014-04-23 13:47:06 +010011#include <stdint.h>
Dan Handley2bd4ef22014-04-09 13:14:54 +010012#include <stdio.h> /* For ssize_t */
Juan Castillo3a66aca2015-04-13 17:36:19 +010013#include <uuid.h>
James Morrissey9d72b4e2014-02-10 17:04:32 +000014
James Morrisseyf2f9bb52014-02-10 16:18:59 +000015
16/* Device type which can be used to enable policy decisions about which device
17 * to access */
18typedef enum {
19 IO_TYPE_INVALID,
20 IO_TYPE_SEMIHOSTING,
Harry Liebel561cd332014-02-14 14:42:48 +000021 IO_TYPE_MEMMAP,
Gerald Lejeune339f5592015-07-21 14:15:12 +020022 IO_TYPE_DUMMY,
Harry Liebel561cd332014-02-14 14:42:48 +000023 IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
Haojian Zhuang12ade162016-03-18 15:14:19 +080024 IO_TYPE_BLOCK,
Yann Gautierf325df52018-10-15 09:36:21 +020025 IO_TYPE_MMC,
26 IO_TYPE_STM32IMAGE,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000027 IO_TYPE_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010028} io_type_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000029
30
31/* Modes used when seeking data on a supported device */
32typedef enum {
33 IO_SEEK_INVALID,
34 IO_SEEK_SET,
35 IO_SEEK_END,
36 IO_SEEK_CUR,
37 IO_SEEK_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010038} io_seek_mode_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000039
40
41/* Connector type, providing a means of identifying a device to open */
42struct io_dev_connector;
43
James Morrisseyf2f9bb52014-02-10 16:18:59 +000044
45/* File specification - used to refer to data on a device supporting file-like
46 * entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010047typedef struct io_file_spec {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000048 const char *path;
49 unsigned int mode;
Dan Handleye2712bc2014-04-10 15:37:22 +010050} io_file_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000051
Juan Castillo3a66aca2015-04-13 17:36:19 +010052/* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
53 * images) */
54typedef struct io_uuid_spec {
55 const uuid_t uuid;
56} io_uuid_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000057
58/* Block specification - used to refer to data on a device supporting
59 * block-like entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010060typedef struct io_block_spec {
Dan Handleya4cb68e2014-04-23 13:47:06 +010061 size_t offset;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000062 size_t length;
Dan Handleye2712bc2014-04-10 15:37:22 +010063} io_block_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000064
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
James Morrisseyf2f9bb52014-02-10 16:18:59 +000072/* Open a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010073int io_dev_open(const struct io_dev_connector *dev_con,
74 const uintptr_t dev_spec,
Roberto Vargas1a6eed32018-02-12 12:36:17 +000075 uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000076
77
78/* Initialise a device explicitly - to permit lazy initialisation or
79 * re-initialisation */
Dan Handleya4cb68e2014-04-23 13:47:06 +010080int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000081
82/* TODO: Consider whether an explicit "shutdown" API should be included */
83
84/* Close a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010085int io_dev_close(uintptr_t dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000086
87
88/* Synchronous operations */
Dan Handleya4cb68e2014-04-23 13:47:06 +010089int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000090
Dan Handleya4cb68e2014-04-23 13:47:06 +010091int io_seek(uintptr_t handle, io_seek_mode_t mode, ssize_t offset);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000092
Dan Handleya4cb68e2014-04-23 13:47:06 +010093int io_size(uintptr_t handle, size_t *length);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000094
Dan Handleya4cb68e2014-04-23 13:47:06 +010095int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
96 size_t *length_read);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000097
Dan Handleya4cb68e2014-04-23 13:47:06 +010098int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000099 size_t *length_written);
100
Dan Handleya4cb68e2014-04-23 13:47:06 +0100101int io_close(uintptr_t handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000102
103
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000104#endif /* IO_STORAGE_H */