#uACPI - a portable and easy-to-integrate ACPI implementation

1 messages · Page 33 of 1

flat badge
#

Probably also more work than just respecting the window meme

vast kestrel
#

Probably lol

loud ice
#

you are allowed to do that

#

also, keep in mind (uefi) firmware devs

flat badge
#

Not really, you can just block (in case of send)

#

Or busy poll your nic or whatever (in case of recv)

flat badge
loud ice
#

hmm maybe

flat badge
#

A not entirely stupid minimal send would: block until window size > 0 -> send packet -> wait for ack

#

A minimal receive would receive packets up to an internal buffer size, then announce window = 0 and ack

#

That way you still don't need to deal with multiple in flight packets but you also won't randomly cause retransmission despite no packet loss

torpid ferry
#

that's still better than TFTP though

#

and probably even simpler

#

TFTP works Fine™️ on lans with very low packet loss, so it's probably fine for quite a lot of things

loud ice
#

except you have room to expand to better impls

fiery turtle
#

Gonna drop 30 commits when I merge this PR soon, which will mark the 1.0 release

#

not a single api break which is nice

north holly
fiery turtle
#

i've changed quite a lot of interpreter logic

north holly
#

I can test now, but whether I should is a different question (I'm at school)

fiery turtle
#

lmfao

#

boot it on your phone i guess

north holly
#

nah I'm on my laptop

fiery turtle
#

ah lol

#

nah just test when you're back home with all of your pcs

#

im not in a rush anyway

#

these are the most dangerous potentially

#

but new special field handling might break something too

north holly
#

I will test all

#

that I have

fiery turtle
north holly
#

so suspend, EC, driver interface's PnP

#

and other stuff

fiery turtle
#

nice

north holly
#

on my laptop, main PC, and other PC

#

maybe I'll find other older stuff

fiery turtle
#

LETSFUCKINGGOOOOOO x2

north holly
#

uh oh @fiery turtle

#

wake-from-suspend hangs

fiery turtle
#

how tf did u test it in school

north holly
#

on a personal laptop

fiery turtle
#

what is it supposed to do?

north holly
#

what, waking from suspend?

fiery turtle
#

after

north holly
#

print it woke from suspend and return to bash

fiery turtle
#

in qemu?

north holly
#

yes

fiery turtle
#

try revertng and seeing if its an obos regression instead KEKW

#

because qemu doesnt have a _WAK and i didnt change any other logic

north holly
#

lucky you infy

fiery turtle
#

lmao

#

i know i can always blame obos and it always works

north holly
#

wonder where it works

fiery turtle
#

u mean hangs

north holly
#

*it went wrong

#

yeah

fiery turtle
#

obos suspend regression #99999

north holly
#

except I haven't changed any acpi code thinkong

fiery turtle
#

maybe your on_wake hook for some driver hangs

north holly
#

(at all)

#

wait it never even enters suspend?

fiery turtle
north holly
#

gtg now

#

oh thank god it's a userspace bug

fiery turtle
#

wtf

north holly
#

it was never calling into OBOS_Suspend

#

I was trying to fix a bug with receiving from the uart driver

#

so I made the powerctl command use getchar instead of my workaround

#

so I could test it

#

@fiery turtle yeah suspend worked

fiery turtle
#

letsgo

north holly
#

in qemu

#

I will test my laptop

fiery turtle
#

at school? 💀

north holly
#

why not lol

#

didn't get caught

north holly
#

it hangs

#

with new uacpi

#

I tested on the exact same commit of obos with old uacpi, it didn't hang

fiery turtle
#

we're gonna need some triple fault debugging

fiery turtle
#

huh

north holly
#

it hangs before suspend

fiery turtle
#

so does it hang before or after

north holly
#

it hangs during kernel init, so before suspend

fiery turtle
#

that should be easy to printf at least

north holly
#

yeah

#

I'm going to enable uacpi trace logs

#

and obos debug logs

fiery turtle
#

yeah

north holly
#

uhh it doesn't hang on new uacpi

#

either that, or it's because I added logs

fiery turtle
#

☠️

north holly
#

or it didn't hang in the first place and I misread my logs

#

it never hung

#

that's a compiler error trl

gentle peak
#

that doesn't handle timeouts properly

north holly
#

Obos has never handled timeouts properly lol

median crest
#

Timeouts on locks are CRINGE

#

Do not respect them out of spite for the firmware devs

fiery turtle
#

yeah they are

median crest
#

Infiltrate microsoft and change the acpi driver to not handle them

fiery turtle
#

either 0 or infinite are the only respectable ones

median crest
#

Send a patch to linux to not handle them

#

Resist the oppression firmware devs do against os devs

north holly
#

Send a patch to netbsd

dense steppe
#

timeouts suck. they are annoying to implement and they should ideally never be hit.

but it is better to timeout than to deadlock forever.

#

btw... is it guaranteed that AML will release mutexes in the same thread that acquires them? because my mutexes make the following assumption:

 * - The same task that holds a lock must unlock it.
fiery turtle
#

they're force released by uacpi upon method exit if aml forgets to do it

dense steppe
#

great

#

then I don't have to rework my mutexes, which would've been annoying™️

frank canopy
#

hm i should probably make sure i handle 0 timeout properly at some point

dense steppe
#

for me, a timeout of zero is just "optimistically try to acquire the mutex. if it fails, don't try again."

#

it's like the easiest part of a mutex implementation

frank canopy
#

it is I just don't remember if I bothered lmao

dense steppe
#

it is literally just:

/**
 * Attempt fast mutex lock. Returns true on success, otherwise writes the value
 * found in @mutex->owner_and_lock into *@expected.
 */
static inline bool
mutex_lock_fastpath (struct mutex *mutex, struct task *self, unsigned long *expected)
{
    *expected = 0;
    unsigned long desired = (unsigned long) self;

    return atomic_cmpxchg_acqrel_acq (&mutex->owner_and_lock, expected, desired);
}

// ... later in the same file
/**
 * Lock @mutex. Common part.
 */
static errno_t
mutex_lock_common (struct mutex *mutex, usecs_t timeout_us, bool interruptible)
{
    struct task *self = get_current_task ();
    unsigned int task_state = interruptible ? TASK_INTERRUPTIBLE : TASK_UNINTERRUPTIBLE;

    unsigned long expected;
    if (mutex_lock_fastpath (mutex, self, &expected))
        return ESUCCESS;

    if (!timeout_us)
        return EAGAIN;

        // ... invoke mutex slowpath
}
#

and my mutexes are overcomplicated

frank canopy
fiery turtle
#

Doubt anyone is gonna care tho

mortal yoke
#

also cringe recursive parser meme

fiery turtle
torpid ferry
winter orbit
#

i know of an easy to use ACPI implementation they can adopt

fiery turtle
#

They're fully nih I think

winter orbit
mortal yoke
#

well at least its more nih than using existing code

fiery turtle
#

Lol

winter orbit
#

I've seen far more unique projects here though

mortal yoke
#

yeah there def are

left orbit
#

yeah well, serenity is just a bunch of people who have no idea how to osdev trying to osdev

winter orbit
#

most people are people who don't know how to osdev trying to osdev,

what matters is how much you're willing to learn from your mistakes oof
everyone starts somewhere

#

But I don't have a lot of respect for serenity at this point

fiery turtle
winter orbit
#

Yeah they've got some issues

mortal yoke
#

though to be fair I don't even have that many for actual real hardware, rtl8139/8169 (which works as long as the phy is properly handled by the fw), gicv3, spmi (incomplete and not properly hooked to anything), hda, xhci (like I said its kinda broken), usb hid (might be slightly broken idk) and usb rndis

left orbit
#

usb drivers tend to just work™️ if your *hci driver is good

#

thats why i like usb

mortal yoke
#

yeah

#

my xhci driver also mostly worked before I tried fixing it, the reason why I started to mess with it was an old mouse from like 2002 (3y older than me lol) generating a transaction error when getting the first 8 bytes of the device desc after first sending set addr with the bit set that prevents it from reaching the device (I tried with different packet sizes too like 8 and 64 but neither helped)

jaunty fox
#

it's good to do posix since it's the open standard for operating systems but that doesn't mean that all innovations should be rejected

fiery turtle
jaunty fox
strong heath
#

w^x is pretty good

left orbit
#

they do jails iirc

fiery turtle
#

also they disallow syscalls from everywhere but libc

jaunty fox
strong heath
jaunty fox
left orbit
#

idk how good or faithful their jail implementation is though

#

they also have a "syscall region" thing, which apparently comes from mach (but i might be wrong)

#

meaning any syscall made from outside that memory range won't work

jaunty fox
#

it's an openbsdism

deft canopy
left orbit
#

that is fair though lol

#

i wouldn't want random people coming in and harassing me to add feature x or y

#

if u want it then do it urself

#

if it want it too then i might invest some time into it

deft canopy
left orbit
#

boo hoo

deft canopy
#

In serentity's case it isnt that big, so meh

left orbit
#

it's an open source project

#

focused on the community

strong heath
#

its fair to say "hey would you be interested on implementing this yourself?", saying "either implement this or fuck off" is very heavy handed

left orbit
#

working together

jaunty fox
deft canopy
left orbit
#

im not a big fan of the hostility

jaunty fox
#

moreover there is a bit of a denial of the complexities of engineering big systems that's inherent to the logic of this response

left orbit
#

especially since its supposed to be semi professional

#

but like i dont blame them either

jaunty fox
#

for example, would serenityos say that someone should submit a PR to turn it into a microkernel?

strong heath
jaunty fox
#

the same goes for a lot of other changes, there's no point pretending there's just blocks of code and you throw them into a PR and that's a change made

deft canopy
jaunty fox
#

though i accept that free software in general is a place where social responsibility is very lacking and that's visible in how little there is in the way of accessibility

#

in particular ever since Sun went away and since the advent of wayland, accessibility in the whole GNOME stack has gradually withered away to now being effectively unusable

deft canopy
#

I hope one day I'm big

#

So many ways I'd like to improve computing

fiery turtle
#

One last thing I decided to do before 1.0 is GAS caching, more specifically so that

  1. the entire GAS is mapped before its used as opposed to per-access-mapping
  2. for FADT registers, everything is pre-mapped at init time
uacpi_status uacpi_map_gas(const struct acpi_gas *gas, struct mapped_gas *out_mapped)
{
    uacpi_status ret;
    uacpi_u8 access_bit_width;
    uacpi_size total_width;

    ret = gas_validate(gas, &access_bit_width, &total_width);
    if (ret != UACPI_STATUS_OK)
        return ret;

    out_mapped->access_bit_width = access_bit_width;
    out_mapped->total_bit_width = total_width;
    out_mapped->bit_offset = gas->register_bit_offset;

    if (gas->address_space_id == UACPI_ADDRESS_SPACE_SYSTEM_MEMORY) {
        out_mapped->mapping = uacpi_kernel_map(gas->address, total_width / 8);
        if (uacpi_unlikely(out_mapped->mapping == UACPI_NULL))
            return UACPI_STATUS_MAPPING_FAILED;

        out_mapped->read = uacpi_system_memory_read;
        out_mapped->write = uacpi_system_memory_write;
        out_mapped->unmap = uacpi_kernel_unmap;
    } else { // IO, validated by gas_validate above
        ret = uacpi_kernel_io_map(gas->address, total_width / 8, &out_mapped->mapping);
        if (uacpi_unlikely_error(ret))
            return ret;

        out_mapped->read = uacpi_kernel_io_read;
        out_mapped->write = uacpi_kernel_io_write;
        out_mapped->unmap = uacpi_kernel_io_unmap;
    }

    return UACPI_STATUS_OK;
}
#

I might make this public API as well tbh

#
/*
 * Map a GAS for faster access in the future. The handle returned via
 * 'out_mapped' must be freed & unmapped using uacpi_unmap_gas() when
 * no longer needed.
 */
uacpi_status uacpi_map_gas(const struct acpi_gas *gas, uacpi_mapped_gas **out_mapped);
void uacpi_unmap_gas(uacpi_mapped_gas *);

/*
 * Same as uacpi_gas_{read,write} but operates on a pre-mapped handle for faster
 * access and/or ability to use in critical sections/irq contexts.
 */
uacpi_status uacpi_gas_read_mapped(const uacpi_mapped_gas *gas, uacpi_u64 *value);
uacpi_status uacpi_gas_write_mapped(const uacpi_mapped_gas *gas, uacpi_u64 value);

Something like this

loud ice
#

what is a GAS?

loud ice
#

ah

#

its just a memory region

fiery turtle
#

thanks to this, qualcomm engineers were able to put the reset register in EmbeddedControl address space 💀

fiery turtle
loud ice
#

oh its one region in an address space

loud ice
#

resetting requires talking to the EC

fiery turtle
#

yeah

#

usually its abstracted away over SMM

#

on x86 at least

loud ice
#

no smm on arm

fiery turtle
#

yeah

loud ice
#

it could also be part of 8042 emulation on x86

fiery turtle
#

EL3 trl

loud ice
#

since at least on cros_ec it's routed to the EC as well

fiery turtle
#

yeah

#

i know usb->8042 works via smm trapping ps2 keyboard ports and stuff

vast kestrel
loud ice
#

oh right, page tables

vast kestrel
#

Smm also has page tables

loud ice
#

page tables for the target system that is

vast kestrel
#

But with el3 you have per core timers and I think even interrupt redirection

#

You do?

loud ice
#

wait what?

#

in smm?

#

no you dont afaik

vast kestrel
#

Nono I meant you do as in, i didn't know el3 had those

loud ice
#

ah yeah

#

it does

#

its a vm

vast kestrel
#

Doesn't only el2 have those?

fiery turtle
#

bruh the 1.0 PR is getting huge

#

at 33 commits right now

#

but those are all very imporant changes id like to have before release

dense steppe
#

you could make it a 0.99 PR for people to test, and when that gives a satisfactory result, you do the actual 1.0 PR.

kind mantle
#

Non

#

1.0-RC1

fiery turtle
vale isle
#

i love release candidates

fiery turtle
#

mandatory astral test

torpid root
fiery turtle
#

nop

#

as a matter of fact not a single api breakage is introduced in that pr

torpid root
#

very nice

#

oh does normal uacpi_gas_read/write map and unmap on every call?

fiery turtle
#

yeah ofc

#

since raw api got removed

kindred beacon
#

assertos testing would be funni too

fiery turtle
#

indeed

median crest
fiery turtle
#

very

#
commit e0f1fd3e031d6749472776c9a4b306aa3b8edb12 (origin/rewrite, origin/HEAD, rewrite)
Author: Matheus <[email protected]>
Date:   Mon Oct 28 16:24:43 2024 -0300

    tsc: fix it being broken when max base leaf < 0x15
median crest
#

dang

jaunty fox
vagrant hull
#

i won't stop yapping until everyone here accesses pci ecam via eax/ax/al only

fiery turtle
rustic compass
#

what thats a requirement? even tho ecam is mmio?

fiery turtle
#

Yup

north holly
rustic compass
#

how do they even think they can enforce it when the cpu core only sees a memory write

north holly
#
char cpu_vendor[13] = {0};
memset(cpu_vendor, 0, 13);
__cpuid__(0, 0, nullptr, (uint32_t*)&cpu_vendor[0],(uint32_t*)&cpu_vendor[8], (uint32_t*)&cpu_vendor[4]);
if (memcmp(cpu_vendor, "AuthenticAMD", 12))
{
    OBOS_Log("Fuck you AMD, OBOS is just gonna sit here and triple fault\n");
    return;
}```
gentle peak
rustic compass
gentle peak
#

but it's a good idea to follow the rule anyway

mortal yoke
#

why is it a thing anyway

gentle peak
#

who knows

mortal yoke
#

like what is the technical reasoning for it

north holly
#

amd brainrot

#

only good thing coming out of amd is amd64

rustic compass
mortal yoke
#

though to be fair if its only like one old cpu then not like it really matters

north holly
#

what if just to tease them I use edx

gentle peak
#

yeah the rule doesn't make sense to me either but it exists and persists to this day so

#

not like it has a big impact

#

I highly doubt the codegen impact of requiring eax instead of any register is significant compared to the MMIO access itself

mortal yoke
#

or just don't care about it, its going to work just fine on the majority of cpus I am sure

gentle peak
#

valid

#

I implemented it anyways because it's not difficult at all

#

but at least on zen 3 it works perfectly fine if not using eax

rustic compass
#

just report to the user that his cpu is faultymeme

flat badge
#

I bet the technical reasoning is stupid

#

Maybe some SMM emulation expects it to behave that way

gentle peak
#

maybe

fiery turtle
#

TLDR always use legacy pci io and you're golden chad

flat badge
#

except that legacy pci io doesn't support pcie caps

#

or non zero segments

fiery turtle
#

whats a pcie chad

frank canopy
#

speaking of amd requirements I'm still mad that high level page tables can't have the global bit set on amd (its ignored on intel)

frank canopy
slow drift
#

can't you set the global bit only for the last pml?

#

i.e. PTE if you're only using 4KiB pages

rustic compass
#

that wouldnt work

frank canopy
slow drift
#

oh I thought you just have a recursive function to get the last PML

#

but the page tables themselves are recursive

calm latch
#

solution to all paging problems: don't use recursive page tables

slow drift
#

why would someone use them?

#

they seem to complicate stuff rather than simplifying it

#

I like how this thread becomes home to a lot of discussions related to anything but uACPI

frank canopy
#

lmao yeah

#

it costs one top level page entry and you get access to any page structure for a virtual address without having to do traversal

slow drift
#

so.. the benefit is you don't traverse the page tables?

frank canopy
#

not manually anyway yeah

#

I can get any of the page tables for a virtual address with just some bit math

slow drift
#

and I can get any page table for a virtual address with just some function calls and some bit shifts

#

what's the deal

frank canopy
#

it isn't really a big deal either way

#

does save having to manually map all the page tables but that's not a huge deal

slow drift
#

it's more of a hack than anything, which seems harder to implement than a "normal" VMM

#

or maybe not but still, it's a hack and imo it should not be relied on

#

I guess this is subjective

frank canopy
#

shrug it's technically a hack but it fails out of the standard so it can be relied on. either way it's subjective

slow drift
gentle peak
#

mostly useful on 32 bit platforms where an hhdm is infeasible

slow drift
#

oh alright

#

on 32 bit it makes sense

frank canopy
#

yeah

#

i think windows still uses it and linux might but for them its probably a holdover more than anything

slim panther
#

we need to convince upstream to switch to uacpi

vast kestrel
#

Linux doesn't have recursive page tables

#

But they are neat, I used them to embed the buddy allocators metadata directly in the page table entries of the direct map

#

And if you want to iterate the page table for whatever reason it's also very convenient since you don't have to do a tree like iterations but it's just a for loop

hollow elm
#

i found it in some document for zen3/4 iirc

#

it's probably just ^C^V at this point without much thinking though?

calm latch
#

No issues with recursive mappings, and no issues with 32 bit platforms

gentle peak
#

there are slight issues with performance though

#

those can be mostly mitigated ig

#

but still not as good as recursive or hhdm

calm latch
#

But those also potentially cause a lot of page walks

blissful creek
#

how are there 32k messages in here

kind mantle
#

Because of this

blissful creek
#

Oh i see

#

typical of every server

kindred beacon
#

I have a new motto proposal btw

#

uACPI, the shitty kernel microbenchmark for garbage homebrew kernels

fiery turtle
#

Lol

north holly
#

damn uACPI thread is going to go past obos' message count soon

#

I need to lock in and get shit done

kindred beacon
#

can't compete with nyaux anyways

north holly
slim panther
#

tf

torpid root
#

too many one word messages

hasty plinth
#

the early days of the nyaux thread were different

sterile egret
#

lmao

fiery turtle
#

Fun fact u didnt care about:

❯ grep -rh "SCI Interrupt :" | sort --unique
[02Eh 0046   2]                SCI Interrupt : 0009

the SCI IRQ is always 9 (on literally all 500 blobs that I have)
(well okay its set to 0 on hw-reduced blobs)

torpid root
#

that's actually interesting

fiery turtle
fiery turtle
#

Almost done with these sorts of tests for opregion types

#

One last (the hardest) left for GenericSerialBus

#

and on the test runner side

rustic compass
#

How many features/feature completeness could a os achieve with only table and aml support without ec and non mmio/pci gas support?

fiery turtle
#

non mmio/pci gas is very very rare, like i've only seen it on arm

#

as for no EC, u can basically do most things as well, some of the more advanced aml stuff might not work, like reading battery stats for example

frank canopy
#

so with no ec you lose out on advanced laptop things then?

hollow elm
#

advanced laptop things like the power button :^)

hollow elm
#

or well, on modern amd laptops the power button doesnt even use the ec

fiery turtle
#

for AMD u literally need an AMD GPIO driver as well lol

fiery turtle
#

but if u play around with uacpi's OSI settings u can report old windows

hollow elm
#

just report that you're hp-ux or something meme

fiery turtle
#

yeah only servers check for HP-UX lmfao

hollow elm
#

i think my old laptop checks for it as well

fiery turtle
#

damn

hollow elm
#

idk if it does anything with that information other than treating it the same as some version of windows tho

frank canopy
#

neat

deft canopy
fiery turtle
#

definitely

deft canopy
#

Just gonna ask rene and some others for the AML dumps, idk why i never thought to ask them

fiery turtle
#

is rene the guy from t2

deft canopy
#

Ya

fiery turtle
#

ohhh

#

thatd be cool

#

if they have very old x86 laptops or pcs too

deft canopy
#

I would be surprised if someone in their server didnt have some old stuff, i can def ask around

fiery turtle
#

much appreciated

sterile egret
fiery turtle
#

Compaq is known for the amount of quirks it has in the kernel so should be insane

frank canopy
frank canopy
#

np

frank canopy
gentle peak
#

amd bios and kernel developer guide

frank canopy
#

thanks

gentle peak
#

from the family 15h one

frank canopy
#

found it, thanks

#

weirdest random requirement still

hollow elm
#

for zen 3/3+/4

calm latch
#

where did you find it?

hollow elm
#

has a bunch of docs uploaded as attachments

hollow elm
#

okay "Processor Programming Reference (PPR) Vol 1 for AMD Family 1Ah Model 02h C1 - 57238 Rev 0.24 - Sep 29, 2024" also contains that

#

in section 2.1.8.1

strong heath
#

why does uacpi have the io_read/io_write be multiplexed calls

#

isnt it a dirtier approach all around than having separate functions for separate sizes? you have to pass bigger integers than necessary, do switches for the byte size values, handle bad cases...

#

why is it not io_read8, io_read16, and io_read32

north holly
strong heath
#

its left for the kernel to do it

north holly
#

What do you even mean by bad cases?

fiery turtle
#

because a lot of kernels already have their own similar functions that do the switch, u can just redirect the call to those

strong heath
#

any value that isnt valid, like, anything above 4 for x86 platforms

fiery turtle
#

also, less apis to implement == better

north holly
#

Invalid argument

#

Not like that's impossible to do

strong heath
#

yeah but why do you have to do that at all is the point here

fiery turtle
#

answered above

#

although i do agree that its dirtier

north holly
#

Meh I think it's fine

fiery turtle
#

ACPICA gives u raw bit size that u must round up to next byte boundary

#

so theres that

loud ice
#

lmfao what

fiery turtle
#

yea..

loud ice
#

but yeah i agree that uacpi should have split 8/16/32

strong heath
north holly
loud ice
strong heath
fiery turtle
#

wdym by a lot

#

either i do the switch or u do it

loud ice
#

it pesimizes it in the os code

#

not in uacpi

strong heath
#

if you want to do it inside uacpi that is your deal

#

dont pass that debt to the kernel

fiery turtle
#

uacpi doesnt know the size its going to read or write ahead of time

#

so its the same exact code

#

just different place

north holly
#

^

#

Example of this is GAS reads/writes

fiery turtle
#

or AML fields

loud ice
#

static safety is still better though

strong heath
#

this is actively an issue for type safety among others

#

and performance

fiery turtle
#

it doesnt affect performance

north holly
loud ice
#

someone has to do the switch

#

its either you or uacpi

fiery turtle
#

yeah

strong heath
#

if uacpi has to do the switch, that is their issue, why do you have to dirty the kernel API so you dont have to do it

#

its such a weird approach

vagrant hull
#

also i am not gonna say anything but i don't think that "ACPICA does it like that" should be much of a justification for doing things similarily :^)

fiery turtle
#

nah i was giving an example of how u can make this api even worse lol

vagrant hull
#

yeah i'm just saying

strong heath
#

ACPICA makes you kill all your children so uACPI claiming only your firstborn is great design

fiery turtle
#

but yeah i agree overall that its cleaner

north holly
#

Felt like it

loud ice
#

shkwve straight up does not have io bars at all lol, and its fine

north holly
#

Needs IO space bars

loud ice
#

sounds like a skill issued device

#

and so i dont care

north holly
#

It is

#

Well

#

Not really

loud ice
#

sorry i dont have any nics at the moment

north holly
#

Just some ethernet controller

loud ice
#

the closest i have to a NIC is usb

#

hey i have usb and u dont so im right and ur wrong, checkmate!

vagrant hull
#

as a matter of fact if it were up to me i'd get rid of the io_map/io_unmap APIs entirely and just have the io read/write 8/16/32 and that's it, for x86, since that's basically the only platform that needs it, and to hell with following the ACPI spec to the T

loud ice
#

though i should probably fix it

loud ice
vagrant hull
#

yeah

loud ice
#

thats straight up not how it works

loud ice
mortal yoke
loud ice
#

also

#

which microkernel has uacpi in userspace?

north holly
fiery turtle
#

anyway ill make a vote about splitting them i think

loud ice
#

managarm has it in kernelmode

fiery turtle
north holly
loud ice
#

ah

#

ok i guess

#

but yeah anyway id run uacpi with iopl and be done with it

fiery turtle
#

thats what he does atm lol

loud ice
#

or lazily attempt obtaining permissions for it

loud ice
#

a lot easier too

#

and faster

loud ice
fiery turtle
#

#polls message

vagrant hull
#

idk it just seems a bit overcomplicated but i maybe just haven't thought it through

loud ice
#

i mean honestly, apart from the microkernel thing i'd be okay with uacpi straight up inlining its own asm for it

vagrant hull
#

^

fiery turtle
#

so it would have to leak a handle

#

or have internal cache

north holly
loud ice
#

or just not use the api for mapping io ports

fiery turtle
#

thats what im saying

#

it would have to map() read() unmap()

loud ice
fiery turtle
#

well in reactos u have to map

loud ice
#

or map all ports at startup and who cares that its broken

loud ice
fiery turtle
#

lol

#

anyway korona had some very good arguments for why we should keep the map api

#

i was gonna remove it entirely

fiery turtle
#

i dont remember them but u can search

#

yeah

loud ice
#

it was just "cant use it in microkernels"

#

which has counterpoint: iopl

fiery turtle
#

it was a bit more than that

north holly
#

Microkernels aren't even real anyway

loud ice
#

hmm

#

or spend the 8k on an iopb which unmasks everything

fiery turtle
#

like why have map for memory and pci, but not io, which is technically also on every other arch

#

why make it special just because its not needed on x86

north holly
#

Also is uacpi 1.0.0 soon

fiery turtle
#

i think its a good argument

fiery turtle
#

io exists on anything that has pci

loud ice
#

its tied to the pci controller

#

not the platform

fiery turtle
#

aml can still use it tho

loud ice
#

no it cant

#

there is no single io port range for it to be given

fiery turtle
#
Device (PCI0)
{
    OperationRegion(..., SystemIO, ...)
}
north holly
#

AML could probably do anything

loud ice
fiery turtle
#

lol

loud ice
#

also that doesnt have any defined answer

#

have you seen any vendor which does this btw?

fiery turtle
#

like linux does have io support for aml compiled in for arm

#

explicitly

#

so im assuming thats for a reason

north holly
#

Wassit do

fiery turtle
#

which is enabled by

strong heath
#

another question, for the virtual memory map functions of uacpi, what caching do you guys prefer

#

uncachable?

fiery turtle
#

nope

strong heath
#

general purpose write back?

fiery turtle
#

that will kill your perf

strong heath
#

idk im asking

north holly
#

I use hhdm

fiery turtle
#

on x86 u use hhdm

north holly
#

Soooooooooo

strong heath
#

ah yes the hhdm caching

loud ice
#

very specific

loud ice
fiery turtle
#

well ok u use MTRR which are set correctly

north holly
#

Yes very

fiery turtle
#

on other arches you want to look at the e820

#

and decide based on the memory type

loud ice
#

no e820 outside of x86

fiery turtle
#

similar concept applies

#

its a universal name

#

for a memory map

loud ice
#

the efi memory map does not have any entry that tells you "use caching mode X"

strong heath
#

okay so you dont know so its write back

#

okay

loud ice
#

map it nGnRnE (arm)

#

and UC (x86)

strong heath
#

I just got told to not do UC

loud ice
#

and put a fence and cache flush before and after it (riscv)

fiery turtle
#

no, dont do what pitust tells u jesus lol

loud ice
#

you cant not do that if you want valid code lol

#

on arm you defo need nGnRnE

fiery turtle
#

no u dont

loud ice
#

holy shit what

#

okay so the answer is nGnRnE

#

ah wait no

#

efi has a bit cool

#

damn

fiery turtle
#

normal memory is mapped as normal memory

loud ice
#

honestly. just map it nGnRnE and be done with it

fiery turtle
#

that will kill your perf tho

loud ice
#

how much actual perf do you lose by that?

loud ice
fiery turtle
#

aml has a lot of global data in acpi reclaim

#

that it references all the time

fiery turtle
loud ice
fiery turtle
#

no idea tbh

loud ice
#

and a poll is maybe a couple writes

#

and anyway arm ngnrne does not apply to ram, only devices

calm latch
north holly
#

Probably just a memory bar

loud ice
gentle peak
#

pio on non x86 is just MMIO with an offset

loud ice
#

so on x86 you have mtrrs

fiery turtle
loud ice
#

im mapping it ngnrne and you cant stop me

#

also linux is like a pretty good os

fiery turtle
loud ice
#

inb4 not

calm latch
#

Idk it works as normal

loud ice
#

honestly i suspect its RO to stop attacks

#

not for perf

calm latch
#

I map framebuffer as UC KEKW

loud ice
#

lmfao

fiery turtle
calm latch
#

Because my phys map function just maps everything as UC

loud ice
calm latch
loud ice
fiery turtle
calm latch
fiery turtle
#

i mean it maps the fb as UC

#

sooo

north holly
calm latch
#

hhdm is for the weak

loud ice
#

yeah and those with performance concerns too i guess

calm latch
#

the difference is in a couple of page walks

fiery turtle
loud ice
#

yeah its average linux code

fiery turtle
#

th rest is mapped literally as normal ram

#

this logic is correct tho i think

#

device addresses wont be on the efi map

#

the rest will

calm latch
#

"But what about hot(un)plug memory "

fiery turtle
#

hotpluggable memory regions do appear in the memory map

calm latch
fiery turtle
#

i think

#

anyway why would aml reference them lmao

gentle peak
#

device addresses could appear in the efi memmap though

#

as reserved

fiery turtle
gentle peak
fiery turtle
#

which would default prot to ngnrne

gentle peak
#

fair enough

calm latch
#

anyway, I think I'll be adding another memory manager to pmOS eventually

#

To do stuff like PCI bar allocation

strong heath
#

maybe uacpi should pass to the map function a preference for the caching

fiery turtle
#

it doesnt have any

#

its an anonymous memory address that aml wanted to map

strong heath
#

well maybe you should have one then

fiery turtle
#

there isnt a caching hint in aml

#

its just heres an address read it

loud ice
#

just map it nc and call it a day smh

#

you are overthinking it

#

hmm

#

i wonder

#

could you induce SMM bugs by messing with MTRRs

fiery turtle
#

you definitely can

calm latch
loud ice
#

which brings us to the next two questions

fiery turtle
#

your pc hanging

loud ice
#

1

#

how do i make it exploitable

#

and 2

#

how do i get smm code out of my framework

fiery turtle
#

framework should have opensource firmware iirc?

loud ice
#

no

#

its closed

#

insyde i think

fiery turtle
#

bruh

loud ice
#

yeah ik it sucks

#

they should have went with coreboot+tianocore

#

but whatever

fiery turtle
#

another open source dream shattered

loud ice
fiery turtle
#

steamdeck can do coreboot they cant lmfao

loud ice
#

its chromeos

mortal yoke
#

the board that I have has a mostly open firmware impl available based on coreboot + edk2

jaunty fox
loud ice
#

so its the standard chromeos coreboot/depthcharge setup

fiery turtle
#

and steamdeck too

#

so stupid

loud ice
jaunty fox
#

wait

fiery turtle
#

yeah, all aml tables it has are COREBOOT stuff

jaunty fox
#

do you mean openfirmware or open-source firmware

loud ice
#

oh damn

loud ice
#

sorry not OF

#

obviously

#

OF on x86 would be stupid

jaunty fox
fiery turtle
#

that thing has so many quirks in linux

#

a custom ec impl too

north holly
loud ice
jaunty fox
mortal yoke
fiery turtle
loud ice
#

damn

fiery turtle
#

anyway vote pls: #polls message
If this is accepted id like to do it before 1.0

strong heath
#

what the hell does it mean for uacpi_kernel_get_thread_id to return a void *

#

what does the void * represent

#

is it a pointer to an opaque structure? is it an integer cast to a pointer?

gentle peak
#

opaque value that's unique for each running thread

strong heath
#

thank you representative of the OOMF guild

loud ice
#

opaque handle

#

uacpi returns uacpi_handle's all the time

gentle peak
#

afaik it's only used for recursive mutexes

fiery turtle
#

platform/arch_helpers.h

strong heath
#

I love binding loosey goosey typesystems with vibes based meanings into Ada/SPARK, which has the strongest type system ever made

#

how can you tell

fiery turtle
#

make it use your strong type if u wish

#

as long as you can propagate it to C

loud ice
#

(you probably cant)

loud ice
#

i love a good bit of vibe-driven development

calm latch
#

isn't this basically all of C?

fiery turtle
#

damn this vote is closer than i thought

loud ice
#

yeah thats pretty close

fiery turtle
#

waiting for nyaux to vote

loud ice
#

what about my alts?

#

my alts also deserve a voice!

fiery turtle
#

no

loud ice
#

wait this is not even about map its just the width?

fiery turtle
#

im definitely not removing map

loud ice
#

cringe

fiery turtle
#

u meanchad

loud ice
#

the only case where map makes any sense is the pmOS setup, and they run uacpi with iopl(3) ANYWAY

fiery turtle
#

its 2 loc to stub out io_map

calm latch
#

I can try and change it to use the tss meme

#

(it also makes sense for ARM?)

loud ice
#

IO ports are a property of the PCI controller, not of the entire SOC

calm latch
#

does uacpi not use io on it?

fiery turtle
#

right but why does inb etc work on linux

#

on arm

#

without specifying any sort of base or controller address

loud ice
#

i truly do not know

calm latch
#

I need to port pmOS to arm

loud ice
#

i think it reads from base 0 though

#

which is. weird.

#

or maybe not idk

#

anyway linux sucks, systemio makes no sense on !x86 and it doesnt make sense anyway

#

also this is something you can add back if and when we find firmware that needs it

#

which i think is unlikely

calm latch
fiery turtle
#

basically my thoughts

  • potentially arm memes, although no one knows what aml on arm does
  • microkernels
  • abstractions for mapping both address spaces with one helper (like reactos)
  • aligns nicely with AML since i can pre-map all opregions
  • aligns nicely with pci and memory apis since they do map stuff
  • trivial to stub out if it's a no-op in your kernel
loud ice
#

ok fair

fiery turtle
#

basically the only argument against is "lol it doenst need mapping are u stupid"

#

and well, my less apis to implement == better idea

#

but i think in this case its justified

frank canopy
fiery turtle
#

it reads from here:

#
/* PCI fixed i/o mapping */
#define PCI_IO_VIRT_BASE    0xfee00000
#define PCI_IOBASE        ((void __iomem *)PCI_IO_VIRT_BASE)
loud ice
#

you want arm64

#

not arm

fiery turtle
#

ah nvm

#

similar stuff there tho

loud ice
#

uh. no

fiery turtle
#
#define PCI_IO_START        (VMEMMAP_END + SZ_8M)
#define PCI_IO_END        (PCI_IO_START + PCI_IO_SIZE)
frank canopy
#

ahhh ok

loud ice
#

inb is not a thing on arm64

#

zero references

#

ah wait its generic

fiery turtle
#

yep

#
#if !defined(inb) && !defined(_inb)
#define _inb _inb
static inline u8 _inb(unsigned long addr)
{
    u8 val;

    __io_pbr();
    val = __raw_readb(PCI_IOBASE + addr);
    __io_par(val);
    return val;
}
#endif
loud ice
#

ah yeah

#

oh huh so so cursed

#

they mmap it to a fixed place

fiery turtle
#

what do they even map there

loud ice
#

the pci io window

#

presumably

fiery turtle
#
int pci_remap_iospace(const struct resource *res, phys_addr_t phys_addr)
{
    unsigned long vaddr = (unsigned long)PCI_IOBASE + res->start;

    if (!(res->flags & IORESOURCE_IO))
        return -EINVAL;

    if (res->end > IO_SPACE_LIMIT)
        return -EINVAL;

    return vmap_page_range(vaddr, vaddr + resource_size(res), phys_addr,
                   __pgprot(get_mem_type(pci_ioremap_mem_type)->prot_pte));
}
EXPORT_SYMBOL(pci_remap_iospace);
#

you're right

#

they just emulate x86

#

basically all PCI IO is mapped to one place

calm latch
fiery turtle
#

they pretend its a separate address space and remap it to a fixed location

#

so u use inb for x86 and other arches

fiery turtle
#

hmm ok

#

what's nice is there's basically one usage of these helpers in the entire code base

#

like 1 extra for io write

fiery turtle
slim panther
#

yes

flat badge
#

Yes, PCI pio is mapped to MMIO on non-x86 platforms

#

That's not surprising isn't it?

fiery turtle
#

nah

#

whats surprising is how linux emulates it

flat badge
#

Iirc I also mentioned it before

fiery turtle
#

we knew that already

#

i wonder how linux manages collisions in that global pio region

loud ice
#

honestly this feels so much like a linux-specific hack

fiery turtle
#

if you have one controller where 0x1000 IO maps to 0xDEADBEEF and another where 0x1000 IO maps to 0xBEEFDEAD so there's no collision technically

#

but in that global region offset 0x1000 would collide

loud ice
#

also, i'd advise against adding this to uAPI

fiery turtle
#

this?

loud ice
#

this as in, the pci pio mapping thing

#

(without a pci device handle to base it off of)

fiery turtle
#

we aren't adding that

loud ice
#

if you haev a pci device handle its obviously fine

#

yeah okay cool

fiery turtle
#

we will have bar_map and bar_read/write, and normal port io for legacy devices, aml etc

fiery turtle
#

i mean same api as uacpi uses for port io

#

which is technically x86 specific

loud ice
#

that does not work for uDRM

fiery turtle
#

it does

#

it needs it for e.g. bochs

#

which needs to touch vga regs

loud ice
#

the vga device bar names the registers iirc

fiery turtle
#

the bochs gpu certainly doesnt have that in the bar

mortal yoke
#

there are vbe specific ones at least that aren't covered by any bar

#

yeah

loud ice
#

wtf?

#

okay then

#

allow udrm asking for io ports not covered by a BAR

#

but still against the pci device

fiery turtle
#

yeah its unfortunate

#

how would that api map into uacpi

loud ice
fiery turtle
#

like it doesnt know what pci device to associate it with

loud ice
#

indeed

#

this can't work with uacpi, but uacpi is a very special case

mortal yoke
#

why would it have to take in a pci device anyway?

fiery turtle
#

lets put it this way, whats the downside of a raw legacy io uapi interface?

flat badge
#

I think what linux does it more or less the same as on x86: it will give each device a different range if i/o ports even if they are on different controllers

loud ice
flat badge
#

So there no collision

loud ice
#

that sounds so annoying to implement

fiery turtle
#

that would make sense i guess

fiery turtle
flat badge
#

yes, sure, automatic BAR assignment is not a thing on most platforms

#

That's an x86 special

loud ice
#

i think uefi does it

#

on all platforms

flat badge
#

Yes, true.

loud ice
#

but yeah this sounds very annoying to correctly implement

flat badge
#

Well, uefi has to implement this correctly for x86 already

loud ice
flat badge
#

If they support multiple segments at all at least (iirc ovmf doesn't)

loud ice
#

afaik

flat badge
#

No, servers have multiple ones

loud ice
#

ah really

#

okay

flat badge
#

at least larger servers

loud ice
#

interesting

fiery turtle
#

chromebook has pci segments lol

flat badge
#

They have one segment per socket

loud ice
#

like my one?

#

neat as a testing platform (if the charging port worked at least)

fiery turtle
#

it was either your chromebook or qualcomm's windows laptop

hollow elm
#

the rpi5 technically (as per linux) has 3 segments meme

fiery turtle
#

ah yeah nvm

loud ice
#

ah okay it was sdxe

hollow elm
loud ice
#

ngl i love how the open source firmware is the clean and well written one

#

and then the closed firmware is just lolnope

fiery turtle
#

i mean yeah it makes sense

#

how can it avoid collisions otherwise

#

on like busses

loud ice
#

they have different pci windows

hollow elm
#

yeah, and segments are not really a thing outside of acpi/os internals so

fiery turtle
#

who guaratees that tho

#

u can have both pci roots have a bus range of 0-3 or something

hollow elm
#

all 3 controllers have a 00:00.0 device that's a root port (and its configuration space is actually just the controller's mmio registers meme)

fiery turtle
#

bruh yeah

hollow elm
#

like the driver does if dev == 00:00.0: return mmio_base

#

else: write dev to window register, return pointer to window

fiery turtle
hollow elm
#

iirc the driver provides the read/write functions and not just the map function? and in those it takes a lock on the controller

hollow elm
fiery turtle
flat badge
#

Does the acpi firmware for raspi just not expose pcie?

fiery turtle
#

iirc its a hacky handrolled aml blob?

#

and they dont have mcfg

hollow elm
flat badge
fiery turtle
#

true

hollow elm
#

for the user-accessible pci connector on the pi5 they have a hack to expose the single function thats at 01:00.0 via MCFG

#

by pointing MCFG at the 4k window in the controller's mmio, and using os-specific hacks (one for windows and one for linux) to make sure the os only scans for 1 function at the root

flat badge
#

:^)

fiery turtle
#

most stable arm acpi implementation

dusky glade
#

api changes

#

i dont want to replace my 32 lines of code with 8 lines of code

#

😡

vagrant hull
#

(0000000000) successfully loaded 1 AML blob, 1702 ops in 17ms (avg 100117/s)

strong heath
#

fast

vagrant hull
#

yes

#

what can cause the load namespace function to return out of memory?

fiery turtle
#

mutexes etc returning NULL

north holly
#

You returned nullptr

fiery turtle
north holly
#

Test uacpi on serenityos trl

vagrant hull
#

well that i don't know, it's still faster than some other OSes here

fiery turtle
#

is this tcg

vagrant hull
#

anyways i want to make it work, speed is not a concern of mine rn

#

no it's kvm

fiery turtle
#

well true reactos got like 30k lol

vagrant hull
#

mutexes should theoretically be implemented

north holly
#

An allocation function

#

Like mutex alloc

vagrant hull
#

too generic

left orbit
#

or one of the create functions

#

yeah

north holly
#

uacpi kernel alloc

#

For example

vagrant hull
#

streaks says his alloc cannot give null

north holly
#

I would say size=0

left orbit
#

maybe try setting log level to debug

fiery turtle
#

create_{event,mutex,whatever}

north holly
strong heath
#

size=0 is handled

fiery turtle
#

size=0 is never a thing

#

i have a hard assert agianst that in the test runner

strong heath
#

and it cannot return null because it runs OOM handlers internally

vagrant hull
#

ok how do i make it debug verbose then

north holly
#

uacpi context set log level

#

Iirc

fiery turtle
#

show kernel api code

vagrant hull
#

wdym

strong heath
#

if you are brave enough to try to debug Ada code lol

left orbit
#

show the implementation of the uacpi kernel api

vagrant hull
#

it's long

left orbit
#

all the uacpi_kernel_* functions

vagrant hull
#

i didn't even push it anywhere yet

#

it's almost 400loc

left orbit
#

thats not big at all

north holly
#

uacpi_context_set_log_level(UACPI_LOG_DEBUG);

#

or to UACPI_LOG_TRACE

left orbit
#

trace will show you the opcodes being executed

strong heath
#

does uACPI do always aligned mmaps

left orbit
#

which should tell you what uacpi is trying to do

north holly
#

Iirc

fiery turtle
left orbit
#

never aligned or never misaligned

kind mantle
strong heath
#

would uacpi take a failed mmap as out of memory itself

#

even when no out of memory status is returned

fiery turtle
#

no

#

that would be a mapping_failed

fiery turtle
left orbit
#

ah

#

so it's the kernel's job to align the address, map the required page(s) and return an address that can be used to access them

#

makes sense

fiery turtle
#

yeah, just round_down(), map, and add diff

vagrant hull
#

so like

#

once you do initialize/load_namespace (we fixed the issue btw, it was that it needed events to be created as non-null for some reason)

fiery turtle
#

For some reason?

left orbit
#

lmao]

fiery turtle
#

Is it unclear why

left orbit
#

mint what are u smoking

loud ice
#

how else would you signal an out of memory condition to uacpi

#

outside of returning null

#

also how does a null event work lol

vagrant hull
#

i say for some reason because it doesn't seem to use events?

#

or are events mandatory?

loud ice
#

well you cant return an error when allocating them

#

thats for sure

fiery turtle
#

Events are used for the global firmware lock when its contented

#

And from AML

strong heath
#

well idk it seems to work for the time being

vagrant hull
#

it works with events being a literal no-op

fiery turtle
#

Because its not contended in qemu

loud ice
#

why do you not use a mutex?

vagrant hull
#

can you use a mutex?

fiery turtle
#

You cant

loud ice
#

why?

fiery turtle
#

The way firmware tells you its relased is via an interrupt

loud ice
#

i dont see a problem

#

queue work to release it in the interrupt handler

fiery turtle
#

Thats not

#

The problem

loud ice
#

okay sorry i dont understand the issue

#

like it would be ideal if you only used one concurrency primitive as much as possible/feasible

fiery turtle
#

When uacpi tries to acquire it, it may be used by firmware

fiery turtle
#

U cant not have it

fiery turtle
#

The way u know its released is via an irq

loud ice
#

yeah so if you see that it is contended, you acquire a helper mutex