Skip to content

Commit

Permalink
hdata/test: Add memory reservations to hdata_to_dt
Browse files Browse the repository at this point in the history
Currently memory reservations are parsed, but since they are not
processed until mem_region_init() they don't appear in the output
device tree blob. Several bugs have been found with memory reservations
so we want them to be part of the test output.

Add them and clean up several usages of printf() since we want only the
dtb to appear in standard out.

Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
Reviewed-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
Signed-off-by: Stewart Smith <stewart@linux.vnet.ibm.com>
  • Loading branch information
oohal authored and stewartsmith committed Jun 6, 2017
1 parent 23ca5d4 commit cc7b746
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 17 deletions.
22 changes: 11 additions & 11 deletions core/mem_region.c
Expand Up @@ -291,23 +291,23 @@ void mem_dump_allocs(void)
struct alloc_hdr *hdr;

/* Second pass: populate property data */
printf("Memory regions:\n");
prlog(PR_INFO, "Memory regions:\n");
list_for_each(&regions, region, list) {
if (!(region->type == REGION_SKIBOOT_HEAP ||
region->type == REGION_MEMORY))
continue;
printf(" 0x%012llx..%012llx : %s\n",
prlog(PR_INFO, " 0x%012llx..%012llx : %s\n",
(long long)region->start,
(long long)(region->start + region->len - 1),
region->name);
if (region->free_list.n.next == NULL) {
printf(" no allocs\n");
prlog(PR_INFO, " no allocs\n");
continue;
}
for (hdr = region_start(region); hdr; hdr = next_hdr(region, hdr)) {
if (hdr->free)
continue;
printf(" 0x%.8lx %s\n", hdr->num_longs * sizeof(long),
prlog(PR_INFO, " 0x%.8lx %s\n", hdr->num_longs * sizeof(long),
hdr_location(hdr));
}
}
Expand All @@ -322,7 +322,7 @@ int64_t mem_dump_free(void)

total_free = 0;

printf("Free space in HEAP memory regions:\n");
prlog(PR_INFO, "Free space in HEAP memory regions:\n");
list_for_each(&regions, region, list) {
if (!(region->type == REGION_SKIBOOT_HEAP ||
region->type == REGION_MEMORY))
Expand All @@ -338,12 +338,12 @@ int64_t mem_dump_free(void)

region_free+= hdr->num_longs * sizeof(long);
}
printf("Region %s free: %"PRIx64"\n",
prlog(PR_INFO, "Region %s free: %"PRIx64"\n",
region->name, region_free);
total_free += region_free;
}

printf("Total free: %"PRIu64"\n", total_free);
prlog(PR_INFO, "Total free: %"PRIu64"\n", total_free);

return total_free;
}
Expand Down Expand Up @@ -1107,7 +1107,7 @@ void mem_region_release_unused(void)
lock(&mem_region_lock);
assert(!mem_regions_finalised);

printf("Releasing unused memory:\n");
prlog(PR_INFO, "Releasing unused memory:\n");
list_for_each(&regions, r, list) {
uint64_t used_len;

Expand All @@ -1118,7 +1118,7 @@ void mem_region_release_unused(void)

used_len = allocated_length(r);

printf(" %s: %llu/%llu used\n",
prlog(PR_INFO, " %s: %llu/%llu used\n",
r->name, (long long)used_len, (long long)r->len);

/* We keep the skiboot heap. */
Expand Down Expand Up @@ -1230,7 +1230,7 @@ void mem_region_add_dt_reserved(void)
name = names = malloc(names_len);
range = ranges = malloc(ranges_len);

printf("Reserved regions:\n");
prlog(PR_INFO, "Reserved regions:\n");
/* Second pass: populate property data */
list_for_each(&regions, region, list) {
if (!region_is_reservable(region))
Expand All @@ -1239,7 +1239,7 @@ void mem_region_add_dt_reserved(void)
memcpy(name, region->name, len);
name += len;

printf(" 0x%012llx..%012llx : %s\n",
prlog(PR_INFO, " 0x%012llx..%012llx : %s\n",
(long long)region->start,
(long long)(region->start + region->len - 1),
region->name);
Expand Down
10 changes: 10 additions & 0 deletions hdata/test/hdata_to_dt.c
Expand Up @@ -67,6 +67,7 @@ unsigned long tb_hz = 512000000;
#define __CPU_H
struct cpu_thread {
uint32_t pir;
uint32_t chip_id;
};

struct cpu_thread __boot_cpu, *boot_cpu = &__boot_cpu;
Expand Down Expand Up @@ -94,6 +95,11 @@ struct dt_node *add_ics_node(void)

static bool spira_check_ptr(const void *ptr, const char *file, unsigned int line);

/* should probably check this */
#define BITS_PER_LONG 64
/* not used, just needs to exist */
#define cpu_max_pir 0x7

#include "../cpu-common.c"
#include "../fsp.c"
#include "../hdif.c"
Expand All @@ -113,6 +119,7 @@ static bool spira_check_ptr(const void *ptr, const char *file, unsigned int line
#include "../../test/dt_common.c"
#include "../../core/fdt.c"
#include "../../hw/phys-map.c"
#include "../../core/mem_region.c"

#include <err.h>

Expand Down Expand Up @@ -335,6 +342,9 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE);
}

mem_region_init();
mem_region_release_unused();

if (!blobs)
squash_blobs(dt_root);

Expand Down
20 changes: 14 additions & 6 deletions hdata/test/stubs.c
Expand Up @@ -23,8 +23,6 @@

#include "../../ccan/list/list.c"

unsigned long top_of_ram = 16ULL * 1024 * 1024 * 1024;

void _prlog(int log_level __attribute__((unused)), const char* fmt, ...) __attribute__((format (printf, 2, 3)));

#ifndef pr_fmt
Expand Down Expand Up @@ -102,10 +100,20 @@ STUB(fsp_adjust_lid_side);
STUB(backtrace);

/* Add HW specific stubs here */
static void noop_function(void) {}
#define NOOP_STUB(fnname) \
void fnname(void) __attribute__((weak, alias ("noop_function")))

static bool true_stub(void) { return true; }
static bool false_stub(void) { return false; }

#define TRUE_STUB(fnname) \
void fnname(void) __attribute__((weak, alias ("true_stub")))
#define FALSE_STUB(fnname) \
void fnname(void) __attribute__((weak, alias ("false_stub")))
#define NOOP_STUB FALSE_STUB

TRUE_STUB(lock_held_by_me);
NOOP_STUB(lock);
NOOP_STUB(unlock);
NOOP_STUB(early_uart_init);
NOOP_STUB(mem_reserve_fw);
NOOP_STUB(mem_reserve_hwbuf);
NOOP_STUB(add_chip_dev_associativity);

0 comments on commit cc7b746

Please sign in to comment.