Skip to content

Commit

Permalink
debug descriptor: make endian-clean
Browse files Browse the repository at this point in the history
Signed-off-by: Nicholas Piggin <npiggin@gmail.com>
Signed-off-by: Oliver O'Halloran <oohall@gmail.com>
  • Loading branch information
npiggin authored and oohal committed Dec 16, 2019
1 parent 45c1436 commit 1959efa
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 35 deletions.
9 changes: 7 additions & 2 deletions core/init.c
Expand Up @@ -72,9 +72,9 @@ void skiboot_gcov_done(void);

struct debug_descriptor debug_descriptor = {
.eye_catcher = "OPALdbug",
.version = DEBUG_DESC_VERSION,
.version = CPU_TO_BE32(DEBUG_DESC_VERSION),
.state_flags = 0,
.memcons_phys = (uint64_t)&memcons,
.memcons_phys = 0, /* cpu_to_be64(&memcons) can't init constant */
.trace_mask = 0, /* All traces disabled by default */
/* console log level:
* high 4 bits in memory, low 4 bits driver (e.g. uart). */
Expand Down Expand Up @@ -1008,6 +1008,11 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt)
*/
pre_init_boot_cpu();

/*
* Point to our mem console
*/
debug_descriptor.memcons_phys = cpu_to_be64((uint64_t)&memcons);

/*
* Before first printk, ensure console buffer is clear or
* reading tools might think it has wrapped
Expand Down
22 changes: 11 additions & 11 deletions core/trace.c
Expand Up @@ -121,7 +121,7 @@ void trace_add(union trace *trace, u8 type, u16 len)
#endif
/* Skip traces not enabled in the debug descriptor */
if (trace->hdr.type < (8 * sizeof(debug_descriptor.trace_mask)) &&
!((1ul << trace->hdr.type) & debug_descriptor.trace_mask))
!((1ul << trace->hdr.type) & be64_to_cpu(debug_descriptor.trace_mask)))
return;

trace->hdr.timestamp = cpu_to_be64(mftb());
Expand Down Expand Up @@ -171,12 +171,12 @@ static void trace_add_dt_props(void)
if (!exports)
return;

prop = malloc(sizeof(u64) * 2 * debug_descriptor.num_traces);
prop = malloc(sizeof(u64) * 2 * be32_to_cpu(debug_descriptor.num_traces));

