1 /* 2 * AMD SEV test cases 3 * 4 * Copyright (c) 2021, Google Inc 5 * 6 * Authors: 7 * Hyunwook (Wooky) Baek <baekhw@google.com> 8 * Zixuan Wang <zixuanwang@google.com> 9 * 10 * SPDX-License-Identifier: LGPL-2.0-or-later 11 */ 12 13 #include "libcflat.h" 14 #include "x86/processor.h" 15 #include "x86/amd_sev.h" 16 #include "msr.h" 17 18 #define TESTDEV_IO_PORT 0xe0 19 20 static char st1[] = "abcdefghijklmnop"; 21 test_stringio(void)22static void test_stringio(void) 23 { 24 int st1_len = sizeof(st1) - 1; 25 u16 got; 26 27 asm volatile("cld \n\t" 28 "movw %0, %%dx \n\t" 29 "rep outsw \n\t" 30 : : "i"((short)TESTDEV_IO_PORT), 31 "S"(st1), "c"(st1_len / 2)); 32 33 asm volatile("inw %1, %0\n\t" : "=a"(got) : "i"((short)TESTDEV_IO_PORT)); 34 35 report((got & 0xff) == st1[sizeof(st1) - 3], "outsb nearly up"); 36 report((got & 0xff00) >> 8 == st1[sizeof(st1) - 2], "outsb up"); 37 } 38 main(void)39int main(void) 40 { 41 if (!amd_sev_enabled()) { 42 report_skip("AMD SEV not enabled\n"); 43 goto out; 44 } 45 46 printf("SEV-ES is %senabled.\n", amd_sev_es_enabled() ? "" : "not "); 47 48 test_stringio(); 49 50 out: 51 return report_summary(); 52 } 53