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 | |
Andrew Jeffery | a66bcea | 2018-08-08 17:03:10 +0930 | [diff] [blame] | 4 | #ifndef WINDOWS_H |
| 5 | #define WINDOWS_H |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 6 | |
Andrew Jeffery | 651ff9d | 2018-08-08 17:06:11 +0930 | [diff] [blame] | 7 | #define WINDOWS_NO_FLUSH false |
| 8 | #define WINDOWS_WITH_FLUSH true |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 9 | |
Andrew Jeffery | 26558db | 2018-08-10 00:22:38 +0930 | [diff] [blame] | 10 | struct 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 | |
| 19 | struct 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 | |
| 27 | struct window_list { |
| 28 | uint32_t num; |
| 29 | uint32_t max_age; |
| 30 | uint32_t default_size; |
| 31 | struct window_context *window; |
| 32 | }; |
Andrew Jeffery | 2f342ef | 2017-04-11 13:20:43 +0930 | [diff] [blame] | 33 | |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 34 | /* Initialisation Functions */ |
Andrew Jeffery | c1a67fa | 2018-08-08 17:07:38 +0930 | [diff] [blame] | 35 | int windows_init(struct mbox_context *context); |
Andrew Jeffery | f5f5142 | 2018-08-08 17:08:33 +0930 | [diff] [blame] | 36 | void windows_free(struct mbox_context *context); |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 37 | /* Write From Window Functions */ |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 38 | int window_flush_v1(struct mbox_context *context, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 39 | uint32_t offset_bytes, uint32_t count_bytes); |
Andrew Jeffery | 3200c07 | 2018-08-08 17:12:03 +0930 | [diff] [blame] | 40 | int window_flush(struct mbox_context *context, uint32_t offset, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 41 | uint32_t count, uint8_t type); |
| 42 | /* Window Management Functions */ |
Andrew Jeffery | 348ea79 | 2018-08-08 17:13:53 +0930 | [diff] [blame] | 43 | void windows_alloc_dirty_bytemap(struct mbox_context *context); |
Andrew Jeffery | 7d5ada6 | 2018-08-08 17:16:16 +0930 | [diff] [blame] | 44 | 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] | 45 | uint32_t offset, uint32_t size, uint8_t val); |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 46 | void windows_close_current(struct mbox_context *context, uint8_t flags); |
Andrew Jeffery | 5dc9f95 | 2018-08-08 17:21:34 +0930 | [diff] [blame] | 47 | void window_reset(struct mbox_context *context, struct window_context *window); |
Andrew Jeffery | 2ebfd20 | 2018-08-20 11:46:28 +0930 | [diff] [blame] | 48 | bool windows_reset_all(struct mbox_context *context); |
Andrew Jeffery | 9412f05 | 2018-08-08 17:25:47 +0930 | [diff] [blame] | 49 | struct window_context *windows_find_oldest(struct mbox_context *context); |
Andrew Jeffery | d8c12e1 | 2018-08-08 17:26:31 +0930 | [diff] [blame] | 50 | struct window_context *windows_find_largest(struct mbox_context *context); |
Andrew Jeffery | 17c477a | 2018-08-08 17:27:19 +0930 | [diff] [blame] | 51 | struct window_context *windows_search(struct mbox_context *context, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 52 | uint32_t offset, bool exact); |
Andrew Jeffery | ebbfce5 | 2018-08-08 17:29:45 +0930 | [diff] [blame] | 53 | int windows_create_map(struct mbox_context *context, |
Suraj Jitindar Singh | e39c916 | 2017-03-28 10:47:43 +1100 | [diff] [blame] | 54 | struct window_context **this_window, |
| 55 | uint32_t offset, bool exact); |
| 56 | |
Andrew Jeffery | a66bcea | 2018-08-08 17:03:10 +0930 | [diff] [blame] | 57 | #endif /* WINDOWS_H */ |