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
Getting the raw enumeration of devices on custom OS
-
- Member
- Posts: 97
- Joined: Tue Mar 10, 2015 10:08 am
Re: Getting the raw enumeration of devices on custom OS
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.
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
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
-
- Member
- Posts: 97
- Joined: Tue Mar 10, 2015 10:08 am
Re: Getting the raw enumeration of devices on custom OS
AAAh, i forgot about those tables (madt, fadt and so on).
Thanks Spyder
Thanks Spyder
Re: Getting the raw enumeration of devices on custom OS
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 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.
-
- Member
- Posts: 97
- Joined: Tue Mar 10, 2015 10:08 am
Re: Getting the raw enumeration of devices on custom OS
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.
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.
Re: Getting the raw enumeration of devices on custom OS
Hi,
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
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).JulienDarc wrote:I heard ACPI would make its way in ARM too. So ACPI is the way to go.
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.