blob: c22f94b79b0f0b8176636df0dc0196f227f642ce [file] [log] [blame]
Andrew Jeffery1e531af2018-08-07 13:32:57 +09301/* SPDX-License-Identifier: Apache-2.0 */
2/* Copyright (C) 2018 IBM Corp. */
3
4#ifndef PROTOCOL_H
5#define PROTOCOL_H
6
7struct mbox_context;
8
9/*
10 * The GET_MBOX_INFO command is special as it can change the interface based on
11 * negotiation. As such we need to accommodate all response types
12 */
13struct protocol_get_info {
14 struct {
15 uint8_t api_version;
16 } req;
17 struct {
18 uint8_t api_version;
19 union {
20 struct {
21 uint16_t read_window_size;
22 uint16_t write_window_size;
23 } v1;
24 struct {
25 uint8_t block_size_shift;
26 uint16_t timeout;
27 } v2;
28 };
29 } resp;
30};
31
Andrew Jeffery91a87452018-08-07 14:54:14 +093032struct protocol_get_flash_info {
33 struct {
34 union {
35 struct {
36 uint32_t flash_size;
37 uint32_t erase_size;
38 } v1;
39 struct {
40 uint16_t flash_size;
41 uint16_t erase_size;
42 } v2;
43 };
44 } resp;
45};
46
Andrew Jeffery22fa5002018-08-07 15:22:50 +093047struct protocol_create_window {
48 struct {
49 uint16_t offset;
50 uint16_t size;
51 uint8_t id;
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +093052 bool ro;
Andrew Jeffery22fa5002018-08-07 15:22:50 +093053 } req;
54 struct {
55 uint16_t lpc_address;
56 uint16_t size;
57 uint16_t offset;
58 } resp;
59};
60
Andrew Jefferya336e432018-08-07 16:00:40 +093061struct protocol_mark_dirty {
62 struct {
63 union {
64 struct {
65 uint16_t offset;
66 uint32_t size;
67 } v1;
68 struct {
69 uint16_t offset;
70 uint16_t size;
71 } v2;
72 };
73 } req;
74};
75
Andrew Jeffery62a3daa2018-08-07 22:30:32 +093076struct protocol_erase {
77 struct {
78 uint16_t offset;
79 uint16_t size;
80 } req;
81};
82
Andrew Jeffery9b920cf2018-08-07 22:49:19 +093083struct protocol_flush {
84 struct {
85 uint16_t offset;
86 uint32_t size;
87 } req;
88};
Andrew Jeffery62a3daa2018-08-07 22:30:32 +093089
Andrew Jeffery1e531af2018-08-07 13:32:57 +093090struct protocol_ops {
Andrew Jefferyab666a52018-08-07 14:28:09 +093091 int (*reset)(struct mbox_context *context);
Andrew Jeffery1e531af2018-08-07 13:32:57 +093092 int (*get_info)(struct mbox_context *context,
93 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +093094 int (*get_flash_info)(struct mbox_context *context,
95 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +093096 int (*create_window)(struct mbox_context *context,
97 struct protocol_create_window *io);
Andrew Jefferya336e432018-08-07 16:00:40 +093098 int (*mark_dirty)(struct mbox_context *context,
99 struct protocol_mark_dirty *io);
Andrew Jeffery62a3daa2018-08-07 22:30:32 +0930100 int (*erase)(struct mbox_context *context, struct protocol_erase *io);
Andrew Jeffery9b920cf2018-08-07 22:49:19 +0930101 int (*flush)(struct mbox_context *context, struct protocol_flush *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930102};
103
104int protocol_init(struct mbox_context *context);
105void protocol_free(struct mbox_context *context);
106
107int protocol_negotiate_version(struct mbox_context *context, uint8_t requested);
108
109/* Protocol v1 */
Andrew Jefferyab666a52018-08-07 14:28:09 +0930110int protocol_v1_reset(struct mbox_context *context);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930111int protocol_v1_get_info(struct mbox_context *context,
112 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +0930113int protocol_v1_get_flash_info(struct mbox_context *context,
114 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +0930115int protocol_v1_create_window(struct mbox_context *context,
116 struct protocol_create_window *io);
Andrew Jefferya336e432018-08-07 16:00:40 +0930117int protocol_v1_mark_dirty(struct mbox_context *context,
118 struct protocol_mark_dirty *io);
Andrew Jeffery9b920cf2018-08-07 22:49:19 +0930119int protocol_v1_flush(struct mbox_context *context, struct protocol_flush *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930120
121/* Protocol v2 */
122int protocol_v2_get_info(struct mbox_context *context,
123 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +0930124int protocol_v2_get_flash_info(struct mbox_context *context,
125 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +0930126int protocol_v2_create_window(struct mbox_context *context,
127 struct protocol_create_window *io);
Andrew Jefferya336e432018-08-07 16:00:40 +0930128int protocol_v2_mark_dirty(struct mbox_context *context,
129 struct protocol_mark_dirty *io);
Andrew Jeffery62a3daa2018-08-07 22:30:32 +0930130int protocol_v2_erase(struct mbox_context *context,
131 struct protocol_erase *io);
Andrew Jeffery9b920cf2018-08-07 22:49:19 +0930132int protocol_v2_flush(struct mbox_context *context, struct protocol_flush *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +0930133
134#endif /* PROTOCOL_H */