1 /*
2 * Copyright (c) 2019, Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included
12 * in all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 */
22
23 #include "MDF_FC_common_genx.h"
24
Secure_Block_Copy(ushort Block_Height,ushort Buffer_Offset)25 _GENX_MAIN_ void Secure_Block_Copy(ushort Block_Height, ushort Buffer_Offset)
26 {
27 SurfaceIndex Input_Surface(MDF_FC_SECURITY_COPY_INPUT_BTI);
28 SurfaceIndex Output_Surface(MDF_FC_SECURITY_COPY_OUTPUT_BTI);
29
30 matrix<uint, 9, 8> Mesg1;
31 matrix<uint, 9, 8> Mesg2;
32
33 uint desc_y1, desc_y2;
34 uint desc_y3, desc_y4;
35
36 Mesg1.select<1, 1, 8, 1>(0, 0) = cm_get_r0();
37 Mesg2.select<1, 1, 8, 1>(0, 0) = cm_get_r0();
38
39 matrix_ref<uchar, 8, 32> Temp1 = Mesg1.format<uchar, 9, 32>().select<8, 1, 32, 1>(1, 0);
40 matrix_ref<uchar, 8, 32> Temp2 = Mesg2.format<uchar, 9, 32>().select<8, 1, 32, 1>(1, 0);
41 uint Read_8_rows;
42 Read_8_rows = Block_Height & 0xFFF8;
43
44 uint RemainingRowOffset = Buffer_Offset + Read_8_rows;
45 uint RemainingRows = Block_Height & 0x7;
46
47 for (uint i = 0; i < Read_8_rows; i+= 8)
48 {
49 read(Input_Surface, 0, i + Buffer_Offset, Temp1);
50 write(Output_Surface, 0, i + Buffer_Offset, Temp1);
51 read(Input_Surface, 32, i + Buffer_Offset, Temp2);
52 write(Output_Surface,32, i + Buffer_Offset, Temp2);
53 }
54
55 if (RemainingRows)
56 {
57 desc_y1 = nDPMR_MSGDSC + (RemainingRows << 20) + MDF_FC_SECURITY_COPY_INPUT_BTI;
58 desc_y2 = nDPMW_MSGDSC + (RemainingRows << 25) + MDF_FC_SECURITY_COPY_OUTPUT_BTI;
59
60 desc_y3 = nDPMR_MSGDSC + (RemainingRows << 20) + MDF_FC_SECURITY_COPY_INPUT_BTI;
61 desc_y4 = nDPMW_MSGDSC + (RemainingRows << 25) + MDF_FC_SECURITY_COPY_OUTPUT_BTI;
62
63 Mesg1.select<1, 1, 1, 1>(0, 0) = 0;
64 Mesg1.select<1, 1, 1, 1>(0, 1) = RemainingRowOffset;
65 Mesg1.select<1, 1, 1, 1>(0, 2) = nBLOCK_WIDTH_32 + ((RemainingRows - 1) << 16);
66
67 Mesg2.select<1, 1, 1, 1>(0, 0) = 32;
68 Mesg2.select<1, 1, 1, 1>(0, 1) = RemainingRowOffset;
69 Mesg2.select<1, 1, 1, 1>(0, 2) = nBLOCK_WIDTH_32 + ((RemainingRows - 1) << 16);
70
71 // left half read/write
72 cm_send(Temp1,
73 Mesg1,
74 nDATAPORT_DC1,
75 desc_y1,
76 0);
77
78 cm_send(NULL,
79 Mesg1,
80 nDATAPORT_DC1,
81 desc_y2,
82 0);
83
84 // right half read/write
85 cm_send(Temp2,
86 Mesg2,
87 nDATAPORT_DC1,
88 desc_y3,
89 0);
90
91 cm_send(NULL,
92 Mesg2,
93 nDATAPORT_DC1,
94 desc_y4,
95 0);
96
97 }
98 }