#asahi-dev · 2022-03-22 12:54
marcanlike mailbox already did but that's just because it's a crap design, it *could've* been done properly :)#asahi-dev · 2022-03-22 12:54
marcanit'd just complicate everything with impedance mismatches#asahi-dev · 2022-03-22 12:54
marcanso there is no benefit in trying to shoehorn this into some standard subsystem#asahi-dev · 2022-03-22 12:54
marcanthere's also the fact that none of this is ever going to be useful outside these tightly coupled apple devices anyway#asahi-dev · 2022-03-22 12:52
marcanthat different parent drivers then configure as needed#asahi-dev · 2022-03-22 12:52
marcanhence why we settled on implementing it as a helper library#asahi-dev · 2022-03-22 12:52
marcanso since there's all this variability we pretty much need a bespoke interface between RTKit and whatever's on top#asahi-dev · 2022-03-22 12:52
marcanyup#asahi-dev · 2022-03-22 12:51
marcanin the same context#asahi-dev · 2022-03-22 12:51
marcaneither the copro says "give me a buffer this big" or "here's a buffer for you"#asahi-dev · 2022-03-22 12:51
marcanyeah, and also whether the AP or the copro allocates memory varies by copro and specific endpoint#asahi-dev · 2022-03-22 12:51
marcanwhile others may actually allocate memory and return an appropriate DVA#asahi-dev · 2022-03-22 12:51
marcane.g. the SMC driver just verifies that any addresses SMC gives us are in the expected (whitelisted) SRAM range, then does an ioremap#asahi-dev · 2022-03-22 12:50
marcanso since the specifics of mapping buffers and translating addresses differ from instance to instance, RTKit punts that to a callback back into the parent driver so it can do whatever it needs to do#asahi-dev · 2022-03-22 12:50
marcanand that offset varies from device to device! M1 Max/Pro differ from M1 there#asahi-dev · 2022-03-22 12:49
marcanso we actually have 1 addres space for SMC (physical only), but 3 for DCP (physical, IOVAs that the IOMMU maps, and DVAs used by RTKit/DCP stuff which is IOVA plus an offset in the top bits)#asahi-dev · 2022-03-22 12:49
marcanwhile DCP uses an IOMMU for everything, including its own firmware mapped via the DAPF (which we normally don't even touch from linux), and that adds an offset to virtual addresses#asahi-dev · 2022-03-22 12:48
marcanNVMe has that SART whitelist thing, plus the NVMMU which is not used for RTKit, mostly, except for some debug mode commands sven found which IIRC break that model#asahi-dev · 2022-03-22 12:48
marcanSMC uses a dedicated SRAM and does not have DMA access elsewhere, so no IOMMU#asahi-dev · 2022-03-22 12:48
marcanone of the design decisions that went into RTKit was punting the specifics of how device addresses are mapped to the upper level driver, because it's just too variable#asahi-dev · 2022-03-22 12:47
marcanyeah#asahi-dev · 2022-03-22 12:46
marcanalso tangential, but DCP actually talks to the SMC key-value interface over a backdoor mailbox, all on its own (the copro, not us) :)#asahi-dev · 2022-03-22 12:46
marcanyes (and the mailbox below it)#asahi-dev · 2022-03-22 12:46
marcansince that's specifically battery/charging related (non-laptops do have power stats available, but those belong in hwmon)#asahi-dev · 2022-03-22 12:45
marcanoh yeah, and macsmc-power won't probe on non-laptop M1s of course :)#asahi-dev · 2022-03-22 12:43
marcanand possibly other things#asahi-dev · 2022-03-22 12:43
marcanthere's also not yet done hwmon support that would be shared between all 3 machine types#asahi-dev · 2022-03-22 12:42
marcanso for example only M1s have GPIOs and handle the RTC through this (and those specific upper drivers have DT bindings which on x86 wouldn't exist), but macsmc-power is configless and I think should instantiate on T2 Macs too to provide nice battery stats there (possibly better than the ACPI ones)#asahi-dev · 2022-03-22 12:41
marcanthe upper macsmc-* driver are always probed, but not all SMC instances in different machines would have all those features. they check to see if the relevant keys exist, if they do they probe, otherwise they ENODEV#asahi-dev · 2022-03-22 12:41
marcanmacsmc-acpi instead would have ACPI shenanigans as the lower layer abstraction, etc.#asahi-dev · 2022-03-22 12:41
marcanand then in the rtkit case, that also builds on top of the RTKit helper library and talks to the hardware mailbox over the mailbox abstraction#asahi-dev · 2022-03-22 12:40
marcanwe'd have a macsmc-acpi and macsmc-ioport alongside it, for the other machine types#asahi-dev · 2022-03-22 12:40
marcanmacsmc-rtkit is the actual mfd parent driver, it just initializes RTKit and provides the backend ops and then calls macsmc to actually register the mfd and everything on top#asahi-dev · 2022-03-22 12:39
marcanmacsmc is fairly thin, it mostly provides helpers for reading/writing different key types, enumerating/searching for keys, and does the general mfd registration#asahi-dev · 2022-03-22 12:39
marcanmacsmc-* drivers instantiate mfd sub-devices on top of macsmc, using a generic, higher-level key-value API#asahi-dev · 2022-03-22 12:38
marcan[gpio/RTC/power_supply/whatever else] > macsmc-* driver > [SMC higher level key-value abstraction] > macsmc > [SMC key-value back-end ops] > macsmc-rtkit > [RTKit endpoint API] > rtkit helper > [mailbox API] > apple-mailbox#asahi-dev · 2022-03-22 12:37
marcanactually five I guess#asahi-dev · 2022-03-22 12:36
marcanthere's up to four abstractions involved in SMC#asahi-dev · 2022-03-22 12:36
marcanno, T2 macs use a different thing (they do use RTKit internally but I don't think any of that is exposed)#asahi-dev · 2022-03-22 12:36
marcan(it is not spinlocked properly either, I gave up on that since it doesn't matter for this sole use case and trying to do it properly was too much of a mess)#asahi-dev · 2022-03-22 12:35
marcannote: the atomic thing is a special case for sending the final system shutdown/reboot command to SMC, which has to happen in atomic context; this is probably going to be the only consumer of that particular API#asahi-dev · 2022-03-22 12:34
marcan(pre-T2 Macs do some ioport interface for the key/value access, while T2 macs do some ACPI thing)#asahi-dev · 2022-03-22 12:33
marcanthat is the SMC RTKit backend (there's another layer in there because I want the upper level SMC stuff to work on T2 and pre-T2 x86 macs too, which do not use RTKit)#asahi-dev · 2022-03-22 12:33
marcanarnd: https://github.com/AsahiLinux/linux/blob/asahi/drivers/platform/apple/smc_rtkit.c#asahi-dev · 2022-03-22 12:33
marcanSMC too!#asahi-dev · 2022-03-22 12:33
marcanso for that having a separate mailbox driver does kind of make sense#asahi-dev · 2022-03-22 12:33
marcanyeah#asahi-dev · 2022-03-22 12:32
marcan(this is one reason we waited to submit until now, we wanted to iterate on that a bit)#asahi-dev · 2022-03-22 12:31
marcanSMC, NVMe, and DCP pretty much cover all the "weird" combinations of memory management for RTKit core endpoints, and all three are already up and running, so the current RTKit module design is already fairly well proven in that regard#asahi-dev · 2022-03-22 12:31
marcanDCP too