xref: /linux/drivers/accel/ivpu/ivpu_hw.h (revision 75079df919efcc30eb5bf0427c83fb578f4fe4fc)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2020 - 2024 Intel Corporation
4  */
5 
6 #ifndef __IVPU_HW_H__
7 #define __IVPU_HW_H__
8 
9 #include <linux/kfifo.h>
10 
11 #include "ivpu_drv.h"
12 #include "ivpu_hw_btrs.h"
13 #include "ivpu_hw_ip.h"
14 
15 #define IVPU_HW_IRQ_FIFO_LENGTH 1024
16 
17 #define IVPU_HW_IRQ_SRC_IPC 1
18 
19 struct ivpu_addr_range {
20 	resource_size_t start;
21 	resource_size_t end;
22 };
23 
24 struct ivpu_hw_info {
25 	struct {
26 		bool (*btrs_irq_handler)(struct ivpu_device *vdev, int irq);
27 		bool (*ip_irq_handler)(struct ivpu_device *vdev, int irq);
28 		DECLARE_KFIFO(fifo, u8, IVPU_HW_IRQ_FIFO_LENGTH);
29 	} irq;
30 	struct {
31 		struct ivpu_addr_range global;
32 		struct ivpu_addr_range user;
33 		struct ivpu_addr_range shave;
34 		struct ivpu_addr_range dma;
35 	} ranges;
36 	struct {
37 		u8 min_ratio;
38 		u8 max_ratio;
39 		/*
40 		 * Pll ratio for the efficiency frequency. The VPU has optimum
41 		 * performance to power ratio at this frequency.
42 		 */
43 		u8 pn_ratio;
44 		u32 profiling_freq;
45 	} pll;
46 	u32 tile_fuse;
47 	u32 sched_mode;
48 	u32 sku;
49 	u16 config;
50 	int dma_bits;
51 	ktime_t d0i3_entry_host_ts;
52 	u64 d0i3_entry_vpu_ts;
53 };
54 
55 int ivpu_hw_init(struct ivpu_device *vdev);
56 int ivpu_hw_power_up(struct ivpu_device *vdev);
57 int ivpu_hw_power_down(struct ivpu_device *vdev);
58 int ivpu_hw_reset(struct ivpu_device *vdev);
59 int ivpu_hw_boot_fw(struct ivpu_device *vdev);
60 void ivpu_hw_profiling_freq_drive(struct ivpu_device *vdev, bool enable);
61 void ivpu_irq_handlers_init(struct ivpu_device *vdev);
62 void ivpu_hw_irq_enable(struct ivpu_device *vdev);
63 void ivpu_hw_irq_disable(struct ivpu_device *vdev);
64 irqreturn_t ivpu_hw_irq_handler(int irq, void *ptr);
65 
66 static inline u32 ivpu_hw_btrs_irq_handler(struct ivpu_device *vdev, int irq)
67 {
68 	return vdev->hw->irq.btrs_irq_handler(vdev, irq);
69 }
70 
71 static inline u32 ivpu_hw_ip_irq_handler(struct ivpu_device *vdev, int irq)
72 {
73 	return vdev->hw->irq.ip_irq_handler(vdev, irq);
74 }
75 
76 static inline void ivpu_hw_range_init(struct ivpu_addr_range *range, u64 start, u64 size)
77 {
78 	range->start = start;
79 	range->end = start + size;
80 }
81 
82 static inline u64 ivpu_hw_range_size(const struct ivpu_addr_range *range)
83 {
84 	return range->end - range->start;
85 }
86 
87 static inline u32 ivpu_hw_ratio_to_freq(struct ivpu_device *vdev, u32 ratio)
88 {
89 	return ivpu_hw_btrs_ratio_to_freq(vdev, ratio);
90 }
91 
92 static inline void ivpu_hw_irq_clear(struct ivpu_device *vdev)
93 {
94 	ivpu_hw_ip_irq_clear(vdev);
95 }
96 
97 static inline u32 ivpu_hw_pll_freq_get(struct ivpu_device *vdev)
98 {
99 	return ivpu_hw_btrs_pll_freq_get(vdev);
100 }
101 
102 static inline u32 ivpu_hw_profiling_freq_get(struct ivpu_device *vdev)
103 {
104 	return vdev->hw->pll.profiling_freq;
105 }
106 
107 static inline void ivpu_hw_diagnose_failure(struct ivpu_device *vdev)
108 {
109 	ivpu_hw_ip_diagnose_failure(vdev);
110 	ivpu_hw_btrs_diagnose_failure(vdev);
111 }
112 
113 static inline u32 ivpu_hw_telemetry_offset_get(struct ivpu_device *vdev)
114 {
115 	return ivpu_hw_btrs_telemetry_offset_get(vdev);
116 }
117 
118 static inline u32 ivpu_hw_telemetry_size_get(struct ivpu_device *vdev)
119 {
120 	return ivpu_hw_btrs_telemetry_size_get(vdev);
121 }
122 
123 static inline u32 ivpu_hw_telemetry_enable_get(struct ivpu_device *vdev)
124 {
125 	return ivpu_hw_btrs_telemetry_enable_get(vdev);
126 }
127 
128 static inline bool ivpu_hw_is_idle(struct ivpu_device *vdev)
129 {
130 	return ivpu_hw_btrs_is_idle(vdev);
131 }
132 
133 static inline int ivpu_hw_wait_for_idle(struct ivpu_device *vdev)
134 {
135 	return ivpu_hw_btrs_wait_for_idle(vdev);
136 }
137 
138 static inline void ivpu_hw_ipc_tx_set(struct ivpu_device *vdev, u32 vpu_addr)
139 {
140 	ivpu_hw_ip_ipc_tx_set(vdev, vpu_addr);
141 }
142 
143 static inline void ivpu_hw_db_set(struct ivpu_device *vdev, u32 db_id)
144 {
145 	ivpu_hw_ip_db_set(vdev, db_id);
146 }
147 
148 static inline u32 ivpu_hw_ipc_rx_addr_get(struct ivpu_device *vdev)
149 {
150 	return ivpu_hw_ip_ipc_rx_addr_get(vdev);
151 }
152 
153 static inline u32 ivpu_hw_ipc_rx_count_get(struct ivpu_device *vdev)
154 {
155 	return ivpu_hw_ip_ipc_rx_count_get(vdev);
156 }
157 
158 #endif /* __IVPU_HW_H__ */
159