Vengineerの戯言

人生は短いけど、長いです。人生を楽しみましょう!

NVIDIAがGPUのKernel Modulesを公開したので、ソースコード解析をしてみる(その7)

はじめに

NVIDIAGPUのKernel Modulesを公開したので、ソースコード解析をしてみる、(その7)

今回は、デバイスドライバの登録時に何を行っているかを見ていきます。

nv_module_init

open-gpu-kernel-modules/nv.c at main · NVIDIA/open-gpu-kernel-modules · GitHub

  • nv_cap_drv_init
  • nvlink_drivers_init
  • nv_init_rsync_info
  • nv_sev_init
  • rm_init_rm
  • nv_module_state_init

rm_init_rm

nvidia_open

kgspInitRm

#define kgspInitRm(pGpu, pKernelGsp, pGspFw) kgspInitRm_IMPL(pGpu, pKernelGsp, pGspFw)

kgspInitRm_IMPL にて、GSP Firmware (SEC2) と MVDec0 Formware をダウンロードしているっぽい。

  • kgspExtractVbiosFromRom_HAL
#define kgspExtractVbiosFromRom_HAL(pGpu, pKernelGsp, ppVbiosImg) kgspExtractVbiosFromRom(pGpu, pKernelGsp, ppVbiosImg)

- kgspExtractVbiosFromRom_TU102

  • kgspParseFwsecUcodeFromVbiosImg
#define kgspParseFwsecUcodeFromVbiosImg(pGpu, pKernelGsp, pVbiosImg, ppFwsecUcode) kgspParseFwsecUcodeFromVbiosImg_IMPL(pGpu, pKernelGsp, pVbiosImg, ppFwsecUcode)

この関数で、ファイル (/lib/firmware/nvidia/515.43.04/gsp.bin) を解析する。

の中で、Falcon/RISC-V側にダウンロードしているっぽい。

kgspBootstrapRiscvOSEarly

FB layout

このファイルの中に、FB layout ということで、GSP FW booter image に関する記述が載っていました。

 * Calculate the FB layout. Also, copy GSP FW booter image to FB.
 *
 * Firmware scrubs the last 256mb of FB, no memory outside of this region
 * may be used until the FW RM has scrubbed the remainder of memory.
 *
 *   ---------------------------- <- fbSize (end of FB, 1M aligned)
 *   | VGA WORKSPACE            |
 *   ---------------------------- <- vbiosReservedOffset  (64K? aligned)
 *   | (potential align. gap)   |
 *   ---------------------------- <- gspFwWprEnd (128K aligned)
 *   | FRTS data                |    (frtsSize is 0 on GA100)
 *   | ------------------------ | <- frtsOffset
 *   | BOOT BIN (e.g. SK + BL)  |
 *   ---------------------------- <- bootBinOffset
 *   | GSP FW ELF               |
 *   ---------------------------- <- gspFwOffset
 *   | GSP FW (WPR) HEAP        |
 *   ---------------------------- <- gspFwHeapOffset
 *   | Booter-placed metadata   |
 *   | (struct GspFwWprMeta)    |
 *   ---------------------------- <- gspFwWprStart (128K aligned)
 *   | GSP FW (non-WPR) HEAP    |
 *   ---------------------------- <- nonWprHeapOffset, gspFwRsvdStart

この情報から見つけたのが、こちら

/*!
 * GSP firmware WPR metadata
 *
 * Initialized by CPU-RM and DMA'd to FB, at the end of what will be WPR2.
 * Verified, and locked in WPR2 by Booter.
 *
 * Firmware scrubs the last 256mb of FB, no memory outside of this region
 * may be used until the FW RM has scrubbed the remainder of memory.
 *
 *   ---------------------------- <- fbSize (end of FB, 1M aligned)
 *   | VGA WORKSPACE            |
 *   ---------------------------- <- vbiosReservedOffset  (64K? aligned)
 *   | (potential align. gap)   |
 *   ---------------------------- <- gspFwWprEnd (128K aligned)
 *   | FRTS data                |    (frtsSize is 0 on GA100)
 *   | ------------------------ | <- frtsOffset
 *   | BOOT BIN (e.g. SK + BL)  |
 *   ---------------------------- <- bootBinOffset
 *   | GSP FW ELF               |
 *   ---------------------------- <- gspFwOffset
 *   | GSP FW (WPR) HEAP        |
 *   ---------------------------- <- gspFwHeapOffset
 *   | Booter-placed metadata   |
 *   | (struct GspFwWprMeta)    |
 *   ---------------------------- <- gspFwWprStart (128K aligned)
 *   | GSP FW (non-WPR) HEAP    |
 *   ---------------------------- <- nonWprHeapOffset, gspFwRsvdStart
 *                                   (GSP_CARVEOUT_SIZE bytes from end of FB)
 */

おわりに

今回は、デバイスドライバの登録について、見てみました。