1dd08ebf6SMatthew Brost /* SPDX-License-Identifier: MIT */ 2dd08ebf6SMatthew Brost /* 3dd08ebf6SMatthew Brost * Copyright © 2022 Intel Corporation 4dd08ebf6SMatthew Brost */ 5dd08ebf6SMatthew Brost 6dd08ebf6SMatthew Brost #ifndef _XE_MIGRATE_DOC_H_ 7dd08ebf6SMatthew Brost #define _XE_MIGRATE_DOC_H_ 8dd08ebf6SMatthew Brost 9dd08ebf6SMatthew Brost /** 10dd08ebf6SMatthew Brost * DOC: Migrate Layer 11dd08ebf6SMatthew Brost * 12dd08ebf6SMatthew Brost * The XE migrate layer is used generate jobs which can copy memory (eviction), 13dd08ebf6SMatthew Brost * clear memory, or program tables (binds). This layer exists in every GT, has 14dd08ebf6SMatthew Brost * a migrate engine, and uses a special VM for all generated jobs. 15dd08ebf6SMatthew Brost * 16dd08ebf6SMatthew Brost * Special VM details 17dd08ebf6SMatthew Brost * ================== 18dd08ebf6SMatthew Brost * 19dd08ebf6SMatthew Brost * The special VM is configured with a page structure where we can dynamically 20dd08ebf6SMatthew Brost * map BOs which need to be copied and cleared, dynamically map other VM's page 21dd08ebf6SMatthew Brost * table BOs for updates, and identity map the entire device's VRAM with 1 GB 22dd08ebf6SMatthew Brost * pages. 23dd08ebf6SMatthew Brost * 24*b99cb621SNiranjana Vishwanathapura * Currently the page structure consists of 32 physical pages with 16 being 25dd08ebf6SMatthew Brost * reserved for BO mapping during copies and clear, 1 reserved for kernel binds, 26dd08ebf6SMatthew Brost * several pages are needed to setup the identity mappings (exact number based 27dd08ebf6SMatthew Brost * on how many bits of address space the device has), and the rest are reserved 28dd08ebf6SMatthew Brost * user bind operations. 29dd08ebf6SMatthew Brost * 30dd08ebf6SMatthew Brost * TODO: Diagram of layout 31dd08ebf6SMatthew Brost * 32dd08ebf6SMatthew Brost * Bind jobs 33dd08ebf6SMatthew Brost * ========= 34dd08ebf6SMatthew Brost * 35dd08ebf6SMatthew Brost * A bind job consist of two batches and runs either on the migrate engine 36dd08ebf6SMatthew Brost * (kernel binds) or the bind engine passed in (user binds). In both cases the 37dd08ebf6SMatthew Brost * VM of the engine is the migrate VM. 38dd08ebf6SMatthew Brost * 39dd08ebf6SMatthew Brost * The first batch is used to update the migration VM page structure to point to 40dd08ebf6SMatthew Brost * the bind VM page table BOs which need to be updated. A physical page is 41dd08ebf6SMatthew Brost * required for this. If it is a user bind, the page is allocated from pool of 42dd08ebf6SMatthew Brost * pages reserved user bind operations with drm_suballoc managing this pool. If 43dd08ebf6SMatthew Brost * it is a kernel bind, the page reserved for kernel binds is used. 44dd08ebf6SMatthew Brost * 45dd08ebf6SMatthew Brost * The first batch is only required for devices without VRAM as when the device 46dd08ebf6SMatthew Brost * has VRAM the bind VM page table BOs are in VRAM and the identity mapping can 47dd08ebf6SMatthew Brost * be used. 48dd08ebf6SMatthew Brost * 49dd08ebf6SMatthew Brost * The second batch is used to program page table updated in the bind VM. Why 50dd08ebf6SMatthew Brost * not just one batch? Well the TLBs need to be invalidated between these two 51dd08ebf6SMatthew Brost * batches and that only can be done from the ring. 52dd08ebf6SMatthew Brost * 53dd08ebf6SMatthew Brost * When the bind job complete, the page allocated is returned the pool of pages 54dd08ebf6SMatthew Brost * reserved for user bind operations if a user bind. No need do this for kernel 55dd08ebf6SMatthew Brost * binds as the reserved kernel page is serially used by each job. 56dd08ebf6SMatthew Brost * 57dd08ebf6SMatthew Brost * Copy / clear jobs 58dd08ebf6SMatthew Brost * ================= 59dd08ebf6SMatthew Brost * 60dd08ebf6SMatthew Brost * A copy or clear job consist of two batches and runs on the migrate engine. 61dd08ebf6SMatthew Brost * 62dd08ebf6SMatthew Brost * Like binds, the first batch is used update the migration VM page structure. 63dd08ebf6SMatthew Brost * In copy jobs, we need to map the source and destination of the BO into page 64dd08ebf6SMatthew Brost * the structure. In clear jobs, we just need to add 1 mapping of BO into the 65dd08ebf6SMatthew Brost * page structure. We use the 16 reserved pages in migration VM for mappings, 66dd08ebf6SMatthew Brost * this gives us a maximum copy size of 16 MB and maximum clear size of 32 MB. 67dd08ebf6SMatthew Brost * 68dd08ebf6SMatthew Brost * The second batch is used do either do the copy or clear. Again similar to 69dd08ebf6SMatthew Brost * binds, two batches are required as the TLBs need to be invalidated from the 70dd08ebf6SMatthew Brost * ring between the batches. 71dd08ebf6SMatthew Brost * 72dd08ebf6SMatthew Brost * More than one job will be generated if the BO is larger than maximum copy / 73dd08ebf6SMatthew Brost * clear size. 74dd08ebf6SMatthew Brost * 75dd08ebf6SMatthew Brost * Future work 76dd08ebf6SMatthew Brost * =========== 77dd08ebf6SMatthew Brost * 78dd08ebf6SMatthew Brost * Update copy and clear code to use identity mapped VRAM. 79dd08ebf6SMatthew Brost * 80dd08ebf6SMatthew Brost * Can we rework the use of the pages async binds to use all the entries in each 81dd08ebf6SMatthew Brost * page? 82dd08ebf6SMatthew Brost * 83dd08ebf6SMatthew Brost * Using large pages for sysmem mappings. 84dd08ebf6SMatthew Brost * 85dd08ebf6SMatthew Brost * Is it possible to identity map the sysmem? We should explore this. 86dd08ebf6SMatthew Brost */ 87dd08ebf6SMatthew Brost 88dd08ebf6SMatthew Brost #endif 89