/* * ======== doCmd ======== */ static Int doCmd(Int cmdId, Processor_Handle proc) { Int result; GT_2trace(curTrace, GT_ENTER, "doCmd> Enter (cmdId=%d, proc=0x%x)\n", cmdId, proc); //pthread_mutex_lock(&dcmd.gate); Lock_acquire(dcmd.gate); dcmd.proc = proc; dcmd.cmdId = cmdId; //pthread_cond_signal(&dcmd.cmdPresent); Sem_post(dcmd.cmdPresent); //while (dcmd.reply == NONE) { // pthread_cond_wait(&dcmd.replyPresent, &dcmd.gate); //} Sem_pend(dcmd.replyPresent, Sem_FOREVER); result = dcmd.reply; dcmd.reply = NONE; //pthread_mutex_unlock(&dcmd.gate); Lock_release(dcmd.gate); GT_1trace(curTrace, GT_ENTER, "doCmd> Exit (result=%d)\n", result); return (result); }
void command_getstate(JsmnContext * jc) { localptr(String, sequence) = String_value_none(); int client_sequence; jc->flag1 = 0; sequence = jsmn_lookup_string(jc, "sequence"); if (String_is_none(sequence)) { fprintf(stderr, "%s: missing sequence\n", __func__); return; } client_sequence = atoi(s(sequence)); fprintf(stderr, "\ngetstate ipc fd=%d\n", jc->fd1); if (client_sequence == playbackState.sequence) { #ifdef PBPIPE playbackState.wake_count += 1; #endif #ifdef PBEVENTFD playbackState.wake_count += 1; #endif /* Release lock. */ Lock_release(&playbackState.lock); /* Block waiting for sequence update, or ipc socket to timeout. */ sequence_wait(jc->fd1); fprintf(stderr, "done wait ipc fd=%d\n", jc->fd1); /* Grab lock and continue. */ Lock_acquire(&playbackState.lock); } if (client_sequence != playbackState.sequence) { jc->result = String_sprintf("{" "\"sequence\":%d" ",\"playing\":%d" ",\"paused\":%d" ",\"recording\":%d" ",\"title\":\"%s\"" ",\"runtime\":\"%lld\"" ",\"current_time\":\"%lld\"" ",\"clientid\":\"%s\"" "}\n", playbackState.sequence, playbackState.playing, playbackState.paused, playbackState.recording, String_is_none(playbackState.title) ? "":s(playbackState.title), playbackState.run_time, playbackState.current_time, String_is_none(playbackState.clientid) ? "":s(playbackState.clientid) ); } }
/* * ======== Memory_getBufferVirtualAddress ======== * Converts physical address to user virtual address. */ Ptr Memory_getBufferVirtualAddress( UInt32 physicalAddress, Int sizeInBytes) { /* * Do the reverse mapping by looking at our list of buffers; if not found, * result will be 0. */ UInt32 virtualAddress = 0; Lock_acquire( moduleLock ); Log_print2(Diags_ENTRY, "[+E] Memory_getBufferVirtualAddress> " "Enter(physAddr=0x%x, size=0x%x)", (IArg)physicalAddress, (IArg)sizeInBytes); if (Memory_skipVirtualAddressTranslation == TRUE) { virtualAddress = physicalAddress; goto Memory_getBufferVirtualAddress_return; } if (sizeInBytes == 0) { Log_print0(Diags_USER6, "[+6] Memory_getBufferVirtualAddress> " "invalid buffer size provided (0)"); /* Note that virtualAddress is already initialized to zero */ goto Memory_getBufferVirtualAddress_return; } virtualAddress = getVirtualAddress(physicalAddress, sizeInBytes); Memory_getBufferVirtualAddress_return: Log_print1(Diags_EXIT, "[+X] Memory_getBufferVirtualAddress> " "return (0x%x)", (IArg)virtualAddress); Lock_release( moduleLock ); return (Ptr)virtualAddress; }
static Bool contigFree(Ptr addr, UInt size, Int type) { Bool retVal = FALSE; CMEM_AllocParams cmemParams; Log_print2(Diags_ENTRY, "[+E] Memory_contigFree> Enter(addr=0x%x, size=0x%x)", (IArg)addr, (IArg)size); if (!cmemInitialized) { return (FALSE); } Lock_acquire( moduleLock ); if (removeContigBuf((UInt32)addr, size) >= 0) { /* CMEM_free uses just the 'type' param */ cmemParams.type = type; if (CMEM_free(addr, &cmemParams) == 0) { retVal = TRUE; } else { Log_print1(Diags_USER6, "[+6] Memory_contigFree> " "Warning: CMEM_free(0x%x) failed", (IArg)addr); } } else { Log_print2(Diags_USER7, "[+7] Memory_contigFree> " "ERROR: buffer (addr=0x%x, size=0x%x) not found in " "translation cache\n", (IArg)addr, (IArg)size); } Lock_release(moduleLock); Log_print1(Diags_EXIT, "[+X] Memory_contigFree> return (0x%x)", (IArg)retVal); return (retVal); }
/* * ======== Memory_getBufferPhysicalAddress ======== * Converts user virtual address to physical address, * but also verifies that the buffer is really contiguous * and does some bookkeeping so that reverse mapping is possible. * Returns 0 on failure, physical address on success. * *isContiguous is set to TRUE or FALSE if isContiguous!=NULL. */ UInt32 Memory_getBufferPhysicalAddress( Ptr virtualAddress, Int sizeInBytes, /* input */ Bool *isContiguous /* output */ ) { UInt32 physicalAddress = 0; UInt32 physicalAddressOfLastByte; Lock_acquire(moduleLock); Log_print2(Diags_ENTRY, "[+E] Memory_getBufferPhysicalAddress> " "Enter(virtAddr=0x%x, size=0x%x)", (IArg)virtualAddress, (IArg)sizeInBytes); if (Memory_skipVirtualAddressTranslation == TRUE) { if (isContiguous != NULL) { *isContiguous = TRUE; } physicalAddress = (UInt32)virtualAddress; goto Memory_getBufferPhysicalAddress_return; } if (sizeInBytes == 0) { Log_print0(Diags_USER6, "[+6] Memory_getBufferPhysicalAddress> " "invalid buffer size provided (0)"); /* Note that physicalAddress is already initialized to zero */ goto Memory_getBufferPhysicalAddress_return; } /* first try to find the buffer in our tables */ physicalAddress = getPhysicalAddress((UInt32)virtualAddress, sizeInBytes); if (physicalAddress != 0) { if (isContiguous != NULL) { *isContiguous = TRUE; } } else { #if 0 /* TODO:M - should we re-enable this as a warning? */ /* [cr]TODO:H this is DaVinci specific; should the caller check it? */ /* Ensure the buffer destined for the DSP is cache aligned. */ if ((((UInt32)virtualAddress) & 0x7F) != 0) { Log_print1(Diags_USER7, "[+7] Memory_getBufferPhysicalAddress> " "ERROR: buffer (0x%x) is not cache aligned on 128 byte " "boundary.", (IArg)virtualAddress); Lock_release(moduleLock); return (0); } #endif /* ask CMEM to convert addresses of the first and the last byte */ physicalAddress = CMEM_getPhys(virtualAddress); Log_print2(Diags_USER1, "[+1] Memory_getBufferPhysicalAddress> " "CMEM_getPhys(0x%x) = 0x%x.", (IArg)virtualAddress, (IArg)physicalAddress); physicalAddressOfLastByte = CMEM_getPhys( (Ptr)((UInt32)virtualAddress + sizeInBytes - 1)); if (physicalAddress != 0) { if (physicalAddressOfLastByte == physicalAddress + sizeInBytes - 1) { if (isContiguous != NULL) { *isContiguous = TRUE; } } else { if (isContiguous != NULL) { *isContiguous = FALSE; } else { Log_print2(Diags_USER7, "[+7] Memory_getBufferPhysicalAddress> " "ERROR: user buffer at addr=0x%x, size=0x%x " "is NOT contiguous", (IArg)virtualAddress, (IArg)sizeInBytes); } /* invalid buffer - it's not contiguous. */ physicalAddress = 0; } } } Memory_getBufferPhysicalAddress_return: Log_print1(Diags_EXIT, "[+X] Memory_getBufferPhysicalAddress> " "return (0x%x)", (IArg)physicalAddress); Lock_release(moduleLock); return (physicalAddress); }
/* * ======== contigAlloc ======== */ static Ptr contigAlloc(UInt size, UInt align, Bool cacheable, Bool heap) { Ptr addr = NULL; UInt32 physAddr; CMEM_AllocParams cmemParams; /* lock acquire should be after the trace, but it's unlikely to fail * and we get a more consistent/less confusing output this way. */ Lock_acquire(moduleLock); Log_print4(Diags_ENTRY, "[+E] Memory_contigAlloc> " "Enter(size=0x%x, align=0x%x, cached=%s, heap=%s)", (IArg)size, (IArg)align, (IArg)(cacheable ? "TRUE" : "FALSE"), (IArg)(heap ? "TRUE" : "FALSE")); if (!cmemInitialized) { Log_print1(Diags_USER7, "[+7] Memory_contigAlloc> " "ERROR: request for size=0x%x failed -- CMEM has not been " "initialized.", (IArg)size); goto contigAlloc_return; } if (!heap && (Int)align > CMEMPOOLALIGN) { Log_print2(Diags_USER6, "[+6] Memory_contigAlloc> " "Warning: alignment %#x not supported for pool-based allocations," " using fixed alignment %#x.", (IArg)align, (IArg)CMEMPOOLALIGN); /* align is not used for pool-based allocs, but set it anyway */ align = CMEMPOOLALIGN; } cmemParams.type = heap ? CMEM_HEAP : CMEM_POOL; cmemParams.flags = cacheable ? CMEM_CACHED : CMEM_NONCACHED; cmemParams.alignment = align; addr = CMEM_alloc(size, &cmemParams); Log_print2(Diags_USER4, "[+4] Memory_contigAlloc> CMEM_alloc(0x%x) = 0x%x.", (IArg)size, (IArg)addr); if (addr != NULL) { /* since the allocation succeeded, get physical address now and add the * description for this buffer in our list of contiguous buffers. */ physAddr = CMEM_getPhys(addr); if (physAddr != 0) { Log_print2(Diags_USER4, "[+4] Memory_contigAlloc> " "CMEM_getPhys(0x%x) = 0x%x.", (IArg)addr, (IArg)physAddr); addContigBuf((Uint32)addr, size, physAddr); } else { Log_print1(Diags_USER7, "[+7] Memory_contigAlloc> " "ERROR: CMEM_getPhys(0x%x) (virt-to-phys) failed; " "releasing the block.", (IArg)addr); CMEM_free(addr, &cmemParams); addr = NULL; } } else { Log_print0(Diags_USER7, "[+7] Memory_contigAlloc> " "ERROR: CMEM alloc failed"); } contigAlloc_return: Log_print1(Diags_EXIT, "[+X] Memory_contigAlloc> return (0x%x)", (IArg)addr); Lock_release(moduleLock); return addr; }