Back to home page

OSCL-LXR

 
 

    


0001 /*
0002  * Copyright 2019 Advanced Micro Devices, Inc.
0003  *
0004  * Permission is hereby granted, free of charge, to any person obtaining a
0005  * copy of this software and associated documentation files (the "Software"),
0006  * to deal in the Software without restriction, including without limitation
0007  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
0008  * and/or sell copies of the Software, and to permit persons to whom the
0009  * Software is furnished to do so, subject to the following conditions:
0010  *
0011  * The above copyright notice and this permission notice shall be included in
0012  * all copies or substantial portions of the Software.
0013  *
0014  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0015  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0016  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
0017  * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
0018  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
0019  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
0020  * OTHER DEALINGS IN THE SOFTWARE.
0021  *
0022  * Authors: AMD
0023  *
0024  */
0025 
0026 #include "dmub/dmub_srv_stat.h"
0027 #include "dmub/inc/dmub_cmd.h"
0028 
0029 /**
0030  * DOC: DMUB_SRV STAT Interface
0031  *
0032  * These interfaces are called without acquiring DAL and DC locks.
0033  * Hence, there is limitations on whese interfaces can access. Only
0034  * variables exclusively defined for these interfaces can be modified.
0035  */
0036 
0037 /**
0038  * dmub_srv_stat_get_notification - Retrieves a dmub outbox notification, set up dmub notification
0039  *                                  structure with message information. Also a pending bit if queue
0040  *                                  is having more notifications
0041  *  @dmub: dmub srv structure
0042  *  @notify: dmub notification structure to be filled up
0043  *
0044  *  Returns: dmub_status
0045  */
0046 enum dmub_status dmub_srv_stat_get_notification(struct dmub_srv *dmub,
0047                         struct dmub_notification *notify)
0048 {
0049     /**
0050      * This function is called without dal and dc locks, so
0051      * we shall not modify any dmub variables, only dmub->outbox1_rb
0052      * is exempted as it is exclusively accessed by this function
0053      */
0054     union dmub_rb_out_cmd cmd = {0};
0055 
0056     if (!dmub->hw_init) {
0057         notify->type = DMUB_NOTIFICATION_NO_DATA;
0058         notify->pending_notification = false;
0059         return DMUB_STATUS_INVALID;
0060     }
0061 
0062     /* Get write pointer which is updated by dmub */
0063     dmub->outbox1_rb.wrpt = dmub->hw_funcs.get_outbox1_wptr(dmub);
0064 
0065     if (!dmub_rb_out_front(&dmub->outbox1_rb, &cmd)) {
0066         notify->type = DMUB_NOTIFICATION_NO_DATA;
0067         notify->pending_notification = false;
0068         return DMUB_STATUS_OK;
0069     }
0070 
0071     switch (cmd.cmd_common.header.type) {
0072     case DMUB_OUT_CMD__DP_AUX_REPLY:
0073         notify->type = DMUB_NOTIFICATION_AUX_REPLY;
0074         notify->link_index = cmd.dp_aux_reply.control.instance;
0075         notify->result = cmd.dp_aux_reply.control.result;
0076         dmub_memcpy((void *)&notify->aux_reply,
0077             (void *)&cmd.dp_aux_reply.reply_data, sizeof(struct aux_reply_data));
0078         break;
0079     case DMUB_OUT_CMD__DP_HPD_NOTIFY:
0080         if (cmd.dp_hpd_notify.hpd_data.hpd_type == DP_HPD) {
0081             notify->type = DMUB_NOTIFICATION_HPD;
0082             notify->hpd_status = cmd.dp_hpd_notify.hpd_data.hpd_status;
0083         } else {
0084             notify->type = DMUB_NOTIFICATION_HPD_IRQ;
0085         }
0086 
0087         notify->link_index = cmd.dp_hpd_notify.hpd_data.instance;
0088         notify->result = AUX_RET_SUCCESS;
0089         break;
0090     case DMUB_OUT_CMD__SET_CONFIG_REPLY:
0091         notify->type = DMUB_NOTIFICATION_SET_CONFIG_REPLY;
0092         notify->link_index = cmd.set_config_reply.set_config_reply_control.instance;
0093         notify->sc_status = cmd.set_config_reply.set_config_reply_control.status;
0094         break;
0095     default:
0096         notify->type = DMUB_NOTIFICATION_NO_DATA;
0097         break;
0098     }
0099 
0100     /* Pop outbox1 ringbuffer and update read pointer */
0101     dmub_rb_pop_front(&dmub->outbox1_rb);
0102     dmub->hw_funcs.set_outbox1_rptr(dmub, dmub->outbox1_rb.rptr);
0103 
0104     /**
0105      * Notify dc whether dmub has a pending outbox message,
0106      * this is to avoid one more call to dmub_srv_stat_get_notification
0107      */
0108     if (dmub_rb_empty(&dmub->outbox1_rb))
0109         notify->pending_notification = false;
0110     else
0111         notify->pending_notification = true;
0112 
0113     return DMUB_STATUS_OK;
0114 }