Habana Labs kernel driver
Subsystems (7)
cover Habana Labs kernel driver
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Habana is a leading startup in the emerging AI processor space and we have already started production of our first Goya inference processor PCIe card and delivered it to customers. The Goya processor silicon has been tested since June of 2018 and is production-qualified by now. The Gaudi training processor solution is slated to sample in the second quarter of 2019.
This patch-set contains the kernel driver for Habana's AI Processors (AIP) that are designed to accelerate Deep Learning inference and training workloads. The current version supports only the Goya processor and support for Gaudi will be upstreamed after the ASIC will be available to customers.
The Goya processor has been designed from the ground up for deep learning inference workloads. It comprises a cluster of eight fully programmable Tensor Processing Cores (TPC). The TPC core is a VLIW SIMD vector processor with ISA and hardware that was tailored to serve deep learning workloads efficiently.
In addition, Goya contains software-managed, on-die memory along with five separate DMA channels, a PCIe Gen4 x16 system interface and 4/8/16GB of DDR4 memory.
Goya has 3 PCI bars (64-bit), which are not exposed to user-space. They map the on-chip memory and configuration space (bar 0-1), MSI-X table (bar 2-3) and DDR4 memory (bar 4-5).
Each TPC engine and DMA channel has a H/W queue attached to it, called QMAN. The S/W provides command buffers to the H/W queues (through the kernel driver) and the H/W consumes the command buffers. To prevent malicious users from stealing data from other users through the Host or Device memory, Goya has an internal MMU and a security protection scheme. In addition, The kernel driver parses the command buffer and rejects it if it contains disallowed commands.
The QMANs are triggered by a write to a PI (producer index) register. The QMAN H/W logic maintains a CI (consumer index) register. When PI==CI, the queue is empty. When PI+1==CI, the queue is full (note the queue is cyclic). Each entry in the H/W queue is 16-bytes, and contains a pointer and length of a variable-size command buffer, which the user fills with specific commands that the H/W logic can read and execute.
For each DMA QMAN, there is a completion queue that the QMAN writes to when it finishes the execution of the command buffer. The QMAN also sends an MSI-X interrupt after writing the completion entry.
Inference workloads running on Goya are associated with an address space through the ASID (address-space ID) property. Goya supports up to 1024 ASIDs. The ASID value is updated by the kernel driver in the relevant registers before scheduling a workload.
During its initialization, the driver registers itself to the PCI subsystem. For each Habana PCI device found, a char device node (/dev/hlX) is created.
The driver currently exposes a total of five IOCTLs. One IOCTL allows the application to submit workloads to the device, and another to wait on completion of submitted workloads. The other three IOCTLs are used for memory management, command buffer creation and information/status retrieval.
In addition, the driver exposes several sensors through the hwmon subsystem and provides various system-level information in sysfs for system administrators.
The first step for an application process is to open the correct hlX device it wants to work with. Calls to open create a new "context" for that application in the driver's internal structures and a unique ASID is assigned to that context. The context object lives until the process releases the file descriptor AND its command submissions have finished executing on the device.
Next step is for the application to request information about the device, such as amount of DDR4 memory. The application then can go on to create command buffers for its command submissions and allocate and map device or host memory (host memory can only be mapped) to the internal device's MMU subsystem.
At this point the application can load various deep learning topologies to the device DDR memory. After that, it can start to submit inference workloads using those topologies. For each workload, the the application receives a sequence number that represents the workload. The application can then query the driver regarding the status of the workload using that sequence number.
In case a workload didn't finish execution after 5 seconds (configurable using a kernel module parameter) from the time it was scheduled to run, a TDR (timeout detection & recovery) event occurs in the driver. The driver will then mark that workload as "timed out", perform a minimal reset of the device (DMA and compute units only) and abort all other workloads of that context that were already submitted to the H/W queues.
I would appricate any feedback, question and/or review.
p.s. for those who prefer to clone the tree instead of looking at the emails, you can grab a copy from our company's page in GitHub:
https://github.com/HabanaAI/linux/releases/tag/hl_patchset_v1
Thanks,
Oded
Oded Gabbay (14):
habanalabs: add skeleton driver
habanalabs: add Goya registers header files
habanalabs: add basic Goya support
habanalabs: add context and ASID modules
habanalabs: add command buffer module
habanalabs: add basic Goya h/w initialization
habanalabs: add h/w queues module
habanalabs: add event queue and interrupts
habanalabs: add sysfs and hwmon support
habanalabs: add device reset support
habanalabs: add command submission module
habanalabs: implement INFO IOCTL
habanalabs: add debugfs support
Update MAINTAINERS and CREDITS with habanalabs info
Omer Shpigelman (1):
habanalabs: add virtual memory and MMU modules
CREDITS | 2 +- .../ABI/testing/debugfs-driver-habanalabs | 127 + .../ABI/testing/sysfs-driver-habanalabs | 190 + MAINTAINERS | 9 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/habanalabs/Kconfig | 22 + drivers/misc/habanalabs/Makefile | 14 + drivers/misc/habanalabs/asid.c | 58 + drivers/misc/habanalabs/command_buffer.c | 425 + drivers/misc/habanalabs/command_submission.c | 799 ++ drivers/misc/habanalabs/context.c | 216 + drivers/misc/habanalabs/debugfs.c | 1069 ++ drivers/misc/habanalabs/device.c | 1097 ++ drivers/misc/habanalabs/goya/Makefile | 3 + drivers/misc/habanalabs/goya/goya.c | 6347 ++++++++++++ drivers/misc/habanalabs/goya/goyaP.h | 161 + drivers/misc/habanalabs/goya/goya_hwmgr.c | 306 + drivers/misc/habanalabs/goya/goya_security.c | 2999 ++++++ drivers/misc/habanalabs/habanalabs.h | 1464 +++ drivers/misc/habanalabs/habanalabs_drv.c | 474 + drivers/misc/habanalabs/habanalabs_ioctl.c | 237 + drivers/misc/habanalabs/hw_queue.c | 654 ++ drivers/misc/habanalabs/hwmon.c | 449 + .../include/goya/asic_reg/cpu_ca53_cfg_regs.h | 213 + .../include/goya/asic_reg/cpu_if_regs.h | 110 + .../include/goya/asic_reg/cpu_pll_regs.h | 186 + .../include/goya/asic_reg/ddr_mc_ch0_regs.h | 1158 +++ .../include/goya/asic_reg/ddr_mc_ch1_regs.h | 1158 +++ .../include/goya/asic_reg/ddr_misc_ch0_regs.h | 156 + .../include/goya/asic_reg/ddr_misc_ch1_regs.h | 156 + .../include/goya/asic_reg/dma_ch_0_regs.h | 512 + .../include/goya/asic_reg/dma_ch_1_regs.h | 512 + .../include/goya/asic_reg/dma_ch_2_regs.h | 512 + .../include/goya/asic_reg/dma_ch_3_regs.h | 512 + .../include/goya/asic_reg/dma_ch_4_regs.h | 512 + .../include/goya/asic_reg/dma_macro_regs.h | 242 + .../include/goya/asic_reg/dma_nrtr_regs.h | 380 + .../include/goya/asic_reg/dma_qm_0_regs.h | 543 + .../include/goya/asic_reg/dma_qm_1_regs.h | 543 + .../include/goya/asic_reg/dma_qm_2_regs.h | 543 + .../include/goya/asic_reg/dma_qm_3_regs.h | 543 + .../include/goya/asic_reg/dma_qm_4_regs.h | 543 + .../include/goya/asic_reg/gic_regs.h | 9079 +++++++++++++++++ .../include/goya/asic_reg/goya_blocks.h | 1372 +++ .../include/goya/asic_reg/goya_masks.h | 262 + .../include/goya/asic_reg/goya_regs.h | 119 + .../include/goya/asic_reg/ic_pll_regs.h | 186 + .../include/goya/asic_reg/mc_pll_regs.h | 186 + .../include/goya/asic_reg/mme1_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme2_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme3_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme4_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme5_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme6_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme_cmdq_regs.h | 431 + .../include/goya/asic_reg/mme_qm_regs.h | 543 + .../include/goya/asic_reg/mme_regs.h | 2422 +++++ .../include/goya/asic_reg/mmu_regs.h | 158 + .../include/goya/asic_reg/pci_nrtr_regs.h | 380 + .../include/goya/asic_reg/pcie_aux_regs.h | 476 + .../include/goya/asic_reg/pcie_dbi_regs.h | 2909 ++++++ .../goya/asic_reg/psoc_emmc_pll_regs.h | 186 + .../goya/asic_reg/psoc_global_conf_regs.h | 1119 ++ .../include/goya/asic_reg/psoc_mme_pll_regs.h | 186 + .../include/goya/asic_reg/psoc_pci_pll_regs.h | 186 + .../include/goya/asic_reg/psoc_spi_regs.h | 427 + .../goya/asic_reg/sram_y0_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x4_rtr_regs.h | 215 + .../include/goya/asic_reg/stlb_regs.h | 133 + .../include/goya/asic_reg/sync_mngr_regs.h | 4930 +++++++++ .../include/goya/asic_reg/tpc0_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc0_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc0_eml_cfg_regs.h | 580 ++ .../include/goya/asic_reg/tpc0_nrtr_regs.h | 380 + .../include/goya/asic_reg/tpc0_qm_regs.h | 543 + .../include/goya/asic_reg/tpc1_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc1_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc1_qm_regs.h | 543 + .../include/goya/asic_reg/tpc1_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc2_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc2_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc2_qm_regs.h | 543 + .../include/goya/asic_reg/tpc2_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc3_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc3_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc3_qm_regs.h | 543 + .../include/goya/asic_reg/tpc3_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc4_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc4_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc4_qm_regs.h | 543 + .../include/goya/asic_reg/tpc4_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc5_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc5_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc5_qm_regs.h | 543 + .../include/goya/asic_reg/tpc5_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc6_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc6_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc6_qm_regs.h | 543 + .../include/goya/asic_reg/tpc6_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc7_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc7_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc7_nrtr_regs.h | 380 + .../include/goya/asic_reg/tpc7_qm_regs.h | 543 + .../include/goya/asic_reg/tpc_pll_regs.h | 186 + drivers/misc/habanalabs/include/goya/goya.h | 117 + .../include/goya/goya_async_events.h | 186 + .../habanalabs/include/goya/goya_boot_if.h | 32 + .../habanalabs/include/goya/goya_packets.h | 234 + .../habanalabs/include/habanalabs_device_if.h | 397 + .../include/hw_ip/mmu/mmu_general.h | 45 + .../habanalabs/include/hw_ip/mmu/mmu_v1_0.h | 15 + drivers/misc/habanalabs/irq.c | 325 + drivers/misc/habanalabs/memory.c | 1714 ++++ drivers/misc/habanalabs/mmu.c | 604 ++ drivers/misc/habanalabs/sysfs.c | 690 ++ include/uapi/misc/habanalabs.h | 412 + 145 files changed, 99610 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/debugfs-driver-habanalabs create mode 100644 Documentation/ABI/testing/sysfs-driver-habanalabs create mode 100644 drivers/misc/habanalabs/Kconfig create mode 100644 drivers/misc/habanalabs/Makefile create mode 100644 drivers/misc/habanalabs/asid.c create mode 100644 drivers/misc/habanalabs/command_buffer.c create mode 100644 drivers/misc/habanalabs/command_submission.c create mode 100644 drivers/misc/habanalabs/context.c create mode 100644 drivers/misc/habanalabs/debugfs.c create mode 100644 drivers/misc/habanalabs/device.c create mode 100644 drivers/misc/habanalabs/goya/Makefile create mode 100644 drivers/misc/habanalabs/goya/goya.c create mode 100644 drivers/misc/habanalabs/goya/goyaP.h create mode 100644 drivers/misc/habanalabs/goya/goya_hwmgr.c create mode 100644 drivers/misc/habanalabs/goya/goya_security.c create mode 100644 drivers/misc/habanalabs/habanalabs.h create mode 100644 drivers/misc/habanalabs/habanalabs_drv.c create mode 100644 drivers/misc/habanalabs/habanalabs_ioctl.c create mode 100644 drivers/misc/habanalabs/hw_queue.c create mode 100644 drivers/misc/habanalabs/hwmon.c create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_ca53_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_if_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_mc_ch0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_mc_ch1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_misc_ch0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_misc_ch1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_2_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_3_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_4_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_macro_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_2_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_3_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_4_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/gic_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_blocks.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_masks.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ic_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme5_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme6_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mmu_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pci_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pcie_aux_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pcie_dbi_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_emmc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_global_conf_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_mme_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_pci_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_spi_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/stlb_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sync_mngr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_eml_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/goya.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_async_events.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_boot_if.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_packets.h create mode 100644 drivers/misc/habanalabs/include/habanalabs_device_if.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_0.h create mode 100644 drivers/misc/habanalabs/irq.c create mode 100644 drivers/misc/habanalabs/memory.c create mode 100644 drivers/misc/habanalabs/mmu.c create mode 100644 drivers/misc/habanalabs/sysfs.c create mode 100644 include/uapi/misc/habanalabs.h
Signature · 1 line
2.17.1
PATCH 1/15 habanalabs: add skeleton driver
This patch adds the habanalabs skeleton driver. The driver does nothing at this stage except very basic operations. It contains the minimal code to insmod and rmmod the driver and to create a /dev/hlX file per PCI device.
--- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/habanalabs/Kconfig | 22 ++ drivers/misc/habanalabs/Makefile | 7 + drivers/misc/habanalabs/device.c | 331 ++++++++++++++++ drivers/misc/habanalabs/habanalabs.h | 149 +++++++ drivers/misc/habanalabs/habanalabs_drv.c | 366 ++++++++++++++++++ .../habanalabs/include/habanalabs_device_if.h | 125 ++++++ 8 files changed, 1002 insertions(+) create mode 100644 drivers/misc/habanalabs/Kconfig create mode 100644 drivers/misc/habanalabs/Makefile create mode 100644 drivers/misc/habanalabs/device.c create mode 100644 drivers/misc/habanalabs/habanalabs.h create mode 100644 drivers/misc/habanalabs/habanalabs_drv.c create mode 100644 drivers/misc/habanalabs/include/habanalabs_device_if.h
drivers/misc/Kconfig +1 -0
@@ -535,4 +535,5 @@ source "drivers/misc/echo/Kconfig" source "drivers/misc/cxl/Kconfig" source "drivers/misc/ocxl/Kconfig" source "drivers/misc/cardreader/Kconfig" +source "drivers/misc/habanalabs/Kconfig" endmenu
drivers/misc/Makefile +1 -0
@@ -59,3 +59,4 @@ obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o obj-$(CONFIG_OCXL) += ocxl/ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic.o +obj-$(CONFIG_HABANA_AI) += habanalabs/
drivers/misc/habanalabs/Kconfig new file +22 -0
@@ -0,0 +1,22 @@ +# +# HabanaLabs AI accelerators driver +# + +config HABANA_AI + tristate "HabanaAI accelerators (habanalabs)" + depends on PCI + select FRAME_VECTOR + help + Enables PCIe card driver for Habana's AI Processors (AIP) that are + designed to accelerate Deep Learning inference and training workloads. + + The driver manages the PCIe devices and provides IOCTL interface for + the user to submit workloads to the devices. + + The user-space interface is described in + include/uapi/misc/habanalabs.h + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called habanalabs.
drivers/misc/habanalabs/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# +# Makefile for HabanaLabs AI accelerators driver +# + +obj-m := habanalabs.o + +habanalabs-y := habanalabs_drv.o device.o
drivers/misc/habanalabs/device.c new file +331 -0
331 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h new file +149 -0
149 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c new file +366 -0
366 lines not on this page · raw message
drivers/misc/habanalabs/include/habanalabs_device_if.h new file +125 -0
125 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 3/15 habanalabs: add basic Goya support
In reply to Oded GabbayThis patch adds a basic support for the Goya device. The code initializes the device's PCI controller and PCI bars. It also initializes various S/W structures and adds some basic helper functions.
--- drivers/misc/habanalabs/Makefile | 5 +- drivers/misc/habanalabs/device.c | 71 +++ drivers/misc/habanalabs/goya/Makefile | 3 + drivers/misc/habanalabs/goya/goya.c | 633 ++++++++++++++++++++ drivers/misc/habanalabs/goya/goyaP.h | 125 ++++ drivers/misc/habanalabs/habanalabs.h | 131 ++++ drivers/misc/habanalabs/habanalabs_drv.c | 3 + drivers/misc/habanalabs/include/goya/goya.h | 115 ++++ 8 files changed, 1085 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/habanalabs/goya/Makefile create mode 100644 drivers/misc/habanalabs/goya/goya.c create mode 100644 drivers/misc/habanalabs/goya/goyaP.h create mode 100644 drivers/misc/habanalabs/include/goya/goya.h
drivers/misc/habanalabs/Makefile +4 -1
@@ -4,4 +4,7 @@ obj-m := habanalabs.o -habanalabs-y := habanalabs_drv.o device.o +habanalabs-y := habanalabs_drv.o device.o + +include $(src)/goya/Makefile +habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/device.c +71 -0
125 lines not on this page · raw message
drivers/misc/habanalabs/goya/Makefile new file +3 -0
@@ -0,0 +1,3 @@ +subdir-ccflags-y += -I$(src) + +HL_GOYA_FILES := goya/goya.o
drivers/misc/habanalabs/goya/goya.c new file +633 -0
633 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h new file +125 -0
125 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h +131 -0
178 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +3 -0
@@ -136,6 +136,9 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->major = hl_major; +/* Parameters for bring-up - set them to defaults */ + hdev->reset_pcilink =0 ; + hdev->disabled = true; hdev->pdev = pdev;/* can be NULL in case of simulator device */
drivers/misc/habanalabs/include/goya/goya.h new file +115 -0
115 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 5/15 habanalabs: add command buffer module
In reply to Oded GabbayThis patch adds the CB module, which allows the user to create and destroy CBs and to map them to the user's process address-space.
A command buffer is a memory blocks that reside in DMA-able address-space and is physically contiguous so it can be accessed by the device without MMU translation. The command buffer memory is allocated using the coherent DMA API.
When creating a new CB, the IOCTL returns a handle of it, and the user-space process needs to use that handle to mmap the buffer to get a VA in the user's address-space.
Before destroying (freeing) a CB, the user must unmap the CB's VA using the CB handle.
Each CB has a reference counter, which tracks its usage in command submissions and also its mmaps (only a single mmap is allowed).
The driver maintains a pool of pre-allocated CBs in order to reduce latency during command submissions. In case the pool is empty, the driver will go to the slow-path of allocating a new CB, i.e. calling dma_alloc_coherent.
--- drivers/misc/habanalabs/Makefile | 3 +- drivers/misc/habanalabs/command_buffer.c | 414 +++++++++++++++++++++ drivers/misc/habanalabs/device.c | 43 ++- drivers/misc/habanalabs/goya/goya.c | 28 ++ drivers/misc/habanalabs/habanalabs.h | 95 ++++- drivers/misc/habanalabs/habanalabs_drv.c | 2 + drivers/misc/habanalabs/habanalabs_ioctl.c | 102 +++++ include/uapi/misc/habanalabs.h | 62 +++ 8 files changed, 746 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/habanalabs/command_buffer.c create mode 100644 drivers/misc/habanalabs/habanalabs_ioctl.c create mode 100644 include/uapi/misc/habanalabs.h
drivers/misc/habanalabs/Makefile +2 -1
@@ -4,7 +4,8 @@ obj-m := habanalabs.o -habanalabs-y := habanalabs_drv.o device.o context.o asid.o +habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ + command_buffer.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/command_buffer.c new file +414 -0
414 lines not on this page · raw message
drivers/misc/habanalabs/device.c +42 -1
87 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +28 -0
@@ -92,6 +92,9 @@#define GOYA_MAX_INITIATORS 20 +#define GOYA_CB_POOL_CB_CNT 512 +#define GOYA_CB_POOL_CB_SIZE 0x20000/* 128KB */ +static void goya_get_fixed_properties (struct hl_device *hdev) {struct asic_fixed_properties *prop = &hdev->asic_prop;
@@ -119,6 +122,8 @@ static void goya_get_fixed_properties(struct hl_device *hdev) prop->tpc_enabled_mask =TPC_ENABLED_MASK ; prop->high_pll =PLL_HIGH_DEFAULT ; + prop->cb_pool_cb_cnt =GOYA_CB_POOL_CB_CNT ; + prop->cb_pool_cb_size =GOYA_CB_POOL_CB_SIZE ; }/**
@@ -598,6 +603,27 @@ int goya_resume(struct hl_device *hdev)return 0 ; } +int goya_mmap (struct hl_fpriv *hpriv,struct vm_area_struct *vma) +{ +return -EINVAL ; +} + +int goya_cb_mmap (struct hl_device *hdev,struct vm_area_struct *vma, +u64 kaddress,phys_addr_t paddress,u32 size) +{ +int rc; + + vma->vm_flags |=VM_IO |VM_PFNMAP |VM_DONTEXPAND |VM_DONTDUMP | +VM_DONTCOPY |VM_NORESERVE ; + + rc =remap_pfn_range (vma, vma->vm_start, paddress >>PAGE_SHIFT , + size, vma->vm_page_prot); +if (rc) +dev_err (hdev->dev,"remap_pfn_range error %d" , rc); + +return rc; +} +void *goya_dma_alloc_coherent (struct hl_device *hdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) {
@@ -617,6 +643,8 @@ static const struct hl_asic_funcs goya_funcs = { .sw_fini = goya_sw_fini, .suspend = goya_suspend, .resume = goya_resume, + .mmap = goya_mmap, + .cb_mmap = goya_cb_mmap, .dma_alloc_coherent = goya_dma_alloc_coherent, .dma_free_coherent = goya_dma_free_coherent, };
drivers/misc/habanalabs/habanalabs.h +94 -1
175 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +2 -0
@@ -123,6 +123,7 @@ int hl_device_open(struct inode *inode, struct file *filp)kref_init (&hpriv->refcount);nonseekable_open (inode, filp); +hl_cb_mgr_init (&hpriv->cb_mgr);hl_ctx_mgr_init (&hpriv->ctx_mgr); rc =hl_ctx_create (hdev, hpriv);
@@ -138,6 +139,7 @@ int hl_device_open(struct inode *inode, struct file *filp) out_err: filp->private_data =NULL ;hl_ctx_mgr_fini (hpriv->hdev, &hpriv->ctx_mgr); +hl_cb_mgr_fini (hpriv->hdev, &hpriv->cb_mgr);kfree (hpriv); close_device:
drivers/misc/habanalabs/habanalabs_ioctl.c new file +102 -0
102 lines not on this page · raw message
include/uapi/misc/habanalabs.h new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 8/15 habanalabs: add event queue and interrupts
In reply to Oded GabbayThis patch adds support for receiving events from Goya's control CPU and for receiving MSI-X interrupts from Goya's DMA engines and CPU.
Goya's PCI controller supports up to 8 MSI-X interrupts, which only 6 of them are currently used. The first 5 interrupts are dedicated for Goya's DMA engine queues. The 6th interrupt is dedicated for Goya's control CPU.
The DMA queue will signal its MSI-X entry upon each completion of a command buffer that was placed on its primary queue. The driver will then mark that CB as completed and free the related resources. It will also update the command submission object which that CB belongs to.
There is a dedicated event queue (EQ) between the driver and Goya's control CPU. The EQ is located on the Host memory. The control CPU writes a new entry to the EQ for various reasons, such as ECC error, MMU page fault, Hot temperature. After writing the new entry to the EQ, the control CPU will trigger its dedicated MSI-X entry to signal the driver that there is a new entry in the EQ. The driver will then read the entry and act accordingly.
--- drivers/misc/habanalabs/device.c | 35 +- drivers/misc/habanalabs/goya/goya.c | 522 +++++++++++++++++++- drivers/misc/habanalabs/goya/goyaP.h | 1 + drivers/misc/habanalabs/habanalabs.h | 37 ++ drivers/misc/habanalabs/include/goya/goya.h | 1 - drivers/misc/habanalabs/irq.c | 144 ++++++ 6 files changed, 729 insertions(+), 11 deletions(-)
drivers/misc/habanalabs/device.c +34 -1
@@ -173,9 +173,17 @@ static int device_early_init(struct hl_device *hdev) hdev->cq_wq =alloc_workqueue ("hl-free-jobs" ,WQ_UNBOUND ,0 );if (hdev->cq_wq ==NULL ) {dev_err (hdev->dev,"Failed to allocate CQ workqueue\n" ); + rc = -ENOMEM ; goto asid_fini; } + hdev->eq_wq =alloc_workqueue ("hl-events" ,WQ_UNBOUND ,0 ); +if (hdev->eq_wq ==NULL ) { +dev_err (hdev->dev,"Failed to allocate EQ workqueue\n" ); + rc = -ENOMEM ; + goto free_cq_wq; + } +hl_cb_mgr_init (&hdev->kernel_cb_mgr);mutex_init (&hdev->device_open);
@@ -184,6 +192,8 @@ static int device_early_init(struct hl_device *hdev)return 0 ; +free_cq_wq: +destroy_workqueue (hdev->cq_wq); asid_fini:hl_asid_fini (hdev); early_fini:
@@ -205,6 +215,7 @@ static void device_early_fini(struct hl_device *hdev)hl_cb_mgr_fini (hdev, &hdev->kernel_cb_mgr); +destroy_workqueue (hdev->eq_wq);destroy_workqueue (hdev->cq_wq);hl_asid_fini (hdev);
@@ -343,11 +354,22 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) } } +/* +* Initialize the event queue. Must be done before hw_init, +* because there the address of the event queue is being +* passed as argument to request_irq +*/ + rc =hl_eq_init (hdev, &hdev->event_queue); +if (rc) { +dev_err (hdev->dev,"failed to initialize event queue\n" ); + goto cq_fini; + } +/* Allocate the kernel context */ hdev->kernel_ctx =kzalloc (sizeof (*hdev->kernel_ctx),GFP_KERNEL );if (!hdev->kernel_ctx) { rc = -ENOMEM ; - goto cq_fini; + goto eq_fini; } hdev->user_ctx =NULL ;
@@ -392,6 +414,8 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) "kernel ctx is still alive on initialization failure\n"); free_ctx:kfree (hdev->kernel_ctx); +eq_fini: +hl_eq_fini (hdev, &hdev->event_queue); cq_fini:for (i =0 ; i < cq_ready_cnt ; i++)hl_cq_fini (hdev, &hdev->completion_queue[i]);
@@ -433,6 +457,13 @@ void hl_device_fini(struct hl_device *hdev)/* Mark device as disabled */ hdev->disabled = true; +/* +* Halt the engines and disable interrupts so we won't get any more +* completions from H/W and we won't have any accesses from the +* H/W to the host machine +*/ + hdev->asic_funcs->halt_engines (hdev, true); +hl_cb_pool_fini (hdev);/* Release kernel context */
@@ -442,6 +473,8 @@ void hl_device_fini(struct hl_device *hdev)/* Reset the H/W. It will be in idle state after this returns */ hdev->asic_funcs->hw_fini (hdev, true); +hl_eq_fini (hdev, &hdev->event_queue); +for (i =0 ; i < hdev->asic_prop.completion_queues_count ; i++)hl_cq_fini (hdev, &hdev->completion_queue[i]);kfree (hdev->completion_queue);
drivers/misc/habanalabs/goya/goya.c +513 -9
613 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h +1 -0
@@ -123,6 +123,7 @@ struct goya_device {/* TODO: remove hw_queues_lock after moving to scheduler code */ spinlock_t hw_queues_lock;u64 ddr_bar_cur_addr; +u32 events_stat[GOYA_ASYNC_EVENT_ID_SIZE ];u32 hw_cap_initialized; };
drivers/misc/habanalabs/habanalabs.h +37 -0
@@ -83,6 +83,7 @@ struct hw_queue_properties {* @cfg_size: configuration space size on SRAM. * @sram_size: total size of SRAM. * @max_asid: maximum number of open contexts (ASIDs). +* @num_of_events: number of possible internal H/W IRQs. * @completion_queues_count: number of completion queues. * @high_pll: high PLL frequency used by the device. * @cb_pool_cb_cnt: number of CBs in the CB pool.
@@ -109,6 +110,7 @@ struct asic_fixed_properties {u32 cfg_size;u32 sram_size;u32 max_asid; +u32 num_of_events;u32 high_pll;u32 cb_pool_cb_cnt;u32 cb_pool_cb_size;
@@ -209,6 +211,9 @@ struct hl_cs_job;#define HL_CQ_LENGTH HL_QUEUE_LENGTH#define HL_CQ_SIZE_IN_BYTES (HL_CQ_LENGTH * HL_CQ_ENTRY_SIZE) +/* Must be power of 2 (HL_PAGE_SIZE / HL_EQ_ENTRY_SIZE) */ +#define HL_EQ_LENGTH 64 +#define HL_EQ_SIZE_IN_BYTES (HL_EQ_LENGTH * HL_EQ_ENTRY_SIZE)/**
@@ -256,6 +261,20 @@ struct hl_cq {atomic_t free_slots_cnt; }; +/** +* struct hl_eq - describes the event queue (single one per device) +* @hdev: pointer to the device structure +* @kernel_address: holds the queue's kernel virtual address +* @bus_address: holds the queue's DMA address +* @ci: ci inside the queue +*/ +struct hl_eq { +struct hl_device *hdev; +u64 kernel_address; +dma_addr_t bus_address; +u32 ci; +}; +
@@ -288,6 +307,9 @@ enum hl_asic_type {* @sw_fini: tears down driver state, does not configure H/W. * @hw_init: sets up the H/W state. * @hw_fini: tears down the H/W state. +* @halt_engines: halt engines, needed for reset sequence. This also disables +* interrupts from the device. Should be called before +* hw_fini and before CS rollback. * @suspend: handles IP specific H/W or SW changes for suspend. * @resume: handles IP specific H/W or SW changes for resume. * @mmap: mmap function, does nothing.
@@ -303,6 +325,9 @@ enum hl_asic_type {* @dma_pool_free: free small DMA allocation from pool. * @cpu_accessible_dma_pool_alloc: allocate CPU PQ packet from DMA pool. * @cpu_accessible_dma_pool_free: free CPU PQ packet from DMA pool. +* @update_eq_ci: update event queue CI. +* @handle_eqe: handle event queue entry (IRQ) from ArmCP. +* @get_events_stat: retrieve event queue entries histogram. * @hw_queues_lock: acquire H/W queues lock. * @hw_queues_unlock: release H/W queues lock. * @send_cpu_message: send buffer to ArmCP.
@@ -314,6 +339,7 @@ struct hl_asic_funcs {int (*sw_fini)(struct hl_device *hdev);int (*hw_init)(struct hl_device *hdev);void (*hw_fini)(struct hl_device *hdev,bool hard_reset); +void (*halt_engines)(struct hl_device *hdev,bool hard_reset);int (*suspend)(struct hl_device *hdev);int (*resume)(struct hl_device *hdev);int (*mmap)(struct hl_fpriv *hpriv,struct vm_area_struct *vma);
@@ -336,6 +362,10 @@ struct hl_asic_funcs { size_t size, dma_addr_t *dma_handle);void (*cpu_accessible_dma_pool_free)(struct hl_device *hdev,size_t size,void *vaddr); +void (*update_eq_ci)(struct hl_device *hdev,u32 val); +void (*handle_eqe)(struct hl_device *hdev, +struct hl_eq_entry *eq_entry); +void * (*get_events_stat)(struct hl_device *hdev,u32 *size);void (*hw_queues_lock)(struct hl_device *hdev);void (*hw_queues_unlock)(struct hl_device *hdev); int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
@@ -474,6 +504,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @kernel_ctx: KMD context structure. * @kernel_queues: array of hl_hw_queue. * @kernel_cb_mgr: command buffer manager for creating/destroying/handling CGs. +* @event_queue: event queue for IRQ from ArmCP. * @dma_pool: DMA pool for small allocations. * @cpu_accessible_dma_mem: KMD <-> ArmCP shared memory CPU address. * @cpu_accessible_dma_address: KMD <-> ArmCP shared memory DMA address.
@@ -504,9 +535,11 @@ struct hl_device {enum hl_asic_type asic_type;struct hl_cq *completion_queue;struct workqueue_struct *cq_wq; +struct workqueue_struct *eq_wq;struct hl_ctx *kernel_ctx;struct hl_hw_queue *kernel_queues;struct hl_cb_mgr kernel_cb_mgr; +struct hl_eq event_queue;struct dma_pool *dma_pool;void *cpu_accessible_dma_mem;dma_addr_t cpu_accessible_dma_address;
@@ -593,6 +626,10 @@ void hl_hw_queue_inc_ci_kernel(struct hl_device *hdev, u32 hw_queue_id);int hl_cq_init (struct hl_device *hdev,struct hl_cq *q,u32 hw_queue_id);void hl_cq_fini (struct hl_device *hdev,struct hl_cq *q); +int hl_eq_init (struct hl_device *hdev,struct hl_eq *q); +void hl_eq_fini (struct hl_device *hdev,struct hl_eq *q); +irqreturn_t hl_irq_handler_cq (int irq,void *arg); +irqreturn_t hl_irq_handler_eq (int irq,void *arg);int hl_asid_init (struct hl_device *hdev);void hl_asid_fini (struct hl_device *hdev);unsigned long hl_asid_alloc (struct hl_device *hdev);
drivers/misc/habanalabs/include/goya/goya.h +0 -1
@@ -65,7 +65,6 @@#define GOYA_MSIX_ENTRIES 8#define EVENT_QUEUE_MSIX_IDX 5 -#define ARMCP_RESET_MSIX_IDX 6#define QMAN_PQ_ENTRY_SIZE 16/* Bytes */
drivers/misc/habanalabs/irq.c +144 -0
165 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 9/15 habanalabs: add sysfs and hwmon support
In reply to Oded GabbayThis patch add the sysfs and hwmon entries that are exposed by the driver.
Goya has several sensors, from various categories such as temperature, voltage, current, etc. The driver exposes those sensors in the standard hwmon mechanism.
In addition, the driver exposes a couple of interfaces in sysfs, both for configuration and for providing status of the device or driver.
The configuration attributes is for Power Management:
- Automatic or manual
- Frequency value when moving to high frequency mode
- Maximum power the device is allowed to consume
The rest of the attributes are read-only and provide the following information:
- Versions of the various firmwares running on the device
- Contents of the device's EEPROM
- The device type (currently only Goya is supported)
- PCI address of the device (to allow user-space to connect between /dev/hlX to PCI address)
- Status of the device (operational, malfunction, in_reset)
- How many processes are open on the device's file
--- .../ABI/testing/sysfs-driver-habanalabs | 190 ++++++ drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/device.c | 146 +++++ drivers/misc/habanalabs/goya/Makefile | 2 +- drivers/misc/habanalabs/goya/goya.c | 230 +++++++ drivers/misc/habanalabs/goya/goyaP.h | 21 + drivers/misc/habanalabs/goya/goya_hwmgr.c | 306 +++++++++ drivers/misc/habanalabs/habanalabs.h | 97 +++ drivers/misc/habanalabs/habanalabs_drv.c | 7 + drivers/misc/habanalabs/hwmon.c | 449 +++++++++++++ drivers/misc/habanalabs/sysfs.c | 588 ++++++++++++++++++ 11 files changed, 2036 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-habanalabs create mode 100644 drivers/misc/habanalabs/goya/goya_hwmgr.c create mode 100644 drivers/misc/habanalabs/hwmon.c create mode 100644 drivers/misc/habanalabs/sysfs.c
Documentation/ABI/testing/sysfs-driver-habanalabs new file +190 -0
@@ -0,0 +1,190 @@ +What: /sys/class/habanalabs/hl<n>/armcp_kernel_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the Linux kernel running on the device's CPU + +What: /sys/class/habanalabs/hl<n>/armcp_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the application running on the device's CPU + +What: /sys/class/habanalabs/hl<n>/cpld_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the Device's CPLD F/W + +What: /sys/class/habanalabs/hl<n>/device_type +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the code name of the device according to its type. + The supported values are: "GOYA" + +What: /sys/class/habanalabs/hl<n>/eeprom +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: A binary file attribute that contains the contents of the + on-board EEPROM + +What: /sys/class/habanalabs/hl<n>/fuse_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the device's version from the eFuse + +What: /sys/class/habanalabs/hl<n>/hard_reset +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Interface to trigger a hard-reset operation for the device. + Hard-reset will reset ALL internal components of the device + except for the PCI interface and the internal PLLs + +What: /sys/class/habanalabs/hl<n>/hard_reset_cnt +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays how many times the device have undergone a hard-reset + operation + +What: /sys/class/habanalabs/hl<n>/high_pll +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Allows the user to set the maximum clock frequency for MME, TPC + and IC when the power management profile is set to "automatic". + +What: /sys/class/habanalabs/hl<n>/ic_clk +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Allows the user to set the maximum clock frequency of the + Interconnect fabric. Writes to this parameter affect the device + only when the power management profile is set to "manual" mode. + The device IC clock might be set to lower value then the + maximum. The user should read the ic_clk_curr to see the actual + frequency value of the IC + +What: /sys/class/habanalabs/hl<n>/ic_clk_curr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the current clock frequency of the Interconnect fabric + +What: /sys/class/habanalabs/hl<n>/infineon_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the Device's power supply F/W code + +What: /sys/class/habanalabs/hl<n>/max_power +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Allows the user to set the maximum power consumption of the + device in milliwatts. + +What: /sys/class/habanalabs/hl<n>/mme_clk +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Allows the user to set the maximum clock frequency of the + MME compute engine. Writes to this parameter affect the device + only when the power management profile is set to "manual" mode. + The device MME clock might be set to lower value then the + maximum. The user should read the mme_clk_curr to see the actual + frequency value of the MME + +What: /sys/class/habanalabs/hl<n>/mme_clk_curr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the current clock frequency of the MME compute engine + +What: /sys/class/habanalabs/hl<n>/pci_addr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the PCI address of the device. This is needed so the + user would be able to open a device based on its PCI address + +What: /sys/class/habanalabs/hl<n>/pm_mng_profile +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Power management profile. Values are "auto", "manual". In "auto" + mode, the driver will set the maximum clock frequency to a high + value when a user-space process opens the device's file (unless + it was already opened by another process). The driver will set + the max clock frequency to a low value when there are no user + processes that are opened on the device's file. In "manual" + mode, the user sets the maximum clock frequency by writing to + ic_clk, mme_clk and tpc_clk + + +What: /sys/class/habanalabs/hl<n>/preboot_btl_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the device's preboot F/W code + +What: /sys/class/habanalabs/hl<n>/soft_reset +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Interface to trigger a soft-reset operation for the device. + Soft-reset will reset only the compute and DMA engines of the + device + +What: /sys/class/habanalabs/hl<n>/soft_reset_cnt +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays how many times the device have undergone a soft-reset + operation + +What: /sys/class/habanalabs/hl<n>/status +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Status of the card: "Operational", "Malfunction", "In reset". + +What: /sys/class/habanalabs/hl<n>/thermal_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the Device's thermal daemon + +What: /sys/class/habanalabs/hl<n>/tpc_clk +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Allows the user to set the maximum clock frequency of the + TPC compute engines. Writes to this parameter affect the device + only when the power management profile is set to "manual" mode. + The device TPC clock might be set to lower value then the + maximum. The user should read the tpc_clk_curr to see the actual + frequency value of the TPC + +What: /sys/class/habanalabs/hl<n>/tpc_clk_curr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the current clock frequency of the TPC compute engines + +What: /sys/class/habanalabs/hl<n>/uboot_ver +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Version of the u-boot running on the device's CPU + +What: /sys/class/habanalabs/hl<n>/write_open_cnt +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the total number of user processes that are currently + opened on the device's file
drivers/misc/habanalabs/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-m := habanalabs.o habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ - command_buffer.o hw_queue.o irq.o + command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/device.c +146 -0
175 lines not on this page · raw message
drivers/misc/habanalabs/goya/Makefile +1 -1
@@ -1,3 +1,3 @@ subdir-ccflags-y += -I$(src) -HL_GOYA_FILES := goya/goya.o goya/goya_security.o +HL_GOYA_FILES := goya/goya.o goya/goya_security.o goya/goya_hwmgr.o
drivers/misc/habanalabs/goya/goya.c +230 -0
282 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h +21 -0
@@ -48,7 +48,10 @@#define PLL_HIGH_DEFAULT 1575000000/* 1.575 GHz */ +#define MAX_POWER_DEFAULT 200000/* 200W */ +#define GOYA_ARMCP_INFO_TIMEOUT 10000000/* 10s */ +#define GOYA_ARMCP_EEPROM_TIMEOUT 10000000/* 10s */ #define DRAM_PHYS_DEFAULT_SIZE 0x100000000ull/* 4GB */
@@ -119,9 +122,15 @@ enum goya_fw_component {struct goya_device {int (*test_cpu_queue)(struct hl_device *hdev); +int (*armcp_info_get)(struct hl_device *hdev);/* TODO: remove hw_queues_lock after moving to scheduler code */ spinlock_t hw_queues_lock; + +u64 mme_clk; +u64 tpc_clk; +u64 ic_clk; +u64 ddr_bar_cur_addr;u32 events_stat[GOYA_ASYNC_EVENT_ID_SIZE ];u32 hw_cap_initialized;
@@ -130,6 +139,18 @@ struct goya_device {int goya_test_cpu_queue (struct hl_device *hdev);int goya_send_cpu_message (struct hl_device *hdev,u32 *msg,u16 len,u32 timeout,long *result); +long goya_get_temperature (struct hl_device *hdev,int sensor_index,u32 attr); +long goya_get_voltage (struct hl_device *hdev,int sensor_index,u32 attr); +long goya_get_current (struct hl_device *hdev,int sensor_index,u32 attr); +long goya_get_fan_speed (struct hl_device *hdev,int sensor_index,u32 attr); +long goya_get_pwm_info (struct hl_device *hdev,int sensor_index,u32 attr); +void goya_set_pwm_info (struct hl_device *hdev,int sensor_index,u32 attr, +long value); +void goya_set_pll_profile (struct hl_device *hdev,enum hl_pll_frequency freq); +int goya_add_device_attr (struct hl_device *hdev); +void goya_remove_device_attr (struct hl_device *hdev);void goya_init_security (struct hl_device *hdev); +u64 goya_get_max_power (struct hl_device *hdev); +void goya_set_max_power (struct hl_device *hdev,u64 value);#endif /* GOYAP_H_ */
drivers/misc/habanalabs/goya/goya_hwmgr.c new file +306 -0
306 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h +97 -0
231 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +7 -0
@@ -134,6 +134,13 @@ int hl_device_open(struct inode *inode, struct file *filp) hpriv->taskpid =find_get_pid (current->pid); +/* +* Device is IDLE at this point so it is legal to change PLLs. There +* is no need to check anything because if the PLL is already HIGH, the +* set function will return without doing anything +*/ +hl_device_set_frequency (hdev,PLL_HIGH ); +return 0 ; out_err:
drivers/misc/habanalabs/hwmon.c new file +449 -0
449 lines not on this page · raw message
drivers/misc/habanalabs/sysfs.c new file +588 -0
588 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 11/15 habanalabs: add command submission module
In reply to Oded GabbayThis patch adds the main flow for the user to submit work to the device.
Each work is described by a command submission object (CS). The CS contains 3 arrays of command buffers: One for execution, and two for context-switch (store and restore).
For each CB, the user specifies on which queue to put that CB. In case of an internal queue, the entry doesn't contain a pointer to the CB but the address in the on-chip memory that the CB resides at.
The driver parses some of the CBs to enforce security restrictions.
The user receives a sequence number that represents the CS object. The user can then query the driver regarding the status of the CS, using that sequence number.
In case the CS doesn't finish before the timeout expires, the driver will perform a soft-reset of the device.
--- drivers/misc/habanalabs/Makefile | 3 +- drivers/misc/habanalabs/command_submission.c | 787 +++++++++++++ drivers/misc/habanalabs/context.c | 52 +- drivers/misc/habanalabs/device.c | 16 + drivers/misc/habanalabs/goya/goya.c | 1082 ++++++++++++++++++ drivers/misc/habanalabs/habanalabs.h | 274 +++++ drivers/misc/habanalabs/habanalabs_drv.c | 23 + drivers/misc/habanalabs/habanalabs_ioctl.c | 4 +- drivers/misc/habanalabs/hw_queue.c | 250 ++++ drivers/misc/habanalabs/memory.c | 200 ++++ include/uapi/misc/habanalabs.h | 158 ++- 11 files changed, 2842 insertions(+), 7 deletions(-) create mode 100644 drivers/misc/habanalabs/command_submission.c create mode 100644 drivers/misc/habanalabs/memory.c
drivers/misc/habanalabs/Makefile +2 -1
@@ -5,7 +5,8 @@ obj-m := habanalabs.o habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ - command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o + command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \ + command_submission.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/command_submission.c new file +787 -0
787 lines not on this page · raw message
drivers/misc/habanalabs/context.c +48 -4
82 lines not on this page · raw message
drivers/misc/habanalabs/device.c +16 -0
@@ -22,6 +22,8 @@ static void hpriv_release(struct kref *ref)put_pid (hpriv->taskpid); +mutex_destroy (&hpriv->restore_phase_mutex); +kfree (hpriv);/* Now the FD is really closed */
@@ -188,6 +190,8 @@ static int device_early_init(struct hl_device *hdev)mutex_init (&hdev->device_open);mutex_init (&hdev->send_cpu_message_lock); +INIT_LIST_HEAD (&hdev->hw_queues_mirror_list); +spin_lock_init (&hdev->hw_queues_mirror_lock);atomic_set (&hdev->in_reset,0 );atomic_set (&hdev->fd_open_cnt,0 );
@@ -563,6 +567,9 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,*/ hdev->asic_funcs->halt_engines (hdev, hard_reset); +/* Go over all the queues, release all CS and their jobs */ +hl_cs_rollback_all (hdev); +if (hard_reset) {/* Release kernel context */ if (hl_ctx_put (hdev->kernel_ctx) !=1 ) {
@@ -586,6 +593,12 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,for (i =0 ; i < hdev->asic_prop.completion_queues_count ; i++)hl_cq_reset (hdev, &hdev->completion_queue[i]); +/* Make sure the setup phase for the user context will run again */ +if (hdev->user_ctx) { +atomic_set (&hdev->user_ctx->thread_restore_token,1 ); + hdev->user_ctx->thread_restore_wait_token =0 ; + } +/* Finished tear-down, starting to re-initialize */ if (hard_reset) {
@@ -916,6 +929,9 @@ void hl_device_fini(struct hl_device *hdev)*/ hdev->asic_funcs->halt_engines (hdev, true); +/* Go over all the queues, release all CS and their jobs */ +hl_cs_rollback_all (hdev); +hl_cb_pool_fini (hdev);/* Release kernel context */
drivers/misc/habanalabs/goya/goya.c +1082 -0
1,124 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h +274 -0
456 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +23 -0
@@ -30,6 +30,17 @@ static struct class *hl_class;DEFINE_IDR (hl_devs_idr);DEFINE_MUTEX (hl_devs_idr_lock); +static int timeout_locked =5 ; +static int reset_on_lockup =1 ; + +module_param (timeout_locked, int,0444 ); +MODULE_PARM_DESC (timeout_locked, +"Device lockup timeout in seconds (0 = disabled, default 5s)" ); + +module_param (reset_on_lockup, int,0444 ); +MODULE_PARM_DESC (reset_on_lockup, +"Do device reset on lockup (0 = no, 1 = yes, default yes)" ); +#define PCI_VENDOR_ID_HABANALABS 0x1da3#define PCI_IDS_GOYA 0x0001
@@ -120,6 +131,7 @@ int hl_device_open(struct inode *inode, struct file *filp) hpriv->hdev = hdev; filp->private_data = hpriv; hpriv->filp = filp; +mutex_init (&hpriv->restore_phase_mutex);kref_init (&hpriv->refcount);nonseekable_open (inode, filp);
@@ -147,6 +159,7 @@ int hl_device_open(struct inode *inode, struct file *filp) filp->private_data =NULL ;hl_ctx_mgr_fini (hpriv->hdev, &hpriv->ctx_mgr);hl_cb_mgr_fini (hpriv->hdev, &hpriv->cb_mgr); +mutex_destroy (&hpriv->restore_phase_mutex);kfree (hpriv); close_device:
@@ -186,8 +199,10 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, } hdev->major = hl_major; + hdev->reset_on_lockup = reset_on_lockup;/* Parameters for bring-up - set them to defaults */ + hdev->mmu_enable =0 ; hdev->cpu_enable =1 ; hdev->reset_pcilink =0 ; hdev->config_pll =0 ;
@@ -209,6 +224,14 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev,if (!hdev->cpu_queues_enable) hdev->heartbeat =0 ; +if (hdev->ifh) + timeout_locked =0 ; + +if (timeout_locked) + hdev->timeout_jiffies =msecs_to_jiffies (timeout_locked *1000 ); +else + hdev->timeout_jiffies =MAX_SCHEDULE_TIMEOUT ; + hdev->disabled = true; hdev->pdev = pdev;/* can be NULL in case of simulator device */
drivers/misc/habanalabs/habanalabs_ioctl.c +3 -1
@@ -16,7 +16,9 @@ [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func}static const struct hl_ioctl_desc hl_ioctls[] = { -HL_IOCTL_DEF (HL_IOCTL_CB , hl_cb_ioctl) +HL_IOCTL_DEF (HL_IOCTL_CB , hl_cb_ioctl), +HL_IOCTL_DEF (HL_IOCTL_CS , hl_cs_ioctl), +HL_IOCTL_DEF (HL_IOCTL_WAIT_CS , hl_cs_wait_ioctl) };#define HL_CORE_IOCTL_COUNT ARRAY_SIZE(hl_ioctls)
drivers/misc/habanalabs/hw_queue.c +250 -0
268 lines not on this page · raw message
drivers/misc/habanalabs/memory.c new file +200 -0
163 lines not on this page · raw message
include/uapi/misc/habanalabs.h +157 -1
158 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH 13/15 habanalabs: implement INFO IOCTL
In reply to Oded GabbayThis patch implements the INFO IOCTL. That IOCTL is used by the user to query information that is relevant/needed by the user in order to submit deep learning jobs to Goya.
The information is divided into several categories, such as H/W IP, Events that happened, DDR usage and more.
--- drivers/misc/habanalabs/goya/goya.c | 6 + drivers/misc/habanalabs/habanalabs.h | 2 + drivers/misc/habanalabs/habanalabs_ioctl.c | 132 +++++++++++++++++++++ include/uapi/misc/habanalabs.h | 76 +++++++++++- 4 files changed, 215 insertions(+), 1 deletion(-)
drivers/misc/habanalabs/goya/goya.c +6 -0
@@ -6120,6 +6120,11 @@ static void goya_hw_queues_unlock(struct hl_device *hdev)spin_unlock (&goya->hw_queues_lock); } +static u32 goya_get_pci_id (struct hl_device *hdev) +{ +return hdev->pdev->device; +} +int goya_get_eeprom_data (struct hl_device *hdev,void *data,size_t max_size) {struct goya_device *goya = hdev->asic_specific;
@@ -6217,6 +6222,7 @@ static const struct hl_asic_funcs goya_funcs = { .soft_reset_late_init = goya_soft_reset_late_init, .hw_queues_lock = goya_hw_queues_lock, .hw_queues_unlock = goya_hw_queues_unlock, + .get_pci_id = goya_get_pci_id, .get_eeprom_data = goya_get_eeprom_data, .send_cpu_message = goya_send_cpu_message };
drivers/misc/habanalabs/habanalabs.h +2 -0
@@ -462,6 +462,7 @@ enum hl_pll_frequency {* @soft_reset_late_init: perform certain actions needed after soft reset. * @hw_queues_lock: acquire H/W queues lock. * @hw_queues_unlock: release H/W queues lock. +* @get_pci_id: retrieve PCI ID. * @get_eeprom_data: retrieve EEPROM data from F/W. * @send_cpu_message: send buffer to ArmCP. */
@@ -530,6 +531,7 @@ struct hl_asic_funcs {int (*soft_reset_late_init)(struct hl_device *hdev);void (*hw_queues_lock)(struct hl_device *hdev);void (*hw_queues_unlock)(struct hl_device *hdev); +u32 (*get_pci_id)(struct hl_device *hdev);int (*get_eeprom_data)(struct hl_device *hdev,void *data,size_t max_size); int (*send_cpu_message)(struct hl_device *hdev, u32 *msg,
drivers/misc/habanalabs/habanalabs_ioctl.c +132 -0
142 lines not on this page · raw message
include/uapi/misc/habanalabs.h +75 -1
94 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 14/15 habanalabs: add debugfs support
In reply to Oded GabbayThis patch adds debugfs support to the driver. It allows the user-space to display information that is contained in the internal structures of the driver, such as:
- active command submissions
- active user virtual memory mappings
- number of allocated command buffers
It also enables the user to perform reads and writes through Goya's PCI bars.
--- .../ABI/testing/debugfs-driver-habanalabs | 127 ++ drivers/misc/habanalabs/Makefile | 2 + drivers/misc/habanalabs/command_buffer.c | 4 + drivers/misc/habanalabs/command_submission.c | 12 + drivers/misc/habanalabs/debugfs.c | 1069 +++++++++++++++++ drivers/misc/habanalabs/device.c | 6 + drivers/misc/habanalabs/goya/goya.c | 108 ++ drivers/misc/habanalabs/goya/goyaP.h | 5 + drivers/misc/habanalabs/habanalabs.h | 191 +++ drivers/misc/habanalabs/habanalabs_drv.c | 16 +- drivers/misc/habanalabs/memory.c | 8 + 11 files changed, 1546 insertions(+), 2 deletions(-) create mode 100644 Documentation/ABI/testing/debugfs-driver-habanalabs create mode 100644 drivers/misc/habanalabs/debugfs.c
Documentation/ABI/testing/debugfs-driver-habanalabs new file +127 -0
@@ -0,0 +1,127 @@ +What: /sys/kernel/debug/habanalabs/hl<n>/addr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets the device address to be used for read or write through + PCI bar. The acceptable value is a string that starts with "0x" + +What: /sys/kernel/debug/habanalabs/hl<n>/command_buffers +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays a list with information about the currently allocated + command buffers + +What: /sys/kernel/debug/habanalabs/hl<n>/command_submission +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays a list with information about the currently active + command submissions + +What: /sys/kernel/debug/habanalabs/hl<n>/command_submission_jobs +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays a list with detailed information about each JOB (CB) of + each active command submission + +What: /sys/kernel/debug/habanalabs/hl<n>/data32 +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Allows the root user to read or write directly through the + device's PCI bar. Writing to this file generates a write + transaction while reading from the file generates a read + transcation. This custom interface is needed (instead of using + the generic Linux user-space PCI mapping) because the DDR bar + is very small compared to the DDR memory and only the driver can + move the bar before and after the transaction + +What: /sys/kernel/debug/habanalabs/hl<n>/device +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Enables the root user to set the device to specific state. + Valid values are "disable", "enable", "suspend", "resume". + User can read this property to see the valid values + +What: /sys/kernel/debug/habanalabs/hl<n>/i2c_addr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets I2C device address for I2C transaction that is generated + by the device's CPU + +What: /sys/kernel/debug/habanalabs/hl<n>/i2c_bus +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets I2C bus address for I2C transaction that is generated by + the device's CPU + +What: /sys/kernel/debug/habanalabs/hl<n>/i2c_data +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Triggers an I2C transaction that is generated by the device's + CPU. Writing to this file generates a write transaction while + reading from the file generates a read transcation + +What: /sys/kernel/debug/habanalabs/hl<n>/i2c_reg +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets I2C register id for I2C transaction that is generated by + the device's CPU + +What: /sys/kernel/debug/habanalabs/hl<n>/led0 +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets the state of the first S/W led on the device + +What: /sys/kernel/debug/habanalabs/hl<n>/led1 +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets the state of the second S/W led on the device + +What: /sys/kernel/debug/habanalabs/hl<n>/led2 +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets the state of the third S/W led on the device + +What: /sys/kernel/debug/habanalabs/hl<n>/mmu +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays the hop values and physical address for a given ASID + and virtual address. The user should write the ASID and VA into + the file and then read the file to get the result. + e.g. to display info about VA 0x1000 for ASID 1 you need to do: + echo "1 0x1000" > /sys/kernel/debug/habanalabs/hl0/mmu + +What: /sys/kernel/debug/habanalabs/hl<n>/set_power_state +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Sets the PCI power state. Valid values are "1" for D0 and "2" + for D3Hot + +What: /sys/kernel/debug/habanalabs/hl<n>/userptr +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays a list with information about the currently user + pointers (user virtual addresses) that are pinned and mapped + to DMA addresses + +What: /sys/kernel/debug/habanalabs/hl<n>/vm +Date: Jan 2019 +KernelVersion: 5.1 +Contact: [email protected] +Description: Displays a list with information about all the active virtual + address mappings per ASID +
drivers/misc/habanalabs/Makefile +2 -0
@@ -8,5 +8,7 @@ habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \ command_submission.o mmu.o +habanalabs-$(CONFIG_DEBUG_FS) += debugfs.o + include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/command_buffer.c +4 -0
@@ -36,6 +36,8 @@ static void cb_release(struct kref *ref) cb = container_of(ref, struct hl_cb, refcount); hdev = cb->hdev; +hl_debugfs_remove_cb (cb); +cb_do_release (hdev, cb); }
@@ -141,6 +143,8 @@ int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr, *handle = cb->id |HL_MMAP_CB_MASK ; *handle <<=PAGE_SHIFT ; +hl_debugfs_add_cb (cb); +return 0 ; release_cb:
drivers/misc/habanalabs/command_submission.c +12 -0
@@ -153,6 +153,8 @@ static void free_job(struct hl_device *hdev, struct hl_cs_job *job)list_del (&job->cs_node);spin_unlock (&cs->job_lock); +hl_debugfs_remove_job (hdev, job); +if (job->ext_queue)cs_put (cs);
@@ -215,6 +217,12 @@ static void cs_do_release(struct kref *ref) } } +/* +* Must be called before hl_ctx_put because inside we use ctx to get +* the device +*/ +hl_debugfs_remove_cs (cs); +hl_ctx_put (cs->ctx);if (cs->timedout)
@@ -483,6 +491,8 @@ static int _hl_cs_ioctl(struct hl_fpriv *hpriv, void __user *chunks, *cs_seq = cs->sequence; +hl_debugfs_add_cs (cs); +/* Validate ALL the CS chunks before submitting the CS */ for (i =0 , parse_cnt =0 ; i < num_chunks ; i++, parse_cnt++) {struct hl_cs_chunk *chunk = &cs_chunk_array[i];
@@ -531,6 +541,8 @@ static int _hl_cs_ioctl(struct hl_fpriv *hpriv, void __user *chunks,if (job->ext_queue)cs_get (cs); +hl_debugfs_add_job (hdev, job); + rc =cs_parser (hpriv, job);if (rc) { dev_err(hdev->dev,
drivers/misc/habanalabs/debugfs.c new file +1069 -0
1,069 lines not on this page · raw message
drivers/misc/habanalabs/device.c +6 -0
@@ -22,6 +22,8 @@ static void hpriv_release(struct kref *ref)put_pid (hpriv->taskpid); +hl_debugfs_remove_file (hpriv); +mutex_destroy (&hpriv->restore_phase_mutex);kfree (hpriv);
@@ -807,6 +809,8 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) goto free_cb_pool; } +hl_debugfs_add_device (hdev); + rc = hdev->asic_funcs->hw_init (hdev);if (rc) {dev_err (hdev->dev,"failed to initialize the H/W\n" );
@@ -936,6 +940,8 @@ void hl_device_fini(struct hl_device *hdev)device_late_fini (hdev); +hl_debugfs_remove_device (hdev); +hl_sysfs_fini (hdev);/*
drivers/misc/habanalabs/goya/goya.c +108 -0
144 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h +5 -0
@@ -136,6 +136,10 @@ struct goya_device {u32 hw_cap_initialized; }; +int goya_debugfs_i2c_read (struct hl_device *hdev,u8 i2c_bus, +u8 i2c_addr,u8 i2c_reg,u32 *val); +int goya_debugfs_i2c_write (struct hl_device *hdev,u8 i2c_bus, +u8 i2c_addr,u8 i2c_reg,u32 val);int goya_test_cpu_queue (struct hl_device *hdev);int goya_send_cpu_message (struct hl_device *hdev,u32 *msg,u16 len,u32 timeout,long *result);
@@ -146,6 +150,7 @@ long goya_get_fan_speed(struct hl_device *hdev, int sensor_index, u32 attr);long goya_get_pwm_info (struct hl_device *hdev,int sensor_index,u32 attr);void goya_set_pwm_info (struct hl_device *hdev,int sensor_index,u32 attr,long value); +void goya_debugfs_led_set (struct hl_device *hdev,u8 led,u8 state);void goya_set_pll_profile (struct hl_device *hdev,enum hl_pll_frequency freq);int goya_add_device_attr (struct hl_device *hdev);void goya_remove_device_attr (struct hl_device *hdev);
drivers/misc/habanalabs/habanalabs.h +191 -0
287 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +14 -2
@@ -153,6 +153,8 @@ int hl_device_open(struct inode *inode, struct file *filp)*/ hl_device_set_frequency (hdev,PLL_HIGH ); +hl_debugfs_add_file (hpriv); +return 0 ; out_err:
@@ -425,17 +427,20 @@ static int __init hl_init(void) goto remove_major; } +hl_debugfs_init (); + rc =pci_register_driver (&hl_pci_driver);if (rc) {pr_err ("habanalabs: failed to register pci device\n" ); - goto remove_class; + goto remove_debugfs; }pr_debug ("habanalabs: driver loaded\n" );return 0 ; -remove_class: +remove_debugfs: +hl_debugfs_fini ();class_destroy (hl_class); remove_major:unregister_chrdev_region (MKDEV (hl_major,0 ),HL_MAX_MINORS );
@@ -450,6 +455,13 @@ static void __exit hl_exit(void) {pci_unregister_driver (&hl_pci_driver); +/* +* Removing debugfs must be after all devices or simulator devices +* have been removed because otherwise we get a bug in the +* debugfs module for referencing NULL objects +*/ +hl_debugfs_fini (); +class_destroy (hl_class);unregister_chrdev_region (MKDEV (hl_major,0 ),HL_MAX_MINORS );
drivers/misc/habanalabs/memory.c +8 -0
@@ -1284,6 +1284,8 @@ int hl_pin_host_memory(struct hl_device *hdev, u64 addr, u32 size, goto free_sgt; } +hl_debugfs_add_userptr (hdev, userptr); +return 0 ; free_sgt:
@@ -1309,6 +1311,8 @@ int hl_unpin_host_memory(struct hl_device *hdev, struct hl_userptr *userptr) {struct page **pages; +hl_debugfs_remove_userptr (hdev, userptr); +if (userptr->dma_mapped) hdev->asic_funcs->hl_dma_unmap_sg(hdev, userptr->sgt->sgl,
@@ -1470,6 +1474,8 @@ int hl_vm_ctx_init_with_ranges(struct hl_ctx *ctx, u64 host_range_start, goto dram_vm_err; } +hl_debugfs_add_ctx_mem_hash (hdev, ctx); +return 0 ; dram_vm_err:
@@ -1590,6 +1596,8 @@ void hl_vm_ctx_fini(struct hl_ctx *ctx)struct hlist_node *tmp_node;int i; +hl_debugfs_remove_ctx_mem_hash (hdev, ctx); +if (!hash_empty (ctx->mem_hash))dev_notice (hdev->dev,"ctx is freed while it has va in use\n" );
Signature · 1 line
2.17.1
PATCH 12/15 habanalabs: add virtual memory and MMU modules
In reply to Oded GabbayFrom: Omer Shpigelman <[email protected]>
This patch adds the Virtual Memory and MMU modules.
Goya has an internal MMU which provides process isolation on the internal DDR. The internal MMU also performs translations for transactions that go from Goya to the Host.
The driver is responsible for allocating and freeing memory on the DDR upon user request. It also provides an interface to map and unmap DDR and Host memory to the device address space.
--- drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/context.c | 19 +- drivers/misc/habanalabs/device.c | 20 +- drivers/misc/habanalabs/goya/goya.c | 391 +++++ drivers/misc/habanalabs/habanalabs.h | 195 +++ drivers/misc/habanalabs/habanalabs_drv.c | 2 +- drivers/misc/habanalabs/habanalabs_ioctl.c | 3 +- drivers/misc/habanalabs/include/goya/goya.h | 6 +- .../include/hw_ip/mmu/mmu_general.h | 45 + .../habanalabs/include/hw_ip/mmu/mmu_v1_0.h | 15 + drivers/misc/habanalabs/memory.c | 1506 +++++++++++++++++ drivers/misc/habanalabs/mmu.c | 604 +++++++ include/uapi/misc/habanalabs.h | 122 +- 13 files changed, 2922 insertions(+), 8 deletions(-) create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_0.h create mode 100644 drivers/misc/habanalabs/mmu.c
drivers/misc/habanalabs/Makefile +1 -1
@@ -6,7 +6,7 @@ obj-m := habanalabs.o habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ command_buffer.o hw_queue.o irq.o sysfs.o hwmon.o memory.o \ - command_submission.o + command_submission.o mmu.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/context.c +18 -1
@@ -26,8 +26,10 @@ static void hl_ctx_fini(struct hl_ctx *ctx)for (i =0 ; i <HL_MAX_PENDING_CS ; i++)dma_fence_put (ctx->cs_pending[i]); -if (ctx->asid !=HL_KERNEL_ASID_ID ) +if (ctx->asid !=HL_KERNEL_ASID_ID ) { +hl_vm_ctx_fini (ctx);hl_asid_free (hdev, ctx->asid); + } }void hl_ctx_do_release (struct kref *ref)
@@ -97,6 +99,8 @@ void hl_ctx_free(struct hl_device *hdev, struct hl_ctx *ctx)int hl_ctx_init (struct hl_device *hdev,struct hl_ctx *ctx,bool is_kernel_ctx) { +int rc =0 ; + ctx->hdev = hdev;kref_init (&ctx->refcount);
@@ -114,9 +118,22 @@ int hl_ctx_init(struct hl_device *hdev, struct hl_ctx *ctx, bool is_kernel_ctx)dev_err (hdev->dev,"No free ASID, failed to create context\n" );return -ENOMEM ; } + + rc =hl_vm_ctx_init (ctx); +if (rc) { +dev_err (hdev->dev,"Failed to init mem ctx module\n" ); + rc = -ENOMEM ; + goto mem_ctx_err; + } }return 0 ; + +mem_ctx_err: +if (ctx->asid !=HL_KERNEL_ASID_ID ) +hl_asid_free (hdev, ctx->asid); + +return rc; }void hl_ctx_get (struct hl_device *hdev,struct hl_ctx *ctx)
drivers/misc/habanalabs/device.c +19 -1
@@ -585,8 +585,10 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset,/* Reset the H/W. It will be in idle state after this returns */ hdev->asic_funcs->hw_fini (hdev, hard_reset); -if (hard_reset) +if (hard_reset) { +hl_vm_fini (hdev);hl_eq_reset (hdev, &hdev->event_queue); + }/* Re-initialize PI,CI to 0 in all queues (hw queue, cq) */ hl_hw_queue_reset (hdev, hard_reset);
@@ -647,6 +649,13 @@ int hl_device_reset(struct hl_device *hdev, bool hard_reset, goto out_err; } + rc =hl_vm_init (hdev); +if (rc) { +dev_err (hdev->dev, +"Failed to init memory module after hard reset\n" ); + goto out_err; + } +hl_set_max_power (hdev, hdev->max_power); hdev->hard_reset_pending = false;
@@ -828,6 +837,13 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) hdev->asic_name, hdev->asic_prop.dram_size / 1024 / 1024 / 1024); + rc =hl_vm_init (hdev); +if (rc) { +dev_err (hdev->dev,"Failed to initialize memory module\n" ); + rc =0 ; + goto out_disabled; + } + rc =hl_hwmon_init (hdev);if (rc) {dev_err (hdev->dev,"Failed to initialize hwmon\n" );
@@ -941,6 +957,8 @@ void hl_device_fini(struct hl_device *hdev)/* Reset the H/W. It will be in idle state after this returns */ hdev->asic_funcs->hw_fini (hdev, true); +hl_vm_fini (hdev); +hl_eq_fini (hdev, &hdev->event_queue);for (i =0 ; i < hdev->asic_prop.completion_queues_count ; i++)
drivers/misc/habanalabs/goya/goya.c +391 -0
464 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h +195 -0
319 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +1 -1
@@ -202,7 +202,7 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->reset_on_lockup = reset_on_lockup;/* Parameters for bring-up - set them to defaults */ - hdev->mmu_enable =0 ; + hdev->mmu_enable =1 ; hdev->cpu_enable =1 ; hdev->reset_pcilink =0 ; hdev->config_pll =0 ;
drivers/misc/habanalabs/habanalabs_ioctl.c +2 -1
@@ -18,7 +18,8 @@static const struct hl_ioctl_desc hl_ioctls[] = {HL_IOCTL_DEF (HL_IOCTL_CB , hl_cb_ioctl),HL_IOCTL_DEF (HL_IOCTL_CS , hl_cs_ioctl), -HL_IOCTL_DEF (HL_IOCTL_WAIT_CS , hl_cs_wait_ioctl) +HL_IOCTL_DEF (HL_IOCTL_WAIT_CS , hl_cs_wait_ioctl), +HL_IOCTL_DEF (HL_IOCTL_MEMORY , hl_mem_ioctl) };#define HL_CORE_IOCTL_COUNT ARRAY_SIZE(hl_ioctls)
drivers/misc/habanalabs/include/goya/goya.h +4 -2
@@ -36,12 +36,14 @@#define CPU_FW_IMAGE_SIZE 0x10000000/* 256MB */ #define MMU_PAGE_TABLES_SIZE 0x0E000000/* 224MB */ +#define MMU_CACHE_MNG_SIZE 0x00001000/* 4KB */ #define CPU_PQ_PKT_SIZE 0x00001000/* 4KB */ -#define CPU_PQ_DATA_SIZE 0x01FFF000/* 32MB - 4KB */ +#define CPU_PQ_DATA_SIZE 0x01FFE000/* 32MB - 8KB */ #define CPU_FW_IMAGE_ADDR DRAM_PHYS_BASE#define MMU_PAGE_TABLES_ADDR (CPU_FW_IMAGE_ADDR + CPU_FW_IMAGE_SIZE) -#define CPU_PQ_PKT_ADDR (MMU_PAGE_TABLES_ADDR + MMU_PAGE_TABLES_SIZE) +#define MMU_CACHE_MNG_ADDR (MMU_PAGE_TABLES_ADDR + MMU_PAGE_TABLES_SIZE) +#define CPU_PQ_PKT_ADDR (MMU_CACHE_MNG_ADDR + MMU_CACHE_MNG_SIZE)#define CPU_PQ_DATA_ADDR (CPU_PQ_PKT_ADDR + CPU_PQ_PKT_SIZE)#define DRAM_BASE_ADDR_USER (CPU_PQ_DATA_ADDR + CPU_PQ_DATA_SIZE)
drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h new file +45 -0
45 lines not on this page · raw message
drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_0.h new file +15 -0
@@ -0,0 +1,15 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +*/ + +#ifndef INCLUDE_MMU_V1_0_H_ +#define INCLUDE_MMU_V1_0_H_ + +#define MMU_HOP0_PA43_12 0x490004 +#define MMU_HOP0_PA49_44 0x490008 +#define MMU_ASID_BUSY 0x490000 + +#endif /* INCLUDE_MMU_V1_0_H_ */
drivers/misc/habanalabs/memory.c +1506 -0
1,521 lines not on this page · raw message
drivers/misc/habanalabs/mmu.c new file +604 -0
509 lines not on this page · raw message
include/uapi/misc/habanalabs.h +121 -1
122 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH 15/15 Update MAINTAINERS and CREDITS with habanalabs info
In reply to Oded GabbayThe habanalabs driver was written from scratch from the very first days of Habana and is maintained by Oded Gabbay.
--- CREDITS | 2 +- MAINTAINERS | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-)
CREDITS +1 -1
@@ -1222,7 +1222,7 @@ S: Brazil N: Oded Gabbay E: [email protected] -D: AMD KFD maintainer +D: HabanaLabs and AMD KFD maintainer S: 12 Shraga Raphaeli S: Petah-Tikva, 4906418 S: Israel
MAINTAINERS +9 -0
@@ -6641,6 +6641,15 @@ F: drivers/clocksource/h8300_*.c F: drivers/clk/h8300/ F: drivers/irqchip/irq-renesas-h8*.c +HABANALABS PCI DRIVER +M: Oded Gabbay <[email protected]> +T: git https://github.com/HabanaAI/linux.git +S: Supported +F: drivers/misc/habanalabs/ +F: include/uapi/misc/habanalabs.h +F: Documentation/ABI/testing/sysfs-driver-habanalabs +F: Documentation/ABI/testing/debugfs-driver-habanalabs + HACKRF MEDIA DRIVER M: Antti Palosaari <[email protected]> L: [email protected]
Signature · 1 line
2.17.1
PATCH 6/15 habanalabs: add basic Goya h/w initialization
In reply to Oded GabbayThis patch adds the basic part of Goya's H/W initialization. It adds code that initializes Goya's internal CPU, various registers that are related to internal routing, scrambling, workarounds for H/W bugs, etc.
It also initializes Goya's security scheme that prevents the user from abusing Goya to steal data from the host, crash the host, change Goya's F/W, etc.
--- drivers/misc/habanalabs/device.c | 12 + drivers/misc/habanalabs/goya/Makefile | 2 +- drivers/misc/habanalabs/goya/goya.c | 1892 ++++++++++- drivers/misc/habanalabs/goya/goyaP.h | 3 + drivers/misc/habanalabs/goya/goya_security.c | 2999 +++++++++++++++++ drivers/misc/habanalabs/habanalabs.h | 16 + drivers/misc/habanalabs/habanalabs_drv.c | 8 + drivers/misc/habanalabs/include/goya/goya.h | 1 + .../include/goya/goya_async_events.h | 186 + .../habanalabs/include/goya/goya_boot_if.h | 32 + 10 files changed, 5144 insertions(+), 7 deletions(-) create mode 100644 drivers/misc/habanalabs/goya/goya_security.c create mode 100644 drivers/misc/habanalabs/include/goya/goya_async_events.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_boot_if.h
drivers/misc/habanalabs/device.c +12 -0
@@ -315,6 +315,15 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) goto release_ctx; } + rc = hdev->asic_funcs->hw_init (hdev); +if (rc) { +dev_err (hdev->dev,"failed to initialize the H/W\n" ); + rc =0 ; + goto out_disabled; + } + + hdev->disabled = false; +dev_notice (hdev->dev,"Successfully added device to habanalabs driver\n" );
@@ -366,6 +375,9 @@ void hl_device_fini(struct hl_device *hdev)if ((hdev->kernel_ctx) && (hl_ctx_put (hdev->kernel_ctx) !=1 ))dev_err (hdev->dev,"kernel ctx is still alive\n" ); +/* Reset the H/W. It will be in idle state after this returns */ + hdev->asic_funcs->hw_fini (hdev, true); +/* Call ASIC S/W finalize function */ hdev->asic_funcs->sw_fini (hdev);
drivers/misc/habanalabs/goya/Makefile +1 -1
@@ -1,3 +1,3 @@ subdir-ccflags-y += -I$(src) -HL_GOYA_FILES := goya/goya.o +HL_GOYA_FILES := goya/goya.o goya/goya_security.o
drivers/misc/habanalabs/goya/goya.c +1886 -6
1,919 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h +3 -0
@@ -9,6 +9,7 @@#define GOYAP_H_ #include "habanalabs.h" +#include "include/goya/goya_boot_if.h" #include "include/goya/goya.h" #define NUMBER_OF_CMPLT_QUEUES 5
@@ -122,4 +123,6 @@ struct goya_device { u32 hw_cap_initialized; }; +void goya_init_security (struct hl_device *hdev); +#endif /* GOYAP_H_ */
drivers/misc/habanalabs/goya/goya_security.c new file +2999 -0
1,038 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +8 -0
Lines of this file are not shown. View the raw message.
drivers/misc/habanalabs/include/goya/goya.h +1 -0
Lines of this file are not shown. View the raw message.
drivers/misc/habanalabs/include/goya/goya_async_events.h new file +186 -0
186 lines not on this page · raw message
drivers/misc/habanalabs/include/goya/goya_boot_if.h new file +32 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH 7/15 habanalabs: add h/w queues module
In reply to Oded GabbayThis patch adds the H/W queues module and the code to initialize Goya's various compute and DMA engines and their queues.
Goya has 5 DMA channels, 8 TPC engines and a single MME engine. For each channel/engine, there is a H/W queue logic which is used to pass commands from the user to the H/W. That logic is called QMAN.
There are two types of QMANs: external and internal. The DMA QMANs are considered external while the TPC and MME QMANs are considered internal. For each external queue there is a completion queue, which is located on the Host memory.
The differences between external and internal QMANs are:
1. The location of the queue's memory. External QMANs are located on the Host memory while internal QMANs are located on the on-chip memory.
2. The external QMAN write an entry to a completion queue and sends an MSI-X interrupt upon completion of a command buffer that was given to it. The internal QMAN doesn't do that.
--- drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/device.c | 74 +- drivers/misc/habanalabs/goya/goya.c | 1518 +++++++++++++++-- drivers/misc/habanalabs/goya/goyaP.h | 6 + drivers/misc/habanalabs/habanalabs.h | 176 +- drivers/misc/habanalabs/habanalabs_drv.c | 6 + drivers/misc/habanalabs/hw_queue.c | 404 +++++ .../habanalabs/include/goya/goya_packets.h | 234 +++ .../habanalabs/include/habanalabs_device_if.h | 272 +++ drivers/misc/habanalabs/irq.c | 150 ++ 10 files changed, 2721 insertions(+), 121 deletions(-) create mode 100644 drivers/misc/habanalabs/hw_queue.c create mode 100644 drivers/misc/habanalabs/include/goya/goya_packets.h create mode 100644 drivers/misc/habanalabs/irq.c
drivers/misc/habanalabs/Makefile +1 -1
@@ -5,7 +5,7 @@ obj-m := habanalabs.o habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ - command_buffer.o + command_buffer.o hw_queue.o irq.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/device.c +72 -2
136 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +1401 -117
1,635 lines not on this page · raw message
drivers/misc/habanalabs/goya/goyaP.h +6 -0
@@ -9,6 +9,7 @@#define GOYAP_H_ #include "habanalabs.h" +#include "include/goya/goya_packets.h" #include "include/goya/goya_boot_if.h" #include "include/goya/goya.h"
@@ -117,12 +118,17 @@ enum goya_fw_component { };struct goya_device { +int (*test_cpu_queue)(struct hl_device *hdev); +/* TODO: remove hw_queues_lock after moving to scheduler code */ spinlock_t hw_queues_lock;u64 ddr_bar_cur_addr;u32 hw_cap_initialized; }; +int goya_test_cpu_queue (struct hl_device *hdev); +int goya_send_cpu_message (struct hl_device *hdev,u32 *msg,u16 len, +u32 timeout,long *result);void goya_init_security (struct hl_device *hdev);#endif /* GOYAP_H_ */
drivers/misc/habanalabs/habanalabs.h +175 -1
262 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +6 -0
@@ -184,13 +184,19 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->cpu_enable =1 ; hdev->reset_pcilink =0 ; hdev->config_pll =0 ; + hdev->cpu_queues_enable =1 ; hdev->fw_loading =1 ; + hdev->ifh =0 ; hdev->pldm =0 ;/* If CPU is disabled, no point in loading FW */ if (!hdev->cpu_enable) hdev->fw_loading =0 ; +/* If we don't load FW, no need to initialize CPU queues */ +if (!hdev->fw_loading) + hdev->cpu_queues_enable =0 ; + hdev->disabled = true; hdev->pdev = pdev;/* can be NULL in case of simulator device */
drivers/misc/habanalabs/hw_queue.c new file +404 -0
404 lines not on this page · raw message
drivers/misc/habanalabs/include/goya/goya_packets.h new file +234 -0
234 lines not on this page · raw message
drivers/misc/habanalabs/include/habanalabs_device_if.h +272 -0
278 lines not on this page · raw message
drivers/misc/habanalabs/irq.c new file +150 -0
150 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.17.1
Part of the diff is not shown here. View the raw message.
PATCH 10/15 habanalabs: add device reset support
In reply to Oded GabbayThis patch adds support for doing various on-the-fly reset of Goya.
The driver supports two types of resets:
1. soft-reset
2. hard-reset
Soft-reset is done when the device detects a timeout of a command submission that was given to the device. The soft-reset process only resets the engines that are relevant for the submission of compute jobs, i.e. the DMA channels, the TPCs and the MME. The purpose is to bring the device as fast as possible to a working state.
Hard-reset is done in several cases:
1. After soft-reset is done but the device is not responding
2. When fatal errors occur inside the device, e.g. ECC error
3. When the driver is removed
Hard-reset performs a reset of the entire chip except for the PCI controller and the PLLs. It is a much longer process then soft-reset but it helps to recover the device without the need to reboot the Host.
After hard-reset, the driver will restore the max power attribute and in case of manual power management, the frequencies that were set.
This patch also adds two entries to the sysfs, which allows the root user to initiate a soft or hard reset.
--- drivers/misc/habanalabs/command_buffer.c | 11 +- drivers/misc/habanalabs/device.c | 308 +++++++++++++++++++++- drivers/misc/habanalabs/goya/goya.c | 201 ++++++++++++++ drivers/misc/habanalabs/goya/goya_hwmgr.c | 18 +- drivers/misc/habanalabs/habanalabs.h | 35 +++ drivers/misc/habanalabs/habanalabs_drv.c | 9 +- drivers/misc/habanalabs/hwmon.c | 4 +- drivers/misc/habanalabs/irq.c | 31 +++ drivers/misc/habanalabs/sysfs.c | 120 ++++++++- 9 files changed, 712 insertions(+), 25 deletions(-)
drivers/misc/habanalabs/command_buffer.c +9 -2
@@ -81,9 +81,10 @@ int hl_cb_create(struct hl_device *hdev, struct hl_cb_mgr *mgr,bool alloc_new_cb = true;int rc; -if (hdev->disabled) { +if ((hdev->disabled) || ((atomic_read (&hdev->in_reset)) && + (ctx_id !=HL_KERNEL_ASID_ID ))) {dev_warn_ratelimited (hdev->dev, -"Device is disabled !!! Can't create new CBs\n" ); +"Device is disabled or in reset !!! Can't create new CBs\n" ); rc = -EBUSY ; goto out_err; }
@@ -187,6 +188,12 @@ int hl_cb_ioctl(struct hl_fpriv *hpriv, void *data)u64 handle;int rc; +if (hdev->hard_reset_pending) { +dev_crit_ratelimited (hdev->dev, +"Device HARD reset pending !!! Please close FD\n" ); +return -ENODEV ; + } +switch (args->in.op) {case HL_CB_OP_CREATE : rc = hl_cb_create(hdev, &hpriv->cb_mgr, args->in.cb_size,
drivers/misc/habanalabs/device.c +307 -1
364 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya.c +201 -0
233 lines not on this page · raw message
drivers/misc/habanalabs/goya/goya_hwmgr.c +9 -9
@@ -38,7 +38,7 @@ static ssize_t mme_clk_show(struct device *dev, struct device_attribute *attr,struct hl_device *hdev =dev_get_drvdata (dev);long value; -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ; value =hl_get_frequency (hdev,MME_PLL , false);
@@ -57,7 +57,7 @@ static ssize_t mme_clk_store(struct device *dev, struct device_attribute *attr,int rc;long value; -if (hdev->disabled) { +if ((hdev->disabled) || (atomic_read (&hdev->in_reset))) { count = -ENODEV ; goto fail; }
@@ -87,7 +87,7 @@ static ssize_t tpc_clk_show(struct device *dev, struct device_attribute *attr,struct hl_device *hdev =dev_get_drvdata (dev);long value; -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ; value =hl_get_frequency (hdev,TPC_PLL , false);
@@ -106,7 +106,7 @@ static ssize_t tpc_clk_store(struct device *dev, struct device_attribute *attr,int rc;long value; -if (hdev->disabled) { +if ((hdev->disabled) || (atomic_read (&hdev->in_reset))) { count = -ENODEV ; goto fail; }
@@ -136,7 +136,7 @@ static ssize_t ic_clk_show(struct device *dev, struct device_attribute *attr,struct hl_device *hdev =dev_get_drvdata (dev);long value; -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ; value =hl_get_frequency (hdev,IC_PLL , false);
@@ -155,7 +155,7 @@ static ssize_t ic_clk_store(struct device *dev, struct device_attribute *attr,int rc;long value; -if (hdev->disabled) { +if ((hdev->disabled) || (atomic_read (&hdev->in_reset))) { count = -ENODEV ; goto fail; }
@@ -185,7 +185,7 @@ static ssize_t mme_clk_curr_show(struct device *dev,struct hl_device *hdev =dev_get_drvdata (dev);long value; -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ; value =hl_get_frequency (hdev,MME_PLL , true);
@@ -202,7 +202,7 @@ static ssize_t tpc_clk_curr_show(struct device *dev,struct hl_device *hdev =dev_get_drvdata (dev);long value; -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ; value =hl_get_frequency (hdev,TPC_PLL , true);
@@ -219,7 +219,7 @@ static ssize_t ic_clk_curr_show(struct device *dev,struct hl_device *hdev =dev_get_drvdata (dev);long value; -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ; value =hl_get_frequency (hdev,IC_PLL , true);
drivers/misc/habanalabs/habanalabs.h +35 -0
@@ -23,8 +23,12 @@#define HL_MMAP_CB_MASK (0x8000000000000000ull >> PAGE_SHIFT) +#define HL_PENDING_RESET_PER_SEC 5 +#define HL_DEVICE_TIMEOUT_USEC 1000000/* 1 s */ +#define HL_HEARTBEAT_PER_USEC 5000000/* 5 s */ +#define HL_PLL_LOW_JOB_FREQ_USEC 5000000/* 5 s */ #define HL_MAX_QUEUES 128
@@ -370,8 +374,10 @@ enum hl_pll_frequency {* @handle_eqe: handle event queue entry (IRQ) from ArmCP. * @set_pll_profile: change PLL profile (manual/automatic). * @get_events_stat: retrieve event queue entries histogram. +* @send_heartbeat: send is-alive packet to ArmCP and verify response. * @enable_clock_gating: enable clock gating for reducing power consumption. * @disable_clock_gating: disable clock for accessing registers on HBW. +* @soft_reset_late_init: perform certain actions needed after soft reset. * @hw_queues_lock: acquire H/W queues lock. * @hw_queues_unlock: release H/W queues lock. * @get_eeprom_data: retrieve EEPROM data from F/W.
@@ -417,8 +423,10 @@ struct hl_asic_funcs {void (*set_pll_profile)(struct hl_device *hdev,enum hl_pll_frequency freq);void * (*get_events_stat)(struct hl_device *hdev,u32 *size); +int (*send_heartbeat)(struct hl_device *hdev);void (*enable_clock_gating)(struct hl_device *hdev);void (*disable_clock_gating)(struct hl_device *hdev); +int (*soft_reset_late_init)(struct hl_device *hdev);void (*hw_queues_lock)(struct hl_device *hdev);void (*hw_queues_unlock)(struct hl_device *hdev); int (*get_eeprom_data)(struct hl_device *hdev, void *data,
@@ -544,6 +552,16 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | \ (val) << REG_FIELD_SHIFT(reg, field)) +/** +* struct hl_device_reset_work - reset workqueue task wrapper. +* @reset_work: reset work to be done. +* @hdev: habanalabs device structure. +*/ +struct hl_device_reset_work { +struct work_struct reset_work; +struct hl_device *hdev; +}; +/** * struct hl_device - habanalabs device structure. * @pdev: pointer to PCI device, can be NULL in case of simulator device.
@@ -552,6 +570,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @cdev: related char device. * @dev: realted kernel basic device structure. * @work_freq: delayed work to lower device frequency if possible. +* @work_heartbeat: delayed work for ArmCP is-alive check. * @asic_name: ASIC specific nmae. * @asic_type: ASIC specific type. * @completion_queue: array of hl_cq.
@@ -579,6 +598,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @cb_pool: list of preallocated CBs. * @cb_pool_lock: protects the CB pool. * @user_ctx: current user context executing. +* @in_reset: is device in reset flow. * @curr_pll_profile: current PLL profile. * @fd_open_cnt: number of open context executing. * @max_power: the max power of the device, as configured by the sysadmin. This
@@ -586,10 +606,14 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* value and update the F/W after the re-initialization * @major: habanalabs KMD major. * @high_pll: high PLL profile frequency. +* @soft_reset_cnt: number of soft reset since KMD loading. +* @hard_reset_cnt: number of hard reset since KMD loading. * @id: device minor. * @disabled: is device disabled. * @late_init_done: is late init stage was done during initialization. * @hwmon_initialized: is H/W monitor sensors was initialized. +* @hard_reset_pending: is there a hard reset work pending. +* @heartbeat: is heartbeat sanity check towards ArmCP enabled. */ struct hl_device {struct pci_dev *pdev;
@@ -598,6 +622,7 @@ struct hl_device {struct cdev cdev;struct device *dev;struct delayed_work work_freq; +struct delayed_work work_heartbeat;char asic_name[16 ];enum hl_asic_type asic_type;struct hl_cq *completion_queue;
@@ -630,15 +655,20 @@ struct hl_device {/* TODO: The following fields should be moved for multi-context */ struct hl_ctx *user_ctx; +atomic_t in_reset;atomic_t curr_pll_profile;atomic_t fd_open_cnt;u64 max_power;u32 major;u32 high_pll; +u32 soft_reset_cnt; +u32 hard_reset_cnt;u16 id;u8 disabled;u8 late_init_done;u8 hwmon_initialized; +u8 hard_reset_pending; +u8 heartbeat;/* Parameters for bring-up */ u8 cpu_enable;
@@ -696,6 +726,7 @@ int hl_hw_queue_send_cb_no_cmpl(struct hl_device *hdev, u32 hw_queue_id, u32 cb_size, u64 cb_ptr);u32 hl_hw_queue_add_ptr (u32 ptr,u16 val);void hl_hw_queue_inc_ci_kernel (struct hl_device *hdev,u32 hw_queue_id); +void hl_hw_queue_reset (struct hl_device *hdev,bool hard_reset);#define hl_queue_inc_ptr (p) hl_hw_queue_add_ptr(p, 1)#define hl_pi_2_offset (pi) ((pi) & (HL_QUEUE_LENGTH - 1))
@@ -704,6 +735,8 @@ int hl_cq_init(struct hl_device *hdev, struct hl_cq *q, u32 hw_queue_id);void hl_cq_fini (struct hl_device *hdev,struct hl_cq *q);int hl_eq_init (struct hl_device *hdev,struct hl_eq *q);void hl_eq_fini (struct hl_device *hdev,struct hl_eq *q); +void hl_cq_reset (struct hl_device *hdev,struct hl_cq *q); +void hl_eq_reset (struct hl_device *hdev,struct hl_eq *q);irqreturn_t hl_irq_handler_cq (int irq,void *arg);irqreturn_t hl_irq_handler_eq (int irq,void *arg);int hl_asid_init (struct hl_device *hdev);
@@ -721,6 +754,8 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass);void hl_device_fini (struct hl_device *hdev);int hl_device_suspend (struct hl_device *hdev);int hl_device_resume (struct hl_device *hdev); +int hl_device_reset (struct hl_device *hdev,bool hard_reset, +bool from_hard_reset_thread);void hl_hpriv_get (struct hl_fpriv *hpriv);void hl_hpriv_put (struct hl_fpriv *hpriv);int hl_device_set_frequency (struct hl_device *hdev,enum hl_pll_frequency freq);
drivers/misc/habanalabs/habanalabs_drv.c +7 -2
@@ -91,9 +91,9 @@ int hl_device_open(struct inode *inode, struct file *filp)mutex_lock (&hdev->device_open); -if (hdev->disabled) { +if ((hdev->disabled) || (atomic_read (&hdev->in_reset))) {dev_err_ratelimited (hdev->dev, -"Can't open %s because it is disabled\n" , +"Can't open %s because it is disabled or in reset\n" ,dev_name (hdev->dev));mutex_unlock (&hdev->device_open);return -EPERM ;
@@ -195,6 +195,7 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->fw_loading =1 ; hdev->ifh =0 ; hdev->pldm =0 ; + hdev->heartbeat =1 ;/* If CPU is disabled, no point in loading FW */ if (!hdev->cpu_enable)
@@ -204,6 +205,10 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev,if (!hdev->fw_loading) hdev->cpu_queues_enable =0 ; +/* If CPU queues not enabled, no way to do heartbeat */ +if (!hdev->cpu_queues_enable) + hdev->heartbeat =0 ; + hdev->disabled = true; hdev->pdev = pdev;/* can be NULL in case of simulator device */
drivers/misc/habanalabs/hwmon.c +2 -2
@@ -111,7 +111,7 @@ static int hl_read(struct device *dev, enum hwmon_sensor_types type, {struct hl_device *hdev =dev_get_drvdata (dev); -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ;switch (type) {
@@ -185,7 +185,7 @@ static int hl_write(struct device *dev, enum hwmon_sensor_types type, {struct hl_device *hdev =dev_get_drvdata (dev); -if (hdev->disabled) +if ((hdev->disabled) || (atomic_read (&hdev->in_reset)))return -ENODEV ;switch (type) {
drivers/misc/habanalabs/irq.c +31 -0
@@ -250,6 +250,23 @@ void hl_cq_fini(struct hl_device *hdev, struct hl_cq *q) (void *) q->kernel_address, q->bus_address); } +void hl_cq_reset (struct hl_device *hdev,struct hl_cq *q) +{ + q->ci =0 ; + q->pi =0 ; + +atomic_set (&q->free_slots_cnt,HL_CQ_LENGTH ); + +/* +* It's not enough to just reset the PI/CI because the H/W may have +* written valid completion entries before it was halted and therefore +* we need to clean the actual queues so we won't process old entries +* when the device is operational again +*/ + +memset ((void *) q->kernel_address,0 ,HL_CQ_SIZE_IN_BYTES ); +} +/** * hl_eq_init - main initialization function for an event queue object *
@@ -292,3 +309,17 @@ void hl_eq_fini(struct hl_device *hdev, struct hl_eq *q) hdev->asic_funcs->dma_free_coherent (hdev,HL_EQ_SIZE_IN_BYTES , (void *) q->kernel_address, q->bus_address); } + +void hl_eq_reset (struct hl_device *hdev,struct hl_eq *q) +{ + q->ci =0 ; + +/* +* It's not enough to just reset the PI/CI because the H/W may have +* written valid completion entries before it was halted and therefore +* we need to clean the actual queues so we won't process old entries +* when the device is operational again +*/ + +memset ((void *) q->kernel_address,0 ,HL_EQ_SIZE_IN_BYTES ); +}
drivers/misc/habanalabs/sysfs.c +111 -9
228 lines not on this page · raw message
Signature · 1 line
2.17.1
PATCH 4/15 habanalabs: add context and ASID modules
In reply to Oded GabbayThis patch adds two modules - ASID and context.
Each user process the opens a device's file must have at least one context before it is able to "work" with the device. Each context has its own device address-space and contains information about its runtime state (its active command submissions).
To have address-space separation between contexts, each context is assigned a unique ASID, which stands for "address-space id". Goya supports up to 1024 ASIDs.
Currently, the driver doesn't support multiple contexts. Therefore, the user doesn't need to actively create a context. A "primary context" is created automatically when the user opens the device's file.
--- drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/asid.c | 58 +++++++++ drivers/misc/habanalabs/context.c | 155 +++++++++++++++++++++++ drivers/misc/habanalabs/device.c | 47 +++++++ drivers/misc/habanalabs/habanalabs.h | 70 ++++++++++ drivers/misc/habanalabs/habanalabs_drv.c | 46 ++++++- 6 files changed, 375 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/habanalabs/asid.c create mode 100644 drivers/misc/habanalabs/context.c
drivers/misc/habanalabs/Makefile +1 -1
@@ -4,7 +4,7 @@ obj-m := habanalabs.o -habanalabs-y := habanalabs_drv.o device.o +habanalabs-y := habanalabs_drv.o device.o context.o asid.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)
drivers/misc/habanalabs/asid.c new file +58 -0
58 lines not on this page · raw message
drivers/misc/habanalabs/context.c new file +155 -0
155 lines not on this page · raw message
drivers/misc/habanalabs/device.c +47 -0
92 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs.h +70 -0
124 lines not on this page · raw message
drivers/misc/habanalabs/habanalabs_drv.c +44 -2
68 lines not on this page · raw message
Signature · 1 line
2.17.1
Re: [PATCH 01/15] habanalabs: add skeleton driver
In reply to Oded GabbayQuoted 3 lines · Oded Gabbay
This patch adds the habanalabs skeleton driver. The driver does nothing at this stage except very basic operations. It contains the minimal code to insmod and rmmod the driver and to create a
/dev/hlXfile per PCI device.
trivial notes:
drivers/misc/habanalabs/Makefile
Quoted 2 lines
drivers/misc/habanalabs/Makefile +0
-0
[]
Quoted 1 line
\ No newline at end of file
You should fixes these. There are a least a couple of them.
drivers/misc/habanalabs/device.c
Quoted 1 line
drivers/misc/habanalabs/device.c +0
-0
[]
drivers/misc/habanalabs/device.c line 6
Quoted 7 lines
drivers/misc/habanalabs/device.c +6
-0@@ -0,0 +1,331 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/
Add #define pr_fmt(fmt) "habanalabs: " fmt
drivers/misc/habanalabs/device.c line 8
Quoted 2 lines
drivers/misc/habanalabs/device.c +2
-0+ +#include "habanalabs.h"
or add it in this file
drivers/misc/habanalabs/device.c line 82
Quoted 8 lines
drivers/misc/habanalabs/device.c +8
-0+static int device_setup_cdev (struct hl_device *hdev,struct class *hclass, +int minor,const struct file_operations *fops) +{ +int err, devno =MKDEV (hdev->major, minor); +struct cdev *hdev_cdev = &hdev->cdev; +char name[8 ]; + +sprintf (name,"hl%d" , hdev->id);
Might overflow name one day
drivers/misc/habanalabs/device.c line 88
Quoted 6 lines
drivers/misc/habanalabs/device.c +6
-0+ +cdev_init (hdev_cdev, fops); + hdev_cdev->owner =THIS_MODULE ; + err =cdev_add (hdev_cdev, devno,1 ); +if (err) { +pr_err ("habanalabs: Failed to add char device %s" , name);
So #define pr_fmt can auto prefix these and this would be
pr_err("Failed to add char device %s\n", name);missing terminating '\n' btw
drivers/misc/habanalabs/device.c line 94
Quoted 6 lines
drivers/misc/habanalabs/device.c +6
-0+ goto err_cdev_add; + } + + hdev->dev =device_create (hclass,NULL , devno,NULL ,"%s" , name); +if (IS_ERR (hdev->dev)) { +pr_err ("habanalabs: Failed to create device %s\n" , name);
And this would be:
pr_err("Failed to create device %s\n", name);etc...
drivers/misc/habanalabs/device.c line 121
Quoted 5 lines
drivers/misc/habanalabs/device.c +5
-0+static int device_early_init (struct hl_device *hdev) +{ +switch (hdev->asic_type) { +case ASIC_GOYA : +sprintf (hdev->asic_name,"GOYA" );
strcpy or perhaps better still as strlcpy
drivers/misc/habanalabs/device.c line 35
Quoted 2 lines
drivers/misc/habanalabs/device.c +2
-0+int hl_device_init (struct hl_device *hdev,struct class *hclass) +{
[]
drivers/misc/habanalabs/device.c line 212
Quoted 2 lines
drivers/misc/habanalabs/device.c +2
-0+dev_notice (hdev->dev, +"Successfully added device to habanalabs driver\n" );
This is mostly aligned to open parenthesis, but perhaps it could check with scripts/checkpatch.pl --strict and see if you agree with anything it bleats.
drivers/misc/habanalabs/device.c line 278
Quoted 9 lines
drivers/misc/habanalabs/device.c +9
-0+int hl_poll_timeout_memory (struct hl_device *hdev,u64 addr, +u32 timeout_us,u32 *val) +{ +/* +* pReturnVal is defined as volatile because it points to HOST memory, +* which is being written to by the device. Therefore, we can't use +* locks to synchronize it and it is not a memory-mapped register space +*/ +volatile u32 *pReturnVal = (volatile u32 *) addr;
It'd be nice to avoid hungarian and camelcase
Quoted 6 lines
drivers/misc/habanalabs/device.c +6
-0+ktime_t timeout =ktime_add_us (ktime_get (), timeout_us); + +might_sleep (); + +for (;;) { + *val = *pReturnVal;
drivers/misc/habanalabs/device.c line 294
Quoted 10 lines
drivers/misc/habanalabs/device.c +10
-0+if (*val) +break ; +if (ktime_compare (ktime_get (), timeout) >0 ) { + *val = *pReturnVal; +break ; + } +usleep_range ((100 >>2 ) +1 ,100 ); + } + +return (*val ?0 : -ETIMEDOUT );
Unnecessary parentheses
drivers/misc/habanalabs/habanalabs_drv.c
Quoted 1 line
drivers/misc/habanalabs/habanalabs_drv.c +0
-0
[]
drivers/misc/habanalabs/habanalabs_drv.c line 40
Quoted 4 lines
drivers/misc/habanalabs/habanalabs_drv.c +4
-0+static struct pci_device_id ids[] = { + {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GOYA ), }, + {0 , } +};
static const?
drivers/misc/habanalabs/include/habanalabs_device_if.h
Quoted 1 line
drivers/misc/habanalabs/include/habanalabs_device_if.h +0
-0
[]
drivers/misc/habanalabs/include/habanalabs_device_if.h line 29
Quoted 13 lines
drivers/misc/habanalabs/include/habanalabs_device_if.h +13
-0+struct hl_bd { +__u64 ptr; +__u32 len; +union { +struct { +__u32 repeat:16 ; +__u32 res1:8 ; +__u32 repeat_valid:1 ; +__u32 res2:7 ; + }; +__u32 ctl; + }; +};
Maybe use the appropriate bit-endian __le<size> instead of __u<size> with whatever cpu_to_le<size> / le<size>_to_cpu bits are necessary.
Hi,
Quoted 23 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Habana is a leading startup in the emerging AI processor space and we have already started production of our first Goya inference processor PCIe card and delivered it to customers. The Goya processor silicon has been tested since June of 2018 and is production-qualified by now. The Gaudi training processor solution is slated to sample in the second quarter of 2019.
This patch-set contains the kernel driver for Habana's AI Processors (AIP) that are designed to accelerate Deep Learning inference and training workloads. The current version supports only the Goya processor and support for Gaudi will be upstreamed after the ASIC will be available to customers.
The Goya processor has been designed from the ground up for deep learning inference workloads. It comprises a cluster of eight fully programmable Tensor Processing Cores (TPC). The TPC core is a VLIW SIMD vector processor with ISA and hardware that was tailored to serve deep learning workloads efficiently.
[ ... ]
Quoted 1 line
I would appricate any feedback, question and/or review.
I've looked at the patches 1,3-5 for now, it seems patch 2 still didn't make it to lore.kernel.org.
FWIW, I think it's a good solid work, unless you spoil it in patches 6-14 ;-)
As a general note, maybe drivers/misc is not the most appropriate place for such a complex beast. How about drivers/accelerator/ai?
Quoted 318 lines
p.s. for those who prefer to clone the tree instead of looking at the emails, you can grab a copy from our company's page in GitHub:
https://github.com/HabanaAI/linux/releases/tag/hl_patchset_v1
Thanks,
OdedOded Gabbay (14):
habanalabs: add skeleton driver
habanalabs: add Goya registers header files
habanalabs: add basic Goya support
habanalabs: add context and ASID modules
habanalabs: add command buffer module
habanalabs: add basic Goya h/w initialization
habanalabs: add h/w queues module
habanalabs: add event queue and interrupts
habanalabs: add sysfs and hwmon support
habanalabs: add device reset support
habanalabs: add command submission module
habanalabs: implement INFO IOCTL
habanalabs: add debugfs support
UpdateMAINTAINERSand CREDITS with habanalabs infoOmer Shpigelman (1):
habanalabs: add virtual memory and MMU modulesCREDITS | 2 +- .../ABI/testing/debugfs-driver-habanalabs | 127 + .../ABI/testing/sysfs-driver-habanalabs | 190 + MAINTAINERS | 9 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/habanalabs/Kconfig | 22 + drivers/misc/habanalabs/Makefile | 14 + drivers/misc/habanalabs/asid.c | 58 + drivers/misc/habanalabs/command_buffer.c | 425 + drivers/misc/habanalabs/command_submission.c | 799 ++ drivers/misc/habanalabs/context.c | 216 + drivers/misc/habanalabs/debugfs.c | 1069 ++ drivers/misc/habanalabs/device.c | 1097 ++ drivers/misc/habanalabs/goya/Makefile | 3 + drivers/misc/habanalabs/goya/goya.c | 6347 ++++++++++++ drivers/misc/habanalabs/goya/goyaP.h | 161 + drivers/misc/habanalabs/goya/goya_hwmgr.c | 306 + drivers/misc/habanalabs/goya/goya_security.c | 2999 ++++++ drivers/misc/habanalabs/habanalabs.h | 1464 +++ drivers/misc/habanalabs/habanalabs_drv.c | 474 + drivers/misc/habanalabs/habanalabs_ioctl.c | 237 + drivers/misc/habanalabs/hw_queue.c | 654 ++ drivers/misc/habanalabs/hwmon.c | 449 + .../include/goya/asic_reg/cpu_ca53_cfg_regs.h | 213 + .../include/goya/asic_reg/cpu_if_regs.h | 110 + .../include/goya/asic_reg/cpu_pll_regs.h | 186 + .../include/goya/asic_reg/ddr_mc_ch0_regs.h | 1158 +++ .../include/goya/asic_reg/ddr_mc_ch1_regs.h | 1158 +++ .../include/goya/asic_reg/ddr_misc_ch0_regs.h | 156 + .../include/goya/asic_reg/ddr_misc_ch1_regs.h | 156 + .../include/goya/asic_reg/dma_ch_0_regs.h | 512 + .../include/goya/asic_reg/dma_ch_1_regs.h | 512 + .../include/goya/asic_reg/dma_ch_2_regs.h | 512 + .../include/goya/asic_reg/dma_ch_3_regs.h | 512 + .../include/goya/asic_reg/dma_ch_4_regs.h | 512 + .../include/goya/asic_reg/dma_macro_regs.h | 242 + .../include/goya/asic_reg/dma_nrtr_regs.h | 380 + .../include/goya/asic_reg/dma_qm_0_regs.h | 543 + .../include/goya/asic_reg/dma_qm_1_regs.h | 543 + .../include/goya/asic_reg/dma_qm_2_regs.h | 543 + .../include/goya/asic_reg/dma_qm_3_regs.h | 543 + .../include/goya/asic_reg/dma_qm_4_regs.h | 543 + .../include/goya/asic_reg/gic_regs.h | 9079 +++++++++++++++++ .../include/goya/asic_reg/goya_blocks.h | 1372 +++ .../include/goya/asic_reg/goya_masks.h | 262 + .../include/goya/asic_reg/goya_regs.h | 119 + .../include/goya/asic_reg/ic_pll_regs.h | 186 + .../include/goya/asic_reg/mc_pll_regs.h | 186 + .../include/goya/asic_reg/mme1_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme2_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme3_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme4_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme5_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme6_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme_cmdq_regs.h | 431 + .../include/goya/asic_reg/mme_qm_regs.h | 543 + .../include/goya/asic_reg/mme_regs.h | 2422 +++++ .../include/goya/asic_reg/mmu_regs.h | 158 + .../include/goya/asic_reg/pci_nrtr_regs.h | 380 + .../include/goya/asic_reg/pcie_aux_regs.h | 476 + .../include/goya/asic_reg/pcie_dbi_regs.h | 2909 ++++++ .../goya/asic_reg/psoc_emmc_pll_regs.h | 186 + .../goya/asic_reg/psoc_global_conf_regs.h | 1119 ++ .../include/goya/asic_reg/psoc_mme_pll_regs.h | 186 + .../include/goya/asic_reg/psoc_pci_pll_regs.h | 186 + .../include/goya/asic_reg/psoc_spi_regs.h | 427 + .../goya/asic_reg/sram_y0_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x4_rtr_regs.h | 215 + .../include/goya/asic_reg/stlb_regs.h | 133 + .../include/goya/asic_reg/sync_mngr_regs.h | 4930 +++++++++ .../include/goya/asic_reg/tpc0_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc0_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc0_eml_cfg_regs.h | 580 ++ .../include/goya/asic_reg/tpc0_nrtr_regs.h | 380 + .../include/goya/asic_reg/tpc0_qm_regs.h | 543 + .../include/goya/asic_reg/tpc1_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc1_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc1_qm_regs.h | 543 + .../include/goya/asic_reg/tpc1_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc2_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc2_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc2_qm_regs.h | 543 + .../include/goya/asic_reg/tpc2_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc3_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc3_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc3_qm_regs.h | 543 + .../include/goya/asic_reg/tpc3_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc4_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc4_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc4_qm_regs.h | 543 + .../include/goya/asic_reg/tpc4_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc5_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc5_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc5_qm_regs.h | 543 + .../include/goya/asic_reg/tpc5_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc6_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc6_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc6_qm_regs.h | 543 + .../include/goya/asic_reg/tpc6_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc7_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc7_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc7_nrtr_regs.h | 380 + .../include/goya/asic_reg/tpc7_qm_regs.h | 543 + .../include/goya/asic_reg/tpc_pll_regs.h | 186 + drivers/misc/habanalabs/include/goya/goya.h | 117 + .../include/goya/goya_async_events.h | 186 + .../habanalabs/include/goya/goya_boot_if.h | 32 + .../habanalabs/include/goya/goya_packets.h | 234 + .../habanalabs/include/habanalabs_device_if.h | 397 + .../include/hw_ip/mmu/mmu_general.h | 45 + .../habanalabs/include/hw_ip/mmu/mmu_v1_0.h | 15 + drivers/misc/habanalabs/irq.c | 325 + drivers/misc/habanalabs/memory.c | 1714 ++++ drivers/misc/habanalabs/mmu.c | 604 ++ drivers/misc/habanalabs/sysfs.c | 690 ++ include/uapi/misc/habanalabs.h | 412 + 145 files changed, 99610 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/debugfs-driver-habanalabs create mode 100644 Documentation/ABI/testing/sysfs-driver-habanalabs create mode 100644 drivers/misc/habanalabs/Kconfig create mode 100644 drivers/misc/habanalabs/Makefile create mode 100644 drivers/misc/habanalabs/asid.c create mode 100644 drivers/misc/habanalabs/command_buffer.c create mode 100644 drivers/misc/habanalabs/command_submission.c create mode 100644 drivers/misc/habanalabs/context.c create mode 100644 drivers/misc/habanalabs/debugfs.c create mode 100644 drivers/misc/habanalabs/device.c create mode 100644 drivers/misc/habanalabs/goya/Makefile create mode 100644 drivers/misc/habanalabs/goya/goya.c create mode 100644 drivers/misc/habanalabs/goya/goyaP.h create mode 100644 drivers/misc/habanalabs/goya/goya_hwmgr.c create mode 100644 drivers/misc/habanalabs/goya/goya_security.c create mode 100644 drivers/misc/habanalabs/habanalabs.h create mode 100644 drivers/misc/habanalabs/habanalabs_drv.c create mode 100644 drivers/misc/habanalabs/habanalabs_ioctl.c create mode 100644 drivers/misc/habanalabs/hw_queue.c create mode 100644 drivers/misc/habanalabs/hwmon.c create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_ca53_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_if_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_mc_ch0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_mc_ch1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_misc_ch0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_misc_ch1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_2_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_3_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_4_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_macro_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_2_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_3_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_4_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/gic_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_blocks.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_masks.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ic_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme5_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme6_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mmu_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pci_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pcie_aux_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pcie_dbi_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_emmc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_global_conf_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_mme_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_pci_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_spi_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/stlb_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sync_mngr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_eml_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/goya.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_async_events.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_boot_if.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_packets.h create mode 100644 drivers/misc/habanalabs/include/habanalabs_device_if.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_0.h create mode 100644 drivers/misc/habanalabs/irq.c create mode 100644 drivers/misc/habanalabs/memory.c create mode 100644 drivers/misc/habanalabs/mmu.c create mode 100644 drivers/misc/habanalabs/sysfs.c create mode 100644 include/uapi/misc/habanalabs.hSignature · 1 line
2.17.1
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 01/15] habanalabs: add skeleton driver
In reply to Oded GabbayQuoted 124 lines · Oded Gabbay
This patch adds the habanalabs skeleton driver. The driver does nothing at this stage except very basic operations. It contains the minimal code to insmod and rmmod the driver and to create a
/dev/hlXfile per PCI device.Signed-off-by Oded Gabbay <[email protected]>--- drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/habanalabs/Kconfig | 22 ++ drivers/misc/habanalabs/Makefile | 7 + drivers/misc/habanalabs/device.c | 331 ++++++++++++++++ drivers/misc/habanalabs/habanalabs.h | 149 +++++++ drivers/misc/habanalabs/habanalabs_drv.c | 366 ++++++++++++++++++ .../habanalabs/include/habanalabs_device_if.h | 125 ++++++ 8 files changed, 1002 insertions(+) create mode 100644 drivers/misc/habanalabs/Kconfig create mode 100644 drivers/misc/habanalabs/Makefile create mode 100644 drivers/misc/habanalabs/device.c create mode 100644 drivers/misc/habanalabs/habanalabs.h create mode 100644 drivers/misc/habanalabs/habanalabs_drv.c create mode 100644 drivers/misc/habanalabs/include/habanalabs_device_if.hdrivers/misc/Kconfig +1
-0@@ -535,4 +535,5 @@ source "drivers/misc/echo/Kconfig" source "drivers/misc/cxl/Kconfig" source "drivers/misc/ocxl/Kconfig" source "drivers/misc/cardreader/Kconfig" +source "drivers/misc/habanalabs/Kconfig" endmenudrivers/misc/Makefile +1
-0@@ -59,3 +59,4 @@ obj-$(CONFIG_PCI_ENDPOINT_TEST) += pci_endpoint_test.o obj-$(CONFIG_OCXL) += ocxl/ obj-y += cardreader/ obj-$(CONFIG_PVPANIC) += pvpanic.o +obj-$(CONFIG_HABANA_AI) += habanalabs/drivers/misc/habanalabs/Kconfig new file +22
-0@@ -0,0 +1,22 @@ +# +# HabanaLabs AI accelerators driver +# + +config HABANA_AI + tristate "HabanaAI accelerators (habanalabs)" + depends on PCI + select FRAME_VECTOR + help + Enables PCIe card driver for Habana's AI Processors (AIP) that are + designed to accelerate Deep Learning inference and training workloads. + + The driver manages the PCIe devices and provides IOCTL interface for + the user to submit workloads to the devices. + + The user-space interface is described in + include/uapi/misc/habanalabs.h + + If unsure, say N. + + To compile this driver as a module, choose M here: the + module will be called habanalabs.drivers/misc/habanalabs/Makefile new file +7
-0@@ -0,0 +1,7 @@ +# +# Makefile for HabanaLabs AI accelerators driver +# + +obj-m := habanalabs.o + +habanalabs-y := habanalabs_drv.o device.odrivers/misc/habanalabs/device.c new file +35
-0@@ -0,0 +1,331 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/ + +#include "habanalabs.h" + +#include <linux/fs.h> +#include <linux/kthread.h> +#include <linux/sched/signal.h> + +static void hpriv_release (struct kref *ref) +{ +struct hl_fpriv *hpriv; +struct hl_device *hdev; + + hpriv = container_of(ref, struct hl_fpriv, refcount); + + hdev = hpriv->hdev; + +put_pid (hpriv->taskpid); + +kfree (hpriv); +} + +void hl_hpriv_get (struct hl_fpriv *hpriv) +{ +kref_get (&hpriv->refcount); +} + +void hl_hpriv_put (struct hl_fpriv *hpriv) +{ +kref_put (&hpriv->refcount, hpriv_release);
drivers/misc/habanalabs/device.c line 45
Quoted 10 lines
drivers/misc/habanalabs/device.c new file +10
-0+} + +/** +* hl_device_release - release function for habanalabs device +* +* @inode: pointer to inode structure +* @filp: pointer to file structure +* +* Called when process closes an habanalabs device +*/
It's nice to see docs coming along with the codei
I have some comments for the formatting.
kernel-doc won't be happy about missing return value descriptions, and although they are sometimes redundant or too obvious their absence makes 'make V=1 htmldocs' really noisy.
In general, it would be nice if you could link hanabnalabs driver kernel-doc somewhere in Documentation/ run 'make V=1 htmldocs'.
Quoted 78 lines
drivers/misc/habanalabs/device.c new file +78
-0+static int hl_device_release (struct inode *inode,struct file *filp) +{ +struct hl_fpriv *hpriv = filp->private_data; + + filp->private_data =NULL ; + +hl_hpriv_put (hpriv); + +return 0 ; +} + +static const struct file_operations hl_ops = { + .owner =THIS_MODULE , + .open = hl_device_open, + .release = hl_device_release +}; + +/** +* device_setup_cdev - setup cdev and device for habanalabs device +* +* @hdev: pointer to habanalabs device structure +* @hclass: pointer to the class object of the device +* @minor: minor number of the specific device +* @fpos : file operations to install for this device +* +* Create a cdev and a Linux device for habanalabs's device. Need to be +* called at the end of the habanalabs device initialization process, +* because this function exposes the device to the user +*/ +static int device_setup_cdev (struct hl_device *hdev,struct class *hclass, +int minor,const struct file_operations *fops) +{ +int err, devno =MKDEV (hdev->major, minor); +struct cdev *hdev_cdev = &hdev->cdev; +char name[8 ]; + +sprintf (name,"hl%d" , hdev->id); + +cdev_init (hdev_cdev, fops); + hdev_cdev->owner =THIS_MODULE ; + err =cdev_add (hdev_cdev, devno,1 ); +if (err) { +pr_err ("habanalabs: Failed to add char device %s" , name); + goto err_cdev_add; + } + + hdev->dev =device_create (hclass,NULL , devno,NULL ,"%s" , name); +if (IS_ERR (hdev->dev)) { +pr_err ("habanalabs: Failed to create device %s\n" , name); + err =PTR_ERR (hdev->dev); + goto err_device_create; + } + +dev_set_drvdata (hdev->dev, hdev); + +return 0 ; + +err_device_create: +cdev_del (hdev_cdev); +err_cdev_add: +return err; +} + +/** +* device_early_init - do some early initialization for the habanalabs device +* +* @hdev: pointer to habanalabs device structure +* +* Install the relevant function pointers and call the early_init function, +* if such a function exists +*/ +static int device_early_init (struct hl_device *hdev) +{ +switch (hdev->asic_type) { +case ASIC_GOYA : +sprintf (hdev->asic_name,"GOYA" ); +break ; +default :
drivers/misc/habanalabs/device.c line 133
Quoted 10 lines
drivers/misc/habanalabs/device.c new file +10
-0+dev_err (hdev->dev,"Unrecognized ASIC type %d\n" , + hdev->asic_type); +return -EINVAL ; + } + +return 0 ; +} + +/** +* device_early_fini - finalize all that was done in device_early_fini
^init
Quoted 5 lines
drivers/misc/habanalabs/device.c new file +5
-0+* +* @hdev: pointer to habanalabs device structure +* +*/ +static void device_early_fini (struct hl_device *hdev)
drivers/misc/habanalabs/device.c line 148
Quoted 10 lines
drivers/misc/habanalabs/device.c new file +10
-0+{ +} + +/** +* hl_device_suspend - initiate device suspend +* +* @hdev: pointer to habanalabs device structure +* +* Puts the hw in the suspend state (all asics). +* Returns 0 for success or an error on failure.
Should be Return: or Returns: for kernel-doc to understand it.
drivers/misc/habanalabs/device.c line 149
Quoted 1 line
drivers/misc/habanalabs/device.c new file +1
-0+* Called at driver suspend.
This probably should be marked as Context:
Quoted 10 lines
drivers/misc/habanalabs/device.c new file +10
-0+*/ +int hl_device_suspend (struct hl_device *hdev) +{ +pci_save_state (hdev->pdev); + +/* Shut down the device */ +pci_disable_device (hdev->pdev); +pci_set_power_state (hdev->pdev, PCI_D3hot); + +return 0 ;
drivers/misc/habanalabs/device.c line 169
Quoted 10 lines
drivers/misc/habanalabs/device.c new file +10
-0+} + +/** +* hl_device_resume - initiate device resume +* +* @hdev: pointer to habanalabs device structure +* +* Bring the hw back to operating state (all asics). +* Returns 0 for success or an error on failure. +* Called at driver resume.
Same comments as for the previous functions.
Quoted 48 lines
drivers/misc/habanalabs/device.c new file +48
-0+*/ +int hl_device_resume (struct hl_device *hdev) +{ +int rc; + +pci_set_power_state (hdev->pdev,PCI_D0 ); +pci_restore_state (hdev->pdev); + rc =pci_enable_device (hdev->pdev); +if (rc) { +dev_err (hdev->dev, +"Failed to enable PCI device in resume\n" ); +return rc; + } + +return 0 ; +} + +/** +* hl_device_init - main initialization function for habanalabs device +* +* @hdev: pointer to habanalabs device structure +* +* Allocate an id for the device, do early initialization and then call the +* ASIC specific initialization functions. Finally, create the cdev and the +* Linux device to expose it to the user +*/ +int hl_device_init (struct hl_device *hdev,struct class *hclass) +{ +int rc; + +/* Create device */ + rc =device_setup_cdev (hdev, hclass, hdev->id, &hl_ops); + +if (rc) + goto out_disabled; + +/* Initialize ASIC function pointers and perform early init */ + rc =device_early_init (hdev); +if (rc) + goto release_device; + +dev_notice (hdev->dev, +"Successfully added device to habanalabs driver\n" ); + +return 0 ; + +release_device: +device_destroy (hclass, hdev->dev->devt);
drivers/misc/habanalabs/device.c line 227
Quoted 10 lines
drivers/misc/habanalabs/device.c new file +10
-0+cdev_del (&hdev->cdev); +out_disabled: + hdev->disabled = true; +if (hdev->pdev) +dev_err (&hdev->pdev->dev, +"Failed to initialize hl%d. Device is NOT usable !!!\n" , + hdev->id); +else +pr_err ("habanalabs: Failed to initialize hl%d. Device is NOT usable !!!\n" , + hdev->id);
Maybe three exclamation marks would be too much?
Quoted 130 lines
drivers/misc/habanalabs/device.c new file +104
-0+ +return rc; +} + +/** +* hl_device_fini - main tear-down function for habanalabs device +* +* @hdev: pointer to habanalabs device structure +* +* Destroy the device, call ASIC fini functions and release the id +*/ +void hl_device_fini (struct hl_device *hdev) +{ +dev_info (hdev->dev,"Removing device\n" ); + +/* Mark device as disabled */ + hdev->disabled = true; + +device_early_fini (hdev); + +/* Hide device from user */ +device_destroy (hdev->dev->class, hdev->dev->devt); +cdev_del (&hdev->cdev); + +pr_info ("habanalabs: removed device successfully\n" ); +} + +/** +* hl_poll_timeout_memory - Periodically poll a host memory address +* until it is not zero or a timeout occurs +* @hdev: pointer to habanalabs device structure +* @addr: Address to poll +* @timeout_us: timeout in us +* @val: Variable to read the value into +* +* Returns 0 on success and -ETIMEDOUT upon a timeout. In either +* case, the last read value at @addr is stored in @val. Must not +* be called from atomic context if sleep_us or timeout_us are used. +* +* The function sleeps for 100us with timeout value of +* timeout_us +*/ +int hl_poll_timeout_memory (struct hl_device *hdev,u64 addr, +u32 timeout_us,u32 *val) +{ +/* +* pReturnVal is defined as volatile because it points to HOST memory, +* which is being written to by the device. Therefore, we can't use +* locks to synchronize it and it is not a memory-mapped register space +*/ +volatile u32 *pReturnVal = (volatile u32 *) addr; +ktime_t timeout =ktime_add_us (ktime_get (), timeout_us); + +might_sleep (); + +for (;;) { + *val = *pReturnVal; +if (*val) +break ; +if (ktime_compare (ktime_get (), timeout) >0 ) { + *val = *pReturnVal; +break ; + } +usleep_range ((100 >>2 ) +1 ,100 ); + } + +return (*val ?0 : -ETIMEDOUT ); +} + +/** +* hl_poll_timeout_devicememory - Periodically poll a device memory address +* until it is not zero or a timeout occurs +* @hdev: pointer to habanalabs device structure +* @addr: Device address to poll +* @timeout_us: timeout in us +* @val: Variable to read the value into +* +* Returns 0 on success and -ETIMEDOUT upon a timeout. In either +* case, the last read value at @addr is stored in @val. Must not +* be called from atomic context if sleep_us or timeout_us are used. +* +* The function sleeps for 100us with timeout value of +* timeout_us +*/ +int hl_poll_timeout_device_memory (struct hl_device *hdev,void __iomem *addr, +u32 timeout_us,u32 *val) +{ +ktime_t timeout =ktime_add_us (ktime_get (), timeout_us); + +might_sleep (); + +for (;;) { + *val =readl (addr); +if (*val) +break ; +if (ktime_compare (ktime_get (), timeout) >0 ) { + *val =readl (addr); +break ; + } +usleep_range ((100 >>2 ) +1 ,100 ); + } + +return (*val ?0 : -ETIMEDOUT ); +}drivers/misc/habanalabs/habanalabs.h new file +20
-0@@ -0,0 +1,149 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +*/ + +#ifndef HABANALABSP_H_ +#define HABANALABSP_H_ + +#include "include/habanalabs_device_if.h" + +#include <linux/pci.h> +#include <linux/types.h> +#include <linux/cdev.h> +#include <linux/interrupt.h> +#include <linux/iopoll.h> +#include <linux/dma-fence.h> +#include <linux/hashtable.h> +#include <linux/hwmon.h>
drivers/misc/habanalabs/habanalabs.h line 30
Quoted 10 lines
drivers/misc/habanalabs/habanalabs.h new file +10
-0+ +#define HL_NAME "habanalabs" + +struct hl_device ; + + + + + +
Too many blank lines, IMHO.
Quoted 167 lines
drivers/misc/habanalabs/habanalabs.h new file +119
-0+/* +* ASICs +*/ + +/** +* enum hl_asic_type - supported ASIC types. +* @ASIC_AUTO_DETECT: ASIC type will be automatically set. +* @ASIC_GOYA: Goya device. +* @ASIC_LAST: last ASIC type. +*/ +enum hl_asic_type { +ASIC_AUTO_DETECT , +ASIC_GOYA , +ASIC_LAST +}; + + + + + +/* +* FILE PRIVATE STRUCTURE +*/ + +/** +* struct hl_fpriv - process information stored in FD private data. +* @hdev: habanalabs device structure. +* @filp: pointer to the given file structure. +* @taskpid: current process ID. +* @refcount: number of related contexts. +*/ +struct hl_fpriv { +struct hl_device *hdev; +struct file *filp; +struct pid *taskpid; +struct kref refcount; +}; + + + + +/* +* DEVICES +*/ + +/* Theoretical limit only. A single host can only contain up to 4 or 8 PCIe +* x16 cards. In extereme cases, there are hosts that can accommodate 16 cards +*/ +#define HL_MAX_MINORS 256 + +/** +* struct hl_device - habanalabs device structure. +* @pdev: pointer to PCI device, can be NULL in case of simulator device. +* @cdev: related char device. +* @dev: realted kernel basic device structure. +* @asic_name: ASIC specific nmae. +* @asic_type: ASIC specific type. +* @major: habanalabs KMD major. +* @id: device minor. +* @disabled: is device disabled. +*/ +struct hl_device { +struct pci_dev *pdev; +struct cdev cdev; +struct device *dev; +char asic_name[16 ]; +enum hl_asic_type asic_type; +u32 major; +u16 id; +u8 disabled; +}; + +/* +* IOCTLs +*/ + +/** +* typedef hl_ioctl_t - typedef for ioctl function in the driver +* @hpriv: pointer to the FD's private data, which contains state of +* user process +* @data: pointer to the input/output arguments structure of the IOCTL +* +* Return: 0 for success, negative value for error +*/ +typedef int hl_ioctl_t (struct hl_fpriv *hpriv,void *data); + +/** +* struct hl_ioctl_desc - describes an IOCTL entry of the driver. +* @cmd: the IOCTL code as created by the kernel macros. +* @func: pointer to the driver's function that should be called for this IOCTL. +*/ +struct hl_ioctl_desc { +unsigned int cmd; +hl_ioctl_t *func; +}; + + + + + +/* +* Kernel module functions that can be accessed by entire module +*/ + +int hl_device_open (struct inode *inode,struct file *filp); +int create_hdev (struct hl_device **dev,struct pci_dev *pdev, +enum hl_asic_type asic_type,int minor); +void destroy_hdev (struct hl_device *hdev); +int hl_poll_timeout_memory (struct hl_device *hdev,u64 addr,u32 timeout_us, +u32 *val); +int hl_poll_timeout_device_memory (struct hl_device *hdev,void __iomem *addr, +u32 timeout_us,u32 *val); + +int hl_device_init (struct hl_device *hdev,struct class *hclass); +void hl_device_fini (struct hl_device *hdev); +int hl_device_suspend (struct hl_device *hdev); +int hl_device_resume (struct hl_device *hdev); + +#endif /* HABANALABSP_H_ */ drivers/misc/habanalabs/habanalabs_drv.c new file +42
-0@@ -0,0 +1,366 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +* Author: Oded Gabbay <[email protected]> +* +*/ + +#include "habanalabs.h" + +#include <linux/device.h> +#include <linux/module.h> +#include <linux/init.h> +#include <linux/kthread.h> + +#include <linux/fs.h> + +#define HL_DRIVER_AUTHOR "HabanaLabs Kernel Driver Team" + +#define HL_DRIVER_DESC "Driver for HabanaLabs's AI Accelerators" + +MODULE_AUTHOR (HL_DRIVER_AUTHOR ); +MODULE_DESCRIPTION (HL_DRIVER_DESC ); +MODULE_LICENSE ("GPL v2" ); + +static int hl_major; +static struct class *hl_class; +DEFINE_IDR (hl_devs_idr); +DEFINE_MUTEX (hl_devs_idr_lock); + +#define PCI_VENDOR_ID_HABANALABS 0x1da3 + +#define PCI_IDS_GOYA 0x0001 + +static struct pci_device_id ids[] = { + {PCI_DEVICE (PCI_VENDOR_ID_HABANALABS ,PCI_IDS_GOYA ), }, + {0 , } +}; +MODULE_DEVICE_TABLE (pci, ids); +
drivers/misc/habanalabs/habanalabs_drv.c line 52
Quoted 10 lines
drivers/misc/habanalabs/habanalabs_drv.c new file +10
-0+/** +* get_asic_type - translate device id to asic type +* +* @device: id of the PCI device +* @asic_type: pointer that will be filled by the asic type +* +* Translate device id to asic type. +* In case of unidentified device, return -1 +*/ +static int get_asic_type (u16 device,enum hl_asic_type *asic_type)
This can simply return the hl_asic_type, see also a comment in create_hdev(().
Quoted 81 lines
drivers/misc/habanalabs/habanalabs_drv.c new file +81
-0+{ +int rc =0 ; + +switch (device) { +case PCI_IDS_GOYA : + *asic_type =ASIC_GOYA ; +break ; +default : + *asic_type = rc =-1 ; +break ; + } + +return rc; +} + +/** +* hl_device_open - open function for habanalabs device +* +* @inode: pointer to inode structure +* @filp: pointer to file structure +* +* Called when process opens an habanalabs device. +*/ +int hl_device_open (struct inode *inode,struct file *filp) +{ +struct hl_device *hdev; +struct hl_fpriv *hpriv; + +mutex_lock (&hl_devs_idr_lock); + hdev =idr_find (&hl_devs_idr,iminor (inode)); +mutex_unlock (&hl_devs_idr_lock); + +if (!hdev) { +pr_err ("habanalabs: Couldn't find device %d:%d\n" , +imajor (inode),iminor (inode)); +return -ENXIO ; + } + + hpriv =kzalloc (sizeof (*hpriv),GFP_KERNEL ); +if (!hpriv) +return -ENOMEM ; + + hpriv->hdev = hdev; + filp->private_data = hpriv; + hpriv->filp = filp; +kref_init (&hpriv->refcount); +nonseekable_open (inode, filp); + + hpriv->taskpid =find_get_pid (current->pid); + +return 0 ; +} + +/** +* create_hdev - create habanalabs device instance +* +* @dev: will hold the pointer to the new habanalabs device structure +* @pdev: pointer to the pci device +* @asic_type: in case of simulator device, which device is it +* @minor: in case of simulator device, the minor of the device +* +* Allocate memory for habanalabs device and initialize basic fields +* Identify the ASIC type +* Allocate ID (minor) for the device (only for real devices) +*/ +int create_hdev (struct hl_device **dev,struct pci_dev *pdev, +enum hl_asic_type asic_type,int minor) +{ +struct hl_device *hdev; +int rc; + + *dev =NULL ; + + hdev =kzalloc (sizeof (*hdev),GFP_KERNEL ); +if (!hdev) { +if (pdev) +dev_err (&pdev->dev, +"Not enough memory for habanalabs device\n" ); +else +pr_err ("habanalabs: Not enough memory for device\n" ); +
drivers/misc/habanalabs/habanalabs_drv.c line 143
Quoted 10 lines
drivers/misc/habanalabs/habanalabs_drv.c new file +10
-0+return -ENOMEM ; + } + + hdev->major = hl_major; + + hdev->disabled = true; + hdev->pdev = pdev;/* can be NULL in case of simulator device */ + +if (asic_type ==ASIC_AUTO_DETECT ) { + rc =get_asic_type (pdev->device, &hdev->asic_type);
You can just make it
&hdev->asic_type = get_asic_type(pdev->device);
drivers/misc/habanalabs/habanalabs_drv.c line 151
Quoted 8 lines
drivers/misc/habanalabs/habanalabs_drv.c new file +8
-0+if (rc) { +dev_err (&pdev->dev,"Unsupported ASIC\n" ); + rc = -ENODEV ; + goto free_hdev; + } + }else { + hdev->asic_type = asic_type; + }
In the current version create_hdev() is always called with ASIC_AUTO_DETECT, what are the usecases for other types?
drivers/misc/habanalabs/habanalabs_drv.c line 159
Quoted 8 lines
drivers/misc/habanalabs/habanalabs_drv.c new file +8
-0+ +mutex_lock (&hl_devs_idr_lock); + +if (minor ==-1 ) { + rc =idr_alloc (&hl_devs_idr, hdev,0 ,HL_MAX_MINORS , +GFP_KERNEL ); + }else { +idr_replace (&hl_devs_idr, hdev, minor);
idr_replace can fail, can't it?
Quoted 341 lines
drivers/misc/habanalabs/habanalabs_drv.c new file +207
-0+ rc = minor; + } + +mutex_unlock (&hl_devs_idr_lock); + +if (rc <0 ) { +if (rc == -ENOSPC ) { +pr_err ("habanalabs: too many devices in the system\n" ); + rc = -EBUSY ; + } + goto free_hdev; + } + + hdev->id = rc; + + *dev = hdev; + +return 0 ; + +free_hdev: +kfree (hdev); +return rc; +} + +/** +* destroy_hdev - destroy habanalabs device instance +* +* @dev: pointer to the habanalabs device structure +* +*/ +void destroy_hdev (struct hl_device *hdev) +{ +/* Remove device from the device list */ +mutex_lock (&hl_devs_idr_lock); +idr_remove (&hl_devs_idr, hdev->id); +mutex_unlock (&hl_devs_idr_lock); + +kfree (hdev); +} + +static int hl_pmops_suspend (struct device *dev) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct hl_device *hdev =pci_get_drvdata (pdev); + +pr_debug ("habanalabs: Going to suspend PCI device\n" ); + +if (!hdev) { +pr_err ("habanalabs: device pointer is NULL in suspend\n" ); +return 0 ; + } + +return hl_device_suspend (hdev); +} + +static int hl_pmops_resume (struct device *dev) +{ +struct pci_dev *pdev =to_pci_dev (dev); +struct hl_device *hdev =pci_get_drvdata (pdev); + +pr_debug ("habanalabs: Going to resume PCI device\n" ); + +if (!hdev) { +pr_err ("habanalabs: device pointer is NULL in resume\n" ); +return 0 ; + } + +return hl_device_resume (hdev); +} + +/** +* hl_pci_probe - probe PCI habanalabs devices +* +* @pdev: pointer to pci device +* @id: pointer to pci device id structure +* +* Standard PCI probe function for habanalabs device. +* Create a new habanalabs device and initialize it according to the +* device's type +*/ +static int hl_pci_probe (struct pci_dev *pdev, +const struct pci_device_id *id) +{ +struct hl_device *hdev; +int rc; + +dev_info (&pdev->dev,HL_NAME +" device found [%04x:%04x] (rev %x)\n" , + (int )pdev->vendor, (int )pdev->device, (int )pdev->revision); + + rc =create_hdev (&hdev, pdev,ASIC_AUTO_DETECT ,-1 ); +if (rc) +return rc; + +pci_set_drvdata (pdev, hdev); + + rc =hl_device_init (hdev, hl_class); +if (rc) { +dev_err (&pdev->dev,"Fatal error during habanalabs device init\n" ); + rc = -ENODEV ; + goto disable_device; + } + +return 0 ; + +disable_device: +pci_set_drvdata (pdev,NULL ); +destroy_hdev (hdev); + +return rc; +} + +/** +* hl_pci_remove - remove PCI habanalabs devices +* +* @pdev: pointer to pci device +* +* Standard PCI remove function for habanalabs device +*/ +static void hl_pci_remove (struct pci_dev *pdev) +{ +struct hl_device *hdev; + + hdev =pci_get_drvdata (pdev); +if (!hdev) +return ; + +hl_device_fini (hdev); +pci_set_drvdata (pdev,NULL ); + +destroy_hdev (hdev); +} + +static const struct dev_pm_ops hl_pm_ops = { + .suspend = hl_pmops_suspend, + .resume = hl_pmops_resume, +}; + +static struct pci_driver hl_pci_driver = { + .name =HL_NAME , + .id_table = ids, + .probe = hl_pci_probe, + .remove = hl_pci_remove, + .driver.pm = &hl_pm_ops, +}; + +/** +* hl_init - Initialize the habanalabs kernel driver +* +*/ +static int __init hl_init (void ) +{ +int rc; +dev_t dev; + +pr_info ("habanalabs: loading driver\n" ); + + rc =alloc_chrdev_region (&dev,0 ,HL_MAX_MINORS ,HL_NAME ); +if (rc <0 ) { +pr_err ("habanalabs: unable to get major\n" ); +return rc; + } + + hl_major =MAJOR (dev); + + hl_class =class_create (THIS_MODULE ,HL_NAME ); +if (IS_ERR (hl_class)) { +pr_err ("habanalabs: failed to allocate class\n" ); + rc =PTR_ERR (hl_class); + goto remove_major; + } + + rc =pci_register_driver (&hl_pci_driver); +if (rc) { +pr_err ("habanalabs: failed to register pci device\n" ); + goto remove_class; + } + +pr_debug ("habanalabs: driver loaded\n" ); + +return 0 ; + +remove_class: +class_destroy (hl_class); +remove_major: +unregister_chrdev_region (MKDEV (hl_major,0 ),HL_MAX_MINORS ); +return rc; +} + +/** +* hl_exit - Release all resources of the habanalabs kernel driver +* +*/ +static void __exit hl_exit(void) +{ +pci_unregister_driver (&hl_pci_driver); + +class_destroy (hl_class); +unregister_chrdev_region (MKDEV (hl_major,0 ),HL_MAX_MINORS ); + +idr_destroy (&hl_devs_idr); + +pr_debug ("habanalabs: driver removed\n" ); +} + +module_init (hl_init); +module_exit (hl_exit);drivers/misc/habanalabs/include/habanalabs_device_if.h new file +125
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +*/ + +#ifndef HABANALABS_DEVICE_IF_H +#define HABANALABS_DEVICE_IF_H + +#include <linux/types.h> + +/* +* PRIMARY QUEUE +*/ + +struct hl_bd { +__u64 ptr; +__u32 len; +union { +struct { +__u32 repeat:16 ; +__u32 res1:8 ; +__u32 repeat_valid:1 ; +__u32 res2:7 ; + }; +__u32 ctl; + }; +}; + +#define HL_BD_SIZE sizeof(struct hl_bd) + +/* +* BD_CTL_REPEAT_VALID tells the CP whether the repeat field in the BD CTL is +* valid. 1 means the repeat field is valid, 0 means not-valid, +* i.e. repeat == 1 +*/ +#define BD_CTL_REPEAT_VALID_SHIFT 24 +#define BD_CTL_REPEAT_VALID_MASK 0x01000000 + +#define BD_CTL_SHADOW_INDEX_SHIFT 0 +#define BD_CTL_SHADOW_INDEX_MASK 0x00000FFF + +/* +* COMPLETION QUEUE +*/ + +struct hl_cq_entry { +__u32 data; +}; + +#define HL_CQ_ENTRY_SIZE sizeof(struct hl_cq_entry) + +#define CQ_ENTRY_READY_SHIFT 31 +#define CQ_ENTRY_READY_MASK 0x80000000 + +#define CQ_ENTRY_SHADOW_INDEX_VALID_SHIFT 30 +#define CQ_ENTRY_SHADOW_INDEX_VALID_MASK 0x40000000 + +#define CQ_ENTRY_SHADOW_INDEX_SHIFT BD_CTL_SHADOW_INDEX_SHIFT +#define CQ_ENTRY_SHADOW_INDEX_MASK BD_CTL_SHADOW_INDEX_MASK + +/* +* EVENT QUEUE +*/ + +struct hl_eq_header { +__u32 reserved; +union { +struct { +__u32 ctx_id :10 ; + __u32:6; +__u32 opcode :10 ; + __u32:5; +__u32 ready :1 ; + }; +__u32 ctl; + }; +}; + +struct hl_eq_entry { +struct hl_eq_header hdr; +__u64 data[7 ]; +}; + +#define HL_EQ_ENTRY_SIZE sizeof(struct hl_eq_entry) + +#define EQ_CTL_READY_SHIFT 31 +#define EQ_CTL_READY_MASK 0x80000000 + +#define EQ_CTL_EVENT_TYPE_SHIFT 16 +#define EQ_CTL_EVENT_TYPE_MASK 0x03FF0000 + +enum pq_init_status { +PQ_INIT_STATUS_NA =0 , +PQ_INIT_STATUS_READY_FOR_CP , +PQ_INIT_STATUS_READY_FOR_HOST +}; + +/* +* ArmCP info +*/ + +#define VERSION_MAX_LEN 128 +#define ARMCP_MAX_SENSORS 128 + +struct armcp_sensor { +__u32 type; +__u32 flags; +}; + +/* must be aligned to 4 bytes */ +struct armcp_info { +struct armcp_sensor sensors[ARMCP_MAX_SENSORS ]; +__u8 kernel_version[VERSION_MAX_LEN ]; +__u32 reserved[3 ]; +__u32 cpld_version; +__u32 infineon_version; +__u8 fuse_version[VERSION_MAX_LEN ]; +__u8 thermal_version[VERSION_MAX_LEN ]; +__u8 armcp_version[VERSION_MAX_LEN ]; +__u64 dram_size; +}; + +#endif /* HABANALABS_DEVICE_IF_H */ Signature · 1 line
2.17.1
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 03/15] habanalabs: add basic Goya support
In reply to Oded GabbayQuoted 313 lines · Oded Gabbay
This patch adds a basic support for the Goya device. The code initializes the device's PCI controller and PCI bars. It also initializes various S/W structures and adds some basic helper functions.
Signed-off-by Oded Gabbay <[email protected]>--- drivers/misc/habanalabs/Makefile | 5 +- drivers/misc/habanalabs/device.c | 71 +++ drivers/misc/habanalabs/goya/Makefile | 3 + drivers/misc/habanalabs/goya/goya.c | 633 ++++++++++++++++++++ drivers/misc/habanalabs/goya/goyaP.h | 125 ++++ drivers/misc/habanalabs/habanalabs.h | 131 ++++ drivers/misc/habanalabs/habanalabs_drv.c | 3 + drivers/misc/habanalabs/include/goya/goya.h | 115 ++++ 8 files changed, 1085 insertions(+), 1 deletion(-) create mode 100644 drivers/misc/habanalabs/goya/Makefile create mode 100644 drivers/misc/habanalabs/goya/goya.c create mode 100644 drivers/misc/habanalabs/goya/goyaP.h create mode 100644 drivers/misc/habanalabs/include/goya/goya.hdrivers/misc/habanalabs/Makefile +4
-1@@ -4,4 +4,7 @@ obj-m := habanalabs.o -habanalabs-y := habanalabs_drv.o device.o +habanalabs-y := habanalabs_drv.o device.o + +include $(src)/goya/Makefile +habanalabs-y += $(HL_GOYA_FILES)drivers/misc/habanalabs/device.c +71
-0@@ -116,8 +116,11 @@ static int device_setup_cdev(struct hl_device *hdev, struct class *hclass,*/ static int device_early_init (struct hl_device *hdev) { +int rc; +switch (hdev->asic_type) {case ASIC_GOYA : +goya_set_asic_funcs (hdev);sprintf (hdev->asic_name,"GOYA" );break ;default :@@ -126,6 +129,10 @@ static int device_early_init(struct hl_device *hdev)return -EINVAL ; } + rc = hdev->asic_funcs->early_init (hdev); +if (rc) +return rc; +return 0 ; }@@ -137,6 +144,10 @@ static int device_early_init(struct hl_device *hdev)*/ static void device_early_fini (struct hl_device *hdev) { + +if (hdev->asic_funcs->early_fini) + hdev->asic_funcs->early_fini (hdev); + }/** @@ -150,8 +161,15 @@ static void device_early_fini(struct hl_device *hdev)*/ int hl_device_suspend (struct hl_device *hdev) { +int rc; +pci_save_state (hdev->pdev); + rc = hdev->asic_funcs->suspend (hdev); +if (rc) +dev_err (hdev->dev, +"Failed to disable PCI access of device CPU\n" ); +/* Shut down the device */ pci_disable_device (hdev->pdev);pci_set_power_state (hdev->pdev, PCI_D3hot);@@ -181,6 +199,13 @@ int hl_device_resume(struct hl_device *hdev)return rc; } + rc = hdev->asic_funcs->resume (hdev); +if (rc) { +dev_err (hdev->dev, +"Failed to enable PCI access from device CPU\n" ); +return rc; + } +return 0 ; }@@ -208,11 +233,21 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)if (rc) goto release_device; +/* +* Start calling ASIC initialization. First S/W then H/W and finally +* late init +*/ + rc = hdev->asic_funcs->sw_init (hdev); +if (rc) + goto early_fini; +dev_notice (hdev->dev,"Successfully added device to habanalabs driver\n" );return 0 ; +early_fini: +device_early_fini (hdev); release_device:device_destroy (hclass, hdev->dev->devt);cdev_del (&hdev->cdev);@@ -243,6 +278,9 @@ void hl_device_fini(struct hl_device *hdev)/* Mark device as disabled */ hdev->disabled = true; +/* Call ASIC S/W finalize function */ + hdev->asic_funcs->sw_fini (hdev); +device_early_fini (hdev);/* Hide device from user */ @@ -329,3 +367,36 @@ int hl_poll_timeout_device_memory(struct hl_device *hdev, void __iomem *addr,return (*val ?0 : -ETIMEDOUT ); } + +/* +* MMIO register access helper functions. +*/ + +/** +* hl_rreg - Read an MMIO register +* +* @hdev: pointer to habanalabs device structure +* @reg: MMIO register offset (in bytes) +* +* Returns the value of the MMIO register we are asked to read +* +*/ +inline u32 hl_rreg (struct hl_device *hdev,u32 reg) +{ +return readl (hdev->rmmio + reg); +} + +/** +* hl_wreg - Write to an MMIO register +* +* @hdev: pointer to habanalabs device structure +* @reg: MMIO register offset (in bytes) +* @val: 32-bit value +* +* Writes the 32-bit value into the MMIO register +* +*/ +inline void hl_wreg (struct hl_device *hdev,u32 reg,u32 val) +{ +writel (val, hdev->rmmio + reg); +}drivers/misc/habanalabs/goya/Makefile new file +3
-0@@ -0,0 +1,3 @@ +subdir-ccflags-y += -I$(src) + +HL_GOYA_FILES := goya/goya.odrivers/misc/habanalabs/goya/goya.c new file +126
-0@@ -0,0 +1,633 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/ + +#include "goyaP.h" +#include "include/goya/asic_reg/goya_masks.h" + +#include <linux/fs.h> +#include <linux/delay.h> +#include <linux/vmalloc.h> +#include <linux/sched.h> +#include <linux/genalloc.h> +#include <linux/sysfs.h> +#include <linux/kfifo.h> +#include <linux/dma-mapping.h> +#include <linux/firmware.h> +#include <linux/log2.h> +#include <linux/hwmon.h> +#include <linux/string.h> +#include <linux/io.h> + +/* +* GOYA security scheme: +* +* 1. Host is protected by: +* - Range registers (When MMU is enabled, DMA RR does NOT protect host) +* - MMU +* +* 2. DRAM is protected by: +* - Range registers (protect the first 512MB) +* - MMU (isolation between users) +* +* 3. Configuration is protected by: +* - Range registers +* - Protection bits +* +* When MMU is disabled: +* +* QMAN DMA: PQ, CQ, CP, DMA are secured. +* PQ, CB and the data are on the host. +* +* QMAN TPC/MME: +* PQ, CQ and CP are not secured. +* PQ, CB and the data are on the SRAM/DRAM. +* +* Since QMAN DMA is secured, KMD is parsing the DMA CB: +* - KMD checks DMA pointer +* - WREG, MSG_PROT are not allowed. +* - MSG_LONG/SHORT are allowed. +* +* A read/write transaction by the QMAN to a protected area will succeed if +* and only if the QMAN's CP is secured and MSG_PROT is used +* +* +* When MMU is enabled: +* +* QMAN DMA: PQ, CQ and CP are secured. +* MMU is set to bypass on the Secure props register of the QMAN. +* The reasons we don't enable MMU for PQ, CQ and CP are: +* - PQ entry is in kernel address space and KMD doesn't map it. +* - CP writes to MSIX register and to kernel address space (completion +* queue). +* +* DMA is not secured but because CP is secured, KMD still needs to parse the +* CB, but doesn't need to check the DMA addresses. +* +* For QMAN DMA 0, DMA is also secured because only KMD uses this DMA and KMD +* doesn't map memory in MMU. +* +* QMAN TPC/MME: PQ, CQ and CP aren't secured (no change from MMU disabled mode) +* +* DMA RR does NOT protect host because DMA is not secured +* +*/ + +#define GOYA_MMU_REGS_NUM 61 + +#define GOYA_DMA_POOL_BLK_SIZE 0x100/* 256 bytes */ + +#define GOYA_RESET_TIMEOUT_MSEC 500/* 500ms */ +#define GOYA_PLDM_RESET_TIMEOUT_MSEC 20000/* 20s */ +#define GOYA_RESET_WAIT_MSEC 1/* 1ms */ +#define GOYA_CPU_RESET_WAIT_MSEC 100/* 100ms */ +#define GOYA_PLDM_RESET_WAIT_MSEC 1000/* 1s */ +#define GOYA_CPU_TIMEOUT_USEC 10000000/* 10s */ +#define GOYA_TEST_QUEUE_WAIT_USEC 100000/* 100ms */ + +#define GOYA_QMAN0_FENCE_VAL 0xD169B243 + +#define GOYA_MAX_INITIATORS 20 + +static void goya_get_fixed_properties (struct hl_device *hdev) +{ +struct asic_fixed_properties *prop = &hdev->asic_prop; + + prop->completion_queues_count =NUMBER_OF_CMPLT_QUEUES ; + + prop->dram_base_address =DRAM_PHYS_BASE ; + prop->dram_size =DRAM_PHYS_DEFAULT_SIZE ; + prop->dram_end_address = prop->dram_base_address + prop->dram_size; + prop->dram_user_base_address =DRAM_BASE_ADDR_USER ; + + prop->sram_base_address =SRAM_BASE_ADDR ; + prop->sram_size =SRAM_SIZE ; + prop->sram_end_address = prop->sram_base_address + prop->sram_size; + prop->sram_user_base_address = prop->sram_base_address + +SRAM_USER_BASE_OFFSET ; + + prop->host_phys_base_address =HOST_PHYS_BASE ; + prop->va_space_host_start_address =VA_HOST_SPACE_START ; + prop->va_space_host_end_address =VA_HOST_SPACE_END ; + prop->va_space_dram_start_address =VA_DDR_SPACE_START ; + prop->va_space_dram_end_address =VA_DDR_SPACE_END ; + prop->cfg_size =CFG_SIZE ; + prop->max_asid =MAX_ASID ; + prop->tpc_enabled_mask =TPC_ENABLED_MASK ; + + prop->high_pll =PLL_HIGH_DEFAULT ; +} + +/** +* goya_pci_bars_map - Map PCI BARS of Goya device +*
drivers/misc/habanalabs/goya/goya.c line 136
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+* @hdev: pointer to hl_device structure +* +* Request PCI regions and map them to kernel virtual addresses. +* Returns 0 on success +* +*/ +int goya_pci_bars_map (struct hl_device *hdev) +{ +struct pci_dev *pdev = hdev->pdev; +int rc;
You could just init rc= -ENODEV here and avoid the hassle below.
Quoted 93 lines
drivers/misc/habanalabs/goya/goya.c new file +93
-0+ + rc =pci_request_regions (pdev,HL_NAME ); +if (rc) { +dev_err (hdev->dev,"Cannot obtain PCI resources\n" ); +return rc; + } + + hdev->pcie_bar[SRAM_CFG_BAR_ID ] = +pci_ioremap_bar (pdev,SRAM_CFG_BAR_ID ); +if (!hdev->pcie_bar[SRAM_CFG_BAR_ID ]) { +dev_err (hdev->dev,"pci_ioremap_bar failed for CFG\n" ); + rc = -ENODEV ; + goto err_release_regions; + } + + hdev->pcie_bar[MSIX_BAR_ID ] =pci_ioremap_bar (pdev,MSIX_BAR_ID ); +if (!hdev->pcie_bar[MSIX_BAR_ID ]) { +dev_err (hdev->dev,"pci_ioremap_bar failed for MSIX\n" ); + rc = -ENODEV ; + goto err_unmap_sram_cfg; + } + + hdev->pcie_bar[DDR_BAR_ID ] =pci_ioremap_wc_bar (pdev,DDR_BAR_ID ); +if (!hdev->pcie_bar[DDR_BAR_ID ]) { +dev_err (hdev->dev,"pci_ioremap_bar failed for DDR\n" ); + rc = -ENODEV ; + goto err_unmap_msix; + } + + hdev->rmmio = hdev->pcie_bar[SRAM_CFG_BAR_ID ] + + (CFG_BASE -SRAM_BASE_ADDR ); + +return 0 ; + +err_unmap_msix: +iounmap (hdev->pcie_bar[MSIX_BAR_ID ]); +err_unmap_sram_cfg: +iounmap (hdev->pcie_bar[SRAM_CFG_BAR_ID ]); +err_release_regions: +pci_release_regions (pdev); + +return rc; +} + +/** +* goya_pci_bars_unmap - Unmap PCI BARS of Goya device +* +* @hdev: pointer to hl_device structure +* +* Release all PCI BARS and unmap their virtual addresses +* +*/ +static void goya_pci_bars_unmap (struct hl_device *hdev) +{ +struct pci_dev *pdev = hdev->pdev; + +iounmap (hdev->pcie_bar[DDR_BAR_ID ]); +iounmap (hdev->pcie_bar[MSIX_BAR_ID ]); +iounmap (hdev->pcie_bar[SRAM_CFG_BAR_ID ]); +pci_release_regions (pdev); +} + +/** +* goya_elbi_write - Write through the ELBI interface +* +* @hdev: pointer to hl_device structure +* +* return 0 on success, -1 on failure +* +*/ +static int goya_elbi_write (struct hl_device *hdev,u64 addr,u32 data) +{ +struct pci_dev *pdev = hdev->pdev; +ktime_t timeout; +u32 val; + +/* Clear previous status */ +pci_write_config_dword (pdev, mmPCI_CONFIG_ELBI_STS,0 ); + +pci_write_config_dword (pdev, mmPCI_CONFIG_ELBI_ADDR, (u32 ) addr); +pci_write_config_dword (pdev, mmPCI_CONFIG_ELBI_DATA, data); +pci_write_config_dword (pdev, mmPCI_CONFIG_ELBI_CTRL, +PCI_CONFIG_ELBI_CTRL_WRITE ); + + timeout =ktime_add_ms (ktime_get (),10 ); +for (;;) { +pci_read_config_dword (pdev, mmPCI_CONFIG_ELBI_STS, &val); +if (val &PCI_CONFIG_ELBI_STS_MASK ) +break ; +if (ktime_compare (ktime_get (), timeout) >0 ) { +pci_read_config_dword (pdev, mmPCI_CONFIG_ELBI_STS, + &val); +break ;
drivers/misc/habanalabs/goya/goya.c line 239
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+ } +usleep_range (300 ,500 ); + } + +if ((val &PCI_CONFIG_ELBI_STS_MASK ) ==PCI_CONFIG_ELBI_STS_DONE ) +return 0 ; + +if (val &PCI_CONFIG_ELBI_STS_ERR ) { +dev_err (hdev->dev,"Error writing to ELBI\n" );o + return -1;
Please change -1 to an error code, say -EIO...
Quoted 16 lines
drivers/misc/habanalabs/goya/goya.c new file +16
-0+ } + +if (!(val &PCI_CONFIG_ELBI_STS_MASK )) { +dev_err (hdev->dev,"ELBI write didn't finish in time\n" ); +return -1 ; + } + +dev_err (hdev->dev,"ELBI write has undefined bits in status\n" ); +return -1 ; +} + +/** +* goya_iatu_write - iatu write routine +* +* @hdev: pointer to hl_device structure +*
drivers/misc/habanalabs/goya/goya.c line 265
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+*/ +static int goya_iatu_write (struct hl_device *hdev,u32 addr,u32 data) +{ +u32 dbi_offset; +int rc; + + dbi_offset = addr &0xFFF ; + + rc =goya_elbi_write (hdev,CFG_BASE + mmPCIE_AUX_DBI,0x00300000 ); + rc |=goya_elbi_write (hdev, mmPCIE_DBI_BASE + dbi_offset, data);
hmm, error code in goya_elbi_write probably won't work... Any reason to try the second write if the first failed?
Quoted 39 lines
drivers/misc/habanalabs/goya/goya.c new file +39
-0+ +return rc; +} + +void goya_reset_link_through_bridge (struct hl_device *hdev) +{ +struct pci_dev *pdev = hdev->pdev; +struct pci_dev *parent_port; +u16 val; + + parent_port = pdev->bus->self; +pci_read_config_word (parent_port,PCI_BRIDGE_CONTROL , &val); + val |=PCI_BRIDGE_CTL_BUS_RESET ; +pci_write_config_word (parent_port,PCI_BRIDGE_CONTROL , val); +ssleep (1 ); + + val &= ~(PCI_BRIDGE_CTL_BUS_RESET ); +pci_write_config_word (parent_port,PCI_BRIDGE_CONTROL , val); +ssleep (3 ); +} + +/** +* goya_set_ddr_bar_base - set DDR bar to map specific device address +* +* @hdev: pointer to hl_device structure +* @addr: address in DDR. Must be aligned to DDR bar size +* +* This function configures the iATU so that the DDR bar will start at the +* specified addr. +* +*/ +static int goya_set_ddr_bar_base (struct hl_device *hdev,u64 addr) +{ +struct goya_device *goya = hdev->asic_specific; +int rc; + +if ((goya) && (goya->ddr_bar_cur_addr == addr)) +return 0 ; +
drivers/misc/habanalabs/goya/goya.c line 314
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+/* Inbound Region 1 - Bar 4 - Point to DDR */ + rc =goya_iatu_write (hdev,0x314 ,lower_32_bits (addr)); + rc |=goya_iatu_write (hdev,0x318 ,upper_32_bits (addr)); + rc |=goya_iatu_write (hdev,0x300 ,0 ); +/* Enable + Bar match + match enable + Bar 4 */ + rc |=goya_iatu_write (hdev,0x304 ,0xC0080400 ); + +/* Return the DBI window to the default location */ + rc |=goya_elbi_write (hdev,CFG_BASE + mmPCIE_AUX_DBI,0 ); + rc |=goya_elbi_write (hdev,CFG_BASE + mmPCIE_AUX_DBI_32,0 );
And here as well.
drivers/misc/habanalabs/goya/goya.c line 319
Quoted 5 lines
drivers/misc/habanalabs/goya/goya.c new file +5
-0+ +if (rc) { +dev_err (hdev->dev,"failed to map DDR bar to 0x%08llx\n" , addr); +return rc; + }
I believe that at least here you'd want to return an error code.
Quoted 38 lines
drivers/misc/habanalabs/goya/goya.c new file +38
-0+ +if (goya) + goya->ddr_bar_cur_addr = addr; + +return 0 ; +} + +/** +* goya_init_iatu - Initialize the iATU unit inside the PCI controller +* +* @hdev: pointer to hl_device structure +* +* This is needed in case the firmware doesn't initialize the iATU +* +*/ +static int goya_init_iatu (struct hl_device *hdev) +{ +int rc; + +/* Inbound Region 0 - Bar 0 - Point to SRAM_BASE_ADDR */ + rc =goya_iatu_write (hdev,0x114 ,lower_32_bits (SRAM_BASE_ADDR )); + rc |=goya_iatu_write (hdev,0x118 ,upper_32_bits (SRAM_BASE_ADDR )); + rc |=goya_iatu_write (hdev,0x100 ,0 ); +/* Enable + Bar match + match enable */ + rc |=goya_iatu_write (hdev,0x104 ,0xC0080000 ); + +/* Inbound Region 1 - Bar 4 - Point to DDR */ + rc |=goya_set_ddr_bar_base (hdev,DRAM_PHYS_BASE ); + +/* Outbound Region 0 - Point to Host */ + rc |=goya_iatu_write (hdev,0x008 ,lower_32_bits (HOST_PHYS_BASE )); + rc |=goya_iatu_write (hdev,0x00C ,upper_32_bits (HOST_PHYS_BASE )); + rc |=goya_iatu_write (hdev,0x010 , +lower_32_bits (HOST_PHYS_BASE +HOST_PHYS_SIZE -1 )); + rc |=goya_iatu_write (hdev,0x014 ,0 ); + rc |=goya_iatu_write (hdev,0x018 ,0 ); + rc |=goya_iatu_write (hdev,0x020 , +upper_32_bits (HOST_PHYS_BASE +HOST_PHYS_SIZE -1 ));
drivers/misc/habanalabs/goya/goya.c line 367
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+/* Increase region size */ + rc |=goya_iatu_write (hdev,0x000 ,0x00002000 ); +/* Enable */ + rc |=goya_iatu_write (hdev,0x004 ,0x80000000 ); + +/* Return the DBI window to the default location */ + rc |=goya_elbi_write (hdev,CFG_BASE + mmPCIE_AUX_DBI,0 ); + rc |=goya_elbi_write (hdev,CFG_BASE + mmPCIE_AUX_DBI_32,0 ); + +return rc;
Ditto
Quoted 124 lines
drivers/misc/habanalabs/goya/goya.c new file +124
-0+} + +/** +* goya_early_init - GOYA early initialization code +* +* @hdev: pointer to hl_device structure +* +* Verify PCI bars +* Set DMA masks +* PCI controller initialization +* Map PCI bars +* +*/ +static int goya_early_init (struct hl_device *hdev) +{ +struct asic_fixed_properties *prop = &hdev->asic_prop; +struct pci_dev *pdev = hdev->pdev; +u32 val; +int rc; + +goya_get_fixed_properties (hdev); + +/* Check BAR sizes */ +if (pci_resource_len (pdev,SRAM_CFG_BAR_ID ) !=CFG_BAR_SIZE ) { +dev_err (hdev->dev, +"Not " HL_NAME "? BAR %d size %llu, expecting %llu\n" , +SRAM_CFG_BAR_ID , +pci_resource_len (pdev,SRAM_CFG_BAR_ID ), +CFG_BAR_SIZE ); +return -ENODEV ; + } + +if (pci_resource_len (pdev,MSIX_BAR_ID ) !=MSIX_BAR_SIZE ) { +dev_err (hdev->dev, +"Not " HL_NAME "? BAR %d size %llu, expecting %llu\n" , +MSIX_BAR_ID ,pci_resource_len (pdev,MSIX_BAR_ID ), +MSIX_BAR_SIZE ); +return -ENODEV ; + } + + prop->dram_pci_bar_size =pci_resource_len (pdev,DDR_BAR_ID ); + +/* set DMA mask for GOYA */ + rc =pci_set_dma_mask (pdev,DMA_BIT_MASK (39 )); +if (rc) { +dev_warn (hdev->dev,"Unable to set pci dma mask to 39 bits\n" ); + rc =pci_set_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (rc) { +dev_err (hdev->dev, +"Unable to set pci dma mask to 32 bits\n" ); +return rc; + } + } + + rc =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (39 )); +if (rc) { +dev_warn (hdev->dev, +"Unable to set pci consistent dma mask to 39 bits\n" ); + rc =pci_set_consistent_dma_mask (pdev,DMA_BIT_MASK (32 )); +if (rc) { +dev_err (hdev->dev, +"Unable to set pci consistent dma mask to 32 bits\n" ); +return rc; + } + } + +if (hdev->reset_pcilink) +goya_reset_link_through_bridge (hdev); + + rc =pci_enable_device_mem (pdev); +if (rc) { +dev_err (hdev->dev,"can't enable PCI device\n" ); +return rc; + } + +pci_set_master (pdev); + + rc =goya_init_iatu (hdev); +if (rc) { +dev_err (hdev->dev,"Failed to initialize iATU\n" ); + goto disable_device; + } + + rc =goya_pci_bars_map (hdev); +if (rc) { +dev_err (hdev->dev,"Failed to initialize PCI BARS\n" ); + goto disable_device; + } + + val =RREG32 (mmPSOC_GLOBAL_CONF_BOOT_STRAP_PINS); +if (val &PSOC_GLOBAL_CONF_BOOT_STRAP_PINS_SRIOV_EN_MASK ) +dev_warn (hdev->dev, +"PCI strap is not configured correctly, PCI bus errors may occur\n" ); + +return 0 ; + +disable_device: +pci_clear_master (pdev); +pci_disable_device (pdev); + +return rc; +} + +/** +* goya_early_fini - GOYA early finalization code +* +* @hdev: pointer to hl_device structure +* +* Unmap PCI bars +* +*/ +int goya_early_fini (struct hl_device *hdev) +{ +goya_pci_bars_unmap (hdev); + +pci_clear_master (hdev->pdev); +pci_disable_device (hdev->pdev); + +return 0 ; +} + +/** +* goya_sw_init - Goya software initialization code +*
drivers/misc/habanalabs/goya/goya.c line 501
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+* @hdev: pointer to hl_device structure +* +*/ +static int goya_sw_init (struct hl_device *hdev) +{ +struct goya_device *goya; +int rc; + +/* Allocate device structure */ + goya =kzalloc (sizeof (*goya),GFP_KERNEL );
Consider using devm_k[mz]alloc() for memory allocations throughout the driver. I didn't check all the spots where it can be applicable.
Quoted 25 lines
drivers/misc/habanalabs/goya/goya.c new file +25
-0+if (!goya) +return -ENOMEM ; + +/* according to goya_init_iatu */ + goya->ddr_bar_cur_addr =DRAM_PHYS_BASE ; + hdev->asic_specific = goya; + +/* Create DMA pool for small allocations */ + hdev->dma_pool =dma_pool_create (dev_name (hdev->dev), + &hdev->pdev->dev,GOYA_DMA_POOL_BLK_SIZE ,8 ,0 ); +if (!hdev->dma_pool) { +dev_err (hdev->dev,"failed to create DMA pool\n" ); + rc = -ENOMEM ; + goto free_goya_device; + } + + hdev->cpu_accessible_dma_mem = + hdev->asic_funcs->dma_alloc_coherent (hdev, +CPU_ACCESSIBLE_MEM_SIZE , + &hdev->cpu_accessible_dma_address, +GFP_KERNEL | __GFP_ZERO); + +if (!hdev->cpu_accessible_dma_mem) { + dev_err(hdev->dev, + "failed to allocate %d of dma memory for CPU accessible memory space\n",
drivers/misc/habanalabs/goya/goya.c line 536
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+ CPU_ACCESSIBLE_MEM_SIZE); + rc = -ENOMEM ; + goto free_dma_pool; + } + + hdev->cpu_accessible_dma_pool =gen_pool_create (CPU_PKT_SHIFT ,-1 ); +if (!hdev->cpu_accessible_dma_pool) { +dev_err (hdev->dev, +"Failed to create CPU accessible DMA pool\n" ); + rc = -ENOMEM ;
You could init rc = -ENOMEM at the beginning and save the duplication.
Quoted 75 lines
drivers/misc/habanalabs/goya/goya.c new file +75
-0+ goto free_cpu_pq_dma_mem; + } + + rc =gen_pool_add (hdev->cpu_accessible_dma_pool, + (u64 ) hdev->cpu_accessible_dma_mem, +CPU_ACCESSIBLE_MEM_SIZE ,-1 ); +if (rc) { +dev_err (hdev->dev, +"Failed to add memory to CPU accessible DMA pool\n" ); + rc = -EFAULT ; + goto free_cpu_pq_pool; + } + +spin_lock_init (&goya->hw_queues_lock); + +return 0 ; + +free_cpu_pq_pool: +gen_pool_destroy (hdev->cpu_accessible_dma_pool); +free_cpu_pq_dma_mem: + hdev->asic_funcs->dma_free_coherent (hdev,CPU_ACCESSIBLE_MEM_SIZE , + hdev->cpu_accessible_dma_mem, + hdev->cpu_accessible_dma_address); +free_dma_pool: +dma_pool_destroy (hdev->dma_pool); +free_goya_device: +kfree (goya); + +return rc; +} + +/** +* goya_sw_fini - Goya software tear-down code +* +* @hdev: pointer to hl_device structure +* +*/ +int goya_sw_fini (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; + +gen_pool_destroy (hdev->cpu_accessible_dma_pool); + + hdev->asic_funcs->dma_free_coherent (hdev,CPU_ACCESSIBLE_MEM_SIZE , + hdev->cpu_accessible_dma_mem, + hdev->cpu_accessible_dma_address); + +dma_pool_destroy (hdev->dma_pool); + +kfree (goya); + +return 0 ; +} + +int goya_suspend (struct hl_device *hdev) +{ +return 0 ; +} + +int goya_resume (struct hl_device *hdev) +{ +return 0 ; +} + +void *goya_dma_alloc_coherent (struct hl_device *hdev,size_t size, +dma_addr_t *dma_handle,gfp_t flags) +{ +return dma_alloc_coherent (&hdev->pdev->dev, size, dma_handle, flags); +} + +void goya_dma_free_coherent (struct hl_device *hdev,size_t size,void *cpu_addr, +dma_addr_t dma_handle) +{ +dma_free_coherent (&hdev->pdev->dev, size, cpu_addr, dma_handle); +}
drivers/misc/habanalabs/goya/goya.c line 621
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c new file +10
-0+ +static const struct hl_asic_funcs goya_funcs = { + .early_init = goya_early_init, + .early_fini = goya_early_fini, + .sw_init = goya_sw_init, + .sw_fini = goya_sw_fini, + .suspend = goya_suspend, + .resume = goya_resume, + .dma_alloc_coherent = goya_dma_alloc_coherent, + .dma_free_coherent = goya_dma_free_coherent,
Is there any additional functionality that is planned in goya or gaudi in these two functions?
It seems like they are not really needed, at least at the moment and for sure that don't need to be part of ASIC ops.
Quoted 467 lines
drivers/misc/habanalabs/goya/goya.c new file +12
-0+}; + +/** +* goya_set_asic_funcs - set Goya function pointers +* +* @*hdev: pointer to hl_device structure +* +*/ +void goya_set_asic_funcs (struct hl_device *hdev) +{ + hdev->asic_funcs = &goya_funcs; +}drivers/misc/habanalabs/goya/goyaP.h new file +125
-0@@ -0,0 +1,125 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +*/ + +#ifndef GOYAP_H_ +#define GOYAP_H_ + +#include "habanalabs.h" +#include "include/goya/goya.h" + +#define NUMBER_OF_CMPLT_QUEUES 5 +#define NUMBER_OF_EXT_HW_QUEUES 5 +#define NUMBER_OF_CPU_HW_QUEUES 1 +#define NUMBER_OF_INT_HW_QUEUES 9 +#define NUMBER_OF_HW_QUEUES (NUMBER_OF_EXT_HW_QUEUES + \ + NUMBER_OF_CPU_HW_QUEUES + \ + NUMBER_OF_INT_HW_QUEUES) + +/* +* Number of MSIX interrupts IDS: +* Each completion queue has 1 ID +* The event queue has 1 ID +* ArmCP reset has 1 ID +*/ +#define NUMBER_OF_INTERRUPTS (NUMBER_OF_CMPLT_QUEUES + 2) + +#if (NUMBER_OF_HW_QUEUES >=HL_MAX_QUEUES ) +#error "Number of H/W queues must be smaller than HL_MAX_QUEUES" +#endif + +#if (NUMBER_OF_INTERRUPTS >GOYA_MSIX_ENTRIES ) +#error "Number of MSIX interrupts must be smaller or equal to GOYA_MSIX_ENTRIES" +#endif + +#define QMAN_FENCE_TIMEOUT_USEC 10000/* 10 ms */ + +#define QMAN_STOP_TIMEOUT_USEC 100000/* 100 ms */ + +#define TPC_MAX_NUM 8 +#define TPC_ENABLED_MASK 0xFF + +#define DMA_MAX_NUM 5 + +#define PLL_HIGH_DEFAULT 1575000000/* 1.575 GHz */ + +#define GOYA_ARMCP_INFO_TIMEOUT 10000000/* 10s */ + +#define DRAM_PHYS_DEFAULT_SIZE 0x100000000ull/* 4GB */ + +/* +* SRAM Memory Map for KMD +* +* KMD occupies KMD_SRAM_SIZE bytes from the start of SRAM. It is used for +* MME/TPC QMANs +* +*/ + +#define MME_QMAN_BASE_OFFSET 0x000000/* Must be 0 */ +#define MME_QMAN_LENGTH 64 +#define TPC_QMAN_LENGTH 64 + +#define TPC0_QMAN_BASE_OFFSET (MME_QMAN_BASE_OFFSET + \ + (MME_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC1_QMAN_BASE_OFFSET (TPC0_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC2_QMAN_BASE_OFFSET (TPC1_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC3_QMAN_BASE_OFFSET (TPC2_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC4_QMAN_BASE_OFFSET (TPC3_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC5_QMAN_BASE_OFFSET (TPC4_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC6_QMAN_BASE_OFFSET (TPC5_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) +#define TPC7_QMAN_BASE_OFFSET (TPC6_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) + +#define SRAM_KMD_RES_OFFSET (TPC7_QMAN_BASE_OFFSET + \ + (TPC_QMAN_LENGTH * QMAN_PQ_ENTRY_SIZE)) + +#if (SRAM_KMD_RES_OFFSET >=KMD_SRAM_RESERVED_SIZE ) +#error "MME/TPC QMANs SRAM space exceeds limit" +#endif + +#define SRAM_USER_BASE_OFFSET KMD_SRAM_RESERVED_SIZE + +#define DMA_MAX_TRANSFER_SIZE 0xFFFFFFFF + +#define HW_CAP_PLL 0x00000001 +#define HW_CAP_DDR_0 0x00000002 +#define HW_CAP_DDR_1 0x00000004 +#define HW_CAP_MME 0x00000008 +#define HW_CAP_CPU 0x00000010 +#define HW_CAP_DMA 0x00000020 +#define HW_CAP_MSIX 0x00000040 +#define HW_CAP_CPU_Q 0x00000080 +#define HW_CAP_MMU 0x00000100 +#define HW_CAP_TPC_MBIST 0x00000200 +#define HW_CAP_GOLDEN 0x00000400 +#define HW_CAP_TPC 0x00000800 + +#define CPU_PKT_SHIFT 5 +#define CPU_PKT_SIZE (1 << CPU_PKT_SHIFT) +#define CPU_PKT_MASK (~((1 << CPU_PKT_SHIFT) - 1)) +#define CPU_MAX_PKTS_IN_CB 32 +#define CPU_CB_SIZE (CPU_PKT_SIZE * CPU_MAX_PKTS_IN_CB) +#define CPU_ACCESSIBLE_MEM_SIZE (HL_QUEUE_LENGTH * CPU_CB_SIZE) + +enum goya_fw_component { +FW_COMP_UBOOT , +FW_COMP_PREBOOT +}; + +struct goya_device { +/* TODO: remove hw_queues_lock after moving to scheduler code */ +spinlock_t hw_queues_lock; +u64 ddr_bar_cur_addr; +u32 hw_cap_initialized; +}; + +#endif /* GOYAP_H_ */ drivers/misc/habanalabs/habanalabs.h +131
-0@@ -21,11 +21,64 @@#define HL_NAME "habanalabs" +#define HL_MAX_QUEUES 128 +struct hl_device ; +/** +* struct asic_fixed_properties - ASIC specific immutable properties. +* @sram_base_address: SRAM physical start address. +* @sram_end_address: SRAM physical end address. +* @sram_user_base_address - SRAM physical start address for user access. +* @dram_base_address: DRAM physical start address. +* @dram_end_address: DRAM physical end address. +* @dram_user_base_address: DRAM physical start address for user access. +* @dram_size: DRAM total size. +* @dram_pci_bar_size: size of PCI bar towards DRAM. +* @host_phys_base_address: base physical address of host memory for +* transactions that the device generates. +* @va_space_host_start_address: base address of virtual memory range for +* mapping host memory. +* @va_space_host_end_address: end address of virtual memory range for +* mapping host memory. +* @va_space_dram_start_address: base address of virtual memory range for +* mapping DRAM memory. +* @va_space_dram_end_address: end address of virtual memory range for +* mapping DRAM memory. +* @cfg_size: configuration space size on SRAM. +* @sram_size: total size of SRAM. +* @max_asid: maximum number of open contexts (ASIDs). +* @completion_queues_count: number of completion queues. +* @high_pll: high PLL frequency used by the device. +* @tpc_enabled_mask: which TPCs are enabled. +*/ +struct asic_fixed_properties { +u64 sram_base_address; +u64 sram_end_address; +u64 sram_user_base_address; +u64 dram_base_address; +u64 dram_end_address; +u64 dram_user_base_address; +u64 dram_size; +u64 dram_pci_bar_size; +u64 host_phys_base_address; +u64 va_space_host_start_address; +u64 va_space_host_end_address; +u64 va_space_dram_start_address; +u64 va_space_dram_end_address; +u32 cfg_size; +u32 sram_size; +u32 max_asid; +u32 high_pll; +u8 completion_queues_count; +u8 tpc_enabled_mask; +}; + + +#define HL_QUEUE_LENGTH 256/* @@ -47,6 +100,30 @@ enum hl_asic_type { +/** +* struct hl_asic_funcs - ASIC specific functions that are can be called from +* common code. +* @early_init: sets up early driver state (pre sw_init), doesn't configure H/W. +* @early_fini: tears down what was done in early_init. +* @sw_init: sets up driver state, does not configure H/W. +* @sw_fini: tears down driver state, does not configure H/W. +* @suspend: handles IP specific H/W or SW changes for suspend. +* @resume: handles IP specific H/W or SW changes for resume. +* @dma_alloc_coherent: DMA allocate coherent memory. +* @dma_free_coherent: free DMA allocation. +*/ +struct hl_asic_funcs { +int (*early_init)(struct hl_device *hdev); +int (*early_fini)(struct hl_device *hdev); +int (*sw_init)(struct hl_device *hdev); +int (*sw_fini)(struct hl_device *hdev); +int (*suspend)(struct hl_device *hdev); +int (*resume)(struct hl_device *hdev); +void * (*dma_alloc_coherent)(struct hl_device *hdev,size_t size, +dma_addr_t *dma_handle,gfp_t flag); +void (*dma_free_coherent)(struct hl_device *hdev,size_t size, +void *cpu_addr,dma_addr_t dma_handle); +};/* * FILE PRIVATE STRUCTURE @@ -78,26 +155,78 @@ struct hl_fpriv {*/ #define HL_MAX_MINORS 256 +/* +* Registers read & write functions. +*/ + +u32 hl_rreg (struct hl_device *hdev,u32 reg); +void hl_wreg (struct hl_device *hdev,u32 reg,u32 val); + +#define hl_poll_timeout (hdev, addr, val, cond, sleep_us, timeout_us) \ + readl_poll_timeout(hdev->rmmio + addr, val, cond, sleep_us, timeout_us) + +#define RREG32 (reg) hl_rreg(hdev, (reg)) +#define WREG32 (reg, v) hl_wreg(hdev, (reg), (v)) +#define DREG32 (reg) pr_info("REGISTER: " #reg " : 0x%08X\n", \ + hl_rreg(hdev, (reg))) + +#define WREG32_P (reg, val, mask) \ + do { \ + u32 tmp_ = RREG32(reg); \ + tmp_ &= (mask); \ + tmp_ |= ((val) & ~(mask)); \ + WREG32(reg, tmp_); \ + } while (0) +#define WREG32_AND (reg, and) WREG32_P(reg, 0, and) +#define WREG32_OR (reg, or) WREG32_P(reg, or, ~(or)) + +#define REG_FIELD_SHIFT (reg, field) reg##_##field##_SHIFT +#define REG_FIELD_MASK (reg, field) reg##_##field##_MASK +#define WREG32_FIELD (reg, field, val) \ + WREG32(mm##reg, (RREG32(mm##reg) & ~REG_FIELD_MASK(reg, field)) | \ + (val) << REG_FIELD_SHIFT(reg, field)) +/** * struct hl_device - habanalabs device structure. * @pdev: pointer to PCI device, can be NULL in case of simulator device. +* @pcie_bar: array of available PCIe bars. +* @rmmio: configuration area address on SRAM. * @cdev: related char device. * @dev: realted kernel basic device structure. * @asic_name: ASIC specific nmae. * @asic_type: ASIC specific type. +* @dma_pool: DMA pool for small allocations. +* @cpu_accessible_dma_mem: KMD <-> ArmCP shared memory CPU address. +* @cpu_accessible_dma_address: KMD <-> ArmCP shared memory DMA address. +* @cpu_accessible_dma_pool: KMD <-> ArmCP shared memory pool. +* @asic_prop: ASIC specific immutable properties. +* @asic_funcs: ASIC specific functions. +* @asic_specific: ASIC specific information to use only from ASIC files. * @major: habanalabs KMD major. * @id: device minor. * @disabled: is device disabled. */ struct hl_device {struct pci_dev *pdev; +void __iomem *pcie_bar[6 ]; +void __iomem *rmmio;struct cdev cdev;struct device *dev;char asic_name[16 ];enum hl_asic_type asic_type; +struct dma_pool *dma_pool; +void *cpu_accessible_dma_mem; +dma_addr_t cpu_accessible_dma_address; +struct gen_pool *cpu_accessible_dma_pool; +struct asic_fixed_properties asic_prop; +const struct hl_asic_funcs *asic_funcs; +void *asic_specific;u32 major;u16 id;u8 disabled; + +/* Parameters for bring-up */ +u8 reset_pcilink; };/* @@ -146,4 +275,6 @@ void hl_device_fini(struct hl_device *hdev);int hl_device_suspend (struct hl_device *hdev);int hl_device_resume (struct hl_device *hdev); +void goya_set_asic_funcs (struct hl_device *hdev); +#endif /* HABANALABSP_H_ */ drivers/misc/habanalabs/habanalabs_drv.c +3
-0@@ -136,6 +136,9 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->major = hl_major; +/* Parameters for bring-up - set them to defaults */ + hdev->reset_pcilink =0 ; + hdev->disabled = true; hdev->pdev = pdev;/* can be NULL in case of simulator device */ drivers/misc/habanalabs/include/goya/goya.h new file +115
-0@@ -0,0 +1,115 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +* Author: Oded Gabbay <[email protected]> +* +*/ + +#ifndef GOYA_H +#define GOYA_H + +#include "asic_reg/goya_regs.h" + +#include <linux/types.h> + +#define SRAM_CFG_BAR_ID 0 +#define MSIX_BAR_ID 2 +#define DDR_BAR_ID 4 + +#define CFG_BAR_SIZE 0x10000000ull/* 256MB */ +#define MSIX_BAR_SIZE 0x1000ull/* 4KB */ + +#define CFG_BASE 0x7FFC000000ull +#define CFG_SIZE 0x4000000/* 32MB CFG + 32MB DBG*/ + +#define SRAM_BASE_ADDR 0x7FF0000000ull +#define SRAM_SIZE 0x32A0000/* 50.625MB */ +#define KMD_SRAM_RESERVED_SIZE 0x8000/* 32KB */ + +#define SRAM_BASE_ADDR_USER (0x7FF0000000ull + KMD_SRAM_RESERVED_SIZE) +#define SRAM_SIZE_USER (SRAM_SIZE - KMD_SRAM_RESERVED_SIZE) + +#define DRAM_PHYS_BASE 0x0ull + +#define CPU_FW_IMAGE_SIZE 0x10000000/* 256MB */ +#define MMU_PAGE_TABLES_SIZE 0x0E000000/* 224MB */ +#define CPU_PQ_PKT_SIZE 0x00001000/* 4KB */ +#define CPU_PQ_DATA_SIZE 0x01FFF000/* 32MB - 4KB */ + +#define CPU_FW_IMAGE_ADDR DRAM_PHYS_BASE +#define MMU_PAGE_TABLES_ADDR (CPU_FW_IMAGE_ADDR + CPU_FW_IMAGE_SIZE) +#define CPU_PQ_PKT_ADDR (MMU_PAGE_TABLES_ADDR + MMU_PAGE_TABLES_SIZE) +#define CPU_PQ_DATA_ADDR (CPU_PQ_PKT_ADDR + CPU_PQ_PKT_SIZE) +#define DRAM_BASE_ADDR_USER (CPU_PQ_DATA_ADDR + CPU_PQ_DATA_SIZE) + +#define HOST_PHYS_BASE 0x8000000000ull/* 0.5TB */ +#define HOST_PHYS_SIZE 0x1000000000000ull/* 0.25PB (48 bits) */ + +#define VA_HOST_SPACE_START 0x1000000000000ull/* 256TB */ +#define VA_HOST_SPACE_END 0x3FF8000000000ull/* 1PB - 1TB */ +#define VA_HOST_SPACE_SIZE (VA_HOST_SPACE_END - \ + VA_HOST_SPACE_START)/* 767TB */ + +#define VA_DDR_SPACE_START 0x800000000ull/* 32GB */ +#define VA_DDR_SPACE_END 0x2000000000ull/* 128GB */ +#define VA_DDR_SPACE_SIZE (VA_DDR_SPACE_END - \ + VA_DDR_SPACE_START)/* 128GB */ + +#define CPU_BOOT_ADDR 0x7FF8040000ull + +#define UBOOT_FW_OFFSET 0x100000/* 1MB in SRAM */ +#define LINUX_FW_OFFSET 0x800000/* 8BM in DDR */ + +#define GOYA_MSIX_ENTRIES 8 +#define EVENT_QUEUE_MSIX_IDX 5 +#define ARMCP_RESET_MSIX_IDX 6 + +#define QMAN_PQ_ENTRY_SIZE 16/* Bytes */ + +#define MAX_ASID 1024 + +#define PROT_BITS_OFFS 0xF80 + +/* +* Queue Numbering +* +* The external queues (DMA channels + CPU) MUST be before the internal queues +* and each group (DMA channels + CPU and internal) must be contiguous inside +* itself but there can be a gap between the two groups (although not +* recommended) +*/ + +enum goya_queue_id { +GOYA_QUEUE_ID_DMA_0 =0 , +GOYA_QUEUE_ID_DMA_1 , +GOYA_QUEUE_ID_DMA_2 , +GOYA_QUEUE_ID_DMA_3 , +GOYA_QUEUE_ID_DMA_4 , +GOYA_QUEUE_ID_CPU_PQ , +GOYA_QUEUE_ID_MME , +GOYA_QUEUE_ID_TPC0 , +GOYA_QUEUE_ID_TPC1 , +GOYA_QUEUE_ID_TPC2 , +GOYA_QUEUE_ID_TPC3 , +GOYA_QUEUE_ID_TPC4 , +GOYA_QUEUE_ID_TPC5 , +GOYA_QUEUE_ID_TPC6 , +GOYA_QUEUE_ID_TPC7 , +GOYA_QUEUE_ID_SIZE +}; + +enum goya_pll_index { +CPU_PLL =0 , +IC_PLL , +MC_PLL , +MME_PLL , +PCI_PLL , +EMMC_PLL , +TPC_PLL +}; + +#define GOYA_PLL_FREQ_LOW 50000000/* 50 MHz */ + +#endif /* GOYA_H */ Signature · 1 line
2.17.1
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 05/15] habanalabs: add command buffer module
In reply to Oded GabbayQuoted 2 lines · Oded Gabbay
This patch adds the CB module, which allows the user to create and destroy CBs and to map them to the user's process address-space.
Can you please spell "command buffer" at least first time it's mentioned?
Quoted 61 lines
A command buffer is a memory blocks that reside in DMA-able address-space and is physically contiguous so it can be accessed by the device without MMU translation. The command buffer memory is allocated using the coherent DMA API.
When creating a new CB, the IOCTL returns a handle of it, and the user-space process needs to use that handle to mmap the buffer to get a VA in the user's address-space.
Before destroying (freeing) a CB, the user must unmap the CB's VA using the CB handle.
Each CB has a reference counter, which tracks its usage in command submissions and also its mmaps (only a single mmap is allowed).
The driver maintains a pool of pre-allocated CBs in order to reduce latency during command submissions. In case the pool is empty, the driver will go to the slow-path of allocating a new CB, i.e. calling
dma_alloc_coherent.Signed-off-by Oded Gabbay <[email protected]>--- drivers/misc/habanalabs/Makefile | 3 +- drivers/misc/habanalabs/command_buffer.c | 414 +++++++++++++++++++++ drivers/misc/habanalabs/device.c | 43 ++- drivers/misc/habanalabs/goya/goya.c | 28 ++ drivers/misc/habanalabs/habanalabs.h | 95 ++++- drivers/misc/habanalabs/habanalabs_drv.c | 2 + drivers/misc/habanalabs/habanalabs_ioctl.c | 102 +++++ include/uapi/misc/habanalabs.h | 62 +++ 8 files changed, 746 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/habanalabs/command_buffer.c create mode 100644 drivers/misc/habanalabs/habanalabs_ioctl.c create mode 100644 include/uapi/misc/habanalabs.hdrivers/misc/habanalabs/Makefile +2
-1@@ -4,7 +4,8 @@ obj-m := habanalabs.o -habanalabs-y := habanalabs_drv.o device.o context.o asid.o +habanalabs-y := habanalabs_drv.o device.o context.o asid.o habanalabs_ioctl.o \ + command_buffer.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)drivers/misc/habanalabs/command_buffer.c new file +6
-0@@ -0,0 +1,414 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/
drivers/misc/habanalabs/command_buffer.c line 16
Quoted 10 lines
drivers/misc/habanalabs/command_buffer.c new file +10
-0+ +#include <uapi/misc/habanalabs.h> +#include "habanalabs.h" + +#include <linux/dma-mapping.h> + +static void cb_fini (struct hl_device *hdev,struct hl_cb *cb) +{ + hdev->asic_funcs->dma_free_coherent (hdev, cb->size, + (void *) cb->kernel_address, cb->bus_address);
As it seems, ASIC specific dma_free_coherent is a shortcut for a generic dma_free_coherent. Why not use it directly?
Quoted 23 lines
drivers/misc/habanalabs/command_buffer.c new file +23
-0+kfree (cb); +} + +static void cb_do_release (struct hl_device *hdev,struct hl_cb *cb) +{ +if (cb->is_pool) { +spin_lock (&hdev->cb_pool_lock); +list_add (&cb->pool_list, &hdev->cb_pool); +spin_unlock (&hdev->cb_pool_lock); + }else { +cb_fini (hdev, cb); + } +} + +static void cb_release (struct kref *ref) +{ +struct hl_device *hdev; +struct hl_cb *cb; + + cb = container_of(ref, struct hl_cb, refcount); + hdev = cb->hdev; + +cb_do_release (hdev, cb);
drivers/misc/habanalabs/command_buffer.c line 49
Quoted 10 lines
drivers/misc/habanalabs/command_buffer.c new file +10
-0+} + +static struct hl_cb *hl_cb_alloc (struct hl_device *hdev,u32 cb_size, +int ctx_id) +{ +struct hl_cb *cb; +void *p; + +if (ctx_id ==HL_KERNEL_ASID_ID ) + cb =kzalloc (sizeof (*cb),GFP_ATOMIC );
The GFP_ATOMIC should be used when the caller cannot tolerate reclaim or sleep and it does not seem to be the case here.
drivers/misc/habanalabs/command_buffer.c line 58
Quoted 9 lines
drivers/misc/habanalabs/command_buffer.c new file +9
-0+else + cb =kzalloc (sizeof (*cb),GFP_KERNEL ); + +if (!cb) +return NULL ; + +if (ctx_id ==HL_KERNEL_ASID_ID ) + p = hdev->asic_funcs->dma_alloc_coherent (hdev, cb_size, + &cb->bus_address,GFP_ATOMIC );
GFP_KERNEL?
Quoted 39 lines
drivers/misc/habanalabs/command_buffer.c new file +39
-0+else + p = hdev->asic_funcs->dma_alloc_coherent (hdev, cb_size, + &cb->bus_address, +GFP_USER | __GFP_ZERO); +if (!p) { +dev_err (hdev->dev, +"failed to allocate %d of dma memory for CB\n" , + cb_size); +kfree (cb); +return NULL ; + } + + cb->kernel_address = (u64 ) p; + cb->size = cb_size; + +return cb; +} + +int hl_cb_create (struct hl_device *hdev,struct hl_cb_mgr *mgr, +u32 cb_size,u64 *handle,int ctx_id) +{ +struct hl_cb *cb; +bool alloc_new_cb = true; +int rc; + +if (hdev->disabled) { +dev_warn_ratelimited (hdev->dev, +"Device is disabled !!! Can't create new CBs\n" ); + rc = -EBUSY ; + goto out_err; + } + +/* Minimum allocation must be PAGE SIZE */ +if (cb_size <PAGE_SIZE ) + cb_size =PAGE_SIZE ; + +if (ctx_id ==HL_KERNEL_ASID_ID && + cb_size <= hdev->asic_prop.cb_pool_cb_size) { +
drivers/misc/habanalabs/command_buffer.c line 107
Quoted 10 lines
drivers/misc/habanalabs/command_buffer.c new file +10
-0+spin_lock (&hdev->cb_pool_lock); +if (!list_empty (&hdev->cb_pool)) { + cb =list_first_entry (&hdev->cb_pool,typeof (*cb), + pool_list); +list_del (&cb->pool_list); +spin_unlock (&hdev->cb_pool_lock); + alloc_new_cb = false; + }else { +spin_unlock (&hdev->cb_pool_lock); +dev_warn_once (hdev->dev,"CB pool is empty\n" );
Isn't it going to be a false alarm when you allocate the cb for the first time?
Quoted 6 lines
drivers/misc/habanalabs/command_buffer.c new file +6
-0+ } + } + +if (alloc_new_cb) { + cb =hl_cb_alloc (hdev, cb_size, ctx_id); +if (!cb) {
drivers/misc/habanalabs/command_buffer.c line 123
Quoted 10 lines
drivers/misc/habanalabs/command_buffer.c new file +10
-0+ rc = -ENOMEM ; + goto out_err; + } + } + + cb->hdev = hdev; + cb->ctx_id = ctx_id; + +spin_lock (&mgr->cb_lock); + rc =idr_alloc (&mgr->cb_handles, cb,1 ,0 ,GFP_ATOMIC );
It seems the ID will remain dangling if the cb is reused.
Quoted 111 lines
drivers/misc/habanalabs/command_buffer.c new file +111
-0+spin_unlock (&mgr->cb_lock); + +if (rc <0 ) { +dev_err (hdev->dev,"Failed to allocate IDR for a new CB\n" ); + goto release_cb; + } + + cb->id = rc; + +kref_init (&cb->refcount); +spin_lock_init (&cb->lock); + +/* +* idr is 32-bit so we can safely OR it with a mask that is above +* 32 bit +*/ + *handle = cb->id |HL_MMAP_CB_MASK ; + *handle <<=PAGE_SHIFT ; + +return 0 ; + +release_cb: +cb_do_release (hdev, cb); +out_err: + *handle =0 ; + +return rc; +} + +int hl_cb_destroy (struct hl_device *hdev,struct hl_cb_mgr *mgr,u64 cb_handle) +{ +struct hl_cb *cb; +u32 handle; +int rc =0 ; + +/* +* handle was given to user to do mmap, I need to shift it back to +* how the idr module gave it to me +*/ + cb_handle >>=PAGE_SHIFT ; + handle = (u32 ) cb_handle; + +spin_lock (&mgr->cb_lock); + + cb =idr_find (&mgr->cb_handles, handle); +if (cb) { +idr_remove (&mgr->cb_handles, handle); +spin_unlock (&mgr->cb_lock); +kref_put (&cb->refcount, cb_release); + }else { +spin_unlock (&mgr->cb_lock); +dev_err (hdev->dev, +"CB destroy failed, no match to handle 0x%x\n" , handle); + rc = -EINVAL ; + } + +return rc; +} + +int hl_cb_ioctl (struct hl_fpriv *hpriv,void *data) +{ +union hl_cb_args *args = data; +struct hl_device *hdev = hpriv->hdev; +u64 handle; +int rc; + +switch (args->in.op) { +case HL_CB_OP_CREATE : + rc =hl_cb_create (hdev, &hpriv->cb_mgr, args->in.cb_size, + &handle, hpriv->ctx->asid); +memset (args,0 ,sizeof (*args)); + args->out.cb_handle = handle; +break ; +case HL_CB_OP_DESTROY : + rc =hl_cb_destroy (hdev, &hpriv->cb_mgr, + args->in.cb_handle); +memset (args,0 ,sizeof (*args)); +break ; +default : + rc = -EINVAL ; +break ; + } + +return rc; +} + +static void cb_vm_close (struct vm_area_struct *vma) +{ +struct hl_cb *cb = (struct hl_cb *) vma->vm_private_data; + +hl_cb_put (cb); + +spin_lock (&cb->lock); + cb->mmap = false; + cb->vm_start =0 ; + cb->vm_end =0 ; +spin_unlock (&cb->lock); + + vma->vm_private_data =NULL ; +} + +static const struct vm_operations_struct cb_vm_ops = { + .close = cb_vm_close +}; + +int hl_cb_mmap (struct hl_fpriv *hpriv,struct vm_area_struct *vma) +{ +struct hl_device *hdev = hpriv->hdev; +struct hl_cb *cb; +phys_addr_t address; +u32 handle;
drivers/misc/habanalabs/command_buffer.c line 244
Quoted 10 lines
drivers/misc/habanalabs/command_buffer.c new file +10
-0+int rc; + + handle = vma->vm_pgoff; + +/* reference was taken here */ + cb =hl_cb_get (hdev, &hpriv->cb_mgr, handle); +if (!cb) { +dev_err (hdev->dev, +"CB mmap failed, no match to handle %d\n" , handle); + goto err_out;
why no simply return -EINVAL?
Quoted 570 lines
drivers/misc/habanalabs/command_buffer.c new file +170
-0+ } + +/* Validation check */ +if (vma->vm_end - vma->vm_start != cb->size) { +dev_err (hdev->dev, +"CB mmap failed, mmap size 0x%lx != 0x%x cb size\n" , + vma->vm_end - vma->vm_start, cb->size); + goto put_cb; + } + +spin_lock (&cb->lock); + +if (cb->mmap) { +dev_err (hdev->dev, +"CB mmap failed, CB already mmaped to user\n" ); + goto release_lock; + } + + cb->mmap = true; + +spin_unlock (&cb->lock); + + vma->vm_ops = &cb_vm_ops; + +/* +* Note: We're transferring the cb reference to +* vma->vm_private_data here. +*/ + + vma->vm_private_data = cb; + +/* Calculate address for CB */ + address =virt_to_phys ((void *) cb->kernel_address); + + rc = hdev->asic_funcs->cb_mmap (hdev, vma, cb->kernel_address, + address, cb->size); + +if (rc) { +spin_lock (&cb->lock); + cb->mmap = false; + goto release_lock; + } + + cb->vm_start = vma->vm_start; + cb->vm_end = vma->vm_end; + +return 0 ; + +release_lock: +spin_unlock (&cb->lock); +put_cb: +hl_cb_put (cb); +err_out: +return -EINVAL ; +} + +struct hl_cb *hl_cb_get (struct hl_device *hdev,struct hl_cb_mgr *mgr, +u32 handle) +{ +struct hl_cb *cb; + +spin_lock (&mgr->cb_lock); + cb =idr_find (&mgr->cb_handles, handle); + +if (!cb) { +spin_unlock (&mgr->cb_lock); +dev_warn (hdev->dev, +"CB get failed, no match to handle %d\n" , handle); +return NULL ; + } + +kref_get (&cb->refcount); + +spin_unlock (&mgr->cb_lock); + +return cb; + +} + +void hl_cb_put (struct hl_cb *cb) +{ +kref_put (&cb->refcount, cb_release); +} + +void hl_cb_mgr_init (struct hl_cb_mgr *mgr) +{ +spin_lock_init (&mgr->cb_lock); +idr_init (&mgr->cb_handles); +} + +void hl_cb_mgr_fini (struct hl_device *hdev,struct hl_cb_mgr *mgr) +{ +struct hl_cb *cb; +struct idr *idp; +u32 id; + + idp = &mgr->cb_handles; + +idr_for_each_entry (idp, cb, id) { +if (kref_put (&cb->refcount, cb_release) !=1 ) +dev_err (hdev->dev, +"CB %d for CTX ID %d is still alive\n" , + id, cb->ctx_id); + } + +idr_destroy (&mgr->cb_handles); +} + +struct hl_cb *hl_cb_kernel_create (struct hl_device *hdev,u32 cb_size) +{ +u64 cb_handle; +struct hl_cb *cb; +int rc; + + rc =hl_cb_create (hdev, &hdev->kernel_cb_mgr, cb_size, &cb_handle, +HL_KERNEL_ASID_ID ); +if (rc) { +dev_err (hdev->dev,"Failed to allocate CB for KMD %d\n" , rc); +return NULL ; + } + + cb_handle >>=PAGE_SHIFT ; + cb =hl_cb_get (hdev, &hdev->kernel_cb_mgr, (u32 ) cb_handle); +/* hl_cb_get should never fail here so use kernel WARN */ +WARN (!cb,"Kernel CB handle invalid 0x%x\n" , (u32 ) cb_handle); +if (!cb) + goto destroy_cb; + +return cb; + +destroy_cb: +hl_cb_destroy (hdev, &hdev->kernel_cb_mgr, cb_handle <<PAGE_SHIFT ); + +return NULL ; +} + +int hl_cb_pool_init (struct hl_device *hdev) +{ +struct hl_cb *cb; +int i; + +INIT_LIST_HEAD (&hdev->cb_pool); +spin_lock_init (&hdev->cb_pool_lock); + +for (i =0 ; i < hdev->asic_prop.cb_pool_cb_cnt ; i++) { + cb =hl_cb_alloc (hdev, hdev->asic_prop.cb_pool_cb_size, +HL_KERNEL_ASID_ID ); +if (cb) { + cb->is_pool = true; +list_add (&cb->pool_list, &hdev->cb_pool); + }else { +hl_cb_pool_fini (hdev); +return -ENOMEM ; + } + } + +return 0 ; +} + +int hl_cb_pool_fini (struct hl_device *hdev) +{ +struct hl_cb *cb, *tmp; + +list_for_each_entry_safe (cb, tmp, &hdev->cb_pool, pool_list) { +list_del (&cb->pool_list); +cb_fini (hdev, cb); + } + +return 0 ; +}drivers/misc/habanalabs/device.c +42
-1@@ -53,6 +53,7 @@ static int hl_device_release(struct inode *inode, struct file *filp) {struct hl_fpriv *hpriv = filp->private_data; +hl_cb_mgr_fini (hpriv->hdev, &hpriv->cb_mgr);hl_ctx_mgr_fini (hpriv->hdev, &hpriv->ctx_mgr); filp->private_data =NULL ;@@ -62,10 +63,34 @@ static int hl_device_release(struct inode *inode, struct file *filp)return 0 ; } +/** +* hl_mmap - mmap function for habanalabs device +* +* @*filp: pointer to file structure +* @*vma: pointer to vm_area_struct of the process +* +* Called when process does an mmap on habanalabs device. Call the device's mmap +* function at the end of the common code. +*/ +static int hl_mmap (struct file *filp,struct vm_area_struct *vma) +{ +struct hl_fpriv *hpriv = filp->private_data; + +if ((vma->vm_pgoff &HL_MMAP_CB_MASK ) ==HL_MMAP_CB_MASK ) { + vma->vm_pgoff ^=HL_MMAP_CB_MASK ; +return hl_cb_mmap (hpriv, vma); + } + +return hpriv->hdev->asic_funcs->mmap (hpriv, vma); +} +static const struct file_operations hl_ops = { .owner =THIS_MODULE , .open = hl_device_open, - .release = hl_device_release + .release = hl_device_release, + .mmap = hl_mmap, + .unlocked_ioctl = hl_ioctl, + .compat_ioctl = hl_ioctl };/** @@ -145,6 +170,8 @@ static int device_early_init(struct hl_device *hdev)if (rc) goto early_fini; +hl_cb_mgr_init (&hdev->kernel_cb_mgr); +mutex_init (&hdev->device_open);atomic_set (&hdev->fd_open_cnt,0 );@@ -166,6 +193,8 @@ static int device_early_init(struct hl_device *hdev)static void device_early_fini (struct hl_device *hdev) { +hl_cb_mgr_fini (hdev, &hdev->kernel_cb_mgr); +hl_asid_fini (hdev);if (hdev->asic_funcs->early_fini)@@ -280,11 +309,21 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) goto free_ctx; } + rc =hl_cb_pool_init (hdev); +if (rc) { +dev_err (hdev->dev,"failed to initialize CB pool\n" ); + goto release_ctx; + } +dev_notice (hdev->dev,"Successfully added device to habanalabs driver\n" );return 0 ; +release_ctx: +if (hl_ctx_put (hdev->kernel_ctx) !=1 ) +dev_err (hdev->dev, +"kernel ctx is still alive on initialization failure\n" ); free_ctx:kfree (hdev->kernel_ctx); sw_fini:@@ -321,6 +360,8 @@ void hl_device_fini(struct hl_device *hdev)/* Mark device as disabled */ hdev->disabled = true; +hl_cb_pool_fini (hdev); +/* Release kernel context */ if ((hdev->kernel_ctx) && (hl_ctx_put (hdev->kernel_ctx) !=1 ))dev_err (hdev->dev,"kernel ctx is still alive\n" );drivers/misc/habanalabs/goya/goya.c +28
-0@@ -92,6 +92,9 @@#define GOYA_MAX_INITIATORS 20 +#define GOYA_CB_POOL_CB_CNT 512 +#define GOYA_CB_POOL_CB_SIZE 0x20000/* 128KB */ +static void goya_get_fixed_properties (struct hl_device *hdev) {struct asic_fixed_properties *prop = &hdev->asic_prop;@@ -119,6 +122,8 @@ static void goya_get_fixed_properties(struct hl_device *hdev) prop->tpc_enabled_mask =TPC_ENABLED_MASK ; prop->high_pll =PLL_HIGH_DEFAULT ; + prop->cb_pool_cb_cnt =GOYA_CB_POOL_CB_CNT ; + prop->cb_pool_cb_size =GOYA_CB_POOL_CB_SIZE ; }/** @@ -598,6 +603,27 @@ int goya_resume(struct hl_device *hdev)return 0 ; } +int goya_mmap (struct hl_fpriv *hpriv,struct vm_area_struct *vma) +{ +return -EINVAL ; +} + +int goya_cb_mmap (struct hl_device *hdev,struct vm_area_struct *vma, +u64 kaddress,phys_addr_t paddress,u32 size) +{ +int rc; + + vma->vm_flags |=VM_IO |VM_PFNMAP |VM_DONTEXPAND |VM_DONTDUMP | +VM_DONTCOPY |VM_NORESERVE ; + + rc =remap_pfn_range (vma, vma->vm_start, paddress >>PAGE_SHIFT , + size, vma->vm_page_prot); +if (rc) +dev_err (hdev->dev,"remap_pfn_range error %d" , rc); + +return rc; +} +void *goya_dma_alloc_coherent (struct hl_device *hdev,size_t size,dma_addr_t *dma_handle,gfp_t flags) {@@ -617,6 +643,8 @@ static const struct hl_asic_funcs goya_funcs = { .sw_fini = goya_sw_fini, .suspend = goya_suspend, .resume = goya_resume, + .mmap = goya_mmap, + .cb_mmap = goya_cb_mmap, .dma_alloc_coherent = goya_dma_alloc_coherent, .dma_free_coherent = goya_dma_free_coherent, };drivers/misc/habanalabs/habanalabs.h +94
-1@@ -21,10 +21,12 @@#define HL_NAME "habanalabs" +#define HL_MMAP_CB_MASK (0x8000000000000000ull >> PAGE_SHIFT) +#define HL_MAX_QUEUES 128struct hl_device ; - +struct hl_fpriv ;@@ -53,6 +55,8 @@ struct hl_device;* @max_asid: maximum number of open contexts (ASIDs). * @completion_queues_count: number of completion queues. * @high_pll: high PLL frequency used by the device. +* @cb_pool_cb_cnt: number of CBs in the CB pool. +* @cb_pool_cb_size: size of each CB in the CB pool. * @tpc_enabled_mask: which TPCs are enabled. */ struct asic_fixed_properties {@@ -73,11 +77,68 @@ struct asic_fixed_properties {u32 sram_size;u32 max_asid;u32 high_pll; +u32 cb_pool_cb_cnt; +u32 cb_pool_cb_size;u8 completion_queues_count;u8 tpc_enabled_mask; }; + + + + +/* +* Command Buffers +*/ + +/** +* struct hl_cb_mgr - describes a Command Buffer Manager. +* @cb_lock: protects cb_handles. +* @cb_handles: an idr to hold all command buffer handles. +*/ +struct hl_cb_mgr { +spinlock_t cb_lock; +struct idr cb_handles;/* protected by cb_lock */ +}; + +/** +* struct hl_cb - describes a Command Buffer. +* @refcount: reference counter for usage of the CB. +* @hdev: pointer to device this CB belongs to. +* @lock: spinlock to protect mmap/cs flows. +* @pool_list: node in pool list of command buffers. +* @kernel_address: Holds the CB's kernel virtual address. +* @bus_address: Holds the CB's DMA address. +* @vm_start: Holds the CB's user start virtual address (when mmaped). +* @vm_end: Holds the CB's user end virtual address (when mmaped). +* @size: holds the CB's size. +* @id: the CB's ID. +* @ctx_id: holds the ID of the owner's context. +* @mmap: true if the CB is currently mmaped to user. +* @is_pool: true if CB was acquired from the pool, false otherwise. +*/ +struct hl_cb { +struct kref refcount; +struct hl_device *hdev; +spinlock_t lock; +struct list_head pool_list; +u64 kernel_address; +dma_addr_t bus_address; +u64 vm_start; +u64 vm_end; +u32 size; +u32 id; +u32 ctx_id; +u8 mmap; +u8 is_pool; +}; + + + + + +#define HL_QUEUE_LENGTH 256@@ -109,6 +170,8 @@ enum hl_asic_type {* @sw_fini: tears down driver state, does not configure H/W. * @suspend: handles IP specific H/W or SW changes for suspend. * @resume: handles IP specific H/W or SW changes for resume. +* @mmap: mmap function, does nothing. +* @cb_mmap: maps a CB. * @dma_alloc_coherent: DMA allocate coherent memory. * @dma_free_coherent: free DMA allocation. */ @@ -119,6 +182,9 @@ struct hl_asic_funcs {int (*sw_fini)(struct hl_device *hdev);int (*suspend)(struct hl_device *hdev);int (*resume)(struct hl_device *hdev); +int (*mmap)(struct hl_fpriv *hpriv,struct vm_area_struct *vma); +int (*cb_mmap)(struct hl_device *hdev,struct vm_area_struct *vma, +u64 kaddress,phys_addr_t paddress,u32 size);void * (*dma_alloc_coherent)(struct hl_device *hdev,size_t size,dma_addr_t *dma_handle,gfp_t flag); void (*dma_free_coherent)(struct hl_device *hdev, size_t size,@@ -175,6 +241,7 @@ struct hl_ctx_mgr {* @taskpid: current process ID. * @ctx: current executing context. * @ctx_mgr: context manager to handle multiple context for this FD. +* @cb_mgr: command buffer manager to handle multiple buffers for this FD. * @refcount: number of related contexts. */ struct hl_fpriv {@@ -183,6 +250,7 @@ struct hl_fpriv {struct pid *taskpid;struct hl_ctx *ctx;/* TODO: remove for multiple ctx */ struct hl_ctx_mgr ctx_mgr; +struct hl_cb_mgr cb_mgr;struct kref refcount; };@@ -239,6 +307,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @asic_name: ASIC specific nmae. * @asic_type: ASIC specific type. * @kernel_ctx: KMD context structure. +* @kernel_cb_mgr: command buffer manager for creating/destroying/handling CGs. * @dma_pool: DMA pool for small allocations. * @cpu_accessible_dma_mem: KMD <-> ArmCP shared memory CPU address. * @cpu_accessible_dma_address: KMD <-> ArmCP shared memory DMA address. @@ -249,6 +318,8 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @asic_prop: ASIC specific immutable properties. * @asic_funcs: ASIC specific functions. * @asic_specific: ASIC specific information to use only from ASIC files. +* @cb_pool: list of preallocated CBs. +* @cb_pool_lock: protects the CB pool. * @user_ctx: current user context executing. * @fd_open_cnt: number of open context executing. * @major: habanalabs KMD major. @@ -264,6 +335,7 @@ struct hl_device {char asic_name[16 ];enum hl_asic_type asic_type;struct hl_ctx *kernel_ctx; +struct hl_cb_mgr kernel_cb_mgr;struct dma_pool *dma_pool;void *cpu_accessible_dma_mem;dma_addr_t cpu_accessible_dma_address;@@ -275,6 +347,10 @@ struct hl_device {struct asic_fixed_properties asic_prop;const struct hl_asic_funcs *asic_funcs;void *asic_specific; + +struct list_head cb_pool; +spinlock_t cb_pool_lock; +/* TODO: The following fields should be moved for multi-context */ struct hl_ctx *user_ctx;atomic_t fd_open_cnt;@@ -345,6 +421,23 @@ int hl_device_resume(struct hl_device *hdev);void hl_hpriv_get (struct hl_fpriv *hpriv);void hl_hpriv_put (struct hl_fpriv *hpriv); +int hl_cb_create (struct hl_device *hdev,struct hl_cb_mgr *mgr,u32 cb_size, +u64 *handle,int ctx_id); +int hl_cb_destroy (struct hl_device *hdev,struct hl_cb_mgr *mgr,u64 cb_handle); +int hl_cb_mmap (struct hl_fpriv *hpriv,struct vm_area_struct *vma); +struct hl_cb *hl_cb_get (struct hl_device *hdev,struct hl_cb_mgr *mgr, +u32 handle); +void hl_cb_put (struct hl_cb *cb); +void hl_cb_mgr_init (struct hl_cb_mgr *mgr); +void hl_cb_mgr_fini (struct hl_device *hdev,struct hl_cb_mgr *mgr); +struct hl_cb *hl_cb_kernel_create (struct hl_device *hdev,u32 cb_size); +int hl_cb_pool_init (struct hl_device *hdev); +int hl_cb_pool_fini (struct hl_device *hdev); +void goya_set_asic_funcs (struct hl_device *hdev); +/* IOCTLs */ +long hl_ioctl (struct file *filep,unsigned int cmd,unsigned long arg); +int hl_cb_ioctl (struct hl_fpriv *hpriv,void *data); +#endif /* HABANALABSP_H_ */ drivers/misc/habanalabs/habanalabs_drv.c +2
-0@@ -123,6 +123,7 @@ int hl_device_open(struct inode *inode, struct file *filp)kref_init (&hpriv->refcount);nonseekable_open (inode, filp); +hl_cb_mgr_init (&hpriv->cb_mgr);hl_ctx_mgr_init (&hpriv->ctx_mgr); rc =hl_ctx_create (hdev, hpriv);@@ -138,6 +139,7 @@ int hl_device_open(struct inode *inode, struct file *filp) out_err: filp->private_data =NULL ;hl_ctx_mgr_fini (hpriv->hdev, &hpriv->ctx_mgr); +hl_cb_mgr_fini (hpriv->hdev, &hpriv->cb_mgr);kfree (hpriv); close_device:drivers/misc/habanalabs/habanalabs_ioctl.c new file +26
-0@@ -0,0 +1,102 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/ + +#include <uapi/misc/habanalabs.h> +#include "habanalabs.h" + +#include <linux/fs.h> +#include <linux/uaccess.h> +#include <linux/cred.h> + +#define HL_IOCTL_DEF (ioctl, _func) \ + [_IOC_NR(ioctl)] = {.cmd = ioctl, .func = _func} + +static const struct hl_ioctl_desc hl_ioctls[] = { +HL_IOCTL_DEF (HL_IOCTL_CB , hl_cb_ioctl) +}; + +#define HL_CORE_IOCTL_COUNT ARRAY_SIZE(hl_ioctls) + +long hl_ioctl (struct file *filep,unsigned int cmd,unsigned long arg) +{ +struct hl_fpriv *hpriv = filep->private_data;
drivers/misc/habanalabs/habanalabs_ioctl.c line 36
Quoted 10 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +10
-0+struct hl_device *hdev = hpriv->hdev; +hl_ioctl_t *func; +const struct hl_ioctl_desc *ioctl =NULL ; +unsigned int nr =_IOC_NR (cmd); +char stack_kdata[128 ]; +char *kdata =NULL ; +unsigned int usize, asize; +int retcode = -EINVAL ; + +if (nr >=HL_CORE_IOCTL_COUNT )
nr > HL_CORE_IOCTL_COUNT, isn't it?
drivers/misc/habanalabs/habanalabs_ioctl.c line 37
Quoted 1 line
drivers/misc/habanalabs/habanalabs_ioctl.c new file +1
-0+ goto err_i1;
err_i1 is not very meaningfull. Maybe invalid_ioctl?
drivers/misc/habanalabs/habanalabs_ioctl.c line 39
Quoted 2 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +2
-0+ +if ((nr >=HL_COMMAND_START ) && (nr <HL_COMMAND_END )) {
The HL_COMMAND_{START,END} do not seem to be defined. Besides, this check seem to be overlapped with
if (nr > HL_CORE_IOCTL_COUNT)
Quoted 25 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +25
-0+u32 hl_size; + + ioctl = &hl_ioctls[nr]; + + hl_size =_IOC_SIZE (ioctl->cmd); + usize = asize =_IOC_SIZE (cmd); +if (hl_size > asize) + asize = hl_size; + + cmd = ioctl->cmd; + }else { + goto err_i1; + } + +/* Do not trust userspace, use our own definition */ + func = ioctl->func; + +if (unlikely (!func)) { +dev_dbg (hdev->dev,"no function\n" ); + retcode = -EINVAL ; + goto err_i1; + } + +if (cmd & (IOC_IN |IOC_OUT )) { +if (asize <=sizeof (stack_kdata)) {
drivers/misc/habanalabs/habanalabs_ioctl.c line 74
Quoted 10 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +10
-0+ kdata = stack_kdata; + }else { + kdata =kmalloc (asize,GFP_KERNEL ); +if (!kdata) { + retcode = -ENOMEM ; + goto err_i1; + } + } +if (asize > usize) +memset (kdata + usize,0 , asize - usize);
Just init stack_kdata to 0 and use kzalloc instead of malloc.
Quoted 12 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +12
-0+ } + +if (cmd &IOC_IN ) { +if (copy_from_user (kdata, (void __user *)arg, usize)) { + retcode = -EFAULT ; + goto err_i1; + } + }else if (cmd &IOC_OUT ) { +memset (kdata,0 , usize); + } + + retcode =func (hpriv, kdata);
drivers/misc/habanalabs/habanalabs_ioctl.c line 96
Quoted 10 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +10
-0+ +if (cmd &IOC_OUT ) +if (copy_to_user ((void __user *)arg, kdata, usize)) + retcode = -EFAULT ; + +err_i1: +if (!ioctl) +dev_dbg (hdev->dev, +"invalid ioctl: pid=%d, cmd=0x%02x, nr=0x%02x\n" , +task_pid_nr (current), cmd, nr);
I think this can move right after the 'nr' sanity check and there you can simple return -EINVAL after dev_dbg().
Quoted 77 lines
drivers/misc/habanalabs/habanalabs_ioctl.c new file +6
-0+ +if (kdata != stack_kdata) +kfree (kdata); + +return retcode; +}include/uapi/misc/habanalabs.h new file +62
-0@@ -0,0 +1,62 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note +* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +* Author: Oded Gabbay <[email protected]> +* +*/ + +#ifndef HABANALABS_H_ +#define HABANALABS_H_ + +#include <linux/types.h> +#include <linux/ioctl.h> + +/* Opcode to create a new command buffer */ +#define HL_CB_OP_CREATE 0 +/* Opcode to destroy previously created command buffer */ +#define HL_CB_OP_DESTROY 1 + +struct hl_cb_in { +/* Handle of CB or 0 if we want to create one */ +__u64 cb_handle; +/* HL_CB_OP_* */ +__u32 op; +/* Size of CB. Minimum requested size must be PAGE_SIZE */ +__u32 cb_size; +/* Context ID - Currently not in use */ +__u32 ctx_id; +__u32 pad; +}; + +struct hl_cb_out { +/* Handle of CB */ +__u64 cb_handle; +}; + +union hl_cb_args { +struct hl_cb_in in; +struct hl_cb_out out; +}; + +/* +* Command Buffer +* - Request a Command Buffer +* - Destroy a Command Buffer +* +* The command buffers are memory blocks that reside in DMA-able address +* space and are physically contiguous so they can be accessed by the device +* directly. They are allocated using the coherent DMA API. +* +* When creating a new CB, the IOCTL returns a handle of it, and the user-space +* process needs to use that handle to mmap the buffer so it can access them. +* +*/ +#define HL_IOCTL_CB \ + _IOWR('H', 0x02, union hl_cb_args) + +#define HL_COMMAND_START 0x02 +#define HL_COMMAND_END 0x03 + +#endif /* HABANALABS_H_ */ Signature · 1 line
2.17.1
Signature · 2 lines
Sincerely yours, Mike.
Re: [PATCH 04/15] habanalabs: add context and ASID modules
In reply to Oded GabbayQuoted 3 lines · Oded Gabbay
This patch adds two modules - ASID and context.
Each user process the opens a device's file must have at least one context
^that
Quoted 433 lines
before it is able to "work" with the device. Each context has its own device address-space and contains information about its runtime state (its active command submissions).
To have address-space separation between contexts, each context is assigned a unique ASID, which stands for "address-space id". Goya supports up to 1024 ASIDs.
Currently, the driver doesn't support multiple contexts. Therefore, the user doesn't need to actively create a context. A "primary context" is created automatically when the user opens the device's file.
Signed-off-by Oded Gabbay <[email protected]>--- drivers/misc/habanalabs/Makefile | 2 +- drivers/misc/habanalabs/asid.c | 58 +++++++++ drivers/misc/habanalabs/context.c | 155 +++++++++++++++++++++++ drivers/misc/habanalabs/device.c | 47 +++++++ drivers/misc/habanalabs/habanalabs.h | 70 ++++++++++ drivers/misc/habanalabs/habanalabs_drv.c | 46 ++++++- 6 files changed, 375 insertions(+), 3 deletions(-) create mode 100644 drivers/misc/habanalabs/asid.c create mode 100644 drivers/misc/habanalabs/context.cdrivers/misc/habanalabs/Makefile +1
-1@@ -4,7 +4,7 @@ obj-m := habanalabs.o -habanalabs-y := habanalabs_drv.o device.o +habanalabs-y := habanalabs_drv.o device.o context.o asid.o include $(src)/goya/Makefile habanalabs-y += $(HL_GOYA_FILES)drivers/misc/habanalabs/asid.c new file +58
-0@@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/ + +#include "habanalabs.h" + +#include <linux/slab.h> +#include <linux/types.h> + +int hl_asid_init (struct hl_device *hdev) +{ + hdev->asid_bitmap =kcalloc (BITS_TO_LONGS (hdev->asic_prop.max_asid), +sizeof (*hdev->asid_bitmap),GFP_KERNEL ); +if (!hdev->asid_bitmap) +return -ENOMEM ; + +mutex_init (&hdev->asid_mutex); + +/* ASID 0 is reserved for KMD */ +set_bit (0 , hdev->asid_bitmap); + +return 0 ; +} + +void hl_asid_fini (struct hl_device *hdev) +{ +mutex_destroy (&hdev->asid_mutex); +kfree (hdev->asid_bitmap); +} + +unsigned long hl_asid_alloc (struct hl_device *hdev) +{ +unsigned long found; + +mutex_lock (&hdev->asid_mutex); + + found =find_first_zero_bit (hdev->asid_bitmap, + hdev->asic_prop.max_asid); +if (found == hdev->asic_prop.max_asid) + found =0 ; +else +set_bit (found, hdev->asid_bitmap); + +mutex_unlock (&hdev->asid_mutex); + +return found; +} + +void hl_asid_free (struct hl_device *hdev,unsigned long asid) +{ +if (WARN ((asid ==0 || asid >= hdev->asic_prop.max_asid), +"Invalid ASID %lu" , asid)) +return ; +clear_bit (asid, hdev->asid_bitmap); +}drivers/misc/habanalabs/context.c new file +155
-0@@ -0,0 +1,155 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/ + +#include "habanalabs.h" + +#include <linux/sched.h> +#include <linux/delay.h> + +static void hl_ctx_fini (struct hl_ctx *ctx) +{ +struct hl_device *hdev = ctx->hdev; + +if (ctx->asid !=HL_KERNEL_ASID_ID ) +hl_asid_free (hdev, ctx->asid); +} + +void hl_ctx_do_release (struct kref *ref) +{ +struct hl_ctx *ctx; + + ctx = container_of(ref, struct hl_ctx, refcount); + +dev_dbg (ctx->hdev->dev,"Now really releasing context %d\n" , ctx->asid); + +hl_ctx_fini (ctx); + +if (ctx->hpriv) +hl_hpriv_put (ctx->hpriv); + +kfree (ctx); +} + +int hl_ctx_create (struct hl_device *hdev,struct hl_fpriv *hpriv) +{ +struct hl_ctx_mgr *mgr = &hpriv->ctx_mgr; +struct hl_ctx *ctx; +int rc; + + ctx =kzalloc (sizeof (*ctx),GFP_KERNEL ); +if (!ctx) { + rc = -ENOMEM ; + goto out_err; + } + + rc =hl_ctx_init (hdev, ctx, false); +if (rc) + goto free_ctx; + +hl_hpriv_get (hpriv); + ctx->hpriv = hpriv; + +/* TODO: remove for multiple contexts */ + hpriv->ctx = ctx; + hdev->user_ctx = ctx; + +mutex_lock (&mgr->ctx_lock); + rc =idr_alloc (&mgr->ctx_handles, ctx,1 ,0 ,GFP_KERNEL ); +mutex_unlock (&mgr->ctx_lock); + +if (rc <0 ) { +dev_err (hdev->dev,"Failed to allocate IDR for a new CTX\n" ); +hl_ctx_free (hdev, ctx); + goto out_err; + } + +return 0 ; + +free_ctx: +kfree (ctx); +out_err: +return rc; +} + +void hl_ctx_free (struct hl_device *hdev,struct hl_ctx *ctx) +{ +if (kref_put (&ctx->refcount, hl_ctx_do_release) ==1 ) +return ; + +dev_warn (hdev->dev, +"Context %d closed or terminated but its CS are executing\n" , + ctx->asid); +} + +int hl_ctx_init (struct hl_device *hdev,struct hl_ctx *ctx,bool is_kernel_ctx) +{ + ctx->hdev = hdev; + +kref_init (&ctx->refcount); + +if (is_kernel_ctx) { + ctx->asid =HL_KERNEL_ASID_ID ;/* KMD gets ASID 0 */ + }else { + ctx->asid =hl_asid_alloc (hdev); +if (!ctx->asid) { +dev_err (hdev->dev,"No free ASID, failed to create context\n" ); +return -ENOMEM ; + } + } + +dev_dbg (hdev->dev,"Created context with ASID %u\n" , ctx->asid); + +return 0 ; +} + +void hl_ctx_get (struct hl_device *hdev,struct hl_ctx *ctx) +{ +kref_get (&ctx->refcount); +} + +int hl_ctx_put (struct hl_ctx *ctx) +{ +return kref_put (&ctx->refcount, hl_ctx_do_release); +} + +/** +* hl_ctx_mgr_init - initialize the context manager +* +* @mgr: pointer to context manager structure +* +* This manager is an object inside the hpriv object of the user process. +* The function is called when a user process opens the FD. +*/ +void hl_ctx_mgr_init (struct hl_ctx_mgr *mgr) +{ +mutex_init (&mgr->ctx_lock); +idr_init (&mgr->ctx_handles); +} + +/** +* hl_ctx_mgr_fini - finalize the context manager +* +* @hdev: pointer to device structure +* @mgr: pointer to context manager structure +* +* This function goes over all the contexts in the manager and frees them. +* It is called when a process closes the FD. +*/ +void hl_ctx_mgr_fini (struct hl_device *hdev,struct hl_ctx_mgr *mgr) +{ +struct hl_ctx *ctx; +struct idr *idp; +u32 id; + + idp = &mgr->ctx_handles; + +idr_for_each_entry (idp, ctx, id) +hl_ctx_free (hdev, ctx); + +idr_destroy (&mgr->ctx_handles); +mutex_destroy (&mgr->ctx_lock); +}drivers/misc/habanalabs/device.c +47
-0@@ -23,6 +23,12 @@ static void hpriv_release(struct kref *ref)put_pid (hpriv->taskpid);kfree (hpriv); + +/* Now the FD is really closed */ +atomic_dec (&hdev->fd_open_cnt); + +/* This allows a new user context to open the device */ + hdev->user_ctx =NULL ; }void hl_hpriv_get (struct hl_fpriv *hpriv)@@ -47,6 +53,8 @@ static int hl_device_release(struct inode *inode, struct file *filp) {struct hl_fpriv *hpriv = filp->private_data; +hl_ctx_mgr_fini (hpriv->hdev, &hpriv->ctx_mgr); + filp->private_data =NULL ;hl_hpriv_put (hpriv);@@ -133,7 +141,20 @@ static int device_early_init(struct hl_device *hdev)if (rc)return rc; + rc =hl_asid_init (hdev); +if (rc) + goto early_fini; + +mutex_init (&hdev->device_open); +atomic_set (&hdev->fd_open_cnt,0 ); +return 0 ; + +early_fini: +if (hdev->asic_funcs->early_fini) + hdev->asic_funcs->early_fini (hdev); + +return rc; }/** @@ -145,9 +166,12 @@ static int device_early_init(struct hl_device *hdev)static void device_early_fini (struct hl_device *hdev) { +hl_asid_fini (hdev); +if (hdev->asic_funcs->early_fini) hdev->asic_funcs->early_fini (hdev); +mutex_destroy (&hdev->device_open); }/** @@ -241,11 +265,30 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass)if (rc) goto early_fini; +/* Allocate the kernel context */ + hdev->kernel_ctx =kzalloc (sizeof (*hdev->kernel_ctx),GFP_KERNEL ); +if (!hdev->kernel_ctx) { + rc = -ENOMEM ; + goto sw_fini; + } + + hdev->user_ctx =NULL ; + + rc =hl_ctx_init (hdev, hdev->kernel_ctx, true); +if (rc) { +dev_err (hdev->dev,"failed to initialize kernel context\n" ); + goto free_ctx; + } +dev_notice (hdev->dev,"Successfully added device to habanalabs driver\n" );return 0 ; +free_ctx: +kfree (hdev->kernel_ctx); +sw_fini: + hdev->asic_funcs->sw_fini (hdev); early_fini:device_early_fini (hdev); release_device:@@ -278,6 +321,10 @@ void hl_device_fini(struct hl_device *hdev)/* Mark device as disabled */ hdev->disabled = true; +/* Release kernel context */ +if ((hdev->kernel_ctx) && (hl_ctx_put (hdev->kernel_ctx) !=1 )) +dev_err (hdev->dev,"kernel ctx is still alive\n" ); +/* Call ASIC S/W finalize function */ hdev->asic_funcs->sw_fini (hdev);drivers/misc/habanalabs/habanalabs.h +43
-0@@ -125,6 +125,45 @@ struct hl_asic_funcs { void *cpu_addr, dma_addr_t dma_handle); }; + + + + +/* +* CONTEXTS +*/ + +#define HL_KERNEL_ASID_ID 0 + +/** +* struct hl_ctx - user/kernel context. +* @hpriv: pointer to the private (KMD) data of the process (fd). +* @hdev: pointer to the device structure. +* @refcount: reference counter for the context. Context is released only when +* this hits 0l. It is incremented on CS and CS_WAIT. +* @asid: context's unique address space ID in the device's MMU. +*/ +struct hl_ctx { +struct hl_fpriv *hpriv; +struct hl_device *hdev; +struct kref refcount; +u32 asid; +}; + +/** +* struct hl_ctx_mgr - for handling multiple contexts. +* @ctx_lock: protects ctx_handles. +* @ctx_handles: idr to hold all ctx handles. +*/ +struct hl_ctx_mgr { +struct mutex ctx_lock; +struct idr ctx_handles; +}; + + + + +/* * FILE PRIVATE STRUCTURE */ @@ -134,12 +173,16 @@ struct hl_asic_funcs {* @hdev: habanalabs device structure. * @filp: pointer to the given file structure. * @taskpid: current process ID. +* @ctx: current executing context. +* @ctx_mgr: context manager to handle multiple context for this FD. * @refcount: number of related contexts. */ struct hl_fpriv {struct hl_device *hdev;struct file *filp;struct pid *taskpid; +struct hl_ctx *ctx;/* TODO: remove for multiple ctx */ +struct hl_ctx_mgr ctx_mgr;struct kref refcount; };@@ -195,13 +238,19 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @dev: realted kernel basic device structure.
drivers/misc/habanalabs/habanalabs.h void hl_wreg(struct hl_device *hdev, u32 reg, u32 val); · line 248
Quoted 10 lines
drivers/misc/habanalabs/habanalabs.h +4
-0* @asic_name: ASIC specific nmae. * @asic_type: ASIC specific type. +* @kernel_ctx: KMD context structure. * @dma_pool: DMA pool for small allocations. * @cpu_accessible_dma_mem: KMD <-> ArmCP shared memory CPU address. * @cpu_accessible_dma_address: KMD <-> ArmCP shared memory DMA address. * @cpu_accessible_dma_pool: KMD <-> ArmCP shared memory pool. +* @asid_bitmap: holds used/available ASIDs. +* @asid_mutex: protects asid_bitmap. +* @device_open: lock for sanity checks upon FD open.
device_open is an ambiguous name for a lock
Quoted 132 lines
drivers/misc/habanalabs/habanalabs.h +23
-0* @asic_prop: ASIC specific immutable properties. * @asic_funcs: ASIC specific functions. * @asic_specific: ASIC specific information to use only from ASIC files. +* @user_ctx: current user context executing. +* @fd_open_cnt: number of open context executing. * @major: habanalabs KMD major. * @id: device minor. * @disabled: is device disabled. @@ -214,13 +263,21 @@ struct hl_device {struct device *dev;char asic_name[16 ];enum hl_asic_type asic_type; +struct hl_ctx *kernel_ctx;struct dma_pool *dma_pool;void *cpu_accessible_dma_mem;dma_addr_t cpu_accessible_dma_address;struct gen_pool *cpu_accessible_dma_pool; +unsigned long *asid_bitmap; +struct mutex asid_mutex; +/* TODO: change to rw_sem for multiple contexts (same as other IOCTL) */ +struct mutex device_open;struct asic_fixed_properties asic_prop;const struct hl_asic_funcs *asic_funcs;void *asic_specific; +/* TODO: The following fields should be moved for multi-context */ +struct hl_ctx *user_ctx; +atomic_t fd_open_cnt;u32 major;u16 id;u8 disabled;@@ -270,10 +327,23 @@ int hl_poll_timeout_memory(struct hl_device *hdev, u64 addr, u32 timeout_us,int hl_poll_timeout_device_memory (struct hl_device *hdev,void __iomem *addr,u32 timeout_us,u32 *val); +int hl_asid_init (struct hl_device *hdev); +void hl_asid_fini (struct hl_device *hdev); +unsigned long hl_asid_alloc (struct hl_device *hdev); +void hl_asid_free (struct hl_device *hdev,unsigned long asid); + +int hl_ctx_create (struct hl_device *hdev,struct hl_fpriv *hpriv); +void hl_ctx_free (struct hl_device *hdev,struct hl_ctx *ctx); +int hl_ctx_init (struct hl_device *hdev,struct hl_ctx *ctx,bool is_kernel_ctx); +int hl_ctx_put (struct hl_ctx *ctx); +void hl_ctx_mgr_init (struct hl_ctx_mgr *mgr); +void hl_ctx_mgr_fini (struct hl_device *hdev,struct hl_ctx_mgr *mgr);int hl_device_init (struct hl_device *hdev,struct class *hclass);void hl_device_fini (struct hl_device *hdev);int hl_device_suspend (struct hl_device *hdev);int hl_device_resume (struct hl_device *hdev); +void hl_hpriv_get (struct hl_fpriv *hpriv); +void hl_hpriv_put (struct hl_fpriv *hpriv);void goya_set_asic_funcs (struct hl_device *hdev);drivers/misc/habanalabs/habanalabs_drv.c +44
-2@@ -77,6 +77,7 @@ int hl_device_open(struct inode *inode, struct file *filp) {struct hl_device *hdev;struct hl_fpriv *hpriv; +int rc;mutex_lock (&hl_devs_idr_lock); hdev =idr_find (&hl_devs_idr,iminor (inode));@@ -88,9 +89,33 @@ int hl_device_open(struct inode *inode, struct file *filp)return -ENXIO ; } +mutex_lock (&hdev->device_open); + +if (hdev->disabled) { +dev_err_ratelimited (hdev->dev, +"Can't open %s because it is disabled\n" , +dev_name (hdev->dev)); +mutex_unlock (&hdev->device_open); +return -EPERM ; + } + +if (hdev->user_ctx) { +dev_info_ratelimited (hdev->dev, +"Device %s is already attached to application\n" , +dev_name (hdev->dev)); +mutex_unlock (&hdev->device_open); +return -EBUSY ; + } + +atomic_inc (&hdev->fd_open_cnt); + +mutex_unlock (&hdev->device_open); + hpriv =kzalloc (sizeof (*hpriv),GFP_KERNEL ); -if (!hpriv) -return -ENOMEM ; +if (!hpriv) { + rc = -ENOMEM ; + goto close_device; + } hpriv->hdev = hdev; filp->private_data = hpriv;@@ -98,9 +123,26 @@ int hl_device_open(struct inode *inode, struct file *filp)kref_init (&hpriv->refcount);nonseekable_open (inode, filp); +hl_ctx_mgr_init (&hpriv->ctx_mgr); + + rc =hl_ctx_create (hdev, hpriv); +if (rc) { +dev_err (hdev->dev,"Failed to open FD (CTX fail)\n" ); + goto out_err; + } + hpriv->taskpid =find_get_pid (current->pid);return 0 ; + +out_err: + filp->private_data =NULL ; +hl_ctx_mgr_fini (hpriv->hdev, &hpriv->ctx_mgr); +kfree (hpriv); + +close_device: +atomic_dec (&hdev->fd_open_cnt); +return rc; }/** Signature · 1 line
2.17.1
Signature · 2 lines
Sincerely yours, Mike.
Greg KH
maintainerRe: [PATCH 01/15] habanalabs: add skeleton driver
In reply to Mike RapoportQuoted 13 lines · Mike Rapoport
Quoted 8 lines · Oded Gabbay
+/**
+ *hl_device_release- release function for habanalabs device
+ *
+ * @inode: pointer to inode structure
+ * @filp: pointer to file structure
+ *
+ * Called when process closes an habanalabs device
+ */It's nice to see docs coming along with the codei
I have some comments for the formatting.
Quoted 8 lines
kernel-doc won't be happy about missing return value descriptions, and although they are sometimes redundant or too obvious their absence makes 'make V=1 htmldocs' really noisy.
In general, it would be nice if you could link hanabnalabs driver kernel-doc somewhere in
Documentation/run 'make V=1 htmldocs'.Quoted 1 line
+static int
hl_device_release(struct inode *inode, struct file *filp)
There's no need for kerneldoc comments for static functions, as no one can call them and they are not part of any api.
So what would be better here is to just drop the /** line and use /*
thanks,
greg k-h
Re: [PATCH 01/15] habanalabs: add skeleton driver
Quoted 21 lines · Greg KH
Quoted 20 lines · Mike Rapoport
Quoted 8 lines · Oded Gabbay
+/**
+ *hl_device_release- release function for habanalabs device
+ *
+ * @inode: pointer to inode structure
+ * @filp: pointer to file structure
+ *
+ * Called when process closes an habanalabs device
+ */It's nice to see docs coming along with the codei
I have some comments for the formatting.kernel-doc won't be happy about missing return value descriptions, and although they are sometimes redundant or too obvious their absence makes 'make V=1 htmldocs' really noisy.
In general, it would be nice if you could link hanabnalabs driver kernel-doc somewhere in
Documentation/run 'make V=1 htmldocs'.
Quoted 6 lines
Quoted 1 line
Quoted 1 line
+static int
hl_device_release(struct inode *inode, struct file *filp)There's no need for kerneldoc comments for static functions, as no one can call them and they are not part of any api.
So what would be better here is to just drop the /** line and use /*
Maybe it'd make sense to use /* for most of the comments in this driver as there are kernel-doc formatting issues in non-static functions as well, I was just too lazy to go over all of them.
Quoted 4 lines
thanks,
greg k-h
Signature · 2 lines
Sincerely yours, Mike.
Hi,
Quoted 13 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Habana is a leading startup in the emerging AI processor space and we have already started production of our first Goya inference processor PCIe card and delivered it to customers. The Goya processor silicon has been tested since June of 2018 and is production-qualified by now. The Gaudi training processor solution is slated to sample in the second quarter of 2019.
Quoted 5 lines
This patch-set contains the kernel driver for Habana's AI Processors (AIP) that are designed to accelerate Deep Learning inference and training workloads. The current version supports only the Goya processor and support for Gaudi will be upstreamed after the ASIC will be available to customers.
[...]
As others have mentioned, thanks for the amount of background and information in this patch set, it's great to see.
Some have pointed out style and formatting issues, I'm not going to do that here but I do have some higher-level comments:
- There's a whole bunch of register definition headers. Outside of
GPUs, traditionally we don't include the full sets unless they're needed in the driver since they tend to be very verbose.
- I see a good amount of HW setup code that's mostly just writing
hardcoded values to a large number of registers. I don't have any specific recommendation on how to do it better, but doing as much as possible of this through on-device firmware tends to be a little cleaner (or rather, hides it from the kernel. :). I don't know if that fits your design though.
- Are there any pointers to the userspace pieces that are used to run
on this card, or any kind of test suites that can be used when someone has the hardware and is looking to change the driver?
But, I think the largest question I have (for a broader audience) is:
I predict that we will see a handful of these kind of devices over the upcoming future -- definitely from ML accelerators but maybe also for other kinds of processing, where there's a command-based, buffer-based setup sending workloads to an offload engine and getting results back. While the first waves will all look different due to design trade-offs made in isolation, I think it makes sense to group them in one bucket instead of merging them through drivers/misc, if nothing else to encourage more cross-collaboration over time. First steps in figuring out long-term suitable frameworks is to get a survey of a few non-shared implementations.
So, I'd like to propose a drivers/accel drivers subtree, and I'd be happy to bootstrap it with a small group (@Dave Airlie: I think your input from GPU land be very useful, want to join in?). Individual drivers maintained by existing maintainers, of course.
I think it might make sense to move the CAPI/OpenCAPI drivers over as well -- not necessarily to change those drivers, but to group them with the rest as more show up.
-Olof
-Olof
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
Second, I talked to Greg a couple of weeks ago about this driver and I definitely didn't get any such requirement from him. Had I gotten such a requirement, I would have planned this differently.
Third, I think this requirement, while maybe valid for drivers that are inside an established framework with common userspace library, such as drm, doesn't apply to a standalone driver which is not part of any subsystem. There is no way that "someone" will create a userspace for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Thanks,
Oded
Quoted 27 lines · Olof Johansson
Hi,
Quoted 13 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Habana is a leading startup in the emerging AI processor space and we have already started production of our first Goya inference processor PCIe card and delivered it to customers. The Goya processor silicon has been tested since June of 2018 and is production-qualified by now. The Gaudi training processor solution is slated to sample in the second quarter of 2019.
Quoted 5 lines
This patch-set contains the kernel driver for Habana's AI Processors (AIP) that are designed to accelerate Deep Learning inference and training workloads. The current version supports only the Goya processor and support for Gaudi will be upstreamed after the ASIC will be available to customers.
[...]
As others have mentioned, thanks for the amount of background and information in this patch set, it's great to see.
Quoted 6 lines
Some have pointed out style and formatting issues, I'm not going to do that here but I do have some higher-level comments:
- There's a whole bunch of register definition headers. Outside of
GPUs, traditionally we don't include the full sets unless they're needed in the driver since they tend to be very verbose.
And it is not the entire list :)
I trimmed down the files to only the files I actually use registers from. I didn't went into those files and removed from them the registers I don't use.
I hope this isn't a hard requirement because that's really a dirty work.
Quoted 6 lines
- I see a good amount of HW setup code that's mostly just writing
hardcoded values to a large number of registers. I don't have any specific recommendation on how to do it better, but doing as much as possible of this through on-device firmware tends to be a little cleaner (or rather, hides it from the kernel. :). I don't know if that fits your design though.
This is actually not according to our design. In our design, the host driver is the "king" of the device and we prefer to have all initializations which can be done from the host to be done from the host.
I know its not a "technical" hard reason, but on the other hand, I don't think that's really something so terrible that it can't be done from the driver.
Quoted 3 lines
- Are there any pointers to the userspace pieces that are used to run
on this card, or any kind of test suites that can be used when someone has the hardware and is looking to change the driver?
Not right now. I do hope we can release a package with some pre-compiled libraries and binaries that can be used to work vs. the driver, but I don't believe it will be open-source. At least, not in 2019.
Quoted 14 lines
But, I think the largest question I have (for a broader audience) is:
I predict that we will see a handful of these kind of devices over the upcoming future -- definitely from ML accelerators but maybe also for other kinds of processing, where there's a command-based, buffer-based setup sending workloads to an offload engine and getting results back. While the first waves will all look different due to design trade-offs made in isolation, I think it makes sense to group them in one bucket instead of merging them through
drivers/misc, if nothing else to encourage more cross-collaboration over time. First steps in figuring out long-term suitable frameworks is to get a survey of a few non-shared implementations.
Quoted 8 lines
So, I'd like to propose a
drivers/acceldrivers subtree, and I'd be happy to bootstrap it with a small group (@Dave Airlie: I think your input from GPU land be very useful, want to join in?). Individual drivers maintained by existing maintainers, of course.I think it might make sense to move the CAPI/OpenCAPI drivers over as well -- not necessarily to change those drivers, but to group them with the rest as more show up.
I actually prefer not going down that path, at least not from the start. AFAIK, there is no other device driver in the kernel for AI acceleration and I don't want to presume I know all the answers for such devices.
You have said it yourself: there will be many devices and they won't be similar, at least not in the next few years. So I think that trying to setup a subsystem for this now would be a premature optimization.
Oded
Quoted 7 lines
(quoted diff) +0
-2-Olof -Olof
Quoted 30 lines · Mike Rapoport
Hi,
Quoted 23 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Habana is a leading startup in the emerging AI processor space and we have already started production of our first Goya inference processor PCIe card and delivered it to customers. The Goya processor silicon has been tested since June of 2018 and is production-qualified by now. The Gaudi training processor solution is slated to sample in the second quarter of 2019.
This patch-set contains the kernel driver for Habana's AI Processors (AIP) that are designed to accelerate Deep Learning inference and training workloads. The current version supports only the Goya processor and support for Gaudi will be upstreamed after the ASIC will be available to customers.
The Goya processor has been designed from the ground up for deep learning inference workloads. It comprises a cluster of eight fully programmable Tensor Processing Cores (TPC). The TPC core is a VLIW SIMD vector processor with ISA and hardware that was tailored to serve deep learning workloads efficiently.
[ ... ]
Quoted 7 lines
Quoted 1 line
I would appricate any feedback, question and/or review.
I've looked at the patches 1,3-5 for now, it seems patch 2 still didn't make it to lore.kernel.org.
FWIW, I think it's a good solid work, unless you spoil it in patches 6-14 ;-)
Thanks! I will go over your comments in the next few days.
Quoted 3 lines
As a general note, maybe
drivers/miscis not the most appropriate place for such a complex beast. How aboutdrivers/accelerator/ai?
I talked to Greg about it a couple of weeks ago and we both agreed that drivers/misc is the correct place for this driver, at this point in time.
I don't see any reason why it couldn't be moved later on, when there will be other drivers, but for now I just don't see the need to open a new subsystem in the kernel.
Oded
Quoted 324 lines
Quoted 316 lines
p.s. for those who prefer to clone the tree instead of looking at the emails, you can grab a copy from our company's page in GitHub:
https://github.com/HabanaAI/linux/releases/tag/hl_patchset_v1
Thanks,
OdedOded Gabbay (14):
habanalabs: add skeleton driver
habanalabs: add Goya registers header files
habanalabs: add basic Goya support
habanalabs: add context and ASID modules
habanalabs: add command buffer module
habanalabs: add basic Goya h/w initialization
habanalabs: add h/w queues module
habanalabs: add event queue and interrupts
habanalabs: add sysfs and hwmon support
habanalabs: add device reset support
habanalabs: add command submission module
habanalabs: implement INFO IOCTL
habanalabs: add debugfs support
UpdateMAINTAINERSand CREDITS with habanalabs infoOmer Shpigelman (1):
habanalabs: add virtual memory and MMU modulesCREDITS | 2 +- .../ABI/testing/debugfs-driver-habanalabs | 127 + .../ABI/testing/sysfs-driver-habanalabs | 190 + MAINTAINERS | 9 + drivers/misc/Kconfig | 1 + drivers/misc/Makefile | 1 + drivers/misc/habanalabs/Kconfig | 22 + drivers/misc/habanalabs/Makefile | 14 + drivers/misc/habanalabs/asid.c | 58 + drivers/misc/habanalabs/command_buffer.c | 425 + drivers/misc/habanalabs/command_submission.c | 799 ++ drivers/misc/habanalabs/context.c | 216 + drivers/misc/habanalabs/debugfs.c | 1069 ++ drivers/misc/habanalabs/device.c | 1097 ++ drivers/misc/habanalabs/goya/Makefile | 3 + drivers/misc/habanalabs/goya/goya.c | 6347 ++++++++++++ drivers/misc/habanalabs/goya/goyaP.h | 161 + drivers/misc/habanalabs/goya/goya_hwmgr.c | 306 + drivers/misc/habanalabs/goya/goya_security.c | 2999 ++++++ drivers/misc/habanalabs/habanalabs.h | 1464 +++ drivers/misc/habanalabs/habanalabs_drv.c | 474 + drivers/misc/habanalabs/habanalabs_ioctl.c | 237 + drivers/misc/habanalabs/hw_queue.c | 654 ++ drivers/misc/habanalabs/hwmon.c | 449 + .../include/goya/asic_reg/cpu_ca53_cfg_regs.h | 213 + .../include/goya/asic_reg/cpu_if_regs.h | 110 + .../include/goya/asic_reg/cpu_pll_regs.h | 186 + .../include/goya/asic_reg/ddr_mc_ch0_regs.h | 1158 +++ .../include/goya/asic_reg/ddr_mc_ch1_regs.h | 1158 +++ .../include/goya/asic_reg/ddr_misc_ch0_regs.h | 156 + .../include/goya/asic_reg/ddr_misc_ch1_regs.h | 156 + .../include/goya/asic_reg/dma_ch_0_regs.h | 512 + .../include/goya/asic_reg/dma_ch_1_regs.h | 512 + .../include/goya/asic_reg/dma_ch_2_regs.h | 512 + .../include/goya/asic_reg/dma_ch_3_regs.h | 512 + .../include/goya/asic_reg/dma_ch_4_regs.h | 512 + .../include/goya/asic_reg/dma_macro_regs.h | 242 + .../include/goya/asic_reg/dma_nrtr_regs.h | 380 + .../include/goya/asic_reg/dma_qm_0_regs.h | 543 + .../include/goya/asic_reg/dma_qm_1_regs.h | 543 + .../include/goya/asic_reg/dma_qm_2_regs.h | 543 + .../include/goya/asic_reg/dma_qm_3_regs.h | 543 + .../include/goya/asic_reg/dma_qm_4_regs.h | 543 + .../include/goya/asic_reg/gic_regs.h | 9079 +++++++++++++++++ .../include/goya/asic_reg/goya_blocks.h | 1372 +++ .../include/goya/asic_reg/goya_masks.h | 262 + .../include/goya/asic_reg/goya_regs.h | 119 + .../include/goya/asic_reg/ic_pll_regs.h | 186 + .../include/goya/asic_reg/mc_pll_regs.h | 186 + .../include/goya/asic_reg/mme1_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme2_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme3_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme4_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme5_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme6_rtr_regs.h | 876 ++ .../include/goya/asic_reg/mme_cmdq_regs.h | 431 + .../include/goya/asic_reg/mme_qm_regs.h | 543 + .../include/goya/asic_reg/mme_regs.h | 2422 +++++ .../include/goya/asic_reg/mmu_regs.h | 158 + .../include/goya/asic_reg/pci_nrtr_regs.h | 380 + .../include/goya/asic_reg/pcie_aux_regs.h | 476 + .../include/goya/asic_reg/pcie_dbi_regs.h | 2909 ++++++ .../goya/asic_reg/psoc_emmc_pll_regs.h | 186 + .../goya/asic_reg/psoc_global_conf_regs.h | 1119 ++ .../include/goya/asic_reg/psoc_mme_pll_regs.h | 186 + .../include/goya/asic_reg/psoc_pci_pll_regs.h | 186 + .../include/goya/asic_reg/psoc_spi_regs.h | 427 + .../goya/asic_reg/sram_y0_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y0_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y1_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y2_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y3_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y4_x4_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x0_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x1_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x2_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x3_rtr_regs.h | 215 + .../goya/asic_reg/sram_y5_x4_rtr_regs.h | 215 + .../include/goya/asic_reg/stlb_regs.h | 133 + .../include/goya/asic_reg/sync_mngr_regs.h | 4930 +++++++++ .../include/goya/asic_reg/tpc0_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc0_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc0_eml_cfg_regs.h | 580 ++ .../include/goya/asic_reg/tpc0_nrtr_regs.h | 380 + .../include/goya/asic_reg/tpc0_qm_regs.h | 543 + .../include/goya/asic_reg/tpc1_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc1_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc1_qm_regs.h | 543 + .../include/goya/asic_reg/tpc1_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc2_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc2_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc2_qm_regs.h | 543 + .../include/goya/asic_reg/tpc2_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc3_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc3_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc3_qm_regs.h | 543 + .../include/goya/asic_reg/tpc3_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc4_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc4_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc4_qm_regs.h | 543 + .../include/goya/asic_reg/tpc4_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc5_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc5_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc5_qm_regs.h | 543 + .../include/goya/asic_reg/tpc5_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc6_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc6_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc6_qm_regs.h | 543 + .../include/goya/asic_reg/tpc6_rtr_regs.h | 848 ++ .../include/goya/asic_reg/tpc7_cfg_regs.h | 2110 ++++ .../include/goya/asic_reg/tpc7_cmdq_regs.h | 431 + .../include/goya/asic_reg/tpc7_nrtr_regs.h | 380 + .../include/goya/asic_reg/tpc7_qm_regs.h | 543 + .../include/goya/asic_reg/tpc_pll_regs.h | 186 + drivers/misc/habanalabs/include/goya/goya.h | 117 + .../include/goya/goya_async_events.h | 186 + .../habanalabs/include/goya/goya_boot_if.h | 32 + .../habanalabs/include/goya/goya_packets.h | 234 + .../habanalabs/include/habanalabs_device_if.h | 397 + .../include/hw_ip/mmu/mmu_general.h | 45 + .../habanalabs/include/hw_ip/mmu/mmu_v1_0.h | 15 + drivers/misc/habanalabs/irq.c | 325 + drivers/misc/habanalabs/memory.c | 1714 ++++ drivers/misc/habanalabs/mmu.c | 604 ++ drivers/misc/habanalabs/sysfs.c | 690 ++ include/uapi/misc/habanalabs.h | 412 + 145 files changed, 99610 insertions(+), 1 deletion(-) create mode 100644 Documentation/ABI/testing/debugfs-driver-habanalabs create mode 100644 Documentation/ABI/testing/sysfs-driver-habanalabs create mode 100644 drivers/misc/habanalabs/Kconfig create mode 100644 drivers/misc/habanalabs/Makefile create mode 100644 drivers/misc/habanalabs/asid.c create mode 100644 drivers/misc/habanalabs/command_buffer.c create mode 100644 drivers/misc/habanalabs/command_submission.c create mode 100644 drivers/misc/habanalabs/context.c create mode 100644 drivers/misc/habanalabs/debugfs.c create mode 100644 drivers/misc/habanalabs/device.c create mode 100644 drivers/misc/habanalabs/goya/Makefile create mode 100644 drivers/misc/habanalabs/goya/goya.c create mode 100644 drivers/misc/habanalabs/goya/goyaP.h create mode 100644 drivers/misc/habanalabs/goya/goya_hwmgr.c create mode 100644 drivers/misc/habanalabs/goya/goya_security.c create mode 100644 drivers/misc/habanalabs/habanalabs.h create mode 100644 drivers/misc/habanalabs/habanalabs_drv.c create mode 100644 drivers/misc/habanalabs/habanalabs_ioctl.c create mode 100644 drivers/misc/habanalabs/hw_queue.c create mode 100644 drivers/misc/habanalabs/hwmon.c create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_ca53_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_if_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/cpu_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_mc_ch0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_mc_ch1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_misc_ch0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ddr_misc_ch1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_2_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_3_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_ch_4_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_macro_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_0_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_1_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_2_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_3_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/dma_qm_4_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/gic_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_blocks.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_masks.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/goya_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/ic_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme5_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme6_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mme_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/mmu_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pci_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pcie_aux_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/pcie_dbi_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_emmc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_global_conf_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_mme_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_pci_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/psoc_spi_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y0_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y1_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y2_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y3_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y4_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x0_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sram_y5_x4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/stlb_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/sync_mngr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_eml_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc0_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc1_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc2_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc3_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc4_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc5_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc6_rtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_cfg_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_cmdq_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_nrtr_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc7_qm_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/asic_reg/tpc_pll_regs.h create mode 100644 drivers/misc/habanalabs/include/goya/goya.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_async_events.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_boot_if.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_packets.h create mode 100644 drivers/misc/habanalabs/include/habanalabs_device_if.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_general.h create mode 100644 drivers/misc/habanalabs/include/hw_ip/mmu/mmu_v1_0.h create mode 100644 drivers/misc/habanalabs/irq.c create mode 100644 drivers/misc/habanalabs/memory.c create mode 100644 drivers/misc/habanalabs/mmu.c create mode 100644 drivers/misc/habanalabs/sysfs.c create mode 100644 include/uapi/misc/habanalabs.hQuoted 3 lines
--
2.17.1--
Sincerely yours,
Mike.
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.
Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.
So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
Dave.
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
-Olof
Quoted 36 lines · Oded Gabbay
Quoted 27 lines · Olof Johansson
Hi,
Quoted 13 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Habana is a leading startup in the emerging AI processor space and we have already started production of our first Goya inference processor PCIe card and delivered it to customers. The Goya processor silicon has been tested since June of 2018 and is production-qualified by now. The Gaudi training processor solution is slated to sample in the second quarter of 2019.
Quoted 5 lines
This patch-set contains the kernel driver for Habana's AI Processors (AIP) that are designed to accelerate Deep Learning inference and training workloads. The current version supports only the Goya processor and support for Gaudi will be upstreamed after the ASIC will be available to customers.
[...]
As others have mentioned, thanks for the amount of background and information in this patch set, it's great to see.
Quoted 6 lines
Some have pointed out style and formatting issues, I'm not going to do that here but I do have some higher-level comments:
- There's a whole bunch of register definition headers. Outside of
GPUs, traditionally we don't include the full sets unless they're needed in the driver since they tend to be very verbose.
Quoted 5 lines
And it is not the entire list :)
I trimmed down the files to only the files I actually use registers from. I didn't went into those files and removed from them the registers I don't use.
I hope this isn't a hard requirement because that's really a dirty work.
Yeah, it's always awkward to do this kind of cleanup. drivers/staging was created in part for allowing a driver to go through this while in-tree, if that helps.
Quoted 7 lines
Quoted 6 lines
- I see a good amount of HW setup code that's mostly just writing
hardcoded values to a large number of registers. I don't have any specific recommendation on how to do it better, but doing as much as possible of this through on-device firmware tends to be a little cleaner (or rather, hides it from the kernel. :). I don't know if that fits your design though.
Quoted 7 lines
This is actually not according to our design. In our design, the host driver is the "king" of the device and we prefer to have all initializations which can be done from the host to be done from the host.
I know its not a "technical" hard reason, but on the other hand, I don't think that's really something so terrible that it can't be done from the driver.
This is why I was asking. It makes for a lot of boilerplate in the driver, all with magic constants. They usually end up in some other layer, but they're often constants no matter what.
Quoted 8 lines
Quoted 3 lines
- Are there any pointers to the userspace pieces that are used to run
on this card, or any kind of test suites that can be used when someone has the hardware and is looking to change the driver?Not right now. I do hope we can release a package with some pre-compiled libraries and binaries that can be used to work vs. the driver, but I don't believe it will be open-source. At least, not in 2019.
See my other reply, having the lowest layer of the interface from userspace open might be an approach worth exploring.
Quoted 18 lines
Quoted 18 lines
But, I think the largest question I have (for a broader audience) is:
I predict that we will see a handful of these kind of devices over the upcoming future -- definitely from ML accelerators but maybe also for other kinds of processing, where there's a command-based, buffer-based setup sending workloads to an offload engine and getting results back. While the first waves will all look different due to design trade-offs made in isolation, I think it makes sense to group them in one bucket instead of merging them through
drivers/misc, if nothing else to encourage more cross-collaboration over time. First steps in figuring out long-term suitable frameworks is to get a survey of a few non-shared implementations.So, I'd like to propose a
drivers/acceldrivers subtree, and I'd be happy to bootstrap it with a small group (@Dave Airlie: I think your input from GPU land be very useful, want to join in?). Individual drivers maintained by existing maintainers, of course.
Quoted 8 lines
Quoted 3 lines
I think it might make sense to move the CAPI/OpenCAPI drivers over as well -- not necessarily to change those drivers, but to group them with the rest as more show up.
I actually prefer not going down that path, at least not from the start. AFAIK, there is no other device driver in the kernel for AI acceleration and I don't want to presume I know all the answers for such devices.
I'm not saying you have to have those answers, I'm just saying let's start grouping them now so we at least have one place to look at them, especially since we now have more than 2.
Quoted 3 lines
You have said it yourself: there will be many devices and they won't be similar, at least not in the next few years. So I think that trying to setup a subsystem for this now would be a premature optimization.
It is initially not about building the shared subsystem as much as grouping the general type of devices together, get someone to keep an overall view across them, and encouraging more work between vendors such as cross-review, etc.
-Olof
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So if we want any kind of freedom to play with the UAPI, enhance it or change it in anyway we must be free to build program for the device ourself.
I believe that the GPU sub-system requirement are a good guideline to follow and the only exception with drivers/ that i am aware of is the fpga. Everything else in driver as either an open source userspace, expose a common API (like network) or is so simple that anyone can write a userspace for it.
For any complex device that execute program we should really enforce the open source userspace so that we can properly audit the driver as otherwise we only have half of the story with no idea what the other half might implies.
Cheers,
Jérôme
Quoted 54 lines · Olof Johansson
Quoted 52 lines · Dave Airlie
Quoted 49 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
Quoted 8 lines
Quoted 8 lines
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
I'm willing to explain the security mechanisms we have in our device and how the driver initialize them in order to protect the host, and to isolate between users.
I've done a LOT of work on that during the design of the ASIC and I believe we have a good story there. If you want, we can go over that code and explain the architecture in more detail.
Quoted 7 lines
Quoted 7 lines
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
I understand what you are saying and I think (but I can't guarantee it yet) that I may be able to provide some minimal userspace to make sure this interface won't break.
Quoted 46 lines
Quoted 17 lines
Quoted 5 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 8 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
-Olof
As I wrote above, I do think I could provide a very low userspace piece that will contain the IOCTL facing functions and perhaps an additional test code that will show how to run some simple tests on the hardware to provide users the ability to do minimal liveness checking.
I do want to ask that it won't block the upstream process because it could take some time to provide that as I would need to split our userspace code.
I will also need to clear that internally first, but I don't see a reason why I won't be able to do that.
But before I start doing that internally, I need to have some kind of assurance I won't do that for nothing. i.e, providing this library's code will be enough to satisfy this specific requirement (I'm not talking about other stuff of course that might show up in the review).
Thanks,
Oded
Oded
Quoted 122 lines · Jerome Glisse
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Quoted 5 lines
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So actually in my case in order to exercise the IOCTL API, you can give "work" to the device that will not trigger the compute parts, but only the different queues and the DMA engines.
I think that is enough to validate that the IOCTLs won't break. All the "commands" that you can give to the queue logic (QMAN) is exposed in one of the files in the driver (goya_packets.h).
I want to stress this - To validate the IOCTLs, it is enough to do DMA work. You will use ALL the 5 IOCTLs to do just that - give work to the DMA engines.
And as I wrote to Dave, I can explain my security architecture in detail and how I make sure the programmable cores can't be used by malicious users.
And nice to hear from you Jerome :) I missed you!
Thanks,
Oded
Quoted 21 lines
So if we want any kind of freedom to play with the UAPI, enhance it or change it in anyway we must be free to build program for the device ourself.
I believe that the GPU sub-system requirement are a good guideline to follow and the only exception with
drivers/that i am aware of is the fpga. Everything else in driver as either an open source userspace, expose a common API (like network) or is so simple that anyone can write a userspace for it.For any complex device that execute program we should really enforce the open source userspace so that we can properly audit the driver as otherwise we only have half of the story with no idea what the other half might implies.
Cheers,
Jérôme
Quoted 132 lines · Jerome Glisse
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So if we want any kind of freedom to play with the UAPI, enhance it or change it in anyway we must be free to build program for the device ourself.
Quoted 5 lines
I believe that the GPU sub-system requirement are a good guideline to follow and the only exception with
drivers/that i am aware of is the fpga. Everything else in driver as either an open source userspace, expose a common API (like network) or is so simple that anyone can write a userspace for it.
Once we have a common framework I agree that we need enough tools to exercise everything needed. I don't agree that this includes full sources to everything. We don't expect this for most PCIe cards today either.
If the GPU subsystem is to be followed, I fear that we will end up with Nvidia-equivalent vendors from day 1, where they will just build a bigger and bigger software stack on the side instead of joining in, and someone will need to best-effort bridge the gap by reverse engineering. I don't want that situation long-term, which is why I think it's reasonable to be more relaxed during the early days with upfront, clear, expectations for the longer term that hardware/kernel interfaces need to be exercisable.
Quoted 4 lines
For any complex device that execute program we should really enforce the open source userspace so that we can properly audit the driver as otherwise we only have half of the story with no idea what the other half might implies.
What you're demanding is open userspace _and_ firmware. Since without firmware sources, you can't audit any on-chip behavior either (in reality, most commands passed down are likely parsed by said firmware).
-Olof
Quoted 137 lines · Oded Gabbay
Quoted 122 lines · Jerome Glisse
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Quoted 5 lines
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So actually in my case in order to exercise the IOCTL API, you can give "work" to the device that will not trigger the compute parts, but only the different queues and the DMA engines.
I think that is enough to validate that the IOCTLs won't break. All the "commands" that you can give to the queue logic (QMAN) is exposed in one of the files in the driver (goya_packets.h).
Quoted 3 lines
I want to stress this - To validate the IOCTLs, it is enough to do DMA work. You will use ALL the 5 IOCTLs to do just that - give work to the DMA engines.
I personally think this is a reasonable trade-off, given that you have a communication layer between. For hardware that doesn't have that, and where device behavior and data movement depends on execution on the compute parts, more would need to be open.
-Olof
Quoted 139 lines · Olof Johansson
Quoted 132 lines · Jerome Glisse
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So if we want any kind of freedom to play with the UAPI, enhance it or change it in anyway we must be free to build program for the device ourself.
Quoted 5 lines
I believe that the GPU sub-system requirement are a good guideline to follow and the only exception with
drivers/that i am aware of is the fpga. Everything else in driver as either an open source userspace, expose a common API (like network) or is so simple that anyone can write a userspace for it.
Quoted 4 lines
Once we have a common framework I agree that we need enough tools to exercise everything needed. I don't agree that this includes full sources to everything. We don't expect this for most PCIe cards today either.
We do expected this today except for FPGA, i do not know any single pcie device with upstream driver that we do not know how to program. Biggest chunk of PCIE devices are straightforward (network, sound, media, ...).
So in effect today the lowest common denominator is open source user space or device API is so simple that user space is obvious (various media device).
Quoted 9 lines
If the GPU subsystem is to be followed, I fear that we will end up with Nvidia-equivalent vendors from day 1, where they will just build a bigger and bigger software stack on the side instead of joining in, and someone will need to best-effort bridge the gap by reverse engineering. I don't want that situation long-term, which is why I think it's reasonable to be more relaxed during the early days with upfront, clear, expectations for the longer term that hardware/kernel interfaces need to be exercisable.
I think the other way around, allowing people to push upstream driver with no open source user space and people loose any motivation to work on open sourcing their userspace. Not being upstream is painful enough that they will get pressure to go upstream and if upstream means open source userspace then they have to comply.
Quoted 10 lines
Quoted 5 lines
For any complex device that execute program we should really enforce the open source userspace so that we can properly audit the driver as otherwise we only have half of the story with no idea what the other half might implies.
What you're demanding is open userspace _and_ firmware. Since without firmware sources, you can't audit any on-chip behavior either (in reality, most commands passed down are likely parsed by said firmware).
No i do not ask for firmware. If we have any doubt about what the firm- ware can let through then we can lock down the ioctl ie parse commands from userspace and only allow kernel to write sanitize command to command queue. By auditing here i mean being able to understand the overall flow that is expected from program so from that program flow we can work on what is the best UAPI with minimum overhead to achieve that program flow the most efficiently. Sorry if that was not clear.
Cheers,
Jérôme
Quoted 13 lines · Olof Johansson
But, I think the largest question I have (for a broader audience) is:
I predict that we will see a handful of these kind of devices over the upcoming future -- definitely from ML accelerators but maybe also for other kinds of processing, where there's a command-based, buffer-based setup sending workloads to an offload engine and getting results back. While the first waves will all look different due to design trade-offs made in isolation, I think it makes sense to group them in one bucket instead of merging them through
drivers/misc, if nothing else to encourage more cross-collaboration over time. First steps in figuring out long-term suitable frameworks is to get a survey of a few non-shared implementations.
Quoted 8 lines
So, I'd like to propose a
drivers/acceldrivers subtree, and I'd be happy to bootstrap it with a small group (@Dave Airlie: I think your input from GPU land be very useful, want to join in?). Individual drivers maintained by existing maintainers, of course.I think it might make sense to move the CAPI/OpenCAPI drivers over as well -- not necessarily to change those drivers, but to group them with the rest as more show up.
For cxl/ocxl, I have no objection to moving to this new subtree if that's what we all agree to do. (what do people do about UAPI headers in this situation? keep them where they are in misc/?)
If we do go ahead and set up this new subtree, perhaps we can use the mailing list I set up at [email protected] but we haven't really started using...
Signature · 2 lines
Andrew Donnellan OzLabs, ADL Canberra [email protected] IBM Australia Limited
Hi all,
Top post, because new argument.
There's lots of really good technical arguments for having the userspace component of a driver stack that spans both kernel and userspace open too. For me, that's not really the important argument.
I care about open source, I'm not interested in blobs (beyond that they're useful for reverse engineering). I think the upstream community should care about open source, and by and large it very much
does: We haven't merged ndiswrapper, or the nvidia shim, or anything like that to make running blobs in the kernel easier. And at least in the case of the one traditional driver subsystem where 90% of the driver lives in userspace, we also care about that part being open.
Anything else is imo just a long-term dis-service to the community of customers, other vendors, ... Adapting a famous quote: If you're ok with throwing away some long term software freedom for a bit of short term hardware support you'll get neither.
So if someone propose to merge some open source kernel driver that requires piles of closed source userspace to be any use at all, I'm just not interested. And if the fpga folks have merged fpga drivers without at least a basic (non-optimizing) RTL compiler, then that was a grave mistake. That doing this is also technically a bad idea (for all the reasons already discussed) is just the icing on the top for me.
And to tie this back to the technical discussion, here's a scenario that's bound to happen:
1. vendor crams their open source driver into upstream, with full blob userspace
2. vendor gets bored (runs low on money, accidentally fired the entire old team, needs to do more value add, whatever, ...) rewrites the entire stack
3. vendor crams their new&completely incompatible open source stack into upstream
4. upstream is now unvoluntarily stuck maintaining 2 drivers for the exact same thing, and we can't fix anything of that because if you touch one side of the stack without undertstanding the other part you're guaranteed to create regressions (yes this is how this works with gpu drivers, we've learned this the hard way)
5. repeat
Hence for these technical reasons you'll then end up with a subsystem that only the vendor can touch, and hence also the vendor can abandon at will. Not like drivers/gpu, where customers, consulting shops, students, ... routinely can&do add new features to existing drivers.
This is not a winning move.
Cheers, Daniel
Quoted 192 lines · Jerome Glisse
Quoted 139 lines · Olof Johansson
Quoted 132 lines · Jerome Glisse
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So if we want any kind of freedom to play with the UAPI, enhance it or change it in anyway we must be free to build program for the device ourself.
Quoted 5 lines
I believe that the GPU sub-system requirement are a good guideline to follow and the only exception with
drivers/that i am aware of is the fpga. Everything else in driver as either an open source userspace, expose a common API (like network) or is so simple that anyone can write a userspace for it.Quoted 4 lines
Once we have a common framework I agree that we need enough tools to exercise everything needed. I don't agree that this includes full sources to everything. We don't expect this for most PCIe cards today either.
We do expected this today except for FPGA, i do not know any single pcie device with upstream driver that we do not know how to program. Biggest chunk of PCIE devices are straightforward (network, sound, media, ...).
So in effect today the lowest common denominator is open source user space or device API is so simple that user space is obvious (various media device).
Quoted 9 lines
If the GPU subsystem is to be followed, I fear that we will end up with Nvidia-equivalent vendors from day 1, where they will just build a bigger and bigger software stack on the side instead of joining in, and someone will need to best-effort bridge the gap by reverse engineering. I don't want that situation long-term, which is why I think it's reasonable to be more relaxed during the early days with upfront, clear, expectations for the longer term that hardware/kernel interfaces need to be exercisable.
I think the other way around, allowing people to push upstream driver with no open source user space and people loose any motivation to work on open sourcing their userspace. Not being upstream is painful enough that they will get pressure to go upstream and if upstream means open source userspace then they have to comply.
Quoted 10 lines
Quoted 5 lines
For any complex device that execute program we should really enforce the open source userspace so that we can properly audit the driver as otherwise we only have half of the story with no idea what the other half might implies.
What you're demanding is open userspace _and_ firmware. Since without firmware sources, you can't audit any on-chip behavior either (in reality, most commands passed down are likely parsed by said firmware).
No i do not ask for firmware. If we have any doubt about what the firm- ware can let through then we can lock down the ioctl ie parse commands from userspace and only allow kernel to write sanitize command to command queue. By auditing here i mean being able to understand the overall flow that is expected from program so from that program flow we can work on what is the best UAPI with minimum overhead to achieve that program flow the most efficiently. Sorry if that was not clear.
Cheers,
Jérôme
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Hi Daniel and Jerome,
I know I won't be able to convince you but I want to say that I think your arguments for full userspace open source are not really technical.
IMHO, an open-source, thin runtime that provides code to operate ALL the uAPI the driver exports + commitment to only using this library as the interface to the driver is good enough for the issue of uAPI breakage. And that thing I can provide.
If at a later time habana will decide to throw it all away (not going to happen while I'm here), then its habana's problem. Not the kernel. In that case, I would argue that the kernel shouldn't accept a new driver from habana. But as long as we keep API compatibility, I don't see any harm.
I'm not convinced by your request to open the ISA of the programmable cores. How is that relevant to the kernel driver. I don't even do anything with those cores. The uAPI I export isn't related whatsoever to those cores.
I honestly think that if your position is accepted by the Linux kernel community, companies building AI accelerators won't go near the kernel. They will simply go down the path Nvidia has gone, which is to have an out-of-tree kernel driver + big closed userspace. That's a totally sustainable path from business POV (see Nvidia's dominance in GPU and deep learning). I don't see how that will serve any of us. I would think we want to lure companies into open sourcing their code, and you don't do that by saying: "if you don't open your entire code base, don't bother to open any part of it".
Thanks,
Oded
Quoted 254 lines · Daniel Vetter
Hi all,
Top post, because new argument.
There's lots of really good technical arguments for having the userspace component of a driver stack that spans both kernel and userspace open too. For me, that's not really the important argument.
I care about open source, I'm not interested in blobs (beyond that they're useful for reverse engineering). I think the upstream community should care about open source, and by and large it very much
does: We haven't merged ndiswrapper, or the nvidia shim, or anything like that to make running blobs in the kernel easier. And at least in the case of the one traditional driver subsystem where 90% of the driver lives in userspace, we also care about that part being open.Anything else is imo just a long-term dis-service to the community of customers, other vendors, ... Adapting a famous quote: If you're ok with throwing away some long term software freedom for a bit of short term hardware support you'll get neither.
So if someone propose to merge some open source kernel driver that requires piles of closed source userspace to be any use at all, I'm just not interested. And if the fpga folks have merged fpga drivers without at least a basic (non-optimizing) RTL compiler, then that was a grave mistake. That doing this is also technically a bad idea (for all the reasons already discussed) is just the icing on the top for me.
And to tie this back to the technical discussion, here's a scenario that's bound to happen:
1. vendor crams their open source driver into upstream, with full blob userspace
2. vendor gets bored (runs low on money, accidentally fired the entire old team, needs to do more value add, whatever, ...) rewrites the entire stack
3. vendor crams their new&completely incompatible open source stack into upstream
4. upstream is now unvoluntarily stuck maintaining 2 drivers for the exact same thing, and we can't fix anything of that because if you touch one side of the stack without undertstanding the other part you're guaranteed to create regressions (yes this is how this works with gpu drivers, we've learned this the hard way)
5. repeatHence for these technical reasons you'll then end up with a subsystem that only the vendor can touch, and hence also the vendor can abandon at will. Not like
drivers/gpu, where customers, consulting shops, students, ... routinely can&do add new features to existing drivers.This is not a winning move.
Cheers, Daniel
Quoted 190 lines · Jerome Glisse
Quoted 139 lines · Olof Johansson
Quoted 132 lines · Jerome Glisse
Quoted 114 lines · Olof Johansson
Quoted 84 lines · Dave Airlie
Quoted 41 lines · Oded Gabbay
Quoted 34 lines · Dave Airlie
Adding Daniel as well.
Dave.
Quoted 28 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
Having large closed userspaces that we have no insight into means we get suboptimal locked for ever uAPIs. If someone in the future creates an open source userspace, we will end up in a place where they get suboptimal behaviour because they are locked into a uAPI that we can't change.
Dave.
Hi Dave,
While I always appreciate your opinion and happy to hear it, I totally disagree with you on this point.Quoted 8 lines
First of all, as you said, this device is NOT a GPU. Hence, I wasn't aware that this rule might apply to this driver or to any other driver outside of drm. Has this rule been applied to all the current drivers in the kernel tree with userspace facing API via IOCTLs, which are not in the drm subsystem ? I see the logic for GPUs as they drive the display of the entire machine, but this is an accelerator for a specific purpose, not something generic as GPU. I just don't see how one can treat them in the same way.
The logic isn't there for GPUs for those reason that we have an established library or that GPUs are in laptops. They are just where we learned the lessons of merging things whose primary reason for being in the kernel is to execute stuff from misc userspace stacks, where the uAPI has to remain stable indefinitely.
a) security - without knowledge of what the accelerator can do how can we know if the API you expose isn't just a giant root hole?
b) uAPI stability. Without a userspace for this, there is no way for anyone even if in possession of the hardware to validate the uAPI you provide and are asking the kernel to commit to supporting indefinitely is optimal or secure. If an open source userspace appears is it to be limited to API the closed userspace has created. It limits the future unnecessarily.
Quoted 4 lines
There is no way that "someone" will create a userspace
for our H/W without the intimate knowledge of the H/W or without the ISA of our programmable cores. Maybe for large companies this request is valid, but for startups complying to this request is not realistic.So what benefit does the Linux kernel get from having support for this feature upstream?
If users can't access the necessary code to use it, why does this require to be maintained in the kernel.
Quoted 4 lines
To conclude, I think this approach discourage other companies from open sourcing their drivers and is counter-productive. I'm not sure you are aware of how difficult it is to convince startup management to opensource the code...
Quoted 7 lines
Oh I am, but I'm also more aware how quickly startups go away and leave the kernel holding a lot of code we don't know how to validate or use.
I'm opening to being convinced but I think defining new userspace facing APIs is a task that we should take a lot more seriously going forward to avoid mistakes of the past.
I think the most important thing here is to know that things are likely to change quite a bit over the next couple of years, and that we don't know yet what we actually need. If we hold off picking up support for hardware while all of this is ironed out, we'll miss out on being exposed to it, and will have a very tall hill to climb once we try to convince vendors to come into the fold. It's also not been a requirement for the other two drivers we have merged, as far as I can tell (CAPI and OpenCAPI) so the cat's already out of the bag.
I'd rather not get stuck in a stand-off needing the longterm solution to pick up the short term contribution. That way we can move over to a _new_ API once there's been a better chance of finding common grounds and once things settle down a bit, instead of trying to bring some larger legacy codebase for devices that people might no longer care much about over to the newer APIs.
It's better to be exposed to the HW and drivers now, than having people build large elaborate out-of-tree software stacks for this. It's also better to get them to come and collaborate now, instead of pushing them away until things are perfect.
Quoted 5 lines
Having a way to validate and exercise the userspace API is important, including ability to change it if needed. Would it be possible to open up the lowest userspace pieces (driver interactions), even if some other layers might not yet be, to exercise the device/kernel/userspace interfaces without "live" workload, etc?
Yes and to exercise the userspace API you need at very least to know the ISA so that you can write program for the accelerator. You also need to know the set of commands the hardware has. The ioctl and how to create a userspace that interact with the kernel is the easy part, the hard part is the compiler.
So if we want any kind of freedom to play with the UAPI, enhance it or change it in anyway we must be free to build program for the device ourself.
Quoted 5 lines
I believe that the GPU sub-system requirement are a good guideline to follow and the only exception with
drivers/that i am aware of is the fpga. Everything else in driver as either an open source userspace, expose a common API (like network) or is so simple that anyone can write a userspace for it.Quoted 4 lines
Once we have a common framework I agree that we need enough tools to exercise everything needed. I don't agree that this includes full sources to everything. We don't expect this for most PCIe cards today either.
We do expected this today except for FPGA, i do not know any single pcie device with upstream driver that we do not know how to program. Biggest chunk of PCIE devices are straightforward (network, sound, media, ...).
So in effect today the lowest common denominator is open source user space or device API is so simple that user space is obvious (various media device).
Quoted 9 lines
If the GPU subsystem is to be followed, I fear that we will end up with Nvidia-equivalent vendors from day 1, where they will just build a bigger and bigger software stack on the side instead of joining in, and someone will need to best-effort bridge the gap by reverse engineering. I don't want that situation long-term, which is why I think it's reasonable to be more relaxed during the early days with upfront, clear, expectations for the longer term that hardware/kernel interfaces need to be exercisable.
I think the other way around, allowing people to push upstream driver with no open source user space and people loose any motivation to work on open sourcing their userspace. Not being upstream is painful enough that they will get pressure to go upstream and if upstream means open source userspace then they have to comply.
Quoted 10 lines
Quoted 5 lines
For any complex device that execute program we should really enforce the open source userspace so that we can properly audit the driver as otherwise we only have half of the story with no idea what the other half might implies.
What you're demanding is open userspace _and_ firmware. Since without firmware sources, you can't audit any on-chip behavior either (in reality, most commands passed down are likely parsed by said firmware).
No i do not ask for firmware. If we have any doubt about what the firm- ware can let through then we can lock down the ioctl ie parse commands from userspace and only allow kernel to write sanitize command to command queue. By auditing here i mean being able to understand the overall flow that is expected from program so from that program flow we can work on what is the best UAPI with minimum overhead to achieve that program flow the most efficiently. Sorry if that was not clear.
Quoted 2 lines
Cheers,
Jérôme--
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Quoted 3 lines
I know I won't be able to convince you but I want to say that I think your arguments for full userspace open source are not really technical.
There is more to keeping a kernel going than technical argument unfortunately.
I guess the question for Greg, Olof etc, is do we care about Linux the kernel, or Linux the open source ecosystem, if the former, these sort of accelerator shim drivers are fine, useless to anyone who doesn't have all the magic hidden userspace, and impossible to support for anyone else, if the latter, we should leave the cost of maintenance to the company benefiting from it and leave maintaining it out of tree.
Simple question like If I plug your accelerator into Power or ARM64, where do I get the port of your userspace to use it?
I'm not the final arbiter on this sort of thing, but I'm definitely going to make sure that anyone who lands this code is explicit in ignoring any experience we've had in this area and in the future will gladly accept "I told you so" :-)
Dave.
Quoted 23 lines · On Thu, 24 Jan 2019 12:03:06 +1100 Andrew Donnellan…
Quoted 13 lines · Olof Johansson
But, I think the largest question I have (for a broader audience) is:
I predict that we will see a handful of these kind of devices over the upcoming future -- definitely from ML accelerators but maybe also for other kinds of processing, where there's a command-based, buffer-based setup sending workloads to an offload engine and getting results back. While the first waves will all look different due to design trade-offs made in isolation, I think it makes sense to group them in one bucket instead of merging them through
drivers/misc, if nothing else to encourage more cross-collaboration over time. First steps in figuring out long-term suitable frameworks is to get a survey of a few non-shared implementations.Quoted 8 lines
So, I'd like to propose a
drivers/acceldrivers subtree, and I'd be happy to bootstrap it with a small group (@Dave Airlie: I think your input from GPU land be very useful, want to join in?). Individual drivers maintained by existing maintainers, of course.I think it might make sense to move the CAPI/OpenCAPI drivers over as well -- not necessarily to change those drivers, but to group them with the rest as more show up.
Quoted 8 lines
For cxl/ocxl, I have no objection to moving to this new subtree if that's what we all agree to do. (what do people do about UAPI headers in this situation? keep them where they are in misc/?)
If we do go ahead and set up this new subtree, perhaps we can use the mailing list I set up at [email protected] but we haven't really started using...
Assuming the concensus falls behind this...
I'll push this for the CCIX drivers as well as those start to turn up.
This particularly driver had passed me by until this email so great to get the heads up via that list!
Sounds like a good plan in general to me.
Jonathan
Hi,
Quoted 4 lines · Daniel Vetter
Hi all,
Top post, because new argument.
I'm diving in and replying to this instead of other replies upthread, since I think it brings up the core of the disagreement.
Quoted 11 lines
There's lots of really good technical arguments for having the userspace component of a driver stack that spans both kernel and userspace open too. For me, that's not really the important argument.
I care about open source, I'm not interested in blobs (beyond that they're useful for reverse engineering). I think the upstream community should care about open source, and by and large it very much
does: We haven't merged ndiswrapper, or the nvidia shim, or anything like that to make running blobs in the kernel easier. And at least in the case of the one traditional driver subsystem where 90% of the driver lives in userspace, we also care about that part being open.
Nobody is talking about merging kernel blobs. I think we're all in agreement that it's absolutely out of question.
Traditionally, nearly all hardware has had closed firmware as well, and if anything affects how we are tied down on making kernel-level changes, this is a big one. What makes userspace different from that perspective? Why do we have that double standard?
The question is if we're looking to alienate vendors and create a whole new set of Nvidia-style driver stacks that will grow and grow, or if we're willing to discuss with them and get them involved now, to a point where we can come up with a reasonable, standardized/extensible interface between upper levels of device FW, through kernel and into low-level userspace. Getting them to separate out the low-level portions of their software stacks to something that is open is a medium-term good compromise in this direction (ideally they might end up sharing this layer too, but that's not on me to decide). Most of these pieces of hardware work in similar manners; a stream of commands with data, and a stream of completions/results/output data.
I'm incredibly impressed by how much of the graphics stack is open, and how much of it has been reverse engineered for the closed platforms. But if we have a chance to do it differently here, and in particular avoid the long cycle of alienating the vendors and encouraging them to build out-of-tree elaborate stacks for later reverse engineering and catch-up, I would really like to.
There's currently one large benefit between these drivers and the graphics space as far as I know; nobody's trying to do unified drivers between Linux and other OS:es, so the whole "we need a messy shim layer and a universal driver" situation should be avoidable (and to be clear, we would not accept such drivers no matter what).
Quoted 4 lines
Anything else is imo just a long-term dis-service to the community of customers, other vendors, ... Adapting a famous quote: If you're ok with throwing away some long term software freedom for a bit of short term hardware support you'll get neither.
The argument here is not "short term hardware support", since that's not what we're adding (since you need more than the kernel pieces for that). What we're able to do is collaborate instead of having all these vendors work out-of-tree on their own with absolutely no discussions with us at all, and nowhere to share their work without setting up some new organization (with all the overhead from that). I think getting people to collaborate in-tree is the best shot we have at success.
Quoted 8 lines
So if someone propose to merge some open source kernel driver that requires piles of closed source userspace to be any use at all, I'm just not interested. And if the fpga folks have merged fpga drivers without at least a basic (non-optimizing) RTL compiler, then that was a grave mistake. That doing this is also technically a bad idea (for all the reasons already discussed) is just the icing on the top for me.
Quoted 14 lines
And to tie this back to the technical discussion, here's a scenario that's bound to happen:
1. vendor crams their open source driver into upstream, with full blob userspace
2. vendor gets bored (runs low on money, accidentally fired the entire old team, needs to do more value add, whatever, ...) rewrites the entire stack
3. vendor crams their new&completely incompatible open source stack into upstream
4. upstream is now unvoluntarily stuck maintaining 2 drivers for the exact same thing, and we can't fix anything of that because if you touch one side of the stack without undertstanding the other part you're guaranteed to create regressions (yes this is how this works with gpu drivers, we've learned this the hard way)
5. repeat
This can be avoided, in that we would not allow second completely separate stacks. We should have a transition point where we don't allow one-off weird custom drivers in the future, but we don't know what the shared implementation will look like yet.
We have precedence from the wifi space, where we pushed back and got vendors to move towards shared interfaces.
Quoted 6 lines
Hence for these technical reasons you'll then end up with a subsystem that only the vendor can touch, and hence also the vendor can abandon at will. Not like
drivers/gpu, where customers, consulting shops, students, ... routinely can&do add new features to existing drivers.This is not a winning move.
It depends on what the goal is. Complete software freedom? I agree, this might not get us much closer to that (but also not further). And if that's the goal, we should refuse to merge any driver that doesn't have open device firmware as well. Why would we have double standards in this area? Why are we allowing libusb to implement proprietary userspace drivers?
So, let's loop back to the technical arguments instead.
What we want from a technical goal is to avoid broad proliferation of completely separate out-of-tree software stacks, and get people to collaborate and benefit from each others work in ways that we can still change things over time where we need to from the kernel side. Is anyone disagreeing with that (technical) goal?
Unless there's disagreement on the goal, where the views differ is on how to get there -- whether we are better of pretending that this hardware doesn't exist, and try to come up with some elaborate shared framework that nobody is using yet, with the hopes that vendors will move over from their proprietary stack once they've already been successful in shipping that. Or whether we're better off getting them engaged with us, picking up their drivers for the early hardware and we all get exposure to the stacks and keep communication channels open with clear understanding that we expect this engagement to shift over time.
Since we're starting fresh here, we can set our own expectations
upfront: No second implementations unless they're onto a shared framework, and we can even preserve the right to remove hardware support (treat it as staging drivers) if a vendor disengages and goes away, or if promises in other areas are broken (such as open low-level userspace).
-Olof
Quoted 5 lines · Dave Airlie
Quoted 4 lines
I know I won't be able to convince you but I want to say that I think your arguments for full userspace open source are not really technical.
Quoted 8 lines
There is more to keeping a kernel going than technical argument unfortunately.
I guess the question for Greg, Olof etc, is do we care about Linux the kernel, or Linux the open source ecosystem, if the former, these sort of accelerator shim drivers are fine, useless to anyone who doesn't have all the magic hidden userspace, and impossible to support for anyone else, if the latter, we should leave the cost of maintenance to the company benefiting from it and leave maintaining it out of tree.
As mentioned in my reply to Daniel, I think we've got a history of being pragmatic and finding reasonable trade-offs of what can be open and what can be closed. For example, if truly care about open source ecosystem, drivers that require closed firmware should also be refused.
Quoted 2 lines
Simple question like If I plug your accelerator into Power or ARM64, where do I get the port of your userspace to use it?
Does demanding complete open userspace get us closer to that goal in reality? By refusing to work with people to enable their hardware, they will still ship their platforms out of tree, using DKMS and all the other ways of getting kernel modules installed to talk to the hardware. And we'd be no closer.
In the end, they'd open up their userspace when there's business reasons to do so. It's well-known how to work around refusal from us to merge drivers by now, so it's not much leverage in that area.
Quoted 4 lines
I'm not the final arbiter on this sort of thing, but I'm definitely going to make sure that anyone who lands this code is explicit in ignoring any experience we've had in this area and in the future will gladly accept "I told you so" :-)
There's only one final arbiter on any inclusion to code to the kernel, but we tend to sort out most disagreements without going all the way there.
I still think engaging has a better chance of success than rejecting the contributions, especially with clear expectations w.r.t. continued engagement and no second implementations over time. In all honestly, either approach might fail miserably.
-Olof
Greg Kroah-Hartman
maintainerQuoted 15 lines · Dave Airlie
Quoted 6 lines · Oded Gabbay
Hello,
For those who don't know me, my name is Oded Gabbay (Kernel Maintainer for AMD's amdkfd driver, worked at RedHat's Desktop group) and I work at Habana Labs since its inception two and a half years ago.
Hey Oded,
So this creates a driver with a userspace facing API via ioctls. Although this isn't a "GPU" driver we have a rule in the graphics drivers are for accelerators that we don't merge userspace API with an appropriate userspace user.
Quoted 4 lines
https://dri.freedesktop.org/docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements
I see nothing in these accelerator drivers that make me think we should be treating them different.
I understand that this is your position on when you accept drivers into the DRM layer, as you need to interact with common interfaces and a massive userspace stack at the same time. And that's wonderful, it allows you to be able to move both sides of that stack forward without removing support for devices that worked on older kernels.
But, that's not really the case with this new driver at all. We add new driver subsystems, and individual drivers, with loads of new ioctls, in every new kernel release. We don't impose on all of them the "your userspace code must be open" rule, so why is this new driver somehow different from them?
Yes, there is the fun legal issue of "derivative works" when talking about a userspace program that is written to only interact with a specific kernel driver using a custom api like this one has, and how the license of the kernel side (GPLv2) affects the userspace side (whatever), but that is something that I leave up to the lawyers who like discussing and enforcing such things.
When evaluating this driver (note, I saw it for a few revisions before Oded posted it here), all I did was try to make sure that it fit in properly with the kernel apis and methods of operations. Given that there are no in-kernel drivers for this type of device, and that it really is a pretty small shim layer around the hardware, which means that userspace does a lot of the heavy lifting, it is going to be a very hardware-specific user/kernel api, and that shows.
Sidenote, this could have almost just been a UIO driver, which would have put _ALL_ of the logic in userspace. At least this way we have a chance for the kernel code to be sane and not try to inflict problems on the rest of the system.
Going forward, it would be wonderful if we could come up with a unified api for how to interact with these types of hardware accelerators, but given the newness of this industry, and the vastly different ways people are trying to solve the problem, that is going to take a few attempts, and many years before we can get there. Until then, taking drivers like this into the kernel tree makes sense as that way all of our users will be able to use that hardware, and better yet, the rest of us can learn more about how this stuff works so that we can help out with that api generation when it happens.
So for now, I have no objection to taking this type of driver into the tree. Yes, it would be wonderful if we had an open userspace program to drive it so that we could actually test and make changes to the api over time, but I think that is something that the submitting company needs to realize will be better for them to do, as for right now, all of that testing and changes are their responsibility.
As for what directory the code should live in, I suggested "misc" as there was no other universal location, and I hate to see new subsystems be created with only one driver, as that's pretty sad. But it's just a name/location, I have no dog in the fight, so I really don't care where it ends up in the tree, just as long as it gets merged somewhere :)
thanks,
greg k-h
Quoted 16 lines · Olof Johansson
Quoted 5 lines · Dave Airlie
Quoted 4 lines
I know I won't be able to convince you but I want to say that I think your arguments for full userspace open source are not really technical.
Quoted 8 lines
There is more to keeping a kernel going than technical argument unfortunately.
I guess the question for Greg, Olof etc, is do we care about Linux the kernel, or Linux the open source ecosystem, if the former, these sort of accelerator shim drivers are fine, useless to anyone who doesn't have all the magic hidden userspace, and impossible to support for anyone else, if the latter, we should leave the cost of maintenance to the company benefiting from it and leave maintaining it out of tree.
Quoted 5 lines
As mentioned in my reply to Daniel, I think we've got a history of being pragmatic and finding reasonable trade-offs of what can be open and what can be closed. For example, if truly care about open source ecosystem, drivers that require closed firmware should also be refused.
Firmware has traditionally been different since usually it's looked down, doesn't do much wrt functionality (dumb fifo scheduling at best, not really power management) and so could be reasonably shrugged off as "it's part of hw". If you care about the open graphics ecosystem, i.e. your ability to port the stack to new cpu architectures, new window systems (e.g. android -> xorg, or xorg -> android, or something entirely new like wayland), new, more efficient client interface (vulkan is a very new fad), then having a closed firmware is not going to be a problem. Closed compiler, closed runtime, closed anything else otoh is a serious practical pain.
Unfortunately hw vendors seem to have realized that we (overall community of customers, distro, upstream) are not insisting on open firmware, so they're moving a lot of "valuable sauce" (no really, it's not) into the firmware. PM governors, cpu scheduling algorithms, that kind of stuff. We're not pleased, and there's lots of people doing the behind the scenes work to fix it. One practical problem is that even if we've demonstrated that r/e'ing a uc is no bigger challenge than anything, there's usually this pesky issue with signatures. So we can't force the vendors like we can with the userspace side. Otherwise nouveau would have completely open firmware even for latest chips (like it has for olders).
Quoted 9 lines
Quoted 2 lines
Simple question like If I plug your accelerator into Power or ARM64, where do I get the port of your userspace to use it?
Does demanding complete open userspace get us closer to that goal in reality? By refusing to work with people to enable their hardware, they will still ship their platforms out of tree, using DKMS and all the other ways of getting kernel modules installed to talk to the hardware. And we'd be no closer.
Quoted 3 lines
In the end, they'd open up their userspace when there's business reasons to do so. It's well-known how to work around refusal from us to merge drivers by now, so it's not much leverage in that area.
Correct. None of the hw vendors had a business reason to open source anything unforunately. Yes, eventually customers started demanding open source and treatening to buy the competition, but this only works if you have multiple reasonably performant & conformant stacks for different vendors. The only way to get these is to reverse engineer them.
Now reverse-engineering is a major pain in itself (despite all the great tooling gpu folks developed over the past 10 years to convert it from a black art to a repeatable engineering excercise), but if you additionally prefer the vendors closed stack (which you do by allowing to get them to get merged) the r/e'd stack has no chance. And there is not other way to get your open source stack. I can't really go into all the details of the past 15+ of open source gpus, but without the pressure of other r/e'ed stacks and the pressure of having stacks for competitiors (all made possible through aggressive code sharing) we would have 0 open source gfx stacks. All the ones we have either got started with r/e first (and eventually the vendor jumped on board) or survived through r/e and customer efforts (because the vendor planned to abandon it). Another part of this is that we accept userspace only when it's the common upstream (if there is one), to prevent vendors closing down their stacks gradually.
So yeah I think by not clearly preferring open source over stacks-with-blobs (how radically you do that is a bit a balance act in the end, I think we've maxed out in drivers/gpu on what's practically possible) you'll just make sure that there's never going to be a serious open source stack.
Quoted 5 lines
Quoted 4 lines
I'm not the final arbiter on this sort of thing, but I'm definitely going to make sure that anyone who lands this code is explicit in ignoring any experience we've had in this area and in the future will gladly accept "I told you so" :-)
Quoted 8 lines
There's only one final arbiter on any inclusion to code to the kernel, but we tend to sort out most disagreements without going all the way there.
I still think engaging has a better chance of success than rejecting the contributions, especially with clear expectations w.r.t. continued engagement and no second implementations over time. In all honestly, either approach might fail miserably.
This is maybe not clear, but we still work together with the blob folks as much as possible, for demonstration: nvidia sponsored XDC this year, and nvidia engineers have been regularly presenting there. Collaboration happens around the driver interfaces, like loaders (in userspace), buffer sharing, synchronization, negotiation of buffer formats and all that stuff. Do as much enganging as possible, but if you give preferrential treatment to the closed stacks over the open ones (and by default the vendor _always_ gives you a closed stack, or as closed as possible, there's just no business case for them to open up without a customer demanding it and competition providing it too), you will end up with a closed stack for a very long time, maybe forever.
Even if you insist on an open stack it's going to take years, since the only way to get there is lots of r/e, and you need to have at least 2 stacks or otherwise the customers can't walk away from the negotiation table. So again from gfx experience: The only way to get open stacks is solid competition by open stacks, and customers/distros investing ridiculous amounts of money to r/e the chips and write these open&cross vendor stacks. The business case for vendors to open source their stacks is just not there. Not until they can't sell their chips any other way anymore (nvidia will embrace open stacks as soon as their margins evaporate, not a second earlier, like all the others before them). Maybe at the next hallway track we need to go through a few examples of what all happened and is still happening in the background (here's maybe not a good idea).
-Daniel
Signature · 3 lines
Daniel Vetter Software Engineer, Intel Corporation +41 (0) 79 365 57 48 - http://blog.ffwll.ch
Re: [PATCH 06/15] habanalabs: add basic Goya h/w initialization
In reply to Oded GabbayHi,
This starts the 6-9 review :)
These were more difficult to review because small pieces of code are interleaved with large sequences of register writes. Probably making these register data rather than code can help.
Quoted 30 lines · Oded Gabbay
This patch adds the basic part of Goya's H/W initialization. It adds code that initializes Goya's internal CPU, various registers that are related to internal routing, scrambling, workarounds for H/W bugs, etc.
It also initializes Goya's security scheme that prevents the user from abusing Goya to steal data from the host, crash the host, change Goya's F/W, etc.
Signed-off-by Oded Gabbay <[email protected]>--- drivers/misc/habanalabs/device.c | 12 + drivers/misc/habanalabs/goya/Makefile | 2 +- drivers/misc/habanalabs/goya/goya.c | 1892 ++++++++++- drivers/misc/habanalabs/goya/goyaP.h | 3 + drivers/misc/habanalabs/goya/goya_security.c | 2999 +++++++++++++++++ drivers/misc/habanalabs/habanalabs.h | 16 + drivers/misc/habanalabs/habanalabs_drv.c | 8 + drivers/misc/habanalabs/include/goya/goya.h | 1 + .../include/goya/goya_async_events.h | 186 + .../habanalabs/include/goya/goya_boot_if.h | 32 + 10 files changed, 5144 insertions(+), 7 deletions(-) create mode 100644 drivers/misc/habanalabs/goya/goya_security.c create mode 100644 drivers/misc/habanalabs/include/goya/goya_async_events.h create mode 100644 drivers/misc/habanalabs/include/goya/goya_boot_if.hdrivers/misc/habanalabs/device.c +0
-0
drivers/misc/habanalabs/device.c int hl_device_init(struct hl_device *hdev, struct class *hclass) · line 321
Quoted 7 lines
drivers/misc/habanalabs/device.c +4
-0@@ -315,6 +315,15 @@ int hl_device_init(struct hl_device *hdev, struct class *hclass) goto release_ctx; } + rc = hdev->asic_funcs->hw_init (hdev); +if (rc) { +dev_err (hdev->dev,"failed to initialize the H/W\n" ); + rc =0 ;
Mistype, I suppose.
Quoted 48 lines
drivers/misc/habanalabs/device.c +8
-0+ goto out_disabled; + } + + hdev->disabled = false; +dev_notice (hdev->dev,"Successfully added device to habanalabs driver\n" );@@ -366,6 +375,9 @@ void hl_device_fini(struct hl_device *hdev)if ((hdev->kernel_ctx) && (hl_ctx_put (hdev->kernel_ctx) !=1 ))dev_err (hdev->dev,"kernel ctx is still alive\n" ); +/* Reset the H/W. It will be in idle state after this returns */ + hdev->asic_funcs->hw_fini (hdev, true); +/* Call ASIC S/W finalize function */ hdev->asic_funcs->sw_fini (hdev);drivers/misc/habanalabs/goya/Makefile +1
-1@@ -1,3 +1,3 @@ subdir-ccflags-y += -I$(src) -HL_GOYA_FILES := goya/goya.o +HL_GOYA_FILES := goya/goya.o goya/goya_security.odrivers/misc/habanalabs/goya/goya.c +2
-2@@ -119,11 +119,11 @@ static void goya_get_fixed_properties(struct hl_device *hdev) prop->va_space_dram_end_address =VA_DDR_SPACE_END ; prop->cfg_size =CFG_SIZE ; prop->max_asid =MAX_ASID ; + prop->cb_pool_cb_cnt =GOYA_CB_POOL_CB_CNT ; + prop->cb_pool_cb_size =GOYA_CB_POOL_CB_SIZE ; prop->tpc_enabled_mask =TPC_ENABLED_MASK ; prop->high_pll =PLL_HIGH_DEFAULT ; - prop->cb_pool_cb_cnt =GOYA_CB_POOL_CB_CNT ; - prop->cb_pool_cb_size =GOYA_CB_POOL_CB_SIZE ; }/**
drivers/misc/habanalabs/goya/goya.c static int goya_early_init(struct hl_device *hdev) · line 463
Quoted 9 lines
drivers/misc/habanalabs/goya/goya.c +2
-4@@ -459,10 +459,12 @@ static int goya_early_init(struct hl_device *hdev) goto disable_device; } - val =RREG32 (mmPSOC_GLOBAL_CONF_BOOT_STRAP_PINS); -if (val &PSOC_GLOBAL_CONF_BOOT_STRAP_PINS_SRIOV_EN_MASK ) -dev_warn (hdev->dev, -"PCI strap is not configured correctly, PCI bus errors may occur\n" ); +if (!hdev->pldm) { + val =RREG32 (mmPSOC_GLOBAL_CONF_BOOT_STRAP_PINS);
What is the purpose of the 'mm' prefix in register names?
Quoted 61 lines
drivers/misc/habanalabs/goya/goya.c +54
-0+if (val &PSOC_GLOBAL_CONF_BOOT_STRAP_PINS_SRIOV_EN_MASK ) +dev_warn (hdev->dev, +"PCI strap is not configured correctly, PCI bus errors may occur\n" ); + }return 0 ;@@ -593,6 +595,1882 @@ int goya_sw_fini(struct hl_device *hdev)return 0 ; } +/** +* goya_init_pll - Initialize pll registers +* +* @hdev: pointer to hl_device structure +* +*/ +static void goya_init_pll (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; +u16 hbw_nr, hbw_nf, hbw_od, hbw_nb; +u16 cpu_nr, cpu_nf, cpu_od, cpu_nb; +u16 mc_nr, mc_nf, mc_od, mc_nb; +u16 pci_nr, pci_nf, pci_od, pci_nb; +u16 emmc_nr, emmc_nf, emmc_od, emmc_nb; + +if (!hdev->config_pll) +return ; + +if (goya->hw_cap_initialized &HW_CAP_PLL ) +return ; + +if (hdev->cpu_enable) { +dev_info (hdev->dev, +"Waiting 5s for u-boot before configuring PLLs\n" ); +ssleep (5 ); + } + +/* +* PLL possible configuration values: +{50000000,1,16,16,8}, +{100000000,1,32,16,16}, +{150000000,1,48,16,24}, +{200000000,1,64,16,32}, +{250000000,1,70,14,35}, +{300000000,1,60,10,30}, +{350000000,1,70,10,35}, +{400000000,1,64,8,32}, +{450000000,1,54,6,27}, +{500000000,1,60,6,30}, +{550000000,1,66,6,33}, +{600000000,1,48,4,24}, +{650000000,1,52,4,26}, +{700000000,1,56,4,28}, +{750000000,1,60,4,30}, +{800000000,1,64,4,32}, +{850000000,1,68,4,34}, +{900000000,1,36,2,18}, +{950000000,1,38,2,19}, +{1000000000,1,40,2,20}, +{1050000000,1,42,2,21},
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 657
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+ {1100000000,1,44,2,22}, + {1150000000,1,46,2,23}, + {1200000000,1,48,2,24}, + {1250000000,1,50,2,25}, + {1300000000,1,52,2,26}, + {1350000000,1,54,2,27}, + {1400000000,1,56,2,28}, + {1450000000,1,58,2,29}, + {1500000000,1,60,2,30}, + {1550000000,1,62,2,31},
Some explanation about the correspondence of these values to _nr, _nf, _od and _nb would be helpfull.
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 660
Quoted 3 lines
drivers/misc/habanalabs/goya/goya.c +3
-0+*/ + +if (hdev->pldm) {
/* ? MHz */
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 670
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+ hbw_nr =4 , hbw_nf =302 , hbw_od =1 , hbw_nb =151 ; + cpu_nr =0 , cpu_nf =47 , cpu_od =1 , cpu_nb =32 ; + mc_nr =1 , mc_nf =159 , mc_od =9 , mc_nb =79 ; + pci_nr =4 , pci_nf =343 , pci_od =3 , pci_nb =171 ; + emmc_nr =24 , emmc_nf =415 , emmc_od =15 , emmc_nb =207 ; + }else { +/* 200MHz */ + hbw_nr =0 , hbw_nf =63 , hbw_od =15 , hbw_nb =31 ; + cpu_nr =0 , cpu_nf =47 , cpu_od =1 , cpu_nb =23 ; + mc_nr =2 , mc_nf =0x9f , mc_od =3 , mc_nb =0x4f ;
The hex here looks inconsistent.
Quoted 17 lines
drivers/misc/habanalabs/goya/goya.c +17
-0+ pci_nr =4 , pci_nf =343 , pci_od =3 , pci_nb =171 ; + emmc_nr =24 , emmc_nf =415 , emmc_od =15 , emmc_nb =207 ; + } + +/* Adjust divider for SPI */ +WREG32 (mmPSOC_SPI_BAUDR,8 ); + +WREG32 (mmCPU_PLL_RST,1 ); +WREG32 (mmCPU_PLL_NR, cpu_nr); +WREG32 (mmCPU_PLL_NF, cpu_nf); +WREG32 (mmCPU_PLL_OD, cpu_od); +WREG32 (mmCPU_PLL_NB, cpu_nb); +WREG32 (mmCPU_PLL_DATA_CHNG,0x11 ); + +/* delay before taking PLL out of reset */ +udelay (100 ); +
[ ... ]
Quoted 334 lines
drivers/misc/habanalabs/goya/goya.c +334
-0+ + goya->hw_cap_initialized |=HW_CAP_PLL ; +} + +static void goya_set_pll_refclk (struct hl_device *hdev) +{ +WREG32 (mmCPU_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmCPU_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmCPU_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmCPU_PLL_DIV_SEL_3,0x0 ); + +WREG32 (mmIC_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmIC_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmIC_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmIC_PLL_DIV_SEL_3,0x0 ); + +WREG32 (mmMC_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmMC_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmMC_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmMC_PLL_DIV_SEL_3,0x0 ); + +WREG32 (mmPSOC_MME_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmPSOC_MME_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmPSOC_MME_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmPSOC_MME_PLL_DIV_SEL_3,0x0 ); + +WREG32 (mmPSOC_PCI_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmPSOC_PCI_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmPSOC_PCI_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmPSOC_PCI_PLL_DIV_SEL_3,0x0 ); + +WREG32 (mmPSOC_EMMC_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmPSOC_EMMC_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmPSOC_EMMC_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmPSOC_EMMC_PLL_DIV_SEL_3,0x0 ); + +WREG32 (mmTPC_PLL_DIV_SEL_0,0x0 ); +WREG32 (mmTPC_PLL_DIV_SEL_1,0x0 ); +WREG32 (mmTPC_PLL_DIV_SEL_2,0x0 ); +WREG32 (mmTPC_PLL_DIV_SEL_3,0x0 ); +} + +static void goya_disable_clk_rlx (struct hl_device *hdev) +{ +WREG32 (mmPSOC_MME_PLL_CLK_RLX_0,0x100010 ); +WREG32 (mmIC_PLL_CLK_RLX_0,0x100010 ); +} + +/** +* goya_init_ddr_ch0 - Initialize DDR CH0 controller of the chip +* +* @hdev: pointer to hl_device structure +* +*/ +static void goya_init_ddr_ch0 (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; +u32 val; + +if (goya->hw_cap_initialized &HW_CAP_DDR_0 ) +return ; + + val =RREG32 (mmDDR_MISC_CH0_CFG_DONE); +if (val &DDR_MISC_CH0_CFG_DONE_CFG_DONE_MASK ) { + goya->hw_cap_initialized |=HW_CAP_DDR_0 ; +return ; + } + +WREG32 (mmDDR_MC_CH0_DBG1,0x00000001 ); +WREG32 (mmDDR_MC_CH0_PWRCTL,0x00000001 ); + + val =RREG32 (mmDDR_MC_CH0_STAT); + +WREG32 (mmDDR_MC_CH0_MSTR,0x81040210 ); +WREG32 (mmDDR_MC_CH0_MRCTRL0,0x4000a0f0 ); +WREG32 (mmDDR_MC_CH0_MRCTRL1,0x00022ad0 ); +WREG32 (mmDDR_MC_CH0_MRCTRL2,0x091629e1 ); +WREG32 (mmDDR_MC_CH0_PWRCTL,0x00000008 ); +WREG32 (mmDDR_MC_CH0_PWRTMG,0x00040002 ); +WREG32 (mmDDR_MC_CH0_HWLPCTL,0x00be0002 ); +WREG32 (mmDDR_MC_CH0_RFSHCTL0,0x0091f020 ); +WREG32 (mmDDR_MC_CH0_RFSHCTL1,0x00120018 ); +WREG32 ((mmDDR_MC_CH0_MSTR +0x00000058 ),0x00160005 ); +WREG32 (mmDDR_MC_CH0_RFSHCTL3,0x00000020 ); +WREG32 (mmDDR_MC_CH0_RFSHTMG,0x003000d0 ); +WREG32 (mmDDR_MC_CH0_ECCCFG0,0x00000010 ); +WREG32 (mmDDR_MC_CH0_ECCCFG1,0x00000002 ); +WREG32 (mmDDR_MC_CH0_ECCCTL,0x00000300 ); +WREG32 (mmDDR_MC_CH0_ECCPOISONADDR0,0x00000078 ); +WREG32 (mmDDR_MC_CH0_ECCPOISONADDR1,0x100062f7 ); +WREG32 (mmDDR_MC_CH0_CRCPARCTL0,0x00008000 ); +WREG32 (mmDDR_MC_CH0_CRCPARCTL1,0x0e088301 ); +WREG32 (mmDDR_MC_CH0_CRCPARCTL2,0x00600527 ); +WREG32 (mmDDR_MC_CH0_INIT0,0x00070002 ); +WREG32 (mmDDR_MC_CH0_INIT1,0x0001000e ); +WREG32 (mmDDR_MC_CH0_INIT3,0x0c510001 ); +WREG32 (mmDDR_MC_CH0_INIT4,0x00280400 ); +WREG32 (mmDDR_MC_CH0_INIT5,0x00110000 ); +WREG32 (mmDDR_MC_CH0_INIT6,0x02000643 ); +WREG32 (mmDDR_MC_CH0_INIT7,0x00001000 ); +WREG32 (mmDDR_MC_CH0_DIMMCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH0_RANKCTL,0x000009a0 ); +WREG32 (mmDDR_MC_CH0_DRAMTMG0,0x1918361a ); +WREG32 (mmDDR_MC_CH0_DRAMTMG1,0x00080724 ); +WREG32 (mmDDR_MC_CH0_DRAMTMG2,0x080d0713 ); +WREG32 (mmDDR_MC_CH0_DRAMTMG3,0x00012012 ); +WREG32 (mmDDR_MC_CH0_DRAMTMG4,0x0b04060b ); +WREG32 (mmDDR_MC_CH0_DRAMTMG5,0x0a0c0804 ); +WREG32 (mmDDR_MC_CH0_DRAMTMG8,0x0606490c ); +WREG32 (mmDDR_MC_CH0_DRAMTMG9,0x0002050f ); +WREG32 (mmDDR_MC_CH0_DRAMTMG10,0x000e0d0f ); +WREG32 (mmDDR_MC_CH0_DRAMTMG11,0x270b011f ); +WREG32 (mmDDR_MC_CH0_DRAMTMG12,0x00000010 ); +WREG32 (mmDDR_MC_CH0_DRAMTMG15,0x00000000 ); +WREG32 (mmDDR_MC_CH0_ZQCTL0,0x31000040 ); +WREG32 (mmDDR_MC_CH0_ZQCTL1,0x00000070 ); +WREG32 (mmDDR_MC_CH0_DFITMG0,0x05978211 ); +WREG32 (mmDDR_MC_CH0_DFITMG1,0x00080101 ); +WREG32 (mmDDR_MC_CH0_DFILPCFG0,0x07006031 ); +WREG32 (mmDDR_MC_CH0_DFILPCFG1,0x00000010 ); +WREG32 (mmDDR_MC_CH0_DFIUPD0,0x40400018 ); +WREG32 (mmDDR_MC_CH0_DFIUPD1,0x000b0046 ); +WREG32 (mmDDR_MC_CH0_DFIUPD2,0x00000000 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH0_DFITMG2,0x00001711 ); +WREG32 (mmDDR_MC_CH0_DFITMG3,0x0000001e ); +WREG32 (mmDDR_MC_CH0_DBICTL,0x00000001 ); +WREG32 (mmDDR_MC_CH0_DFIPHYMSTR,0x00000000 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP0,0x00001f1f ); +WREG32 (mmDDR_MC_CH0_ADDRMAP1,0x003f1503 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP2,0x01000400 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP3,0x04000505 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP4,0x00001f1f ); +WREG32 (mmDDR_MC_CH0_ADDRMAP5,0x06060303 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP6,0x0f050709 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP7,0x00000f0f ); +WREG32 (mmDDR_MC_CH0_ADDRMAP8,0x00003f01 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP9,0x09000606 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP10,0x02090105 ); +WREG32 (mmDDR_MC_CH0_ADDRMAP11,0x0000000a ); +WREG32 (mmDDR_MC_CH0_ODTCFG,0x09090a08 ); +WREG32 (mmDDR_MC_CH0_ODTMAP,0x9ae1b5fe ); +WREG32 (mmDDR_MC_CH0_SCHED,0x664d3700 ); +WREG32 (mmDDR_MC_CH0_SCHED1,0x00000000 ); +WREG32 (mmDDR_MC_CH0_PERFHPR1,0x1700e024 ); +WREG32 (mmDDR_MC_CH0_PERFLPR1,0x1e00836c ); +WREG32 (mmDDR_MC_CH0_PERFWR1,0x260046c9 ); +WREG32 (mmDDR_MC_CH0_DQMAP0,0x0d2b3503 ); +WREG32 (mmDDR_MC_CH0_DQMAP1,0x042a0537 ); +WREG32 (mmDDR_MC_CH0_DQMAP2,0x330b2806 ); +WREG32 (mmDDR_MC_CH0_DQMAP3,0x27013803 ); +WREG32 (mmDDR_MC_CH0_DQMAP4,0x0000022c ); +WREG32 (mmDDR_MC_CH0_DQMAP5,0x00000001 ); +WREG32 (mmDDR_MC_CH0_DBG0,0x00000001 ); +WREG32 (mmDDR_MC_CH0_DBG1,0x00000000 ); +WREG32 (mmDDR_MC_CH0_DBGCMD,0x00000000 ); +WREG32 (mmDDR_MC_CH0_SWCTL,0x00000001 ); +WREG32 (mmDDR_MC_CH0_POISONCFG,0x00000001 ); +WREG32 (mmDDR_MC_CH0_ADVECCINDEX,0x00000004 ); +WREG32 (mmDDR_MC_CH0_ECCPOISONPAT0,0x00000000 ); +WREG32 (mmDDR_MC_CH0_ECCPOISONPAT1,0x00000000 ); +WREG32 (mmDDR_MC_CH0_ECCPOISONPAT2,0x00000000 ); +WREG32 (mmDDR_MC_CH0_CAPARPOISONCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH0_PCCFG,0x00000011 ); +WREG32 (mmDDR_MC_CH0_PCFGR_0,0x0000518c ); +WREG32 (mmDDR_MC_CH0_PCFGW_0,0x00001263 ); +WREG32 (mmDDR_MC_CH0_PCTRL_0,0x00000001 ); +WREG32 (mmDDR_MC_CH0_PCFGQOS0_0,0x0011000e ); +WREG32 (mmDDR_MC_CH0_SBRCTL,0x0016b540 ); +WREG32 (mmDDR_MC_CH0_SBRWDATA0,0x8c1d1786 ); +WREG32 (mmDDR_MC_CH0_SBRWDATA1,0x265f03dd ); + + val =RREG32 (mmDDR_MC_CH0_RFSHCTL3); + +WREG32 (mmDDR_MISC_CH0_CFG_DONE,0x00000001 ); + +WREG32 (mmDDR_MC_CH0_DBG1,0x00000000 ); + + val =RREG32 (mmDDR_MC_CH0_PWRCTL); + +WREG32 (mmDDR_MC_CH0_PWRCTL,0x00000002 ); + + val =RREG32 (mmDDR_MC_CH0_PWRCTL); + +WREG32 (mmDDR_MC_CH0_PWRCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH0_SWCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000040 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000040 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000060 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000040 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH0_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH0_PCTRL_0,0x00000001 ); + + goya->hw_cap_initialized |=HW_CAP_DDR_0 ; +} + +/** +* goya_init_ddr_ch1 - Initialize DDR CH1 controller of the chip +* +* @hdev: pointer to hl_device structure +* +*/ +static void goya_init_ddr_ch1 (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; +u32 val; + +if (goya->hw_cap_initialized &HW_CAP_DDR_1 ) +return ; + + val =RREG32 (mmDDR_MISC_CH1_CFG_DONE); +if (val &DDR_MISC_CH1_CFG_DONE_CFG_DONE_MASK ) { + goya->hw_cap_initialized |=HW_CAP_DDR_1 ; +return ; + } + +WREG32 (mmDDR_MC_CH1_DBG1,0x00000001 ); +WREG32 (mmDDR_MC_CH1_PWRCTL,0x00000001 ); + + val =RREG32 (mmDDR_MC_CH1_STAT); + +WREG32 (mmDDR_MC_CH1_MSTR,0x81040210 ); +WREG32 (mmDDR_MC_CH1_MRCTRL0,0x4000a0f0 ); +WREG32 (mmDDR_MC_CH1_MRCTRL1,0x00022ad0 ); +WREG32 (mmDDR_MC_CH1_MRCTRL2,0x091629e1 ); +WREG32 (mmDDR_MC_CH1_PWRCTL,0x00000008 ); +WREG32 (mmDDR_MC_CH1_PWRTMG,0x00040002 ); +WREG32 (mmDDR_MC_CH1_HWLPCTL,0x00be0002 ); +WREG32 (mmDDR_MC_CH1_RFSHCTL0,0x0091f020 ); +WREG32 (mmDDR_MC_CH1_RFSHCTL1,0x00120018 ); +WREG32 ((mmDDR_MC_CH1_MSTR +0x00000058 ),0x00160005 ); +WREG32 (mmDDR_MC_CH1_RFSHCTL3,0x00000020 ); +WREG32 (mmDDR_MC_CH1_RFSHTMG,0x003000d0 ); +WREG32 (mmDDR_MC_CH1_ECCCFG0,0x00000010 ); +WREG32 (mmDDR_MC_CH1_ECCCFG1,0x00000002 ); +WREG32 (mmDDR_MC_CH1_ECCCTL,0x00000300 ); +WREG32 (mmDDR_MC_CH1_ECCPOISONADDR0,0x00000078 ); +WREG32 (mmDDR_MC_CH1_ECCPOISONADDR1,0x100062f7 ); +WREG32 (mmDDR_MC_CH1_CRCPARCTL0,0x00008000 ); +WREG32 (mmDDR_MC_CH1_CRCPARCTL1,0x0e088301 ); +WREG32 (mmDDR_MC_CH1_CRCPARCTL2,0x00600527 ); +WREG32 (mmDDR_MC_CH1_INIT0,0x00070002 ); +WREG32 (mmDDR_MC_CH1_INIT1,0x0001000e ); +WREG32 (mmDDR_MC_CH1_INIT3,0x0c510001 ); +WREG32 (mmDDR_MC_CH1_INIT4,0x00280400 ); +WREG32 (mmDDR_MC_CH1_INIT5,0x00110000 ); +WREG32 (mmDDR_MC_CH1_INIT6,0x02000643 ); +WREG32 (mmDDR_MC_CH1_INIT7,0x00001000 ); +WREG32 (mmDDR_MC_CH1_DIMMCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH1_RANKCTL,0x000009a0 ); +WREG32 (mmDDR_MC_CH1_DRAMTMG0,0x1918361a ); +WREG32 (mmDDR_MC_CH1_DRAMTMG1,0x00080724 ); +WREG32 (mmDDR_MC_CH1_DRAMTMG2,0x080d0713 ); +WREG32 (mmDDR_MC_CH1_DRAMTMG3,0x00012012 ); +WREG32 (mmDDR_MC_CH1_DRAMTMG4,0x0b04060b ); +WREG32 (mmDDR_MC_CH1_DRAMTMG5,0x0a0c0804 ); +WREG32 (mmDDR_MC_CH1_DRAMTMG8,0x0606490c ); +WREG32 (mmDDR_MC_CH1_DRAMTMG9,0x0002050f ); +WREG32 (mmDDR_MC_CH1_DRAMTMG10,0x000e0d0f ); +WREG32 (mmDDR_MC_CH1_DRAMTMG11,0x270b011f ); +WREG32 (mmDDR_MC_CH1_DRAMTMG12,0x00000010 ); +WREG32 (mmDDR_MC_CH1_DRAMTMG15,0x00000000 ); +WREG32 (mmDDR_MC_CH1_ZQCTL0,0x31000040 ); +WREG32 (mmDDR_MC_CH1_ZQCTL1,0x00000070 ); +WREG32 (mmDDR_MC_CH1_DFITMG0,0x05978211 ); +WREG32 (mmDDR_MC_CH1_DFITMG1,0x00080101 ); +WREG32 (mmDDR_MC_CH1_DFILPCFG0,0x07006031 ); +WREG32 (mmDDR_MC_CH1_DFILPCFG1,0x00000010 ); +WREG32 (mmDDR_MC_CH1_DFIUPD0,0x40400018 ); +WREG32 (mmDDR_MC_CH1_DFIUPD1,0x000b0046 ); +WREG32 (mmDDR_MC_CH1_DFIUPD2,0x00000000 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH1_DFITMG2,0x00001711 ); +WREG32 (mmDDR_MC_CH1_DFITMG3,0x0000001e ); +WREG32 (mmDDR_MC_CH1_DBICTL,0x00000001 ); +WREG32 (mmDDR_MC_CH1_DFIPHYMSTR,0x00000000 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP0,0x00001f1f ); +WREG32 (mmDDR_MC_CH1_ADDRMAP1,0x003f1503 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP2,0x01000400 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP3,0x04000505 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP4,0x00001f1f ); +WREG32 (mmDDR_MC_CH1_ADDRMAP5,0x06060303 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP6,0x0f050709 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP7,0x00000f0f ); +WREG32 (mmDDR_MC_CH1_ADDRMAP8,0x00003f01 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP9,0x09000606 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP10,0x02090105 ); +WREG32 (mmDDR_MC_CH1_ADDRMAP11,0x0000000a ); +WREG32 (mmDDR_MC_CH1_ODTCFG,0x09090a08 ); +WREG32 (mmDDR_MC_CH1_ODTMAP,0x9ae1b5fe ); +WREG32 (mmDDR_MC_CH1_SCHED,0x664d3700 ); +WREG32 (mmDDR_MC_CH1_SCHED1,0x00000000 ); +WREG32 (mmDDR_MC_CH1_PERFHPR1,0x1700e024 ); +WREG32 (mmDDR_MC_CH1_PERFLPR1,0x1e00836c ); +WREG32 (mmDDR_MC_CH1_PERFWR1,0x260046c9 ); +WREG32 (mmDDR_MC_CH1_DQMAP0,0x0d2b3503 ); +WREG32 (mmDDR_MC_CH1_DQMAP1,0x042a0537 ); +WREG32 (mmDDR_MC_CH1_DQMAP2,0x330b2806 ); +WREG32 (mmDDR_MC_CH1_DQMAP3,0x27013803 ); +WREG32 (mmDDR_MC_CH1_DQMAP4,0x0000022c ); +WREG32 (mmDDR_MC_CH1_DQMAP5,0x00000001 ); +WREG32 (mmDDR_MC_CH1_DBG0,0x00000001 ); +WREG32 (mmDDR_MC_CH1_DBG1,0x00000000 ); +WREG32 (mmDDR_MC_CH1_DBGCMD,0x00000000 ); +WREG32 (mmDDR_MC_CH1_SWCTL,0x00000001 ); +WREG32 (mmDDR_MC_CH1_POISONCFG,0x00000001 ); +WREG32 (mmDDR_MC_CH1_ADVECCINDEX,0x00000004 ); +WREG32 (mmDDR_MC_CH1_ECCPOISONPAT0,0x00000000 ); +WREG32 (mmDDR_MC_CH1_ECCPOISONPAT1,0x00000000 ); +WREG32 (mmDDR_MC_CH1_ECCPOISONPAT2,0x00000000 ); +WREG32 (mmDDR_MC_CH1_CAPARPOISONCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH1_PCCFG,0x00000011 ); +WREG32 (mmDDR_MC_CH1_PCFGR_0,0x0000518c ); +WREG32 (mmDDR_MC_CH1_PCFGW_0,0x00001263 ); +WREG32 (mmDDR_MC_CH1_PCTRL_0,0x00000001 ); +WREG32 (mmDDR_MC_CH1_PCFGQOS0_0,0x0011000e ); +WREG32 (mmDDR_MC_CH1_SBRCTL,0x0016b540 ); +WREG32 (mmDDR_MC_CH1_SBRWDATA0,0x8c1d1786 ); +WREG32 (mmDDR_MC_CH1_SBRWDATA1,0x265f03dd ); + + val =RREG32 (mmDDR_MC_CH1_RFSHCTL3); + +WREG32 (mmDDR_MISC_CH1_CFG_DONE,0x00000001 ); + +WREG32 (mmDDR_MC_CH1_DBG1,0x00000000 ); + + val =RREG32 (mmDDR_MC_CH1_PWRCTL); + +WREG32 (mmDDR_MC_CH1_PWRCTL,0x00000002 ); + + val =RREG32 (mmDDR_MC_CH1_PWRCTL); +
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1191
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+WREG32 (mmDDR_MC_CH1_PWRCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH1_SWCTL,0x00000000 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000040 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000040 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000060 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000040 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH1_DFIMISC,0x00000041 ); +WREG32 (mmDDR_MC_CH1_PCTRL_0,0x00000001 );
The initialization sequence for the second DDR channel looks really similar to that of the first channel.
I would guess their control registers have identical offsets from some base address. If this is the case the DDR initialization can be factored out and get that base address as a parameter.
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1202
Quoted 11 lines
drivers/misc/habanalabs/goya/goya.c +11
-0+ + goya->hw_cap_initialized |=HW_CAP_DDR_1 ; +} + +static void _goya_tpc_mbist_workaround (struct hl_device *hdev,u8 tpc_id) +{ +u64 tpc_eml_address; +u32 val, tpc_offset, tpc_eml_offset, tpc_slm_offset; +int err, slm_index; + +WARN_ON (tpc_id >=TPC_MAX_NUM );
Is it safe to continue if tpc_id >= TPC_MAX_NUM?
Quoted 145 lines
drivers/misc/habanalabs/goya/goya.c +145
-0+ tpc_offset = tpc_id *0x40000 ; + tpc_eml_offset = tpc_id *0x200000 ; + tpc_eml_address = (mmTPC0_EML_CFG_BASE + tpc_eml_offset -CFG_BASE ); + tpc_slm_offset = tpc_eml_address +0x100000 ; + +/* +* Workaround for Bug H2 #2443 : +* "TPC SB is not initialized on chip reset" +*/ + + val =RREG32 (mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset); +if (val &TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_ACTIVE_MASK ) +dev_warn (hdev->dev,"TPC%d MBIST ACTIVE is not cleared\n" , + tpc_id); + +WREG32 (mmTPC0_CFG_FUNC_MBIST_PAT + tpc_offset, val &0xFFFFF000 ); + +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_0 + tpc_offset,0x37FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_1 + tpc_offset,0x303F ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_2 + tpc_offset,0x71FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_3 + tpc_offset,0x71FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_4 + tpc_offset,0x70FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_5 + tpc_offset,0x70FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_6 + tpc_offset,0x70FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_7 + tpc_offset,0x70FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_8 + tpc_offset,0x70FF ); +WREG32 (mmTPC0_CFG_FUNC_MBIST_MEM_9 + tpc_offset,0x70FF ); + +WREG32_OR (mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset, +1 <<TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_START_SHIFT ); + + err =hl_poll_timeout ( + hdev, + mmTPC0_CFG_FUNC_MBIST_CNTRL + tpc_offset, + val, + (val &TPC0_CFG_FUNC_MBIST_CNTRL_MBIST_DONE_MASK ), +1000 , +HL_DEVICE_TIMEOUT_USEC ); + +if (err) +dev_err (hdev->dev, +"Timeout while waiting for TPC%d MBIST DONE\n" , tpc_id); + +WREG32_OR (mmTPC0_EML_CFG_DBG_CNT + tpc_eml_offset, +1 <<TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT ); + +msleep (GOYA_RESET_WAIT_MSEC ); + +WREG32_AND (mmTPC0_EML_CFG_DBG_CNT + tpc_eml_offset, + ~(1 <<TPC0_EML_CFG_DBG_CNT_CORE_RST_SHIFT )); + +msleep (GOYA_RESET_WAIT_MSEC ); + +for (slm_index =0 ; slm_index <256 ; slm_index++) +WREG32 (tpc_slm_offset + (slm_index <<2 ),0 ); + + val =RREG32 (tpc_slm_offset); + +WREG32 (mmTPC0_CFG_BASE + tpc_offset +0xF40 -CFG_BASE ,0x100 ); +} + +static void goya_tpc_mbist_workaround (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; +int i; + +if (hdev->pldm) +return ; + +if (goya->hw_cap_initialized &HW_CAP_TPC_MBIST ) +return ; + +/* Workaround for H2 #2443 */ + +for (i =0 ; i <TPC_MAX_NUM ; i++) +_goya_tpc_mbist_workaround (hdev, i); + + goya->hw_cap_initialized |=HW_CAP_TPC_MBIST ; +} + +/** +* goya_init_golden_registers - Initialize golden registers +* +* @hdev: pointer to hl_device structure +* +* Initialize the H/W registers of the device +* +*/ +static void goya_init_golden_registers (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; +u32 polynom[10 ], tpc_intr_mask; + +if (goya->hw_cap_initialized &HW_CAP_GOLDEN ) +return ; + + polynom[0 ] =0x00020080 ; + polynom[1 ] =0x00401000 ; + polynom[2 ] =0x00200800 ; + polynom[3 ] =0x00002000 ; + polynom[4 ] =0x00080200 ; + polynom[5 ] =0x00040100 ; + polynom[6 ] =0x00100400 ; + polynom[7 ] =0x00004000 ; + polynom[8 ] =0x00010000 ; + polynom[9 ] =0x00008000 ; + +/* Mask all arithmetic interrupts from TPC */ + tpc_intr_mask =0x7FFF ; + +WREG32 (mmDMA_NRTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmDMA_NRTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmDMA_NRTR_SCRAMB_EN,1 <<DMA_NRTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmDMA_NRTR_NON_LIN_SCRAMB, +1 <<DMA_NRTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmSRAM_Y5_X0_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y4_X0_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y3_X0_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y2_X0_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y1_X0_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y0_X0_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y5_X1_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y4_X1_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y3_X1_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y2_X1_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y1_X1_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y0_X1_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y5_X2_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y4_X2_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y3_X2_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y2_X2_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y1_X2_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y0_X2_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y5_X3_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y4_X3_RTR_HBW_RD_RQ_L_ARB,0x302 );
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1358
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+WREG32 (mmSRAM_Y3_X3_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y2_X3_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y1_X3_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y0_X3_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y5_X4_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y4_X4_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y3_X4_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y2_X4_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y1_X4_RTR_HBW_RD_RQ_L_ARB,0x302 ); +WREG32 (mmSRAM_Y0_X4_RTR_HBW_RD_RQ_L_ARB,0x302 );
Any chance this can be done in a loop?
Quoted 20 lines
drivers/misc/habanalabs/goya/goya.c +20
-0+WREG32 (mmSRAM_Y5_X0_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y4_X0_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y3_X0_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y2_X0_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y1_X0_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y0_X0_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y5_X1_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y4_X1_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y3_X1_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y2_X1_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y1_X1_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y0_X1_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y5_X2_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y4_X2_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y3_X2_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y2_X2_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y1_X2_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y0_X2_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y5_X3_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y4_X3_RTR_HBW_DATA_L_ARB,0x204 );
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1388
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+WREG32 (mmSRAM_Y3_X3_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y2_X3_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y1_X3_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y0_X3_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y5_X4_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y4_X4_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y3_X4_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y2_X4_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y1_X4_RTR_HBW_DATA_L_ARB,0x204 ); +WREG32 (mmSRAM_Y0_X4_RTR_HBW_DATA_L_ARB,0x204 );
Ditto.
Quoted 8 lines
drivers/misc/habanalabs/goya/goya.c +8
-0+WREG32 (mmSRAM_Y5_X0_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y4_X0_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y3_X0_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y2_X0_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y1_X0_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y0_X0_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y5_X1_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y4_X1_RTR_HBW_DATA_E_ARB,0x206 );
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1406
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+WREG32 (mmSRAM_Y3_X1_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y2_X1_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y1_X1_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y0_X1_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y5_X2_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y4_X2_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y3_X2_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y2_X2_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y1_X2_RTR_HBW_DATA_E_ARB,0x206 ); +WREG32 (mmSRAM_Y0_X2_RTR_HBW_DATA_E_ARB,0x206 );
And here and below as well.
Quoted 12 lines
drivers/misc/habanalabs/goya/goya.c +12
-0+WREG32 (mmSRAM_Y5_X3_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y4_X3_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y3_X3_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y2_X3_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y1_X3_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y0_X3_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y5_X4_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y4_X4_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y3_X4_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y2_X4_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y1_X4_RTR_HBW_DATA_E_ARB,0x207 ); +WREG32 (mmSRAM_Y0_X4_RTR_HBW_DATA_E_ARB,0x207 );
[ ... ]
Quoted 55 lines
drivers/misc/habanalabs/goya/goya.c +55
-0+WREG32 (mmMME1_RTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmMME1_RTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmMME2_RTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmMME2_RTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmMME3_RTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmMME3_RTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmMME4_RTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmMME4_RTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmMME5_RTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmMME5_RTR_SPLIT_COEF_9, polynom[9 ] >>7 ); +
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1663
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+WREG32 (mmMME6_RTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmMME6_RTR_SPLIT_COEF_9, polynom[9 ] >>7 );
This sequence seem to repeat itself. If the register map permits I'd suggest splitting writes of the polynom[] to registers into a helper function.
Quoted 39 lines
drivers/misc/habanalabs/goya/goya.c +39
-0+ +WREG32 (mmMME1_RTR_SCRAMB_EN,1 <<MME1_RTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmMME1_RTR_NON_LIN_SCRAMB, +1 <<MME1_RTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmMME2_RTR_SCRAMB_EN,1 <<MME2_RTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmMME2_RTR_NON_LIN_SCRAMB, +1 <<MME2_RTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmMME3_RTR_SCRAMB_EN,1 <<MME3_RTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmMME3_RTR_NON_LIN_SCRAMB, +1 <<MME3_RTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmMME4_RTR_SCRAMB_EN,1 <<MME4_RTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmMME4_RTR_NON_LIN_SCRAMB, +1 <<MME4_RTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmMME5_RTR_SCRAMB_EN,1 <<MME5_RTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmMME5_RTR_NON_LIN_SCRAMB, +1 <<MME5_RTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmMME6_RTR_SCRAMB_EN,1 <<MME6_RTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmMME6_RTR_NON_LIN_SCRAMB, +1 <<MME6_RTR_NON_LIN_SCRAMB_EN_SHIFT ); + +WREG32 (mmTPC0_NRTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmTPC0_NRTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmTPC0_NRTR_SCRAMB_EN,1 <<TPC0_NRTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmTPC0_NRTR_NON_LIN_SCRAMB, +1 <<TPC0_NRTR_NON_LIN_SCRAMB_EN_SHIFT );
[ ... ]
Quoted 32 lines
drivers/misc/habanalabs/goya/goya.c +32
-0+/* +* Workaround for Bug H2 #2441 : +* "ST.NOP set trace event illegal opcode" +*/ +WREG32 (mmTPC6_CFG_TPC_INTR_MASK, tpc_intr_mask); + +WREG32 (mmTPC7_NRTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_4, polynom[4 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmTPC7_NRTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmTPC7_NRTR_SCRAMB_EN,1 <<TPC7_NRTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmTPC7_NRTR_NON_LIN_SCRAMB, +1 <<TPC7_NRTR_NON_LIN_SCRAMB_EN_SHIFT ); + +/* +* Workaround for Bug H2 #2441 : +* "ST.NOP set trace event illegal opcode" +*/ +WREG32 (mmTPC7_CFG_TPC_INTR_MASK, tpc_intr_mask); + +WREG32 (mmPCI_NRTR_SPLIT_COEF_0, polynom[0 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_1, polynom[1 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_2, polynom[2 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_3, polynom[3 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_4, polynom[4 ] >>7 );
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 1949
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+WREG32 (mmPCI_NRTR_SPLIT_COEF_5, polynom[5 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_6, polynom[6 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_7, polynom[7 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_8, polynom[8 ] >>7 ); +WREG32 (mmPCI_NRTR_SPLIT_COEF_9, polynom[9 ] >>7 ); + +WREG32 (mmPCI_NRTR_SCRAMB_EN,1 <<PCI_NRTR_SCRAMB_EN_VAL_SHIFT ); +WREG32 (mmPCI_NRTR_NON_LIN_SCRAMB, +1 <<PCI_NRTR_NON_LIN_SCRAMB_EN_SHIFT ); +
I think all these long sequences of register writes could be grouped into something like
struct regs_write_seq {
unsigned long addr;
unsigned long val;
};const struct regs_write_seq golden_regs1 [] {
...
};const struct regs_write_seq workaround_bug_2411 [] {
...
};and written with a helper function looping over such array.
Quoted 69 lines
drivers/misc/habanalabs/goya/goya.c +69
-0+/* +* Workaround for H2 #HW-23 bug +* Set DMA max outstanding read requests to 240 on DMA CH 1. Set it +* to 16 on KMD DMA +* We need to limit only these DMAs because the user can only read +* from Host using DMA CH 1 +*/ +WREG32 (mmDMA_CH_0_CFG0,0x0fff0010 ); +WREG32 (mmDMA_CH_1_CFG0,0x0fff00F0 ); + + goya->hw_cap_initialized |=HW_CAP_GOLDEN ; +} + + +/** +* goya_push_uboot_to_device - Push u-boot FW code to device +* +* @hdev: pointer to hl_device structure +* +* Copy u-boot fw code from firmware file to SRAM BAR. +* Returns 0 on success +* +*/ +static int goya_push_uboot_to_device (struct hl_device *hdev) +{ +char fw_name[200 ]; +const u64 *fw_data; +void __iomem *dst; +size_t fw_size, i; +int rc; + +snprintf (fw_name,sizeof (fw_name),"habanalabs/goya/goya-u-boot.bin" ); + + rc =request_firmware (&hdev->spl_fw, fw_name, hdev->dev); + +if (rc) { +dev_err (hdev->dev,"Failed to request u-boot fw image\n" ); + goto out; + } + + fw_size = hdev->spl_fw->size; +if ((fw_size %4 ) !=0 ) { +dev_err (hdev->dev,"illegal u-boot firmware size %lu\n" , + fw_size); + rc = -EINVAL ; + goto out; + } + +dev_dbg (hdev->dev,"u-boot firmware size == %lu\n" , fw_size); + + fw_data = (const u64 *) hdev->spl_fw->data; + dst = hdev->pcie_bar[SRAM_CFG_BAR_ID ] +UBOOT_FW_OFFSET ; + +if ((hdev->spl_fw->size %8 ) !=0 ) + fw_size -=8 ; + +for (i =0 ; i < fw_size ; i +=8 , fw_data++, dst +=8 ) { +if (!(i & (0x80000 -1 ))) +dev_dbg (hdev->dev, +"u-boot copied so far %lu out of %lu" , + i, fw_size); + +writeq (*fw_data, dst); + } + +if ((hdev->spl_fw->size %8 ) !=0 ) +writel (*(const u32 *) fw_data, dst); + +out:
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 2028
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+release_firmware (hdev->spl_fw); +return rc; +} + +/** +* goya_push_linux_to_device - Push LINUX FW code to device +* +* @hdev: pointer to hl_device structure +* +* Copy LINXU fw code from firmware file to DDR BAR.
^ Linux
Quoted 42 lines
+ * Returns 0 on success
+ *
+ */drivers/misc/habanalabs/goya/goya.c +39
-0+static int goya_push_linux_to_device (struct hl_device *hdev) +{ +char fw_name[200 ]; +const u64 *fw_data; +void __iomem *dst; +size_t fw_size, i; +int rc; + +snprintf (fw_name,sizeof (fw_name),"habanalabs/goya/goya-fit.itb" ); + + rc =request_firmware (&hdev->spl_fw, fw_name, hdev->dev); + +if (rc) { +dev_err (hdev->dev,"Failed to request Linux fw image\n" ); + goto out; + } + + fw_size = hdev->spl_fw->size; +if ((fw_size %4 ) !=0 ) { +dev_err (hdev->dev,"illegal Linux firmware size %lu\n" , + fw_size); + rc = -EINVAL ; + goto out; + } + +dev_dbg (hdev->dev,"Linux firmware size == %lu\n" , fw_size); + + fw_data = (const u64 *) hdev->spl_fw->data; + dst = hdev->pcie_bar[DDR_BAR_ID ] +LINUX_FW_OFFSET ; + +if ((hdev->spl_fw->size %8 ) !=0 ) + fw_size -=8 ; + +for (i =0 ; i < fw_size ; i +=8 , fw_data++, dst +=8 ) { +if (!(i & (0x80000 -1 ))) { +dev_dbg (hdev->dev, +"Linux copied so far %lu out of %lu" , + i, fw_size); +usleep_range (20 ,100 );
drivers/misc/habanalabs/goya/goya.c int goya_sw_fini(struct hl_device *hdev) · line 2080
Quoted 10 lines
drivers/misc/habanalabs/goya/goya.c +10
-0+ } +writeq (*fw_data, dst); + } + +if ((hdev->spl_fw->size %8 ) !=0 ) +writel (*(const u32 *) fw_data, dst); + +out: +release_firmware (hdev->spl_fw); +return rc;
The U-Boot and Linux loading to the device seem almost identical. I think it can be declared as
static int goya_push_fw_to_device(struct hl_device *hdev, const char *name,
void __iomem *dst)
and called twice.
Quoted 499 lines
drivers/misc/habanalabs/goya/goya.c +395
-0+} + +static int goya_pldm_init_cpu (struct hl_device *hdev) +{ +u32 val, unit_rst_val; +int rc; + +/* Must initialize SRAM scrambler before pushing u-boot to SRAM */ +goya_init_golden_registers (hdev); + +/* Put ARM cores into reset */ +WREG32 (mmCPU_CA53_CFG_ARM_RST_CONTROL,CPU_RESET_ASSERT ); + val =RREG32 (mmCPU_CA53_CFG_ARM_RST_CONTROL); + +/* Reset the CA53 MACRO */ + unit_rst_val =RREG32 (mmPSOC_GLOBAL_CONF_UNIT_RST_N); +WREG32 (mmPSOC_GLOBAL_CONF_UNIT_RST_N,CA53_RESET ); + val =RREG32 (mmPSOC_GLOBAL_CONF_UNIT_RST_N); +WREG32 (mmPSOC_GLOBAL_CONF_UNIT_RST_N, unit_rst_val); + val =RREG32 (mmPSOC_GLOBAL_CONF_UNIT_RST_N); + + rc =goya_push_uboot_to_device (hdev); +if (rc) +return rc; + + rc =goya_push_linux_to_device (hdev); +if (rc) +return rc; + +WREG32 (mmPSOC_GLOBAL_CONF_UBOOT_MAGIC,KMD_MSG_FIT_RDY ); +WREG32 (mmPSOC_GLOBAL_CONF_WARM_REBOOT,CPU_BOOT_STATUS_NA ); + +WREG32 (mmCPU_CA53_CFG_RST_ADDR_LSB_0, +lower_32_bits (SRAM_BASE_ADDR +UBOOT_FW_OFFSET )); +WREG32 (mmCPU_CA53_CFG_RST_ADDR_MSB_0, +upper_32_bits (SRAM_BASE_ADDR +UBOOT_FW_OFFSET )); + +/* Release ARM core 0 from reset */ +WREG32 (mmCPU_CA53_CFG_ARM_RST_CONTROL, +CPU_RESET_CORE0_DEASSERT ); + val =RREG32 (mmCPU_CA53_CFG_ARM_RST_CONTROL); + +return 0 ; +} + +/* +* FW component passes an offset from SRAM_BASE_ADDR in SCRATCHPAD_xx. +* The version string should be located by that offset. +*/ +static void goya_read_device_fw_version (struct hl_device *hdev, +enum goya_fw_component fwc) +{ +const char *name; +u32 ver_off; +char *dest; + +switch (fwc) { +case FW_COMP_UBOOT : + ver_off =RREG32 (mmPSOC_GLOBAL_CONF_SCRATCHPAD_29); + dest = hdev->asic_prop.uboot_ver; + name ="U-Boot" ; +break ; +case FW_COMP_PREBOOT : + ver_off =RREG32 (mmPSOC_GLOBAL_CONF_SCRATCHPAD_28); + dest = hdev->asic_prop.preboot_ver; + name ="Preboot" ; +break ; +default : +dev_warn (hdev->dev,"Undefined FW component: %d\n" , fwc); +return ; + } + + ver_off &= ~((u32 )SRAM_BASE_ADDR ); + +if (ver_off <SRAM_SIZE -VERSION_MAX_LEN ) { +memcpy_fromio (dest, hdev->pcie_bar[SRAM_CFG_BAR_ID ] + ver_off, +VERSION_MAX_LEN ); + }else { +dev_err (hdev->dev,"%s version offset (0x%x) is above SRAM\n" , + name, ver_off); +strcpy (dest,"unavailable" ); + } +} + +static int goya_init_cpu (struct hl_device *hdev,u32 cpu_timeout) +{ +struct goya_device *goya = hdev->asic_specific; +u32 status; +int rc; + +if (!hdev->cpu_enable) +return 0 ; + +if (goya->hw_cap_initialized &HW_CAP_CPU ) +return 0 ; + +/* +* Before pushing u-boot/linux to device, need to set the ddr bar to +* base address of dram +*/ + rc =goya_set_ddr_bar_base (hdev,DRAM_PHYS_BASE ); +if (rc) { +dev_err (hdev->dev, +"failed to map DDR bar to DRAM base address\n" ); +return rc; + } + +if (hdev->pldm) { + rc =goya_pldm_init_cpu (hdev); +if (rc) +return rc; + + goto out; + } + +/* Make sure CPU boot-loader is running */ + rc =hl_poll_timeout ( + hdev, + mmPSOC_GLOBAL_CONF_WARM_REBOOT, + status, + (status ==CPU_BOOT_STATUS_DRAM_RDY ) || + (status ==CPU_BOOT_STATUS_SRAM_AVAIL ), +10000 , + cpu_timeout); + +if (rc) { +dev_err (hdev->dev,"Error in ARM u-boot !!!" ); +switch (status) { +case CPU_BOOT_STATUS_NA : +dev_err (hdev->dev, +"ARM status %d - BTL did NOT run\n" , status); +break ; +case CPU_BOOT_STATUS_IN_WFE : +dev_err (hdev->dev, +"ARM status %d - Inside WFE loop\n" , status); +break ; +case CPU_BOOT_STATUS_IN_BTL : +dev_err (hdev->dev, +"ARM status %d - Stuck in BTL\n" , status); +break ; +case CPU_BOOT_STATUS_IN_PREBOOT : +dev_err (hdev->dev, +"ARM status %d - Stuck in Preboot\n" , status); +break ; +case CPU_BOOT_STATUS_IN_SPL : +dev_err (hdev->dev, +"ARM status %d - Stuck in SPL\n" , status); +break ; +case CPU_BOOT_STATUS_IN_UBOOT : +dev_err (hdev->dev, +"ARM status %d - Stuck in u-boot\n" , status); +break ; +case CPU_BOOT_STATUS_DRAM_INIT_FAIL : +dev_err (hdev->dev, +"ARM status %d - DDR initialization failed\n" , + status); +break ; +default : +dev_err (hdev->dev, +"ARM status %d - Invalid status code\n" , + status); +break ; + } +return -EIO ; + } + +/* Read U-Boot version now in case we will later fail */ +goya_read_device_fw_version (hdev,FW_COMP_UBOOT ); +goya_read_device_fw_version (hdev,FW_COMP_PREBOOT ); + +if (status ==CPU_BOOT_STATUS_SRAM_AVAIL ) + goto out; + +if (!hdev->fw_loading) { +dev_info (hdev->dev,"Skip loading FW\n" ); + goto out; + } + + rc =goya_push_linux_to_device (hdev); +if (rc) +return rc; + +WREG32 (mmPSOC_GLOBAL_CONF_UBOOT_MAGIC,KMD_MSG_FIT_RDY ); + + rc =hl_poll_timeout ( + hdev, + mmPSOC_GLOBAL_CONF_WARM_REBOOT, + status, + (status ==CPU_BOOT_STATUS_SRAM_AVAIL ), +10000 , + cpu_timeout); + +if (rc) { +if (status ==CPU_BOOT_STATUS_FIT_CORRUPTED ) +dev_err (hdev->dev, +"ARM u-boot reports FIT image is corrupted\n" ); +else +dev_err (hdev->dev, +"ARM Linux failed to load, %d\n" , status); +WREG32 (mmPSOC_GLOBAL_CONF_UBOOT_MAGIC,KMD_MSG_NA ); +return -EIO ; + } + +dev_info (hdev->dev,"Successfully loaded firmware to device\n" ); + +out: + goya->hw_cap_initialized |=HW_CAP_CPU ; + +return 0 ; +} + +/** +* goya_hw_init - Goya hardware initialization code +* +* @hdev: pointer to hl_device structure +* +* Returns 0 on success +* +*/ +static int goya_hw_init (struct hl_device *hdev) +{ +struct asic_fixed_properties *prop = &hdev->asic_prop; +u32 val; +int rc; + +dev_info (hdev->dev,"Starting initialization of H/W\n" ); + +/* Perform read from the device to make sure device is up */ + val =RREG32 (mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG); + +goya_init_pll (hdev); + +if (hdev->pldm) { +goya_init_ddr_ch0 (hdev); +goya_init_ddr_ch1 (hdev); + } + + rc =goya_init_cpu (hdev,GOYA_CPU_TIMEOUT_USEC ); +if (rc) { +dev_err (hdev->dev,"failed to initialize CPU\n" ); +return rc; + } + +goya_tpc_mbist_workaround (hdev); + +goya_init_golden_registers (hdev); + +/* +* After CPU initialization is finished, change DDR bar mapping inside +* iATU to point to the start address of the MMU page tables +*/ + rc =goya_set_ddr_bar_base (hdev,DRAM_PHYS_BASE + + (MMU_PAGE_TABLES_ADDR & ~(prop->dram_pci_bar_size -0x1ull ))); +if (rc) { +dev_err (hdev->dev, +"failed to map DDR bar to MMU page tables\n" ); +return rc; + } + +goya_init_security (hdev); + +/* CPU initialization is finished, we can now move to 48 bit DMA mask */ + rc =pci_set_dma_mask (hdev->pdev,DMA_BIT_MASK (48 )); +if (rc) { +dev_warn (hdev->dev,"Unable to set pci dma mask to 48 bits\n" ); + rc =pci_set_dma_mask (hdev->pdev,DMA_BIT_MASK (32 )); +if (rc) { +dev_err (hdev->dev, +"Unable to set pci dma mask to 32 bits\n" ); +return rc; + } + } + + rc =pci_set_consistent_dma_mask (hdev->pdev,DMA_BIT_MASK (48 )); +if (rc) { +dev_warn (hdev->dev, +"Unable to set pci consistent dma mask to 48 bits\n" ); + rc =pci_set_consistent_dma_mask (hdev->pdev,DMA_BIT_MASK (32 )); +if (rc) { +dev_err (hdev->dev, +"Unable to set pci consistent dma mask to 32 bits\n" ); +return rc; + } + } + +/* Perform read from the device to flush all MSI-X configuration */ + val =RREG32 (mmPCIE_DBI_DEVICE_ID_VENDOR_ID_REG); + +return 0 ; +} + +/** +* goya_hw_fini - Goya hardware tear-down code +* +* @hdev: pointer to hl_device structure +* @hard_reset: should we do hard reset to all engines or just reset the +* compute/dma engines +* +* The function does the following: +* - Send interrupt to CPU to go into "quiet" mode +* - Stall MME, TPC +* - Stop External, Internal QMANs +* - Disable MSI-X +* - Issue reset command +* - Wait until reset is done +* - Start device BTL +* +*/ +static void goya_hw_fini (struct hl_device *hdev,bool hard_reset) +{ +struct goya_device *goya = hdev->asic_specific; +u32 reset_timeout_ms, status; + +if (hdev->pldm) + reset_timeout_ms =GOYA_PLDM_RESET_TIMEOUT_MSEC ; +else + reset_timeout_ms =GOYA_RESET_TIMEOUT_MSEC ; + +if (hard_reset) { +goya_set_ddr_bar_base (hdev,DRAM_PHYS_BASE ); +goya_disable_clk_rlx (hdev); +goya_set_pll_refclk (hdev); + +WREG32 (mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG,RESET_ALL ); +dev_info (hdev->dev, +"Issued HARD reset command, going to wait %dms\n" , + reset_timeout_ms); + }else { +WREG32 (mmPSOC_GLOBAL_CONF_SW_ALL_RST_CFG,DMA_MME_TPC_RESET ); +dev_info (hdev->dev, +"Issued SOFT reset command, going to wait %dms\n" , + reset_timeout_ms); + } + +/* +* After hard reset, we can't poll the BTM_FSM register because the PSOC +* itself is in reset. In either reset we need to wait until the reset +* is deasserted +*/ +msleep (reset_timeout_ms); + + status =RREG32 (mmPSOC_GLOBAL_CONF_BTM_FSM); +if (status &PSOC_GLOBAL_CONF_BTM_FSM_STATE_MASK ) +dev_err (hdev->dev, +"Timeout while waiting for device to reset 0x%x\n" , + status); + +if (!hard_reset) { + goya->hw_cap_initialized &= ~(HW_CAP_DMA |HW_CAP_MME | +HW_CAP_GOLDEN |HW_CAP_TPC ); +WREG32 (mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR, +GOYA_ASYNC_EVENT_ID_SOFT_RESET ); +return ; + } + +/* Chicken bit to re-initiate boot sequencer flow */ +WREG32 (mmPSOC_GLOBAL_CONF_BOOT_SEQ_RE_START, +1 <<PSOC_GLOBAL_CONF_BOOT_SEQ_RE_START_IND_SHIFT ); +/* Move boot manager FSM to pre boot sequencer init state */ +WREG32 (mmPSOC_GLOBAL_CONF_SW_BTM_FSM, +0xA <<PSOC_GLOBAL_CONF_SW_BTM_FSM_CTRL_SHIFT ); + + goya->hw_cap_initialized &= ~(HW_CAP_CPU |HW_CAP_CPU_Q | +HW_CAP_DDR_0 |HW_CAP_DDR_1 | +HW_CAP_DMA |HW_CAP_MME | +HW_CAP_MMU |HW_CAP_TPC_MBIST | +HW_CAP_GOLDEN |HW_CAP_TPC ); + +if (!hdev->pldm) { +int rc; +/* In case we are running inside VM and the VM is +* shutting down, we need to make sure CPU boot-loader +* is running before we can continue the VM shutdown. +* That is because the VM will send an FLR signal that +* we must answer +*/ +dev_info (hdev->dev, +"Going to wait up to %ds for CPU boot loader\n" , +GOYA_CPU_TIMEOUT_USEC /1000 /1000 ); + + rc =hl_poll_timeout ( + hdev, + mmPSOC_GLOBAL_CONF_WARM_REBOOT, + status, + (status ==CPU_BOOT_STATUS_DRAM_RDY ), +10000 , +GOYA_CPU_TIMEOUT_USEC ); +if (rc) +dev_err (hdev->dev, +"failed to wait for CPU boot loader\n" ); + } +} +int goya_suspend (struct hl_device *hdev) {return 0 ;@@ -641,6 +2519,8 @@ static const struct hl_asic_funcs goya_funcs = { .early_fini = goya_early_fini, .sw_init = goya_sw_init, .sw_fini = goya_sw_fini, + .hw_init = goya_hw_init, + .hw_fini = goya_hw_fini, .suspend = goya_suspend, .resume = goya_resume, .mmap = goya_mmap,drivers/misc/habanalabs/goya/goyaP.h +3
-0@@ -9,6 +9,7 @@#define GOYAP_H_ #include "habanalabs.h" +#include "include/goya/goya_boot_if.h" #include "include/goya/goya.h" #define NUMBER_OF_CMPLT_QUEUES 5@@ -122,4 +123,6 @@ struct goya_device { u32 hw_cap_initialized; }; +void goya_init_security (struct hl_device *hdev); +#endif /* GOYAP_H_ */ drivers/misc/habanalabs/goya/goya_security.c new file +69
-0@@ -0,0 +1,2999 @@ +// SPDX-License-Identifier: GPL-2.0 + +/* +* Copyright 2016-2018 HabanaLabs, Ltd. +* All Rights Reserved. +*/ + +#include "goyaP.h" + +/** +* goya_set_block_as_protected - set the given block as protected +* +* @hdev: pointer to hl_device structure +* @block: block base address +* +*/ +static void goya_pb_set_block (struct hl_device *hdev,u64 base) +{ +u32 pb_addr = base -CFG_BASE +PROT_BITS_OFFS ; + +while (pb_addr &0xFFF ) { +WREG32 (pb_addr,0 ); + pb_addr +=4 ; + } +} + +static void goya_init_mme_protection_bits (struct hl_device *hdev) +{ +u32 pb_addr, mask; +u8 word_offset; + +/* TODO: change to real reg name when Soc Online is updated */ +u64 mmMME_SBB_POWER_ECO1 =0xDFF60 , + mmMME_SBB_POWER_ECO2 =0xDFF64 ; + +goya_pb_set_block (hdev, mmACC_MS_ECC_MEM_0_BASE); +goya_pb_set_block (hdev, mmACC_MS_ECC_MEM_1_BASE); +goya_pb_set_block (hdev, mmACC_MS_ECC_MEM_2_BASE); +goya_pb_set_block (hdev, mmACC_MS_ECC_MEM_3_BASE); + +goya_pb_set_block (hdev, mmSBA_ECC_MEM_BASE); +goya_pb_set_block (hdev, mmSBB_ECC_MEM_BASE); + +goya_pb_set_block (hdev, mmMME1_RTR_BASE); +goya_pb_set_block (hdev, mmMME1_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME1_WR_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME2_RTR_BASE); +goya_pb_set_block (hdev, mmMME2_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME2_WR_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME3_RTR_BASE); +goya_pb_set_block (hdev, mmMME3_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME3_WR_REGULATOR_BASE); + +goya_pb_set_block (hdev, mmMME4_RTR_BASE); +goya_pb_set_block (hdev, mmMME4_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME4_WR_REGULATOR_BASE); + +goya_pb_set_block (hdev, mmMME5_RTR_BASE); +goya_pb_set_block (hdev, mmMME5_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME5_WR_REGULATOR_BASE); + +goya_pb_set_block (hdev, mmMME6_RTR_BASE); +goya_pb_set_block (hdev, mmMME6_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmMME6_WR_REGULATOR_BASE); + + pb_addr = (mmMME_DUMMY & ~0xFFF ) +PROT_BITS_OFFS ; + word_offset = ((mmMME_DUMMY &PROT_BITS_OFFS ) >>7 ) <<2 ; + mask =1 << ((mmMME_DUMMY &0x7F ) >>2 ); + mask |=1 << ((mmMME_RESET &0x7F ) >>2 );
drivers/misc/habanalabs/goya/goya_security.c line 79
Quoted 10 lines
drivers/misc/habanalabs/goya/goya_security.c new file +10
-0+ mask |=1 << ((mmMME_STALL &0x7F ) >>2 ); + mask |=1 << ((mmMME_SM_BASE_ADDRESS_LOW &0x7F ) >>2 ); + mask |=1 << ((mmMME_SM_BASE_ADDRESS_HIGH &0x7F ) >>2 ); + mask |=1 << ((mmMME_DBGMEM_ADD &0x7F ) >>2 ); + mask |=1 << ((mmMME_DBGMEM_DATA_WR &0x7F ) >>2 ); + mask |=1 << ((mmMME_DBGMEM_DATA_RD &0x7F ) >>2 ); + mask |=1 << ((mmMME_DBGMEM_CTRL &0x7F ) >>2 ); + mask |=1 << ((mmMME_DBGMEM_RC &0x7F ) >>2 ); + mask |=1 << ((mmMME_LOG_SHADOW &0x7F ) >>2 ); +
The mask here and below seems to be a constant.
A #define could suffice, no?
Quoted 25 lines
drivers/misc/habanalabs/goya/goya_security.c new file +25
-0+WREG32 (pb_addr + word_offset, ~mask); + + pb_addr = (mmMME_STORE_MAX_CREDIT & ~0xFFF ) +PROT_BITS_OFFS ; + word_offset = ((mmMME_STORE_MAX_CREDIT &PROT_BITS_OFFS ) >>7 ) <<2 ; + mask =1 << ((mmMME_STORE_MAX_CREDIT &0x7F ) >>2 ); + mask |=1 << ((mmMME_AGU &0x7F ) >>2 ); + mask |=1 << ((mmMME_SBA &0x7F ) >>2 ); + mask |=1 << ((mmMME_SBB &0x7F ) >>2 ); + mask |=1 << ((mmMME_SBC &0x7F ) >>2 ); + mask |=1 << ((mmMME_WBC &0x7F ) >>2 ); + mask |=1 << ((mmMME_SBA_CONTROL_DATA &0x7F ) >>2 ); + mask |=1 << ((mmMME_SBB_CONTROL_DATA &0x7F ) >>2 ); + mask |=1 << ((mmMME_SBC_CONTROL_DATA &0x7F ) >>2 ); + mask |=1 << ((mmMME_WBC_CONTROL_DATA &0x7F ) >>2 ); + mask |=1 << ((mmMME_TE &0x7F ) >>2 ); + mask |=1 << ((mmMME_TE2DEC &0x7F ) >>2 ); + mask |=1 << ((mmMME_REI_STATUS &0x7F ) >>2 ); + mask |=1 << ((mmMME_REI_MASK &0x7F ) >>2 ); + mask |=1 << ((mmMME_SEI_STATUS &0x7F ) >>2 ); + mask |=1 << ((mmMME_SEI_MASK &0x7F ) >>2 ); + mask |=1 << ((mmMME_SPI_STATUS &0x7F ) >>2 ); + mask |=1 << ((mmMME_SPI_MASK &0x7F ) >>2 ); + +WREG32 (pb_addr + word_offset, ~mask); +
[ ... ]
Quoted 35 lines
drivers/misc/habanalabs/goya/goya_security.c new file +35
-0+ +/** +* goya_init_protection_bits - Initialize protection bits for specific registers +* +* @hdev: pointer to hl_device structure +* +* All protection bits are 1 by default, means not protected. Need to set to 0 +* each bit that belongs to a protected register. +* +*/ +static void goya_init_protection_bits (struct hl_device *hdev) +{ +/* +* In each 4K block of registers, the last 128 bytes are protection +* bits - total of 1024 bits, one for each register. Each bit is related +* to a specific register, by the order of the registers. +* So in order to calculate the bit that is related to a given register, +* we need to calculate its word offset and then the exact bit inside +* the word (which is 4 bytes). +* +* Register address: +* +* 31 12 11 7 6 2 1 0 +* ----------------------------------------------------------------- +* | Don't | word | bit location | 0 | +* | care | offset | inside word | | +* ----------------------------------------------------------------- +* +* Bits 7-11 represents the word offset inside the 128 bytes. +* Bits 2-6 represents the bit location inside the word. +*/ + +goya_pb_set_block (hdev, mmPCI_NRTR_BASE); +goya_pb_set_block (hdev, mmPCI_RD_REGULATOR_BASE); +goya_pb_set_block (hdev, mmPCI_WR_REGULATOR_BASE);
[ ... ]
Quoted 15 lines
drivers/misc/habanalabs/goya/goya_security.c new file +15
-0+goya_init_mme_protection_bits (hdev); + +goya_init_dma_protection_bits (hdev); + +goya_init_tpc_protection_bits (hdev); +} + +/** +* goya_init_security - Initialize security model +* +* @hdev: pointer to hl_device structure +* +* Initialize the security model of the device +* That includes range registers and protection bit per register +*
drivers/misc/habanalabs/goya/goya_security.c line 2265
Quoted 10 lines
drivers/misc/habanalabs/goya/goya_security.c new file +10
-0+*/ +void goya_init_security (struct hl_device *hdev) +{ +struct goya_device *goya = hdev->asic_specific; + +u32 dram_addr_lo =lower_32_bits (DRAM_PHYS_BASE ); +u32 dram_addr_hi =upper_32_bits (DRAM_PHYS_BASE ); + +u32 lbw_rng0_base =0xFC440000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng0_mask =0xFFFF0000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ;
These are anyway magic numbers, why not include the mask in them directly? BTW, I couldn't fine DMA_MACRO_LBW_RANGE_BASE_R_MASK anywhere in the driver.
Quoted 72 lines
drivers/misc/habanalabs/goya/goya_security.c new file +72
-0+ +u32 lbw_rng1_base =0xFC480000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng1_mask =0xFFF80000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng2_base =0xFC600000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng2_mask =0xFFE00000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng3_base =0xFC800000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng3_mask =0xFFF00000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng4_base =0xFCC02000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng4_mask =0xFFFFF000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng5_base =0xFCC40000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng5_mask =0xFFFF8000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng6_base =0xFCC48000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng6_mask =0xFFFFF000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng7_base =0xFCC4A000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng7_mask =0xFFFFE000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng8_base =0xFCC4C000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng8_mask =0xFFFFC000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng9_base =0xFCC50000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng9_mask =0xFFFF0000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng10_base =0xFCC60000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng10_mask =0xFFFE0000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng11_base =0xFCE00000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng11_mask =0xFFFFC000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng12_base =0xFE484000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng12_mask =0xFFFFF000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +u32 lbw_rng13_base =0xFEC43000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; +u32 lbw_rng13_mask =0xFFFFF000 &DMA_MACRO_LBW_RANGE_BASE_R_MASK ; + +WREG32 (mmDMA_MACRO_LBW_RANGE_HIT_BLOCK,0xFFFF ); +WREG32 (mmDMA_MACRO_HBW_RANGE_HIT_BLOCK,0xFF ); + +if (!(goya->hw_cap_initialized &HW_CAP_MMU )) { +WREG32 (mmDMA_MACRO_HBW_RANGE_HIT_BLOCK,0xFE ); + +/* Protect HOST */ +WREG32 (mmDMA_MACRO_HBW_RANGE_BASE_31_0_0,0 ); +WREG32 (mmDMA_MACRO_HBW_RANGE_BASE_49_32_0,0 ); +WREG32 (mmDMA_MACRO_HBW_RANGE_MASK_31_0_0,0 ); +WREG32 (mmDMA_MACRO_HBW_RANGE_MASK_49_32_0,0xFFF80 ); + } + +/* +* Protect DDR @ +* DRAM_VIRT_BASE : DRAM_VIRT_BASE + DRAM_VIRT_END +* The mask protects the first 512MB +*/ +WREG32 (mmDMA_MACRO_HBW_RANGE_BASE_31_0_1, dram_addr_lo); +WREG32 (mmDMA_MACRO_HBW_RANGE_BASE_49_32_1, dram_addr_hi); +WREG32 (mmDMA_MACRO_HBW_RANGE_MASK_31_0_1,0xE0000000 ); +WREG32 (mmDMA_MACRO_HBW_RANGE_MASK_49_32_1,0x3FFFF ); + +/* Protect registers */ + +WREG32 (mmDMA_MACRO_LBW_RANGE_BASE_0, lbw_rng0_base); +WREG32 (mmDMA_MACRO_LBW_RANGE_MASK_0, lbw_rng0_mask); +WREG32 (mmDMA_MACRO_LBW_RANGE_BASE_1, lbw_rng1_base); +WREG32 (mmDMA_MACRO_LBW_RANGE_MASK_1, lbw_rng1_mask); +WREG32 (mmDMA_MACRO_LBW_RANGE_BASE_2, lbw_rng2_base); +WREG32 (mmDMA_MACRO_LBW_RANGE_MASK_2, lbw_rng2_mask); +WREG32 (mmDMA_MACRO_LBW_RANGE_BASE_3, lbw_rng3_base);
[ ... ]
Quoted 86 lines
drivers/misc/habanalabs/goya/goya_security.c new file +2
-0+goya_init_protection_bits (hdev); +}drivers/misc/habanalabs/habanalabs.h +16
-0@@ -23,6 +23,8 @@#define HL_MMAP_CB_MASK (0x8000000000000000ull >> PAGE_SHIFT) +#define HL_DEVICE_TIMEOUT_USEC 1000000/* 1 s */ +#define HL_MAX_QUEUES 128struct hl_device ;@@ -32,6 +34,8 @@ struct hl_fpriv;/** * struct asic_fixed_properties - ASIC specific immutable properties. +* @uboot_ver: F/W U-boot version. +* @preboot_ver: F/W Preboot version. * @sram_base_address: SRAM physical start address. * @sram_end_address: SRAM physical end address. * @sram_user_base_address - SRAM physical start address for user access. @@ -60,6 +64,8 @@ struct hl_fpriv;* @tpc_enabled_mask: which TPCs are enabled. */ struct asic_fixed_properties { +char uboot_ver[VERSION_MAX_LEN ]; +char preboot_ver[VERSION_MAX_LEN ];u64 sram_base_address;u64 sram_end_address;u64 sram_user_base_address;@@ -168,6 +174,8 @@ enum hl_asic_type {* @early_fini: tears down what was done in early_init. * @sw_init: sets up driver state, does not configure H/W. * @sw_fini: tears down driver state, does not configure H/W. +* @hw_init: sets up the H/W state. +* @hw_fini: tears down the H/W state. * @suspend: handles IP specific H/W or SW changes for suspend. * @resume: handles IP specific H/W or SW changes for resume. * @mmap: mmap function, does nothing. @@ -180,6 +188,8 @@ struct hl_asic_funcs {int (*early_fini)(struct hl_device *hdev);int (*sw_init)(struct hl_device *hdev);int (*sw_fini)(struct hl_device *hdev); +int (*hw_init)(struct hl_device *hdev); +void (*hw_fini)(struct hl_device *hdev,bool hard_reset);int (*suspend)(struct hl_device *hdev);int (*resume)(struct hl_device *hdev);int (*mmap)(struct hl_fpriv *hpriv,struct vm_area_struct *vma);@@ -312,6 +322,7 @@ void hl_wreg(struct hl_device *hdev, u32 reg, u32 val);* @cpu_accessible_dma_mem: KMD <-> ArmCP shared memory CPU address. * @cpu_accessible_dma_address: KMD <-> ArmCP shared memory DMA address. * @cpu_accessible_dma_pool: KMD <-> ArmCP shared memory pool. +* @spl_fw: image to load to ArmCP. * @asid_bitmap: holds used/available ASIDs. * @asid_mutex: protects asid_bitmap. * @device_open: lock for sanity checks upon FD open. @@ -340,6 +351,7 @@ struct hl_device {void *cpu_accessible_dma_mem;dma_addr_t cpu_accessible_dma_address;struct gen_pool *cpu_accessible_dma_pool; +const struct firmware *spl_fw;unsigned long *asid_bitmap;struct mutex asid_mutex;/* TODO: change to rw_sem for multiple contexts (same as other IOCTL) */ @@ -359,7 +371,11 @@ struct hl_device {u8 disabled;/* Parameters for bring-up */ +u8 cpu_enable;u8 reset_pcilink; +u8 config_pll; +u8 fw_loading; +u8 pldm; };/* drivers/misc/habanalabs/habanalabs_drv.c +0
-0@@ -181,7 +181,15 @@ int create_hdev(struct hl_device **dev, struct pci_dev *pdev, hdev->major = hl_major;
drivers/misc/habanalabs/habanalabs_drv.c int create_hdev(struct hl_device **dev, struct pci_dev *pdev, · line 192
Quoted 10 lines
drivers/misc/habanalabs/habanalabs_drv.c +8
-0/* Parameters for bring-up - set them to defaults */ + hdev->cpu_enable =1 ; hdev->reset_pcilink =0 ; + hdev->config_pll =0 ; + hdev->fw_loading =1 ; + hdev->pldm =0 ; + +/* If CPU is disabled, no point in loading FW */ +if (!hdev->cpu_enable) + hdev->fw_loading =0 ;
The CPU was enabled just a couple of lines above, wasn't it? I've noticed there are a lot of checks for hdev->cpu_enabled and hdev->pldm but I didn't see them ever change.
drivers/misc/habanalabs/include/goya/goya_async_events.h
Quoted 20 lines
drivers/misc/habanalabs/habanalabs_drv.c +0
-0hdev->disabled = true; hdev->pdev = pdev;/* can be NULL in case of simulator device */ drivers/misc/habanalabs/include/goya/goya.h +1
-0@@ -11,6 +11,7 @@#define GOYA_H #include "asic_reg/goya_regs.h" +#include "goya_async_events.h" #include <linux/types.h> drivers/misc/habanalabs/include/goya/goya_async_events.h new file +0
-0
This, apparently, should have been a part of patch 8 (habanalabs: add event queue and interrupts)
Quoted 228 lines
drivers/misc/habanalabs/include/goya/goya_async_events.h new file +186
-0@@ -0,0 +1,186 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +*/ + +#ifndef __GOYA_ASYNC_EVENTS_H_ +#define __GOYA_ASYNC_EVENTS_H_ + +enum goya_async_event_id { +GOYA_ASYNC_EVENT_ID_PCIE_IF =33 , +GOYA_ASYNC_EVENT_ID_TPC0_ECC =36 , +GOYA_ASYNC_EVENT_ID_TPC1_ECC =39 , +GOYA_ASYNC_EVENT_ID_TPC2_ECC =42 , +GOYA_ASYNC_EVENT_ID_TPC3_ECC =45 , +GOYA_ASYNC_EVENT_ID_TPC4_ECC =48 , +GOYA_ASYNC_EVENT_ID_TPC5_ECC =51 , +GOYA_ASYNC_EVENT_ID_TPC6_ECC =54 , +GOYA_ASYNC_EVENT_ID_TPC7_ECC =57 , +GOYA_ASYNC_EVENT_ID_MME_ECC =60 , +GOYA_ASYNC_EVENT_ID_MME_ECC_EXT =61 , +GOYA_ASYNC_EVENT_ID_MMU_ECC =63 , +GOYA_ASYNC_EVENT_ID_DMA_MACRO =64 , +GOYA_ASYNC_EVENT_ID_DMA_ECC =66 , +GOYA_ASYNC_EVENT_ID_CPU_IF_ECC =75 , +GOYA_ASYNC_EVENT_ID_PSOC_MEM =78 , +GOYA_ASYNC_EVENT_ID_PSOC_CORESIGHT =79 , +GOYA_ASYNC_EVENT_ID_SRAM0 =81 , +GOYA_ASYNC_EVENT_ID_SRAM1 =82 , +GOYA_ASYNC_EVENT_ID_SRAM2 =83 , +GOYA_ASYNC_EVENT_ID_SRAM3 =84 , +GOYA_ASYNC_EVENT_ID_SRAM4 =85 , +GOYA_ASYNC_EVENT_ID_SRAM5 =86 , +GOYA_ASYNC_EVENT_ID_SRAM6 =87 , +GOYA_ASYNC_EVENT_ID_SRAM7 =88 , +GOYA_ASYNC_EVENT_ID_SRAM8 =89 , +GOYA_ASYNC_EVENT_ID_SRAM9 =90 , +GOYA_ASYNC_EVENT_ID_SRAM10 =91 , +GOYA_ASYNC_EVENT_ID_SRAM11 =92 , +GOYA_ASYNC_EVENT_ID_SRAM12 =93 , +GOYA_ASYNC_EVENT_ID_SRAM13 =94 , +GOYA_ASYNC_EVENT_ID_SRAM14 =95 , +GOYA_ASYNC_EVENT_ID_SRAM15 =96 , +GOYA_ASYNC_EVENT_ID_SRAM16 =97 , +GOYA_ASYNC_EVENT_ID_SRAM17 =98 , +GOYA_ASYNC_EVENT_ID_SRAM18 =99 , +GOYA_ASYNC_EVENT_ID_SRAM19 =100 , +GOYA_ASYNC_EVENT_ID_SRAM20 =101 , +GOYA_ASYNC_EVENT_ID_SRAM21 =102 , +GOYA_ASYNC_EVENT_ID_SRAM22 =103 , +GOYA_ASYNC_EVENT_ID_SRAM23 =104 , +GOYA_ASYNC_EVENT_ID_SRAM24 =105 , +GOYA_ASYNC_EVENT_ID_SRAM25 =106 , +GOYA_ASYNC_EVENT_ID_SRAM26 =107 , +GOYA_ASYNC_EVENT_ID_SRAM27 =108 , +GOYA_ASYNC_EVENT_ID_SRAM28 =109 , +GOYA_ASYNC_EVENT_ID_SRAM29 =110 , +GOYA_ASYNC_EVENT_ID_GIC500 =112 , +GOYA_ASYNC_EVENT_ID_PCIE_DEC =115 , +GOYA_ASYNC_EVENT_ID_TPC0_DEC =117 , +GOYA_ASYNC_EVENT_ID_TPC1_DEC =120 , +GOYA_ASYNC_EVENT_ID_TPC2_DEC =123 , +GOYA_ASYNC_EVENT_ID_TPC3_DEC =126 , +GOYA_ASYNC_EVENT_ID_TPC4_DEC =129 , +GOYA_ASYNC_EVENT_ID_TPC5_DEC =132 , +GOYA_ASYNC_EVENT_ID_TPC6_DEC =135 , +GOYA_ASYNC_EVENT_ID_TPC7_DEC =138 , +GOYA_ASYNC_EVENT_ID_AXI_ECC =139 , +GOYA_ASYNC_EVENT_ID_L2_RAM_ECC =140 , +GOYA_ASYNC_EVENT_ID_MME_WACS =141 , +GOYA_ASYNC_EVENT_ID_MME_WACSD =142 , +GOYA_ASYNC_EVENT_ID_PLL0 =143 , +GOYA_ASYNC_EVENT_ID_PLL1 =144 , +GOYA_ASYNC_EVENT_ID_PLL3 =146 , +GOYA_ASYNC_EVENT_ID_PLL4 =147 , +GOYA_ASYNC_EVENT_ID_PLL5 =148 , +GOYA_ASYNC_EVENT_ID_PLL6 =149 , +GOYA_ASYNC_EVENT_ID_CPU_AXI_SPLITTER =155 , +GOYA_ASYNC_EVENT_ID_PSOC_AXI_DEC =159 , +GOYA_ASYNC_EVENT_ID_PSOC =160 , +GOYA_ASYNC_EVENT_ID_PCIE_FLR =171 , +GOYA_ASYNC_EVENT_ID_PCIE_HOT_RESET =172 , +GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG0 =174 , +GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG1 =175 , +GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG2 =176 , +GOYA_ASYNC_EVENT_ID_PCIE_QID0_ENG3 =177 , +GOYA_ASYNC_EVENT_ID_PCIE_QID1_ENG0 =178 , +GOYA_ASYNC_EVENT_ID_PCIE_QID1_ENG1 =179 , +GOYA_ASYNC_EVENT_ID_PCIE_QID1_ENG2 =180 , +GOYA_ASYNC_EVENT_ID_PCIE_QID1_ENG3 =181 , +GOYA_ASYNC_EVENT_ID_PCIE_APB =182 , +GOYA_ASYNC_EVENT_ID_PCIE_QDB =183 , +GOYA_ASYNC_EVENT_ID_PCIE_BM_D_P_WR =184 , +GOYA_ASYNC_EVENT_ID_PCIE_BM_D_RD =185 , +GOYA_ASYNC_EVENT_ID_PCIE_BM_U_P_WR =186 , +GOYA_ASYNC_EVENT_ID_PCIE_BM_U_RD =187 , +GOYA_ASYNC_EVENT_ID_TPC0_BMON_SPMU =190 , +GOYA_ASYNC_EVENT_ID_TPC0_KRN_ERR =191 , +GOYA_ASYNC_EVENT_ID_TPC1_BMON_SPMU =200 , +GOYA_ASYNC_EVENT_ID_TPC1_KRN_ERR =201 , +GOYA_ASYNC_EVENT_ID_TPC2_BMON_SPMU =210 , +GOYA_ASYNC_EVENT_ID_TPC2_KRN_ERR =211 , +GOYA_ASYNC_EVENT_ID_TPC3_BMON_SPMU =220 , +GOYA_ASYNC_EVENT_ID_TPC3_KRN_ERR =221 , +GOYA_ASYNC_EVENT_ID_TPC4_BMON_SPMU =230 , +GOYA_ASYNC_EVENT_ID_TPC4_KRN_ERR =231 , +GOYA_ASYNC_EVENT_ID_TPC5_BMON_SPMU =240 , +GOYA_ASYNC_EVENT_ID_TPC5_KRN_ERR =241 , +GOYA_ASYNC_EVENT_ID_TPC6_BMON_SPMU =250 , +GOYA_ASYNC_EVENT_ID_TPC6_KRN_ERR =251 , +GOYA_ASYNC_EVENT_ID_TPC7_BMON_SPMU =260 , +GOYA_ASYNC_EVENT_ID_TPC7_KRN_ERR =261 , +GOYA_ASYNC_EVENT_ID_MMU_SBA_SPMU0 =270 , +GOYA_ASYNC_EVENT_ID_MMU_SBA_SPMU1 =271 , +GOYA_ASYNC_EVENT_ID_MME_WACS_UP =272 , +GOYA_ASYNC_EVENT_ID_MME_WACS_DOWN =273 , +GOYA_ASYNC_EVENT_ID_MMU_PAGE_FAULT =280 , +GOYA_ASYNC_EVENT_ID_MMU_WR_PERM =281 , +GOYA_ASYNC_EVENT_ID_MMU_DBG_BM =282 , +GOYA_ASYNC_EVENT_ID_DMA_BM_CH0 =290 , +GOYA_ASYNC_EVENT_ID_DMA_BM_CH1 =291 , +GOYA_ASYNC_EVENT_ID_DMA_BM_CH2 =292 , +GOYA_ASYNC_EVENT_ID_DMA_BM_CH3 =293 , +GOYA_ASYNC_EVENT_ID_DMA_BM_CH4 =294 , +GOYA_ASYNC_EVENT_ID_DDR0_PHY_DFI =300 , +GOYA_ASYNC_EVENT_ID_DDR0_ECC_SCRUB =301 , +GOYA_ASYNC_EVENT_ID_DDR0_DB_ECC =302 , +GOYA_ASYNC_EVENT_ID_DDR0_SB_ECC =303 , +GOYA_ASYNC_EVENT_ID_DDR0_SB_ECC_MC =304 , +GOYA_ASYNC_EVENT_ID_DDR0_AXI_RD =305 , +GOYA_ASYNC_EVENT_ID_DDR0_AXI_WR =306 , +GOYA_ASYNC_EVENT_ID_DDR1_PHY_DFI =310 , +GOYA_ASYNC_EVENT_ID_DDR1_ECC_SCRUB =311 , +GOYA_ASYNC_EVENT_ID_DDR1_DB_ECC =312 , +GOYA_ASYNC_EVENT_ID_DDR1_SB_ECC =313 , +GOYA_ASYNC_EVENT_ID_DDR1_SB_ECC_MC =314 , +GOYA_ASYNC_EVENT_ID_DDR1_AXI_RD =315 , +GOYA_ASYNC_EVENT_ID_DDR1_AXI_WR =316 , +GOYA_ASYNC_EVENT_ID_CPU_BMON =320 , +GOYA_ASYNC_EVENT_ID_TS_EAST =322 , +GOYA_ASYNC_EVENT_ID_TS_WEST =323 , +GOYA_ASYNC_EVENT_ID_TS_NORTH =324 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_0 =330 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_1 =331 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_U16_2 =332 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_05_SW_RESET =356 , +GOYA_ASYNC_EVENT_ID_PSOC_GPIO_10_VRHOT_ICRIT =361 , +GOYA_ASYNC_EVENT_ID_TPC0_CMDQ =430 , +GOYA_ASYNC_EVENT_ID_TPC1_CMDQ =431 , +GOYA_ASYNC_EVENT_ID_TPC2_CMDQ =432 , +GOYA_ASYNC_EVENT_ID_TPC3_CMDQ =433 , +GOYA_ASYNC_EVENT_ID_TPC4_CMDQ =434 , +GOYA_ASYNC_EVENT_ID_TPC5_CMDQ =435 , +GOYA_ASYNC_EVENT_ID_TPC6_CMDQ =436 , +GOYA_ASYNC_EVENT_ID_TPC7_CMDQ =437 , +GOYA_ASYNC_EVENT_ID_TPC0_QM =438 , +GOYA_ASYNC_EVENT_ID_TPC1_QM =439 , +GOYA_ASYNC_EVENT_ID_TPC2_QM =440 , +GOYA_ASYNC_EVENT_ID_TPC3_QM =441 , +GOYA_ASYNC_EVENT_ID_TPC4_QM =442 , +GOYA_ASYNC_EVENT_ID_TPC5_QM =443 , +GOYA_ASYNC_EVENT_ID_TPC6_QM =444 , +GOYA_ASYNC_EVENT_ID_TPC7_QM =445 , +GOYA_ASYNC_EVENT_ID_MME_QM =447 , +GOYA_ASYNC_EVENT_ID_MME_CMDQ =448 , +GOYA_ASYNC_EVENT_ID_DMA0_QM =449 , +GOYA_ASYNC_EVENT_ID_DMA1_QM =450 , +GOYA_ASYNC_EVENT_ID_DMA2_QM =451 , +GOYA_ASYNC_EVENT_ID_DMA3_QM =452 , +GOYA_ASYNC_EVENT_ID_DMA4_QM =453 , +GOYA_ASYNC_EVENT_ID_DMA_ON_HBW =454 , +GOYA_ASYNC_EVENT_ID_DMA0_CH =455 , +GOYA_ASYNC_EVENT_ID_DMA1_CH =456 , +GOYA_ASYNC_EVENT_ID_DMA2_CH =457 , +GOYA_ASYNC_EVENT_ID_DMA3_CH =458 , +GOYA_ASYNC_EVENT_ID_DMA4_CH =459 , +GOYA_ASYNC_EVENT_ID_PI_UPDATE =484 , +GOYA_ASYNC_EVENT_ID_HALT_MACHINE =485 , +GOYA_ASYNC_EVENT_ID_INTS_REGISTER =486 , +GOYA_ASYNC_EVENT_ID_SOFT_RESET =487 , +GOYA_ASYNC_EVENT_ID_LAST_VALID_ID =1023 , +GOYA_ASYNC_EVENT_ID_SIZE +}; + +#endif /* __GOYA_ASYNC_EVENTS_H_ */ drivers/misc/habanalabs/include/goya/goya_boot_if.h new file +32
-0@@ -0,0 +1,32 @@ +/* SPDX-License-Identifier: GPL-2.0 +* +* Copyright 2018 HabanaLabs, Ltd. +* All Rights Reserved. +* +* Author: Oded Gabbay <[email protected]> +* +*/ + +#ifndef GOYA_BOOT_IF_H +#define GOYA_BOOT_IF_H + +enum cpu_boot_status { +CPU_BOOT_STATUS_NA =0 ,/* Default value after reset of chip */ +CPU_BOOT_STATUS_IN_WFE , +CPU_BOOT_STATUS_DRAM_RDY , +CPU_BOOT_STATUS_SRAM_AVAIL , +CPU_BOOT_STATUS_IN_BTL ,/* BTL is H/W FSM */ +CPU_BOOT_STATUS_IN_PREBOOT , +CPU_BOOT_STATUS_IN_SPL , +CPU_BOOT_STATUS_IN_UBOOT , +CPU_BOOT_STATUS_DRAM_INIT_FAIL , +CPU_BOOT_STATUS_FIT_CORRUPTED +}; + +enum kmd_msg { +KMD_MSG_NA =0 , +KMD_MSG_GOTO_WFE , +KMD_MSG_FIT_RDY +}; + +#endif /* GOYA_BOOT_IF_H */ Signature · 1 line
2.17.1
Signature · 2 lines
Sincerely yours, Mike.