Page 1 of 1
USB ECHI PROCEDURE
Posted: Tue Sep 05, 2017 9:22 pm
by Jeland
Hi, Can somebody help me steps on how to perform usb ehci.
I was stuck after getting the BAR address. I got an address 0xA331D0000 and when reading the capabilities register all i got is 0.
I don't know if its because the memory mapped OI in the BAR0 is above 1MB and I'm doing this in real mode.
Is it possible to change the memory mapped OI address in BAR0 below to 1MB address like in 0xD0000000 segment?
Thanks a Lot.
- Jay
Re: USB ECHI PROCEDURE
Posted: Tue Sep 05, 2017 9:54 pm
by BenLunt
Jeland wrote:Hi, Can somebody help me steps on how to perform usb ehci.
How far along are you? Doesn't sound very far.
Jeland wrote:I was stuck after getting the BAR address. I got an address 0xA331D0000 and when reading the capabilities register all i got is 0.
That address doesn't look right, though it could be.
Jeland wrote:I don't know if its because the memory mapped OI in the BAR0 is above 1MB and I'm doing this in real mode.
Unless you are using 32-bit addressing in real mode, you aren't going to read anything from the EHCI.
Jeland wrote:Is it possible to change the memory mapped OI address in BAR0 below to 1MB address like in 0xD0000000 segment?
Yes. But not below 1Meg, and 0xD0000000 is not below 1Meg. Also, it is I/O, not OI. I/O is Input/Output.
It sounds like you are just starting and have a lot of reading and research ahead of you. There are many resources to start with. The specifications would be a good start. Maybe a good book?
http://www.usb.org/developers/docs/
https://www.intel.com/content/www/us/en ... ation.html
http://www.fysnet.net/the_universal_serial_bus.htm
See what you can find out and then post a little code or something that we can have a look at.
Ben
P.S. May I ask why you are (possibly) starting with EHCI? UHCI and OHCI are a bit easier and usually are required for a good EHCI implementation. Also, xHCI is a bit easier than EHCI, in my opinion. Just curious.
Re: USB ECHI PROCEDURE
Posted: Tue Sep 05, 2017 11:01 pm
by Jeland
Well I just started last Month?
I've been reading usb2 specs and ehci specs.
I'm sorry, Typing Error. The Address I got is 0xA331D000 not 0xA331D0000.
and the below 1MB address is 0xD0000 physical address and i'm using 16 bit addressing..
Well when i try to scan PCI devices. I only have EHCI and xHCI.
i'm thinking usb2 will be a good start.
Btw, If the base address i got is correct, how can i read the capability register using MMIO?
I'm using MASM Assembly for coding..
Also I already ordered your book and still waiting for it. Hopefully it will help me..
Here is my small code
Code: Select all
push 0 ; Reserved 00FEh - 00FFh
push 0 ; Reserved 00FCh - 00FDh
xor ax, ax ; Clear AX Register
mov ax, @Data ; Set DS
mov ds, ax ;
call Check_PCI ; CHECK PCI INSTALLED (int 1Ah)
mov bp, sp
.....
mov byte ptr ds:[bp+3], 080h ; Enable PCI Access
mov byte ptr ds:[bp+2], 000h ; start to Bus 0
mov byte ptr ds:[bp+1], 0E8h ; start to ECHI Device and Function 0
mov byte ptr ds:[bp], 000h ; start to register 0
.....
; Read EHCI BAR
mov byte ptr ds:[0FCh],10h ; OFFSET 0x10 BAR0
mov si, 0FCh
mov dx, PCI_INDEX ;PCI_INDEX = 0CF8h
outs dx, dword ptr ds:[si]
mov dx, PCI_DATA ;PCI_DATA = 0CFCh
in eax, dx
and eax, 0FFFFFF00h ; Mask lower byte
mov esi, eax
mov mov dl, [esi + 00h] ; Read CAPLENGTH
.....
Re: USB ECHI PROCEDURE
Posted: Wed Sep 06, 2017 12:29 am
by Korona
You cannot access the BAR using 16 bit addressing (as its address is > 1 MiB). Switch to 32 bit protected mode (or if you're really masochistic unreal mode).
Re: USB ECHI PROCEDURE
Posted: Wed Sep 06, 2017 12:37 am
by Jeland
You cannot access the BAR using 16 bit addressing (as its address is > 1 MiB). Switch to 32 bit protected mode (or if you're really masochistic unreal mode).
Is there a way to change the address in BAR0 so that it can be accessed using 16-bit addressing?
Re: USB ECHI PROCEDURE
Posted: Wed Sep 06, 2017 12:42 am
by thepowersgang
All of the addresses below 1MB are already "allocated", so no, you can't.
There is no reason to be using real mode on a machine that has a USB controller, switch to protected mode and things become a lot easier.
Re: USB ECHI PROCEDURE
Posted: Wed Sep 06, 2017 5:23 am
by Octacone
Sorry, but USB + Real Mode combination is just plain stupid. Real mode is stupid thing to consider in 2017 by itself.
It is so old that it might even get removed as a mode all-together.
Please switch to protected/long mode if you want to have any chances of success.
Listen all, it is okay to have fun in real mode as a hobby, but considering it as a solution in 2017 is just ridicules.
Real mode just makes your life a whole lot harder, when wanting to implement some of the newer hardware.
It is your OS, do whatever you want, this is just my honest opinion/suggestion.
Re: USB ECHI PROCEDURE
Posted: Wed Sep 06, 2017 8:49 am
by BenLunt
These are all good suggestions you should take. The only way to access the memory-mapped hardware in real mode is to move to protected mode, initialize the selectors, then move back to real mode, creating what has been termed as unreal mode. Then you can use 32-bit registers to access memory above the 1 Meg mark. However, if you are going to go through the trouble to get to unreal mode, you might as well stay in protected mode. The only advantage to unreal mode is that you still have (Legacy) BIOS access.
My book shows you, from the beginning, how to get started, step by step. How to first access the PCI and find the device, and how to extract the information you need from it. It then shows you how to access the hardware using a flat address space. However, Volume 8 does not show you have to get to that flat address space. This is assumed, shown in Volume 1, and/or learned from other resources.
Also, from what I gather, you may not know the difference between Port I/O and Mem-mapped I/O. Port I/O you use the 'in' and 'out' instructions. Mem-Mapped I/O is reading and writing from/to an address in the memory address space using memory access instructions, just like accessing real memory. The hardware "catches" the read/write before it makes it to physical memory.
When my book arrives, be sure to follow the instructions to get the associated CDROM which has C source code examples and utilities. Also be sure to see
http://www.fysnet.net/the_universal_serial_bus.htm for an errata and other notes not yet added to the book.
Once you have read a while, and have tried some code of your own, feel free to post more questions. However, please note that we won't do it for you. We are more than happy to point you in the right direction, point out an error or two, but you must do the work. Hope that doesn't sound rude, but it is the truth.
Above all else, enjoy your work.
Ben