[Skiboot] [PATCH v10 17/31] debug descriptor: make endian-clean
Nicholas Piggin
npiggin at gmail.com
Sun Dec 8 23:22:58 AEDT 2019
Signed-off-by: Nicholas Piggin <npiggin at gmail.com>
---
core/init.c | 9 +++++++--
core/trace.c | 22 +++++++++++-----------
include/debug_descriptor.h | 26 +++++++++++++-------------
platforms/ibm-fsp/common.c | 19 ++++++++++---------
4 files changed, 41 insertions(+), 35 deletions(-)
diff --git a/core/init.c b/core/init.c
index d90695c16..b7bf2e50c 100644
--- a/core/init.c
+++ b/core/init.c
@@ -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). */
@@ -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
diff --git a/core/trace.c b/core/trace.c
index 5388972f3..5c71370fd 100644
--- a/core/trace.c
+++ b/core/trace.c
@@ -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());
@@ -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);
@@ -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 */
diff --git a/include/debug_descriptor.h b/include/debug_descriptor.h
index 774c3607d..cbe9293e3 100644
--- a/include/debug_descriptor.h
+++ b/include/debug_descriptor.h
@@ -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;
diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c
index 48b9fd884..c288bff36 100644
--- a/platforms/ibm-fsp/common.c
+++ b/platforms/ibm-fsp/common.c
@@ -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
@@ -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;
}
}
--
2.23.0
More information about the Skiboot
mailing list