1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
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 /* 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 /**************************************************************************/
_ux_utility_pci_class_scan(ULONG pci_class,ULONG bus_number,ULONG device_number,ULONG function_number,ULONG * current_bus_number,ULONG * current_device_number,ULONG * current_function_number)77 ULONG _ux_utility_pci_class_scan(ULONG pci_class, ULONG bus_number, ULONG device_number,
78 ULONG function_number, ULONG *current_bus_number,
79 ULONG *current_device_number, ULONG *current_function_number)
80 {
81
82 ULONG bus_number_index;
83 ULONG device_number_index;
84 ULONG function_number_index;
85 ULONG value;
86 ULONG current_pci_class;
87
88
89 /* Scan all bus. */
90 for (bus_number_index = bus_number; bus_number_index <= UX_PCI_NB_BUS; bus_number_index++)
91 {
92
93 /* Scan all devices. */
94 for(device_number_index = device_number;device_number_index <= UX_PCI_NB_DEVICE; device_number_index++)
95 {
96
97 /* Scan all functions. */
98 for(function_number_index = function_number; function_number_index <= UX_PCI_NB_FUNCTIONS; function_number_index++)
99 {
100
101 /* Reset all PCI address for next loop. */
102 function_number = 0;
103 device_number = 0;
104 bus_number = 0;
105
106 /* Read the PCI class bus/device/function. */
107 value = _ux_utility_pci_read(bus_number_index, device_number_index, function_number_index,
108 UX_PCI_CFG_REVISION,32);
109
110 /* Isolate the class code which is in the upper 3 bytes. */
111 current_pci_class = (value >> 8) & 0x00ffffff;
112
113 /* Do we have a match with the demanded class? */
114 if(current_pci_class == pci_class)
115 {
116
117 /* Return the position of this device on the PCI */
118 *current_bus_number = bus_number_index;
119 *current_device_number = device_number_index;
120 *current_function_number = function_number_index;
121
122 /* Return success! */
123 return(UX_SUCCESS);
124 }
125 }
126 }
127 }
128
129 /* Return an error since we didn't find anything. */
130 return(UX_ERROR);
131 }
132
133