36

Even if we remove the default OS and install a new one it can interact with the battery. Are there some drivers for it? How does it work?

0

3 Answers 3

33

The operating system interfaces with the firmware of an embedded controller that is part of the Advanced Configuration and Power Interface (ACPI).

Wikipedia defines it as :

In a computer, the Advanced Configuration and Power Interface (ACPI) provides an open standard that operating systems can use to discover and configure computer hardware components, to perform power management by (for example) putting unused components to sleep, and to perform status monitoring. First released in December 1996, ACPI aims to replace Advanced Power Management (APM), the MultiProcessor Specification, and the Plug and Play BIOS (PnP) Specification.[1] ACPI brings the power management under the control of the operating system, as opposed to the previous BIOS-centric system that relied on platform-specific firmware to determine power management and configuration policies.

Internally, ACPI advertises the available components and their functions to the operating system kernel using instruction lists ("methods") provided through the system firmware (Unified Extensible Firmware Interface (UEFI) or BIOS), which the kernel parses. ACPI then executes the desired operations (such as the initialization of hardware components) using an embedded minimal virtual machine.

The answer is then that a circuit or micro-chip is embedded in the motherboard, that itself contains a micro operating system which makes available some services via the computer firmware - UEFI or BIOS. It controls many aspects of power and device management.

The computer operating system has a system driver that is dedicated to interfacing with ACPI. Once ACPI is activated, it takes exclusive control of all aspects of power management and device configuration.

In many aspects ACPI is an operating system behind your operating system, except that it comes with the motherboard and is not under your control. There have been voices likening it to a Trojan horse and calling it a security risk. It may be disabled, but some computers may not boot without it, and advanced power management is then in any case disabled as well.

For more information about its use in Windows see the article Battery and power subsystem hardware design.

17
  • 1
    I might be wrong but it sounds like the last paragraph's description completely confuses ACPI with SMM and/or with Intel's ME/AMT. ACPI is mostly a static data structure, with small amounts of bytecode that the OS itself has to interpret, whereas ME is the actual system. Commented Oct 5, 2018 at 10:46
  • 1
    @grawity: Don't think so. You may find a similar discussion in the Wikipedia ACPI article.
    – harrymc
    Commented Oct 5, 2018 at 10:47
  • 1
    I don't see much discussion in there beyond a few quotes from one Shuttleworth's one blog post, and after reading both pages I'm not convinced in the slightest – it seems to me that he just lumps everything that comes with the system under the "ACPI" name, be it the BIOS or the Intel ME or whatever. As far as I know, out of all the garbage that comes with a modern system, ACPI is probably the only part that doesn't run on its own, and certainly not under the OS. Commented Oct 5, 2018 at 11:00
  • 2
    @grawity ACPI includes a firmware level code execution interface too though, that's how a lot of the firmware interaction involving it actually happens. On certain systems, this even uses SMM for the actual code execution, though that is thankfully getting less and less common. Commented Oct 5, 2018 at 17:44
  • @grawity: Yes, ACPI does nothing in the sense that it's only a controller. The UEFI/BIOS similarly manages devices and is placed higher in the hardware hierarchy, and one of them is the ACPI. Functions are externalized at each level, also becoming more and more generalized with each level. Software such as operating systems is designed in much the same approach of levels of generalization, which is how humans attack complex problems.
    – harrymc
    Commented Oct 5, 2018 at 20:41
59

As a complement to the other answer, how does the software running on the computer know what the battery level is? It asks the battery.

Most laptop batteries are smart batteries that have their own microcontroller or "fuel gauge" ASIC, which the host can communicate with over SMBus. People have reverse engineered some examples.

The SMBus may or may not be exposed directly to the operating system in a way that allows the administrator to query it directly. There are various programs like OpenHardwareMonitor or Speccy or lm-sensors that can interrogate the bus to find out about the hardware.

5
  • great explanation to understand the basic concept in general! Although I would ad quotation marks around the word "asks".
    – Albin
    Commented Oct 5, 2018 at 11:23
  • There is no conflict with my answer : SMBus is a component that is managed by ACPI for mobile computers in which it exists.
    – harrymc
    Commented Oct 5, 2018 at 11:55
  • 1
    This smart battery interface can also be exposed through more standard means, such as USB. For instance, many UPSs have a USB port on them that, when plugged into the computer, tells the computer how much power is left and displays it just like a laptop does.
    – TheHans255
    Commented Oct 5, 2018 at 13:55
  • 2
    @TheHansinator I would argue that SMBus is the standard means for communicating with a smart battery. Almost all phone's and laptops use it, which is a whole lot more systems than are using external UPS devices. Commented Oct 5, 2018 at 17:41
  • @AustinHemmelgarn True. Maybe a better word is "conventional", in that the system is more or less an OS abstraction that devices besides embedded batteries can use.
    – TheHans255
    Commented Oct 5, 2018 at 17:43
2

More generally, all computer chips have documentation which tells designers and programmers what they do and how to configure them to do it. Low level access to these chips can be done by reading and writing directly to the chip's registers.

More complicated chips can come with a software program called a 'driver' that allows high level access to the operating system or even other applications. Your smart phone for example has an Application Programming Interface (API) that allows access to much of the phone's hardware, GPS, accelerometer, battery, camera, etc. When you write an "App", you can access these hardware devices using the API just as the operating system can (though the OS usually has more extensive access than a program running in 'user space'.)

These interfaces are very well defined so that when you make a function call to the hardware chip, it will respond with the information requested. The battery controller chip is just one example of this generic infrastructure.

Whomever writes the operating system code gets the documentation for the chip and writes software to communicate with the chip and retrieve the information it desires.

So the next time you load a 'driver' (or it is done automatically) for an external hard drive, USB thumb drive, or something else, you'll understand a bit more about how things happen 'under the hood'.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .