xref: /openbmc/hiomapd/windows.h (revision f1e547c7)
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright (C) 2018 IBM Corp. */
3 
4 #ifndef WINDOWS_H
5 #define WINDOWS_H
6 
7 #include <stdbool.h>
8 
9 #define WINDOWS_NO_FLUSH	false
10 #define WINDOWS_WITH_FLUSH	true
11 
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 };
35 
36 /* Initialisation Functions */
37 int windows_init(struct mbox_context *context);
38 void windows_free(struct mbox_context *context);
39 /* Write From Window Functions */
40 int window_flush_v1(struct mbox_context *context,
41 			 uint32_t offset_bytes, uint32_t count_bytes);
42 int window_flush(struct mbox_context *context, uint32_t offset,
43 		      uint32_t count, uint8_t type);
44 /* Window Management Functions */
45 void windows_alloc_dirty_bytemap(struct mbox_context *context);
46 int window_set_bytemap(struct mbox_context *context, struct window_context *cur,
47 		       uint32_t offset, uint32_t size, uint8_t val);
48 void windows_close_current(struct mbox_context *context, uint8_t flags);
49 void window_reset(struct mbox_context *context, struct window_context *window);
50 bool windows_reset_all(struct mbox_context *context);
51 struct window_context *windows_find_oldest(struct mbox_context *context);
52 struct window_context *windows_find_largest(struct mbox_context *context);
53 struct window_context *windows_search(struct mbox_context *context,
54 				      uint32_t offset, bool exact);
55 int windows_create_map(struct mbox_context *context,
56 		      struct window_context **this_window,
57 		      uint32_t offset, bool exact);
58 
59 #endif /* WINDOWS_H */
60