Index: sys/arch/arm/broadcom/bcm2835_vcaudio.c =================================================================== RCS file: /cvsroot/src/sys/arch/arm/broadcom/bcm2835_vcaudio.c,v retrieving revision 1.18 diff -p -u -r1.18 bcm2835_vcaudio.c --- sys/arch/arm/broadcom/bcm2835_vcaudio.c 24 Apr 2021 23:36:26 -0000 1.18 +++ sys/arch/arm/broadcom/bcm2835_vcaudio.c 21 Jan 2023 13:52:08 -0000 @@ -68,15 +68,17 @@ enum { VCAUDIO_INPUT_DAC_VOLUME, VCAUDIO_OUTPUT_AUTO_VOLUME, VCAUDIO_OUTPUT_HEADPHONE_VOLUME, - VCAUDIO_OUTPUT_HDMI_VOLUME, - VCAUDIO_OUTPUT_SELECT, - VCAUDIO_ENUM_LAST, + VCAUDIO_OUTPUT_HDMI0_VOLUME, + VCAUDIO_OUTPUT_HDMI1_VOLUME, + VCAUDIO_OUTPUT_SELECT }; enum vcaudio_dest { VCAUDIO_DEST_AUTO = 0, VCAUDIO_DEST_HP = 1, - VCAUDIO_DEST_HDMI = 2, + VCAUDIO_DEST_HDMI0 = 2, + VCAUDIO_DEST_HDMI1 = 3, + VCAUDIO_DEST_LAST = VCAUDIO_DEST_HDMI1 }; /* @@ -136,7 +138,7 @@ struct vcaudio_softc { short sc_peer_version; - int sc_hwvol[3]; + int sc_hwvol[VCAUDIO_DEST_LAST+1]; enum vcaudio_dest sc_dest; uint8_t sc_swvol; @@ -267,7 +269,8 @@ vcaudio_init(struct vcaudio_softc *sc) sc->sc_swvol = 255; sc->sc_hwvol[VCAUDIO_DEST_AUTO] = 255; sc->sc_hwvol[VCAUDIO_DEST_HP] = 255; - sc->sc_hwvol[VCAUDIO_DEST_HDMI] = 255; + sc->sc_hwvol[VCAUDIO_DEST_HDMI0] = 255; + sc->sc_hwvol[VCAUDIO_DEST_HDMI1] = 255; sc->sc_dest = VCAUDIO_DEST_AUTO; sc->sc_format.mode = AUMODE_PLAY; @@ -286,6 +289,7 @@ vcaudio_init(struct vcaudio_softc *sc) "couldn't init vchi instance (%d)\n", error); return EIO; } +printf("vcaudio: initialised\n"); error = vchi_connect(NULL, 0, sc->sc_instance); if (error) { @@ -293,6 +297,7 @@ vcaudio_init(struct vcaudio_softc *sc) "couldn't connect vchi (%d)\n", error); return EIO; } +printf("vcaudio: connected\n"); SERVICE_CREATION_T setup = { .version = VCHI_VERSION(VC_AUDIOSERV_VER), @@ -313,8 +318,10 @@ vcaudio_init(struct vcaudio_softc *sc) error); return EIO; } +printf("vcaudio: service open\n"); vchi_get_peer_version(sc->sc_service, &sc->sc_peer_version); +printf("vcaudio: got peer version %d\n", sc->sc_peer_version); if (sc->sc_peer_version < 2) { aprint_error_dev(sc->sc_dev, @@ -324,7 +331,8 @@ vcaudio_init(struct vcaudio_softc *sc) } memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_OPEN; + msg.type = htole32(VC_AUDIO_MSG_TYPE_OPEN); +printf("vcaudio: sending open message\n"); error = vchi_msg_queue(sc->sc_service, &msg, sizeof(msg), VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); if (error) { @@ -333,10 +341,11 @@ vcaudio_init(struct vcaudio_softc *sc) } memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_CONFIG; - msg.u.config.channels = 2; - msg.u.config.samplerate = 48000; - msg.u.config.bps = 16; + msg.type = htole32(VC_AUDIO_MSG_TYPE_CONFIG); + msg.u.config.channels = htole32(2); + msg.u.config.samplerate = htole32(48000); + msg.u.config.bps = htole32(16); +printf("vcaudio: sending config message\n"); error = vcaudio_msg_sync(sc, &msg, sizeof(msg)); if (error) { aprint_error_dev(sc->sc_dev, @@ -344,17 +353,20 @@ vcaudio_init(struct vcaudio_softc *sc) } memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_CONTROL; - msg.u.control.volume = vol2vc(sc->sc_hwvol[sc->sc_dest]); - msg.u.control.dest = sc->sc_dest; + msg.type = htole32(VC_AUDIO_MSG_TYPE_CONTROL); + msg.u.control.volume = htole32(vol2vc(sc->sc_hwvol[sc->sc_dest])); + msg.u.control.dest = htole32(sc->sc_dest); +printf("vcaudio: sending control message\n"); error = vcaudio_msg_sync(sc, &msg, sizeof(msg)); if (error) { aprint_error_dev(sc->sc_dev, "couldn't send CONTROL message (%d)\n", error); } +printf("vcaudio: release\n"); vchi_service_release(sc->sc_service); +printf("vcaudio: init done\n"); return 0; } @@ -379,47 +391,58 @@ vcaudio_service_callback(void *priv, con return; } - switch (msg.type) { + switch (le32toh(msg.type)) { case VC_AUDIO_MSG_TYPE_RESULT: mutex_enter(&sc->sc_msglock); - sc->sc_success = msg.u.result.success; + sc->sc_success = le32toh(msg.u.result.success); sc->sc_msgdone = true; cv_broadcast(&sc->sc_msgcv); mutex_exit(&sc->sc_msglock); break; case VC_AUDIO_MSG_TYPE_COMPLETE: - if (msg.u.complete.cookie1 == VC_AUDIO_WRITE_COOKIE1 && - msg.u.complete.cookie2 == VC_AUDIO_WRITE_COOKIE2) { - int count = msg.u.complete.count & 0xffff; - int perr = (msg.u.complete.count & __BIT(30)) != 0; + if (le32toh(msg.u.complete.cookie1) == VC_AUDIO_WRITE_COOKIE1 && + le32toh(msg.u.complete.cookie2) == VC_AUDIO_WRITE_COOKIE2) { + int count = le32toh(msg.u.complete.count) & 0xffff; + int perr = (le32toh(msg.u.complete.count) & __BIT(30)) != 0; bool sched = false; mutex_enter(&sc->sc_intr_lock); if (count > 0) { + // count played bytes sc->sc_pbytes += count; } +device_printf(sc->sc_dev, "complete %d err %d done %d of %d\n",count,perr,sc->sc_pbytes,sc->sc_pblksize); + if (perr && sc->sc_started) { -#ifdef VCAUDIO_DEBUG +//#ifdef VCAUDIO_DEBUG device_printf(sc->sc_dev, "underrun\n"); -#endif +//#endif sched = true; } if (sc->sc_pbytes >= sc->sc_pblksize) { + // if more than a block was played, tell user + // XXX possible to have more than one block ? sc->sc_pbytes -= sc->sc_pblksize; sched = true; } if (sched && sc->sc_pint) { + // tell user sc->sc_pint(sc->sc_pintarg); + // grow free space + // sched assures (?) that we collected + // enough chunks for a pblk sc->sc_abytes += sc->sc_pblksize; + // tell worker to refill cv_signal(&sc->sc_datacv); } mutex_exit(&sc->sc_intr_lock); } break; default: + device_printf(sc->sc_dev, "unknown msg.type %d\n", le32toh(msg.type)); break; } } @@ -441,6 +464,7 @@ vcaudio_worker(void *priv) intrarg = sc->sc_pintarg; if (intr == NULL || intrarg == NULL) { + // not configured yet cv_wait_sig(&sc->sc_datacv, &sc->sc_intr_lock); continue; } @@ -448,25 +472,30 @@ vcaudio_worker(void *priv) KASSERT(sc->sc_pblksize != 0); if (sc->sc_abytes < sc->sc_pblksize) { + // free space too small, wait for more cv_wait_sig(&sc->sc_datacv, &sc->sc_intr_lock); continue; } + + // always handle full blocks ? count = sc->sc_pblksize; memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_WRITE; - msg.u.write.max_packet = VCAUDIO_MSGSIZE; - msg.u.write.count = count; - msg.u.write.cookie1 = VC_AUDIO_WRITE_COOKIE1; - msg.u.write.cookie2 = VC_AUDIO_WRITE_COOKIE2; - msg.u.write.silence = 0; + msg.type = htole32(VC_AUDIO_MSG_TYPE_WRITE); + msg.u.write.max_packet = htole16(VCAUDIO_MSGSIZE); + msg.u.write.count = htole32(count); + msg.u.write.cookie1 = htole32(VC_AUDIO_WRITE_COOKIE1); + msg.u.write.cookie2 = htole32(VC_AUDIO_WRITE_COOKIE2); + msg.u.write.silence = htole16(0); + // work on current play position, one block (==count) block = (uint8_t *)sc->sc_pstart + sc->sc_ppos; resid = count; off = 0; vchi_service_use(sc->sc_service); +device_printf(sc->sc_dev, "MSG_TYPE_WRITE %d\n", le32toh(msg.u.write.count)); error = vchi_msg_queue(sc->sc_service, &msg, sizeof(msg), VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); if (error) { @@ -474,8 +503,10 @@ vcaudio_worker(void *priv) goto done; } + // queue count bytes in max_packet chunks while (resid > 0) { - nb = uimin(resid, msg.u.write.max_packet); + nb = uimin(resid, VCAUDIO_MSGSIZE); +device_printf(sc->sc_dev, "MSG_TYPE_WRITE %d offset %d\n", le32toh(msg.u.write.count), off); error = vchi_msg_queue(sc->sc_service, (char *)block + off, nb, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); @@ -489,8 +520,8 @@ vcaudio_worker(void *priv) resid -= nb; } - sc->sc_abytes -= count; - sc->sc_ppos += count; + sc->sc_abytes -= count; // reduce free space + sc->sc_ppos += count; // bump play position if ((uint8_t *)sc->sc_pstart + sc->sc_ppos >= (uint8_t *)sc->sc_pend) sc->sc_ppos = 0; @@ -500,8 +531,10 @@ vcaudio_worker(void *priv) if (sc->sc_pblkcnt == VCAUDIO_PREFILLCOUNT) { + // !started and have 2 blocks -> start memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_START; + msg.type = htole32(VC_AUDIO_MSG_TYPE_START); +device_printf(sc->sc_dev, "MSG_TYPE_START\n"); error = vchi_msg_queue(sc->sc_service, &msg, sizeof(msg), VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); @@ -511,9 +544,11 @@ vcaudio_worker(void *priv) goto done; } sc->sc_started = true; + // count played bytes since start module block size sc->sc_pbytes = 0; } else { intr(intrarg); + // grow free space, assume that we moved a single block (XXX should be count?) sc->sc_abytes += sc->sc_pblksize; } } @@ -533,6 +568,7 @@ vcaudio_msg_sync(struct vcaudio_softc *s sc->sc_success = -1; sc->sc_msgdone = false; +device_printf(sc->sc_dev, "MSG type %d\n", le32toh(msg->type)); error = vchi_msg_queue(sc->sc_service, msg, msglen, VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); if (error) { @@ -585,8 +621,9 @@ vcaudio_halt_output(void *priv) vchi_service_use(sc->sc_service); memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_STOP; - msg.u.stop.draining = 0; + msg.type = htole32(VC_AUDIO_MSG_TYPE_STOP); + msg.u.stop.draining = htole32(1); +device_printf(sc->sc_dev, "MSG_TYPE_STOP\n"); error = vchi_msg_queue(sc->sc_service, &msg, sizeof(msg), VCHI_FLAGS_BLOCK_UNTIL_QUEUED, NULL); if (error) { @@ -620,10 +657,11 @@ vcaudio_set_volume(struct vcaudio_softc vchi_service_use(sc->sc_service); memset(&msg, 0, sizeof(msg)); - msg.type = VC_AUDIO_MSG_TYPE_CONTROL; - msg.u.control.volume = vol2vc(hwvol); - msg.u.control.dest = dest; + msg.type = htole32(VC_AUDIO_MSG_TYPE_CONTROL); + msg.u.control.volume = htole32(vol2vc(hwvol)); + msg.u.control.dest = htole32(dest); +device_printf(sc->sc_dev, "MSG_TYPE_CONTROL\n"); error = vcaudio_msg_sync(sc, &msg, sizeof(msg)); if (error) { device_printf(sc->sc_dev, @@ -651,11 +689,14 @@ vcaudio_set_port(void *priv, mixer_ctrl_ case VCAUDIO_OUTPUT_HEADPHONE_VOLUME: return vcaudio_set_volume(sc, VCAUDIO_DEST_HP, mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT]); - case VCAUDIO_OUTPUT_HDMI_VOLUME: - return vcaudio_set_volume(sc, VCAUDIO_DEST_HDMI, + case VCAUDIO_OUTPUT_HDMI0_VOLUME: + return vcaudio_set_volume(sc, VCAUDIO_DEST_HDMI0, + mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT]); + case VCAUDIO_OUTPUT_HDMI1_VOLUME: + return vcaudio_set_volume(sc, VCAUDIO_DEST_HDMI1, mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT]); case VCAUDIO_OUTPUT_SELECT: - if (mc->un.ord < 0 || mc->un.ord > 2) + if (mc->un.ord < 0 || mc->un.ord > VCAUDIO_DEST_LAST) return EINVAL; sc->sc_dest = mc->un.ord; return vcaudio_set_volume(sc, mc->un.ord, @@ -686,10 +727,15 @@ vcaudio_get_port(void *priv, mixer_ctrl_ mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = sc->sc_hwvol[VCAUDIO_DEST_HP]; return 0; - case VCAUDIO_OUTPUT_HDMI_VOLUME: + case VCAUDIO_OUTPUT_HDMI0_VOLUME: + mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = + mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = + sc->sc_hwvol[VCAUDIO_DEST_HDMI0]; + return 0; + case VCAUDIO_OUTPUT_HDMI1_VOLUME: mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = - sc->sc_hwvol[VCAUDIO_DEST_HDMI]; + sc->sc_hwvol[VCAUDIO_DEST_HDMI1]; return 0; case VCAUDIO_OUTPUT_SELECT: mc->un.ord = sc->sc_dest; @@ -740,9 +786,18 @@ vcaudio_query_devinfo(void *priv, mixer_ di->un.v.delta = 13; strcpy(di->un.v.units.name, AudioNvolume); return 0; - case VCAUDIO_OUTPUT_HDMI_VOLUME: + case VCAUDIO_OUTPUT_HDMI0_VOLUME: + di->mixer_class = VCAUDIO_OUTPUT_CLASS; + strcpy(di->label.name, "hdmi"); /* XXX hdmi0? */ + di->type = AUDIO_MIXER_VALUE; + di->next = di->prev = AUDIO_MIXER_LAST; + di->un.v.num_channels = 2; + di->un.v.delta = 13; + strcpy(di->un.v.units.name, AudioNvolume); + return 0; + case VCAUDIO_OUTPUT_HDMI1_VOLUME: di->mixer_class = VCAUDIO_OUTPUT_CLASS; - strcpy(di->label.name, "hdmi"); + strcpy(di->label.name, "hdmi1"); di->type = AUDIO_MIXER_VALUE; di->next = di->prev = AUDIO_MIXER_LAST; di->un.v.num_channels = 2; @@ -762,13 +817,15 @@ vcaudio_query_devinfo(void *priv, mixer_ strcpy(di->label.name, AudioNselect); di->type = AUDIO_MIXER_ENUM; di->next = di->prev = AUDIO_MIXER_LAST; - di->un.e.num_mem = 3; - di->un.e.member[0].ord = 0; + di->un.e.num_mem = 4; + di->un.e.member[0].ord = VCAUDIO_DEST_AUTO; strcpy(di->un.e.member[0].label.name, "auto"); - di->un.e.member[1].ord = 1; + di->un.e.member[1].ord = VCAUDIO_DEST_HP; strcpy(di->un.e.member[1].label.name, AudioNheadphone); - di->un.e.member[2].ord = 2; - strcpy(di->un.e.member[2].label.name, "hdmi"); + di->un.e.member[2].ord = VCAUDIO_DEST_HDMI0; + strcpy(di->un.e.member[2].label.name, "hdmi"); /* XXX hdmi0? */ + di->un.e.member[3].ord = VCAUDIO_DEST_HDMI1; + strcpy(di->un.e.member[3].label.name, "hdmi1"); return 0; } Index: sys/external/bsd/vchiq/conf/files.vchiq =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/conf/files.vchiq,v retrieving revision 1.4 diff -p -u -r1.4 files.vchiq --- sys/external/bsd/vchiq/conf/files.vchiq 31 Dec 2019 01:00:22 -0000 1.4 +++ sys/external/bsd/vchiq/conf/files.vchiq 21 Jan 2023 13:52:08 -0000 @@ -24,4 +24,4 @@ attach vchiq at acpinodebus with vchiq_a file external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_acpi.c vchiq_acpi endif -makeoptions vchiq CPPFLAGS+="-I$S/external/bsd/vchiq/dist -I$S/external/bsd/common/include -DVCOS_VERIFY_BKPTS=1 -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -DVCHIQ_ENABLE_DEBUG=1 -DVCHIQ_LOG_DEFAULT=5" +makeoptions vchiq CPPFLAGS+="-I$S/external/bsd/vchiq/dist -I$S/external/bsd/common/include -DVCOS_VERIFY_BKPTS=1 -DUSE_VCHIQ_ARM -D__VCCOREVER__=0x04000000 -DVCHIQ_ENABLE_DEBUG=1 -DVCHIQ_LOG_DEFAULT=7" Index: sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.c,v retrieving revision 1.10 diff -p -u -r1.10 vchi_bsd.c --- sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.c 5 Nov 2017 09:11:43 -0000 1.10 +++ sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.c 21 Jan 2023 13:52:08 -0000 @@ -138,7 +138,7 @@ _sema_init(struct semaphore *s, int valu memset(s, 0, sizeof(*s)); mutex_init(&s->mtx, MUTEX_DEFAULT, IPL_VM); cv_init(&s->cv, "semacv"); - s->value = value; + s->value = htole32(value); } void @@ -153,13 +153,13 @@ down(struct semaphore *s) { mutex_enter(&s->mtx); - while (s->value == 0) { + while (le32toh(s->value) == 0) { s->waiters++; cv_wait(&s->cv, &s->mtx); s->waiters--; } - s->value--; + s->value = htole32(le32toh(s->value) - 1); mutex_exit(&s->mtx); } @@ -169,7 +169,7 @@ down_interruptible(struct semaphore *s) mutex_enter(&s->mtx); - while (s->value == 0) { + while (le32toh(s->value) == 0) { s->waiters++; int ret = cv_wait_sig(&s->cv, &s->mtx); s->waiters--; @@ -180,7 +180,7 @@ down_interruptible(struct semaphore *s) } } - s->value--; + s->value = htole32(le32toh(s->value) - 1); mutex_exit(&s->mtx); return 0; @@ -193,9 +193,9 @@ down_trylock(struct semaphore *s) mutex_enter(&s->mtx); - if (s->value > 0) { + if (le32toh(s->value) > 0) { /* Success. */ - s->value--; + s->value = htole32(le32toh(s->value) - 1); ret = 0; } @@ -208,8 +208,8 @@ void up(struct semaphore *s) { mutex_enter(&s->mtx); - s->value++; - if (s->value > 0 && s->waiters) + s->value = htole32(le32toh(s->value) + 1); + if (le32toh(s->value) > 0 && s->waiters) cv_signal(&s->cv); mutex_exit(&s->mtx); Index: sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.h =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.h,v retrieving revision 1.19 diff -p -u -r1.19 vchi_bsd.h --- sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.h 6 Feb 2022 12:12:08 -0000 1.19 +++ sys/external/bsd/vchiq/dist/interface/compat/vchi_bsd.h 21 Jan 2023 13:52:08 -0000 @@ -48,6 +48,8 @@ #include #include +#include /* for dsb() */ + /* * Copy from/to user API */ Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_2835_arm.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_2835_arm.c,v retrieving revision 1.23 diff -p -u -r1.23 vchiq_2835_arm.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_2835_arm.c 3 Nov 2020 08:41:30 -0000 1.23 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_2835_arm.c 21 Jan 2023 13:52:08 -0000 @@ -37,6 +37,7 @@ #include #include #include +#include #include @@ -47,6 +48,8 @@ #include #include +#include + #define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32) #define VCHIQ_DOORBELL_IRQ IRQ_ARM_DOORBELL_0 @@ -160,9 +163,9 @@ vchiq_platform_init(VCHIQ_STATE_T *state } vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] = - (int)slot_phys + slot_mem_size; + htole32((int)slot_phys + slot_mem_size); vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] = - MAX_FRAGMENTS; + htole32(MAX_FRAGMENTS); g_fragments_base = (char *)slot_mem + slot_mem_size; slot_mem_size += frag_mem_size; @@ -182,6 +185,7 @@ vchiq_platform_init(VCHIQ_STATE_T *state goto failed_vchiq_init; } +#if 1 /* Send the base address of the slots to VideoCore */ dsb(sy); /* Ensure all writes have completed */ @@ -190,6 +194,17 @@ vchiq_platform_init(VCHIQ_STATE_T *state bcm_mbox_write(BCM2835_MBOX_CHAN_VCHIQ, (unsigned int)slot_phys); bus_dmamap_sync(dma_tag, dma_map, 0, slot_mem_size, BUS_DMASYNC_POSTREAD | BUS_DMASYNC_POSTWRITE); +#else + uint32_t chanbase = slot_phys; + err = -rpi_vchiq_init(&chanbase); + if (err || chanbase) { + vchiq_log_error(vchiq_core_log_level, + "failed to set channelbase (%d)", err); + if (err == 0) + err = ENXIO; + goto failed_vchiq_init; + } +#endif vchiq_log_info(vchiq_arm_log_level, "vchiq_init - done (slots %p, phys %x)", @@ -206,7 +221,7 @@ failed_load: failed_alloc: bus_dmamap_destroy(dma_tag, dma_map); - return err; + return err; } void __exit @@ -221,25 +236,34 @@ vchiq_platform_exit(VCHIQ_STATE_T *state VCHIQ_STATUS_T vchiq_platform_init_state(VCHIQ_STATE_T *state) { - VCHIQ_STATUS_T status = VCHIQ_SUCCESS; - state->platform_state = kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL); - ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 1; - status = vchiq_arm_init_state(state, &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state); - if(status != VCHIQ_SUCCESS) - { - ((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited = 0; - } - return status; + VCHIQ_STATUS_T status = VCHIQ_SUCCESS; + VCHIQ_2835_ARM_STATE_T *platform_state; + + state->platform_state = + kzalloc(sizeof(VCHIQ_2835_ARM_STATE_T), GFP_KERNEL); + + platform_state = (VCHIQ_2835_ARM_STATE_T *)state->platform_state; + + platform_state->inited = 1; + status = vchiq_arm_init_state(state, &platform_state->arm_state); + + if (status != VCHIQ_SUCCESS) + platform_state->inited = 0; + + return status; } VCHIQ_ARM_STATE_T* vchiq_platform_get_arm_state(VCHIQ_STATE_T *state) { - if(!((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->inited) - { - BUG(); - } - return &((VCHIQ_2835_ARM_STATE_T*)state->platform_state)->arm_state; + VCHIQ_2835_ARM_STATE_T *platform_state; + + platform_state = (VCHIQ_2835_ARM_STATE_T *)state->platform_state; + + if(!platform_state->inited) + BUG(); + + return &platform_state->arm_state; } int @@ -265,6 +289,7 @@ typedef struct bulkinfo_struct { struct proc *proc; void *buf; int size; + struct buf B; } BULKINFO_T; /* There is a potential problem with partial cache lines (pages?) @@ -296,12 +321,16 @@ vchiq_prepare_bulk_data(VCHIQ_BULK_T *bu WARN_ON(memhandle != VCHI_MEM_HANDLE_INVALID); + bulk->remote_data = NULL; + bi = kmem_alloc(sizeof(*bi), KM_SLEEP); bi->buf = buf; bi->size = size; bi->pagelist_size = sizeof(PAGELIST_T) + - (maxsegs * sizeof(unsigned long)); + ((maxsegs - 1) * sizeof(unsigned long)); bi->proc = curproc; + // memset(&bi->B, 0, sizeof(struct buf)); + // buf_init(&bi->B); ret = bus_dmamem_alloc(dma_tag, bi->pagelist_size, 0 /*CACHE_LINE_SIZE*/, 0, bi->pagelist_sgs, @@ -327,25 +356,40 @@ vchiq_prepare_bulk_data(VCHIQ_BULK_T *bu if (ret != 0) goto fail4; + ret = bus_dmamap_create(dma_tag, size, maxsegs, size, 0, + BUS_DMA_WAITOK, &bi->dmamap); + + if (ret != 0) + goto fail5; + /* - * Need to wire the buffer pages in. + * Need to wire the buffer pages and map them + * into kernel address space. */ if (IS_USER_ADDRESS(buf)) { ret = uvm_vslock(bi->proc->p_vmspace, buf, size, uvmflags); if (ret != 0) { printf("%s: uvm_vslock failed (%d)\n", __func__, ret); - goto fail5; + goto fail6; } - } - - ret = bus_dmamap_create(dma_tag, size, maxsegs, size, 0, - BUS_DMA_WAITOK, &bi->dmamap); - if (ret != 0) - goto fail6; + /* fake buf for vmapbuf */ + bi->B.b_flags = B_PHYS; + bi->B.b_data = buf; + bi->B.b_proc = bi->proc; + ret = vmapbuf(&bi->B, size); + if (ret != 0) { + printf("%s: vmapbuf failed (%d)\n", __func__, ret); + uvm_vsunlock(bi->proc->p_vmspace, buf, size); + goto fail6; + } - ret = bus_dmamap_load(dma_tag, bi->dmamap, buf, size, - curproc, BUS_DMA_WAITOK | dmaflags); + ret = bus_dmamap_load(dma_tag, bi->dmamap, bi->B.b_data, bi->size, + NULL, BUS_DMA_WAITOK | dmaflags); + } else { + ret = bus_dmamap_load(dma_tag, bi->dmamap, bi->buf, bi->size, + bi->proc, BUS_DMA_WAITOK | dmaflags); + } if (ret != 0) goto fail7; @@ -415,11 +459,13 @@ vchiq_prepare_bulk_data(VCHIQ_BULK_T *bu return VCHIQ_SUCCESS; fail7: - bus_dmamap_destroy(dma_tag, bi->dmamap); + if (IS_USER_ADDRESS(bi->buf)) { + vunmapbuf(&bi->B, bi->size); + uvm_vsunlock(bi->proc->p_vmspace, bi->buf, bi->size); + } fail6: - if (IS_USER_ADDRESS(bi->buf)) - uvm_vsunlock(curproc->p_vmspace, bi->buf, bi->size); + bus_dmamap_destroy(dma_tag, bi->dmamap); fail5: bus_dmamap_unload(dma_tag, bi->pagelist_map); @@ -507,8 +553,10 @@ vchiq_complete_bulk(VCHIQ_BULK_T *bulk) } bus_dmamap_unload(dma_tag, bi->dmamap); bus_dmamap_destroy(dma_tag, bi->dmamap); - if (IS_USER_ADDRESS(bi->buf)) + if (IS_USER_ADDRESS(bi->buf)) { + vunmapbuf(&bi->B, bi->size); uvm_vsunlock(bi->proc->p_vmspace, bi->buf, bi->size); + } bus_dmamap_unload(dma_tag, bi->pagelist_map); bus_dmamap_destroy(dma_tag, bi->pagelist_map); @@ -517,6 +565,8 @@ vchiq_complete_bulk(VCHIQ_BULK_T *bulk) bus_dmamem_free(dma_tag, bi->pagelist_sgs, __arraycount(bi->pagelist_sgs)); kmem_free(bi, sizeof(*bi)); + + bulk->remote_data = NULL; } } Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_arm.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_arm.c,v retrieving revision 1.21 diff -p -u -r1.21 vchiq_arm.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_arm.c 22 Jan 2020 19:15:49 -0000 1.21 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_arm.c 21 Jan 2023 13:52:08 -0000 @@ -466,6 +466,11 @@ vchiq_ioctl(struct file *fp, u_long cmd, ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) && (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ? ioctl_names[_IOC_NR(cmd)] : "", arg); +printf("vchiq_ioctl - instance %p, cmd %s, arg %p\n", + instance, + ((_IOC_TYPE(cmd) == VCHIQ_IOC_MAGIC) && + (_IOC_NR(cmd) <= VCHIQ_IOC_MAX)) ? + ioctl_names[_IOC_NR(cmd)] : "", arg); switch (cmd) { case VCHIQ_IOC_SHUTDOWN: @@ -1585,12 +1590,12 @@ vchiq_get_state(void) if (g_state.remote == NULL) printk(KERN_ERR "%s: g_state.remote == NULL\n", __func__); - else if (g_state.remote->initialised != 1) + else if (le32toh(g_state.remote->initialised) != 1) printk(KERN_NOTICE "%s: g_state.remote->initialised != 1 (%d)\n", - __func__, g_state.remote->initialised); + __func__, le32toh(g_state.remote->initialised)); return ((g_state.remote != NULL) && - (g_state.remote->initialised == 1)) ? &g_state : NULL; + (le32toh(g_state.remote->initialised) == 1)) ? &g_state : NULL; } /* Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.c,v retrieving revision 1.15 diff -p -u -r1.15 vchiq_core.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.c 26 Sep 2020 12:58:23 -0000 1.15 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.c 21 Jan 2023 13:52:08 -0000 @@ -428,7 +428,7 @@ vchiq_set_conn_state(VCHIQ_STATE_T *stat static inline void remote_event_create(VCHIQ_STATE_T *state, REMOTE_EVENT_T *event) { - event->armed = 0; + event->armed = htole32(0); /* Don't clear the 'fired' flag because it may already have been set ** by the other side. */ _sema_init((struct semaphore *)((char *)state + event->event), 0); @@ -437,36 +437,41 @@ remote_event_create(VCHIQ_STATE_T *state static inline int remote_event_wait(VCHIQ_STATE_T *state, REMOTE_EVENT_T *event) { - if (!event->fired) { - event->armed = 1; + if (!le32toh(event->fired)) { + event->armed = htole32(1); dsb(sy); - if (!event->fired) { + if (!le32toh(event->fired)) { +//printf("remote_event_wait %d\n", event->event); if (down_interruptible( (struct semaphore *) ((char *)state + event->event)) != 0) { - event->armed = 0; +//printf("remote_event_wait failed %d\n", event->event); + event->armed = htole32(0); return 0; } } - event->armed = 0; + event->armed = htole32(0); wmb(); - } +//printf("remote_event_wait succeeded %d\n", event->event); + } else +//printf("remote_event_wait already fired %d\n", event->event); - event->fired = 0; + event->fired = htole32(0); return 1; } static inline void remote_event_signal_local(VCHIQ_STATE_T *state, REMOTE_EVENT_T *event) { - event->armed = 0; + event->armed = htole32(0); up((struct semaphore *)((char *)state + event->event)); } static inline void remote_event_poll(VCHIQ_STATE_T *state, REMOTE_EVENT_T *event) { - if (event->fired && event->armed) +//printf("remote_event_poll %u armed=%d fired=%d\n", event->event, le32toh(event->armed), le32toh(event->fired)); + if (le32toh(event->fired) && le32toh(event->armed)) remote_event_signal_local(state, event); } @@ -546,10 +551,10 @@ request_poll(VCHIQ_STATE_T *state, VCHIQ do { value = atomic_read(&state->poll_services[ - service->localport>>5]); + BITSET_WORD(service->localport)]); } while (atomic_cmpxchg( - &state->poll_services[service->localport>>5], - value, value | (1 << (service->localport & 0x1f))) + &state->poll_services[BITSET_WORD(service->localport)], + value, value | BITSET_BIT(service->localport)) != value); } @@ -575,8 +580,8 @@ reserve_space(VCHIQ_STATE_T *state, int WARN_ON(state->tx_data == NULL); header = (VCHIQ_HEADER_T *) (state->tx_data + (tx_pos & VCHIQ_SLOT_MASK)); - header->msgid = VCHIQ_MSGID_PADDING; - header->size = slot_space - sizeof(VCHIQ_HEADER_T); + header->msgid = htole32(VCHIQ_MSGID_PADDING); + header->size = htole32(slot_space - sizeof(VCHIQ_HEADER_T)); tx_pos += slot_space; } @@ -594,7 +599,7 @@ reserve_space(VCHIQ_STATE_T *state, int /* But first, flush through the last slot. */ state->local_tx_pos = tx_pos; - local->tx_pos = tx_pos; + local->tx_pos = htole32(tx_pos); remote_event_signal(&state->remote->trigger); if (!is_blocking || @@ -606,9 +611,9 @@ reserve_space(VCHIQ_STATE_T *state, int BUG_ON(tx_pos == (state->slot_queue_available * VCHIQ_SLOT_SIZE)); - slot_index = local->slot_queue[ + slot_index = le32toh(local->slot_queue[ SLOT_QUEUE_INDEX_FROM_POS(tx_pos) & - VCHIQ_SLOT_QUEUE_MASK]; + VCHIQ_SLOT_QUEUE_MASK]); state->tx_data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index); } @@ -635,10 +640,10 @@ process_free_queue(VCHIQ_STATE_T *state) ** values. */ mb(); - while (slot_queue_available != local->slot_queue_recycle) { + while (slot_queue_available != le32toh(local->slot_queue_recycle)) { unsigned int pos; - int slot_index = local->slot_queue[slot_queue_available++ & - VCHIQ_SLOT_QUEUE_MASK]; + int slot_index = le32toh(local->slot_queue[slot_queue_available++ & + VCHIQ_SLOT_QUEUE_MASK]); char *data = (char *)SLOT_DATA_FROM_INDEX(state, slot_index); int data_found = 0; @@ -646,7 +651,7 @@ process_free_queue(VCHIQ_STATE_T *state) vchiq_log_trace(vchiq_core_log_level, "%d: pfq %d=%p %x %x", state->id, slot_index, data, - local->slot_queue_recycle, slot_queue_available); + le32toh(local->slot_queue_recycle), slot_queue_available); /* Initialise the bitmask for services which have used this ** slot */ @@ -657,7 +662,7 @@ process_free_queue(VCHIQ_STATE_T *state) while (pos < VCHIQ_SLOT_SIZE) { VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)(data + pos); - int msgid = header->msgid; + int msgid = le32toh(header->msgid); if (VCHIQ_MSG_TYPE(msgid) == VCHIQ_MSG_DATA) { int port = VCHIQ_MSG_SRCPORT(msgid); VCHIQ_SERVICE_QUOTA_T *service_quota = @@ -686,8 +691,8 @@ process_free_queue(VCHIQ_STATE_T *state) service_quota-> message_use_count, header, msgid, - header->msgid, - header->size); + le32toh(header->msgid), + le32toh(header->size)); WARN(1, "invalid message use count\n"); } if (!BITSET_IS_SET(service_found, port)) { @@ -711,7 +716,7 @@ process_free_queue(VCHIQ_STATE_T *state) "%d: pfq:%d %x@%p - " "slot_use->%d", state->id, port, - header->size, + le32toh(header->size), header, count - 1); } else { @@ -727,8 +732,8 @@ process_free_queue(VCHIQ_STATE_T *state) port, count, header, msgid, - header->msgid, - header->size); + le32toh(header->msgid), + le32toh(header->size)); WARN(1, "bad slot use count\n"); } } @@ -736,13 +741,14 @@ process_free_queue(VCHIQ_STATE_T *state) data_found = 1; } - pos += calc_stride(header->size); + pos += calc_stride(le32toh(header->size)); if (pos > VCHIQ_SLOT_SIZE) { vchiq_log_error(vchiq_core_log_level, "pfq - pos %x: header %p, msgid %x, " "header->msgid %x, header->size %x", pos, header, msgid, - header->msgid, header->size); + le32toh(header->msgid), + le32toh(header->size)); WARN(1, "invalid slot position\n"); } } @@ -815,6 +821,7 @@ queue_message(VCHIQ_STATE_T *state, VCHI ** slots */ while ((tx_end_index != state->previous_data_index) && (state->data_use_count == state->data_quota)) { +//printf("wait for slots\n"); VCHIQ_STATS_INC(state, data_stalls); spin_unlock("a_spinlock); lmutex_unlock(&state->slot_mutex); @@ -848,6 +855,8 @@ queue_message(VCHIQ_STATE_T *state, VCHI msg_type_str(type), size, service_quota->message_use_count, service_quota->slot_use_count); +//printf("%d: qm:%d %s,%x - quota stall " "(msg %d, slot %d)\n", state->id, service->localport, msg_type_str(type), size, service_quota->message_use_count, service_quota->slot_use_count); + VCHIQ_SERVICE_STATS_INC(service, quota_stalls); lmutex_unlock(&state->slot_mutex); if (down_interruptible(&service_quota->quota_event) @@ -870,6 +879,7 @@ queue_message(VCHIQ_STATE_T *state, VCHI spin_unlock("a_spinlock); } +//printf("queue_message: reserve %u\n", stride); header = reserve_space(state, stride, flags & QMFLAGS_IS_BLOCKING); if (!header) { @@ -894,6 +904,7 @@ queue_message(VCHIQ_STATE_T *state, VCHI header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); +//printf("%d: qm %s@%p,%x (%d->%d)\n", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); BUG_ON(!service); BUG_ON((flags & (QMFLAGS_NO_MUTEX_LOCK | @@ -902,6 +913,7 @@ queue_message(VCHIQ_STATE_T *state, VCHI for (i = 0, pos = 0; i < (unsigned int)count; pos += elements[i++].size) if (elements[i].size) { +//printf("copy_from_user(%d): %p + %d <= %p / %zu\n",i,header->data,pos,elements[i].data, (size_t)elements[i].size); if (vchiq_copy_from_user (header->data + pos, elements[i].data, (size_t) elements[i].size) != @@ -944,11 +956,14 @@ queue_message(VCHIQ_STATE_T *state, VCHI spin_unlock("a_spinlock); if (slot_use_count) +{ vchiq_log_trace(vchiq_core_log_level, "%d: qm:%d %s,%x - slot_use->%d (hdr %p)", state->id, service->localport, msg_type_str(VCHIQ_MSG_TYPE(msgid)), size, slot_use_count, header); +//printf("%d: qm:%d %s,%x - slot_use->%d (hdr %p)\n", state->id, service->localport, msg_type_str(VCHIQ_MSG_TYPE(msgid)), size, slot_use_count, header); +} VCHIQ_SERVICE_STATS_INC(service, ctrl_tx_count); VCHIQ_SERVICE_STATS_ADD(service, ctrl_tx_bytes, size); @@ -959,6 +974,8 @@ queue_message(VCHIQ_STATE_T *state, VCHI header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); +//printf("%d: qm %s@%p,%x (%d->%d)\n", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); + if (size != 0) { WARN_ON(!((count == 1) && (size == elements[0].size))); memcpy(header->data, elements[0].data, @@ -967,8 +984,8 @@ queue_message(VCHIQ_STATE_T *state, VCHI VCHIQ_STATS_INC(state, ctrl_tx_count); } - header->msgid = msgid; - header->size = size; + header->msgid = htole32(msgid); + header->size = htole32(size); { int svc_fourcc; @@ -985,13 +1002,15 @@ queue_message(VCHIQ_STATE_T *state, VCHI VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid), size); +//printf("Sent Msg %s(%u) to %c%c%c%c s:%u d:%d len:%d\n", msg_type_str(VCHIQ_MSG_TYPE(msgid)), VCHIQ_MSG_TYPE(msgid), VCHIQ_FOURCC_AS_4CHARS(svc_fourcc), VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid), size); } /* Make sure the new header is visible to the peer. */ wmb(); /* Make the new tx_pos visible to the peer. */ - local->tx_pos = state->local_tx_pos; + local->tx_pos = htole32(state->local_tx_pos); +//printf("new tx_pos = %d\n", le32toh(local->tx_pos)); wmb(); if (service && (type == VCHIQ_MSG_CLOSE)) @@ -1000,6 +1019,7 @@ queue_message(VCHIQ_STATE_T *state, VCHI if (!(flags & QMFLAGS_NO_MUTEX_UNLOCK)) lmutex_unlock(&state->slot_mutex); +//printf("trigger\n"); remote_event_signal(&state->remote->trigger); return VCHIQ_SUCCESS; @@ -1020,15 +1040,16 @@ queue_message_sync(VCHIQ_STATE_T *state, (lmutex_lock_interruptible(&state->sync_mutex) != 0)) return VCHIQ_RETRY; +//printf("sync_release wait\n"); remote_event_wait(state, &local->sync_release); rmb(); header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, - local->slot_sync); + le32toh(local->slot_sync)); { - int oldmsgid = header->msgid; + int oldmsgid = le32toh(header->msgid); if (oldmsgid != VCHIQ_MSGID_PADDING) vchiq_log_error(vchiq_core_log_level, "%d: qms - msgid %x, not PADDING", @@ -1044,10 +1065,12 @@ queue_message_sync(VCHIQ_STATE_T *state, header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); +//printf("%d: qms %s@%p,%x (%d->%d)\n", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); for (i = 0, pos = 0; i < (unsigned int)count; pos += elements[i++].size) if (elements[i].size) { +//printf("copy_from_user(%d): %p + %d <= %p / %zu\n",i,header->data,pos,elements[i].data, (size_t)elements[i].size); if (vchiq_copy_from_user (header->data + pos, elements[i].data, (size_t) elements[i].size) != @@ -1073,6 +1096,8 @@ queue_message_sync(VCHIQ_STATE_T *state, header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); +//printf("%d: qms %s@%p,%x (%d->%d)\n", state->id, msg_type_str(VCHIQ_MSG_TYPE(msgid)), header, size, VCHIQ_MSG_SRCPORT(msgid), VCHIQ_MSG_DSTPORT(msgid)); + if (size != 0) { WARN_ON(!((count == 1) && (size == elements[0].size))); memcpy(header->data, elements[0].data, @@ -1081,8 +1106,8 @@ queue_message_sync(VCHIQ_STATE_T *state, VCHIQ_STATS_INC(state, ctrl_tx_count); } - header->size = size; - header->msgid = msgid; + header->size = htole32(size); + header->msgid = htole32(msgid); if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) { int svc_fourcc; @@ -1104,6 +1129,7 @@ queue_message_sync(VCHIQ_STATE_T *state, /* Make sure the new header is visible to the peer. */ wmb(); +//printf("sync_trigger\n"); remote_event_signal(&state->remote->sync_trigger); if (VCHIQ_MSG_TYPE(msgid) != VCHIQ_MSG_PAUSE) @@ -1127,7 +1153,7 @@ release_slot(VCHIQ_STATE_T *state, VCHIQ lmutex_lock(&state->recycle_mutex); if (header) { - int msgid = header->msgid; + int msgid = le32toh(header->msgid); if (((msgid & VCHIQ_MSGID_CLAIMED) == 0) || (service && service->closing)) { lmutex_unlock(&state->recycle_mutex); @@ -1136,7 +1162,7 @@ release_slot(VCHIQ_STATE_T *state, VCHIQ /* Rewrite the message header to prevent a double ** release */ - header->msgid = msgid & ~VCHIQ_MSGID_CLAIMED; + header->msgid = htole32(msgid & ~VCHIQ_MSGID_CLAIMED); } release_count = slot_info->release_count; @@ -1151,18 +1177,19 @@ release_slot(VCHIQ_STATE_T *state, VCHIQ ** mutex. */ rmb(); - slot_queue_recycle = state->remote->slot_queue_recycle; + slot_queue_recycle = le32toh(state->remote->slot_queue_recycle); state->remote->slot_queue[slot_queue_recycle & VCHIQ_SLOT_QUEUE_MASK] = - SLOT_INDEX_FROM_INFO(state, slot_info); - state->remote->slot_queue_recycle = slot_queue_recycle + 1; + htole32(SLOT_INDEX_FROM_INFO(state, slot_info)); + state->remote->slot_queue_recycle = htole32(slot_queue_recycle + 1); vchiq_log_info(vchiq_core_log_level, "%d: release_slot %d - recycle->%x", state->id, SLOT_INDEX_FROM_INFO(state, slot_info), - state->remote->slot_queue_recycle); + le32toh(state->remote->slot_queue_recycle)); /* A write barrier is necessary, but remote_event_signal ** contains one. */ +//printf("recycle\n"); remote_event_signal(&state->remote->recycle); } @@ -1181,6 +1208,7 @@ notify_bulks(VCHIQ_SERVICE_T *service, V service->state->id, service->localport, (queue == &service->bulk_tx) ? 't' : 'r', queue->process, queue->remote_notify, queue->remove); +//printf("%d: nb:%d %cx - p=%x rn=%x r=%x\n", service->state->id, service->localport, (queue == &service->bulk_tx) ? 't' : 'r', queue->process, queue->remote_notify, queue->remove); if (service->state->is_master) { while (queue->remote_notify != queue->process) { @@ -1293,6 +1321,7 @@ poll_services(VCHIQ_STATE_T *state) continue; service_flags = atomic_xchg(&service->poll_flags, 0); +//printf("poll g=%d i=%d flags=%08x\n", group, i, service_flags); if (service_flags & (1 << VCHIQ_POLL_REMOVE)) { vchiq_log_info(vchiq_core_log_level, @@ -1355,6 +1384,7 @@ resolve_bulks(VCHIQ_SERVICE_T *service, (queue == &service->bulk_tx) ? 't' : 'r', queue->local_insert, queue->remote_insert, queue->process); +//printf("%d: rb:%d %cx - li=%x ri=%x p=%x\n", state->id, service->localport, (queue == &service->bulk_tx) ? 't' : 'r', queue->local_insert, queue->remote_insert, queue->process); WARN_ON(!((int)(queue->local_insert - queue->process) > 0)); WARN_ON(!((int)(queue->remote_insert - queue->process) > 0)); @@ -1409,6 +1439,8 @@ abort_outstanding_bulks(VCHIQ_SERVICE_T "%d: aob:%d %cx - li=%x ri=%x p=%x", service->state->id, service->localport, is_tx ? 't' : 'r', queue->local_insert, queue->remote_insert, queue->process); +//printf("%d: aob:%d %cx - li=%x ri=%x p=%x\n", service->state->id, service->localport, is_tx ? 't' : 'r', queue->local_insert, queue->remote_insert, queue->process); + WARN_ON(!((int)(queue->local_insert - queue->process) >= 0)); WARN_ON(!((int)(queue->remote_insert - queue->process) >= 0)); @@ -1513,8 +1545,8 @@ parse_open(VCHIQ_STATE_T *state, VCHIQ_H int msgid, size; unsigned int localport, remoteport; - msgid = header->msgid; - size = header->size; + msgid = le32toh(header->msgid); + size = le32toh(header->size); //int type = VCHIQ_MSG_TYPE(msgid); localport = VCHIQ_MSG_DSTPORT(msgid); remoteport = VCHIQ_MSG_SRCPORT(msgid); @@ -1523,7 +1555,7 @@ parse_open(VCHIQ_STATE_T *state, VCHIQ_H (struct vchiq_open_payload *)header->data; unsigned int fourcc; - fourcc = payload->fourcc; + fourcc = le32toh(payload->fourcc); vchiq_log_info(vchiq_core_log_level, "%d: prs OPEN@%p (%d->'%c%c%c%c')", state->id, header, @@ -1534,8 +1566,8 @@ parse_open(VCHIQ_STATE_T *state, VCHIQ_H if (service) { /* A matching service exists */ - short v = payload->version; - short version_min = payload->version_min; + short v = le16toh(payload->version); + short version_min = le16toh(payload->version_min); if ((service->version < version_min) || (v < service->version_min)) { /* Version mismatch */ @@ -1555,7 +1587,7 @@ parse_open(VCHIQ_STATE_T *state, VCHIQ_H if (service->srvstate == VCHIQ_SRVSTATE_LISTENING) { struct vchiq_openack_payload ack_payload = { - service->version + htole32(service->version) }; VCHIQ_ELEMENT_T body = { &ack_payload, @@ -1635,8 +1667,9 @@ parse_rx_slots(VCHIQ_STATE_T *state) int tx_pos; DEBUG_INITIALISE(state->local) - tx_pos = remote->tx_pos; + tx_pos = le32toh(remote->tx_pos); +//printf("parse_rx %d != %d\n", state->rx_pos, tx_pos); while (state->rx_pos != tx_pos) { VCHIQ_HEADER_T *header; int msgid, size; @@ -1647,9 +1680,9 @@ parse_rx_slots(VCHIQ_STATE_T *state) if (!state->rx_data) { int rx_index; WARN_ON(!((state->rx_pos & VCHIQ_SLOT_MASK) == 0)); - rx_index = remote->slot_queue[ + rx_index = le32toh(remote->slot_queue[ SLOT_QUEUE_INDEX_FROM_POS(state->rx_pos) & - VCHIQ_SLOT_QUEUE_MASK]; + VCHIQ_SLOT_QUEUE_MASK]); state->rx_data = (char *)SLOT_DATA_FROM_INDEX(state, rx_index); state->rx_info = SLOT_INFO_FROM_INDEX(state, rx_index); @@ -1664,12 +1697,13 @@ parse_rx_slots(VCHIQ_STATE_T *state) header = (VCHIQ_HEADER_T *)(state->rx_data + (state->rx_pos & VCHIQ_SLOT_MASK)); DEBUG_VALUE(PARSE_HEADER, (int)(intptr_t)header); - msgid = header->msgid; + msgid = le32toh(header->msgid); DEBUG_VALUE(PARSE_MSGID, msgid); - size = header->size; + size = le32toh(header->size); type = VCHIQ_MSG_TYPE(msgid); localport = VCHIQ_MSG_DSTPORT(msgid); remoteport = VCHIQ_MSG_SRCPORT(msgid); +//printf("received msgid=%u size=%u\n", msgid, size); if (type != VCHIQ_MSG_DATA) VCHIQ_STATS_INC(state, ctrl_rx_count); @@ -1757,7 +1791,7 @@ parse_rx_slots(VCHIQ_STATE_T *state) const struct vchiq_openack_payload *payload = (struct vchiq_openack_payload *) header->data; - service->peer_version = payload->version; + service->peer_version = le16toh(payload->version); } vchiq_log_info(vchiq_core_log_level, "%d: prs OPENACK@%p,%x (%d->%d) v:%d", @@ -1803,7 +1837,7 @@ parse_rx_slots(VCHIQ_STATE_T *state) if ((service->remoteport == remoteport) && (service->srvstate == VCHIQ_SRVSTATE_OPEN)) { - header->msgid = msgid | VCHIQ_MSGID_CLAIMED; + header->msgid = htole32(msgid | VCHIQ_MSGID_CLAIMED); claim_slot(state->rx_info); DEBUG_TRACE(PARSE_LINE); if (make_service_callback(service, @@ -1823,8 +1857,8 @@ parse_rx_slots(VCHIQ_STATE_T *state) vchiq_log_info(vchiq_core_log_level, "%d: prs CONNECT@%p", state->id, header); - state->version_common = ((VCHIQ_SLOT_ZERO_T *) - state->slot_data)->version; + state->version_common = le32toh(((VCHIQ_SLOT_ZERO_T *) + state->slot_data)->version); up(&state->connect); break; case VCHIQ_MSG_BULK_RX: @@ -2059,12 +2093,14 @@ slot_handler_func(void *v) while (1) { DEBUG_COUNT(SLOT_HANDLER_COUNT); DEBUG_TRACE(SLOT_HANDLER_LINE); +//printf("trigger wait\n"); remote_event_wait(state, &local->trigger); rmb(); DEBUG_TRACE(SLOT_HANDLER_LINE); if (state->poll_needed) { +//printf("poll_needed\n"); /* Check if we need to suspend - may change our * conn_state */ vchiq_platform_check_suspend(state); @@ -2073,6 +2109,7 @@ slot_handler_func(void *v) /* Handle service polling and other rare conditions here ** out of the mainline code */ +//printf("conn_state %d\n", state->conn_state); switch (state->conn_state) { case VCHIQ_CONNSTATE_CONNECTED: /* Poll the services as requested */ @@ -2149,6 +2186,7 @@ recycle_func(void *v) VCHIQ_SHARED_STATE_T *local = state->local; while (1) { +//printf("recycle wait\n"); remote_event_wait(state, &local->recycle); process_free_queue(state); @@ -2165,7 +2203,7 @@ sync_func(void *v) VCHIQ_STATE_T *state = (VCHIQ_STATE_T *) v; VCHIQ_SHARED_STATE_T *local = state->local; VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, - state->remote->slot_sync); + le32toh(state->remote->slot_sync)); while (1) { VCHIQ_SERVICE_T *service; @@ -2173,18 +2211,18 @@ sync_func(void *v) int type; unsigned int localport, remoteport; +//printf("sync_trigger wait\n"); remote_event_wait(state, &local->sync_trigger); rmb(); - msgid = header->msgid; - size = header->size; + msgid = le32toh(header->msgid); + size = le32toh(header->size); type = VCHIQ_MSG_TYPE(msgid); localport = VCHIQ_MSG_DSTPORT(msgid); remoteport = VCHIQ_MSG_SRCPORT(msgid); service = find_service_by_port(state, localport); - if (!service) { vchiq_log_error(vchiq_sync_log_level, "%d: sf %s@%p (%d->%d) - " @@ -2192,11 +2230,13 @@ sync_func(void *v) state->id, msg_type_str(type), header, remoteport, localport, localport); +//printf("%d: sf %s@%p (%d->%d) - " "invalid/closed service %d\n", state->id, msg_type_str(type), header, remoteport, localport, localport); + release_message_sync(state, header); continue; } - if (vchiq_sync_log_level >= VCHIQ_LOG_TRACE) { + if (1 || vchiq_sync_log_level >= VCHIQ_LOG_TRACE) { int svc_fourcc; svc_fourcc = service @@ -2207,6 +2247,7 @@ sync_func(void *v) msg_type_str(type), VCHIQ_FOURCC_AS_4CHARS(svc_fourcc), remoteport, localport, size); +//printf("Rcvd Msg %s from %c%c%c%c s:%d d:%d len:%d\n", msg_type_str(type), VCHIQ_FOURCC_AS_4CHARS(svc_fourcc), remoteport, localport, size); if (size > 0) vchiq_log_dump_mem("Rcvd", 0, header->data, min(16, size)); @@ -2218,7 +2259,7 @@ sync_func(void *v) const struct vchiq_openack_payload *payload = (struct vchiq_openack_payload *) header->data; - service->peer_version = payload->version; + service->peer_version = le32toh(payload->version); } vchiq_log_info(vchiq_sync_log_level, "%d: sf OPENACK@%p,%x (%d->%d) v:%d", @@ -2296,6 +2337,10 @@ vchiq_init_slots(void *mem_base, int mem int num_slots = (mem_size - mem_align)/VCHIQ_SLOT_SIZE; int first_data_slot = VCHIQ_SLOT_ZERO_SLOTS; +//printf("init_slots %p + %d = %p\n", (char *)mem_base, mem_align, slot_zero); +//printf("num_slots %d\n", num_slots); +//printf("first_data_slot %d\n", first_data_slot); + /* Ensure there is enough memory to run an absolutely minimum system */ num_slots -= first_data_slot; @@ -2308,20 +2353,20 @@ vchiq_init_slots(void *mem_base, int mem memset(slot_zero, 0, sizeof(VCHIQ_SLOT_ZERO_T)); - slot_zero->magic = VCHIQ_MAGIC; - slot_zero->version = VCHIQ_VERSION; - slot_zero->version_min = VCHIQ_VERSION_MIN; - slot_zero->slot_zero_size = sizeof(VCHIQ_SLOT_ZERO_T); - slot_zero->slot_size = VCHIQ_SLOT_SIZE; - slot_zero->max_slots = VCHIQ_MAX_SLOTS; - slot_zero->max_slots_per_side = VCHIQ_MAX_SLOTS_PER_SIDE; - - slot_zero->master.slot_sync = first_data_slot; - slot_zero->master.slot_first = first_data_slot + 1; - slot_zero->master.slot_last = first_data_slot + (num_slots/2) - 1; - slot_zero->slave.slot_sync = first_data_slot + (num_slots/2); - slot_zero->slave.slot_first = first_data_slot + (num_slots/2) + 1; - slot_zero->slave.slot_last = first_data_slot + num_slots - 1; + slot_zero->magic = htole32(VCHIQ_MAGIC); + slot_zero->version = htole16(VCHIQ_VERSION); + slot_zero->version_min = htole16(VCHIQ_VERSION_MIN); + slot_zero->slot_zero_size = htole32(sizeof(VCHIQ_SLOT_ZERO_T)); + slot_zero->slot_size = htole32(VCHIQ_SLOT_SIZE); + slot_zero->max_slots = htole32(VCHIQ_MAX_SLOTS); + slot_zero->max_slots_per_side = htole32(VCHIQ_MAX_SLOTS_PER_SIDE); + + slot_zero->master.slot_sync = htole32(first_data_slot); + slot_zero->master.slot_first = htole32(first_data_slot + 1); + slot_zero->master.slot_last = htole32(first_data_slot + (num_slots/2) - 1); + slot_zero->slave.slot_sync = htole32(first_data_slot + (num_slots/2)); + slot_zero->slave.slot_first = htole32(first_data_slot + (num_slots/2) + 1); + slot_zero->slave.slot_last = htole32(first_data_slot + num_slots - 1); return slot_zero; } @@ -2347,11 +2392,11 @@ vchiq_init_state(VCHIQ_STATE_T *state, V /* Check the input configuration */ - if (slot_zero->magic != VCHIQ_MAGIC) { + if (le32toh(slot_zero->magic) != VCHIQ_MAGIC) { vchiq_loud_error_header(); vchiq_loud_error("Invalid VCHIQ magic value found."); vchiq_loud_error("slot_zero=%p: magic=%x (expected %x)", - slot_zero, slot_zero->magic, VCHIQ_MAGIC); + slot_zero, le32toh(slot_zero->magic), VCHIQ_MAGIC); vchiq_loud_error_footer(); return VCHIQ_ERROR; } @@ -2359,65 +2404,65 @@ vchiq_init_state(VCHIQ_STATE_T *state, V vchiq_log_warning(vchiq_core_log_level, "local ver %d (min %d), remote ver %d.", VCHIQ_VERSION, VCHIQ_VERSION_MIN, - slot_zero->version); + le32toh(slot_zero->version)); - if (slot_zero->version < VCHIQ_VERSION_MIN) { + if (le16toh(slot_zero->version) < VCHIQ_VERSION_MIN) { vchiq_loud_error_header(); vchiq_loud_error("Incompatible VCHIQ versions found."); vchiq_loud_error("slot_zero=%p: VideoCore version=%d " "(minimum %d)", - slot_zero, slot_zero->version, + slot_zero, le16toh(slot_zero->version), VCHIQ_VERSION_MIN); vchiq_loud_error("Restart with a newer VideoCore image."); vchiq_loud_error_footer(); return VCHIQ_ERROR; } - if (VCHIQ_VERSION < slot_zero->version_min) { + if (VCHIQ_VERSION < le16toh(slot_zero->version_min)) { vchiq_loud_error_header(); vchiq_loud_error("Incompatible VCHIQ versions found."); vchiq_loud_error("slot_zero=%p: version=%d (VideoCore " "minimum %d)", slot_zero, VCHIQ_VERSION, - slot_zero->version_min); + le16toh(slot_zero->version_min)); vchiq_loud_error("Restart with a newer kernel."); vchiq_loud_error_footer(); return VCHIQ_ERROR; } - if ((slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) || - (slot_zero->slot_size != VCHIQ_SLOT_SIZE) || - (slot_zero->max_slots != VCHIQ_MAX_SLOTS) || - (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE)) { + if ((le32toh(slot_zero->slot_zero_size) != sizeof(VCHIQ_SLOT_ZERO_T)) || + (le32toh(slot_zero->slot_size) != VCHIQ_SLOT_SIZE) || + (le32toh(slot_zero->max_slots) != VCHIQ_MAX_SLOTS) || + (le32toh(slot_zero->max_slots_per_side) != VCHIQ_MAX_SLOTS_PER_SIDE)) { vchiq_loud_error_header(); - if (slot_zero->slot_zero_size != sizeof(VCHIQ_SLOT_ZERO_T)) + if (le32toh(slot_zero->slot_zero_size) != sizeof(VCHIQ_SLOT_ZERO_T)) vchiq_loud_error("slot_zero=%p: slot_zero_size=%x " "(expected %zx)", slot_zero, - slot_zero->slot_zero_size, + le32toh(slot_zero->slot_zero_size), sizeof(VCHIQ_SLOT_ZERO_T)); - if (slot_zero->slot_size != VCHIQ_SLOT_SIZE) + if (le32toh(slot_zero->slot_size) != VCHIQ_SLOT_SIZE) vchiq_loud_error("slot_zero=%p: slot_size=%d " "(expected %d", - slot_zero, slot_zero->slot_size, + slot_zero, le32toh(slot_zero->slot_size), VCHIQ_SLOT_SIZE); - if (slot_zero->max_slots != VCHIQ_MAX_SLOTS) + if (le32toh(slot_zero->max_slots) != VCHIQ_MAX_SLOTS) vchiq_loud_error("slot_zero=%p: max_slots=%d " "(expected %d)", - slot_zero, slot_zero->max_slots, + slot_zero, le32toh(slot_zero->max_slots), VCHIQ_MAX_SLOTS); - if (slot_zero->max_slots_per_side != VCHIQ_MAX_SLOTS_PER_SIDE) + if (le32toh(slot_zero->max_slots_per_side) != VCHIQ_MAX_SLOTS_PER_SIDE) vchiq_loud_error("slot_zero=%p: max_slots_per_side=%d " "(expected %d)", slot_zero, - slot_zero->max_slots_per_side, + le32toh(slot_zero->max_slots_per_side), VCHIQ_MAX_SLOTS_PER_SIDE); vchiq_loud_error_footer(); return VCHIQ_ERROR; } - if (VCHIQ_VERSION < slot_zero->version) - slot_zero->version = VCHIQ_VERSION; + if (VCHIQ_VERSION < le16toh(slot_zero->version)) + slot_zero->version = htole16(VCHIQ_VERSION); if (is_master) { local = &slot_zero->master; @@ -2427,9 +2472,9 @@ vchiq_init_state(VCHIQ_STATE_T *state, V remote = &slot_zero->master; } - if (local->initialised) { + if (le32toh(local->initialised)) { vchiq_loud_error_header(); - if (remote->initialised) + if (le32toh(remote->initialised)) vchiq_loud_error("local state has already been " "initialised"); else @@ -2449,6 +2494,7 @@ vchiq_init_state(VCHIQ_STATE_T *state, V state->local = local; state->remote = remote; +//printf("local %p remote %p\n", local, remote); state->slot_data = (VCHIQ_SLOT_T *)slot_zero; /* @@ -2468,15 +2514,15 @@ vchiq_init_state(VCHIQ_STATE_T *state, V _sema_init(&state->data_quota_event, 0); state->slot_queue_available = 0; - for (i = 0; i < VCHIQ_MAX_SERVICES; i++) { VCHIQ_SERVICE_QUOTA_T *service_quota = &state->service_quotas[i]; _sema_init(&service_quota->quota_event, 0); } +//printf("ok\n"); - for (i = local->slot_first; i <= local->slot_last; i++) { - local->slot_queue[state->slot_queue_available++] = i; + for (i = le32toh(local->slot_first); i <= le32toh(local->slot_last); i++) { + local->slot_queue[state->slot_queue_available++] = htole32(i); up(&state->slot_available_event); } @@ -2491,24 +2537,28 @@ vchiq_init_state(VCHIQ_STATE_T *state, V local->trigger.event = offsetof(VCHIQ_STATE_T, trigger_event); remote_event_create(state, &local->trigger); - local->tx_pos = 0; + local->tx_pos = htole32(0); +//printf("trigger %d at %d\n", local->trigger.event, le32toh(local->tx_pos)); local->recycle.event = offsetof(VCHIQ_STATE_T, recycle_event); remote_event_create(state, &local->recycle); - local->slot_queue_recycle = state->slot_queue_available; + local->slot_queue_recycle = htole32(state->slot_queue_available); +//printf("recycle %d at %d\n", local->recycle.event, le32toh(local->slot_queue_recycle)); local->sync_trigger.event = offsetof(VCHIQ_STATE_T, sync_trigger_event); remote_event_create(state, &local->sync_trigger); +//printf("sync_trigger %d\n", local->sync_trigger.event); local->sync_release.event = offsetof(VCHIQ_STATE_T, sync_release_event); remote_event_create(state, &local->sync_release); +//printf("sync_release %d\n", local->sync_release.event); /* At start-of-day, the slot is empty and available */ - ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, local->slot_sync))->msgid + ((VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, le32toh(local->slot_sync)))->msgid = VCHIQ_MSGID_PADDING; remote_event_signal_local(state, &local->sync_release); - local->debug[DEBUG_ENTRIES] = DEBUG_MAX; + local->debug[DEBUG_ENTRIES] = htole32(DEBUG_MAX); status = vchiq_platform_init_state(state); if (status != VCHIQ_SUCCESS) @@ -2561,11 +2611,12 @@ vchiq_init_state(VCHIQ_STATE_T *state, V vchiq_states[0] = state; /* Indicate readiness to the other side */ - local->initialised = 1; + local->initialised = htole32(1); vchiq_log_info(vchiq_core_log_level, "%s: local initialized\n", __func__); +//printf("local initialized %d\n", (int)status); return status; } @@ -2714,10 +2765,10 @@ VCHIQ_STATUS_T vchiq_open_service_internal(VCHIQ_SERVICE_T *service, int client_id) { struct vchiq_open_payload payload = { - service->base.fourcc, - client_id, - service->version, - service->version_min + htole32(service->base.fourcc), + htole32(client_id), + htole16(service->version), + htole16(service->version_min) }; VCHIQ_ELEMENT_T body = { &payload, sizeof(payload) }; VCHIQ_STATUS_T status = VCHIQ_SUCCESS; @@ -2752,7 +2803,7 @@ static void release_service_messages(VCHIQ_SERVICE_T *service) { VCHIQ_STATE_T *state = service->state; - int slot_last = state->remote->slot_last; + int slot_last = le32toh(state->remote->slot_last); int i; /* Release any claimed messages aimed at this service */ @@ -2760,14 +2811,14 @@ release_service_messages(VCHIQ_SERVICE_T if (service->sync) { VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)SLOT_DATA_FROM_INDEX(state, - state->remote->slot_sync); + le32toh(state->remote->slot_sync)); if (VCHIQ_MSG_DSTPORT(header->msgid) == service->localport) release_message_sync(state, header); return; } - for (i = state->remote->slot_first; i <= slot_last; i++) { + for (i = le32toh(state->remote->slot_first); i <= slot_last; i++) { VCHIQ_SLOT_INFO_T *slot_info = SLOT_INFO_FROM_INDEX(state, i); if (slot_info->release_count != slot_info->use_count) { @@ -2786,7 +2837,7 @@ release_service_messages(VCHIQ_SERVICE_T while (pos < end) { VCHIQ_HEADER_T *header = (VCHIQ_HEADER_T *)(data + pos); - int msgid = header->msgid; + int msgid = le32toh(header->msgid); int port = VCHIQ_MSG_DSTPORT(msgid); if ((port == service->localport) && (msgid & VCHIQ_MSGID_CLAIMED)) { @@ -2796,15 +2847,15 @@ release_service_messages(VCHIQ_SERVICE_T release_slot(state, slot_info, header, NULL); } - pos += calc_stride(header->size); + pos += calc_stride(le32toh(header->size)); if (pos > VCHIQ_SLOT_SIZE) { vchiq_log_error(vchiq_core_log_level, "fsi - pos %x: header %p, " "msgid %x, header->msgid %x, " "header->size %x", pos, header, - msgid, header->msgid, - header->size); + msgid, le32toh(header->msgid), + le32toh(header->size)); WARN(1, "invalid slot position\n"); } } @@ -3398,7 +3449,9 @@ vchiq_bulk_transfer(VCHIQ_SERVICE_HANDLE (dir == VCHIQ_BULK_TRANSMIT) ? VCHIQ_POLL_TXNOTIFY : VCHIQ_POLL_RXNOTIFY); } else { - int payload[2] = { (int)(uintptr_t)bulk->data, bulk->size }; + int payload[2] = { + htole32((int)(uintptr_t)bulk->data), + htole32(bulk->size) }; VCHIQ_ELEMENT_T element = { payload, sizeof(payload) }; status = queue_message(state, NULL, @@ -3523,16 +3576,16 @@ vchiq_release_message(VCHIQ_SERVICE_HAND slot_index = SLOT_INDEX_FROM_DATA(state, (void *)header); - if ((slot_index >= remote->slot_first) && - (slot_index <= remote->slot_last)) { - int msgid = header->msgid; + if ((slot_index >= le32toh(remote->slot_first)) && + (slot_index <= le32toh(remote->slot_last))) { + int msgid = le32toh(header->msgid); if (msgid & VCHIQ_MSGID_CLAIMED) { VCHIQ_SLOT_INFO_T *slot_info = SLOT_INFO_FROM_INDEX(state, slot_index); release_slot(state, slot_info, header, service); } - } else if (slot_index == remote->slot_sync) + } else if (slot_index == le32toh(remote->slot_sync)) release_message_sync(state, header); unlock_service(service); @@ -3541,7 +3594,7 @@ vchiq_release_message(VCHIQ_SERVICE_HAND static void release_message_sync(VCHIQ_STATE_T *state, VCHIQ_HEADER_T *header) { - header->msgid = VCHIQ_MSGID_PADDING; + header->msgid = htole32(VCHIQ_MSGID_PADDING); wmb(); remote_event_signal(&state->remote->sync_release); } @@ -3689,15 +3742,15 @@ vchiq_dump_shared_state(void *dump_conte int len; len = snprintf(buf, sizeof(buf), " %s: slots %d-%d tx_pos=%x recycle=%x", - label, shared->slot_first, shared->slot_last, - shared->tx_pos, shared->slot_queue_recycle); + label, le32toh(shared->slot_first), le32toh(shared->slot_last), + le32toh(shared->tx_pos), le32toh(shared->slot_queue_recycle)); vchiq_dump(dump_context, buf, len + 1); len = snprintf(buf, sizeof(buf), " Slots claimed:"); vchiq_dump(dump_context, buf, len + 1); - for (i = shared->slot_first; i <= shared->slot_last; i++) { + for (i = le32toh(shared->slot_first); i <= le32toh(shared->slot_last); i++) { VCHIQ_SLOT_INFO_T slot_info = *SLOT_INFO_FROM_INDEX(state, i); if (slot_info.use_count != slot_info.release_count) { len = snprintf(buf, sizeof(buf), @@ -3707,9 +3760,9 @@ vchiq_dump_shared_state(void *dump_conte } } - for (i = 1; i < shared->debug[DEBUG_ENTRIES]; i++) { + for (i = 1; i < le32toh(shared->debug[DEBUG_ENTRIES]); i++) { len = snprintf(buf, sizeof(buf), " DEBUG: %s = %d(%x)", - debug_names[i], shared->debug[i], shared->debug[i]); + debug_names[i], le32toh(shared->debug[i]), le32toh(shared->debug[i])); vchiq_dump(dump_context, buf, len + 1); } } @@ -3727,7 +3780,7 @@ vchiq_dump_state(void *dump_context, VCH len = snprintf(buf, sizeof(buf), " tx_pos=%x(@%x), rx_pos=%x(@%x)", - state->local->tx_pos, + le32toh(state->local->tx_pos), (uint32_t)(uintptr_t)state->tx_data + (state->local_tx_pos & VCHIQ_SLOT_MASK), state->rx_pos, @@ -3755,7 +3808,7 @@ vchiq_dump_state(void *dump_context, VCH ((state->slot_queue_available * VCHIQ_SLOT_SIZE) - state->local_tx_pos) / VCHIQ_SLOT_SIZE, state->data_quota - state->data_use_count, - state->local->slot_queue_recycle - state->slot_queue_available, + le32toh(state->local->slot_queue_recycle) - state->slot_queue_available, state->stats.slot_stalls, state->stats.data_stalls); vchiq_dump(dump_context, buf, len + 1); Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.h =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.h,v retrieving revision 1.8 diff -p -u -r1.8 vchiq_core.h --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.h 3 Nov 2020 12:04:56 -0000 1.8 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_core.h 21 Jan 2023 13:52:08 -0000 @@ -187,11 +187,11 @@ enum { #define DEBUG_INITIALISE(local) int *debug_ptr = (local)->debug; #define DEBUG_TRACE(d) \ - do { debug_ptr[DEBUG_ ## d] = __LINE__; dsb(sy); } while (0) + do { debug_ptr[DEBUG_ ## d] = htole32(__LINE__); dsb(sy); } while (0) #define DEBUG_VALUE(d, v) \ - do { debug_ptr[DEBUG_ ## d] = (v); dsb(sy); } while (0) + do { debug_ptr[DEBUG_ ## d] = htole32((v)); dsb(sy); } while (0) #define DEBUG_COUNT(d) \ - do { debug_ptr[DEBUG_ ## d]++; dsb(sy); } while (0) + do { debug_ptr[DEBUG_ ## d] = htole32(le32toh(debug_ptr[DEBUG_ ## d]) + 1); dsb(sy); } while (0) #else /* VCHIQ_ENABLE_DEBUG */ Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_kmod_netbsd.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_kmod_netbsd.c,v retrieving revision 1.12 diff -p -u -r1.12 vchiq_kmod_netbsd.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_kmod_netbsd.c 26 Sep 2020 12:58:23 -0000 1.12 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_kmod_netbsd.c 21 Jan 2023 13:52:08 -0000 @@ -96,11 +96,11 @@ remote_event_signal(REMOTE_EVENT_T *even { wmb(); - event->fired = 1; + event->fired = htole32(1); dsb(sy); /* data barrier operation */ - if (event->armed) { + if (le32toh(event->armed)) { bus_space_write_4(vchiq_softc->sc_iot, vchiq_softc->sc_ioh, VCHIQ_DOORBELL2, 0); bus_space_barrier(vchiq_softc->sc_iot, vchiq_softc->sc_ioh, @@ -135,4 +135,14 @@ SYSCTL_SETUP(sysctl_hw_vchiq_setup, "sys CTLFLAG_PERMANENT|CTLFLAG_READWRITE, CTLTYPE_INT, "sync", "VChiq Sync Loglevel", NULL, 0, &vchiq_sync_log_level, 0, CTL_CREATE, CTL_EOL); + + sysctl_createv(clog, 0, &cnode, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "arm", "VChiq Arm Loglevel", NULL, 0, + &vchiq_arm_log_level, 0, CTL_CREATE, CTL_EOL); + + sysctl_createv(clog, 0, &cnode, NULL, + CTLFLAG_PERMANENT|CTLFLAG_READWRITE, + CTLTYPE_INT, "susp", "VChiq Suspend Loglevel", NULL, 0, + &vchiq_susp_log_level, 0, CTL_CREATE, CTL_EOL); } Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_acpi.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_acpi.c,v retrieving revision 1.5 diff -p -u -r1.5 vchiq_netbsd_acpi.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_acpi.c 7 Aug 2021 16:19:18 -0000 1.5 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_acpi.c 21 Jan 2023 13:52:08 -0000 @@ -93,10 +93,10 @@ vchiq_acpi_attach(device_t parent, devic sc->sc_iot = aa->aa_memt; asc->sc_handle = aa->aa_node->ad_handle; -#if BYTE_ORDER == BIG_ENDIAN - aprint_error_dev(sc->sc_dev, "not supported yet in big-endian mode\n"); - return; -#endif +//#if BYTE_ORDER == BIG_ENDIAN +// aprint_error_dev(sc->sc_dev, "not supported yet in big-endian mode\n"); +// return; +//#endif rv = acpi_resource_parse(self, aa->aa_node->ad_handle, "_CRS", &res, &acpi_resource_parse_ops_default); Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_fdt.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_fdt.c,v retrieving revision 1.7 diff -p -u -r1.7 vchiq_netbsd_fdt.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_fdt.c 7 Aug 2021 16:19:18 -0000 1.7 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_netbsd_fdt.c 21 Jan 2023 13:52:08 -0000 @@ -93,11 +93,6 @@ vchiq_fdt_attach(device_t parent, device sc->sc_iot = faa->faa_bst; fsc->sc_phandle = phandle; -#if BYTE_ORDER == BIG_ENDIAN - aprint_error_dev(sc->sc_dev, "not supported yet in big-endian mode\n"); - return; -#endif - bus_addr_t addr; bus_size_t size; Index: sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_shim.c =================================================================== RCS file: /cvsroot/src/sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_shim.c,v retrieving revision 1.7 diff -p -u -r1.7 vchiq_shim.c --- sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_shim.c 22 Jan 2020 19:15:49 -0000 1.7 +++ sys/external/bsd/vchiq/dist/interface/vchiq_arm/vchiq_shim.c 21 Jan 2023 13:52:08 -0000 @@ -112,7 +112,7 @@ int32_t vchi_msg_peek(VCHI_SERVICE_HANDL header = vchiu_queue_peek(&service->queue); *data = header->data; - *msg_size = header->size; + *msg_size = le32toh(header->size); return 0; } @@ -336,10 +336,10 @@ int32_t vchi_msg_dequeue(VCHI_SERVICE_HA header = vchiu_queue_pop(&service->queue); - memcpy(data, header->data, header->size < max_data_size_to_read ? - header->size : max_data_size_to_read); + memcpy(data, header->data, le32toh(header->size) < max_data_size_to_read ? + le32toh(header->size) : max_data_size_to_read); - *actual_msg_size = header->size; + *actual_msg_size = le32toh(header->size); vchiq_release_message(service->handle, header); @@ -446,7 +446,7 @@ int32_t vchi_msg_hold(VCHI_SERVICE_HANDL header = vchiu_queue_pop(&service->queue); *data = header->data; - *msg_size = header->size; + *msg_size = le32toh(header->size); message_handle->service = (struct opaque_vchi_service_t *)(uintptr_t)service->handle;