| 1 | /* SPDX-License-Identifier: MIT */ |
| 2 | /* |
| 3 | * Copyright © 2022 Intel Corporation |
| 4 | */ |
| 5 | |
| 6 | #ifndef _XE_GGTT_TYPES_H_ |
| 7 | #define _XE_GGTT_TYPES_H_ |
| 8 | |
| 9 | #include <drm/drm_mm.h> |
| 10 | |
| 11 | #include "xe_pt_types.h" |
| 12 | |
| 13 | struct xe_bo; |
| 14 | struct xe_gt; |
| 15 | |
| 16 | /** |
| 17 | * struct xe_ggtt - Main GGTT struct |
| 18 | * |
| 19 | * In general, each tile can contains its own Global Graphics Translation Table |
| 20 | * (GGTT) instance. |
| 21 | */ |
| 22 | struct xe_ggtt { |
| 23 | /** @tile: Back pointer to tile where this GGTT belongs */ |
| 24 | struct xe_tile *tile; |
| 25 | /** @size: Total size of this GGTT */ |
| 26 | u64 size; |
| 27 | |
| 28 | #define XE_GGTT_FLAGS_64K BIT(0) |
| 29 | /** |
| 30 | * @flags: Flags for this GGTT |
| 31 | * Acceptable flags: |
| 32 | * - %XE_GGTT_FLAGS_64K - if PTE size is 64K. Otherwise, regular is 4K. |
| 33 | */ |
| 34 | unsigned int flags; |
| 35 | /** @scratch: Internal object allocation used as a scratch page */ |
| 36 | struct xe_bo *scratch; |
| 37 | /** @lock: Mutex lock to protect GGTT data */ |
| 38 | struct mutex lock; |
| 39 | /** |
| 40 | * @gsm: The iomem pointer to the actual location of the translation |
| 41 | * table located in the GSM for easy PTE manipulation |
| 42 | */ |
| 43 | u64 __iomem *gsm; |
| 44 | /** @pt_ops: Page Table operations per platform */ |
| 45 | const struct xe_ggtt_pt_ops *pt_ops; |
| 46 | /** @mm: The memory manager used to manage individual GGTT allocations */ |
| 47 | struct drm_mm mm; |
| 48 | /** @access_count: counts GGTT writes */ |
| 49 | unsigned int access_count; |
| 50 | /** @wq: Dedicated unordered work queue to process node removals */ |
| 51 | struct workqueue_struct *wq; |
| 52 | }; |
| 53 | |
| 54 | /** |
| 55 | * struct xe_ggtt_node - A node in GGTT. |
| 56 | * |
| 57 | * This struct needs to be initialized (only-once) with xe_ggtt_node_init() before any node |
| 58 | * insertion, reservation, or 'ballooning'. |
| 59 | * It will, then, be finalized by either xe_ggtt_node_remove() or xe_ggtt_node_deballoon(). |
| 60 | */ |
| 61 | struct xe_ggtt_node { |
| 62 | /** @ggtt: Back pointer to xe_ggtt where this region will be inserted at */ |
| 63 | struct xe_ggtt *ggtt; |
| 64 | /** @base: A drm_mm_node */ |
| 65 | struct drm_mm_node base; |
| 66 | /** @delayed_removal_work: The work struct for the delayed removal */ |
| 67 | struct work_struct delayed_removal_work; |
| 68 | /** @invalidate_on_remove: If it needs invalidation upon removal */ |
| 69 | bool invalidate_on_remove; |
| 70 | }; |
| 71 | |
| 72 | /** |
| 73 | * struct xe_ggtt_pt_ops - GGTT Page table operations |
| 74 | * Which can vary from platform to platform. |
| 75 | */ |
| 76 | struct xe_ggtt_pt_ops { |
| 77 | /** @pte_encode_flags: Encode PTE flags for a given BO */ |
| 78 | u64 (*pte_encode_flags)(struct xe_bo *bo, u16 pat_index); |
| 79 | /** @ggtt_set_pte: Directly write into GGTT's PTE */ |
| 80 | void (*ggtt_set_pte)(struct xe_ggtt *ggtt, u64 addr, u64 pte); |
| 81 | /** @ggtt_get_pte: Directly read from GGTT's PTE */ |
| 82 | u64 (*ggtt_get_pte)(struct xe_ggtt *ggtt, u64 addr); |
| 83 | }; |
| 84 | |
| 85 | #endif |
| 86 | |