bcm2835_mbox/property: replace ldl_phys/stl_phys with endian-specific accesses

PMM pointed out that ldl_phys and stl_phys are dependent on the CPU's
endianness, whereas device model code should be independent of
it. This changes the relevant Raspberry Pi devices to explicitly call
the little-endian variants.

Signed-off-by: Andrew Baumann <Andrew.Baumann@microsoft.com>
Message-id: 1456880233-22568-1-git-send-email-Andrew.Baumann@microsoft.com
Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
Andrew Baumann 2016-03-04 11:30:18 +00:00 committed by Peter Maydell
parent 4824a61a6d
commit eab713941a
2 changed files with 22 additions and 22 deletions

View File

@ -98,7 +98,7 @@ static void bcm2835_mbox_update(BCM2835MboxState *s)
*/ */
for (n = 0; n < MBOX_CHAN_COUNT; n++) { for (n = 0; n < MBOX_CHAN_COUNT; n++) {
while (s->available[n] && !(s->mbox[0].status & ARM_MS_FULL)) { while (s->available[n] && !(s->mbox[0].status & ARM_MS_FULL)) {
value = ldl_phys(&s->mbox_as, n << MBOX_AS_CHAN_SHIFT); value = ldl_le_phys(&s->mbox_as, n << MBOX_AS_CHAN_SHIFT);
assert(value != MBOX_INVALID_DATA); /* Pending interrupt but no data */ assert(value != MBOX_INVALID_DATA); /* Pending interrupt but no data */
mbox_push(&s->mbox[0], value); mbox_push(&s->mbox[0], value);
} }
@ -207,12 +207,12 @@ static void bcm2835_mbox_write(void *opaque, hwaddr offset,
ch = value & 0xf; ch = value & 0xf;
if (ch < MBOX_CHAN_COUNT) { if (ch < MBOX_CHAN_COUNT) {
childaddr = ch << MBOX_AS_CHAN_SHIFT; childaddr = ch << MBOX_AS_CHAN_SHIFT;
if (ldl_phys(&s->mbox_as, childaddr + MBOX_AS_PENDING)) { if (ldl_le_phys(&s->mbox_as, childaddr + MBOX_AS_PENDING)) {
/* Child busy, push delayed. Push it in the arm->vc mbox */ /* Child busy, push delayed. Push it in the arm->vc mbox */
mbox_push(&s->mbox[1], value); mbox_push(&s->mbox[1], value);
} else { } else {
/* Push it directly to the child device */ /* Push it directly to the child device */
stl_phys(&s->mbox_as, childaddr, value); stl_le_phys(&s->mbox_as, childaddr, value);
} }
} else { } else {
/* Invalid channel number */ /* Invalid channel number */

View File

@ -22,20 +22,20 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
s->addr = value; s->addr = value;
tot_len = ldl_phys(&s->dma_as, value); tot_len = ldl_le_phys(&s->dma_as, value);
/* @(addr + 4) : Buffer response code */ /* @(addr + 4) : Buffer response code */
value = s->addr + 8; value = s->addr + 8;
while (value + 8 <= s->addr + tot_len) { while (value + 8 <= s->addr + tot_len) {
tag = ldl_phys(&s->dma_as, value); tag = ldl_le_phys(&s->dma_as, value);
bufsize = ldl_phys(&s->dma_as, value + 4); bufsize = ldl_le_phys(&s->dma_as, value + 4);
/* @(value + 8) : Request/response indicator */ /* @(value + 8) : Request/response indicator */
resplen = 0; resplen = 0;
switch (tag) { switch (tag) {
case 0x00000000: /* End tag */ case 0x00000000: /* End tag */
break; break;
case 0x00000001: /* Get firmware revision */ case 0x00000001: /* Get firmware revision */
stl_phys(&s->dma_as, value + 12, 346337); stl_le_phys(&s->dma_as, value + 12, 346337);
resplen = 4; resplen = 4;
break; break;
case 0x00010001: /* Get board model */ case 0x00010001: /* Get board model */
@ -44,7 +44,7 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
resplen = 4; resplen = 4;
break; break;
case 0x00010002: /* Get board revision */ case 0x00010002: /* Get board revision */
stl_phys(&s->dma_as, value + 12, s->board_rev); stl_le_phys(&s->dma_as, value + 12, s->board_rev);
resplen = 4; resplen = 4;
break; break;
case 0x00010003: /* Get board MAC address */ case 0x00010003: /* Get board MAC address */
@ -58,24 +58,24 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
break; break;
case 0x00010005: /* Get ARM memory */ case 0x00010005: /* Get ARM memory */
/* base */ /* base */
stl_phys(&s->dma_as, value + 12, 0); stl_le_phys(&s->dma_as, value + 12, 0);
/* size */ /* size */
stl_phys(&s->dma_as, value + 16, s->ram_size); stl_le_phys(&s->dma_as, value + 16, s->ram_size);
resplen = 8; resplen = 8;
break; break;
case 0x00028001: /* Set power state */ case 0x00028001: /* Set power state */
/* Assume that whatever device they asked for exists, /* Assume that whatever device they asked for exists,
* and we'll just claim we set it to the desired state * and we'll just claim we set it to the desired state
*/ */
tmp = ldl_phys(&s->dma_as, value + 16); tmp = ldl_le_phys(&s->dma_as, value + 16);
stl_phys(&s->dma_as, value + 16, (tmp & 1)); stl_le_phys(&s->dma_as, value + 16, (tmp & 1));
resplen = 8; resplen = 8;
break; break;
/* Clocks */ /* Clocks */
case 0x00030001: /* Get clock state */ case 0x00030001: /* Get clock state */
stl_phys(&s->dma_as, value + 16, 0x1); stl_le_phys(&s->dma_as, value + 16, 0x1);
resplen = 8; resplen = 8;
break; break;
@ -88,15 +88,15 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
case 0x00030002: /* Get clock rate */ case 0x00030002: /* Get clock rate */
case 0x00030004: /* Get max clock rate */ case 0x00030004: /* Get max clock rate */
case 0x00030007: /* Get min clock rate */ case 0x00030007: /* Get min clock rate */
switch (ldl_phys(&s->dma_as, value + 12)) { switch (ldl_le_phys(&s->dma_as, value + 12)) {
case 1: /* EMMC */ case 1: /* EMMC */
stl_phys(&s->dma_as, value + 16, 50000000); stl_le_phys(&s->dma_as, value + 16, 50000000);
break; break;
case 2: /* UART */ case 2: /* UART */
stl_phys(&s->dma_as, value + 16, 3000000); stl_le_phys(&s->dma_as, value + 16, 3000000);
break; break;
default: default:
stl_phys(&s->dma_as, value + 16, 700000000); stl_le_phys(&s->dma_as, value + 16, 700000000);
break; break;
} }
resplen = 8; resplen = 8;
@ -113,19 +113,19 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
/* Temperature */ /* Temperature */
case 0x00030006: /* Get temperature */ case 0x00030006: /* Get temperature */
stl_phys(&s->dma_as, value + 16, 25000); stl_le_phys(&s->dma_as, value + 16, 25000);
resplen = 8; resplen = 8;
break; break;
case 0x0003000A: /* Get max temperature */ case 0x0003000A: /* Get max temperature */
stl_phys(&s->dma_as, value + 16, 99000); stl_le_phys(&s->dma_as, value + 16, 99000);
resplen = 8; resplen = 8;
break; break;
case 0x00060001: /* Get DMA channels */ case 0x00060001: /* Get DMA channels */
/* channels 2-5 */ /* channels 2-5 */
stl_phys(&s->dma_as, value + 12, 0x003C); stl_le_phys(&s->dma_as, value + 12, 0x003C);
resplen = 4; resplen = 4;
break; break;
@ -143,12 +143,12 @@ static void bcm2835_property_mbox_push(BCM2835PropertyState *s, uint32_t value)
break; break;
} }
stl_phys(&s->dma_as, value + 8, (1 << 31) | resplen); stl_le_phys(&s->dma_as, value + 8, (1 << 31) | resplen);
value += bufsize + 12; value += bufsize + 12;
} }
/* Buffer response code */ /* Buffer response code */
stl_phys(&s->dma_as, s->addr + 4, (1 << 31)); stl_le_phys(&s->dma_as, s->addr + 4, (1 << 31));
} }
static uint64_t bcm2835_property_read(void *opaque, hwaddr offset, static uint64_t bcm2835_property_read(void *opaque, hwaddr offset,