2015-04-21 03:55:21 +07:00
|
|
|
/*
|
|
|
|
* Copyright 2008 Advanced Micro Devices, Inc.
|
|
|
|
* Copyright 2008 Red Hat Inc.
|
|
|
|
* Copyright 2009 Jerome Glisse.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
* OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*
|
|
|
|
* Authors: Dave Airlie
|
|
|
|
* Alex Deucher
|
|
|
|
* Jerome Glisse
|
|
|
|
*/
|
2019-06-10 05:07:56 +07:00
|
|
|
|
|
|
|
#include <linux/pci.h>
|
|
|
|
#include <linux/vmalloc.h>
|
|
|
|
|
2015-04-21 03:55:21 +07:00
|
|
|
#include <drm/amdgpu_drm.h>
|
2017-05-09 05:58:17 +07:00
|
|
|
#ifdef CONFIG_X86
|
|
|
|
#include <asm/set_memory.h>
|
|
|
|
#endif
|
2015-04-21 03:55:21 +07:00
|
|
|
#include "amdgpu.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* GART
|
|
|
|
* The GART (Graphics Aperture Remapping Table) is an aperture
|
|
|
|
* in the GPU's address space. System pages can be mapped into
|
|
|
|
* the aperture and look like contiguous pages from the GPU's
|
|
|
|
* perspective. A page table maps the pages in the aperture
|
|
|
|
* to the actual backing pages in system memory.
|
|
|
|
*
|
|
|
|
* Radeon GPUs support both an internal GART, as described above,
|
|
|
|
* and AGP. AGP works similarly, but the GART table is configured
|
|
|
|
* and maintained by the northbridge rather than the driver.
|
|
|
|
* Radeon hw has a separate AGP aperture that is programmed to
|
|
|
|
* point to the AGP aperture provided by the northbridge and the
|
|
|
|
* requests are passed through to the northbridge aperture.
|
|
|
|
* Both AGP and internal GART can be used at the same time, however
|
|
|
|
* that is not currently supported by the driver.
|
|
|
|
*
|
|
|
|
* This file handles the common internal GART management.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common GART table functions.
|
|
|
|
*/
|
2017-06-26 16:37:49 +07:00
|
|
|
|
2017-12-16 04:28:33 +07:00
|
|
|
/**
|
|
|
|
* amdgpu_dummy_page_init - init dummy page used by the driver
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Allocate the dummy page used by the driver (all asics).
|
|
|
|
* This dummy page is used by the driver as a filler for gart entries
|
|
|
|
* when pages are taken out of the GART
|
|
|
|
* Returns 0 on sucess, -ENOMEM on failure.
|
|
|
|
*/
|
|
|
|
static int amdgpu_gart_dummy_page_init(struct amdgpu_device *adev)
|
|
|
|
{
|
2018-02-22 14:35:11 +07:00
|
|
|
struct page *dummy_page = adev->mman.bdev.glob->dummy_read_page;
|
|
|
|
|
|
|
|
if (adev->dummy_page_addr)
|
2017-12-16 04:28:33 +07:00
|
|
|
return 0;
|
2018-02-22 14:35:11 +07:00
|
|
|
adev->dummy_page_addr = pci_map_page(adev->pdev, dummy_page, 0,
|
|
|
|
PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
|
|
|
|
if (pci_dma_mapping_error(adev->pdev, adev->dummy_page_addr)) {
|
2017-12-16 04:28:33 +07:00
|
|
|
dev_err(&adev->pdev->dev, "Failed to DMA MAP the dummy page\n");
|
2018-02-22 14:35:11 +07:00
|
|
|
adev->dummy_page_addr = 0;
|
2017-12-16 04:28:33 +07:00
|
|
|
return -ENOMEM;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_dummy_page_fini - free dummy page used by the driver
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Frees the dummy page used by the driver (all asics).
|
|
|
|
*/
|
|
|
|
static void amdgpu_gart_dummy_page_fini(struct amdgpu_device *adev)
|
|
|
|
{
|
2018-02-22 14:35:11 +07:00
|
|
|
if (!adev->dummy_page_addr)
|
2017-12-16 04:28:33 +07:00
|
|
|
return;
|
2018-02-22 14:35:11 +07:00
|
|
|
pci_unmap_page(adev->pdev, adev->dummy_page_addr,
|
|
|
|
PAGE_SIZE, PCI_DMA_BIDIRECTIONAL);
|
|
|
|
adev->dummy_page_addr = 0;
|
2017-12-16 04:28:33 +07:00
|
|
|
}
|
|
|
|
|
2015-04-21 03:55:21 +07:00
|
|
|
/**
|
|
|
|
* amdgpu_gart_table_vram_alloc - allocate vram for gart page table
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Allocate video memory for GART page table
|
|
|
|
* (pcie r4xx, r5xx+). These asics require the
|
|
|
|
* gart table to be in video memory.
|
|
|
|
* Returns 0 for success, error for failure.
|
|
|
|
*/
|
|
|
|
int amdgpu_gart_table_vram_alloc(struct amdgpu_device *adev)
|
|
|
|
{
|
2017-11-21 12:29:14 +07:00
|
|
|
int r;
|
|
|
|
|
2018-08-21 22:07:47 +07:00
|
|
|
if (adev->gart.bo == NULL) {
|
2018-04-16 17:27:50 +07:00
|
|
|
struct amdgpu_bo_param bp;
|
|
|
|
|
|
|
|
memset(&bp, 0, sizeof(bp));
|
|
|
|
bp.size = adev->gart.table_size;
|
|
|
|
bp.byte_align = PAGE_SIZE;
|
|
|
|
bp.domain = AMDGPU_GEM_DOMAIN_VRAM;
|
|
|
|
bp.flags = AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED |
|
|
|
|
AMDGPU_GEM_CREATE_VRAM_CONTIGUOUS;
|
|
|
|
bp.type = ttm_bo_type_kernel;
|
|
|
|
bp.resv = NULL;
|
2018-08-21 22:07:47 +07:00
|
|
|
r = amdgpu_bo_create(adev, &bp, &adev->gart.bo);
|
2017-11-21 12:29:14 +07:00
|
|
|
if (r) {
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gart_table_vram_pin - pin gart page table in vram
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Pin the GART page table in vram so it will not be moved
|
|
|
|
* by the memory manager (pcie r4xx, r5xx+). These asics require the
|
|
|
|
* gart table to be in video memory.
|
|
|
|
* Returns 0 for success, error for failure.
|
|
|
|
*/
|
|
|
|
int amdgpu_gart_table_vram_pin(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2018-08-21 22:07:47 +07:00
|
|
|
r = amdgpu_bo_reserve(adev->gart.bo, false);
|
2017-11-21 12:29:14 +07:00
|
|
|
if (unlikely(r != 0))
|
|
|
|
return r;
|
2018-08-21 22:07:47 +07:00
|
|
|
r = amdgpu_bo_pin(adev->gart.bo, AMDGPU_GEM_DOMAIN_VRAM);
|
2017-11-21 12:29:14 +07:00
|
|
|
if (r) {
|
2018-08-21 22:07:47 +07:00
|
|
|
amdgpu_bo_unreserve(adev->gart.bo);
|
2017-11-21 12:29:14 +07:00
|
|
|
return r;
|
|
|
|
}
|
2018-08-21 22:07:47 +07:00
|
|
|
r = amdgpu_bo_kmap(adev->gart.bo, &adev->gart.ptr);
|
2017-11-21 12:29:14 +07:00
|
|
|
if (r)
|
2018-08-21 22:07:47 +07:00
|
|
|
amdgpu_bo_unpin(adev->gart.bo);
|
|
|
|
amdgpu_bo_unreserve(adev->gart.bo);
|
2017-11-21 12:29:14 +07:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gart_table_vram_unpin - unpin gart page table in vram
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Unpin the GART page table in vram (pcie r4xx, r5xx+).
|
|
|
|
* These asics require the gart table to be in video memory.
|
|
|
|
*/
|
|
|
|
void amdgpu_gart_table_vram_unpin(struct amdgpu_device *adev)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
|
2018-08-21 22:07:47 +07:00
|
|
|
if (adev->gart.bo == NULL) {
|
2017-11-21 12:29:14 +07:00
|
|
|
return;
|
|
|
|
}
|
2018-08-21 22:07:47 +07:00
|
|
|
r = amdgpu_bo_reserve(adev->gart.bo, true);
|
2017-11-21 12:29:14 +07:00
|
|
|
if (likely(r == 0)) {
|
2018-08-21 22:07:47 +07:00
|
|
|
amdgpu_bo_kunmap(adev->gart.bo);
|
|
|
|
amdgpu_bo_unpin(adev->gart.bo);
|
|
|
|
amdgpu_bo_unreserve(adev->gart.bo);
|
2017-11-21 12:29:14 +07:00
|
|
|
adev->gart.ptr = NULL;
|
|
|
|
}
|
2015-04-21 03:55:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gart_table_vram_free - free gart page table vram
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Free the video memory used for the GART page table
|
|
|
|
* (pcie r4xx, r5xx+). These asics require the gart table to
|
|
|
|
* be in video memory.
|
|
|
|
*/
|
|
|
|
void amdgpu_gart_table_vram_free(struct amdgpu_device *adev)
|
|
|
|
{
|
2018-08-21 22:07:47 +07:00
|
|
|
if (adev->gart.bo == NULL) {
|
2017-11-21 12:29:14 +07:00
|
|
|
return;
|
|
|
|
}
|
2018-08-21 22:07:47 +07:00
|
|
|
amdgpu_bo_unref(&adev->gart.bo);
|
2015-04-21 03:55:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Common gart functions.
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
* amdgpu_gart_unbind - unbind pages from the gart page table
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
* @offset: offset into the GPU's gart aperture
|
|
|
|
* @pages: number of pages to unbind
|
|
|
|
*
|
|
|
|
* Unbinds the requested pages from the gart page table and
|
|
|
|
* replaces them with the dummy page (all asics).
|
2017-05-05 12:27:10 +07:00
|
|
|
* Returns 0 for success, -EINVAL for failure.
|
2015-04-21 03:55:21 +07:00
|
|
|
*/
|
2017-05-05 12:27:10 +07:00
|
|
|
int amdgpu_gart_unbind(struct amdgpu_device *adev, uint64_t offset,
|
2015-04-21 03:55:21 +07:00
|
|
|
int pages)
|
|
|
|
{
|
|
|
|
unsigned t;
|
|
|
|
unsigned p;
|
|
|
|
int i, j;
|
|
|
|
u64 page_base;
|
2017-03-04 04:42:27 +07:00
|
|
|
/* Starting from VEGA10, system bit must be 0 to mean invalid. */
|
|
|
|
uint64_t flags = 0;
|
2015-04-21 03:55:21 +07:00
|
|
|
|
|
|
|
if (!adev->gart.ready) {
|
|
|
|
WARN(1, "trying to unbind memory from uninitialized GART !\n");
|
2017-05-05 12:27:10 +07:00
|
|
|
return -EINVAL;
|
2015-04-21 03:55:21 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
t = offset / AMDGPU_GPU_PAGE_SIZE;
|
2018-06-22 23:54:03 +07:00
|
|
|
p = t / AMDGPU_GPU_PAGES_IN_CPU_PAGE;
|
2015-04-21 03:55:21 +07:00
|
|
|
for (i = 0; i < pages; i++, p++) {
|
2016-09-25 21:10:06 +07:00
|
|
|
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
|
2016-03-30 19:42:57 +07:00
|
|
|
adev->gart.pages[p] = NULL;
|
|
|
|
#endif
|
2018-02-22 14:35:11 +07:00
|
|
|
page_base = adev->dummy_page_addr;
|
2016-03-30 19:42:57 +07:00
|
|
|
if (!adev->gart.ptr)
|
|
|
|
continue;
|
2015-04-21 03:55:21 +07:00
|
|
|
|
2018-06-22 23:54:03 +07:00
|
|
|
for (j = 0; j < AMDGPU_GPU_PAGES_IN_CPU_PAGE; j++, t++) {
|
2018-01-12 21:26:08 +07:00
|
|
|
amdgpu_gmc_set_pte_pde(adev, adev->gart.ptr,
|
|
|
|
t, page_base, flags);
|
2016-03-30 19:42:57 +07:00
|
|
|
page_base += AMDGPU_GPU_PAGE_SIZE;
|
2015-04-21 03:55:21 +07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mb();
|
2018-01-19 20:17:40 +07:00
|
|
|
amdgpu_asic_flush_hdp(adev, NULL);
|
2018-10-13 04:17:05 +07:00
|
|
|
amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
|
2017-05-05 12:27:10 +07:00
|
|
|
return 0;
|
2015-04-21 03:55:21 +07:00
|
|
|
}
|
|
|
|
|
2017-06-29 22:24:26 +07:00
|
|
|
/**
|
|
|
|
* amdgpu_gart_map - map dma_addresses into GART entries
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
* @offset: offset into the GPU's gart aperture
|
|
|
|
* @pages: number of pages to bind
|
|
|
|
* @dma_addr: DMA addresses of pages
|
2018-10-24 09:58:04 +07:00
|
|
|
* @flags: page table entry flags
|
|
|
|
* @dst: CPU address of the gart table
|
2017-06-29 22:24:26 +07:00
|
|
|
*
|
|
|
|
* Map the dma_addresses into GART entries (all asics).
|
|
|
|
* Returns 0 for success, -EINVAL for failure.
|
|
|
|
*/
|
|
|
|
int amdgpu_gart_map(struct amdgpu_device *adev, uint64_t offset,
|
|
|
|
int pages, dma_addr_t *dma_addr, uint64_t flags,
|
|
|
|
void *dst)
|
|
|
|
{
|
|
|
|
uint64_t page_base;
|
|
|
|
unsigned i, j, t;
|
|
|
|
|
|
|
|
if (!adev->gart.ready) {
|
|
|
|
WARN(1, "trying to bind memory to uninitialized GART !\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
t = offset / AMDGPU_GPU_PAGE_SIZE;
|
|
|
|
|
|
|
|
for (i = 0; i < pages; i++) {
|
|
|
|
page_base = dma_addr[i];
|
2018-06-22 23:54:03 +07:00
|
|
|
for (j = 0; j < AMDGPU_GPU_PAGES_IN_CPU_PAGE; j++, t++) {
|
2018-01-12 21:26:08 +07:00
|
|
|
amdgpu_gmc_set_pte_pde(adev, dst, t, page_base, flags);
|
2017-06-29 22:24:26 +07:00
|
|
|
page_base += AMDGPU_GPU_PAGE_SIZE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2015-04-21 03:55:21 +07:00
|
|
|
/**
|
|
|
|
* amdgpu_gart_bind - bind pages into the gart page table
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
* @offset: offset into the GPU's gart aperture
|
|
|
|
* @pages: number of pages to bind
|
|
|
|
* @pagelist: pages to bind
|
|
|
|
* @dma_addr: DMA addresses of pages
|
|
|
|
*
|
|
|
|
* Binds the requested pages to the gart page table
|
|
|
|
* (all asics).
|
|
|
|
* Returns 0 for success, -EINVAL for failure.
|
|
|
|
*/
|
2016-08-13 06:25:21 +07:00
|
|
|
int amdgpu_gart_bind(struct amdgpu_device *adev, uint64_t offset,
|
2015-04-21 03:55:21 +07:00
|
|
|
int pages, struct page **pagelist, dma_addr_t *dma_addr,
|
2016-09-21 15:19:19 +07:00
|
|
|
uint64_t flags)
|
2015-04-21 03:55:21 +07:00
|
|
|
{
|
2017-06-29 22:24:26 +07:00
|
|
|
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
|
|
|
|
unsigned i,t,p;
|
|
|
|
#endif
|
|
|
|
int r;
|
2015-04-21 03:55:21 +07:00
|
|
|
|
|
|
|
if (!adev->gart.ready) {
|
|
|
|
WARN(1, "trying to bind memory to uninitialized GART !\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2017-06-29 22:24:26 +07:00
|
|
|
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
|
2015-04-21 03:55:21 +07:00
|
|
|
t = offset / AMDGPU_GPU_PAGE_SIZE;
|
2018-06-22 23:54:03 +07:00
|
|
|
p = t / AMDGPU_GPU_PAGES_IN_CPU_PAGE;
|
2017-06-29 22:24:26 +07:00
|
|
|
for (i = 0; i < pages; i++, p++)
|
2018-02-23 22:08:51 +07:00
|
|
|
adev->gart.pages[p] = pagelist ? pagelist[i] : NULL;
|
2016-03-30 19:42:57 +07:00
|
|
|
#endif
|
2017-06-29 22:24:26 +07:00
|
|
|
|
2017-10-16 22:37:06 +07:00
|
|
|
if (!adev->gart.ptr)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
r = amdgpu_gart_map(adev, offset, pages, dma_addr, flags,
|
|
|
|
adev->gart.ptr);
|
|
|
|
if (r)
|
|
|
|
return r;
|
2017-06-29 22:24:26 +07:00
|
|
|
|
2015-04-21 03:55:21 +07:00
|
|
|
mb();
|
2018-01-19 20:17:40 +07:00
|
|
|
amdgpu_asic_flush_hdp(adev, NULL);
|
2018-10-13 04:17:05 +07:00
|
|
|
amdgpu_gmc_flush_gpu_tlb(adev, 0, 0);
|
2015-04-21 03:55:21 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gart_init - init the driver info for managing the gart
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Allocate the dummy page and init the gart driver info (all asics).
|
|
|
|
* Returns 0 for success, error for failure.
|
|
|
|
*/
|
|
|
|
int amdgpu_gart_init(struct amdgpu_device *adev)
|
|
|
|
{
|
2016-03-30 15:54:16 +07:00
|
|
|
int r;
|
2015-04-21 03:55:21 +07:00
|
|
|
|
2018-02-22 14:35:11 +07:00
|
|
|
if (adev->dummy_page_addr)
|
2015-04-21 03:55:21 +07:00
|
|
|
return 0;
|
2016-03-30 19:42:57 +07:00
|
|
|
|
2015-04-21 03:55:21 +07:00
|
|
|
/* We need PAGE_SIZE >= AMDGPU_GPU_PAGE_SIZE */
|
|
|
|
if (PAGE_SIZE < AMDGPU_GPU_PAGE_SIZE) {
|
|
|
|
DRM_ERROR("Page size is smaller than GPU page size!\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
2017-12-16 04:28:33 +07:00
|
|
|
r = amdgpu_gart_dummy_page_init(adev);
|
2015-04-21 03:55:21 +07:00
|
|
|
if (r)
|
|
|
|
return r;
|
|
|
|
/* Compute table size */
|
2018-01-12 20:52:22 +07:00
|
|
|
adev->gart.num_cpu_pages = adev->gmc.gart_size / PAGE_SIZE;
|
|
|
|
adev->gart.num_gpu_pages = adev->gmc.gart_size / AMDGPU_GPU_PAGE_SIZE;
|
2015-04-21 03:55:21 +07:00
|
|
|
DRM_INFO("GART: num cpu pages %u, num gpu pages %u\n",
|
|
|
|
adev->gart.num_cpu_pages, adev->gart.num_gpu_pages);
|
2016-03-30 19:42:57 +07:00
|
|
|
|
2016-09-25 21:10:06 +07:00
|
|
|
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
|
2015-04-21 03:55:21 +07:00
|
|
|
/* Allocate pages table */
|
treewide: Use array_size() in vzalloc()
The vzalloc() function has no 2-factor argument form, so multiplication
factors need to be wrapped in array_size(). This patch replaces cases of:
vzalloc(a * b)
with:
vzalloc(array_size(a, b))
as well as handling cases of:
vzalloc(a * b * c)
with:
vzalloc(array3_size(a, b, c))
This does, however, attempt to ignore constant size factors like:
vzalloc(4 * 1024)
though any constants defined via macros get caught up in the conversion.
Any factors with a sizeof() of "unsigned char", "char", and "u8" were
dropped, since they're redundant.
The Coccinelle script used for this was:
// Fix redundant parens around sizeof().
@@
type TYPE;
expression THING, E;
@@
(
vzalloc(
- (sizeof(TYPE)) * E
+ sizeof(TYPE) * E
, ...)
|
vzalloc(
- (sizeof(THING)) * E
+ sizeof(THING) * E
, ...)
)
// Drop single-byte sizes and redundant parens.
@@
expression COUNT;
typedef u8;
typedef __u8;
@@
(
vzalloc(
- sizeof(u8) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(__u8) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(char) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(unsigned char) * (COUNT)
+ COUNT
, ...)
|
vzalloc(
- sizeof(u8) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(__u8) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(char) * COUNT
+ COUNT
, ...)
|
vzalloc(
- sizeof(unsigned char) * COUNT
+ COUNT
, ...)
)
// 2-factor product with sizeof(type/expression) and identifier or constant.
@@
type TYPE;
expression THING;
identifier COUNT_ID;
constant COUNT_CONST;
@@
(
vzalloc(
- sizeof(TYPE) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT_ID
+ array_size(COUNT_ID, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT_ID)
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT_ID
+ array_size(COUNT_ID, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT_CONST)
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT_CONST
+ array_size(COUNT_CONST, sizeof(THING))
, ...)
)
// 2-factor product, only identifiers.
@@
identifier SIZE, COUNT;
@@
vzalloc(
- SIZE * COUNT
+ array_size(COUNT, SIZE)
, ...)
// 3-factor product with 1 sizeof(type) or sizeof(expression), with
// redundant parens removed.
@@
expression THING;
identifier STRIDE, COUNT;
type TYPE;
@@
(
vzalloc(
- sizeof(TYPE) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(TYPE) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(TYPE))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT) * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * (COUNT) * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT * (STRIDE)
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
|
vzalloc(
- sizeof(THING) * COUNT * STRIDE
+ array3_size(COUNT, STRIDE, sizeof(THING))
, ...)
)
// 3-factor product with 2 sizeof(variable), with redundant parens removed.
@@
expression THING1, THING2;
identifier COUNT;
type TYPE1, TYPE2;
@@
(
vzalloc(
- sizeof(TYPE1) * sizeof(TYPE2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(TYPE2))
, ...)
|
vzalloc(
- sizeof(THING1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(THING1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(THING1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * COUNT
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
|
vzalloc(
- sizeof(TYPE1) * sizeof(THING2) * (COUNT)
+ array3_size(COUNT, sizeof(TYPE1), sizeof(THING2))
, ...)
)
// 3-factor product, only identifiers, with redundant parens removed.
@@
identifier STRIDE, SIZE, COUNT;
@@
(
vzalloc(
- (COUNT) * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * (STRIDE) * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * STRIDE * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- (COUNT) * (STRIDE) * (SIZE)
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
|
vzalloc(
- COUNT * STRIDE * SIZE
+ array3_size(COUNT, STRIDE, SIZE)
, ...)
)
// Any remaining multi-factor products, first at least 3-factor products
// when they're not all constants...
@@
expression E1, E2, E3;
constant C1, C2, C3;
@@
(
vzalloc(C1 * C2 * C3, ...)
|
vzalloc(
- E1 * E2 * E3
+ array3_size(E1, E2, E3)
, ...)
)
// And then all remaining 2 factors products when they're not all constants.
@@
expression E1, E2;
constant C1, C2;
@@
(
vzalloc(C1 * C2, ...)
|
vzalloc(
- E1 * E2
+ array_size(E1, E2)
, ...)
)
Signed-off-by: Kees Cook <keescook@chromium.org>
2018-06-13 04:27:37 +07:00
|
|
|
adev->gart.pages = vzalloc(array_size(sizeof(void *),
|
|
|
|
adev->gart.num_cpu_pages));
|
2017-11-14 10:55:50 +07:00
|
|
|
if (adev->gart.pages == NULL)
|
2015-04-21 03:55:21 +07:00
|
|
|
return -ENOMEM;
|
2016-03-30 19:42:57 +07:00
|
|
|
#endif
|
|
|
|
|
2015-04-21 03:55:21 +07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* amdgpu_gart_fini - tear down the driver info for managing the gart
|
|
|
|
*
|
|
|
|
* @adev: amdgpu_device pointer
|
|
|
|
*
|
|
|
|
* Tear down the gart driver info and free the dummy page (all asics).
|
|
|
|
*/
|
|
|
|
void amdgpu_gart_fini(struct amdgpu_device *adev)
|
|
|
|
{
|
2016-09-25 21:10:06 +07:00
|
|
|
#ifdef CONFIG_DRM_AMDGPU_GART_DEBUGFS
|
2015-04-21 03:55:21 +07:00
|
|
|
vfree(adev->gart.pages);
|
|
|
|
adev->gart.pages = NULL;
|
2016-03-30 19:42:57 +07:00
|
|
|
#endif
|
2017-12-16 04:28:33 +07:00
|
|
|
amdgpu_gart_dummy_page_fini(adev);
|
2015-04-21 03:55:21 +07:00
|
|
|
}
|