···11+/*22+ * Copyright 2021 Advanced Micro Devices, Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ */2323+#include "amdgpu.h"2424+#include "amdgpu_atombios.h"2525+#include "nbio_v7_11.h"2626+2727+#include "nbio/nbio_7_11_0_offset.h"2828+#include "nbio/nbio_7_11_0_sh_mask.h"2929+#include <uapi/linux/kfd_ioctl.h>3030+3131+static u32 nbio_v7_11_get_rev_id(struct amdgpu_device *adev)3232+{3333+ u32 tmp;3434+ printk("%s, getid\n",__func__);3535+3636+ tmp = RREG32_SOC15(NBIO, 0, regRCC_STRAP1_RCC_DEV0_EPF0_STRAP0);3737+3838+ tmp &= RCC_STRAP0_RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0_MASK;3939+ tmp >>= RCC_STRAP0_RCC_DEV0_EPF0_STRAP0__STRAP_ATI_REV_ID_DEV0_F0__SHIFT;4040+4141+ return tmp;4242+}4343+4444+static void nbio_v7_11_mc_access_enable(struct amdgpu_device *adev, bool enable)4545+{4646+ if (enable)4747+ WREG32_SOC15(NBIO, 0, regBIF_BX1_BIF_FB_EN,4848+ BIF_BX1_BIF_FB_EN__FB_READ_EN_MASK |4949+ BIF_BX1_BIF_FB_EN__FB_WRITE_EN_MASK);5050+ else5151+ WREG32_SOC15(NBIO, 0, regBIF_BX1_BIF_FB_EN, 0);5252+}5353+5454+static u32 nbio_v7_11_get_memsize(struct amdgpu_device *adev)5555+{5656+ return RREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_0_RCC_CONFIG_MEMSIZE);5757+}5858+5959+static void nbio_v7_11_sdma_doorbell_range(struct amdgpu_device *adev, int instance,6060+ bool use_doorbell, int doorbell_index,6161+ int doorbell_size)6262+{6363+ u32 reg = SOC15_REG_OFFSET(NBIO, 0, regGDC0_BIF_SDMA0_DOORBELL_RANGE);6464+ u32 doorbell_range = RREG32_PCIE_PORT(reg);6565+6666+ if (use_doorbell) {6767+ doorbell_range = REG_SET_FIELD(doorbell_range,6868+ GDC0_BIF_SDMA0_DOORBELL_RANGE,6969+ OFFSET, doorbell_index);7070+ doorbell_range = REG_SET_FIELD(doorbell_range,7171+ GDC0_BIF_SDMA0_DOORBELL_RANGE,7272+ SIZE, doorbell_size);7373+ } else {7474+ doorbell_range = REG_SET_FIELD(doorbell_range,7575+ GDC0_BIF_SDMA0_DOORBELL_RANGE,7676+ SIZE, 0);7777+ }7878+7979+ WREG32_PCIE_PORT(reg, doorbell_range);8080+}8181+8282+static void nbio_v7_11_enable_doorbell_aperture(struct amdgpu_device *adev,8383+ bool enable)8484+{8585+ u32 reg;8686+8787+8888+ reg = RREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_0_RCC_DOORBELL_APER_EN);8989+ reg = REG_SET_FIELD(reg, RCC_DEV0_EPF0_0_RCC_DOORBELL_APER_EN,9090+ BIF_DOORBELL_APER_EN, enable ? 1 : 0);9191+9292+ WREG32_SOC15(NBIO, 0, regRCC_DEV0_EPF0_0_RCC_DOORBELL_APER_EN, reg);9393+}9494+9595+static void nbio_v7_11_enable_doorbell_selfring_aperture(struct amdgpu_device *adev,9696+ bool enable)9797+{9898+/* u32 tmp = 0;9999+100100+ if (enable) {101101+ tmp = REG_SET_FIELD(tmp, BIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,102102+ DOORBELL_SELFRING_GPA_APER_EN, 1) |103103+ REG_SET_FIELD(tmp, BIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,104104+ DOORBELL_SELFRING_GPA_APER_MODE, 1) |105105+ REG_SET_FIELD(tmp, BIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,106106+ DOORBELL_SELFRING_GPA_APER_SIZE, 0);107107+108108+ WREG32_SOC15(NBIO, 0,109109+ regBIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_BASE_LOW,110110+ lower_32_bits(adev->doorbell.base));111111+ WREG32_SOC15(NBIO, 0,112112+ regBIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_BASE_HIGH,113113+ upper_32_bits(adev->doorbell.base));114114+ }115115+116116+ WREG32_SOC15(NBIO, 0, regBIF_BX_PF0_DOORBELL_SELFRING_GPA_APER_CNTL,117117+ tmp);118118+*/119119+}120120+121121+122122+static void nbio_v7_11_ih_doorbell_range(struct amdgpu_device *adev,123123+ bool use_doorbell, int doorbell_index)124124+{ 125125+ u32 ih_doorbell_range = RREG32_SOC15(NBIO, 0,regGDC0_BIF_IH_DOORBELL_RANGE);126126+127127+ if (use_doorbell) {128128+ ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,129129+ GDC0_BIF_IH_DOORBELL_RANGE, OFFSET,130130+ doorbell_index);131131+ ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,132132+ GDC0_BIF_IH_DOORBELL_RANGE, SIZE,133133+ 2);134134+ } else {135135+ ih_doorbell_range = REG_SET_FIELD(ih_doorbell_range,136136+ GDC0_BIF_IH_DOORBELL_RANGE, SIZE,137137+ 0);138138+ }139139+140140+ WREG32_SOC15(NBIO, 0, regGDC0_BIF_IH_DOORBELL_RANGE,141141+ ih_doorbell_range);142142+}143143+144144+static void nbio_v7_11_ih_control(struct amdgpu_device *adev)145145+{146146+ u32 interrupt_cntl;147147+148148+ /* setup interrupt control */149149+ WREG32_SOC15(NBIO, 0, regBIF_BX1_INTERRUPT_CNTL2,150150+ adev->dummy_page_addr >> 8);151151+152152+ interrupt_cntl = RREG32_SOC15(NBIO, 0, regBIF_BX1_INTERRUPT_CNTL);153153+ /*154154+ * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=0 - dummy read disabled with msi, enabled without msi155155+ * INTERRUPT_CNTL__IH_DUMMY_RD_OVERRIDE_MASK=1 - dummy read controlled by IH_DUMMY_RD_EN156156+ */157157+ interrupt_cntl = REG_SET_FIELD(interrupt_cntl, BIF_BX1_INTERRUPT_CNTL,158158+ IH_DUMMY_RD_OVERRIDE, 0);159159+160160+ /* INTERRUPT_CNTL__IH_REQ_NONSNOOP_EN_MASK=1 if ring is in non-cacheable memory, e.g., vram */161161+ interrupt_cntl = REG_SET_FIELD(interrupt_cntl, BIF_BX1_INTERRUPT_CNTL,162162+ IH_REQ_NONSNOOP_EN, 0);163163+164164+ WREG32_SOC15(NBIO, 0, regBIF_BX1_INTERRUPT_CNTL, interrupt_cntl);165165+}166166+167167+static u32 nbio_v7_11_get_hdp_flush_req_offset(struct amdgpu_device *adev)168168+{169169+ return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_GPU_HDP_FLUSH_REQ);170170+}171171+172172+static u32 nbio_v7_11_get_hdp_flush_done_offset(struct amdgpu_device *adev)173173+{174174+ return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_GPU_HDP_FLUSH_DONE);175175+}176176+177177+static u32 nbio_v7_11_get_pcie_index_offset(struct amdgpu_device *adev)178178+{179179+ return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX1_PCIE_INDEX2);180180+}181181+182182+static u32 nbio_v7_11_get_pcie_data_offset(struct amdgpu_device *adev)183183+{184184+ return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX1_PCIE_DATA2);185185+}186186+187187+static u32 nbio_v7_11_get_pcie_port_index_offset(struct amdgpu_device *adev)188188+{189189+ return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_RSMU_INDEX);190190+}191191+192192+static u32 nbio_v7_11_get_pcie_port_data_offset(struct amdgpu_device *adev)193193+{194194+ return SOC15_REG_OFFSET(NBIO, 0, regBIF_BX_PF0_RSMU_DATA);195195+}196196+197197+const struct nbio_hdp_flush_reg nbio_v7_11_hdp_flush_reg = {198198+ .ref_and_mask_cp0 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP0_MASK,199199+ .ref_and_mask_cp1 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP1_MASK,200200+ .ref_and_mask_cp2 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP2_MASK,201201+ .ref_and_mask_cp3 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP3_MASK,202202+ .ref_and_mask_cp4 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP4_MASK,203203+ .ref_and_mask_cp5 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP5_MASK,204204+ .ref_and_mask_cp6 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP6_MASK,205205+ .ref_and_mask_cp7 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP7_MASK,206206+ .ref_and_mask_cp8 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP8_MASK,207207+ .ref_and_mask_cp9 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__CP9_MASK,208208+ .ref_and_mask_sdma0 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__SDMA0_MASK,209209+ .ref_and_mask_sdma1 = BIF_BX_PF0_GPU_HDP_FLUSH_DONE__SDMA1_MASK,210210+};211211+212212+static void nbio_v7_11_init_registers(struct amdgpu_device *adev)213213+{214214+/* uint32_t def, data;215215+216216+ def = data = RREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3);217217+ data = REG_SET_FIELD(data, BIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3,218218+ CI_SWUS_MAX_READ_REQUEST_SIZE_MODE, 1);219219+ data = REG_SET_FIELD(data, BIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3,220220+ CI_SWUS_MAX_READ_REQUEST_SIZE_PRIV, 1);221221+222222+ if (def != data)223223+ WREG32_SOC15(NBIO, 0, regBIF_BIF256_CI256_RC3X4_USB4_PCIE_MST_CTRL_3, data);224224+*/225225+}226226+227227+const struct amdgpu_nbio_funcs nbio_v7_11_funcs = {228228+ .get_hdp_flush_req_offset = nbio_v7_11_get_hdp_flush_req_offset,229229+ .get_hdp_flush_done_offset = nbio_v7_11_get_hdp_flush_done_offset,230230+ .get_pcie_index_offset = nbio_v7_11_get_pcie_index_offset,231231+ .get_pcie_data_offset = nbio_v7_11_get_pcie_data_offset,232232+ .get_pcie_port_index_offset = nbio_v7_11_get_pcie_port_index_offset,233233+ .get_pcie_port_data_offset = nbio_v7_11_get_pcie_port_data_offset,234234+ .get_rev_id = nbio_v7_11_get_rev_id,235235+ .mc_access_enable = nbio_v7_11_mc_access_enable,236236+ .get_memsize = nbio_v7_11_get_memsize,237237+ .sdma_doorbell_range = nbio_v7_11_sdma_doorbell_range,238238+ .enable_doorbell_aperture = nbio_v7_11_enable_doorbell_aperture,239239+ .enable_doorbell_selfring_aperture = nbio_v7_11_enable_doorbell_selfring_aperture,240240+ .ih_doorbell_range = nbio_v7_11_ih_doorbell_range,241241+ .ih_control = nbio_v7_11_ih_control,242242+ .init_registers = nbio_v7_11_init_registers,243243+};
+33
drivers/gpu/drm/amd/amdgpu/nbio_v7_11.h
···11+/*22+ * Copyright 2021 Advanced Micro Devices, Inc.33+ *44+ * Permission is hereby granted, free of charge, to any person obtaining a55+ * copy of this software and associated documentation files (the "Software"),66+ * to deal in the Software without restriction, including without limitation77+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,88+ * and/or sell copies of the Software, and to permit persons to whom the99+ * Software is furnished to do so, subject to the following conditions:1010+ *1111+ * The above copyright notice and this permission notice shall be included in1212+ * all copies or substantial portions of the Software.1313+ *1414+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR1515+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,1616+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL1717+ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR1818+ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,1919+ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR2020+ * OTHER DEALINGS IN THE SOFTWARE.2121+ *2222+ */2323+2424+#ifndef __NBIO_V7_11_H__2525+#define __NBIO_V7_11_H__2626+2727+#include "soc15_common.h"2828+2929+extern const struct nbio_hdp_flush_reg nbio_v7_11_hdp_flush_reg;3030+extern const struct amdgpu_nbio_funcs nbio_v7_11_funcs;3131+extern const struct amdgpu_nbio_ras_funcs nbio_v7_11_ras_funcs;3232+3333+#endif