xref: /linux/drivers/gpu/drm/imagination/pvr_device.h (revision e7b2b108cdeab76a7e7324459e50b0c1214c0386)
1 /* SPDX-License-Identifier: GPL-2.0-only OR MIT */
2 /* Copyright (c) 2023 Imagination Technologies Ltd. */
3 
4 #ifndef PVR_DEVICE_H
5 #define PVR_DEVICE_H
6 
7 #include "pvr_ccb.h"
8 #include "pvr_device_info.h"
9 #include "pvr_fw.h"
10 #include "pvr_params.h"
11 #include "pvr_rogue_fwif_stream.h"
12 #include "pvr_stream.h"
13 
14 #include <drm/drm_device.h>
15 #include <drm/drm_file.h>
16 #include <drm/drm_mm.h>
17 
18 #include <linux/bits.h>
19 #include <linux/compiler_attributes.h>
20 #include <linux/compiler_types.h>
21 #include <linux/io.h>
22 #include <linux/iopoll.h>
23 #include <linux/kernel.h>
24 #include <linux/math.h>
25 #include <linux/mutex.h>
26 #include <linux/timer.h>
27 #include <linux/types.h>
28 #include <linux/wait.h>
29 #include <linux/workqueue.h>
30 #include <linux/xarray.h>
31 
32 /* Forward declaration from <linux/clk.h>. */
33 struct clk;
34 
35 /* Forward declaration from <linux/firmware.h>. */
36 struct firmware;
37 
38 /**
39  * struct pvr_gpu_id - Hardware GPU ID information for a PowerVR device
40  * @b: Branch ID.
41  * @v: Version ID.
42  * @n: Number of scalable units.
43  * @c: Config ID.
44  */
45 struct pvr_gpu_id {
46 	u16 b, v, n, c;
47 };
48 
49 /**
50  * struct pvr_fw_version - Firmware version information
51  * @major: Major version number.
52  * @minor: Minor version number.
53  */
54 struct pvr_fw_version {
55 	u16 major, minor;
56 };
57 
58 /**
59  * struct pvr_device - powervr-specific wrapper for &struct drm_device
60  */
61 struct pvr_device {
62 	/**
63 	 * @base: The underlying &struct drm_device.
64 	 *
65 	 * Do not access this member directly, instead call
66 	 * from_pvr_device().
67 	 */
68 	struct drm_device base;
69 
70 	/** @gpu_id: GPU ID detected at runtime. */
71 	struct pvr_gpu_id gpu_id;
72 
73 	/**
74 	 * @features: Hardware feature information.
75 	 *
76 	 * Do not access this member directly, instead use PVR_HAS_FEATURE()
77 	 * or PVR_FEATURE_VALUE() macros.
78 	 */
79 	struct pvr_device_features features;
80 
81 	/**
82 	 * @quirks: Hardware quirk information.
83 	 *
84 	 * Do not access this member directly, instead use PVR_HAS_QUIRK().
85 	 */
86 	struct pvr_device_quirks quirks;
87 
88 	/**
89 	 * @enhancements: Hardware enhancement information.
90 	 *
91 	 * Do not access this member directly, instead use
92 	 * PVR_HAS_ENHANCEMENT().
93 	 */
94 	struct pvr_device_enhancements enhancements;
95 
96 	/** @fw_version: Firmware version detected at runtime. */
97 	struct pvr_fw_version fw_version;
98 
99 	/** @regs_resource: Resource representing device control registers. */
100 	struct resource *regs_resource;
101 
102 	/**
103 	 * @regs: Device control registers.
104 	 *
105 	 * These are mapped into memory when the device is initialized; that
106 	 * location is where this pointer points.
107 	 */
108 	void __iomem *regs;
109 
110 	/**
111 	 * @core_clk: General core clock.
112 	 *
113 	 * This is the primary clock used by the entire GPU core.
114 	 */
115 	struct clk *core_clk;
116 
117 	/**
118 	 * @sys_clk: Optional system bus clock.
119 	 *
120 	 * This may be used on some platforms to provide an independent clock to the SoC Interface
121 	 * (SOCIF). If present, this needs to be enabled/disabled together with @core_clk.
122 	 */
123 	struct clk *sys_clk;
124 
125 	/**
126 	 * @mem_clk: Optional memory clock.
127 	 *
128 	 * This may be used on some platforms to provide an independent clock to the Memory
129 	 * Interface (MEMIF). If present, this needs to be enabled/disabled together with @core_clk.
130 	 */
131 	struct clk *mem_clk;
132 
133 	/** @irq: IRQ number. */
134 	int irq;
135 
136 	/** @fwccb: Firmware CCB. */
137 	struct pvr_ccb fwccb;
138 
139 	/**
140 	 * @kernel_vm_ctx: Virtual memory context used for kernel mappings.
141 	 *
142 	 * This is used for mappings in the firmware address region when a META firmware processor
143 	 * is in use.
144 	 *
145 	 * When a MIPS firmware processor is in use, this will be %NULL.
146 	 */
147 	struct pvr_vm_context *kernel_vm_ctx;
148 
149 	/** @fw_dev: Firmware related data. */
150 	struct pvr_fw_device fw_dev;
151 
152 	/**
153 	 * @params: Device-specific parameters.
154 	 *
155 	 *          The values of these parameters are initialized from the
156 	 *          defaults specified as module parameters. They may be
157 	 *          modified at runtime via debugfs (if enabled).
158 	 */
159 	struct pvr_device_params params;
160 
161 	/** @stream_musthave_quirks: Bit array of "must-have" quirks for stream commands. */
162 	u32 stream_musthave_quirks[PVR_STREAM_TYPE_MAX][PVR_STREAM_EXTHDR_TYPE_MAX];
163 
164 	/**
165 	 * @mmu_flush_cache_flags: Records which MMU caches require flushing
166 	 * before submitting the next job.
167 	 */
168 	atomic_t mmu_flush_cache_flags;
169 
170 	/**
171 	 * @ctx_ids: Array of contexts belonging to this device. Array members
172 	 *           are of type "struct pvr_context *".
173 	 *
174 	 * This array is used to allocate IDs used by the firmware.
175 	 */
176 	struct xarray ctx_ids;
177 
178 	/**
179 	 * @free_list_ids: Array of free lists belonging to this device. Array members
180 	 *                 are of type "struct pvr_free_list *".
181 	 *
182 	 * This array is used to allocate IDs used by the firmware.
183 	 */
184 	struct xarray free_list_ids;
185 
186 	/**
187 	 * @job_ids: Array of jobs belonging to this device. Array members
188 	 *           are of type "struct pvr_job *".
189 	 */
190 	struct xarray job_ids;
191 
192 	/**
193 	 * @queues: Queue-related fields.
194 	 */
195 	struct {
196 		/** @active: Active queue list. */
197 		struct list_head active;
198 
199 		/** @idle: Idle queue list. */
200 		struct list_head idle;
201 
202 		/** @lock: Lock protecting access to the active/idle lists. */
203 		struct mutex lock;
204 	} queues;
205 
206 	/**
207 	 * @watchdog: Watchdog for communications with firmware.
208 	 */
209 	struct {
210 		/** @work: Work item for watchdog callback. */
211 		struct delayed_work work;
212 
213 		/**
214 		 * @old_kccb_cmds_executed: KCCB command execution count at last
215 		 * watchdog poll.
216 		 */
217 		u32 old_kccb_cmds_executed;
218 
219 		/**
220 		 * @kccb_stall_count: Number of watchdog polls KCCB has been
221 		 * stalled for.
222 		 */
223 		u32 kccb_stall_count;
224 	} watchdog;
225 
226 	/**
227 	 * @kccb: Circular buffer for communications with firmware.
228 	 */
229 	struct {
230 		/** @ccb: Kernel CCB. */
231 		struct pvr_ccb ccb;
232 
233 		/** @rtn_q: Waitqueue for KCCB command return waiters. */
234 		wait_queue_head_t rtn_q;
235 
236 		/** @rtn_obj: Object representing KCCB return slots. */
237 		struct pvr_fw_object *rtn_obj;
238 
239 		/**
240 		 * @rtn: Pointer to CPU mapping of KCCB return slots. Must be
241 		 * accessed by READ_ONCE()/WRITE_ONCE().
242 		 */
243 		u32 *rtn;
244 
245 		/** @slot_count: Total number of KCCB slots available. */
246 		u32 slot_count;
247 
248 		/** @reserved_count: Number of KCCB slots reserved for future use. */
249 		u32 reserved_count;
250 
251 		/**
252 		 * @waiters: List of KCCB slot waiters.
253 		 */
254 		struct list_head waiters;
255 
256 		/** @fence_ctx: KCCB fence context. */
257 		struct {
258 			/** @id: KCCB fence context ID allocated with dma_fence_context_alloc(). */
259 			u64 id;
260 
261 			/** @seqno: Sequence number incremented each time a fence is created. */
262 			atomic_t seqno;
263 
264 			/**
265 			 * @lock: Lock used to synchronize access to fences allocated by this
266 			 * context.
267 			 */
268 			spinlock_t lock;
269 		} fence_ctx;
270 	} kccb;
271 
272 	/**
273 	 * @lost: %true if the device has been lost.
274 	 *
275 	 * This variable is set if the device has become irretrievably unavailable, e.g. if the
276 	 * firmware processor has stopped responding and can not be revived via a hard reset.
277 	 */
278 	bool lost;
279 
280 	/**
281 	 * @reset_sem: Reset semaphore.
282 	 *
283 	 * GPU reset code will lock this for writing. Any code that submits commands to the firmware
284 	 * that isn't in an IRQ handler or on the scheduler workqueue must lock this for reading.
285 	 * Once this has been successfully locked, &pvr_dev->lost _must_ be checked, and -%EIO must
286 	 * be returned if it is set.
287 	 */
288 	struct rw_semaphore reset_sem;
289 
290 	/** @sched_wq: Workqueue for schedulers. */
291 	struct workqueue_struct *sched_wq;
292 };
293 
294 /**
295  * struct pvr_file - powervr-specific data to be assigned to &struct
296  * drm_file.driver_priv
297  */
298 struct pvr_file {
299 	/**
300 	 * @file: A reference to the parent &struct drm_file.
301 	 *
302 	 * Do not access this member directly, instead call from_pvr_file().
303 	 */
304 	struct drm_file *file;
305 
306 	/**
307 	 * @pvr_dev: A reference to the powervr-specific wrapper for the
308 	 * associated device. Saves on repeated calls to to_pvr_device().
309 	 */
310 	struct pvr_device *pvr_dev;
311 
312 	/**
313 	 * @ctx_handles: Array of contexts belonging to this file. Array members
314 	 * are of type "struct pvr_context *".
315 	 *
316 	 * This array is used to allocate handles returned to userspace.
317 	 */
318 	struct xarray ctx_handles;
319 
320 	/**
321 	 * @free_list_handles: Array of free lists belonging to this file. Array
322 	 * members are of type "struct pvr_free_list *".
323 	 *
324 	 * This array is used to allocate handles returned to userspace.
325 	 */
326 	struct xarray free_list_handles;
327 
328 	/**
329 	 * @hwrt_handles: Array of HWRT datasets belonging to this file. Array
330 	 * members are of type "struct pvr_hwrt_dataset *".
331 	 *
332 	 * This array is used to allocate handles returned to userspace.
333 	 */
334 	struct xarray hwrt_handles;
335 
336 	/**
337 	 * @vm_ctx_handles: Array of VM contexts belonging to this file. Array
338 	 * members are of type "struct pvr_vm_context *".
339 	 *
340 	 * This array is used to allocate handles returned to userspace.
341 	 */
342 	struct xarray vm_ctx_handles;
343 };
344 
345 /**
346  * PVR_HAS_FEATURE() - Tests whether a PowerVR device has a given feature
347  * @pvr_dev: [IN] Target PowerVR device.
348  * @feature: [IN] Hardware feature name.
349  *
350  * Feature names are derived from those found in &struct pvr_device_features by
351  * dropping the 'has_' prefix, which is applied by this macro.
352  *
353  * Return:
354  *  * true if the named feature is present in the hardware
355  *  * false if the named feature is not present in the hardware
356  */
357 #define PVR_HAS_FEATURE(pvr_dev, feature) ((pvr_dev)->features.has_##feature)
358 
359 /**
360  * PVR_FEATURE_VALUE() - Gets a PowerVR device feature value
361  * @pvr_dev: [IN] Target PowerVR device.
362  * @feature: [IN] Feature name.
363  * @value_out: [OUT] Feature value.
364  *
365  * This macro will get a feature value for those features that have values.
366  * If the feature is not present, nothing will be stored to @value_out.
367  *
368  * Feature names are derived from those found in &struct pvr_device_features by
369  * dropping the 'has_' prefix.
370  *
371  * Return:
372  *  * 0 on success, or
373  *  * -%EINVAL if the named feature is not present in the hardware
374  */
375 #define PVR_FEATURE_VALUE(pvr_dev, feature, value_out)             \
376 	({                                                         \
377 		struct pvr_device *_pvr_dev = pvr_dev;             \
378 		int _ret = -EINVAL;                                \
379 		if (_pvr_dev->features.has_##feature) {            \
380 			*(value_out) = _pvr_dev->features.feature; \
381 			_ret = 0;                                  \
382 		}                                                  \
383 		_ret;                                              \
384 	})
385 
386 /**
387  * PVR_HAS_QUIRK() - Tests whether a physical device has a given quirk
388  * @pvr_dev: [IN] Target PowerVR device.
389  * @quirk: [IN] Hardware quirk name.
390  *
391  * Quirk numbers are derived from those found in #pvr_device_quirks by
392  * dropping the 'has_brn' prefix, which is applied by this macro.
393  *
394  * Returns
395  *  * true if the quirk is present in the hardware, or
396  *  * false if the quirk is not present in the hardware.
397  */
398 #define PVR_HAS_QUIRK(pvr_dev, quirk) ((pvr_dev)->quirks.has_brn##quirk)
399 
400 /**
401  * PVR_HAS_ENHANCEMENT() - Tests whether a physical device has a given
402  *                         enhancement
403  * @pvr_dev: [IN] Target PowerVR device.
404  * @enhancement: [IN] Hardware enhancement name.
405  *
406  * Enhancement numbers are derived from those found in #pvr_device_enhancements
407  * by dropping the 'has_ern' prefix, which is applied by this macro.
408  *
409  * Returns
410  *  * true if the enhancement is present in the hardware, or
411  *  * false if the enhancement is not present in the hardware.
412  */
413 #define PVR_HAS_ENHANCEMENT(pvr_dev, enhancement) ((pvr_dev)->enhancements.has_ern##enhancement)
414 
415 #define from_pvr_device(pvr_dev) (&(pvr_dev)->base)
416 
417 #define to_pvr_device(drm_dev) container_of_const(drm_dev, struct pvr_device, base)
418 
419 #define from_pvr_file(pvr_file) ((pvr_file)->file)
420 
421 #define to_pvr_file(file) ((file)->driver_priv)
422 
423 /**
424  * PVR_PACKED_BVNC() - Packs B, V, N and C values into a 64-bit unsigned integer
425  * @b: Branch ID.
426  * @v: Version ID.
427  * @n: Number of scalable units.
428  * @c: Config ID.
429  *
430  * The packed layout is as follows:
431  *
432  *    +--------+--------+--------+-------+
433  *    | 63..48 | 47..32 | 31..16 | 15..0 |
434  *    +========+========+========+=======+
435  *    | B      | V      | N      | C     |
436  *    +--------+--------+--------+-------+
437  *
438  * pvr_gpu_id_to_packed_bvnc() should be used instead of this macro when a
439  * &struct pvr_gpu_id is available in order to ensure proper type checking.
440  *
441  * Return: Packed BVNC.
442  */
443 /* clang-format off */
444 #define PVR_PACKED_BVNC(b, v, n, c) \
445 	((((u64)(b) & GENMASK_ULL(15, 0)) << 48) | \
446 	 (((u64)(v) & GENMASK_ULL(15, 0)) << 32) | \
447 	 (((u64)(n) & GENMASK_ULL(15, 0)) << 16) | \
448 	 (((u64)(c) & GENMASK_ULL(15, 0)) <<  0))
449 /* clang-format on */
450 
451 /**
452  * pvr_gpu_id_to_packed_bvnc() - Packs B, V, N and C values into a 64-bit
453  * unsigned integer
454  * @gpu_id: GPU ID.
455  *
456  * The packed layout is as follows:
457  *
458  *    +--------+--------+--------+-------+
459  *    | 63..48 | 47..32 | 31..16 | 15..0 |
460  *    +========+========+========+=======+
461  *    | B      | V      | N      | C     |
462  *    +--------+--------+--------+-------+
463  *
464  * This should be used in preference to PVR_PACKED_BVNC() when a &struct
465  * pvr_gpu_id is available in order to ensure proper type checking.
466  *
467  * Return: Packed BVNC.
468  */
469 static __always_inline u64
470 pvr_gpu_id_to_packed_bvnc(struct pvr_gpu_id *gpu_id)
471 {
472 	return PVR_PACKED_BVNC(gpu_id->b, gpu_id->v, gpu_id->n, gpu_id->c);
473 }
474 
475 static __always_inline void
476 packed_bvnc_to_pvr_gpu_id(u64 bvnc, struct pvr_gpu_id *gpu_id)
477 {
478 	gpu_id->b = (bvnc & GENMASK_ULL(63, 48)) >> 48;
479 	gpu_id->v = (bvnc & GENMASK_ULL(47, 32)) >> 32;
480 	gpu_id->n = (bvnc & GENMASK_ULL(31, 16)) >> 16;
481 	gpu_id->c = bvnc & GENMASK_ULL(15, 0);
482 }
483 
484 int pvr_device_init(struct pvr_device *pvr_dev);
485 void pvr_device_fini(struct pvr_device *pvr_dev);
486 void pvr_device_reset(struct pvr_device *pvr_dev);
487 
488 bool
489 pvr_device_has_uapi_quirk(struct pvr_device *pvr_dev, u32 quirk);
490 bool
491 pvr_device_has_uapi_enhancement(struct pvr_device *pvr_dev, u32 enhancement);
492 bool
493 pvr_device_has_feature(struct pvr_device *pvr_dev, u32 feature);
494 
495 /**
496  * PVR_CR_FIELD_GET() - Extract a single field from a PowerVR control register
497  * @val: Value of the target register.
498  * @field: Field specifier, as defined in "pvr_rogue_cr_defs.h".
499  *
500  * Return: The extracted field.
501  */
502 #define PVR_CR_FIELD_GET(val, field) FIELD_GET(~ROGUE_CR_##field##_CLRMSK, val)
503 
504 /**
505  * pvr_cr_read32() - Read a 32-bit register from a PowerVR device
506  * @pvr_dev: Target PowerVR device.
507  * @reg: Target register.
508  *
509  * Return: The value of the requested register.
510  */
511 static __always_inline u32
512 pvr_cr_read32(struct pvr_device *pvr_dev, u32 reg)
513 {
514 	return ioread32(pvr_dev->regs + reg);
515 }
516 
517 /**
518  * pvr_cr_read64() - Read a 64-bit register from a PowerVR device
519  * @pvr_dev: Target PowerVR device.
520  * @reg: Target register.
521  *
522  * Return: The value of the requested register.
523  */
524 static __always_inline u64
525 pvr_cr_read64(struct pvr_device *pvr_dev, u32 reg)
526 {
527 	return ioread64(pvr_dev->regs + reg);
528 }
529 
530 /**
531  * pvr_cr_write32() - Write to a 32-bit register in a PowerVR device
532  * @pvr_dev: Target PowerVR device.
533  * @reg: Target register.
534  * @val: Value to write.
535  */
536 static __always_inline void
537 pvr_cr_write32(struct pvr_device *pvr_dev, u32 reg, u32 val)
538 {
539 	iowrite32(val, pvr_dev->regs + reg);
540 }
541 
542 /**
543  * pvr_cr_write64() - Write to a 64-bit register in a PowerVR device
544  * @pvr_dev: Target PowerVR device.
545  * @reg: Target register.
546  * @val: Value to write.
547  */
548 static __always_inline void
549 pvr_cr_write64(struct pvr_device *pvr_dev, u32 reg, u64 val)
550 {
551 	iowrite64(val, pvr_dev->regs + reg);
552 }
553 
554 /**
555  * pvr_cr_poll_reg32() - Wait for a 32-bit register to match a given value by
556  *                       polling
557  * @pvr_dev: Target PowerVR device.
558  * @reg_addr: Address of register.
559  * @reg_value: Expected register value (after masking).
560  * @reg_mask: Mask of bits valid for comparison with @reg_value.
561  * @timeout_usec: Timeout length, in us.
562  *
563  * Returns:
564  *  * 0 on success, or
565  *  * -%ETIMEDOUT on timeout.
566  */
567 static __always_inline int
568 pvr_cr_poll_reg32(struct pvr_device *pvr_dev, u32 reg_addr, u32 reg_value,
569 		  u32 reg_mask, u64 timeout_usec)
570 {
571 	u32 value;
572 
573 	return readl_poll_timeout(pvr_dev->regs + reg_addr, value,
574 		(value & reg_mask) == reg_value, 0, timeout_usec);
575 }
576 
577 /**
578  * pvr_cr_poll_reg64() - Wait for a 64-bit register to match a given value by
579  *                       polling
580  * @pvr_dev: Target PowerVR device.
581  * @reg_addr: Address of register.
582  * @reg_value: Expected register value (after masking).
583  * @reg_mask: Mask of bits valid for comparison with @reg_value.
584  * @timeout_usec: Timeout length, in us.
585  *
586  * Returns:
587  *  * 0 on success, or
588  *  * -%ETIMEDOUT on timeout.
589  */
590 static __always_inline int
591 pvr_cr_poll_reg64(struct pvr_device *pvr_dev, u32 reg_addr, u64 reg_value,
592 		  u64 reg_mask, u64 timeout_usec)
593 {
594 	u64 value;
595 
596 	return readq_poll_timeout(pvr_dev->regs + reg_addr, value,
597 		(value & reg_mask) == reg_value, 0, timeout_usec);
598 }
599 
600 /**
601  * pvr_round_up_to_cacheline_size() - Round up a provided size to be cacheline
602  *                                    aligned
603  * @pvr_dev: Target PowerVR device.
604  * @size: Initial size, in bytes.
605  *
606  * Returns:
607  *  * Size aligned to cacheline size.
608  */
609 static __always_inline size_t
610 pvr_round_up_to_cacheline_size(struct pvr_device *pvr_dev, size_t size)
611 {
612 	u16 slc_cacheline_size_bits = 0;
613 	u16 slc_cacheline_size_bytes;
614 
615 	WARN_ON(!PVR_HAS_FEATURE(pvr_dev, slc_cache_line_size_bits));
616 	PVR_FEATURE_VALUE(pvr_dev, slc_cache_line_size_bits,
617 			  &slc_cacheline_size_bits);
618 	slc_cacheline_size_bytes = slc_cacheline_size_bits / 8;
619 
620 	return round_up(size, slc_cacheline_size_bytes);
621 }
622 
623 /**
624  * DOC: IOCTL validation helpers
625  *
626  * To validate the constraints imposed on IOCTL argument structs, a collection
627  * of macros and helper functions exist in ``pvr_device.h``.
628  *
629  * Of the current helpers, it should only be necessary to call
630  * PVR_IOCTL_UNION_PADDING_CHECK() directly. This macro should be used once in
631  * every code path which extracts a union member from a struct passed from
632  * userspace.
633  */
634 
635 /**
636  * pvr_ioctl_union_padding_check() - Validate that the implicit padding between
637  * the end of a union member and the end of the union itself is zeroed.
638  * @instance: Pointer to the instance of the struct to validate.
639  * @union_offset: Offset into the type of @instance of the target union. Must
640  * be 64-bit aligned.
641  * @union_size: Size of the target union in the type of @instance. Must be
642  * 64-bit aligned.
643  * @member_size: Size of the target member in the target union specified by
644  * @union_offset and @union_size. It is assumed that the offset of the target
645  * member is zero relative to @union_offset. Must be 64-bit aligned.
646  *
647  * You probably want to use PVR_IOCTL_UNION_PADDING_CHECK() instead of calling
648  * this function directly, since that macro abstracts away much of the setup,
649  * and also provides some static validation. See its docs for details.
650  *
651  * Return:
652  *  * %true if every byte between the end of the used member of the union and
653  *    the end of that union is zeroed, or
654  *  * %false otherwise.
655  */
656 static __always_inline bool
657 pvr_ioctl_union_padding_check(void *instance, size_t union_offset,
658 			      size_t union_size, size_t member_size)
659 {
660 	/*
661 	 * void pointer arithmetic is technically illegal - cast to a byte
662 	 * pointer so this addition works safely.
663 	 */
664 	void *padding_start = ((u8 *)instance) + union_offset + member_size;
665 	size_t padding_size = union_size - member_size;
666 
667 	return !memchr_inv(padding_start, 0, padding_size);
668 }
669 
670 /**
671  * PVR_STATIC_ASSERT_64BIT_ALIGNED() - Inline assertion for 64-bit alignment.
672  * @static_expr_: Target expression to evaluate.
673  *
674  * If @static_expr_ does not evaluate to a constant integer which would be a
675  * 64-bit aligned address (i.e. a multiple of 8), compilation will fail.
676  *
677  * Return:
678  * The value of @static_expr_.
679  */
680 #define PVR_STATIC_ASSERT_64BIT_ALIGNED(static_expr_)                     \
681 	({                                                                \
682 		static_assert(((static_expr_) & (sizeof(u64) - 1)) == 0); \
683 		(static_expr_);                                           \
684 	})
685 
686 /**
687  * PVR_IOCTL_UNION_PADDING_CHECK() - Validate that the implicit padding between
688  * the end of a union member and the end of the union itself is zeroed.
689  * @struct_instance_: An expression which evaluates to a pointer to a UAPI data
690  * struct.
691  * @union_: The name of the union member of @struct_instance_ to check. If the
692  * union member is nested within the type of @struct_instance_, this may
693  * contain the member access operator (".").
694  * @member_: The name of the member of @union_ to assess.
695  *
696  * This is a wrapper around pvr_ioctl_union_padding_check() which performs
697  * alignment checks and simplifies things for the caller.
698  *
699  * Return:
700  *  * %true if every byte in @struct_instance_ between the end of @member_ and
701  *    the end of @union_ is zeroed, or
702  *  * %false otherwise.
703  */
704 #define PVR_IOCTL_UNION_PADDING_CHECK(struct_instance_, union_, member_)     \
705 	({                                                                   \
706 		typeof(struct_instance_) __instance = (struct_instance_);    \
707 		size_t __union_offset = PVR_STATIC_ASSERT_64BIT_ALIGNED(     \
708 			offsetof(typeof(*__instance), union_));              \
709 		size_t __union_size = PVR_STATIC_ASSERT_64BIT_ALIGNED(       \
710 			sizeof(__instance->union_));                         \
711 		size_t __member_size = PVR_STATIC_ASSERT_64BIT_ALIGNED(      \
712 			sizeof(__instance->union_.member_));                 \
713 		pvr_ioctl_union_padding_check(__instance, __union_offset,    \
714 					      __union_size, __member_size);  \
715 	})
716 
717 #define PVR_FW_PROCESSOR_TYPE_META  0
718 #define PVR_FW_PROCESSOR_TYPE_MIPS  1
719 #define PVR_FW_PROCESSOR_TYPE_RISCV 2
720 
721 #endif /* PVR_DEVICE_H */
722