OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 8:19 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: no response to USB get_descriptor
PostPosted: Fri Apr 07, 2023 1:51 am 
Offline

Joined: Fri Apr 07, 2023 1:15 am
Posts: 2
Created a custom kernel that starts from UEFI and trying to get USB controller working,
but I never get any response to get device descriptor. On an old Intel MacBook the keyboard
and mouse are usb devices, two EHCI controllers with two and three companion UHCI
controllers respectively. I first tried writing my own code but got no response so then
tried adopting
https://github.com/pdoane/osdev/tree/master/usb
and the same problem again at
UsbDevInit in usb/dev.c

I was wondering how a controller can access memory that is not in memory mapped range.
It uses Bus Mastering PCI but I notice Linux and MacOS refer to DMA in their usb controller code.
What could be causing this problem?


Top
 Profile  
 
 Post subject: Re: no response to USB get_descriptor
PostPosted: Wed Apr 12, 2023 3:34 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
burzin wrote:
It uses Bus Mastering PCI but I notice Linux and MacOS refer to DMA in their usb controller code.

Bus mastering is one type of DMA.

burzin wrote:
What could be causing this problem?

Does your PCI initialization code set up the command register in the configuration space? Firmware may not enable everything you need for you.


Top
 Profile  
 
 Post subject: Re: no response to USB get_descriptor
PostPosted: Wed Apr 12, 2023 4:40 pm 
Offline

Joined: Fri Apr 07, 2023 1:15 am
Posts: 2
I eventually found the cause when I looked at the assembly output of clang compiler.
It was the compiler emitting quad instructions when it should have emitted long ones.
I replaced all the u32 typedefs with uint32_t and that fixed it.

Yes I do set up the PCI command register, that is very confusing. The ICH8 data sheet
says UHCI is hardwired to disable MMIO, I enable port io and bus mastering. Then
how does the controller access the frame list and buffers, but it works anyhow.


Top
 Profile  
 
 Post subject: Re: no response to USB get_descriptor
PostPosted: Wed Apr 12, 2023 5:17 pm 
Offline
Member
Member

Joined: Tue Apr 03, 2018 2:44 am
Posts: 401
burzin wrote:
Yes I do set up the PCI command register, that is very confusing. The ICH8 data sheet
says UHCI is hardwired to disable MMIO, I enable port io and bus mastering. Then
how does the controller access the frame list and buffers, but it works anyhow.


MMIO is mapping device registers into the memory address space. UHCI registers are defined in terms of IO port space, not memory mapped space (as indicated by PCI BAR0 bit 0).

The frame list is referenced by the Frame List Base Address register. That points to memory in the PCI device address space, which is access using PCI busmaster DMA. On PCs, that address space often corresponds to the same physical address space used by RAM memory, but it may not be so if the PCI device address space is mapped using an IOMMU.

The frame list itself points to queue heads (QH) and/or transfer descriptors (TD), which are the data structures which actually point to buffers, and again, those buffers are accessed using PCI busmaster DMA in the PCI device address space.


Top
 Profile  
 
 Post subject: Re: no response to USB get_descriptor
PostPosted: Wed Apr 12, 2023 5:36 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 5099
burzin wrote:
Yes I do set up the PCI command register, that is very confusing. The ICH8 data sheet
says UHCI is hardwired to disable MMIO, I enable port io and bus mastering. Then
how does the controller access the frame list and buffers, but it works anyhow.

MMIO has nothing to do with how the PCI device accesses memory. MMIO is when the CPU uses memory instructions like MOV to access the PCI device's registers. Bus mastering DMA is when the PCI device accesses memory.

You can't access UHCI registers with MOV, so the MMIO bit does not need to be set.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot] and 59 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group