1 Star 0 Fork 124

zhouli57/src-qemu

forked from src-openEuler/qemu 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
test-tpm-tis-Get-prepared-to-share-tests-between-ISA.patch 40.97 KB
一键复制 编辑 原始数据 按行查看 历史
JackJF 提交于 2020-08-13 13:11 . aarch64 support vtpm
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044
From c8ed2a1fbe306ecbfb5c7d4156ae81c029829d95 Mon Sep 17 00:00:00 2001
From: jiangfangjie <jiangfangjie@huawei.com>
Date: Thu, 13 Aug 2020 20:56:54 +0800
Subject: [PATCH 18/19] test: tpm-tis: Get prepared to share tests between ISA
and sysbus devices
ISA and sysbus TPM-TIS devices will share their tests. Only
the main() will change (instantiation option is different).
Also the base address of the TPM-TIS device is going to be
different. on x86 it is located at 0xFED40000 while on ARM
it can be located at any location, discovered through the
device tree description.
So we put shared test functions in a new object module.
Each test needs to set tpm_tis_base_addr global variable.
Also take benefit of this move to fix "block comments using
a leading */ on a separate line" checkpatch warnings.
Signed-off-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Message-id: 20200305165149.618-10-eric.auger@redhat.com
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
Signed-off-by: jiangfangjie <jiangfangjie@huawei.com>
---
tests/Makefile.include | 2 +-
tests/tpm-crb-swtpm-test.c | 4 +
tests/tpm-crb-test.c | 3 +
tests/tpm-tis-swtpm-test.c | 3 +
tests/tpm-tis-test.c | 414 +---------------------------------
tests/tpm-tis-util.c | 451 +++++++++++++++++++++++++++++++++++++
tests/tpm-tis-util.h | 23 ++
tests/tpm-util.c | 3 -
tests/tpm-util.h | 5 +
9 files changed, 493 insertions(+), 415 deletions(-)
create mode 100644 tests/tpm-tis-util.c
create mode 100644 tests/tpm-tis-util.h
diff --git a/tests/Makefile.include b/tests/Makefile.include
index c151de64..950b32a2 100644
--- a/tests/Makefile.include
+++ b/tests/Makefile.include
@@ -667,7 +667,7 @@ tests/tpm-crb-swtpm-test$(EXESUF): tests/tpm-crb-swtpm-test.o tests/tpm-emu.o \
tests/tpm-crb-test$(EXESUF): tests/tpm-crb-test.o tests/tpm-emu.o $(test-io-obj-y)
tests/tpm-tis-swtpm-test$(EXESUF): tests/tpm-tis-swtpm-test.o tests/tpm-emu.o \
tests/tpm-util.o tests/tpm-tests.o $(test-io-obj-y)
-tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-emu.o $(test-io-obj-y)
+tests/tpm-tis-test$(EXESUF): tests/tpm-tis-test.o tests/tpm-tis-util.o tests/tpm-emu.o $(test-io-obj-y)
tests/test-io-channel-file$(EXESUF): tests/test-io-channel-file.o \
tests/io-channel-helpers.o $(test-io-obj-y)
tests/test-io-channel-tls$(EXESUF): tests/test-io-channel-tls.o \
diff --git a/tests/tpm-crb-swtpm-test.c b/tests/tpm-crb-swtpm-test.c
index 5228cb7a..55fdb565 100644
--- a/tests/tpm-crb-swtpm-test.c
+++ b/tests/tpm-crb-swtpm-test.c
@@ -18,6 +18,10 @@
#include "libqtest.h"
#include "qemu/module.h"
#include "tpm-tests.h"
+#include "hw/acpi/tpm.h"
+
+/* Not used but needed for linking */
+uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
typedef struct TestState {
char *src_tpm_path;
diff --git a/tests/tpm-crb-test.c b/tests/tpm-crb-test.c
index a139caa5..32695810 100644
--- a/tests/tpm-crb-test.c
+++ b/tests/tpm-crb-test.c
@@ -19,6 +19,9 @@
#include "qemu/module.h"
#include "tpm-emu.h"
+/* Not used but needed for linking */
+uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
+
#define TPM_CMD "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00"
static void tpm_crb_test(const void *data)
diff --git a/tests/tpm-tis-swtpm-test.c b/tests/tpm-tis-swtpm-test.c
index 9470f157..90131cb3 100644
--- a/tests/tpm-tis-swtpm-test.c
+++ b/tests/tpm-tis-swtpm-test.c
@@ -18,6 +18,9 @@
#include "libqtest.h"
#include "qemu/module.h"
#include "tpm-tests.h"
+#include "hw/acpi/tpm.h"
+
+uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
typedef struct TestState {
char *src_tpm_path;
diff --git a/tests/tpm-tis-test.c b/tests/tpm-tis-test.c
index 92a7e95a..8042de13 100644
--- a/tests/tpm-tis-test.c
+++ b/tests/tpm-tis-test.c
@@ -1,5 +1,5 @@
/*
- * QTest testcase for TPM TIS
+ * QTest testcase for ISA TPM TIS
*
* Copyright (c) 2018 Red Hat, Inc.
* Copyright (c) 2018 IBM Corporation
@@ -20,417 +20,9 @@
#include "libqtest.h"
#include "qemu/module.h"
#include "tpm-emu.h"
+#include "tpm-tis-util.h"
-#define TIS_REG(LOCTY, REG) \
- (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG)
-
-#define DEBUG_TIS_TEST 0
-
-#define DPRINTF(fmt, ...) do { \
- if (DEBUG_TIS_TEST) { \
- printf(fmt, ## __VA_ARGS__); \
- } \
-} while (0)
-
-#define DPRINTF_ACCESS \
- DPRINTF("%s: %d: locty=%d l=%d access=0x%02x pending_request_flag=0x%x\n", \
- __func__, __LINE__, locty, l, access, pending_request_flag)
-
-#define DPRINTF_STS \
- DPRINTF("%s: %d: sts = 0x%08x\n", __func__, __LINE__, sts)
-
-static const uint8_t TPM_CMD[12] =
- "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
-
-static void tpm_tis_test_check_localities(const void *data)
-{
- uint8_t locty;
- uint8_t access;
- uint32_t ifaceid;
- uint32_t capability;
- uint32_t didvid;
- uint32_t rid;
-
- for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) {
- access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- capability = readl(TIS_REG(locty, TPM_TIS_REG_INTF_CAPABILITY));
- g_assert_cmpint(capability, ==, TPM_TIS_CAPABILITIES_SUPPORTED2_0);
-
- ifaceid = readl(TIS_REG(locty, TPM_TIS_REG_INTERFACE_ID));
- g_assert_cmpint(ifaceid, ==, TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2_0);
-
- didvid = readl(TIS_REG(locty, TPM_TIS_REG_DID_VID));
- g_assert_cmpint(didvid, !=, 0);
- g_assert_cmpint(didvid, !=, 0xffffffff);
-
- rid = readl(TIS_REG(locty, TPM_TIS_REG_RID));
- g_assert_cmpint(rid, !=, 0);
- g_assert_cmpint(rid, !=, 0xffffffff);
- }
-}
-
-static void tpm_tis_test_check_access_reg(const void *data)
-{
- uint8_t locty;
- uint8_t access;
-
- /* do not test locality 4 (hw only) */
- for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* request use of locality */
- writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
-
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* release access */
- writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS),
- TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- }
-}
-
-/*
- * Test case for seizing access by a higher number locality
- */
-static void tpm_tis_test_check_access_reg_seize(const void *data)
-{
- int locty, l;
- uint8_t access;
- uint8_t pending_request_flag;
-
- /* do not test locality 4 (hw only) */
- for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
- pending_request_flag = 0;
-
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* request use of locality */
- writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* lower localities cannot seize access */
- for (l = 0; l < locty; l++) {
- /* lower locality is not active */
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* try to request use from 'l' */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
-
- /* requesting use from 'l' was not possible;
- we must see REQUEST_USE and possibly PENDING_REQUEST */
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_REQUEST_USE |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* locality 'locty' must be unchanged;
- we must see PENDING_REQUEST */
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_PENDING_REQUEST |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* try to seize from 'l' */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE);
- /* seize from 'l' was not possible */
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_REQUEST_USE |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* locality 'locty' must be unchanged */
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_PENDING_REQUEST |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* on the next loop we will have a PENDING_REQUEST flag
- set for locality 'l' */
- pending_request_flag = TPM_TIS_ACCESS_PENDING_REQUEST;
- }
-
- /* higher localities can 'seize' access but not 'request use';
- note: this will activate first l+1, then l+2 etc. */
- for (l = locty + 1; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
- /* try to 'request use' from 'l' */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
-
- /* requesting use from 'l' was not possible; we should see
- REQUEST_USE and may see PENDING_REQUEST */
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_REQUEST_USE |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* locality 'l-1' must be unchanged; we should always
- see PENDING_REQUEST from 'l' requesting access */
- access = readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_PENDING_REQUEST |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* try to seize from 'l' */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE);
-
- /* seize from 'l' was possible */
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* l - 1 should show that it has BEEN_SEIZED */
- access = readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_BEEN_SEIZED |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* clear the BEEN_SEIZED flag and make sure it's gone */
- writeb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS),
- TPM_TIS_ACCESS_BEEN_SEIZED);
-
- access = readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- }
-
- /* PENDING_REQUEST will not be set if locty = 0 since all localities
- were active; in case of locty = 1, locality 0 will be active
- but no PENDING_REQUEST anywhere */
- if (locty <= 1) {
- pending_request_flag = 0;
- }
-
- /* release access from l - 1; this activates locty - 1 */
- l--;
-
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
-
- DPRINTF("%s: %d: relinquishing control on l = %d\n",
- __func__, __LINE__, l);
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS),
- TPM_TIS_ACCESS_ACTIVE_LOCALITY);
-
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- for (l = locty - 1; l >= 0; l--) {
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* release this locality */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS),
- TPM_TIS_ACCESS_ACTIVE_LOCALITY);
-
- if (l == 1) {
- pending_request_flag = 0;
- }
- }
-
- /* no locality may be active now */
- for (l = 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- }
- }
-}
-
-/*
- * Test case for getting access when higher number locality relinquishes access
- */
-static void tpm_tis_test_check_access_reg_release(const void *data)
-{
- int locty, l;
- uint8_t access;
- uint8_t pending_request_flag;
-
- /* do not test locality 4 (hw only) */
- for (locty = TPM_TIS_NUM_LOCALITIES - 2; locty >= 0; locty--) {
- pending_request_flag = 0;
-
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* request use of locality */
- writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
- access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- /* request use of all other localities */
- for (l = 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
- if (l == locty) {
- continue;
- }
- /* request use of locality 'l' -- we MUST see REQUEST USE and
- may see PENDING_REQUEST */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_REQUEST_USE |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- pending_request_flag = TPM_TIS_ACCESS_PENDING_REQUEST;
- }
- /* release locality 'locty' */
- writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS),
- TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- /* highest locality should now be active; release it and make sure the
- next higest locality is active afterwards */
- for (l = TPM_TIS_NUM_LOCALITIES - 2; l >= 0; l--) {
- if (l == locty) {
- continue;
- }
- /* 'l' should be active now */
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- /* 'l' relinquishes access */
- writeb(TIS_REG(l, TPM_TIS_REG_ACCESS),
- TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
- DPRINTF_ACCESS;
- if (l == 1 || (locty <= 1 && l == 2)) {
- pending_request_flag = 0;
- }
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- pending_request_flag |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
- }
- }
-}
-
-/*
- * Test case for transmitting packets
- */
-static void tpm_tis_test_check_transmit(const void *data)
-{
- const TestState *s = data;
- uint8_t access;
- uint32_t sts;
- uint16_t bcount;
- size_t i;
-
- /* request use of locality 0 */
- writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
- access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
- g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
- TPM_TIS_ACCESS_ACTIVE_LOCALITY |
- TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
-
- sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
- DPRINTF_STS;
-
- g_assert_cmpint(sts & 0xff, ==, 0);
- g_assert_cmpint(sts & TPM_TIS_STS_TPM_FAMILY_MASK, ==,
- TPM_TIS_STS_TPM_FAMILY2_0);
-
- bcount = (sts >> 8) & 0xffff;
- g_assert_cmpint(bcount, >=, 128);
-
- writel(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY);
- sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
- DPRINTF_STS;
- g_assert_cmpint(sts & 0xff, ==, TPM_TIS_STS_COMMAND_READY);
-
- /* transmit command */
- for (i = 0; i < sizeof(TPM_CMD); i++) {
- writeb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO), TPM_CMD[i]);
- sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
- DPRINTF_STS;
- if (i < sizeof(TPM_CMD) - 1) {
- g_assert_cmpint(sts & 0xff, ==,
- TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID);
- } else {
- g_assert_cmpint(sts & 0xff, ==, TPM_TIS_STS_VALID);
- }
- g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
- }
- /* start processing */
- writeb(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO);
-
- uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
- do {
- sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
- if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
- break;
- }
- } while (g_get_monotonic_time() < end_time);
-
- sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
- DPRINTF_STS;
- g_assert_cmpint(sts & 0xff, == ,
- TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE);
- bcount = (sts >> 8) & 0xffff;
-
- /* read response */
- uint8_t tpm_msg[sizeof(struct tpm_hdr)];
- g_assert_cmpint(sizeof(tpm_msg), ==, bcount);
-
- for (i = 0; i < sizeof(tpm_msg); i++) {
- tpm_msg[i] = readb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO));
- sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
- DPRINTF_STS;
- if (sts & TPM_TIS_STS_DATA_AVAILABLE) {
- g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
- }
- }
- g_assert_cmpmem(tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_msg));
-
- /* relinquish use of locality 0 */
- writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_ACTIVE_LOCALITY);
- access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
-}
+uint64_t tpm_tis_base_addr = TPM_TIS_ADDR_BASE;
int main(int argc, char **argv)
{
diff --git a/tests/tpm-tis-util.c b/tests/tpm-tis-util.c
new file mode 100644
index 00000000..9aff503f
--- /dev/null
+++ b/tests/tpm-tis-util.c
@@ -0,0 +1,451 @@
+/*
+ * QTest testcase for TPM TIS: common test functions used for both
+ * the ISA and SYSBUS devices
+ *
+ * Copyright (c) 2018 Red Hat, Inc.
+ * Copyright (c) 2018 IBM Corporation
+ *
+ * Authors:
+ * Marc-André Lureau <marcandre.lureau@redhat.com>
+ * Stefan Berger <stefanb@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#include "qemu/osdep.h"
+#include <glib/gstdio.h>
+
+#include "hw/acpi/tpm.h"
+#include "io/channel-socket.h"
+#include "libqtest.h"
+#include "qemu/module.h"
+#include "tpm-emu.h"
+#include "tpm-util.h"
+#include "tpm-tis-util.h"
+
+#define DEBUG_TIS_TEST 0
+
+#define DPRINTF(fmt, ...) do { \
+ if (DEBUG_TIS_TEST) { \
+ printf(fmt, ## __VA_ARGS__); \
+ } \
+} while (0)
+
+#define DPRINTF_ACCESS \
+ DPRINTF("%s: %d: locty=%d l=%d access=0x%02x pending_request_flag=0x%x\n", \
+ __func__, __LINE__, locty, l, access, pending_request_flag)
+
+#define DPRINTF_STS \
+ DPRINTF("%s: %d: sts = 0x%08x\n", __func__, __LINE__, sts)
+
+static const uint8_t TPM_CMD[12] =
+ "\x80\x01\x00\x00\x00\x0c\x00\x00\x01\x44\x00\x00";
+
+void tpm_tis_test_check_localities(const void *data)
+{
+ uint8_t locty;
+ uint8_t access;
+ uint32_t ifaceid;
+ uint32_t capability;
+ uint32_t didvid;
+ uint32_t rid;
+
+ for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES; locty++) {
+ access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ capability = readl(TIS_REG(locty, TPM_TIS_REG_INTF_CAPABILITY));
+ g_assert_cmpint(capability, ==, TPM_TIS_CAPABILITIES_SUPPORTED2_0);
+
+ ifaceid = readl(TIS_REG(locty, TPM_TIS_REG_INTERFACE_ID));
+ g_assert_cmpint(ifaceid, ==, TPM_TIS_IFACE_ID_SUPPORTED_FLAGS2_0);
+
+ didvid = readl(TIS_REG(locty, TPM_TIS_REG_DID_VID));
+ g_assert_cmpint(didvid, !=, 0);
+ g_assert_cmpint(didvid, !=, 0xffffffff);
+
+ rid = readl(TIS_REG(locty, TPM_TIS_REG_RID));
+ g_assert_cmpint(rid, !=, 0);
+ g_assert_cmpint(rid, !=, 0xffffffff);
+ }
+}
+
+void tpm_tis_test_check_access_reg(const void *data)
+{
+ uint8_t locty;
+ uint8_t access;
+
+ /* do not test locality 4 (hw only) */
+ for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* request use of locality */
+ writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* release access */
+ writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+ }
+}
+
+/*
+ * Test case for seizing access by a higher number locality
+ */
+void tpm_tis_test_check_access_reg_seize(const void *data)
+{
+ int locty, l;
+ uint8_t access;
+ uint8_t pending_request_flag;
+
+ /* do not test locality 4 (hw only) */
+ for (locty = 0; locty < TPM_TIS_NUM_LOCALITIES - 1; locty++) {
+ pending_request_flag = 0;
+
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* request use of locality */
+ writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* lower localities cannot seize access */
+ for (l = 0; l < locty; l++) {
+ /* lower locality is not active */
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* try to request use from 'l' */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+
+ /*
+ * requesting use from 'l' was not possible;
+ * we must see REQUEST_USE and possibly PENDING_REQUEST
+ */
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_REQUEST_USE |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /*
+ * locality 'locty' must be unchanged;
+ * we must see PENDING_REQUEST
+ */
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_PENDING_REQUEST |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* try to seize from 'l' */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE);
+ /* seize from 'l' was not possible */
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_REQUEST_USE |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* locality 'locty' must be unchanged */
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_PENDING_REQUEST |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /*
+ * on the next loop we will have a PENDING_REQUEST flag
+ * set for locality 'l'
+ */
+ pending_request_flag = TPM_TIS_ACCESS_PENDING_REQUEST;
+ }
+
+ /*
+ * higher localities can 'seize' access but not 'request use';
+ * note: this will activate first l+1, then l+2 etc.
+ */
+ for (l = locty + 1; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
+ /* try to 'request use' from 'l' */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+
+ /*
+ * requesting use from 'l' was not possible; we should see
+ * REQUEST_USE and may see PENDING_REQUEST
+ */
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_REQUEST_USE |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /*
+ * locality 'l-1' must be unchanged; we should always
+ * see PENDING_REQUEST from 'l' requesting access
+ */
+ access = readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_PENDING_REQUEST |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* try to seize from 'l' */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_SEIZE);
+
+ /* seize from 'l' was possible */
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* l - 1 should show that it has BEEN_SEIZED */
+ access = readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_BEEN_SEIZED |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* clear the BEEN_SEIZED flag and make sure it's gone */
+ writeb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_BEEN_SEIZED);
+
+ access = readb(TIS_REG(l - 1, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+ }
+
+ /*
+ * PENDING_REQUEST will not be set if locty = 0 since all localities
+ * were active; in case of locty = 1, locality 0 will be active
+ * but no PENDING_REQUEST anywhere
+ */
+ if (locty <= 1) {
+ pending_request_flag = 0;
+ }
+
+ /* release access from l - 1; this activates locty - 1 */
+ l--;
+
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+
+ DPRINTF("%s: %d: relinquishing control on l = %d\n",
+ __func__, __LINE__, l);
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ for (l = locty - 1; l >= 0; l--) {
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* release this locality */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+
+ if (l == 1) {
+ pending_request_flag = 0;
+ }
+ }
+
+ /* no locality may be active now */
+ for (l = 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+ }
+ }
+}
+
+/*
+ * Test case for getting access when higher number locality relinquishes access
+ */
+void tpm_tis_test_check_access_reg_release(const void *data)
+{
+ int locty, l;
+ uint8_t access;
+ uint8_t pending_request_flag;
+
+ /* do not test locality 4 (hw only) */
+ for (locty = TPM_TIS_NUM_LOCALITIES - 2; locty >= 0; locty--) {
+ pending_request_flag = 0;
+
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* request use of locality */
+ writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+ access = readb(TIS_REG(locty, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ /* request use of all other localities */
+ for (l = 0; l < TPM_TIS_NUM_LOCALITIES - 1; l++) {
+ if (l == locty) {
+ continue;
+ }
+ /*
+ * request use of locality 'l' -- we MUST see REQUEST USE and
+ * may see PENDING_REQUEST
+ */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_REQUEST_USE |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+ pending_request_flag = TPM_TIS_ACCESS_PENDING_REQUEST;
+ }
+ /* release locality 'locty' */
+ writeb(TIS_REG(locty, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+ /*
+ * highest locality should now be active; release it and make sure the
+ * next higest locality is active afterwards
+ */
+ for (l = TPM_TIS_NUM_LOCALITIES - 2; l >= 0; l--) {
+ if (l == locty) {
+ continue;
+ }
+ /* 'l' should be active now */
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+ /* 'l' relinquishes access */
+ writeb(TIS_REG(l, TPM_TIS_REG_ACCESS),
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+ access = readb(TIS_REG(l, TPM_TIS_REG_ACCESS));
+ DPRINTF_ACCESS;
+ if (l == 1 || (locty <= 1 && l == 2)) {
+ pending_request_flag = 0;
+ }
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ pending_request_flag |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+ }
+ }
+}
+
+/*
+ * Test case for transmitting packets
+ */
+void tpm_tis_test_check_transmit(const void *data)
+{
+ const TestState *s = data;
+ uint8_t access;
+ uint32_t sts;
+ uint16_t bcount;
+ size_t i;
+
+ /* request use of locality 0 */
+ writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_REQUEST_USE);
+ access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
+ g_assert_cmpint(access, ==, TPM_TIS_ACCESS_TPM_REG_VALID_STS |
+ TPM_TIS_ACCESS_ACTIVE_LOCALITY |
+ TPM_TIS_ACCESS_TPM_ESTABLISHMENT);
+
+ sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
+ DPRINTF_STS;
+
+ g_assert_cmpint(sts & 0xff, ==, 0);
+ g_assert_cmpint(sts & TPM_TIS_STS_TPM_FAMILY_MASK, ==,
+ TPM_TIS_STS_TPM_FAMILY2_0);
+
+ bcount = (sts >> 8) & 0xffff;
+ g_assert_cmpint(bcount, >=, 128);
+
+ writel(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_COMMAND_READY);
+ sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
+ DPRINTF_STS;
+ g_assert_cmpint(sts & 0xff, ==, TPM_TIS_STS_COMMAND_READY);
+
+ /* transmit command */
+ for (i = 0; i < sizeof(TPM_CMD); i++) {
+ writeb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO), TPM_CMD[i]);
+ sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
+ DPRINTF_STS;
+ if (i < sizeof(TPM_CMD) - 1) {
+ g_assert_cmpint(sts & 0xff, ==,
+ TPM_TIS_STS_EXPECT | TPM_TIS_STS_VALID);
+ } else {
+ g_assert_cmpint(sts & 0xff, ==, TPM_TIS_STS_VALID);
+ }
+ g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
+ }
+ /* start processing */
+ writeb(TIS_REG(0, TPM_TIS_REG_STS), TPM_TIS_STS_TPM_GO);
+
+ uint64_t end_time = g_get_monotonic_time() + 50 * G_TIME_SPAN_SECOND;
+ do {
+ sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
+ if ((sts & TPM_TIS_STS_DATA_AVAILABLE) != 0) {
+ break;
+ }
+ } while (g_get_monotonic_time() < end_time);
+
+ sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
+ DPRINTF_STS;
+ g_assert_cmpint(sts & 0xff, == ,
+ TPM_TIS_STS_VALID | TPM_TIS_STS_DATA_AVAILABLE);
+ bcount = (sts >> 8) & 0xffff;
+
+ /* read response */
+ uint8_t tpm_msg[sizeof(struct tpm_hdr)];
+ g_assert_cmpint(sizeof(tpm_msg), ==, bcount);
+
+ for (i = 0; i < sizeof(tpm_msg); i++) {
+ tpm_msg[i] = readb(TIS_REG(0, TPM_TIS_REG_DATA_FIFO));
+ sts = readl(TIS_REG(0, TPM_TIS_REG_STS));
+ DPRINTF_STS;
+ if (sts & TPM_TIS_STS_DATA_AVAILABLE) {
+ g_assert_cmpint((sts >> 8) & 0xffff, ==, --bcount);
+ }
+ }
+ g_assert_cmpmem(tpm_msg, sizeof(tpm_msg), s->tpm_msg, sizeof(*s->tpm_msg));
+
+ /* relinquish use of locality 0 */
+ writeb(TIS_REG(0, TPM_TIS_REG_ACCESS), TPM_TIS_ACCESS_ACTIVE_LOCALITY);
+ access = readb(TIS_REG(0, TPM_TIS_REG_ACCESS));
+}
diff --git a/tests/tpm-tis-util.h b/tests/tpm-tis-util.h
new file mode 100644
index 00000000..d10efe86
--- /dev/null
+++ b/tests/tpm-tis-util.h
@@ -0,0 +1,23 @@
+/*
+ * QTest TPM TIS: Common test functions used for both the
+ * ISA and SYSBUS devices
+ *
+ * Copyright (c) 2018 IBM Corporation
+ *
+ * Authors:
+ * Stefan Berger <stefanb@linux.vnet.ibm.com>
+ *
+ * This work is licensed under the terms of the GNU GPL, version 2 or later.
+ * See the COPYING file in the top-level directory.
+ */
+
+#ifndef TESTS_TPM_TIS_UTIL_H
+#define TESTS_TPM_TIS_UTIL_H
+
+void tpm_tis_test_check_localities(const void *data);
+void tpm_tis_test_check_access_reg(const void *data);
+void tpm_tis_test_check_access_reg_seize(const void *data);
+void tpm_tis_test_check_access_reg_release(const void *data);
+void tpm_tis_test_check_transmit(const void *data);
+
+#endif /* TESTS_TPM_TIS_UTIL_H */
diff --git a/tests/tpm-util.c b/tests/tpm-util.c
index 7ecdae2f..34efae8f 100644
--- a/tests/tpm-util.c
+++ b/tests/tpm-util.c
@@ -19,9 +19,6 @@
#include "tpm-util.h"
#include "qapi/qmp/qdict.h"
-#define TIS_REG(LOCTY, REG) \
- (TPM_TIS_ADDR_BASE + ((LOCTY) << 12) + REG)
-
void tpm_util_crb_transfer(QTestState *s,
const unsigned char *req, size_t req_size,
unsigned char *rsp, size_t rsp_size)
diff --git a/tests/tpm-util.h b/tests/tpm-util.h
index 15e39249..3b97d690 100644
--- a/tests/tpm-util.h
+++ b/tests/tpm-util.h
@@ -15,6 +15,11 @@
#include "io/channel-socket.h"
+extern uint64_t tpm_tis_base_addr;
+
+#define TIS_REG(LOCTY, REG) \
+ (tpm_tis_base_addr + ((LOCTY) << 12) + REG)
+
typedef void (tx_func)(QTestState *s,
const unsigned char *req, size_t req_size,
unsigned char *rsp, size_t rsp_size);
--
2.23.0
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/zhouli57/src-qemu.git
git@gitee.com:zhouli57/src-qemu.git
zhouli57
src-qemu
src-qemu
master

搜索帮助

0d507c66 1850385 C8b1a773 1850385