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