blob: 31793832d0ee4f8354b766808501a86d59808f96 [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,
22 IO_TYPE_FIRMWARE_IMAGE_PACKAGE,
Haojian Zhuang12ade162016-03-18 15:14:19 +080023 IO_TYPE_BLOCK,
Lionel Debieve64a524d2019-09-09 20:13:34 +020024 IO_TYPE_MTD,
Yann Gautierf325df52018-10-15 09:36:21 +020025 IO_TYPE_MMC,
Sumit Garg617e2152019-11-15 15:34:55 +053026 IO_TYPE_ENCRYPTED,
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 {
Louis Mayencourtbadcac82019-10-24 15:18:46 +010055 uuid_t uuid;
Juan Castillo3a66aca2015-04-13 17:36:19 +010056} 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
James Morrisseyf2f9bb52014-02-10 16:18:59 +000082/* Close a connection to a device */
Dan Handleya4cb68e2014-04-23 13:47:06 +010083int io_dev_close(uintptr_t dev_handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000084
85
86/* Synchronous operations */
Dan Handleya4cb68e2014-04-23 13:47:06 +010087int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000088
Yann Gautierf30cddc2019-04-16 11:35:19 +020089int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000090
Dan Handleya4cb68e2014-04-23 13:47:06 +010091int io_size(uintptr_t handle, size_t *length);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000092
Dan Handleya4cb68e2014-04-23 13:47:06 +010093int io_read(uintptr_t handle, uintptr_t buffer, size_t length,
94 size_t *length_read);
James Morrisseyf2f9bb52014-02-10 16:18:59 +000095
Dan Handleya4cb68e2014-04-23 13:47:06 +010096int io_write(uintptr_t handle, const uintptr_t buffer, size_t length,
James Morrisseyf2f9bb52014-02-10 16:18:59 +000097 size_t *length_written);
98
Dan Handleya4cb68e2014-04-23 13:47:06 +010099int io_close(uintptr_t handle);
James Morrisseyf2f9bb52014-02-10 16:18:59 +0000100
101
Antonio Nino Diaz5eb88372018-11-08 10:20:19 +0000102#endif /* IO_STORAGE_H */