Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

drm/amdgpu: move atom functions from amdgpu_device.c

and move them to amdgpu_atombios.c for consistency.

Acked-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

+236 -235
+234 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c
··· 27 27 #include <drm/amdgpu_drm.h> 28 28 #include "amdgpu.h" 29 29 #include "amdgpu_atombios.h" 30 + #include "amdgpu_atomfirmware.h" 30 31 #include "amdgpu_i2c.h" 31 32 32 33 #include "atom.h" ··· 1700 1699 WREG32(adev->bios_scratch_reg_offset + 6, bios_6_scratch); 1701 1700 } 1702 1701 1703 - void amdgpu_atombios_scratch_regs_init(struct amdgpu_device *adev) 1702 + static void amdgpu_atombios_scratch_regs_init(struct amdgpu_device *adev) 1704 1703 { 1705 1704 uint32_t bios_2_scratch, bios_6_scratch; 1706 1705 ··· 1777 1776 #endif 1778 1777 } 1779 1778 1780 - int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev) 1779 + static int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev) 1781 1780 { 1782 1781 struct atom_context *ctx = adev->mode_info.atom_context; 1783 1782 int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware); ··· 1820 1819 ctx->scratch_size_bytes = usage_bytes; 1821 1820 return 0; 1822 1821 } 1822 + 1823 + /* ATOM accessor methods */ 1824 + /* 1825 + * ATOM is an interpreted byte code stored in tables in the vbios. The 1826 + * driver registers callbacks to access registers and the interpreter 1827 + * in the driver parses the tables and executes then to program specific 1828 + * actions (set display modes, asic init, etc.). See amdgpu_atombios.c, 1829 + * atombios.h, and atom.c 1830 + */ 1831 + 1832 + /** 1833 + * cail_pll_read - read PLL register 1834 + * 1835 + * @info: atom card_info pointer 1836 + * @reg: PLL register offset 1837 + * 1838 + * Provides a PLL register accessor for the atom interpreter (r4xx+). 1839 + * Returns the value of the PLL register. 1840 + */ 1841 + static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) 1842 + { 1843 + return 0; 1844 + } 1845 + 1846 + /** 1847 + * cail_pll_write - write PLL register 1848 + * 1849 + * @info: atom card_info pointer 1850 + * @reg: PLL register offset 1851 + * @val: value to write to the pll register 1852 + * 1853 + * Provides a PLL register accessor for the atom interpreter (r4xx+). 1854 + */ 1855 + static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) 1856 + { 1857 + 1858 + } 1859 + 1860 + /** 1861 + * cail_mc_read - read MC (Memory Controller) register 1862 + * 1863 + * @info: atom card_info pointer 1864 + * @reg: MC register offset 1865 + * 1866 + * Provides an MC register accessor for the atom interpreter (r4xx+). 1867 + * Returns the value of the MC register. 1868 + */ 1869 + static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) 1870 + { 1871 + return 0; 1872 + } 1873 + 1874 + /** 1875 + * cail_mc_write - write MC (Memory Controller) register 1876 + * 1877 + * @info: atom card_info pointer 1878 + * @reg: MC register offset 1879 + * @val: value to write to the pll register 1880 + * 1881 + * Provides a MC register accessor for the atom interpreter (r4xx+). 1882 + */ 1883 + static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) 1884 + { 1885 + 1886 + } 1887 + 1888 + /** 1889 + * cail_reg_write - write MMIO register 1890 + * 1891 + * @info: atom card_info pointer 1892 + * @reg: MMIO register offset 1893 + * @val: value to write to the pll register 1894 + * 1895 + * Provides a MMIO register accessor for the atom interpreter (r4xx+). 1896 + */ 1897 + static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) 1898 + { 1899 + struct amdgpu_device *adev = info->dev->dev_private; 1900 + 1901 + WREG32(reg, val); 1902 + } 1903 + 1904 + /** 1905 + * cail_reg_read - read MMIO register 1906 + * 1907 + * @info: atom card_info pointer 1908 + * @reg: MMIO register offset 1909 + * 1910 + * Provides an MMIO register accessor for the atom interpreter (r4xx+). 1911 + * Returns the value of the MMIO register. 1912 + */ 1913 + static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) 1914 + { 1915 + struct amdgpu_device *adev = info->dev->dev_private; 1916 + uint32_t r; 1917 + 1918 + r = RREG32(reg); 1919 + return r; 1920 + } 1921 + 1922 + /** 1923 + * cail_ioreg_write - write IO register 1924 + * 1925 + * @info: atom card_info pointer 1926 + * @reg: IO register offset 1927 + * @val: value to write to the pll register 1928 + * 1929 + * Provides a IO register accessor for the atom interpreter (r4xx+). 1930 + */ 1931 + static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) 1932 + { 1933 + struct amdgpu_device *adev = info->dev->dev_private; 1934 + 1935 + WREG32_IO(reg, val); 1936 + } 1937 + 1938 + /** 1939 + * cail_ioreg_read - read IO register 1940 + * 1941 + * @info: atom card_info pointer 1942 + * @reg: IO register offset 1943 + * 1944 + * Provides an IO register accessor for the atom interpreter (r4xx+). 1945 + * Returns the value of the IO register. 1946 + */ 1947 + static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) 1948 + { 1949 + struct amdgpu_device *adev = info->dev->dev_private; 1950 + uint32_t r; 1951 + 1952 + r = RREG32_IO(reg); 1953 + return r; 1954 + } 1955 + 1956 + static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev, 1957 + struct device_attribute *attr, 1958 + char *buf) 1959 + { 1960 + struct drm_device *ddev = dev_get_drvdata(dev); 1961 + struct amdgpu_device *adev = ddev->dev_private; 1962 + struct atom_context *ctx = adev->mode_info.atom_context; 1963 + 1964 + return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version); 1965 + } 1966 + 1967 + static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version, 1968 + NULL); 1969 + 1970 + /** 1971 + * amdgpu_atombios_fini - free the driver info and callbacks for atombios 1972 + * 1973 + * @adev: amdgpu_device pointer 1974 + * 1975 + * Frees the driver info and register access callbacks for the ATOM 1976 + * interpreter (r4xx+). 1977 + * Called at driver shutdown. 1978 + */ 1979 + void amdgpu_atombios_fini(struct amdgpu_device *adev) 1980 + { 1981 + if (adev->mode_info.atom_context) { 1982 + kfree(adev->mode_info.atom_context->scratch); 1983 + kfree(adev->mode_info.atom_context->iio); 1984 + } 1985 + kfree(adev->mode_info.atom_context); 1986 + adev->mode_info.atom_context = NULL; 1987 + kfree(adev->mode_info.atom_card_info); 1988 + adev->mode_info.atom_card_info = NULL; 1989 + device_remove_file(adev->dev, &dev_attr_vbios_version); 1990 + } 1991 + 1992 + /** 1993 + * amdgpu_atombios_init - init the driver info and callbacks for atombios 1994 + * 1995 + * @adev: amdgpu_device pointer 1996 + * 1997 + * Initializes the driver info and register access callbacks for the 1998 + * ATOM interpreter (r4xx+). 1999 + * Returns 0 on sucess, -ENOMEM on failure. 2000 + * Called at driver startup. 2001 + */ 2002 + int amdgpu_atombios_init(struct amdgpu_device *adev) 2003 + { 2004 + struct card_info *atom_card_info = 2005 + kzalloc(sizeof(struct card_info), GFP_KERNEL); 2006 + int ret; 2007 + 2008 + if (!atom_card_info) 2009 + return -ENOMEM; 2010 + 2011 + adev->mode_info.atom_card_info = atom_card_info; 2012 + atom_card_info->dev = adev->ddev; 2013 + atom_card_info->reg_read = cail_reg_read; 2014 + atom_card_info->reg_write = cail_reg_write; 2015 + /* needed for iio ops */ 2016 + if (adev->rio_mem) { 2017 + atom_card_info->ioreg_read = cail_ioreg_read; 2018 + atom_card_info->ioreg_write = cail_ioreg_write; 2019 + } else { 2020 + DRM_DEBUG("PCI I/O BAR is not found. Using MMIO to access ATOM BIOS\n"); 2021 + atom_card_info->ioreg_read = cail_reg_read; 2022 + atom_card_info->ioreg_write = cail_reg_write; 2023 + } 2024 + atom_card_info->mc_read = cail_mc_read; 2025 + atom_card_info->mc_write = cail_mc_write; 2026 + atom_card_info->pll_read = cail_pll_read; 2027 + atom_card_info->pll_write = cail_pll_write; 2028 + 2029 + adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios); 2030 + if (!adev->mode_info.atom_context) { 2031 + amdgpu_atombios_fini(adev); 2032 + return -ENOMEM; 2033 + } 2034 + 2035 + mutex_init(&adev->mode_info.atom_context->mutex); 2036 + if (adev->is_atom_fw) { 2037 + amdgpu_atomfirmware_scratch_regs_init(adev); 2038 + amdgpu_atomfirmware_allocate_fb_scratch(adev); 2039 + } else { 2040 + amdgpu_atombios_scratch_regs_init(adev); 2041 + amdgpu_atombios_allocate_fb_scratch(adev); 2042 + } 2043 + 2044 + ret = device_create_file(adev->dev, &dev_attr_vbios_version); 2045 + if (ret) { 2046 + DRM_ERROR("Failed to create device file for VBIOS version\n"); 2047 + return ret; 2048 + } 2049 + 2050 + return 0; 2051 + } 2052 +
+2 -2
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.h
··· 195 195 bool amdgpu_atombios_has_gpu_virtualization_table(struct amdgpu_device *adev); 196 196 197 197 void amdgpu_atombios_scratch_regs_lock(struct amdgpu_device *adev, bool lock); 198 - void amdgpu_atombios_scratch_regs_init(struct amdgpu_device *adev); 199 198 void amdgpu_atombios_scratch_regs_engine_hung(struct amdgpu_device *adev, 200 199 bool hung); 201 200 bool amdgpu_atombios_scratch_need_asic_init(struct amdgpu_device *adev); ··· 216 217 u8 voltage_type, 217 218 u8 *svd_gpio_id, u8 *svc_gpio_id); 218 219 219 - int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev); 220 + void amdgpu_atombios_fini(struct amdgpu_device *adev); 221 + int amdgpu_atombios_init(struct amdgpu_device *adev); 220 222 221 223 #endif
-231
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
··· 898 898 adev->dummy_page.page = NULL; 899 899 } 900 900 901 - 902 - /* ATOM accessor methods */ 903 - /* 904 - * ATOM is an interpreted byte code stored in tables in the vbios. The 905 - * driver registers callbacks to access registers and the interpreter 906 - * in the driver parses the tables and executes then to program specific 907 - * actions (set display modes, asic init, etc.). See amdgpu_atombios.c, 908 - * atombios.h, and atom.c 909 - */ 910 - 911 - /** 912 - * cail_pll_read - read PLL register 913 - * 914 - * @info: atom card_info pointer 915 - * @reg: PLL register offset 916 - * 917 - * Provides a PLL register accessor for the atom interpreter (r4xx+). 918 - * Returns the value of the PLL register. 919 - */ 920 - static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) 921 - { 922 - return 0; 923 - } 924 - 925 - /** 926 - * cail_pll_write - write PLL register 927 - * 928 - * @info: atom card_info pointer 929 - * @reg: PLL register offset 930 - * @val: value to write to the pll register 931 - * 932 - * Provides a PLL register accessor for the atom interpreter (r4xx+). 933 - */ 934 - static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) 935 - { 936 - 937 - } 938 - 939 - /** 940 - * cail_mc_read - read MC (Memory Controller) register 941 - * 942 - * @info: atom card_info pointer 943 - * @reg: MC register offset 944 - * 945 - * Provides an MC register accessor for the atom interpreter (r4xx+). 946 - * Returns the value of the MC register. 947 - */ 948 - static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) 949 - { 950 - return 0; 951 - } 952 - 953 - /** 954 - * cail_mc_write - write MC (Memory Controller) register 955 - * 956 - * @info: atom card_info pointer 957 - * @reg: MC register offset 958 - * @val: value to write to the pll register 959 - * 960 - * Provides a MC register accessor for the atom interpreter (r4xx+). 961 - */ 962 - static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) 963 - { 964 - 965 - } 966 - 967 - /** 968 - * cail_reg_write - write MMIO register 969 - * 970 - * @info: atom card_info pointer 971 - * @reg: MMIO register offset 972 - * @val: value to write to the pll register 973 - * 974 - * Provides a MMIO register accessor for the atom interpreter (r4xx+). 975 - */ 976 - static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) 977 - { 978 - struct amdgpu_device *adev = info->dev->dev_private; 979 - 980 - WREG32(reg, val); 981 - } 982 - 983 - /** 984 - * cail_reg_read - read MMIO register 985 - * 986 - * @info: atom card_info pointer 987 - * @reg: MMIO register offset 988 - * 989 - * Provides an MMIO register accessor for the atom interpreter (r4xx+). 990 - * Returns the value of the MMIO register. 991 - */ 992 - static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) 993 - { 994 - struct amdgpu_device *adev = info->dev->dev_private; 995 - uint32_t r; 996 - 997 - r = RREG32(reg); 998 - return r; 999 - } 1000 - 1001 - /** 1002 - * cail_ioreg_write - write IO register 1003 - * 1004 - * @info: atom card_info pointer 1005 - * @reg: IO register offset 1006 - * @val: value to write to the pll register 1007 - * 1008 - * Provides a IO register accessor for the atom interpreter (r4xx+). 1009 - */ 1010 - static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) 1011 - { 1012 - struct amdgpu_device *adev = info->dev->dev_private; 1013 - 1014 - WREG32_IO(reg, val); 1015 - } 1016 - 1017 - /** 1018 - * cail_ioreg_read - read IO register 1019 - * 1020 - * @info: atom card_info pointer 1021 - * @reg: IO register offset 1022 - * 1023 - * Provides an IO register accessor for the atom interpreter (r4xx+). 1024 - * Returns the value of the IO register. 1025 - */ 1026 - static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) 1027 - { 1028 - struct amdgpu_device *adev = info->dev->dev_private; 1029 - uint32_t r; 1030 - 1031 - r = RREG32_IO(reg); 1032 - return r; 1033 - } 1034 - 1035 - static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev, 1036 - struct device_attribute *attr, 1037 - char *buf) 1038 - { 1039 - struct drm_device *ddev = dev_get_drvdata(dev); 1040 - struct amdgpu_device *adev = ddev->dev_private; 1041 - struct atom_context *ctx = adev->mode_info.atom_context; 1042 - 1043 - return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version); 1044 - } 1045 - 1046 - static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version, 1047 - NULL); 1048 - 1049 - /** 1050 - * amdgpu_atombios_fini - free the driver info and callbacks for atombios 1051 - * 1052 - * @adev: amdgpu_device pointer 1053 - * 1054 - * Frees the driver info and register access callbacks for the ATOM 1055 - * interpreter (r4xx+). 1056 - * Called at driver shutdown. 1057 - */ 1058 - static void amdgpu_atombios_fini(struct amdgpu_device *adev) 1059 - { 1060 - if (adev->mode_info.atom_context) { 1061 - kfree(adev->mode_info.atom_context->scratch); 1062 - kfree(adev->mode_info.atom_context->iio); 1063 - } 1064 - kfree(adev->mode_info.atom_context); 1065 - adev->mode_info.atom_context = NULL; 1066 - kfree(adev->mode_info.atom_card_info); 1067 - adev->mode_info.atom_card_info = NULL; 1068 - device_remove_file(adev->dev, &dev_attr_vbios_version); 1069 - } 1070 - 1071 - /** 1072 - * amdgpu_atombios_init - init the driver info and callbacks for atombios 1073 - * 1074 - * @adev: amdgpu_device pointer 1075 - * 1076 - * Initializes the driver info and register access callbacks for the 1077 - * ATOM interpreter (r4xx+). 1078 - * Returns 0 on sucess, -ENOMEM on failure. 1079 - * Called at driver startup. 1080 - */ 1081 - static int amdgpu_atombios_init(struct amdgpu_device *adev) 1082 - { 1083 - struct card_info *atom_card_info = 1084 - kzalloc(sizeof(struct card_info), GFP_KERNEL); 1085 - int ret; 1086 - 1087 - if (!atom_card_info) 1088 - return -ENOMEM; 1089 - 1090 - adev->mode_info.atom_card_info = atom_card_info; 1091 - atom_card_info->dev = adev->ddev; 1092 - atom_card_info->reg_read = cail_reg_read; 1093 - atom_card_info->reg_write = cail_reg_write; 1094 - /* needed for iio ops */ 1095 - if (adev->rio_mem) { 1096 - atom_card_info->ioreg_read = cail_ioreg_read; 1097 - atom_card_info->ioreg_write = cail_ioreg_write; 1098 - } else { 1099 - DRM_DEBUG("PCI I/O BAR is not found. Using MMIO to access ATOM BIOS\n"); 1100 - atom_card_info->ioreg_read = cail_reg_read; 1101 - atom_card_info->ioreg_write = cail_reg_write; 1102 - } 1103 - atom_card_info->mc_read = cail_mc_read; 1104 - atom_card_info->mc_write = cail_mc_write; 1105 - atom_card_info->pll_read = cail_pll_read; 1106 - atom_card_info->pll_write = cail_pll_write; 1107 - 1108 - adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios); 1109 - if (!adev->mode_info.atom_context) { 1110 - amdgpu_atombios_fini(adev); 1111 - return -ENOMEM; 1112 - } 1113 - 1114 - mutex_init(&adev->mode_info.atom_context->mutex); 1115 - if (adev->is_atom_fw) { 1116 - amdgpu_atomfirmware_scratch_regs_init(adev); 1117 - amdgpu_atomfirmware_allocate_fb_scratch(adev); 1118 - } else { 1119 - amdgpu_atombios_scratch_regs_init(adev); 1120 - amdgpu_atombios_allocate_fb_scratch(adev); 1121 - } 1122 - 1123 - ret = device_create_file(adev->dev, &dev_attr_vbios_version); 1124 - if (ret) { 1125 - DRM_ERROR("Failed to create device file for VBIOS version\n"); 1126 - return ret; 1127 - } 1128 - 1129 - return 0; 1130 - } 1131 - 1132 901 /* if we get transitioned to only one device, take VGA back */ 1133 902 /** 1134 903 * amdgpu_vga_set_decode - enable/disable vga decode