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