OSDev.org

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

All times are UTC - 6 hours




Post new topic Reply to topic  [ 8 posts ] 
Author Message
 Post subject: USB ECHI PROCEDURE
PostPosted: Tue Sep 05, 2017 9:22 pm 
Offline

Joined: Mon Aug 07, 2017 1:10 am
Posts: 3
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


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Tue Sep 05, 2017 9:54 pm 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
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.


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Tue Sep 05, 2017 11:01 pm 
Offline

Joined: Mon Aug 07, 2017 1:10 am
Posts: 3
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:
   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
   
   .....


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Wed Sep 06, 2017 12:29 am 
Offline
Member
Member

Joined: Thu May 17, 2007 1:27 pm
Posts: 999
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).

_________________
managarm: Microkernel-based OS capable of running a Wayland desktop (Discord: https://discord.gg/7WB6Ur3). My OS-dev projects: [mlibc: Portable C library for managarm, qword, Linux, Sigma, ...] [LAI: AML interpreter] [xbstrap: Build system for OS distributions].


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Wed Sep 06, 2017 12:37 am 
Offline

Joined: Mon Aug 07, 2017 1:10 am
Posts: 3
Quote:
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?


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Wed Sep 06, 2017 12:42 am 
Offline
Member
Member
User avatar

Joined: Tue Dec 25, 2007 6:03 am
Posts: 734
Location: Perth, Western Australia
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.

_________________
Kernel Development, It's the brain surgery of programming.
Acess2 OS (c) | Tifflin OS (rust) | mrustc - Rust compiler
Currently Working on: mrustc


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Wed Sep 06, 2017 5:23 am 
Offline
Member
Member
User avatar

Joined: Fri Aug 07, 2015 6:13 am
Posts: 1134
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.

_________________
OS: Basic OS
About: 32 Bit Monolithic Kernel Written in C++ and Assembly, Custom FAT 32 Bootloader


Top
 Profile  
 
 Post subject: Re: USB ECHI PROCEDURE
PostPosted: Wed Sep 06, 2017 8:49 am 
Offline
Member
Member
User avatar

Joined: Sat Nov 22, 2014 6:33 pm
Posts: 934
Location: USA
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


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], DotBot [Bot] and 65 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