Commit graph

866 commits

Author SHA1 Message Date
Hector Martin
83ac04c1a9 fb: Fix FB junk leftover from stage1 in stage2
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-09-18 00:00:22 +09:00
Hector Martin
9741ff9b97 fb: Fix UAF after fb shutdown
fb_console_reserve_lines() in mmu_shutdown() was causing a blit from the
freed framebuffer, putting heap metadata junk at the top left corner.

Signed-off-by: Hector Martin <marcan@marcan.st>
2024-09-17 23:59:29 +09:00
Hector Martin
cdb6d41aa2 display: Add workaround for Sequoia DCP handoff bug
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-09-17 23:42:42 +09:00
Hector Martin
793ca17209 firmware: Add 15.0 and function to check SFW against a range
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-09-17 23:42:05 +09:00
Hector Martin
8a122f86c4 exception: Fix EL1 exception return path
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-08-11 20:21:21 +09:00
Janne Grunau
421dfa4252 dcp: Fix firmware mapping check on t8103/t600x
t8103 and t600x use "asc-dram-mask" in iop-dcp-nub to mask bits out of
DMA addresses. This needs to be used in the firmware mappings
check/remap since the segments have maskable bits sets.

Fixes: 8332e24 ("dcp: Undo carnage from bad stage1 DART code")
Signed-off-by: Janne Grunau <j@jannau.net>
2024-05-18 14:51:24 +09:00
Janne Grunau
56feda2b5e dart: Fix parsing of variable lenght "vm-base" property
Signed-off-by: Janne Grunau <j@jannau.net>
2024-05-18 14:51:24 +09:00
Hector Martin
dfffdf6609 display: Avoid placing FBs at IOVA 0
Also search harder for a matching dcp/disp iova, in case it matters.

Fixes: #391
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 10:22:55 +09:00
Hector Martin
1841d88dcd clang-format: Gate out 18.1.6 changes
So `make format` in Fedora doesn't disagree with CI...

Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 02:18:29 +09:00
Hector Martin
4f8ddca920 clang-format 18.1.6 changes
This isn't in Fedora yet...

Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 02:16:14 +09:00
Hector Martin
387cc2ecec kboot_gpu: Fix warnings
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 02:05:12 +09:00
Hector Martin
657654ac09 clang-format 18
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 02:05:12 +09:00
Hector Martin
8332e2454c dcp: Undo carnage from bad stage1 DART code
A bug in our DART code was wiping and aliasing page tables. Go through
the segment ranges for DCP and redo any missing mappings. If we redid
any mappings, then PMGR reset DCP so it can recover from having faulted
on the previous boot.

Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 01:57:34 +09:00
Hector Martin
c83ad3fc4d dart: Fix silent logic for dart_translate()
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 01:56:57 +09:00
Hector Martin
8c107bf80a dart: Introduce dart_map_flags() and dart_translate_silent()
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 01:56:32 +09:00
Hector Martin
58090bb58c dart: Fix L2 table allocation & half-fix carnage from stage1
We were assuming L2 tables were always allocated consecutively at low
IOVAs. 14.5 broke this, causing all kinds of explosions.

The new code looks for the first unused L2 PT, and also checks whether
the first 2 entries are aliased to latter entries (which is what the old
code caused). If so, it clears them and reallocates them. This doesn't
undo the PT wipe from stage1 though, so downstream code has to redo any
missing mappings...

Signed-off-by: Hector Martin <marcan@marcan.st>
2024-05-17 01:54:30 +09:00
Janne Grunau
0c64b6b4c1 sio: Rework sio init for dual die SoCs
Use a struct instead of global variable to hold the necessary setup
information. This allows executing the setup for both sio instances.
In addition change the status to "okay" so that sio can remain disabled
if the setup fails.

Signed-off-by: Janne Grunau <j@jannau.net>
2024-04-29 16:46:20 +09:00
Hector Martin
95d67cf9d2 Update to clang-format 17
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-04-09 12:57:55 +09:00
Hector Martin
af6ca83187 proxy: Add EL0 SMP ops
Signed-off-by: Hector Martin <marcan@marcan.st>
2024-04-09 09:20:40 +09:00
Hector Martin
90eef7223e Fix condition for SPMI HPM
Fixes: 9065c700df ("Workaround lack of SPMI support in usb.c")
Signed-off-by: Hector Martin <marcan@marcan.st>
2023-12-17 19:09:06 +09:00
Janne Grunau
11b9d4475b display: Fix pmgr device id for t6022 dcpext4
Signed-off-by: Janne Grunau <j@jannau.net>
2023-12-16 17:17:37 +09:00
Josh Soref
e52eaf4f43 Spelling fixes
Correct misspellings identified by the check-spelling action.

