12fc7b156SRob Clark // SPDX-License-Identifier: GPL-2.0-only
22fc7b156SRob Clark /*
32fc7b156SRob Clark  * Copyright (C) 2020 Google, Inc
42fc7b156SRob Clark  */
52fc7b156SRob Clark 
62fc7b156SRob Clark #ifndef __ADRENO_SMMU_PRIV_H
72fc7b156SRob Clark #define __ADRENO_SMMU_PRIV_H
82fc7b156SRob Clark 
92fc7b156SRob Clark #include <linux/io-pgtable.h>
102fc7b156SRob Clark 
112fc7b156SRob Clark /**
12ab5df7b9SJordan Crouse  * struct adreno_smmu_fault_info - container for key fault information
13ab5df7b9SJordan Crouse  *
14ab5df7b9SJordan Crouse  * @far: The faulting IOVA from ARM_SMMU_CB_FAR
15ab5df7b9SJordan Crouse  * @ttbr0: The current TTBR0 pagetable from ARM_SMMU_CB_TTBR0
16ab5df7b9SJordan Crouse  * @contextidr: The value of ARM_SMMU_CB_CONTEXTIDR
17ab5df7b9SJordan Crouse  * @fsr: The fault status from ARM_SMMU_CB_FSR
18ab5df7b9SJordan Crouse  * @fsynr0: The value of FSYNR0 from ARM_SMMU_CB_FSYNR0
19ab5df7b9SJordan Crouse  * @fsynr1: The value of FSYNR1 from ARM_SMMU_CB_FSYNR0
20ab5df7b9SJordan Crouse  * @cbfrsynra: The value of CBFRSYNRA from ARM_SMMU_GR1_CBFRSYNRA(idx)
21ab5df7b9SJordan Crouse  *
22ab5df7b9SJordan Crouse  * This struct passes back key page fault information to the GPU driver
23ab5df7b9SJordan Crouse  * through the get_fault_info function pointer.
24ab5df7b9SJordan Crouse  * The GPU driver can use this information to print informative
25ab5df7b9SJordan Crouse  * log messages and provide deeper GPU specific insight into the fault.
26ab5df7b9SJordan Crouse  */
27ab5df7b9SJordan Crouse struct adreno_smmu_fault_info {
28ab5df7b9SJordan Crouse 	u64 far;
29ab5df7b9SJordan Crouse 	u64 ttbr0;
30ab5df7b9SJordan Crouse 	u32 contextidr;
31ab5df7b9SJordan Crouse 	u32 fsr;
32ab5df7b9SJordan Crouse 	u32 fsynr0;
33ab5df7b9SJordan Crouse 	u32 fsynr1;
34ab5df7b9SJordan Crouse 	u32 cbfrsynra;
35ab5df7b9SJordan Crouse };
36ab5df7b9SJordan Crouse 
37ab5df7b9SJordan Crouse /**
382fc7b156SRob Clark  * struct adreno_smmu_priv - private interface between adreno-smmu and GPU
392fc7b156SRob Clark  *
402fc7b156SRob Clark  * @cookie:        An opque token provided by adreno-smmu and passed
412fc7b156SRob Clark  *                 back into the callbacks
422fc7b156SRob Clark  * @get_ttbr1_cfg: Get the TTBR1 config for the GPUs context-bank
432fc7b156SRob Clark  * @set_ttbr0_cfg: Set the TTBR0 config for the GPUs context bank.  A
442fc7b156SRob Clark  *                 NULL config disables TTBR0 translation, otherwise
452fc7b156SRob Clark  *                 TTBR0 translation is enabled with the specified cfg
46ab5df7b9SJordan Crouse  * @get_fault_info: Called by the GPU fault handler to get information about
47ab5df7b9SJordan Crouse  *                  the fault
48*ba6014a4SRob Clark  * @set_stall:     Configure whether stall on fault (CFCFG) is enabled.  Call
49*ba6014a4SRob Clark  *                 before set_ttbr0_cfg().  If stalling on fault is enabled,
50*ba6014a4SRob Clark  *                 the GPU driver must call resume_translation()
51*ba6014a4SRob Clark  * @resume_translation: Resume translation after a fault
52*ba6014a4SRob Clark  *
532fc7b156SRob Clark  *
542fc7b156SRob Clark  * The GPU driver (drm/msm) and adreno-smmu work together for controlling
552fc7b156SRob Clark  * the GPU's SMMU instance.  This is by necessity, as the GPU is directly
562fc7b156SRob Clark  * updating the SMMU for context switches, while on the other hand we do
572fc7b156SRob Clark  * not want to duplicate all of the initial setup logic from arm-smmu.
582fc7b156SRob Clark  *
592fc7b156SRob Clark  * This private interface is used for the two drivers to coordinate.  The
602fc7b156SRob Clark  * cookie and callback functions are populated when the GPU driver attaches
612fc7b156SRob Clark  * it's domain.
622fc7b156SRob Clark  */
632fc7b156SRob Clark struct adreno_smmu_priv {
642fc7b156SRob Clark     const void *cookie;
652fc7b156SRob Clark     const struct io_pgtable_cfg *(*get_ttbr1_cfg)(const void *cookie);
662fc7b156SRob Clark     int (*set_ttbr0_cfg)(const void *cookie, const struct io_pgtable_cfg *cfg);
67ab5df7b9SJordan Crouse     void (*get_fault_info)(const void *cookie, struct adreno_smmu_fault_info *info);
68*ba6014a4SRob Clark     void (*set_stall)(const void *cookie, bool enabled);
69*ba6014a4SRob Clark     void (*resume_translation)(const void *cookie, bool terminate);
702fc7b156SRob Clark };
712fc7b156SRob Clark 
722fc7b156SRob Clark #endif /* __ADRENO_SMMU_PRIV_H */
73