2022-06-17 16:05:59 -07:00
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
/*
|
|
|
|
* Copyright © 2022 Intel Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "intel_ggtt_gmch.h"
|
|
|
|
|
2024-05-30 06:19:02 -07:00
|
|
|
#include <drm/intel/intel-gtt.h>
|
2022-06-17 16:05:59 -07:00
|
|
|
|
|
|
|
#include <linux/agp_backend.h>
|
|
|
|
|
|
|
|
#include "i915_drv.h"
|
|
|
|
#include "i915_utils.h"
|
|
|
|
#include "intel_gtt.h"
|
|
|
|
#include "intel_gt_regs.h"
|
|
|
|
#include "intel_gt.h"
|
|
|
|
|
|
|
|
static void gmch_ggtt_insert_page(struct i915_address_space *vm,
|
|
|
|
dma_addr_t addr,
|
|
|
|
u64 offset,
|
drm/i915/gt: Fix parameter in gmch_ggtt_insert_{entries, page}()
When building with clang's -Wincompatible-function-pointer-types-strict,
the following warnings occur:
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:102:23: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, dma_addr_t, u64, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, unsigned int, unsigned long long, unsigned int, unsigned int)') from 'void (struct i915_address_space *, dma_addr_t, u64, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, unsigned int, unsigned long long, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_page = gmch_ggtt_insert_page;
^ ~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:103:26: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, unsigned int)') from 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, unsigned int)') [-Werror, -Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
^ ~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
The warning is pointing out that while 'enum i915_cache_level' and
'unsigned int' are ABI compatible, these indirect calls will fail
clang's kernel Control Flow Integrity (kCFI) checks, as the callback's
signature does not exactly match the prototype's signature.
To fix this, replace the cache_level parameter with pat_index, as was
done in other places within i915 where there is no difference between
cache_level and pat_index on certain generations.
Fixes: 9275277d5324 ("drm/i915: use pat_index instead of cache_level")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: Fei Yang <fei.yang@intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230530-i915-gt-cache_level-wincompatible-function-pointer-types-strict-v1-2-54501d598229@kernel.org
2023-05-30 11:24:39 -07:00
|
|
|
unsigned int pat_index,
|
2022-06-17 16:05:59 -07:00
|
|
|
u32 unused)
|
|
|
|
{
|
drm/i915/gt: Fix parameter in gmch_ggtt_insert_{entries, page}()
When building with clang's -Wincompatible-function-pointer-types-strict,
the following warnings occur:
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:102:23: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, dma_addr_t, u64, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, unsigned int, unsigned long long, unsigned int, unsigned int)') from 'void (struct i915_address_space *, dma_addr_t, u64, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, unsigned int, unsigned long long, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_page = gmch_ggtt_insert_page;
^ ~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:103:26: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, unsigned int)') from 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, unsigned int)') [-Werror, -Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
^ ~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
The warning is pointing out that while 'enum i915_cache_level' and
'unsigned int' are ABI compatible, these indirect calls will fail
clang's kernel Control Flow Integrity (kCFI) checks, as the callback's
signature does not exactly match the prototype's signature.
To fix this, replace the cache_level parameter with pat_index, as was
done in other places within i915 where there is no difference between
cache_level and pat_index on certain generations.
Fixes: 9275277d5324 ("drm/i915: use pat_index instead of cache_level")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: Fei Yang <fei.yang@intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230530-i915-gt-cache_level-wincompatible-function-pointer-types-strict-v1-2-54501d598229@kernel.org
2023-05-30 11:24:39 -07:00
|
|
|
unsigned int flags = (pat_index == I915_CACHE_NONE) ?
|
2022-06-17 16:05:59 -07:00
|
|
|
AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
|
|
|
|
|
|
|
|
intel_gmch_gtt_insert_page(addr, offset >> PAGE_SHIFT, flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gmch_ggtt_insert_entries(struct i915_address_space *vm,
|
|
|
|
struct i915_vma_resource *vma_res,
|
drm/i915/gt: Fix parameter in gmch_ggtt_insert_{entries, page}()
When building with clang's -Wincompatible-function-pointer-types-strict,
the following warnings occur:
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:102:23: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, dma_addr_t, u64, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, unsigned int, unsigned long long, unsigned int, unsigned int)') from 'void (struct i915_address_space *, dma_addr_t, u64, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, unsigned int, unsigned long long, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_page = gmch_ggtt_insert_page;
^ ~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:103:26: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, unsigned int)') from 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, unsigned int)') [-Werror, -Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
^ ~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
The warning is pointing out that while 'enum i915_cache_level' and
'unsigned int' are ABI compatible, these indirect calls will fail
clang's kernel Control Flow Integrity (kCFI) checks, as the callback's
signature does not exactly match the prototype's signature.
To fix this, replace the cache_level parameter with pat_index, as was
done in other places within i915 where there is no difference between
cache_level and pat_index on certain generations.
Fixes: 9275277d5324 ("drm/i915: use pat_index instead of cache_level")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: Fei Yang <fei.yang@intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230530-i915-gt-cache_level-wincompatible-function-pointer-types-strict-v1-2-54501d598229@kernel.org
2023-05-30 11:24:39 -07:00
|
|
|
unsigned int pat_index,
|
2022-06-17 16:05:59 -07:00
|
|
|
u32 unused)
|
|
|
|
{
|
drm/i915/gt: Fix parameter in gmch_ggtt_insert_{entries, page}()
When building with clang's -Wincompatible-function-pointer-types-strict,
the following warnings occur:
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:102:23: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, dma_addr_t, u64, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, unsigned int, unsigned long long, unsigned int, unsigned int)') from 'void (struct i915_address_space *, dma_addr_t, u64, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, unsigned int, unsigned long long, enum i915_cache_level, unsigned int)') [-Werror,-Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_page = gmch_ggtt_insert_page;
^ ~~~~~~~~~~~~~~~~~~~~~
drivers/gpu/drm/i915/gt/intel_ggtt_gmch.c:103:26: error: incompatible function pointer types assigning to 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, u32)' (aka 'void (*)(struct i915_address_space *, struct i915_vma_resource *, unsigned int, unsigned int)') from 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, u32)' (aka 'void (struct i915_address_space *, struct i915_vma_resource *, enum i915_cache_level, unsigned int)') [-Werror, -Wincompatible-function-pointer-types-strict]
ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
^ ~~~~~~~~~~~~~~~~~~~~~~~~
2 errors generated.
The warning is pointing out that while 'enum i915_cache_level' and
'unsigned int' are ABI compatible, these indirect calls will fail
clang's kernel Control Flow Integrity (kCFI) checks, as the callback's
signature does not exactly match the prototype's signature.
To fix this, replace the cache_level parameter with pat_index, as was
done in other places within i915 where there is no difference between
cache_level and pat_index on certain generations.
Fixes: 9275277d5324 ("drm/i915: use pat_index instead of cache_level")
Signed-off-by: Nathan Chancellor <nathan@kernel.org>
Reviewed-by: Andi Shyti <andi.shyti@linux.intel.com>
Reviewed-by: Fei Yang <fei.yang@intel.com>
Signed-off-by: Andi Shyti <andi.shyti@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230530-i915-gt-cache_level-wincompatible-function-pointer-types-strict-v1-2-54501d598229@kernel.org
2023-05-30 11:24:39 -07:00
|
|
|
unsigned int flags = (pat_index == I915_CACHE_NONE) ?
|
2022-06-17 16:05:59 -07:00
|
|
|
AGP_USER_MEMORY : AGP_USER_CACHED_MEMORY;
|
|
|
|
|
|
|
|
intel_gmch_gtt_insert_sg_entries(vma_res->bi.pages, vma_res->start >> PAGE_SHIFT,
|
|
|
|
flags);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gmch_ggtt_invalidate(struct i915_ggtt *ggtt)
|
|
|
|
{
|
|
|
|
intel_gmch_gtt_flush();
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gmch_ggtt_clear_range(struct i915_address_space *vm,
|
|
|
|
u64 start, u64 length)
|
|
|
|
{
|
|
|
|
intel_gmch_gtt_clear_range(start >> PAGE_SHIFT, length >> PAGE_SHIFT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gmch_ggtt_remove(struct i915_address_space *vm)
|
|
|
|
{
|
|
|
|
intel_gmch_remove();
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Certain Gen5 chipsets require idling the GPU before unmapping anything from
|
|
|
|
* the GTT when VT-d is enabled.
|
|
|
|
*/
|
|
|
|
static bool needs_idle_maps(struct drm_i915_private *i915)
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
* Query intel_iommu to see if we need the workaround. Presumably that
|
|
|
|
* was loaded first.
|
|
|
|
*/
|
|
|
|
if (!i915_vtd_active(i915))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (GRAPHICS_VER(i915) == 5 && IS_MOBILE(i915))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int intel_ggtt_gmch_probe(struct i915_ggtt *ggtt)
|
|
|
|
{
|
|
|
|
struct drm_i915_private *i915 = ggtt->vm.i915;
|
|
|
|
phys_addr_t gmadr_base;
|
|
|
|
int ret;
|
|
|
|
|
2023-01-17 05:33:06 -07:00
|
|
|
ret = intel_gmch_probe(i915->gmch.pdev, to_pci_dev(i915->drm.dev), NULL);
|
2022-06-17 16:05:59 -07:00
|
|
|
if (!ret) {
|
|
|
|
drm_err(&i915->drm, "failed to set up gmch\n");
|
|
|
|
return -EIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
intel_gmch_gtt_get(&ggtt->vm.total, &gmadr_base, &ggtt->mappable_end);
|
|
|
|
|
2023-01-16 10:34:22 -07:00
|
|
|
ggtt->gmadr = DEFINE_RES_MEM(gmadr_base, ggtt->mappable_end);
|
2022-06-17 16:05:59 -07:00
|
|
|
|
|
|
|
ggtt->vm.alloc_pt_dma = alloc_pt_dma;
|
|
|
|
ggtt->vm.alloc_scratch_dma = alloc_pt_dma;
|
|
|
|
|
|
|
|
if (needs_idle_maps(i915)) {
|
|
|
|
drm_notice(&i915->drm,
|
|
|
|
"Flushing DMA requests before IOMMU unmaps; performance may be degraded\n");
|
|
|
|
ggtt->do_idle_maps = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
ggtt->vm.insert_page = gmch_ggtt_insert_page;
|
|
|
|
ggtt->vm.insert_entries = gmch_ggtt_insert_entries;
|
|
|
|
ggtt->vm.clear_range = gmch_ggtt_clear_range;
|
2023-03-10 02:23:49 -07:00
|
|
|
ggtt->vm.scratch_range = gmch_ggtt_clear_range;
|
2022-06-17 16:05:59 -07:00
|
|
|
ggtt->vm.cleanup = gmch_ggtt_remove;
|
|
|
|
|
|
|
|
ggtt->invalidate = gmch_ggtt_invalidate;
|
|
|
|
|
|
|
|
ggtt->vm.vma_ops.bind_vma = intel_ggtt_bind_vma;
|
|
|
|
ggtt->vm.vma_ops.unbind_vma = intel_ggtt_unbind_vma;
|
|
|
|
|
|
|
|
if (unlikely(ggtt->do_idle_maps))
|
|
|
|
drm_notice(&i915->drm,
|
|
|
|
"Applying Ironlake quirks for intel_iommu\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int intel_ggtt_gmch_enable_hw(struct drm_i915_private *i915)
|
|
|
|
{
|
|
|
|
if (!intel_gmch_enable_gtt())
|
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void intel_ggtt_gmch_flush(void)
|
|
|
|
{
|
|
|
|
intel_gmch_gtt_flush();
|
|
|
|
}
|