drm/virtio: Fix return value for VIRTGPU_CONTEXT_PARAM_DEBUG_NAME
[linux-2.6-block.git] / drivers / accel / ivpu / ivpu_hw.h
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2020-2023 Intel Corporation
4  */
5
6 #ifndef __IVPU_HW_H__
7 #define __IVPU_HW_H__
8
9 #include "ivpu_drv.h"
10
11 struct ivpu_hw_ops {
12         int (*info_init)(struct ivpu_device *vdev);
13         int (*power_up)(struct ivpu_device *vdev);
14         int (*boot_fw)(struct ivpu_device *vdev);
15         int (*power_down)(struct ivpu_device *vdev);
16         bool (*is_idle)(struct ivpu_device *vdev);
17         int (*wait_for_idle)(struct ivpu_device *vdev);
18         void (*wdt_disable)(struct ivpu_device *vdev);
19         void (*diagnose_failure)(struct ivpu_device *vdev);
20         u32 (*profiling_freq_get)(struct ivpu_device *vdev);
21         void (*profiling_freq_drive)(struct ivpu_device *vdev, bool enable);
22         u32 (*reg_pll_freq_get)(struct ivpu_device *vdev);
23         u32 (*reg_telemetry_offset_get)(struct ivpu_device *vdev);
24         u32 (*reg_telemetry_size_get)(struct ivpu_device *vdev);
25         u32 (*reg_telemetry_enable_get)(struct ivpu_device *vdev);
26         void (*reg_db_set)(struct ivpu_device *vdev, u32 db_id);
27         u32 (*reg_ipc_rx_addr_get)(struct ivpu_device *vdev);
28         u32 (*reg_ipc_rx_count_get)(struct ivpu_device *vdev);
29         void (*reg_ipc_tx_set)(struct ivpu_device *vdev, u32 vpu_addr);
30         void (*irq_clear)(struct ivpu_device *vdev);
31         void (*irq_enable)(struct ivpu_device *vdev);
32         void (*irq_disable)(struct ivpu_device *vdev);
33         irqreturn_t (*irq_handler)(int irq, void *ptr);
34 };
35
36 struct ivpu_addr_range {
37         resource_size_t start;
38         resource_size_t end;
39 };
40
41 struct ivpu_hw_info {
42         const struct ivpu_hw_ops *ops;
43         struct {
44                 struct ivpu_addr_range global;
45                 struct ivpu_addr_range user;
46                 struct ivpu_addr_range shave;
47                 struct ivpu_addr_range dma;
48         } ranges;
49         struct {
50                 u8 min_ratio;
51                 u8 max_ratio;
52                 /*
53                  * Pll ratio for the efficiency frequency. The VPU has optimum
54                  * performance to power ratio at this frequency.
55                  */
56                 u8 pn_ratio;
57                 u32 profiling_freq;
58         } pll;
59         u32 tile_fuse;
60         u32 sku;
61         u16 config;
62         int dma_bits;
63         ktime_t d0i3_entry_host_ts;
64         u64 d0i3_entry_vpu_ts;
65 };
66
67 extern const struct ivpu_hw_ops ivpu_hw_37xx_ops;
68 extern const struct ivpu_hw_ops ivpu_hw_40xx_ops;
69
70 static inline int ivpu_hw_info_init(struct ivpu_device *vdev)
71 {
72         return vdev->hw->ops->info_init(vdev);
73 };
74
75 static inline int ivpu_hw_power_up(struct ivpu_device *vdev)
76 {
77         ivpu_dbg(vdev, PM, "HW power up\n");
78
79         return vdev->hw->ops->power_up(vdev);
80 };
81
82 static inline int ivpu_hw_boot_fw(struct ivpu_device *vdev)
83 {
84         return vdev->hw->ops->boot_fw(vdev);
85 };
86
87 static inline bool ivpu_hw_is_idle(struct ivpu_device *vdev)
88 {
89         return vdev->hw->ops->is_idle(vdev);
90 };
91
92 static inline int ivpu_hw_wait_for_idle(struct ivpu_device *vdev)
93 {
94         return vdev->hw->ops->wait_for_idle(vdev);
95 };
96
97 static inline int ivpu_hw_power_down(struct ivpu_device *vdev)
98 {
99         ivpu_dbg(vdev, PM, "HW power down\n");
100
101         return vdev->hw->ops->power_down(vdev);
102 };
103
104 static inline void ivpu_hw_wdt_disable(struct ivpu_device *vdev)
105 {
106         vdev->hw->ops->wdt_disable(vdev);
107 };
108
109 static inline u32 ivpu_hw_profiling_freq_get(struct ivpu_device *vdev)
110 {
111         return vdev->hw->ops->profiling_freq_get(vdev);
112 };
113
114 static inline void ivpu_hw_profiling_freq_drive(struct ivpu_device *vdev, bool enable)
115 {
116         return vdev->hw->ops->profiling_freq_drive(vdev, enable);
117 };
118
119 /* Register indirect accesses */
120 static inline u32 ivpu_hw_reg_pll_freq_get(struct ivpu_device *vdev)
121 {
122         return vdev->hw->ops->reg_pll_freq_get(vdev);
123 };
124
125 static inline u32 ivpu_hw_reg_telemetry_offset_get(struct ivpu_device *vdev)
126 {
127         return vdev->hw->ops->reg_telemetry_offset_get(vdev);
128 };
129
130 static inline u32 ivpu_hw_reg_telemetry_size_get(struct ivpu_device *vdev)
131 {
132         return vdev->hw->ops->reg_telemetry_size_get(vdev);
133 };
134
135 static inline u32 ivpu_hw_reg_telemetry_enable_get(struct ivpu_device *vdev)
136 {
137         return vdev->hw->ops->reg_telemetry_enable_get(vdev);
138 };
139
140 static inline void ivpu_hw_reg_db_set(struct ivpu_device *vdev, u32 db_id)
141 {
142         vdev->hw->ops->reg_db_set(vdev, db_id);
143 };
144
145 static inline u32 ivpu_hw_reg_ipc_rx_addr_get(struct ivpu_device *vdev)
146 {
147         return vdev->hw->ops->reg_ipc_rx_addr_get(vdev);
148 };
149
150 static inline u32 ivpu_hw_reg_ipc_rx_count_get(struct ivpu_device *vdev)
151 {
152         return vdev->hw->ops->reg_ipc_rx_count_get(vdev);
153 };
154
155 static inline void ivpu_hw_reg_ipc_tx_set(struct ivpu_device *vdev, u32 vpu_addr)
156 {
157         vdev->hw->ops->reg_ipc_tx_set(vdev, vpu_addr);
158 };
159
160 static inline void ivpu_hw_irq_clear(struct ivpu_device *vdev)
161 {
162         vdev->hw->ops->irq_clear(vdev);
163 };
164
165 static inline void ivpu_hw_irq_enable(struct ivpu_device *vdev)
166 {
167         vdev->hw->ops->irq_enable(vdev);
168 };
169
170 static inline void ivpu_hw_irq_disable(struct ivpu_device *vdev)
171 {
172         vdev->hw->ops->irq_disable(vdev);
173 };
174
175 static inline void ivpu_hw_init_range(struct ivpu_addr_range *range, u64 start, u64 size)
176 {
177         range->start = start;
178         range->end = start + size;
179 }
180
181 static inline u64 ivpu_hw_range_size(const struct ivpu_addr_range *range)
182 {
183         return range->end - range->start;
184 }
185
186 static inline void ivpu_hw_diagnose_failure(struct ivpu_device *vdev)
187 {
188         vdev->hw->ops->diagnose_failure(vdev);
189 }
190
191 #endif /* __IVPU_HW_H__ */