GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_utility_pci_write.c Lines: 20 20 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_write                               PORTABLE C      */
35
/*                                                           6.1          */
36
/*  AUTHOR                                                                */
37
/*                                                                        */
38
/*    Chaoqiong Xiao, Microsoft Corporation                               */
39
/*                                                                        */
40
/*  DESCRIPTION                                                           */
41
/*                                                                        */
42
/*    This function writes a 32/16/8 bit value to 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
/*    value                                 Value to write                */
52
/*    write_size                            Size of write                 */
53
/*                                                                        */
54
/*  OUTPUT                                                                */
55
/*                                                                        */
56
/*    None                                                                */
57
/*                                                                        */
58
/*  CALLS                                                                 */
59
/*                                                                        */
60
/*    outpl                                 PCI output long function      */
61
/*    outpw                                 PCI output word function      */
62
/*    outpb                                 PCI output byte 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
4
VOID  _ux_utility_pci_write(ULONG bus_number, ULONG device_number, ULONG function_number,
78
                                ULONG offset, ULONG value, UINT write_size)
79
{
80
81
ULONG   destination_address;
82
ULONG   cfg_ctrl;
83
84
85
    /* Calculate the destination address.  */
86
4
    destination_address =  (((bus_number << 16) & 0x00ff0000) | ((device_number << 11) & 0x0000f800) |
87
4
                                    ((function_number << 8) & 0x00000700));
88
89
    /* Calculate the configure control value.  */
90
4
    cfg_ctrl = destination_address | offset | 0x80000000;
91
92
    /* Process relative to write size.  */
93

4
    switch(write_size)
94
    {
95
96
1
    case 32:
97
98
        /* Write the address we need to write to.  */
99
1
        outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
100
101
        /* Write the 32 bit content of this address.  */
102
1
        outpl(UX_PCI_CFG_DATA_ADDRESS, value);
103
1
        break;
104
105
1
    case 16:
106
107
        /* Write the address we need to write to.  */
108
1
        outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
109
110
        /* Write the 16 bit content of this address.  */
111
1
        outpw(UX_PCI_CFG_DATA_ADDRESS + (offset & 2), (USHORT) value);
112
1
        break;
113
114
1
    case 8:
115
116
        /* Write the address we need to write to.  */
117
1
        outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
118
119
        /* Write the 8 bit content of this address */
120
1
        outpb(UX_PCI_CFG_DATA_ADDRESS + (offset & 3), (UCHAR) value);
121
1
        break;
122
123
1
    default:
124
125
1
        break;
126
    }
127
4
}
128