habanalabs: calculate trace frequency from PLL
authorAdam Aharon <aaharon@habana.ai>
Tue, 26 May 2020 08:04:30 +0000 (11:04 +0300)
committerOded Gabbay <oded.gabbay@gmail.com>
Fri, 24 Jul 2020 17:31:35 +0000 (20:31 +0300)
The profiler needs to know the PLL values for correctly showing the
profiling data. Because our firmware can use different PLL configurations,
we need to read the PLL values from the ASIC to pass them to the profiler.

Signed-off-by: Adam Aharon <aaharon@habana.ai>
Reviewed-by: Oded Gabbay <oded.gabbay@gmail.com>
Signed-off-by: Oded Gabbay <oded.gabbay@gmail.com>
drivers/misc/habanalabs/gaudi/gaudi.c
drivers/misc/habanalabs/gaudi/gaudi_coresight.c
drivers/misc/habanalabs/goya/goya.c
drivers/misc/habanalabs/goya/goya_coresight.c
drivers/misc/habanalabs/habanalabs.h
drivers/misc/habanalabs/include/gaudi/asic_reg/gaudi_regs.h
drivers/misc/habanalabs/include/gaudi/asic_reg/psoc_cpu_pll_regs.h [new file with mode: 0644]

index 0c5d5831f3271eb9f53f37d78ffe1f7853d0fc14..aa4139626a0473b1c5ee3b6fdf8b162bf5416fc9 100644 (file)
@@ -555,11 +555,36 @@ static int gaudi_early_fini(struct hl_device *hdev)
 static void gaudi_fetch_psoc_frequency(struct hl_device *hdev)
 {
        struct asic_fixed_properties *prop = &hdev->asic_prop;
+       u32 trace_freq = 0;
+       u32 pll_clk = 0;
+       u32 div_fctr = RREG32(mmPSOC_CPU_PLL_DIV_FACTOR_2);
+       u32 div_sel = RREG32(mmPSOC_CPU_PLL_DIV_SEL_2);
+       u32 nr = RREG32(mmPSOC_CPU_PLL_NR);
+       u32 nf = RREG32(mmPSOC_CPU_PLL_NF);
+       u32 od = RREG32(mmPSOC_CPU_PLL_OD);
+
+       if (div_sel == DIV_SEL_REF_CLK || div_sel == DIV_SEL_DIVIDED_REF) {
+               if (div_sel == DIV_SEL_REF_CLK)
+                       trace_freq = PLL_REF_CLK;
+               else
+                       trace_freq = PLL_REF_CLK / (div_fctr + 1);
+       } else if (div_sel == DIV_SEL_PLL_CLK ||
+                                       div_sel == DIV_SEL_DIVIDED_PLL) {
+               pll_clk = PLL_REF_CLK * (nf + 1) / ((nr + 1) * (od + 1));
+               if (div_sel == DIV_SEL_PLL_CLK)
+                       trace_freq = pll_clk;
+               else
+                       trace_freq = pll_clk / (div_fctr + 1);
+       } else {
+               dev_warn(hdev->dev,
+                       "Received invalid div select value: %d", div_sel);
+       }
 
-       prop->psoc_pci_pll_nr = RREG32(mmPSOC_PCI_PLL_NR);
-       prop->psoc_pci_pll_nf = RREG32(mmPSOC_PCI_PLL_NF);
-       prop->psoc_pci_pll_od = RREG32(mmPSOC_PCI_PLL_OD);
-       prop->psoc_pci_pll_div_factor = RREG32(mmPSOC_PCI_PLL_DIV_FACTOR_1);
+       prop->psoc_timestamp_frequency = trace_freq;
+       prop->psoc_pci_pll_nr = nr;
+       prop->psoc_pci_pll_nf = nf;
+       prop->psoc_pci_pll_od = od;
+       prop->psoc_pci_pll_div_factor = div_fctr;
 }
 
 static int _gaudi_init_tpc_mem(struct hl_device *hdev,
index bf0e062d7b874e60376741811661b957041fddc9..c32322cb1728118754a107ccd1f3597d6514f4c7 100644 (file)
@@ -392,6 +392,7 @@ static int gaudi_config_stm(struct hl_device *hdev,
 {
        struct hl_debug_params_stm *input;
        u64 base_reg;
+       u32 frequency;
        int rc;
 
        if (params->reg_idx >= ARRAY_SIZE(debug_stm_regs)) {
@@ -420,7 +421,10 @@ static int gaudi_config_stm(struct hl_device *hdev,
                WREG32(base_reg + 0xE00, lower_32_bits(input->sp_mask));
                WREG32(base_reg + 0xEF4, input->id);
                WREG32(base_reg + 0xDF4, 0x80);
-               WREG32(base_reg + 0xE8C, input->frequency);
+               frequency = hdev->asic_prop.psoc_timestamp_frequency;
+               if (frequency == 0)
+                       frequency = input->frequency;
+               WREG32(base_reg + 0xE8C, frequency);
                WREG32(base_reg + 0xE90, 0x7FF);
 
                /* SW-2176 - SW WA for HW bug */
index ff9e8a31ced4367459b794180a2510111a9d0ffe..ff32a8fa7624b5bf4f15e274054c134adf6d2fa2 100644 (file)
@@ -594,11 +594,36 @@ static void goya_qman0_set_security(struct hl_device *hdev, bool secure)
 static void goya_fetch_psoc_frequency(struct hl_device *hdev)
 {
        struct asic_fixed_properties *prop = &hdev->asic_prop;
+       u32 trace_freq = 0;
+       u32 pll_clk = 0;
+       u32 div_fctr = RREG32(mmPSOC_PCI_PLL_DIV_FACTOR_1);
+       u32 div_sel = RREG32(mmPSOC_PCI_PLL_DIV_SEL_1);
+       u32 nr = RREG32(mmPSOC_PCI_PLL_NR);
+       u32 nf = RREG32(mmPSOC_PCI_PLL_NF);
+       u32 od = RREG32(mmPSOC_PCI_PLL_OD);
+
+       if (div_sel == DIV_SEL_REF_CLK || div_sel == DIV_SEL_DIVIDED_REF) {
+               if (div_sel == DIV_SEL_REF_CLK)
+                       trace_freq = PLL_REF_CLK;
+               else
+                       trace_freq = PLL_REF_CLK / (div_fctr + 1);
+       } else if (div_sel == DIV_SEL_PLL_CLK ||
+                                       div_sel == DIV_SEL_DIVIDED_PLL) {
+               pll_clk = PLL_REF_CLK * (nf + 1) / ((nr + 1) * (od + 1));
+               if (div_sel == DIV_SEL_PLL_CLK)
+                       trace_freq = pll_clk;
+               else
+                       trace_freq = pll_clk / (div_fctr + 1);
+       } else {
+               dev_warn(hdev->dev,
+                       "Received invalid div select value: %d", div_sel);
+       }
 
-       prop->psoc_pci_pll_nr = RREG32(mmPSOC_PCI_PLL_NR);
-       prop->psoc_pci_pll_nf = RREG32(mmPSOC_PCI_PLL_NF);
-       prop->psoc_pci_pll_od = RREG32(mmPSOC_PCI_PLL_OD);
-       prop->psoc_pci_pll_div_factor = RREG32(mmPSOC_PCI_PLL_DIV_FACTOR_1);
+       prop->psoc_timestamp_frequency = trace_freq;
+       prop->psoc_pci_pll_nr = nr;
+       prop->psoc_pci_pll_nf = nf;
+       prop->psoc_pci_pll_od = od;
+       prop->psoc_pci_pll_div_factor = div_fctr;
 }
 
 int goya_late_init(struct hl_device *hdev)
index aa51fc71f0a1ffbbd3e7fabc672bafb6971cd1a2..18e12e9d284b72418d48a67fd22804cab53ce63d 100644 (file)
@@ -232,6 +232,7 @@ static int goya_config_stm(struct hl_device *hdev,
 {
        struct hl_debug_params_stm *input;
        u64 base_reg;
+       u32 frequency;
        int rc;
 
        if (params->reg_idx >= ARRAY_SIZE(debug_stm_regs)) {
@@ -264,7 +265,10 @@ static int goya_config_stm(struct hl_device *hdev,
                WREG32(base_reg + 0xE20, 0xFFFFFFFF);
                WREG32(base_reg + 0xEF4, input->id);
                WREG32(base_reg + 0xDF4, 0x80);
-               WREG32(base_reg + 0xE8C, input->frequency);
+               frequency = hdev->asic_prop.psoc_timestamp_frequency;
+               if (frequency == 0)
+                       frequency = input->frequency;
+               WREG32(base_reg + 0xE8C, frequency);
                WREG32(base_reg + 0xE90, 0x7FF);
                WREG32(base_reg + 0xE80, 0x27 | (input->id << 16));
        } else {
index 8cd4b55d06084154112fa2b953226fd6f74f1f04..4e68a41cce77fd4b04fce83171d9771ca411ba8e 100644 (file)
@@ -247,6 +247,7 @@ struct hl_mmu_properties {
  * @psoc_pci_pll_nf: PCI PLL NF value.
  * @psoc_pci_pll_od: PCI PLL OD value.
  * @psoc_pci_pll_div_factor: PCI PLL DIV FACTOR 1 value.
+ * @psoc_timestamp_frequency: frequency of the psoc timestamp clock.
  * @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.
@@ -291,6 +292,7 @@ struct asic_fixed_properties {
        u32                             psoc_pci_pll_nf;
        u32                             psoc_pci_pll_od;
        u32                             psoc_pci_pll_div_factor;
+       u32                             psoc_timestamp_frequency;
        u32                             high_pll;
        u32                             cb_pool_cb_cnt;
        u32                             cb_pool_cb_size;
@@ -533,6 +535,15 @@ enum hl_pll_frequency {
        PLL_LAST
 };
 
+#define PLL_REF_CLK 50
+
+enum div_select_defs {
+       DIV_SEL_REF_CLK = 0,
+       DIV_SEL_PLL_CLK = 1,
+       DIV_SEL_DIVIDED_REF = 2,
+       DIV_SEL_DIVIDED_PLL = 3,
+};
+
 /**
  * struct hl_asic_funcs - ASIC specific functions that are can be called from
  *                        common code.
index 85e3b514859574a6de72d3d13ce0b8c6a9f26ef5..62078077aee5af985a912fc0a77bfef56041bbf8 100644 (file)
@@ -91,6 +91,7 @@
 
 #include "psoc_pci_pll_regs.h"
 #include "psoc_hbm_pll_regs.h"
+#include "psoc_cpu_pll_regs.h"
 
 #define GAUDI_ECC_MEM_SEL_OFFSET       0xF18
 #define GAUDI_ECC_ADDRESS_OFFSET       0xF1C
diff --git a/drivers/misc/habanalabs/include/gaudi/asic_reg/psoc_cpu_pll_regs.h b/drivers/misc/habanalabs/include/gaudi/asic_reg/psoc_cpu_pll_regs.h
new file mode 100644 (file)
index 0000000..2585c70
--- /dev/null
@@ -0,0 +1,114 @@
+/* SPDX-License-Identifier: GPL-2.0
+ *
+ * Copyright 2016-2018 HabanaLabs, Ltd.
+ * All Rights Reserved.
+ *
+ */
+
+/************************************
+ ** This is an auto-generated file **
+ **       DO NOT EDIT BELOW        **
+ ************************************/
+
+#ifndef ASIC_REG_PSOC_CPU_PLL_REGS_H_
+#define ASIC_REG_PSOC_CPU_PLL_REGS_H_
+
+/*
+ *****************************************
+ *   PSOC_CPU_PLL (Prototype: PLL)
+ *****************************************
+ */
+
+#define mmPSOC_CPU_PLL_NR                                            0xC70100
+
+#define mmPSOC_CPU_PLL_NF                                            0xC70104
+
+#define mmPSOC_CPU_PLL_OD                                            0xC70108
+
+#define mmPSOC_CPU_PLL_NB                                            0xC7010C
+
+#define mmPSOC_CPU_PLL_CFG                                           0xC70110
+
+#define mmPSOC_CPU_PLL_LOSE_MASK                                     0xC70120
+
+#define mmPSOC_CPU_PLL_LOCK_INTR                                     0xC70128
+
+#define mmPSOC_CPU_PLL_LOCK_BYPASS                                   0xC7012C
+
+#define mmPSOC_CPU_PLL_DATA_CHNG                                     0xC70130
+
+#define mmPSOC_CPU_PLL_RST                                           0xC70134
+
+#define mmPSOC_CPU_PLL_SLIP_WD_CNTR                                  0xC70150
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_0                                  0xC70200
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_1                                  0xC70204
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_2                                  0xC70208
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_3                                  0xC7020C
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_CMD_0                              0xC70220
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_CMD_1                              0xC70224
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_CMD_2                              0xC70228
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_CMD_3                              0xC7022C
+
+#define mmPSOC_CPU_PLL_DIV_SEL_0                                     0xC70280
+
+#define mmPSOC_CPU_PLL_DIV_SEL_1                                     0xC70284
+
+#define mmPSOC_CPU_PLL_DIV_SEL_2                                     0xC70288
+
+#define mmPSOC_CPU_PLL_DIV_SEL_3                                     0xC7028C
+
+#define mmPSOC_CPU_PLL_DIV_EN_0                                      0xC702A0
+
+#define mmPSOC_CPU_PLL_DIV_EN_1                                      0xC702A4
+
+#define mmPSOC_CPU_PLL_DIV_EN_2                                      0xC702A8
+
+#define mmPSOC_CPU_PLL_DIV_EN_3                                      0xC702AC
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_BUSY_0                             0xC702C0
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_BUSY_1                             0xC702C4
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_BUSY_2                             0xC702C8
+
+#define mmPSOC_CPU_PLL_DIV_FACTOR_BUSY_3                             0xC702CC
+
+#define mmPSOC_CPU_PLL_CLK_GATER                                     0xC70300
+
+#define mmPSOC_CPU_PLL_CLK_RLX_0                                     0xC70310
+
+#define mmPSOC_CPU_PLL_CLK_RLX_1                                     0xC70314
+
+#define mmPSOC_CPU_PLL_CLK_RLX_2                                     0xC70318
+
+#define mmPSOC_CPU_PLL_CLK_RLX_3                                     0xC7031C
+
+#define mmPSOC_CPU_PLL_REF_CNTR_PERIOD                               0xC70400
+
+#define mmPSOC_CPU_PLL_REF_LOW_THRESHOLD                             0xC70410
+
+#define mmPSOC_CPU_PLL_REF_HIGH_THRESHOLD                            0xC70420
+
+#define mmPSOC_CPU_PLL_PLL_NOT_STABLE                                0xC70430
+
+#define mmPSOC_CPU_PLL_FREQ_CALC_EN                                  0xC70440
+
+#define mmPSOC_CPU_PLL_RLX_BITMAP_CFG                                0xC70500
+
+#define mmPSOC_CPU_PLL_RLX_BITMAP_0                                  0xC70510
+
+#define mmPSOC_CPU_PLL_RLX_BITMAP_1                                  0xC70514
+
+#define mmPSOC_CPU_PLL_RLX_BITMAP_2                                  0xC70518
+
+#define mmPSOC_CPU_PLL_RLX_BITMAP_3                                  0xC7051C
+
+#endif /* ASIC_REG_PSOC_CPU_PLL_REGS_H_ */