amdgpu: extract pci_*_quirk_flags into redox_quirk_bridge.c (Gap 15)

R1-R10 audit Gap 15: the pci_*_quirk_flags and
redox_pci_set_quirk_flags symbols lived inside redox_stubs.c
alongside kmalloc, printk, and other generic glue functions.
The 'stub' file name was misleading — the flag word that
pci_get_quirk_flags() returned was real, computed by
redox-drm (Rust) via redox_driver_sys::quirks::lookup_pci_quirks_full()
and pushed across the FFI boundary.

This change:

- Adds source/redox_quirk_bridge.c containing the three
  symbols plus a static g_redox_quirk_flags global. The
  header documents the Rust-to-C data flow and references
  the audit + the Rust-side caller at display.rs:155.
- Removes the three functions and the g_pci_quirk_flags
  static from source/redox_stubs.c. redox_stubs.c now only
  contains generic glue (kmalloc, printk, msleep, udelay,
  firmware_store, etc.) and the file name matches its
  contents.
- Updates recipe.toml Stage 1 to compile the new
  translation unit alongside redox_stubs.c. Both files
  are linked into libamdgpu_dc_redox.so.

The Rust-side caller in
local/recipes/gpu/redox-drm/source/src/drivers/amd/display.rs
is unchanged: the FFI symbol name 'redox_pci_set_quirk_flags'
is the same, so the linker picks up the new definition
without any code change on the Rust side.

No caller code in amdgpu_redox_main.c changes either —
pci_get_quirk_flags and pci_has_quirk are still declared
in redox_glue.h with the same signatures, and the new TU
provides the single definition that the linker resolves.

The end result is identical behavior (the flag word flows
the same way) with cleaner file naming and accurate
documentation. The audit's stub-finding is now a non-issue
for these symbols: there is no longer a stub; the bridge
file is named for what it does.
This commit is contained in:
2026-06-07 20:44:08 +03:00
parent 2838894c65
commit 98982cc2fa
3 changed files with 39 additions and 19 deletions
+1
View File
@@ -72,6 +72,7 @@ export CFLAGS="-std=gnu11 -D__redox__ -D__KERNEL__ -DCONFIG_DRM_AMDGPU -DCONFIG_
# Stage 1: Compile Redox glue code
"${TARGET_CC}" -c ${CFLAGS} "${REDOX_GLUE}/amdgpu_redox_main.c" -o amdgpu_redox_main.o
"${TARGET_CC}" -c ${CFLAGS} "${REDOX_GLUE}/redox_stubs.c" -o redox_stubs.o
"${TARGET_CC}" -c ${CFLAGS} "${REDOX_GLUE}/redox_quirk_bridge.c" -o redox_quirk_bridge.o
# Stage 2: DCN hardware display files
#
@@ -0,0 +1,38 @@
/* R1R10 audit Gap 15: amdgpu C ↔ redox-drm Rust quirk-flag bridge.
*
* The data flow is:
* 1. redox-drm (Rust) calls
* `redox_driver_sys::quirks::lookup_pci_quirks_full(&info)` —
* the same path pcid uses at enumeration time. The result is
* a real 64-bit flag word from the compiled-in table + TOML.
* 2. Rust pushes the word into this TU via
* `redox_pci_set_quirk_flags` (defined below).
* 3. amdgpu C reads via `pci_get_quirk_flags` / `pci_has_quirk`.
*
* The previously-shared `redox_stubs.c` was misleading: the flag
* word is real, not a fake constant. Splitting the bridge out is
* the audit's documentation fix. Rust-side caller is
* `local/recipes/gpu/redox-drm/source/src/drivers/amd/display.rs:155`.
*/
#include "redox_glue.h"
static u64 g_redox_quirk_flags;
void redox_pci_set_quirk_flags(u64 quirk_flags)
{
g_redox_quirk_flags = quirk_flags;
printk("PCI quirk flags stored: %#llx\n", (unsigned long long)quirk_flags);
}
u64 pci_get_quirk_flags(struct pci_dev *pdev)
{
(void)pdev;
return g_redox_quirk_flags;
}
bool pci_has_quirk(struct pci_dev *pdev, u64 flag)
{
(void)pdev;
return (g_redox_quirk_flags & flag) != 0;
}
@@ -221,7 +221,6 @@ void redox_dma_free_coherent(size_t size, void *vaddr, dma_addr_t dma_handle)
*/
static struct pci_dev g_pci_dev;
static int g_pci_dev_populated;
static u64 g_pci_quirk_flags;
#define REDOX_MAX_FIRMWARE_BYTES (64U * 1024U * 1024U)
#define REDOX_MAX_STORED_FIRMWARES 32
@@ -323,24 +322,6 @@ void redox_pci_release_regions(struct pci_dev *pdev)
(void)pdev;
}
u64 pci_get_quirk_flags(struct pci_dev *pdev)
{
(void)pdev;
return g_pci_quirk_flags;
}
bool pci_has_quirk(struct pci_dev *pdev, u64 flag)
{
(void)pdev;
return (g_pci_quirk_flags & flag) != 0;
}
void redox_pci_set_quirk_flags(u64 quirk_flags)
{
g_pci_quirk_flags = quirk_flags;
printk("PCI quirk flags stored: %#llx\n", (unsigned long long)quirk_flags);
}
void redox_firmware_store(const char *name, const u8 *data, size_t size)
{
int i;