1 /*
2  * Copyright (c) 2019-2021, ARM Limited and Contributors. All rights reserved.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef IO_MTD_H
8 #define IO_MTD_H
9 
10 #include <stdint.h>
11 #include <stdio.h>
12 
13 #include <drivers/io/io_storage.h>
14 
15 /* MTD devices ops */
16 typedef struct io_mtd_ops {
17 	/*
18 	 * Initialize MTD framework and retrieve device information.
19 	 *
20 	 * @size:  [out] MTD device size in bytes.
21 	 * @erase_size: [out] MTD erase size in bytes.
22 	 * Return 0 on success, a negative error code otherwise.
23 	 */
24 	int (*init)(unsigned long long *size, unsigned int *erase_size);
25 
26 	/*
27 	 * Execute a read memory operation.
28 	 *
29 	 * @offset: Offset in bytes to start read operation.
30 	 * @buffer: [out] Buffer to store read data.
31 	 * @length: Required length to be read in bytes.
32 	 * @out_length: [out] Length read in bytes.
33 	 * Return 0 on success, a negative error code otherwise.
34 	 */
35 	int (*read)(unsigned int offset, uintptr_t buffer, size_t length,
36 		    size_t *out_length);
37 
38 	/*
39 	 * Execute a write memory operation.
40 	 *
41 	 * @offset: Offset in bytes to start write operation.
42 	 * @buffer: Buffer to be written in device.
43 	 * @length: Required length to be written in bytes.
44 	 * Return 0 on success, a negative error code otherwise.
45 	 */
46 	int (*write)(unsigned int offset, uintptr_t buffer, size_t length);
47 
48 	/*
49 	 * Look for an offset to be added to the given offset.
50 	 *
51 	 * @base: Base address of the area.
52 	 * @offset: Offset in bytes to start read operation.
53 	 * @extra_offset: [out] Offset to be added to the previous offset.
54 	 * Return 0 on success, a negative error code otherwise.
55 	 */
56 	int (*seek)(uintptr_t base, unsigned int offset, size_t *extra_offset);
57 } io_mtd_ops_t;
58 
59 typedef struct io_mtd_dev_spec {
60 	unsigned long long device_size;
61 	unsigned int erase_size;
62 	size_t offset;
63 	io_mtd_ops_t ops;
64 } io_mtd_dev_spec_t;
65 
66 struct io_dev_connector;
67 
68 int register_io_dev_mtd(const struct io_dev_connector **dev_con);
69 
70 #endif /* IO_MTD_H */
71