@samitouri / QOSamiQemu / commits / afd36b9c07

tests/qtest: aspeed_smc: Add fast-read test coverage

Introduce a spi_ctrl_set_fast_read() helper and add read_page_mem_fast_read (CTRL_FREADMODE with dummy byte) and write_page_fast_read (user-mode FAST_READ) tests. While at it, replace the license boilerplate with SPDX identifier. Reviewed-by: Bin Meng <bin.meng@processmission.com> Link: https://lore.kernel.org/qemu-devel/20260714124621.522948-3-clg@redhat.com Signed-off-by: Cédric Le Goater <clg@redhat.com>

Cédric Le Goater committed Jul 14, 2026 at 14:46 UTC afd36b9c073276cf57476e2c2b367c6289a62ec3
4 files changed +90 -51
tests/qtest/aspeed-smc-utils.c
+58 -17
@@ -4,23 +4,7 @@
4 *
5 * Copyright (C) 2016 IBM Corp.
6 *
7 - * Permission is hereby granted, free of charge, to any person obtaining a copy
8 - * of this software and associated documentation files (the "Software"), to deal
9 - * in the Software without restriction, including without limitation the rights
10 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 - * copies of the Software, and to permit persons to whom the Software is
12 - * furnished to do so, subject to the following conditions:
13 - *
14 - * The above copyright notice and this permission notice shall be included in
15 - * all copies or substantial portions of the Software.
16 - *
17 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 - * THE SOFTWARE.
7 + * SPDX-License-Identifier: MIT
8 */
9
10 #include "qemu/osdep.h"
@@ -107,6 +91,23 @@ static void spi_ctrl_setmode(const AspeedSMCTestData *data, uint8_t mode,
91 spi_writel(data, ctrl_reg, ctrl);
92 }
93
94 +/* Set FREADMODE with a fast read command and 1 dummy byte */
95 +static void spi_ctrl_set_fast_read(const AspeedSMCTestData *data, uint8_t cmd)
96 +{
97 + uint32_t ctrl_reg = R_CTRL0 + data->cs * 4;
98 + uint32_t ctrl = spi_readl(data, ctrl_reg);
99 + uint32_t iomode = 0;
100 +
101 + ctrl &= ~(CTRL_USERMODE | (0xff << 16) |
102 + (0x3 << CTRL_DUMMY_LOW_SHIFT) |
103 + (0x1 << CTRL_DUMMY_HIGH_SHIFT) |
104 + CTRL_IO_MODE_MASK);
105 + ctrl |= CTRL_FREADMODE | (cmd << 16) |
106 + (1 << CTRL_DUMMY_LOW_SHIFT) |
107 + iomode;
108 + spi_writel(data, ctrl_reg, ctrl);
109 +}
110 +
111 static void spi_ctrl_start_user(const AspeedSMCTestData *data)
112 {
113 uint32_t ctrl_reg = R_CTRL0 + data->cs * 4;
@@ -697,3 +698,43 @@ void aspeed_smc_test_write_page_qpi(const void *data)
698 flash_reset(test_data);
699 }
700
701 +static void read_page_mem_fast_read(const AspeedSMCTestData *data,
702 + uint32_t addr, uint32_t *page)
703 +{
704 + int i;
705 +
706 + spi_ctrl_set_fast_read(data, FAST_READ);
707 +
708 + for (i = 0; i < FLASH_PAGE_SIZE / 4; i++) {
709 + page[i] = make_be32(flash_readl(data, addr + i * 4));
710 + }
711 +}
712 +
713 +void aspeed_smc_test_read_page_mem_fast_read(const void *data)
714 +{
715 + test_read_page_mem(data, read_page_mem_fast_read);
716 +}
717 +
718 +static void read_page_fast_read(const AspeedSMCTestData *data,
719 + uint32_t addr, uint32_t *page)
720 +{
721 + int i;
722 +
723 + spi_ctrl_start_user(data);
724 +
725 + flash_writeb(data, 0, EN_4BYTE_ADDR);
726 + flash_writeb(data, 0, FAST_READ);
727 + flash_writel(data, 0, make_be32(addr));
728 + /* 1 dummy byte for standard SPI fast-read */
729 + flash_writeb(data, 0, 0x00);
730 +
731 + for (i = 0; i < FLASH_PAGE_SIZE / 4; i++) {
732 + page[i] = make_be32(flash_readl(data, 0));
733 + }
734 + spi_ctrl_stop_user(data);
735 +}
736 +
737 +void aspeed_smc_test_write_page_fast_read(const void *data)
738 +{
739 + test_write_page(data, read_page_fast_read);
740 +}
tests/qtest/aspeed-smc-utils.h
+6 -17
@@ -4,23 +4,7 @@
4 *
5 * Copyright (C) 2016 IBM Corp.
6 *
7 - * Permission is hereby granted, free of charge, to any person obtaining a copy
8 - * of this software and associated documentation files (the "Software"), to deal
9 - * in the Software without restriction, including without limitation the rights
10 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 - * copies of the Software, and to permit persons to whom the Software is
12 - * furnished to do so, subject to the following conditions:
13 - *
14 - * The above copyright notice and this permission notice shall be included in
15 - * all copies or substantial portions of the Software.
16 - *
17 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 - * THE SOFTWARE.
7 + * SPDX-License-Identifier: MIT
8 */
9
10 #ifndef TESTS_ASPEED_SMC_UTILS_H
@@ -44,6 +28,8 @@
28 #define CTRL_FREADMODE 0x1
29 #define CTRL_WRITEMODE 0x2
30 #define CTRL_USERMODE 0x3
31 +#define CTRL_DUMMY_LOW_SHIFT 6
32 +#define CTRL_DUMMY_HIGH_SHIFT 14
33 #define SR_WEL BIT(1)
34
35 /*
@@ -55,6 +41,7 @@ enum {
41 WRDI = 0x4,
42 BULK_ERASE = 0xc7,
43 READ = 0x03,
44 + FAST_READ = 0x0b,
45 PP = 0x02,
46 WRSR = 0x1,
47 WREN = 0x6,
@@ -90,5 +77,7 @@ void aspeed_smc_test_status_reg_write_protection(const void *data);
77 void aspeed_smc_test_write_block_protect(const void *data);
78 void aspeed_smc_test_write_block_protect_bottom_bit(const void *data);
79 void aspeed_smc_test_write_page_qpi(const void *data);
80 +void aspeed_smc_test_read_page_mem_fast_read(const void *data);
81 +void aspeed_smc_test_write_page_fast_read(const void *data);
82
83 #endif /* TESTS_ASPEED_SMC_UTILS_H */
tests/qtest/aspeed_smc-test.c
+22 -17
@@ -4,23 +4,7 @@
4 *
5 * Copyright (C) 2016 IBM Corp.
6 *
7 - * Permission is hereby granted, free of charge, to any person obtaining a copy
8 - * of this software and associated documentation files (the "Software"), to deal
9 - * in the Software without restriction, including without limitation the rights
10 - * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 - * copies of the Software, and to permit persons to whom the Software is
12 - * furnished to do so, subject to the following conditions:
13 - *
14 - * The above copyright notice and this permission notice shall be included in
15 - * all copies or substantial portions of the Software.
16 - *
17 - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 - * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 - * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 - * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 - * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
23 - * THE SOFTWARE.
7 + * SPDX-License-Identifier: MIT
8 */
9
10 #include "qemu/osdep.h"
@@ -68,6 +52,15 @@ static void test_palmetto_bmc(AspeedSMCTestData *data)
52 data, aspeed_smc_test_read_status_reg);
53 qtest_add_data_func("/ast2400/smc/status_reg_write_protection",
54 data, aspeed_smc_test_status_reg_write_protection);
55 + qtest_add_data_func("/ast2400/smc/read_page_mem_fast_read",
56 + data, aspeed_smc_test_read_page_mem_fast_read);
57 + qtest_add_data_func("/ast2400/smc/write_page_fast_read",
58 + data, aspeed_smc_test_write_page_fast_read);
59 + /*
60 + * Block protect tests must be run last because the block protect
61 + * state is not cleared by reset_memory() and silently prevents
62 + * subsequent flash writes.
63 + */
64 qtest_add_data_func("/ast2400/smc/write_block_protect",
65 data, aspeed_smc_test_write_block_protect);
66 qtest_add_data_func("/ast2400/smc/write_block_protect_bottom_bit",
@@ -115,6 +108,10 @@ static void test_ast2500_evb(AspeedSMCTestData *data)
108 data, aspeed_smc_test_read_status_reg);
109 qtest_add_data_func("/ast2500/smc/write_page_qpi",
110 data, aspeed_smc_test_write_page_qpi);
111 + qtest_add_data_func("/ast2500/smc/read_page_mem_fast_read",
112 + data, aspeed_smc_test_read_page_mem_fast_read);
113 + qtest_add_data_func("/ast2500/smc/write_page_fast_read",
114 + data, aspeed_smc_test_write_page_fast_read);
115 }
116
117 static void test_ast2600_evb(AspeedSMCTestData *data)
@@ -158,6 +155,10 @@ static void test_ast2600_evb(AspeedSMCTestData *data)
155 data, aspeed_smc_test_read_status_reg);
156 qtest_add_data_func("/ast2600/smc/write_page_qpi",
157 data, aspeed_smc_test_write_page_qpi);
158 + qtest_add_data_func("/ast2600/smc/read_page_mem_fast_read",
159 + data, aspeed_smc_test_read_page_mem_fast_read);
160 + qtest_add_data_func("/ast2600/smc/write_page_fast_read",
161 + data, aspeed_smc_test_write_page_fast_read);
162 }
163
164 static void test_ast1030_evb(AspeedSMCTestData *data)
@@ -201,6 +202,10 @@ static void test_ast1030_evb(AspeedSMCTestData *data)
202 data, aspeed_smc_test_read_status_reg);
203 qtest_add_data_func("/ast1030/smc/write_page_qpi",
204 data, aspeed_smc_test_write_page_qpi);
205 + qtest_add_data_func("/ast1030/smc/read_page_mem_fast_read",
206 + data, aspeed_smc_test_read_page_mem_fast_read);
207 + qtest_add_data_func("/ast1030/smc/write_page_fast_read",
208 + data, aspeed_smc_test_write_page_fast_read);
209 }
210
211 int main(int argc, char **argv)
tests/qtest/ast2700-smc-test.c
+4
@@ -52,6 +52,10 @@ static void test_ast2700_evb(AspeedSMCTestData *data)
52 data, aspeed_smc_test_read_status_reg);
53 qtest_add_data_func("/ast2700/smc/write_page_qpi",
54 data, aspeed_smc_test_write_page_qpi);
55 + qtest_add_data_func("/ast2700/smc/read_page_mem_fast_read",
56 + data, aspeed_smc_test_read_page_mem_fast_read);
57 + qtest_add_data_func("/ast2700/smc/write_page_fast_read",
58 + data, aspeed_smc_test_write_page_fast_read);
59 }
60
61 int main(int argc, char **argv)