2018-02-08 17:47:50 +01:00
|
|
|
/*
|
|
|
|
* QTest testcase for SDHCI controllers
|
|
|
|
*
|
|
|
|
* Written by Philippe Mathieu-Daudé <f4bug@amsat.org>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2019-05-23 16:35:07 +02:00
|
|
|
|
2018-02-08 17:47:50 +01:00
|
|
|
#include "qemu/osdep.h"
|
|
|
|
#include "hw/registerfields.h"
|
2020-08-04 20:00:40 +02:00
|
|
|
#include "libqos/libqtest.h"
|
2019-05-23 16:35:07 +02:00
|
|
|
#include "qemu/module.h"
|
2018-02-08 17:47:50 +01:00
|
|
|
#include "libqos/pci-pc.h"
|
|
|
|
#include "hw/pci/pci.h"
|
2018-07-11 14:40:25 +02:00
|
|
|
#include "libqos/qgraph.h"
|
|
|
|
#include "libqos/sdhci.h"
|
2018-02-08 17:47:50 +01:00
|
|
|
|
|
|
|
#define SDHC_CAPAB 0x40
|
2018-02-08 17:47:52 +01:00
|
|
|
FIELD(SDHC_CAPAB, BASECLKFREQ, 8, 8); /* since v2 */
|
2018-02-08 17:47:53 +01:00
|
|
|
FIELD(SDHC_CAPAB, SDMA, 22, 1);
|
2018-02-08 17:48:17 +01:00
|
|
|
FIELD(SDHC_CAPAB, SDR, 32, 3); /* since v3 */
|
|
|
|
FIELD(SDHC_CAPAB, DRIVER, 36, 3); /* since v3 */
|
2018-02-08 17:47:50 +01:00
|
|
|
#define SDHC_HCVER 0xFE
|
|
|
|
|
2018-02-08 17:47:54 +01:00
|
|
|
static void check_specs_version(QSDHCI *s, uint8_t version)
|
|
|
|
{
|
|
|
|
uint32_t v;
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
v = s->readw(s, SDHC_HCVER);
|
2018-02-08 17:47:54 +01:00
|
|
|
v &= 0xff;
|
|
|
|
v += 1;
|
|
|
|
g_assert_cmpuint(v, ==, version);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:47:50 +01:00
|
|
|
static void check_capab_capareg(QSDHCI *s, uint64_t expec_capab)
|
|
|
|
{
|
|
|
|
uint64_t capab;
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
capab = s->readq(s, SDHC_CAPAB);
|
2018-02-08 17:47:50 +01:00
|
|
|
g_assert_cmphex(capab, ==, expec_capab);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:47:51 +01:00
|
|
|
static void check_capab_readonly(QSDHCI *s)
|
|
|
|
{
|
|
|
|
const uint64_t vrand = 0x123456789abcdef;
|
|
|
|
uint64_t capab0, capab1;
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
capab0 = s->readq(s, SDHC_CAPAB);
|
2018-02-08 17:47:51 +01:00
|
|
|
g_assert_cmpuint(capab0, !=, vrand);
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
s->writeq(s, SDHC_CAPAB, vrand);
|
|
|
|
capab1 = s->readq(s, SDHC_CAPAB);
|
2018-02-08 17:47:51 +01:00
|
|
|
g_assert_cmpuint(capab1, !=, vrand);
|
|
|
|
g_assert_cmpuint(capab1, ==, capab0);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:47:52 +01:00
|
|
|
static void check_capab_baseclock(QSDHCI *s, uint8_t expec_freq)
|
|
|
|
{
|
|
|
|
uint64_t capab, capab_freq;
|
|
|
|
|
|
|
|
if (!expec_freq) {
|
|
|
|
return;
|
|
|
|
}
|
2018-07-11 14:40:25 +02:00
|
|
|
capab = s->readq(s, SDHC_CAPAB);
|
2018-02-08 17:47:52 +01:00
|
|
|
capab_freq = FIELD_EX64(capab, SDHC_CAPAB, BASECLKFREQ);
|
|
|
|
g_assert_cmpuint(capab_freq, ==, expec_freq);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:47:53 +01:00
|
|
|
static void check_capab_sdma(QSDHCI *s, bool supported)
|
|
|
|
{
|
|
|
|
uint64_t capab, capab_sdma;
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
capab = s->readq(s, SDHC_CAPAB);
|
2018-02-08 17:47:53 +01:00
|
|
|
capab_sdma = FIELD_EX64(capab, SDHC_CAPAB, SDMA);
|
|
|
|
g_assert_cmpuint(capab_sdma, ==, supported);
|
|
|
|
}
|
|
|
|
|
2018-02-08 17:48:17 +01:00
|
|
|
static void check_capab_v3(QSDHCI *s, uint8_t version)
|
|
|
|
{
|
|
|
|
uint64_t capab, capab_v3;
|
|
|
|
|
|
|
|
if (version < 3) {
|
|
|
|
/* before v3 those fields are RESERVED */
|
2018-07-11 14:40:25 +02:00
|
|
|
capab = s->readq(s, SDHC_CAPAB);
|
2018-02-08 17:48:17 +01:00
|
|
|
capab_v3 = FIELD_EX64(capab, SDHC_CAPAB, SDR);
|
|
|
|
g_assert_cmpuint(capab_v3, ==, 0);
|
|
|
|
capab_v3 = FIELD_EX64(capab, SDHC_CAPAB, DRIVER);
|
|
|
|
g_assert_cmpuint(capab_v3, ==, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
static void test_registers(void *obj, void *data, QGuestAllocator *alloc)
|
2018-02-08 17:47:50 +01:00
|
|
|
{
|
2018-07-11 14:40:25 +02:00
|
|
|
QSDHCI *s = obj;
|
2018-02-08 17:47:50 +01:00
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
check_specs_version(s, s->props.version);
|
|
|
|
check_capab_capareg(s, s->props.capab.reg);
|
2018-02-08 17:47:51 +01:00
|
|
|
check_capab_readonly(s);
|
2018-07-11 14:40:25 +02:00
|
|
|
check_capab_v3(s, s->props.version);
|
|
|
|
check_capab_sdma(s, s->props.capab.sdma);
|
|
|
|
check_capab_baseclock(s, s->props.baseclock);
|
2018-02-08 17:47:50 +01:00
|
|
|
}
|
|
|
|
|
2018-07-11 14:40:25 +02:00
|
|
|
static void register_sdhci_test(void)
|
2018-02-08 17:47:50 +01:00
|
|
|
{
|
2018-07-11 14:40:25 +02:00
|
|
|
qos_add_test("registers", "sdhci", test_registers, NULL);
|
2018-02-08 17:47:50 +01:00
|
|
|
}
|
2018-07-11 14:40:25 +02:00
|
|
|
|
|
|
|
libqos_init(register_sdhci_test);
|