Example #1
0
void
CDMProxy::OnCDMCreated(uint32_t aPromiseId)
{
  MOZ_ASSERT(NS_IsMainThread());
  if (mKeys.IsNull()) {
    return;
  }
  MOZ_ASSERT(!GetNodeId().IsEmpty());
  if (mCDM) {
    mKeys->OnCDMCreated(aPromiseId, GetNodeId(), mCDM->GetPluginId());
  } else {
    // No CDM? Just reject the promise.
    mKeys->RejectPromise(aPromiseId, NS_ERROR_DOM_INVALID_STATE_ERR);
  }
}
    /// <summary>
    ///     Called to affinitize the given thread proxy to this virtual processor.
    /// </summary>
    /// <param name="pThreadProxy">
    ///     The new thread proxy to run atop this virtual processor root.
    /// </param>
    void FreeVirtualProcessorRoot::Affinitize(FreeThreadProxy *pThreadProxy)
    {
        //
        // Wait until the thread proxy is firmly blocked. This is essential to prevent vproc root orphanage
        // if the thread proxy we're switching to is IN THE PROCESS of switching out to a different one. An example of how this
        // could happen:

        // 1] ctxA is running on vp1. It is in the process of blocking, and wants to switch to ctxB. This means ctxA's thread proxy
        // tpA must affintize ctxB's thread proxy tpB to its own vproc root, vproot1.

        // 2] At the exact same time, ctxA is unblocked by ctxY and put onto a runnables collection in its scheduler. Meanwhile, ctxZ
        // executing on vp2, has also decided to block. It picks ctxA off the runnables collection, and proceeds to switch to it.
        // This means that ctxZ's thread proxy tpZ must affinitize ctxA's thread proxy tpA to ITS vproc root vproot2.

        // 3] Now, if tpZ affintizes tpA to vproot2 BEFORE tpA has had a chance to affintize tpB to vproot1, tpB gets mistakenly
        // affintized to vproot2, and vproot1 is orphaned.

        // In order to prevent this, tpZ MUST wait until AFTER tpA has finished its affinitization. This is indicated via the
        // blocked flag. tpA will set its blocked flag to 1, after it has finished affintizing tpB to vproot1, at which point it is
        // safe for tpZ to modify tpA's vproc root and change it from vproot1 to vproot2.
        //

        pThreadProxy->SpinUntilBlocked();

        m_pExecutingProxy = pThreadProxy;
        pThreadProxy->SetVirtualProcessorRoot(this);

        HardwareAffinity newAffinity = GetSchedulerProxy()->GetNodeAffinity(GetNodeId());
        pThreadProxy->SetAffinity(newAffinity);
    }
Example #3
0
void				FillMiscDatas(unsigned int *Datas)
{
	BYTE		Buffer[0x400];
	HKEY		rKey;
	DWORD		BufSz = 0x400;
	int			ret;
	double		PlatForm;

	PlatForm = PlatFormSpecific();
	Datas[0] = *(unsigned int *)&PlatForm;
	Datas[1] = *(unsigned int *)GetNodeId();

	ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software\\Microsoft\\Windows\\CurrentVersion", 0, KEY_QUERY_VALUE, &rKey);
	if (ret)
		return ;
	ret = RegQueryValueExA(rKey, "ProductId", NULL, NULL, (LPBYTE)Buffer, &BufSz);
	if (ret)
		return ;
	RegCloseKey(rKey);
	Datas[2] = BytesSHA1(Buffer, BufSz);

	ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter\\8\\DiskController\\0\\DiskPeripheral\\0", 0, KEY_QUERY_VALUE, &rKey);
	if (ret)
		return ;
	ret = RegQueryValueExA(rKey, "Identifier", NULL, NULL, (LPBYTE)Buffer, &BufSz);
	if (ret)
		return ;
	RegCloseKey(rKey);
	Datas[3] = BytesSHA1(Buffer, BufSz);

	ret = GetVolumeInformationA("C:\\", 0, 0, (LPDWORD)Buffer, 0, 0, 0, 0);
	Datas[4] = BytesSHA1(Buffer, 0x04);
}
Example #4
0
nsresult
GMPAudioDecoder::Init()
{
  MOZ_ASSERT(IsOnGMPThread());

  mMPS = do_GetService("@mozilla.org/goanna-media-plugin-service;1");
  MOZ_ASSERT(mMPS);

  nsTArray<nsCString> tags;
  InitTags(tags);
  nsresult rv = mMPS->GetGMPAudioDecoder(&tags, GetNodeId(), &mGMP);
  NS_ENSURE_SUCCESS(rv, rv);
  MOZ_ASSERT(mGMP);

  nsTArray<uint8_t> codecSpecific;
  codecSpecific.AppendElements(mConfig.audio_specific_config->Elements(),
                               mConfig.audio_specific_config->Length());

  rv = mGMP->InitDecode(kGMPAudioCodecAAC,
                        mConfig.channel_count,
                        mConfig.bits_per_sample,
                        mConfig.samples_per_second,
                        codecSpecific,
                        mAdapter);
  NS_ENSURE_SUCCESS(rv, rv);

  return NS_OK;
}
Example #5
0
void				FillMiscDatas(unsigned int *Datas)
{
	BYTE		Buffer[0x400];
	DWORD		BufSz = 0x400;
	int			ret;
	__int64 PlatForm;

	PlatForm = PlatFormSpecific();
	Datas[0] = *(unsigned int *)&PlatForm;
	Datas[1] = *(unsigned int *)GetNodeId();

	if (!QueryRegValue(HKEY_LOCAL_MACHINE, 
		"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\ProductId",
		(LPBYTE)Buffer, &BufSz))
		return;
	Datas[2] = BytesSHA1(Buffer, BufSz);

	BufSz = 0x400;
	if (!QueryRegValue(HKEY_LOCAL_MACHINE, 
		"HARDWARE\\DESCRIPTION\\System\\MultifunctionAdapter\\*\\DiskController\\*\\DiskPeripheral\\*\\Identifier",
		(LPBYTE)Buffer, &BufSz))
		return;
	Datas[3] = BytesSHA1(Buffer, BufSz);

	ret = GetVolumeInformationA("C:\\", 0, 0, (LPDWORD)Buffer, 0, 0, 0, 0);
	Datas[4] = BytesSHA1(Buffer, 0x04);

#ifdef SKYPE5
	__int64 AI = FillAdaptersInfo(NULL);
	Datas[5] = *(DWORD*)&AI;
#endif

}
/**
 * Get PCI Config Space Address for the current running core.
 *
 * @param[out]   PciAddress   The Processor's PCI Config Space address (Function 0, Register 0)
 * @param[in]    StdHeader    Header for library and services.
 *
 * @retval       TRUE         The core is present, PCI Address valid
 * @retval       FALSE        The core is not present, PCI Address not valid.
 */
