Andrew Jeffery | 4fe996c | 2018-02-27 12:16:48 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 3 | |
| 4 | #define _GNU_SOURCE |
| 5 | #include <assert.h> |
| 6 | #include <errno.h> |
| 7 | #include <fcntl.h> |
| 8 | #include <getopt.h> |
| 9 | #include <limits.h> |
| 10 | #include <poll.h> |
| 11 | #include <stdbool.h> |
| 12 | #include <stdint.h> |
| 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
| 15 | #include <string.h> |
| 16 | #include <syslog.h> |
| 17 | #include <signal.h> |
| 18 | #include <sys/ioctl.h> |
| 19 | #include <sys/mman.h> |
| 20 | #include <sys/stat.h> |
| 21 | #include <sys/timerfd.h> |
| 22 | #include <sys/types.h> |
| 23 | #include <time.h> |
| 24 | #include <unistd.h> |
| 25 | #include <inttypes.h> |
| 26 | #include <mtd/mtd-abi.h> |
| 27 | |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 28 | #include "mboxd.h" |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 29 | #include "common.h" |
Andrew Jeffery | 457a6e5 | 2018-08-08 11:21:08 +0930 | [diff] [blame] | 30 | #include "transport_mbox.h" |
Andrew Jeffery | f593b1b | 2018-08-08 11:01:04 +0930 | [diff] [blame] | 31 | #include "windows.h" |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 32 | #include "backend.h" |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 33 | |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 34 | #pragma GCC diagnostic push |
| 35 | #pragma GCC diagnostic ignored "-Wpointer-arith" |
| 36 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 37 | /* Initialisation Functions */ |
| 38 | |
| 39 | /* |
| 40 | * init_window_state() - Initialise a new window to a known state |
| 41 | * @window: The window to initialise |
| 42 | * @size: The size of the window |
| 43 | */ |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 44 | static void init_window_state(struct window_context *window, uint32_t size) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 45 | { |
| 46 | window->mem = NULL; |
| 47 | window->flash_offset = FLASH_OFFSET_UNINIT; |
| 48 | window->size = size; |
| 49 | window->dirty_bmap = NULL; |
| 50 | window->age = 0; |
| 51 | } |
| 52 | |
| 53 | /* |
| 54 | * init_window_mem() - Divide the reserved memory region among the windows |
| 55 | * @context: The mbox context pointer |
| 56 | * |
| 57 | * Return: 0 on success otherwise negative error code |
| 58 | */ |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 59 | static int init_window_mem(struct mbox_context *context) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 60 | { |
| 61 | void *mem_location = context->mem; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 62 | size_t i; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * Carve up the reserved memory region and allocate it to each of the |
| 66 | * windows. The windows are placed one after the other in ascending |
| 67 | * order, so the first window will be first in memory and so on. We |
| 68 | * shouldn't have allocated more windows than we have memory, but if we |
| 69 | * did we will error out here |
| 70 | */ |
| 71 | for (i = 0; i < context->windows.num; i++) { |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 72 | uint32_t size = context->windows.window[i].size; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 73 | MSG_DBG("Window %zd @ %p for size 0x%.8x\n", i, |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 74 | mem_location, size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 75 | context->windows.window[i].mem = mem_location; |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 76 | mem_location += size; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 77 | if (mem_location > (context->mem + context->mem_size)) { |
| 78 | /* Tried to allocate window past the end of memory */ |
| 79 | MSG_ERR("Total size of windows exceeds reserved mem\n"); |
| 80 | MSG_ERR("Try smaller or fewer windows\n"); |
| 81 | MSG_ERR("Mem size: 0x%.8x\n", context->mem_size); |
| 82 | return -1; |
| 83 | } |
| 84 | } |
| 85 | |
| 86 | return 0; |
| 87 | } |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 88 | /* |
Andrew Jeffery | c1a67fa | 2018-08-08 17:07:38 +0930 | [diff] [blame] | 89 | * windows_init() - Initalise the window cache |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 90 | * @context: The mbox context pointer |
| 91 | * |
| 92 | * Return: 0 on success otherwise negative |
| 93 | */ |
Andrew Jeffery | c1a67fa | 2018-08-08 17:07:38 +0930 | [diff] [blame] | 94 | int windows_init(struct mbox_context *context) |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 95 | { |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 96 | size_t i; |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 97 | |
| 98 | /* Check if window size and number set - otherwise set to default */ |
| 99 | if (!context->windows.default_size) { |
| 100 | /* Default to 1MB windows */ |
| 101 | context->windows.default_size = 1 << 20; |
| 102 | } |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 103 | MSG_INFO("Window size: 0x%.8x\n", context->windows.default_size); |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 104 | if (!context->windows.num) { |
| 105 | /* Use the entire reserved memory region by default */ |
| 106 | context->windows.num = context->mem_size / |
| 107 | context->windows.default_size; |
| 108 | } |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 109 | MSG_INFO("Number of windows: %d\n", context->windows.num); |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 110 | |
| 111 | context->windows.window = calloc(context->windows.num, |
| 112 | sizeof(*context->windows.window)); |
| 113 | if (!context->windows.window) { |
| 114 | MSG_ERR("Memory allocation failed\n"); |
| 115 | return -1; |
| 116 | } |
| 117 | |
| 118 | for (i = 0; i < context->windows.num; i++) { |
| 119 | init_window_state(&context->windows.window[i], |
| 120 | context->windows.default_size); |
| 121 | } |
| 122 | |
| 123 | return init_window_mem(context); |
| 124 | } |
| 125 | |
| 126 | /* |
Andrew Jeffery | f5f5142 | 2018-08-08 17:08:33 +0930 | [diff] [blame] | 127 | * windows_free() - Free the window cache |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 128 | * @context: The mbox context pointer |
| 129 | */ |
Andrew Jeffery | f5f5142 | 2018-08-08 17:08:33 +0930 | [diff] [blame] | 130 | void windows_free(struct mbox_context *context) |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 131 | { |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 132 | size_t i; |
Suraj Jitindar Singh | c29172e | 2017-04-12 14:26:47 +1000 | [diff] [blame] | 133 | |
| 134 | /* Check window cache has actually been allocated */ |
| 135 | if (context->windows.window) { |
| 136 | for (i = 0; i < context->windows.num; i++) { |
| 137 | free(context->windows.window[i].dirty_bmap); |
| 138 | } |
| 139 | free(context->windows.window); |
| 140 | } |
| 141 | } |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 142 | |
| 143 | /* Write from Window Functions */ |
| 144 | |
| 145 | /* |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 146 | * window_flush_v1() - Handle writing when erase and block size differ |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 147 | * @context: The mbox context pointer |
| 148 | * @offset_bytes: The offset in the current window to write from (bytes) |
| 149 | * @count_bytes: Number of bytes to write |
| 150 | * |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 151 | * Handle a window_flush for dirty memory when block_size is less than the |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 152 | * flash erase size |
| 153 | * This requires us to be a bit careful because we might have to erase more |
| 154 | * than we want to write which could result in data loss if we don't have the |
| 155 | * entire portion of flash to be erased already saved in memory (for us to |
| 156 | * write back after the erase) |
| 157 | * |
| 158 | * Return: 0 on success otherwise negative error code |
| 159 | */ |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 160 | int window_flush_v1(struct mbox_context *context, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 161 | uint32_t offset_bytes, uint32_t count_bytes) |
| 162 | { |
| 163 | int rc; |
| 164 | uint32_t flash_offset; |
| 165 | struct window_context low_mem = { 0 }, high_mem = { 0 }; |
| 166 | |
| 167 | /* Find where in phys flash this is based on the window.flash_offset */ |
| 168 | flash_offset = context->current->flash_offset + offset_bytes; |
| 169 | |
| 170 | /* |
| 171 | * low_mem.flash_offset = erase boundary below where we're writing |
| 172 | * low_mem.size = size from low_mem.flash_offset to where we're writing |
| 173 | * |
| 174 | * high_mem.flash_offset = end of where we're writing |
| 175 | * high_mem.size = size from end of where we're writing to next erase |
| 176 | * boundary |
| 177 | */ |
| 178 | low_mem.flash_offset = align_down(flash_offset, |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 179 | 1 << context->backend.erase_size_shift); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 180 | low_mem.size = flash_offset - low_mem.flash_offset; |
| 181 | high_mem.flash_offset = flash_offset + count_bytes; |
| 182 | high_mem.size = align_up(high_mem.flash_offset, |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 183 | 1 << context->backend.erase_size_shift) - |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 184 | high_mem.flash_offset; |
| 185 | |
| 186 | /* |
| 187 | * Check if we already have a copy of the required flash areas in |
| 188 | * memory as part of the existing window |
| 189 | */ |
| 190 | if (low_mem.flash_offset < context->current->flash_offset) { |
| 191 | /* Before the start of our current window */ |
| 192 | low_mem.mem = malloc(low_mem.size); |
| 193 | if (!low_mem.mem) { |
| 194 | MSG_ERR("Unable to allocate memory\n"); |
Andrew Jeffery | 8eab215 | 2018-08-09 23:47:29 +0930 | [diff] [blame] | 195 | return -ENOMEM; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 196 | } |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 197 | rc = backend_copy(&context->backend, low_mem.flash_offset, |
| 198 | low_mem.mem, low_mem.size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 199 | if (rc < 0) { |
| 200 | goto out; |
| 201 | } |
| 202 | } |
| 203 | if ((high_mem.flash_offset + high_mem.size) > |
| 204 | (context->current->flash_offset + context->current->size)) { |
| 205 | /* After the end of our current window */ |
| 206 | high_mem.mem = malloc(high_mem.size); |
| 207 | if (!high_mem.mem) { |
| 208 | MSG_ERR("Unable to allocate memory\n"); |
Andrew Jeffery | 8eab215 | 2018-08-09 23:47:29 +0930 | [diff] [blame] | 209 | rc = -ENOMEM; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 210 | goto out; |
| 211 | } |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 212 | rc = backend_copy(&context->backend, high_mem.flash_offset, |
| 213 | high_mem.mem, high_mem.size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 214 | if (rc < 0) { |
| 215 | goto out; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | /* |
| 220 | * We need to erase the flash from low_mem.flash_offset-> |
| 221 | * high_mem.flash_offset + high_mem.size |
| 222 | */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 223 | rc = backend_erase(&context->backend, low_mem.flash_offset, |
| 224 | (high_mem.flash_offset - low_mem.flash_offset) + |
| 225 | high_mem.size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 226 | if (rc < 0) { |
| 227 | MSG_ERR("Couldn't erase flash\n"); |
| 228 | goto out; |
| 229 | } |
| 230 | |
| 231 | /* Write back over the erased area */ |
| 232 | if (low_mem.mem) { |
| 233 | /* Exceed window at the start */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 234 | rc = backend_write(&context->backend, low_mem.flash_offset, |
| 235 | low_mem.mem, low_mem.size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 236 | if (rc < 0) { |
| 237 | goto out; |
| 238 | } |
| 239 | } |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 240 | rc = backend_write(&context->backend, flash_offset, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 241 | context->current->mem + offset_bytes, count_bytes); |
| 242 | if (rc < 0) { |
| 243 | goto out; |
| 244 | } |
| 245 | /* |
| 246 | * We still need to write the last little bit that we erased - it's |
| 247 | * either in the current window or the high_mem window. |
| 248 | */ |
| 249 | if (high_mem.mem) { |
| 250 | /* Exceed window at the end */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 251 | rc = backend_write(&context->backend, high_mem.flash_offset, |
| 252 | high_mem.mem, high_mem.size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 253 | if (rc < 0) { |
| 254 | goto out; |
| 255 | } |
| 256 | } else { |
| 257 | /* Write from the current window - it's atleast that big */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 258 | rc = backend_write(&context->backend, high_mem.flash_offset, |
| 259 | context->current->mem + offset_bytes + |
| 260 | count_bytes, high_mem.size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 261 | if (rc < 0) { |
| 262 | goto out; |
| 263 | } |
| 264 | } |
| 265 | |
| 266 | out: |
| 267 | free(low_mem.mem); |
| 268 | free(high_mem.mem); |
| 269 | return rc; |
| 270 | } |
| 271 | |
| 272 | /* |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 273 | * window_flush() - Write back to the flash from the current window |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 274 | * @context: The mbox context pointer |
| 275 | * @offset_bytes: The offset in the current window to write from (blocks) |
| 276 | * @count_bytes: Number of blocks to write |
| 277 | * @type: Whether this is an erase & write or just an erase |
| 278 | * |
| 279 | * Return: 0 on success otherwise negative error code |
| 280 | */ |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 281 | int window_flush(struct mbox_context *context, uint32_t offset, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 282 | uint32_t count, uint8_t type) |
| 283 | { |
| 284 | int rc; |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 285 | uint32_t flash_offset, count_bytes = count << context->backend.block_size_shift; |
| 286 | uint32_t offset_bytes = offset << context->backend.block_size_shift; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 287 | |
| 288 | switch (type) { |
| 289 | case WINDOW_ERASED: /* >= V2 ONLY -> block_size == erasesize */ |
| 290 | flash_offset = context->current->flash_offset + offset_bytes; |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 291 | rc = backend_erase(&context->backend, flash_offset, |
| 292 | count_bytes); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 293 | if (rc < 0) { |
| 294 | MSG_ERR("Couldn't erase flash\n"); |
| 295 | return rc; |
| 296 | } |
| 297 | break; |
| 298 | case WINDOW_DIRTY: |
| 299 | /* |
| 300 | * For protocol V1, block_size may be smaller than erase size |
| 301 | * so we have a special function to make sure that we do this |
| 302 | * correctly without losing data. |
| 303 | */ |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 304 | if (context->backend.erase_size_shift != |
| 305 | context->backend.block_size_shift) { |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 306 | return window_flush_v1(context, offset_bytes, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 307 | count_bytes); |
| 308 | } |
| 309 | flash_offset = context->current->flash_offset + offset_bytes; |
| 310 | |
| 311 | /* Erase the flash */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 312 | rc = backend_erase(&context->backend, flash_offset, |
| 313 | count_bytes); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 314 | if (rc < 0) { |
| 315 | return rc; |
| 316 | } |
| 317 | |
| 318 | /* Write to the erased flash */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 319 | rc = backend_write(&context->backend, flash_offset, |
| 320 | context->current->mem + offset_bytes, |
| 321 | count_bytes); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 322 | if (rc < 0) { |
| 323 | return rc; |
| 324 | } |
| 325 | |
| 326 | break; |
| 327 | default: |
| 328 | /* We shouldn't be able to get here */ |
| 329 | MSG_ERR("Write from window with invalid type: %d\n", type); |
Andrew Jeffery | 8eab215 | 2018-08-09 23:47:29 +0930 | [diff] [blame] | 330 | return -EPERM; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 331 | } |
| 332 | |
| 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | /* Window Management Functions */ |
| 337 | |
| 338 | /* |
Andrew Jeffery | 348ea79 | 2018-08-08 17:13:53 +0930 | [diff] [blame] | 339 | * windows_alloc_dirty_bytemap() - (re)allocate all the window dirty bytemaps |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 340 | * @context: The mbox context pointer |
| 341 | */ |
Andrew Jeffery | 348ea79 | 2018-08-08 17:13:53 +0930 | [diff] [blame] | 342 | void windows_alloc_dirty_bytemap(struct mbox_context *context) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 343 | { |
| 344 | struct window_context *cur; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 345 | size_t i; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 346 | |
| 347 | for (i = 0; i < context->windows.num; i++) { |
| 348 | cur = &context->windows.window[i]; |
| 349 | /* There may already be one allocated */ |
| 350 | free(cur->dirty_bmap); |
| 351 | /* Allocate the new one */ |
Andrew Jeffery | 41c337e | 2018-08-13 23:30:16 +0930 | [diff] [blame] | 352 | cur->dirty_bmap = calloc((context->windows.default_size >> |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 353 | context->backend.block_size_shift), |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 354 | sizeof(*cur->dirty_bmap)); |
| 355 | } |
| 356 | } |
| 357 | |
| 358 | /* |
Andrew Jeffery | 7d5ada6 | 2018-08-08 17:16:16 +0930 | [diff] [blame] | 359 | * window_set_bytemap() - Set the window bytemap |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 360 | * @context: The mbox context pointer |
| 361 | * @cur: The window to set the bytemap of |
| 362 | * @offset: Where in the window to set the bytemap (blocks) |
| 363 | * @size: The number of blocks to set |
| 364 | * @val: The value to set the bytemap to |
| 365 | * |
| 366 | * Return: 0 on success otherwise negative error code |
| 367 | */ |
Andrew Jeffery | 7d5ada6 | 2018-08-08 17:16:16 +0930 | [diff] [blame] | 368 | int window_set_bytemap(struct mbox_context *context, struct window_context *cur, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 369 | uint32_t offset, uint32_t size, uint8_t val) |
| 370 | { |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 371 | if (offset + size > (cur->size >> context->backend.block_size_shift)) { |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 372 | MSG_ERR("Tried to set window bytemap past end of window\n"); |
| 373 | MSG_ERR("Requested offset: 0x%x size: 0x%x window size: 0x%x\n", |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 374 | offset << context->backend.block_size_shift, |
| 375 | size << context->backend.block_size_shift, |
| 376 | cur->size << context->backend.block_size_shift); |
Andrew Jeffery | 6a0e2de | 2018-08-07 22:31:00 +0930 | [diff] [blame] | 377 | return -EACCES; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 378 | } |
| 379 | |
| 380 | memset(cur->dirty_bmap + offset, val, size); |
| 381 | return 0; |
| 382 | } |
| 383 | |
| 384 | /* |
Andrew Jeffery | b65bb4c | 2018-08-08 17:18:24 +0930 | [diff] [blame] | 385 | * windows_close_current() - Close the current (active) window |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 386 | * @context: The mbox context pointer |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 387 | * @flags: Flags as defined for a close command in the protocol |
| 388 | * |
| 389 | * This closes the current window. If the host has requested the current window |
| 390 | * be closed then we don't need to set the bmc event bit |
| 391 | * (set_bmc_event == false), otherwise if the current window has been closed |
| 392 | * without the host requesting it the bmc event bit must be set to indicate this |
| 393 | * to the host (set_bmc_event == true). |
| 394 | */ |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 395 | void windows_close_current(struct mbox_context *context, uint8_t flags) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 396 | { |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 397 | MSG_DBG("Close current window, flags: 0x%.2x\n", flags); |
| 398 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 399 | if (flags & FLAGS_SHORT_LIFETIME) { |
| 400 | context->current->age = 0; |
| 401 | } |
| 402 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 403 | context->current = NULL; |
| 404 | context->current_is_write = false; |
| 405 | } |
| 406 | |
| 407 | /* |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 408 | * window_reset() - Reset a window context to a well defined default state |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 409 | * @context: The mbox context pointer |
| 410 | * @window: The window to reset |
| 411 | */ |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 412 | void window_reset(struct mbox_context *context, struct window_context *window) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 413 | { |
| 414 | window->flash_offset = FLASH_OFFSET_UNINIT; |
| 415 | window->size = context->windows.default_size; |
| 416 | if (window->dirty_bmap) { /* Might not have been allocated */ |
Andrew Jeffery | 7d5ada6 | 2018-08-08 17:16:16 +0930 | [diff] [blame] | 417 | window_set_bytemap(context, window, 0, |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 418 | window->size >> context->backend.block_size_shift, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 419 | WINDOW_CLEAN); |
| 420 | } |
| 421 | window->age = 0; |
| 422 | } |
| 423 | |
| 424 | /* |
Andrew Jeffery | d6a7426 | 2018-08-08 17:25:01 +0930 | [diff] [blame] | 425 | * windows_reset_all() - Reset all windows to a well defined default state |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 426 | * @context: The mbox context pointer |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 427 | * |
| 428 | * @return True if there was a window open that was closed, false otherwise |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 429 | */ |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 430 | bool windows_reset_all(struct mbox_context *context) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 431 | { |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 432 | bool closed = context->current; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 433 | size_t i; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 434 | |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 435 | MSG_DBG("Resetting all windows\n"); |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 436 | |
| 437 | context->windows.max_age = 0; |
| 438 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 439 | /* We might have an open window which needs closing */ |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 440 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 441 | if (context->current) { |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 442 | windows_close_current(context, FLAGS_NONE); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 443 | } |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 444 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 445 | for (i = 0; i < context->windows.num; i++) { |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 446 | window_reset(context, &context->windows.window[i]); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 447 | } |
| 448 | |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 449 | return closed; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 450 | } |
| 451 | |
| 452 | /* |
Andrew Jeffery | 9412f05 | 2018-08-08 17:25:47 +0930 | [diff] [blame] | 453 | * windows_find_oldest() - Find the oldest (Least Recently Used) window |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 454 | * @context: The mbox context pointer |
| 455 | * |
| 456 | * Return: Pointer to the least recently used window |
| 457 | */ |
Andrew Jeffery | 9412f05 | 2018-08-08 17:25:47 +0930 | [diff] [blame] | 458 | struct window_context *windows_find_oldest(struct mbox_context *context) |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 459 | { |
| 460 | struct window_context *oldest = NULL, *cur; |
| 461 | uint32_t min_age = context->windows.max_age + 1; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 462 | size_t i; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 463 | |
| 464 | for (i = 0; i < context->windows.num; i++) { |
| 465 | cur = &context->windows.window[i]; |
| 466 | |
| 467 | if (cur->age < min_age) { |
| 468 | min_age = cur->age; |
| 469 | oldest = cur; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | return oldest; |
| 474 | } |
| 475 | |
| 476 | /* |
Andrew Jeffery | d8c12e1 | 2018-08-08 17:26:31 +0930 | [diff] [blame] | 477 | * windows_find_largest() - Find the largest window in the window cache |
Suraj Jitindar Singh | 5a3a066 | 2017-04-27 11:55:26 +1000 | [diff] [blame] | 478 | * @context: The mbox context pointer |
| 479 | * |
| 480 | * Return: The largest window |
| 481 | */ |
Andrew Jeffery | d8c12e1 | 2018-08-08 17:26:31 +0930 | [diff] [blame] | 482 | struct window_context *windows_find_largest(struct mbox_context *context) |
Suraj Jitindar Singh | 5a3a066 | 2017-04-27 11:55:26 +1000 | [diff] [blame] | 483 | { |
| 484 | struct window_context *largest = NULL, *cur; |
| 485 | uint32_t max_size = 0; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 486 | size_t i; |
Suraj Jitindar Singh | 5a3a066 | 2017-04-27 11:55:26 +1000 | [diff] [blame] | 487 | |
| 488 | for (i = 0; i < context->windows.num; i++) { |
| 489 | cur = &context->windows.window[i]; |
| 490 | |
| 491 | if (cur->size > max_size) { |
| 492 | max_size = cur->size; |
| 493 | largest = cur; |
| 494 | } |
| 495 | } |
| 496 | |
| 497 | return largest; |
| 498 | } |
| 499 | |
| 500 | /* |
Andrew Jeffery | 17c477a | 2018-08-08 17:27:19 +0930 | [diff] [blame] | 501 | * windows_search() - Search the window cache for a window containing offset |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 502 | * @context: The mbox context pointer |
| 503 | * @offset: Absolute flash offset to search for (bytes) |
| 504 | * @exact: If the window must exactly map the requested offset |
| 505 | * |
| 506 | * This will search the cache of windows for one containing the requested |
| 507 | * offset. For V1 of the protocol windows must exactly map the offset since we |
| 508 | * can't tell the host how much of its request we actually mapped and it will |
| 509 | * thus assume it can access window->size from the offset we give it. |
| 510 | * |
| 511 | * Return: Pointer to a window containing the requested offset otherwise |
| 512 | * NULL |
| 513 | */ |
Andrew Jeffery | 17c477a | 2018-08-08 17:27:19 +0930 | [diff] [blame] | 514 | struct window_context *windows_search(struct mbox_context *context, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 515 | uint32_t offset, bool exact) |
| 516 | { |
| 517 | struct window_context *cur; |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 518 | size_t i; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 519 | |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 520 | MSG_DBG("Searching for window which contains 0x%.8x %s\n", |
| 521 | offset, exact ? "exactly" : ""); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 522 | for (i = 0; i < context->windows.num; i++) { |
| 523 | cur = &context->windows.window[i]; |
| 524 | if (cur->flash_offset == FLASH_OFFSET_UNINIT) { |
| 525 | /* Uninitialised Window */ |
| 526 | if (offset == FLASH_OFFSET_UNINIT) { |
| 527 | return cur; |
| 528 | } |
| 529 | continue; |
| 530 | } |
| 531 | if ((offset >= cur->flash_offset) && |
| 532 | (offset < (cur->flash_offset + cur->size))) { |
| 533 | if (exact && (cur->flash_offset != offset)) { |
| 534 | continue; |
| 535 | } |
| 536 | /* This window contains the requested offset */ |
| 537 | cur->age = ++(context->windows.max_age); |
| 538 | return cur; |
| 539 | } |
| 540 | } |
| 541 | |
| 542 | return NULL; |
| 543 | } |
| 544 | |
| 545 | /* |
Andrew Jeffery | ebbfce5 | 2018-08-08 17:29:45 +0930 | [diff] [blame] | 546 | * windows_create_map() - Create a window mapping which maps the requested offset |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 547 | * @context: The mbox context pointer |
| 548 | * @this_window: A pointer to update to the "new" window |
| 549 | * @offset: Absolute flash offset to create a mapping for (bytes) |
| 550 | * @exact: If the window must exactly map the requested offset |
| 551 | * |
| 552 | * This is used to create a window mapping for the requested offset when there |
| 553 | * is no existing window in the cache which satisfies the offset. This involves |
| 554 | * choosing an existing window from the window cache to evict so we can use it |
| 555 | * to store the flash contents from the requested offset, we then point the |
| 556 | * caller to that window since it now maps their request. |
| 557 | * |
| 558 | * Return: 0 on success otherwise negative error code |
| 559 | */ |
Andrew Jeffery | ebbfce5 | 2018-08-08 17:29:45 +0930 | [diff] [blame] | 560 | int windows_create_map(struct mbox_context *context, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 561 | struct window_context **this_window, uint32_t offset, |
| 562 | bool exact) |
| 563 | { |
| 564 | struct window_context *cur = NULL; |
| 565 | int rc; |
| 566 | |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 567 | MSG_DBG("Creating window which maps 0x%.8x %s\n", offset, |
| 568 | exact ? "exactly" : ""); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 569 | |
| 570 | /* Search for an uninitialised window, use this before evicting */ |
Andrew Jeffery | 17c477a | 2018-08-08 17:27:19 +0930 | [diff] [blame] | 571 | cur = windows_search(context, FLASH_OFFSET_UNINIT, true); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 572 | |
| 573 | /* No uninitialised window found, we need to choose one to "evict" */ |
| 574 | if (!cur) { |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 575 | MSG_DBG("No uninitialised window, evicting one\n"); |
Andrew Jeffery | 9412f05 | 2018-08-08 17:25:47 +0930 | [diff] [blame] | 576 | cur = windows_find_oldest(context); |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 577 | window_reset(context, cur); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 578 | } |
| 579 | |
Alvin Wang | 8cef63e | 2019-10-15 23:23:38 +0800 | [diff] [blame] | 580 | /* Adjust the offset for alignment by the backend. It will help prevent the |
| 581 | * overlap. |
| 582 | */ |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 583 | if (!exact) { |
Alvin Wang | 8cef63e | 2019-10-15 23:23:38 +0800 | [diff] [blame] | 584 | if (backend_align_offset(&(context->backend), &offset, cur->size)) { |
| 585 | MSG_ERR("Can't adjust the offset by backend\n"); |
| 586 | } |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 587 | } |
| 588 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 589 | if (offset > context->backend.flash_size) { |
Andrew Jeffery | 3da0de6 | 2018-03-23 12:27:15 +1030 | [diff] [blame] | 590 | MSG_ERR("Tried to open read window past flash limit\n"); |
Andrew Jeffery | 8eab215 | 2018-08-09 23:47:29 +0930 | [diff] [blame] | 591 | return -EINVAL; |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 592 | } else if ((offset + cur->size) > context->backend.flash_size) { |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 593 | /* |
| 594 | * There is V1 skiboot implementations out there which don't |
| 595 | * mask offset with window size, meaning when we have |
| 596 | * window size == flash size we will never allow the host to |
| 597 | * open a window except at 0x0, which isn't always where the |
| 598 | * host requests it. Thus we have to ignore this check and just |
| 599 | * hope the host doesn't access past the end of the window |
| 600 | * (which it shouldn't) for V1 implementations to get around |
| 601 | * this. |
| 602 | */ |
| 603 | if (context->version == API_VERSION_1) { |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 604 | cur->size = align_down(context->backend.flash_size - offset, |
| 605 | 1 << context->backend.block_size_shift); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 606 | } else { |
Andrew Jeffery | 3da0de6 | 2018-03-23 12:27:15 +1030 | [diff] [blame] | 607 | /* |
| 608 | * Allow requests to exceed the flash size, but limit |
| 609 | * the response to the size of the flash. |
| 610 | */ |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 611 | cur->size = context->backend.flash_size - offset; |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 612 | } |
| 613 | } |
| 614 | |
| 615 | /* Copy from flash into the window buffer */ |
Andrew Jeffery | 0297e5b | 2019-03-14 16:36:27 +1030 | [diff] [blame] | 616 | rc = backend_copy(&context->backend, offset, cur->mem, cur->size); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 617 | if (rc < 0) { |
| 618 | /* We don't know how much we've copied -> better reset window */ |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 619 | window_reset(context, cur); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 620 | return rc; |
| 621 | } |
Andrew Jeffery | 1a3f843 | 2018-03-02 10:18:02 +1030 | [diff] [blame] | 622 | /* |
| 623 | * rc isn't guaranteed to be aligned, so align up |
| 624 | * |
| 625 | * FIXME: This should only be the case for the vpnor ToC now, so handle |
| 626 | * it there |
| 627 | */ |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 628 | cur->size = align_up(rc, (1ULL << context->backend.block_size_shift)); |
Suraj Jitindar Singh | 8493c33 | 2017-10-06 14:29:45 +1100 | [diff] [blame] | 629 | /* Would like a known value, pick 0xFF to it looks like erased flash */ |
| 630 | memset(cur->mem + rc, 0xFF, cur->size - rc); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 631 | |
| 632 | /* |
| 633 | * Since for V1 windows aren't constrained to start at multiples of |
| 634 | * window size it's possible that something already maps this offset. |
| 635 | * Reset any windows which map this offset to avoid coherency problems. |
| 636 | * We just have to check for anything which maps the start or the end |
| 637 | * of the window since all windows are the same size so another window |
| 638 | * cannot map just the middle of this window. |
| 639 | */ |
| 640 | if (context->version == API_VERSION_1) { |
| 641 | uint32_t i; |
| 642 | |
Suraj Jitindar Singh | 2851959 | 2017-04-27 14:48:58 +1000 | [diff] [blame] | 643 | MSG_DBG("Checking for window overlap\n"); |
| 644 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 645 | for (i = offset; i < (offset + cur->size); i += (cur->size - 1)) { |
| 646 | struct window_context *tmp = NULL; |
| 647 | do { |
Andrew Jeffery | 17c477a | 2018-08-08 17:27:19 +0930 | [diff] [blame] | 648 | tmp = windows_search(context, i, false); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 649 | if (tmp) { |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 650 | window_reset(context, tmp); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 651 | } |
| 652 | } while (tmp); |
| 653 | } |
| 654 | } |
| 655 | |
| 656 | /* Clear the bytemap of the window just loaded -> we know it's clean */ |
Andrew Jeffery | 7d5ada6 | 2018-08-08 17:16:16 +0930 | [diff] [blame] | 657 | window_set_bytemap(context, cur, 0, |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 658 | cur->size >> context->backend.block_size_shift, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 659 | WINDOW_CLEAN); |
| 660 | |
| 661 | /* Update so we know what's in the window */ |
| 662 | cur->flash_offset = offset; |
| 663 | cur->age = ++(context->windows.max_age); |
| 664 | *this_window = cur; |
| 665 | |
| 666 | return 0; |
| 667 | } |
Patrick Williams | 68a24c9 | 2023-07-25 12:02:16 -0500 | [diff] [blame] | 668 | |
| 669 | #pragma GCC diagnostic pop |