summaryrefslogtreecommitdiffstats
path: root/include/drivers/io/io_mtd.h
blob: 2b5d9b1017a35095d2d2feb5aac975a0742a65d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * Copyright (c) 2019-2021, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

#ifndef IO_MTD_H
#define IO_MTD_H

#include <stdint.h>
#include <stdio.h>

#include <drivers/io/io_storage.h>

/* MTD devices ops */
typedef struct io_mtd_ops {
	/*
	 * Initialize MTD framework and retrieve device information.
	 *
	 * @size:  [out] MTD device size in bytes.
	 * @erase_size: [out] MTD erase size in bytes.
	 * Return 0 on success, a negative error code otherwise.
	 */
	int (*init)(unsigned long long *size, unsigned int *erase_size);

	/*
	 * Execute a read memory operation.
	 *
	 * @offset: Offset in bytes to start read operation.
	 * @buffer: [out] Buffer to store read data.
	 * @length: Required length to be read in bytes.
	 * @out_length: [out] Length read in bytes.
	 * Return 0 on success, a negative error code otherwise.
	 */
	int (*read)(unsigned int offset, uintptr_t buffer, size_t length,
		    size_t *out_length);

	/*
	 * Execute a write memory operation.
	 *
	 * @offset: Offset in bytes to start write operation.
	 * @buffer: Buffer to be written in device.
	 * @length: Required length to be written in bytes.
	 * Return 0 on success, a negative error code otherwise.
	 */
	int (*write)(unsigned int offset, uintptr_t buffer, size_t length);

	/*
	 * Look for an offset to be added to the given offset.
	 *
	 * @base: Base address of the area.
	 * @offset: Offset in bytes to start read operation.
	 * @extra_offset: [out] Offset to be added to the previous offset.
	 * Return 0 on success, a negative error code otherwise.
	 */
	int (*seek)(uintptr_t base, unsigned int offset, size_t *extra_offset);
} io_mtd_ops_t;

typedef struct io_mtd_dev_spec {
	unsigned long long device_size;
	unsigned int erase_size;
	size_t offset;
	io_mtd_ops_t ops;
} io_mtd_dev_spec_t;

struct io_dev_connector;

int register_io_dev_mtd(const struct io_dev_connector **dev_con);

#endif /* IO_MTD_H */