blob: 754d8671b010709c08340448375fc3003621ccae [file] [log] [blame]
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +01001/* SPDX-License-Identifier: GPL-2.0+ */
2/*
3 * Copyright (c) 2023 Addiva Elektronik
4 * Author: Tobias Waldekranz <tobias@waldekranz.com>
5 */
6
7#ifndef _BLKMAP_H
8#define _BLKMAP_H
9
Masahisa Kojimaaaef1ae2023-11-10 13:25:36 +090010#include <dm/lists.h>
11
12/**
13 * struct blkmap - Block map
14 *
15 * Data associated with a blkmap.
16 *
17 * @label: Human readable name of this blkmap
18 * @blk: Underlying block device
19 * @slices: List of slices associated with this blkmap
20 */
21struct blkmap {
22 char *label;
23 struct udevice *blk;
24 struct list_head slices;
25};
26
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +010027/**
Tobias Waldekranzf7241a42023-02-16 16:33:51 +010028 * blkmap_map_linear() - Map region of other block device
29 *
30 * @dev: Blkmap to create the mapping on
31 * @blknr: Start block number of the mapping
32 * @blkcnt: Number of blocks to map
33 * @lblk: The target block device of the mapping
34 * @lblknr: The start block number of the target device
35 * Returns: 0 on success, negative error code on failure
36 */
37int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
38 struct udevice *lblk, lbaint_t lblknr);
39
40/**
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010041 * blkmap_map_mem() - Map region of memory
42 *
43 * @dev: Blkmap to create the mapping on
44 * @blknr: Start block number of the mapping
45 * @blkcnt: Number of blocks to map
46 * @addr: The target memory address of the mapping
47 * Returns: 0 on success, negative error code on failure
48 */
49int blkmap_map_mem(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
50 void *addr);
51
52/**
53 * blkmap_map_pmem() - Map region of physical memory
54 *
55 * Ensures that a valid physical to virtual memory mapping for the
56 * requested region is valid for the lifetime of the mapping, on
57 * architectures that require it (sandbox).
58 *
59 * @dev: Blkmap to create the mapping on
60 * @blknr: Start block number of the mapping
61 * @blkcnt: Number of blocks to map
62 * @paddr: The target physical memory address of the mapping
Sughosh Ganucf377222025-03-17 14:04:01 +053063 * @preserve: Mapping intended to be preserved for subsequent stages,
64 * like the OS (e.g. ISO installer)
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010065 * Returns: 0 on success, negative error code on failure
66 */
67int blkmap_map_pmem(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
Sughosh Ganucf377222025-03-17 14:04:01 +053068 phys_addr_t paddr, bool preserve);
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010069
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010070/**
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +010071 * blkmap_from_label() - Find blkmap from label
72 *
73 * @label: Label of the requested blkmap
74 * Returns: A pointer to the blkmap on success, NULL on failure
75 */
76struct udevice *blkmap_from_label(const char *label);
77
78/**
79 * blkmap_create() - Create new blkmap
80 *
81 * @label: Label of the new blkmap
82 * @devp: If not NULL, updated with the address of the resulting device
83 * Returns: 0 on success, negative error code on failure
84 */
85int blkmap_create(const char *label, struct udevice **devp);
86
87/**
88 * blkmap_destroy() - Destroy blkmap
89 *
90 * @dev: The blkmap to be destroyed
91 * Returns: 0 on success, negative error code on failure
92 */
93int blkmap_destroy(struct udevice *dev);
94
Masahisa Kojimaaaef1ae2023-11-10 13:25:36 +090095/**
96 * blkmap_create_ramdisk() - Create new ramdisk with blkmap
97 *
98 * @label: Label of the new blkmap
99 * @image_addr: Target memory start address of this mapping
100 * @image_size: Target memory size of this mapping
101 * @devp: Updated with the address of the created blkmap device
102 * Returns: 0 on success, negative error code on failure
103 */
104int blkmap_create_ramdisk(const char *label, ulong image_addr, ulong image_size,
105 struct udevice **devp);
106
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +0100107#endif /* _BLKMAP_H */