Signed-off-by: Josh Soref <jsoref@gmail.com>
2023-12-13 16:50:42 +09:00
Janne Grunau
c11a012697 nvme: t6022: Derive die from nvme_base address
For some reason the ans node for t602x devices has an empty
"clock-gates" property. Use the MMIO address instead to determine on
which die the device is.

Fixes: 34f49a5 ("nvme: assume die 0 if clock-gates not set")
Signed-off-by: Janne Grunau <j@jannau.net>
2023-12-12 10:42:26 +09:00
Daniel Berlin
9065c700df Workaround lack of SPMI support in usb.c
M3+ have a new USB power controller and it works over SPMI.
However, the USB ports work (at least within m1n1) if we ignore
this and just init the phys directly.

This detects the case where we are not on an I2C based USB machine,
and initializes the phys directly.

Eventually we should support SPMI properly.

Signed-off-By: Daniel Berlin <dberlin@dberlin.org>
2023-12-03 17:44:50 +09:00
Daniel Berlin
c45da55256 More support for M3 chips
The UART base has moved from the M2 chips.
Everest settings introduce some changes to unknown registers
The MCC data has changed as well.

There is a drive-by change where I discovered what some of the unknown
HID18 bits are and documented them.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
2023-12-03 17:37:20 +09:00
Daniel Berlin
9f846b1e41 Support boot CPU not being 0.
Right now, we assume the boot cpu is cpu0.  That is not true on m3 max,
where it is CPU 4.

To figure out which CPU is the boot CPU, we check to see which CPU
is running before we start any other CPUs, and record the MPIDR/idx.

Without this patch, four issues happen on m3 max:

1. We try to start the boot CPU again, crashing it
2. We skip the real CPU 0
3. We start m1n1 again on CPU0 when we boot it
4. We enable interrupts on CPU0 because we think it's the primary CPU.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
2023-12-03 17:23:13 +09:00
Janne Grunau
5006e083c7 display: Use dcpext0 for HDMI out on t8112/t6020/t6021
dcpext0 behaves like dcp on M1* devices and can sleep after display
init. This has the advantage of not breaking macOS when starting with an
initialized display.
dcpext* are according to Apple's tech specs slightly more powerful than
dcp. They are advertised as 6K at 60Hz while dcp seems to be limited to
5K at 60Hz.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-27 13:33:08 +09:00
Janne Grunau
5245fc6a58 dcp: Pass the die number for dptx' connectTo method
Apperently just informative as display init on M2 Ultra in m1n1 worked
as expected despite passing '0' as die number.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-27 13:33:08 +09:00
Janne Grunau
ba69847862 display: Add NO_DISPLAY build config to skip display init
Required for stage 1 loader to allow chainloaded display/dcp experiments
to start with the state left by iboot.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-27 13:33:08 +09:00
Janne Grunau
232836bd64 kboot_gpu: Declare GPU firmware 13.6.2 as 13.5 compatible
Tested on t6001-j314c.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-15 12:13:00 +09:00
Janne Grunau
65185bd306 kboot: Declare DCP firmware 13.6.2 as 13.5 compatible
Tested on t6001-j314c.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-15 12:13:00 +09:00
Janne Grunau
0a8aa3da87 isp: Declare 13.6.2 firmware as 13.5 compatible on t600x/t602x
Tested on t6001-j314c.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-15 12:13:00 +09:00
Janne Grunau
630c62785a firmware: Add 13.6.2 and 14.1.1 firmware versions
Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-15 12:13:00 +09:00
Daniel Berlin
a925356096 Add initial M3 values for CPU_START_OFF
I only can easily find the T6031/T6034/T8122 values.
If there is a T6030, the value is not in the same place I found these.

Signed-off-by: Daniel Berlin <dberlin@dberlin.org>
2023-11-14 19:01:30 +09:00
Alyssa Ross
8bdfdb7ce8 Fix build with -DDEBUG
If DEBUG is not defined, the compiler doesn't look at the arguments to
dprintf().  This has led to dprintf() bitrotting over time, referring
to variables that no longer exist, or by the wrong type, etc.

