• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /** @file
2   PCI resouces support functions declaration for PCI Bus module.
3 
4 Copyright (c) 2006 - 2011, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution.  The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9 
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12 
13 **/
14 
15 #ifndef _EFI_PCI_RESOURCE_SUPPORT_H_
16 #define _EFI_PCI_RESOURCE_SUPPORT_H_
17 
18 typedef enum {
19   PciResUsageTypical,
20   PciResUsagePadding
21 } PCI_RESOURCE_USAGE;
22 
23 #define PCI_RESOURCE_SIGNATURE  SIGNATURE_32 ('p', 'c', 'r', 'c')
24 
25 typedef struct {
26   UINT32              Signature;
27   LIST_ENTRY          Link;
28   LIST_ENTRY          ChildList;
29   PCI_IO_DEVICE       *PciDev;
30   UINT64              Alignment;
31   UINT64              Offset;
32   UINT8               Bar;
33   PCI_BAR_TYPE        ResType;
34   UINT64              Length;
35   BOOLEAN             Reserved;
36   PCI_RESOURCE_USAGE  ResourceUsage;
37   BOOLEAN             Virtual;
38 } PCI_RESOURCE_NODE;
39 
40 #define RESOURCE_NODE_FROM_LINK(a) \
41   CR (a, PCI_RESOURCE_NODE, Link, PCI_RESOURCE_SIGNATURE)
42 
43 /**
44   The function is used to skip VGA range.
45 
46   @param Start    Returned start address including VGA range.
47   @param Length   The length of VGA range.
48 
49 **/
50 VOID
51 SkipVGAAperture (
52   OUT UINT64   *Start,
53   IN  UINT64   Length
54   );
55 
56 /**
57   This function is used to skip ISA aliasing aperture.
58 
59   @param Start    Returned start address including ISA aliasing aperture.
60   @param Length   The length of ISA aliasing aperture.
61 
62 **/
63 VOID
64 SkipIsaAliasAperture (
65   OUT UINT64   *Start,
66   IN  UINT64   Length
67   );
68 
69 /**
70   This function inserts a resource node into the resource list.
71   The resource list is sorted in descend order.
72 
73   @param Bridge  PCI resource node for bridge.
74   @param ResNode Resource node want to be inserted.
75 
76 **/
77 VOID
78 InsertResourceNode (
79   IN OUT PCI_RESOURCE_NODE   *Bridge,
80   IN     PCI_RESOURCE_NODE   *ResNode
81   );
82 
83 /**
84   This routine is used to merge two different resource trees in need of
85   resoure degradation.
86 
87   For example, if an upstream PPB doesn't support,
88   prefetchable memory decoding, the PCI bus driver will choose to call this function
89   to merge prefectchable memory resource list into normal memory list.
90 
91   If the TypeMerge is TRUE, Res resource type is changed to the type of destination resource
92   type.
93   If Dst is NULL or Res is NULL, ASSERT ().
94 
95   @param Dst        Point to destination resource tree.
96   @param Res        Point to source resource tree.
97   @param TypeMerge  If the TypeMerge is TRUE, Res resource type is changed to the type of
98                     destination resource type.
99 
100 **/
101 VOID
102 MergeResourceTree (
103   IN PCI_RESOURCE_NODE   *Dst,
104   IN PCI_RESOURCE_NODE   *Res,
105   IN BOOLEAN             TypeMerge
106   );
107 
108 /**
109   This function is used to calculate the IO16 aperture
110   for a bridge.
111 
112   @param Bridge    PCI resource node for bridge.
113 
114 **/
115 VOID
116 CalculateApertureIo16 (
117   IN PCI_RESOURCE_NODE    *Bridge
118   );
119 
120 /**
121   This function is used to calculate the resource aperture
122   for a given bridge device.
123 
124   @param Bridge      PCI resouce node for given bridge device.
125 
126 **/
127 VOID
128 CalculateResourceAperture (
129   IN PCI_RESOURCE_NODE    *Bridge
130   );
131 
132 /**
133   Get IO/Memory resource infor for given PCI device.
134 
135   @param PciDev     Pci device instance.
136   @param IoNode     Resource info node for IO .
137   @param Mem32Node  Resource info node for 32-bit memory.
138   @param PMem32Node Resource info node for 32-bit Prefetchable Memory.
139   @param Mem64Node  Resource info node for 64-bit memory.
140   @param PMem64Node Resource info node for 64-bit Prefetchable Memory.
141 
142 **/
143 VOID
144 GetResourceFromDevice (
145   IN     PCI_IO_DEVICE     *PciDev,
146   IN OUT PCI_RESOURCE_NODE *IoNode,
147   IN OUT PCI_RESOURCE_NODE *Mem32Node,
148   IN OUT PCI_RESOURCE_NODE *PMem32Node,
149   IN OUT PCI_RESOURCE_NODE *Mem64Node,
150   IN OUT PCI_RESOURCE_NODE *PMem64Node
151   );
152 
153 /**
154   This function is used to create a resource node.
155 
156   @param PciDev       Pci device instance.
157   @param Length       Length of Io/Memory resource.
158   @param Alignment    Alignment of resource.
159   @param Bar          Bar index.
160   @param ResType      Type of resource: IO/Memory.
161   @param ResUsage     Resource usage.
162 
163   @return PCI resource node created for given PCI device.
164           NULL means PCI resource node is not created.
165 
166 **/
167 PCI_RESOURCE_NODE *
168 CreateResourceNode (
169   IN PCI_IO_DEVICE         *PciDev,
170   IN UINT64                Length,
171   IN UINT64                Alignment,
172   IN UINT8                 Bar,
173   IN PCI_BAR_TYPE          ResType,
174   IN PCI_RESOURCE_USAGE    ResUsage
175   );
176 
177 /**
178   This function is used to extract resource request from
179   IOV VF device node list.
180 
181   @param PciDev       Pci device instance.
182   @param Length       Length of Io/Memory resource.
183   @param Alignment    Alignment of resource.
184   @param Bar          Bar index.
185   @param ResType      Type of resource: IO/Memory.
186   @param ResUsage     Resource usage.
187 
188   @return PCI resource node created for given PCI device.
189           NULL means PCI resource node is not created.
190 
191 **/
192 PCI_RESOURCE_NODE *
193 CreateVfResourceNode (
194   IN PCI_IO_DEVICE         *PciDev,
195   IN UINT64                Length,
196   IN UINT64                Alignment,
197   IN UINT8                 Bar,
198   IN PCI_BAR_TYPE          ResType,
199   IN PCI_RESOURCE_USAGE    ResUsage
200   );
201 
202 /**
203   This function is used to extract resource request from
204   device node list.
205 
206   @param Bridge     Pci device instance.
207   @param IoNode     Resource info node for IO.
208   @param Mem32Node  Resource info node for 32-bit memory.
209   @param PMem32Node Resource info node for 32-bit Prefetchable Memory.
210   @param Mem64Node  Resource info node for 64-bit memory.
211   @param PMem64Node Resource info node for 64-bit Prefetchable Memory.
212 
213 **/
214 VOID
215 CreateResourceMap (
216   IN     PCI_IO_DEVICE     *Bridge,
217   IN OUT PCI_RESOURCE_NODE *IoNode,
218   IN OUT PCI_RESOURCE_NODE *Mem32Node,
219   IN OUT PCI_RESOURCE_NODE *PMem32Node,
220   IN OUT PCI_RESOURCE_NODE *Mem64Node,
221   IN OUT PCI_RESOURCE_NODE *PMem64Node
222   );
223 
224 /**
225   This function is used to do the resource padding for a specific platform.
226 
227   @param PciDev     Pci device instance.
228   @param IoNode     Resource info node for IO.
229   @param Mem32Node  Resource info node for 32-bit memory.
230   @param PMem32Node Resource info node for 32-bit Prefetchable Memory.
231   @param Mem64Node  Resource info node for 64-bit memory.
232   @param PMem64Node Resource info node for 64-bit Prefetchable Memory.
233 
234 **/
235 VOID
236 ResourcePaddingPolicy (
237   IN PCI_IO_DEVICE     *PciDev,
238   IN PCI_RESOURCE_NODE *IoNode,
239   IN PCI_RESOURCE_NODE *Mem32Node,
240   IN PCI_RESOURCE_NODE *PMem32Node,
241   IN PCI_RESOURCE_NODE *Mem64Node,
242   IN PCI_RESOURCE_NODE *PMem64Node
243   );
244 
245 /**
246   This function is used to degrade resource if the upstream bridge
247   doesn't support certain resource. Degradation path is
248   PMEM64 -> MEM64  -> MEM32
249   PMEM64 -> PMEM32 -> MEM32
250   IO32   -> IO16.
251 
252   @param Bridge     Pci device instance.
253   @param Mem32Node  Resource info node for 32-bit memory.
254   @param PMem32Node Resource info node for 32-bit Prefetchable Memory.
255   @param Mem64Node  Resource info node for 64-bit memory.
256   @param PMem64Node Resource info node for 64-bit Prefetchable Memory.
257 
258 **/
259 VOID
260 DegradeResource (
261   IN PCI_IO_DEVICE     *Bridge,
262   IN PCI_RESOURCE_NODE *Mem32Node,
263   IN PCI_RESOURCE_NODE *PMem32Node,
264   IN PCI_RESOURCE_NODE *Mem64Node,
265   IN PCI_RESOURCE_NODE *PMem64Node
266   );
267 
268 /**
269   Test whether bridge device support decode resource.
270 
271   @param Bridge    Bridge device instance.
272   @param Decode    Decode type according to resource type.
273 
274   @return TRUE     The bridge device support decode resource.
275   @return FALSE    The bridge device don't support decode resource.
276 
277 **/
278 BOOLEAN
279 BridgeSupportResourceDecode (
280   IN PCI_IO_DEVICE *Bridge,
281   IN UINT32        Decode
282   );
283 
284 /**
285   This function is used to program the resource allocated
286   for each resource node under specified bridge.
287 
288   @param Base     Base address of resource to be progammed.
289   @param Bridge   PCI resource node for the bridge device.
290 
291   @retval EFI_SUCCESS            Successfully to program all resouces
292                                  on given PCI bridge device.
293   @retval EFI_OUT_OF_RESOURCES   Base is all one.
294 
295 **/
296 EFI_STATUS
297 ProgramResource (
298   IN UINT64            Base,
299   IN PCI_RESOURCE_NODE *Bridge
300   );
301 
302 /**
303   Program Bar register for PCI device.
304 
305   @param Base  Base address for PCI device resource to be progammed.
306   @param Node  Point to resoure node structure.
307 
308 **/
309 VOID
310 ProgramBar (
311   IN UINT64            Base,
312   IN PCI_RESOURCE_NODE *Node
313   );
314 
315 /**
316   Program IOV VF Bar register for PCI device.
317 
318   @param Base  Base address for PCI device resource to be progammed.
319   @param Node  Point to resoure node structure.
320 
321 **/
322 EFI_STATUS
323 ProgramVfBar (
324   IN UINT64            Base,
325   IN PCI_RESOURCE_NODE *Node
326   );
327 
328 /**
329   Program PCI-PCI bridge apperture.
330 
331   @param Base  Base address for resource.
332   @param Node  Point to resoure node structure.
333 
334 **/
335 VOID
336 ProgramPpbApperture (
337   IN UINT64            Base,
338   IN PCI_RESOURCE_NODE *Node
339   );
340 
341 /**
342   Program parent bridge for Option Rom.
343 
344   @param PciDevice      Pci deivce instance.
345   @param OptionRomBase  Base address for Optiona Rom.
346   @param Enable         Enable or disable PCI memory.
347 
348 **/
349 VOID
350 ProgrameUpstreamBridgeForRom (
351   IN PCI_IO_DEVICE   *PciDevice,
352   IN UINT32          OptionRomBase,
353   IN BOOLEAN         Enable
354   );
355 
356 /**
357   Test whether resource exists for a bridge.
358 
359   @param Bridge  Point to resource node for a bridge.
360 
361   @retval TRUE   There is resource on the given bridge.
362   @retval FALSE  There isn't resource on the given bridge.
363 
364 **/
365 BOOLEAN
366 ResourceRequestExisted (
367   IN PCI_RESOURCE_NODE    *Bridge
368   );
369 
370 /**
371   Initialize resource pool structure.
372 
373   @param ResourcePool Point to resource pool structure. This pool
374                       is reset to all zero when returned.
375   @param ResourceType Type of resource.
376 
377 **/
378 VOID
379 InitializeResourcePool (
380   IN OUT PCI_RESOURCE_NODE   *ResourcePool,
381   IN     PCI_BAR_TYPE        ResourceType
382   );
383 
384 /**
385   Destory given resource tree.
386 
387   @param Bridge  PCI resource root node of resource tree.
388 
389 **/
390 VOID
391 DestroyResourceTree (
392   IN PCI_RESOURCE_NODE *Bridge
393   );
394 
395 /**
396   Insert resource padding for P2C.
397 
398   @param PciDev     Pci device instance.
399   @param IoNode     Resource info node for IO.
400   @param Mem32Node  Resource info node for 32-bit memory.
401   @param PMem32Node Resource info node for 32-bit Prefetchable Memory.
402   @param Mem64Node  Resource info node for 64-bit memory.
403   @param PMem64Node Resource info node for 64-bit Prefetchable Memory.
404 
405 **/
406 VOID
407 ResourcePaddingForCardBusBridge (
408   IN PCI_IO_DEVICE        *PciDev,
409   IN PCI_RESOURCE_NODE    *IoNode,
410   IN PCI_RESOURCE_NODE    *Mem32Node,
411   IN PCI_RESOURCE_NODE    *PMem32Node,
412   IN PCI_RESOURCE_NODE    *Mem64Node,
413   IN PCI_RESOURCE_NODE    *PMem64Node
414   );
415 
416 /**
417   Program PCI Card device register for given resource node.
418 
419   @param Base    Base address of PCI Card device to be programmed.
420   @param Node    Given resource node.
421 
422 **/
423 VOID
424 ProgramP2C (
425   IN UINT64            Base,
426   IN PCI_RESOURCE_NODE *Node
427   );
428 
429 /**
430   Create padding resource node.
431 
432   @param PciDev     Pci device instance.
433   @param IoNode     Resource info node for IO.
434   @param Mem32Node  Resource info node for 32-bit memory.
435   @param PMem32Node Resource info node for 32-bit Prefetchable Memory.
436   @param Mem64Node  Resource info node for 64-bit memory.
437   @param PMem64Node Resource info node for 64-bit Prefetchable Memory.
438 
439 **/
440 VOID
441 ApplyResourcePadding (
442   IN PCI_IO_DEVICE         *PciDev,
443   IN PCI_RESOURCE_NODE     *IoNode,
444   IN PCI_RESOURCE_NODE     *Mem32Node,
445   IN PCI_RESOURCE_NODE     *PMem32Node,
446   IN PCI_RESOURCE_NODE     *Mem64Node,
447   IN PCI_RESOURCE_NODE     *PMem64Node
448   );
449 
450 /**
451   Get padding resource for PCI-PCI bridge.
452 
453   @param  PciIoDevice     PCI-PCI bridge device instance.
454 
455   @note   Feature flag PcdPciBusHotplugDeviceSupport determines
456           whether need to pad resource for them.
457 **/
458 VOID
459 GetResourcePaddingPpb (
460   IN  PCI_IO_DEVICE                  *PciIoDevice
461   );
462 
463 #endif
464