@@ -54,20 +54,14 @@ static char bootargs[BOOT_ARG_LEN];
5454 * Begin Limit Type Length
5555 * 0: 0 - 0xA0000 RAM 0xA0000
5656 * 1: 0x100000 - lowmem part1 RAM 0x0
57- * 2: gpu_rsvd_bot - gpu_rsvd_top (reserved) 0x4004000
58- * 3: lowmem part2 - 0x7f800000 (reserved) 0x0
59- * 4: SW SRAM_bot - 0x80000000 (reserved) SOFTWARE_SRAM_MAX_SIZE
60- * 5: 0xDB000000 - 0xDF000000 (reserved) 64MB
61- * 6: 0xDF000000 - 0xE0000000 (reserved) 16MB
62- * 7: 0xE0000000 - 0x100000000 MCFG, MMIO 512MB
63- * 8: 0x140000000 - highmem RAM highmem - 5GB
57+ * 2: SW SRAM_bot - SW SRAM_top (reserved) SOFTWARE_SRAM_MAX_SIZE
58+ * 3: gpu_rsvd_bot - gpu_rsvd_top (reserved) 0x4004000
59+ * 4: lowmem part2 - 0x80000000 (reserved) 0x0
60+ * 5: 0xE0000000 - 0x100000000 MCFG, MMIO 512MB
61+ * 6: 0x140000000 - highmem RAM highmem - 5GB
6462 *
6563 * FIXME: Do we need to reserve DSM and OPREGION for GVTD here.
6664 */
67-
68- #define GPU_DSM_OPREGION_BASE_GPA 0x3B800000
69- #define GPU_DSM_OPREGION_SIZE 0x4004000
70-
7165const struct e820_entry e820_default_entries [NUM_E820_ENTRIES ] = {
7266 { /* 0 to video memory */
7367 .baseaddr = 0x00000000 ,
@@ -81,30 +75,30 @@ const struct e820_entry e820_default_entries[NUM_E820_ENTRIES] = {
8175 .type = E820_TYPE_RAM
8276 },
8377
84- { /* TGL GPU DSM & OpRegion area */
85- .baseaddr = GPU_DSM_OPREGION_BASE_GPA ,
86- .length = GPU_DSM_OPREGION_SIZE ,
87- .type = E820_TYPE_RESERVED
88- },
89-
90- { /* lowmem part2 to lowmem_limit */
91- .baseaddr = GPU_DSM_OPREGION_BASE_GPA + GPU_DSM_OPREGION_SIZE ,
92- .length = 0x0 ,
93- .type = E820_TYPE_RESERVED
94- },
95-
9678 /*
97- * Software SRAM area: base: 0x7f800000, size: 0x800000
79+ * Software SRAM area: size: 0x800000
9880 * In native, the Software SRAM region should be part of DRAM memory.
9981 * But one fixed Software SRAM gpa is friendly for virtualization due
10082 * to decoupled with various guest memory size.
10183 */
10284 {
103- .baseaddr = SOFTWARE_SRAM_BASE_GPA ,
104- .length = SOFTWARE_SRAM_MAX_SIZE ,
85+ .baseaddr = 0x0 ,
86+ .length = 0x0 ,
10587 .type = E820_TYPE_RESERVED
10688 },
10789
90+ { /* GPU DSM & OpRegion reserved region */
91+ .baseaddr = 0x0 ,
92+ .length = 0x0 ,
93+ .type = E820_TYPE_RESERVED
94+ },
95+
96+ { /* lowmem part2 to lowmem_limit */
97+ .baseaddr = 0x0 ,
98+ .length = 0x0 ,
99+ .type = E820_TYPE_RESERVED
100+ },
101+
108102 { /* ECFG_BASE to 4GB */
109103 .baseaddr = PCI_EMUL_ECFG_BASE ,
110104 .length = (4 * GB ) - PCI_EMUL_ECFG_BASE ,
@@ -225,32 +219,65 @@ uint32_t
225219acrn_create_e820_table (struct vmctx * ctx , struct e820_entry * e820 )
226220{
227221 uint32_t removed = 0 , k ;
222+ uint32_t gpu_rsvmem_base_gpa = 0 ;
223+ uint64_t software_sram_base_gpa = 0 ;
228224
229225 memcpy (e820 , e820_default_entries , sizeof (e820_default_entries ));
230- if (ctx -> lowmem <= e820 [LOWRAM_E820_ENTRY + 2 ].baseaddr ) {
231- e820 [LOWRAM_E820_ENTRY ].length =
232- (ctx -> lowmem < e820 [LOWRAM_E820_ENTRY + 1 ].baseaddr ? ctx -> lowmem :
233- e820 [LOWRAM_E820_ENTRY + 1 ].baseaddr ) - e820 [LOWRAM_E820_ENTRY ].baseaddr ;
234226
235- memmove (& e820 [LOWRAM_E820_ENTRY + 2 ], & e820 [LOWRAM_E820_ENTRY + 3 ],
236- sizeof (struct e820_entry ) *
237- (NUM_E820_ENTRIES - (LOWRAM_E820_ENTRY + 3 )));
238- removed ++ ;
227+ /* FIXME: Here wastes 8MB memory if pSRAM is enabled, and 64MB+16KB if
228+ * GPU reserved memory is exist.
229+ *
230+ * Determines the GPU region due to DSM identical mapping.
231+ */
232+ gpu_rsvmem_base_gpa = get_gpu_rsvmem_base_gpa ();
233+ if (gpu_rsvmem_base_gpa ) {
234+ e820 [LOWRAM_E820_ENTRY + 2 ].baseaddr = gpu_rsvmem_base_gpa ;
235+ e820 [LOWRAM_E820_ENTRY + 2 ].length = get_gpu_rsvmem_size ();
239236 } else {
240- e820 [LOWRAM_E820_ENTRY ]. length = e820 [ LOWRAM_E820_ENTRY + 1 ].baseaddr -
241- e820 [ LOWRAM_E820_ENTRY ]. baseaddr ;
237+ e820 [LOWRAM_E820_ENTRY + 2 ].baseaddr = ctx -> lowmem_limit ;
238+ }
242239
243- e820 [LOWRAM_E820_ENTRY + 2 ].length =
244- ((ctx -> lowmem < e820 [LOWRAM_E820_ENTRY + 3 ].baseaddr ) ? ctx -> lowmem :
245- e820 [LOWRAM_E820_ENTRY + 3 ].baseaddr ) - e820 [LOWRAM_E820_ENTRY + 2 ].baseaddr ;
240+ /* Always put SW SRAM before GPU region and keep 1MB boundary for protection. */
241+ software_sram_base_gpa = get_software_sram_base_gpa ();
242+ if (software_sram_base_gpa ) {
243+ e820 [LOWRAM_E820_ENTRY + 1 ].baseaddr = software_sram_base_gpa ;
244+ e820 [LOWRAM_E820_ENTRY + 1 ].length = get_software_sram_size ();
245+ } else {
246+ e820 [LOWRAM_E820_ENTRY + 1 ].baseaddr = e820 [LOWRAM_E820_ENTRY + 2 ].baseaddr ;
246247 }
247248
248- /* remove [5GB, highmem) if it's empty */
249- if ( ctx -> highmem > 0 ) {
250- e820 [HIGHRAM_E820_ENTRY - removed ]. type = E820_TYPE_RAM ;
251- e820 [ HIGHRAM_E820_ENTRY - removed ]. length = ctx -> highmem ;
249+ if ( ctx -> lowmem <= e820 [ LOWRAM_E820_ENTRY + 1 ]. baseaddr ) {
250+ /* Caculation for lowmem part1 */
251+ e820 [LOWRAM_E820_ENTRY ]. length =
252+ ctx -> lowmem - e820 [ LOWRAM_E820_ENTRY ]. baseaddr ;
252253 } else {
253- removed ++ ;
254+ /* Caculation for lowmem part1 */
255+ e820 [LOWRAM_E820_ENTRY ].length =
256+ e820 [LOWRAM_E820_ENTRY + 1 ].baseaddr - e820 [LOWRAM_E820_ENTRY ].baseaddr ;
257+ /* Caculation for lowmem part2 */
258+ e820 [LOWRAM_E820_ENTRY + 3 ].baseaddr =
259+ e820 [LOWRAM_E820_ENTRY + 2 ].baseaddr + e820 [LOWRAM_E820_ENTRY + 2 ].length ;
260+ if (ctx -> lowmem > e820 [LOWRAM_E820_ENTRY + 3 ].baseaddr ) {
261+ e820 [LOWRAM_E820_ENTRY + 3 ].length =
262+ ctx -> lowmem - e820 [LOWRAM_E820_ENTRY + 3 ].baseaddr ;
263+ e820 [LOWRAM_E820_ENTRY + 3 ].type = E820_TYPE_RAM ;
264+ }
265+ }
266+
267+ /* Caculation for highmem */
268+ if (ctx -> highmem > 0 ) {
269+ e820 [HIGHRAM_E820_ENTRY ].type = E820_TYPE_RAM ;
270+ e820 [HIGHRAM_E820_ENTRY ].length = ctx -> highmem ;
271+ }
272+
273+ /* Remove empty entries in e820 table */
274+ for (k = 0 ; k < (NUM_E820_ENTRIES - 1 - removed ); k ++ ) {
275+ if (e820 [k ].length == 0x0 ) {
276+ memmove (& e820 [k ], & e820 [k + 1 ], sizeof (struct e820_entry ) *
277+ (NUM_E820_ENTRIES - (k + 1 )));
278+ k -- ;
279+ removed ++ ;
280+ }
254281 }
255282
256283 pr_info ("SW_LOAD: build e820 %d entries to addr: %p\r\n" ,
0 commit comments