1/*
2 * Copyright (c) 2014-2016, NVIDIA CORPORATION.
3 * Copright 2019, Data61
4 * Commonwealth Scientific and Industrial Research Organisation (CSIRO)
5 * ABN 41 687 119 230.
6 *
7 * This software may be distributed and modified according to the terms of
8 * the GNU General Public License version 2. Note that NO WARRANTY is provided.
9 * See "LICENSE_GPLv2.txt" for details.
10 *
11 * @TAG(DATA61_GPL)
12 */
13
14/*
15 * This a port of the Tegra BPMP sources from U-Boot with some small additional
16 * modifications. Similar to the Tegra IVC protocol, there's no documentation
17 * on the BPMP module ABI.
18 */
19
20#ifndef _ABI_BPMP_ABI_H_
21#define _ABI_BPMP_ABI_H_
22
23#ifdef LK
24#include <stdint.h>
25#endif
26#include <platsupport/io.h>
27#include <tx2bpmp/hsp.h>
28#include <tx2bpmp/ivc.h>
29#include <utils/util.h>
30
31#ifndef __ABI_PACKED
32#define __ABI_PACKED __attribute__((packed))
33#endif
34
35#ifdef NO_GCC_EXTENSIONS
36#define EMPTY char empty;
37#define EMPTY_ARRAY 1
38#else
39#define EMPTY
40#define EMPTY_ARRAY 0
41#endif
42
43#ifndef __UNION_ANON
44#define __UNION_ANON
45#endif
46/**
47 * @file
48 */
49
50#define __BPMP_CHECK_ARGS(function) \
51    do {                                                                            \
52        if (!bpmp) { ZF_LOGE("bpmp is NULL"); return -EINVAL; }                     \
53        if (!function) { ZF_LOGE(#function " not implemented"); return -ENOSYS; }   \
54    } while(0)
55
56struct tx2_bpmp {
57    void *data;
58    int (*call)(void *data, int mrq, void *tx_msg, size_t tx_size, void *rx_msg, size_t rx_size);
59    int (*destroy)(void *data);
60};
61
62/*
63 * Initialises the BPMP interfaces.
64 *
65 * @param io_ops Initialised IO ops interface.
66 * @param bpmp Pointer to a BPMP struct pointer that will be filled in.
67 *
68 * @return 0 on success, otherwise an error code.
69 */
70int tx2_bpmp_init(ps_io_ops_t *io_ops, struct tx2_bpmp *bpmp);
71
72/*
73 * Destroys an initialised BPMP interface.
74 *
75 * @param bpmp Initialised BPMP interface that will be destroyed.
76 *
77 * @return 0 on success, otherwise an error code.
78 */
79static inline int tx2_bpmp_destroy(struct tx2_bpmp *bpmp)
80{
81    __BPMP_CHECK_ARGS(bpmp->destroy);
82    return bpmp->destroy(bpmp->data);
83}
84
85/*
86 * Sends a request to the BPMP device module and waits for a response.
87 *
88 * @param bpmp An initialised BPMP interface.
89 * @param mrq The Message Request (MRQ) code of the request. See MRQ_Codes below for the valid codes.
90 * @param tx_msg The contents of the request message. See the corresponding mrq_*_request structs for the
91 *               valid request layouts.
92 * @param tx_size Size in bytes of the request message.
93 * @param rx_msg A buffer to hold the response of the request. See the coressponding mrq_*_response structs
94 *               for the valid response layouts.
95 * @param rx_size Size in bytes of the response buffer.
96 */
97static inline int tx2_bpmp_call(struct tx2_bpmp *bpmp, int mrq, void *tx_msg, size_t tx_size, void *rx_msg,
98                                size_t rx_size)
99{
100    __BPMP_CHECK_ARGS(bpmp->call);
101    return bpmp->call(bpmp->data, mrq, tx_msg, tx_size, rx_msg, rx_size);
102}
103
104/**
105 * @defgroup MRQ MRQ Messages
106 * @brief Messages sent to/from BPMP via IPC
107 * @{
108 *   @defgroup MRQ_Format Message Format
109 *   @defgroup MRQ_Codes Message Request (MRQ) Codes
110 *   @defgroup MRQ_Payloads Message Payloads
111 *   @defgroup Error_Codes Error Codes
112 * @}
113 */
114
115/**
116 * @addtogroup MRQ_Format Message Format
117 * @{
118 * The CPU requests the BPMP to perform a particular service by
119 * sending it an IVC frame containing a single MRQ message. An MRQ
120 * message consists of a @ref mrq_request followed by a payload whose
121 * format depends on mrq_request::mrq.
122 *
123 * The BPMP processes the data and replies with an IVC frame (on the
124 * same IVC channel) containing and MRQ response. An MRQ response
125 * consists of a @ref mrq_response followed by a payload whose format
126 * depends on the associated mrq_request::mrq.
127 *
128 * A well-defined subset of the MRQ messages that the CPU sends to the
129 * BPMP can lead to BPMP eventually sending an MRQ message to the
130 * CPU. For example, when the CPU uses an #MRQ_THERMAL message to set
131 * a thermal trip point, the BPMP may eventually send a single
132 * #MRQ_THERMAL message of its own to the CPU indicating that the trip
133 * point has been crossed.
134 * @}
135 */
136
137/**
138 * @ingroup MRQ_Format
139 * @brief header for an MRQ message
140 *
141 * Provides the MRQ number for the MRQ message: #mrq. The remainder of
142 * the MRQ message is a payload (immediately following the
143 * mrq_request) whose format depends on mrq.
144 *
145 * @todo document the flags
146 */
147struct mrq_request {
148	/** @brief MRQ number of the request */
149	uint32_t mrq;
150	/** @brief flags for the request */
151	uint32_t flags;
152} __ABI_PACKED;
153
154/**
155 * @ingroup MRQ_Format
156 * @brief header for an MRQ response
157 *
158 *  Provides an error code for the associated MRQ message. The
159 *  remainder of the MRQ response is a payload (immediately following
160 *  the mrq_response) whose format depends on the associated
161 *  mrq_request::mrq
162 *
163 * @todo document the flags
164 */
165struct mrq_response {
166	/** @brief error code for the MRQ request itself */
167	int32_t err;
168	/** @brief flags for the response */
169	uint32_t flags;
170} __ABI_PACKED;
171
172/**
173 * @ingroup MRQ_Format
174 * Minimum needed size for an IPC message buffer
175 */
176#define MSG_MIN_SZ	128
177/**
178 * @ingroup MRQ_Format
179 *  Minimum size guaranteed for data in an IPC message buffer
180 */
181#define MSG_DATA_MIN_SZ	120
182
183/**
184 * @ingroup MRQ_Codes
185 * @name Legal MRQ codes
186 * These are the legal values for mrq_request::mrq
187 * @{
188 */
189
190#define MRQ_PING		0
191#define MRQ_QUERY_TAG		1
192#define MRQ_MODULE_LOAD		4
193#define MRQ_MODULE_UNLOAD	5
194#define MRQ_TRACE_MODIFY	7
195#define MRQ_WRITE_TRACE		8
196#define MRQ_THREADED_PING	9
197#define MRQ_MODULE_MAIL		11
198#define MRQ_DEBUGFS		19
199#define MRQ_RESET		20
200#define MRQ_I2C			21
201#define MRQ_CLK			22
202#define MRQ_QUERY_ABI		23
203#define MRQ_PG_READ_STATE	25
204#define MRQ_PG_UPDATE_STATE	26
205#define MRQ_THERMAL		27
206#define MRQ_CPU_VHINT		28
207#define MRQ_ABI_RATCHET		29
208#define MRQ_EMC_DVFS_LATENCY	31
209#define MRQ_TRACE_ITER		64
210
211/** @} */
212
213/**
214 * @ingroup MRQ_Codes
215 * @brief Maximum MRQ code to be sent by CPU software to
216 * BPMP. Subject to change in future
217 */
218#define MAX_CPU_MRQ_ID		64
219
220/**
221 * @addtogroup MRQ_Payloads Message Payloads
222 * @{
223 *   @defgroup Ping
224 *   @defgroup Query_Tag Query Tag
225 *   @defgroup Module Loadable Modules
226 *   @defgroup Trace
227 *   @defgroup Debugfs
228 *   @defgroup Reset
229 *   @defgroup I2C
230 *   @defgroup Clocks
231 *   @defgroup ABI_info ABI Info
232 *   @defgroup MC_Flush MC Flush
233 *   @defgroup Powergating
234 *   @defgroup Thermal
235 *   @defgroup Vhint CPU Voltage hint
236 *   @defgroup MRQ_Deprecated Deprecated MRQ messages
237 *   @defgroup EMC
238 * @}
239 */
240
241
242/**
243 * @ingroup MRQ_Codes
244 * @def MRQ_PING
245 * @brief A simple ping
246 *
247 * * Platforms: All
248 * * Initiators: Any
249 * * Targets: Any
250 * * Request Payload: @ref mrq_ping_request
251 * * Response Payload: @ref mrq_ping_response
252 *
253 * @ingroup MRQ_Codes
254 * @def MRQ_THREADED_PING
255 * @brief A deeper ping
256 *
257 * * Platforms: All
258 * * Initiators: Any
259 * * Targets: BPMP
260 * * Request Payload: @ref mrq_ping_request
261 * * Response Payload: @ref mrq_ping_response
262 *
263 * Behavior is equivalent to a simple #MRQ_PING except that BPMP
264 * responds from a thread context (providing a slightly more robust
265 * sign of life).
266 *
267 */
268
269/**
270 * @ingroup Ping
271 * @brief request with #MRQ_PING
272 *
273 * Used by the sender of an #MRQ_PING message to request a pong from
274 * recipient. The response from the recipient is computed based on
275 * #challenge.
276 */
277struct mrq_ping_request {
278/** @brief arbitrarily chosen value */
279	uint32_t challenge;
280} __ABI_PACKED;
281
282/**
283 * @ingroup Ping
284 * @brief response to #MRQ_PING
285 *
286 * Sent in response to an #MRQ_PING message. #reply should be the
287 * mrq_ping_request challenge left shifted by 1 with the carry-bit
288 * dropped.
289 *
290 */
291struct mrq_ping_response {
292	/** @brief response to the MRQ_PING challege */
293	uint32_t reply;
294} __ABI_PACKED;
295
296/**
297 * @ingroup MRQ_Codes
298 * @def MRQ_QUERY_TAG
299 * @brief Query BPMP firmware's tag (i.e. version information)
300 *
301 * * Platforms: All
302 * * Initiators: CCPLEX
303 * * Targets: BPMP
304 * * Request Payload: @ref mrq_query_tag_request
305 * * Response Payload: N/A
306 *
307 */
308
309/**
310 * @ingroup Query_Tag
311 * @brief request with #MRQ_QUERY_TAG
312 *
313 * Used by #MRQ_QUERY_TAG call to ask BPMP to fill in the memory
314 * pointed by #addr with BPMP firmware header.
315 *
316 * The sender is reponsible for ensuring that #addr is mapped in to
317 * the recipient's address map.
318 */
319struct mrq_query_tag_request {
320  /** @brief base address to store the firmware header */
321	uint32_t addr;
322} __ABI_PACKED;
323
324/**
325 * @ingroup MRQ_Codes
326 * @def MRQ_MODULE_LOAD
327 * @brief dynamically load a BPMP code module
328 *
329 * * Platforms: All
330 * * Initiators: CCPLEX
331 * * Targets: BPMP
332 * * Request Payload: @ref mrq_module_load_request
333 * * Response Payload: @ref mrq_module_load_response
334 *
335 * @note This MRQ is disabled on production systems
336 *
337 */
338
339/**
340 * @ingroup Module
341 * @brief request with #MRQ_MODULE_LOAD
342 *
343 * Used by #MRQ_MODULE_LOAD calls to ask the recipient to dynamically
344 * load the code located at #phys_addr and having size #size
345 * bytes. #phys_addr is treated as a void pointer.
346 *
347 * The recipient copies the code from #phys_addr to locally allocated
348 * memory prior to responding to this message.
349 *
350 * @todo document the module header format
351 *
352 * The sender is responsible for ensuring that the code is mapped in
353 * the recipient's address map.
354 *
355 */
356struct mrq_module_load_request {
357	/** @brief base address of the code to load. Treated as (void *) */
358	uint32_t phys_addr; /* (void *) */
359	/** @brief size in bytes of code to load */
360	uint32_t size;
361} __ABI_PACKED;
362
363/**
364 * @ingroup Module
365 * @brief response to #MRQ_MODULE_LOAD
366 *
367 * @todo document mrq_response::err
368 */
369struct mrq_module_load_response {
370	/** @brief handle to the loaded module */
371	uint32_t base;
372} __ABI_PACKED;
373
374/**
375 * @ingroup MRQ_Codes
376 * @def MRQ_MODULE_UNLOAD
377 * @brief unload a previously loaded code module
378 *
379 * * Platforms: All
380 * * Initiators: CCPLEX
381 * * Targets: BPMP
382 * * Request Payload: @ref mrq_module_unload_request
383 * * Response Payload: N/A
384 *
385 * @note This MRQ is disabled on production systems
386 */
387
388/**
389 * @ingroup Module
390 * @brief request with #MRQ_MODULE_UNLOAD
391 *
392 * Used by #MRQ_MODULE_UNLOAD calls to request that a previously loaded
393 * module be unloaded.
394 */
395struct mrq_module_unload_request {
396	/** @brief handle of the module to unload */
397	uint32_t base;
398} __ABI_PACKED;
399
400/**
401 * @ingroup MRQ_Codes
402 * @def MRQ_TRACE_MODIFY
403 * @brief modify the set of enabled trace events
404 *
405 * * Platforms: All
406 * * Initiators: CCPLEX
407 * * Targets: BPMP
408 * * Request Payload: @ref mrq_trace_modify_request
409 * * Response Payload: @ref mrq_trace_modify_response
410 *
411 * @note This MRQ is disabled on production systems
412 */
413
414/**
415 * @ingroup Trace
416 * @brief request with #MRQ_TRACE_MODIFY
417 *
418 * Used by %MRQ_TRACE_MODIFY calls to enable or disable specify trace
419 * events.  #set takes precedence for any bit set in both #set and
420 * #clr.
421 */
422struct mrq_trace_modify_request {
423	/** @brief bit mask of trace events to disable */
424	uint32_t clr;
425	/** @brief bit mask of trace events to enable */
426	uint32_t set;
427} __ABI_PACKED;
428
429/**
430 * @ingroup Trace
431 * @brief response to #MRQ_TRACE_MODIFY
432 *
433 * Sent in repsonse to an #MRQ_TRACE_MODIFY message. #mask reflects the
434 * state of which events are enabled after the recipient acted on the
435 * message.
436 *
437 */
438struct mrq_trace_modify_response {
439	/** @brief bit mask of trace event enable states */
440	uint32_t mask;
441} __ABI_PACKED;
442
443/**
444 * @ingroup MRQ_Codes
445 * @def MRQ_WRITE_TRACE
446 * @brief Write trace data to a buffer
447 *
448 * * Platforms: All
449 * * Initiators: CCPLEX
450 * * Targets: BPMP
451 * * Request Payload: @ref mrq_write_trace_request
452 * * Response Payload: @ref mrq_write_trace_response
453 *
454 * mrq_response::err depends on the @ref mrq_write_trace_request field
455 * values. err is -#BPMP_EINVAL if size is zero or area is NULL or
456 * area is in an illegal range. A positive value for err indicates the
457 * number of bytes written to area.
458 *
459 * @note This MRQ is disabled on production systems
460 */
461
462/**
463 * @ingroup Trace
464 * @brief request with #MRQ_WRITE_TRACE
465 *
466 * Used by MRQ_WRITE_TRACE calls to ask the recipient to copy trace
467 * data from the recipient's local buffer to the output buffer. #area
468 * is treated as a byte-aligned pointer in the recipient's address
469 * space.
470 *
471 * The sender is responsible for ensuring that the output
472 * buffer is mapped in the recipient's address map. The recipient is
473 * responsible for protecting its own code and data from accidental
474 * overwrites.
475 */
476struct mrq_write_trace_request {
477	/** @brief base address of output buffer */
478	uint32_t area;
479	/** @brief size in bytes of the output buffer */
480	uint32_t size;
481} __ABI_PACKED;
482
483/**
484 * @ingroup Trace
485 * @brief response to #MRQ_WRITE_TRACE
486 *
487 * Once this response is sent, the respondent will not access the
488 * output buffer further.
489 */
490struct mrq_write_trace_response {
491	/**
492	 * @brief flag whether more data remains in local buffer
493	 *
494	 * Value is 1 if the entire local trace buffer has been
495	 * drained to the outputbuffer. Value is 0 otherwise.
496	 */
497	uint32_t eof;
498} __ABI_PACKED;
499
500/** @private */
501struct mrq_threaded_ping_request {
502	uint32_t challenge;
503} __ABI_PACKED;
504
505/** @private */
506struct mrq_threaded_ping_response {
507	uint32_t reply;
508} __ABI_PACKED;
509
510/**
511 * @ingroup MRQ_Codes
512 * @def MRQ_MODULE_MAIL
513 * @brief send a message to a loadable module
514 *
515 * * Platforms: All
516 * * Initiators: Any
517 * * Targets: BPMP
518 * * Request Payload: @ref mrq_module_mail_request
519 * * Response Payload: @ref mrq_module_mail_response
520 *
521 * @note This MRQ is disabled on production systems
522 */
523
524/**
525 * @ingroup Module
526 * @brief request with #MRQ_MODULE_MAIL
527 */
528struct mrq_module_mail_request {
529	/** @brief handle to the previously loaded module */
530	uint32_t base;
531	/** @brief module-specific mail payload
532	 *
533	 * The length of data[ ] is unknown to the BPMP core firmware
534	 * but it is limited to the size of an IPC message.
535	 */
536	uint8_t data[EMPTY_ARRAY];
537} __ABI_PACKED;
538
539/**
540 * @ingroup Module
541 * @brief response to #MRQ_MODULE_MAIL
542 */
543struct mrq_module_mail_response {
544	/** @brief module-specific mail payload
545	 *
546	 * The length of data[ ] is unknown to the BPMP core firmware
547	 * but it is limited to the size of an IPC message.
548	 */
549	uint8_t data[EMPTY_ARRAY];
550} __ABI_PACKED;
551
552/**
553 * @ingroup MRQ_Codes
554 * @def MRQ_DEBUGFS
555 * @brief Interact with BPMP's debugfs file nodes
556 *
557 * * Platforms: T186
558 * * Initiators: Any
559 * * Targets: BPMP
560 * * Request Payload: @ref mrq_debugfs_request
561 * * Response Payload: @ref mrq_debugfs_response
562 */
563
564/**
565 * @addtogroup Debugfs
566 * @{
567 *
568 * The BPMP firmware implements a pseudo-filesystem called
569 * debugfs. Any driver within the firmware may register with debugfs
570 * to expose an arbitrary set of "files" in the filesystem. When
571 * software on the CPU writes to a debugfs file, debugfs passes the
572 * written data to a callback provided by the driver. When software on
573 * the CPU reads a debugfs file, debugfs queries the driver for the
574 * data to return to the CPU. The intention of the debugfs filesystem
575 * is to provide information useful for debugging the system at
576 * runtime.
577 *
578 * @note The files exposed via debugfs are not part of the
579 * BPMP firmware's ABI. debugfs files may be added or removed in any
580 * given version of the firmware. Typically the semantics of a debugfs
581 * file are consistent from version to version but even that is not
582 * guaranteed.
583 *
584 * @}
585 */
586/** @ingroup Debugfs */
587enum mrq_debugfs_commands {
588	CMD_DEBUGFS_READ = 1,
589	CMD_DEBUGFS_WRITE = 2,
590	CMD_DEBUGFS_DUMPDIR = 3,
591	CMD_DEBUGFS_MAX
592};
593
594/**
595 * @ingroup Debugfs
596 * @brief parameters for CMD_DEBUGFS_READ/WRITE command
597 */
598struct cmd_debugfs_fileop_request {
599	/** @brief physical address pointing at filename */
600	uint32_t fnameaddr;
601	/** @brief length in bytes of filename buffer */
602	uint32_t fnamelen;
603	/** @brief physical address pointing to data buffer */
604	uint32_t dataaddr;
605	/** @brief length in bytes of data buffer */
606	uint32_t datalen;
607} __ABI_PACKED;
608
609/**
610 * @ingroup Debugfs
611 * @brief parameters for CMD_DEBUGFS_READ/WRITE command
612 */
613struct cmd_debugfs_dumpdir_request {
614	/** @brief physical address pointing to data buffer */
615	uint32_t dataaddr;
616	/** @brief length in bytes of data buffer */
617	uint32_t datalen;
618} __ABI_PACKED;
619
620/**
621 * @ingroup Debugfs
622 * @brief response data for CMD_DEBUGFS_READ/WRITE command
623 */
624struct cmd_debugfs_fileop_response {
625	/** @brief always 0 */
626	uint32_t reserved;
627	/** @brief number of bytes read from or written to data buffer */
628	uint32_t nbytes;
629} __ABI_PACKED;
630
631/**
632 * @ingroup Debugfs
633 * @brief response data for CMD_DEBUGFS_DUMPDIR command
634 */
635struct cmd_debugfs_dumpdir_response {
636	/** @brief always 0 */
637	uint32_t reserved;
638	/** @brief number of bytes read from or written to data buffer */
639	uint32_t nbytes;
640} __ABI_PACKED;
641
642/**
643 * @ingroup Debugfs
644 * @brief request with #MRQ_DEBUGFS.
645 *
646 * The sender of an MRQ_DEBUGFS message uses #cmd to specify a debugfs
647 * command to execute. Legal commands are the values of @ref
648 * mrq_debugfs_commands. Each command requires a specific additional
649 * payload of data.
650 *
651 * |command            |payload|
652 * |-------------------|-------|
653 * |CMD_DEBUGFS_READ   |fop    |
654 * |CMD_DEBUGFS_WRITE  |fop    |
655 * |CMD_DEBUGFS_DUMPDIR|dumpdir|
656 */
657struct mrq_debugfs_request {
658	uint32_t cmd;
659	union {
660		struct cmd_debugfs_fileop_request fop;
661		struct cmd_debugfs_dumpdir_request dumpdir;
662	} __UNION_ANON;
663} __ABI_PACKED;
664
665/**
666 * @ingroup Debugfs
667 */
668struct mrq_debugfs_response {
669	/** @brief always 0 */
670	int32_t reserved;
671	union {
672		/** @brief response data for CMD_DEBUGFS_READ OR
673		 * CMD_DEBUGFS_WRITE command
674		 */
675		struct cmd_debugfs_fileop_response fop;
676		/** @brief response data for CMD_DEBUGFS_DUMPDIR command */
677		struct cmd_debugfs_dumpdir_response dumpdir;
678	} __UNION_ANON;
679} __ABI_PACKED;
680
681/**
682 * @addtogroup Debugfs
683 * @{
684 */
685#define DEBUGFS_S_ISDIR	(1 << 9)
686#define DEBUGFS_S_IRUSR	(1 << 8)
687#define DEBUGFS_S_IWUSR	(1 << 7)
688/** @} */
689
690
691/**
692 * @ingroup MRQ_Codes
693 * @def MRQ_RESET
694 * @brief reset an IP block
695 *
696 * * Platforms: T186
697 * * Initiators: Any
698 * * Targets: BPMP
699 * * Request Payload: @ref mrq_reset_request
700 * * Response Payload: N/A
701 */
702
703/**
704 * @ingroup Reset
705 */
706enum mrq_reset_commands {
707	CMD_RESET_ASSERT = 1,
708	CMD_RESET_DEASSERT = 2,
709	CMD_RESET_MODULE = 3,
710	CMD_RESET_MAX, /* not part of ABI and subject to change */
711};
712
713/**
714 * @ingroup Reset
715 * @brief request with MRQ_RESET
716 *
717 * Used by the sender of an #MRQ_RESET message to request BPMP to
718 * assert or or deassert a given reset line.
719 */
720struct mrq_reset_request {
721	/** @brief reset action to perform (@enum mrq_reset_commands) */
722	uint32_t cmd;
723	/** @brief id of the reset to affected */
724	uint32_t reset_id;
725} __ABI_PACKED;
726
727/**
728 * @ingroup MRQ_Codes
729 * @def MRQ_I2C
730 * @brief issue an i2c transaction
731 *
732 * * Platforms: T186
733 * * Initiators: Any
734 * * Targets: BPMP
735 * * Request Payload: @ref mrq_i2c_request
736 * * Response Payload: @ref mrq_i2c_response
737 */
738
739/**
740 * @addtogroup I2C
741 * @{
742 */
743#define TEGRA_I2C_IPC_MAX_IN_BUF_SIZE	(MSG_DATA_MIN_SZ - 12)
744#define TEGRA_I2C_IPC_MAX_OUT_BUF_SIZE	(MSG_DATA_MIN_SZ - 4)
745/** @} */
746
747/**
748 * @ingroup I2C
749 * @name Serial I2C flags
750 * Use these flags with serial_i2c_request::flags
751 * @{
752 */
753#define SERIALI2C_TEN           0x0010
754#define SERIALI2C_RD            0x0001
755#define SERIALI2C_STOP          0x8000
756#define SERIALI2C_NOSTART       0x4000
757#define SERIALI2C_REV_DIR_ADDR  0x2000
758#define SERIALI2C_IGNORE_NAK    0x1000
759#define SERIALI2C_NO_RD_ACK     0x0800
760#define SERIALI2C_RECV_LEN      0x0400
761/** @} */
762/** @ingroup I2C */
763enum {
764	CMD_I2C_XFER = 1
765};
766
767/**
768 * @ingroup I2C
769 * @brief serializable i2c request
770 *
771 * Instances of this structure are packed (little-endian) into
772 * cmd_i2c_xfer_request::data_buf. Each instance represents a single
773 * transaction (or a portion of a transaction with repeated starts) on
774 * an i2c bus.
775 *
776 * Because these structures are packed, some instances are likely to
777 * be misaligned. Additionally because #data is variable length, it is
778 * not possible to iterate through a serialized list of these
779 * structures without inspecting #len in each instance.  It may be
780 * easier to serialize or deserialize cmd_i2c_xfer_request::data_buf
781 * manually rather than using this structure definition.
782*/
783struct serial_i2c_request {
784	/** @brief I2C slave address */
785	uint16_t addr;
786	/** @brief bitmask of SERIALI2C_ flags */
787	uint16_t flags;
788	/** @brief length of I2C transaction in bytes */
789	uint16_t len;
790	/** @brief for write transactions only, #len bytes of data */
791	uint8_t data[];
792} __ABI_PACKED;
793
794/**
795 * @ingroup I2C
796 * @brief trigger one or more i2c transactions
797 */
798struct cmd_i2c_xfer_request {
799	/** @brief valid bus number from mach-t186/i2c-t186.h*/
800	uint32_t bus_id;
801
802	/** @brief count of valid bytes in #data_buf*/
803	uint32_t data_size;
804
805	/** @brief serialized packed instances of @ref serial_i2c_request*/
806	uint8_t data_buf[TEGRA_I2C_IPC_MAX_IN_BUF_SIZE];
807} __ABI_PACKED;
808
809/**
810 * @ingroup I2C
811 * @brief container for data read from the i2c bus
812 *
813 * Processing an cmd_i2c_xfer_request::data_buf causes BPMP to execute
814 * zero or more I2C reads. The data read from the bus is serialized
815 * into #data_buf.
816 */
817struct cmd_i2c_xfer_response {
818	/** @brief count of valid bytes in #data_buf*/
819	uint32_t data_size;
820	/** @brief i2c read data */
821	uint8_t data_buf[TEGRA_I2C_IPC_MAX_OUT_BUF_SIZE];
822} __ABI_PACKED;
823
824/**
825 * @ingroup I2C
826 * @brief request with #MRQ_I2C
827 */
828struct mrq_i2c_request {
829	/** @brief always CMD_I2C_XFER (i.e. 1) */
830	uint32_t cmd;
831	/** @brief parameters of the transfer request */
832	struct cmd_i2c_xfer_request xfer;
833} __ABI_PACKED;
834
835/**
836 * @ingroup I2C
837 * @brief response to #MRQ_I2C
838 */
839struct mrq_i2c_response {
840	struct cmd_i2c_xfer_response xfer;
841} __ABI_PACKED;
842
843/**
844 * @ingroup MRQ_Codes
845 * @def MRQ_CLK
846 *
847 * * Platforms: T186
848 * * Initiators: Any
849 * * Targets: BPMP
850 * * Request Payload: @ref mrq_clk_request
851 * * Response Payload: @ref mrq_clk_response
852 * @addtogroup Clocks
853 * @{
854 */
855
856/**
857 * @name MRQ_CLK sub-commands
858 * @{
859 */
860enum {
861	CMD_CLK_GET_RATE = 1,
862	CMD_CLK_SET_RATE = 2,
863	CMD_CLK_ROUND_RATE = 3,
864	CMD_CLK_GET_PARENT = 4,
865	CMD_CLK_SET_PARENT = 5,
866	CMD_CLK_IS_ENABLED = 6,
867	CMD_CLK_ENABLE = 7,
868	CMD_CLK_DISABLE = 8,
869	CMD_CLK_GET_ALL_INFO = 14,
870	CMD_CLK_GET_MAX_CLK_ID = 15,
871	CMD_CLK_MAX,
872};
873/** @} */
874
875#define MRQ_CLK_NAME_MAXLEN	40
876#define MRQ_CLK_MAX_PARENTS	16
877
878/** @private */
879struct cmd_clk_get_rate_request {
880	EMPTY
881} __ABI_PACKED;
882
883struct cmd_clk_get_rate_response {
884	int64_t rate;
885} __ABI_PACKED;
886
887struct cmd_clk_set_rate_request {
888	int32_t unused;
889	int64_t rate;
890} __ABI_PACKED;
891
892struct cmd_clk_set_rate_response {
893	int64_t rate;
894} __ABI_PACKED;
895
896struct cmd_clk_round_rate_request {
897	int32_t unused;
898	int64_t rate;
899} __ABI_PACKED;
900
901struct cmd_clk_round_rate_response {
902	int64_t rate;
903} __ABI_PACKED;
904
905/** @private */
906struct cmd_clk_get_parent_request {
907	EMPTY
908} __ABI_PACKED;
909
910struct cmd_clk_get_parent_response {
911	uint32_t parent_id;
912} __ABI_PACKED;
913
914struct cmd_clk_set_parent_request {
915	uint32_t parent_id;
916} __ABI_PACKED;
917
918struct cmd_clk_set_parent_response {
919	uint32_t parent_id;
920} __ABI_PACKED;
921
922/** @private */
923struct cmd_clk_is_enabled_request {
924	EMPTY
925} __ABI_PACKED;
926
927struct cmd_clk_is_enabled_response {
928	int32_t state;
929} __ABI_PACKED;
930
931/** @private */
932struct cmd_clk_enable_request {
933	EMPTY
934} __ABI_PACKED;
935
936/** @private */
937struct cmd_clk_enable_response {
938	EMPTY
939} __ABI_PACKED;
940
941/** @private */
942struct cmd_clk_disable_request {
943	EMPTY
944} __ABI_PACKED;
945
946/** @private */
947struct cmd_clk_disable_response {
948	EMPTY
949} __ABI_PACKED;
950
951/** @private */
952struct cmd_clk_get_all_info_request {
953	EMPTY
954} __ABI_PACKED;
955
956struct cmd_clk_get_all_info_response {
957	uint32_t flags;
958	uint32_t parent;
959	uint32_t parents[MRQ_CLK_MAX_PARENTS];
960	uint8_t num_parents;
961	uint8_t name[MRQ_CLK_NAME_MAXLEN];
962} __ABI_PACKED;
963
964/** @private */
965struct cmd_clk_get_max_clk_id_request {
966	EMPTY
967} __ABI_PACKED;
968
969struct cmd_clk_get_max_clk_id_response {
970	uint32_t max_id;
971} __ABI_PACKED;
972/** @} */
973
974/**
975 * @ingroup Clocks
976 * @brief request with #MRQ_CLK
977 *
978 * Used by the sender of an #MRQ_CLK message to control clocks. The
979 * clk_request is split into several sub-commands. Some sub-commands
980 * require no additional data. Others have a sub-command specific
981 * payload
982 *
983 * |sub-command                 |payload                |
984 * |----------------------------|-----------------------|
985 * |CMD_CLK_GET_RATE            |-                      |
986 * |CMD_CLK_SET_RATE            |clk_set_rate           |
987 * |CMD_CLK_ROUND_RATE          |clk_round_rate         |
988 * |CMD_CLK_GET_PARENT          |-                      |
989 * |CMD_CLK_SET_PARENT          |clk_set_parent         |
990 * |CMD_CLK_IS_ENABLED          |-                      |
991 * |CMD_CLK_ENABLE              |-                      |
992 * |CMD_CLK_DISABLE             |-                      |
993 * |CMD_CLK_GET_ALL_INFO        |-                      |
994 * |CMD_CLK_GET_MAX_CLK_ID      |-                      |
995 *
996 */
997
998struct mrq_clk_request {
999	/** @brief sub-command and clock id concatenated to 32-bit word.
1000	 * - bits[31..24] is the sub-cmd.
1001	 * - bits[23..0] is the clock id
1002	 */
1003	uint32_t cmd_and_id;
1004
1005	union {
1006		/** @private */
1007		struct cmd_clk_get_rate_request clk_get_rate;
1008		struct cmd_clk_set_rate_request clk_set_rate;
1009		struct cmd_clk_round_rate_request clk_round_rate;
1010		/** @private */
1011		struct cmd_clk_get_parent_request clk_get_parent;
1012		struct cmd_clk_set_parent_request clk_set_parent;
1013		/** @private */
1014		struct cmd_clk_enable_request clk_enable;
1015		/** @private */
1016		struct cmd_clk_disable_request clk_disable;
1017		/** @private */
1018		struct cmd_clk_is_enabled_request clk_is_enabled;
1019		/** @private */
1020		struct cmd_clk_get_all_info_request clk_get_all_info;
1021		/** @private */
1022		struct cmd_clk_get_max_clk_id_request clk_get_max_clk_id;
1023	} __UNION_ANON;
1024} __ABI_PACKED;
1025
1026/**
1027 * @ingroup Clocks
1028 * @brief response to MRQ_CLK
1029 *
1030 * Each sub-command supported by @ref mrq_clk_request may return
1031 * sub-command-specific data. Some do and some do not as indicated in
1032 * the following table
1033 *
1034 * |sub-command                 |payload                 |
1035 * |----------------------------|------------------------|
1036 * |CMD_CLK_GET_RATE            |clk_get_rate            |
1037 * |CMD_CLK_SET_RATE            |clk_set_rate            |
1038 * |CMD_CLK_ROUND_RATE          |clk_round_rate          |
1039 * |CMD_CLK_GET_PARENT          |clk_get_parent          |
1040 * |CMD_CLK_SET_PARENT          |clk_set_parent          |
1041 * |CMD_CLK_IS_ENABLED          |clk_is_enabled          |
1042 * |CMD_CLK_ENABLE              |-                       |
1043 * |CMD_CLK_DISABLE             |-                       |
1044 * |CMD_CLK_GET_ALL_INFO        |clk_get_all_info        |
1045 * |CMD_CLK_GET_MAX_CLK_ID      |clk_get_max_id          |
1046 *
1047 */
1048
1049struct mrq_clk_response {
1050	union {
1051		struct cmd_clk_get_rate_response clk_get_rate;
1052		struct cmd_clk_set_rate_response clk_set_rate;
1053		struct cmd_clk_round_rate_response clk_round_rate;
1054		struct cmd_clk_get_parent_response clk_get_parent;
1055		struct cmd_clk_set_parent_response clk_set_parent;
1056		/** @private */
1057		struct cmd_clk_enable_response clk_enable;
1058		/** @private */
1059		struct cmd_clk_disable_response clk_disable;
1060		struct cmd_clk_is_enabled_response clk_is_enabled;
1061		struct cmd_clk_get_all_info_response clk_get_all_info;
1062		struct cmd_clk_get_max_clk_id_response clk_get_max_clk_id;
1063	} __UNION_ANON;
1064} __ABI_PACKED;
1065
1066/**
1067 * @ingroup MRQ_Codes
1068 * @def MRQ_QUERY_ABI
1069 * @brief check if an MRQ is implemented
1070 *
1071 * * Platforms: All
1072 * * Initiators: Any
1073 * * Targets: Any
1074 * * Request Payload: @ref mrq_query_abi_request
1075 * * Response Payload: @ref mrq_query_abi_response
1076 */
1077
1078/**
1079 * @ingroup ABI_info
1080 * @brief request with MRQ_QUERY_ABI
1081 *
1082 * Used by #MRQ_QUERY_ABI call to check if MRQ code #mrq is supported
1083 * by the recipient.
1084 */
1085struct mrq_query_abi_request {
1086	/** @brief MRQ code to query */
1087	uint32_t mrq;
1088} __ABI_PACKED;
1089
1090/**
1091 * @ingroup ABI_info
1092 * @brief response to MRQ_QUERY_ABI
1093 */
1094struct mrq_query_abi_response {
1095	/** @brief 0 if queried MRQ is supported. Else, -#BPMP_ENODEV */
1096	int32_t status;
1097} __ABI_PACKED;
1098
1099/**
1100 * @ingroup MRQ_Codes
1101 * @def MRQ_PG_READ_STATE
1102 * @brief read the power-gating state of a partition
1103 *
1104 * * Platforms: T186
1105 * * Initiators: Any
1106 * * Targets: BPMP
1107 * * Request Payload: @ref mrq_pg_read_state_request
1108 * * Response Payload: @ref mrq_pg_read_state_response
1109 * @addtogroup Powergating
1110 * @{
1111 */
1112
1113/**
1114 * @brief request with #MRQ_PG_READ_STATE
1115 *
1116 * Used by MRQ_PG_READ_STATE call to read the current state of a
1117 * partition.
1118 */
1119struct mrq_pg_read_state_request {
1120	/** @brief ID of partition */
1121	uint32_t partition_id;
1122} __ABI_PACKED;
1123
1124/**
1125 * @brief response to MRQ_PG_READ_STATE
1126 * @todo define possible errors.
1127 */
1128struct mrq_pg_read_state_response {
1129	/** @brief read as don't care */
1130	uint32_t sram_state;
1131	/** @brief state of power partition
1132	 * * 0 : off
1133	 * * 1 : on
1134	 */
1135	uint32_t logic_state;
1136} __ABI_PACKED;
1137
1138/** @} */
1139
1140/**
1141 * @ingroup MRQ_Codes
1142 * @def MRQ_PG_UPDATE_STATE
1143 * @brief modify the power-gating state of a partition
1144 *
1145 * * Platforms: T186
1146 * * Initiators: Any
1147 * * Targets: BPMP
1148 * * Request Payload: @ref mrq_pg_update_state_request
1149 * * Response Payload: N/A
1150 * @addtogroup Powergating
1151 * @{
1152 */
1153
1154/**
1155 * @brief request with mrq_pg_update_state_request
1156 *
1157 * Used by #MRQ_PG_UPDATE_STATE call to request BPMP to change the
1158 * state of a power partition #partition_id.
1159 */
1160struct mrq_pg_update_state_request {
1161	/** @brief ID of partition */
1162	uint32_t partition_id;
1163	/** @brief secondary control of power partition
1164	 *  @details Ignored by many versions of the BPMP
1165	 *  firmware. For maximum compatibility, set the value
1166	 *  according to @logic_state
1167	 * *  0x1: power ON partition (@ref logic_state == 0x3)
1168	 * *  0x3: power OFF partition (@ref logic_state == 0x1)
1169	 */
1170	uint32_t sram_state;
1171	/** @brief controls state of power partition, legal values are
1172	 * *  0x1 : power OFF partition
1173	 * *  0x3 : power ON partition
1174	 */
1175	uint32_t logic_state;
1176	/** @brief change state of clocks of the power partition, legal values
1177	 * *  0x0 : do not change clock state
1178	 * *  0x1 : disable partition clocks (only applicable when
1179	 *          @ref logic_state == 0x1)
1180	 * *  0x3 : enable partition clocks (only applicable when
1181	 *          @ref logic_state == 0x3)
1182	 */
1183	uint32_t clock_state;
1184} __ABI_PACKED;
1185/** @} */
1186
1187/**
1188 * @ingroup MRQ_Codes
1189 * @def MRQ_THERMAL
1190 * @brief interact with BPMP thermal framework
1191 *
1192 * * Platforms: T186
1193 * * Initiators: Any
1194 * * Targets: Any
1195 * * Request Payload: TODO
1196 * * Response Payload: TODO
1197 *
1198 * @addtogroup Thermal
1199 *
1200 * The BPMP firmware includes a thermal framework. Drivers within the
1201 * bpmp firmware register with the framework to provide thermal
1202 * zones. Each thermal zone corresponds to an entity whose temperature
1203 * can be measured. The framework also has a notion of trip points. A
1204 * trip point consists of a thermal zone id, a temperature, and a
1205 * callback routine. The framework invokes the callback when the zone
1206 * hits the indicated temperature. The BPMP firmware uses this thermal
1207 * framework interally to implement various temperature-dependent
1208 * functions.
1209 *
1210 * Software on the CPU can use #MRQ_THERMAL (with payload @ref
1211 * mrq_thermal_host_to_bpmp_request) to interact with the BPMP thermal
1212 * framework. The CPU must It can query the number of supported zones,
1213 * query zone temperatures, and set trip points.
1214 *
1215 * When a trip point set by the CPU gets crossed, BPMP firmware issues
1216 * an IPC to the CPU having mrq_request::mrq = #MRQ_THERMAL and a
1217 * payload of @ref mrq_thermal_bpmp_to_host_request.
1218 * @{
1219 */
1220enum mrq_thermal_host_to_bpmp_cmd {
1221	/**
1222	 * @brief Check whether the BPMP driver supports the specified
1223	 * request type.
1224	 *
1225	 * Host needs to supply request parameters.
1226	 *
1227	 * mrq_response::err is 0 if the specified request is
1228	 * supported and -#BPMP_ENODEV otherwise.
1229	 */
1230	CMD_THERMAL_QUERY_ABI = 0,
1231
1232	/**
1233	 * @brief Get the current temperature of the specified zone.
1234	 *
1235	 * Host needs to supply request parameters.
1236	 *
1237	 * mrq_response::err is
1238	 * *  0: Temperature query succeeded.
1239	 * *  -#BPMP_EINVAL: Invalid request parameters.
1240	 * *  -#BPMP_ENOENT: No driver registered for thermal zone..
1241	 * *  -#BPMP_EFAULT: Problem reading temperature measurement.
1242	 */
1243	CMD_THERMAL_GET_TEMP = 1,
1244
1245	/**
1246	 * @brief Enable or disable and set the lower and upper
1247	 *   thermal limits for a thermal trip point. Each zone has
1248	 *   one trip point.
1249	 *
1250	 * Host needs to supply request parameters. Once the
1251	 * temperature hits a trip point, the BPMP will send a message
1252	 * to the CPU having MRQ=MRQ_THERMAL and
1253	 * type=CMD_THERMAL_HOST_TRIP_REACHED
1254	 *
1255	 * mrq_response::err is
1256	 * *  0: Trip successfully set.
1257	 * *  -#BPMP_EINVAL: Invalid request parameters.
1258	 * *  -#BPMP_ENOENT: No driver registered for thermal zone.
1259	 * *  -#BPMP_EFAULT: Problem setting trip point.
1260	 */
1261	CMD_THERMAL_SET_TRIP = 2,
1262
1263	/**
1264	 * @brief Get the number of supported thermal zones.
1265	 *
1266	 * No request parameters required.
1267	 *
1268	 * mrq_response::err is always 0, indicating success.
1269	 */
1270	CMD_THERMAL_GET_NUM_ZONES = 3,
1271
1272	/** @brief: number of supported host-to-bpmp commands. May
1273	 * increase in future
1274	 */
1275	CMD_THERMAL_HOST_TO_BPMP_NUM
1276};
1277
1278enum mrq_thermal_bpmp_to_host_cmd {
1279	/**
1280	 * @brief Indication that the temperature for a zone has
1281	 *   exceeded the range indicated in the thermal trip point
1282	 *   for the zone.
1283	 *
1284	 * BPMP needs to supply request parameters. Host only needs to
1285	 * acknowledge.
1286	 */
1287	CMD_THERMAL_HOST_TRIP_REACHED = 100,
1288
1289	/** @brief: number of supported bpmp-to-host commands. May
1290	 * increase in future
1291	 */
1292	CMD_THERMAL_BPMP_TO_HOST_NUM
1293};
1294
1295/*
1296 * Host->BPMP request data for request type CMD_THERMAL_QUERY_ABI
1297 *
1298 * zone: Request type for which to check existence.
1299 */
1300struct cmd_thermal_query_abi_request {
1301	uint32_t type;
1302} __ABI_PACKED;
1303
1304/*
1305 * Host->BPMP request data for request type CMD_THERMAL_GET_TEMP
1306 *
1307 * zone: Number of thermal zone.
1308 */
1309struct cmd_thermal_get_temp_request {
1310	uint32_t zone;
1311} __ABI_PACKED;
1312
1313/*
1314 * BPMP->Host reply data for request CMD_THERMAL_GET_TEMP
1315 *
1316 * error: 0 if request succeeded.
1317 *	-BPMP_EINVAL if request parameters were invalid.
1318 *      -BPMP_ENOENT if no driver was registered for the specified thermal zone.
1319 *      -BPMP_EFAULT for other thermal zone driver errors.
1320 * temp: Current temperature in millicelsius.
1321 */
1322struct cmd_thermal_get_temp_response {
1323	int32_t temp;
1324} __ABI_PACKED;
1325
1326/*
1327 * Host->BPMP request data for request type CMD_THERMAL_SET_TRIP
1328 *
1329 * zone: Number of thermal zone.
1330 * low: Temperature of lower trip point in millicelsius
1331 * high: Temperature of upper trip point in millicelsius
1332 * enabled: 1 to enable trip point, 0 to disable trip point
1333 */
1334struct cmd_thermal_set_trip_request {
1335	uint32_t zone;
1336	int32_t low;
1337	int32_t high;
1338	uint32_t enabled;
1339} __ABI_PACKED;
1340
1341/*
1342 * BPMP->Host request data for request type CMD_THERMAL_HOST_TRIP_REACHED
1343 *
1344 * zone: Number of thermal zone where trip point was reached.
1345 */
1346struct cmd_thermal_host_trip_reached_request {
1347	uint32_t zone;
1348} __ABI_PACKED;
1349
1350/*
1351 * BPMP->Host reply data for request type CMD_THERMAL_GET_NUM_ZONES
1352 *
1353 * num: Number of supported thermal zones. The thermal zones are indexed
1354 *      starting from zero.
1355 */
1356struct cmd_thermal_get_num_zones_response {
1357	uint32_t num;
1358} __ABI_PACKED;
1359
1360/*
1361 * Host->BPMP request data.
1362 *
1363 * Reply type is union mrq_thermal_bpmp_to_host_response.
1364 *
1365 * type: Type of request. Values listed in enum mrq_thermal_type.
1366 * data: Request type specific parameters.
1367 */
1368struct mrq_thermal_host_to_bpmp_request {
1369	uint32_t type;
1370	union {
1371		struct cmd_thermal_query_abi_request query_abi;
1372		struct cmd_thermal_get_temp_request get_temp;
1373		struct cmd_thermal_set_trip_request set_trip;
1374	} __UNION_ANON;
1375} __ABI_PACKED;
1376
1377/*
1378 * BPMP->Host request data.
1379 *
1380 * type: Type of request. Values listed in enum mrq_thermal_type.
1381 * data: Request type specific parameters.
1382 */
1383struct mrq_thermal_bpmp_to_host_request {
1384	uint32_t type;
1385	union {
1386		struct cmd_thermal_host_trip_reached_request host_trip_reached;
1387	} __UNION_ANON;
1388} __ABI_PACKED;
1389
1390/*
1391 * Data in reply to a Host->BPMP request.
1392 */
1393union mrq_thermal_bpmp_to_host_response {
1394	struct cmd_thermal_get_temp_response get_temp;
1395	struct cmd_thermal_get_num_zones_response get_num_zones;
1396} __ABI_PACKED;
1397/** @} */
1398
1399/**
1400 * @ingroup MRQ_Codes
1401 * @def MRQ_CPU_VHINT
1402 * @brief Query CPU voltage hint data
1403 *
1404 * * Platforms: T186
1405 * * Initiators: CCPLEX
1406 * * Targets: BPMP
1407 * * Request Payload: @ref mrq_cpu_vhint_request
1408 * * Response Payload: N/A
1409 *
1410 * @addtogroup Vhint CPU Voltage hint
1411 * @{
1412 */
1413
1414/**
1415 * @brief request with #MRQ_CPU_VHINT
1416 *
1417 * Used by #MRQ_CPU_VHINT call by CCPLEX to retrieve voltage hint data
1418 * from BPMP to memory space pointed by #addr. CCPLEX is responsible
1419 * to allocate sizeof(cpu_vhint_data) sized block of memory and
1420 * appropriately map it for BPMP before sending the request.
1421 */
1422struct mrq_cpu_vhint_request {
1423	/** @brief IOVA address for the #cpu_vhint_data */
1424	uint32_t addr; /* struct cpu_vhint_data * */
1425	/** @brief ID of the cluster whose data is requested */
1426	uint32_t cluster_id; /* enum cluster_id */
1427} __ABI_PACKED;
1428
1429/**
1430 * @brief description of the CPU v/f relation
1431 *
1432 * Used by #MRQ_CPU_VHINT call to carry data pointed by #addr of
1433 * struct mrq_cpu_vhint_request
1434 */
1435struct cpu_vhint_data {
1436	uint32_t ref_clk_hz; /**< reference frequency in Hz */
1437	uint16_t pdiv; /**< post divider value */
1438	uint16_t mdiv; /**< input divider value */
1439	uint16_t ndiv_max; /**< fMAX expressed with max NDIV value */
1440	/** table of ndiv values as a function of vINDEX (voltage index) */
1441	uint16_t ndiv[80];
1442	/** minimum allowed NDIV value */
1443	uint16_t ndiv_min;
1444	/** minimum allowed voltage hint value (as in vINDEX) */
1445	uint16_t vfloor;
1446	/** maximum allowed voltage hint value (as in vINDEX) */
1447	uint16_t vceil;
1448	/** post-multiplier for vindex value */
1449	uint16_t vindex_mult;
1450	/** post-divider for vindex value */
1451	uint16_t vindex_div;
1452	/** reserved for future use */
1453	uint16_t reserved[328];
1454} __ABI_PACKED;
1455
1456/** @} */
1457
1458/**
1459 * @ingroup MRQ_Codes
1460 * @def MRQ_ABI_RATCHET
1461 * @brief ABI ratchet value query
1462 *
1463 * * Platforms: T186
1464 * * Initiators: Any
1465 * * Targets: BPMP
1466 * * Request Payload: @ref mrq_abi_ratchet_request
1467 * * Response Payload: @ref mrq_abi_ratchet_response
1468 * @addtogroup ABI_info
1469 * @{
1470 */
1471
1472/**
1473 * @brief an ABI compatibility mechanism
1474 *
1475 * BPMP_ABI_RATCHET_VALUE may increase for various reasons in a future
1476 * revision of this header file.
1477 * 1. That future revision deprecates some MRQ
1478 * 2. That future revision introduces a breaking change to an existing
1479 *    MRQ or
1480 * 3. A bug is discovered in an existing implementation of the BPMP-FW
1481 *    (or possibly one of its clients) which warrants deprecating that
1482 *    implementation.
1483 */
1484#define BPMP_ABI_RATCHET_VALUE 3
1485
1486/**
1487 * @brief request with #MRQ_ABI_RATCHET.
1488 *
1489 * #ratchet should be #BPMP_ABI_RATCHET_VALUE from the ABI header
1490 * against which the requester was compiled.
1491 *
1492 * If ratchet is less than BPMP's #BPMP_ABI_RATCHET_VALUE, BPMP may
1493 * reply with mrq_response::err = -#BPMP_ERANGE to indicate that
1494 * BPMP-FW cannot interoperate correctly with the requester. Requester
1495 * should cease further communication with BPMP.
1496 *
1497 * Otherwise, err shall be 0.
1498 */
1499struct mrq_abi_ratchet_request {
1500	/** @brief requester's ratchet value */
1501	uint16_t ratchet;
1502};
1503
1504/**
1505 * @brief response to #MRQ_ABI_RATCHET
1506 *
1507 * #ratchet shall be #BPMP_ABI_RATCHET_VALUE from the ABI header
1508 * against which BPMP firwmare was compiled.
1509 *
1510 * If #ratchet is less than the requester's #BPMP_ABI_RATCHET_VALUE,
1511 * the requster must either interoperate with BPMP according to an ABI
1512 * header version with BPMP_ABI_RATCHET_VALUE = ratchet or cease
1513 * communication with BPMP.
1514 *
1515 * If mrq_response::err is 0 and ratchet is greater than or equal to the
1516 * requester's BPMP_ABI_RATCHET_VALUE, the requester should continue
1517 * normal operation.
1518 */
1519struct mrq_abi_ratchet_response {
1520	/** @brief BPMP's ratchet value */
1521	uint16_t ratchet;
1522};
1523/** @} */
1524
1525/**
1526 * @ingroup MRQ_Codes
1527 * @def MRQ_EMC_DVFS_LATENCY
1528 * @brief query frequency dependent EMC DVFS latency
1529 *
1530 * * Platforms: T186
1531 * * Initiators: CCPLEX
1532 * * Targets: BPMP
1533 * * Request Payload: N/A
1534 * * Response Payload: @ref mrq_emc_dvfs_latency_response
1535 * @addtogroup EMC
1536 * @{
1537 */
1538
1539/**
1540 * @brief used by @ref mrq_emc_dvfs_latency_response
1541 */
1542struct emc_dvfs_latency {
1543	/** @brief EMC frequency in kHz */
1544	uint32_t freq;
1545	/** @brief EMC DVFS latency in nanoseconds */
1546	uint32_t latency;
1547} __ABI_PACKED;
1548
1549#define EMC_DVFS_LATENCY_MAX_SIZE	14
1550/**
1551 * @brief response to #MRQ_EMC_DVFS_LATENCY
1552 */
1553struct mrq_emc_dvfs_latency_response {
1554	/** @brief the number valid entries in #pairs */
1555	uint32_t num_pairs;
1556	/** @brief EMC <frequency, latency> information */
1557	struct emc_dvfs_latency pairs[EMC_DVFS_LATENCY_MAX_SIZE];
1558} __ABI_PACKED;
1559
1560/** @} */
1561
1562/**
1563 * @ingroup MRQ_Codes
1564 * @def MRQ_TRACE_ITER
1565 * @brief manage the trace iterator
1566 *
1567 * * Platforms: All
1568 * * Initiators: CCPLEX
1569 * * Targets: BPMP
1570 * * Request Payload: N/A
1571 * * Response Payload: @ref mrq_trace_iter_request
1572 * @addtogroup Trace
1573 * @{
1574 */
1575enum {
1576	/** @brief (re)start the tracing now. Ignore older events */
1577	TRACE_ITER_INIT = 0,
1578	/** @brief clobber all events in the trace buffer */
1579	TRACE_ITER_CLEAN = 1
1580};
1581
1582/**
1583 * @brief request with #MRQ_TRACE_ITER
1584 */
1585struct mrq_trace_iter_request {
1586	/** @brief TRACE_ITER_INIT or TRACE_ITER_CLEAN */
1587	uint32_t cmd;
1588} __ABI_PACKED;
1589
1590/** @} */
1591
1592/*
1593 *  4. Enumerations
1594 */
1595
1596/*
1597 *   4.1 CPU enumerations
1598 *
1599 * See <mach-t186/system-t186.h>
1600 *
1601 *   4.2 CPU Cluster enumerations
1602 *
1603 * See <mach-t186/system-t186.h>
1604 *
1605 *   4.3 System low power state enumerations
1606 *
1607 * See <mach-t186/system-t186.h>
1608 */
1609
1610/*
1611 *   4.4 Clock enumerations
1612 *
1613 * For clock enumerations, see <mach-t186/clk-t186.h>
1614 */
1615
1616/*
1617 *   4.5 Reset enumerations
1618 *
1619 * For reset enumerations, see <mach-t186/reset-t186.h>
1620 */
1621
1622/*
1623 *   4.6 Thermal sensor enumerations
1624 *
1625 * For thermal sensor enumerations, see <mach-t186/thermal-t186.h>
1626 */
1627
1628/**
1629 * @defgroup Error_Codes
1630 * Negative values for mrq_response::err generally indicate some
1631 * error. The ABI defines the following error codes. Negating these
1632 * defines is an exercise left to the user.
1633 * @{
1634 */
1635/** @brief No such file or directory */
1636#define BPMP_ENOENT	2
1637/** @brief No MRQ handler */
1638#define BPMP_ENOHANDLER	3
1639/** @brief I/O error */
1640#define BPMP_EIO	5
1641/** @brief Bad sub-MRQ command */
1642#define BPMP_EBADCMD	6
1643/** @brief Not enough memory */
1644#define BPMP_ENOMEM	12
1645/** @brief Permission denied */
1646#define BPMP_EACCES	13
1647/** @brief Bad address */
1648#define BPMP_EFAULT	14
1649/** @brief No such device */
1650#define BPMP_ENODEV	19
1651/** @brief Argument is a directory */
1652#define BPMP_EISDIR	21
1653/** @brief Invalid argument */
1654#define BPMP_EINVAL	22
1655/** @brief Timeout during operation */
1656#define BPMP_ETIMEDOUT  23
1657/** @brief Out of range */
1658#define BPMP_ERANGE	34
1659/** @} */
1660/** @} */
1661#endif
1662