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

Configure Feed

Select the types of activity you want to include in your feed.

drm/amdgpu/ttm: Allocate/Free 4K MMIO_REMAP Singleton

Add mmio_remap bookkeeping to amdgpu_device and introduce
amdgpu_ttm_mmio_remap_bo_init()/fini() to manage a kernel-owned,
one-page (4K) BO in AMDGPU_GEM_DOMAIN_MMIO_REMAP.

Bookkeeping:
- adev->rmmio_remap.bo : kernel-owned singleton BO

The BO is allocated during TTM init when a remap bus address is available
(adev->rmmio_remap.bus_addr) and PAGE_SIZE <= AMDGPU_GPU_PAGE_SIZE (4K),
and freed during TTM fini.

v2:
- Check mmio_remap bus address (adev->rmmio_remap.bus_addr) instead of
rmmio_base. (Alex)
- Skip quietly if PAGE_SIZE > AMDGPU_GPU_PAGE_SIZE or no bus address
(no warn). (Alex)
- Use `amdgpu_bo_create()` (not *_kernel) - Only with this The object
is stored in adev->mmio_remap.bo and will later be exposed to
userspace via a GEM handle. (Christian)

v3:
- Remove obvious comment before amdgpu_ttm_mmio_remap_bo_fini() call.
(Alex)

v4:
- Squash bookkeeping into this patch (Christian)

Suggested-by: Christian König <christian.koenig@amd.com>
Suggested-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>

authored by

Srinivasan Shanmugam and committed by
Alex Deucher
2a7a794e 9e46b8bb

+60
+1
drivers/gpu/drm/amd/amdgpu/amdgpu.h
··· 752 752 struct amdgpu_mmio_remap { 753 753 u32 reg_offset; 754 754 resource_size_t bus_addr; 755 + struct amdgpu_bo *bo; 755 756 }; 756 757 757 758 /* Define the HW IP blocks will be used in driver , add more if necessary */
+59
drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
··· 1854 1854 adev->mman.ttm_pools = NULL; 1855 1855 } 1856 1856 1857 + /** 1858 + * amdgpu_ttm_mmio_remap_bo_init - Allocate the singleton 4K MMIO_REMAP BO 1859 + * @adev: amdgpu device 1860 + * 1861 + * Allocates a one-page (4K) GEM BO in AMDGPU_GEM_DOMAIN_MMIO_REMAP when the 1862 + * hardware exposes a remap base (adev->rmmio_remap.bus_addr) and the host 1863 + * PAGE_SIZE is <= AMDGPU_GPU_PAGE_SIZE (4K). The BO is created as a regular 1864 + * GEM object (amdgpu_bo_create). 1865 + * 1866 + * Return: 1867 + * * 0 on success or intentional skip (feature not present/unsupported) 1868 + * * negative errno on allocation failure 1869 + */ 1870 + static int amdgpu_ttm_mmio_remap_bo_init(struct amdgpu_device *adev) 1871 + { 1872 + struct amdgpu_bo_param bp; 1873 + int r; 1874 + 1875 + /* Skip if HW doesn't expose remap, or if PAGE_SIZE > AMDGPU_GPU_PAGE_SIZE (4K). */ 1876 + if (!adev->rmmio_remap.bus_addr || PAGE_SIZE > AMDGPU_GPU_PAGE_SIZE) 1877 + return 0; 1878 + 1879 + memset(&bp, 0, sizeof(bp)); 1880 + 1881 + /* Create exactly one GEM BO in the MMIO_REMAP domain. */ 1882 + bp.type = ttm_bo_type_device; /* userspace-mappable GEM */ 1883 + bp.size = AMDGPU_GPU_PAGE_SIZE; /* 4K */ 1884 + bp.byte_align = AMDGPU_GPU_PAGE_SIZE; 1885 + bp.domain = AMDGPU_GEM_DOMAIN_MMIO_REMAP; 1886 + bp.flags = 0; 1887 + bp.resv = NULL; 1888 + bp.bo_ptr_size = sizeof(struct amdgpu_bo); 1889 + 1890 + r = amdgpu_bo_create(adev, &bp, &adev->rmmio_remap.bo); 1891 + if (r) 1892 + return r; 1893 + 1894 + return 0; 1895 + } 1896 + 1897 + /** 1898 + * amdgpu_ttm_mmio_remap_bo_fini - Free the singleton MMIO_REMAP BO 1899 + * @adev: amdgpu device 1900 + * 1901 + * Frees the kernel-owned MMIO_REMAP BO if it was allocated by 1902 + * amdgpu_ttm_mmio_remap_bo_init(). 1903 + */ 1904 + static void amdgpu_ttm_mmio_remap_bo_fini(struct amdgpu_device *adev) 1905 + { 1906 + amdgpu_bo_unref(&adev->rmmio_remap.bo); 1907 + adev->rmmio_remap.bo = NULL; 1908 + } 1909 + 1857 1910 /* 1858 1911 * amdgpu_ttm_init - Init the memory management (ttm) as well as various 1859 1912 * gtt/vram related fields. ··· 2081 2028 return r; 2082 2029 } 2083 2030 2031 + /* Allocate the singleton MMIO_REMAP BO (4K) if supported */ 2032 + r = amdgpu_ttm_mmio_remap_bo_init(adev); 2033 + if (r) 2034 + return r; 2035 + 2084 2036 /* Initialize preemptible memory pool */ 2085 2037 r = amdgpu_preempt_mgr_init(adev); 2086 2038 if (r) { ··· 2149 2091 amdgpu_bo_free_kernel(&adev->mman.sdma_access_bo, NULL, 2150 2092 &adev->mman.sdma_access_ptr); 2151 2093 2094 + amdgpu_ttm_mmio_remap_bo_fini(adev); 2152 2095 amdgpu_ttm_fw_reserve_vram_fini(adev); 2153 2096 amdgpu_ttm_drv_reserve_vram_fini(adev); 2154 2097