Writing PCI Config space?

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
Wolf9466
Posts: 12
Joined: Sun Jun 28, 2009 11:17 pm

Writing PCI Config space?

Post 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?
User avatar
thepowersgang
Member
Member
Posts: 734
Joined: Tue Dec 25, 2007 6:03 am
Libera.chat IRC: thePowersGang
Location: Perth, Western Australia
Contact:

Re: Writing PCI Config space?

Post 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)
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc
Post Reply