Subject: Re: pci_read_config_byte
To: Allen Briggs <briggs@netbsd.org>
From: Ed <garbageout@sbcglobal.net>
List: tech-kern
Date: 05/28/2005 13:15:06
Allen Briggs wrote:
> On Sat, May 28, 2005 at 12:28:21PM -0500, Ed wrote:
> 
>>I'm borrowing some code from Linux.  What is the NetBSD equivalent of 
>>the Linux functions pci_read_config_byte and pci_write_config_byte?  I 
>>found pci_conf_read and pci_conf_write, but that seems to read and write 
>>a whole dword.  If this is not the correct forum for kernel hacking, 
>>please advise.  Thank you.
> 
> 
> PCI doesn't have a config read or write for anything but 32-bit
> quantities.  If you want to write a byte, you need to do the
> read-modify-write for the 32-bit quantity that contains that byte.
> The Linux functions probably just encapsulate that.
> 
> -allen
> 

Interesting.  Why then does Linux access the PCI config space in bytes, 
words, or dwords?

static int pci_conf1_read (int seg, int bus, int devfn, int reg, int 
len, u32 *value)
{
	unsigned long flags;

	if (!value || (bus > 255) || (devfn > 255) || (reg > 255))
		return -EINVAL;

	spin_lock_irqsave(&pci_config_lock, flags);

	outl(PCI_CONF1_ADDRESS(bus, devfn, reg), 0xCF8);

	switch (len) {
	case 1:
		*value = inb(0xCFC + (reg & 3));
		break;
	case 2:
		*value = inw(0xCFC + (reg & 2));
		break;
	case 4:
		*value = inl(0xCFC);
		break;
	}

	spin_unlock_irqrestore(&pci_config_lock, flags);

	return 0;
}