blob: cd526f95286ce541686bf39e47499646ba78d6ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** Utility */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_utility_pci_read PORTABLE C */
/* 6.1 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function reads a 32/16/8 bit value from a specific PCI bus */
/* at a certain offset. */
/* */
/* INPUT */
/* */
/* bus_number PCI bus number */
/* device_number Device number */
/* function_number Function number */
/* offset Offset */
/* read_size Size of read */
/* */
/* OUTPUT */
/* */
/* 32-bit value */
/* */
/* CALLS */
/* */
/* inpl PCI input long */
/* inpw PCI input word */
/* inpb PCI input byte */
/* outpl PCI output function */
/* */
/* CALLED BY */
/* */
/* USBX Components */
/* */
/**************************************************************************/
ULONG _ux_utility_pci_read(ULONG bus_number, ULONG device_number, ULONG function_number,
ULONG offset, UINT read_size)
{
ULONG destination_address;
ULONG cfg_ctrl;
/* Calculate the destination address. */
destination_address = (((bus_number << 16) & 0x00ff0000) | ((device_number << 11) & 0x0000f800) |
((function_number << 8) & 0x00000700));
/* Calculate the configure control value. */
cfg_ctrl = destination_address | offset | 0x80000000;
/* Read based on the size requested. */
switch(read_size)
{
case 32:
/* Write the address we need to read from. */
outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
/* Return the 32 bit content of this address. */
return(inpl(UX_PCI_CFG_DATA_ADDRESS));
case 16:
/* Write the address we need to read from. */
outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
/* Return the 16 bit content of this address. */
return((USHORT)(inpw(UX_PCI_CFG_DATA_ADDRESS)));
case 8:
/* Write the address we need to read from. */
outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl);
/* Return the 8 bit content of this address */
return((ULONG)(inpb(UX_PCI_CFG_DATA_ADDRESS)));
default:
return(0);
}
}
|