So im working on a UHCI driver. I initialised the controller and I want to see which ports are connected. On qemu and bochs this goes well. On real hardware it keeps rising interrupts and saying there is nothing in the ports. This is my code: https://github.com/AdeRegt/SanderOSUSB/ ... CI?files=1

Post subject: Re: UHCI can find usb on emulators but not on real hardware

Posted: Wed Nov 28, 2018 2:00 pm

Member

Joined: Sat Nov 22, 2014 6:33 pmPosts: 560Location: USA

I haven't had a chance to look over your code yet, but I plan on it soon.

One of the biggest things to recognize when it works on emulators, whom are horrible at absolute timing, and real hardware, which is excellent at real timing, is, well you guessed it, timing.

You must allow the hardware to actually do what it is asked to do. On an emulator, the emulation is already there. i.e.: as soon as you request the data, the data is already there waiting to be sent. On real hardware, this is not necessarily the case.

Also, the reset of the device has a lot of differences between emulators and hardware. On an emulator, it simply is the setting and clearing of the reset bit. Done. On real hardware, it is the timing between the time the reset bit is set, then cleared, as well as which other bits are set or cleared at the same time. If my memory serves, one of the bits in the Ports register *must* be cleared before or at the same time you clear the reset bit or a device will not reset.

Welcome to the art of real hardware testing. I will tell you, a hardware analyzer, such as the Beagle I got, is a wonderful piece of hardware to help with this stuff, if you can afford the expense.

When I get a chance, I will have a look at your code. In the meantime, check your reset timing and other timing code.

I send the Global Reset (bit 2) instead of the HCReset (bit 1). This makes sure that all devices attached also see a reset.

Just for your information, it is much easier to read the following:

Code:

outportw(BAR,(1<<1)); // set bit 1

than

Code:

outportw(BAR,0b0000000000000010);

i.e.: Using "(1<<8)" is much easier to read than "0b0000000100000000". You don't have to count bits with (1<<8).

A few more notes: - Some controllers/devices require the schedule to be running before a port reset. - You *must* check the "HcHalted" bit after starting/stopping the schedule. Simply setting or clearing the "Run" bit does not mean it is started/stopped. The "HcHalted" bit indicates if the schedule is running or not. - Write your port initialize code so that sending a port index value will indicate which port you are initializing. i.e:

Code:

void init_uhci_port(unsigned long BAR){

should be

Code:

void init_uhci_port(const phy_address BAR, const int portnum) {

All routines that manipulate a port should have an index such as this. ("phy_address" is defined/typedef as 32-bits or 64-bits depending on the machine it is compiled for. However, for PORT I/O, this isn't must of a need. For MEM-MAPPED I/O, this is a great need.)

- Use #define's for registers. i.e.:

Code:

#define UHCI_COMMAND 0x0000

etc., then use

Code:

outportw(BAR + UHCI_COMMAND, value);

This is so much easier to read, allowing the reader (you) to know which register you are writing to. Go a little further and use #define's for each bit as well.

it keeps hanging in there "forever" and shows this (emulator snapshot) :

Because the controller will not clear bit 2 when it is done. You must clear it after 10ms. Please note that this is 10 milliseconds, not 10 seconds. Your code suggests that you are waiting one (1) second per tick. This is way too long. Also, after the reset, clearing the bit, you need to delay again for USB_TRSTRCY milliseconds. This is the recovery wait.

All of this is explained in the UHCI specification sheet. A quick search for "UHCI specs" will bring it up. (Hint, this is the first)

SanderR wrote:

Also, must I set the run bit in order to detect the devices? since I have no commands for my queue. Thank you.

You shouldn't have to, per the specification, but I have found that if the run bit is not set, some controllers don't perform as advertised. I have seen comments to this in other code/documentation as well.

Post subject: Re: UHCI can find usb on emulators but not on real hardware

Posted: Mon Feb 11, 2019 4:21 pm

Joined: Tue Aug 30, 2016 1:31 pmPosts: 10

No, I have not made any progress.I had a small pause and then started again with hope this time it would go better.Still, on the emulators (BOCHS and QEMU) it is working while on real hardware it is still refusing.I am currently working on a way to make the queue work and maybe it is detected that way.The system is booted from USB, but LEGACY says it is 0xFFFF so probably it will not change the outcome of my code.

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 10 guests

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