blob: 9b5fc09d38fdad4094891009e8b31e5772cea442 [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 Jeffery1e531af2018-08-07 13:32:57 +093061struct protocol_ops {
Andrew Jefferyab666a52018-08-07 14:28:09 +093062 int (*reset)(struct mbox_context *context);
Andrew Jeffery1e531af2018-08-07 13:32:57 +093063 int (*get_info)(struct mbox_context *context,
64 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +093065 int (*get_flash_info)(struct mbox_context *context,
66 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +093067 int (*create_window)(struct mbox_context *context,
68 struct protocol_create_window *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +093069};
70
71int protocol_init(struct mbox_context *context);
72void protocol_free(struct mbox_context *context);
73
74int protocol_negotiate_version(struct mbox_context *context, uint8_t requested);
75
76/* Protocol v1 */
Andrew Jefferyab666a52018-08-07 14:28:09 +093077int protocol_v1_reset(struct mbox_context *context);
Andrew Jeffery1e531af2018-08-07 13:32:57 +093078int protocol_v1_get_info(struct mbox_context *context,
79 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +093080int protocol_v1_get_flash_info(struct mbox_context *context,
81 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +093082int protocol_v1_create_window(struct mbox_context *context,
83 struct protocol_create_window *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +093084
85/* Protocol v2 */
86int protocol_v2_get_info(struct mbox_context *context,
87 struct protocol_get_info *io);
Andrew Jeffery91a87452018-08-07 14:54:14 +093088int protocol_v2_get_flash_info(struct mbox_context *context,
89 struct protocol_get_flash_info *io);
Andrew Jeffery4bcec8e2018-08-07 15:33:41 +093090int protocol_v2_create_window(struct mbox_context *context,
91 struct protocol_create_window *io);
Andrew Jeffery1e531af2018-08-07 13:32:57 +093092
93#endif /* PROTOCOL_H */