summaryrefslogtreecommitdiff
path: root/DuetPkg/PciRootBridgeNoEnumerationDxe/PcatPciRootBridge.h
blob: 50bd9b43b2a47fa79e2eb0f6f6a2eb43773c3119 (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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/*++

Copyright (c) 2005 - 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:
  PcatPciRootBridge.h

Abstract:

  The driver for the host to pci bridge (root bridge).

--*/

#ifndef _PCAT_PCI_ROOT_BRIDGE_H_
#define _PCAT_PCI_ROOT_BRIDGE_H_

#include <PiDxe.h>
#include <Protocol/PciRootBridgeIo.h>
#include <Protocol/DeviceIo.h>
#include <Protocol/CpuIo.h>

#include <Library/UefiLib.h>
#include <Library/BaseLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UefiBootServicesTableLib.h>
#include <Library/DebugLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DevicePathLib.h>
#include <Library/HobLib.h>

#include <Guid/PciOptionRomTable.h>
#include <Guid/HobList.h>
#include <Guid/PciExpressBaseAddress.h>

#include <IndustryStandard/Acpi.h>
#include <IndustryStandard/Pci.h>
//
// Driver Instance Data Prototypes
//
#define PCAT_PCI_ROOT_BRIDGE_SIGNATURE  EFI_SIGNATURE_32('p', 'c', 'r', 'b')

typedef struct {
  UINT32                            Signature;
  EFI_HANDLE                        Handle;
                                    
  EFI_DEVICE_PATH_PROTOCOL          *DevicePath;
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL   Io;
  EFI_CPU_IO_PROTOCOL               *CpuIo;

  UINT32                            RootBridgeNumber;
  UINT32                            PrimaryBus;
  UINT32                            SubordinateBus;
                                     
  UINT64                            MemBase;     // Offsets host to bus memory addr.
  UINT64                            MemLimit;    // Max allowable memory access
                                    
  UINT64                            IoBase;      // Offsets host to bus io addr.
  UINT64                            IoLimit;     // Max allowable io access
                                    
  UINT64                            PciAddress;
  UINT64                            PciData;
                                    
  UINT64                            PhysicalMemoryBase;
  UINT64                            PhysicalIoBase;
                                     
  EFI_LOCK                          PciLock;
                                    
  UINT64                            Attributes;
                                    
  UINT64                            Mem32Base;
  UINT64                            Mem32Limit;
  UINT64                            Pmem32Base;
  UINT64                            Pmem32Limit;
  UINT64                            Mem64Base;
  UINT64                            Mem64Limit;
  UINT64                            Pmem64Base;
  UINT64                            Pmem64Limit;

  UINT64                            PciExpressBaseAddress;

  EFI_ACPI_ADDRESS_SPACE_DESCRIPTOR *Configuration;

  LIST_ENTRY                    MapInfo;
} PCAT_PCI_ROOT_BRIDGE_INSTANCE;

//
// Driver Instance Data Macros
//
#define DRIVER_INSTANCE_FROM_PCI_ROOT_BRIDGE_IO_THIS(a) \
  CR(a, PCAT_PCI_ROOT_BRIDGE_INSTANCE, Io, PCAT_PCI_ROOT_BRIDGE_SIGNATURE)

#define VOLATILE volatile
//
// Private data types
//
typedef union {
  UINT8   VOLATILE  *buf;
  UINT8   VOLATILE  *ui8;
  UINT16  VOLATILE  *ui16;
  UINT32  VOLATILE  *ui32;
  UINT64  VOLATILE  *ui64;
  UINTN   VOLATILE  ui;
} PTR;

typedef struct {
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_OPERATION  Operation;
  UINTN                                      NumberOfBytes;
  UINTN                                      NumberOfPages;
  EFI_PHYSICAL_ADDRESS                       HostAddress;
  EFI_PHYSICAL_ADDRESS                       MappedHostAddress;
} MAP_INFO;

typedef struct {
  LIST_ENTRY Link;
  MAP_INFO * Map;  
} MAP_INFO_INSTANCE;

typedef
VOID
(*EFI_PCI_BUS_SCAN_CALLBACK) (
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *IoDev,
  UINT16                           MinBus,
  UINT16                           MaxBus,
  UINT16                           MinDevice,
  UINT16                           MaxDevice,
  UINT16                           MinFunc,
  UINT16                           MaxFunc,
  UINT16                           Bus,
  UINT16                           Device,
  UINT16                           Func,
  IN VOID                          *Context
  );

typedef struct {
  UINT16                    *CommandRegisterBuffer;
  UINT32                    PpbMemoryWindow;     
} PCAT_PCI_ROOT_BRIDGE_SCAN_FOR_ROM_CONTEXT;

//
// Driver Protocol Constructor Prototypes
//
EFI_STATUS 
ConstructConfiguration(
  IN OUT PCAT_PCI_ROOT_BRIDGE_INSTANCE  *PrivateData
  );

EFI_STATUS
PcatPciRootBridgeParseBars (
  IN PCAT_PCI_ROOT_BRIDGE_INSTANCE  *PrivateData,
  IN UINT16                         Command,
  IN UINTN                          Bus,
  IN UINTN                          Device,
  IN UINTN                          Function
  );

EFI_STATUS
ScanPciRootBridgeForRoms(
  EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *IoDev
  );

EFI_STATUS
PcatRootBridgeDevicePathConstructor (
  IN EFI_DEVICE_PATH_PROTOCOL  **Protocol,
  IN UINTN                     RootBridgeNumber,
  IN BOOLEAN                   IsPciExpress
  );

EFI_STATUS
PcatRootBridgeIoConstructor (
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL  *Protocol,
  IN UINTN                            SegmentNumber
  );

EFI_STATUS
PcatRootBridgeIoGetIoPortMapping (
  OUT EFI_PHYSICAL_ADDRESS  *IoPortMapping,
  OUT EFI_PHYSICAL_ADDRESS  *MemoryPortMapping
  );

EFI_STATUS
PcatRootBridgeIoPciRW (
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL        *This,
  IN BOOLEAN                                Write,
  IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH  Width,
  IN UINT64                                 UserAddress,
  IN UINTN                                  Count,
  IN OUT VOID                               *UserBuffer
  );

UINT64
GetPciExpressBaseAddressForRootBridge (
  IN UINTN    HostBridgeNumber,
  IN UINTN    RootBridgeNumber
  );

//
// Driver entry point prototype
//
EFI_STATUS
EFIAPI
InitializePcatPciRootBridge (
  IN EFI_HANDLE       ImageHandle,
  IN EFI_SYSTEM_TABLE *SystemTable
  );

extern EFI_CPU_IO_PROTOCOL  *gCpuIo;

#endif