diff options
Diffstat (limited to 'drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c')
-rw-r--r-- | drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | 236 |
1 files changed, 234 insertions, 2 deletions
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c index ffaf0534e33c..bf872f694f50 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <drm/amdgpu_drm.h> | 27 | #include <drm/amdgpu_drm.h> |
28 | #include "amdgpu.h" | 28 | #include "amdgpu.h" |
29 | #include "amdgpu_atombios.h" | 29 | #include "amdgpu_atombios.h" |
30 | #include "amdgpu_atomfirmware.h" | ||
30 | #include "amdgpu_i2c.h" | 31 | #include "amdgpu_i2c.h" |
31 | 32 | ||
32 | #include "atom.h" | 33 | #include "atom.h" |
@@ -1699,7 +1700,7 @@ void amdgpu_atombios_scratch_regs_lock(struct amdgpu_device *adev, bool lock) | |||
1699 | WREG32(adev->bios_scratch_reg_offset + 6, bios_6_scratch); | 1700 | WREG32(adev->bios_scratch_reg_offset + 6, bios_6_scratch); |
1700 | } | 1701 | } |
1701 | 1702 | ||
1702 | void amdgpu_atombios_scratch_regs_init(struct amdgpu_device *adev) | 1703 | static void amdgpu_atombios_scratch_regs_init(struct amdgpu_device *adev) |
1703 | { | 1704 | { |
1704 | uint32_t bios_2_scratch, bios_6_scratch; | 1705 | uint32_t bios_2_scratch, bios_6_scratch; |
1705 | 1706 | ||
@@ -1776,7 +1777,7 @@ void amdgpu_atombios_copy_swap(u8 *dst, u8 *src, u8 num_bytes, bool to_le) | |||
1776 | #endif | 1777 | #endif |
1777 | } | 1778 | } |
1778 | 1779 | ||
1779 | int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev) | 1780 | static int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev) |
1780 | { | 1781 | { |
1781 | struct atom_context *ctx = adev->mode_info.atom_context; | 1782 | struct atom_context *ctx = adev->mode_info.atom_context; |
1782 | int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware); | 1783 | int index = GetIndexIntoMasterTable(DATA, VRAM_UsageByFirmware); |
@@ -1819,3 +1820,234 @@ int amdgpu_atombios_allocate_fb_scratch(struct amdgpu_device *adev) | |||
1819 | ctx->scratch_size_bytes = usage_bytes; | 1820 | ctx->scratch_size_bytes = usage_bytes; |
1820 | return 0; | 1821 | return 0; |
1821 | } | 1822 | } |
1823 | |||
1824 | /* ATOM accessor methods */ | ||
1825 | /* | ||
1826 | * ATOM is an interpreted byte code stored in tables in the vbios. The | ||
1827 | * driver registers callbacks to access registers and the interpreter | ||
1828 | * in the driver parses the tables and executes then to program specific | ||
1829 | * actions (set display modes, asic init, etc.). See amdgpu_atombios.c, | ||
1830 | * atombios.h, and atom.c | ||
1831 | */ | ||
1832 | |||
1833 | /** | ||
1834 | * cail_pll_read - read PLL register | ||
1835 | * | ||
1836 | * @info: atom card_info pointer | ||
1837 | * @reg: PLL register offset | ||
1838 | * | ||
1839 | * Provides a PLL register accessor for the atom interpreter (r4xx+). | ||
1840 | * Returns the value of the PLL register. | ||
1841 | */ | ||
1842 | static uint32_t cail_pll_read(struct card_info *info, uint32_t reg) | ||
1843 | { | ||
1844 | return 0; | ||
1845 | } | ||
1846 | |||
1847 | /** | ||
1848 | * cail_pll_write - write PLL register | ||
1849 | * | ||
1850 | * @info: atom card_info pointer | ||
1851 | * @reg: PLL register offset | ||
1852 | * @val: value to write to the pll register | ||
1853 | * | ||
1854 | * Provides a PLL register accessor for the atom interpreter (r4xx+). | ||
1855 | */ | ||
1856 | static void cail_pll_write(struct card_info *info, uint32_t reg, uint32_t val) | ||
1857 | { | ||
1858 | |||
1859 | } | ||
1860 | |||
1861 | /** | ||
1862 | * cail_mc_read - read MC (Memory Controller) register | ||
1863 | * | ||
1864 | * @info: atom card_info pointer | ||
1865 | * @reg: MC register offset | ||
1866 | * | ||
1867 | * Provides an MC register accessor for the atom interpreter (r4xx+). | ||
1868 | * Returns the value of the MC register. | ||
1869 | */ | ||
1870 | static uint32_t cail_mc_read(struct card_info *info, uint32_t reg) | ||
1871 | { | ||
1872 | return 0; | ||
1873 | } | ||
1874 | |||
1875 | /** | ||
1876 | * cail_mc_write - write MC (Memory Controller) register | ||
1877 | * | ||
1878 | * @info: atom card_info pointer | ||
1879 | * @reg: MC register offset | ||
1880 | * @val: value to write to the pll register | ||
1881 | * | ||
1882 | * Provides a MC register accessor for the atom interpreter (r4xx+). | ||
1883 | */ | ||
1884 | static void cail_mc_write(struct card_info *info, uint32_t reg, uint32_t val) | ||
1885 | { | ||
1886 | |||
1887 | } | ||
1888 | |||
1889 | /** | ||
1890 | * cail_reg_write - write MMIO register | ||
1891 | * | ||
1892 | * @info: atom card_info pointer | ||
1893 | * @reg: MMIO register offset | ||
1894 | * @val: value to write to the pll register | ||
1895 | * | ||
1896 | * Provides a MMIO register accessor for the atom interpreter (r4xx+). | ||
1897 | */ | ||
1898 | static void cail_reg_write(struct card_info *info, uint32_t reg, uint32_t val) | ||
1899 | { | ||
1900 | struct amdgpu_device *adev = info->dev->dev_private; | ||
1901 | |||
1902 | WREG32(reg, val); | ||
1903 | } | ||
1904 | |||
1905 | /** | ||
1906 | * cail_reg_read - read MMIO register | ||
1907 | * | ||
1908 | * @info: atom card_info pointer | ||
1909 | * @reg: MMIO register offset | ||
1910 | * | ||
1911 | * Provides an MMIO register accessor for the atom interpreter (r4xx+). | ||
1912 | * Returns the value of the MMIO register. | ||
1913 | */ | ||
1914 | static uint32_t cail_reg_read(struct card_info *info, uint32_t reg) | ||
1915 | { | ||
1916 | struct amdgpu_device *adev = info->dev->dev_private; | ||
1917 | uint32_t r; | ||
1918 | |||
1919 | r = RREG32(reg); | ||
1920 | return r; | ||
1921 | } | ||
1922 | |||
1923 | /** | ||
1924 | * cail_ioreg_write - write IO register | ||
1925 | * | ||
1926 | * @info: atom card_info pointer | ||
1927 | * @reg: IO register offset | ||
1928 | * @val: value to write to the pll register | ||
1929 | * | ||
1930 | * Provides a IO register accessor for the atom interpreter (r4xx+). | ||
1931 | */ | ||
1932 | static void cail_ioreg_write(struct card_info *info, uint32_t reg, uint32_t val) | ||
1933 | { | ||
1934 | struct amdgpu_device *adev = info->dev->dev_private; | ||
1935 | |||
1936 | WREG32_IO(reg, val); | ||
1937 | } | ||
1938 | |||
1939 | /** | ||
1940 | * cail_ioreg_read - read IO register | ||
1941 | * | ||
1942 | * @info: atom card_info pointer | ||
1943 | * @reg: IO register offset | ||
1944 | * | ||
1945 | * Provides an IO register accessor for the atom interpreter (r4xx+). | ||
1946 | * Returns the value of the IO register. | ||
1947 | */ | ||
1948 | static uint32_t cail_ioreg_read(struct card_info *info, uint32_t reg) | ||
1949 | { | ||
1950 | struct amdgpu_device *adev = info->dev->dev_private; | ||
1951 | uint32_t r; | ||
1952 | |||
1953 | r = RREG32_IO(reg); | ||
1954 | return r; | ||
1955 | } | ||
1956 | |||
1957 | static ssize_t amdgpu_atombios_get_vbios_version(struct device *dev, | ||
1958 | struct device_attribute *attr, | ||
1959 | char *buf) | ||
1960 | { | ||
1961 | struct drm_device *ddev = dev_get_drvdata(dev); | ||
1962 | struct amdgpu_device *adev = ddev->dev_private; | ||
1963 | struct atom_context *ctx = adev->mode_info.atom_context; | ||
1964 | |||
1965 | return snprintf(buf, PAGE_SIZE, "%s\n", ctx->vbios_version); | ||
1966 | } | ||
1967 | |||
1968 | static DEVICE_ATTR(vbios_version, 0444, amdgpu_atombios_get_vbios_version, | ||
1969 | NULL); | ||
1970 | |||
1971 | /** | ||
1972 | * amdgpu_atombios_fini - free the driver info and callbacks for atombios | ||
1973 | * | ||
1974 | * @adev: amdgpu_device pointer | ||
1975 | * | ||
1976 | * Frees the driver info and register access callbacks for the ATOM | ||
1977 | * interpreter (r4xx+). | ||
1978 | * Called at driver shutdown. | ||
1979 | */ | ||
1980 | void amdgpu_atombios_fini(struct amdgpu_device *adev) | ||
1981 | { | ||
1982 | if (adev->mode_info.atom_context) { | ||
1983 | kfree(adev->mode_info.atom_context->scratch); | ||
1984 | kfree(adev->mode_info.atom_context->iio); | ||
1985 | } | ||
1986 | kfree(adev->mode_info.atom_context); | ||
1987 | adev->mode_info.atom_context = NULL; | ||
1988 | kfree(adev->mode_info.atom_card_info); | ||
1989 | adev->mode_info.atom_card_info = NULL; | ||
1990 | device_remove_file(adev->dev, &dev_attr_vbios_version); | ||
1991 | } | ||
1992 | |||
1993 | /** | ||
1994 | * amdgpu_atombios_init - init the driver info and callbacks for atombios | ||
1995 | * | ||
1996 | * @adev: amdgpu_device pointer | ||
1997 | * | ||
1998 | * Initializes the driver info and register access callbacks for the | ||
1999 | * ATOM interpreter (r4xx+). | ||
2000 | * Returns 0 on sucess, -ENOMEM on failure. | ||
2001 | * Called at driver startup. | ||
2002 | */ | ||
2003 | int amdgpu_atombios_init(struct amdgpu_device *adev) | ||
2004 | { | ||
2005 | struct card_info *atom_card_info = | ||
2006 | kzalloc(sizeof(struct card_info), GFP_KERNEL); | ||
2007 | int ret; | ||
2008 | |||
2009 | if (!atom_card_info) | ||
2010 | return -ENOMEM; | ||
2011 | |||
2012 | adev->mode_info.atom_card_info = atom_card_info; | ||
2013 | atom_card_info->dev = adev->ddev; | ||
2014 | atom_card_info->reg_read = cail_reg_read; | ||
2015 | atom_card_info->reg_write = cail_reg_write; | ||
2016 | /* needed for iio ops */ | ||
2017 | if (adev->rio_mem) { | ||
2018 | atom_card_info->ioreg_read = cail_ioreg_read; | ||
2019 | atom_card_info->ioreg_write = cail_ioreg_write; | ||
2020 | } else { | ||
2021 | DRM_DEBUG("PCI I/O BAR is not found. Using MMIO to access ATOM BIOS\n"); | ||
2022 | atom_card_info->ioreg_read = cail_reg_read; | ||
2023 | atom_card_info->ioreg_write = cail_reg_write; | ||
2024 | } | ||
2025 | atom_card_info->mc_read = cail_mc_read; | ||
2026 | atom_card_info->mc_write = cail_mc_write; | ||
2027 | atom_card_info->pll_read = cail_pll_read; | ||
2028 | atom_card_info->pll_write = cail_pll_write; | ||
2029 | |||
2030 | adev->mode_info.atom_context = amdgpu_atom_parse(atom_card_info, adev->bios); | ||
2031 | if (!adev->mode_info.atom_context) { | ||
2032 | amdgpu_atombios_fini(adev); | ||
2033 | return -ENOMEM; | ||
2034 | } | ||
2035 | |||
2036 | mutex_init(&adev->mode_info.atom_context->mutex); | ||
2037 | if (adev->is_atom_fw) { | ||
2038 | amdgpu_atomfirmware_scratch_regs_init(adev); | ||
2039 | amdgpu_atomfirmware_allocate_fb_scratch(adev); | ||
2040 | } else { | ||
2041 | amdgpu_atombios_scratch_regs_init(adev); | ||
2042 | amdgpu_atombios_allocate_fb_scratch(adev); | ||
2043 | } | ||
2044 | |||
2045 | ret = device_create_file(adev->dev, &dev_attr_vbios_version); | ||
2046 | if (ret) { | ||
2047 | DRM_ERROR("Failed to create device file for VBIOS version\n"); | ||
2048 | return ret; | ||
2049 | } | ||
2050 | |||
2051 | return 0; | ||
2052 | } | ||
2053 | |||