blob: 8f30ed050b3bc18ac13002d69e9699db3659e32c [file] [log] [blame]
James Morrisseyf2f9bb52014-02-10 16:18:59 +00001/*
Yann Gautier5d2eb552022-11-14 14:14:48 +01002 * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved.
James Morrisseyf2f9bb52014-02-10 16:18:59 +00003 *
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 */
James Morrissey9d72b4e2014-02-10 17:04:32 +000013
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000014#include <tools_share/uuid.h>
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,
Lionel Debieve64a524d2019-09-09 20:13:34 +020025 IO_TYPE_MTD,
Yann Gautierf325df52018-10-15 09:36:21 +020026 IO_TYPE_MMC,
Sumit Garg617e2152019-11-15 15:34:55 +053027 IO_TYPE_ENCRYPTED,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000028 IO_TYPE_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010029} io_type_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000030
31
32/* Modes used when seeking data on a supported device */
33typedef enum {
34 IO_SEEK_INVALID,
35 IO_SEEK_SET,
36 IO_SEEK_END,
37 IO_SEEK_CUR,
38 IO_SEEK_MAX
Dan Handleye2712bc2014-04-10 15:37:22 +010039} io_seek_mode_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000040
41
42/* Connector type, providing a means of identifying a device to open */
43struct io_dev_connector;
44
James Morrisseyf2f9bb52014-02-10 16:18:59 +000045
46/* File specification - used to refer to data on a device supporting file-like
47 * entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010048typedef struct io_file_spec {
James Morrisseyf2f9bb52014-02-10 16:18:59 +000049 const char *path;
50 unsigned int mode;
Dan Handleye2712bc2014-04-10 15:37:22 +010051} io_file_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000052
Juan Castillo3a66aca2015-04-13 17:36:19 +010053/* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP
54 * images) */
55typedef struct io_uuid_spec {
Louis Mayencourtbadcac82019-10-24 15:18:46 +010056 uuid_t uuid;
Juan Castillo3a66aca2015-04-13 17:36:19 +010057} io_uuid_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000058
59/* Block specification - used to refer to data on a device supporting
60 * block-like entities */
Dan Handleye2712bc2014-04-10 15:37:22 +010061typedef struct io_block_spec {
Dan Handleya4cb68e2014-04-23 13:47:06 +010062 size_t offset;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000063 size_t length;
Dan Handleye2712bc2014-04-10 15:37:22 +010064} io_block_spec_t;
James Morrisseyf2f9bb52014-02-10 16:18:59 +000065
66
67/* Access modes used when accessing data on a device */
68#define IO_MODE_INVALID (0)
69#define IO_MODE_RO (1 << 0)
70#define IO_MODE_RW (1 << 1)
71
72
James Morrisseyf2f9bb52014-02-10 16:18:59 +000073/* Open a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010074int io_dev_open(const struct io_dev_connector *dev_con,
75 const uintptr_t dev_spec,
Roberto Vargas1a6eed32018-02-12 12:36:17 +000076 uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000077
78
79/* Initialise a device explicitly - to permit lazy initialisation or
80 * re-initialisation */
Dan Handleya4cb68e2014-04-23 13:47:06 +010081int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000082
James Morrisseyf2f9bb52014-02-10 16:18:59 +000083/* Close a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010084int io_dev_close(uintptr_t dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000085
86
87/* Synchronous operations */
Dan Handleya4cb68e2014-04-23 13:47:06 +010088int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000089
Yann Gautierf30cddc2019-04-16 11:35:19 +020090int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000091
Dan Handleya4cb68e2014-04-23 13:47:06 +010092int io_size(uintptr_t handle, size_t *length);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000093
Dan Handleya4cb68e2014-04-23 13:47:06 +010094int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
95 size_t *length_read);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000096
Dan Handleya4cb68e2014-04-23 13:47:06 +010097int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000098 size_t *length_written);
99
Dan Handleya4cb68e2014-04-23 13:47:06 +0100100int io_close(uintptr_t handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000101
102
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000103#endif /* IO_STORAGE_H */