Skip to content

Commit

Permalink
memconsole: make endian-clean
Browse files Browse the repository at this point in the history
Convert memconsole dt construction and in-memory tables to use
explicit endian conversions.

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 61800f2 commit 45c1436
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 27 deletions.
22 changes: 11 additions & 11 deletions core/console.c
Expand Up @@ -30,11 +30,11 @@ static struct lock con_lock = LOCK_UNLOCKED;

/* This is mapped via TCEs so we keep it alone in a page */
struct memcons memcons __section(".data.memcons") = {
.magic = MEMCONS_MAGIC,
.obuf_phys = INMEM_CON_START,
.ibuf_phys = INMEM_CON_START + INMEM_CON_OUT_LEN,
.obuf_size = INMEM_CON_OUT_LEN,
.ibuf_size = INMEM_CON_IN_LEN,
.magic = CPU_TO_BE64(MEMCONS_MAGIC),
.obuf_phys = CPU_TO_BE64(INMEM_CON_START),
.ibuf_phys = CPU_TO_BE64(INMEM_CON_START + INMEM_CON_OUT_LEN),
.obuf_size = CPU_TO_BE32(INMEM_CON_OUT_LEN),
.ibuf_size = CPU_TO_BE32(INMEM_CON_IN_LEN),
};

static bool dummy_console_enabled(void)
Expand Down Expand Up @@ -197,7 +197,7 @@ static void inmem_write(char c)
if (con_wrapped)
opos |= MEMCONS_OUT_POS_WRAP;
lwsync();
memcons.out_pos = opos;
memcons.out_pos = cpu_to_be32(opos);

/* If head reaches tail, push tail around & drop chars */
if (con_in == con_out)
Expand All @@ -207,12 +207,12 @@ static void inmem_write(char c)
static size_t inmem_read(char *buf, size_t req)
{
size_t read = 0;
char *ibuf = (char *)memcons.ibuf_phys;
char *ibuf = (char *)be64_to_cpu(memcons.ibuf_phys);

while (req && memcons.in_prod != memcons.in_cons) {
*(buf++) = ibuf[memcons.in_cons];
while (req && be32_to_cpu(memcons.in_prod) != be32_to_cpu(memcons.in_cons)) {
*(buf++) = ibuf[be32_to_cpu(memcons.in_cons)];
lwsync();
memcons.in_cons = (memcons.in_cons + 1) % INMEM_CON_IN_LEN;
memcons.in_cons = cpu_to_be32((be32_to_cpu(memcons.in_cons) + 1) % INMEM_CON_IN_LEN);
req--;
read++;
}
Expand Down Expand Up @@ -428,7 +428,7 @@ void dummy_console_add_nodes(void)
{
struct dt_property *p;

add_opal_console_node(0, "raw", memcons.obuf_size);
add_opal_console_node(0, "raw", be32_to_cpu(memcons.obuf_size));

/* Mambo might have left a crap one, clear it */
p = __dt_find_property(dt_chosen, "linux,stdout-path");
Expand Down
16 changes: 8 additions & 8 deletions include/console.h
Expand Up @@ -14,17 +14,17 @@
* (This is v3 of the format, the previous one sucked)
*/
struct memcons {
uint64_t magic;
__be64 magic;
#define MEMCONS_MAGIC 0x6630696567726173LL
uint64_t obuf_phys;
uint64_t ibuf_phys;
uint32_t obuf_size;
uint32_t ibuf_size;
uint32_t out_pos;
__be64 obuf_phys;
__be64 ibuf_phys;
__be32 obuf_size;
__be32 ibuf_size;
__be32 out_pos;
#define MEMCONS_OUT_POS_WRAP 0x80000000u
#define MEMCONS_OUT_POS_MASK 0x00ffffffu
uint32_t in_prod;
uint32_t in_cons;
__be32 in_prod;
__be32 in_cons;
};

extern struct memcons memcons;
Expand Down
4 changes: 2 additions & 2 deletions platforms/ibm-fsp/common.c
Expand Up @@ -25,9 +25,9 @@ static void map_debug_areas(void)
fsp_tce_map(PSI_DMA_LOG_BUF, (void*)INMEM_CON_START, INMEM_CON_LEN);

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

t = PSI_DMA_TRACE_BASE;
Expand Down
12 changes: 6 additions & 6 deletions platforms/ibm-fsp/hostservices.c
Expand Up @@ -178,11 +178,11 @@ static bool hbrt_con_wrapped;
#define HBRT_CON_OUT_LEN (HBRT_CON_LEN - HBRT_CON_IN_LEN)

static struct memcons hbrt_memcons __section(".data.memcons") = {
.magic = MEMCONS_MAGIC,
.obuf_phys = HBRT_CON_START,
.ibuf_phys = HBRT_CON_START + HBRT_CON_OUT_LEN,
.obuf_size = HBRT_CON_OUT_LEN,
.ibuf_size = HBRT_CON_IN_LEN,
.magic = CPU_TO_BE64(MEMCONS_MAGIC),
.obuf_phys = CPU_TO_BE64(HBRT_CON_START),
.ibuf_phys = CPU_TO_BE64(HBRT_CON_START + HBRT_CON_OUT_LEN),
.obuf_size = CPU_TO_BE32(HBRT_CON_OUT_LEN),
.ibuf_size = CPU_TO_BE32(HBRT_CON_IN_LEN),
};

static void hservice_putc(char c)
Expand All @@ -206,7 +206,7 @@ static void hservice_putc(char c)
if (hbrt_con_wrapped)
opos |= MEMCONS_OUT_POS_WRAP;
lwsync();
hbrt_memcons.out_pos = opos;
hbrt_memcons.out_pos = cpu_to_be32(opos);
}

static void hservice_puts(const char *str)
Expand Down

0 comments on commit 45c1436

Please sign in to comment.