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