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