1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Texas Instruments System Control Interface Protocol
4  * Based on include/linux/soc/ti/ti_sci_protocol.h from Linux.
5  *
6  * Copyright (C) 2018 Texas Instruments Incorporated - https://www.ti.com/
7  *	Nishanth Menon
8  *	Lokesh Vutla <lokeshvutla@ti.com>
9  */
10 
11 #ifndef __TISCI_PROTOCOL_H
12 #define __TISCI_PROTOCOL_H
13 
14 #include <linux/bitops.h>
15 #include <linux/err.h>
16 
17 /**
18  * struct ti_sci_version_info - version information structure
19  * @abi_major:	Major ABI version. Change here implies risk of backward
20  *		compatibility break.
21  * @abi_minor:	Minor ABI version. Change here implies new feature addition,
22  *		or compatible change in ABI.
23  * @firmware_revision:	Firmware revision (not usually used).
24  * @firmware_description: Firmware description (not usually used).
25  */
26 struct ti_sci_version_info {
27 	u8 abi_major;
28 	u8 abi_minor;
29 	u16 firmware_revision;
30 	char firmware_description[32];
31 };
32 
33 /**
34  * struct ti_sci_dm_version_info - version information structure
35  * @abi_major:		Major ABI version. Change here implies risk of backward
36  *			compatibility break.
37  * @abi_minor:		Minor ABI version. Change here implies new feature addition,
38  *			or compatible change in ABI.
39  * @patch_ver:		Patch version of the firmware.
40  * @sub_ver:		Sub-version of the firmware.
41  * @dm_ver:		DM version.
42  * @sci_server_version: Version string of the SCI server.
43  * @rm_pm_hal_version:  Version string of the RM PM HAL.
44  */
45 struct ti_sci_dm_version_info {
46 	u8 abi_major;
47 	u8 abi_minor;
48 	u8 patch_ver;
49 	u8 sub_ver;
50 	u16 dm_ver;
51 	char rm_pm_hal_version[12];
52 	char sci_server_version[26];
53 };
54 
55 struct ti_sci_handle;
56 
57 /**
58  * struct ti_sci_board_ops - Board config operations
59  * @board_config: Command to set the board configuration
60  *		  Returns 0 for successful exclusive request, else returns
61  *		  corresponding error message.
62  * @board_config_rm: Command to set the board resource management
63  *		  configuration
64  *		  Returns 0 for successful exclusive request, else returns
65  *		  corresponding error message.
66  * @board_config_security: Command to set the board security configuration
67  *		  Returns 0 for successful exclusive request, else returns
68  *		  corresponding error message.
69  * @board_config_pm: Command to trigger and set the board power and clock
70  *		  management related configuration
71  *		  Returns 0 for successful exclusive request, else returns
72  *		  corresponding error message.
73  */
74 struct ti_sci_board_ops {
75 	int (*board_config)(const struct ti_sci_handle *handle,
76 			    u64 addr, u32 size);
77 	int (*board_config_rm)(const struct ti_sci_handle *handle,
78 			       u64 addr, u32 size);
79 	int (*board_config_security)(const struct ti_sci_handle *handle,
80 				     u64 addr, u32 size);
81 	int (*board_config_pm)(const struct ti_sci_handle *handle,
82 			       u64 addr, u32 size);
83 };
84 
85 /**
86  * struct ti_sci_dev_ops - Device control operations
87  * @get_device: Command to request for device managed by TISCI
88  *		Returns 0 for successful exclusive request, else returns
89  *		corresponding error message.
90  * @idle_device: Command to idle a device managed by TISCI
91  *		Returns 0 for successful exclusive request, else returns
92  *		corresponding error message.
93  * @put_device:	Command to release a device managed by TISCI
94  *		Returns 0 for successful release, else returns corresponding
95  *		error message.
96  * @is_valid:	Check if the device ID is a valid ID.
97  *		Returns 0 if the ID is valid, else returns corresponding error.
98  * @get_context_loss_count: Command to retrieve context loss counter - this
99  *		increments every time the device looses context. Overflow
100  *		is possible.
101  *		- count: pointer to u32 which will retrieve counter
102  *		Returns 0 for successful information request and count has
103  *		proper data, else returns corresponding error message.
104  * @is_idle:	Reports back about device idle state
105  *		- req_state: Returns requested idle state
106  *		Returns 0 for successful information request and req_state and
107  *		current_state has proper data, else returns corresponding error
108  *		message.
109  * @is_stop:	Reports back about device stop state
110  *		- req_state: Returns requested stop state
111  *		- current_state: Returns current stop state
112  *		Returns 0 for successful information request and req_state and
113  *		current_state has proper data, else returns corresponding error
114  *		message.
115  * @is_on:	Reports back about device ON(or active) state
116  *		- req_state: Returns requested ON state
117  *		- current_state: Returns current ON state
118  *		Returns 0 for successful information request and req_state and
119  *		current_state has proper data, else returns corresponding error
120  *		message.
121  * @is_transitioning: Reports back if the device is in the middle of transition
122  *		of state.
123  *		-current_state: Returns 'true' if currently transitioning.
124  * @set_device_resets: Command to configure resets for device managed by TISCI.
125  *		-reset_state: Device specific reset bit field
126  *		Returns 0 for successful request, else returns
127  *		corresponding error message.
128  * @get_device_resets: Command to read state of resets for device managed
129  *		by TISCI.
130  *		-reset_state: pointer to u32 which will retrieve resets
131  *		Returns 0 for successful request, else returns
132  *		corresponding error message.
133  * @release_exclusive_devices: Command to release all the exclusive devices
134  *		attached to this host. This should be used very carefully
135  *		and only at the end of execution of your software.
136  *
137  * NOTE: for all these functions, the following parameters are generic in
138  * nature:
139  * -handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
140  * -id:		Device Identifier
141  *
142  * Request for the device - NOTE: the client MUST maintain integrity of
143  * usage count by balancing get_device with put_device. No refcounting is
144  * managed by driver for that purpose.
145  */
146 struct ti_sci_dev_ops {
147 	int (*get_device)(const struct ti_sci_handle *handle, u32 id);
148 	int (*get_device_exclusive)(const struct ti_sci_handle *handle, u32 id);
149 	int (*idle_device)(const struct ti_sci_handle *handle, u32 id);
150 	int (*idle_device_exclusive)(const struct ti_sci_handle *handle,
151 				     u32 id);
152 	int (*put_device)(const struct ti_sci_handle *handle, u32 id);
153 	int (*is_valid)(const struct ti_sci_handle *handle, u32 id);
154 	int (*get_context_loss_count)(const struct ti_sci_handle *handle,
155 				      u32 id, u32 *count);
156 	int (*is_idle)(const struct ti_sci_handle *handle, u32 id,
157 		       bool *requested_state);
158 	int (*is_stop)(const struct ti_sci_handle *handle, u32 id,
159 		       bool *req_state, bool *current_state);
160 	int (*is_on)(const struct ti_sci_handle *handle, u32 id,
161 		     bool *req_state, bool *current_state);
162 	int (*is_transitioning)(const struct ti_sci_handle *handle, u32 id,
163 				bool *current_state);
164 	int (*set_device_resets)(const struct ti_sci_handle *handle, u32 id,
165 				 u32 reset_state);
166 	int (*get_device_resets)(const struct ti_sci_handle *handle, u32 id,
167 				 u32 *reset_state);
168 	int (*release_exclusive_devices)(void);
169 };
170 
171 /**
172  * struct ti_sci_clk_ops - Clock control operations
173  * @get_clock:	Request for activation of clock and manage by processor
174  *		- needs_ssc: 'true' if Spread Spectrum clock is desired.
175  *		- can_change_freq: 'true' if frequency change is desired.
176  *		- enable_input_term: 'true' if input termination is desired.
177  * @idle_clock:	Request for Idling a clock managed by processor
178  * @put_clock:	Release the clock to be auto managed by TISCI
179  * @is_auto:	Is the clock being auto managed
180  *		- req_state: state indicating if the clock is auto managed
181  * @is_on:	Is the clock ON
182  *		- req_state: if the clock is requested to be forced ON
183  *		- current_state: if the clock is currently ON
184  * @is_off:	Is the clock OFF
185  *		- req_state: if the clock is requested to be forced OFF
186  *		- current_state: if the clock is currently Gated
187  * @set_parent:	Set the clock source of a specific device clock
188  *		- parent_id: Parent clock identifier to set.
189  * @get_parent:	Get the current clock source of a specific device clock
190  *		- parent_id: Parent clock identifier which is the parent.
191  * @get_num_parents: Get the number of parents of the current clock source
192  *		- num_parents: returns the number of parent clocks.
193  * @get_best_match_freq: Find a best matching frequency for a frequency
194  *		range.
195  *		- match_freq: Best matching frequency in Hz.
196  * @set_freq:	Set the Clock frequency
197  * @get_freq:	Get the Clock frequency
198  *		- current_freq: Frequency in Hz that the clock is at.
199  *
200  * NOTE: for all these functions, the following parameters are generic in
201  * nature:
202  * -handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
203  * -did:	Device identifier this request is for
204  * -cid:	Clock identifier for the device for this request.
205  *		Each device has it's own set of clock inputs. This indexes
206  *		which clock input to modify.
207  * -min_freq:	The minimum allowable frequency in Hz. This is the minimum
208  *		allowable programmed frequency and does not account for clock
209  *		tolerances and jitter.
210  * -target_freq: The target clock frequency in Hz. A frequency will be
211  *		processed as close to this target frequency as possible.
212  * -max_freq:	The maximum allowable frequency in Hz. This is the maximum
213  *		allowable programmed frequency and does not account for clock
214  *		tolerances and jitter.
215  *
216  * Request for the clock - NOTE: the client MUST maintain integrity of
217  * usage count by balancing get_clock with put_clock. No refcounting is
218  * managed by driver for that purpose.
219  */
220 struct ti_sci_clk_ops {
221 	int (*get_clock)(const struct ti_sci_handle *handle, u32 did, u8 cid,
222 			 bool needs_ssc, bool can_change_freq,
223 			 bool enable_input_term);
224 	int (*idle_clock)(const struct ti_sci_handle *handle, u32 did, u8 cid);
225 	int (*put_clock)(const struct ti_sci_handle *handle, u32 did, u8 cid);
226 	int (*is_auto)(const struct ti_sci_handle *handle, u32 did, u8 cid,
227 		       bool *req_state);
228 	int (*is_on)(const struct ti_sci_handle *handle, u32 did, u8 cid,
229 		     bool *req_state, bool *current_state);
230 	int (*is_off)(const struct ti_sci_handle *handle, u32 did, u8 cid,
231 		      bool *req_state, bool *current_state);
232 	int (*set_parent)(const struct ti_sci_handle *handle, u32 did, u8 cid,
233 			  u8 parent_id);
234 	int (*get_parent)(const struct ti_sci_handle *handle, u32 did, u8 cid,
235 			  u8 *parent_id);
236 	int (*get_num_parents)(const struct ti_sci_handle *handle, u32 did,
237 			       u8 cid, u8 *num_parents);
238 	int (*get_best_match_freq)(const struct ti_sci_handle *handle, u32 did,
239 				   u8 cid, u64 min_freq, u64 target_freq,
240 				   u64 max_freq, u64 *match_freq);
241 	int (*set_freq)(const struct ti_sci_handle *handle, u32 did, u8 cid,
242 			u64 min_freq, u64 target_freq, u64 max_freq);
243 	int (*get_freq)(const struct ti_sci_handle *handle, u32 did, u8 cid,
244 			u64 *current_freq);
245 };
246 
247 /**
248  * struct ti_sci_rm_core_ops - Resource management core operations
249  * @get_range:		Get a range of resources belonging to ti sci host.
250  * @get_rage_from_shost:	Get a range of resources belonging to
251  *				specified host id.
252  *			- s_host: Host processing entity to which the
253  *				  resources are allocated
254  *
255  * NOTE: for these functions, all the parameters are consolidated and defined
256  * as below:
257  * - handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
258  * - dev_id:	TISCI device ID.
259  * - subtype:	Resource assignment subtype that is being requested
260  *		from the given device.
261  * - range_start:	Start index of the resource range
262  * - range_end:		Number of resources in the range
263  */
264 struct ti_sci_rm_core_ops {
265 	int (*get_range)(const struct ti_sci_handle *handle, u32 dev_id,
266 			 u8 subtype, u16 *range_start, u16 *range_num);
267 	int (*get_range_from_shost)(const struct ti_sci_handle *handle,
268 				    u32 dev_id, u8 subtype, u8 s_host,
269 				    u16 *range_start, u16 *range_num);
270 };
271 
272 /**
273  * struct ti_sci_core_ops - SoC Core Operations
274  * @reboot_device: Reboot the SoC
275  *		Returns 0 for successful request(ideally should never return),
276  *		else returns corresponding error value.
277  * @query_msmc: Query the size of available msmc
278  *		Return 0 for successful query else appropriate error value.
279  */
280 struct ti_sci_core_ops {
281 	int (*reboot_device)(const struct ti_sci_handle *handle);
282 	int (*query_msmc)(const struct ti_sci_handle *handle,
283 			  u64 *msmc_start, u64 *msmc_end);
284 };
285 
286 /**
287  * struct ti_sci_firmware_ops - DM firmware operations
288  * @query_dm_cap: Query the DM capabilities
289  *                Return 0 for successful query else appropriate error value.
290  * @get_dm_version: Get the DM version.
291  *                  Return 0 for successful request else appropriate error value.
292  */
293 struct ti_sci_firmware_ops {
294 	int (*query_dm_cap)(struct ti_sci_handle *handle,
295 			    u64 *dm_cap);
296 	int (*get_dm_version)(struct ti_sci_handle *handle,
297 			      struct ti_sci_dm_version_info *get_dm_version);
298 };
299 
300 #define TI_SCI_MSG_FLAG_FW_CAP_DM	0x100
301 
302 /**
303  * struct ti_sci_proc_ops - Processor specific operations.
304  *
305  * @proc_request: Request for controlling a physical processor.
306  *		The requesting host should be in the processor access list.
307  * @proc_release: Relinquish a physical processor control
308  * @proc_handover: Handover a physical processor control to another host
309  *		   in the permitted list.
310  * @set_proc_boot_cfg: Base configuration of the processor
311  * @set_proc_boot_ctrl: Setup limited control flags in specific cases.
312  * @proc_auth_boot_image:
313  * @get_proc_boot_status: Get the state of physical processor
314  * @proc_shutdown_no_wait: Shutdown a core without requesting or waiting for a
315  *			   response.
316  *
317  * NOTE: for all these functions, the following parameters are generic in
318  * nature:
319  * -handle:	Pointer to TISCI handle as retrieved by *ti_sci_get_handle
320  * -pid:	Processor ID
321  *
322  */
323 struct ti_sci_proc_ops {
324 	int (*proc_request)(const struct ti_sci_handle *handle, u8 pid);
325 	int (*proc_release)(const struct ti_sci_handle *handle, u8 pid);
326 	int (*proc_handover)(const struct ti_sci_handle *handle, u8 pid,
327 			     u8 hid);
328 	int (*set_proc_boot_cfg)(const struct ti_sci_handle *handle, u8 pid,
329 				 u64 bv, u32 cfg_set, u32 cfg_clr);
330 	int (*set_proc_boot_ctrl)(const struct ti_sci_handle *handle, u8 pid,
331 				  u32 ctrl_set, u32 ctrl_clr);
332 	int (*proc_auth_boot_image)(const struct ti_sci_handle *handle,
333 				    u64 *image_addr, u32 *image_size);
334 	int (*get_proc_boot_status)(const struct ti_sci_handle *handle, u8 pid,
335 				    u64 *bv, u32 *cfg_flags, u32 *ctrl_flags,
336 				    u32 *sts_flags);
337 	int (*proc_shutdown_no_wait)(const struct ti_sci_handle *handle,
338 				     u8 pid);
339 };
340 
341 #define TI_SCI_RING_MODE_RING			(0)
342 #define TI_SCI_RING_MODE_MESSAGE		(1)
343 #define TI_SCI_RING_MODE_CREDENTIALS		(2)
344 #define TI_SCI_RING_MODE_QM			(3)
345 
346 #define TI_SCI_MSG_UNUSED_SECONDARY_HOST TI_SCI_RM_NULL_U8
347 
348 /* RA config.addr_lo parameter is valid for RM ring configure TI_SCI message */
349 #define TI_SCI_MSG_VALUE_RM_RING_ADDR_LO_VALID	BIT(0)
350 /* RA config.addr_hi parameter is valid for RM ring configure TI_SCI message */
351 #define TI_SCI_MSG_VALUE_RM_RING_ADDR_HI_VALID	BIT(1)
352  /* RA config.count parameter is valid for RM ring configure TI_SCI message */
353 #define TI_SCI_MSG_VALUE_RM_RING_COUNT_VALID	BIT(2)
354 /* RA config.mode parameter is valid for RM ring configure TI_SCI message */
355 #define TI_SCI_MSG_VALUE_RM_RING_MODE_VALID	BIT(3)
356 /* RA config.size parameter is valid for RM ring configure TI_SCI message */
357 #define TI_SCI_MSG_VALUE_RM_RING_SIZE_VALID	BIT(4)
358 /* RA config.order_id parameter is valid for RM ring configure TISCI message */
359 #define TI_SCI_MSG_VALUE_RM_RING_ORDER_ID_VALID	BIT(5)
360 
361 #define TI_SCI_MSG_VALUE_RM_ALL_NO_ORDER \
362 	(TI_SCI_MSG_VALUE_RM_RING_ADDR_LO_VALID | \
363 	TI_SCI_MSG_VALUE_RM_RING_ADDR_HI_VALID | \
364 	TI_SCI_MSG_VALUE_RM_RING_COUNT_VALID | \
365 	TI_SCI_MSG_VALUE_RM_RING_MODE_VALID | \
366 	TI_SCI_MSG_VALUE_RM_RING_SIZE_VALID)
367 
368 /**
369  * struct ti_sci_rm_ringacc_ops - Ring Accelerator Management operations
370  * @config: configure the SoC Navigator Subsystem Ring Accelerator ring
371  */
372 struct ti_sci_rm_ringacc_ops {
373 	int (*config)(const struct ti_sci_handle *handle,
374 		      u32 valid_params, u16 nav_id, u16 index,
375 		      u32 addr_lo, u32 addr_hi, u32 count, u8 mode,
376 		      u8 size, u8 order_id
377 	);
378 };
379 
380 /**
381  * struct ti_sci_rm_psil_ops - PSI-L thread operations
382  * @pair: pair PSI-L source thread to a destination thread.
383  *	If the src_thread is mapped to UDMA tchan, the corresponding channel's
384  *	TCHAN_THRD_ID register is updated.
385  *	If the dst_thread is mapped to UDMA rchan, the corresponding channel's
386  *	RCHAN_THRD_ID register is updated.
387  * @unpair: unpair PSI-L source thread from a destination thread.
388  *	If the src_thread is mapped to UDMA tchan, the corresponding channel's
389  *	TCHAN_THRD_ID register is cleared.
390  *	If the dst_thread is mapped to UDMA rchan, the corresponding channel's
391  *	RCHAN_THRD_ID register is cleared.
392  */
393 struct ti_sci_rm_psil_ops {
394 	int (*pair)(const struct ti_sci_handle *handle, u32 nav_id,
395 		    u32 src_thread, u32 dst_thread);
396 	int (*unpair)(const struct ti_sci_handle *handle, u32 nav_id,
397 		      u32 src_thread, u32 dst_thread);
398 };
399 
400 /* UDMAP channel types */
401 #define TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR		2
402 #define TI_SCI_RM_UDMAP_CHAN_TYPE_PKT_PBRR_SB		3	/* RX only */
403 #define TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_PBRR		10
404 #define TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_PBVR		11
405 #define TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_BCOPY_PBRR	12
406 #define TI_SCI_RM_UDMAP_CHAN_TYPE_3RDP_BCOPY_PBVR	13
407 
408 /* UDMAP channel atypes */
409 #define TI_SCI_RM_UDMAP_ATYPE_PHYS			0
410 #define TI_SCI_RM_UDMAP_ATYPE_INTERMEDIATE		1
411 #define TI_SCI_RM_UDMAP_ATYPE_VIRTUAL			2
412 
413 /* UDMAP channel scheduling priorities */
414 #define TI_SCI_RM_UDMAP_SCHED_PRIOR_HIGH		0
415 #define TI_SCI_RM_UDMAP_SCHED_PRIOR_MEDHIGH		1
416 #define TI_SCI_RM_UDMAP_SCHED_PRIOR_MEDLOW		2
417 #define TI_SCI_RM_UDMAP_SCHED_PRIOR_LOW			3
418 
419 #define TI_SCI_RM_UDMAP_RX_FLOW_DESC_HOST		0
420 #define TI_SCI_RM_UDMAP_RX_FLOW_DESC_MONO		2
421 
422 #define TI_SCI_RM_UDMAP_CHAN_BURST_SIZE_64_BYTES	1
423 #define TI_SCI_RM_UDMAP_CHAN_BURST_SIZE_128_BYTES	2
424 #define TI_SCI_RM_UDMAP_CHAN_BURST_SIZE_256_BYTES	3
425 
426 #define TI_SCI_RM_BCDMA_EXTENDED_CH_TYPE_TCHAN		0
427 #define TI_SCI_RM_BCDMA_EXTENDED_CH_TYPE_BCHAN		1
428 
429 /* UDMAP TX/RX channel valid_params common declarations */
430 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_PAUSE_ON_ERR_VALID		BIT(0)
431 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_ATYPE_VALID                BIT(1)
432 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_CHAN_TYPE_VALID            BIT(2)
433 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_FETCH_SIZE_VALID           BIT(3)
434 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_CQ_QNUM_VALID              BIT(4)
435 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_PRIORITY_VALID             BIT(5)
436 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_QOS_VALID                  BIT(6)
437 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_ORDER_ID_VALID             BIT(7)
438 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_SCHED_PRIORITY_VALID       BIT(8)
439 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_BURST_SIZE_VALID		BIT(14)
440 
441 /**
442  * Configures a Navigator Subsystem UDMAP transmit channel
443  *
444  * Configures a Navigator Subsystem UDMAP transmit channel registers.
445  * See @ti_sci_msg_rm_udmap_tx_ch_cfg_req
446  */
447 struct ti_sci_msg_rm_udmap_tx_ch_cfg {
448 	u32 valid_params;
449 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_EINFO_VALID        BIT(9)
450 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FILT_PSWORDS_VALID      BIT(10)
451 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_SUPR_TDPKT_VALID        BIT(11)
452 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_CREDIT_COUNT_VALID      BIT(12)
453 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_FDEPTH_VALID            BIT(13)
454 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_TX_TDTYPE_VALID            BIT(15)
455 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_EXTENDED_CH_TYPE_VALID	BIT(16)
456 	u16 nav_id;
457 	u16 index;
458 	u8 tx_pause_on_err;
459 	u8 tx_filt_einfo;
460 	u8 tx_filt_pswords;
461 	u8 tx_atype;
462 	u8 tx_chan_type;
463 	u8 tx_supr_tdpkt;
464 	u16 tx_fetch_size;
465 	u8 tx_credit_count;
466 	u16 txcq_qnum;
467 	u8 tx_priority;
468 	u8 tx_qos;
469 	u8 tx_orderid;
470 	u16 fdepth;
471 	u8 tx_sched_priority;
472 	u8 tx_burst_size;
473 	u8 tx_tdtype;
474 	u8 extended_ch_type;
475 };
476 
477 /**
478  * Configures a Navigator Subsystem UDMAP receive channel
479  *
480  * Configures a Navigator Subsystem UDMAP receive channel registers.
481  * See @ti_sci_msg_rm_udmap_rx_ch_cfg_req
482  */
483 struct ti_sci_msg_rm_udmap_rx_ch_cfg {
484 	u32 valid_params;
485 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_START_VALID      BIT(9)
486 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_FLOWID_CNT_VALID        BIT(10)
487 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_SHORT_VALID      BIT(11)
488 #define TI_SCI_MSG_VALUE_RM_UDMAP_CH_RX_IGNORE_LONG_VALID       BIT(12)
489 	u16 nav_id;
490 	u16 index;
491 	u16 rx_fetch_size;
492 	u16 rxcq_qnum;
493 	u8 rx_priority;
494 	u8 rx_qos;
495 	u8 rx_orderid;
496 	u8 rx_sched_priority;
497 	u16 flowid_start;
498 	u16 flowid_cnt;
499 	u8 rx_pause_on_err;
500 	u8 rx_atype;
501 	u8 rx_chan_type;
502 	u8 rx_ignore_short;
503 	u8 rx_ignore_long;
504 	u8 rx_burst_size;
505 };
506 
507 /**
508  * Configures a Navigator Subsystem UDMAP receive flow
509  *
510  * Configures a Navigator Subsystem UDMAP receive flow's registers.
511  * See @tis_ci_msg_rm_udmap_flow_cfg_req
512  */
513 struct ti_sci_msg_rm_udmap_flow_cfg {
514 	u32 valid_params;
515 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_EINFO_PRESENT_VALID	BIT(0)
516 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PSINFO_PRESENT_VALID     BIT(1)
517 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_ERROR_HANDLING_VALID     BIT(2)
518 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DESC_TYPE_VALID          BIT(3)
519 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SOP_OFFSET_VALID         BIT(4)
520 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_QNUM_VALID          BIT(5)
521 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_HI_VALID         BIT(6)
522 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_LO_VALID         BIT(7)
523 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_HI_VALID        BIT(8)
524 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_LO_VALID        BIT(9)
525 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_HI_SEL_VALID     BIT(10)
526 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_SRC_TAG_LO_SEL_VALID     BIT(11)
527 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_HI_SEL_VALID    BIT(12)
528 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_DEST_TAG_LO_SEL_VALID    BIT(13)
529 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ0_SZ0_QNUM_VALID      BIT(14)
530 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ1_QNUM_VALID          BIT(15)
531 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ2_QNUM_VALID          BIT(16)
532 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_FDQ3_QNUM_VALID          BIT(17)
533 #define TI_SCI_MSG_VALUE_RM_UDMAP_FLOW_PS_LOCATION_VALID        BIT(18)
534 	u16 nav_id;
535 	u16 flow_index;
536 	u8 rx_einfo_present;
537 	u8 rx_psinfo_present;
538 	u8 rx_error_handling;
539 	u8 rx_desc_type;
540 	u16 rx_sop_offset;
541 	u16 rx_dest_qnum;
542 	u8 rx_src_tag_hi;
543 	u8 rx_src_tag_lo;
544 	u8 rx_dest_tag_hi;
545 	u8 rx_dest_tag_lo;
546 	u8 rx_src_tag_hi_sel;
547 	u8 rx_src_tag_lo_sel;
548 	u8 rx_dest_tag_hi_sel;
549 	u8 rx_dest_tag_lo_sel;
550 	u16 rx_fdq0_sz0_qnum;
551 	u16 rx_fdq1_qnum;
552 	u16 rx_fdq2_qnum;
553 	u16 rx_fdq3_qnum;
554 	u8 rx_ps_location;
555 };
556 
557 /**
558  * struct ti_sci_rm_udmap_ops - UDMA Management operations
559  * @tx_ch_cfg: configure SoC Navigator Subsystem UDMA transmit channel.
560  * @rx_ch_cfg: configure SoC Navigator Subsystem UDMA receive channel.
561  * @rx_flow_cfg: configure SoC Navigator Subsystem UDMA receive flow.
562  */
563 struct ti_sci_rm_udmap_ops {
564 	int (*tx_ch_cfg)(const struct ti_sci_handle *handle,
565 			 const struct ti_sci_msg_rm_udmap_tx_ch_cfg *params);
566 	int (*rx_ch_cfg)(const struct ti_sci_handle *handle,
567 			 const struct ti_sci_msg_rm_udmap_rx_ch_cfg *params);
568 	int (*rx_flow_cfg)(
569 		const struct ti_sci_handle *handle,
570 		const struct ti_sci_msg_rm_udmap_flow_cfg *params);
571 };
572 
573 /**
574  * struct ti_sci_msg_fwl_region_cfg - Request and Response for firewalls settings
575  *
576  * @fwl_id:		Firewall ID in question
577  * @region:		Region or channel number to set config info
578  *			This field is unused in case of a simple firewall  and must be initialized
579  *			to zero.  In case of a region based firewall, this field indicates the
580  *			region in question. (index starting from 0) In case of a channel based
581  *			firewall, this field indicates the channel in question (index starting
582  *			from 0)
583  * @n_permission_regs:	Number of permission registers to set
584  * @control:		Contents of the firewall CONTROL register to set
585  * @permissions:	Contents of the firewall PERMISSION register to set
586  * @start_address:	Contents of the firewall START_ADDRESS register to set
587  * @end_address:	Contents of the firewall END_ADDRESS register to set
588  */
589 struct ti_sci_msg_fwl_region {
590 	u16 fwl_id;
591 	u16 region;
592 	u32 n_permission_regs;
593 	u32 control;
594 	u32 permissions[3];
595 	u64 start_address;
596 	u64 end_address;
597 } __packed;
598 
599 /**
600  * \brief Request and Response for firewall owner change
601  *
602  * @fwl_id:		Firewall ID in question
603  * @region:		Region or channel number to set config info
604  *			This field is unused in case of a simple firewall  and must be initialized
605  *			to zero.  In case of a region based firewall, this field indicates the
606  *			region in question. (index starting from 0) In case of a channel based
607  *			firewall, this field indicates the channel in question (index starting
608  *			from 0)
609  * @n_permission_regs:	Number of permission registers <= 3
610  * @control:		Control register value for this region
611  * @owner_index:	New owner index to change to. Owner indexes are setup in DMSC firmware boot configuration data
612  * @owner_privid:	New owner priv-id, used to lookup owner_index is not known, must be set to zero otherwise
613  * @owner_permission_bits: New owner permission bits
614  */
615 struct ti_sci_msg_fwl_owner {
616 	u16 fwl_id;
617 	u16 region;
618 	u8 owner_index;
619 	u8 owner_privid;
620 	u16 owner_permission_bits;
621 } __packed;
622 
623 /**
624  * struct ti_sci_fwl_ops - Firewall specific operations
625  * @set_fwl_region: Request for configuring the firewall permissions.
626  * @get_fwl_region: Request for retrieving the firewall permissions.
627  * @change_fwl_owner: Request for a change of firewall owner.
628  */
629 struct ti_sci_fwl_ops {
630 	int (*set_fwl_region)(const struct ti_sci_handle *handle, const struct ti_sci_msg_fwl_region *region);
631 	int (*get_fwl_region)(const struct ti_sci_handle *handle, struct ti_sci_msg_fwl_region *region);
632 	int (*change_fwl_owner)(const struct ti_sci_handle *handle, struct ti_sci_msg_fwl_owner *owner);
633 };
634 
635 /**
636  * struct ti_sci_ops - Function support for TI SCI
637  * @board_ops:	Miscellaneous operations
638  * @dev_ops:	Device specific operations
639  * @clk_ops:	Clock specific operations
640  * @core_ops:	Core specific operations
641  * @proc_ops:	Processor specific operations
642  * @ring_ops: Ring Accelerator Management operations
643  * @fw_ops:	Firewall specific operations
644  */
645 struct ti_sci_ops {
646 	struct ti_sci_board_ops board_ops;
647 	struct ti_sci_dev_ops dev_ops;
648 	struct ti_sci_clk_ops clk_ops;
649 	struct ti_sci_core_ops core_ops;
650 	struct ti_sci_firmware_ops fw_ops;
651 	struct ti_sci_proc_ops proc_ops;
652 	struct ti_sci_rm_core_ops rm_core_ops;
653 	struct ti_sci_rm_ringacc_ops rm_ring_ops;
654 	struct ti_sci_rm_psil_ops rm_psil_ops;
655 	struct ti_sci_rm_udmap_ops rm_udmap_ops;
656 	struct ti_sci_fwl_ops fwl_ops;
657 };
658 
659 /**
660  * struct ti_sci_handle - Handle returned to TI SCI clients for usage.
661  * @ops:	operations that are made available to TI SCI clients
662  * @version:	structure containing version information
663  */
664 struct ti_sci_handle {
665 	struct ti_sci_ops ops;
666 	struct ti_sci_version_info version;
667 };
668 
669 #define TI_SCI_RESOURCE_NULL	0xffff
670 
671 /**
672  * struct ti_sci_resource_desc - Description of TI SCI resource instance range.
673  * @start:	Start index of the resource.
674  * @num:	Number of resources.
675  * @res_map:	Bitmap to manage the allocation of these resources.
676  */
677 struct ti_sci_resource_desc {
678 	u16 start;
679 	u16 num;
680 	unsigned long *res_map;
681 };
682 
683 /**
684  * struct ti_sci_resource - Structure representing a resource assigned
685  *			    to a device.
686  * @sets:	Number of sets available from this resource type
687  * @desc:	Array of resource descriptors.
688  */
689 struct ti_sci_resource {
690 	u16 sets;
691 	struct ti_sci_resource_desc *desc;
692 };
693 
694 #if IS_ENABLED(CONFIG_TI_SCI_PROTOCOL)
695 
696 const struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *dev);
697 const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev);
698 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
699 						  const char *property);
700 u16 ti_sci_get_free_resource(struct ti_sci_resource *res);
701 void ti_sci_release_resource(struct ti_sci_resource *res, u16 id);
702 struct ti_sci_resource *
703 devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
704 			    struct udevice *dev, u32 dev_id, char *of_prop);
705 
706 #else	/* CONFIG_TI_SCI_PROTOCOL */
707 
708 static inline
ti_sci_get_handle_from_sysfw(struct udevice * dev)709 const struct ti_sci_handle *ti_sci_get_handle_from_sysfw(struct udevice *dev)
710 {
711 	return ERR_PTR(-EINVAL);
712 }
713 
ti_sci_get_handle(struct udevice * dev)714 static inline const struct ti_sci_handle *ti_sci_get_handle(struct udevice *dev)
715 {
716 	return ERR_PTR(-EINVAL);
717 }
718 
719 static inline
ti_sci_get_by_phandle(struct udevice * dev,const char * property)720 const struct ti_sci_handle *ti_sci_get_by_phandle(struct udevice *dev,
721 						  const char *property)
722 {
723 	return ERR_PTR(-EINVAL);
724 }
725 
ti_sci_get_free_resource(struct ti_sci_resource * res)726 static inline u16 ti_sci_get_free_resource(struct ti_sci_resource *res)
727 {
728 	return TI_SCI_RESOURCE_NULL;
729 }
730 
ti_sci_release_resource(struct ti_sci_resource * res,u16 id)731 static inline void ti_sci_release_resource(struct ti_sci_resource *res, u16 id)
732 {
733 }
734 
735 static inline struct ti_sci_resource *
devm_ti_sci_get_of_resource(const struct ti_sci_handle * handle,struct udevice * dev,u32 dev_id,char * of_prop)736 devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
737 			    struct udevice *dev, u32 dev_id, char *of_prop)
738 {
739 	return ERR_PTR(-EINVAL);
740 }
741 #endif	/* CONFIG_TI_SCI_PROTOCOL */
742 
743 #endif	/* __TISCI_PROTOCOL_H */
744