Page 1 of 1

Writing PCI Config space?

Posted: Sat Apr 02, 2011 7:09 pm
by Wolf9466
I've written functions to read the PCI configuration space, but I can't seem to find any sources to write it. I looked at the Linux source, and it does some strange thing with a structure, I checked Google, and it only has advice on how to do it with existing drivers, and there's nothing in the wiki on it. I tried this:

Code: Select all

void PCIConfigWriteWord(unsigned long bus, unsigned long dev, unsigned long func, unsigned long reg, unsigned short val)
{
	 /* Create and write out config address  */
    outd(PCI_CONFIG_ADDR, (unsigned long int)((bus << 16) | (dev << 11) | (func << 8) | (reg & 0xfc) | ((unsigned int)0x80000000)));

	/* Write out the data */
	outd(PCI_DATA_ADDR, val);
	return;
}
but it didn't work. Any advice?

Re: Writing PCI Config space?

Posted: Sat Apr 02, 2011 10:35 pm
by thepowersgang
Assuming you have your port numbers correct, and the range of values you are passing is valid. The only problem with that code is the value you are writing is being passed as a short (which is usually 16 bits), it should be a long (or preferably something like uint32_t)