James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 1 | /* |
Yann Gautier | 5d2eb55 | 2022-11-14 14:14:48 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2022, ARM Limited and Contributors. All rights reserved. |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 7 | #ifndef IO_STORAGE_H |
| 8 | #define IO_STORAGE_H |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 9 | |
Juan Castillo | add146f | 2015-10-01 17:55:11 +0100 | [diff] [blame] | 10 | #include <errno.h> |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 11 | #include <stdint.h> |
Dan Handley | 2bd4ef2 | 2014-04-09 13:14:54 +0100 | [diff] [blame] | 12 | #include <stdio.h> /* For ssize_t */ |
James Morrissey | 9d72b4e | 2014-02-10 17:04:32 +0000 | [diff] [blame] | 13 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | #include <tools_share/uuid.h> |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 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, |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 21 | IO_TYPE_MEMMAP, |
Gerald Lejeune | 339f559 | 2015-07-21 14:15:12 +0200 | [diff] [blame] | 22 | IO_TYPE_DUMMY, |
Harry Liebel | 561cd33 | 2014-02-14 14:42:48 +0000 | [diff] [blame] | 23 | IO_TYPE_FIRMWARE_IMAGE_PACKAGE, |
Haojian Zhuang | 12ade16 | 2016-03-18 15:14:19 +0800 | [diff] [blame] | 24 | IO_TYPE_BLOCK, |
Lionel Debieve | 64a524d | 2019-09-09 20:13:34 +0200 | [diff] [blame] | 25 | IO_TYPE_MTD, |
Yann Gautier | f325df5 | 2018-10-15 09:36:21 +0200 | [diff] [blame] | 26 | IO_TYPE_MMC, |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 27 | IO_TYPE_ENCRYPTED, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 28 | IO_TYPE_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 29 | } io_type_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 30 | |
| 31 | |
| 32 | /* Modes used when seeking data on a supported device */ |
| 33 | typedef enum { |
| 34 | IO_SEEK_INVALID, |
| 35 | IO_SEEK_SET, |
| 36 | IO_SEEK_END, |
| 37 | IO_SEEK_CUR, |
| 38 | IO_SEEK_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 39 | } io_seek_mode_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 40 | |
| 41 | |
| 42 | /* Connector type, providing a means of identifying a device to open */ |
| 43 | struct io_dev_connector; |
| 44 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 45 | |
| 46 | /* File specification - used to refer to data on a device supporting file-like |
| 47 | * entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 48 | typedef struct io_file_spec { |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 49 | const char *path; |
| 50 | unsigned int mode; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 51 | } io_file_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 52 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 53 | /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP |
| 54 | * images) */ |
| 55 | typedef struct io_uuid_spec { |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 56 | uuid_t uuid; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 57 | } io_uuid_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 58 | |
| 59 | /* Block specification - used to refer to data on a device supporting |
| 60 | * block-like entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 61 | typedef struct io_block_spec { |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 62 | size_t offset; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 63 | size_t length; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 64 | } io_block_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 65 | |
| 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 Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 73 | /* Open a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 74 | int io_dev_open(const struct io_dev_connector *dev_con, |
| 75 | const uintptr_t dev_spec, |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 76 | uintptr_t *handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 77 | |
| 78 | |
| 79 | /* Initialise a device explicitly - to permit lazy initialisation or |
| 80 | * re-initialisation */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 81 | int io_dev_init(uintptr_t dev_handle, const uintptr_t init_params); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 82 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 83 | /* Close a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 84 | int io_dev_close(uintptr_t dev_handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 85 | |
| 86 | |
| 87 | /* Synchronous operations */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 88 | int io_open(uintptr_t dev_handle, const uintptr_t spec, uintptr_t *handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 89 | |
Yann Gautier | f30cddc | 2019-04-16 11:35:19 +0200 | [diff] [blame] | 90 | int io_seek(uintptr_t handle, io_seek_mode_t mode, signed long long offset); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 91 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 92 | int io_size(uintptr_t handle, size_t *length); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 93 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 94 | int io_read(uintptr_t handle, uintptr_t buffer, size_t length, |
| 95 | size_t *length_read); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 96 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 97 | int io_write(uintptr_t handle, const uintptr_t buffer, size_t length, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 98 | size_t *length_written); |
| 99 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 100 | int io_close(uintptr_t handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 101 | |
| 102 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 103 | #endif /* IO_STORAGE_H */ |