blob: 57555fda4fb7b3826b56308c4e9f387fa7001f28 [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
Sughosh Ganu8231d032025-03-17 14:04:02 +053010#include <blk.h>
Masahisa Kojimaaaef1ae2023-11-10 13:25:36 +090011#include <dm/lists.h>
12
13/**
14 * struct blkmap - Block map
15 *
16 * Data associated with a blkmap.
17 *
18 * @label: Human readable name of this blkmap
19 * @blk: Underlying block device
20 * @slices: List of slices associated with this blkmap
21 */
22struct blkmap {
23 char *label;
24 struct udevice *blk;
25 struct list_head slices;
26};
27
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +010028/**
Tobias Waldekranzf7241a42023-02-16 16:33:51 +010029 * blkmap_map_linear() - Map region of other block device
30 *
31 * @dev: Blkmap to create the mapping on
32 * @blknr: Start block number of the mapping
33 * @blkcnt: Number of blocks to map
34 * @lblk: The target block device of the mapping
35 * @lblknr: The start block number of the target device
36 * Returns: 0 on success, negative error code on failure
37 */
38int blkmap_map_linear(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
39 struct udevice *lblk, lbaint_t lblknr);
40
41/**
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010042 * blkmap_map_mem() - Map region of memory
43 *
44 * @dev: Blkmap to create the mapping on
45 * @blknr: Start block number of the mapping
46 * @blkcnt: Number of blocks to map
47 * @addr: The target memory address of the mapping
48 * Returns: 0 on success, negative error code on failure
49 */
50int blkmap_map_mem(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
51 void *addr);
52
53/**
54 * blkmap_map_pmem() - Map region of physical memory
55 *
56 * Ensures that a valid physical to virtual memory mapping for the
57 * requested region is valid for the lifetime of the mapping, on
58 * architectures that require it (sandbox).
59 *
60 * @dev: Blkmap to create the mapping on
61 * @blknr: Start block number of the mapping
62 * @blkcnt: Number of blocks to map
63 * @paddr: The target physical memory address of the mapping
Sughosh Ganucf377222025-03-17 14:04:01 +053064 * @preserve: Mapping intended to be preserved for subsequent stages,
65 * like the OS (e.g. ISO installer)
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010066 * Returns: 0 on success, negative error code on failure
67 */
68int blkmap_map_pmem(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt,
Sughosh Ganucf377222025-03-17 14:04:01 +053069 phys_addr_t paddr, bool preserve);
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010070
Tobias Waldekranz5f7f8222023-02-16 16:33:50 +010071/**
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +010072 * blkmap_from_label() - Find blkmap from label
73 *
74 * @label: Label of the requested blkmap
75 * Returns: A pointer to the blkmap on success, NULL on failure
76 */
77struct udevice *blkmap_from_label(const char *label);
78
79/**
80 * blkmap_create() - Create new blkmap
81 *
82 * @label: Label of the new blkmap
83 * @devp: If not NULL, updated with the address of the resulting device
84 * Returns: 0 on success, negative error code on failure
85 */
86int blkmap_create(const char *label, struct udevice **devp);
87
88/**
89 * blkmap_destroy() - Destroy blkmap
90 *
91 * @dev: The blkmap to be destroyed
92 * Returns: 0 on success, negative error code on failure
93 */
94int blkmap_destroy(struct udevice *dev);
95
Masahisa Kojimaaaef1ae2023-11-10 13:25:36 +090096/**
97 * blkmap_create_ramdisk() - Create new ramdisk with blkmap
98 *
99 * @label: Label of the new blkmap
100 * @image_addr: Target memory start address of this mapping
101 * @image_size: Target memory size of this mapping
102 * @devp: Updated with the address of the created blkmap device
103 * Returns: 0 on success, negative error code on failure
104 */
105int blkmap_create_ramdisk(const char *label, ulong image_addr, ulong image_size,
106 struct udevice **devp);
107
Sughosh Ganu8231d032025-03-17 14:04:02 +0530108/**
109 * blkmap_get_preserved_pmem_slices() - Look for memory mapped preserved slices
110 * @cb: Callback function to call for the blkmap slice
111 * @ctx: Argument to be passed to the callback function
112 *
113 * The function is used to iterate through all the blkmap slices, looking
114 * specifically for memory mapped blkmap mapping which has been
115 * created with the preserve attribute. The function looks for such slices
116 * with the relevant attributes and then calls the callback function which
117 * then does additional configuration as needed. The callback function is
118 * invoked for all the discovered slices, unless there is an error returned
119 * by the callback, in which case the function returns that error.
120 *
121 * The callback function has the following arguments
122 * @ctx: Argument to be passed to the callback function
123 * @addr: Start address of the memory mapped slice
124 * @size: Size of the memory mapped slice
125 *
126 * Typically, the callback will perform some configuration needed for the
127 * information passed on to it. An example of this would be setting up the
128 * pmem node in a device-tree(passed through the ctx argument) with the
129 * parameters passed on to the callback.
130 *
131 * Return: 0 on success, negative error on failure
132 */
133int blkmap_get_preserved_pmem_slices(int (*cb)(void *ctx, u64 addr,
134 u64 size), void *ctx);
135
Tobias Waldekranz4f76dd32023-02-16 16:33:49 +0100136#endif /* _BLKMAP_H */