Skip to content

Commit c7206e7

Browse files
FlyGoattsbogend
authored andcommitted
MIPS: Loongson64: Handle more memory types passed from firmware
There are many types of revsered memory passed from firmware that should be reserved in memblock, and UMA memory passed from firmware that should be added to system memory for system to use. Also for memblock there is no need to align those space into page, which actually cause problems. Handle them properly to prevent memory corruption on some systems. Cc: [email protected] Signed-off-by: Jiaxun Yang <[email protected]> Signed-off-by: Thomas Bogendoerfer <[email protected]>
1 parent edc0378 commit c7206e7

File tree

2 files changed

+31
-17
lines changed

2 files changed

+31
-17
lines changed

arch/mips/include/asm/mach-loongson64/boot_param.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,11 @@
1414
#define ADAPTER_ROM 8
1515
#define ACPI_TABLE 9
1616
#define SMBIOS_TABLE 10
17-
#define MAX_MEMORY_TYPE 11
17+
#define UMA_VIDEO_RAM 11
18+
#define VUMA_VIDEO_RAM 12
19+
#define MAX_MEMORY_TYPE 13
20+
21+
#define MEM_SIZE_IS_IN_BYTES (1 << 31)
1822

1923
#define LOONGSON3_BOOT_MEM_MAP_MAX 128
2024
struct efi_memory_map_loongson {

arch/mips/loongson64/init.c

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@ void virtual_early_config(void)
4949
void __init szmem(unsigned int node)
5050
{
5151
u32 i, mem_type;
52-
static unsigned long num_physpages;
53-
u64 node_id, node_psize, start_pfn, end_pfn, mem_start, mem_size;
52+
phys_addr_t node_id, mem_start, mem_size;
5453

5554
/* Otherwise come from DTB */
5655
if (loongson_sysconf.fw_interface != LOONGSON_LEFI)
@@ -64,27 +63,38 @@ void __init szmem(unsigned int node)
6463

6564
mem_type = loongson_memmap->map[i].mem_type;
6665
mem_size = loongson_memmap->map[i].mem_size;
67-
mem_start = loongson_memmap->map[i].mem_start;
66+
67+
/* Memory size comes in MB if MEM_SIZE_IS_IN_BYTES not set */
68+
if (mem_size & MEM_SIZE_IS_IN_BYTES)
69+
mem_size &= ~MEM_SIZE_IS_IN_BYTES;
70+
else
71+
mem_size = mem_size << 20;
72+
73+
mem_start = (node_id << 44) | loongson_memmap->map[i].mem_start;
6874

6975
switch (mem_type) {
7076
case SYSTEM_RAM_LOW:
7177
case SYSTEM_RAM_HIGH:
72-
start_pfn = ((node_id << 44) + mem_start) >> PAGE_SHIFT;
73-
node_psize = (mem_size << 20) >> PAGE_SHIFT;
74-
end_pfn = start_pfn + node_psize;
75-
num_physpages += node_psize;
76-
pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n",
77-
(u32)node_id, mem_type, mem_start, mem_size);
78-
pr_info(" start_pfn:0x%llx, end_pfn:0x%llx, num_physpages:0x%lx\n",
79-
start_pfn, end_pfn, num_physpages);
80-
memblock_add_node(PFN_PHYS(start_pfn),
81-
PFN_PHYS(node_psize), node,
78+
case UMA_VIDEO_RAM:
79+
pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes usable\n",
80+
(u32)node_id, mem_type, &mem_start, &mem_size);
81+
memblock_add_node(mem_start, mem_size, node,
8282
MEMBLOCK_NONE);
8383
break;
8484
case SYSTEM_RAM_RESERVED:
85-
pr_info("Node%d: mem_type:%d, mem_start:0x%llx, mem_size:0x%llx MB\n",
86-
(u32)node_id, mem_type, mem_start, mem_size);
87-
memblock_reserve(((node_id << 44) + mem_start), mem_size << 20);
85+
case VIDEO_ROM:
86+
case ADAPTER_ROM:
87+
case ACPI_TABLE:
88+
case SMBIOS_TABLE:
89+
pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes reserved\n",
90+
(u32)node_id, mem_type, &mem_start, &mem_size);
91+
memblock_reserve(mem_start, mem_size);
92+
break;
93+
/* We should not reserve VUMA_VIDEO_RAM as it overlaps with MMIO */
94+
case VUMA_VIDEO_RAM:
95+
default:
96+
pr_info("Node %d, mem_type:%d\t[%pa], %pa bytes unhandled\n",
97+
(u32)node_id, mem_type, &mem_start, &mem_size);
8898
break;
8999
}
90100
}

0 commit comments

Comments
 (0)