#pmOS - microkernel OS for RISC-V, x86, and LoongArch
1 messages · Page 2 of 1
With both of them
F
Yeah this is a modern standby laptop
does dmesg without strict mode still contain that error?
I think some of them don't even have S3
This is the old dmesg https://pastebin.com/W9zrQntR
With default boot options on fedora
i see
i still dont understand this whatsoever
how its not failing on that _STA call with strict mode
I can't find EC chapter in ACPI spec
I this I need to sleep
I've been looking at SDM of cource I couldn't find it

ohhhh nvm
im retarded
acpica has an optimization
if there's no _INI it doesnt walk down that subtree
so it never calls that _BAT's _STA
ok case closed at least
So a fat bug
not a bug in this case, just a cosmetic log spam that uacpi does
as for the strict-mode error message, it is some ACPICA's bug
no one really tests the strict mode
i guess
It spammed a bunch of stuff
the text is kinda unreadable at that res
Yeah I need to fix scaling
But it's sending a bunch of events working from battery
which Notify is it saying it gets
Doing nothing
which ones do u get when u connect power
Just unplugging it and leaving on battery
Wait a minute I'm gonna remove logs
Pritnfs*
Since it doesn't hang anymore
sure
yeah this is WMI memes
Windows Management Instrumentation Device
Basically firmware talking to windows at runtime
for device specific events & configuration
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
some examples of what your aml has that is configurable via WMI
yeah
oh yeah looks correct, u get a notify for ADP0 (power adapter) status change, and the battery
It's spamming a bunch of this
the fact that there's no handler here is incorrect, no
If I disconnect it from the wall
WMID or battery
This is what I get if I disconnect the USB hub
yeah wait a sec
your firmware might be truly fucked
ill see where it has a stray embedded control opregion
This is what i get conencting the charger
looks correct
ADP0 status change and BAT0 status change
0x80 means status change
if you install notify handlers to these devices u would get them called by uacpi prompting you to re-read their status
btw power button does nothing? @carmine nacelle
Nothing
interesting, could be a uacpi skill issue or could be something else
ok so
your firmware is basically
fucked
or rather
But I've only added the old way of power button handling I think
the new way is hooking up a Notify handler to the power button device
but u dont even get that Notify
So basically
your firmware just creates an entirely new EmbeddeControl opregion
that has no _REG method or anything
and assumes its accessible if the main opregion is available
acpica has a special workaround for this which i've ignored because i never saw a real life example
but now i do lmao
uacpi probably
nah ill fix it ofc
sinec acpicia works around it
basically yeah
@carmine nacelle u can fix it right now by installing the EmbeddedControl handler to root
instead of the EC node
ohh
nvm
i was thiking of a different workaround
linux does this
acpi_handle scope_handle = ec == first_ec ? ACPI_ROOT_OBJECT : ec->handle;
acpi_ec_enter_noirq(ec);
status = acpi_install_address_space_handler_no_reg(scope_handle,
ACPI_ADR_SPACE_EC,
&acpi_ec_space_handler,
NULL, ec);
if its the first EC being created the handlers are installed to root
otherwise to EC scope
So this is what I have to do?
yup
i was initially thiking of this workaround:
/*******************************************************************************
*
* FUNCTION: AcpiEvExecuteOrphanRegMethod
*
* PARAMETERS: DeviceNode - Namespace node for an ACPI device
* SpaceId - The address space ID
*
* RETURN: None
*
* DESCRIPTION: Execute an "orphan" _REG method that appears under an ACPI
* device. This is a _REG method that has no corresponding region
* within the device's scope. ACPI tables depending on these
* "orphan" _REG methods have been seen for both EC and GPIO
* Operation Regions. Presumably the Windows ACPI implementation
* always calls the _REG method independent of the presence of
* an actual Operation Region with the correct address space ID.
*
* MUTEX: Assumes the namespace is locked
*
******************************************************************************/
static void
AcpiEvExecuteOrphanRegMethod (
And it's not gonna be fixed by uACPI
but this isnt your case
it's not a uacpi problem really
i just misunderstood
ok
this will be fixed by uacpi, but this isnt your issue
_REG methods that are orphans
what linux does makes a lot of sense actually
if its the only EC u can handle all opregions of this type with it
if there are multiple all other ones will be region-local
stupid question but how do I pass root to uacpi_install_address_space_handler?
uacpi_namespace_root()
Yep
Device (UBTC)
{
Name (_HID, EisaId ("USBC000")) // _HID: Hardware ID
Name (_CID, EisaId ("PNP0CA0")) // _CID: Compatible ID
Name (_UID, Zero) // _UID: Unique ID
Name (_DDN, "USB Type C") // _DDN: DOS Device Name
do u get this notify when attaching something to port?
Yes
Or a charger
This laptop has 3 USB C ports
And that's it
(also USB 4)
(and I have a thunderbolt 3 laptop)
nice
(so it could be something to try to implement)
fuck i wannna know why power button doesnt do anything
Lid also works I think
you're supposed to be getting _Q35 but you arent for some reason
LID0 
nice, LID status change
at least your ec driver is good now
the power button thing bothers me because qookie had the exact same issue
Keyboard backlight
i wonder if firmware expects you to run some extra methods for this to work
Where do I put the printfs
wdym?
To debug it
let me see
like basically what happens is probably the EC has some sort of an if (should_generate_event(...))
that we're failing
idk why
but like it has no problem generating e.g. lid status changes
which is strange
like i would imagine maybe it checks the os version to decide, but then again uacpi responds yes to all modern windows versions
@carmine nacelle are your timed mutex acquires implemented correctly?
I ignore timeouts
just unconditional forever wait?
Btw the image with EC driver and latest uACPI
Yes
ok that should be fine then
And it's the same mutex as usual
Which should be working
Or assert fail if it doesn't
btw
uacpi_status result = uacpi_get_current_resources(node, &resources);
if (result != UACPI_STATUS_OK) {
return UACPI_ITERATION_DECISION_CONTINUE;
}
struct ec_init_ctx ctx = {};
uacpi_for_each_resource(resources, find_ec_resources, &ctx);
uacpi_free_resources(resources);
there's a uacpi_for_each_device_resource
I'll look at it later
Something might be hanging and we might not be seeing it
looks correct
i doubt its hanging because ive seen the exact same behavior on mammogram on qookies laptop
all notifies coming it but the power button
i dont fucking understand
skill issue, but where
@carmine nacelle just for funsies, can u try uacpi_uninstall_interface("Windows 2015") before loading the namespace
lets pretend we're windows 7 and not 10
who knows
well aml does
(I'll check it once I come back)
it queries for all windows versions up to 10
Linux 
the TLDR is every linux now responds false to it
Nothing changed
i wonder what we're doing wrong
like we know the order is correct here, I've verified against linux
and they do react to the power button
right?
could this be related?
nah this is printed by ACPICA as well
yeah all your logs are correct
Some of the FN buttons are also broken
But maybe it's sent to PS/2
Like lock, calculator and some other things
Sound controls
I can try managram...
Could there be some other mechanism?
For the power button
those are standard ps/2 keys i think
maybe
nah just these two
nah it wont do anything differently
there are two possibilities
- since you don't have any sort of power management you don't call any methods that do stuff related to that, perhaps power button is initialized as part of that
- uacpi does some IO incorrectly which leads to incorrectly initialized state of something
if you're feeling brave u can try porting ACPICA
Keyronex has acpica, right?
Who had it then
nobody
Bruh
but u can try porting it 
tbh its public api is similar to uacpi's so u wont struggle too much, but its very hard to port because there isnt a clear interface for stdlib
Does Linux have some sort of debug mode for acpi?
like yes but it has so many acpi-related drivers
its impossible to tell which one could affect this
Which was the other laptop where power button wasn't working?
Maybe there's something in common
@hexed acorn pls tell us
i think the model goes something like hp laptop 15s-eq1124nw
i havent tried managarm on it recently so maybe it works now
Chatgpt says this
The issue that I'm having is that everything works but the power button
like u dont get any irq at all
so that means something isnt configured correctly
whos skill issue that is remains unknown
(i mean during the power button press)
How do I see AML?
When looking at managarm code, they do register some gpe events after finalizing gpe init
Which sounds wrong
Could it be some whatever Ryzen laptops firmware everyone is using weirdness?
acpidump > dump.txt && acpixtract -a dump.txt && iasl *.dat && code dsdt.dsl
EC init happens in _REG
but it's really hard to tell what it does exactly because obv its chipset specific
I also do that I think
Might be a problem
I register all my GPEs before finalizing init
So does Linux I think
yeah managarm only does it because uacpi didnt have thread safety
so it would crash during ns init
because it would get an irq
PNP0C0C?
thats your power button device yes
Could I need to be registering it explicitly?
if we configured EC correctly you would get a query which would result in Notify(PWRB)
nah like
from the software standpoint you're doing everything correctly
obos might have a chance at getting it to work if its point 1 here
because he calls all power-related methods
or at least some of them
Linux does this
static bool acpi_wakeup_gpe_init(struct acpi_device *device)
{
static const struct acpi_device_id button_device_ids[] = {
{"PNP0C0C", 0}, /* Power button */
{"PNP0C0D", ACPI_AVOID_WAKE_FROM_S5}, /* Lid */
{"PNP0C0E", ACPI_AVOID_WAKE_FROM_S5}, /* Sleep button */
{"", 0},
};
struct acpi_device_wakeup *wakeup = &device->wakeup;
const struct acpi_device_id *match;
acpi_status status;
wakeup->flags.notifier_present = 0;
/* Power button, Lid switch always enable wakeup */
match = acpi_match_acpi_device(button_device_ids, device);
if (match) {
if ((match->driver_data & ACPI_AVOID_WAKE_FROM_S5) &&
wakeup->sleep_state == ACPI_STATE_S5)
wakeup->sleep_state = ACPI_STATE_S4;
acpi_mark_gpe_for_wake(wakeup->gpe_device, wakeup->gpe_number);
device_set_wakeup_capable(&device->dev, true);
return true;
}
status = acpi_setup_gpe_for_wake(device->handle, wakeup->gpe_device,
wakeup->gpe_number);
return ACPI_SUCCESS(status);
}
This is for a device btw
And is also for wake from suspend
Iirc
this is for suspending
runtime notifications are done via EC
So not what I want
basically yeah
Yeah
Daily obos shilling
There is obos' code for enabling wake gpes
like the simplest way to debug it would be trying to make an acpica driver that does the exact same thing u do with uacpi
if u do get a power button notifcation with it then its a uacpi bug
otherwise its u not calling some configuration method or ordering
The spec says this
The power button programming model can also use the generic hardware programming model. This allows the power
button to reside in any of the generic hardware address spaces (for example, the embedded controller) instead of fixed
space. If the power button is implemented using generic hardware, then the OEM needs to define the power button as
a device with an _HID object value of “PNP0C0C,” which then identifies this device as the power button to OSPM.
The AML event handler then generates a Notify command to notify OSPM that a power button event was generated.
While the system is in the working state, a power button press is a user request to transition the system into either the
sleeping (G1) or soft-off state (G2). In these cases, the power button event handler issues the Notify command with
the device specific code of 0x80. This indicates to OSPM to pass control to the power button driver (PNP0C0C) with
the knowledge that a transition out of the G0 state is being requested. Upon waking from a G1 sleeping state, the AML
event handler generates a notify command with the code of 0x2 to indicate it was responsible for waking the system.
Could it be sent by HID?
_HID is just a string object
In these cases, the power button event handler issues the Notify command with
the device specific code of 0x80.
this is what u dont get
I think I'll try to fix my PS/2 driver
I don't think I'm doing that
In order to hook that up you will need to:
Write an embedded controller driver Find the EC device in the AML namespace (PNP ID "PNP0C09" or ECDT table), attach an address space handler Find a power button object in the namespace, attach a notify handler Detect the general purpose event number used by the embedded controller (_GPE method), install a handler for it In the event handler, execute the QR_EC command to find out the index of the query requested by the EC Run the requested query by executing the corresponding "EC._QXX" control method in AML If this query was for a power button press, you will receive a notifications with value 0x80 (S0 Power Button Pressed)
Wait, no, I do
nevermind
Imma try managram
try it but i doubt anything is going to change
HEY IM SO SORRY
TESTING IT NOW
im really curious what we're doing wrong for the power button but thats currently too much work to debug
It doesn't work on my laptop for no reason
i cant show the kernel output very well
because its on my mani system
it did say some errors
though
wdym
If it's assert fail that's fine
does it shutdown instantly?
My shutdown has a 3 seconds timer
okay i see
I have an old macbook at home, which was also not shutting down without EC driver
I'm coming there this weekend and can try to test it
(also I finish classes this week, so disregarding exams I'll have a lot of time for osdev
)
It's 2012 mac so that's gonna be fun
But AML was assuming it and uACPI would not initialize iirc
i wish we could easily test acpica
@carmine nacelle if u could build a custom linux to run on your hw we could also add prints or trace io done by acpica or something
I need to finish some stuff
Still, can power button somehow be wired to keyboard or something weird?
i have a suspicion it requires advanced platform power capabilities that are configured via _OSC
I might as well implement that if it's not too difficult
anyway we're gonna find out what it requires
by commenting stuff out or adding printfs
Fun
Linux dualboot time
Although I think I can just boot life cd with custom kernel
Like it's a grub option away
I've built lfs once...
Anyway
I could also try bsds
Elixir Cross Referencer - source code of Linux v6.12.5: drivers/acpi/ec.c
there's already this as a start
I think I really need to learn about Linux internals one day...
idk how to enable this print so its easier for us to add our own lmao
Like it's just C
probably some log level we need to set
bootlin is insanely good for this
u can go to implementation and find all users of a function
I think you need to compile linux with DEBUG?
nah
Then it starts to printk
just replace those with pr_info
following the macros
yeye
replace these with pr_info
for starters
Do I replace everything?
What kernel options do I need
I can't find AMDGPU...
Ok i'm compiling it
Never compiled linux on this laptop
bruh
kernel/sys.c:1307:21: error: ‘LINUX_VERSION_PATCHLEVEL’ undeclared (first use in this function); did you mean ‘LINUX_VERSION_CODE’?
1307 | v = LINUX_VERSION_PATCHLEVEL + 60;
| ^~~~~~~~~~~~~~~~~~~~~~~~
| LINUX_VERSION_CODE
just make olddefconfig probably
I've enabled amdgpu and my wifi card
As built in
It should boot if I just use the new kernel, right?
Like without modules and stuff
(idk why it wouldn't)
yes
Why am I getting this ```
drivers/usb/core/hcd.c:115:33: error: ‘LINUX_VERSION_PATCHLEVEL’ undeclared here (not in a function); did you mean ‘LINUX_VERSION_CODE’?
115 | #define KERNEL_VER bin2bcd(LINUX_VERSION_PATCHLEVEL)
I've checked out to v6.13
It shouldn't be broken
how do u configure it
make menuconfig
ah
yeah idk, linux surely doesnt have any broken commits
so its some skill issue on your part i believe
I'll redownload it
Idk
I'm too stupid
How do I write linux to drive
(i mead dd)
I'm gonna try rufus again
because with dd windows can't read the partitions
skill issue ratified
nice
Idk
I'm supposed to be using bzImage instead of vmlinuz, right?
I'm too tired for this
This says it's kernel panic https://discourse.nixos.org/t/system-wont-boot-path-efi-stub/29212
All of a sudden my computer doesn’t boot up successfully anymore. After selecting the NixOS generation in the boot loader menu, I get EFI stub: Loaded initrd from LINUX_EFI_INITRD_MEDIA_GUID device path EFI stub: Measured initrd data into PCR 9 Nothing seems to happen afterwards. This also happens for older NixOS generations that worked previo...
Btw I think this laptop doesn't even have CSM
I'll try fedora instead of Ubuntu...
I'm hoping Linus' favourite is gonna do better
try it
It turns off after a bit
F
Idk what am I supposed to do
I think I'll dualboot fedora finally
One small problem
Time to get a separate nvme for linux
fun
thats a separate bug albeit also important
if you want it fixed u can write an email to power management maintiners
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
this doesn't look out of place i'd suppose
anyways
I'm trying to compile linux again
Wow, this laptop flies with linux
grep dmesg
there's nothing
to verify, is there s5?
misha@fedora:~/linux-6.12.5$ sudo cat /sys/power/mem_sleep
[s2idle]
vim
meh
I'm not profficient enough in it
Idk if it's bios stupidity, but this laptop is refusing to speed up fans to decent rpm
With Linux
it's almost compiled
I'm booting mainline kernel...
Omg it worked ```
[ 70.413998] ACPI: EC: Query(0x11) started
[ 70.414243] ACPI: EC: Query(0x11) stopped
[ 70.576168] ACPI: EC: Query(0x11) started
[ 70.576375] ACPI: EC: Query(0x11) stopped
[ 71.055577] ACPI: EC: Query(0x12) started
[ 71.055719] ACPI: EC: Query(0x12) stopped
[ 71.181797] ACPI: EC: Query(0x12) started
@twilit talon there are no EC queries when I press power button
This if from brightness buttons
ok thats an amazing find
What do we do now lol
0x12 etc
Like if I connect and disconnect the battery I also get a bunch queries
no missing queries that happen for linux but not for u?
It's the other way around
wdym
Like disconnecting a charger pmOS would receive a query every few seconds or so
And I haven't noticed that on Linux
Although that might be from AML
But yeah in general I think I have the same
Stuff
Where could the power button be coming from then?
ok so now we find out how it notices that the power button is pressed
Bruh Linux is so fucked it doesn't even turn the screen off when closing the lid
hmm i wonder how we can find that out
let see
add printfs here
if this is called when u press the power button we'll panic to dump the backtrace
keep them its fine
@hexed acorn apparently there's a third way to route a power button which we didnt know about
we added printfs to linux on his laptop
@carmine nacelle whats the laptop brand again
acpi shouldn't be a module, right?
Lenovo
no
hmm i wonder if thinkpad_acpi.c is applicable to you
@twilit talon ```
[ 61.668168] ACPI: button: acpi_button_notify handle 00000000c935dbe2 event 128 device 000000004764d9ce
[ 61.668199] ACPI: button: acpi_button_notify: power
Is should be similar to a thinkpad I'd suppose
hly shit
ok
now we need to panic
I was between this laptop and a similar thinkpad when buying it
why
or actually
how do I extract the stuff from handle
u dont
dump_backtrace() or something
there should be a function like that
or do WARN_ON(1)
where u have that printf
Why does it take like half an hour to compile a single c file
lol
we're about to find out where its called from i guess
becaues its definitely not the ec
actually we might not
because it will be dispatched from the work queue
rebooting...
we need to catch it when it gets scheduled
maybe not yet
well try it anyway maybe we'll see something
im gonna need u to do more complex hacking
Bro
lol
And it's taking its time...
@carmine nacelle u do install a fixed event handler for it right?
Idr
please dont tell me u dont
This is what I do
ok yeah u do
And it worked on linuxmaster's laptop
add a printf on this line as well pls https://elixir.bootlin.com/linux/v6.12.5/source/drivers/acpi/button.c#L477
next time
did it finish updating?
bruh it did but it booted into the wrong kernel
ah right yeah
bruyh
[ 34.567108] Call Trace:
[ 34.567112] <TASK>
[ 34.567115] ? acpi_button_notify+0x28/0x140
[ 34.567119] ? __warn.cold+0x93/0xfa
[ 34.567124] ? acpi_button_notify+0x28/0x140
[ 34.567134] ? report_bug+0xff/0x140
[ 34.567142] ? handle_bug+0x58/0x90
[ 34.567148] ? exc_invalid_op+0x17/0x70
[ 34.567153] ? asm_exc_invalid_op+0x1a/0x20
[ 34.567164] ? acpi_button_notify+0x28/0x140
[ 34.567170] acpi_ev_notify_dispatch+0x48/0x80
[ 34.567179] acpi_os_execute_deferred+0x17/0x30
[ 34.567184] process_one_work+0x176/0x330
[ 34.567193] worker_thread+0x252/0x390
[ 34.567201] ? __pfx_worker_thread+0x10/0x10
[ 34.567207] kthread+0xcf/0x100
[ 34.567212] ? __pfx_kthread+0x10/0x10
[ 34.567217] ret_from_fork+0x31/0x50
[ 34.567223] ? __pfx_kthread+0x10/0x10
[ 34.567228] ret_from_fork_asm+0x1a/0x30
[ 34.567239] </TASK>
[ 34.567242] ---[ end trace 0000000000000000 ]---
Yep it's from queue
printfs with if statements?
or actually
we can simplify it
i want u do add a WARN_ON(1) to acpi_os_execute if the work is of type OSL_NOTIFY_HANDLER
acpi/osl.c
osunixxf.c?
compiling...
and will have some extra stuff because of other notifies
wait, I forgor about the other printf
its fine but u can add it if its not too late
it's linking the kernel
there may be one extra layer of abstraction but we'll see
[ 50.757662] Call Trace:
[ 50.757665] <TASK>
[ 50.757669] ? acpi_os_execute+0xf5/0x110
[ 50.757676] ? __warn.cold+0x93/0xfa
[ 50.757682] ? acpi_os_execute+0xf5/0x110
[ 50.757699] ? report_bug+0xff/0x140
[ 50.757708] ? handle_bug+0x58/0x90
[ 50.757716] ? exc_invalid_op+0x17/0x70
[ 50.757723] ? asm_exc_invalid_op+0x1a/0x20
[ 50.757738] ? __pfx_acpi_ev_notify_dispatch+0x10/0x10
[ 50.757758] ? __pfx_acpi_ev_notify_dispatch+0x10/0x10
[ 50.757765] ? acpi_os_execute+0xf5/0x110
[ 50.757773] acpi_ev_queue_notify_request+0xb2/0x110
[ 50.757783] acpi_ds_exec_end_op+0x19c/0x560
[ 50.757791] acpi_ps_parse_loop+0x100/0x6b0
[ 50.757801] acpi_ps_parse_aml+0x80/0x3c0
[ 50.757809] acpi_ps_execute_method+0x13f/0x270
[ 50.757818] acpi_ns_evaluate+0x13e/0x2d0
[ 50.757832] acpi_evaluate_object+0x182/0x340
[ 50.757840] acpi_execute_simple_method+0x60/0x80
[ 50.757851] acpi_gpio_irq_handler_evt+0x17/0x30
[ 50.757855] irq_thread_fn+0x20/0x60
[ 50.757861] irq_thread+0x1b0/0x2f0
[ 50.757866] ? __pfx_irq_thread_fn+0x10/0x10
[ 50.757871] ? __pfx_irq_thread_dtor+0x10/0x10
[ 50.757874] ? __pfx_irq_thread+0x10/0x10
[ 50.757877] kthread+0xcf/0x100
[ 50.757881] ? __pfx_kthread+0x10/0x10
[ 50.757883] ret_from_fork+0x31/0x50
[ 50.757888] ? __pfx_kthread+0x10/0x10
[ 50.757890] ret_from_fork_asm+0x1a/0x30
[ 50.757897] </TASK>
[ 50.757899] ---[ end trace 0000000000000000 ]---
I think this is the right one
gpio
yup
@hexed acorn ?
i guess qookie's stuff is also routed via GPIO
let me see which driver is responsible for it
do you want full dmesg?
and fucking bootlin is 503'ing me
nah its fine
im glad its not a uacpi skill issue
/**
* acpi_gpiochip_request_interrupts() - Register isr for gpio chip ACPI events
* @chip: GPIO chip
*
* ACPI5 platforms can use GPIO signaled ACPI events. These GPIO interrupts are
* handled by ACPI event methods which need to be called from the GPIO
* chip's interrupt handler. acpi_gpiochip_request_interrupts() finds out which
* GPIO pins have ACPI event methods and assigns interrupt handlers that calls
* the ACPI event methods for those pins.
*/
which file is this
so old windows would have no power button?
this is the method
thats called by linux on your laptop
Notify (\_SB.PWRB, 0x80) // Status Change
Name (BUF0, ResourceTemplate ()
{
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullDefault, 0x1388,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0000
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003D
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003E
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003A
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003B
}
GpioInt (Edge, ActiveLow, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0012
}
})
and these are the possible event indices
wait
sb is south bridge?
system bus
On Hardware-reduced ACPI platforms
definetely my laptop
no, it's an x86 laptop with fucked firmware
nah just very overcomplicated modern hw
Ok I'm rebootig to windows
Device (GPIO)
{
Name (_HID, "AMDI0030") // _HID: Hardware ID
Name (_CID, "AMDI0030") // _CID: Compatible ID
Name (_UID, 0x00) // _UID: Unique ID
Method (_CRS, 0, NotSerialized) // _CRS: Current Resource Settings
{
Name (RBUF, ResourceTemplate ()
{
Interrupt (ResourceConsumer, Level, ActiveLow, Shared, ,, )
{
0x00000007,
}
Memory32Fixed (ReadWrite,
0xFED81500, // Address Base
0x00000400, // Address Length
)
})
Return (RBUF) /* \_SB_.GPIO._CRS.RBUF */
}
Method (_STA, 0, NotSerialized) // _STA: Status
{
If ((TSOS >= 0x70))
{
Return (0x0F)
}
Else
{
Return (0x00)
}
}
}
You're gonna have to write a driver for this
its a controller at 0xFED81500 with IRQ 7
Where do I look for documentation
LPT1 / Unreliable "spurious" interrupt (usually)
(from osdev wiki)
yeah no
you will be the first with such a driver
drivers/pinctrl/pinctrl-amd.c @carmine nacelle
its a tiny driver
qookie also has AMD
yeah
i would see who calls acpi_gpiochip_request_interrupts but bootlin is fucking dead
maybe u dont even need a special driver for this specific gpio controller
id have to read the acpi spec to figure out how tf this is routed
btw this only returns "present" if OS >= Windows 10
otherwise it says device doesnt exist
lol
hmm u sure thats the one?
gpio/gpiolib.c#L2021
yeah idk its a whole gpio subsystem
no idea how any of this works
you will be a pioneer here
How can I know which devices I have?
no like
u sure the spec refers to this
for your driver u can just use uacpi_find_devices("AMDI0030", ...)
or find_devices_at which supports multiple hids
oh cool
This has to be it, it appeared in 2018 edition and wasn't in 2015
yeah
what's fch
Oh it's amd's chipset
according to chatgpt
Can WDT be used as another time source? 
Wait does amd have a separate PIC?
wtf is this
wake from suspend
2.17.16.1 Interrupt GPIO
All the configuration bits (Bit[x]) used in the following steps come from GPIOx[0F8:000:step4],
GPIOx[1FC:100:step4] and GPIOx[2DC:200:step4] if the pin is used as an interrupt:
1. The driver should program the DebounceTmrOut/DebounceTmrOutUnit/DebounceCntrl bits according to
the data passed by BIOS through ASL code.
2. Configure Bit[8], Bit[9] and Bit[10] (See GPIOx[0F8:000:step4]) according to the data passed by BIOS
through ASL code.
3. Set Bit[11] = 1 and Bit[12] = 1 (See GPIOx[0F8:000:step4]) to enable interrupt delivery and interrupt status then its interrupt status is at Bit[28] when the GPIO input is asserted.
4. Configure the GPIO controller interrupt, configure as an active low, level interrupt, reference Bit[10:8]
(See GPIOx[0F8:000:step4]).
5. The driver should clear the interrupt status Bit[28] (See GPIOx[0F8:000:step4]), then set GPIOxFC[EOI]
= 1 to deassert interrupt request after acknowledging the interrupt.
Basically u need this
parse the _AEI and configure thie respective pins
then when u get the interrupt for the respective pin call _EVT(pin_idx)
In your case these:
Method (_AEI, 0, NotSerialized) // _AEI: ACPI Event Interrupts
{
Name (BUF0, ResourceTemplate ()
{
GpioInt (Edge, ActiveHigh, ExclusiveAndWake, PullDefault, 0x1388,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0000
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003D
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003E
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003A
}
GpioInt (Level, ActiveHigh, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x003B
}
GpioInt (Edge, ActiveLow, ExclusiveAndWake, PullNone, 0x0000,
"\\_SB.GPIO", 0x00, ResourceConsumer, ,
)
{ // Pin list
0x0012
}
})
M460 (" OEM-ASL-\\_SB.GPIO._AEI\n", 0x00, 0x00, 0x00, 0x00, 0x00, 0x00)
Return (BUF0) /* \_SB_.GPIO._AEI.BUF0 */
}
uacpi_for_each_device_resource(gpio, "_AEI", do_configure_pin)
this is your do_configure_pin: https://elixir.bootlin.com/linux/v6.12.5/source/drivers/gpio/gpiolib-acpi.c#L406
it even tells u 2. Configure Bit[8], Bit[9] and Bit[10] (See GPIOx[0F8:000:step4]) according to the data passed by BIOS through ASL code.
so it's not even amd specific?
This is from your spec
this code
Well this code then calls into the specific driver to configure irqs
But technically yes
anyway should be easy to do
nice
looking at the asl i only see Notify(PWRB, 0x80) in _Q28 of the EC
look in ssdts
i decompiled it with iasl -e ssd* -d dsdt.dat
do i have your dump?
you should
How do I extract this with uACPI?
Name (RBUF, ResourceTemplate ()
{
Interrupt (ResourceConsumer, Level, ActiveLow, Shared, ,, )
{
0x00000007,
}
Memory32Fixed (ReadWrite,
0xFED81500, // Address Base
0x00000400, // Address Length
)
})
Return (RBUF) /* \_SB_.GPIO._CRS.RBUF */```
uacpi_for_each_device_resouce
are there any sensitive tables other than the one with the windows key
or uacpi_get_current_resources
Yes, and then
nah
Wait
for_each_resource
I have similar code in interrupts routing stuff
@twilit talon
lets see
Fun, my PCI routing code was leaking memory
yup its there
exact same thing as his pc
ssdt15
Notify (\_SB.PWRB, 0x80)
and u have a GPIO device with AMDI0030
okay nice case closed
I'm trying to write the driver
would be nice to have this driver for managarm as well
if u manage to get it working ill try to steal your code
Oh I'm dumb I didn't read the headers
cool
huh why didn't this work then
never used -e
iasl -da dsdt.dat ssdt* also doesn't work because it cries about stuff getting redefined
yeah but that yields multiple source files right
yeah
i was thinking of decompiling it such that you get one combined source file
if u want the most careful disassembly u should be passing them in correct order
but it doesnt really matter
ssdt* will incorrectly sort ssdt1 ssdt10 etc
true
your gpio has two memory regions for some reason
Memory32Fixed (ReadWrite,
0xFED81500, // Address Base
0x00000400, // Address Length
)
Memory32Fixed (ReadWrite,
0xFED81200, // Address Base
0x00000100, // Address Length
)
})
looks like iasl goes through arguments in reverse order as well :^)
lmao
Wtf is UACPI_POLARITY_ACTIVE_BOTH?
Some resource types allow Both
i didnt invent these types lol
ActiveLevel can be one of ActiveHigh, ActiveLow or ActiveBoth. ActiveBoth can be specified only if EdgeLevel is Edge. The bit field name _POL is automatically created to refer to this portion of the resource descriptor.
I know
Wtf am I supposed to do with this
use it?
Mine has 1
Just the first one
yeah
I want to support both
id look how linux deals with it
btw how does acpica on linux actually load this if iasl can't decompile it because of the redefinitions
i do not see any redefinition errors in dmesg
it gets redfinitions because stubbed IO reading garbage
Maybe I can convence them to dump their aml as well
oh god
AML often has shit like
if (REG == 123) { Device (IDK) {} }
so some devices are only instantiated if some platform state says they exist etc
iasl option to accept a log of all mmio/pio to decompile correctly when
could be nice
So strange like they route a lot of things via EC but then the fucking power button requires a separate driver lmao
ran out of pins on the ec :^)
lmao
had to dump linux backtraces to figure out how the fuck it gets that button press 
apparently all modern AMD is this way
okay but this is gonna be kinda annoying to handle
i don't really want the gpio driver in the kernel
we dont really need the full gpio driver tbh, could just have a stub that configures interrupts
but yeah
ideally its somehow configured via userspace
by listening to acpi devices on mbus
its the mmio address?
yeah i was thinking a new protocol that the gpio driver would provide over mbus
I mean yes
and the kernel would just look for the gpio device ig
yeah maybe
lunix seems to ignore the second mmio region?
gpio_dev->base = devm_platform_get_and_ioremap_resource(pdev, 0, &res);
if (IS_ERR(gpio_dev->base)) {
dev_err(&pdev->dev, "Failed to get gpio io resource.\n");
return PTR_ERR(gpio_dev->base);
}
i assume the 0 means 0-th resource
i could reboot into windows to see ig
i do still have the win10 install around
well windows displaying that resource type doesnt mean it uses it for anything
that's also true
it reserves it to prevent conflicts
yeah its the index
resource 0 is irq tho
What does it mean per ACPI spec?
considering ioremap maybe it means first mem/port resource?
perhaps
i will check if bootlin loads
So just throw my hands in the air and ignore it?
e.g. your _SB will declare all resources used by the motherboard, which can be a hundred IO and memory ranges
doesnt mean you have to do anything about it
ideally u register it as a used memory range to prevent range conflicts
But what if some hardware swaps the order around
its always the same for each device type
I don't have bar stuff
so in your case u ignore it yes
So doesn't matter for now I guess...
infy where can i learn to write aml and have something execute it
i wanna mess around with aml
language seems cool
af
i mean idk look at examples
its pretty easy
U have methods, they have Local variables, and Args
Its like python
u can have the uacpi test runner to execute it
alr
Btw @twilit talon does uacpi have macros for uacpi_resource_fixed_memory32::write_status bits?
yes
// write_status
#define UACPI_NON_WRITABLE 0
#define UACPI_WRITABLE 1
go for it 
seems to be the case because the code just below does platform_get_irq with an index of 0 as well
lets see...
void __iomem *
devm_platform_get_and_ioremap_resource(struct platform_device *pdev,
unsigned int index, struct resource **res)
{
struct resource *r;
r = platform_get_resource(pdev, IORESOURCE_MEM, index);
if (res)
*res = r;
return devm_ioremap_resource(&pdev->dev, r);
}```
platform_get_resource(pdev, IORESOURCE_MEM, index);
yeah ur right
so even the order doesnt matter
Should I use this as bitmask?
Or does it only take these values
only those
I mean realistically I can assert it
now i want to know what the second entry is referring to, but i can't seem to find chipset docs, and ig i won't find out from linux
Wth would write only resource be doing there
static const struct uacpi_resource_convert_instruction convert_memory32[] = {
OP(BIT_FIELD_1, AML_F(memory32, information),
NATIVE_F(memory32, write_status), IMM(0)),
OP(FIELD_32, AML_F(memory32, minimum), NATIVE_F(memory32, minimum), IMM(4)),
END(),
};
its very simple
just that bit
the rest is zeroed
wonder if the windows driver has the answer
@hexed acorn
yeah probably
Everything is open source if you have IDA?
hm not exactly my platform (fam17h model 60h) but the first memory resource points to gpio bank 0, and the second into the reserved space
how do u know?
which spec is this?
My platform is also different but that's all I could find
the one mishakov linked
Mine is Zen 4
time to find your platforms spec
maybe it's a register containing the seed for a bitcoin wallet with 10mil in it
best place to hide that
its 256 bytes
the seed is a bunch of words from a predetermined dictionary
if there are docs for his platform only from last year surely u can find docs for yours
looks like they haven't even published ones for zen 1
family 15h is pre-zen
ah damn
if the 2 reddit posts on r/amd with a combined 11 comments hasn't pushed them to do so, i don't know what will
well linux does work on your pc right
yeah
so nothing of importance probably
i mean yeah that much i figured, it's just sheer curiosity at this point
should be basically walk over the pins, configure them according to what aml wants, then call _EVT on irq if pin status is set
in addition to i2c
yeah
always wondered what a smbus is
lets see, i spy ```
/mnt/Windows/System32/drivers/amdgpio2.sys
i2c controller
oh fair
god bless they have debug prints
lol
hmm ghidra's output looks pretty fugly
Which type of resource is that?
hmmm i think amdgpio2.sys also only looks at the first memory resource
I kinda have everything but this
in uacpi
Like I could have this driver by the end of today
i see a loop in which it goes through all resources (?), calls MmMapIoSpace for one type, saves another for later (and complains that no proper irq resource was found if that's missing)
Nice
Fixed memory 32
unfortunately there's a virtual function call that i can't figure out what it is (i'm guessing it's a vtable provided by windows?)
Oh these
I dont remember, look at the enum
Is it not set by the driver?
if it is, i can't see where it's being set
Hmm
oh it's gpio connector...
I can check later if you cant figure it out
lol
its gpio connection, yes
it has 3 sub-types
or 2 rather
#define UACPI_GPIO_CONNECTION_INTERRUPT 0x00
#define UACPI_GPIO_CONNECTION_IO 0x01
okay whatever, either ghidra is trolling or i'm dumb
but i think it also just looks at the first memory resource
so it ignores the second one?
i think so
well i last booted into the install a few months ago
but the resources for the gpio controllers haven't changed since i got the laptop
(even after a bios update)
no i mean like
perhaps the new driver ships with like early access windows 11
and yours is the stable old version
ah
hmm there is this condition in the loop ```
else if ( *(_BYTE )v15 == 3 && (((_DWORD *)(v15 + 12) - 768) & 0xFFFFFEFF) == 0 )
byte at v15 is the type (checks for 2 for the irq resource), v15 + 4 is the address, so what's at v15 + 12
hmm is it size
4 + 8 = 12
ohhhh
this is size == 0x400?
so it explicitly ignores the smaller memory resource
i could quickly reboot and check ig
although that might be handled by a different subsystem
aka the driver doesnt decide
all _CRS stuff is unconditionally stored there
the fact that the driver has an explicit size check makes this even weirder
just sanity checking maybe
windows shows both memory resources in device manager
and also, apparently next to all the other amd system devices, there's AMD Crash Defender
ok I'm back
I think bootlin is completely dead lol
it works if u refresh enough
What would be pin list?
in uacpi_resource_gpio_connection
source??
u mean pin_table?
// Pin list
pin_table
lol
huh
mircosoft trying to make people buy new PCs?
Ok, time for hardcore printf'ing
thats for when u have multiple possible configuration
it tells u which ones are good which ones are not
Idk if I'm being flat-brained, but it's not finding gpio
show code
Passing Windows 2015 doesn't show it
show code x2
if u disable windows 2015 its not shown yes
u have to pretend to be > windows 10
looks like it
I'm extra flat brained
I've been editing pci code instead of gpio for some reason
lmao
Btw, my AML is passing 3 resources...
1, 12, 29
This is my b550 desktop