142 lines · c
1/*2 * Copyright 2019 Advanced Micro Devices, Inc.3 *4 * Permission is hereby granted, free of charge, to any person obtaining a5 * copy of this software and associated documentation files (the "Software"),6 * to deal in the Software without restriction, including without limitation7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,8 * and/or sell copies of the Software, and to permit persons to whom the9 * Software is furnished to do so, subject to the following conditions:10 *11 * The above copyright notice and this permission notice shall be included in12 * all copies or substantial portions of the Software.13 *14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR18 * 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 OR20 * OTHER DEALINGS IN THE SOFTWARE.21 *22 * Authors: AMD23 *24 */25 26#include "dmub/dmub_srv_stat.h"27#include "dmub/inc/dmub_cmd.h"28 29/**30 * DOC: DMUB_SRV STAT Interface31 *32 * These interfaces are called without acquiring DAL and DC locks.33 * Hence, there is limitations on whese interfaces can access. Only34 * variables exclusively defined for these interfaces can be modified.35 */36 37/**38 * dmub_srv_stat_get_notification - Retrieves a dmub outbox notification, set up dmub notification39 * structure with message information. Also a pending bit if queue40 * is having more notifications41 * @dmub: dmub srv structure42 * @notify: dmub notification structure to be filled up43 *44 * Returns: dmub_status45 */46enum dmub_status dmub_srv_stat_get_notification(struct dmub_srv *dmub,47 struct dmub_notification *notify)48{49 /**50 * This function is called without dal and dc locks, so51 * we shall not modify any dmub variables, only dmub->outbox1_rb52 * is exempted as it is exclusively accessed by this function53 */54 union dmub_rb_out_cmd cmd = {0};55 56 if (!dmub->hw_init) {57 notify->type = DMUB_NOTIFICATION_NO_DATA;58 notify->pending_notification = false;59 return DMUB_STATUS_INVALID;60 }61 62 /* Get write pointer which is updated by dmub */63 dmub->outbox1_rb.wrpt = dmub->hw_funcs.get_outbox1_wptr(dmub);64 65 if (!dmub_rb_out_front(&dmub->outbox1_rb, &cmd)) {66 notify->type = DMUB_NOTIFICATION_NO_DATA;67 notify->pending_notification = false;68 return DMUB_STATUS_OK;69 }70 71 switch (cmd.cmd_common.header.type) {72 case DMUB_OUT_CMD__DP_AUX_REPLY:73 notify->type = DMUB_NOTIFICATION_AUX_REPLY;74 notify->link_index = cmd.dp_aux_reply.control.instance;75 notify->result = cmd.dp_aux_reply.control.result;76 dmub_memcpy((void *)¬ify->aux_reply,77 (void *)&cmd.dp_aux_reply.reply_data, sizeof(struct aux_reply_data));78 break;79 case DMUB_OUT_CMD__DP_HPD_NOTIFY:80 if (cmd.dp_hpd_notify.hpd_data.hpd_type == DP_HPD) {81 notify->type = DMUB_NOTIFICATION_HPD;82 notify->hpd_status = cmd.dp_hpd_notify.hpd_data.hpd_status;83 } else {84 notify->type = DMUB_NOTIFICATION_HPD_IRQ;85 }86 87 notify->link_index = cmd.dp_hpd_notify.hpd_data.instance;88 notify->result = AUX_RET_SUCCESS;89 break;90 case DMUB_OUT_CMD__SET_CONFIG_REPLY:91 notify->type = DMUB_NOTIFICATION_SET_CONFIG_REPLY;92 notify->link_index = cmd.set_config_reply.set_config_reply_control.instance;93 notify->sc_status = cmd.set_config_reply.set_config_reply_control.status;94 break;95 case DMUB_OUT_CMD__DPIA_NOTIFICATION:96 notify->type = DMUB_NOTIFICATION_DPIA_NOTIFICATION;97 notify->link_index = cmd.dpia_notification.payload.header.instance;98 99 if (cmd.dpia_notification.payload.header.type == DPIA_NOTIFY__BW_ALLOCATION) {100 101 notify->dpia_notification.payload.data.dpia_bw_alloc.estimated_bw =102 cmd.dpia_notification.payload.data.dpia_bw_alloc.estimated_bw;103 notify->dpia_notification.payload.data.dpia_bw_alloc.allocated_bw =104 cmd.dpia_notification.payload.data.dpia_bw_alloc.allocated_bw;105 106 if (cmd.dpia_notification.payload.data.dpia_bw_alloc.bits.bw_request_failed)107 notify->result = DPIA_BW_REQ_FAILED;108 else if (cmd.dpia_notification.payload.data.dpia_bw_alloc.bits.bw_request_succeeded)109 notify->result = DPIA_BW_REQ_SUCCESS;110 else if (cmd.dpia_notification.payload.data.dpia_bw_alloc.bits.est_bw_changed)111 notify->result = DPIA_EST_BW_CHANGED;112 else if (cmd.dpia_notification.payload.data.dpia_bw_alloc.bits.bw_alloc_cap_changed)113 notify->result = DPIA_BW_ALLOC_CAPS_CHANGED;114 }115 break;116 case DMUB_OUT_CMD__HPD_SENSE_NOTIFY:117 notify->type = DMUB_NOTIFICATION_HPD_SENSE_NOTIFY;118 dmub_memcpy(¬ify->hpd_sense_notify,119 &cmd.hpd_sense_notify.data,120 sizeof(cmd.hpd_sense_notify.data));121 break;122 default:123 notify->type = DMUB_NOTIFICATION_NO_DATA;124 break;125 }126 127 /* Pop outbox1 ringbuffer and update read pointer */128 dmub_rb_pop_front(&dmub->outbox1_rb);129 dmub->hw_funcs.set_outbox1_rptr(dmub, dmub->outbox1_rb.rptr);130 131 /**132 * Notify dc whether dmub has a pending outbox message,133 * this is to avoid one more call to dmub_srv_stat_get_notification134 */135 if (dmub_rb_empty(&dmub->outbox1_rb))136 notify->pending_notification = false;137 else138 notify->pending_notification = true;139 140 return DMUB_STATUS_OK;141}142