/** * DOC: Global Graphics Translation Table (GGTT) * * Xe GGTT implements the support for a Global Virtual Address space that is used * for resources that are accessible to privileged (i.e. kernel-mode) processes, * and not tied to a specific user-level process. For example, the Graphics * micro-Controller (GuC) and Display Engine (if present) utilize this Global * address space. * * The Global GTT (GGTT) translates from the Global virtual address to a physical * address that can be accessed by HW. The GGTT is a flat, single-level table. * * Xe implements a simplified version of the GGTT specifically managing only a * certain range of it that goes from the Write Once Protected Content Memory (WOPCM) * Layout to a predefined GUC_GGTT_TOP. This approach avoids complications related to * the GuC (Graphics Microcontroller) hardware limitations. The GuC address space * is limited on both ends of the GGTT, because the GuC shim HW redirects * accesses to those addresses to other HW areas instead of going through the * GGTT. On the bottom end, the GuC can't access offsets below the WOPCM size, * while on the top side the limit is fixed at GUC_GGTT_TOP. To keep things * simple, instead of checking each object to see if they are accessed by GuC or * not, we just exclude those areas from the allocator. Additionally, to simplify * the driver load, we use the maximum WOPCM size in this logic instead of the * programmed one, so we don't need to wait until the actual size to be * programmed is determined (which requires FW fetch) before initializing the * GGTT. These simplifications might waste space in the GGTT (about 20-25 MBs * depending on the platform) but we can live with this. Another benefit of this * is the GuC bootrom can't access anything below the WOPCM max size so anything * the bootrom needs to access (e.g. a RSA key) needs to be placed in the GGTT * above the WOPCM max size. Starting the GGTT allocations above the WOPCM max * give us the correct placement for free.
*/
/** * xe_ggtt_alloc - Allocate a GGTT for a given &xe_tile * @tile: &xe_tile * * Allocates a &xe_ggtt for a given tile. * * Return: &xe_ggtt on success, or NULL when out of memory.
*/ struct xe_ggtt *xe_ggtt_alloc(struct xe_tile *tile)
{ struct xe_ggtt *ggtt = drmm_kzalloc(&tile_to_xe(tile)->drm, sizeof(*ggtt), GFP_KERNEL); if (ggtt)
ggtt->tile = tile; return ggtt;
}
/** * xe_ggtt_init_early - Early GGTT initialization * @ggtt: the &xe_ggtt to be initialized * * It allows to create new mappings usable by the GuC. * Mappings are not usable by the HW engines, as it doesn't have scratch nor * initial clear done to it yet. That will happen in the regular, non-early * GGTT initialization. * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_init_early(struct xe_ggtt *ggtt)
{ struct xe_device *xe = tile_to_xe(ggtt->tile); struct pci_dev *pdev = to_pci_dev(xe->drm.dev); unsignedint gsm_size; int err;
if (IS_SRIOV_VF(xe) || GRAPHICS_VERx100(xe) >= 1250)
gsm_size = SZ_8M; /* GGTT is expected to be 4GiB */ else
gsm_size = probe_gsm_size(pdev);
if (gsm_size == 0) {
drm_err(&xe->drm, "Hardware reported no preallocated GSM\n"); return -ENOMEM;
}
/* Display may have allocated inside ggtt, so be careful with clearing here */
mutex_lock(&ggtt->lock);
drm_mm_for_each_hole(hole, &ggtt->mm, start, end)
xe_ggtt_clear(ggtt, start, end - start);
/** * xe_ggtt_node_remove - Remove a &xe_ggtt_node from the GGTT * @node: the &xe_ggtt_node to be removed * @invalidate: if node needs invalidation upon removal
*/ void xe_ggtt_node_remove(struct xe_ggtt_node *node, bool invalidate)
{ struct xe_ggtt *ggtt; struct xe_device *xe;
/** * xe_ggtt_init - Regular non-early GGTT initialization * @ggtt: the &xe_ggtt to be initialized * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_init(struct xe_ggtt *ggtt)
{ struct xe_device *xe = tile_to_xe(ggtt->tile); unsignedint flags; int err;
/* * So we don't need to worry about 64K GGTT layout when dealing with * scratch entries, rather keep the scratch page in system memory on * platforms where 64K pages are needed for VRAM.
*/
flags = 0; if (ggtt->flags & XE_GGTT_FLAGS_64K)
flags |= XE_BO_FLAG_SYSTEM; else
flags |= XE_BO_FLAG_VRAM_IF_DGFX(ggtt->tile);
/* * XXX: Barrier for GGTT pages. Unsure exactly why this required but * without this LNL is having issues with the GuC reading scratch page * vs. correct GGTT page. Not particularly a hot code path so blindly * do a mmio read here which results in GuC reading correct GGTT page.
*/
xe_mmio_read32(xe_root_tile_mmio(xe), VF_CAP_REG);
/* Each GT in a tile has its own TLB to cache GGTT lookups */
ggtt_invalidate_gt_tlb(ggtt->tile->primary_gt);
ggtt_invalidate_gt_tlb(ggtt->tile->media_gt);
}
/** * xe_ggtt_node_insert_balloon_locked - prevent allocation of specified GGTT addresses * @node: the &xe_ggtt_node to hold reserved GGTT node * @start: the starting GGTT address of the reserved region * @end: then end GGTT address of the reserved region * * To be used in cases where ggtt->lock is already taken. * Use xe_ggtt_node_remove_balloon_locked() to release a reserved GGTT node. * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_node_insert_balloon_locked(struct xe_ggtt_node *node, u64 start, u64 end)
{ struct xe_ggtt *ggtt = node->ggtt; int err;
/** * xe_ggtt_node_remove_balloon_locked - release a reserved GGTT region * @node: the &xe_ggtt_node with reserved GGTT region * * To be used in cases where ggtt->lock is already taken. * See xe_ggtt_node_insert_balloon_locked() for details.
*/ void xe_ggtt_node_remove_balloon_locked(struct xe_ggtt_node *node)
{ if (!xe_ggtt_node_allocated(node)) return;
/** * xe_ggtt_shift_nodes_locked - Shift GGTT nodes to adjust for a change in usable address range. * @ggtt: the &xe_ggtt struct instance * @shift: change to the location of area provisioned for current VF * * This function moves all nodes from the GGTT VM, to a temp list. These nodes are expected * to represent allocations in range formerly assigned to current VF, before the range changed. * When the GGTT VM is completely clear of any nodes, they are re-added with shifted offsets. * * The function has no ability of failing - because it shifts existing nodes, without * any additional processing. If the nodes were successfully existing at the old address, * they will do the same at the new one. A fail inside this function would indicate that * the list of nodes was either already damaged, or that the shift brings the address range * outside of valid bounds. Both cases justify an assert rather than error code.
*/ void xe_ggtt_shift_nodes_locked(struct xe_ggtt *ggtt, s64 shift)
{ struct xe_tile *tile __maybe_unused = ggtt->tile; struct drm_mm_node *node, *tmpn;
LIST_HEAD(temp_list_head);
lockdep_assert_held(&ggtt->lock);
if (IS_ENABLED(CONFIG_DRM_XE_DEBUG))
drm_mm_for_each_node_safe(node, tmpn, &ggtt->mm)
xe_ggtt_assert_fit(ggtt, node->start + shift, node->size);
/** * xe_ggtt_node_insert_locked - Locked version to insert a &xe_ggtt_node into the GGTT * @node: the &xe_ggtt_node to be inserted * @size: size of the node * @align: alignment constrain of the node * @mm_flags: flags to control the node behavior * * It cannot be called without first having called xe_ggtt_init() once. * To be used in cases where ggtt->lock is already taken. * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_node_insert_locked(struct xe_ggtt_node *node,
u32 size, u32 align, u32 mm_flags)
{ return drm_mm_insert_node_generic(&node->ggtt->mm, &node->base, size, align, 0,
mm_flags);
}
/** * xe_ggtt_node_insert - Insert a &xe_ggtt_node into the GGTT * @node: the &xe_ggtt_node to be inserted * @size: size of the node * @align: alignment constrain of the node * * It cannot be called without first having called xe_ggtt_init() once. * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_node_insert(struct xe_ggtt_node *node, u32 size, u32 align)
{ int ret;
if (!node || !node->ggtt) return -ENOENT;
mutex_lock(&node->ggtt->lock);
ret = xe_ggtt_node_insert_locked(node, size, align,
DRM_MM_INSERT_HIGH);
mutex_unlock(&node->ggtt->lock);
return ret;
}
/** * xe_ggtt_node_init - Initialize %xe_ggtt_node struct * @ggtt: the &xe_ggtt where the new node will later be inserted/reserved. * * This function will allocate the struct %xe_ggtt_node and return its pointer. * This struct will then be freed after the node removal upon xe_ggtt_node_remove() * or xe_ggtt_node_remove_balloon_locked(). * Having %xe_ggtt_node struct allocated doesn't mean that the node is already allocated * in GGTT. Only the xe_ggtt_node_insert(), xe_ggtt_node_insert_locked(), * xe_ggtt_node_insert_balloon_locked() will ensure the node is inserted or reserved in GGTT. * * Return: A pointer to %xe_ggtt_node struct on success. An ERR_PTR otherwise.
**/ struct xe_ggtt_node *xe_ggtt_node_init(struct xe_ggtt *ggtt)
{ struct xe_ggtt_node *node = kzalloc(sizeof(*node), GFP_NOFS);
/** * xe_ggtt_node_fini - Forcebly finalize %xe_ggtt_node struct * @node: the &xe_ggtt_node to be freed * * If anything went wrong with either xe_ggtt_node_insert(), xe_ggtt_node_insert_locked(), * or xe_ggtt_node_insert_balloon_locked(); and this @node is not going to be reused, then, * this function needs to be called to free the %xe_ggtt_node struct
**/ void xe_ggtt_node_fini(struct xe_ggtt_node *node)
{
kfree(node);
}
/** * xe_ggtt_node_allocated - Check if node is allocated in GGTT * @node: the &xe_ggtt_node to be inspected * * Return: True if allocated, False otherwise.
*/ bool xe_ggtt_node_allocated(conststruct xe_ggtt_node *node)
{ if (!node || !node->ggtt) returnfalse;
return drm_mm_node_allocated(&node->base);
}
/** * xe_ggtt_map_bo - Map the BO into GGTT * @ggtt: the &xe_ggtt where node will be mapped * @node: the &xe_ggtt_node where this BO is mapped * @bo: the &xe_bo to be mapped * @pat_index: Which pat_index to use.
*/ void xe_ggtt_map_bo(struct xe_ggtt *ggtt, struct xe_ggtt_node *node, struct xe_bo *bo, u16 pat_index)
{
u64 start, pte, end; struct xe_res_cursor cur;
if (XE_WARN_ON(!node)) return;
start = node->base.start;
end = start + xe_bo_size(bo);
for (xe_res_first(bo->ttm.resource, 0, xe_bo_size(bo), &cur);
cur.remaining; xe_res_next(&cur, XE_PAGE_SIZE))
ggtt->pt_ops->ggtt_set_pte(ggtt, end - cur.remaining,
pte + cur.start);
}
}
/** * xe_ggtt_map_bo_unlocked - Restore a mapping of a BO into GGTT * @ggtt: the &xe_ggtt where node will be mapped * @bo: the &xe_bo to be mapped * * This is used to restore a GGTT mapping after suspend.
*/ void xe_ggtt_map_bo_unlocked(struct xe_ggtt *ggtt, struct xe_bo *bo)
{
u16 cache_mode = bo->flags & XE_BO_FLAG_NEEDS_UC ? XE_CACHE_NONE : XE_CACHE_WB;
u16 pat_index = tile_to_xe(ggtt->tile)->pat.idx[cache_mode];
if (xe_bo_is_vram(bo) && ggtt->flags & XE_GGTT_FLAGS_64K)
alignment = SZ_64K;
if (XE_WARN_ON(bo->ggtt_node[tile_id])) { /* Someone's already inserted this BO in the GGTT */
xe_tile_assert(ggtt->tile, bo->ggtt_node[tile_id]->base.size == xe_bo_size(bo)); return 0;
}
err = xe_bo_validate(bo, NULL, false); if (err) return err;
if (!err && bo->flags & XE_BO_FLAG_GGTT_INVALIDATE)
xe_ggtt_invalidate(ggtt);
out:
xe_pm_runtime_put(tile_to_xe(ggtt->tile));
return err;
}
/** * xe_ggtt_insert_bo_at - Insert BO at a specific GGTT space * @ggtt: the &xe_ggtt where bo will be inserted * @bo: the &xe_bo to be inserted * @start: address where it will be inserted * @end: end of the range where it will be inserted * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_insert_bo_at(struct xe_ggtt *ggtt, struct xe_bo *bo,
u64 start, u64 end)
{ return __xe_ggtt_insert_bo_at(ggtt, bo, start, end);
}
/** * xe_ggtt_insert_bo - Insert BO into GGTT * @ggtt: the &xe_ggtt where bo will be inserted * @bo: the &xe_bo to be inserted * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_insert_bo(struct xe_ggtt *ggtt, struct xe_bo *bo)
{ return __xe_ggtt_insert_bo_at(ggtt, bo, 0, U64_MAX);
}
/** * xe_ggtt_remove_bo - Remove a BO from the GGTT * @ggtt: the &xe_ggtt where node will be removed * @bo: the &xe_bo to be removed
*/ void xe_ggtt_remove_bo(struct xe_ggtt *ggtt, struct xe_bo *bo)
{
u8 tile_id = ggtt->tile->id;
if (XE_WARN_ON(!bo->ggtt_node[tile_id])) return;
/* This BO is not currently in the GGTT */
xe_tile_assert(ggtt->tile, bo->ggtt_node[tile_id]->base.size == xe_bo_size(bo));
/** * xe_ggtt_assign - assign a GGTT region to the VF * @node: the &xe_ggtt_node to update * @vfid: the VF identifier * * This function is used by the PF driver to assign a GGTT region to the VF. * In addition to PTE's VFID bits 11:2 also PRESENT bit 0 is set as on some * platforms VFs can't modify that either.
*/ void xe_ggtt_assign(conststruct xe_ggtt_node *node, u16 vfid)
{
mutex_lock(&node->ggtt->lock);
xe_ggtt_assign_locked(node->ggtt, &node->base, vfid);
mutex_unlock(&node->ggtt->lock);
} #endif
/** * xe_ggtt_dump - Dump GGTT for debug * @ggtt: the &xe_ggtt to be dumped * @p: the &drm_mm_printer helper handle to be used to dump the information * * Return: 0 on success or a negative error code on failure.
*/ int xe_ggtt_dump(struct xe_ggtt *ggtt, struct drm_printer *p)
{ int err;
err = mutex_lock_interruptible(&ggtt->lock); if (err) return err;
/** * xe_ggtt_encode_pte_flags - Get PTE encoding flags for BO * @ggtt: &xe_ggtt * @bo: &xe_bo * @pat_index: The pat_index for the PTE. * * This function returns the pte_flags for a given BO, without address. * It's used for DPT to fill a GGTT mapped BO with a linear lookup table.
*/
u64 xe_ggtt_encode_pte_flags(struct xe_ggtt *ggtt, struct xe_bo *bo, u16 pat_index)
{ return ggtt->pt_ops->pte_encode_flags(bo, pat_index);
}
/** * xe_ggtt_read_pte - Read a PTE from the GGTT * @ggtt: &xe_ggtt * @offset: the offset for which the mapping should be read. * * Used by testcases, and by display reading out an inherited bios FB.
*/
u64 xe_ggtt_read_pte(struct xe_ggtt *ggtt, u64 offset)
{ return ioread64(ggtt->gsm + (offset / XE_PAGE_SIZE));
}
Messung V0.5
¤ Dauer der Verarbeitung: 0.31 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.