GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_utility_pci_read.c Lines: 16 16 100.0 %
Date: 2024-12-12 17:16:36 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 *
4
 * This program and the accompanying materials are made available under the
5
 * terms of the MIT License which is available at
6
 * https://opensource.org/licenses/MIT.
7
 *
8
 * SPDX-License-Identifier: MIT
9
 **************************************************************************/
10
11
12
/**************************************************************************/
13
/**************************************************************************/
14
/**                                                                       */
15
/** USBX Component                                                        */
16
/**                                                                       */
17
/**   Utility                                                             */
18
/**                                                                       */
19
/**************************************************************************/
20
/**************************************************************************/
21
22
23
/* Include necessary system files.  */
24
25
#define UX_SOURCE_CODE
26
27
#include "ux_api.h"
28
29
30
/**************************************************************************/
31
/*                                                                        */
32
/*  FUNCTION                                               RELEASE        */
33
/*                                                                        */
34
/*    _ux_utility_pci_read                                PORTABLE C      */
35
/*                                                           6.1          */
36
/*  AUTHOR                                                                */
37
/*                                                                        */
38
/*    Chaoqiong Xiao, Microsoft Corporation                               */
39
/*                                                                        */
40
/*  DESCRIPTION                                                           */
41
/*                                                                        */
42
/*    This function reads a 32/16/8 bit value from a specific PCI bus     */
43
/*    at a certain offset.                                                */
44
/*                                                                        */
45
/*  INPUT                                                                 */
46
/*                                                                        */
47
/*    bus_number                            PCI bus number                */
48
/*    device_number                         Device number                 */
49
/*    function_number                       Function number               */
50
/*    offset                                Offset                        */
51
/*    read_size                             Size of read                  */
52
/*                                                                        */
53
/*  OUTPUT                                                                */
54
/*                                                                        */
55
/*    32-bit value                                                        */
56
/*                                                                        */
57
/*  CALLS                                                                 */
58
/*                                                                        */
59
/*    inpl                                  PCI input long                */
60
/*    inpw                                  PCI input word                */
61
/*    inpb                                  PCI input byte                */
62
/*    outpl                                 PCI output function           */
63
/*                                                                        */
64
/*  CALLED BY                                                             */
65
/*                                                                        */
66
/*    USBX Components                                                     */
67
/*                                                                        */
68
/*  RELEASE HISTORY                                                       */
69
/*                                                                        */
70
/*    DATE              NAME                      DESCRIPTION             */
71
/*                                                                        */
72
/*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
73
/*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
74
/*                                            resulting in version 6.1    */
75
/*                                                                        */
76
/**************************************************************************/
77
67589
ULONG  _ux_utility_pci_read(ULONG bus_number, ULONG device_number, ULONG function_number,
78
                                        ULONG offset, UINT read_size)
79
{
80
81
ULONG   destination_address;
82
ULONG   cfg_ctrl;
83
84
85
    /* Calculate the destination address.  */
86
67589
    destination_address =  (((bus_number << 16) & 0x00ff0000) | ((device_number << 11) & 0x0000f800) |
87
67589
                                ((function_number << 8) & 0x00000700));
88
89
    /* Calculate the configure control value.  */
90
67589
    cfg_ctrl = destination_address | offset | 0x80000000;
91
92
    /* Read based on the size requested.  */
93

67589
    switch(read_size)
94
    {
95
96
67586
    case 32:
97
98
        /* Write the address we need to read from.  */
99
67586
        outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
100
101
        /* Return the 32 bit content of this address.  */
102
67586
        return(inpl(UX_PCI_CFG_DATA_ADDRESS));
103
104
1
    case 16:
105
106
        /* Write the address we need to read from.  */
107
1
        outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
108
109
        /* Return the 16 bit content of this address.  */
110
1
        return((USHORT)(inpw(UX_PCI_CFG_DATA_ADDRESS)));
111
112
1
    case 8:
113
114
        /* Write the address we need to read from.  */
115
1
        outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
116
117
        /* Return the 8 bit content of this address */
118
1
        return((ULONG)(inpb(UX_PCI_CFG_DATA_ADDRESS)));
119
120
1
    default:
121
122
1
        return(0);
123
    }
124
}