drm/imagination: Move all FW interface check macros to pvr_checks.h

The same macros are redefined in three places, so move them to a common
file to reduce duplication and make it easier to reuse them.

Signed-off-by: Alexandru Dadu <alexandru.dadu@imgtec.com>
Co-developed-by: Alessio Belle <alessio.belle@imgtec.com>
Reviewed-by: Brajesh Gupta <brajesh.gupta@imgtec.com>
Link: https://patch.msgid.link/20260729-fwif-checks-updates-v1-1-af65e9606a7e@imgtec.com
Signed-off-by: Alessio Belle <alessio.belle@imgtec.com>
This commit is contained in:
Alexandru Dadu 2026-07-29 15:57:06 +01:00 committed by Alessio Belle
parent bc47d5937f
commit e0c92f0f9e
4 changed files with 39 additions and 41 deletions

View File

@ -0,0 +1,36 @@
/* SPDX-License-Identifier: GPL-2.0-only OR MIT */
/* Copyright (c) 2026 Imagination Technologies Ltd. */
#ifndef PVR_CHECK_H
#define PVR_CHECK_H
#include <linux/build_bug.h>
#include <linux/overflow.h>
#include <linux/stddef.h>
#define OFFSET_CHECK(type, member, offset) \
static_assert(offsetof(type, member) == (offset), \
"offsetof(" #type ", " #member ") incorrect")
#define SIZE_CHECK(type, size) \
static_assert(sizeof(type) == (size), #type " is incorrect size")
#define ALIGN_CHECK(type, align) \
static_assert(__alignof__(type) <= (align), #type " has incorrect alignment")
/*
* Where the last member of a struct is a flexible array member, using
* SIZE_CHECK() is pointless. If the structure is not already padded to
* alignment without the flexible array member, sizeof() will not match the
* offset of the flexible array member and the "correct" sizeof() value is
* completely meaningless.
*
* In those instances, use FLEX_ARRAY_CHECK() instead to assert that the final
* field is a flexible array member and that it behaves as expected.
*/
#define FLEX_ARRAY_CHECK(type, member) \
static_assert(flex_array_size((type *)NULL, member, 1) == \
sizeof_field(type, member[0]), \
#type "->" #member " is incorrect size")
#endif /* PVR_CHECK_H */

View File

@ -4,31 +4,7 @@
#ifndef PVR_ROGUE_FWIF_CHECK_H
#define PVR_ROGUE_FWIF_CHECK_H
#include <linux/build_bug.h>
#include <linux/overflow.h>
#include <linux/stddef.h>
#define OFFSET_CHECK(type, member, offset) \
static_assert(offsetof(type, member) == (offset), \
"offsetof(" #type ", " #member ") incorrect")
#define SIZE_CHECK(type, size) \
static_assert(sizeof(type) == (size), #type " is incorrect size")
/*
* Where the last member of a struct is a flexible array member, using
* SIZE_CHECK() is pointless. If the structure is not already padded to
* alignment without the flexible array member, sizeof() will not match the
* offset of the flexible array member and the "correct" sizeof() value is
* completely meaningless.
*
* In those instances, use FLEX_ARRAY_CHECK() instead to assert that the final
* field is a flexible array member and that it behaves as expected.
*/
#define FLEX_ARRAY_CHECK(type, member) \
static_assert(flex_array_size((type *)NULL, member, 1) == \
sizeof_field(type, member[0]), \
#type "->" #member " is incorrect size")
#include "pvr_check.h"
OFFSET_CHECK(struct rogue_fwif_file_info_buf, path, 0);
OFFSET_CHECK(struct rogue_fwif_file_info_buf, info, 200);

View File

@ -4,14 +4,7 @@
#ifndef PVR_ROGUE_FWIF_CLIENT_CHECK_H
#define PVR_ROGUE_FWIF_CLIENT_CHECK_H
#include <linux/build_bug.h>
#define OFFSET_CHECK(type, member, offset) \
static_assert(offsetof(type, member) == (offset), \
"offsetof(" #type ", " #member ") incorrect")
#define SIZE_CHECK(type, size) \
static_assert(sizeof(type) == (size), #type " is incorrect size")
#include "pvr_check.h"
OFFSET_CHECK(struct rogue_fwif_geom_regs, vdm_ctrl_stream_base, 0);
OFFSET_CHECK(struct rogue_fwif_geom_regs, tpu_border_colour_table, 8);

View File

@ -4,14 +4,7 @@
#ifndef PVR_ROGUE_FWIF_SHARED_CHECK_H
#define PVR_ROGUE_FWIF_SHARED_CHECK_H
#include <linux/build_bug.h>
#define OFFSET_CHECK(type, member, offset) \
static_assert(offsetof(type, member) == (offset), \
"offsetof(" #type ", " #member ") incorrect")
#define SIZE_CHECK(type, size) \
static_assert(sizeof(type) == (size), #type " is incorrect size")
#include "pvr_check.h"
OFFSET_CHECK(struct rogue_fwif_dma_addr, dev_addr, 0);
OFFSET_CHECK(struct rogue_fwif_dma_addr, fw_addr, 8);