blob: 10d76f99829f4fe2983ec53b37be46af9719a4d7 [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 Jeffery651ff9d2018-08-08 17:06:11 +09307#define WINDOWS_NO_FLUSH false
8#define WINDOWS_WITH_FLUSH true
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +11009
Andrew Jeffery26558db2018-08-10 00:22:38 +093010struct mbox_context;
11
12/* Window Dirty/Erase bytemap masks */
13#define WINDOW_CLEAN 0x00
14#define WINDOW_DIRTY 0x01
15#define WINDOW_ERASED 0x02
16
17#define FLASH_OFFSET_UNINIT 0xFFFFFFFF
18
19struct window_context {
20 void *mem; /* Portion of Reserved Memory Region */
21 uint32_t flash_offset; /* Flash area the window maps (bytes) */
22 uint32_t size; /* Window Size (bytes) power-of-2 */
23 uint8_t *dirty_bmap; /* Bytemap of the dirty/erased state */
24 uint32_t age; /* Used for LRU eviction scheme */
25};
26
27struct window_list {
28 uint32_t num;
29 uint32_t max_age;
30 uint32_t default_size;
31 struct window_context *window;
32};
Andrew Jeffery2f342ef2017-04-11 13:20:43 +093033
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110034/* Initialisation Functions */
Andrew Jefferyc1a67fa2018-08-08 17:07:38 +093035int windows_init(struct mbox_context *context);
Andrew Jefferyf5f51422018-08-08 17:08:33 +093036void windows_free(struct mbox_context *context);
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110037/* Write From Window Functions */
Andrew Jeffery3200c072018-08-08 17:12:03 +093038int window_flush_v1(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110039 uint32_t offset_bytes, uint32_t count_bytes);
Andrew Jeffery3200c072018-08-08 17:12:03 +093040int window_flush(struct mbox_context *context, uint32_t offset,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110041 uint32_t count, uint8_t type);
42/* Window Management Functions */
Andrew Jeffery348ea792018-08-08 17:13:53 +093043void windows_alloc_dirty_bytemap(struct mbox_context *context);
Andrew Jeffery7d5ada62018-08-08 17:16:16 +093044int window_set_bytemap(struct mbox_context *context, struct window_context *cur,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110045 uint32_t offset, uint32_t size, uint8_t val);
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093046void windows_close_current(struct mbox_context *context, uint8_t flags);
Andrew Jeffery5dc9f952018-08-08 17:21:34 +093047void window_reset(struct mbox_context *context, struct window_context *window);
Andrew Jeffery2ebfd202018-08-20 11:46:28 +093048bool windows_reset_all(struct mbox_context *context);
Andrew Jeffery9412f052018-08-08 17:25:47 +093049struct window_context *windows_find_oldest(struct mbox_context *context);
Andrew Jefferyd8c12e12018-08-08 17:26:31 +093050struct window_context *windows_find_largest(struct mbox_context *context);
Andrew Jeffery17c477a2018-08-08 17:27:19 +093051struct window_context *windows_search(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110052 uint32_t offset, bool exact);
Andrew Jefferyebbfce52018-08-08 17:29:45 +093053int windows_create_map(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110054 struct window_context **this_window,
55 uint32_t offset, bool exact);
56
Andrew Jefferya66bcea2018-08-08 17:03:10 +093057#endif /* WINDOWS_H */