1 /*
2  * Copyright 2019 Advanced Micro Devices, Inc.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included in
12  * all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
17  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20  * OTHER DEALINGS IN THE SOFTWARE.
21  *
22  * Authors: AMD
23  *
24  */
25 
26 #ifndef _DMUB_SRV_H_
27 #define _DMUB_SRV_H_
28 
29 /**
30  * DOC: DMUB interface and operation
31  *
32  * DMUB is the interface to the display DMCUB microcontroller on DCN hardware.
33  * It delegates hardware initialization and command submission to the
34  * microcontroller. DMUB is the shortname for DMCUB.
35  *
36  * This interface is not thread-safe. Ensure that all access to the interface
37  * is properly synchronized by the caller.
38  *
39  * Initialization and usage of the DMUB service should be done in the
40  * steps given below:
41  *
42  * 1. dmub_srv_create()
43  * 2. dmub_srv_has_hw_support()
44  * 3. dmub_srv_calc_region_info()
45  * 4. dmub_srv_hw_init()
46  *
47  * The call to dmub_srv_create() is required to use the server.
48  *
49  * The calls to dmub_srv_has_hw_support() and dmub_srv_calc_region_info()
50  * are helpers to query cache window size and allocate framebuffer(s)
51  * for the cache windows.
52  *
53  * The call to dmub_srv_hw_init() programs the DMCUB registers to prepare
54  * for command submission. Commands can be queued via dmub_srv_cmd_queue()
55  * and executed via dmub_srv_cmd_execute().
56  *
57  * If the queue is full the dmub_srv_wait_for_idle() call can be used to
58  * wait until the queue has been cleared.
59  *
60  * Destroying the DMUB service can be done by calling dmub_srv_destroy().
61  * This does not clear DMUB hardware state, only software state.
62  *
63  * The interface is intended to be standalone and should not depend on any
64  * other component within DAL.
65  */
66 
67 #include "inc/dmub_cmd.h"
68 
69 #if defined(__cplusplus)
70 extern "C" {
71 #endif
72 
73 /* Forward declarations */
74 struct dmub_srv;
75 struct dmub_srv_common_regs;
76 struct dmub_srv_dcn31_regs;
77 
78 struct dmcub_trace_buf_entry;
79 
80 /* enum dmub_status - return code for dmcub functions */
81 enum dmub_status {
82 	DMUB_STATUS_OK = 0,
83 	DMUB_STATUS_NO_CTX,
84 	DMUB_STATUS_QUEUE_FULL,
85 	DMUB_STATUS_TIMEOUT,
86 	DMUB_STATUS_INVALID,
87 };
88 
89 /* enum dmub_asic - dmub asic identifier */
90 enum dmub_asic {
91 	DMUB_ASIC_NONE = 0,
92 	DMUB_ASIC_DCN20,
93 	DMUB_ASIC_DCN21,
94 	DMUB_ASIC_DCN30,
95 	DMUB_ASIC_DCN301,
96 	DMUB_ASIC_DCN302,
97 	DMUB_ASIC_DCN303,
98 	DMUB_ASIC_DCN31,
99 	DMUB_ASIC_MAX,
100 };
101 
102 /* enum dmub_window_id - dmub window identifier */
103 enum dmub_window_id {
104 	DMUB_WINDOW_0_INST_CONST = 0,
105 	DMUB_WINDOW_1_STACK,
106 	DMUB_WINDOW_2_BSS_DATA,
107 	DMUB_WINDOW_3_VBIOS,
108 	DMUB_WINDOW_4_MAILBOX,
109 	DMUB_WINDOW_5_TRACEBUFF,
110 	DMUB_WINDOW_6_FW_STATE,
111 	DMUB_WINDOW_7_SCRATCH_MEM,
112 	DMUB_WINDOW_TOTAL,
113 };
114 
115 /* enum dmub_notification_type - dmub outbox notification identifier */
116 enum dmub_notification_type {
117 	DMUB_NOTIFICATION_NO_DATA = 0,
118 	DMUB_NOTIFICATION_AUX_REPLY,
119 	DMUB_NOTIFICATION_HPD,
120 	DMUB_NOTIFICATION_HPD_IRQ,
121 	DMUB_NOTIFICATION_MAX
122 };
123 
124 /**
125  * struct dmub_region - dmub hw memory region
126  * @base: base address for region, must be 256 byte aligned
127  * @top: top address for region
128  */
129 struct dmub_region {
130 	uint32_t base;
131 	uint32_t top;
132 };
133 
134 /**
135  * struct dmub_window - dmub hw cache window
136  * @off: offset to the fb memory in gpu address space
137  * @r: region in uc address space for cache window
138  */
139 struct dmub_window {
140 	union dmub_addr offset;
141 	struct dmub_region region;
142 };
143 
144 /**
145  * struct dmub_fb - defines a dmub framebuffer memory region
146  * @cpu_addr: cpu virtual address for the region, NULL if invalid
147  * @gpu_addr: gpu virtual address for the region, NULL if invalid
148  * @size: size of the region in bytes, zero if invalid
149  */
150 struct dmub_fb {
151 	void *cpu_addr;
152 	uint64_t gpu_addr;
153 	uint32_t size;
154 };
155 
156 /**
157  * struct dmub_srv_region_params - params used for calculating dmub regions
158  * @inst_const_size: size of the fw inst const section
159  * @bss_data_size: size of the fw bss data section
160  * @vbios_size: size of the vbios data
161  * @fw_bss_data: raw firmware bss data section
162  */
163 struct dmub_srv_region_params {
164 	uint32_t inst_const_size;
165 	uint32_t bss_data_size;
166 	uint32_t vbios_size;
167 	const uint8_t *fw_inst_const;
168 	const uint8_t *fw_bss_data;
169 };
170 
171 /**
172  * struct dmub_srv_region_info - output region info from the dmub service
173  * @fb_size: required minimum fb size for all regions, aligned to 4096 bytes
174  * @num_regions: number of regions used by the dmub service
175  * @regions: region info
176  *
177  * The regions are aligned such that they can be all placed within the
178  * same framebuffer but they can also be placed into different framebuffers.
179  *
180  * The size of each region can be calculated by the caller:
181  * size = reg.top - reg.base
182  *
183  * Care must be taken when performing custom allocations to ensure that each
184  * region base address is 256 byte aligned.
185  */
186 struct dmub_srv_region_info {
187 	uint32_t fb_size;
188 	uint8_t num_regions;
189 	struct dmub_region regions[DMUB_WINDOW_TOTAL];
190 };
191 
192 /**
193  * struct dmub_srv_fb_params - parameters used for driver fb setup
194  * @region_info: region info calculated by dmub service
195  * @cpu_addr: base cpu address for the framebuffer
196  * @gpu_addr: base gpu virtual address for the framebuffer
197  */
198 struct dmub_srv_fb_params {
199 	const struct dmub_srv_region_info *region_info;
200 	void *cpu_addr;
201 	uint64_t gpu_addr;
202 };
203 
204 /**
205  * struct dmub_srv_fb_info - output fb info from the dmub service
206  * @num_fbs: number of required dmub framebuffers
207  * @fbs: fb data for each region
208  *
209  * Output from the dmub service helper that can be used by the
210  * driver to prepare dmub_fb that can be passed into the dmub
211  * hw init service.
212  *
213  * Assumes that all regions are within the same framebuffer
214  * and have been setup according to the region_info generated
215  * by the dmub service.
216  */
217 struct dmub_srv_fb_info {
218 	uint8_t num_fb;
219 	struct dmub_fb fb[DMUB_WINDOW_TOTAL];
220 };
221 
222 /*
223  * struct dmub_srv_hw_params - params for dmub hardware initialization
224  * @fb: framebuffer info for each region
225  * @fb_base: base of the framebuffer aperture
226  * @fb_offset: offset of the framebuffer aperture
227  * @psp_version: psp version to pass for DMCU init
228  * @load_inst_const: true if DMUB should load inst const fw
229  */
230 struct dmub_srv_hw_params {
231 	struct dmub_fb *fb[DMUB_WINDOW_TOTAL];
232 	uint64_t fb_base;
233 	uint64_t fb_offset;
234 	uint32_t psp_version;
235 	bool load_inst_const;
236 	bool skip_panel_power_sequence;
237 	bool disable_z10;
238 };
239 
240 /**
241  * struct dmub_diagnostic_data - Diagnostic data retrieved from DMCUB for
242  * debugging purposes, including logging, crash analysis, etc.
243  */
244 struct dmub_diagnostic_data {
245 	uint32_t dmcub_version;
246 	uint32_t scratch[16];
247 	uint32_t pc;
248 	uint32_t undefined_address_fault_addr;
249 	uint32_t inst_fetch_fault_addr;
250 	uint32_t data_write_fault_addr;
251 	uint32_t inbox1_rptr;
252 	uint32_t inbox1_wptr;
253 	uint32_t inbox1_size;
254 	uint32_t inbox0_rptr;
255 	uint32_t inbox0_wptr;
256 	uint32_t inbox0_size;
257 	uint8_t is_dmcub_enabled : 1;
258 	uint8_t is_dmcub_soft_reset : 1;
259 	uint8_t is_dmcub_secure_reset : 1;
260 	uint8_t is_traceport_en : 1;
261 	uint8_t is_cw0_enabled : 1;
262 	uint8_t is_cw6_enabled : 1;
263 };
264 
265 /**
266  * struct dmub_srv_base_funcs - Driver specific base callbacks
267  */
268 struct dmub_srv_base_funcs {
269 	/**
270 	 * @reg_read:
271 	 *
272 	 * Hook for reading a register.
273 	 *
274 	 * Return: The 32-bit register value from the given address.
275 	 */
276 	uint32_t (*reg_read)(void *ctx, uint32_t address);
277 
278 	/**
279 	 * @reg_write:
280 	 *
281 	 * Hook for writing a value to the register specified by address.
282 	 */
283 	void (*reg_write)(void *ctx, uint32_t address, uint32_t value);
284 };
285 
286 /**
287  * struct dmub_srv_hw_funcs - hardware sequencer funcs for dmub
288  */
289 struct dmub_srv_hw_funcs {
290 	/* private: internal use only */
291 
292 	void (*init)(struct dmub_srv *dmub);
293 
294 	void (*reset)(struct dmub_srv *dmub);
295 
296 	void (*reset_release)(struct dmub_srv *dmub);
297 
298 	void (*backdoor_load)(struct dmub_srv *dmub,
299 			      const struct dmub_window *cw0,
300 			      const struct dmub_window *cw1);
301 
302 	void (*setup_windows)(struct dmub_srv *dmub,
303 			      const struct dmub_window *cw2,
304 			      const struct dmub_window *cw3,
305 			      const struct dmub_window *cw4,
306 			      const struct dmub_window *cw5,
307 			      const struct dmub_window *cw6);
308 
309 	void (*setup_mailbox)(struct dmub_srv *dmub,
310 			      const struct dmub_region *inbox1);
311 
312 	uint32_t (*get_inbox1_rptr)(struct dmub_srv *dmub);
313 
314 	void (*set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset);
315 
316 	void (*setup_out_mailbox)(struct dmub_srv *dmub,
317 			      const struct dmub_region *outbox1);
318 
319 	uint32_t (*get_outbox1_wptr)(struct dmub_srv *dmub);
320 
321 	void (*set_outbox1_rptr)(struct dmub_srv *dmub, uint32_t rptr_offset);
322 
323 	void (*setup_outbox0)(struct dmub_srv *dmub,
324 			      const struct dmub_region *outbox0);
325 
326 	uint32_t (*get_outbox0_wptr)(struct dmub_srv *dmub);
327 
328 	void (*set_outbox0_rptr)(struct dmub_srv *dmub, uint32_t rptr_offset);
329 
330 	uint32_t (*emul_get_inbox1_rptr)(struct dmub_srv *dmub);
331 
332 	void (*emul_set_inbox1_wptr)(struct dmub_srv *dmub, uint32_t wptr_offset);
333 
334 	bool (*is_supported)(struct dmub_srv *dmub);
335 
336 	bool (*is_hw_init)(struct dmub_srv *dmub);
337 
338 	bool (*is_phy_init)(struct dmub_srv *dmub);
339 	void (*enable_dmub_boot_options)(struct dmub_srv *dmub,
340 				const struct dmub_srv_hw_params *params);
341 
342 	void (*skip_dmub_panel_power_sequence)(struct dmub_srv *dmub, bool skip);
343 
344 	union dmub_fw_boot_status (*get_fw_status)(struct dmub_srv *dmub);
345 
346 
347 	void (*set_gpint)(struct dmub_srv *dmub,
348 			  union dmub_gpint_data_register reg);
349 
350 	bool (*is_gpint_acked)(struct dmub_srv *dmub,
351 			       union dmub_gpint_data_register reg);
352 
353 	uint32_t (*get_gpint_response)(struct dmub_srv *dmub);
354 
355 	uint32_t (*get_gpint_dataout)(struct dmub_srv *dmub);
356 
357 	void (*send_inbox0_cmd)(struct dmub_srv *dmub, union dmub_inbox0_data_register data);
358 	uint32_t (*get_current_time)(struct dmub_srv *dmub);
359 
360 	void (*get_diagnostic_data)(struct dmub_srv *dmub, struct dmub_diagnostic_data *dmub_oca);
361 };
362 
363 /**
364  * struct dmub_srv_create_params - params for dmub service creation
365  * @base_funcs: driver supplied base routines
366  * @hw_funcs: optional overrides for hw funcs
367  * @user_ctx: context data for callback funcs
368  * @asic: driver supplied asic
369  * @fw_version: the current firmware version, if any
370  * @is_virtual: false for hw support only
371  */
372 struct dmub_srv_create_params {
373 	struct dmub_srv_base_funcs funcs;
374 	struct dmub_srv_hw_funcs *hw_funcs;
375 	void *user_ctx;
376 	enum dmub_asic asic;
377 	uint32_t fw_version;
378 	bool is_virtual;
379 };
380 
381 /**
382  * struct dmub_srv - software state for dmcub
383  * @asic: dmub asic identifier
384  * @user_ctx: user provided context for the dmub_srv
385  * @fw_version: the current firmware version, if any
386  * @is_virtual: false if hardware support only
387  * @fw_state: dmub firmware state pointer
388  */
389 struct dmub_srv {
390 	enum dmub_asic asic;
391 	void *user_ctx;
392 	uint32_t fw_version;
393 	bool is_virtual;
394 	struct dmub_fb scratch_mem_fb;
395 	volatile const struct dmub_fw_state *fw_state;
396 
397 	/* private: internal use only */
398 	const struct dmub_srv_common_regs *regs;
399 	const struct dmub_srv_dcn31_regs *regs_dcn31;
400 
401 	struct dmub_srv_base_funcs funcs;
402 	struct dmub_srv_hw_funcs hw_funcs;
403 	struct dmub_rb inbox1_rb;
404 	/**
405 	 * outbox1_rb is accessed without locks (dal & dc)
406 	 * and to be used only in dmub_srv_stat_get_notification()
407 	 */
408 	struct dmub_rb outbox1_rb;
409 
410 	struct dmub_rb outbox0_rb;
411 
412 	bool sw_init;
413 	bool hw_init;
414 
415 	uint64_t fb_base;
416 	uint64_t fb_offset;
417 	uint32_t psp_version;
418 
419 	/* Feature capabilities reported by fw */
420 	struct dmub_feature_caps feature_caps;
421 };
422 
423 /**
424  * struct dmub_notification - dmub notification data
425  * @type: dmub notification type
426  * @link_index: link index to identify aux connection
427  * @result: USB4 status returned from dmub
428  * @pending_notification: Indicates there are other pending notifications
429  * @aux_reply: aux reply
430  * @hpd_status: hpd status
431  */
432 struct dmub_notification {
433 	enum dmub_notification_type type;
434 	uint8_t link_index;
435 	uint8_t result;
436 	bool pending_notification;
437 	union {
438 		struct aux_reply_data aux_reply;
439 		enum dp_hpd_status hpd_status;
440 	};
441 };
442 
443 /**
444  * DMUB firmware version helper macro - useful for checking if the version
445  * of a firmware to know if feature or functionality is supported or present.
446  */
447 #define DMUB_FW_VERSION(major, minor, revision) \
448 	((((major) & 0xFF) << 24) | (((minor) & 0xFF) << 16) | ((revision) & 0xFFFF))
449 
450 /**
451  * dmub_srv_create() - creates the DMUB service.
452  * @dmub: the dmub service
453  * @params: creation parameters for the service
454  *
455  * Return:
456  *   DMUB_STATUS_OK - success
457  *   DMUB_STATUS_INVALID - unspecified error
458  */
459 enum dmub_status dmub_srv_create(struct dmub_srv *dmub,
460 				 const struct dmub_srv_create_params *params);
461 
462 /**
463  * dmub_srv_destroy() - destroys the DMUB service.
464  * @dmub: the dmub service
465  */
466 void dmub_srv_destroy(struct dmub_srv *dmub);
467 
468 /**
469  * dmub_srv_calc_region_info() - retreives region info from the dmub service
470  * @dmub: the dmub service
471  * @params: parameters used to calculate region locations
472  * @info_out: the output region info from dmub
473  *
474  * Calculates the base and top address for all relevant dmub regions
475  * using the parameters given (if any).
476  *
477  * Return:
478  *   DMUB_STATUS_OK - success
479  *   DMUB_STATUS_INVALID - unspecified error
480  */
481 enum dmub_status
482 dmub_srv_calc_region_info(struct dmub_srv *dmub,
483 			  const struct dmub_srv_region_params *params,
484 			  struct dmub_srv_region_info *out);
485 
486 /**
487  * dmub_srv_calc_region_info() - retreives fb info from the dmub service
488  * @dmub: the dmub service
489  * @params: parameters used to calculate fb locations
490  * @info_out: the output fb info from dmub
491  *
492  * Calculates the base and top address for all relevant dmub regions
493  * using the parameters given (if any).
494  *
495  * Return:
496  *   DMUB_STATUS_OK - success
497  *   DMUB_STATUS_INVALID - unspecified error
498  */
499 enum dmub_status dmub_srv_calc_fb_info(struct dmub_srv *dmub,
500 				       const struct dmub_srv_fb_params *params,
501 				       struct dmub_srv_fb_info *out);
502 
503 /**
504  * dmub_srv_has_hw_support() - returns hw support state for dmcub
505  * @dmub: the dmub service
506  * @is_supported: hw support state
507  *
508  * Queries the hardware for DMCUB support and returns the result.
509  *
510  * Can be called before dmub_srv_hw_init().
511  *
512  * Return:
513  *   DMUB_STATUS_OK - success
514  *   DMUB_STATUS_INVALID - unspecified error
515  */
516 enum dmub_status dmub_srv_has_hw_support(struct dmub_srv *dmub,
517 					 bool *is_supported);
518 
519 /**
520  * dmub_srv_is_hw_init() - returns hardware init state
521  *
522  * Return:
523  *   DMUB_STATUS_OK - success
524  *   DMUB_STATUS_INVALID - unspecified error
525  */
526 enum dmub_status dmub_srv_is_hw_init(struct dmub_srv *dmub, bool *is_hw_init);
527 
528 /**
529  * dmub_srv_hw_init() - initializes the underlying DMUB hardware
530  * @dmub: the dmub service
531  * @params: params for hardware initialization
532  *
533  * Resets the DMUB hardware and performs backdoor loading of the
534  * required cache regions based on the input framebuffer regions.
535  *
536  * Return:
537  *   DMUB_STATUS_OK - success
538  *   DMUB_STATUS_NO_CTX - dmcub context not initialized
539  *   DMUB_STATUS_INVALID - unspecified error
540  */
541 enum dmub_status dmub_srv_hw_init(struct dmub_srv *dmub,
542 				  const struct dmub_srv_hw_params *params);
543 
544 /**
545  * dmub_srv_hw_reset() - puts the DMUB hardware in reset state if initialized
546  * @dmub: the dmub service
547  *
548  * Before destroying the DMUB service or releasing the backing framebuffer
549  * memory we'll need to put the DMCUB into reset first.
550  *
551  * A subsequent call to dmub_srv_hw_init() will re-enable the DMCUB.
552  *
553  * Return:
554  *   DMUB_STATUS_OK - success
555  *   DMUB_STATUS_INVALID - unspecified error
556  */
557 enum dmub_status dmub_srv_hw_reset(struct dmub_srv *dmub);
558 
559 /**
560  * dmub_srv_cmd_queue() - queues a command to the DMUB
561  * @dmub: the dmub service
562  * @cmd: the command to queue
563  *
564  * Queues a command to the DMUB service but does not begin execution
565  * immediately.
566  *
567  * Return:
568  *   DMUB_STATUS_OK - success
569  *   DMUB_STATUS_QUEUE_FULL - no remaining room in queue
570  *   DMUB_STATUS_INVALID - unspecified error
571  */
572 enum dmub_status dmub_srv_cmd_queue(struct dmub_srv *dmub,
573 				    const union dmub_rb_cmd *cmd);
574 
575 /**
576  * dmub_srv_cmd_execute() - Executes a queued sequence to the dmub
577  * @dmub: the dmub service
578  *
579  * Begins execution of queued commands on the dmub.
580  *
581  * Return:
582  *   DMUB_STATUS_OK - success
583  *   DMUB_STATUS_INVALID - unspecified error
584  */
585 enum dmub_status dmub_srv_cmd_execute(struct dmub_srv *dmub);
586 
587 /**
588  * dmub_srv_wait_for_auto_load() - Waits for firmware auto load to complete
589  * @dmub: the dmub service
590  * @timeout_us: the maximum number of microseconds to wait
591  *
592  * Waits until firmware has been autoloaded by the DMCUB. The maximum
593  * wait time is given in microseconds to prevent spinning forever.
594  *
595  * On ASICs without firmware autoload support this function will return
596  * immediately.
597  *
598  * Return:
599  *   DMUB_STATUS_OK - success
600  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
601  *   DMUB_STATUS_INVALID - unspecified error
602  */
603 enum dmub_status dmub_srv_wait_for_auto_load(struct dmub_srv *dmub,
604 					     uint32_t timeout_us);
605 
606 /**
607  * dmub_srv_wait_for_phy_init() - Waits for DMUB PHY init to complete
608  * @dmub: the dmub service
609  * @timeout_us: the maximum number of microseconds to wait
610  *
611  * Waits until the PHY has been initialized by the DMUB. The maximum
612  * wait time is given in microseconds to prevent spinning forever.
613  *
614  * On ASICs without PHY init support this function will return
615  * immediately.
616  *
617  * Return:
618  *   DMUB_STATUS_OK - success
619  *   DMUB_STATUS_TIMEOUT - wait for phy init timed out
620  *   DMUB_STATUS_INVALID - unspecified error
621  */
622 enum dmub_status dmub_srv_wait_for_phy_init(struct dmub_srv *dmub,
623 					    uint32_t timeout_us);
624 
625 /**
626  * dmub_srv_wait_for_idle() - Waits for the DMUB to be idle
627  * @dmub: the dmub service
628  * @timeout_us: the maximum number of microseconds to wait
629  *
630  * Waits until the DMUB buffer is empty and all commands have
631  * finished processing. The maximum wait time is given in
632  * microseconds to prevent spinning forever.
633  *
634  * Return:
635  *   DMUB_STATUS_OK - success
636  *   DMUB_STATUS_TIMEOUT - wait for buffer to flush timed out
637  *   DMUB_STATUS_INVALID - unspecified error
638  */
639 enum dmub_status dmub_srv_wait_for_idle(struct dmub_srv *dmub,
640 					uint32_t timeout_us);
641 
642 /**
643  * dmub_srv_send_gpint_command() - Sends a GPINT based command.
644  * @dmub: the dmub service
645  * @command_code: the command code to send
646  * @param: the command parameter to send
647  * @timeout_us: the maximum number of microseconds to wait
648  *
649  * Sends a command via the general purpose interrupt (GPINT).
650  * Waits for the number of microseconds specified by timeout_us
651  * for the command ACK before returning.
652  *
653  * Can be called after software initialization.
654  *
655  * Return:
656  *   DMUB_STATUS_OK - success
657  *   DMUB_STATUS_TIMEOUT - wait for ACK timed out
658  *   DMUB_STATUS_INVALID - unspecified error
659  */
660 enum dmub_status
661 dmub_srv_send_gpint_command(struct dmub_srv *dmub,
662 			    enum dmub_gpint_command command_code,
663 			    uint16_t param, uint32_t timeout_us);
664 
665 /**
666  * dmub_srv_get_gpint_response() - Queries the GPINT response.
667  * @dmub: the dmub service
668  * @response: the response for the last GPINT
669  *
670  * Returns the response code for the last GPINT interrupt.
671  *
672  * Can be called after software initialization.
673  *
674  * Return:
675  *   DMUB_STATUS_OK - success
676  *   DMUB_STATUS_INVALID - unspecified error
677  */
678 enum dmub_status dmub_srv_get_gpint_response(struct dmub_srv *dmub,
679 					     uint32_t *response);
680 
681 /**
682  * dmub_srv_get_gpint_dataout() - Queries the GPINT DATAOUT.
683  * @dmub: the dmub service
684  * @dataout: the data for the GPINT DATAOUT
685  *
686  * Returns the response code for the last GPINT DATAOUT interrupt.
687  *
688  * Can be called after software initialization.
689  *
690  * Return:
691  *   DMUB_STATUS_OK - success
692  *   DMUB_STATUS_INVALID - unspecified error
693  */
694 enum dmub_status dmub_srv_get_gpint_dataout(struct dmub_srv *dmub,
695 					     uint32_t *dataout);
696 
697 /**
698  * dmub_flush_buffer_mem() - Read back entire frame buffer region.
699  * This ensures that the write from x86 has been flushed and will not
700  * hang the DMCUB.
701  * @fb: frame buffer to flush
702  *
703  * Can be called after software initialization.
704  */
705 void dmub_flush_buffer_mem(const struct dmub_fb *fb);
706 
707 /**
708  * dmub_srv_get_fw_boot_status() - Returns the DMUB boot status bits.
709  *
710  * @dmub: the dmub service
711  * @status: out pointer for firmware status
712  *
713  * Return:
714  *   DMUB_STATUS_OK - success
715  *   DMUB_STATUS_INVALID - unspecified error, unsupported
716  */
717 enum dmub_status dmub_srv_get_fw_boot_status(struct dmub_srv *dmub,
718 					     union dmub_fw_boot_status *status);
719 
720 enum dmub_status dmub_srv_cmd_with_reply_data(struct dmub_srv *dmub,
721 					      union dmub_rb_cmd *cmd);
722 
723 bool dmub_srv_get_outbox0_msg(struct dmub_srv *dmub, struct dmcub_trace_buf_entry *entry);
724 
725 bool dmub_srv_get_diagnostic_data(struct dmub_srv *dmub, struct dmub_diagnostic_data *diag_data);
726 
727 #if defined(__cplusplus)
728 }
729 #endif
730 
731 #endif /* _DMUB_SRV_H_ */
732