| 1 |
# Copyright (c) 2019, Intel Corporation |
| 2 |
# |
| 3 |
# Permission is hereby granted, free of charge, to any person obtaining a |
| 4 |
# copy of this software and associated documentation files (the "Software"), |
| 5 |
# to deal in the Software without restriction, including without limitation |
| 6 |
# the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 7 |
# and/or sell copies of the Software, and to permit persons to whom the |
| 8 |
# Software is furnished to do so, subject to the following conditions: |
| 9 |
# |
| 10 |
# The above copyright notice and this permission notice shall be included |
| 11 |
# in all copies or substantial portions of the Software. |
| 12 |
# |
| 13 |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 14 |
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 15 |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 16 |
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 17 |
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 18 |
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 19 |
# OTHER DEALINGS IN THE SOFTWARE. |
| 20 |
|
| 21 |
#check whether need some flags to guard the including of below folders |
| 22 |
|
| 23 |
function(gen_vpkernel_from_cm) |
| 24 |
|
| 25 |
set(genx "g12") |
| 26 |
set(kind "tgllp") |
| 27 |
set(name "vp") |
| 28 |
set(platform "gen12_tgllp") |
| 29 |
|
| 30 |
set(krn ig${name}krn_${genx}_${kind}_cmfc) |
| 31 |
set(krnpatch ig${name}krn_${genx}_${kind}_cmfcpatch) |
| 32 |
set(krn_dir ${CMAKE_SOURCE_DIR}/media_driver/agnostic/${platform}/vp/kernel_free) |
| 33 |
set(link_file ${krn_dir}/component_release/LinkFile.txt) |
| 34 |
set(cache_dir ${CMAKE_SOURCE_DIR}/media_driver/agnostic/${platform}/vp/kernel_free/cache_kernel) |
| 35 |
set(kernel_dir ${cache_dir}/kernel) |
| 36 |
set(patch_dir ${cache_dir}/fcpatch) |
| 37 |
set(kernel_hex_dir ${kernel_dir}/hex) |
| 38 |
set(patch_hex_dir ${patch_dir}/hex) |
| 39 |
set(common_header ${CMAKE_SOURCE_DIR}/media_common/agnostic/common/vp/kernel/${name}krnheader.h) |
| 40 |
set(header ${CMAKE_CURRENT_LIST_DIR}/${name}krnheader.h) |
| 41 |
|
| 42 |
message("krn: " ${krn}) |
| 43 |
message("krnpatch: " ${krnpatch}) |
| 44 |
message("krn_dir: " ${krn_dir}) |
| 45 |
message("cache_dir: " ${cache_dir}) |
| 46 |
message("link_file: " ${link_file}) |
| 47 |
message("kernel_dir: " ${kernel_dir}) |
| 48 |
message("patch_dir: " ${patch_dir}) |
| 49 |
message("kernel_hex_dir: " ${kernel_hex_dir}) |
| 50 |
message("patch_hex_dir: " ${patch_hex_dir}) |
| 51 |
message("common_header: " ${common_header}) |
| 52 |
message("header: " ${header}) |
| 53 |
|
| 54 |
add_custom_command( |
| 55 |
OUTPUT ${cache_dir} ${kernel_dir} ${patch_dir} ${kernel_hex_dir} ${patch_hex_dir} |
| 56 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${cache_dir} |
| 57 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${kernel_dir} |
| 58 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${patch_dir} |
| 59 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${kernel_hex_dir} |
| 60 |
COMMAND ${CMAKE_COMMAND} -E make_directory ${patch_hex_dir} |
| 61 |
COMMENT "Creating VP cmfc kernels output directory") |
| 62 |
|
| 63 |
# Compiling all the sources in the kernel source directory. |
| 64 |
file(GLOB_RECURSE srcs ${krn_dir}/Source/*.cpp) |
| 65 |
|
| 66 |
set(objsname "") |
| 67 |
set(cm_genx tgllp) |
| 68 |
|
| 69 |
foreach(src ${srcs}) |
| 70 |
get_filename_component(obj ${src} NAME_WE) # there are other outputs from cmc command, but we use only .dat and .fcpatch |
| 71 |
|
| 72 |
string(FIND ${obj} "Dscale" retVal) |
| 73 |
if(NOT retVal STREQUAL "-1") |
| 74 |
string(REPLACE "Dscale" "DScale" obj ${obj}) |
| 75 |
endif() |
| 76 |
|
| 77 |
if(obj STREQUAL "EOT" OR obj STREQUAL "Secure_Block_Copy") # "EOT" and "Secure_Block_Copy" don't generate the related .fcpatch file. |
| 78 |
add_custom_command( |
| 79 |
OUTPUT ${cache_dir}/${obj}_0.dat |
| 80 |
DEPENDS ${src} ${cache_dir} |
| 81 |
WORKING_DIRECTORY ${cache_dir} |
| 82 |
COMMAND ${CMC} |
| 83 |
-c -Qxcm -Qxcm_jit_target=${cm_genx} |
| 84 |
-I ${krn_dir}/Source/ |
| 85 |
-I ${krn_dir}/Source/Common |
| 86 |
-I ${krn_dir}/Source/Components |
| 87 |
-I ${krn_dir}/Source/Core_Kernels |
| 88 |
-Qxcm_jit_option="-nocompaction -output -binary" |
| 89 |
-mCM_emit_common_isa |
| 90 |
-mCM_no_input_reorder |
| 91 |
-mCM_unique_labels=MDF_FC |
| 92 |
-mCM_printregusage |
| 93 |
-mCM_old_asm_name |
| 94 |
${src} |
| 95 |
&& python ${krn_dir}/Source/rename.py ${cache_dir} ${obj}_0.dat |
| 96 |
COMMENT "Compiling ${src}... to ${cache_dir}/${obj}_0.dat\ |
| 97 |
Checking if renaming is needed..." |
| 98 |
) |
| 99 |
else() |
| 100 |
add_custom_command( |
| 101 |
OUTPUT ${cache_dir}/${obj}_0.dat ${cache_dir}/${obj}.fcpatch |
| 102 |
DEPENDS ${src} ${cache_dir} |
| 103 |
WORKING_DIRECTORY ${cache_dir} |
| 104 |
COMMAND ${CMC} |
| 105 |
-c -Qxcm -Qxcm_jit_target=${cm_genx} |
| 106 |
-I ${krn_dir}/Source/ |
| 107 |
-I ${krn_dir}/Source/Common |
| 108 |
-I ${krn_dir}/Source/Components |
| 109 |
-I ${krn_dir}/Source/Core_Kernels |
| 110 |
-Qxcm_jit_option="-nocompaction -output -binary" |
| 111 |
-mCM_emit_common_isa |
| 112 |
-mCM_no_input_reorder |
| 113 |
-mCM_unique_labels=MDF_FC |
| 114 |
-mCM_printregusage |
| 115 |
-mCM_old_asm_name |
| 116 |
${src} |
| 117 |
&& python ${krn_dir}/Source/rename.py ${cache_dir} ${obj}_0.dat ${obj}.fcpatch |
| 118 |
COMMENT "Compiling ${src}... to ${cache_dir}/${obj}_0.dat\ |
| 119 |
Checking if renaming is needed..." |
| 120 |
) |
| 121 |
endif() |
| 122 |
list(APPEND objsname |
| 123 |
${obj} |
| 124 |
) |
| 125 |
endforeach() |
| 126 |
|
| 127 |
#Generate the .hex files from the .dat files by using KrnToHex. |
| 128 |
set(hexs "") |
| 129 |
|
| 130 |
foreach(objname ${objsname}) |
| 131 |
add_custom_command( |
| 132 |
OUTPUT ${kernel_dir}/${objname}.krn |
| 133 |
DEPENDS ${cache_dir}/${objname}_0.dat ${kernel_dir} |
| 134 |
WORKING_DIRECTORY ${cache_dir} |
| 135 |
COMMAND ${CMAKE_COMMAND} -E copy ${cache_dir}/${objname}_0.dat ${kernel_dir}/${objname}.krn |
| 136 |
) |
| 137 |
endforeach() |
| 138 |
|
| 139 |
foreach(objname ${objsname}) |
| 140 |
add_custom_command( |
| 141 |
OUTPUT ${kernel_hex_dir}/${objname}.hex |
| 142 |
DEPENDS KrnToHex ${kernel_dir}/${objname}.krn ${kernel_hex_dir} |
| 143 |
WORKING_DIRECTORY ${kernel_dir} |
| 144 |
COMMAND KrnToHex ${kernel_dir}/${objname}.krn |
| 145 |
COMMAND ${CMAKE_COMMAND} -E copy ${kernel_dir}/${objname}.hex ${kernel_hex_dir}/${objname}.hex |
| 146 |
COMMAND ${CMAKE_COMMAND} -E remove ${kernel_dir}/${objname}.hex |
| 147 |
COMMENT "Generate the hex files of cmfc kernel" |
| 148 |
) |
| 149 |
set(hexs ${hexs} ${kernel_hex_dir}/${objname}.hex) |
| 150 |
endforeach() |
| 151 |
|
| 152 |
##Generate the .hex files from the .fcpatch files by using KrnToHex. |
| 153 |
|
| 154 |
list(REMOVE_ITEM objsname "EOT" "Secure_Block_Copy") # Remove "EOT" and "Secure_Block_Copy". |
| 155 |
|
| 156 |
foreach(objname ${objsname}) |
| 157 |
add_custom_command( |
| 158 |
OUTPUT ${patch_dir}/${objname}.krn |
| 159 |
DEPENDS ${cache_dir}/${objname}.fcpatch ${patch_dir} |
| 160 |
WORKING_DIRECTORY ${cache_dir} |
| 161 |
COMMAND ${CMAKE_COMMAND} -E copy ${cache_dir}/${objname}.fcpatch ${patch_dir}/${objname}.krn |
| 162 |
) |
| 163 |
endforeach() |
| 164 |
|
| 165 |
set(fcpatch_hexs "") |
| 166 |
foreach(objname ${objsname}) |
| 167 |
add_custom_command( |
| 168 |
OUTPUT ${patch_hex_dir}/${objname}.hex |
| 169 |
DEPENDS KrnToHex ${patch_dir}/${objname}.krn ${patch_hex_dir} |
| 170 |
WORKING_DIRECTORY ${patch_dir} |
| 171 |
COMMAND KrnToHex ${patch_dir}/${objname}.krn |
| 172 |
COMMAND ${CMAKE_COMMAND} -E copy ${patch_dir}/${objname}.hex ${patch_hex_dir}/${objname}.hex |
| 173 |
COMMAND ${CMAKE_COMMAND} -E remove ${patch_dir}/${objname}.hex |
| 174 |
COMMENT "Generate the hex files of cmfc patch" |
| 175 |
) |
| 176 |
set(fcpatch_hexs ${fcpatch_hexs} ${patch_hex_dir}/${objname}.hex) |
| 177 |
endforeach() |
| 178 |
|
| 179 |
add_custom_command( |
| 180 |
OUTPUT ${common_header} |
| 181 |
DEPENDS GenDmyHex ${kernel_hex_dir} #Generate the dummy hexs from the pre-built header |
| 182 |
COMMAND GenDmyHex ${kernel_hex_dir} ${common_header} |
| 183 |
COMMENT "Generating ${common_header} in ${kernel_hex_dir} using GenDmyHex..." |
| 184 |
) |
| 185 |
|
| 186 |
# Generating the .bin files for cmfc kernel and patch respectively. |
| 187 |
|
| 188 |
add_custom_command( |
| 189 |
OUTPUT ${kernel_hex_dir}/${krn}.bin |
| 190 |
DEPENDS GenDmyHex GenKrnBin ${hexs} ${link_file} #Generate the dummy hexs from the pre-built header |
| 191 |
WORKING_DIRECTORY ${kernel_hex_dir} |
| 192 |
COMMAND ${CMAKE_COMMAND} -E copy ${link_file} ${kernel_hex_dir} |
| 193 |
COMMAND GenKrnBin ${kernel_hex_dir} ${name} ${genx} tgllp_cmfc |
| 194 |
COMMAND ${CMAKE_COMMAND} -E copy ${kernel_hex_dir}/${krn}.h ${header} |
| 195 |
#COMMAND ${CMAKE_COMMAND} -E copy ${header} ${common_header} |
| 196 |
COMMENT "Copying ${link_file} to ${kernel_hex_dir}\ |
| 197 |
Generating ${name} ${genx} ${kind} in ${kernel_hex_dir}...\ |
| 198 |
Copying ${kernel_hex_dir}/${krn}.h to ${common_header}..." |
| 199 |
) |
| 200 |
|
| 201 |
add_custom_command( |
| 202 |
OUTPUT ${patch_hex_dir}/${krnpatch}.bin |
| 203 |
DEPENDS GenKrnBin ${fcpatch_hexs} ${link_file} |
| 204 |
WORKING_DIRECTORY ${patch_hex_dir} |
| 205 |
COMMAND ${CMAKE_COMMAND} -E copy ${link_file} ${patch_hex_dir} |
| 206 |
COMMAND GenKrnBin ${patch_hex_dir} ${name} ${genx} tgllp_cmfcpatch |
| 207 |
COMMENT "Copying ${link_file} to ${patch_hex_dir}...\ |
| 208 |
GenKrnBin ${patch_hex_dir} ${name} ${genx} tgllp_cmfcpatch" |
| 209 |
) |
| 210 |
|
| 211 |
# Generating kernel source files for cmfc kernel and patch. |
| 212 |
|
| 213 |
message("Kernel file ${krn_dir}/cmfc/${krn}.c will be generated") |
| 214 |
add_custom_command( |
| 215 |
OUTPUT ${krn_dir}/cmfc/${krn}.c ${krn_dir}/cmfc/${krn}.h |
| 216 |
DEPENDS KernelBinToSource ${kernel_hex_dir}/${krn}.bin |
| 217 |
COMMAND KernelBinToSource -i ${kernel_hex_dir}/${krn}.bin -o ${krn_dir}/cmfc |
| 218 |
COMMENT "Generating kernel file...\ |
| 219 |
KernelBinToSource -i ${kernel_hex_dir}/${krn}.bin -o ${krn_dir}/cmfc" |
| 220 |
) |
| 221 |
|
| 222 |
message("FC patch file ${krn_dir}/cmfcpatch/${krnpatch}.c will be generated") |
| 223 |
add_custom_command( |
| 224 |
OUTPUT ${krn_dir}/cmfcpatch/${krnpatch}.c ${krn_dir}/cmfcpatch/${krnpatch}.h |
| 225 |
DEPENDS KernelBinToSource ${patch_hex_dir}/${krnpatch}.bin |
| 226 |
COMMAND KernelBinToSource -i ${patch_hex_dir}/${krnpatch}.bin -o ${krn_dir}/cmfcpatch |
| 227 |
COMMENT "Generating FC patch file...\ |
| 228 |
KernelBinToSource -i ${patch_hex_dir}/${krnpatch}.bin -o ${krn_dir}/cmfcpatch" |
| 229 |
) |
| 230 |
|
| 231 |
endfunction() |
| 232 |
|
| 233 |
|
| 234 |
if(BUILD_KERNELS) |
| 235 |
gen_vpkernel_from_cm() |
| 236 |
endif() |
| 237 |
|
| 238 |
media_include_subdirectory(cmfc) |
| 239 |
media_include_subdirectory(cmfcpatch) |
| 240 |
|
| 241 |
source_group( "Kernel\\VpKernel" FILES ${TMP_SOURCES_} ${TMP_HEADERS_} ) |
| 242 |
|
| 243 |
media_add_curr_to_include_path() |