xref: /openbmc/hiomapd/protocol.h (revision cb93504e)
1 /* SPDX-License-Identifier: Apache-2.0 */
2 /* Copyright (C) 2018 IBM Corp. */
3 
4 #ifndef PROTOCOL_H
5 #define PROTOCOL_H
6 
7 struct mbox_context;
8 struct transport_ops;
9 
10 /*
11  * The GET_MBOX_INFO command is special as it can change the interface based on
12  * negotiation. As such we need to accommodate all response types
13  */
14 struct protocol_get_info {
15 	struct {
16 		uint8_t api_version;
17 	} req;
18 	struct {
19 		uint8_t api_version;
20 		union {
21 			struct {
22 				uint16_t read_window_size;
23 				uint16_t write_window_size;
24 			} v1;
25 			struct {
26 				uint8_t block_size_shift;
27 				uint16_t timeout;
28 			} v2;
29 		};
30 	} resp;
31 };
32 
33 struct protocol_get_flash_info {
34 	struct {
35 		union {
36 			struct {
37 				uint32_t flash_size;
38 				uint32_t erase_size;
39 			} v1;
40 			struct {
41 				uint16_t flash_size;
42 				uint16_t erase_size;
43 			} v2;
44 		};
45 	} resp;
46 };
47 
48 struct protocol_create_window {
49 	struct {
50 		uint16_t offset;
51 		uint16_t size;
52 		uint8_t id;
53 		bool ro;
54 	} req;
55 	struct {
56 		uint16_t lpc_address;
57 		uint16_t size;
58 		uint16_t offset;
59 	} resp;
60 };
61 
62 struct protocol_mark_dirty {
63 	struct {
64 		union {
65 			struct {
66 				uint16_t offset;
67 				uint32_t size;
68 			} v1;
69 			struct {
70 				uint16_t offset;
71 				uint16_t size;
72 			} v2;
73 		};
74 	} req;
75 };
76 
77 struct protocol_erase {
78 	struct {
79 		uint16_t offset;
80 		uint16_t size;
81 	} req;
82 };
83 
84 struct protocol_flush {
85 	struct {
86 		uint16_t offset;
87 		uint32_t size;
88 	} req;
89 };
90 
91 struct protocol_close {
92 	struct {
93 		uint8_t flags;
94 	} req;
95 };
96 
97 struct protocol_ack {
98 	struct {
99 		uint8_t flags;
100 	} req;
101 };
102 
103 struct protocol_ops {
104 	int (*reset)(struct mbox_context *context);
105 	int (*get_info)(struct mbox_context *context,
106 			struct protocol_get_info *io);
107 	int (*get_flash_info)(struct mbox_context *context,
108 			      struct protocol_get_flash_info *io);
109 	int (*create_window)(struct mbox_context *context,
110 			     struct protocol_create_window *io);
111 	int (*mark_dirty)(struct mbox_context *context,
112 			  struct protocol_mark_dirty *io);
113 	int (*erase)(struct mbox_context *context, struct protocol_erase *io);
114 	int (*flush)(struct mbox_context *context, struct protocol_flush *io);
115 	int (*close)(struct mbox_context *context, struct protocol_close *io);
116 	int (*ack)(struct mbox_context *context, struct protocol_ack *io);
117 };
118 
119 int protocol_init(struct mbox_context *context);
120 void protocol_free(struct mbox_context *context);
121 
122 /* Sneaky reset: Don't tell the host */
123 int __protocol_reset(struct mbox_context *context);
124 
125 /* Noisy reset: Tell the host */
126 int protocol_reset(struct mbox_context *context);
127 
128 int protocol_events_put(struct mbox_context *context,
129 			const struct transport_ops *ops);
130 int protocol_events_set(struct mbox_context *context, uint8_t bmc_event);
131 int protocol_events_clear(struct mbox_context *context, uint8_t bmc_event);
132 
133 #endif /* PROTOCOL_H */
134