mirror of
https://github.com/torvalds/linux.git
synced 2026-04-20 07:43:57 -04:00
Pull drm updates from Dave Airlie:
"Highlights are usual, more AMD IP blocks for future hw, i915/xe
changes, Displayport tunnelling support for i915, msm YUV over DP
changes, new tests for ttm, but its mostly a lot of stuff all over the
place from lots of people.
core:
- EDID cleanups
- scheduler error handling fixes
- managed: add drmm_release_action() with tests
- add ratelimited drm debug print
- DPCD PSR early transport macro
- DP tunneling and bandwidth allocation helpers
- remove built-in edids
- dp: Avoid AUX transfers on powered-down displays
- dp: Add VSC SDP helpers
cross drivers:
- use new drm print helpers
- switch to ->read_edid callback
- gem: add stats for shared buffers plus updates to amdgpu, i915, xe
syncobj:
- fixes to waiting and sleeping
ttm:
- add tests
- fix errno codes
- simply busy-placement handling
- fix page decryption
media:
- tc358743: fix v4l device registration
video:
- move all kernel parameters for video behind CONFIG_VIDEO
sound:
- remove <drm/drm_edid.h> include from header
ci:
- add tests for msm
- fix apq8016 runner
efifb:
- use copy of global screen_info state
vesafb:
- use copy of global screen_info state
simplefb:
- fix logging
bridge:
- ite-6505: fix DP link-training bug
- samsung-dsim: fix error checking in probe
- samsung-dsim: add bsh-smm-s2/pro boards
- tc358767: fix regmap usage
- imx: add i.MX8MP HDMI PVI plus DT bindings
- imx: add i.MX8MP HDMI TX plus DT bindings
- sii902x: fix probing and unregistration
- tc358767: limit pixel PLL input range
- switch to new drm_bridge_read_edid() interface
panel:
- ltk050h3146w: error-handling fixes
- panel-edp: support delay between power-on and enable; use put_sync
in unprepare; support Mediatek MT8173 Chromebooks, BOE NV116WHM-N49
V8.0, BOE NV122WUM-N41, CSO MNC207QS1-1 plus DT bindings
- panel-lvds: support EDT ETML0700Z9NDHA plus DT bindings
- panel-novatek: FRIDA FRD400B25025-A-CTK plus DT bindings
- add BOE TH101MB31IG002-28A plus DT bindings
- add EDT ETML1010G3DRA plus DT bindings
- add Novatek NT36672E LCD DSI plus DT bindings
- nt36523: support 120Hz timings, fix includes
- simple: fix display timings on RK32FN48H
- visionox-vtdr6130: fix initialization
- add Powkiddy RGB10MAX3 plus DT bindings
- st7703: support panel rotation plus DT bindings
- add Himax HX83112A plus DT bindings
- ltk500hd1829: add support for ltk101b4029w and admatec 9904370
- simple: add BOE BP082WX1-100 8.2" panel plus DT bindungs
panel-orientation-quirks:
- GPD Win Mini
amdgpu:
- Validate DMABuf imports in compute VMs
- Add RAS ACA framework
- PSP 13 fixes
- Misc code cleanups
- Replay fixes
- Atom interpretor PS, WS bounds checking
- DML2 fixes
- Audio fixes
- DCN 3.5 Z state fixes
- Remove deprecated ida_simple usage
- UBSAN fixes
- RAS fixes
- Enable seq64 infrastructure
- DC color block enablement
- Documentation updates
- DC documentation updates
- DMCUB updates
- ATHUB 4.1 support
- LSDMA 7.0 support
- JPEG DPG support
- IH 7.0 support
- HDP 7.0 support
- VCN 5.0 support
- SMU 13.0.6 updates
- NBIO 7.11 updates
- SDMA 6.1 updates
- MMHUB 3.3 updates
- DCN 3.5.1 support
- NBIF 6.3.1 support
- VPE 6.1.1 support
amdkfd:
- Validate DMABuf imports in compute VMs
- SVM fixes
- Trap handler updates and enhancements
- Fix cache size reporting
- Relocate the trap handler
radeon:
- Atom interpretor PS, WS bounds checking
- Misc code cleanups
xe:
- new query for GuC submission version
- Remove unused persistent exec_queues
- Add vram frequency sysfs attributes
- Add the flag XE_VM_BIND_FLAG_DUMPABLE
- Drop pre-production workarounds
- Drop kunit tests for unsupported platforms
- Start pumbling SR-IOV support with memory based interrupts for VF
- Allow to map BO in GGTT with PAT index corresponding to XE_CACHE_UC
to work with memory based interrupts
- Add GuC Doorbells Manager as prep work SR-IOV
- Implement additional workarounds for xe2 and MTL
- Program a few registers according to perfomance guide spec for Xe2
- Fix remaining 32b build issues and enable it back
- Fix build with CONFIG_DEBUG_FS=n
- Fix warnings from GuC ABI headers
- Introduce Relay Communication for SR-IOV for VF <-> GuC <-> PF
- Release mmap mappings on rpm suspend
- Disable mid-thread preemption when not properly supported by
hardware
- Fix xe_exec by reserving extra fence slot for CPU bind
- Fix xe_exec with full long running exec queue
- Canonicalize addresses where needed for Xe2 and add to devcoredum
- Toggle USM support for Xe2
- Only allow 1 ufence per exec / bind IOCTL
- Add GuC firmware loading for Lunar Lake
- Add XE_VMA_PTE_64K VMA flag
i915:
- Add more ADL-N PCI IDs
- Enable fastboot also on older platforms
- Early transport for panel replay and PSR
- New ARL PCI IDs
- DP TPS4 PHY test pattern support
- Unify and improve VSC SDP for PSR and non-PSR cases
- Refactor memory regions and improve debug logging
- Rework global state serialization
- Remove unused CDCLK divider fields
- Unify HDCP connector logging format
- Use display instead of graphics version in display code
- Move VBT and opregion debugfs next to the implementation
- Abstract opregion interface, use opaque type
- MTL fixes
- HPD handling fixes
- Add GuC submission interface version query
- Atomically invalidate userptr on mmu-notifier
- Update handling of MMIO triggered reports
- Don't make assumptions about intel_wakeref_t type
- Extend driver code of Xe_LPG to Xe_LPG+
- Add flex arrays to struct i915_syncmap
- Allow for very slow HuC loading
- DP tunneling and bandwidth allocation support
msm:
- Correct bindings for MSM8976 and SM8650 platforms
- Start migration of MDP5 platforms to DPU driver
- X1E80100 MDSS support
- DPU:
- Improve DSC allocation, fixing several important corner cases
- Add support for SDM630/SDM660 platforms
- Simplify dpu_encoder_phys_ops
- Apply fixes targeting DSC support with a single DSC encoder
- Apply fixes for HCTL_EN timing configuration
- X1E80100 support
- Add support for YUV420 over DP
- GPU:
- fix sc7180 UBWC config
- fix a7xx LLC config
- new gpu support: a305B, a750, a702
- machine support: SM7150 (different power levels than other a618)
- a7xx devcoredump support
habanalabs:
- configure IRQ affinity according to NUMA node
- move HBM MMU page tables inside the HBM
- improve device reset
- check extended PCIe errors
ivpu:
- updates to firmware API
- refactor BO allocation
imx:
- use devm_ functions during init
hisilicon:
- fix EDID includes
mgag200:
- improve ioremap usage
- convert to struct drm_edid
- Work around PCI write bursts
nouveau:
- disp: use kmemdup()
- fix EDID includes
- documentation fixes
qaic:
- fixes to BO handling
- make use of DRM managed release
- fix order of remove operations
rockchip:
- analogix_dp: get encoder port from DT
- inno_hdmi: support HDMI for RK3128
- lvds: error-handling fixes
ssd130x:
- support SSD133x plus DT bindings
tegra:
- fix error handling
tilcdc:
- make use of DRM managed release
v3d:
- show memory stats in debugfs
- Support display MMU page size
vc4:
- fix error handling in plane prepare_fb
- fix framebuffer test in plane helpers
virtio:
- add venus capset defines
vkms:
- fix OOB access when programming the LUT
- Kconfig improvements
vmwgfx:
- unmap surface before changing plane state
- fix memory leak in error handling
- documentation fixes
- list command SVGA_3D_CMD_DEFINE_GB_SURFACE_V4 as invalid
- fix null-pointer deref in execbuf
- refactor display-mode probing
- fix fencing for creating cursor MOBs
- fix cursor-memory lifetime
xlnx:
- fix live video input for ZynqMP DPSUB
lima:
- fix memory leak
loongson:
- fail if no VRAM present
meson:
- switch to new drm_bridge_read_edid() interface
renesas:
- add RZ/G2L DU support plus DT bindings
mxsfb:
- Use managed mode config
sun4i:
- HDMI: updates to atomic mode setting
mediatek:
- Add display driver for MT8188 VDOSYS1
- DSI driver cleanups
- Filter modes according to hardware capability
- Fix a null pointer crash in mtk_drm_crtc_finish_page_flip
etnaviv:
- enhancements for NPU and MRT support"
* tag 'drm-next-2024-03-13' of https://gitlab.freedesktop.org/drm/kernel: (1420 commits)
drm/amd/display: Removed redundant @ symbol to fix kernel-doc warnings in -next repo
drm/amd/pm: wait for completion of the EnableGfxImu message
drm/amdgpu/soc21: add mode2 asic reset for SMU IP v14.0.1
drm/amdgpu: add smu 14.0.1 support
drm/amdgpu: add VPE 6.1.1 discovery support
drm/amdgpu/vpe: add VPE 6.1.1 support
drm/amdgpu/vpe: don't emit cond exec command under collaborate mode
drm/amdgpu/vpe: add collaborate mode support for VPE
drm/amdgpu/vpe: add PRED_EXE and COLLAB_SYNC OPCODE
drm/amdgpu/vpe: add multi instance VPE support
drm/amdgpu/discovery: add nbif v6_3_1 ip block
drm/amdgpu: Add nbif v6_3_1 ip block support
drm/amdgpu: Add pcie v6_1_0 ip headers (v5)
drm/amdgpu: Add nbif v6_3_1 ip headers (v5)
arch/powerpc: Remove <linux/fb.h> from backlight code
macintosh/via-pmu-backlight: Include <linux/backlight.h>
fbdev/chipsfb: Include <linux/backlight.h>
drm/etnaviv: Restore some id values
drm/amdkfd: make kfd_class constant
drm/amdgpu: add ring timeout information in devcoredump
...
532 lines
15 KiB
C
532 lines
15 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2021-2023 Intel Corporation
|
|
*/
|
|
|
|
#include <linux/minmax.h>
|
|
|
|
#include "xe_mmio.h"
|
|
|
|
#include <drm/drm_managed.h>
|
|
#include <drm/xe_drm.h>
|
|
|
|
#include "regs/xe_engine_regs.h"
|
|
#include "regs/xe_gt_regs.h"
|
|
#include "regs/xe_regs.h"
|
|
#include "xe_bo.h"
|
|
#include "xe_device.h"
|
|
#include "xe_ggtt.h"
|
|
#include "xe_gt.h"
|
|
#include "xe_gt_mcr.h"
|
|
#include "xe_macros.h"
|
|
#include "xe_module.h"
|
|
#include "xe_sriov.h"
|
|
#include "xe_tile.h"
|
|
|
|
#define XEHP_MTCFG_ADDR XE_REG(0x101800)
|
|
#define TILE_COUNT REG_GENMASK(15, 8)
|
|
|
|
#define BAR_SIZE_SHIFT 20
|
|
|
|
static void
|
|
_resize_bar(struct xe_device *xe, int resno, resource_size_t size)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
|
int bar_size = pci_rebar_bytes_to_size(size);
|
|
int ret;
|
|
|
|
if (pci_resource_len(pdev, resno))
|
|
pci_release_resource(pdev, resno);
|
|
|
|
ret = pci_resize_resource(pdev, resno, bar_size);
|
|
if (ret) {
|
|
drm_info(&xe->drm, "Failed to resize BAR%d to %dM (%pe). Consider enabling 'Resizable BAR' support in your BIOS\n",
|
|
resno, 1 << bar_size, ERR_PTR(ret));
|
|
return;
|
|
}
|
|
|
|
drm_info(&xe->drm, "BAR%d resized to %dM\n", resno, 1 << bar_size);
|
|
}
|
|
|
|
/*
|
|
* if force_vram_bar_size is set, attempt to set to the requested size
|
|
* else set to maximum possible size
|
|
*/
|
|
static void xe_resize_vram_bar(struct xe_device *xe)
|
|
{
|
|
u64 force_vram_bar_size = xe_modparam.force_vram_bar_size;
|
|
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
|
struct pci_bus *root = pdev->bus;
|
|
resource_size_t current_size;
|
|
resource_size_t rebar_size;
|
|
struct resource *root_res;
|
|
u32 bar_size_mask;
|
|
u32 pci_cmd;
|
|
int i;
|
|
|
|
/* gather some relevant info */
|
|
current_size = pci_resource_len(pdev, LMEM_BAR);
|
|
bar_size_mask = pci_rebar_get_possible_sizes(pdev, LMEM_BAR);
|
|
|
|
if (!bar_size_mask)
|
|
return;
|
|
|
|
/* set to a specific size? */
|
|
if (force_vram_bar_size) {
|
|
u32 bar_size_bit;
|
|
|
|
rebar_size = force_vram_bar_size * (resource_size_t)SZ_1M;
|
|
|
|
bar_size_bit = bar_size_mask & BIT(pci_rebar_bytes_to_size(rebar_size));
|
|
|
|
if (!bar_size_bit) {
|
|
drm_info(&xe->drm,
|
|
"Requested size: %lluMiB is not supported by rebar sizes: 0x%x. Leaving default: %lluMiB\n",
|
|
(u64)rebar_size >> 20, bar_size_mask, (u64)current_size >> 20);
|
|
return;
|
|
}
|
|
|
|
rebar_size = 1ULL << (__fls(bar_size_bit) + BAR_SIZE_SHIFT);
|
|
|
|
if (rebar_size == current_size)
|
|
return;
|
|
} else {
|
|
rebar_size = 1ULL << (__fls(bar_size_mask) + BAR_SIZE_SHIFT);
|
|
|
|
/* only resize if larger than current */
|
|
if (rebar_size <= current_size)
|
|
return;
|
|
}
|
|
|
|
drm_info(&xe->drm, "Attempting to resize bar from %lluMiB -> %lluMiB\n",
|
|
(u64)current_size >> 20, (u64)rebar_size >> 20);
|
|
|
|
while (root->parent)
|
|
root = root->parent;
|
|
|
|
pci_bus_for_each_resource(root, root_res, i) {
|
|
if (root_res && root_res->flags & (IORESOURCE_MEM | IORESOURCE_MEM_64) &&
|
|
(u64)root_res->start > 0x100000000ul)
|
|
break;
|
|
}
|
|
|
|
if (!root_res) {
|
|
drm_info(&xe->drm, "Can't resize VRAM BAR - platform support is missing. Consider enabling 'Resizable BAR' support in your BIOS\n");
|
|
return;
|
|
}
|
|
|
|
pci_read_config_dword(pdev, PCI_COMMAND, &pci_cmd);
|
|
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd & ~PCI_COMMAND_MEMORY);
|
|
|
|
_resize_bar(xe, LMEM_BAR, rebar_size);
|
|
|
|
pci_assign_unassigned_bus_resources(pdev->bus);
|
|
pci_write_config_dword(pdev, PCI_COMMAND, pci_cmd);
|
|
}
|
|
|
|
static bool xe_pci_resource_valid(struct pci_dev *pdev, int bar)
|
|
{
|
|
if (!pci_resource_flags(pdev, bar))
|
|
return false;
|
|
|
|
if (pci_resource_flags(pdev, bar) & IORESOURCE_UNSET)
|
|
return false;
|
|
|
|
if (!pci_resource_len(pdev, bar))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
static int xe_determine_lmem_bar_size(struct xe_device *xe)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
|
|
|
if (!xe_pci_resource_valid(pdev, LMEM_BAR)) {
|
|
drm_err(&xe->drm, "pci resource is not valid\n");
|
|
return -ENXIO;
|
|
}
|
|
|
|
xe_resize_vram_bar(xe);
|
|
|
|
xe->mem.vram.io_start = pci_resource_start(pdev, LMEM_BAR);
|
|
xe->mem.vram.io_size = pci_resource_len(pdev, LMEM_BAR);
|
|
if (!xe->mem.vram.io_size)
|
|
return -EIO;
|
|
|
|
/* XXX: Need to change when xe link code is ready */
|
|
xe->mem.vram.dpa_base = 0;
|
|
|
|
/* set up a map to the total memory area. */
|
|
xe->mem.vram.mapping = ioremap_wc(xe->mem.vram.io_start, xe->mem.vram.io_size);
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* xe_mmio_tile_vram_size() - Collect vram size and offset information
|
|
* @tile: tile to get info for
|
|
* @vram_size: available vram (size - device reserved portions)
|
|
* @tile_size: actual vram size
|
|
* @tile_offset: physical start point in the vram address space
|
|
*
|
|
* There are 4 places for size information:
|
|
* - io size (from pci_resource_len of LMEM bar) (only used for small bar and DG1)
|
|
* - TILEx size (actual vram size)
|
|
* - GSMBASE offset (TILEx - "stolen")
|
|
* - CSSBASE offset (TILEx - CSS space necessary)
|
|
*
|
|
* CSSBASE is always a lower/smaller offset then GSMBASE.
|
|
*
|
|
* The actual available size of memory is to the CCS or GSM base.
|
|
* NOTE: multi-tile bases will include the tile offset.
|
|
*
|
|
*/
|
|
static int xe_mmio_tile_vram_size(struct xe_tile *tile, u64 *vram_size,
|
|
u64 *tile_size, u64 *tile_offset)
|
|
{
|
|
struct xe_device *xe = tile_to_xe(tile);
|
|
struct xe_gt *gt = tile->primary_gt;
|
|
u64 offset;
|
|
int err;
|
|
u32 reg;
|
|
|
|
err = xe_force_wake_get(gt_to_fw(gt), XE_FW_GT);
|
|
if (err)
|
|
return err;
|
|
|
|
/* actual size */
|
|
if (unlikely(xe->info.platform == XE_DG1)) {
|
|
*tile_size = pci_resource_len(to_pci_dev(xe->drm.dev), LMEM_BAR);
|
|
*tile_offset = 0;
|
|
} else {
|
|
reg = xe_gt_mcr_unicast_read_any(gt, XEHP_TILE_ADDR_RANGE(gt->info.id));
|
|
*tile_size = (u64)REG_FIELD_GET(GENMASK(14, 8), reg) * SZ_1G;
|
|
*tile_offset = (u64)REG_FIELD_GET(GENMASK(7, 1), reg) * SZ_1G;
|
|
}
|
|
|
|
/* minus device usage */
|
|
if (xe->info.has_flat_ccs) {
|
|
reg = xe_gt_mcr_unicast_read_any(gt, XEHP_FLAT_CCS_BASE_ADDR);
|
|
offset = (u64)REG_FIELD_GET(GENMASK(31, 8), reg) * SZ_64K;
|
|
} else {
|
|
offset = xe_mmio_read64_2x32(gt, GSMBASE);
|
|
}
|
|
|
|
/* remove the tile offset so we have just the available size */
|
|
*vram_size = offset - *tile_offset;
|
|
|
|
return xe_force_wake_put(gt_to_fw(gt), XE_FW_GT);
|
|
}
|
|
|
|
int xe_mmio_probe_vram(struct xe_device *xe)
|
|
{
|
|
struct xe_tile *tile;
|
|
resource_size_t io_size;
|
|
u64 available_size = 0;
|
|
u64 total_size = 0;
|
|
u64 tile_offset;
|
|
u64 tile_size;
|
|
u64 vram_size;
|
|
int err;
|
|
u8 id;
|
|
|
|
if (!IS_DGFX(xe))
|
|
return 0;
|
|
|
|
/* Get the size of the root tile's vram for later accessibility comparison */
|
|
tile = xe_device_get_root_tile(xe);
|
|
err = xe_mmio_tile_vram_size(tile, &vram_size, &tile_size, &tile_offset);
|
|
if (err)
|
|
return err;
|
|
|
|
err = xe_determine_lmem_bar_size(xe);
|
|
if (err)
|
|
return err;
|
|
|
|
drm_info(&xe->drm, "VISIBLE VRAM: %pa, %pa\n", &xe->mem.vram.io_start,
|
|
&xe->mem.vram.io_size);
|
|
|
|
io_size = xe->mem.vram.io_size;
|
|
|
|
/* tile specific ranges */
|
|
for_each_tile(tile, xe, id) {
|
|
err = xe_mmio_tile_vram_size(tile, &vram_size, &tile_size, &tile_offset);
|
|
if (err)
|
|
return err;
|
|
|
|
tile->mem.vram.actual_physical_size = tile_size;
|
|
tile->mem.vram.io_start = xe->mem.vram.io_start + tile_offset;
|
|
tile->mem.vram.io_size = min_t(u64, vram_size, io_size);
|
|
|
|
if (!tile->mem.vram.io_size) {
|
|
drm_err(&xe->drm, "Tile without any CPU visible VRAM. Aborting.\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
tile->mem.vram.dpa_base = xe->mem.vram.dpa_base + tile_offset;
|
|
tile->mem.vram.usable_size = vram_size;
|
|
tile->mem.vram.mapping = xe->mem.vram.mapping + tile_offset;
|
|
|
|
if (tile->mem.vram.io_size < tile->mem.vram.usable_size)
|
|
drm_info(&xe->drm, "Small BAR device\n");
|
|
drm_info(&xe->drm, "VRAM[%u, %u]: Actual physical size %pa, usable size exclude stolen %pa, CPU accessible size %pa\n", id,
|
|
tile->id, &tile->mem.vram.actual_physical_size, &tile->mem.vram.usable_size, &tile->mem.vram.io_size);
|
|
drm_info(&xe->drm, "VRAM[%u, %u]: DPA range: [%pa-%llx], io range: [%pa-%llx]\n", id, tile->id,
|
|
&tile->mem.vram.dpa_base, tile->mem.vram.dpa_base + (u64)tile->mem.vram.actual_physical_size,
|
|
&tile->mem.vram.io_start, tile->mem.vram.io_start + (u64)tile->mem.vram.io_size);
|
|
|
|
/* calculate total size using tile size to get the correct HW sizing */
|
|
total_size += tile_size;
|
|
available_size += vram_size;
|
|
|
|
if (total_size > xe->mem.vram.io_size) {
|
|
drm_info(&xe->drm, "VRAM: %pa is larger than resource %pa\n",
|
|
&total_size, &xe->mem.vram.io_size);
|
|
}
|
|
|
|
io_size -= min_t(u64, tile_size, io_size);
|
|
}
|
|
|
|
xe->mem.vram.actual_physical_size = total_size;
|
|
|
|
drm_info(&xe->drm, "Total VRAM: %pa, %pa\n", &xe->mem.vram.io_start,
|
|
&xe->mem.vram.actual_physical_size);
|
|
drm_info(&xe->drm, "Available VRAM: %pa, %pa\n", &xe->mem.vram.io_start,
|
|
&available_size);
|
|
|
|
return 0;
|
|
}
|
|
|
|
void xe_mmio_probe_tiles(struct xe_device *xe)
|
|
{
|
|
size_t tile_mmio_size = SZ_16M, tile_mmio_ext_size = xe->info.tile_mmio_ext_size;
|
|
u8 id, tile_count = xe->info.tile_count;
|
|
struct xe_gt *gt = xe_root_mmio_gt(xe);
|
|
struct xe_tile *tile;
|
|
void __iomem *regs;
|
|
u32 mtcfg;
|
|
|
|
if (tile_count == 1)
|
|
goto add_mmio_ext;
|
|
|
|
if (!xe->info.skip_mtcfg) {
|
|
mtcfg = xe_mmio_read64_2x32(gt, XEHP_MTCFG_ADDR);
|
|
tile_count = REG_FIELD_GET(TILE_COUNT, mtcfg) + 1;
|
|
if (tile_count < xe->info.tile_count) {
|
|
drm_info(&xe->drm, "tile_count: %d, reduced_tile_count %d\n",
|
|
xe->info.tile_count, tile_count);
|
|
xe->info.tile_count = tile_count;
|
|
|
|
/*
|
|
* FIXME: Needs some work for standalone media, but should be impossible
|
|
* with multi-tile for now.
|
|
*/
|
|
xe->info.gt_count = xe->info.tile_count;
|
|
}
|
|
}
|
|
|
|
regs = xe->mmio.regs;
|
|
for_each_tile(tile, xe, id) {
|
|
tile->mmio.size = tile_mmio_size;
|
|
tile->mmio.regs = regs;
|
|
regs += tile_mmio_size;
|
|
}
|
|
|
|
add_mmio_ext:
|
|
/*
|
|
* By design, there's a contiguous multi-tile MMIO space (16MB hard coded per tile).
|
|
* When supported, there could be an additional contiguous multi-tile MMIO extension
|
|
* space ON TOP of it, and hence the necessity for distinguished MMIO spaces.
|
|
*/
|
|
if (xe->info.has_mmio_ext) {
|
|
regs = xe->mmio.regs + tile_mmio_size * tile_count;
|
|
|
|
for_each_tile(tile, xe, id) {
|
|
tile->mmio_ext.size = tile_mmio_ext_size;
|
|
tile->mmio_ext.regs = regs;
|
|
|
|
regs += tile_mmio_ext_size;
|
|
}
|
|
}
|
|
}
|
|
|
|
static void mmio_fini(struct drm_device *drm, void *arg)
|
|
{
|
|
struct xe_device *xe = arg;
|
|
|
|
pci_iounmap(to_pci_dev(xe->drm.dev), xe->mmio.regs);
|
|
if (xe->mem.vram.mapping)
|
|
iounmap(xe->mem.vram.mapping);
|
|
}
|
|
|
|
static int xe_verify_lmem_ready(struct xe_device *xe)
|
|
{
|
|
struct xe_gt *gt = xe_root_mmio_gt(xe);
|
|
|
|
if (!IS_DGFX(xe))
|
|
return 0;
|
|
|
|
if (IS_SRIOV_VF(xe))
|
|
return 0;
|
|
|
|
/*
|
|
* The boot firmware initializes local memory and assesses its health.
|
|
* If memory training fails, the punit will have been instructed to
|
|
* keep the GT powered down; we won't be able to communicate with it
|
|
* and we should not continue with driver initialization.
|
|
*/
|
|
if (!(xe_mmio_read32(gt, GU_CNTL) & LMEM_INIT)) {
|
|
drm_err(&xe->drm, "VRAM not initialized by firmware\n");
|
|
return -ENODEV;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
int xe_mmio_init(struct xe_device *xe)
|
|
{
|
|
struct pci_dev *pdev = to_pci_dev(xe->drm.dev);
|
|
const int mmio_bar = 0;
|
|
|
|
/*
|
|
* Map the entire BAR.
|
|
* The first 16MB of the BAR, belong to the root tile, and include:
|
|
* registers (0-4MB), reserved space (4MB-8MB) and GGTT (8MB-16MB).
|
|
*/
|
|
xe->mmio.size = pci_resource_len(pdev, mmio_bar);
|
|
xe->mmio.regs = pci_iomap(pdev, mmio_bar, 0);
|
|
if (xe->mmio.regs == NULL) {
|
|
drm_err(&xe->drm, "failed to map registers\n");
|
|
return -EIO;
|
|
}
|
|
|
|
return drmm_add_action_or_reset(&xe->drm, mmio_fini, xe);
|
|
}
|
|
|
|
int xe_mmio_root_tile_init(struct xe_device *xe)
|
|
{
|
|
struct xe_tile *root_tile = xe_device_get_root_tile(xe);
|
|
int err;
|
|
|
|
/* Setup first tile; other tiles (if present) will be setup later. */
|
|
root_tile->mmio.size = SZ_16M;
|
|
root_tile->mmio.regs = xe->mmio.regs;
|
|
|
|
err = xe_verify_lmem_ready(xe);
|
|
if (err)
|
|
return err;
|
|
|
|
return 0;
|
|
}
|
|
|
|
/**
|
|
* xe_mmio_read64_2x32() - Read a 64-bit register as two 32-bit reads
|
|
* @gt: MMIO target GT
|
|
* @reg: register to read value from
|
|
*
|
|
* Although Intel GPUs have some 64-bit registers, the hardware officially
|
|
* only supports GTTMMADR register reads of 32 bits or smaller. Even if
|
|
* a readq operation may return a reasonable value, that violation of the
|
|
* spec shouldn't be relied upon and all 64-bit register reads should be
|
|
* performed as two 32-bit reads of the upper and lower dwords.
|
|
*
|
|
* When reading registers that may be changing (such as
|
|
* counters), a rollover of the lower dword between the two 32-bit reads
|
|
* can be problematic. This function attempts to ensure the upper dword has
|
|
* stabilized before returning the 64-bit value.
|
|
*
|
|
* Note that because this function may re-read the register multiple times
|
|
* while waiting for the value to stabilize it should not be used to read
|
|
* any registers where read operations have side effects.
|
|
*
|
|
* Returns the value of the 64-bit register.
|
|
*/
|
|
u64 xe_mmio_read64_2x32(struct xe_gt *gt, struct xe_reg reg)
|
|
{
|
|
struct xe_reg reg_udw = { .addr = reg.addr + 0x4 };
|
|
u32 ldw, udw, oldudw, retries;
|
|
|
|
if (reg.addr < gt->mmio.adj_limit) {
|
|
reg.addr += gt->mmio.adj_offset;
|
|
reg_udw.addr += gt->mmio.adj_offset;
|
|
}
|
|
|
|
oldudw = xe_mmio_read32(gt, reg_udw);
|
|
for (retries = 5; retries; --retries) {
|
|
ldw = xe_mmio_read32(gt, reg);
|
|
udw = xe_mmio_read32(gt, reg_udw);
|
|
|
|
if (udw == oldudw)
|
|
break;
|
|
|
|
oldudw = udw;
|
|
}
|
|
|
|
xe_gt_WARN(gt, retries == 0,
|
|
"64-bit read of %#x did not stabilize\n", reg.addr);
|
|
|
|
return (u64)udw << 32 | ldw;
|
|
}
|
|
|
|
/**
|
|
* xe_mmio_wait32() - Wait for a register to match the desired masked value
|
|
* @gt: MMIO target GT
|
|
* @reg: register to read value from
|
|
* @mask: mask to be applied to the value read from the register
|
|
* @val: desired value after applying the mask
|
|
* @timeout_us: time out after this period of time. Wait logic tries to be
|
|
* smart, applying an exponential backoff until @timeout_us is reached.
|
|
* @out_val: if not NULL, points where to store the last unmasked value
|
|
* @atomic: needs to be true if calling from an atomic context
|
|
*
|
|
* This function polls for the desired masked value and returns zero on success
|
|
* or -ETIMEDOUT if timed out.
|
|
*
|
|
* Note that @timeout_us represents the minimum amount of time to wait before
|
|
* giving up. The actual time taken by this function can be a little more than
|
|
* @timeout_us for different reasons, specially in non-atomic contexts. Thus,
|
|
* it is possible that this function succeeds even after @timeout_us has passed.
|
|
*/
|
|
int xe_mmio_wait32(struct xe_gt *gt, struct xe_reg reg, u32 mask, u32 val, u32 timeout_us,
|
|
u32 *out_val, bool atomic)
|
|
{
|
|
ktime_t cur = ktime_get_raw();
|
|
const ktime_t end = ktime_add_us(cur, timeout_us);
|
|
int ret = -ETIMEDOUT;
|
|
s64 wait = 10;
|
|
u32 read;
|
|
|
|
for (;;) {
|
|
read = xe_mmio_read32(gt, reg);
|
|
if ((read & mask) == val) {
|
|
ret = 0;
|
|
break;
|
|
}
|
|
|
|
cur = ktime_get_raw();
|
|
if (!ktime_before(cur, end))
|
|
break;
|
|
|
|
if (ktime_after(ktime_add_us(cur, wait), end))
|
|
wait = ktime_us_delta(end, cur);
|
|
|
|
if (atomic)
|
|
udelay(wait);
|
|
else
|
|
usleep_range(wait, wait << 1);
|
|
wait <<= 1;
|
|
}
|
|
|
|
if (ret != 0) {
|
|
read = xe_mmio_read32(gt, reg);
|
|
if ((read & mask) == val)
|
|
ret = 0;
|
|
}
|
|
|
|
if (out_val)
|
|
*out_val = read;
|
|
|
|
return ret;
|
|
}
|