xref: /linux/drivers/gpu/drm/amd/display/dmub/dmub_srv.h (revision 712676ea2bb3882a852bcf49862c4247317fc9b2)
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 #define DMUB_PC_SNAPSHOT_COUNT 10
71 
72 /* Forward declarations */
73 struct dmub_srv;
74 struct dmub_srv_common_regs;
75 struct dmub_srv_dcn31_regs;
76 
77 struct dmcub_trace_buf_entry;
78 
79 /* enum dmub_window_memory_type - memory location type specification for windows */
80 enum dmub_window_memory_type {
81 	DMUB_WINDOW_MEMORY_TYPE_FB = 0,
82 	DMUB_WINDOW_MEMORY_TYPE_GART
83 };
84 
85 /* enum dmub_status - return code for dmcub functions */
86 enum dmub_status {
87 	DMUB_STATUS_OK = 0,
88 	DMUB_STATUS_NO_CTX,
89 	DMUB_STATUS_QUEUE_FULL,
90 	DMUB_STATUS_TIMEOUT,
91 	DMUB_STATUS_INVALID,
92 	DMUB_STATUS_HW_FAILURE,
93 	DMUB_STATUS_POWER_STATE_D3
94 };
95 
96 /* enum dmub_asic - dmub asic identifier */
97 enum dmub_asic {
98 	DMUB_ASIC_NONE = 0,
99 	DMUB_ASIC_DCN20,
100 	DMUB_ASIC_DCN21,
101 	DMUB_ASIC_DCN30,
102 	DMUB_ASIC_DCN301,
103 	DMUB_ASIC_DCN302,
104 	DMUB_ASIC_DCN303,
105 	DMUB_ASIC_DCN31,
106 	DMUB_ASIC_DCN31B,
107 	DMUB_ASIC_DCN314,
108 	DMUB_ASIC_DCN315,
109 	DMUB_ASIC_DCN316,
110 	DMUB_ASIC_DCN32,
111 	DMUB_ASIC_DCN321,
112 	DMUB_ASIC_DCN35,
113 	DMUB_ASIC_DCN351,
114 	DMUB_ASIC_DCN401,
115 	DMUB_ASIC_MAX,
116 };
117 
118 /* enum dmub_window_id - dmub window identifier */
119 enum dmub_window_id {
120 	DMUB_WINDOW_0_INST_CONST = 0,
121 	DMUB_WINDOW_1_STACK,
122 	DMUB_WINDOW_2_BSS_DATA,
123 	DMUB_WINDOW_3_VBIOS,
124 	DMUB_WINDOW_4_MAILBOX,
125 	DMUB_WINDOW_5_TRACEBUFF,
126 	DMUB_WINDOW_6_FW_STATE,
127 	DMUB_WINDOW_7_SCRATCH_MEM,
128 	DMUB_WINDOW_SHARED_STATE,
129 	DMUB_WINDOW_TOTAL,
130 };
131 
132 /* enum dmub_notification_type - dmub outbox notification identifier */
133 enum dmub_notification_type {
134 	DMUB_NOTIFICATION_NO_DATA = 0,
135 	DMUB_NOTIFICATION_AUX_REPLY,
136 	DMUB_NOTIFICATION_HPD,
137 	DMUB_NOTIFICATION_HPD_IRQ,
138 	DMUB_NOTIFICATION_SET_CONFIG_REPLY,
139 	DMUB_NOTIFICATION_DPIA_NOTIFICATION,
140 	DMUB_NOTIFICATION_HPD_SENSE_NOTIFY,
141 	DMUB_NOTIFICATION_MAX
142 };
143 
144 /**
145  * DPIA NOTIFICATION Response Type
146  */
147 enum dpia_notify_bw_alloc_status {
148 
149 	DPIA_BW_REQ_FAILED = 0,
150 	DPIA_BW_REQ_SUCCESS,
151 	DPIA_EST_BW_CHANGED,
152 	DPIA_BW_ALLOC_CAPS_CHANGED
153 };
154 
155 /* enum dmub_memory_access_type - memory access method */
156 enum dmub_memory_access_type {
157 	DMUB_MEMORY_ACCESS_DEFAULT,
158 	DMUB_MEMORY_ACCESS_CPU = DMUB_MEMORY_ACCESS_DEFAULT,
159 	DMUB_MEMORY_ACCESS_DMA
160 };
161 
162 /* enum dmub_power_state type - to track DC power state in dmub_srv */
163 enum dmub_srv_power_state_type {
164 	DMUB_POWER_STATE_UNDEFINED = 0,
165 	DMUB_POWER_STATE_D0 = 1,
166 	DMUB_POWER_STATE_D3 = 8
167 };
168 
169 /**
170  * struct dmub_region - dmub hw memory region
171  * @base: base address for region, must be 256 byte aligned
172  * @top: top address for region
173  */
174 struct dmub_region {
175 	uint32_t base;
176 	uint32_t top;
177 };
178 
179 /**
180  * struct dmub_window - dmub hw cache window
181  * @off: offset to the fb memory in gpu address space
182  * @r: region in uc address space for cache window
183  */
184 struct dmub_window {
185 	union dmub_addr offset;
186 	struct dmub_region region;
187 };
188 
189 /**
190  * struct dmub_fb - defines a dmub framebuffer memory region
191  * @cpu_addr: cpu virtual address for the region, NULL if invalid
192  * @gpu_addr: gpu virtual address for the region, NULL if invalid
193  * @size: size of the region in bytes, zero if invalid
194  */
195 struct dmub_fb {
196 	void *cpu_addr;
197 	uint64_t gpu_addr;
198 	uint32_t size;
199 };
200 
201 /**
202  * struct dmub_srv_region_params - params used for calculating dmub regions
203  * @inst_const_size: size of the fw inst const section
204  * @bss_data_size: size of the fw bss data section
205  * @vbios_size: size of the vbios data
206  * @fw_bss_data: raw firmware bss data section
207  */
208 struct dmub_srv_region_params {
209 	uint32_t inst_const_size;
210 	uint32_t bss_data_size;
211 	uint32_t vbios_size;
212 	const uint8_t *fw_inst_const;
213 	const uint8_t *fw_bss_data;
214 	const enum dmub_window_memory_type *window_memory_type;
215 };
216 
217 /**
218  * struct dmub_srv_region_info - output region info from the dmub service
219  * @fb_size: required minimum fb size for all regions, aligned to 4096 bytes
220  * @num_regions: number of regions used by the dmub service
221  * @regions: region info
222  *
223  * The regions are aligned such that they can be all placed within the
224  * same framebuffer but they can also be placed into different framebuffers.
225  *
226  * The size of each region can be calculated by the caller:
227  * size = reg.top - reg.base
228  *
229  * Care must be taken when performing custom allocations to ensure that each
230  * region base address is 256 byte aligned.
231  */
232 struct dmub_srv_region_info {
233 	uint32_t fb_size;
234 	uint32_t gart_size;
235 	uint8_t num_regions;
236 	struct dmub_region regions[DMUB_WINDOW_TOTAL];
237 };
238 
239 /**
240  * struct dmub_srv_memory_params - parameters used for driver fb setup
241  * @region_info: region info calculated by dmub service
242  * @cpu_fb_addr: base cpu address for the framebuffer
243  * @cpu_inbox_addr: base cpu address for the gart
244  * @gpu_fb_addr: base gpu virtual address for the framebuffer
245  * @gpu_inbox_addr: base gpu virtual address for the gart
246  */
247 struct dmub_srv_memory_params {
248 	const struct dmub_srv_region_info *region_info;
249 	void *cpu_fb_addr;
250 	void *cpu_gart_addr;
251 	uint64_t gpu_fb_addr;
252 	uint64_t gpu_gart_addr;
253 	const enum dmub_window_memory_type *window_memory_type;
254 };
255 
256 /**
257  * struct dmub_srv_fb_info - output fb info from the dmub service
258  * @num_fbs: number of required dmub framebuffers
259  * @fbs: fb data for each region
260  *
261  * Output from the dmub service helper that can be used by the
262  * driver to prepare dmub_fb that can be passed into the dmub
263  * hw init service.
264  *
265  * Assumes that all regions are within the same framebuffer
266  * and have been setup according to the region_info generated
267  * by the dmub service.
268  */
269 struct dmub_srv_fb_info {
270 	uint8_t num_fb;
271 	struct dmub_fb fb[DMUB_WINDOW_TOTAL];
272 };
273 
274 /*
275  * struct dmub_srv_hw_params - params for dmub hardware initialization
276  * @fb: framebuffer info for each region
277  * @fb_base: base of the framebuffer aperture
278  * @fb_offset: offset of the framebuffer aperture
279  * @psp_version: psp version to pass for DMCU init
280  * @load_inst_const: true if DMUB should load inst const fw
281  */
282 struct dmub_srv_hw_params {
283 	struct dmub_fb *fb[DMUB_WINDOW_TOTAL];
284 	uint64_t fb_base;
285 	uint64_t fb_offset;
286 	uint32_t psp_version;
287 	bool load_inst_const;
288 	bool skip_panel_power_sequence;
289 	bool disable_z10;
290 	bool power_optimization;
291 	bool dpia_supported;
292 	bool disable_dpia;
293 	bool usb4_cm_version;
294 	bool fw_in_system_memory;
295 	bool dpia_hpd_int_enable_supported;
296 	bool disable_clock_gate;
297 	bool disallow_dispclk_dppclk_ds;
298 	bool ips_sequential_ono;
299 	enum dmub_memory_access_type mem_access_type;
300 	enum dmub_ips_disable_type disable_ips;
301 	bool disallow_phy_access;
302 	bool disable_sldo_opt;
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 	void (*send_reg_inbox0_cmd_msg)(struct dmub_srv *dmub,
457 			union dmub_rb_cmd *cmd);
458 	uint32_t (*read_reg_inbox0_rsp_int_status)(struct dmub_srv *dmub);
459 	void (*read_reg_inbox0_cmd_rsp)(struct dmub_srv *dmub,
460 			union dmub_rb_cmd *cmd);
461 	void (*write_reg_inbox0_rsp_int_ack)(struct dmub_srv *dmub);
462 	uint32_t (*read_reg_outbox0_rdy_int_status)(struct dmub_srv *dmub);
463 	void (*write_reg_outbox0_rdy_int_ack)(struct dmub_srv *dmub);
464 	void (*read_reg_outbox0_msg)(struct dmub_srv *dmub, uint32_t *msg);
465 	void (*write_reg_outbox0_rsp)(struct dmub_srv *dmub, uint32_t *rsp);
466 	uint32_t (*read_reg_outbox0_rsp_int_status)(struct dmub_srv *dmub);
467 	void (*enable_reg_inbox0_rsp_int)(struct dmub_srv *dmub, bool enable);
468 	void (*enable_reg_outbox0_rdy_int)(struct dmub_srv *dmub, bool enable);
469 };
470 
471 /**
472  * struct dmub_srv_create_params - params for dmub service creation
473  * @base_funcs: driver supplied base routines
474  * @hw_funcs: optional overrides for hw funcs
475  * @user_ctx: context data for callback funcs
476  * @asic: driver supplied asic
477  * @fw_version: the current firmware version, if any
478  * @is_virtual: false for hw support only
479  */
480 struct dmub_srv_create_params {
481 	struct dmub_srv_base_funcs funcs;
482 	struct dmub_srv_hw_funcs *hw_funcs;
483 	void *user_ctx;
484 	enum dmub_asic asic;
485 	uint32_t fw_version;
486 	bool is_virtual;
487 };
488 
489 /**
490  * struct dmub_srv - software state for dmcub
491  * @asic: dmub asic identifier
492  * @user_ctx: user provided context for the dmub_srv
493  * @fw_version: the current firmware version, if any
494  * @is_virtual: false if hardware support only
495  * @shared_state: dmub shared state between firmware and driver
496  * @fw_state: dmub firmware state pointer
497  */
498 struct dmub_srv {
499 	enum dmub_asic asic;
500 	void *user_ctx;
501 	uint32_t fw_version;
502 	bool is_virtual;
503 	struct dmub_fb scratch_mem_fb;
504 	volatile struct dmub_shared_state_feature_block *shared_state;
505 	volatile const struct dmub_fw_state *fw_state;
506 
507 	/* private: internal use only */
508 	const struct dmub_srv_common_regs *regs;
509 	const struct dmub_srv_dcn31_regs *regs_dcn31;
510 	struct dmub_srv_dcn32_regs *regs_dcn32;
511 	struct dmub_srv_dcn35_regs *regs_dcn35;
512 	const struct dmub_srv_dcn401_regs *regs_dcn401;
513 
514 	struct dmub_srv_base_funcs funcs;
515 	struct dmub_srv_hw_funcs hw_funcs;
516 	struct dmub_rb inbox1_rb;
517 	uint32_t inbox1_last_wptr;
518 	/**
519 	 * outbox1_rb is accessed without locks (dal & dc)
520 	 * and to be used only in dmub_srv_stat_get_notification()
521 	 */
522 	struct dmub_rb outbox1_rb;
523 
524 	struct dmub_rb outbox0_rb;
525 
526 	bool sw_init;
527 	bool hw_init;
528 
529 	uint64_t fb_base;
530 	uint64_t fb_offset;
531 	uint32_t psp_version;
532 
533 	/* Feature capabilities reported by fw */
534 	struct dmub_fw_meta_info meta_info;
535 	struct dmub_feature_caps feature_caps;
536 	struct dmub_visual_confirm_color visual_confirm_color;
537 
538 	enum dmub_srv_power_state_type power_state;
539 	struct dmub_srv_debug debug;
540 };
541 
542 /**
543  * struct dmub_notification - dmub notification data
544  * @type: dmub notification type
545  * @link_index: link index to identify aux connection
546  * @result: USB4 status returned from dmub
547  * @pending_notification: Indicates there are other pending notifications
548  * @aux_reply: aux reply
549  * @hpd_status: hpd status
550  * @bw_alloc_reply: BW Allocation reply from CM/DPIA
551  */
552 struct dmub_notification {
553 	enum dmub_notification_type type;
554 	uint8_t link_index;
555 	uint8_t result;
556 	bool pending_notification;
557 	union {
558 		struct aux_reply_data aux_reply;
559 		enum dp_hpd_status hpd_status;
560 		enum set_config_status sc_status;
561 		/**
562 		 * DPIA notification command.
563 		 */
564 		struct dmub_rb_cmd_dpia_notification dpia_notification;
565 		struct dmub_rb_cmd_hpd_sense_notify_data hpd_sense_notify;
566 	};
567 };
568 
569 /**
570  * DMUB firmware version helper macro - useful for checking if the version
571  * of a firmware to know if feature or functionality is supported or present.
572  */
573 #define DMUB_FW_VERSION(major, minor, revision) \
574 	((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | (((revision) & 0xFF) << 8))
575 
576 /**
577  * dmub_srv_create() - creates the DMUB service.
578  * @dmub: the dmub service
579  * @params: creation parameters for the service
580  *
581  * Return:
582  *   DMUB_STATUS_OK - success
583  *   DMUB_STATUS_INVALID - unspecified error
584  */
585 enum dmub_status dmub_srv_create(struct dmub_srv *dmub,
586 				 const struct dmub_srv_create_params *params);
587 
588 /**
589  * dmub_srv_destroy() - destroys the DMUB service.
590  * @dmub: the dmub service
591  */
592 void dmub_srv_destroy(struct dmub_srv *dmub);
593 
594 /**
595  * dmub_srv_calc_region_info() - retreives region info from the dmub service
596  * @dmub: the dmub service
597  * @params: parameters used to calculate region locations
598  * @info_out: the output region info from dmub
599  *
600  * Calculates the base and top address for all relevant dmub regions
601  * using the parameters given (if any).
602  *
603  * Return:
604  *   DMUB_STATUS_OK - success
605  *   DMUB_STATUS_INVALID - unspecified error
606  */
607 enum dmub_status
608 dmub_srv_calc_region_info(struct dmub_srv *dmub,
609 			  const struct dmub_srv_region_params *params,
610 			  struct dmub_srv_region_info *out);
611 
612 /**
613  * dmub_srv_calc_region_info() - retreives fb info from the dmub service
614  * @dmub: the dmub service
615  * @params: parameters used to calculate fb locations
616  * @info_out: the output fb info from dmub
617  *
618  * Calculates the base and top address for all relevant dmub regions
619  * using the parameters given (if any).
620  *
621  * Return:
622  *   DMUB_STATUS_OK - success
623  *   DMUB_STATUS_INVALID - unspecified error
624  */
625 enum dmub_status dmub_srv_calc_mem_info(struct dmub_srv *dmub,
626 				       const struct dmub_srv_memory_params *params,
627 				       struct dmub_srv_fb_info *out);
628 
629 /**
630  * dmub_srv_has_hw_support() - returns hw support state for dmcub
631  * @dmub: the dmub service
632  * @is_supported: hw support state
633  *
634  * Queries the hardware for DMCUB support and returns the result.
635  *
636  * Can be called before dmub_srv_hw_init().
637  *
638  * Return:
639  *   DMUB_STATUS_OK - success
640  *   DMUB_STATUS_INVALID - unspecified error
641  */
642 enum dmub_status dmub_srv_has_hw_support(struct dmub_srv *dmub,
643 					 bool *is_supported);
644 
645 /**
646  * dmub_srv_is_hw_init() - returns hardware init state
647  *
648  * Return:
649  *   DMUB_STATUS_OK - success
650  *   DMUB_STATUS_INVALID - unspecified error
651  */
652 enum dmub_status dmub_srv_is_hw_init(struct dmub_srv *dmub, bool *is_hw_init);
653 
654 /**
655  * dmub_srv_hw_init() - initializes the underlying DMUB hardware
656  * @dmub: the dmub service
657  * @params: params for hardware initialization
658  *
659  * Resets the DMUB hardware and performs backdoor loading of the
660  * required cache regions based on the input framebuffer regions.
661  *
662  * Return:
663  *   DMUB_STATUS_OK - success
664  *   DMUB_STATUS_NO_CTX - dmcub context not initialized
665  *   DMUB_STATUS_INVALID - unspecified error
666  */
667 enum dmub_status dmub_srv_hw_init(struct dmub_srv *dmub,
668 				  const struct dmub_srv_hw_params *params);
669 
670 /**
671  * dmub_srv_hw_reset() - puts the DMUB hardware in reset state if initialized
672  * @dmub: the dmub service
673  *
674  * Before destroying the DMUB service or releasing the backing framebuffer
675  * memory we'll need to put the DMCUB into reset first.
676  *
677  * A subsequent call to dmub_srv_hw_init() will re-enable the DMCUB.
678  *
679  * Return:
680  *   DMUB_STATUS_OK - success
681  *   DMUB_STATUS_INVALID - unspecified error
682  */
683 enum dmub_status dmub_srv_hw_reset(struct dmub_srv *dmub);
684 
685 /**
686  * dmub_srv_sync_inbox1() - sync sw state with hw state
687  * @dmub: the dmub service
688  *
689  * Sync sw state with hw state when resume from S0i3
690  *
691  * Return:
692  *   DMUB_STATUS_OK - success
693  *   DMUB_STATUS_INVALID - unspecified error
694  */
695 enum dmub_status dmub_srv_sync_inbox1(struct dmub_srv *dmub);
696 
697 /**
698  * dmub_srv_cmd_queue() - queues a command to the DMUB
699  * @dmub: the dmub service
700  * @cmd: the command to queue
701  *
702  * Queues a command to the DMUB service but does not begin execution
703  * immediately.
704  *
705  * Return:
706  *   DMUB_STATUS_OK - success
707  *   DMUB_STATUS_QUEUE_FULL - no remaining room in queue
708  *   DMUB_STATUS_INVALID - unspecified error
709  */
710 enum dmub_status dmub_srv_cmd_queue(struct dmub_srv *dmub,
711 				    const union dmub_rb_cmd *cmd);
712 
713 /**
714  * dmub_srv_cmd_execute() - Executes a queued sequence to the dmub
715  * @dmub: the dmub service
716  *
717  * Begins execution of queued commands on the dmub.
718  *
719  * Return:
720  *   DMUB_STATUS_OK - success
721  *   DMUB_STATUS_INVALID - unspecified error
722  */
723 enum dmub_status dmub_srv_cmd_execute(struct dmub_srv *dmub);
724 
725 /**
726  * dmub_srv_wait_for_hw_pwr_up() - Waits for firmware hardware power up is completed
727  * @dmub: the dmub service
728  * @timeout_us: the maximum number of microseconds to wait
729  *
730  * Waits until firmware hardware is powered up. The maximum
731  * wait time is given in microseconds to prevent spinning forever.
732  *
733  * Return:
734  *   DMUB_STATUS_OK - success
735  *   DMUB_STATUS_TIMEOUT - timed out
736  *   DMUB_STATUS_INVALID - unspecified error
737  */
738 enum dmub_status dmub_srv_wait_for_hw_pwr_up(struct dmub_srv *dmub,
739 					     uint32_t timeout_us);
740 
741 bool dmub_srv_is_hw_pwr_up(struct dmub_srv *dmub);
742 
743 /**
744  * dmub_srv_wait_for_auto_load() - Waits for firmware auto load to complete
745  * @dmub: the dmub service
746  * @timeout_us: the maximum number of microseconds to wait
747  *
748  * Waits until firmware has been autoloaded by the DMCUB. The maximum
749  * wait time is given in microseconds to prevent spinning forever.
750  *
751  * On ASICs without firmware autoload support this function will return
752  * immediately.
753  *
754  * Return:
755  *   DMUB_STATUS_OK - success
756  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
757  *   DMUB_STATUS_INVALID - unspecified error
758  */
759 enum dmub_status dmub_srv_wait_for_auto_load(struct dmub_srv *dmub,
760 					     uint32_t timeout_us);
761 
762 /**
763  * dmub_srv_wait_for_phy_init() - Waits for DMUB PHY init to complete
764  * @dmub: the dmub service
765  * @timeout_us: the maximum number of microseconds to wait
766  *
767  * Waits until the PHY has been initialized by the DMUB. The maximum
768  * wait time is given in microseconds to prevent spinning forever.
769  *
770  * On ASICs without PHY init support this function will return
771  * immediately.
772  *
773  * Return:
774  *   DMUB_STATUS_OK - success
775  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
776  *   DMUB_STATUS_INVALID - unspecified error
777  */
778 enum dmub_status dmub_srv_wait_for_phy_init(struct dmub_srv *dmub,
779 					    uint32_t timeout_us);
780 
781 /**
782  * dmub_srv_wait_for_idle() - Waits for the DMUB to be idle
783  * @dmub: the dmub service
784  * @timeout_us: the maximum number of microseconds to wait
785  *
786  * Waits until the DMUB buffer is empty and all commands have
787  * finished processing. The maximum wait time is given in
788  * microseconds to prevent spinning forever.
789  *
790  * Return:
791  *   DMUB_STATUS_OK - success
792  *   DMUB_STATUS_TIMEOUT - wait for buffer to flush timed out
793  *   DMUB_STATUS_INVALID - unspecified error
794  */
795 enum dmub_status dmub_srv_wait_for_idle(struct dmub_srv *dmub,
796 					uint32_t timeout_us);
797 
798 /**
799  * dmub_srv_send_gpint_command() - Sends a GPINT based command.
800  * @dmub: the dmub service
801  * @command_code: the command code to send
802  * @param: the command parameter to send
803  * @timeout_us: the maximum number of microseconds to wait
804  *
805  * Sends a command via the general purpose interrupt (GPINT).
806  * Waits for the number of microseconds specified by timeout_us
807  * for the command ACK before returning.
808  *
809  * Can be called after software initialization.
810  *
811  * Return:
812  *   DMUB_STATUS_OK - success
813  *   DMUB_STATUS_TIMEOUT - wait for ACK timed out
814  *   DMUB_STATUS_INVALID - unspecified error
815  */
816 enum dmub_status
817 dmub_srv_send_gpint_command(struct dmub_srv *dmub,
818 			    enum dmub_gpint_command command_code,
819 			    uint16_t param, uint32_t timeout_us);
820 
821 /**
822  * dmub_srv_get_gpint_response() - Queries the GPINT response.
823  * @dmub: the dmub service
824  * @response: the response for the last GPINT
825  *
826  * Returns the response code for the last GPINT 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_response(struct dmub_srv *dmub,
835 					     uint32_t *response);
836 
837 /**
838  * dmub_srv_get_gpint_dataout() - Queries the GPINT DATAOUT.
839  * @dmub: the dmub service
840  * @dataout: the data for the GPINT DATAOUT
841  *
842  * Returns the response code for the last GPINT DATAOUT interrupt.
843  *
844  * Can be called after software initialization.
845  *
846  * Return:
847  *   DMUB_STATUS_OK - success
848  *   DMUB_STATUS_INVALID - unspecified error
849  */
850 enum dmub_status dmub_srv_get_gpint_dataout(struct dmub_srv *dmub,
851 					     uint32_t *dataout);
852 
853 /**
854  * dmub_flush_buffer_mem() - Read back entire frame buffer region.
855  * This ensures that the write from x86 has been flushed and will not
856  * hang the DMCUB.
857  * @fb: frame buffer to flush
858  *
859  * Can be called after software initialization.
860  */
861 void dmub_flush_buffer_mem(const struct dmub_fb *fb);
862 
863 /**
864  * dmub_srv_get_fw_boot_status() - Returns the DMUB boot status bits.
865  *
866  * @dmub: the dmub service
867  * @status: out pointer for firmware status
868  *
869  * Return:
870  *   DMUB_STATUS_OK - success
871  *   DMUB_STATUS_INVALID - unspecified error, unsupported
872  */
873 enum dmub_status dmub_srv_get_fw_boot_status(struct dmub_srv *dmub,
874 					     union dmub_fw_boot_status *status);
875 
876 enum dmub_status dmub_srv_get_fw_boot_option(struct dmub_srv *dmub,
877 					     union dmub_fw_boot_options *option);
878 
879 enum dmub_status dmub_srv_cmd_with_reply_data(struct dmub_srv *dmub,
880 					      union dmub_rb_cmd *cmd);
881 
882 enum dmub_status dmub_srv_set_skip_panel_power_sequence(struct dmub_srv *dmub,
883 					     bool skip);
884 
885 bool dmub_srv_get_outbox0_msg(struct dmub_srv *dmub, struct dmcub_trace_buf_entry *entry);
886 
887 bool dmub_srv_get_diagnostic_data(struct dmub_srv *dmub, struct dmub_diagnostic_data *diag_data);
888 
889 bool dmub_srv_should_detect(struct dmub_srv *dmub);
890 
891 /**
892  * dmub_srv_send_inbox0_cmd() - Send command to DMUB using INBOX0
893  * @dmub: the dmub service
894  * @data: the data to be sent in the INBOX0 command
895  *
896  * Send command by writing directly to INBOX0 WPTR
897  *
898  * Return:
899  *   DMUB_STATUS_OK - success
900  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
901  */
902 enum dmub_status dmub_srv_send_inbox0_cmd(struct dmub_srv *dmub, union dmub_inbox0_data_register data);
903 
904 /**
905  * dmub_srv_wait_for_inbox0_ack() - wait for DMUB to ACK INBOX0 command
906  * @dmub: the dmub service
907  * @timeout_us: the maximum number of microseconds to wait
908  *
909  * Wait for DMUB to ACK the INBOX0 message
910  *
911  * Return:
912  *   DMUB_STATUS_OK - success
913  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
914  *   DMUB_STATUS_TIMEOUT - wait for ack timed out
915  */
916 enum dmub_status dmub_srv_wait_for_inbox0_ack(struct dmub_srv *dmub, uint32_t timeout_us);
917 
918 /**
919  * dmub_srv_wait_for_inbox0_ack() - clear ACK register for INBOX0
920  * @dmub: the dmub service
921  *
922  * Clear ACK register for INBOX0
923  *
924  * Return:
925  *   DMUB_STATUS_OK - success
926  *   DMUB_STATUS_INVALID - hw_init false or hw function does not exist
927  */
928 enum dmub_status dmub_srv_clear_inbox0_ack(struct dmub_srv *dmub);
929 
930 /**
931  * dmub_srv_subvp_save_surf_addr() - Save primary and meta address for subvp on each flip
932  * @dmub: The dmub service
933  * @addr: The surface address to be programmed on the current flip
934  * @subvp_index: Index of subvp pipe, indicates which subvp pipe the address should be saved for
935  *
936  * Function to save the surface flip addr into scratch registers. This is to fix a race condition
937  * between FW and driver reading / writing to the surface address at the same time. This is
938  * required because there is no EARLIEST_IN_USE_META.
939  *
940  * Return:
941  *   void
942  */
943 void dmub_srv_subvp_save_surf_addr(struct dmub_srv *dmub, const struct dc_plane_address *addr, uint8_t subvp_index);
944 
945 /**
946  * dmub_srv_send_reg_inbox0_cmd() - send a dmub command and wait for the command
947  * being processed by DMUB.
948  * @dmub: The dmub service
949  * @cmd: The dmub command being sent. If with_replay is true, the function will
950  * update cmd with replied data.
951  * @with_reply: true if DMUB reply needs to be copied back to cmd. false if the
952  * cmd doesn't need to be replied.
953  * @timeout_us: timeout in microseconds.
954  *
955  * Return:
956  * DMUB_STATUS_OK - success
957  * DMUB_STATUS_TIMEOUT - DMUB fails to process the command within the timeout
958  * interval.
959  */
960 enum dmub_status dmub_srv_send_reg_inbox0_cmd(
961 		struct dmub_srv *dmub,
962 		union dmub_rb_cmd *cmd,
963 		bool with_reply, uint32_t timeout_us);
964 
965 /**
966  * dmub_srv_set_power_state() - Track DC power state in dmub_srv
967  * @dmub: The dmub service
968  * @power_state: DC power state setting
969  *
970  * Store DC power state in dmub_srv.  If dmub_srv is in D3, then don't send messages to DMUB
971  *
972  * Return:
973  *   void
974  */
975 void dmub_srv_set_power_state(struct dmub_srv *dmub, enum dmub_srv_power_state_type dmub_srv_power_state);
976 
977 #endif /* _DMUB_SRV_H_ */
978