From 211151a39a5d5e204fff3d18a4b704aa478b7c07 Mon Sep 17 00:00:00 2001 From: Akeem G Abodunrin Date: Thu, 27 Feb 2020 00:09:25 +0000 Subject: scripts/generate_clear_kernel: Add script to assemble CB kernel MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This patch adds script and applicable assembly sources, so that we can use igt to assemble Clear Batch Buffer kernel for gen7 and gen7.5 devices - Resultant header files would be imported to i915, and used as they are... With this patch, user need to have mesa configured on their platform, before igt could be used to achieve the purpose of assembling the kernel from source. This is needed for "Security mitigation for Intel Gen7/7.5 HWs" Intel ID: PSIRT-TA-201910-001/CVEID: CVE-2019-14615 v2: Addressed formatting, -g option and other minor issues (Petri) v3: Update script due to suggested changes in i915, and Mesa tool v4: Update help comment with Mesa build option with meson (Petri) v5: Modify how user specify i965_asm - script now takes binary, instead of Mesa tool source directory (Ville). v6: Update script to reflect Mesa tool final changes to assemble CB kernel - and renamed files based on Petri's suggestion... Cc: Ville Syrjälä Cc: Jani Nikula Cc: Joonas Lahtinen Cc: Petri Latvala Cc: Bloomfield Jon Signed-off-by: Akeem G Abodunrin Reviewed-by: Petri Latvala --- scripts/generate_clear_kernel.sh | 151 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 151 insertions(+) create mode 100755 scripts/generate_clear_kernel.sh (limited to 'scripts') diff --git a/scripts/generate_clear_kernel.sh b/scripts/generate_clear_kernel.sh new file mode 100755 index 00000000..af628a86 --- /dev/null +++ b/scripts/generate_clear_kernel.sh @@ -0,0 +1,151 @@ +#!/bin/bash +# +# SPDX-License-Identifier: MIT +# +# Copyright © 2020 Intel Corporation +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +export ASSEMBLY_SOURCE=./lib/i915/shaders/clear_kernel + +function get_help { + echo "Usage: asm_eu_kernel.sh [options]" + echo "Note: hsw_clear_kernel.c/ivb_clear_kernel.c automatically generated by this script should never be modified - it would be imported to i915, to use as it is..." + echo " " + echo "Please make sure your Mesa tool is compiled with "-Dtools=intel" and "-Ddri-drivers=i965", and run this script from IGT source root directory" + echo " " + echo "Options are:" + echo " -h display this help message, and exit" + echo " -g=platform generation of device: use "hsw" for gen7.5, and "ivb" for gen7 devices" + echo " -o=name_of_file output file to store Mesa assembled c-literal for the device - If none specified, default file will be used - ivb/hsw-cb_assembled" + echo " -m=mesa Path to Mesa i965_asm binary" + echo " " + echo " Usage example: \"scripts/generate_clear_kernel.sh -g hsw -o hsw_clear_buffer.h -m /path/to/Mesa/i965_asm/binary\"" +} + +function include_array # $1=array_name - update Mesa output with desired format +{ + array_declaration="static const u32 $(basename $1)_clear_kernel[] = {" + close_array=";" + sed -i "1s/.*/$array_declaration/" $output_file + sed -i "$ s/$/$close_array/" $output_file +} +function prefix_header # $1=filename $2=comment +{ + cat < +{ + check_output_file + + # Using i965_asm tool to assemble hex file from assembly source + $mesa_i965_asm -g $gen_device -t c_literal $input_asm_source -o $output_file + + if [ ! -f ${output_file} ]; then + echo -e "Failed to assemble CB Kernel with Mesa tool\n" + get_help + exit 1 + fi + + # Generate header file + if [ "$gen_device" == "hsw" ]; then + echo "Generating gen7.5 CB Kernel assembled file \"hsw_clear_kernel.c\" for i915 driver..." + + i915_filename=hsw_clear_kernel.c + include_array $gen_device + prefix_header > $i915_filename + cat $output_file >> $i915_filename + + elif [ "$gen_device" == "ivb" ]; then + echo "Generating gen7 CB Kernel assembled file \"ivb_clear_kernel.c\" for i915 driver..." + + i915_filename=ivb_clear_kernel.c + include_array $gen_device + prefix_header $gen_device > $i915_filename + cat $output_file >> $i915_filename + fi +} + +while getopts "hg:o:m:" opt; do + case $opt in + h) get_help; exit 0;; + g) gen_device="$OPTARG" ;; + o) output_file="$OPTARG" ;; + m) mesa_i965_asm="$OPTARG" ;; + \?) + echo -e "Unknown option: -$OPTARG\n" + get_help + exit 1 + ;; + esac +done +shift $(($OPTIND-1)) + +if [ "x$1" != "x" ]; then + echo -e "Unknown option: $1\n" + get_help + exit 1 +fi + +if [ "x$mesa_i965_asm" == "x" ]; then + echo -e "i965_asm binary not found\n" + get_help + exit 1 +fi + +if [ "x$gen_device" != "x" ]; then + if [ "$gen_device" == "hsw" ]; then + input_asm_source="${ASSEMBLY_SOURCE}/hsw.asm" + elif [ "$gen_device" == "ivb" ]; then + input_asm_source="${ASSEMBLY_SOURCE}/ivb.asm" + else + echo -e "Unknown platform specified\n" + get_help + exit 1 + fi + asm_cb_kernel +else + echo -e "Platform generation not specified\n" + get_help + exit 1 +fi -- cgit v1.2.3