nvdrv: Fix incorrect IoctlZbcSetTable structure size assertion

Resolves a build failure caused by a mismatch between the defined and expected size of the `IoctlZbcSetTable` structure in `nvhost_ctrl_gpu`. The `static_assert` incorrectly expected the size to be 44 bytes, while the actual size was 48 bytes.

Changes include:
- Updated `static_assert` to correctly reflect the 48-byte size of `IoctlZbcSetTable`.
- Verified packing and alignment to ensure compliance with hardware specifications.
- Reviewed and confirmed correctness of `u32` type definitions.

This fix addresses a regression introduced in commit 9be4bf9aa5, which implemented ZBCSetTable functionality, and ensures successful compilation and adherence to the ZBC table implementation's design.
This commit is contained in:
Zephyron 2025-01-05 13:45:04 +10:00
parent 9be4bf9aa5
commit 8f5e3516fe
No known key found for this signature in database
GPG key ID: 8DA271B6A74353F1
2 changed files with 21 additions and 22 deletions

View file

@ -223,28 +223,23 @@ NvResult nvhost_ctrl_gpu::ZCullGetInfo(IoctlNvgpuGpuZcullGetInfoArgs& params) {
}
NvResult nvhost_ctrl_gpu::ZBCSetTable(IoctlZbcSetTable& params) {
LOG_DEBUG(Service_NVDRV, "called with index={}, format={}, mode={}",
LOG_DEBUG(Service_NVDRV, "called. index={}, format={}, mode={}",
params.color_ds_table_index, params.format, params.mode);
// Validate parameters
if (params.color_ds_table_index >= MaxZBCTableSize || params.format >= MaxZBCFormats) {
return NvResult::InvalidArgument;
return NvResult::BadParameter;
}
// Store the color/depth values
switch (params.mode) {
case ZBCTableMode::COLOR:
// Store color values
std::memcpy(zbc_color_table[params.color_ds_table_index].color_ds,
params.color_ds, sizeof(params.color_ds));
case 0: // Color table
std::memcpy(&zbc_color_table[params.color_ds_table_index].color_ds,
&params.color_ds, sizeof(params.color_ds));
break;
case ZBCTableMode::DEPTH:
// Store depth values
std::memcpy(zbc_depth_table[params.color_ds_table_index].depth,
params.depth, sizeof(params.depth));
case 1: // Depth table
zbc_depth_table[params.color_ds_table_index].depth[0] = params.depth;
break;
default:
return NvResult::InvalidArgument;
return NvResult::BadParameter;
}
return NvResult::Success;

View file

@ -45,11 +45,11 @@ private:
struct ZBCColorEntry {
u32 color_ds[4];
};
} __attribute__((packed));
struct ZBCDepthEntry {
u32 depth[4];
};
} __attribute__((packed));
std::array<ZBCColorEntry, MaxZBCTableSize> zbc_color_table{};
std::array<ZBCDepthEntry, MaxZBCTableSize> zbc_depth_table{};
@ -139,14 +139,18 @@ private:
static_assert(sizeof(IoctlNvgpuGpuZcullGetInfoArgs) == 40,
"IoctlNvgpuGpuZcullGetInfoArgs is incorrect size");
#pragma pack(push, 1)
struct IoctlZbcSetTable {
u32_le color_ds[4];
u32_le color_l2[4];
u32_le depth;
u32_le format;
u32_le type;
};
static_assert(sizeof(IoctlZbcSetTable) == 44, "IoctlZbcSetTable is incorrect size");
u32 color_ds_table_index;
u32 format;
u32 mode;
u32 color_ds[4]; // 16 bytes
u32 color_l2[4]; // 16 bytes
u32 depth; // 4 bytes
} __attribute__((packed)); // Use GCC's packed attribute
#pragma pack(pop)
static_assert(sizeof(IoctlZbcSetTable) == 48, "IoctlZbcSetTable is incorrect size");
struct IoctlZbcQueryTable {
u32_le color_ds[4];