# SPDX-License-Identifier: GPL-2.0-or-later
# Copyright (C) 2026-present ArchR (https://github.com/archr-linux/Arch-R)

function gpu_profiling() {
  local sysfs_node
  local profiling_state=${1}
  
  case "${HW_DEVICE}" in
    S922X|RK3326)
      # Enable Panfrost profiling - see https://docs.kernel.org/gpu/panfrost.html
      if [[ -e "/sys/bus/platform/drivers/panfrost" ]]; then
        case "${profiling_state}" in
          "on")
            echo 1 > /sys/bus/platform/drivers/panfrost/[a-f0-9]*.gpu/profiling
          ;;
          "off")
            echo 0 > /sys/bus/platform/drivers/panfrost/[a-f0-9]*.gpu/profiling
          ;;
        esac
      fi
    ;;
  esac
}