Esempio n. 1
0
File: pci.cpp Progetto: dfyer/joins
int32 PciHandle::read64(uint64 offset, uint64 * value)
{
	if(hDriver != INVALID_HANDLE_VALUE)
	{
		PCICFG_Request req;
		// ULONG64 result;
		DWORD reslength = 0;
		req.bus = bus;
		req.dev = device;
		req.func = function;
		req.bytes = sizeof(uint64);
		req.reg = (uint32)offset;

		BOOL status = DeviceIoControl(hDriver, IO_CTL_PCICFG_READ, &req, sizeof(PCICFG_Request), value, sizeof(uint64), &reslength, NULL);
		if (!status)
		{
			//std::cerr << "Error reading PCI Config space at bus "<<bus<<" dev "<< device<<" function "<< function <<" offset "<< offset << " size "<< req.bytes  << ". Windows error: "<<GetLastError()<<std::endl;
		}
		return reslength;
	}

	cvt_ds cvt;
	cvt.ui64 = 0;

	BOOL status = ReadPciConfigDwordEx(pciAddress, (DWORD)offset, &(cvt.ui32.low));
	status &= ReadPciConfigDwordEx(pciAddress, ((DWORD)offset) + sizeof(uint32), &(cvt.ui32.high));

	if(status)
	{
		*value = cvt.ui64;
		return sizeof(uint64);
	}
	return 0;
}
Esempio n. 2
0
File: pci.cpp Progetto: dfyer/joins
int32 PciHandle::read32(uint64 offset, uint32 * value)
{
	if(hDriver != INVALID_HANDLE_VALUE)
	{
		PCICFG_Request req;
		ULONG64 result = 0;
		DWORD reslength = 0;
		req.bus = bus;
		req.dev = device;
		req.func = function;
		req.bytes = sizeof(uint32);
		req.reg = (uint32)offset;

		BOOL status = DeviceIoControl(hDriver, IO_CTL_PCICFG_READ, &req, sizeof(PCICFG_Request), &result, sizeof(uint64), &reslength, NULL);
		*value = (uint32)result;
		if (!status)
		{
			//std::cerr << "Error reading PCI Config space at bus "<<bus<<" dev "<< device<<" function "<< function <<" offset "<< offset << " size "<< req.bytes  << ". Windows error: "<<GetLastError()<<std::endl;
		}
		return reslength;
	}
	DWORD result = 0;
	if(ReadPciConfigDwordEx(pciAddress,(DWORD)offset,&result))
	{
		*value = result;
		return sizeof(uint32);
	}
	return 0;
}
BOOL SysReadPciConfigDwordEx(DWORD pciAddress, DWORD regAddress, PDWORD value)
{
	if (SpecialEcsAccessRequired(regAddress)) {
	        return SpecialEcsAccess(false, pciAddress, regAddress, value);
	}
	return ReadPciConfigDwordEx(pciAddress, regAddress, value);
}