1 /*
2  * Copyright 2019 The Hafnium Authors.
3  *
4  * Use of this source code is governed by a BSD-style
5  * license that can be found in the LICENSE file or at
6  * https://opensource.org/licenses/BSD-3-Clause.
7  */
8 
9 #include "hf/arch/std.h"
10 #include "hf/arch/vm/registers.h"
11 
12 #include "hf/ffa.h"
13 
14 #include "vmapi/hf/call.h"
15 
16 #include "../msr.h"
17 #include "primary_with_secondary.h"
18 #include "test/hftest.h"
19 #include "test/vmapi/ffa.h"
20 
TEAR_DOWN(floating_point)21 TEAR_DOWN(floating_point)
22 {
23 	EXPECT_FFA_ERROR(ffa_rx_release(), FFA_DENIED);
24 }
25 
26 /**
27  * Test that floating point registers are saved and restored by
28  * filling them with one value here and a different value in the
29  * service.
30  */
TEST(floating_point,fp_fill)31 TEST(floating_point, fp_fill)
32 {
33 	const double first = 1.2;
34 	const double second = -2.3;
35 	struct ffa_value run_res;
36 	struct mailbox_buffers mb = set_up_mailbox();
37 
38 	fill_fp_registers(first);
39 	SERVICE_SELECT(SERVICE_VM1, "fp_fill", mb.send);
40 	run_res = ffa_run(SERVICE_VM1, 0);
41 	EXPECT_EQ(run_res.func, FFA_YIELD_32);
42 	EXPECT_EQ(check_fp_register(first), true);
43 
44 	fill_fp_registers(second);
45 	run_res = ffa_run(SERVICE_VM1, 0);
46 	EXPECT_EQ(run_res.func, FFA_YIELD_32);
47 	EXPECT_EQ(check_fp_register(second), true);
48 }
49 
50 /**
51  * Test that the floating point control register is restored correctly
52  * on full context switch when needed by changing it in the service.
53  */
TEST(floating_point,fp_fpcr)54 TEST(floating_point, fp_fpcr)
55 {
56 	uintreg_t value = 0;
57 	struct ffa_value run_res;
58 	struct mailbox_buffers mb = set_up_mailbox();
59 
60 	EXPECT_EQ(read_msr(fpcr), value);
61 
62 	SERVICE_SELECT(SERVICE_VM1, "fp_fpcr", mb.send);
63 	run_res = ffa_run(SERVICE_VM1, 0);
64 	EXPECT_EQ(run_res.func, FFA_YIELD_32);
65 	EXPECT_EQ(read_msr(fpcr), value);
66 
67 	run_res = ffa_run(SERVICE_VM1, 0);
68 	EXPECT_EQ(run_res.func, FFA_YIELD_32);
69 	EXPECT_EQ(read_msr(fpcr), value);
70 }
71