blob: 1e9006662f79f42444fc2b182dfd90e6fe2c0110 [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 Jefferyb65bb4c2018-08-08 17:18:24 +093046void windows_close_current(struct mbox_context *context, bool set_bmc_event,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110047 uint8_t flags);
Andrew Jeffery5dc9f952018-08-08 17:21:34 +093048void window_reset(struct mbox_context *context, struct window_context *window);
Andrew Jefferyd6a74262018-08-08 17:25:01 +093049void windows_reset_all(struct mbox_context *context, bool set_bmc_event);
Andrew Jeffery9412f052018-08-08 17:25:47 +093050struct window_context *windows_find_oldest(struct mbox_context *context);
Andrew Jefferyd8c12e12018-08-08 17:26:31 +093051struct window_context *windows_find_largest(struct mbox_context *context);
Andrew Jeffery17c477a2018-08-08 17:27:19 +093052struct window_context *windows_search(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110053 uint32_t offset, bool exact);
Andrew Jefferyebbfce52018-08-08 17:29:45 +093054int windows_create_map(struct mbox_context *context,
Suraj Jitindar Singhe39c9162017-03-28 10:47:43 +110055 struct window_context **this_window,
56 uint32_t offset, bool exact);
57
Andrew Jefferya66bcea2018-08-08 17:03:10 +093058#endif /* WINDOWS_H */