Skip to content

Commit a5718fe

Browse files
FlyGoatpaulburton
authored andcommitted
MIPS: mm: Drop boot_mem_map
Initialize maar by resource map and replace page_is_ram by memblock_is_memory. Signed-off-by: Jiaxun Yang <[email protected]> [[email protected]: - Fix bad MAAR address calculations. - Use ALIGN() & define maar_align to make it clearer what's going on with address manipulations. - Drop the new used field from struct maar_config. - Rework the RAM walk to avoid iterating over the cfg array needlessly to find the first unused entry, then count used entries at the end. Instead just keep the count as we go.] Signed-off-by: Paul Burton <[email protected]> Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected] Cc: [email protected]
1 parent a121d6e commit a5718fe

File tree

1 file changed

+37
-57
lines changed

1 file changed

+37
-57
lines changed

arch/mips/mm/init.c

Lines changed: 37 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -269,37 +269,46 @@ void __init fixrange_init(unsigned long start, unsigned long end,
269269
#endif
270270
}
271271

272-
unsigned __weak platform_maar_init(unsigned num_pairs)
272+
struct maar_walk_info {
273+
struct maar_config cfg[16];
274+
unsigned int num_cfg;
275+
};
276+
277+
static int maar_res_walk(unsigned long start_pfn, unsigned long nr_pages,
278+
void *data)
273279
{
274-
struct maar_config cfg[BOOT_MEM_MAP_MAX];
275-
unsigned i, num_configured, num_cfg = 0;
276-
277-
for (i = 0; i < boot_mem_map.nr_map; i++) {
278-
switch (boot_mem_map.map[i].type) {
279-
case BOOT_MEM_RAM:
280-
case BOOT_MEM_INIT_RAM:
281-
break;
282-
default:
283-
continue;
284-
}
280+
struct maar_walk_info *wi = data;
281+
struct maar_config *cfg = &wi->cfg[wi->num_cfg];
282+
unsigned int maar_align;
285283

286-
/* Round lower up */
287-
cfg[num_cfg].lower = boot_mem_map.map[i].addr;
288-
cfg[num_cfg].lower = (cfg[num_cfg].lower + 0xffff) & ~0xffff;
284+
/* MAAR registers hold physical addresses right shifted by 4 bits */
285+
maar_align = BIT(MIPS_MAAR_ADDR_SHIFT + 4);
289286

290-
/* Round upper down */
291-
cfg[num_cfg].upper = boot_mem_map.map[i].addr +
292-
boot_mem_map.map[i].size;
293-
cfg[num_cfg].upper = (cfg[num_cfg].upper & ~0xffff) - 1;
287+
/* Fill in the MAAR config entry */
288+
cfg->lower = ALIGN(PFN_PHYS(start_pfn), maar_align);
289+
cfg->upper = ALIGN_DOWN(PFN_PHYS(start_pfn + nr_pages), maar_align) - 1;
290+
cfg->attrs = MIPS_MAAR_S;
294291

295-
cfg[num_cfg].attrs = MIPS_MAAR_S;
296-
num_cfg++;
297-
}
292+
/* Ensure we don't overflow the cfg array */
293+
if (!WARN_ON(wi->num_cfg >= ARRAY_SIZE(wi->cfg)))
294+
wi->num_cfg++;
295+
296+
return 0;
297+
}
298+
299+
300+
unsigned __weak platform_maar_init(unsigned num_pairs)
301+
{
302+
unsigned int num_configured;
303+
struct maar_walk_info wi;
304+
305+
wi.num_cfg = 0;
306+
walk_system_ram_range(0, max_pfn, &wi, maar_res_walk);
298307

299-
num_configured = maar_config(cfg, num_cfg, num_pairs);
300-
if (num_configured < num_cfg)
301-
pr_warn("Not enough MAAR pairs (%u) for all bootmem regions (%u)\n",
302-
num_pairs, num_cfg);
308+
num_configured = maar_config(wi.cfg, wi.num_cfg, num_pairs);
309+
if (num_configured < wi.num_cfg)
310+
pr_warn("Not enough MAAR pairs (%u) for all memory regions (%u)\n",
311+
num_pairs, wi.num_cfg);
303312

304313
return num_configured;
305314
}
@@ -382,33 +391,6 @@ void maar_init(void)
382391
}
383392

384393
#ifndef CONFIG_NEED_MULTIPLE_NODES
385-
int page_is_ram(unsigned long pagenr)
386-
{
387-
int i;
388-
389-
for (i = 0; i < boot_mem_map.nr_map; i++) {
390-
unsigned long addr, end;
391-
392-
switch (boot_mem_map.map[i].type) {
393-
case BOOT_MEM_RAM:
394-
case BOOT_MEM_INIT_RAM:
395-
break;
396-
default:
397-
/* not usable memory */
398-
continue;
399-
}
400-
401-
addr = PFN_UP(boot_mem_map.map[i].addr);
402-
end = PFN_DOWN(boot_mem_map.map[i].addr +
403-
boot_mem_map.map[i].size);
404-
405-
if (pagenr >= addr && pagenr < end)
406-
return 1;
407-
}
408-
409-
return 0;
410-
}
411-
412394
void __init paging_init(void)
413395
{
414396
unsigned long max_zone_pfns[MAX_NR_ZONES];
@@ -443,7 +425,7 @@ void __init paging_init(void)
443425
static struct kcore_list kcore_kseg0;
444426
#endif
445427

446-
static inline void mem_init_free_highmem(void)
428+
static inline void __init mem_init_free_highmem(void)
447429
{
448430
#ifdef CONFIG_HIGHMEM
449431
unsigned long tmp;
@@ -452,9 +434,7 @@ static inline void mem_init_free_highmem(void)
452434
return;
453435

454436
for (tmp = highstart_pfn; tmp < highend_pfn; tmp++) {
455-
struct page *page = pfn_to_page(tmp);
456-
457-
if (!page_is_ram(tmp))
437+
if (!memblock_is_memory(PFN_PHYS(tmp)))
458438
SetPageReserved(page);
459439
else
460440
free_highmem_page(page);

0 commit comments

Comments
 (0)