aienux
Aienux, the AienOS kernel: boot, scheduling, IPC and capability boundaries. Pre-alpha; host, emulator and physical evidence are labelled separately.
Brought by drakestapleton
aienux / native / kernel / gpu / amd_smu.c
| 1 | /* native/kernel/gpu/amd_smu.c -- SMU (System Management Unit) state check for |
| 2 | * the 2017 iMac's AMD Radeon Pro 570/575/580 (Polaris 10, PCI 1002:67df). |
| 3 | * |
| 4 | * Apple's EFI leaves the SMC running with its full power-management firmware. |
| 5 | * We check: is it alive (its firmware header is readable), what version, and what |
| 6 | * power state it reports. We do NOT load or reset the SMC -- that would |
| 7 | * require the polaris10 SMC firmware blob to be present and the full init |
| 8 | * sequence (gfx_v8_0 + powerplay). Those are Steps 4-6. |
| 9 | * |
| 10 | * If the SMC is alive, we can use it later for fan and power-limit control. |
| 11 | * If it is not alive, we still proceed -- CP / SDMA do not need the SMC, and |
| 12 | * display works without it. |
| 13 | * |
| 14 | * Sources: include/asic_reg/smu/smu_7_1_3_d.h MIT (C) 2016 AMD, |
| 15 | * pm/powerplay/inc/smu7.h, smu7_ppsmc.h MIT (C) 2016 AMD. |
| 16 | * No floats. All waits TSC-bounded. */ |
| 17 | #include "amd_gpu.h" |
| 18 | |
| 19 | /* SMC indirect access helper (reads 32 bits from SMC address space). */ |
| 20 | static uint32_t smc_ind_rd(uint32_t addr) |
| 21 | { |
| 22 | amd_wr(mmSMC_IND_INDEX_0, addr); |
| 23 | __asm__ volatile("" ::: "memory"); |
| 24 | return amd_rd(mmSMC_IND_DATA_0); |
| 25 | } |
| 26 | |
| 27 | int amd_smu_check(void) |
| 28 | { |
| 29 | struct amd_gpu_state *g = &g_amd_gpu; |
| 30 | |
| 31 | if (!g->regs) { |
| 32 | ck_puts("gpu: smu: no register aperture\n"); |
| 33 | return -1; |
| 34 | } |
| 35 | |
| 36 | /* Read the SMC message registers directly to see if they look sane. Nothing is sent: |
| 37 | * Linux's only header-less message (PPSMC_MSG_Test) is an init command, not a ping. */ |
| 38 | uint32_t msg_reg = amd_rd(mmSMC_MESSAGE_0); |
| 39 | uint32_t resp_reg = amd_rd(mmSMC_RESP_0); |
| 40 | ck_printf("gpu: smu: SMC_MESSAGE_0=0x%08x SMC_RESP_0=0x%08x\n", msg_reg, resp_reg); |
| 41 | |
| 42 | if (msg_reg == 0xffffffffu && resp_reg == 0xffffffffu) { |
| 43 | ck_puts("gpu: smu: registers read all-ones (SMU not accessible)\n"); |
| 44 | g->smu_alive = 0; |
| 45 | g->steps_done |= AMD_STEP_SMU; |
| 46 | return 0; /* non-fatal: proceed without SMU */ |
| 47 | } |
| 48 | |
| 49 | /* The SMC firmware header sits at SMC address 0x20000 (smu7.h:166), reached through |
| 50 | * SMC_IND_INDEX_0 / SMC_IND_DATA_0 (it is SMC address space, not VRAM). Version is the |
| 51 | * dword after Digest[5] (smu7.h:139-140). All-ones or zero means the SMC is not running. */ |
| 52 | uint32_t fw_ver = smc_ind_rd(SMU7_FIRMWARE_HEADER_LOCATION + |
| 53 | SMU7_FIRMWARE_HEADER_Version_offset); |
| 54 | ck_printf("gpu: smu: SMC header at SMC+0x%x: Version=0x%08x\n", |
| 55 | SMU7_FIRMWARE_HEADER_LOCATION + SMU7_FIRMWARE_HEADER_Version_offset, fw_ver); |
| 56 | |
| 57 | g->smu_fw_ver = fw_ver; |
| 58 | g->smu_alive = (fw_ver != 0u && fw_ver != 0xffffffffu); |
| 59 | ck_printf("gpu: smu: smu_alive=%d fw_ver=0x%08x\n", g->smu_alive, g->smu_fw_ver); |
| 60 | |
| 61 | g->steps_done |= AMD_STEP_SMU; |
| 62 | ck_puts("gpu: smu: done\n"); |
| 63 | return 0; |
| 64 | } |