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_class_scan PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function scans the PCI bus from a certain position for a */ |
44 |
|
|
/* specific PCI class. */ |
45 |
|
|
/* */ |
46 |
|
|
/* INPUT */ |
47 |
|
|
/* */ |
48 |
|
|
/* pci_class PCI class requested */ |
49 |
|
|
/* bus_number PCI bus number */ |
50 |
|
|
/* device_number Device number */ |
51 |
|
|
/* function_number Function number */ |
52 |
|
|
/* current_bus_number Current bus number */ |
53 |
|
|
/* current_device_number Current device number */ |
54 |
|
|
/* current_function_number Current function number */ |
55 |
|
|
/* */ |
56 |
|
|
/* OUTPUT */ |
57 |
|
|
/* */ |
58 |
|
|
/* 32-bit value */ |
59 |
|
|
/* */ |
60 |
|
|
/* CALLS */ |
61 |
|
|
/* */ |
62 |
|
|
/* _ux_utility_pci_read PCI read utility */ |
63 |
|
|
/* */ |
64 |
|
|
/* CALLED BY */ |
65 |
|
|
/* */ |
66 |
|
|
/* USBX Components */ |
67 |
|
|
/* */ |
68 |
|
|
/**************************************************************************/ |
69 |
|
2 |
ULONG _ux_utility_pci_class_scan(ULONG pci_class, ULONG bus_number, ULONG device_number, |
70 |
|
|
ULONG function_number, ULONG *current_bus_number, |
71 |
|
|
ULONG *current_device_number, ULONG *current_function_number) |
72 |
|
|
{ |
73 |
|
|
|
74 |
|
|
ULONG bus_number_index; |
75 |
|
|
ULONG device_number_index; |
76 |
|
|
ULONG function_number_index; |
77 |
|
|
ULONG value; |
78 |
|
|
ULONG current_pci_class; |
79 |
|
|
|
80 |
|
|
|
81 |
|
|
/* Scan all bus. */ |
82 |
✓✓ |
258 |
for (bus_number_index = bus_number; bus_number_index <= UX_PCI_NB_BUS; bus_number_index++) |
83 |
|
|
{ |
84 |
|
|
|
85 |
|
|
/* Scan all devices. */ |
86 |
✓✓ |
8705 |
for(device_number_index = device_number;device_number_index <= UX_PCI_NB_DEVICE; device_number_index++) |
87 |
|
|
{ |
88 |
|
|
|
89 |
|
|
/* Scan all functions. */ |
90 |
✓✓ |
76033 |
for(function_number_index = function_number; function_number_index <= UX_PCI_NB_FUNCTIONS; function_number_index++) |
91 |
|
|
{ |
92 |
|
|
|
93 |
|
|
/* Reset all PCI address for next loop. */ |
94 |
|
67585 |
function_number = 0; |
95 |
|
67585 |
device_number = 0; |
96 |
|
67585 |
bus_number = 0; |
97 |
|
|
|
98 |
|
|
/* Read the PCI class bus/device/function. */ |
99 |
|
67585 |
value = _ux_utility_pci_read(bus_number_index, device_number_index, function_number_index, |
100 |
|
|
UX_PCI_CFG_REVISION,32); |
101 |
|
|
|
102 |
|
|
/* Isolate the class code which is in the upper 3 bytes. */ |
103 |
|
67585 |
current_pci_class = (value >> 8) & 0x00ffffff; |
104 |
|
|
|
105 |
|
|
/* Do we have a match with the demanded class? */ |
106 |
✓✓ |
67585 |
if(current_pci_class == pci_class) |
107 |
|
|
{ |
108 |
|
|
|
109 |
|
|
/* Return the position of this device on the PCI */ |
110 |
|
1 |
*current_bus_number = bus_number_index; |
111 |
|
1 |
*current_device_number = device_number_index; |
112 |
|
1 |
*current_function_number = function_number_index; |
113 |
|
|
|
114 |
|
|
/* Return success! */ |
115 |
|
1 |
return(UX_SUCCESS); |
116 |
|
|
} |
117 |
|
|
} |
118 |
|
|
} |
119 |
|
|
} |
120 |
|
|
|
121 |
|
|
/* Return an error since we didn't find anything. */ |
122 |
|
1 |
return(UX_ERROR); |
123 |
|
|
} |
124 |
|
|
|