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_read PORTABLE C */ |
36 |
|
|
/* 6.1 */ |
37 |
|
|
/* AUTHOR */ |
38 |
|
|
/* */ |
39 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
40 |
|
|
/* */ |
41 |
|
|
/* DESCRIPTION */ |
42 |
|
|
/* */ |
43 |
|
|
/* This function reads a 32/16/8 bit value from 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 |
|
|
/* read_size Size of read */ |
53 |
|
|
/* */ |
54 |
|
|
/* OUTPUT */ |
55 |
|
|
/* */ |
56 |
|
|
/* 32-bit value */ |
57 |
|
|
/* */ |
58 |
|
|
/* CALLS */ |
59 |
|
|
/* */ |
60 |
|
|
/* inpl PCI input long */ |
61 |
|
|
/* inpw PCI input word */ |
62 |
|
|
/* inpb PCI input byte */ |
63 |
|
|
/* outpl PCI output function */ |
64 |
|
|
/* */ |
65 |
|
|
/* CALLED BY */ |
66 |
|
|
/* */ |
67 |
|
|
/* USBX Components */ |
68 |
|
|
/* */ |
69 |
|
|
/**************************************************************************/ |
70 |
|
67589 |
ULONG _ux_utility_pci_read(ULONG bus_number, ULONG device_number, ULONG function_number, |
71 |
|
|
ULONG offset, UINT read_size) |
72 |
|
|
{ |
73 |
|
|
|
74 |
|
|
ULONG destination_address; |
75 |
|
|
ULONG cfg_ctrl; |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
/* Calculate the destination address. */ |
79 |
|
67589 |
destination_address = (((bus_number << 16) & 0x00ff0000) | ((device_number << 11) & 0x0000f800) | |
80 |
|
67589 |
((function_number << 8) & 0x00000700)); |
81 |
|
|
|
82 |
|
|
/* Calculate the configure control value. */ |
83 |
|
67589 |
cfg_ctrl = destination_address | offset | 0x80000000; |
84 |
|
|
|
85 |
|
|
/* Read based on the size requested. */ |
86 |
✓✓✓✓
|
67589 |
switch(read_size) |
87 |
|
|
{ |
88 |
|
|
|
89 |
|
67586 |
case 32: |
90 |
|
|
|
91 |
|
|
/* Write the address we need to read from. */ |
92 |
|
67586 |
outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl); |
93 |
|
|
|
94 |
|
|
/* Return the 32 bit content of this address. */ |
95 |
|
67586 |
return(inpl(UX_PCI_CFG_DATA_ADDRESS)); |
96 |
|
|
|
97 |
|
1 |
case 16: |
98 |
|
|
|
99 |
|
|
/* Write the address we need to read from. */ |
100 |
|
1 |
outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl); |
101 |
|
|
|
102 |
|
|
/* Return the 16 bit content of this address. */ |
103 |
|
1 |
return((USHORT)(inpw(UX_PCI_CFG_DATA_ADDRESS))); |
104 |
|
|
|
105 |
|
1 |
case 8: |
106 |
|
|
|
107 |
|
|
/* Write the address we need to read from. */ |
108 |
|
1 |
outpl(UX_PCI_CFG_CTRL_ADDRESS, cfg_ctrl); |
109 |
|
|
|
110 |
|
|
/* Return the 8 bit content of this address */ |
111 |
|
1 |
return((ULONG)(inpb(UX_PCI_CFG_DATA_ADDRESS))); |
112 |
|
|
|
113 |
|
1 |
default: |
114 |
|
|
|
115 |
|
1 |
return(0); |
116 |
|
|
} |
117 |
|
|
} |