1 /* SPDX-License-Identifier: GPL-2.0
3 * Copyright 2016-2018 HabanaLabs, Ltd.
11 #include <linux/types.h>
23 struct hl_eq_header hdr;
27 #define HL_EQ_ENTRY_SIZE sizeof(struct hl_eq_entry)
29 #define EQ_CTL_READY_SHIFT 31
30 #define EQ_CTL_READY_MASK 0x80000000
32 #define EQ_CTL_EVENT_TYPE_SHIFT 16
33 #define EQ_CTL_EVENT_TYPE_MASK 0x03FF0000
36 PQ_INIT_STATUS_NA = 0,
37 PQ_INIT_STATUS_READY_FOR_CP,
38 PQ_INIT_STATUS_READY_FOR_HOST
42 * ArmCP Primary Queue Packets
44 * During normal operation, KMD needs to send various messages to ArmCP,
45 * usually either to SET some value into a H/W periphery or to GET the current
46 * value of some H/W periphery. For example, SET the frequency of MME/TPC and
47 * GET the value of the thermal sensor.
49 * These messages can be initiated either by the User application or by KMD
50 * itself, e.g. power management code. In either case, the communication from
51 * KMD to ArmCP will *always* be in synchronous mode, meaning that KMD will
52 * send a single message and poll until the message was acknowledged and the
53 * results are ready (if results are needed).
55 * This means that only a single message can be sent at a time and KMD must
56 * wait for its result before sending the next message. Having said that,
57 * because these are control messages which are sent in a relatively low
58 * frequency, this limitation seems acceptable. It's important to note that
59 * in case of multiple devices, messages to different devices *can* be sent
62 * The message, inputs/outputs (if relevant) and fence object will be located
63 * on the device DDR at an address that will be determined by KMD. During
64 * device initialization phase, KMD will pass to ArmCP that address. Most of
65 * the message types will contain inputs/outputs inside the message itself.
66 * The common part of each message will contain the opcode of the message (its
67 * type) and a field representing a fence object.
69 * When KMD wishes to send a message to ArmCP, it will write the message
70 * contents to the device DDR, clear the fence object and then write the
71 * value 484 to the mmGIC_DISTRIBUTOR__5_GICD_SETSPI_NSR register to issue
72 * the 484 interrupt-id to the ARM core.
74 * Upon receiving the 484 interrupt-id, ArmCP will read the message from the
75 * DDR. In case the message is a SET operation, ArmCP will first perform the
76 * operation and then write to the fence object on the device DDR. In case the
77 * message is a GET operation, ArmCP will first fill the results section on the
78 * device DDR and then write to the fence object. If an error occurred, ArmCP
79 * will fill the rc field with the right error code.
81 * In the meantime, KMD will poll on the fence object. Once KMD sees that the
82 * fence object is signaled, it will read the results from the device DDR
83 * (if relevant) and resume the code execution in KMD.
85 * To use QMAN packets, the opcode must be the QMAN opcode, shifted by 8
86 * so the value being put by the KMD matches the value read by ArmCP
88 * Non-QMAN packets should be limited to values 1 through (2^8 - 1)
90 * Detailed description:
92 * ARMCP_PACKET_DISABLE_PCI_ACCESS -
93 * After receiving this packet the embedded CPU must NOT issue PCI
94 * transactions (read/write) towards the Host CPU. This also include
95 * sending MSI-X interrupts.
96 * This packet is usually sent before the device is moved to D3Hot state.
98 * ARMCP_PACKET_ENABLE_PCI_ACCESS -
99 * After receiving this packet the embedded CPU is allowed to issue PCI
100 * transactions towards the Host CPU, including sending MSI-X interrupts.
101 * This packet is usually send after the device is moved to D0 state.
103 * ARMCP_PACKET_TEMPERATURE_GET -
104 * Fetch the current temperature / Max / Max Hyst / Critical /
105 * Critical Hyst of a specified thermal sensor. The packet's
106 * arguments specify the desired sensor and the field to get.
108 * ARMCP_PACKET_VOLTAGE_GET -
109 * Fetch the voltage / Max / Min of a specified sensor. The packet's
110 * arguments specify the sensor and type.
112 * ARMCP_PACKET_CURRENT_GET -
113 * Fetch the current / Max / Min of a specified sensor. The packet's
114 * arguments specify the sensor and type.
116 * ARMCP_PACKET_FAN_SPEED_GET -
117 * Fetch the speed / Max / Min of a specified fan. The packet's
118 * arguments specify the sensor and type.
120 * ARMCP_PACKET_PWM_GET -
121 * Fetch the pwm value / mode of a specified pwm. The packet's
122 * arguments specify the sensor and type.
124 * ARMCP_PACKET_PWM_SET -
125 * Set the pwm value / mode of a specified pwm. The packet's
126 * arguments specify the sensor, type and value.
128 * ARMCP_PACKET_FREQUENCY_SET -
129 * Set the frequency of a specified PLL. The packet's arguments specify
130 * the PLL and the desired frequency. The actual frequency in the device
131 * might differ from the requested frequency.
133 * ARMCP_PACKET_FREQUENCY_GET -
134 * Fetch the frequency of a specified PLL. The packet's arguments specify
137 * ARMCP_PACKET_LED_SET -
138 * Set the state of a specified led. The packet's arguments
139 * specify the led and the desired state.
141 * ARMCP_PACKET_I2C_WR -
142 * Write 32-bit value to I2C device. The packet's arguments specify the
143 * I2C bus, address and value.
145 * ARMCP_PACKET_I2C_RD -
146 * Read 32-bit value from I2C device. The packet's arguments specify the
147 * I2C bus and address.
149 * ARMCP_PACKET_INFO_GET -
150 * Fetch information from the device as specified in the packet's
151 * structure. KMD passes the max size it allows the ArmCP to write to
152 * the structure, to prevent data corruption in case of mismatched
155 * ARMCP_PACKET_FLASH_PROGRAM_REMOVED - this packet was removed
157 * ARMCP_PACKET_UNMASK_RAZWI_IRQ -
158 * Unmask the given IRQ. The IRQ number is specified in the value field.
159 * The packet is sent after receiving an interrupt and printing its
160 * relevant information.
162 * ARMCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY -
163 * Unmask the given IRQs. The IRQs numbers are specified in an array right
164 * after the armcp_packet structure, where its first element is the array
165 * length. The packet is sent after a soft reset was done in order to
166 * handle any interrupts that were sent during the reset process.
168 * ARMCP_PACKET_TEST -
169 * Test packet for ArmCP connectivity. The CPU will put the fence value
170 * in the result field.
172 * ARMCP_PACKET_FREQUENCY_CURR_GET -
173 * Fetch the current frequency of a specified PLL. The packet's arguments
176 * ARMCP_PACKET_MAX_POWER_GET -
177 * Fetch the maximal power of the device.
179 * ARMCP_PACKET_MAX_POWER_SET -
180 * Set the maximal power of the device. The packet's arguments specify
183 * ARMCP_PACKET_EEPROM_DATA_GET -
184 * Get EEPROM data from the ArmCP kernel. The buffer is specified in the
185 * addr field. The CPU will put the returned data size in the result
186 * field. In addition, KMD passes the max size it allows the ArmCP to
187 * write to the structure, to prevent data corruption in case of
188 * mismatched KMD/FW versions.
192 enum armcp_packet_id {
193 ARMCP_PACKET_DISABLE_PCI_ACCESS = 1, /* internal */
194 ARMCP_PACKET_ENABLE_PCI_ACCESS, /* internal */
195 ARMCP_PACKET_TEMPERATURE_GET, /* sysfs */
196 ARMCP_PACKET_VOLTAGE_GET, /* sysfs */
197 ARMCP_PACKET_CURRENT_GET, /* sysfs */
198 ARMCP_PACKET_FAN_SPEED_GET, /* sysfs */
199 ARMCP_PACKET_PWM_GET, /* sysfs */
200 ARMCP_PACKET_PWM_SET, /* sysfs */
201 ARMCP_PACKET_FREQUENCY_SET, /* sysfs */
202 ARMCP_PACKET_FREQUENCY_GET, /* sysfs */
203 ARMCP_PACKET_LED_SET, /* debugfs */
204 ARMCP_PACKET_I2C_WR, /* debugfs */
205 ARMCP_PACKET_I2C_RD, /* debugfs */
206 ARMCP_PACKET_INFO_GET, /* IOCTL */
207 ARMCP_PACKET_FLASH_PROGRAM_REMOVED,
208 ARMCP_PACKET_UNMASK_RAZWI_IRQ, /* internal */
209 ARMCP_PACKET_UNMASK_RAZWI_IRQ_ARRAY, /* internal */
210 ARMCP_PACKET_TEST, /* internal */
211 ARMCP_PACKET_FREQUENCY_CURR_GET, /* sysfs */
212 ARMCP_PACKET_MAX_POWER_GET, /* sysfs */
213 ARMCP_PACKET_MAX_POWER_SET, /* sysfs */
214 ARMCP_PACKET_EEPROM_DATA_GET, /* sysfs */
217 #define ARMCP_PACKET_FENCE_VAL 0xFE8CE7A5
219 #define ARMCP_PKT_CTL_RC_SHIFT 12
220 #define ARMCP_PKT_CTL_RC_MASK 0x0000F000
222 #define ARMCP_PKT_CTL_OPCODE_SHIFT 16
223 #define ARMCP_PKT_CTL_OPCODE_MASK 0x1FFF0000
225 struct armcp_packet {
227 __le64 value; /* For SET packets */
228 __le64 result; /* For GET packets */
229 __le64 addr; /* For PQ */
234 __le32 fence; /* Signal to KMD that message is completed */
237 struct {/* For temperature/current/voltage/fan/pwm get/set */
242 struct { /* For I2C read/write */
246 __u8 pad; /* unused */
249 /* For frequency get/set */
255 /* For get Armcp info/EEPROM data */
256 __le32 data_max_size;
260 struct armcp_unmask_irq_arr_packet {
261 struct armcp_packet armcp_pkt;
266 enum armcp_packet_rc {
267 armcp_packet_success,
268 armcp_packet_invalid,
272 enum armcp_temp_type {
280 enum armcp_in_attributes {
286 enum armcp_curr_attributes {
292 enum armcp_fan_attributes {
298 enum armcp_pwm_attributes {
303 #define HL_CPU_PKT_SHIFT 5
304 #define HL_CPU_PKT_SIZE (1 << HL_CPU_PKT_SHIFT)
305 #define HL_CPU_PKT_MASK (~((1 << HL_CPU_PKT_SHIFT) - 1))
306 #define HL_CPU_MAX_PKTS_IN_CB 32
307 #define HL_CPU_CB_SIZE (HL_CPU_PKT_SIZE * \
308 HL_CPU_MAX_PKTS_IN_CB)
309 #define HL_CPU_ACCESSIBLE_MEM_SIZE (HL_QUEUE_LENGTH * HL_CPU_CB_SIZE)
311 /* Event Queue Packets */
313 struct eq_generic_event {
321 #define VERSION_MAX_LEN 128
322 #define ARMCP_MAX_SENSORS 128
324 struct armcp_sensor {
330 struct armcp_sensor sensors[ARMCP_MAX_SENSORS];
331 __u8 kernel_version[VERSION_MAX_LEN];
334 __le32 infineon_version;
335 __u8 fuse_version[VERSION_MAX_LEN];
336 __u8 thermal_version[VERSION_MAX_LEN];
337 __u8 armcp_version[VERSION_MAX_LEN];
341 #endif /* ARMCP_IF_H */