Skip to content

Commit a8441f6

Browse files
jlu5jgarff
authored andcommitted
Fixes for arm64 support (jgarff#316)
* Fix compilation on arm64 (jgarff#173, jgarff#289) * Read CPU revision from /proc/device-tree on arm64 (closes jgarff#289) * rpihw: move declarations to the top of rpi_hw_detect()
1 parent a954ab4 commit a8441f6

File tree

3 files changed

+34
-8
lines changed

3 files changed

+34
-8
lines changed

mailbox.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ void *mapmem(uint32_t base, uint32_t size, const char *mem_dev) {
6868

6969
void *unmapmem(void *addr, uint32_t size) {
7070
uint32_t pagemask = ~0UL ^ (getpagesize() - 1);
71-
uint32_t baseaddr = (uint32_t)addr & pagemask;
71+
uintptr_t baseaddr = (uintptr_t)addr & pagemask;
7272
int s;
7373

7474
s = munmap((void *)baseaddr, size);

rpihw.c

Lines changed: 31 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <string.h>
3434
#include <stdlib.h>
3535
#include <errno.h>
36+
#include <byteswap.h>
3637

3738
#include "rpihw.h"
3839

@@ -324,9 +325,36 @@ static const rpi_hw_t rpi_hw_info[] = {
324325

325326
const rpi_hw_t *rpi_hw_detect(void)
326327
{
328+
const rpi_hw_t *result = NULL;
329+
uint32_t rev;
330+
unsigned i;
331+
332+
#ifdef __aarch64__
333+
// On ARM64, read revision from /proc/device-tree as it is not shown in
334+
// /proc/cpuinfo
335+
FILE *f = fopen("/proc/device-tree/system/linux,revision", "r");
336+
if (!f)
337+
{
338+
return NULL;
339+
}
340+
fread(&rev, sizeof(uint32_t), 1, f);
341+
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
342+
rev = bswap_32(rev); // linux,revision appears to be in big endian
343+
#endif
344+
345+
for (i = 0; i < (sizeof(rpi_hw_info) / sizeof(rpi_hw_info[0])); i++)
346+
{
347+
uint32_t hwver = rpi_hw_info[i].hwver;
348+
if (rev == hwver)
349+
{
350+
result = &rpi_hw_info[i];
351+
352+
goto done;
353+
}
354+
}
355+
#else
327356
FILE *f = fopen("/proc/cpuinfo", "r");
328357
char line[LINE_WIDTH_MAX];
329-
const rpi_hw_t *result = NULL;
330358

331359
if (!f)
332360
{
@@ -337,9 +365,7 @@ const rpi_hw_t *rpi_hw_detect(void)
337365
{
338366
if (strstr(line, HW_VER_STRING))
339367
{
340-
uint32_t rev;
341368
char *substr;
342-
unsigned i;
343369

344370
substr = strstr(line, ": ");
345371
if (!substr)
@@ -361,7 +387,7 @@ const rpi_hw_t *rpi_hw_detect(void)
361387
// Take out warranty and manufacturer bits
362388
hwver &= ~(RPI_WARRANTY_MASK | RPI_MANUFACTURER_MASK);
363389
rev &= ~(RPI_WARRANTY_MASK | RPI_MANUFACTURER_MASK);
364-
390+
365391
if (rev == hwver)
366392
{
367393
result = &rpi_hw_info[i];
@@ -371,7 +397,7 @@ const rpi_hw_t *rpi_hw_detect(void)
371397
}
372398
}
373399
}
374-
400+
#endif
375401
done:
376402
fclose(f);
377403

ws2811.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,7 @@ static int setup_pwm(ws2811_t *ws2811)
392392

393393
dma_cb->source_ad = addr_to_bus(device, device->pxl_raw);
394394

395-
dma_cb->dest_ad = (uint32_t)&((pwm_t *)PWM_PERIPH_PHYS)->fif1;
395+
dma_cb->dest_ad = (uintptr_t)&((pwm_t *)PWM_PERIPH_PHYS)->fif1;
396396
dma_cb->txfr_len = byte_count;
397397
dma_cb->stride = 0;
398398
dma_cb->nextconbk = 0;
@@ -457,7 +457,7 @@ static int setup_pcm(ws2811_t *ws2811)
457457
RPI_DMA_TI_SRC_INC; // Increment src addr
458458

459459
dma_cb->source_ad = addr_to_bus(device, device->pxl_raw);
460-
dma_cb->dest_ad = (uint32_t)&((pcm_t *)PCM_PERIPH_PHYS)->fifo;
460+
dma_cb->dest_ad = (uintptr_t)&((pcm_t *)PCM_PERIPH_PHYS)->fifo;
461461
dma_cb->txfr_len = byte_count;
462462
dma_cb->stride = 0;
463463
dma_cb->nextconbk = 0;

0 commit comments

Comments
 (0)