James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 1 | /* |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 2 | * Copyright (c) 2014-2020, 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, |
| 27 | IO_TYPE_STM32IMAGE, |
Sumit Garg | 617e215 | 2019-11-15 15:34:55 +0530 | [diff] [blame] | 28 | IO_TYPE_ENCRYPTED, |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 29 | IO_TYPE_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 30 | } io_type_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 31 | |
| 32 | |
| 33 | /* Modes used when seeking data on a supported device */ |
| 34 | typedef enum { |
| 35 | IO_SEEK_INVALID, |
| 36 | IO_SEEK_SET, |
| 37 | IO_SEEK_END, |
| 38 | IO_SEEK_CUR, |
| 39 | IO_SEEK_MAX |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 40 | } io_seek_mode_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 41 | |
| 42 | |
| 43 | /* Connector type, providing a means of identifying a device to open */ |
| 44 | struct io_dev_connector; |
| 45 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 46 | |
| 47 | /* File specification - used to refer to data on a device supporting file-like |
| 48 | * entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 49 | typedef struct io_file_spec { |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 50 | const char *path; |
| 51 | unsigned int mode; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 52 | } io_file_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 53 | |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 54 | /* UUID specification - used to refer to data accessed using UUIDs (i.e. FIP |
| 55 | * images) */ |
| 56 | typedef struct io_uuid_spec { |
Louis Mayencourt | badcac8 | 2019-10-24 15:18:46 +0100 | [diff] [blame] | 57 | uuid_t uuid; |
Juan Castillo | 3a66aca | 2015-04-13 17:36:19 +0100 | [diff] [blame] | 58 | } io_uuid_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 59 | |
| 60 | /* Block specification - used to refer to data on a device supporting |
| 61 | * block-like entities */ |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 62 | typedef struct io_block_spec { |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 63 | size_t offset; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 64 | size_t length; |
Dan Handley | e2712bc | 2014-04-10 15:37:22 +0100 | [diff] [blame] | 65 | } io_block_spec_t; |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 66 | |
| 67 | |
| 68 | /* Access modes used when accessing data on a device */ |
| 69 | #define IO_MODE_INVALID (0) |
| 70 | #define IO_MODE_RO (1 << 0) |
| 71 | #define IO_MODE_RW (1 << 1) |
| 72 | |
| 73 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 74 | /* Open a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 75 | int io_dev_open(const struct io_dev_connector *dev_con, |
| 76 | const uintptr_t dev_spec, |
Roberto Vargas | 1a6eed3 | 2018-02-12 12:36:17 +0000 | [diff] [blame] | 77 | uintptr_t *handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 78 | |
| 79 | |
| 80 | /* Initialise a device explicitly - to permit lazy initialisation or |
| 81 | * re-initialisation */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 82 | 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] | 83 | |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 84 | /* Close a connection to a device */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 85 | int io_dev_close(uintptr_t dev_handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 86 | |
| 87 | |
| 88 | /* Synchronous operations */ |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 89 | 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] | 90 | |
Yann Gautier | f30cddc | 2019-04-16 11:35:19 +0200 | [diff] [blame] | 91 | 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] | 92 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 93 | int io_size(uintptr_t handle, size_t *length); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 94 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 95 | int io_read(uintptr_t handle, uintptr_t buffer, size_t length, |
| 96 | size_t *length_read); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 97 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 98 | 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] | 99 | size_t *length_written); |
| 100 | |
Dan Handley | a4cb68e | 2014-04-23 13:47:06 +0100 | [diff] [blame] | 101 | int io_close(uintptr_t handle); |
James Morrissey | f2f9bb5 | 2014-02-10 16:18:59 +0000 | [diff] [blame] | 102 | |
| 103 | |
Antonio Nino Diaz | 5eb8837 | 2018-11-08 10:20:19 +0000 | [diff] [blame] | 104 | #endif /* IO_STORAGE_H */ |