PCI questions
PCI questions
Hello,
I am currently making a PCI bus driver. I have a few questions however.
How do I read the PCI BARs? I know they are in the configuration space, but since they are DWORDs, how do read them.
How do I figure out what IO APIC line INTA, INTB, INTC, and INTD are without ACPI?
Do I need to enable PCI IRQs explicitly? If so, how do you do it?
And lastly, how do you work with the PCI Busmastering DMA?
Thanks,
nexos
I am currently making a PCI bus driver. I have a few questions however.
How do I read the PCI BARs? I know they are in the configuration space, but since they are DWORDs, how do read them.
How do I figure out what IO APIC line INTA, INTB, INTC, and INTD are without ACPI?
Do I need to enable PCI IRQs explicitly? If so, how do you do it?
And lastly, how do you work with the PCI Busmastering DMA?
Thanks,
nexos
- bellezzasolo
- Member
- Posts: 110
- Joined: Sun Feb 20, 2011 2:01 pm
Re: PCI questions
For BARs - Read configuration space as a DWORD.nexos wrote:Hello,
I am currently making a PCI bus driver. I have a few questions however.
How do I read the PCI BARs? I know they are in the configuration space, but since they are DWORDs, how do read them.
How do I figure out what IO APIC line INTA, INTB, INTC, and INTD are without ACPI?
Do I need to enable PCI IRQs explicitly? If so, how do you do it?
And lastly, how do you work with the PCI Busmastering DMA?
Thanks,
nexos
Figuring out IO APIC lines without ACPI? Basically, you don't. You need an AML interpreter to get the correct mappings.
Or, you take my approach, and just use MSI(X) instead
For IRQs, you need to unmask bit 10 of Command/Status to enable pinned interrupts. For MSI, it's a bit of the MSI control register.
Set Bits 1 and 2 of Command/Status to enable memory access and bus mastering.
My PCI(E) code
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
https://github.com/ChaiSoft/ChaiOS
Re: PCI questions
I'm not sure that I understand your problem. You just do a dword "in" to %eax.nexos wrote: How do I read the PCI BARs? I know they are in the configuration space, but since they are DWORDs, how do read them.
-
- Member
- Posts: 5572
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PCI questions
On ancient hardware (and VMs that can run OSes that work on ancient hardware) you can use the MP tables.nexos wrote:How do I figure out what IO APIC line INTA, INTB, INTC, and INTD are without ACPI?
Re: PCI questions
Thanks for your answers. I now have an understanding of PCI and have decided to use MSI in my Operating System.
Re: PCI questions
I have managed to make the PCI bus driver, but what is a simple PCI device I can program to test stuff like IRQs, BAR mapping, MSI, and Busmastering?
- bellezzasolo
- Member
- Posts: 110
- Joined: Sun Feb 20, 2011 2:01 pm
Re: PCI questions
Dare I say it, xHCI?nexos wrote:I have managed to make the PCI bus driver, but what is a simple PCI device I can program to test stuff like IRQs, BAR mapping, MSI, and Busmastering?
Not simple by any means, but it's not hard to test the IRQs and such. A "simple" device descriptor request tests bus mastering.
I'm currently working on an i219[v] driver, because I figure that'll be simpler than implementing a full USB stack for keyboard support, but I haven't tested bus mastering yet. BAR mapping and MSI work though.
Whoever said you can't do OS development on Windows?
https://github.com/ChaiSoft/ChaiOS
https://github.com/ChaiSoft/ChaiOS
Re: PCI questions
So in my BAR obtaining code, it appears that MMIO and IO Space regions are backwards. MMIO regions are set to be IO space and regions, and vice versa. The code that figures whether the BAR represents MMIO looks like this
Is that correct?
Code: Select all
INT isMmio = !barLow & 1;
-
- Member
- Posts: 426
- Joined: Tue Apr 03, 2018 2:44 am
Re: PCI questions
The lowest bit of the BAR is 1 if this is an IO address space BAR.nexos wrote:So in my BAR obtaining code, it appears that MMIO and IO Space regions are backwards. MMIO regions are set to be IO space and regions, and vice versa. The code that figures whether the BAR represents MMIO looks like thisIs that correct?Code: Select all
INT isMmio = !barLow & 1;
Your code looks like it should work, if barLow is a MMIO address, its LSB will be 0, !barLow LSB will be 1, and so isMmio will be non-zero (true). Have you inverted the test later on by accident?
I would find this test easier, though in the form:
Code: Select all
bool isMmio = (0==(barLow & 1));
Re: PCI questions
I have finished my PCI host controller driver. Thanks for all your help during its development.
nexos
nexos
-
- Member
- Posts: 5572
- Joined: Mon Mar 25, 2013 7:01 pm
Re: PCI questions
You forgot parentheses.nexos wrote:Is that correct?Code: Select all
INT isMmio = !barLow & 1;
Code: Select all
INT isMmio = !(barLow & 1);