Open bingmatv opened 1 month ago
The firmware controls the fan speed, not the OS. What the OS can do however is request the frequency of the CPU to change depending on how much cpu usage there is. For this it needs to follow the ACPI specification to request the firmware/cpu to change the frequency.
firmware controls the fan speed
Laptops may use Lithium battery, which is unstable; So the user should control the power quantity stored in Lithium battery, some researchers say that power around 50% is good for Lithium battery. But Sodium-ion battery is more stable. Can the OS control the power stored in Lithium battery, .e.g, between 45% and 55%? Sodium-based batteries are more stable so it's not important to control power stored in Sodium-based batteries.
Depends on the laptop. There is an embedded controller on the mainboard which controls the charging logic. On some laptops there is an option to set a charging limit through ACPI, but on others there is no way to set a limit at all.
On some laptops there is an option to set a charging limit through ACPI
How to find the memory address (if the ACPI allows) to set charging limit?
There is no specific memory address. Instead you have to interpret AML bytecode that is part of the ACPI tables to set the charging limit. This AML bytecode may write to a memory address or it may trigger an interrupt calling into the firmware depending on how the firmware implemented setting the charging limit. The crates in https://github.com/rust-osdev/acpi may be useful for interacting with ACPI. Just be aware that the specification is a mess and basically everyone has to emulate all bugs in the Windows ACPI implementation to be compatible with common firmware implementations. https://github.com/rust-osdev/acpi does not yet do this (even Linux has trouble with getting everything exactly right), so it may not work on your specific system. You may also want to look at https://github.com/acpica/acpica which is the code Linux uses to interface with ACPI. There are no Rust bindings for this yet though afaik.
If the AML contains newlines, should I write \n escape character or directly press Enter key?
AML is a binary format. It is not a string, so it doesn't contain newlines.
Brave search engine provides AI to answer questions, I searched
battery charging limit using acpi machine language
The AI said:
Method (_SBF, 1)
{
// Set battery charging limit to 80%
Store(0x50, ResourceTemplate())
}
Method (_BST, 0)
{
// Check battery status
If (BatteryStatus() == 2) // 2 = charging
{
// Stop charging when battery reaches 80%
If (BatteryLevel() >= 0x50) // 0x50 = 80%
{
Store(0, ResourceTemplate())
}
}
}
Is it correct?
That is the text representation of AML. The actual ACPI tables contain AML in a binary format which is compiled from this text representation.
That is the text representation of AML
Can the parse_table function https://docs.rs/aml/latest/aml/struct.AmlContext.html#method.parse_table parse the text representation to set charging limit?
No, the aml crate doesn't have a compiler for the text representation of AML afaik. You shouldn't need to use the text representation of AML at any point. Instead read the binary version directly from the ACPI tables provided by the firmware of your system. Each firmware will provide different AML specific for the machine it runs on.
Each firmware will provide different AML specific
Is there a universal way to set battery limit? How to know the length to read ACPI? It seems bootloader_api::info::BootInfo only provides rsdp_addr meaning the address.
rsdp_addr points to the RSDP^1, which itself contains the address of the RSDT (ACPI v1) and XSDT (ACPI v2)[^2]. The RSDT/XSDT is the index you can use to find all other ACPI tables. If you use the acpi crate you can use acpi::AcpiTables::from_rsdp to iterate over all ACPI tables.
Can the OS control the power stored in Lithium battery, .e.g, between 45% and 55%?
As @bjorn3 said, it depends on the laptop. Check if the OS that the laptop was designed for (such as Windows or Linux) has a way of controlling battery charging.
I know for some ThinkPads you can set a charging limit so it only charges up to a certain %.
On most Chromebooks you can stop charging, set a charging current limit, and for some Chromebooks you can set a % limit.
I think you would have to communicate with the laptop's embedded controller and send commands to it to control charging (and on Chromebooks you can control the fan too). I think this is pretty complicated to do in your own OS and you would have to look at the Linux kernel's code.
you would have to look at the Linux kernel's code.
Not to be a party pooper, but you have to be careful when learning or borrowing from the linux kernel. It's GPL licensed, so your kernel would need a compatible license (or you do your own stuff).
Also mentioned here https://wiki.osdev.org/Linux_Kernel_Primer
Some computers have a fan to prevent the temperature from being too hot, how to access and control the fan speed?