#!/bin/bash
# Analyze ppfeaturemask for AMD GPU OC

MASK=$(cat /sys/module/amdgpu/parameters/ppfeaturemask 2>/dev/null)
echo "Current ppfeaturemask: $MASK"

python3 -c "
mask = $MASK
print(f'Hex: {mask:#010x}')
print(f'Binary: {mask:032b}')
print()
bits = {
    0: 'PP_FEATURE_DPM_PREFETCHER',
    1: 'PP_FEATURE_DPM_GFXCLK',
    2: 'PP_FEATURE_DPM_UCLK',
    3: 'PP_FEATURE_DPM_SOCCLK',
    4: 'PP_FEATURE_DPM_MP0CLK',
    5: 'PP_FEATURE_DPM_LINK',
    6: 'PP_FEATURE_DPM_DCEFCLK',
    8: 'PP_FEATURE_DS_GFXCLK',
    9: 'PP_FEATURE_DS_SOCCLK',
    10: 'PP_FEATURE_DS_LCLK',
    11: 'PP_FEATURE_DS_FCLK',
    12: 'PP_FEATURE_DS_MP1CLK',
    13: 'PP_FEATURE_FW_DSTATE',
    14: 'PP_OVERDRIVE_MASK',
    15: 'PP_GFXOFF_MASK',
}
for bit, name in sorted(bits.items()):
    val = bool((mask >> bit) & 1)
    flag = 'ON' if val else 'OFF'
    print(f'  Bit {bit:2d}: {flag:3s} - {name}')

# Try all bits ON
full = 0xffffffff
print(f'\nFull enable: {full:#010x}')
# OD specifically
od = mask | (1 << 14)
print(f'With OD: {od:#010x}')
"

echo ""
echo "=== Current boot params ==="
grep -i amdgpu /boot/limine.conf 2>/dev/null || grep -i amdgpu /proc/cmdline 2>/dev/null