for (i = 0; i < debug_descriptor.num_traces; i++) {
uint64_t addr = debug_descriptor.trace_phys[i];
uint64_t size = debug_descriptor.trace_size[i];
uint32_t pir = debug_descriptor.trace_pir[i];
for (i = 0; i < be32_to_cpu(debug_descriptor.num_traces); i++) {
uint64_t addr = be64_to_cpu(debug_descriptor.trace_phys[i]);
uint64_t size = be32_to_cpu(debug_descriptor.trace_size[i]);
uint32_t pir = be16_to_cpu(debug_descriptor.trace_pir[i]);

prop[i * 2] = cpu_to_fdt64(addr);
prop[i * 2 + 1] = cpu_to_fdt64(size);
Expand All @@ -199,18 +199,18 @@ static void trace_add_dt_props(void)

static void trace_add_desc(struct trace_info *t, uint64_t size, uint16_t pir)
{
unsigned int i = debug_descriptor.num_traces;
unsigned int i = be32_to_cpu(debug_descriptor.num_traces);

if (i >= DEBUG_DESC_MAX_TRACES) {
prerror("TRACE: Debug descriptor trace list full !\n");
return;
}
debug_descriptor.num_traces++;

debug_descriptor.trace_phys[i] = (uint64_t)t;
debug_descriptor.num_traces = cpu_to_be32(i + 1);
debug_descriptor.trace_phys[i] = cpu_to_be64((uint64_t)t);
debug_descriptor.trace_tce[i] = 0; /* populated later */
debug_descriptor.trace_size[i] = size;
debug_descriptor.trace_pir[i] = pir;
debug_descriptor.trace_size[i] = cpu_to_be32(size);
debug_descriptor.trace_pir[i] = cpu_to_be16(pir);
}

/* Allocate trace buffers once we know memory topology */
Expand Down
26 changes: 13 additions & 13 deletions include/debug_descriptor.h
Expand Up @@ -11,27 +11,27 @@
struct debug_descriptor {
u8 eye_catcher[8]; /* "OPALdbug" */
#define DEBUG_DESC_VERSION 1
u32 version;
__be32 version;
u8 console_log_levels; /* high 4 bits in memory,
* low 4 bits driver (e.g. uart). */
u8 state_flags; /* various state flags - OPAL_BOOT_COMPLETE etc */
u16 reserved2;
u32 reserved[2];
__be16 reserved2;
__be32 reserved[2];

/* Memory console */
u64 memcons_phys;
u32 memcons_tce;
u32 memcons_obuf_tce;
u32 memcons_ibuf_tce;
__be64 memcons_phys;
__be32 memcons_tce;
__be32 memcons_obuf_tce;
__be32 memcons_ibuf_tce;

/* Traces */
u64 trace_mask;
u32 num_traces;
__be64 trace_mask;
__be32 num_traces;
#define DEBUG_DESC_MAX_TRACES 256
u64 trace_phys[DEBUG_DESC_MAX_TRACES];
u32 trace_size[DEBUG_DESC_MAX_TRACES];
u32 trace_tce[DEBUG_DESC_MAX_TRACES];
u16 trace_pir[DEBUG_DESC_MAX_TRACES];
__be64 trace_phys[DEBUG_DESC_MAX_TRACES];
__be32 trace_size[DEBUG_DESC_MAX_TRACES];
__be32 trace_tce[DEBUG_DESC_MAX_TRACES];
__be16 trace_pir[DEBUG_DESC_MAX_TRACES];
};
extern struct debug_descriptor debug_descriptor;

Expand Down
19 changes: 10 additions & 9 deletions platforms/ibm-fsp/common.c
Expand Up @@ -24,14 +24,14 @@ static void map_debug_areas(void)
fsp_tce_map(PSI_DMA_MEMCONS, &memcons, 0x1000);
fsp_tce_map(PSI_DMA_LOG_BUF, (void*)INMEM_CON_START, INMEM_CON_LEN);

debug_descriptor.memcons_tce = PSI_DMA_MEMCONS;
debug_descriptor.memcons_tce = cpu_to_be32(PSI_DMA_MEMCONS);
t = be64_to_cpu(memcons.obuf_phys) - INMEM_CON_START + PSI_DMA_LOG_BUF;
debug_descriptor.memcons_obuf_tce = t;
debug_descriptor.memcons_obuf_tce = cpu_to_be32(t);
t = be64_to_cpu(memcons.ibuf_phys) - INMEM_CON_START + PSI_DMA_LOG_BUF;
debug_descriptor.memcons_ibuf_tce = t;
debug_descriptor.memcons_ibuf_tce = cpu_to_be32(t);

t = PSI_DMA_TRACE_BASE;
for (i = 0; i < debug_descriptor.num_traces; i++) {
for (i = 0; i < be32_to_cpu(debug_descriptor.num_traces); i++) {
/*
* Trace buffers are misaligned by 0x10 due to the lock
* in the trace structure, and their size is also not
Expand All @@ -46,15 +46,16 @@ static void map_debug_areas(void)
* Note: Maybe we should map them read-only...
*/
uint64_t tstart, tend, toff, tsize;
uint64_t trace_phys = be64_to_cpu(debug_descriptor.trace_phys[i]);
uint32_t trace_size = be32_to_cpu(debug_descriptor.trace_size[i]);

tstart = ALIGN_DOWN(debug_descriptor.trace_phys[i], 0x1000);
tend = ALIGN_UP(debug_descriptor.trace_phys[i] +
debug_descriptor.trace_size[i], 0x1000);
toff = debug_descriptor.trace_phys[i] - tstart;
tstart = ALIGN_DOWN(trace_phys, 0x1000);
tend = ALIGN_UP(trace_phys + trace_size, 0x1000);
toff = trace_phys - tstart;
tsize = tend - tstart;

fsp_tce_map(t, (void *)tstart, tsize);
debug_descriptor.trace_tce[i] = t + toff;
debug_descriptor.trace_tce[i] = cpu_to_be32(t + toff);
t += tsize;
}
}
Expand Down

0 comments on commit 1959efa

Please sign in to comment.