OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Apr 17, 2024 11:49 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Getting the raw enumeration of devices on custom OS
PostPosted: Tue Feb 09, 2016 5:58 am 
Offline
Member
Member

Joined: Tue Mar 10, 2015 10:08 am
Posts: 97
Hello,

I work on a project which will have no filesystem because of the space. We just have "unformated space". The different datas are located at defined offsets, so far so good.

But, I would like to know how we can enumerate all the hardware on a machine.

There is the device tree spec; but I can't stress to use it because of the weird structure of our "filesystem".

Is there a memory location I should look into to start the enumeration of devices? And possibly in a raw format (no blob requiring external tools). Just vendor ID, device ID, address, bus, irq and so on (like in a traditional device tree).

It seems we may getaway from the standards here and I need to know the issues.

Anyone already messed up with a simple kernel enumerating the devices onboard?

Thanks


Top
 Profile  
 
 Post subject: Re: Getting the raw enumeration of devices on custom OS
PostPosted: Tue Feb 09, 2016 8:28 am 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
On a modern PC, you really only have two options: PCI and ACPI.

PCI is much simpler to use, but ACPI gives you a lot more information.

You can read about both of these on the wiki, but basically you can enumerate PCI devices by reading and writing to a specific I/O address. For ACPI, you have to search through system memory to find several data tables that contain information about your system.

Hopefully this answers your question. Let us know if you have any other specific questions, and we'll try to help.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: Getting the raw enumeration of devices on custom OS
PostPosted: Tue Feb 09, 2016 8:33 am 
Offline
Member
Member

Joined: Tue Mar 10, 2015 10:08 am
Posts: 97
AAAh, i forgot about those tables (madt, fadt and so on).

Thanks Spyder


Top
 Profile  
 
 Post subject: Re: Getting the raw enumeration of devices on custom OS
PostPosted: Tue Feb 09, 2016 9:00 am 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

For some reason (not sure why), when I looked at this earlier I assumed "embedded devices"...

For PC; it's important to understand that you're building a hierarchical tree.

You'd start with ACPI (or Intel's "Multi-processor spec" on old systems) and get NUMA information, initial CPU information, more (in addition to whatever you got from "int 0x15, eax=0xE820") memory information, and some information about PCI host controller/s.

The next layer is PCI bus enumeration (using PCI configuration space).

The next layer after that is "controller specific enumeration" (which mostly requires PCI device driver cooperation). This includes things connected to USB controllers, things connected to hard disk controllers, things connected to video cards, etc. You can throw "PCI to LPC bridge" device enumeration into this layer too; but that's mostly done via. ACPI and not a device driver.

Beyond that, it ends up being a recursive search. E.g. USB controller driver tells you about all the USB devices connected to it (which might include a USB hub); USB hub driver tells you about all the USB devices connected to it (which might include a "USB to serial" adapter); "USB to serial" adapter driver tells you about whatever is attached to the other end of each of its serial ports; etc.

Because you've built a hierarchical tree; if someone unplugs the USB hub you know all the devices connected to it (and the devices connected to those devices and .... all the way to the leaves of the tree) are all gone; and if you want to send a PCI device to sleep to save power you know exactly which device/s (from that device all the way to the leaves of the tree) will be effected, and which devices should wake it back up again.

Also note that for hot-plug this doesn't just happen during boot. E.g. if someone plugs in a PCI device (a USB controller) then you end up enumerating (starting from that device) all over again.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Getting the raw enumeration of devices on custom OS
PostPosted: Tue Feb 09, 2016 9:16 am 
Offline
Member
Member

Joined: Tue Mar 10, 2015 10:08 am
Posts: 97
Yes it is for an embedded environment; we are using an intel atom processor.

Some more details: there are no usb and basically, nothing that can be unplugged, but the hardware may be different (means that the OS can run on top of multiple hw configurations that will not change over time).

I heard ACPI would make its way in ARM too. So ACPI is the way to go.


Top
 Profile  
 
 Post subject: Re: Getting the raw enumeration of devices on custom OS
PostPosted: Tue Feb 09, 2016 8:08 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

JulienDarc wrote:
I heard ACPI would make its way in ARM too. So ACPI is the way to go.


UEFI and ACPI have made their way to some ARM systems (mostly servers). I doubt it'll ever make its way to normal ARM embedded SoCs (where its a huge amount of work for chip manufacturers and none of their customers want it).

ACPI doesn't tell you anything useful about most PCI devices or anything connected to any controllers (USB devices, hard disks, etc). Since the very first versions of ACPI's specification it has said (paraphrased from memory) "If the hardware itself provides facilities for enumeration, then there's no point duplicating it in ACPI". For hardware that doesn't provide its own facilities for enumeration (power supply, fans, battery, legacy ISA devices built into the motherboard, IO APIC, etc) for most (but not all) of it you need an AML interpreter (e.g. ACPICA).


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


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

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 93 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