cachepc-linux

Fork of AMDESE/linux with modifications for CachePC side-channel attack
git clone https://git.sinitax.com/sinitax/cachepc-linux
Log | Files | Refs | README | LICENSE | sfeed.txt

bios_parser_common.c (7454B)


      1/*
      2 * Copyright 2012-15 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#include "bios_parser_common.h"
     27#include "include/grph_object_ctrl_defs.h"
     28
     29static enum object_type object_type_from_bios_object_id(uint32_t bios_object_id)
     30{
     31	uint32_t bios_object_type = (bios_object_id & OBJECT_TYPE_MASK)
     32				>> OBJECT_TYPE_SHIFT;
     33	enum object_type object_type;
     34
     35	switch (bios_object_type) {
     36	case GRAPH_OBJECT_TYPE_GPU:
     37		object_type = OBJECT_TYPE_GPU;
     38		break;
     39	case GRAPH_OBJECT_TYPE_ENCODER:
     40		object_type = OBJECT_TYPE_ENCODER;
     41		break;
     42	case GRAPH_OBJECT_TYPE_CONNECTOR:
     43		object_type = OBJECT_TYPE_CONNECTOR;
     44		break;
     45	case GRAPH_OBJECT_TYPE_ROUTER:
     46		object_type = OBJECT_TYPE_ROUTER;
     47		break;
     48	case GRAPH_OBJECT_TYPE_GENERIC:
     49		object_type = OBJECT_TYPE_GENERIC;
     50		break;
     51	default:
     52		object_type = OBJECT_TYPE_UNKNOWN;
     53		break;
     54	}
     55
     56	return object_type;
     57}
     58
     59static enum object_enum_id enum_id_from_bios_object_id(uint32_t bios_object_id)
     60{
     61	uint32_t bios_enum_id =
     62			(bios_object_id & ENUM_ID_MASK) >> ENUM_ID_SHIFT;
     63	enum object_enum_id id;
     64
     65	switch (bios_enum_id) {
     66	case GRAPH_OBJECT_ENUM_ID1:
     67		id = ENUM_ID_1;
     68		break;
     69	case GRAPH_OBJECT_ENUM_ID2:
     70		id = ENUM_ID_2;
     71		break;
     72	case GRAPH_OBJECT_ENUM_ID3:
     73		id = ENUM_ID_3;
     74		break;
     75	case GRAPH_OBJECT_ENUM_ID4:
     76		id = ENUM_ID_4;
     77		break;
     78	case GRAPH_OBJECT_ENUM_ID5:
     79		id = ENUM_ID_5;
     80		break;
     81	case GRAPH_OBJECT_ENUM_ID6:
     82		id = ENUM_ID_6;
     83		break;
     84	case GRAPH_OBJECT_ENUM_ID7:
     85		id = ENUM_ID_7;
     86		break;
     87	default:
     88		id = ENUM_ID_UNKNOWN;
     89		break;
     90	}
     91
     92	return id;
     93}
     94
     95static uint32_t gpu_id_from_bios_object_id(uint32_t bios_object_id)
     96{
     97	return (bios_object_id & OBJECT_ID_MASK) >> OBJECT_ID_SHIFT;
     98}
     99
    100static enum encoder_id encoder_id_from_bios_object_id(uint32_t bios_object_id)
    101{
    102	uint32_t bios_encoder_id = gpu_id_from_bios_object_id(bios_object_id);
    103	enum encoder_id id;
    104
    105	switch (bios_encoder_id) {
    106	case ENCODER_OBJECT_ID_INTERNAL_LVDS:
    107		id = ENCODER_ID_INTERNAL_LVDS;
    108		break;
    109	case ENCODER_OBJECT_ID_INTERNAL_TMDS1:
    110		id = ENCODER_ID_INTERNAL_TMDS1;
    111		break;
    112	case ENCODER_OBJECT_ID_INTERNAL_TMDS2:
    113		id = ENCODER_ID_INTERNAL_TMDS2;
    114		break;
    115	case ENCODER_OBJECT_ID_INTERNAL_DAC1:
    116		id = ENCODER_ID_INTERNAL_DAC1;
    117		break;
    118	case ENCODER_OBJECT_ID_INTERNAL_DAC2:
    119		id = ENCODER_ID_INTERNAL_DAC2;
    120		break;
    121	case ENCODER_OBJECT_ID_INTERNAL_LVTM1:
    122		id = ENCODER_ID_INTERNAL_LVTM1;
    123		break;
    124	case ENCODER_OBJECT_ID_HDMI_INTERNAL:
    125		id = ENCODER_ID_INTERNAL_HDMI;
    126		break;
    127	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_TMDS1:
    128		id = ENCODER_ID_INTERNAL_KLDSCP_TMDS1;
    129		break;
    130	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC1:
    131		id = ENCODER_ID_INTERNAL_KLDSCP_DAC1;
    132		break;
    133	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DAC2:
    134		id = ENCODER_ID_INTERNAL_KLDSCP_DAC2;
    135		break;
    136	case ENCODER_OBJECT_ID_MVPU_FPGA:
    137		id = ENCODER_ID_EXTERNAL_MVPU_FPGA;
    138		break;
    139	case ENCODER_OBJECT_ID_INTERNAL_DDI:
    140		id = ENCODER_ID_INTERNAL_DDI;
    141		break;
    142	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY:
    143		id = ENCODER_ID_INTERNAL_UNIPHY;
    144		break;
    145	case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA:
    146		id = ENCODER_ID_INTERNAL_KLDSCP_LVTMA;
    147		break;
    148	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1:
    149		id = ENCODER_ID_INTERNAL_UNIPHY1;
    150		break;
    151	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2:
    152		id = ENCODER_ID_INTERNAL_UNIPHY2;
    153		break;
    154	case ENCODER_OBJECT_ID_ALMOND: /* ENCODER_OBJECT_ID_NUTMEG */
    155		id = ENCODER_ID_EXTERNAL_NUTMEG;
    156		break;
    157	case ENCODER_OBJECT_ID_TRAVIS:
    158		id = ENCODER_ID_EXTERNAL_TRAVIS;
    159		break;
    160	case ENCODER_OBJECT_ID_INTERNAL_UNIPHY3:
    161		id = ENCODER_ID_INTERNAL_UNIPHY3;
    162		break;
    163	default:
    164		id = ENCODER_ID_UNKNOWN;
    165		ASSERT(0);
    166		break;
    167	}
    168
    169	return id;
    170}
    171
    172static enum connector_id connector_id_from_bios_object_id(
    173	uint32_t bios_object_id)
    174{
    175	uint32_t bios_connector_id = gpu_id_from_bios_object_id(bios_object_id);
    176
    177	enum connector_id id;
    178
    179	switch (bios_connector_id) {
    180	case CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_I:
    181		id = CONNECTOR_ID_SINGLE_LINK_DVII;
    182		break;
    183	case CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_I:
    184		id = CONNECTOR_ID_DUAL_LINK_DVII;
    185		break;
    186	case CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D:
    187		id = CONNECTOR_ID_SINGLE_LINK_DVID;
    188		break;
    189	case CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D:
    190		id = CONNECTOR_ID_DUAL_LINK_DVID;
    191		break;
    192	case CONNECTOR_OBJECT_ID_VGA:
    193		id = CONNECTOR_ID_VGA;
    194		break;
    195	case CONNECTOR_OBJECT_ID_HDMI_TYPE_A:
    196		id = CONNECTOR_ID_HDMI_TYPE_A;
    197		break;
    198	case CONNECTOR_OBJECT_ID_LVDS:
    199		id = CONNECTOR_ID_LVDS;
    200		break;
    201	case CONNECTOR_OBJECT_ID_PCIE_CONNECTOR:
    202		id = CONNECTOR_ID_PCIE;
    203		break;
    204	case CONNECTOR_OBJECT_ID_HARDCODE_DVI:
    205		id = CONNECTOR_ID_HARDCODE_DVI;
    206		break;
    207	case CONNECTOR_OBJECT_ID_DISPLAYPORT:
    208		id = CONNECTOR_ID_DISPLAY_PORT;
    209		break;
    210	case CONNECTOR_OBJECT_ID_eDP:
    211		id = CONNECTOR_ID_EDP;
    212		break;
    213	case CONNECTOR_OBJECT_ID_MXM:
    214		id = CONNECTOR_ID_MXM;
    215		break;
    216	case CONNECTOR_OBJECT_ID_USBC:
    217		id = CONNECTOR_ID_USBC;
    218		break;
    219	default:
    220		id = CONNECTOR_ID_UNKNOWN;
    221		break;
    222	}
    223
    224	return id;
    225}
    226
    227static enum generic_id generic_id_from_bios_object_id(uint32_t bios_object_id)
    228{
    229	uint32_t bios_generic_id = gpu_id_from_bios_object_id(bios_object_id);
    230
    231	enum generic_id id;
    232
    233	switch (bios_generic_id) {
    234	case GENERIC_OBJECT_ID_MXM_OPM:
    235		id = GENERIC_ID_MXM_OPM;
    236		break;
    237	case GENERIC_OBJECT_ID_GLSYNC:
    238		id = GENERIC_ID_GLSYNC;
    239		break;
    240	case GENERIC_OBJECT_ID_STEREO_PIN:
    241		id = GENERIC_ID_STEREO;
    242		break;
    243	default:
    244		id = GENERIC_ID_UNKNOWN;
    245		break;
    246	}
    247
    248	return id;
    249}
    250
    251static uint32_t id_from_bios_object_id(enum object_type type,
    252	uint32_t bios_object_id)
    253{
    254	switch (type) {
    255	case OBJECT_TYPE_GPU:
    256		return gpu_id_from_bios_object_id(bios_object_id);
    257	case OBJECT_TYPE_ENCODER:
    258		return (uint32_t)encoder_id_from_bios_object_id(bios_object_id);
    259	case OBJECT_TYPE_CONNECTOR:
    260		return (uint32_t)connector_id_from_bios_object_id(
    261				bios_object_id);
    262	case OBJECT_TYPE_GENERIC:
    263		return generic_id_from_bios_object_id(bios_object_id);
    264	default:
    265		return 0;
    266	}
    267}
    268
    269struct graphics_object_id object_id_from_bios_object_id(uint32_t bios_object_id)
    270{
    271	enum object_type type;
    272	enum object_enum_id enum_id;
    273	struct graphics_object_id go_id = { 0 };
    274
    275	type = object_type_from_bios_object_id(bios_object_id);
    276
    277	if (OBJECT_TYPE_UNKNOWN == type)
    278		return go_id;
    279
    280	enum_id = enum_id_from_bios_object_id(bios_object_id);
    281
    282	if (ENUM_ID_UNKNOWN == enum_id)
    283		return go_id;
    284
    285	go_id = dal_graphics_object_id_init(
    286			id_from_bios_object_id(type, bios_object_id), enum_id, type);
    287
    288	return go_id;
    289}
    290
    291