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