xref: /linux/drivers/accel/ivpu/ivpu_hw.h (revision 561add0da6d3d07c9bccb0832fb6ed5619167d26)
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 	void (*wdt_disable)(struct ivpu_device *vdev);
18 	void (*diagnose_failure)(struct ivpu_device *vdev);
19 	u32 (*reg_pll_freq_get)(struct ivpu_device *vdev);
20 	u32 (*reg_telemetry_offset_get)(struct ivpu_device *vdev);
21 	u32 (*reg_telemetry_size_get)(struct ivpu_device *vdev);
22 	u32 (*reg_telemetry_enable_get)(struct ivpu_device *vdev);
23 	void (*reg_db_set)(struct ivpu_device *vdev, u32 db_id);
24 	u32 (*reg_ipc_rx_addr_get)(struct ivpu_device *vdev);
25 	u32 (*reg_ipc_rx_count_get)(struct ivpu_device *vdev);
26 	void (*reg_ipc_tx_set)(struct ivpu_device *vdev, u32 vpu_addr);
27 	void (*irq_clear)(struct ivpu_device *vdev);
28 	void (*irq_enable)(struct ivpu_device *vdev);
29 	void (*irq_disable)(struct ivpu_device *vdev);
30 	irqreturn_t (*irq_handler)(int irq, void *ptr);
31 };
32 
33 struct ivpu_addr_range {
34 	resource_size_t start;
35 	resource_size_t end;
36 };
37 
38 struct ivpu_hw_info {
39 	const struct ivpu_hw_ops *ops;
40 	struct {
41 		struct ivpu_addr_range global;
42 		struct ivpu_addr_range user;
43 		struct ivpu_addr_range shave;
44 		struct ivpu_addr_range dma;
45 	} ranges;
46 	struct {
47 		u8 min_ratio;
48 		u8 max_ratio;
49 		/*
50 		 * Pll ratio for the efficiency frequency. The VPU has optimum
51 		 * performance to power ratio at this frequency.
52 		 */
53 		u8 pn_ratio;
54 		u32 profiling_freq;
55 	} pll;
56 	u32 tile_fuse;
57 	u32 sku;
58 	u16 config;
59 	int dma_bits;
60 };
61 
62 extern const struct ivpu_hw_ops ivpu_hw_37xx_ops;
63 extern const struct ivpu_hw_ops ivpu_hw_40xx_ops;
64 
65 static inline int ivpu_hw_info_init(struct ivpu_device *vdev)
66 {
67 	return vdev->hw->ops->info_init(vdev);
68 };
69 
70 static inline int ivpu_hw_power_up(struct ivpu_device *vdev)
71 {
72 	ivpu_dbg(vdev, PM, "HW power up\n");
73 
74 	return vdev->hw->ops->power_up(vdev);
75 };
76 
77 static inline int ivpu_hw_boot_fw(struct ivpu_device *vdev)
78 {
79 	return vdev->hw->ops->boot_fw(vdev);
80 };
81 
82 static inline bool ivpu_hw_is_idle(struct ivpu_device *vdev)
83 {
84 	return vdev->hw->ops->is_idle(vdev);
85 };
86 
87 static inline int ivpu_hw_power_down(struct ivpu_device *vdev)
88 {
89 	ivpu_dbg(vdev, PM, "HW power down\n");
90 
91 	return vdev->hw->ops->power_down(vdev);
92 };
93 
94 static inline void ivpu_hw_wdt_disable(struct ivpu_device *vdev)
95 {
96 	vdev->hw->ops->wdt_disable(vdev);
97 };
98 
99 /* Register indirect accesses */
100 static inline u32 ivpu_hw_reg_pll_freq_get(struct ivpu_device *vdev)
101 {
102 	return vdev->hw->ops->reg_pll_freq_get(vdev);
103 };
104 
105 static inline u32 ivpu_hw_reg_telemetry_offset_get(struct ivpu_device *vdev)
106 {
107 	return vdev->hw->ops->reg_telemetry_offset_get(vdev);
108 };
109 
110 static inline u32 ivpu_hw_reg_telemetry_size_get(struct ivpu_device *vdev)
111 {
112 	return vdev->hw->ops->reg_telemetry_size_get(vdev);
113 };
114 
115 static inline u32 ivpu_hw_reg_telemetry_enable_get(struct ivpu_device *vdev)
116 {
117 	return vdev->hw->ops->reg_telemetry_enable_get(vdev);
118 };
119 
120 static inline void ivpu_hw_reg_db_set(struct ivpu_device *vdev, u32 db_id)
121 {
122 	vdev->hw->ops->reg_db_set(vdev, db_id);
123 };
124 
125 static inline u32 ivpu_hw_reg_ipc_rx_addr_get(struct ivpu_device *vdev)
126 {
127 	return vdev->hw->ops->reg_ipc_rx_addr_get(vdev);
128 };
129 
130 static inline u32 ivpu_hw_reg_ipc_rx_count_get(struct ivpu_device *vdev)
131 {
132 	return vdev->hw->ops->reg_ipc_rx_count_get(vdev);
133 };
134 
135 static inline void ivpu_hw_reg_ipc_tx_set(struct ivpu_device *vdev, u32 vpu_addr)
136 {
137 	vdev->hw->ops->reg_ipc_tx_set(vdev, vpu_addr);
138 };
139 
140 static inline void ivpu_hw_irq_clear(struct ivpu_device *vdev)
141 {
142 	vdev->hw->ops->irq_clear(vdev);
143 };
144 
145 static inline void ivpu_hw_irq_enable(struct ivpu_device *vdev)
146 {
147 	vdev->hw->ops->irq_enable(vdev);
148 };
149 
150 static inline void ivpu_hw_irq_disable(struct ivpu_device *vdev)
151 {
152 	vdev->hw->ops->irq_disable(vdev);
153 };
154 
155 static inline void ivpu_hw_init_range(struct ivpu_addr_range *range, u64 start, u64 size)
156 {
157 	range->start = start;
158 	range->end = start + size;
159 }
160 
161 static inline u64 ivpu_hw_range_size(const struct ivpu_addr_range *range)
162 {
163 	return range->end - range->start;
164 }
165 
166 static inline void ivpu_hw_diagnose_failure(struct ivpu_device *vdev)
167 {
168 	vdev->hw->ops->diagnose_failure(vdev);
169 }
170 
171 #endif /* __IVPU_HW_H__ */
172