Date: Wed, 2 Feb 2022 12:23:36 +0000 From: Marco Devesas Campos <devesas.campos@gmail.com> To: freebsd-arm@freebsd.org Subject: [PATCH] Experimental vchiq and bcm2835_audio support for arm64 Message-ID: <A0775CDC-7382-4A15-8131-482572032308@gmail.com>
next in thread | raw e-mail | index | archive | help
Hi List, Below is a very experimental patch, against stable/13, that brings = bcm2835_audio to the 64bit era -- and with it, the vchiq driver (only to = the extent required by audio -- no promises anything will work beyond = that). There's work and more testing to be done (again, it=E2=80=99s = experimental) but it seems to work quite nicely on my system so I = thought I'd post it here so that (1) people could test it out -- only tried it in an rpi-zero2 and I'd = been keen to hear from people with access to rpis-3; and (2) I could hear from people with actual experience in writing = drivers, since this this is my first foray into kernel and arm = programming, on possible issues with the code. One particular concern is = that call to arm64_dcache_wbinv_range in the code that does DMA.=20 To compile, just add `device vchiq` to your kernel config or use the = GENERIC-VCHIQ config file included in the patch. (If you want any shot = at building it on an rpi without swap, read the comments there) Best, Marco diff --git a/sys/arm/broadcom/bcm2835/bcm2835_audio.c = b/sys/arm/broadcom/bcm2835/bcm2835_audio.c index ae2c9a14fc62..5cd3f4bfd804 100644 --- a/sys/arm/broadcom/bcm2835/bcm2835_audio.c +++ b/sys/arm/broadcom/bcm2835/bcm2835_audio.c @@ -27,6 +27,10 @@ #include "opt_snd.h" #endif =20 +/* + For the PRIu64 identifier +*/ +#include <machine/_inttypes.h> #include <dev/sound/pcm/sound.h> #include <dev/sound/chip.h> =20 @@ -116,6 +120,12 @@ struct bcm2835_audio_chinfo { uint64_t retrieved_samples; uint64_t underruns; int starved; + struct bcm_log_vars { + unsigned int bsize ; + int slept_for_lack_of_space ; + } log_vars; +#define DEFAULT_LOG_VALUES \ + ((struct bcm_log_vars) { .bsize =3D 0 , .slept_for_lack_of_space = =3D 0 }) }; =20 struct bcm2835_audio_info { @@ -135,6 +145,7 @@ struct bcm2835_audio_info { =20 uint32_t flags_pending; =20 + int verbose_trace; /* Worker thread state */ int worker_state; }; @@ -143,6 +154,35 @@ struct bcm2835_audio_info { #define BCM2835_AUDIO_LOCKED(sc) mtx_assert(&(sc)->lock, = MA_OWNED) #define BCM2835_AUDIO_UNLOCK(sc) mtx_unlock(&(sc)->lock) =20 +/* things that really have to be reported */ +#define REPORT_ERROR(sc,...) \ + do{ device_printf((sc)->dev,__VA_ARGS__); }while(0) +/* things that shouldn't clobber the output */ +#define INFORM_THAT(sc,...) \ + do { \ + if(sc->verbose_trace>0){ \ + device_printf((sc)->dev,__VA_ARGS__); \ + } \ + }while(0) +/* things that might clobber the output */ +#define WARN_THAT(sc,...) \ + do { \ + if(sc->verbose_trace>1){ \ + device_printf((sc)->dev,__VA_ARGS__); \ + } \ + }while(0) +/* things that are expected to (will) clobber the output */ +#define TRACE(sc,...) \ + do { \ + if(sc->verbose_trace>2){ \ + device_printf((sc)->dev,__VA_ARGS__); \ + } \ + }while(0) + +/* Useful for circular buffer calcs */ +#define MOD_DIFF(front,rear,mod) (((mod) + (front) - (rear)) % mod) + + static const char * dest_description(uint32_t dest) { @@ -214,10 +254,21 @@ bcm2835_audio_callback(void *param, const = VCHI_CALLBACK_REASON_T reason, void *m m.type); } } else if (m.type =3D=3D VC_AUDIO_MSG_TYPE_COMPLETE) { - struct bcm2835_audio_chinfo *ch =3D m.u.complete.cookie; + unsigned int signaled =3D 0; + struct bcm2835_audio_chinfo *ch ; +#if defined(__aarch64__) + ch =3D (void *) ((((size_t)m.u.complete.callback) << 32) + | ((size_t)m.u.complete.cookie)); +#else + ch =3D (void *) (m.u.complete.cookie); +#endif + =20 int count =3D m.u.complete.count & 0xffff; int perr =3D (m.u.complete.count & (1U << 30)) !=3D 0; + + TRACE(sc,"in:: count:0x%x = perr:%d\n",m.u.complete.count,perr); + ch->callbacks++; if (perr) ch->underruns++; @@ -237,18 +288,51 @@ bcm2835_audio_callback(void *param, const = VCHI_CALLBACK_REASON_T reason, void *m device_printf(sc->dev, = "available_space =3D=3D %d, count =3D %d, perr=3D%d\n", ch->available_space, count, = perr); device_printf(sc->dev, - "retrieved_samples =3D %lld, = submitted_samples =3D %lld\n", + "retrieved_samples =3D = %"PRIu64", submitted_samples =3D %"PRIu64"\n", ch->retrieved_samples, = ch->submitted_samples); } - ch->available_space +=3D count; - ch->retrieved_samples +=3D count; } - if (perr || (ch->available_space >=3D = VCHIQ_AUDIO_PACKET_SIZE)) + /* + EXPERIMENTAL + two lines were before that + close bracket [ed: ftb of the {} matcher] + */ + ch->available_space +=3D count; + ch->retrieved_samples +=3D count; + /* + EXPERIMENTAL + Experimental: if VC says it's empty, believe = it + Has to come after the usual adjustments + */ + if(perr){ + ch->available_space =3D = VCHIQ_AUDIO_BUFFER_SIZE; + perr =3D ch->retrieved_samples; // shd = be !=3D 0 + } + /* + EXPERIMENTAL + Throttle things a bit, so as to not + tire VC out (TBR) + */ + =20 + if ((ch->available_space >=3D = 2*VCHIQ_AUDIO_PACKET_SIZE)){ cv_signal(&sc->worker_cv); + signaled =3D 1; + } } BCM2835_AUDIO_UNLOCK(sc); + if(perr){ + WARN_THAT(sc, + "VC starved; reported %u for a total of = %u\n" + "worker %s\n" , + count,perr, + (signaled ? "signaled": "not signaled") + ); + } } else - printf("%s: unknown m.type: %d\n", __func__, m.type); + WARN_THAT(sc, + "%s: unknown m.type: %d\n", + __func__, m.type + ); } =20 /* VCHIQ stuff */ @@ -260,13 +344,13 @@ bcm2835_audio_init(struct bcm2835_audio_info *sc) /* Initialize and create a VCHI connection */ status =3D vchi_initialise(&sc->vchi_instance); if (status !=3D 0) { - printf("vchi_initialise failed: %d\n", status); + REPORT_ERROR(sc,"vchi_initialise failed: %d\n", status); return; } =20 status =3D vchi_connect(NULL, 0, sc->vchi_instance); if (status !=3D 0) { - printf("vchi_connect failed: %d\n", status); + REPORT_ERROR(sc,"vchi_connect failed: %d\n", status); return; } =20 @@ -298,7 +382,7 @@ bcm2835_audio_release(struct bcm2835_audio_info *sc) if (sc->vchi_handle !=3D VCHIQ_SERVICE_HANDLE_INVALID) { success =3D vchi_service_close(sc->vchi_handle); if (success !=3D 0) - printf("vchi_service_close failed: %d\n", = success); + REPORT_ERROR(sc,"vchi_service_close failed: = %d\n", success); vchi_service_release(sc->vchi_handle); sc->vchi_handle =3D VCHIQ_SERVICE_HANDLE_INVALID; } @@ -328,7 +412,10 @@ bcm2835_audio_start(struct bcm2835_audio_chinfo = *ch) &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); =20 if (ret !=3D 0) - printf("%s: vchi_msg_queue failed (err %d)\n", = __func__, ret); + REPORT_ERROR(sc, + "%s: vchi_msg_queue failed (err %d)\n", + __func__, ret + ); } } =20 @@ -343,11 +430,15 @@ bcm2835_audio_stop(struct bcm2835_audio_chinfo = *ch) m.type =3D VC_AUDIO_MSG_TYPE_STOP; m.u.stop.draining =3D 0; =20 + INFORM_THAT(sc,"sending stop\n"); ret =3D vchi_msg_queue(sc->vchi_handle, &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); =20 if (ret !=3D 0) - printf("%s: vchi_msg_queue failed (err %d)\n", = __func__, ret); + REPORT_ERROR(sc, + "%s: vchi_msg_queue failed (err %d)\n", + __func__, ret + ); } } =20 @@ -363,7 +454,10 @@ bcm2835_audio_open(struct bcm2835_audio_info *sc) &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); =20 if (ret !=3D 0) - printf("%s: vchi_msg_queue failed (err %d)\n", = __func__, ret); + REPORT_ERROR(sc, + "%s: vchi_msg_queue failed (err %d)\n", + __func__, ret + ); } } =20 @@ -385,7 +479,10 @@ bcm2835_audio_update_controls(struct = bcm2835_audio_info *sc, uint32_t volume, ui &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); =20 if (ret !=3D 0) - printf("%s: vchi_msg_queue failed (err %d)\n", = __func__, ret); + REPORT_ERROR(sc, + "%s: vchi_msg_queue failed (err %d)\n", + __func__, ret + ); } } =20 @@ -405,7 +502,10 @@ bcm2835_audio_update_params(struct = bcm2835_audio_info *sc, uint32_t fmt, uint32_ &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); =20 if (ret !=3D 0) - printf("%s: vchi_msg_queue failed (err %d)\n", = __func__, ret); + REPORT_ERROR(sc, + "%s: vchi_msg_queue failed (err %d)\n", + __func__, ret + ); } } =20 @@ -413,18 +513,26 @@ static bool bcm2835_audio_buffer_should_sleep(struct bcm2835_audio_chinfo *ch) { =20 + ch->log_vars.slept_for_lack_of_space =3D 0; if (ch->playback_state !=3D PLAYBACK_PLAYING) return (true); =20 /* Not enough data */ - if (sndbuf_getready(ch->buffer) < VCHIQ_AUDIO_PACKET_SIZE) { - printf("starve\n"); + /*=20 + EXPERIMENTAL + Take unsubmitted stuff into account + */ + if (sndbuf_getready(ch->buffer) + - = MOD_DIFF(ch->unsubmittedptr,sndbuf_getreadyptr(ch->buffer), + sndbuf_getsize(ch->buffer)) + < VCHIQ_AUDIO_PACKET_SIZE) { ch->starved++; return (true); } =20 /* Not enough free space */ if (ch->available_space < VCHIQ_AUDIO_PACKET_SIZE) { + ch->log_vars.slept_for_lack_of_space =3D 1; return (true); } =20 @@ -445,22 +553,27 @@ bcm2835_audio_write_samples(struct = bcm2835_audio_chinfo *ch, void *buf, uint32_t m.type =3D VC_AUDIO_MSG_TYPE_WRITE; m.u.write.count =3D count; m.u.write.max_packet =3D VCHIQ_AUDIO_PACKET_SIZE; - m.u.write.callback =3D NULL; - m.u.write.cookie =3D ch; +#if defined(__aarch64__) + m.u.write.callback =3D (uint32_t)(((size_t) ch) >> 32) & = 0xffffffff; + m.u.write.cookie =3D (uint32_t)(((size_t) ch) & 0xffffffff); +#else + m.u.write.callback =3D (uint32_t) NULL; + m.u.write.cookie =3D (uint32_t) ch; +#endif m.u.write.silence =3D 0; =20 ret =3D vchi_msg_queue(sc->vchi_handle, &m, sizeof m, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); =20 if (ret !=3D 0) - printf("%s: vchi_msg_queue failed (err %d)\n", __func__, = ret); + REPORT_ERROR(sc,"%s: vchi_msg_queue failed (err %d)\n", = __func__, ret); =20 while (count > 0) { int bytes =3D MIN((int)m.u.write.max_packet, = (int)count); ret =3D vchi_msg_queue(sc->vchi_handle, buf, bytes, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); if (ret !=3D 0) - printf("%s: vchi_msg_queue failed: %d\n", + REPORT_ERROR(sc,"%s: vchi_msg_queue failed: = %d\n", __func__, ret); buf =3D (char *)buf + bytes; count -=3D bytes; @@ -492,6 +605,10 @@ bcm2835_audio_worker(void *data) while ((sc->flags_pending =3D=3D 0) && bcm2835_audio_buffer_should_sleep(ch)) { cv_wait_sig(&sc->worker_cv, &sc->lock); + if((sc-> flags_pending =3D=3D 0) + && ch->log_vars.slept_for_lack_of_space) { + TRACE(sc,"slept for lack of space\n"); + } } flags =3D sc->flags_pending; /* Clear pending flags */ @@ -518,16 +635,32 @@ bcm2835_audio_worker(void *data) BCM2835_AUDIO_LOCK(sc); bcm2835_audio_reset_channel(&sc->pch); ch->playback_state =3D PLAYBACK_IDLE; + long sub_total =3D ch->submitted_samples; + long retd =3D ch->retrieved_samples; BCM2835_AUDIO_UNLOCK(sc); + INFORM_THAT(sc, + "stopped audio. submitted a total of %lu = " + "having been acked %lu\n", + sub_total, retd + ); continue; } =20 /* Requested to start playback */ if ((flags & AUDIO_PLAY) && (ch->playback_state =3D=3D PLAYBACK_IDLE)) { + INFORM_THAT(sc, + "starting audio\n" + ); + unsigned int bsize =3D = sndbuf_getsize(ch->buffer); BCM2835_AUDIO_LOCK(sc); ch->playback_state =3D PLAYBACK_PLAYING; + ch->log_vars.bsize =3D bsize; BCM2835_AUDIO_UNLOCK(sc); + INFORM_THAT(sc, + "buffer size is %u\n", + bsize + );=09 bcm2835_audio_start(ch); } =20 @@ -536,20 +669,75 @@ bcm2835_audio_worker(void *data) =20 if (sndbuf_getready(ch->buffer) =3D=3D 0) continue; + uint32_t i_count ;//, size, readyptr; =20 - count =3D sndbuf_getready(ch->buffer); + /* + EXPERIMENTAL + Take unsubmitted stuff into account + */ +/* + count =3D i_count =3D sndbuf_getready(ch->buffer) ; + readyptr =3D sndbuf_getreadyptr(ch->buffer); +*/ + count + =3D i_count + =3D sndbuf_getready(ch->buffer) + - MOD_DIFF(ch->unsubmittedptr, + sndbuf_getreadyptr(ch->buffer), + sndbuf_getsize(ch->buffer)); size =3D sndbuf_getsize(ch->buffer); - readyptr =3D sndbuf_getreadyptr(ch->buffer); + readyptr =3D ch->unsubmittedptr; =20 + int size_changed=3D0; + unsigned int available; BCM2835_AUDIO_LOCK(sc); - if (readyptr + count > size) + if(size !=3D ch->log_vars.bsize){ + ch->log_vars.bsize =3D size; + size_changed =3D 1; + } + available =3D ch->available_space; + /* + EXPERIMENTAL + On arm64, got into situations where=20 + readyptr was less than a packet away + from the end of the buffer, which led + to count being set to 0 and, inexorably, starvation. + Code below tries to take that into account. + The problem might have been fixed with some of the = other changes + that were made in the meantime, but for now this = works fine. + */ + if (readyptr + count > size){ count =3D size - readyptr; - count =3D min(count, ch->available_space); - count -=3D (count % VCHIQ_AUDIO_PACKET_SIZE); + } + //count =3D min(count, ch->available_space); + //count -=3D (count % VCHIQ_AUDIO_PACKET_SIZE); + if(count > ch->available_space){ + count =3D ch->available_space; + count -=3D (count % VCHIQ_AUDIO_PACKET_SIZE); + }else if (count > VCHIQ_AUDIO_PACKET_SIZE){ + count -=3D (count % VCHIQ_AUDIO_PACKET_SIZE); + }else if (size > count + readyptr) { + count =3D 0; + } BCM2835_AUDIO_UNLOCK(sc); - - if (count < VCHIQ_AUDIO_PACKET_SIZE) + if(count % VCHIQ_AUDIO_PACKET_SIZE !=3D 0){ + WARN_THAT(sc, + "count: %u initial count: %u " + "size: %u readyptr: %u available: %u" + "\n", + count,i_count,size,readyptr, available); + } + if(size_changed) INFORM_THAT(sc,"bsize changed to %u\n",size); + =09 + //if (count < VCHIQ_AUDIO_PACKET_SIZE){ + if (count =3D=3D 0){ + WARN_THAT(sc, + "not enough room for a packet: count = %d," + " i_count %d, rptr %d, size %d\n", + count, i_count, readyptr, size + ); continue; + } =20 buf =3D (uint8_t*)sndbuf_getbuf(ch->buffer) + readyptr; =20 @@ -558,8 +746,17 @@ bcm2835_audio_worker(void *data) ch->unsubmittedptr =3D (ch->unsubmittedptr + count) % = sndbuf_getsize(ch->buffer); ch->available_space -=3D count; ch->submitted_samples +=3D count; + long sub =3D count; + long sub_total =3D ch->submitted_samples; + long retd =3D ch->retrieved_samples; KASSERT(ch->available_space >=3D 0, = ("ch->available_space =3D=3D %d\n", ch->available_space)); BCM2835_AUDIO_UNLOCK(sc); + + TRACE(sc, + "submitted %lu for a total of %lu having been acked %lu; = " + "rptr %d, had %u available \n", + sub, sub_total, retd, readyptr, available); + } =20 BCM2835_AUDIO_LOCK(sc); @@ -578,7 +775,9 @@ bcm2835_audio_create_worker(struct = bcm2835_audio_info *sc) sc->worker_state =3D WORKER_RUNNING; if (kproc_create(bcm2835_audio_worker, (void*)sc, &newp, 0, 0, "bcm2835_audio_worker") !=3D 0) { - printf("failed to create bcm2835_audio_worker\n"); + REPORT_ERROR(sc, + "failed to create bcm2835_audio_worker\n" + ); } } =20 @@ -611,6 +810,8 @@ bcmchan_init(kobj_t obj, void *devinfo, struct = snd_dbuf *b, struct pcm_channel * return NULL; } =20 + ch->log_vars =3D DEFAULT_LOG_VALUES; + BCM2835_AUDIO_LOCK(sc); bcm2835_worker_update_params(sc); BCM2835_AUDIO_UNLOCK(sc); @@ -831,6 +1032,9 @@ vchi_audio_sysctl_init(struct bcm2835_audio_info = *sc) SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "starved", CTLFLAG_RD, &sc->pch.starved, sc->pch.starved, "number of starved = conditions"); + SYSCTL_ADD_INT(ctx, tree, OID_AUTO, "trace", + CTLFLAG_RW, &sc->verbose_trace, + sc->verbose_trace, "enable tracing of = transfers"); } =20 static void @@ -862,6 +1066,7 @@ bcm2835_audio_delayed_init(void *xsc) bcm2835_audio_open(sc); sc->volume =3D 75; sc->dest =3D DEST_AUTO; + sc->verbose_trace =3D 0; =20 if (mixer_init(sc->dev, &bcmmixer_class, sc)) { device_printf(sc->dev, "mixer_init failed\n"); diff --git a/sys/arm/broadcom/bcm2835/vc_vchi_audioserv_defs.h = b/sys/arm/broadcom/bcm2835/vc_vchi_audioserv_defs.h index 143c54385916..04292df1c261 100644 --- a/sys/arm/broadcom/bcm2835/vc_vchi_audioserv_defs.h +++ b/sys/arm/broadcom/bcm2835/vc_vchi_audioserv_defs.h @@ -114,8 +114,8 @@ typedef struct typedef struct { uint32_t count; /* in bytes */ - void *callback; - void *cookie; + uint32_t callback; + uint32_t cookie; uint16_t silence; uint16_t max_packet; } VC_AUDIO_WRITE_T; @@ -131,8 +131,8 @@ typedef struct typedef struct { int32_t count; /* Success value */ - void *callback; - void *cookie; + uint32_t callback; + uint32_t cookie; } VC_AUDIO_COMPLETE_T; =20 /* Message header for all messages in HOST->VC direction */ diff --git a/sys/arm64/conf/GENERIC-VCHIQ b/sys/arm64/conf/GENERIC-VCHIQ new file mode 100644 index 000000000000..422ed425894c --- /dev/null +++ b/sys/arm64/conf/GENERIC-VCHIQ @@ -0,0 +1,23 @@ +# +# GENERIC-VCHIQ +# +# Custom kernel for arm64 plus VCHIQ +# +# $FreeBSD$ + +#NO_UNIVERSE + +include GENERIC +ident GENERIC-VCHIQ + +device vchiq + +# If you want to have any chance of compiling this in a RPI Zero 2 +# uncomment the stuff below + +# nomakeoptions DEBUG +# nomakeoptions WITH_CTF +# nooptions DDB_CTF +# makeoptions MALLOC_PRODUCTION=3D1 + + diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c index 279aacd0880a..6d05b35006f0 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_2835_arm.c @@ -171,7 +171,7 @@ vchiq_platform_init(VCHIQ_STATE_T *state) goto failed_load; } =20 - WARN_ON(((int)g_slot_mem & (PAGE_SIZE - 1)) !=3D 0); + WARN_ON(((size_t)g_slot_mem & (PAGE_SIZE - 1)) !=3D 0); =20 vchiq_slot_zero =3D vchiq_init_slots(g_slot_mem, = g_slot_mem_size); if (!vchiq_slot_zero) { @@ -204,8 +204,8 @@ vchiq_platform_init(VCHIQ_STATE_T *state) bcm_mbox_write(BCM2835_MBOX_CHAN_VCHIQ, (unsigned = int)g_slot_phys); =20 vchiq_log_info(vchiq_arm_log_level, - "vchiq_init - done (slots %x, phys %x)", - (unsigned int)vchiq_slot_zero, g_slot_phys); + "vchiq_init - done (slots %zx, phys %zx)", + (size_t)vchiq_slot_zero, g_slot_phys); =20 vchiq_call_connected_callbacks(); =20 @@ -393,13 +393,15 @@ pagelist_page_free(vm_page_t pp) ** from increased speed as a result. */ =20 + + static int create_pagelist(char __user *buf, size_t count, unsigned short type, struct proc *p, BULKINFO_T *bi) { PAGELIST_T *pagelist; vm_page_t* pages; - unsigned long *addrs; + uint32_t *addrs; unsigned int num_pages, i; vm_offset_t offset; int pagelist_size; @@ -453,7 +455,7 @@ create_pagelist(char __user *buf, size_t count, = unsigned short type, } =20 vchiq_log_trace(vchiq_arm_log_level, - "create_pagelist - %x (%d bytes @%p)", (unsigned = int)pagelist, count, buf); + "create_pagelist - %zx (%zu bytes @%p)", = (size_t)pagelist, count, buf); =20 if (!pagelist) return -ENOMEM; @@ -523,8 +525,12 @@ create_pagelist(char __user *buf, size_t count, = unsigned short type, (fragments - g_fragments_base)/g_fragment_size; } =20 +#if defined(__aarch64__) + arm64_dcache_wbinv_range((vm_offset_t)buf,count); +#else pa =3D pmap_extract(PCPU_GET(curpmap), (vm_offset_t)buf); dcache_wbinv_poc((vm_offset_t)buf, pa, count); +#endif =20 bus_dmamap_sync(bi->pagelist_dma_tag, bi->pagelist_dma_map, = BUS_DMASYNC_PREWRITE); =20 @@ -550,7 +556,7 @@ free_pagelist(BULKINFO_T *bi, int actual) pagelist =3D bi->pagelist; =20 vchiq_log_trace(vchiq_arm_log_level, - "free_pagelist - %x, %d (%lu bytes @%p)", (unsigned = int)pagelist, actual, pagelist->length, bi->buf); + "free_pagelist - %zx, %d (%u bytes @%p)", = (size_t)pagelist, actual, pagelist->length, bi->buf); =20 num_pages =3D (pagelist->length + pagelist->offset + PAGE_SIZE - 1) / diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c index 763cd9ce9417..9c0ef541ab08 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_arm.c @@ -442,8 +442,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t = arg, int fflag, #define _IOC_TYPE(x) IOCGROUP(x) =20 vchiq_log_trace(vchiq_arm_log_level, - "vchiq_ioctl - instance %x, cmd %s, arg %p", - (unsigned int)instance, + "vchiq_ioctl - instance %zx, cmd %s, arg %p", + (size_t)instance, ((_IOC_TYPE(cmd) =3D=3D VCHIQ_IOC_MAGIC) && (_IOC_NR(cmd) <=3D VCHIQ_IOC_MAX)) ? ioctl_names[_IOC_NR(cmd)] : "<invalid>", arg); @@ -745,8 +745,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t = arg, int fflag, break; } vchiq_log_info(vchiq_arm_log_level, - "found bulk_waiter %x for pid %d", - (unsigned int)waiter, current->p_pid); + "found bulk_waiter %zx for pid %d", + (size_t)waiter, current->p_pid); args.userdata =3D &waiter->bulk_waiter; } status =3D vchiq_bulk_transfer @@ -776,8 +776,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t = arg, int fflag, list_add(&waiter->list, = &instance->bulk_waiter_list); = lmutex_unlock(&instance->bulk_waiter_list_mutex); vchiq_log_info(vchiq_arm_log_level, - "saved bulk_waiter %x for pid %d", - (unsigned int)waiter, current->p_pid); + "saved bulk_waiter %zx for pid %d", + (size_t)waiter, current->p_pid); =20 memcpy((void *) &(((VCHIQ_QUEUE_BULK_TRANSFER_T *) @@ -860,9 +860,9 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t = arg, int fflag, if (args.msgbufsize < msglen) { vchiq_log_error( = vchiq_arm_log_level, - "header %x: = msgbufsize" + "header %zx: = msgbufsize" " %x < msglen = %x", - (unsigned = int)header, + (size_t)header, args.msgbufsize, msglen); WARN(1, "invalid message = " @@ -1031,8 +1031,8 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t = arg, int fflag, ret =3D -EFAULT; } else { vchiq_log_error(vchiq_arm_log_level, - "header %x: bufsize %x < size %x", - (unsigned int)header, args.bufsize, + "header %zx: bufsize %x < size %x", + (size_t)header, args.bufsize, header->size); WARN(1, "invalid size\n"); ret =3D -EMSGSIZE; @@ -1093,7 +1093,7 @@ vchiq_ioctl(struct cdev *cdev, u_long cmd, caddr_t = arg, int fflag, } break; =20 case VCHIQ_IOC_LIB_VERSION: { - unsigned int lib_version =3D (unsigned int)arg; + size_t lib_version =3D (size_t)arg; =20 if (lib_version < VCHIQ_VERSION_MIN) ret =3D -EINVAL; @@ -1342,9 +1342,9 @@ vchiq_close(struct cdev *dev, int flags __unused, = int fmt __unused, list); list_del(pos); vchiq_log_info(vchiq_arm_log_level, - "bulk_waiter - cleaned up %x " + "bulk_waiter - cleaned up %zx " "for pid %d", - (unsigned int)waiter, = waiter->pid); + (size_t)waiter, waiter->pid); = _sema_destroy(&waiter->bulk_waiter.event); kfree(waiter); } @@ -1435,9 +1435,9 @@ vchiq_dump_platform_instances(void *dump_context) instance =3D service->instance; if (instance && !instance->mark) { len =3D snprintf(buf, sizeof(buf), - "Instance %x: pid %d,%s = completions " + "Instance %zx: pid %d,%s = completions " "%d/%d", - (unsigned int)instance, = instance->pid, + (size_t)instance, instance->pid, instance->connected ? " = connected, " : "", instance->completion_insert - @@ -1465,8 +1465,8 @@ vchiq_dump_platform_service_state(void = *dump_context, VCHIQ_SERVICE_T *service) char buf[80]; int len; =20 - len =3D snprintf(buf, sizeof(buf), " instance %x", - (unsigned int)service->instance); + len =3D snprintf(buf, sizeof(buf), " instance %zx", + (size_t)service->instance); =20 if ((service->base.callback =3D=3D service_callback) && user_service->is_vchi) { diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.c = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.c index 2e30dd7dc3de..ca848e6e9016 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.c @@ -31,6 +31,9 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ =20 +/* For the PRIu64 format identifier */ +#include <machine/_inttypes.h> + #include "vchiq_core.h" #include "vchiq_killable.h" =20 @@ -392,9 +395,9 @@ make_service_callback(VCHIQ_SERVICE_T *service, = VCHIQ_REASON_T reason, VCHIQ_HEADER_T *header, void *bulk_userdata) { VCHIQ_STATUS_T status; - vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %x, = %x)", + vchiq_log_trace(vchiq_core_log_level, "%d: callback:%d (%s, %tx, = %tx)", service->state->id, service->localport, = reason_names[reason], - (unsigned int)header, (unsigned int)bulk_userdata); + (size_t)header, (size_t)bulk_userdata); status =3D service->base.callback(reason, header, = service->handle, bulk_userdata); if (status =3D=3D VCHIQ_ERROR) { @@ -417,13 +420,15 @@ vchiq_set_conn_state(VCHIQ_STATE_T *state, = VCHIQ_CONNSTATE_T newstate) vchiq_platform_conn_state_changed(state, oldstate, newstate); } =20 +#define ACTUAL_EVENT_SEM_ADDR(ref,offset)\ + ((struct semaphore *)(((size_t) ref) + ((size_t) offset))) static inline void -remote_event_create(REMOTE_EVENT_T *event) +remote_event_create(VCHIQ_STATE_T *ref, REMOTE_EVENT_T *event) { event->armed =3D 0; /* Don't clear the 'fired' flag because it may already have been = set ** by the other side. */ - _sema_init(event->event, 0); + _sema_init(ACTUAL_EVENT_SEM_ADDR(ref,event->event), 0); } =20 __unused static inline void @@ -433,13 +438,18 @@ remote_event_destroy(REMOTE_EVENT_T *event) } =20 static inline int -remote_event_wait(REMOTE_EVENT_T *event) +remote_event_wait(VCHIQ_STATE_T *ref, REMOTE_EVENT_T *event) { if (!event->fired) { event->armed =3D 1; +#if defined(__aarch64__) + dsb(sy); +#else dsb(); +#endif + if (!event->fired) { - if (down_interruptible(event->event) !=3D 0) { + if = (down_interruptible(ACTUAL_EVENT_SEM_ADDR(ref,event->event)) !=3D 0) { event->armed =3D 0; return 0; } @@ -453,26 +463,30 @@ remote_event_wait(REMOTE_EVENT_T *event) } =20 static inline void -remote_event_signal_local(REMOTE_EVENT_T *event) +remote_event_signal_local(VCHIQ_STATE_T *ref, REMOTE_EVENT_T *event) { +/* + As per = https://github.com/raspberrypi/linux/commit/a50c4c9a65779ca835746b5fd79d3d= 5278afbdbe +*/ + event->fired =3D 1; event->armed =3D 0; - up(event->event); + up(ACTUAL_EVENT_SEM_ADDR(ref,event->event)); } =20 static inline void -remote_event_poll(REMOTE_EVENT_T *event) +remote_event_poll(VCHIQ_STATE_T *ref, REMOTE_EVENT_T *event) { if (event->fired && event->armed) - remote_event_signal_local(event); + remote_event_signal_local(ref,event); } =20 void remote_event_pollall(VCHIQ_STATE_T *state) { - remote_event_poll(&state->local->sync_trigger); - remote_event_poll(&state->local->sync_release); - remote_event_poll(&state->local->trigger); - remote_event_poll(&state->local->recycle); + remote_event_poll(state , &state->local->sync_trigger); + remote_event_poll(state , &state->local->sync_release); + remote_event_poll(state , &state->local->trigger); + remote_event_poll(state , &state->local->recycle); } =20 /* Round up message sizes so that any space at the end of a slot is = always big @@ -553,7 +567,7 @@ request_poll(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T = *service, int poll_type) wmb(); =20 /* ... and ensure the slot handler runs. */ - remote_event_signal_local(&state->local->trigger); + remote_event_signal_local(state, &state->local->trigger); } =20 /* Called from queue_message, by the slot handler and application = threads, @@ -640,8 +654,8 @@ process_free_queue(VCHIQ_STATE_T *state) =20 rmb(); =20 - vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=3D%x = %x %x", - state->id, slot_index, (unsigned int)data, + vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=3D%tx = %x %x", + state->id, slot_index, (size_t)data, local->slot_queue_recycle, = slot_queue_available); =20 /* Initialise the bitmask for services which have used = this @@ -675,13 +689,13 @@ process_free_queue(VCHIQ_STATE_T *state) = vchiq_log_error(vchiq_core_log_level, "service %d " "message_use_count=3D%d = " - "(header %x, msgid %x, " + "(header %tx, msgid %x, = " "header->msgid %x, " "header->size %x)", port, service_quota-> = message_use_count, - (unsigned int)header, = msgid, + (size_t)header, msgid, header->msgid, header->size); WARN(1, "invalid message use = count\n"); @@ -704,24 +718,24 @@ process_free_queue(VCHIQ_STATE_T *state) = up(&service_quota->quota_event); vchiq_log_trace( = vchiq_core_log_level, - "%d: pfq:%d = %x@%x - " + "%d: pfq:%d = %x@%tx - " "slot_use->%d", state->id, port, header->size, - (unsigned = int)header, + (size_t)header, count - 1); } else { vchiq_log_error( = vchiq_core_log_level, "service = %d " = "slot_use_count" - "=3D%d = (header %x" + "=3D%d = (header %tx" ", msgid = %x, " = "header->msgid" " %x, = header->" "size = %x)", port, count, - (unsigned = int)header, + (size_t)header, msgid, header->msgid, header->size); @@ -735,9 +749,9 @@ process_free_queue(VCHIQ_STATE_T *state) pos +=3D calc_stride(header->size); if (pos > VCHIQ_SLOT_SIZE) { vchiq_log_error(vchiq_core_log_level, - "pfq - pos %x: header %x, msgid = %x, " + "pfq - pos %x: header %tx, msgid = %x, " "header->msgid %x, header->size = %x", - pos, (unsigned int)header, = msgid, + pos, (size_t)header, msgid, header->msgid, header->size); WARN(1, "invalid slot position\n"); } @@ -885,17 +899,16 @@ queue_message(VCHIQ_STATE_T *state, = VCHIQ_SERVICE_T *service, int slot_use_count; =20 vchiq_log_info(vchiq_core_log_level, - "%d: qm %s@%x,%x (%d->%d)", + "%d: qm %s@%tx,%x (%d->%d)", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), - (unsigned int)header, size, + (size_t)header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); =20 BUG_ON(!service); BUG_ON((flags & (QMFLAGS_NO_MUTEX_LOCK | QMFLAGS_NO_MUTEX_UNLOCK)) !=3D 0); - for (i =3D 0, pos =3D 0; i < (unsigned int)count; pos +=3D elements[i++].size) if (elements[i].size) { @@ -951,9 +964,9 @@ queue_message(VCHIQ_STATE_T *state, VCHIQ_SERVICE_T = *service, VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size); } else { vchiq_log_info(vchiq_core_log_level, - "%d: qm %s@%x,%x (%d->%d)", state->id, + "%d: qm %s@%tx,%x (%d->%d)", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), - (unsigned int)header, size, + (size_t)header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); if (size !=3D 0) { @@ -1017,7 +1030,7 @@ queue_message_sync(VCHIQ_STATE_T *state, = VCHIQ_SERVICE_T *service, (lmutex_lock_interruptible(&state->sync_mutex) !=3D 0)) return VCHIQ_RETRY; =20 - remote_event_wait(&local->sync_release); + remote_event_wait(state, &local->sync_release); =20 rmb(); =20 @@ -1036,9 +1049,9 @@ queue_message_sync(VCHIQ_STATE_T *state, = VCHIQ_SERVICE_T *service, int i, pos; =20 vchiq_log_info(vchiq_sync_log_level, - "%d: qms %s@%x,%x (%d->%d)", state->id, + "%d: qms %s@%tx,%x (%d->%d)", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), - (unsigned int)header, size, + (size_t)header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); =20 @@ -1065,9 +1078,9 @@ queue_message_sync(VCHIQ_STATE_T *state, = VCHIQ_SERVICE_T *service, VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size); } else { vchiq_log_info(vchiq_sync_log_level, - "%d: qms %s@%x,%x (%d->%d)", state->id, + "%d: qms %s@%tx,%x (%d->%d)", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), - (unsigned int)header, size, + (size_t)header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); if (size !=3D 0) { @@ -1368,26 +1381,26 @@ resolve_bulks(VCHIQ_SERVICE_T *service, = VCHIQ_BULK_QUEUE_T *queue) "Send Bulk to" : "Recv Bulk from"; if (bulk->actual !=3D VCHIQ_BULK_ACTUAL_ABORTED) vchiq_log_info(SRVTRACE_LEVEL(service), - "%s %c%c%c%c d:%d len:%d = %x<->%x", + "%s %c%c%c%c d:%d len:%d = %tx<->%tx", header, VCHIQ_FOURCC_AS_4CHARS( service->base.fourcc), service->remoteport, bulk->size, - (unsigned int)bulk->data, - (unsigned = int)bulk->remote_data); + (size_t)bulk->data, + (size_t)bulk->remote_data); else vchiq_log_info(SRVTRACE_LEVEL(service), "%s %c%c%c%c d:%d ABORTED - tx = len:%d," - " rx len:%d %x<->%x", + " rx len:%d %tx<->%tx", header, VCHIQ_FOURCC_AS_4CHARS( service->base.fourcc), service->remoteport, bulk->size, bulk->remote_size, - (unsigned int)bulk->data, - (unsigned = int)bulk->remote_data); + (size_t)bulk->data, + (size_t)bulk->remote_data); } =20 vchiq_complete_bulk(bulk); @@ -1522,8 +1535,8 @@ parse_open(VCHIQ_STATE_T *state, VCHIQ_HEADER_T = *header) =20 fourcc =3D payload->fourcc; vchiq_log_info(vchiq_core_log_level, - "%d: prs OPEN@%x (%d->'%c%c%c%c')", - state->id, (unsigned int)header, + "%d: prs OPEN@%tx (%d->'%c%c%c%c')", + state->id, (size_t)header, localport, VCHIQ_FOURCC_AS_4CHARS(fourcc)); =20 @@ -1661,7 +1674,7 @@ parse_rx_slots(VCHIQ_STATE_T *state) =20 header =3D (VCHIQ_HEADER_T *)(state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK)); - DEBUG_VALUE(PARSE_HEADER, (int)header); + DEBUG_VALUE(PARSE_HEADER, (size_t)header); msgid =3D header->msgid; DEBUG_VALUE(PARSE_MSGID, msgid); size =3D header->size; @@ -1695,20 +1708,20 @@ parse_rx_slots(VCHIQ_STATE_T *state) remoteport); if (service) = vchiq_log_warning(vchiq_core_log_level, - "%d: prs %s@%x (%d->%d) = - " + "%d: prs %s@%tx (%d->%d) = - " "found connected service = %d", state->id, = msg_type_str(type), - (unsigned int)header, + (size_t)header, remoteport, localport, service->localport); } =20 if (!service) { vchiq_log_error(vchiq_core_log_level, - "%d: prs %s@%x (%d->%d) - " + "%d: prs %s@%zx (%d->%d) - " "invalid/closed service %d", state->id, msg_type_str(type), - (unsigned int)header, + (size_t)header, remoteport, localport, = localport); goto skip_message; } @@ -1734,12 +1747,12 @@ parse_rx_slots(VCHIQ_STATE_T *state) min(16, size)); } =20 - if (((unsigned int)header & VCHIQ_SLOT_MASK) + = calc_stride(size) + if (((size_t)header & VCHIQ_SLOT_MASK) + = calc_stride(size) > VCHIQ_SLOT_SIZE) { vchiq_log_error(vchiq_core_log_level, - "header %x (msgid %x) - size %x too big = for " + "header %tx (msgid %x) - size %x too big = for " "slot", - (unsigned int)header, (unsigned = int)msgid, + (size_t)header, (unsigned int)msgid, (unsigned int)size); WARN(1, "oversized for slot\n"); } @@ -1758,8 +1771,8 @@ parse_rx_slots(VCHIQ_STATE_T *state) service->peer_version =3D = payload->version; } vchiq_log_info(vchiq_core_log_level, - "%d: prs OPENACK@%x,%x (%d->%d) v:%d", - state->id, (unsigned int)header, size, + "%d: prs OPENACK@%tx,%x (%d->%d) v:%d", + state->id, (size_t)header, size, remoteport, localport, = service->peer_version); if (service->srvstate =3D=3D VCHIQ_SRVSTATE_OPENING) { @@ -1776,8 +1789,8 @@ parse_rx_slots(VCHIQ_STATE_T *state) WARN_ON(size !=3D 0); /* There should be no data = */ =20 vchiq_log_info(vchiq_core_log_level, - "%d: prs CLOSE@%x (%d->%d)", - state->id, (unsigned int)header, + "%d: prs CLOSE@%tx (%d->%d)", + state->id, (size_t)header, remoteport, localport); =20 mark_service_closing_internal(service, 1); @@ -1794,8 +1807,8 @@ parse_rx_slots(VCHIQ_STATE_T *state) break; case VCHIQ_MSG_DATA: vchiq_log_info(vchiq_core_log_level, - "%d: prs DATA@%x,%x (%d->%d)", - state->id, (unsigned int)header, size, + "%d: prs DATA@%tx,%x (%d->%d)", + state->id, (size_t)header, size, remoteport, localport); =20 if ((service->remoteport =3D=3D remoteport) @@ -1819,14 +1832,19 @@ parse_rx_slots(VCHIQ_STATE_T *state) break; case VCHIQ_MSG_CONNECT: vchiq_log_info(vchiq_core_log_level, - "%d: prs CONNECT@%x", - state->id, (unsigned int)header); + "%d: prs CONNECT@%tx", + state->id, (size_t)header); state->version_common =3D ((VCHIQ_SLOT_ZERO_T *) = state->slot_data)->version; up(&state->connect); break; case VCHIQ_MSG_BULK_RX: - case VCHIQ_MSG_BULK_TX: { + case VCHIQ_MSG_BULK_TX: + WARN_ON(1); + break; +/* Appaz this isn't needed = +https://github.com/raspberrypi/linux/commit/14f4d72fb799a9b3170a45ab80d4a= 3ddad541960 +{ VCHIQ_BULK_QUEUE_T *queue; WARN_ON(!state->is_master); queue =3D (type =3D=3D VCHIQ_MSG_BULK_RX) ? @@ -1854,12 +1872,12 @@ parse_rx_slots(VCHIQ_STATE_T *state) wmb(); =20 vchiq_log_info(vchiq_core_log_level, - "%d: prs %s@%x (%d->%d) %x@%x", + "%d: prs %s@%tx (%d->%d) = %x@%tx", state->id, msg_type_str(type), - (unsigned int)header, + (size_t)header, remoteport, localport, bulk->remote_size, - (unsigned = int)bulk->remote_data); + (size_t)bulk->remote_data); =20 queue->remote_insert++; =20 @@ -1888,9 +1906,11 @@ parse_rx_slots(VCHIQ_STATE_T *state) lmutex_unlock(&service->bulk_mutex); if (resolved) notify_bulks(service, queue, - 1/*retry_poll*/); + 1//retry_poll + ); } } break; +*/ case VCHIQ_MSG_BULK_RX_DONE: case VCHIQ_MSG_BULK_TX_DONE: WARN_ON(state->is_master); @@ -1912,10 +1932,10 @@ parse_rx_slots(VCHIQ_STATE_T *state) if ((int)(queue->remote_insert - queue->local_insert) >=3D 0) { = vchiq_log_error(vchiq_core_log_level, - "%d: prs %s@%x (%d->%d) = " + "%d: prs %s@%tx (%d->%d) = " "unexpected = (ri=3D%d,li=3D%d)", state->id, = msg_type_str(type), - (unsigned int)header, + (size_t)header, remoteport, localport, queue->remote_insert, queue->local_insert); @@ -1932,11 +1952,11 @@ parse_rx_slots(VCHIQ_STATE_T *state) queue->remote_insert++; =20 vchiq_log_info(vchiq_core_log_level, - "%d: prs %s@%x (%d->%d) %x@%x", + "%d: prs %s@%tx (%d->%d) = %x@%tx", state->id, msg_type_str(type), - (unsigned int)header, + (size_t)header, remoteport, localport, - bulk->actual, (unsigned = int)bulk->data); + bulk->actual, = (size_t)bulk->data); =20 vchiq_log_trace(vchiq_core_log_level, "%d: prs:%d %cx li=3D%x ri=3D%x = p=3D%x", @@ -1958,14 +1978,14 @@ parse_rx_slots(VCHIQ_STATE_T *state) break; case VCHIQ_MSG_PADDING: vchiq_log_trace(vchiq_core_log_level, - "%d: prs PADDING@%x,%x", - state->id, (unsigned int)header, size); + "%d: prs PADDING@%tx,%x", + state->id, (size_t)header, size); break; case VCHIQ_MSG_PAUSE: /* If initiated, signal the application thread = */ vchiq_log_trace(vchiq_core_log_level, - "%d: prs PAUSE@%x,%x", - state->id, (unsigned int)header, size); + "%d: prs PAUSE@%tx,%x", + state->id, (size_t)header, size); if (state->conn_state =3D=3D = VCHIQ_CONNSTATE_PAUSED) { vchiq_log_error(vchiq_core_log_level, "%d: PAUSE received in state = PAUSED", @@ -1988,8 +2008,8 @@ parse_rx_slots(VCHIQ_STATE_T *state) break; case VCHIQ_MSG_RESUME: vchiq_log_trace(vchiq_core_log_level, - "%d: prs RESUME@%x,%x", - state->id, (unsigned int)header, size); + "%d: prs RESUME@%tx,%x", + state->id, (size_t)header, size); /* Release the slot mutex */ lmutex_unlock(&state->slot_mutex); if (state->is_master) @@ -2010,8 +2030,8 @@ parse_rx_slots(VCHIQ_STATE_T *state) =20 default: vchiq_log_error(vchiq_core_log_level, - "%d: prs invalid msgid %x@%x,%x", - state->id, msgid, (unsigned int)header, = size); + "%d: prs invalid msgid %x@%tx,%x", + state->id, msgid, (size_t)header, size); WARN(1, "invalid message\n"); break; } @@ -2051,7 +2071,7 @@ slot_handler_func(void *v) while (1) { DEBUG_COUNT(SLOT_HANDLER_COUNT); DEBUG_TRACE(SLOT_HANDLER_LINE); - remote_event_wait(&local->trigger); + remote_event_wait(state, &local->trigger); =20 rmb(); =20 @@ -2141,7 +2161,7 @@ recycle_func(void *v) VCHIQ_SHARED_STATE_T *local =3D state->local; =20 while (1) { - remote_event_wait(&local->recycle); + remote_event_wait(state, &local->recycle); =20 process_free_queue(state); } @@ -2165,7 +2185,7 @@ sync_func(void *v) int type; unsigned int localport, remoteport; =20 - remote_event_wait(&local->sync_trigger); + remote_event_wait(state, &local->sync_trigger); =20 rmb(); =20 @@ -2179,10 +2199,10 @@ sync_func(void *v) =20 if (!service) { vchiq_log_error(vchiq_sync_log_level, - "%d: sf %s@%x (%d->%d) - " + "%d: sf %s@%tx (%d->%d) - " "invalid/closed service %d", state->id, msg_type_str(type), - (unsigned int)header, + (size_t)header, remoteport, localport, localport); release_message_sync(state, header); continue; @@ -2213,8 +2233,8 @@ sync_func(void *v) service->peer_version =3D = payload->version; } vchiq_log_info(vchiq_sync_log_level, - "%d: sf OPENACK@%x,%x (%d->%d) v:%d", - state->id, (unsigned int)header, size, + "%d: sf OPENACK@%tx,%x (%d->%d) v:%d", + state->id, (size_t)header, size, remoteport, localport, = service->peer_version); if (service->srvstate =3D=3D = VCHIQ_SRVSTATE_OPENING) { service->remoteport =3D remoteport; @@ -2228,8 +2248,8 @@ sync_func(void *v) =20 case VCHIQ_MSG_DATA: vchiq_log_trace(vchiq_sync_log_level, - "%d: sf DATA@%x,%x (%d->%d)", - state->id, (unsigned int)header, size, + "%d: sf DATA@%tx,%x (%d->%d)", + state->id, (size_t)header, size, remoteport, localport); =20 if ((service->remoteport =3D=3D remoteport) && @@ -2248,8 +2268,8 @@ sync_func(void *v) =20 default: vchiq_log_error(vchiq_sync_log_level, - "%d: sf unexpected msgid %x@%x,%x", - state->id, msgid, (unsigned int)header, = size); + "%d: sf unexpected msgid %x@%tx,%x", + state->id, msgid, (size_t)header, size); release_message_sync(state, header); break; } @@ -2282,7 +2302,7 @@ get_conn_state_name(VCHIQ_CONNSTATE_T conn_state) VCHIQ_SLOT_ZERO_T * vchiq_init_slots(void *mem_base, int mem_size) { - int mem_align =3D (VCHIQ_SLOT_SIZE - (int)mem_base) & = VCHIQ_SLOT_MASK; + int mem_align =3D (int)((VCHIQ_SLOT_SIZE - (long)mem_base) & = VCHIQ_SLOT_MASK); VCHIQ_SLOT_ZERO_T *slot_zero =3D (VCHIQ_SLOT_ZERO_T *)((char *)mem_base + mem_align); int num_slots =3D (mem_size - mem_align)/VCHIQ_SLOT_SIZE; @@ -2334,8 +2354,8 @@ vchiq_init_state(VCHIQ_STATE_T *state, = VCHIQ_SLOT_ZERO_T *slot_zero, if (slot_zero->magic !=3D VCHIQ_MAGIC) { vchiq_loud_error_header(); vchiq_loud_error("Invalid VCHIQ magic value found."); - vchiq_loud_error("slot_zero=3D%x: magic=3D%x (expected = %x)", - (unsigned int)slot_zero, slot_zero->magic, = VCHIQ_MAGIC); + vchiq_loud_error("slot_zero=3D%tx: magic=3D%x (expected = %x)", + (size_t)slot_zero, slot_zero->magic, = VCHIQ_MAGIC); vchiq_loud_error_footer(); return VCHIQ_ERROR; } @@ -2348,9 +2368,9 @@ vchiq_init_state(VCHIQ_STATE_T *state, = VCHIQ_SLOT_ZERO_T *slot_zero, if (slot_zero->version < VCHIQ_VERSION_MIN) { vchiq_loud_error_header(); vchiq_loud_error("Incompatible VCHIQ versions found."); - vchiq_loud_error("slot_zero=3D%x: VideoCore version=3D%d = " + vchiq_loud_error("slot_zero=3D%tx: VideoCore version=3D%d = " "(minimum %d)", - (unsigned int)slot_zero, slot_zero->version, + (size_t)slot_zero, slot_zero->version, VCHIQ_VERSION_MIN); vchiq_loud_error("Restart with a newer VideoCore = image."); vchiq_loud_error_footer(); @@ -2360,9 +2380,9 @@ vchiq_init_state(VCHIQ_STATE_T *state, = VCHIQ_SLOT_ZERO_T *slot_zero, if (VCHIQ_VERSION < slot_zero->version_min) { vchiq_loud_error_header(); vchiq_loud_error("Incompatible VCHIQ versions found."); - vchiq_loud_error("slot_zero=3D%x: version=3D%d = (VideoCore " + vchiq_loud_error("slot_zero=3D%tx: version=3D%d = (VideoCore " "minimum %d)", - (unsigned int)slot_zero, VCHIQ_VERSION, + (size_t)slot_zero, VCHIQ_VERSION, slot_zero->version_min); vchiq_loud_error("Restart with a newer kernel."); vchiq_loud_error_footer(); @@ -2375,25 +2395,25 @@ vchiq_init_state(VCHIQ_STATE_T *state, = VCHIQ_SLOT_ZERO_T *slot_zero, (slot_zero->max_slots_per_side !=3D = VCHIQ_MAX_SLOTS_PER_SIDE)) { vchiq_loud_error_header(); if (slot_zero->slot_zero_size !=3D = sizeof(VCHIQ_SLOT_ZERO_T)) - vchiq_loud_error("slot_zero=3D%x: = slot_zero_size=3D%x " + vchiq_loud_error("slot_zero=3D%tx: = slot_zero_size=3D%x " "(expected %zx)", - (unsigned int)slot_zero, + (size_t)slot_zero, slot_zero->slot_zero_size, sizeof(VCHIQ_SLOT_ZERO_T)); if (slot_zero->slot_size !=3D VCHIQ_SLOT_SIZE) - vchiq_loud_error("slot_zero=3D%x: slot_size=3D%d = " + vchiq_loud_error("slot_zero=3D%tx: slot_size=3D%d = " "(expected %d", - (unsigned int)slot_zero, = slot_zero->slot_size, + (size_t)slot_zero, slot_zero->slot_size, VCHIQ_SLOT_SIZE); if (slot_zero->max_slots !=3D VCHIQ_MAX_SLOTS) - vchiq_loud_error("slot_zero=3D%x: max_slots=3D%d = " + vchiq_loud_error("slot_zero=3D%tx: max_slots=3D%d = " "(expected %d)", - (unsigned int)slot_zero, = slot_zero->max_slots, + (size_t)slot_zero, slot_zero->max_slots, VCHIQ_MAX_SLOTS); if (slot_zero->max_slots_per_side !=3D = VCHIQ_MAX_SLOTS_PER_SIDE) - vchiq_loud_error("slot_zero=3D%x: = max_slots_per_side=3D%d " + vchiq_loud_error("slot_zero=3D%tx: = max_slots_per_side=3D%d " "(expected %d)", - (unsigned int)slot_zero, + (size_t)slot_zero, slot_zero->max_slots_per_side, VCHIQ_MAX_SLOTS_PER_SIDE); vchiq_loud_error_footer(); @@ -2478,24 +2498,24 @@ vchiq_init_state(VCHIQ_STATE_T *state, = VCHIQ_SLOT_ZERO_T *slot_zero, state->data_use_count =3D 0; state->data_quota =3D state->slot_queue_available - 1; =20 - local->trigger.event =3D &state->trigger_event; - remote_event_create(&local->trigger); + local->trigger.event =3D offsetof(VCHIQ_STATE_T, trigger_event); + remote_event_create(state, &local->trigger); local->tx_pos =3D 0; =20 - local->recycle.event =3D &state->recycle_event; - remote_event_create(&local->recycle); + local->recycle.event =3D offsetof(VCHIQ_STATE_T, recycle_event); + remote_event_create(state, &local->recycle); local->slot_queue_recycle =3D state->slot_queue_available; =20 - local->sync_trigger.event =3D &state->sync_trigger_event; - remote_event_create(&local->sync_trigger); + local->sync_trigger.event =3D offsetof(VCHIQ_STATE_T, = sync_trigger_event); + remote_event_create(state, &local->sync_trigger); =20 - local->sync_release.event =3D &state->sync_release_event; - remote_event_create(&local->sync_release); + local->sync_release.event =3D offsetof(VCHIQ_STATE_T, = sync_release_event); + remote_event_create(state, &local->sync_release); =20 /* At start-of-day, the slot is empty and available */ ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, = local->slot_sync))->msgid =3D VCHIQ_MSGID_PADDING; - remote_event_signal_local(&local->sync_release); + remote_event_signal_local(state, &local->sync_release); =20 local->debug[DEBUG_ENTRIES] =3D DEBUG_MAX; =20 @@ -2775,18 +2795,18 @@ release_service_messages(VCHIQ_SERVICE_T = *service) if ((port =3D=3D service->localport) && (msgid & VCHIQ_MSGID_CLAIMED)) { = vchiq_log_info(vchiq_core_log_level, - " fsi - hdr %x", - (unsigned int)header); + " fsi - hdr %tx", + (size_t)header); release_slot(state, slot_info, = header, NULL); } pos +=3D calc_stride(header->size); if (pos > VCHIQ_SLOT_SIZE) { = vchiq_log_error(vchiq_core_log_level, - "fsi - pos %x: header = %x, " + "fsi - pos %x: header = %tx, " "msgid %x, header->msgid = %x, " "header->size %x", - pos, (unsigned = int)header, + pos, (size_t)header, msgid, header->msgid, header->size); WARN(1, "invalid slot = position\n"); @@ -3360,10 +3380,10 @@ vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T = handle, wmb(); =20 vchiq_log_info(vchiq_core_log_level, - "%d: bt (%d->%d) %cx %x@%x %x", + "%d: bt (%d->%d) %cx %x@%tx %tx", state->id, service->localport, service->remoteport, dir_char, - size, (unsigned int)bulk->data, (unsigned int)userdata); + size, (size_t)bulk->data, (size_t)userdata); =20 /* The slot mutex must be held when the service is being closed, = so claim it here to ensure that isn't happening */ @@ -3382,7 +3402,12 @@ vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE_T = handle, (dir =3D=3D VCHIQ_BULK_TRANSMIT) ? VCHIQ_POLL_TXNOTIFY : = VCHIQ_POLL_RXNOTIFY); } else { - int payload[2] =3D { (int)bulk->data, bulk->size }; + /* + EXPERIMENTAL + Makes more sense to me to have these as unsigned = things + even if size is an int (?) + */ + uint32_t payload[2] =3D { (uint32_t)(size_t)bulk->data, = bulk->size }; VCHIQ_ELEMENT_T element =3D { payload, sizeof(payload) = }; =20 status =3D queue_message(state, NULL, @@ -3710,12 +3735,12 @@ vchiq_dump_state(void *dump_context, = VCHIQ_STATE_T *state) vchiq_dump(dump_context, buf, len + 1); =20 len =3D snprintf(buf, sizeof(buf), - " tx_pos=3D%x(@%x), rx_pos=3D%x(@%x)", + " tx_pos=3D%x(@%tx), rx_pos=3D%x(@%tx)", state->local->tx_pos, - (uint32_t)state->tx_data + + (size_t)state->tx_data + (state->local_tx_pos & VCHIQ_SLOT_MASK), state->rx_pos, - (uint32_t)state->rx_data + + (size_t)state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK)); vchiq_dump(dump_context, buf, len + 1); =20 @@ -3817,8 +3842,8 @@ vchiq_dump_service_state(void *dump_context, = VCHIQ_SERVICE_T *service) vchiq_dump(dump_context, buf, len + 1); =20 len =3D snprintf(buf, sizeof(buf), - " Ctrl: tx_count=3D%d, tx_bytes=3D%llu, = " - "rx_count=3D%d, rx_bytes=3D%llu", + " Ctrl: tx_count=3D%d, = tx_bytes=3D%"PRIu64", " + "rx_count=3D%d, rx_bytes=3D%"PRIu64"", service->stats.ctrl_tx_count, service->stats.ctrl_tx_bytes, service->stats.ctrl_rx_count, @@ -3826,8 +3851,8 @@ vchiq_dump_service_state(void *dump_context, = VCHIQ_SERVICE_T *service) vchiq_dump(dump_context, buf, len + 1); =20 len =3D snprintf(buf, sizeof(buf), - " Bulk: tx_count=3D%d, tx_bytes=3D%llu, = " - "rx_count=3D%d, rx_bytes=3D%llu", + " Bulk: tx_count=3D%d, = tx_bytes=3D%"PRIu64", " + "rx_count=3D%d, rx_bytes=3D%"PRIu64"", service->stats.bulk_tx_count, service->stats.bulk_tx_bytes, service->stats.bulk_rx_count, diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.h = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.h index 38ede407f4f4..4e3f41203bc4 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.h +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_core.h @@ -184,12 +184,21 @@ enum { #if VCHIQ_ENABLE_DEBUG =20 #define DEBUG_INITIALISE(local) int *debug_ptr =3D (local)->debug; +#if defined(__aarch64__) +#define DEBUG_TRACE(d) \ + do { debug_ptr[DEBUG_ ## d] =3D __LINE__; dsb(sy); } while (0) +#define DEBUG_VALUE(d, v) \ + do { debug_ptr[DEBUG_ ## d] =3D (v); dsb(sy); } while (0) +#define DEBUG_COUNT(d) \ + do { debug_ptr[DEBUG_ ## d]++; dsb(sy); } while (0) +#else #define DEBUG_TRACE(d) \ do { debug_ptr[DEBUG_ ## d] =3D __LINE__; dsb(); } while (0) #define DEBUG_VALUE(d, v) \ do { debug_ptr[DEBUG_ ## d] =3D (v); dsb(); } while (0) #define DEBUG_COUNT(d) \ do { debug_ptr[DEBUG_ ## d]++; dsb(); } while (0) +#endif =20 #else /* VCHIQ_ENABLE_DEBUG */ =20 @@ -265,7 +274,7 @@ typedef struct vchiq_bulk_queue_struct { typedef struct remote_event_struct { int armed; int fired; - struct semaphore *event; + uint32_t event; } REMOTE_EVENT_T; =20 typedef struct opaque_platform_state_t *VCHIQ_PLATFORM_STATE_T; diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kern_lib.c = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kern_lib.c index 1f849a09d854..22b988dcf436 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kern_lib.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kern_lib.c @@ -151,9 +151,9 @@ VCHIQ_STATUS_T vchiq_shutdown(VCHIQ_INSTANCE_T = instance) list); list_del(pos); vchiq_log_info(vchiq_arm_log_level, - "bulk_waiter - cleaned up %x " + "bulk_waiter - cleaned up %tx " "for pid %d", - (unsigned int)waiter, = waiter->pid); + (size_t)waiter, waiter->pid); _sema_destroy(&waiter->bulk_waiter.event); =20 kfree(waiter); @@ -454,8 +454,8 @@ vchiq_blocking_bulk_transfer(VCHIQ_SERVICE_HANDLE_T = handle, void *data, list_add(&waiter->list, &instance->bulk_waiter_list); lmutex_unlock(&instance->bulk_waiter_list_mutex); vchiq_log_info(vchiq_arm_log_level, - "saved bulk_waiter %x for pid %d", - (unsigned int)waiter, current->p_pid); + "saved bulk_waiter %tx for pid %d", + (size_t)waiter, current->p_pid); } =20 return status; diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c index 53d1819c6cde..dc18678b99a3 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_kmod.c @@ -47,7 +47,7 @@ __FBSDID("$FreeBSD$"); #include <dev/ofw/ofw_bus_subr.h> =20 #include <machine/bus.h> -#include <machine/fdt.h> +//#include <machine/fdt.h> =20 #include "vchiq_arm.h" #include "vchiq_2835.h" @@ -118,13 +118,24 @@ bcm_vchiq_intr(void *arg) void remote_event_signal(REMOTE_EVENT_T *event) { +/* + TODO: Linux puts a wmb() here. most calls to this func are + preceded by a wmb(). Refactor? +*/ event->fired =3D 1; - /* The test on the next line also ensures the write on the = previous line has completed */ + /* UPDATE: not on arm64, it would seem... */ +#if defined(__aarch64__) + dsb(sy); +#endif if (event->armed) { /* trigger vc interrupt */ +#if defined(__aarch64__) + dsb(sy); +#else dsb(); +#endif vchiq_write_4(0x48, 0); } } diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_pagelist.h = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_pagelist.h index 72c362464cc2..d1cb9f1e1658 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_pagelist.h +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_pagelist.h @@ -42,10 +42,10 @@ #define PAGELIST_READ_WITH_FRAGMENTS 2 =20 typedef struct pagelist_struct { - unsigned long length; - unsigned short type; - unsigned short offset; - unsigned long addrs[1]; /* N.B. 12 LSBs hold the number of = following + uint32_t length; + uint16_t type; + uint16_t offset; + uint32_t addrs[1]; /* N.B. 12 LSBs hold the number of = following pages at consecutive addresses. */ } PAGELIST_T; =20 diff --git a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_shim.c = b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_shim.c index cc8ef2e071f8..f33c545cea45 100644 --- a/sys/contrib/vchiq/interface/vchiq_arm/vchiq_shim.c +++ b/sys/contrib/vchiq/interface/vchiq_arm/vchiq_shim.c @@ -398,7 +398,7 @@ EXPORT_SYMBOL(vchi_msg_queuev); ***********************************************************/ int32_t vchi_held_msg_release(VCHI_HELD_MSG_T *message) { - vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)message->service, + = vchiq_release_message((VCHIQ_SERVICE_HANDLE_T)(size_t)message->service, (VCHIQ_HEADER_T *)message->message); =20 return 0; @@ -444,7 +444,7 @@ int32_t vchi_msg_hold(VCHI_SERVICE_HANDLE_T handle, *msg_size =3D header->size; =20 message_handle->service =3D - (struct opaque_vchi_service_t *)service->handle; + (struct opaque_vchi_service_t *)(unsigned = long)service->handle; message_handle->message =3D header; =20 return 0;
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?A0775CDC-7382-4A15-8131-482572032308>