# Copyright 2023 The Hafnium Authors.
#
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file or at
# https://opensource.org/licenses/BSD-3-Clause.

import("//build/image/image.gni")
import("//test/hftest/args.gni")

config("config") {
  include_dirs = [
    "inc",
    "//test/vmapi/common/arch/aarch64/secure/inc/",
  ]
}

source_set("message_loop") {
  testonly = true
  public_configs = [
    ":config",
    "//test/hftest:hftest_config",
    "//src/arch/aarch64:arch_config",
  ]
  sources = [ "message_loop.c" ]
  deps = [ "//test/vmapi/common:ffa" ]
}

source_set("secure_interrupts") {
  testonly = true
  public_configs = [
    ":config",
    "//test/hftest:hftest_config",
    "//src/arch/aarch64:arch_config",
    "//src/arch/aarch64:config",
  ]
  sources = [ "secure_interrupts.c" ]
  deps = [
    "//src/arch/aarch64:smc",
    "//test/vmapi/common:ffa",
    "//test/vmapi/common/arch/aarch64/secure:twdog",
    "//test/vmapi/common/arch/aarch64/system_timer:ap_refclk",
    "//test/vmapi/primary_with_secondaries:ipi_state",
    "//test/vmapi/primary_with_secondaries:twdog_state",
  ]
}

vm_kernel("secure_service") {
  testonly = true
  deps = [
    ":message_loop",
    ":secure_interrupts",
    "//src/arch/aarch64/hftest:interrupts",
    "//src/arch/aarch64/hftest:mm",
    "//test/hftest:hftest_secure_service",
    "//test/vmapi/common/arch/aarch64:exception_handler",
    "//test/vmapi/primary_with_secondaries:primary_with_secondaries",
    "//test/vmapi/primary_with_secondaries/services:boot",
    "//test/vmapi/primary_with_secondaries/services:echo",
    "//test/vmapi/primary_with_secondaries/services:ffa_check",
    "//test/vmapi/primary_with_secondaries/services:memory",
    "//test/vmapi/primary_with_secondaries/services:relay",
    "//test/vmapi/primary_with_secondaries/services:rx_ownership",
    "//test/vmapi/primary_with_secondaries/services:smccc",
    "//vmlib/${plat_arch}:call",
  ]
}

manifest("partition_manifest_service_sp1") {
  source = "partition_manifest_service_sp1.dts"
  output = "partition_manifest_service_sp1.dtb"
}

manifest("partition_manifest_service_sp2") {
  source = "partition_manifest_service_sp2.dts"
  output = "partition_manifest_service_sp2.dtb"
}

manifest("partition_manifest_service_sp3") {
  source = "partition_manifest_service_sp3.dts"
  output = "partition_manifest_service_sp3.dtb"
}

# Partition using FF-A v1.1 for use in backwards compatibility tests.
manifest("partition_manifest_service_sp4") {
  source = "partition_manifest_service_sp4.dts"
  output = "partition_manifest_service_sp4.dtb"
}

partition_package("service_sp1_partition_package") {
  testonly = true
  pm_offset = "0x1000"
  img_offset = "0x2000"
  files = [ [
        "partition_manifest_service_sp1.dtb",
        "secure_service.bin",
        ":partition_manifest_service_sp1",
        ":secure_service",
      ] ]
  output = "service_sp1_partition_package.img"
}

partition_package("service_sp2_partition_package") {
  testonly = true
  pm_offset = "0x1000"
  img_offset = "0x2000"
  files = [ [
        "partition_manifest_service_sp2.dtb",
        "secure_service.bin",
        ":partition_manifest_service_sp2",
        ":secure_service",
      ] ]
  output = "service_sp2_partition_package.img"
}

partition_package("service_sp3_partition_package") {
  testonly = true
  pm_offset = "0x1000"
  img_offset = "0x2000"
  files = [ [
        "partition_manifest_service_sp3.dtb",
        "secure_service.bin",
        ":partition_manifest_service_sp3",
        ":secure_service",
      ] ]
  output = "service_sp3_partition_package.img"
}

partition_package("service_sp4_partition_package") {
  testonly = true
  pm_offset = "0x1000"
  img_offset = "0x2000"
  files = [ [
        "partition_manifest_service_sp4.dtb",
        "secure_service.bin",
        ":partition_manifest_service_sp4",
        ":secure_service",
      ] ]
  output = "service_sp4_partition_package.img"
}
