mirror of
https://github.com/lemonade-sdk/mac_linuxgpu.git
synced 2026-11-22 23:57:31 -10:00
The DART layer refused any mapping past a hard-coded 1.5 GiB of live DMA bytes. Every dext page is DMA-backed, so GTT objects failed with ENOMEM at 1439 MiB (97 MiB already mapped at start) although amdgpu reports 64 GiB of GTT; llama.cpp's 1 GiB staging buffer and pinned host buffers could not be allocated. The limits that exist are the platform's: memory and wiring (the user wire limit here is 108.8 GiB of 128 GiB, with 19.2 GiB kept for the kernel), and the DART's IOVA window for the device, which the device tree gives a Thunderbolt port's dart-apciec as 2047 MiB (IOVAs from 2 GiB). DriverKit enforces both: IOBufferMemoryDescriptor::Create or PrepareForDMA fails. So: - dart.c only accounts live-mapped bytes (used/peak); a mapping fails when the seam fails it. linuxu_dart_budget and rt_dart_ceiling are gone (rt_dart_peak reports the high-water mark). - The seam logs each refusal with its size, the refusing call, its IOReturn and what is already mapped (a run of identical refusals logs its first and every 256th). - The shutdown and probe holds take no ceiling. They count the bytes mapped at their start and those mapped during them; retired mappings keep their DART IOVA until the endpoint reset, so the DART refuses a teardown mapping that would not fit beside them. A ceiling at the live total would refuse every probe allocation (nothing is mapped when the probe hold starts). - The dext's mapping table and dart.c's streaming slots were fixed at 4096 entries, another wall: both grow in chunks that never move. test_iokit_dma models the DART window and adds large mappings: a 1.5 GiB + 16 KiB mapping, a refused 512 MiB one (logged), 4500 live mappings, and a teardown mapping refused beside retired ones under the shutdown hold. test_session_shutdown closes a session with 6 GiB mapped. test_dma_dart maps 3 GiB and 6000 live mappings.
104 lines
4.4 KiB
C
104 lines
4.4 KiB
C
/* linuxu: SHIM (DeviceKit runtime glue) */
|
|
/*
|
|
* rt/dart.h — DMA→DART mapping layer. The host test backend uses identity
|
|
* IOVAs. DriverKit coherent allocations use IODMACommand directly, while
|
|
* streaming mappings use a DART-mapped bounce buffer with explicit copies at
|
|
* DMA ownership boundaries. Neither has a software ceiling on mapped bytes:
|
|
* a mapping fails when the platform refuses it (dma_mapping_error(), NULL
|
|
* or -ENOMEM), and live-mapped bytes are counted for diagnostics.
|
|
*
|
|
* The token table behind the counter is a small hash of live mappings,
|
|
* so double-unmap and unmap-of-unknown are detectable no-ops and
|
|
* teardown is leak-checkable (linuxu_dart_table_count()).
|
|
*/
|
|
#ifndef LINUXU_RT_DART_H
|
|
#define LINUXU_RT_DART_H
|
|
|
|
#include <stddef.h>
|
|
#include <stdint.h>
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/dma-addr.h>
|
|
#include <linux/dma-direction.h>
|
|
#include <linux/gfp.h>
|
|
|
|
/* struct declarations only: this header must stay includable without
|
|
* <linux/mm.h> / <linux/device.h> (those headers' include DAGs are
|
|
* owned by other tracks and change under it). The canonical
|
|
* declarations of the linuxu_dma_* family live in
|
|
* <linux/dma-mapping.h> (with <linux/mm.h> providing struct page);
|
|
* the prototypes below must agree with them. */
|
|
struct device;
|
|
struct page;
|
|
struct scatterlist;
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
/* dma_map_page equivalent over a struct page (backing = page host VA). */
|
|
dma_addr_t linuxu_dma_map_page(struct device *dev, struct page *page,
|
|
unsigned long offset, size_t size,
|
|
enum dma_data_direction dir);
|
|
void linuxu_dma_unmap_page(struct device *dev, dma_addr_t iova, size_t size,
|
|
enum dma_data_direction dir);
|
|
|
|
/* Scatterlist map/unmap: each entry gets a valid IOVA and the mapped bytes
|
|
* are counted. Returns the number of mapped entries, 0 on failure. */
|
|
int linuxu_dma_map_sg(struct device *dev, struct scatterlist *sg, int nents,
|
|
enum dma_data_direction dir);
|
|
void linuxu_dma_unmap_sg(struct device *dev, struct scatterlist *sg,
|
|
int nents, enum dma_data_direction dir);
|
|
|
|
/* Real 16 KB-aligned anon allocation (firmware/ucode load depends on
|
|
* this not returning NULL). */
|
|
void *linuxu_dma_alloc_coherent(struct device *dev, size_t size,
|
|
dma_addr_t *dma_handle, gfp_t gfp);
|
|
void linuxu_dma_free_coherent(struct device *dev, size_t size, void *vaddr,
|
|
dma_addr_t dma_handle);
|
|
|
|
/* Whether [iova, iova + bytes) lies inside one live mapping: what the
|
|
* IOMMU (DART) would translate for the device. An access outside every
|
|
* live mapping is one the DART faults, and behind a Thunderbolt tunnel a
|
|
* DART fault can take the device off the bus. */
|
|
int linuxu_dart_contains(uint64_t iova, uint64_t bytes);
|
|
|
|
/* A mapping made outside this layer: memory of another process that the
|
|
* platform mapped for the device (a display agent's IOSurface, mapped by
|
|
* the dext's IODMACommand). Its bytes are counted, and it is live for
|
|
* linuxu_dart_contains() from linuxu_dart_import() until
|
|
* linuxu_dart_import_release(); the IOVA range itself is the platform's.
|
|
* Returns 0, -EINVAL (empty, overflowing or overlapping a live import) or
|
|
* -ENOMEM (no memory for the record). */
|
|
int linuxu_dart_import(uint64_t iova, uint64_t size);
|
|
void linuxu_dart_import_release(uint64_t iova, uint64_t size);
|
|
|
|
/* Hold DMA releases while @stalled(@arg) reports that a GPU engine has
|
|
* work it has been running longer than its job timeout: memory the driver
|
|
* frees then stays mapped (and allocated) until no engine is stalled, so
|
|
* late work cannot reach an IOVA the DART no longer maps or has handed out
|
|
* again. NULL removes the predicate and releases what was held. Released
|
|
* opportunistically by later mapping calls, or by
|
|
* linuxu_dart_release_held (which returns how many releases are still
|
|
* held). */
|
|
void linuxu_dart_set_hold(bool (*stalled)(void *arg), void *arg);
|
|
unsigned int linuxu_dart_held(void);
|
|
unsigned int linuxu_dart_release_held(void);
|
|
|
|
/* Live-mapped bytes now and at most so far (diagnostics; there is no
|
|
* ceiling: the platform refuses what it cannot map). */
|
|
uint64_t linuxu_dart_used(void);
|
|
uint64_t linuxu_dart_peak(void);
|
|
|
|
/* Test/teardown hooks: number of live entries in the token table
|
|
* (must return to 0 on a clean run), and a full flush (clears the
|
|
* table and resets the counters — not used by the driver). */
|
|
int linuxu_dart_table_count(void);
|
|
void linuxu_dart_reset(void);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif /* LINUXU_RT_DART_H */
|