1 /*
2  * Copyright 2019 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #ifndef _DMUB_SRV_H_
27 #define _DMUB_SRV_H_
28 
29 /**
30  * DOC: DMUB interface and operation
31  *
32  * DMUB is the interface to the display DMCUB microcontroller on DCN hardware.
33  * It delegates hardware initialization and command submission to the
34  * microcontroller. DMUB is the shortname for DMCUB.
35  *
36  * This interface is not thread-safe. Ensure that all access to the interface
37  * is properly synchronized by the caller.
38  *
39  * Initialization and usage of the DMUB service should be done in the
40  * steps given below:
41  *
42  * 1. dmub_srv_create()
43  * 2. dmub_srv_has_hw_support()
44  * 3. dmub_srv_calc_region_info()
45  * 4. dmub_srv_hw_init()
46  *
47  * The call to dmub_srv_create() is required to use the server.
48  *
49  * The calls to dmub_srv_has_hw_support() and dmub_srv_calc_region_info()
50  * are helpers to query cache window size and allocate framebuffer(s)
51  * for the cache windows.
52  *
53  * The call to dmub_srv_hw_init() programs the DMCUB registers to prepare
54  * for command submission. Commands can be queued via dmub_srv_cmd_queue()
55  * and executed via dmub_srv_cmd_execute().
56  *
57  * If the queue is full the dmub_srv_wait_for_idle() call can be used to
58  * wait until the queue has been cleared.
59  *
60  * Destroying the DMUB service can be done by calling dmub_srv_destroy().
61  * This does not clear DMUB hardware state, only software state.
62  *
63  * The interface is intended to be standalone and should not depend on any
64  * other component within DAL.
65  */
66 
67 #include "inc/dmub_cmd.h"
68 
69 #if defined(__cplusplus)
70 extern "C" {
71 #endif
72 
73 /* Forward declarations */
74 struct dmub_srv;
75 struct dmub_srv_common_regs;
76 struct dmub_srv_dcn31_regs;
77 
78 struct dmcub_trace_buf_entry;
79 
80 /* enum dmub_status - return code for dmcub functions */
81 enum dmub_status {
82 	DMUB_STATUS_OK = 0,
83 	DMUB_STATUS_NO_CTX,
84 	DMUB_STATUS_QUEUE_FULL,
85 	DMUB_STATUS_TIMEOUT,
86 	DMUB_STATUS_INVALID,
87 	DMUB_STATUS_HW_FAILURE,
88 };
89 
90 /* enum dmub_asic - dmub asic identifier */
91 enum dmub_asic {
92 	DMUB_ASIC_NONE = 0,
93 	DMUB_ASIC_DCN20,
94 	DMUB_ASIC_DCN21,
95 	DMUB_ASIC_DCN30,
96 	DMUB_ASIC_DCN301,
97 	DMUB_ASIC_DCN302,
98 	DMUB_ASIC_DCN303,
99 	DMUB_ASIC_DCN31,
100 	DMUB_ASIC_DCN31B,
101 	DMUB_ASIC_MAX,
102 };
103 
104 /* enum dmub_window_id - dmub window identifier */
105 enum dmub_window_id {
106 	DMUB_WINDOW_0_INST_CONST = 0,
107 	DMUB_WINDOW_1_STACK,
108 	DMUB_WINDOW_2_BSS_DATA,
109 	DMUB_WINDOW_3_VBIOS,
110 	DMUB_WINDOW_4_MAILBOX,
111 	DMUB_WINDOW_5_TRACEBUFF,
112 	DMUB_WINDOW_6_FW_STATE,
113 	DMUB_WINDOW_7_SCRATCH_MEM,
114 	DMUB_WINDOW_TOTAL,
115 };
116 
117 /* enum dmub_notification_type - dmub outbox notification identifier */
118 enum dmub_notification_type {
119 	DMUB_NOTIFICATION_NO_DATA = 0,
120 	DMUB_NOTIFICATION_AUX_REPLY,
121 	DMUB_NOTIFICATION_HPD,
122 	DMUB_NOTIFICATION_HPD_IRQ,
123 	DMUB_NOTIFICATION_SET_CONFIG_REPLY,
124 	DMUB_NOTIFICATION_MAX
125 };
126 
127 /**
128  * struct dmub_region - dmub hw memory region
129  * @base: base address for region, must be 256 byte aligned
130  * @top: top address for region
131  */
132 struct dmub_region {
133 	uint32_t base;
134 	uint32_t top;
135 };
136 
137 /**
138  * struct dmub_window - dmub hw cache window
139  * @off: offset to the fb memory in gpu address space
140  * @r: region in uc address space for cache window
141  */
142 struct dmub_window {
143 	union dmub_addr offset;
144 	struct dmub_region region;
145 };
146 
147 /**
148  * struct dmub_fb - defines a dmub framebuffer memory region
149  * @cpu_addr: cpu virtual address for the region, NULL if invalid
150  * @gpu_addr: gpu virtual address for the region, NULL if invalid
151  * @size: size of the region in bytes, zero if invalid
152  */
153 struct dmub_fb {
154 	void *cpu_addr;
155 	uint64_t gpu_addr;
156 	uint32_t size;
157 };
158 
159 /**
160  * struct dmub_srv_region_params - params used for calculating dmub regions
161  * @inst_const_size: size of the fw inst const section
162  * @bss_data_size: size of the fw bss data section
163  * @vbios_size: size of the vbios data
164  * @fw_bss_data: raw firmware bss data section
165  */
166 struct dmub_srv_region_params {
167 	uint32_t inst_const_size;
168 	uint32_t bss_data_size;
169 	uint32_t vbios_size;
170 	const uint8_t *fw_inst_const;
171 	const uint8_t *fw_bss_data;
172 };
173 
174 /**
175  * struct dmub_srv_region_info - output region info from the dmub service
176  * @fb_size: required minimum fb size for all regions, aligned to 4096 bytes
177  * @num_regions: number of regions used by the dmub service
178  * @regions: region info
179  *
180  * The regions are aligned such that they can be all placed within the
181  * same framebuffer but they can also be placed into different framebuffers.
182  *
183  * The size of each region can be calculated by the caller:
184  * size = reg.top - reg.base
185  *
186  * Care must be taken when performing custom allocations to ensure that each
187  * region base address is 256 byte aligned.
188  */
189 struct dmub_srv_region_info {
190 	uint32_t fb_size;
191 	uint8_t num_regions;
192 	struct dmub_region regions[DMUB_WINDOW_TOTAL];
193 };
194 
195 /**
196  * struct dmub_srv_fb_params - parameters used for driver fb setup
197  * @region_info: region info calculated by dmub service
198  * @cpu_addr: base cpu address for the framebuffer
199  * @gpu_addr: base gpu virtual address for the framebuffer
200  */
201 struct dmub_srv_fb_params {
202 	const struct dmub_srv_region_info *region_info;
203 	void *cpu_addr;
204 	uint64_t gpu_addr;
205 };
206 
207 /**
208  * struct dmub_srv_fb_info - output fb info from the dmub service
209  * @num_fbs: number of required dmub framebuffers
210  * @fbs: fb data for each region
211  *
212  * Output from the dmub service helper that can be used by the
213  * driver to prepare dmub_fb that can be passed into the dmub
214  * hw init service.
215  *
216  * Assumes that all regions are within the same framebuffer
217  * and have been setup according to the region_info generated
218  * by the dmub service.
219  */
220 struct dmub_srv_fb_info {
221 	uint8_t num_fb;
222 	struct dmub_fb fb[DMUB_WINDOW_TOTAL];
223 };
224 
225 /*
226  * struct dmub_srv_hw_params - params for dmub hardware initialization
227  * @fb: framebuffer info for each region
228  * @fb_base: base of the framebuffer aperture
229  * @fb_offset: offset of the framebuffer aperture
230  * @psp_version: psp version to pass for DMCU init
231  * @load_inst_const: true if DMUB should load inst const fw
232  */
233 struct dmub_srv_hw_params {
234 	struct dmub_fb *fb[DMUB_WINDOW_TOTAL];
235 	uint64_t fb_base;
236 	uint64_t fb_offset;
237 	uint32_t psp_version;
238 	bool load_inst_const;
239 	bool skip_panel_power_sequence;
240 	bool disable_z10;
241 	bool power_optimization;
242 	bool dpia_supported;
243 	bool disable_dpia;
244 };
245 
246 /**
247  * struct dmub_diagnostic_data - Diagnostic data retrieved from DMCUB for
248  * debugging purposes, including logging, crash analysis, etc.
249  */
250 struct dmub_diagnostic_data {
251 	uint32_t dmcub_version;
252 	uint32_t scratch[16];
253 	uint32_t pc;
254 	uint32_t undefined_address_fault_addr;
255 	uint32_t inst_fetch_fault_addr;
256 	uint32_t data_write_fault_addr;
257 	uint32_t inbox1_rptr;
258 	uint32_t inbox1_wptr;
259 	uint32_t inbox1_size;
260 	uint32_t inbox0_rptr;
261 	uint32_t inbox0_wptr;
262 	uint32_t inbox0_size;
263 	uint8_t is_dmcub_enabled : 1;
264 	uint8_t is_dmcub_soft_reset : 1;
265 	uint8_t is_dmcub_secure_reset : 1;
266 	uint8_t is_traceport_en : 1;
267 	uint8_t is_cw0_enabled : 1;
268 	uint8_t is_cw6_enabled : 1;
269 };
270 
271 /**
272  * struct dmub_srv_base_funcs - Driver specific base callbacks
273  */
274 struct dmub_srv_base_funcs {
275 	/**
276 	 * @reg_read:
277 	 *
278 	 * Hook for reading a register.
279 	 *
280 	 * Return: The 32-bit register value from the given address.
281 	 */
282 	uint32_t (*reg_read)(void *ctx, uint32_t address);
283 
284 	/**
285 	 * @reg_write:
286 	 *
287 	 * Hook for writing a value to the register specified by address.
288 	 */
289 	void (*reg_write)(void *ctx, uint32_t address, uint32_t value);
290 };
291 
292 /**
293  * struct dmub_srv_hw_funcs - hardware sequencer funcs for dmub
294  */
295 struct dmub_srv_hw_funcs {
296 	/* private: internal use only */
297 
298 	void (*init)(struct dmub_srv *dmub);
299 
300 	void (*reset)(struct dmub_srv *dmub);
301 
302 	void (*reset_release)(struct dmub_srv *dmub);
303 
304 	void (*backdoor_load)(struct dmub_srv *dmub,
305 			      const struct dmub_window *cw0,
306 			      const struct dmub_window *cw1);
307 
308 	void (*setup_windows)(struct dmub_srv *dmub,
309 			      const struct dmub_window *cw2,
310 			      const struct dmub_window *cw3,
311 			      const struct dmub_window *cw4,
312 			      const struct dmub_window *cw5,
313 			      const struct dmub_window *cw6);
314 
315 	void (*setup_mailbox)(struct dmub_srv *dmub,
316 			      const struct dmub_region *inbox1);
317 
318 	uint32_t (*get_inbox1_rptr)(struct dmub_srv *dmub);
319 
320 	void (*set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset);
321 
322 	void (*setup_out_mailbox)(struct dmub_srv *dmub,
323 			      const struct dmub_region *outbox1);
324 
325 	uint32_t (*get_outbox1_wptr)(struct dmub_srv *dmub);
326 
327 	void (*set_outbox1_rptr)(struct dmub_srv *dmub, uint32_t rptr_offset);
328 
329 	void (*setup_outbox0)(struct dmub_srv *dmub,
330 			      const struct dmub_region *outbox0);
331 
332 	uint32_t (*get_outbox0_wptr)(struct dmub_srv *dmub);
333 
334 	void (*set_outbox0_rptr)(struct dmub_srv *dmub, uint32_t rptr_offset);
335 
336 	uint32_t (*emul_get_inbox1_rptr)(struct dmub_srv *dmub);
337 
338 	void (*emul_set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset);
339 
340 	bool (*is_supported)(struct dmub_srv *dmub);
341 
342 	bool (*is_hw_init)(struct dmub_srv *dmub);
343 
344 	bool (*is_phy_init)(struct dmub_srv *dmub);
345 	void (*enable_dmub_boot_options)(struct dmub_srv *dmub,
346 				const struct dmub_srv_hw_params *params);
347 
348 	void (*skip_dmub_panel_power_sequence)(struct dmub_srv *dmub, bool skip);
349 
350 	union dmub_fw_boot_status (*get_fw_status)(struct dmub_srv *dmub);
351 
352 
353 	void (*set_gpint)(struct dmub_srv *dmub,
354 			  union dmub_gpint_data_register reg);
355 
356 	bool (*is_gpint_acked)(struct dmub_srv *dmub,
357 			       union dmub_gpint_data_register reg);
358 
359 	uint32_t (*get_gpint_response)(struct dmub_srv *dmub);
360 
361 	uint32_t (*get_gpint_dataout)(struct dmub_srv *dmub);
362 
363 	void (*clear_inbox0_ack_register)(struct dmub_srv *dmub);
364 	uint32_t (*read_inbox0_ack_register)(struct dmub_srv *dmub);
365 	void (*send_inbox0_cmd)(struct dmub_srv *dmub, union dmub_inbox0_data_register data);
366 	uint32_t (*get_current_time)(struct dmub_srv *dmub);
367 
368 	void (*get_diagnostic_data)(struct dmub_srv *dmub, struct dmub_diagnostic_data *dmub_oca);
369 
370 	bool (*should_detect)(struct dmub_srv *dmub);
371 };
372 
373 /**
374  * struct dmub_srv_create_params - params for dmub service creation
375  * @base_funcs: driver supplied base routines
376  * @hw_funcs: optional overrides for hw funcs
377  * @user_ctx: context data for callback funcs
378  * @asic: driver supplied asic
379  * @fw_version: the current firmware version, if any
380  * @is_virtual: false for hw support only
381  */
382 struct dmub_srv_create_params {
383 	struct dmub_srv_base_funcs funcs;
384 	struct dmub_srv_hw_funcs *hw_funcs;
385 	void *user_ctx;
386 	enum dmub_asic asic;
387 	uint32_t fw_version;
388 	bool is_virtual;
389 };
390 
391 /**
392  * struct dmub_srv - software state for dmcub
393  * @asic: dmub asic identifier
394  * @user_ctx: user provided context for the dmub_srv
395  * @fw_version: the current firmware version, if any
396  * @is_virtual: false if hardware support only
397  * @fw_state: dmub firmware state pointer
398  */
399 struct dmub_srv {
400 	enum dmub_asic asic;
401 	void *user_ctx;
402 	uint32_t fw_version;
403 	bool is_virtual;
404 	struct dmub_fb scratch_mem_fb;
405 	volatile const struct dmub_fw_state *fw_state;
406 
407 	/* private: internal use only */
408 	const struct dmub_srv_common_regs *regs;
409 	const struct dmub_srv_dcn31_regs *regs_dcn31;
410 
411 	struct dmub_srv_base_funcs funcs;
412 	struct dmub_srv_hw_funcs hw_funcs;
413 	struct dmub_rb inbox1_rb;
414 	uint32_t inbox1_last_wptr;
415 	/**
416 	 * outbox1_rb is accessed without locks (dal & dc)
417 	 * and to be used only in dmub_srv_stat_get_notification()
418 	 */
419 	struct dmub_rb outbox1_rb;
420 
421 	struct dmub_rb outbox0_rb;
422 
423 	bool sw_init;
424 	bool hw_init;
425 
426 	uint64_t fb_base;
427 	uint64_t fb_offset;
428 	uint32_t psp_version;
429 
430 	/* Feature capabilities reported by fw */
431 	struct dmub_feature_caps feature_caps;
432 };
433 
434 /**
435  * struct dmub_notification - dmub notification data
436  * @type: dmub notification type
437  * @link_index: link index to identify aux connection
438  * @result: USB4 status returned from dmub
439  * @pending_notification: Indicates there are other pending notifications
440  * @aux_reply: aux reply
441  * @hpd_status: hpd status
442  */
443 struct dmub_notification {
444 	enum dmub_notification_type type;
445 	uint8_t link_index;
446 	uint8_t result;
447 	bool pending_notification;
448 	union {
449 		struct aux_reply_data aux_reply;
450 		enum dp_hpd_status hpd_status;
451 		enum set_config_status sc_status;
452 	};
453 };
454 
455 /**
456  * DMUB firmware version helper macro - useful for checking if the version
457  * of a firmware to know if feature or functionality is supported or present.
458  */
459 #define DMUB_FW_VERSION(major, minor, revision) \
460 	((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
461 
462 /**
463  * dmub_srv_create() - creates the DMUB service.
464  * @dmub: the dmub service
465  * @params: creation parameters for the service
466  *
467  * Return:
468  *   DMUB_STATUS_OK - success
469  *   DMUB_STATUS_INVALID - unspecified error
470  */
471 enum dmub_status dmub_srv_create(struct dmub_srv *dmub,
472 				 const struct dmub_srv_create_params *params);
473 
474 /**
475  * dmub_srv_destroy() - destroys the DMUB service.
476  * @dmub: the dmub service
477  */
478 void dmub_srv_destroy(struct dmub_srv *dmub);
479 
480 /**
481  * dmub_srv_calc_region_info() - retreives region info from the dmub service
482  * @dmub: the dmub service
483  * @params: parameters used to calculate region locations
484  * @info_out: the output region info from dmub
485  *
486  * Calculates the base and top address for all relevant dmub regions
487  * using the parameters given (if any).
488  *
489  * Return:
490  *   DMUB_STATUS_OK - success
491  *   DMUB_STATUS_INVALID - unspecified error
492  */
493 enum dmub_status
494 dmub_srv_calc_region_info(struct dmub_srv *dmub,
495 			  const struct dmub_srv_region_params *params,
496 			  struct dmub_srv_region_info *out);
497 
498 /**
499  * dmub_srv_calc_region_info() - retreives fb info from the dmub service
500  * @dmub: the dmub service
501  * @params: parameters used to calculate fb locations
502  * @info_out: the output fb info from dmub
503  *
504  * Calculates the base and top address for all relevant dmub regions
505  * using the parameters given (if any).
506  *
507  * Return:
508  *   DMUB_STATUS_OK - success
509  *   DMUB_STATUS_INVALID - unspecified error
510  */
511 enum dmub_status dmub_srv_calc_fb_info(struct dmub_srv *dmub,
512 				       const struct dmub_srv_fb_params *params,
513 				       struct dmub_srv_fb_info *out);
514 
515 /**
516  * dmub_srv_has_hw_support() - returns hw support state for dmcub
517  * @dmub: the dmub service
518  * @is_supported: hw support state
519  *
520  * Queries the hardware for DMCUB support and returns the result.
521  *
522  * Can be called before dmub_srv_hw_init().
523  *
524  * Return:
525  *   DMUB_STATUS_OK - success
526  *   DMUB_STATUS_INVALID - unspecified error
527  */
528 enum dmub_status dmub_srv_has_hw_support(struct dmub_srv *dmub,
529 					 bool *is_supported);
530 
531 /**
532  * dmub_srv_is_hw_init() - returns hardware init state
533  *
534  * Return:
535  *   DMUB_STATUS_OK - success
536  *   DMUB_STATUS_INVALID - unspecified error
537  */
538 enum dmub_status dmub_srv_is_hw_init(struct dmub_srv *dmub, bool *is_hw_init);
539 
540 /**
541  * dmub_srv_hw_init() - initializes the underlying DMUB hardware
542  * @dmub: the dmub service
543  * @params: params for hardware initialization
544  *
545  * Resets the DMUB hardware and performs backdoor loading of the
546  * required cache regions based on the input framebuffer regions.
547  *
548  * Return:
549  *   DMUB_STATUS_OK - success
550  *   DMUB_STATUS_NO_CTX - dmcub context not initialized
551  *   DMUB_STATUS_INVALID - unspecified error
552  */
553 enum dmub_status dmub_srv_hw_init(struct dmub_srv *dmub,
554 				  const struct dmub_srv_hw_params *params);
555 
556 /**
557  * dmub_srv_hw_reset() - puts the DMUB hardware in reset state if initialized
558  * @dmub: the dmub service
559  *
560  * Before destroying the DMUB service or releasing the backing framebuffer
561  * memory we'll need to put the DMCUB into reset first.
562  *
563  * A subsequent call to dmub_srv_hw_init() will re-enable the DMCUB.
564  *
565  * Return:
566  *   DMUB_STATUS_OK - success
567  *   DMUB_STATUS_INVALID - unspecified error
568  */
569 enum dmub_status dmub_srv_hw_reset(struct dmub_srv *dmub);
570 
571 /**
572  * dmub_srv_cmd_queue() - queues a command to the DMUB
573  * @dmub: the dmub service
574  * @cmd: the command to queue
575  *
576  * Queues a command to the DMUB service but does not begin execution
577  * immediately.
578  *
579  * Return:
580  *   DMUB_STATUS_OK - success
581  *   DMUB_STATUS_QUEUE_FULL - no remaining room in queue
582  *   DMUB_STATUS_INVALID - unspecified error
583  */
584 enum dmub_status dmub_srv_cmd_queue(struct dmub_srv *dmub,
585 				    const union dmub_rb_cmd *cmd);
586 
587 /**
588  * dmub_srv_cmd_execute() - Executes a queued sequence to the dmub
589  * @dmub: the dmub service
590  *
591  * Begins execution of queued commands on the dmub.
592  *
593  * Return:
594  *   DMUB_STATUS_OK - success
595  *   DMUB_STATUS_INVALID - unspecified error
596  */
597 enum dmub_status dmub_srv_cmd_execute(struct dmub_srv *dmub);
598 
599 /**
600  * dmub_srv_wait_for_auto_load() - Waits for firmware auto load to complete
601  * @dmub: the dmub service
602  * @timeout_us: the maximum number of microseconds to wait
603  *
604  * Waits until firmware has been autoloaded by the DMCUB. The maximum
605  * wait time is given in microseconds to prevent spinning forever.
606  *
607  * On ASICs without firmware autoload support this function will return
608  * immediately.
609  *
610  * Return:
611  *   DMUB_STATUS_OK - success
612  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
613  *   DMUB_STATUS_INVALID - unspecified error
614  */
615 enum dmub_status dmub_srv_wait_for_auto_load(struct dmub_srv *dmub,
616 					     uint32_t timeout_us);
617 
618 /**
619  * dmub_srv_wait_for_phy_init() - Waits for DMUB PHY init to complete
620  * @dmub: the dmub service
621  * @timeout_us: the maximum number of microseconds to wait
622  *
623  * Waits until the PHY has been initialized by the DMUB. The maximum
624  * wait time is given in microseconds to prevent spinning forever.
625  *
626  * On ASICs without PHY init support this function will return
627  * immediately.
628  *
629  * Return:
630  *   DMUB_STATUS_OK - success
631  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
632  *   DMUB_STATUS_INVALID - unspecified error
633  */
634 enum dmub_status dmub_srv_wait_for_phy_init(struct dmub_srv *dmub,
635 					    uint32_t timeout_us);
636 
637 /**
638  * dmub_srv_wait_for_idle() - Waits for the DMUB to be idle
639  * @dmub: the dmub service
640  * @timeout_us: the maximum number of microseconds to wait
641  *
642  * Waits until the DMUB buffer is empty and all commands have
643  * finished processing. The maximum wait time is given in
644  * microseconds to prevent spinning forever.
645  *
646  * Return:
647  *   DMUB_STATUS_OK - success
648  *   DMUB_STATUS_TIMEOUT - wait for buffer to flush timed out
649  *   DMUB_STATUS_INVALID - unspecified error
650  */
651 enum dmub_status dmub_srv_wait_for_idle(struct dmub_srv *dmub,
652 					uint32_t timeout_us);
653 
654 /**
655  * dmub_srv_send_gpint_command() - Sends a GPINT based command.
656  * @dmub: the dmub service
657  * @command_code: the command code to send
658  * @param: the command parameter to send
659  * @timeout_us: the maximum number of microseconds to wait
660  *
661  * Sends a command via the general purpose interrupt (GPINT).
662  * Waits for the number of microseconds specified by timeout_us
663  * for the command ACK before returning.
664  *
665  * Can be called after software initialization.
666  *
667  * Return:
668  *   DMUB_STATUS_OK - success
669  *   DMUB_STATUS_TIMEOUT - wait for ACK timed out
670  *   DMUB_STATUS_INVALID - unspecified error
671  */
672 enum dmub_status
673 dmub_srv_send_gpint_command(struct dmub_srv *dmub,
674 			    enum dmub_gpint_command command_code,
675 			    uint16_t param, uint32_t timeout_us);
676 
677 /**
678  * dmub_srv_get_gpint_response() - Queries the GPINT response.
679  * @dmub: the dmub service
680  * @response: the response for the last GPINT
681  *
682  * Returns the response code for the last GPINT interrupt.
683  *
684  * Can be called after software initialization.
685  *
686  * Return:
687  *   DMUB_STATUS_OK - success
688  *   DMUB_STATUS_INVALID - unspecified error
689  */
690 enum dmub_status dmub_srv_get_gpint_response(struct dmub_srv *dmub,
691 					     uint32_t *response);
692 
693 /**
694  * dmub_srv_get_gpint_dataout() - Queries the GPINT DATAOUT.
695  * @dmub: the dmub service
696  * @dataout: the data for the GPINT DATAOUT
697  *
698  * Returns the response code for the last GPINT DATAOUT interrupt.
699  *
700  * Can be called after software initialization.
701  *
702  * Return:
703  *   DMUB_STATUS_OK - success
704  *   DMUB_STATUS_INVALID - unspecified error
705  */
706 enum dmub_status dmub_srv_get_gpint_dataout(struct dmub_srv *dmub,
707 					     uint32_t *dataout);
708 
709 /**
710  * dmub_flush_buffer_mem() - Read back entire frame buffer region.
711  * This ensures that the write from x86 has been flushed and will not
712  * hang the DMCUB.
713  * @fb: frame buffer to flush
714  *
715  * Can be called after software initialization.
716  */
717 void dmub_flush_buffer_mem(const struct dmub_fb *fb);
718 
719 /**
720  * dmub_srv_get_fw_boot_status() - Returns the DMUB boot status bits.
721  *
722  * @dmub: the dmub service
723  * @status: out pointer for firmware status
724  *
725  * Return:
726  *   DMUB_STATUS_OK - success
727  *   DMUB_STATUS_INVALID - unspecified error, unsupported
728  */
729 enum dmub_status dmub_srv_get_fw_boot_status(struct dmub_srv *dmub,
730 					     union dmub_fw_boot_status *status);
731 
732 enum dmub_status dmub_srv_cmd_with_reply_data(struct dmub_srv *dmub,
733 					      union dmub_rb_cmd *cmd);
734 
735 bool dmub_srv_get_outbox0_msg(struct dmub_srv *dmub, struct dmcub_trace_buf_entry *entry);
736 
737 bool dmub_srv_get_diagnostic_data(struct dmub_srv *dmub, struct dmub_diagnostic_data *diag_data);
738 
739 bool dmub_srv_should_detect(struct dmub_srv *dmub);
740 
741 /**
742  * dmub_srv_send_inbox0_cmd() - Send command to DMUB using INBOX0
743  * @dmub: the dmub service
744  * @data: the data to be sent in the INBOX0 command
745  *
746  * Send command by writing directly to INBOX0 WPTR
747  *
748  * Return:
749  *   DMUB_STATUS_OK - success
750  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
751  */
752 enum dmub_status dmub_srv_send_inbox0_cmd(struct dmub_srv *dmub, union dmub_inbox0_data_register data);
753 
754 /**
755  * dmub_srv_wait_for_inbox0_ack() - wait for DMUB to ACK INBOX0 command
756  * @dmub: the dmub service
757  * @timeout_us: the maximum number of microseconds to wait
758  *
759  * Wait for DMUB to ACK the INBOX0 message
760  *
761  * Return:
762  *   DMUB_STATUS_OK - success
763  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
764  *   DMUB_STATUS_TIMEOUT - wait for ack timed out
765  */
766 enum dmub_status dmub_srv_wait_for_inbox0_ack(struct dmub_srv *dmub, uint32_t timeout_us);
767 
768 /**
769  * dmub_srv_wait_for_inbox0_ack() - clear ACK register for INBOX0
770  * @dmub: the dmub service
771  *
772  * Clear ACK register for INBOX0
773  *
774  * Return:
775  *   DMUB_STATUS_OK - success
776  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
777  */
778 enum dmub_status dmub_srv_clear_inbox0_ack(struct dmub_srv *dmub);
779 
780 #if defined(__cplusplus)
781 }
782 #endif
783 
784 #endif /* _DMUB_SRV_H_ */
785