How UEFI drivers use the content in the ACPI tables - bios

I came across this project on gibhub https://github.com/UEFI4Phone/edk2sdm/tree/master/Sdm835/SamsungS8Pkg/AcpiTables
This is my first time trying to dig into some non C written files in EDK2. Please excuse me if I did not make it clear.
I realized there are ACPI tables in EDK2 to describe system information that is hardware specific.
When I read the ACPI spec https://uefi.org/specs/ACPI/6.5/05_ACPI_Software_Programming_Model.html
, it mentioned
When OSPM locates the structure, it looks at the physical address for
the Root System Description Table or the Extended System Description
Table.
Also, from Wikipedia https://en.wikipedia.org/wiki/ACPI
The (ACPI) specification is central to the Operating System-directed
configuration and Power Management (OSPM) system. ACPI defines
hardware abstraction interfaces between the device's firmware (e.g.
BIOS, UEFI), the computer hardware components, and the operating
systems.
Looks like BIOS/UEFI only defines (or stores) the ACPI tables and they are used by the operating system.
How does the UEFI make use of the ACPI tables? Does UEFI have drivers to fetch the values in the *.aslc file?

Related

HAL vs BSP vs Drivers

Some context: I'm working on embedded system with Micro-Controler targets. My purpose here is to clarify the terms I can use for my code repository names. I focus on the low-level naming in that post which represents for me the target-oriented code (versus application-oriented code for the high level).
I enter in a loop over the web and forums where nobody seems to clearly defined the difference between these terms: HAL vs BSP vs Drivers.
According to me, all my three terms are theoretically equivalent, but people seems to make difference where the HAL is reserved for the MCU drivers (e.g. UART, GPIO, ...) and the BSP is reserved for the external peripheral drivers (e.g. accelerometer, EEPROM, ...).
Can somebody help me to clarify this? Additionally, can you mention if your answer is based on your personal opinion or if it is based on the reasoning/rationale of a community/company/standard/whatever?
Thank you for your time,

Atom/BayTrail SoC SSP/SPI programming

My particular hardware target is a MinnoboardMax Turbot Dual-E, but I believe this question is generic to Intel Atom/BayTrail processors on other boards.
The SoC has a "multifunction serial port" (SSP) that can be used as a SPI bus interface. It can be attached by ACPI or by PCI (in the later case, the PCI id is 0x8086:0x0f0e). And within the Linux kernel, there is existing driver support (low_speed_spidev, spi_pxa2xx_pci, spi_pxa2xx_platform) which allows access to the hardware.
I would like to access the hardware from UEFI, and I'm finding very little documentation on how to access or program this hardware. I don't care very much whether I have to set it into ACPI or PCI mode in the BIOS, either one is OK for my purposes. I'd love to find an existing driver, but after half a day of searching I'm pretty convinced it's not out there. (Happy to be proven wrong on that.)
In lieu of that, can anyone point me to any code examples that would help to bootstrap this? I've tried looking at the Linux and BSD source code, but they both involve so many extra layers for generality/portability that I'm having trouble sorting out the portions that relate to this particular device, and the portions that simply support a generic driver model.
Edit: Post originally mistakenly said AHCI.

Why do we need AML - ACPI Machine Language?

