示例#1
0
void PCIDriverManager::Probe(int bus)
{
	// for each slot
	for (int slot = 0; slot < 32; slot++)
	{
		unsigned short vendor,device;
		/* try and read the first configuration register. Since there are no */
		/* vendors that == 0xFFFF, it must be a non-existent device. */
		vendor = pciConfigReadWord(bus,slot,0,0);
		if (vendor == 0xffff || vendor == 0x0000)
			continue;
		device = pciConfigReadWord(bus,slot,0,2);
		printf("Found PCI Device: %4x:%4x in slot %d\n", (int)vendor, (int)device, slot);
		if (device == 0xbeef || device == 0xcafe)
		{
			for (int l = 0; l <= 0x3c; l+= 4)
			{
				int data = pciConfigReadDword(bus, slot, 0, l);
				if (l >= 0x10 && l <= 0x24)
				{
					printf("\tBAR%d: %8x -> ", (l - 0x10) / 4, data);
					pciConfigWriteDword(bus, slot, 0, l, ~0);
					uint32_t sz = pciConfigReadDword(bus, slot, 0, l);
					pciConfigWriteDword(bus, slot, 0, l, data);
					if (data & PCI_BASE_ADDRESS_SPACE)
						printf("%8x (%x)\n", sz, pci_size(data, sz, PCI_BASE_ADDRESS_IO_MASK & 0xffff));
					else
						printf("%8x (%x)\n", sz, pci_size(data, sz,  (uint32_t)PCI_BASE_ADDRESS_MEM_MASK));
				}
				else if (data)
					printf("\t%2x: %8x\n", l, data);
			}
		}
	}
}
示例#2
0
文件: pci.c 项目: xvedejas/valix
PciConfigHeaderBasic pciGetBasicConfigHeader(u8 bus, u8 slot, u8 func)
{
    PciConfigHeaderBasic pciHeader;
    pciHeader.bus                       = bus;
    pciHeader.dev                       = slot;
    pciHeader.func                      = func;
    pciHeader.vendorId                  = pciConfigReadWord(bus, slot, func, 0x00);
    pciHeader.deviceId                  = pciConfigReadWord(bus, slot, func, 0x02);
    pciHeader.command                   = pciConfigReadWord(bus, slot, func, 0x04);
    pciHeader.status                    = pciConfigReadWord(bus, slot, func, 0x06);
    pciHeader.revisionId                = pciConfigReadByte(bus, slot, func, 0x08);
    pciHeader.classProgrammingInterface = pciConfigReadByte(bus, slot, func, 0x09);
    pciHeader.classSubclass             = pciConfigReadByte(bus, slot, func, 0x0A);
    pciHeader.classBase                 = pciConfigReadByte(bus, slot, func, 0x0B);
    pciHeader.headerType                = pciConfigReadByte(bus, slot, func, 0x0E);
    pciHeader.baseAddr[0]               = pciConfigReadDword(bus, slot, func, 0x10);
    pciHeader.baseAddr[1]               = pciConfigReadDword(bus, slot, func, 0x14);
    pciHeader.baseAddr[2]               = pciConfigReadDword(bus, slot, func, 0x18);
    pciHeader.baseAddr[3]               = pciConfigReadDword(bus, slot, func, 0x1C);
    pciHeader.baseAddr[4]               = pciConfigReadDword(bus, slot, func, 0x20);
    pciHeader.baseAddr[5]               = pciConfigReadDword(bus, slot, func, 0x24);
    pciHeader.interruptLine             = pciConfigReadByte(bus, slot, func, 0x3C);
    return pciHeader;
}
示例#3
0
uint16_t PCIDriverManager::pciConfigReadWord (unsigned short bus, unsigned short slot,
		unsigned short func, unsigned short offset)
{
	return (uint16_t)(pciConfigReadDword(bus, slot, func, offset) & 0xFFFF);
}
示例#4
0
文件: pci.c 项目: xvedejas/valix
u32 pciGetBar(u8 bus, u8 slot, u8 func, u8 bar)
{
    if (unlikely((u8)bar > 5))
        return 0;
    return pciConfigReadDword(bus, slot, func, 0x10 + ((u8)bar * 4));
}