blob: c32f83baad13ab72762c1a691b9ceb8d695b1ee8 [file] [log] [blame]
Andrew Jeffery4fe996c2018-02-27 12:16:48 +10301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11003
Andrew Jefferya66bcea2018-08-08 17:03:10 +09304#ifndef WINDOWS_H
5#define WINDOWS_H
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11006
Andrew Jefferyb5fd0a42018-08-28 17:00:36 +09307#include <stdbool.h>
8
Andrew Jeffery651ff9d2018-08-08 17:06:11 +09309#define WINDOWS_NO_FLUSH false
10#define WINDOWS_WITH_FLUSH true
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110011
Andrew Jeffery26558db2018-08-10 00:22:38 +093012struct mbox_context;
13
14/* Window Dirty/Erase bytemap masks */
15#define WINDOW_CLEAN 0x00
16#define WINDOW_DIRTY 0x01
17#define WINDOW_ERASED 0x02
18
19#define FLASH_OFFSET_UNINIT 0xFFFFFFFF
20
21struct window_context {
22 void *mem; /* Portion of Reserved Memory Region */
23 uint32_t flash_offset; /* Flash area the window maps (bytes) */
24 uint32_t size; /* Window Size (bytes) power-of-2 */
25 uint8_t *dirty_bmap; /* Bytemap of the dirty/erased state */
26 uint32_t age; /* Used for LRU eviction scheme */
27};
28
29struct window_list {
30 uint32_t num;
31 uint32_t max_age;
32 uint32_t default_size;
33 struct window_context *window;
34};
Andrew Jeffery2f342ef2017-04-11 13:20:43 +093035
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110036/* Initialisation Functions */
Andrew Jefferyc1a67fa2018-08-08 17:07:38 +093037int windows_init(struct mbox_context *context);
Andrew Jefferyf5f51422018-08-08 17:08:33 +093038void windows_free(struct mbox_context *context);
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110039/* Write From Window Functions */
Andrew Jeffery3200c072018-08-08 17:12:03 +093040int window_flush_v1(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110041 uint32_t offset_bytes, uint32_t count_bytes);
Andrew Jeffery3200c072018-08-08 17:12:03 +093042int window_flush(struct mbox_context *context, uint32_t offset,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110043 uint32_t count, uint8_t type);
44/* Window Management Functions */
Andrew Jeffery348ea792018-08-08 17:13:53 +093045void windows_alloc_dirty_bytemap(struct mbox_context *context);
Andrew Jeffery7d5ada62018-08-08 17:16:16 +093046int window_set_bytemap(struct mbox_context *context, struct window_context *cur,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110047 uint32_t offset, uint32_t size, uint8_t val);
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093048void windows_close_current(struct mbox_context *context, uint8_t flags);
Andrew Jeffery5dc9f952018-08-08 17:21:34 +093049void window_reset(struct mbox_context *context, struct window_context *window);
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093050bool windows_reset_all(struct mbox_context *context);
Andrew Jeffery9412f052018-08-08 17:25:47 +093051struct window_context *windows_find_oldest(struct mbox_context *context);
Andrew Jefferyd8c12e12018-08-08 17:26:31 +093052struct window_context *windows_find_largest(struct mbox_context *context);
Andrew Jeffery17c477a2018-08-08 17:27:19 +093053struct window_context *windows_search(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110054 uint32_t offset, bool exact);
Andrew Jefferyebbfce52018-08-08 17:29:45 +093055int windows_create_map(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110056 struct window_context **this_window,
57 uint32_t offset, bool exact);
58
Andrew Jefferya66bcea2018-08-08 17:03:10 +093059#endif /* WINDOWS_H */