As I understand, ACPI defines a generic hardware programming model where operating system relies on the OEM firmware provided AML (ACPI machine language) code to manipulate the hardware.
In order to execute the AML code, operating system has to incorporate an AML interpreter.
So, it looks to me that firmware developers use AML to provide a control interface between platform hardware and operating system.
But do we really need AML?
I think ultimately the hardware can only be configured through the native instruction of the platform. So the AML interpreter must translate the AML into native instructions otherwise it cannot be executed on the platform.
But what's the point of using an intermediate language like AML? I mean though the AML is said to be platform-independent, which means I can use AML to describe my platform in a non-native way.
But the AML is part of the platform firmware in practice. And the entire firmware has already been built into the target platform's native instructions. So what good can it be to make such a little part of the firmware as platform-independent? Why not just use native instructions? There must be some way to let OS use it as well. And this way operating system doesn't need the AML interpreter at all. A lot of complexity can be avoided.
One of the big goals of ACPI over its predecessor APM was to give the OS more viability and control over power state transitions.
APM was a black box. The OS knew nothing about the power management implementation. It would just call a BIOS function and the BIOS handled all of the magic. Did it work? Did the system sleep properly? Did the system freeze? Was a user application able to handle the BIOS implementation? The sad truth was that many systems had power management that was downright broken, and Microsoft wanted to provide a better power management experience for the growing laptop industry.
Now, the BIOS hands the ASL/AML code over to the OS and the OS executes it not the BIOS. If the BIOS code does something dumb (like messing with registers it shouldn't), Windows can detect that by parsing the code and block it. AML is 100% decompilable unlike C.
Remember that ACPI is not x86 specific. At the time it was developed, Itanium and Xscale were around. Intel and Microsoft needed a language that would work on all platforms, both 32 and 64 bit.
Lastly, ASL is more than just a list of executable functions. It is also number of static configuration tables. The ASL code has tables to define the non PnP hardware built onto your motherboard. It has tables of supported power states. A traditional programming language like C isn't really setup for that.
If ACPI was invented today, they would probably use something like XML to provide the info to the OS.
Originally, hardware for "80x86 PC" was cloned from IBM's PC, and this created an effective de-facto standard for hardware to follow. However it didn't take long before manufacturers wanted to add features that didn't previously exist, where there was no (official or de-facto) standard to follow.
This led to a major problem for operating system software (how do you support "non-standard chaos"). Some standards were created for some things (APM, etc) but they didn't really cover everything needed and became out-of-date. ACPI was created to fix this.
Ideally, what was (and still is) needed is standards that allow operating system to detect and use supported features of the motherboard. For example, a "standardised case temperature and fan control" device (with support for detecting how many fans, temperature sensors, etc), or a "standardised CPU speed/power consumption", a "PCI slot IRQ routing for IO APICs" standard, a "hot-plug PCI controller device" standard, etc.
However, ACPI didn't provide useful standards that hardware manufacturers and operating systems can use. Instead, ACPI provided an over-engineered mess (AML) to allow an OS to cope with ACPI's failure to standardise the hardware.
Essentially; we "need" AML now because it's the only viable way for an OS to work-around the "non-standard chaos" problem that ACPI failed to fix.
The problem with providing native code instead of AML is that different operating systems use CPUs in different ways (e.g. native 64-bit 80x86 code in firmware would be useless for an older "32-bit only" OS). AML provides portability between different types of CPUs and between the same CPU/s in different modes.
Also; native code is considered a major security problem (rootkits, etc); and people tend to think an interpreted language mitigates that problem. Of course in practice AML needs far too much access to the underlying hardware and does it in a way that an OS can't check, and there's isn't even a way for an OS to determine if the AML has been maliciously modified before the OS booted. For these reasons AML is still a major security problem despite using interpreted language.

Possible to use BIOS interrupts in Forth?

I am doing a class project comparing different programming languages. Is it possible to use BIOS interrupts in the Forth language? I can't seem to find any such information on this. If so what would be an example?
I think you're under a mistaken idea that there's a single all-encompassing "Forth" out there. There isn't. There are many Forth implementations. Those that run "bare bones" (without an OS) or under DOS can certainly be coaxed to access the BIOS APIs. Those that run under a 32 or 64 bit operating system like Windows or Linux are unlikely to provide such functionality, since the operating system makes it hard to run BIOS APIs to start with.
When running under Windows, using 16-bit BIOS APIs (as opposed to reading data without running BIOS code) is cumbersome. Modern BIOSes also offer 32-bit APIs, but in all cases you're limited to what hardware you can access (none) - this is enforced by the OS, not by the BIOS code.
Generally speaking, the BIOS APIs are cumbersome and there's no point to using them when you have a full-blown operating system available to you.
Now if you don't care much whether the BIOS calls access real hardware or emulated hardware, you can certainly use Forth to access something like DOSBox and run the real BIOS on emulated hardware. Heck, DOSBox provides its own BIOS implementation :)

Most suitable Unix platform for developing device drivers

I completely newbie in device drivers, so I hope my question is in place, but I need to develop a driver to control some equipment. I was thinking on using Linux as the host OS, but not sure if it is such good idea. I've heard some horror stories about the mess of developing device drivers under Linux. Is there a better alternative under the *Nix world? Or maybe should I check other OSes?
Linux documentation is basically non-existent (similar to other platforms). However, there are a few books which do cover enough information to get started, and the trickier kernel bits can borrowed from other drivers (yay for Open Source).
However, it is one of the easiest current platforms to develop drivers for. There are cleaner models, such as QNX, but that product is sadly near the end (and doesn't support 1/10th as much as hardware as Linux)
What type of device is the driver targetting? Many times you can avoid writing in-kernel drivers (for instance, using libusb in userspace, or the user space IO framework)

Resources