Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // Copyright (C) 2018 IBM Corp. |
| 3 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 4 | #include "config.h" |
| 5 | |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 6 | extern "C" { |
| 7 | #include "test/mbox.h" |
| 8 | #include "test/system.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 9 | #include "transport_mbox.h" |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 10 | } |
| 11 | |
Andrew Jeffery | 30bcf84 | 2018-03-26 12:13:20 +1030 | [diff] [blame] | 12 | #include "vpnor/test/tmpd.hpp" |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 13 | |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 14 | #include <cassert> |
| 15 | #include <cstring> |
| 16 | |
Andrew Jeffery | f4bc335 | 2019-03-18 12:09:48 +1030 | [diff] [blame^] | 17 | #include "vpnor/backend.h" |
Andrew Jeffery | 261f61a | 2019-03-14 09:57:28 +1030 | [diff] [blame] | 18 | |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 19 | struct test_context |
| 20 | { |
| 21 | uint8_t seq; |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 22 | struct mbox_context* ctx; |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | // Configure the system and the paritions such that we eventually request a |
| 26 | // window that covers the last section of flash, but the remaining flash is |
| 27 | // smaller than the window size |
| 28 | static constexpr auto BLOCK_SIZE = 4096; |
| 29 | static constexpr auto ERASE_SIZE = BLOCK_SIZE; |
| 30 | static constexpr auto N_WINDOWS = 3; |
| 31 | static constexpr auto WINDOW_SIZE = 2 * BLOCK_SIZE; |
| 32 | static constexpr auto MEM_SIZE = N_WINDOWS * WINDOW_SIZE; |
| 33 | static constexpr auto PNOR_SIZE = (4 * BLOCK_SIZE); |
| 34 | |
| 35 | const std::string toc[] = { |
| 36 | "partition01=ONE,00001000,00003000,80,ECC,READONLY", |
| 37 | }; |
| 38 | |
| 39 | static const uint8_t get_info[] = {0x02, 0x00, 0x02, 0x00, 0x00, 0x00, |
| 40 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| 41 | 0x00, 0x00, 0x00, 0x00}; |
| 42 | |
| 43 | static constexpr auto MBOX_CREATE_READ_WINDOW = 4; |
| 44 | |
William A. Kennington III | d5f1d40 | 2018-10-11 13:55:04 -0700 | [diff] [blame] | 45 | static int mbox_create_read_window(struct test_context* tctx, size_t offset, |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 46 | size_t len) |
| 47 | { |
| 48 | union mbox_regs regs; |
| 49 | |
| 50 | memset(®s, 0, sizeof(regs)); |
| 51 | regs.msg.command = MBOX_CREATE_READ_WINDOW; |
| 52 | regs.msg.seq = ++tctx->seq; |
| 53 | put_u16(®s.msg.args[0], offset); |
| 54 | put_u16(®s.msg.args[2], len); |
| 55 | |
| 56 | return mbox_command_dispatch(tctx->ctx, regs.raw, sizeof(regs.raw)); |
| 57 | } |
| 58 | |
| 59 | int main() |
| 60 | { |
| 61 | namespace test = openpower::virtual_pnor::test; |
| 62 | |
| 63 | struct test_context _tctx = {0}, *tctx = &_tctx; |
| 64 | size_t len; |
| 65 | size_t pos; |
| 66 | int rc; |
| 67 | |
| 68 | system_set_reserved_size(MEM_SIZE); |
| 69 | system_set_mtd_sizes(PNOR_SIZE, ERASE_SIZE); |
| 70 | |
Evan Lojewski | f1e547c | 2019-03-14 14:34:33 +1030 | [diff] [blame] | 71 | tctx->ctx = mbox_create_frontend_context(N_WINDOWS, WINDOW_SIZE); |
| 72 | test::VpnorRoot root(&tctx->ctx->backend, toc, BLOCK_SIZE); |
Andrew Jeffery | 3dce83d | 2018-03-22 16:52:42 +1030 | [diff] [blame] | 73 | |
| 74 | rc = mbox_command_dispatch(tctx->ctx, get_info, sizeof(get_info)); |
| 75 | assert(rc == 1); |
| 76 | |
| 77 | pos = 0; |
| 78 | while (pos < (PNOR_SIZE / BLOCK_SIZE)) |
| 79 | { |
| 80 | struct mbox_msg _msg, *msg = &_msg; |
| 81 | |
| 82 | rc = mbox_create_read_window(tctx, pos, (WINDOW_SIZE / BLOCK_SIZE)); |
| 83 | assert(rc == 1); |
| 84 | |
| 85 | mbox_rspcpy(tctx->ctx, msg); |
| 86 | |
| 87 | len = get_u16(&msg->args[2]); |
| 88 | pos = get_u16(&msg->args[4]) + len; |
| 89 | } |
| 90 | |
| 91 | return 0; |
| 92 | } |