Here, I've tried to fix all the dprintf() calls to the best of my
ability, by comparing them to nearby calls that do compile, and
looking through the git history to understand the original intent.

Signed-off-by: Alyssa Ross <hi@alyssa.is>
2023-11-14 18:58:16 +09:00
Janne Grunau
f297951783 kboot: dcp: Enable dcpext on t600x/t8103 as well
Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
e72e84f669 clk: Add missing '\n' in printf message
Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
48c5ca8eca firmware: Reformat firmware version info table
Disable clanmg-format for it and transform it into a readable form by
padding columns with spaces.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
e4ea2d5319 kboot: dcp: Use OS firmware 13.5 as compat version
The dptxport endpoint changed API between 13.3 and 13.5. Nobody is
supposed to run 13.3 OS firmware at this point so do not claim to be
compatible. The DCP linux driver is fixed since a couple of weeks to
accept 13.5 as compat version.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
4ce65e1c08 kboot: dcpext: Enable dcpext* on t600x only with firmware 13.5
Only the HDMI port on 14 and 16 inch Macbook Pros needs dcpext and the
dptxport endpoint implemention in the DCP driver supports only the 13.5
firmware. Postpone this for after the fedora release.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
c9ae791b79 kboot: dcpext: t8112/t602x: Use dt_reserve_asc_firmware() for dcpext*
Avoids manually matching pre-mapped memory against "carveout-memory-map"
and maintaining a list of hopefully static carveoout regions.
Leave t8103 and t600x alone for now. Porting dcp over to this a littles
harder since that needs additional handling for regions mapped to
"dart-disp0?".

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
9a3a1271a5 kboot: Align segment sizes to 16k in dt_reserve_asc_firmware()
The segment for the dcp firmware text is inexplicably only aligned to 4k.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
69e3610737 display: Optionally use dcpext0/1 on t6020 and t6021
Allows emulating a t6022 system with fused off dcp0/dcp1 display
controllers.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Janne Grunau
8c99a189e0 dptx: Add the number of dptxport services
Avoids waiting 500 ms for the second dptxport service on t6020 and
possibly t6021.

Signed-off-by: Janne Grunau <j@jannau.net>
2023-11-14 18:57:15 +09:00
Hector Martin
787eb8c220 display: More Sonoma workarounds
Power up display early (fixes HPD sometimes) and delay at least one
frame after swapping before quiescing DCP, otherwise the swap somehow
doesn't complete.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-11-02 19:19:10 +09:00
Hector Martin
5cecf53144 everything: Use calloc instead of malloc almost everywhere
This fixes at least one and likely more than one bug where we forgot to
zero-init.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-11-02 18:12:33 +09:00
Hector Martin
321a80c928 afk: Increase timeout from 500 loops to 500ms (time-based)
This should hopefully solve the reliability issues here.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-11-02 18:12:33 +09:00
Hector Martin
40a9444484 display,fb: Clear framebuffer early in the Sonoma stage2 fixup path
stage1 ends up with an ugly Asahi 100% logo on top of a 200% Apple logo.
Let's just clear it so it looks nicer.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-11-02 18:12:33 +09:00
Hector Martin
6af39a9b40 display: Try to modeset twice
This works around issues switching to 120Hz mode on systems affected by
the Sonoma situation, and in general it's probably a good idea anyway.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-11-02 18:12:27 +09:00
Hector Martin
c887c3cb54 display: Work around macOS Sonoma firmware bugs
It appears that when macOS is set to non-ProMotion mode, DCP firmware
<14.0 booted from DCP firmware 14.0+ needs a delay before modesetting to
complete the modeset properly.

The cases here are:
- Older m1n1 stage1 will, as far as it's concerned, initialize the
  display properly, but it won't work. It also misses the retina flag,
  since this codepath was intended for external displays. Use the
  missing retina flag as a signal to trigger reconfig.
- If installed as stage1, we reconfigure the display as usual, now with
  the extra delay. We also set the Retina flag now.

The persistence mechanism for the ProMotion flag is unknown. It doesn't
seem to be nvram. It also doesn't matter if we successfully modeset to
120Hz mode and then reboot, it breaks again, so it's not about the
"current" mode sticking.

Signed-off-by: Hector Martin <marcan@marcan.st>
2023-11-02 18:12:26 +09:00