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_DCN314,
102 	DMUB_ASIC_DCN315,
103 	DMUB_ASIC_DCN316,
104 	DMUB_ASIC_DCN32,
105 	DMUB_ASIC_DCN321,
106 	DMUB_ASIC_MAX,
107 };
108 
109 /* enum dmub_window_id - dmub window identifier */
110 enum dmub_window_id {
111 	DMUB_WINDOW_0_INST_CONST = 0,
112 	DMUB_WINDOW_1_STACK,
113 	DMUB_WINDOW_2_BSS_DATA,
114 	DMUB_WINDOW_3_VBIOS,
115 	DMUB_WINDOW_4_MAILBOX,
116 	DMUB_WINDOW_5_TRACEBUFF,
117 	DMUB_WINDOW_6_FW_STATE,
118 	DMUB_WINDOW_7_SCRATCH_MEM,
119 	DMUB_WINDOW_TOTAL,
120 };
121 
122 /* enum dmub_notification_type - dmub outbox notification identifier */
123 enum dmub_notification_type {
124 	DMUB_NOTIFICATION_NO_DATA = 0,
125 	DMUB_NOTIFICATION_AUX_REPLY,
126 	DMUB_NOTIFICATION_HPD,
127 	DMUB_NOTIFICATION_HPD_IRQ,
128 	DMUB_NOTIFICATION_SET_CONFIG_REPLY,
129 	DMUB_NOTIFICATION_DPIA_NOTIFICATION,
130 	DMUB_NOTIFICATION_MAX
131 };
132 
133 /**
134  * DPIA NOTIFICATION Response Type
135  */
136 enum dpia_notify_bw_alloc_status {
137 
138 	DPIA_BW_REQ_FAILED = 0,
139 	DPIA_BW_REQ_SUCCESS,
140 	DPIA_EST_BW_CHANGED,
141 	DPIA_BW_ALLOC_CAPS_CHANGED
142 };
143 
144 /**
145  * struct dmub_region - dmub hw memory region
146  * @base: base address for region, must be 256 byte aligned
147  * @top: top address for region
148  */
149 struct dmub_region {
150 	uint32_t base;
151 	uint32_t top;
152 };
153 
154 /**
155  * struct dmub_window - dmub hw cache window
156  * @off: offset to the fb memory in gpu address space
157  * @r: region in uc address space for cache window
158  */
159 struct dmub_window {
160 	union dmub_addr offset;
161 	struct dmub_region region;
162 };
163 
164 /**
165  * struct dmub_fb - defines a dmub framebuffer memory region
166  * @cpu_addr: cpu virtual address for the region, NULL if invalid
167  * @gpu_addr: gpu virtual address for the region, NULL if invalid
168  * @size: size of the region in bytes, zero if invalid
169  */
170 struct dmub_fb {
171 	void *cpu_addr;
172 	uint64_t gpu_addr;
173 	uint32_t size;
174 };
175 
176 /**
177  * struct dmub_srv_region_params - params used for calculating dmub regions
178  * @inst_const_size: size of the fw inst const section
179  * @bss_data_size: size of the fw bss data section
180  * @vbios_size: size of the vbios data
181  * @fw_bss_data: raw firmware bss data section
182  */
183 struct dmub_srv_region_params {
184 	uint32_t inst_const_size;
185 	uint32_t bss_data_size;
186 	uint32_t vbios_size;
187 	const uint8_t *fw_inst_const;
188 	const uint8_t *fw_bss_data;
189 };
190 
191 /**
192  * struct dmub_srv_region_info - output region info from the dmub service
193  * @fb_size: required minimum fb size for all regions, aligned to 4096 bytes
194  * @num_regions: number of regions used by the dmub service
195  * @regions: region info
196  *
197  * The regions are aligned such that they can be all placed within the
198  * same framebuffer but they can also be placed into different framebuffers.
199  *
200  * The size of each region can be calculated by the caller:
201  * size = reg.top - reg.base
202  *
203  * Care must be taken when performing custom allocations to ensure that each
204  * region base address is 256 byte aligned.
205  */
206 struct dmub_srv_region_info {
207 	uint32_t fb_size;
208 	uint8_t num_regions;
209 	struct dmub_region regions[DMUB_WINDOW_TOTAL];
210 };
211 
212 /**
213  * struct dmub_srv_fb_params - parameters used for driver fb setup
214  * @region_info: region info calculated by dmub service
215  * @cpu_addr: base cpu address for the framebuffer
216  * @gpu_addr: base gpu virtual address for the framebuffer
217  */
218 struct dmub_srv_fb_params {
219 	const struct dmub_srv_region_info *region_info;
220 	void *cpu_addr;
221 	uint64_t gpu_addr;
222 };
223 
224 /**
225  * struct dmub_srv_fb_info - output fb info from the dmub service
226  * @num_fbs: number of required dmub framebuffers
227  * @fbs: fb data for each region
228  *
229  * Output from the dmub service helper that can be used by the
230  * driver to prepare dmub_fb that can be passed into the dmub
231  * hw init service.
232  *
233  * Assumes that all regions are within the same framebuffer
234  * and have been setup according to the region_info generated
235  * by the dmub service.
236  */
237 struct dmub_srv_fb_info {
238 	uint8_t num_fb;
239 	struct dmub_fb fb[DMUB_WINDOW_TOTAL];
240 };
241 
242 /*
243  * struct dmub_srv_hw_params - params for dmub hardware initialization
244  * @fb: framebuffer info for each region
245  * @fb_base: base of the framebuffer aperture
246  * @fb_offset: offset of the framebuffer aperture
247  * @psp_version: psp version to pass for DMCU init
248  * @load_inst_const: true if DMUB should load inst const fw
249  */
250 struct dmub_srv_hw_params {
251 	struct dmub_fb *fb[DMUB_WINDOW_TOTAL];
252 	uint64_t fb_base;
253 	uint64_t fb_offset;
254 	uint32_t psp_version;
255 	bool load_inst_const;
256 	bool skip_panel_power_sequence;
257 	bool disable_z10;
258 	bool power_optimization;
259 	bool dpia_supported;
260 	bool disable_dpia;
261 	bool usb4_cm_version;
262 	bool fw_in_system_memory;
263 	bool dpia_hpd_int_enable_supported;
264 	bool disable_clock_gate;
265 	bool disallow_dispclk_dppclk_ds;
266 };
267 
268 /**
269  * struct dmub_diagnostic_data - Diagnostic data retrieved from DMCUB for
270  * debugging purposes, including logging, crash analysis, etc.
271  */
272 struct dmub_diagnostic_data {
273 	uint32_t dmcub_version;
274 	uint32_t scratch[17];
275 	uint32_t pc;
276 	uint32_t undefined_address_fault_addr;
277 	uint32_t inst_fetch_fault_addr;
278 	uint32_t data_write_fault_addr;
279 	uint32_t inbox1_rptr;
280 	uint32_t inbox1_wptr;
281 	uint32_t inbox1_size;
282 	uint32_t inbox0_rptr;
283 	uint32_t inbox0_wptr;
284 	uint32_t inbox0_size;
285 	uint32_t gpint_datain0;
286 	uint8_t is_dmcub_enabled : 1;
287 	uint8_t is_dmcub_soft_reset : 1;
288 	uint8_t is_dmcub_secure_reset : 1;
289 	uint8_t is_traceport_en : 1;
290 	uint8_t is_cw0_enabled : 1;
291 	uint8_t is_cw6_enabled : 1;
292 };
293 
294 /**
295  * struct dmub_srv_base_funcs - Driver specific base callbacks
296  */
297 struct dmub_srv_base_funcs {
298 	/**
299 	 * @reg_read:
300 	 *
301 	 * Hook for reading a register.
302 	 *
303 	 * Return: The 32-bit register value from the given address.
304 	 */
305 	uint32_t (*reg_read)(void *ctx, uint32_t address);
306 
307 	/**
308 	 * @reg_write:
309 	 *
310 	 * Hook for writing a value to the register specified by address.
311 	 */
312 	void (*reg_write)(void *ctx, uint32_t address, uint32_t value);
313 };
314 
315 /**
316  * struct dmub_srv_hw_funcs - hardware sequencer funcs for dmub
317  */
318 struct dmub_srv_hw_funcs {
319 	/* private: internal use only */
320 
321 	void (*init)(struct dmub_srv *dmub);
322 
323 	void (*reset)(struct dmub_srv *dmub);
324 
325 	void (*reset_release)(struct dmub_srv *dmub);
326 
327 	void (*backdoor_load)(struct dmub_srv *dmub,
328 			      const struct dmub_window *cw0,
329 			      const struct dmub_window *cw1);
330 
331 	void (*backdoor_load_zfb_mode)(struct dmub_srv *dmub,
332 			      const struct dmub_window *cw0,
333 			      const struct dmub_window *cw1);
334 	void (*setup_windows)(struct dmub_srv *dmub,
335 			      const struct dmub_window *cw2,
336 			      const struct dmub_window *cw3,
337 			      const struct dmub_window *cw4,
338 			      const struct dmub_window *cw5,
339 			      const struct dmub_window *cw6);
340 
341 	void (*setup_mailbox)(struct dmub_srv *dmub,
342 			      const struct dmub_region *inbox1);
343 
344 	uint32_t (*get_inbox1_wptr)(struct dmub_srv *dmub);
345 
346 	uint32_t (*get_inbox1_rptr)(struct dmub_srv *dmub);
347 
348 	void (*set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset);
349 
350 	void (*setup_out_mailbox)(struct dmub_srv *dmub,
351 			      const struct dmub_region *outbox1);
352 
353 	uint32_t (*get_outbox1_wptr)(struct dmub_srv *dmub);
354 
355 	void (*set_outbox1_rptr)(struct dmub_srv *dmub, uint32_t rptr_offset);
356 
357 	void (*setup_outbox0)(struct dmub_srv *dmub,
358 			      const struct dmub_region *outbox0);
359 
360 	uint32_t (*get_outbox0_wptr)(struct dmub_srv *dmub);
361 
362 	void (*set_outbox0_rptr)(struct dmub_srv *dmub, uint32_t rptr_offset);
363 
364 	uint32_t (*emul_get_inbox1_rptr)(struct dmub_srv *dmub);
365 
366 	void (*emul_set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset);
367 
368 	bool (*is_supported)(struct dmub_srv *dmub);
369 
370 	bool (*is_psrsu_supported)(struct dmub_srv *dmub);
371 
372 	bool (*is_hw_init)(struct dmub_srv *dmub);
373 
374 	void (*enable_dmub_boot_options)(struct dmub_srv *dmub,
375 				const struct dmub_srv_hw_params *params);
376 
377 	void (*skip_dmub_panel_power_sequence)(struct dmub_srv *dmub, bool skip);
378 
379 	union dmub_fw_boot_status (*get_fw_status)(struct dmub_srv *dmub);
380 
381 	union dmub_fw_boot_options (*get_fw_boot_option)(struct dmub_srv *dmub);
382 
383 	void (*set_gpint)(struct dmub_srv *dmub,
384 			  union dmub_gpint_data_register reg);
385 
386 	bool (*is_gpint_acked)(struct dmub_srv *dmub,
387 			       union dmub_gpint_data_register reg);
388 
389 	uint32_t (*get_gpint_response)(struct dmub_srv *dmub);
390 
391 	uint32_t (*get_gpint_dataout)(struct dmub_srv *dmub);
392 
393 	void (*configure_dmub_in_system_memory)(struct dmub_srv *dmub);
394 	void (*clear_inbox0_ack_register)(struct dmub_srv *dmub);
395 	uint32_t (*read_inbox0_ack_register)(struct dmub_srv *dmub);
396 	void (*send_inbox0_cmd)(struct dmub_srv *dmub, union dmub_inbox0_data_register data);
397 	uint32_t (*get_current_time)(struct dmub_srv *dmub);
398 
399 	void (*get_diagnostic_data)(struct dmub_srv *dmub, struct dmub_diagnostic_data *dmub_oca);
400 
401 	bool (*should_detect)(struct dmub_srv *dmub);
402 };
403 
404 /**
405  * struct dmub_srv_create_params - params for dmub service creation
406  * @base_funcs: driver supplied base routines
407  * @hw_funcs: optional overrides for hw funcs
408  * @user_ctx: context data for callback funcs
409  * @asic: driver supplied asic
410  * @fw_version: the current firmware version, if any
411  * @is_virtual: false for hw support only
412  */
413 struct dmub_srv_create_params {
414 	struct dmub_srv_base_funcs funcs;
415 	struct dmub_srv_hw_funcs *hw_funcs;
416 	void *user_ctx;
417 	enum dmub_asic asic;
418 	uint32_t fw_version;
419 	bool is_virtual;
420 };
421 
422 /**
423  * struct dmub_srv - software state for dmcub
424  * @asic: dmub asic identifier
425  * @user_ctx: user provided context for the dmub_srv
426  * @fw_version: the current firmware version, if any
427  * @is_virtual: false if hardware support only
428  * @fw_state: dmub firmware state pointer
429  */
430 struct dmub_srv {
431 	enum dmub_asic asic;
432 	void *user_ctx;
433 	uint32_t fw_version;
434 	bool is_virtual;
435 	struct dmub_fb scratch_mem_fb;
436 	volatile const struct dmub_fw_state *fw_state;
437 
438 	/* private: internal use only */
439 	const struct dmub_srv_common_regs *regs;
440 	const struct dmub_srv_dcn31_regs *regs_dcn31;
441 	const struct dmub_srv_dcn32_regs *regs_dcn32;
442 
443 	struct dmub_srv_base_funcs funcs;
444 	struct dmub_srv_hw_funcs hw_funcs;
445 	struct dmub_rb inbox1_rb;
446 	uint32_t inbox1_last_wptr;
447 	/**
448 	 * outbox1_rb is accessed without locks (dal & dc)
449 	 * and to be used only in dmub_srv_stat_get_notification()
450 	 */
451 	struct dmub_rb outbox1_rb;
452 
453 	struct dmub_rb outbox0_rb;
454 
455 	bool sw_init;
456 	bool hw_init;
457 
458 	uint64_t fb_base;
459 	uint64_t fb_offset;
460 	uint32_t psp_version;
461 
462 	/* Feature capabilities reported by fw */
463 	struct dmub_feature_caps feature_caps;
464 	struct dmub_visual_confirm_color visual_confirm_color;
465 };
466 
467 /**
468  * struct dmub_notification - dmub notification data
469  * @type: dmub notification type
470  * @link_index: link index to identify aux connection
471  * @result: USB4 status returned from dmub
472  * @pending_notification: Indicates there are other pending notifications
473  * @aux_reply: aux reply
474  * @hpd_status: hpd status
475  * @bw_alloc_reply: BW Allocation reply from CM/DPIA
476  */
477 struct dmub_notification {
478 	enum dmub_notification_type type;
479 	uint8_t link_index;
480 	uint8_t result;
481 	bool pending_notification;
482 	union {
483 		struct aux_reply_data aux_reply;
484 		enum dp_hpd_status hpd_status;
485 		enum set_config_status sc_status;
486 		/**
487 		 * DPIA notification command.
488 		 */
489 		struct dmub_rb_cmd_dpia_notification dpia_notification;
490 	};
491 };
492 
493 /**
494  * DMUB firmware version helper macro - useful for checking if the version
495  * of a firmware to know if feature or functionality is supported or present.
496  */
497 #define DMUB_FW_VERSION(major, minor, revision) \
498 	((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | (((revision) & 0xFF) << 8))
499 
500 /**
501  * dmub_srv_create() - creates the DMUB service.
502  * @dmub: the dmub service
503  * @params: creation parameters for the service
504  *
505  * Return:
506  *   DMUB_STATUS_OK - success
507  *   DMUB_STATUS_INVALID - unspecified error
508  */
509 enum dmub_status dmub_srv_create(struct dmub_srv *dmub,
510 				 const struct dmub_srv_create_params *params);
511 
512 /**
513  * dmub_srv_destroy() - destroys the DMUB service.
514  * @dmub: the dmub service
515  */
516 void dmub_srv_destroy(struct dmub_srv *dmub);
517 
518 /**
519  * dmub_srv_calc_region_info() - retreives region info from the dmub service
520  * @dmub: the dmub service
521  * @params: parameters used to calculate region locations
522  * @info_out: the output region info from dmub
523  *
524  * Calculates the base and top address for all relevant dmub regions
525  * using the parameters given (if any).
526  *
527  * Return:
528  *   DMUB_STATUS_OK - success
529  *   DMUB_STATUS_INVALID - unspecified error
530  */
531 enum dmub_status
532 dmub_srv_calc_region_info(struct dmub_srv *dmub,
533 			  const struct dmub_srv_region_params *params,
534 			  struct dmub_srv_region_info *out);
535 
536 /**
537  * dmub_srv_calc_region_info() - retreives fb info from the dmub service
538  * @dmub: the dmub service
539  * @params: parameters used to calculate fb locations
540  * @info_out: the output fb info from dmub
541  *
542  * Calculates the base and top address for all relevant dmub regions
543  * using the parameters given (if any).
544  *
545  * Return:
546  *   DMUB_STATUS_OK - success
547  *   DMUB_STATUS_INVALID - unspecified error
548  */
549 enum dmub_status dmub_srv_calc_fb_info(struct dmub_srv *dmub,
550 				       const struct dmub_srv_fb_params *params,
551 				       struct dmub_srv_fb_info *out);
552 
553 /**
554  * dmub_srv_has_hw_support() - returns hw support state for dmcub
555  * @dmub: the dmub service
556  * @is_supported: hw support state
557  *
558  * Queries the hardware for DMCUB support and returns the result.
559  *
560  * Can be called before dmub_srv_hw_init().
561  *
562  * Return:
563  *   DMUB_STATUS_OK - success
564  *   DMUB_STATUS_INVALID - unspecified error
565  */
566 enum dmub_status dmub_srv_has_hw_support(struct dmub_srv *dmub,
567 					 bool *is_supported);
568 
569 /**
570  * dmub_srv_is_hw_init() - returns hardware init state
571  *
572  * Return:
573  *   DMUB_STATUS_OK - success
574  *   DMUB_STATUS_INVALID - unspecified error
575  */
576 enum dmub_status dmub_srv_is_hw_init(struct dmub_srv *dmub, bool *is_hw_init);
577 
578 /**
579  * dmub_srv_hw_init() - initializes the underlying DMUB hardware
580  * @dmub: the dmub service
581  * @params: params for hardware initialization
582  *
583  * Resets the DMUB hardware and performs backdoor loading of the
584  * required cache regions based on the input framebuffer regions.
585  *
586  * Return:
587  *   DMUB_STATUS_OK - success
588  *   DMUB_STATUS_NO_CTX - dmcub context not initialized
589  *   DMUB_STATUS_INVALID - unspecified error
590  */
591 enum dmub_status dmub_srv_hw_init(struct dmub_srv *dmub,
592 				  const struct dmub_srv_hw_params *params);
593 
594 /**
595  * dmub_srv_hw_reset() - puts the DMUB hardware in reset state if initialized
596  * @dmub: the dmub service
597  *
598  * Before destroying the DMUB service or releasing the backing framebuffer
599  * memory we'll need to put the DMCUB into reset first.
600  *
601  * A subsequent call to dmub_srv_hw_init() will re-enable the DMCUB.
602  *
603  * Return:
604  *   DMUB_STATUS_OK - success
605  *   DMUB_STATUS_INVALID - unspecified error
606  */
607 enum dmub_status dmub_srv_hw_reset(struct dmub_srv *dmub);
608 
609 /**
610  * dmub_srv_sync_inbox1() - sync sw state with hw state
611  * @dmub: the dmub service
612  *
613  * Sync sw state with hw state when resume from S0i3
614  *
615  * Return:
616  *   DMUB_STATUS_OK - success
617  *   DMUB_STATUS_INVALID - unspecified error
618  */
619 enum dmub_status dmub_srv_sync_inbox1(struct dmub_srv *dmub);
620 
621 /**
622  * dmub_srv_cmd_queue() - queues a command to the DMUB
623  * @dmub: the dmub service
624  * @cmd: the command to queue
625  *
626  * Queues a command to the DMUB service but does not begin execution
627  * immediately.
628  *
629  * Return:
630  *   DMUB_STATUS_OK - success
631  *   DMUB_STATUS_QUEUE_FULL - no remaining room in queue
632  *   DMUB_STATUS_INVALID - unspecified error
633  */
634 enum dmub_status dmub_srv_cmd_queue(struct dmub_srv *dmub,
635 				    const union dmub_rb_cmd *cmd);
636 
637 /**
638  * dmub_srv_cmd_execute() - Executes a queued sequence to the dmub
639  * @dmub: the dmub service
640  *
641  * Begins execution of queued commands on the dmub.
642  *
643  * Return:
644  *   DMUB_STATUS_OK - success
645  *   DMUB_STATUS_INVALID - unspecified error
646  */
647 enum dmub_status dmub_srv_cmd_execute(struct dmub_srv *dmub);
648 
649 /**
650  * dmub_srv_wait_for_auto_load() - Waits for firmware auto load to complete
651  * @dmub: the dmub service
652  * @timeout_us: the maximum number of microseconds to wait
653  *
654  * Waits until firmware has been autoloaded by the DMCUB. The maximum
655  * wait time is given in microseconds to prevent spinning forever.
656  *
657  * On ASICs without firmware autoload support this function will return
658  * immediately.
659  *
660  * Return:
661  *   DMUB_STATUS_OK - success
662  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
663  *   DMUB_STATUS_INVALID - unspecified error
664  */
665 enum dmub_status dmub_srv_wait_for_auto_load(struct dmub_srv *dmub,
666 					     uint32_t timeout_us);
667 
668 /**
669  * dmub_srv_wait_for_phy_init() - Waits for DMUB PHY init to complete
670  * @dmub: the dmub service
671  * @timeout_us: the maximum number of microseconds to wait
672  *
673  * Waits until the PHY has been initialized by the DMUB. The maximum
674  * wait time is given in microseconds to prevent spinning forever.
675  *
676  * On ASICs without PHY init support this function will return
677  * immediately.
678  *
679  * Return:
680  *   DMUB_STATUS_OK - success
681  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
682  *   DMUB_STATUS_INVALID - unspecified error
683  */
684 enum dmub_status dmub_srv_wait_for_phy_init(struct dmub_srv *dmub,
685 					    uint32_t timeout_us);
686 
687 /**
688  * dmub_srv_wait_for_idle() - Waits for the DMUB to be idle
689  * @dmub: the dmub service
690  * @timeout_us: the maximum number of microseconds to wait
691  *
692  * Waits until the DMUB buffer is empty and all commands have
693  * finished processing. The maximum wait time is given in
694  * microseconds to prevent spinning forever.
695  *
696  * Return:
697  *   DMUB_STATUS_OK - success
698  *   DMUB_STATUS_TIMEOUT - wait for buffer to flush timed out
699  *   DMUB_STATUS_INVALID - unspecified error
700  */
701 enum dmub_status dmub_srv_wait_for_idle(struct dmub_srv *dmub,
702 					uint32_t timeout_us);
703 
704 /**
705  * dmub_srv_send_gpint_command() - Sends a GPINT based command.
706  * @dmub: the dmub service
707  * @command_code: the command code to send
708  * @param: the command parameter to send
709  * @timeout_us: the maximum number of microseconds to wait
710  *
711  * Sends a command via the general purpose interrupt (GPINT).
712  * Waits for the number of microseconds specified by timeout_us
713  * for the command ACK before returning.
714  *
715  * Can be called after software initialization.
716  *
717  * Return:
718  *   DMUB_STATUS_OK - success
719  *   DMUB_STATUS_TIMEOUT - wait for ACK timed out
720  *   DMUB_STATUS_INVALID - unspecified error
721  */
722 enum dmub_status
723 dmub_srv_send_gpint_command(struct dmub_srv *dmub,
724 			    enum dmub_gpint_command command_code,
725 			    uint16_t param, uint32_t timeout_us);
726 
727 /**
728  * dmub_srv_get_gpint_response() - Queries the GPINT response.
729  * @dmub: the dmub service
730  * @response: the response for the last GPINT
731  *
732  * Returns the response code for the last GPINT interrupt.
733  *
734  * Can be called after software initialization.
735  *
736  * Return:
737  *   DMUB_STATUS_OK - success
738  *   DMUB_STATUS_INVALID - unspecified error
739  */
740 enum dmub_status dmub_srv_get_gpint_response(struct dmub_srv *dmub,
741 					     uint32_t *response);
742 
743 /**
744  * dmub_srv_get_gpint_dataout() - Queries the GPINT DATAOUT.
745  * @dmub: the dmub service
746  * @dataout: the data for the GPINT DATAOUT
747  *
748  * Returns the response code for the last GPINT DATAOUT interrupt.
749  *
750  * Can be called after software initialization.
751  *
752  * Return:
753  *   DMUB_STATUS_OK - success
754  *   DMUB_STATUS_INVALID - unspecified error
755  */
756 enum dmub_status dmub_srv_get_gpint_dataout(struct dmub_srv *dmub,
757 					     uint32_t *dataout);
758 
759 /**
760  * dmub_flush_buffer_mem() - Read back entire frame buffer region.
761  * This ensures that the write from x86 has been flushed and will not
762  * hang the DMCUB.
763  * @fb: frame buffer to flush
764  *
765  * Can be called after software initialization.
766  */
767 void dmub_flush_buffer_mem(const struct dmub_fb *fb);
768 
769 /**
770  * dmub_srv_get_fw_boot_status() - Returns the DMUB boot status bits.
771  *
772  * @dmub: the dmub service
773  * @status: out pointer for firmware status
774  *
775  * Return:
776  *   DMUB_STATUS_OK - success
777  *   DMUB_STATUS_INVALID - unspecified error, unsupported
778  */
779 enum dmub_status dmub_srv_get_fw_boot_status(struct dmub_srv *dmub,
780 					     union dmub_fw_boot_status *status);
781 
782 enum dmub_status dmub_srv_get_fw_boot_option(struct dmub_srv *dmub,
783 					     union dmub_fw_boot_options *option);
784 
785 enum dmub_status dmub_srv_cmd_with_reply_data(struct dmub_srv *dmub,
786 					      union dmub_rb_cmd *cmd);
787 
788 enum dmub_status dmub_srv_set_skip_panel_power_sequence(struct dmub_srv *dmub,
789 					     bool skip);
790 
791 bool dmub_srv_get_outbox0_msg(struct dmub_srv *dmub, struct dmcub_trace_buf_entry *entry);
792 
793 bool dmub_srv_get_diagnostic_data(struct dmub_srv *dmub, struct dmub_diagnostic_data *diag_data);
794 
795 bool dmub_srv_should_detect(struct dmub_srv *dmub);
796 
797 /**
798  * dmub_srv_send_inbox0_cmd() - Send command to DMUB using INBOX0
799  * @dmub: the dmub service
800  * @data: the data to be sent in the INBOX0 command
801  *
802  * Send command by writing directly to INBOX0 WPTR
803  *
804  * Return:
805  *   DMUB_STATUS_OK - success
806  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
807  */
808 enum dmub_status dmub_srv_send_inbox0_cmd(struct dmub_srv *dmub, union dmub_inbox0_data_register data);
809 
810 /**
811  * dmub_srv_wait_for_inbox0_ack() - wait for DMUB to ACK INBOX0 command
812  * @dmub: the dmub service
813  * @timeout_us: the maximum number of microseconds to wait
814  *
815  * Wait for DMUB to ACK the INBOX0 message
816  *
817  * Return:
818  *   DMUB_STATUS_OK - success
819  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
820  *   DMUB_STATUS_TIMEOUT - wait for ack timed out
821  */
822 enum dmub_status dmub_srv_wait_for_inbox0_ack(struct dmub_srv *dmub, uint32_t timeout_us);
823 
824 /**
825  * dmub_srv_wait_for_inbox0_ack() - clear ACK register for INBOX0
826  * @dmub: the dmub service
827  *
828  * Clear ACK register for INBOX0
829  *
830  * Return:
831  *   DMUB_STATUS_OK - success
832  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
833  */
834 enum dmub_status dmub_srv_clear_inbox0_ack(struct dmub_srv *dmub);
835 
836 #if defined(__cplusplus)
837 }
838 #endif
839 
840 #endif /* _DMUB_SRV_H_ */
841