mirror of
https://github.com/lemonade-sdk/mac-amdgpu.git
synced 2026-11-23 04:29:26 -10:00
main
10
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
46e8d1460f |
Add HRX host runtime and native atomic validation
Implement coarse host pools, dynamic queue resources, discovery-based topology and ATOM clock queries. Correct R9700 two-array compute masks and NBIF ROM-bank access found during driver 188 validation. Build pinned HRX, Loom and LSE through reproducible macOS adapters. Add guarded HRX compute, queue resource and native CPU/GPU add/CAS controls and contention tests. Driver 189 hardware validation remains pending; no inference or general fine-grained atomic support is claimed. |
||
|
|
682ca7c553 |
Bring up RDNA4 command queues and verified host-memory transfers
Correct firmware acknowledgements, GPU address translation, MES queue setup, SDMA and CP submission, and driver session teardown. Add runtime identity checks, host diagnostics, checked GART mapping lifetime, and reusable aligned aperture reservations. Record build 172 hardware acceptance and build 173 allocator validation. Add 19 regression suites covering packet layouts, firmware sequencing, command-ring reuse, mapping failure retention, and lifecycle behavior. |
||
|
|
3bdeed2de9 |
v0.1.48: SDMA engine actually running — NBIF v6.3.1 + per-IP-version regs + MMIO WPTR mode
First version where the SDMA engine actually processes ring submissions
on this hardware. v0.1.0 through v0.1.46 had multiple cascading bugs;
this commit consolidates the chain of fixes uncovered by a line-by-line
re-audit against upstream amdgpu.
NBIO/NBIF
- Replaced the wrong nbio_v7_11 funcs with a full nbif_v6_3_1 port.
Our chip reports NBIF v6.3.1 in discovery (hw_id=108), not NBIO 7.11.
Different doorbell-routing model: S2A entries with explicit AWID/
AWADDR/RANGE_OFFSET/RANGE_SIZE per port, direct MMIO at BASE_IDX 2
(no PCIE_PORT indirect needed for the entry table). Ported:
nbif_v6_3_1_remap_hdp_registers (BX0 0x012d/0x012e @ BASE_IDX 2)
nbif_v6_3_1_init_registers (RCC_DEV0_EPF2_STRAP2)
nbif_v6_3_1_ih_control (BX0 INTERRUPT_CNTL)
nbif_v6_3_1_enable_doorbell_aperture
nbif_v6_3_1_enable_doorbell_selfring_aperture (BX_PF0)
nbif_v6_3_1_sdma_doorbell_range (S2A ENTRY_2, AWID=0xe AWADDR=0x3)
nbif_v6_3_1_ih_doorbell_range (S2A ENTRY_1)
nbif_v6_3_1_gc_doorbell_init (ENTRY_0=0x30000007, ENTRY_3=0x3000000d)
- PCIE_PORT_RREG32/WREG32 helpers via BIF_BX_PF1_RSMU_INDEX/DATA
(NBIO BASE_IDX 1), distinct from existing SMN path via PCIE_INDEX2.
- BAR2 PCIe phys addr captured in ensure_open, fed into SELFRING base.
- doorbell_init() was defined but never invoked — fix.
- Ordering: SELFRING enabled last (matches soc24_common_late_init).
- IP-version-aware base/_nbif_4_10 register dispatch.
SDMA register correctness
- All QUEUE0_* and UTCL1_* offsets were pulled from gc_12_1_0_offset.h
(a different chip, GFX 12.1) and were systematically 0x180 higher
than the correct gc_12_0_0_offset.h values for our R9700 (GFX 12.0.1).
Every ring-program write — RB_BASE, RB_CNTL, RB_WPTR, DOORBELL,
DOORBELL_OFFSET, WPTR_POLL_ADDR — has been hitting wrong GC registers
since v0.1.0. Corrected.
- sdma_reg_offset now uses GC BASE_IDX 1 for the hyp-dec range
[0x5880..0x589a] per upstream sdma_v7_0_get_reg_offset (line 125).
MCU_CNTL (0x588e) was being read/written at GC[0]+0x588e — a random
unrelated register — for the entire driver lifetime. HALT/RESET
writes had no effect; the symptomatic MCU_CNTL=0x92929292 was the
garbage at the wrong address. Corrected.
- RB_CNTL.MCU_WPTR_POLL_ENABLE = 1 (was 0). Without this the MCU
doesn't react to WPTR updates even with a valid doorbell signal.
- Removed the defensive HALT=1 at SDMA init step 1 — bare-metal
upstream path doesn't halt; halting tears down PSP-autoloaded MCU
firmware state.
- STATUS_REG bit positions corrected in both dext (sdma_log_status)
and Swift (testLiveStatus) decoders per gc_12_0_0_sh_mask.h:142-161.
Per-IP-version register tables
- IPBaseTable now stores IPVersion[block], populated by discovery.
- SDMARegs is no longer a namespace — it's a SDMARegOffsets struct with
per-chip tables: kSDMARegOffsets_gc_12_0_0 (R9700 / GFX 12.0.x) and
kSDMARegOffsets_gc_12_1_0 (gfx1250 / GFX 12.1.x). sdma_pick_reg_table
selects at runtime. All call sites converted to sdma_regs(dev).FIELD.
nbif_is_ip_7_11_4(dev) now reads the actual discovered NBIO version
for the _nbif_4_10 register-variant dispatch.
SDMA kick — MMIO WPTR mode (AS+TB5 deviation)
- BAR2 doorbell aperture writes via IOPCIDevice::MemoryWrite64 do not
reach the SDMA MCU on Apple Silicon + Thunderbolt 5. Verified across
v0.1.30-v0.1.46 with every NBIF routing variant, SELFRING base from
PCI config, WC-flush readback, and engine-side DOORBELL_OFFSET combo.
- sdma_kick_doorbell now does the full four-step kick:
1. sysmem WPTR shadow write (upstream atomic64_set)
2. HDP flush
3. BAR2 doorbell write (upstream WDOORBELL64 — inert on AS+TB5)
4. MMIO RB_WPTR write (upstream use_doorbell=false branch — the
functional path on this platform)
- v0.1.47 verified: SDMA Copy returns status=0 with RPTR=WPTR=0x40
(engine consumed 16 dwords and wrote the fence).
GART soft-gate (defensive)
- GARTContext.reads_supported flag (defaults false) — GART page table
is fully programmed but GPU-initiated reads through DART return zero
on AS+TB5. gart_init populates GARTContext from GMC's just-enabled
aperture and sets the flag with logged platform reasoning.
- BOAlloc(domain=kBODomainGTT) returns kIOReturnUnsupported when the
flag is false, so clients fail fast instead of allocating a BO that
silently misbehaves on every engine read. When Apple exposes a
working sysmem-mapping primitive, flipping the flag in gart_init
lights up the GTT path automatically with no other changes.
Version bumps 0.1.33 through 0.1.48 collapsed into this commit.
|
||
|
|
b04bf9777a |
v0.1.22: full GPU bringup — all 15 stages pass on R9700
Five-version diagnostic chain landing on a state where every IP block
initializes on hardware (IPDiscovery → SDMAInit). The decisive fixes:
v0.1.21 — port minimal smu_smc_hw_setup
PMFW must enable DPM before the IMU autoload state machine fires.
GetDriverIfVersion + SetDriverDramAddrHigh/Low (64KB VRAM slot via
fwBuf bump) + RunDcBtc + EnableAllSmuFeatures. PMFW returns
UnknownCmd for SetAllowedFeaturesMaskLow/High on this build, so the
mask-set is non-fatal — EnableAllSmuFeatures with the IFWI-baked
default mask is what trips the gate. running_features = 0x488f19e_
0x38fffcfb (DPM_GFXCLK + DPM_FCLK + DPM_UCLK + …) and BOOTLOAD_STATUS
transitions 0 → 0x8000003f within < 1 ms.
v0.1.22 — pin VRAM bump allocator to LOW BAR0-mapped region
BAR0 on R9700 + Apple Silicon + TB5 maps the BOTTOM 256 MB of VRAM
(FB_LOCATION_BASE = vram_start), not the top like most desktops. The
bump allocator was initialised with visible_base = vram_start +
(real_vram_size - visible_vram_size) which produced gpu_va near
vram_start + 32 GB — far outside BAR0. CSB write through
bar0_memcpy_to_vram page-faulted and killed the dext immediately
after autoload printed success. Fix: visible_base = vram_start, with
the first 24 MB reserved for PSP's hardcoded slots.
Also in this commit (work since v0.0.63):
- PSP TA bin parser + psp_asd_initialize (LOAD_ASD cmd_id 0x4) wired
between AUTOLOAD_RLC and psp_rl_load (v0.1.19)
- PSP ring KM=2, rb_frame 5-field-only, HDP flush+readback,
fw_pri-memset-before-memcpy (v0.1.14–0.1.18)
- Per-IP firmware extractors (RLC v2.x, MES uni_mes, GFX RS64,
SDMA v7), bump-allocated fwBuf slots per LOAD_IP_FW frame
- GMC + MMHUB + GFXHUB gart_enable port (mmhub_v4_1_0 / gfxhub_v12_0),
GART PT in VRAM at vram_start + 0x700000, CONTEXT0 enable
- RLC autoload wait + CSB content fill + SRM enable + CSIB program
- CP / MES / SDMA / GFX stage handlers (microcode signed off, no
live PM4 yet)
README updated to reflect v0.1.22 state. Deleted stale WORKLIST.md,
ROADMAP.md, and docs/PORTING_NOTES.md / docs/*PLAN*.md per session
cleanup; docs/ is gitignored going forward (audit-2026-05-22/ lives
there locally with the synthesis + per-agent reports + v0.1.19/0.1.20
plans).
Next frontier: first PM4 packet on a live ring (KIQ NOP smoke test) or
SDMA VRAM→VRAM copy. Bringup itself is solved.
|
||
|
|
bf723fba5c | Agent D: bringup reorder + gmc_v12_0.cpp rewrite + IFWI poll fix | ||
|
|
c8d224e93f |
PSP ring: KM=2 fix, GART+NBIO HDP remap, BASE_IDX support → SMU+GMC online
The headline fix: PSP_RING_TYPE__KM was 1 (= PSP_RING_TYPE__UM, the SR-IOV / RBI ring), upstream is 2 (= GPCOM kernel ring). With KM=1 psp_v14_0_ring_create wrote `1<<16 = 0x10000 = INIT_RBI_RING` to C2PMSG_64, PSP responded OK but never honored C2PMSG_67 wptr doorbells — every ring submit silently dropped. KM=2 sends `0x20000 = INIT_GPCOM_RING` and PSP starts processing frames. Other audit-driven fixes that compounded the bring-up issues: - MMHUB register offsets corrected to mmhub_4_1_0_offset.h: FB_OFFSET 0x04c7, AGP_TOP/BOT/BASE 0x0556/0x0557/0x0558, SYSTEM_APERTURE_DEFAULT_LSB/MSB 0x04c8/0x04c9, L2_CNTL4 0x04fd, L2_CNTL5 0x0503, INVALIDATE_ENG0_ADDR_RANGE 0x05ab/0x05ac. - PTE format: add AMDGPU_PTE_IS_PTE (bit 63) to PTEFlags::SYSMEM_RW — mandatory on GFX12 with PAGE_TABLE_DEPTH=0 or every PTE faults. - LoadIPKeyMgrDrv corrected to 0xF0000 (was 0x110000, a bogus value PSP rejected mid-bootloader). - NBIO `remap_hdp_registers` programmed during IPDiscovery (BAR5 byte 0x44000 was a no-op without this). - SOC15 multi-BASE_IDX support: IPBaseTable now stores up to 5 bases per IP, discovery reads them all, SOC15_REG_OFFSET_BIDX(...) added. SMU mailbox now uses MP1 BASE_IDX 1 (was hitting wrong reg). - psp_query_fw_reservation: sends GFX_CMD_ID_FB_FW_RESERV_ADDR + EXT after ring_create (matches upstream for SOS fw_version ≥ 0x3a0e14). - psp_setup_tmr: skip on psp_v14_0_x (boot_time_tmr by SOS) per upstream psp_skip_tmr. - LoadFirmware (post-SOS): parse common_firmware_header and pass (gart_mc_addr + ucode_array_offset_bytes, ucode_size_bytes) to psp_load_ip_fw instead of the whole .bin file. fw_type table: add SDMA_UCODE_TH0 (71), CP_MES (33), CP_MES_DATA (34), RS64 PFP/ME/MEC + P0..P3 stack variants (87-97). - psp_load_ip_fw: drop spurious 4 KB alignment check (upstream doesn't enforce it; ucode_array_offset_bytes is dword-aligned). - rb_frame: leave cmd_buf_size at 0 after memset (was 0x400, which PSP treated as a corrupt frame). - HDP flush: write + readback (mirrors amdgpu_hdp_generic_flush + nbio.get_memsize, the latter being the PCIe-write serialization barrier we were missing). - Host initializeGPU(): reorder to LoadFirmware(SMU) before SMUInit stage so the smu_test_message has a live PMFW to talk to. Untrack docs/ via .gitignore — internal porting notes / audit reports are not for the public tree; keep them local-only. Verified on a real R9700 over Thunderbolt 5: bringup now reaches GMCInit (8 stages green). Next blocker is multi-component firmware parsing for SDMA v3 / RLC sub-bins / uni_mes (PSP returns TEE_ERROR_BAD_PARAMETERS because our simple "skip 32-byte common header" doesn't fit those layouts). |
||
|
|
02ec6d721d |
Diagnostics: read MMHUB vram_start; reveals the C2PMSG_36 bug
Add MMHUB to IPBlock enum (separate from GMC — they're distinct IPs
in upstream) and reconnect HWID::MMHUB to it in discovery's hwid_to_block.
Vendor MMHUBRegs::MMMC_VM_FB_LOCATION_BASE/TOP/OFFSET offsets from
upstream asic_reg/mmhub/mmhub_4_1_0_offset.h (RDNA4).
DumpPSP selector grows outputs[7..10]: MMHUB base, FB_LOCATION_BASE raw,
FB_LOCATION_TOP raw, computed vram_start = (FB_BASE & 0xFFFFFF) << 24.
Host UI prints them with the expected `C2PMSG_36 = vram_start >> 20`.
On the test R9700, this immediately revealed the problem:
psp/mmhub_base: 0x0001a000 FB_LOCATION_BASE=0x00008000
psp/vram_start (MC addr): 0x0000008000000000
→ expected C2PMSG_36 = 0x80000
We've been sending C2PMSG_36 = 0x820 (psp.fwPriBusAddr >> 20 where
fwPriBusAddr is the DART bus address of our sysmem IOBufferMemoryDescriptor).
PSP expects an MC address; vram_start alone is 0x80000 >> 20. The
PCIe bus address we send is not a valid GMC route on this chip — PSP
silently fails the firmware load.
Fix is to move fw_pri (and friends) into VRAM accessed via the visible
BAR0 aperture, then pass C2PMSG_36 = (vram_start + offset) >> 20.
Followup commit.
|
||
|
|
db932bb3c4 |
Discovery bringup: BAR5 for registers, MM_INDEX/DATA for VRAM, FLR + IFWI handshake
Key fixes following upstream amdgpu:
- RREG32/WREG32 now target BAR5 (the MMIO register window for all AMD GPUs
>= CHIP_BONAIRE), not BAR0. BAR0 is the framebuffer aperture and reads
back zero until PSP sets up VRAM. Source: amdgpu_device.c
amdgpu_device_init() lines 3813-3819.
- amdgpu_device_mm_access path: read VRAM beyond the visible aperture via
the mmMM_INDEX/mmMM_INDEX_HI/mmMM_DATA register pair. Required for
small-BAR (256 MB visible / 32 GB total) where the discovery TMR sits
outside BAR0.
- Wait for IFWI handshake (mmMP0_SMN_C2PMSG_33 bit 31) before discovery —
upstream amdgpu_discovery_get_tmr_info polls up to 2s for USB4/TB hotplug.
Best-effort: log on timeout but don't bail (MEMSIZE is the real ready signal).
- Treat vram_size == 0 as tmr_in_sysmem, not failure (upstream behavior).
- Function-Level Reset via IOPCIDevice::Reset() runs before discovery to
kick off a fresh IFWI cycle on cold-hotplugged cards.
Host UI:
- New "Initialize GPU" single-button bringup with per-stage logging
("name → start" / "name → ok" / "name → FAILED kr=...").
- GetDiagnostics selector returns config / BAR layout / PM cap / IFWI /
BAR5+BAR0 MMIO probes so we can diagnose without dext os_log delivery.
After this commit we can reach the GPU's registers, read VRAM size correctly
(0x7770 MB ≈ 30 GB for R9700), and walk VRAM via MM_INDEX. Discovery TMR
still missing from VRAM (PSP-populated, not present on cold-hotplug TB5
without VBIOS) — next step is hardcoding R9700 IP bases from
qemu-vfio-apple traces.
|
||
|
|
34470dd89c |
Phase 1B chunk 18: on-die IP discovery — the way amdgpu does it
Replaces the LoadDiscoveryBin-as-primary-path shortcut with proper
runtime IP discovery, exactly mirroring drivers/gpu/drm/amd/amdgpu/
amdgpu_discovery.c:amdgpu_discovery_get_tmr_info.
Bootstrap registers (absolute BAR0 dword offsets — no IP base
needed; this is the chicken-and-egg solver):
mmRCC_CONFIG_MEMSIZE = 0x0DE3 (VRAM size in MB)
mmDRIVER_SCRATCH_0 = 0x0094 (TMR offset LO — PSP-written)
mmDRIVER_SCRATCH_1 = 0x0095 (TMR offset HI)
mmDRIVER_SCRATCH_2 = 0x0096 (TMR size, 0 if no sysmem override)
These legacy "mm" aliases resolve to the same physical registers
on every gen including RDNA4 — amdgpu uses the same constants
unconditionally for discovery bootstrap. NBIO's SOC15-routed
register (regRCC_DEV0_EPF0_0_RCC_CONFIG_MEMSIZE = 0x00C3) needs
the NBIO IP base which we don't have yet at this stage, so the
legacy path is the right one.
amdgpu_regs.h adds two helpers:
RREG32_abs(dev, reg) — BAR0 read at absolute offset
(bypasses SOC15 entirely)
RBAR2_32(dev, byte_offset) — 32-bit MMIO read from BAR2 at
a given byte offset (used to
read the discovery binary out
of VRAM)
amdgpu_discovery.{h,cpp} gains discover_ips_on_die(dev, *result):
Step 1: read mmRCC_CONFIG_MEMSIZE absolute → VRAM size in MB.
Step 2: read mmDRIVER_SCRATCH_2. If non-zero, PSP placed the
discovery binary in sysmem at (SCRATCH_1|<<32 | SCRATCH_0)
with size SCRATCH_2. That path requires mapping a
host-physical sysmem range from the dext, which AS
PCIDriverKit doesn't expose; log the address + bail
with kIOReturnUnsupported so the caller can fall back
to LoadDiscoveryBin.
Step 3: VRAM-resident TMR. Compute
offset = (vram_mb << 20) - kDiscoveryTMROffset (1 MB).
If that offset is outside the BAR2 visible window
(likely on small-BAR setups), retry at
(visible_size - 1 MB) — many discrete AMD configurations
on small-BAR systems place the TMR at the top of the
visible aperture instead.
Step 4: read kDiscoveryTMRSize (64 KB) bytes from BAR2 + offset
via 32-bit MMIO. Sanity-check the binary signature
before parsing.
Step 5: call discovery_parse() — same parser we already had,
which populates dev.ip with the per-IP base addresses.
BringupStage::IPDiscovery now actually does discovery:
- Calls discover_ips_on_die first.
- On success, runs the existing bringup_ip_discovery() (which
pins R9700 version constants).
- On failure, checks whether IP bases are already set (i.e.
the caller used LoadDiscoveryBin or SetIPBase as the escape
hatch) and treats that as success. Otherwise propagates the
error.
The LoadDiscoveryBin and SetIPBase selectors stay as documented
escape hatches for the "PSP placed TMR in sysmem" path and for
debugging — but the production path is now on-die discovery just
like amdgpu does it.
Build still clean: ** BUILD SUCCEEDED **.
Hello PM4 prerequisites on real hardware now reduce to:
1. Load + activate dext (entitlement granted)
2. InitDevice(IPDiscovery) — runs on-die discovery automatically
3. LoadFirmware(SOS); InitDevice(PSPLoadSOS)
4. InitDevice(PSPRingCreate); InitDevice(TMRSetup)
5. LoadFirmware(PMFW); InitDevice(SMUInit)
6. LoadFirmware for RLC_G, CP_PFP/ME/MEC, MES via PSP LOAD_IP_FW
7. InitDevice(GMCInit); InitDevice(IHInit);
InitDevice(RLCInit); InitDevice(CPInit)
8. SubmitTestPM4 → fence value returned
|
||
|
|
d6486e4dc8 |
Phase 1B chunk 6: IP discovery parser + correct team/bundle IDs
Two related changes that unblock the entitlement application + every
post-discovery bringup stage.
(1) IP discovery binary parser ported from upstream
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c. Reads the packed
binary format documented in include/discovery.h:
binary_header (sig 0x28211407, 6 × table_info entries)
└─ table[0] → ip_discovery_header (sig 'IPDS')
└─ die_info[N] → die_header
└─ ip_v4 [num_ips]
{ hw_id, instance, num_base_address,
major, minor, revision, base_address[] }
For each ip_v4 with hw_id in {MP0, MP1, GC, MMHUB→GMC, HDP,
OSSSYS, SDMA0, SDMA1, NBIF→NBIO} we copy base_address[0] into
DeviceContext.ip via IPBaseTable.set(). PSP/SMU/GMC/etc. queries
isResolved() before using the base — now those checks pass once
discovery has been loaded.
Files:
dext/amdgpu/amdgpu_discovery.h structs + DiscoveryParseResult
dext/amdgpu/amdgpu_discovery.cpp parser (~230 lines)
Selector 13 = LoadDiscoveryBinary: client uploads binary via
DMABuffer (page-aligned per the 16 KB rule), calls
LoadDiscoveryBin(size). Returns (ok, num_ips_total).
scripts/macamdgpu_ping.swift gains --load-discovery PATH that
drives this end-to-end.
Reference binary committed at docs/reference/gfx1151_discovery.bin
— pulled live from the Strix Halo box at 10.10.13.8 via
/sys/kernel/debug/dri/0000:bd:00.0/amdgpu_discovery. Useful for
parser regression checks. The R9700 has its own discovery binary
accessible the same way (via the qemu-vfio-apple Linux VM passing
the card through); pulling that lives on the worklist.
(2) Team ID + bundle identifiers updated to the user's real values:
DEVELOPMENT_TEAM YBQ9BU6Q6F (override with XCODE_TEAM_ID env)
Host app bundle com.geramyloveless.MacAMDGPUHost
Dext bundle com.geramyloveless.MacAMDGPUHost.MacAMDGPU
These match the user's Apple Developer team and the prefix already
used by their qemu-vfio-apple host app, so first build will
round-trip the bundle IDs to the Apple Developer portal cleanly.
project.yml + Host/MacAMDGPUHostApp.swift + scripts/build.sh all
point at the same identifiers.
(3) Dext is now correctly **embedded** in the host app at
Contents/Library/SystemExtensions/MacAMDGPU.dext (xcodegen
'embed: true' with no explicit destination now picks the right
path based on target type = driver-extension).
Build still clean: ** BUILD SUCCEEDED ** for both MacAMDGPU.dext
(126 KB) and MacAMDGPUHost.app on this M5 with Xcode 26.4.1 +
DriverKit SDK 25.4.
|