GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: core/src/ux_utility_pci_write.c Lines: 20 20 100.0 %
Date: 2026-03-06 18:57:10 Branches: 4 4 100.0 %

Line Branch Exec Source
1
/***************************************************************************
2
 * Copyright (c) 2024 Microsoft Corporation
3
 * Copyright (c) 2026-present Eclipse ThreadX contributors
4
 *
5
 * This program and the accompanying materials are made available under the
6
 * terms of the MIT License which is available at
7
 * https://opensource.org/licenses/MIT.
8
 *
9
 * SPDX-License-Identifier: MIT
10
 **************************************************************************/
11
12
13
/**************************************************************************/
14
/**************************************************************************/
15
/**                                                                       */
16
/** USBX Component                                                        */
17
/**                                                                       */
18
/**   Utility                                                             */
19
/**                                                                       */
20
/**************************************************************************/
21
/**************************************************************************/
22
23
24
/* Include necessary system files.  */
25
26
#define UX_SOURCE_CODE
27
28
#include "ux_api.h"
29
30
31
/**************************************************************************/
32
/*                                                                        */
33
/*  FUNCTION                                               RELEASE        */
34
/*                                                                        */
35
/*    _ux_utility_pci_write                               PORTABLE C      */
36
/*                                                           6.1          */
37
/*  AUTHOR                                                                */
38
/*                                                                        */
39
/*    Chaoqiong Xiao, Microsoft Corporation                               */
40
/*                                                                        */
41
/*  DESCRIPTION                                                           */
42
/*                                                                        */
43
/*    This function writes a 32/16/8 bit value to a specific PCI bus      */
44
/*    at a certain offset.                                                */
45
/*                                                                        */
46
/*  INPUT                                                                 */
47
/*                                                                        */
48
/*    bus_number                            PCI bus number                */
49
/*    device_number                         Device number                 */
50
/*    function_number                       Function number               */
51
/*    offset                                Offset                        */
52
/*    value                                 Value to write                */
53
/*    write_size                            Size of write                 */
54
/*                                                                        */
55
/*  OUTPUT                                                                */
56
/*                                                                        */
57
/*    None                                                                */
58
/*                                                                        */
59
/*  CALLS                                                                 */
60
/*                                                                        */
61
/*    outpl                                 PCI output long function      */
62
/*    outpw                                 PCI output word function      */
63
/*    outpb                                 PCI output byte function      */
64
/*                                                                        */
65
/*  CALLED BY                                                             */
66
/*                                                                        */
67
/*    USBX Components                                                     */
68
/*                                                                        */
69
/**************************************************************************/
70
4
VOID  _ux_utility_pci_write(ULONG bus_number, ULONG device_number, ULONG function_number,
71
                                ULONG offset, ULONG value, UINT write_size)
72
{
73
74
ULONG   destination_address;
75
ULONG   cfg_ctrl;
76
77
78
    /* Calculate the destination address.  */
79
4
    destination_address =  (((bus_number << 16) & 0x00ff0000) | ((device_number << 11) & 0x0000f800) |
80
4
                                    ((function_number << 8) & 0x00000700));
81
82
    /* Calculate the configure control value.  */
83
4
    cfg_ctrl = destination_address | offset | 0x80000000;
84
85
    /* Process relative to write size.  */
86

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