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