BOOLEAN
GetCurrPciAddrMulti (
     OUT   PCI_ADDR               *PciAddress,
  IN       AMD_CONFIG_PARAMS      *StdHeader
  )
{
  UINT8        Node;
  UINT32       Socket;
  UINT32       Module;
  UINT32       Core;
  BOOLEAN      Result;
  AGESA_STATUS IgnoredSts;

  Result = TRUE;

  IdentifyCore (StdHeader, &Socket, &Module, &Core, &IgnoredSts);

  ASSERT (Socket < MAX_SOCKETS);
  ASSERT (Module < MAX_DIES);

  if (GetNodeId (Socket, Module, &Node, StdHeader)) {
    // Socket is populated
    PciAddress->AddressValue = MAKE_SBDFO (0, 0, 24, 0, 0);
    PciAddress->Address.Device = PciAddress->Address.Device + Node;
  } else {
    // Socket is not populated
    PciAddress->AddressValue = ILLEGAL_SBDFO;
    Result = FALSE;
  }

  return Result;
}
bool FirewirePort::WriteQuadlet(unsigned char boardId, nodeaddr_t addr, quadlet_t data)
{
    int node = GetNodeId(boardId);
    if (node < MAX_NODES)
        return !raw1394_write(handle, baseNodeId+node, addr, 4, &data);
    else
        return false;
}
Example #8
0
void
GMPCDMProxy::gmp_InitGetGMPDecryptor(nsresult aResult,
                                     const nsACString& aNodeId,
                                     UniquePtr<InitData>&& aData)
{
  uint32_t promiseID = aData->mPromiseId;
  if (NS_FAILED(aResult)) {
    RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
                  NS_LITERAL_CSTRING("GetNodeId() called back, but with a failure result"));
    return;
  }

  mNodeId = aNodeId;
  MOZ_ASSERT(!GetNodeId().IsEmpty());

  nsCOMPtr<mozIGeckoMediaPluginService> mps =
    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  if (!mps) {
    RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
                  NS_LITERAL_CSTRING("Couldn't get MediaPluginService in GMPCDMProxy::gmp_InitGetGMPDecryptor"));
    return;
  }

  EME_LOG("GMPCDMProxy::gmp_Init (%s, %s) NodeId=%s",
          NS_ConvertUTF16toUTF8(aData->mOrigin).get(),
          NS_ConvertUTF16toUTF8(aData->mTopLevelOrigin).get(),
          GetNodeId().get());

  nsTArray<nsCString> tags;
  tags.AppendElement(NS_ConvertUTF16toUTF8(mKeySystem));

  // Note: must capture helper refptr here, before the Move()
  // when we create the GetGMPDecryptorCallback below.
  RefPtr<GMPCrashHelper> crashHelper = Move(aData->mCrashHelper);
  UniquePtr<GetGMPDecryptorCallback> callback(new gmp_InitDoneCallback(this,
                                                                       Move(aData)));
  nsresult rv = mps->GetGMPDecryptor(crashHelper,
                                     &tags,
                                     GetNodeId(),
                                     Move(callback));
  if (NS_FAILED(rv)) {
    RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
                  NS_LITERAL_CSTRING("Call to GetGMPDecryptor() failed early"));
  }
}
bool FirewirePort::WriteBlock(unsigned char boardId, nodeaddr_t addr, quadlet_t *data,
                              unsigned int nbytes)
{
    int node = GetNodeId(boardId);
    if (node < MAX_NODES)
        return !raw1394_write(handle, baseNodeId+node, addr, nbytes, data);
    else
        return false;
}
Example #10
0
NS_IMETHODIMP
GeckoMediaPluginServiceParent::GetNodeId(const nsAString& aOrigin,
                                         const nsAString& aTopLevelOrigin,
                                         bool aInPrivateBrowsing,
                                         UniquePtr<GetNodeIdCallback>&& aCallback)
{
  nsCString nodeId;
  nsresult rv = GetNodeId(aOrigin, aTopLevelOrigin, aInPrivateBrowsing, nodeId);
  aCallback->Done(rv, nodeId);
  return rv;
}
Example #11
0
void
CDMProxy::gmp_InitGetGMPDecryptor(nsresult aResult,
                                  const nsACString& aNodeId,
                                  nsAutoPtr<InitData>&& aData)
{
  uint32_t promiseID = aData->mPromiseId;
  if (NS_FAILED(aResult)) {
    RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
                  NS_LITERAL_CSTRING("GetNodeId() called back, but with a failure result"));
    return;
  }

  mNodeId = aNodeId;
  MOZ_ASSERT(!GetNodeId().IsEmpty());

  nsCOMPtr<mozIGeckoMediaPluginService> mps =
    do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  if (!mps) {
    RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
                  NS_LITERAL_CSTRING("Couldn't get MediaPluginService in CDMProxy::gmp_InitGetGMPDecryptor"));
    return;
  }

  EME_LOG("CDMProxy::gmp_Init (%s, %s) %s NodeId=%s",
          NS_ConvertUTF16toUTF8(aData->mOrigin).get(),
          NS_ConvertUTF16toUTF8(aData->mTopLevelOrigin).get(),
          (aData->mInPrivateBrowsing ? "PrivateBrowsing" : "NonPrivateBrowsing"),
          GetNodeId().get());

  nsTArray<nsCString> tags;
  tags.AppendElement(NS_ConvertUTF16toUTF8(mKeySystem));

  UniquePtr<GetGMPDecryptorCallback> callback(new gmp_InitDoneCallback(this,
                                                                       Move(aData)));
  nsresult rv = mps->GetGMPDecryptor(&tags, GetNodeId(), Move(callback));
  if (NS_FAILED(rv)) {
    RejectPromise(promiseID, NS_ERROR_DOM_INVALID_STATE_ERR,
                  NS_LITERAL_CSTRING("Call to GetGMPDecryptor() failed early"));
  }
}
Example #12
0
void
GMPAudioDecoder::GetGMPAPI(GMPInitDoneRunnable* aInitDone)
{
  MOZ_ASSERT(IsOnGMPThread());

  nsTArray<nsCString> tags;
  InitTags(tags);
  UniquePtr<GetGMPAudioDecoderCallback> callback(
    new GMPInitDoneCallback(this, aInitDone));
  if (NS_FAILED(mMPS->GetGMPAudioDecoder(&tags, GetNodeId(), Move(callback)))) {
    aInitDone->Dispatch();
  }
}
Example #13
0
RefPtr<MediaDataDecoder::InitPromise>
GMPAudioDecoder::Init()
{
  MOZ_ASSERT(IsOnGMPThread());

  mMPS = do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  MOZ_ASSERT(mMPS);

  RefPtr<InitPromise> promise(mInitPromise.Ensure(__func__));

  nsTArray<nsCString> tags;
  InitTags(tags);
  UniquePtr<GetGMPAudioDecoderCallback> callback(new GMPInitDoneCallback(this));
  if (NS_FAILED(mMPS->GetGMPAudioDecoder(&tags, GetNodeId(), Move(callback)))) {
    mInitPromise.Reject(MediaDataDecoder::DecoderFailureReason::INIT_ERROR, __func__);
  }

  return promise;
}
Example #14
0
RefPtr<MediaDataDecoder::InitPromise>
GMPVideoDecoder::Init()
{
  MOZ_ASSERT(IsOnGMPThread());

  mMPS = do_GetService("@mozilla.org/gecko-media-plugin-service;1");
  MOZ_ASSERT(mMPS);

  RefPtr<InitPromise> promise(mInitPromise.Ensure(__func__));

  nsTArray<nsCString> tags;
  InitTags(tags);
  UniquePtr<GetGMPVideoDecoderCallback> callback(new GMPInitDoneCallback(this));
  if (NS_FAILED(mMPS->GetDecryptingGMPVideoDecoder(mCrashHelper,
                                                   &tags,
                                                   GetNodeId(),
                                                   std::move(callback),
                                                   DecryptorId()))) {
    mInitPromise.Reject(NS_ERROR_DOM_MEDIA_FATAL_ERR, __func__);
  }

  return promise;
}
BOOL CGatewayCANopenToEpos::Process_InitiateSDOUpload(CCommand_PS* pCommand, CDeviceCommandSetManagerBase* pDeviceCommandSetManager, HANDLE hDCS_Handle, HANDLE hTransactionHandle)
{
	const DWORD k_MaxDataSize = 4;

	//Constants CANopen
	const int k_ParameterIndex_CobIdClientServer = 0;
	const int k_ParameterIndex_CobIdServerClient = 1;
	const int k_ParameterIndex_Index = 2;
	const int k_ParameterIndex_SubIndex = 3;
			
	const int k_ReturnParameterIndex_CobIdServerClient = 0;
	const int k_ReturnParameterIndex_ExpeditedTransfer = 1;
	const int k_ReturnParameterIndex_SizeIndicated = 2;
	const int k_ReturnParameterIndex_NonValidNbOfBytes = 3;
	const int k_ReturnParameterIndex_Index = 4;
	const int k_ReturnParameterIndex_SubIndex = 5;
	const int k_ReturnParameterIndex_Data = 6;
	const int k_ReturnParameterIndex_AbortCode = 7;

	//Parameter CANopen
	DWORD dCobIdClientServer = 0;
	DWORD dCobIdServerClient = 0;
	WORD wIndex = 0;
	BYTE uSubIndex = 0;
		
	//ReturnParameter CANopen
	BOOL oRetExpeditedTransfer = FALSE;
	BOOL oRetSizeIndicated = FALSE;
	BYTE uRetNonValidNbOfBytes = 0;
	void* pRetDataBuffer = NULL;
	DWORD dRetDataBufferLength = 0;
	DWORD dAbortCode = 0;

	//ReturnParameter
	DWORD dObjectLength = 0;
	
	BOOL oResult = FALSE;
	CErrorInfo errorInfo;

	if(pCommand)
	{
		//Lock CriticalSection
		if(!Lock(pCommand)) return FALSE;

		//Prepare DataBuffer
		dRetDataBufferLength = k_MaxDataSize;
		pRetDataBuffer = malloc(dRetDataBufferLength);
		memset(pRetDataBuffer,0,dRetDataBufferLength);

		//Get ParameterData CANopen
		pCommand->GetParameterData(k_ParameterIndex_CobIdClientServer,&dCobIdClientServer,sizeof(dCobIdClientServer));
		pCommand->GetParameterData(k_ParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->GetParameterData(k_ParameterIndex_Index,&wIndex,sizeof(wIndex));
		pCommand->GetParameterData(k_ParameterIndex_SubIndex,&uSubIndex,sizeof(uSubIndex));

		//Translate Command
		if(oResult = DCS_ReadObject(pDeviceCommandSetManager,hDCS_Handle,hTransactionHandle,GetNodeId(dCobIdClientServer),wIndex,uSubIndex,(BYTE*)pRetDataBuffer,dRetDataBufferLength,&dObjectLength,&errorInfo))
		{
			//Expedited Transfer
			oRetExpeditedTransfer = TRUE;
			oRetSizeIndicated = FALSE;
			uRetNonValidNbOfBytes = 0;
			dAbortCode = errorInfo.GetErrorCode();
		}
		else if(oResult = DCS_InitiateSegmentedRead(pDeviceCommandSetManager,hDCS_Handle,hTransactionHandle,GetNodeId(dCobIdClientServer),wIndex,uSubIndex,&errorInfo))
		{
			//Non Expedited Transfer
			oRetExpeditedTransfer = FALSE;
			oRetSizeIndicated = FALSE;
			uRetNonValidNbOfBytes = 0;
			*((DWORD*)pRetDataBuffer) = 0;
			dAbortCode = errorInfo.GetErrorCode();
			m_oToggle = FALSE;

		}
		else
		{
			//Failed
			dAbortCode = errorInfo.GetErrorCode();
		}

		//Set ReturnParameterData CANopen
		pCommand->SetStatus(oResult,&errorInfo);
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_ExpeditedTransfer,&oRetExpeditedTransfer,sizeof(oRetExpeditedTransfer));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_SizeIndicated,&oRetSizeIndicated,sizeof(oRetSizeIndicated));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_NonValidNbOfBytes,&uRetNonValidNbOfBytes,sizeof(uRetNonValidNbOfBytes));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_Index,&wIndex,sizeof(wIndex));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_SubIndex,&uSubIndex,sizeof(uSubIndex));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_Data,pRetDataBuffer,dRetDataBufferLength);
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_AbortCode,&dAbortCode,sizeof(dAbortCode));
		
		//Free DataBuffer
		if(pRetDataBuffer) free(pRetDataBuffer);
		ResetBufferedData();

		//Unlock CriticalSection
		if(oRetExpeditedTransfer || !oResult)
		{
			Unlock();
		}

		return oResult;
	}

	return FALSE;
    
}
bool FirewirePort::ReadAllBoardsBroadcast(void)
{
    if (!handle || !handle_bc) {
        outStr << "ReadAllBoardsBroadcast: handle for port " << PortNum << " is NULL" << std::endl;
        return false;
    }

    bool ret;
    bool allOK = true;
    bool noneRead = true;
    int hub_node_id = GetNodeId(HubBoard_->BoardId);   //  ZC: NOT USE PLACEHOLDER

    //--- send out broadcast read request -----

#if 0
    quadlet_t debugData;
    nodeaddr_t debugAddr = 0x03;

    bool retdebug = !raw1394_read(handle,
                                  baseNodeId + hub_node_id,    // boardid 7
                                  debugAddr,           // read from hub addr
                                  4,          // read all 16 boards
                                  &debugData);
    if (!retdebug) {
        raw1394_errcode_t ecode = raw1394_get_errcode(handle);
        std::cerr << "debug read ecode = " << ecode << " to_errno = " << raw1394_errcode_to_errno(ecode) << "  "
                  << strerror(raw1394_errcode_to_errno(ecode)) << std::endl;
    }
#endif

    // sequence number from 16 bits 0 to 65535
    ReadSequence_++;
    if (ReadSequence_ == 65536) {
        ReadSequence_ = 1;
    }
    quadlet_t bcReqData = bswap_32((ReadSequence_ << 16) + BoardExistMask_);
    nodeaddr_t bcReqAddr = 0xffffffff000F;    // special address to trigger broadcast read

#if FAKEBC
    ret = !raw1394_write(handle,
                              baseNodeId,
                              bcReqAddr,
                              4,
                              &bcReqData);
    if (!ret) {
        raw1394_errcode_t ecode = raw1394_get_errcode(handle);
        std::cerr << "bbbbbbb fake ecode = " << ecode << " to_errno = " << raw1394_errcode_to_errno(ecode) << "  "
                  << strerror(raw1394_errcode_to_errno(ecode)) << std::endl;
    }
#else
    WriteQuadletBroadcast(bcReqAddr, bcReqData);
#endif

//    // Manual sleep 50 us
    timeval start, check;
    gettimeofday(&start, NULL);
    while(true) {
        gettimeofday(&check, NULL);
        if (((check.tv_sec-start.tv_sec)*1000000 + check.tv_usec-start.tv_usec) > (5.0*NumOfNodes_+10.0)) {
            break;
        }
    }

    // initialize max buffer
    const int hubReadSize = 272;     // 16 * 17 = 272 max
    quadlet_t hubReadBuffer[hubReadSize];
    memset(hubReadBuffer, 0, sizeof(hubReadBuffer));

    // raw1394_read 0 = SUCCESS, -1 = FAIL, flip return value
    ret = !raw1394_read(handle,
                        baseNodeId + hub_node_id,
                        0x1000,           // read from hub addr
                        272 * 4,          // read all 16 boards
                        hubReadBuffer);


    // ----- DEBUG -----------
    static int raw1394readCounter = 0;
    if (!ret) {
        raw1394readCounter++;
        raw1394_errcode_t ecode = raw1394_get_errcode(handle);
        std::cerr << "ecode = " << ecode << " to_errno = " << raw1394_errcode_to_errno(ecode) << "  "
                  << strerror(raw1394_errcode_to_errno(ecode)) << std::endl;
        std::cerr << "raw1394_read failed " << raw1394readCounter << ": " << strerror(errno) << std::endl;
    }
    // -----------------------

    for (int board = 0; board < max_board; board++) {
        if (BoardList[board]) {
            const int readSize = 17;  // 1 seq + 16 data, unit quadlet
            quadlet_t readBuffer[readSize];

            memcpy(readBuffer, &(hubReadBuffer[readSize * board + 0]), readSize * 4);

            unsigned int seq = (bswap_32(readBuffer[0]) >> 16);

            static int errorcounter = 0;
            if (ReadSequence_ != seq) {
                errorcounter++;
                outStr << "errorcounter = " << errorcounter << std::endl;
                outStr << std::hex << seq << "  " << ReadSequence_ << "  " << (int)board << std::endl;
            }

            memcpy(BoardList[board]->GetReadBuffer(), &(readBuffer[1]), (readSize-1) * 4);

            if (ret) noneRead = false;
            else allOK = false;
            BoardList[board]->SetReadValid(ret);
        }
    }

    if (noneRead) {
        PollEvents();
    }

    return allOK;
}
Example #17
0
AGESA_STATUS
PcieConfigurationInit (
  IN       AMD_CONFIG_PARAMS               *StdHeader
  )
{

  AGESA_STATUS          Status;
  PCIe_PLATFORM_CONFIG  *Pcie;
  PCIe_SILICON_CONFIG   *Silicon;
  UINT8                 SocketId;
  UINTN                 CurrentComplexesDataLength;
  UINTN                 ComplexesDataLength;
  UINT8                 ComplexIndex;
  VOID                  *Buffer;
  ComplexesDataLength = 0;
  Status = AGESA_SUCCESS;
  IDS_HDT_CONSOLE (GNB_TRACE, "PcieConfigurationInit Enter\n");
  for (SocketId = 0; SocketId < GetPlatformNumberOfSockets (); SocketId++) {
    if (IsProcessorPresent (SocketId, StdHeader)) {
      Status = PcieFmGetComplexDataLength (SocketId, &CurrentComplexesDataLength, StdHeader);
      ASSERT (Status == AGESA_SUCCESS);
      ComplexesDataLength += CurrentComplexesDataLength;
    }
  }
  ComplexIndex = 0;
  Pcie = GnbAllocateHeapBufferAndClear (AMD_PCIE_COMPLEX_DATA_HANDLE, sizeof (PCIe_PLATFORM_CONFIG) + ComplexesDataLength, StdHeader);
  ASSERT (Pcie != NULL);
  if (Pcie != NULL) {
    PcieConfigAttachChild (&Pcie->Header, &Pcie->ComplexList[ComplexIndex].Header);
    PcieConfigSetDescriptorFlags (Pcie, DESCRIPTOR_PLATFORM | DESCRIPTOR_TERMINATE_LIST | DESCRIPTOR_TERMINATE_TOPOLOGY);
    Buffer = (UINT8 *) (Pcie) + sizeof (PCIe_PLATFORM_CONFIG);
    for (SocketId = 0; SocketId < GetPlatformNumberOfSockets (); SocketId++) {
      if (IsProcessorPresent (SocketId, StdHeader)) {
        Pcie->ComplexList[ComplexIndex].SocketId = SocketId;
        //Attache Comples to Silicon which will be created by PcieFmBuildComplexConfiguration
        PcieConfigAttachChild (&Pcie->ComplexList[ComplexIndex].Header, &((PCIe_SILICON_CONFIG *) Buffer)->Header);
        //Attach Comples to Pcie
        PcieConfigAttachParent (&Pcie->Header, &Pcie->ComplexList[ComplexIndex].Header);
        PcieConfigSetDescriptorFlags (&Pcie->ComplexList[ComplexIndex], DESCRIPTOR_COMPLEX | DESCRIPTOR_TERMINATE_LIST | DESCRIPTOR_TERMINATE_GNB | DESCRIPTOR_TERMINATE_TOPOLOGY);
        PcieFmBuildComplexConfiguration (SocketId, Buffer, StdHeader);
        Silicon = PcieConfigGetChildSilicon (&Pcie->ComplexList[ComplexIndex]);
        while (Silicon != NULL) {
          PcieConfigAttachParent (&Pcie->ComplexList[ComplexIndex].Header, &Silicon->Header);
          GetNodeId (SocketId, Silicon->SiliconId, &Silicon->NodeId, StdHeader);
          GnbFmGetLinkId ((GNB_HANDLE*) Silicon, &Silicon->LinkId, StdHeader);
          Silicon = (PCIe_SILICON_CONFIG *) PcieConfigGetNextTopologyDescriptor (Silicon, DESCRIPTOR_TERMINATE_TOPOLOGY);
        }

        if (ComplexIndex > 0) {
          PcieConfigAttachComplexes (&Pcie->ComplexList[ComplexIndex - 1], &Pcie->ComplexList[ComplexIndex]);
        }
        PcieFmGetComplexDataLength (SocketId, &CurrentComplexesDataLength, StdHeader);
        Buffer = (VOID *) ((UINT8 *) Buffer + CurrentComplexesDataLength);
        ComplexIndex++;
      }
    }
  } else {
    Status = AGESA_FATAL;
  }
  IDS_HDT_CONSOLE (GNB_TRACE, "PcieConfigurationInit Exit [0x%x]\n", Status);
  return Status;
}
BOOL CGatewayCANopenToEpos::Process_UploadSDOSegment(CCommand_PS* pCommand, CDeviceCommandSetManagerBase* pDeviceCommandSetManager, HANDLE hDCS_Handle, HANDLE hTransactionHandle)
{
	const DWORD k_MaxCANopenDataSize = 7;

	//Constants CANopen
	const int k_ParameterIndex_CobIdClientServer = 0;
	const int k_ParameterIndex_CobIdServerClient = 1;
	const int k_ParameterIndex_Toggle = 2;
			
	const int k_ReturnParameterIndex_CobIdServerClient = 0;
	const int k_ReturnParameterIndex_Toggle = 1;
	const int k_ReturnParameterIndex_NonValidNbOfBytes = 2;
	const int k_ReturnParameterIndex_NoMoreSegments = 3;
	const int k_ReturnParameterIndex_SegData = 4;
	const int k_ReturnParameterIndex_AbortCode = 5;

	//Parameter CANopen
	DWORD dCobIdClientServer = 0;
	DWORD dCobIdServerClient = 0;
	BOOL oToggle = FALSE;
		
	//ReturnParameter CANopen
	BYTE uRetNonValidNbOfBytes = 0;
	BOOL oRetNoMoreSegments = FALSE;
	void* pRetSegDataBuffer = NULL;
	DWORD dRetSegDataBufferLength = 0;
	DWORD dSegmentLengthRead = 0;
	DWORD dAbortCode = 0;

	//ReturnParameter Esam
	void* pDataBuffer = NULL;
	DWORD dDataBufferLength = 0;
	
	BOOL oResult = FALSE;
	CErrorInfo errorInfo;

	if(pCommand)
	{
		//Check CriticalSection
		if(!IsLocked(pCommand)) return FALSE;

		//Prepare DataBuffer
		dRetSegDataBufferLength = k_MaxCANopenDataSize;
		pRetSegDataBuffer = malloc(dRetSegDataBufferLength);
		memset(pRetSegDataBuffer,0,dRetSegDataBufferLength);

		//Get ParameterData CANopen
		pCommand->GetParameterData(k_ParameterIndex_CobIdClientServer,&dCobIdClientServer,sizeof(dCobIdClientServer));
		pCommand->GetParameterData(k_ParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->GetParameterData(k_ParameterIndex_Toggle,&oToggle,sizeof(oToggle));

		//Translate Command
		oResult = GetBufferedData(pRetSegDataBuffer,dRetSegDataBufferLength,&dSegmentLengthRead,&oRetNoMoreSegments);
		if(!oResult)
		{
			oResult = DCS_SegmentedRead(pDeviceCommandSetManager,hDCS_Handle,hTransactionHandle,GetNodeId(dCobIdClientServer),m_oToggle,&oRetNoMoreSegments,&pDataBuffer,&dDataBufferLength,&errorInfo);
			if(oResult)
			{
				m_oToggle = !m_oToggle;
				AddBufferedData(pDataBuffer,dDataBufferLength,oRetNoMoreSegments);
				oResult = GetBufferedData(pRetSegDataBuffer,dRetSegDataBufferLength,&dSegmentLengthRead,&oRetNoMoreSegments);
			}
		}
	
		//CheckSize
		if(oResult && (dSegmentLengthRead <= k_MaxCANopenDataSize)) 
		{
			uRetNonValidNbOfBytes = (BYTE)(k_MaxCANopenDataSize-dSegmentLengthRead);
			dAbortCode = errorInfo.GetErrorCode();
		}
		else if(oResult)
		{
			oResult = FALSE;
			if(m_pErrorHandling) m_pErrorHandling->GetError(k_Error_Internal,&errorInfo);
			dAbortCode = errorInfo.GetErrorCode();
		}
		else
		{
			uRetNonValidNbOfBytes = k_MaxCANopenDataSize;
			dAbortCode = errorInfo.GetErrorCode();
		}

		//Set ReturnParameterData CANopen
		pCommand->SetStatus(oResult,&errorInfo);
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_Toggle,&oToggle,sizeof(oToggle));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_NonValidNbOfBytes,&uRetNonValidNbOfBytes,sizeof(uRetNonValidNbOfBytes));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_NoMoreSegments,&oRetNoMoreSegments,sizeof(oRetNoMoreSegments));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_SegData,pRetSegDataBuffer,dSegmentLengthRead);
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_AbortCode,&dAbortCode,sizeof(dAbortCode));
		
		//Free DataBuffer
		if(pRetSegDataBuffer) free(pRetSegDataBuffer);
		if(pDataBuffer) free(pDataBuffer);

		//Unlock CriticalSection
		if(oRetNoMoreSegments || !oResult)
		{
			ResetBufferedData();
			Unlock();
		}

		return oResult;
	}

	return FALSE;
    
}
BOOL CGatewayCANopenToEpos::Process_InitiateSDODownload(CCommand_PS* pCommand, CDeviceCommandSetManagerBase* pDeviceCommandSetManager, HANDLE hDCS_Handle, HANDLE hTransactionHandle)
{
	const DWORD k_MaxDataSize = 4;

	//Constants CANopen
	const int k_ParameterIndex_CobIdClientServer = 0;
	const int k_ParameterIndex_CobIdServerClient = 1;
	const int k_ParameterIndex_ExpeditedTransfer = 2;
	const int k_ParameterIndex_SizeIndicated = 3;
	const int k_ParameterIndex_NonValidNbOfBytes = 4;
	const int k_ParameterIndex_Index = 5;
	const int k_ParameterIndex_SubIndex = 6;
	const int k_ParameterIndex_Data = 7;
		
	const int k_ReturnParameterIndex_CobIdServerClient = 0;
	const int k_ReturnParameterIndex_Index = 1;
	const int k_ReturnParameterIndex_SubIndex = 2;
	const int k_ReturnParameterIndex_AbortCode = 3;

	//Parameter CANopen
	DWORD dCobIdClientServer = 0;
	DWORD dCobIdServerClient = 0;
	BOOL oExpeditedTransfer = 0;
	BOOL oSizeIndicated = FALSE;
	BYTE uNonValidNbOfBytes = 0;
	WORD wIndex = 0;
	BYTE uSubIndex = 0;
	void* pDataBuffer = NULL;
	DWORD dDataBufferLength = 0;
	DWORD dObjectLength = 0;
	
	//ReturnParameter CANopen
	DWORD dAbortCode = 0;

	BOOL oResult = FALSE;
	CErrorInfo errorInfo;

	if(pCommand)
	{
		//Lock CriticalSection
		if(!Lock(pCommand)) return FALSE;

		//Prepare DataBuffer
		dDataBufferLength = pCommand->GetParameterLength(k_ParameterIndex_Data);
		if(dDataBufferLength > 0) pDataBuffer = malloc(dDataBufferLength);

		//Get ParameterData CANopen
		pCommand->GetParameterData(k_ParameterIndex_CobIdClientServer,&dCobIdClientServer,sizeof(dCobIdClientServer));
		pCommand->GetParameterData(k_ParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->GetParameterData(k_ParameterIndex_ExpeditedTransfer,&oExpeditedTransfer,sizeof(oExpeditedTransfer));
		pCommand->GetParameterData(k_ParameterIndex_SizeIndicated,&oSizeIndicated,sizeof(oSizeIndicated));
		pCommand->GetParameterData(k_ParameterIndex_NonValidNbOfBytes,&uNonValidNbOfBytes,sizeof(uNonValidNbOfBytes));
		pCommand->GetParameterData(k_ParameterIndex_Index,&wIndex,sizeof(wIndex));
		pCommand->GetParameterData(k_ParameterIndex_SubIndex,&uSubIndex,sizeof(uSubIndex));
		pCommand->GetParameterData(k_ParameterIndex_Data,pDataBuffer,dDataBufferLength);

		//Check DataBuffer Length
		dDataBufferLength = CheckDataBufferLength(oSizeIndicated,uNonValidNbOfBytes,dDataBufferLength,k_MaxDataSize);
		
		//Translate Command
		if(oExpeditedTransfer)
		{
			//Expedited Transfer
			oResult = DCS_WriteObject(pDeviceCommandSetManager,hDCS_Handle,hTransactionHandle,GetNodeId(dCobIdClientServer),wIndex,uSubIndex,(BYTE*)pDataBuffer,dDataBufferLength,&errorInfo);
			dAbortCode = errorInfo.GetErrorCode();
		}
		else
		{
			//NonExpedited Transfer
			if(oSizeIndicated && (dDataBufferLength >= k_MaxDataSize))
			{
				dObjectLength = *((DWORD*)pDataBuffer);
				oResult = DCS_InitiateSegmentedWrite(pDeviceCommandSetManager,hDCS_Handle,hTransactionHandle,GetNodeId(dCobIdClientServer),wIndex,uSubIndex,dObjectLength,&errorInfo);
				dAbortCode = errorInfo.GetErrorCode();
				m_oToggle = FALSE;

				m_WriteSegmentSize = k_MaxRS232DataSize;
			}
			else
			{
				oResult = FALSE;
				if(m_pErrorHandling) m_pErrorHandling->GetError(k_Error_Internal,&errorInfo);
				dAbortCode = errorInfo.GetErrorCode();
			}
		}
		
		//Set ReturnParameterData CANopen
		pCommand->SetStatus(oResult,&errorInfo);
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_Index,&wIndex,sizeof(wIndex));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_SubIndex,&uSubIndex,sizeof(uSubIndex));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_AbortCode,&dAbortCode,sizeof(dAbortCode));
		
		//Free DataBuffer
		if(pDataBuffer) free(pDataBuffer);
		ResetBufferedData();

		//Unlock CriticalSection
		if(oExpeditedTransfer || !oResult)
		{
			Unlock();
		}

		return oResult;
	}

	return FALSE;

}
BOOL CGatewayCANopenToEpos::Process_DownloadSDOSegment(CCommand_PS* pCommand, CDeviceCommandSetManagerBase* pDeviceCommandSetManager, HANDLE hDCS_Handle, HANDLE hTransactionHandle)
{
	const DWORD k_MaxCANopenDataSize = 7;
	
	//Constants PS CANopen
	const int k_ParameterIndex_CobIdClientServer = 0;
	const int k_ParameterIndex_CobIdServerClient = 1;
	const int k_ParameterIndex_Toggle = 2;
	const int k_ParameterIndex_NonValidNbOfBytes = 3;
	const int k_ParameterIndex_NoMoreSegments = 4;
	const int k_ParameterIndex_SegData = 5;
		
	const int k_ReturnParameterIndex_CobIdServerClient = 0;
	const int k_ReturnParameterIndex_Toggle = 1;
	const int k_ReturnParameterIndex_AbortCode = 2;

	//Parameter CANopen
	DWORD dCobIdClientServer = 0;
	DWORD dCobIdServerClient = 0;
	BOOL oToggle = 0;
	BYTE uNonValidNbOfBytes = 0;
	BOOL oNoMoreSegments = FALSE;
	void* pSegDataBuffer = NULL;
	DWORD dSegDataBufferLength = 0;
		
	//ReturnParameter CANopen
	DWORD dAbortCode = 0;

	//ReturnParameter Esam
	BOOL oRetToggle = FALSE;
	void* pDataBuffer = NULL;
	DWORD dDataBufferLength = 0;
	DWORD dDataLengthRead = 0;
	DWORD dDataLengthWritten = 0;
	
	BOOL oResult = FALSE;
	CErrorInfo errorInfo;

	if(pCommand)
	{
		//Check CriticalSection
		if(!IsLocked(pCommand)) return FALSE;

		//Prepare DataBuffer
		dSegDataBufferLength = pCommand->GetParameterLength(k_ParameterIndex_SegData);
		if(dSegDataBufferLength > 0) pSegDataBuffer = malloc(dSegDataBufferLength);
		dDataBufferLength = m_WriteSegmentSize;
		if(dDataBufferLength > 0) pDataBuffer = malloc(dDataBufferLength);

		//Get ParameterData CANopen
		pCommand->GetParameterData(k_ParameterIndex_CobIdClientServer,&dCobIdClientServer,sizeof(dCobIdClientServer));
		pCommand->GetParameterData(k_ParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->GetParameterData(k_ParameterIndex_Toggle,&oToggle,sizeof(oToggle));
		pCommand->GetParameterData(k_ParameterIndex_NonValidNbOfBytes,&uNonValidNbOfBytes,sizeof(uNonValidNbOfBytes));
		pCommand->GetParameterData(k_ParameterIndex_NoMoreSegments,&oNoMoreSegments,sizeof(oNoMoreSegments));
		pCommand->GetParameterData(k_ParameterIndex_SegData,pSegDataBuffer,dSegDataBufferLength);

		//Check DataBuffer Length
		dSegDataBufferLength = CheckDataBufferLength(TRUE,uNonValidNbOfBytes,dSegDataBufferLength,k_MaxCANopenDataSize);

		//Translate Command
		oResult = AddBufferedData(pSegDataBuffer,dSegDataBufferLength,oNoMoreSegments);
		if(oResult)
		{
			while(GetBufferedData(pDataBuffer,dDataBufferLength,&dDataLengthRead,&oNoMoreSegments))
			{
				//AbortCommand
				if(m_oAbortCommands)
				{
					if(m_pErrorHandling) m_pErrorHandling->GetError(k_Error_CommandAbortedByUser,&errorInfo);
					oResult = FALSE;
					break;
				}

				oResult = DCS_SegmentedWrite(pDeviceCommandSetManager,hDCS_Handle,hTransactionHandle,GetNodeId(dCobIdClientServer),!oNoMoreSegments,m_oToggle,pDataBuffer,dDataLengthRead,&oRetToggle,&dDataLengthWritten,&errorInfo);
				m_oToggle = !m_oToggle;

				//Update SegmentLength
				if(dDataLengthWritten < dDataLengthRead)
				{
					ReverseBufferedData(dDataLengthRead-dDataLengthWritten);
					oNoMoreSegments = FALSE;
					if(pDataBuffer)
					{
						free(pDataBuffer);
						pDataBuffer = NULL;

						m_WriteSegmentSize = dDataLengthWritten;
						dDataBufferLength = dDataLengthWritten;

						if(dDataBufferLength > 0) pDataBuffer = malloc(dDataBufferLength);
					}
				}
				
				if(oNoMoreSegments) break;
			}
		}
		dAbortCode = errorInfo.GetErrorCode();

		//Set ReturnParameterData CANopen
		pCommand->SetStatus(oResult,&errorInfo);
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_CobIdServerClient,&dCobIdServerClient,sizeof(dCobIdServerClient));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_Toggle,&oToggle,sizeof(oToggle));
		pCommand->SetReturnParameterData(k_ReturnParameterIndex_AbortCode,&dAbortCode,sizeof(dAbortCode));
		
		//Free DataBuffer
		if(pSegDataBuffer) free(pSegDataBuffer);
		if(pDataBuffer) free(pDataBuffer);

		//Unlock CriticalSection
		if(oNoMoreSegments || !oResult)
		{
			ResetBufferedData();
			Unlock();
		}
		
		return oResult;
	}
	
	return FALSE;	
    
}
BOOL CGatewayCANopenToEpos::Process_AbortSDOTransfer(CCommand_PS* pCommand, CDeviceCommandSetManagerBase* pDeviceCommandSetManager, HANDLE hDCS_Handle, HANDLE hTransactionHandle)
{
	//*Constants PS*
	const int k_ParameterIndex_CobIdClientServer = 0;
	const int k_ParameterIndex_Index = 1;
	const int k_ParameterIndex_SubIndex = 2;
	const int k_ParameterIndex_AbortCode = 3;
		
	//*Variables PS*
	//Parameter
	DWORD dCobIdClientServer = 0;
	WORD wIndex = 0;
	BYTE uSubIndex = 0;
	DWORD dAbortCode = 0;
	
	BOOL oResult = FALSE;
	CErrorInfo errorInfo;
	
	if(pCommand)
	{
		//Get PS Parameter Data
		pCommand->GetParameterData(k_ParameterIndex_CobIdClientServer,&dCobIdClientServer,sizeof(dCobIdClientServer));
		pCommand->GetParameterData(k_ParameterIndex_Index,&wIndex,sizeof(wIndex));
		pCommand->GetParameterData(k_ParameterIndex_SubIndex,&uSubIndex,sizeof(uSubIndex));
		pCommand->GetParameterData(k_ParameterIndex_AbortCode,&dAbortCode,sizeof(dAbortCode));
		
		//Execute Command
		oResult = DCS_AbortSegmentedTransfer(pDeviceCommandSetManager, hDCS_Handle, hTransactionHandle, GetNodeId(dCobIdClientServer), wIndex, (WORD)uSubIndex, dAbortCode, &errorInfo);
				
		//Set PS ReturnParameter Data
		pCommand->SetStatus(oResult,&errorInfo);

		//Unlock CriticalSection
		Unlock();
	}

	return oResult;
}