1 /*******************************************************************************
2 Copyright (C) Marvell International Ltd. and its affiliates
4 This software file (the "File") is owned and distributed by Marvell
5 International Ltd. and/or its affiliates ("Marvell") under the following
6 alternative licensing terms. Once you have made an election to distribute the
7 File under one of the following license alternatives, please (i) delete this
8 introductory statement regarding license alternatives, (ii) delete the two
9 license alternatives that you have not elected to use and (iii) preserve the
10 Marvell copyright notice above.
12 ********************************************************************************
13 Marvell Commercial License Option
15 If you received this File from Marvell and you have entered into a commercial
16 license agreement (a "Commercial License") with Marvell, the File is licensed
17 to you under the terms of the applicable Commercial License.
19 ********************************************************************************
20 Marvell GPL License Option
22 If you received this File from Marvell, you may opt to use, redistribute and/or
23 modify this File in accordance with the terms and conditions of the General
24 Public License Version 2, June 1991 (the "GPL License"), a copy of which is
25 available along with the File in the license.txt file or by writing to the Free
26 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 or
27 on the worldwide web at http://www.gnu.org/licenses/gpl.txt.
29 THE FILE IS DISTRIBUTED AS-IS, WITHOUT WARRANTY OF ANY KIND, AND THE IMPLIED
30 WARRANTIES OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY
31 DISCLAIMED. The GPL License provides additional details about this warranty
33 ********************************************************************************
34 Marvell BSD License Option
36 If you received this File from Marvell, you may opt to use, redistribute and/or
37 modify this File under the following licensing terms.
38 Redistribution and use in source and binary forms, with or without modification,
39 are permitted provided that the following conditions are met:
41 * Redistributions of source code must retain the above copyright notice,
42 this list of conditions and the following disclaimer.
44 * Redistributions in binary form must reproduce the above copyright
45 notice, this list of conditions and the following disclaimer in the
46 documentation and/or other materials provided with the distribution.
48 * Neither the name of Marvell nor the names of its contributors may be
49 used to endorse or promote products derived from this software without
50 specific prior written permission.
52 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
53 ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
54 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
55 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
56 ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
57 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
58 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
59 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
60 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
61 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
63 *******************************************************************************/
66 #include "mvPciUtils.h"
68 #include "ctrlEnv/mvCtrlEnvLib.h"
70 /* #define MV_DEBUG */
74 #define mvOsPrintf printf
80 This module only support scanning of Header type 00h of pci devices
81 There is no suppotr for Header type 01h of pci devices ( PCI bridges )
85 static MV_STATUS
pciDetectDevice(MV_U32 pciIf
,
89 MV_PCI_DEVICE
*pPciAgent
);
91 static MV_U32
pciDetectDeviceBars(MV_U32 pciIf
,
95 MV_PCI_DEVICE
*pPciAgent
);
102 /*******************************************************************************
103 * mvPciScan - Scan a PCI interface bus
106 * Performs a full scan on a PCI interface and returns all possible details
107 * on the agents found on the bus.
110 * pciIf - PCI Interface
111 * pPciAgents - Pointer to an Array of the pci agents to be detected
112 * pPciAgentsNum - pPciAgents array maximum number of elements
115 * pPciAgents - Array of the pci agents detected on the bus
116 * pPciAgentsNum - Number of pci agents detected on the bus
119 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
121 *******************************************************************************/
123 MV_STATUS
mvPciScan(MV_U32 pciIf
,
124 MV_PCI_DEVICE
*pPciAgents
,
125 MV_U32
*pPciAgentsNum
)
128 MV_U32 devIndex
,funcIndex
=0,busIndex
=0,detectedDevNum
=0;
129 MV_U32 localBus
=mvPciIfLocalBusNumGet(pciIf
);
130 MV_PCI_DEVICE
*pPciDevice
;
131 MV_PCI_DEVICE
*pMainDevice
;
133 DB(mvOsPrintf("mvPciScan: PCI interface num %d\n", pciIf
));
134 /* Parameter checking */
135 if (pciIf
>= mvCtrlPexMaxIfGet())
137 DB(mvOsPrintf("mvPciScan: ERR. Invalid PCI interface num %d\n", pciIf
));
140 if (NULL
== pPciAgents
)
142 DB(mvOsPrintf("mvPciScan: ERR. pPciAgents=NULL \n"));
145 if (NULL
== pPciAgentsNum
)
147 DB(mvOsPrintf("mvPciScan: ERR. pPciAgentsNum=NULL \n"));
152 DB(mvOsPrintf("mvPciScan: PCI interface num %d mvPciMasterEnable\n", pciIf
));
153 /* Master enable the MV PCI master */
154 if (MV_OK
!= mvPciIfMasterEnable(pciIf
,MV_TRUE
))
156 DB(mvOsPrintf("mvPciScan: ERR. mvPciMasterEnable failed \n"));
161 DB(mvOsPrintf("mvPciScan: PCI interface num scan%d\n", pciIf
));
163 /* go through all busses */
164 for (busIndex
=localBus
; busIndex
< MAX_PCI_BUSSES
; busIndex
++)
166 /* go through all possible devices on the local bus */
167 for (devIndex
=0 ; devIndex
< MAX_PCI_DEVICES
; devIndex
++)
169 /* always start with function equal to zero */
172 pPciDevice
=&pPciAgents
[detectedDevNum
];
173 DB(mvOsPrintf("mvPciScan: PCI interface num scan%d:%d\n", busIndex
, devIndex
));
175 if (MV_ERROR
== pciDetectDevice(pciIf
,
181 /* no device detected , try the next address */
185 /* We are here ! means we have detected a device*/
186 /* always we start with only one function per device */
187 pMainDevice
= pPciDevice
;
188 pPciDevice
->funtionsNum
= 1;
195 /* check if we have no more room for a new device */
196 if (detectedDevNum
== *pPciAgentsNum
)
198 DB(mvOsPrintf("mvPciScan: ERR. array passed too small \n"));
202 /* check the detected device if it is a multi functional device then
203 scan all device functions*/
204 if (pPciDevice
->isMultiFunction
== MV_TRUE
)
206 /* start with function number 1 because we have already detected
208 for (funcIndex
=1; funcIndex
<MAX_PCI_FUNCS
; funcIndex
++)
210 pPciDevice
=&pPciAgents
[detectedDevNum
];
212 if (MV_ERROR
== pciDetectDevice(pciIf
,
218 /* no device detected means no more functions !*/
221 /* We are here ! means we have detected a device */
224 pMainDevice
->funtionsNum
++;
227 /* check if we have no more room for a new device */
228 if (detectedDevNum
== *pPciAgentsNum
)
230 DB(mvOsPrintf("mvPciScan: ERR. Array too small\n"));
242 /* return the number of devices actually detected on the bus ! */
243 *pPciAgentsNum
= detectedDevNum
;
250 /*******************************************************************************
251 * pciDetectDevice - Detect a pci device parameters
254 * This function detect if a pci agent exist on certain address !
255 * and if exists then it fills all possible information on the
259 * pciIf - PCI Interface
261 * dev - Device number
262 * func - Function number
267 * pPciAgent - pointer to the pci agent filled with its information
270 * MV_ERROR if no device , MV_OK otherwise
272 *******************************************************************************/
274 static MV_STATUS
pciDetectDevice(MV_U32 pciIf
,
278 MV_PCI_DEVICE
*pPciAgent
)
282 /* no Parameters checking ! because it is static function and it is assumed
283 that all parameters were checked in the calling function */
286 /* Try read the PCI Vendor ID and Device ID */
288 /* We will scan only ourselves and the PCI slots that exist on the
289 board, because we may have a case that we have one slot that has
290 a Cardbus connector, and because CardBus answers all IDsels we want
291 to scan only this slot and ourseleves.
294 #if defined(MV_INCLUDE_PCI)
295 if ((PCI_IF_TYPE_CONVEN_PCIX
== mvPciIfTypeGet(pciIf
)) &&
296 (DB_88F5181_DDR1_PRPMC
!= mvBoardIdGet()) &&
297 (DB_88F5181_DDR1_PEXPCI
!= mvBoardIdGet()) &&
298 (DB_88F5181_DDR1_MNG
!= mvBoardIdGet()))
301 if (mvBoardIsOurPciSlot(bus
, dev
) == MV_FALSE
)
306 #endif /* defined(MV_INCLUDE_PCI) */
308 pciData
= mvPciIfConfigRead(pciIf
, bus
,dev
,func
, PCI_DEVICE_AND_VENDOR_ID
);
310 if (PCI_ERROR_CODE
== pciData
)
312 /* no device exist */
316 /* we are here ! means a device is detected */
318 /* fill basic information */
319 pPciAgent
->busNumber
=bus
;
320 pPciAgent
->deviceNum
=dev
;
321 pPciAgent
->function
=func
;
323 /* Fill the PCI Vendor ID and Device ID */
325 pPciAgent
->venID
= (pciData
& PDVIR_VEN_ID_MASK
) >> PDVIR_VEN_ID_OFFS
;
326 pPciAgent
->deviceID
= (pciData
& PDVIR_DEV_ID_MASK
) >> PDVIR_DEV_ID_OFFS
;
328 /* Read Status and command */
329 pciData
= mvPciIfConfigRead(pciIf
,
331 PCI_STATUS_AND_COMMAND
);
334 /* Fill related Status and Command information*/
336 if (pciData
& PSCR_TAR_FAST_BB
)
338 pPciAgent
->isFastB2BCapable
= MV_TRUE
;
342 pPciAgent
->isFastB2BCapable
= MV_FALSE
;
345 if (pciData
& PSCR_CAP_LIST
)
347 pPciAgent
->isCapListSupport
=MV_TRUE
;
351 pPciAgent
->isCapListSupport
=MV_FALSE
;
354 if (pciData
& PSCR_66MHZ_EN
)
356 pPciAgent
->is66MHZCapable
=MV_TRUE
;
360 pPciAgent
->is66MHZCapable
=MV_FALSE
;
363 /* Read Class Code and Revision */
364 pciData
= mvPciIfConfigRead(pciIf
,
366 PCI_CLASS_CODE_AND_REVISION_ID
);
369 pPciAgent
->baseClassCode
=
370 (pciData
& PCCRIR_BASE_CLASS_MASK
) >> PCCRIR_BASE_CLASS_OFFS
;
372 pPciAgent
->subClassCode
=
373 (pciData
& PCCRIR_SUB_CLASS_MASK
) >> PCCRIR_SUB_CLASS_OFFS
;
376 (pciData
& PCCRIR_PROGIF_MASK
) >> PCCRIR_PROGIF_OFFS
;
378 pPciAgent
->revisionID
=
379 (pciData
& PCCRIR_REVID_MASK
) >> PCCRIR_REVID_OFFS
;
381 /* Read PCI_BIST_HDR_TYPE_LAT_TMR_CACHE_LINE */
382 pciData
= mvPciIfConfigRead(pciIf
,
384 PCI_BIST_HDR_TYPE_LAT_TMR_CACHE_LINE
);
388 pPciAgent
->pciCacheLine
=
389 (pciData
& PBHTLTCLR_CACHELINE_MASK
) >> PBHTLTCLR_CACHELINE_OFFS
;
390 pPciAgent
->pciLatencyTimer
=
391 (pciData
& PBHTLTCLR_LATTIMER_MASK
) >> PBHTLTCLR_LATTIMER_OFFS
;
393 switch (pciData
& PBHTLTCLR_HEADER_MASK
)
395 case PBHTLTCLR_HEADER_STANDARD
:
397 pPciAgent
->pciHeader
=MV_PCI_STANDARD
;
399 case PBHTLTCLR_HEADER_PCI2PCI_BRIDGE
:
401 pPciAgent
->pciHeader
=MV_PCI_PCI2PCI_BRIDGE
;
406 if (pciData
& PBHTLTCLR_MULTI_FUNC
)
408 pPciAgent
->isMultiFunction
=MV_TRUE
;
412 pPciAgent
->isMultiFunction
=MV_FALSE
;
415 if (pciData
& PBHTLTCLR_BISTCAP
)
417 pPciAgent
->isBISTCapable
=MV_TRUE
;
421 pPciAgent
->isBISTCapable
=MV_FALSE
;
425 /* read this device pci bars */
427 pciDetectDeviceBars(pciIf
,
432 /* check if we are bridge*/
433 if ((pPciAgent
->baseClassCode
== PCI_BRIDGE_CLASS
)&&
434 (pPciAgent
->subClassCode
== P2P_BRIDGE_SUB_CLASS_CODE
))
437 /* Read P2P_BUSSES_NUM */
438 pciData
= mvPciIfConfigRead(pciIf
,
442 pPciAgent
->p2pPrimBusNum
=
443 (pciData
& PBM_PRIME_BUS_NUM_MASK
) >> PBM_PRIME_BUS_NUM_OFFS
;
445 pPciAgent
->p2pSecBusNum
=
446 (pciData
& PBM_SEC_BUS_NUM_MASK
) >> PBM_SEC_BUS_NUM_OFFS
;
448 pPciAgent
->p2pSubBusNum
=
449 (pciData
& PBM_SUB_BUS_NUM_MASK
) >> PBM_SUB_BUS_NUM_OFFS
;
451 pPciAgent
->p2pSecLatencyTimer
=
452 (pciData
& PBM_SEC_LAT_TMR_MASK
) >> PBM_SEC_LAT_TMR_OFFS
;
454 /* Read P2P_IO_BASE_LIMIT_SEC_STATUS */
455 pciData
= mvPciIfConfigRead(pciIf
,
457 P2P_IO_BASE_LIMIT_SEC_STATUS
);
459 pPciAgent
->p2pSecStatus
=
460 (pciData
& PIBLSS_SEC_STATUS_MASK
) >> PIBLSS_SEC_STATUS_OFFS
;
463 pPciAgent
->p2pIObase
=
464 (pciData
& PIBLSS_IO_BASE_MASK
) << PIBLSS_IO_LIMIT_OFFS
;
466 /* clear low address (should be zero)*/
467 pPciAgent
->p2pIObase
&= PIBLSS_HIGH_ADDR_MASK
;
469 pPciAgent
->p2pIOLimit
=
470 (pciData
& PIBLSS_IO_LIMIT_MASK
);
472 /* fill low address with 0xfff */
473 pPciAgent
->p2pIOLimit
|= PIBLSS_LOW_ADDR_MASK
;
476 switch ((pciData
& PIBLSS_ADD_CAP_MASK
) >> PIBLSS_ADD_CAP_OFFS
)
478 case PIBLSS_ADD_CAP_16BIT
:
480 pPciAgent
->bIO32
= MV_FALSE
;
483 case PIBLSS_ADD_CAP_32BIT
:
485 pPciAgent
->bIO32
= MV_TRUE
;
487 /* Read P2P_IO_BASE_LIMIT_UPPER_16 */
488 pciData
= mvPciIfConfigRead(pciIf
,
490 P2P_IO_BASE_LIMIT_UPPER_16
);
492 pPciAgent
->p2pIObase
|=
493 (pciData
& PRBU_IO_UPP_BASE_MASK
) << PRBU_IO_UPP_LIMIT_OFFS
;
496 pPciAgent
->p2pIOLimit
|=
497 (pciData
& PRBU_IO_UPP_LIMIT_MASK
);
504 /* Read P2P_MEM_BASE_LIMIT */
505 pciData
= mvPciIfConfigRead(pciIf
,
509 pPciAgent
->p2pMemBase
=
510 (pciData
& PMBL_MEM_BASE_MASK
) << PMBL_MEM_LIMIT_OFFS
;
512 /* clear low address */
513 pPciAgent
->p2pMemBase
&= PMBL_HIGH_ADDR_MASK
;
515 pPciAgent
->p2pMemLimit
=
516 (pciData
& PMBL_MEM_LIMIT_MASK
);
519 pPciAgent
->p2pMemLimit
|= PMBL_LOW_ADDR_MASK
;
522 /* Read P2P_PREF_MEM_BASE_LIMIT */
523 pciData
= mvPciIfConfigRead(pciIf
,
525 P2P_PREF_MEM_BASE_LIMIT
);
528 pPciAgent
->p2pPrefMemBase
=
529 (pciData
& PRMBL_PREF_MEM_BASE_MASK
) << PRMBL_PREF_MEM_LIMIT_OFFS
;
531 /* get high address only */
532 pPciAgent
->p2pPrefMemBase
&= PRMBL_HIGH_ADDR_MASK
;
536 pPciAgent
->p2pPrefMemLimit
=
537 (pciData
& PRMBL_PREF_MEM_LIMIT_MASK
);
540 pPciAgent
->p2pPrefMemLimit
|= PRMBL_LOW_ADDR_MASK
;
542 switch (pciData
& PRMBL_ADD_CAP_MASK
)
544 case PRMBL_ADD_CAP_32BIT
:
546 pPciAgent
->bPrefMem64
= MV_FALSE
;
548 /* Read P2P_PREF_BASE_UPPER_32 */
549 pPciAgent
->p2pPrefBaseUpper32Bits
= 0;
551 /* Read P2P_PREF_LIMIT_UPPER_32 */
552 pPciAgent
->p2pPrefLimitUpper32Bits
= 0;
555 case PRMBL_ADD_CAP_64BIT
:
557 pPciAgent
->bPrefMem64
= MV_TRUE
;
559 /* Read P2P_PREF_BASE_UPPER_32 */
560 pPciAgent
->p2pPrefBaseUpper32Bits
= mvPciIfConfigRead(pciIf
,
562 P2P_PREF_BASE_UPPER_32
);
564 /* Read P2P_PREF_LIMIT_UPPER_32 */
565 pPciAgent
->p2pPrefLimitUpper32Bits
= mvPciIfConfigRead(pciIf
,
567 P2P_PREF_LIMIT_UPPER_32
);
576 /* Read PCI_SUBSYS_ID_AND_SUBSYS_VENDOR_ID */
577 pciData
= mvPciIfConfigRead(pciIf
,
579 PCI_SUBSYS_ID_AND_SUBSYS_VENDOR_ID
);
582 pPciAgent
->subSysVenID
=
583 (pciData
& PSISVIR_VENID_MASK
) >> PSISVIR_VENID_OFFS
;
584 pPciAgent
->subSysID
=
585 (pciData
& PSISVIR_DEVID_MASK
) >> PSISVIR_DEVID_OFFS
;
588 /* Read PCI_EXPANSION_ROM_BASE_ADDR_REG */
589 pciData
= mvPciIfConfigRead(pciIf
,
591 PCI_EXPANSION_ROM_BASE_ADDR_REG
);
594 if (pciData
& PERBAR_EXPROMEN
)
596 pPciAgent
->isExpRom
= MV_TRUE
;
600 pPciAgent
->isExpRom
= MV_FALSE
;
603 pPciAgent
->expRomAddr
=
604 (pciData
& PERBAR_BASE_MASK
) >> PERBAR_BASE_OFFS
;
609 if (MV_TRUE
== pPciAgent
->isCapListSupport
)
611 /* Read PCI_CAPABILTY_LIST_POINTER */
612 pciData
= mvPciIfConfigRead(pciIf
,
614 PCI_CAPABILTY_LIST_POINTER
);
616 pPciAgent
->capListPointer
=
617 (pciData
& PCLPR_CAPPTR_MASK
) >> PCLPR_CAPPTR_OFFS
;
621 /* Read PCI_INTERRUPT_PIN_AND_LINE */
622 pciData
= mvPciIfConfigRead(pciIf
,
624 PCI_INTERRUPT_PIN_AND_LINE
);
628 (pciData
& PIPLR_INTLINE_MASK
) >> PIPLR_INTLINE_OFFS
;
631 (MV_PCI_INT_PIN
)(pciData
& PIPLR_INTPIN_MASK
) >> PIPLR_INTPIN_OFFS
;
634 (pciData
& PIPLR_MINGRANT_MASK
) >> PIPLR_MINGRANT_OFFS
;
635 pPciAgent
->maxLatency
=
636 (pciData
& PIPLR_MAXLATEN_MASK
) >> PIPLR_MAXLATEN_OFFS
;
638 mvPciClassNameGet(pPciAgent
->baseClassCode
,
639 (MV_8
*)pPciAgent
->type
);
646 /*******************************************************************************
647 * pciDetectDeviceBars - Detect a pci device bars
650 * This function detects all pci agent bars
653 * pciIf - PCI Interface
655 * dev - Device number
656 * func - Function number
661 * pPciAgent - pointer to the pci agent filled with its information
664 * detected bars number
666 *******************************************************************************/
667 static MV_U32
pciDetectDeviceBars(MV_U32 pciIf
,
671 MV_PCI_DEVICE
*pPciAgent
)
673 MV_U32 pciData
,barIndex
,detectedBar
=0;
674 MV_U32 tmpBaseHigh
=0,tmpBaseLow
=0;
677 pPciAgent
->barsNum
=0;
679 /* check if we are bridge*/
680 if ((pPciAgent
->baseClassCode
== PCI_BRIDGE_CLASS
)&&
681 (pPciAgent
->subClassCode
== P2P_BRIDGE_SUB_CLASS_CODE
))
690 /* read this device pci bars */
691 for (barIndex
= 0 ; barIndex
< pciMaxBars
; barIndex
++ )
693 /* Read PCI_MEMORY_BAR_BASE_ADDR */
694 tmpBaseLow
= pciData
= mvPciIfConfigRead(pciIf
,
696 PCI_MEMORY_BAR_BASE_ADDR(barIndex
));
698 pPciAgent
->pciBar
[detectedBar
].barOffset
=
699 PCI_MEMORY_BAR_BASE_ADDR(barIndex
);
701 /* check if the bar is 32bit or 64bit bar */
702 switch (pciData
& PBBLR_TYPE_MASK
)
704 case PBBLR_TYPE_32BIT_ADDR
:
705 pPciAgent
->pciBar
[detectedBar
].barType
= PCI_32BIT_BAR
;
707 case PBBLR_TYPE_64BIT_ADDR
:
708 pPciAgent
->pciBar
[detectedBar
].barType
= PCI_64BIT_BAR
;
713 /* check if it is memory or IO bar */
714 if (pciData
& PBBLR_IOSPACE
)
716 pPciAgent
->pciBar
[detectedBar
].barMapping
=PCI_IO_BAR
;
720 pPciAgent
->pciBar
[detectedBar
].barMapping
=PCI_MEMORY_BAR
;
723 /* if it is memory bar then check if it is prefetchable */
724 if (PCI_MEMORY_BAR
== pPciAgent
->pciBar
[detectedBar
].barMapping
)
726 if (pciData
& PBBLR_PREFETCH_EN
)
728 pPciAgent
->pciBar
[detectedBar
].isPrefetchable
= MV_TRUE
;
732 pPciAgent
->pciBar
[detectedBar
].isPrefetchable
= MV_FALSE
;
735 pPciAgent
->pciBar
[detectedBar
].barBaseLow
=
736 pciData
& PBBLR_MEM_BASE_MASK
;
742 pPciAgent
->pciBar
[detectedBar
].barBaseLow
=
743 pciData
& PBBLR_IO_BASE_MASK
;
747 pPciAgent
->pciBar
[detectedBar
].barBaseHigh
=0;
749 if (PCI_64BIT_BAR
== pPciAgent
->pciBar
[detectedBar
].barType
)
753 tmpBaseHigh
= pPciAgent
->pciBar
[detectedBar
].barBaseHigh
=
754 mvPciIfConfigRead(pciIf
,
756 PCI_MEMORY_BAR_BASE_ADDR(barIndex
));
761 /* calculating full base address (64bit) */
762 pPciAgent
->pciBar
[detectedBar
].barBaseAddr
=
763 (MV_U64
)pPciAgent
->pciBar
[detectedBar
].barBaseHigh
;
765 pPciAgent
->pciBar
[detectedBar
].barBaseAddr
<<= 32;
767 pPciAgent
->pciBar
[detectedBar
].barBaseAddr
|=
768 (MV_U64
)pPciAgent
->pciBar
[detectedBar
].barBaseLow
;
772 /* get the sizes of the the bar */
774 pPciAgent
->pciBar
[detectedBar
].barSizeHigh
=0;
776 if ((PCI_64BIT_BAR
== pPciAgent
->pciBar
[detectedBar
].barType
) &&
777 (PCI_MEMORY_BAR
== pPciAgent
->pciBar
[detectedBar
].barMapping
))
780 /* write oxffffffff to the bar to get the size */
781 /* start with sizelow ( original value was saved in tmpBaseLow ) */
782 mvPciIfConfigWrite(pciIf
,
784 PCI_MEMORY_BAR_BASE_ADDR(barIndex
-1),
788 pPciAgent
->pciBar
[detectedBar
].barSizeLow
=
789 mvPciIfConfigRead(pciIf
,
791 PCI_MEMORY_BAR_BASE_ADDR(barIndex
-1));
795 /* restore original value */
796 mvPciIfConfigWrite(pciIf
,
798 PCI_MEMORY_BAR_BASE_ADDR(barIndex
-1),
802 /* now do the same for BaseHigh */
804 /* write oxffffffff to the bar to get the size */
805 mvPciIfConfigWrite(pciIf
,
807 PCI_MEMORY_BAR_BASE_ADDR(barIndex
),
811 pPciAgent
->pciBar
[detectedBar
].barSizeHigh
=
812 mvPciIfConfigRead(pciIf
,
814 PCI_MEMORY_BAR_BASE_ADDR(barIndex
));
816 /* restore original value */
817 mvPciIfConfigWrite(pciIf
,
819 PCI_MEMORY_BAR_BASE_ADDR(barIndex
),
822 if ((0 == pPciAgent
->pciBar
[detectedBar
].barSizeLow
)&&
823 (0 == pPciAgent
->pciBar
[detectedBar
].barSizeHigh
))
825 /* this bar is not applicable for this device,
826 ignore all previous settings and check the next bar*/
828 /* we though this was a 64bit bar , and it seems this
829 was wrong ! so decrement barIndex */
834 /* calculate the full 64 bit size */
836 if (0 != pPciAgent
->pciBar
[detectedBar
].barSizeHigh
)
838 pPciAgent
->pciBar
[detectedBar
].barSizeLow
&= PBBLR_MEM_BASE_MASK
;
840 pPciAgent
->pciBar
[detectedBar
].barSizeLow
=
841 ~pPciAgent
->pciBar
[detectedBar
].barSizeLow
+ 1;
843 pPciAgent
->pciBar
[detectedBar
].barSizeHigh
= 0;
849 pPciAgent
->pciBar
[detectedBar
].barSizeLow
&= PBBLR_MEM_BASE_MASK
;
851 pPciAgent
->pciBar
[detectedBar
].barSizeLow
=
852 ~pPciAgent
->pciBar
[detectedBar
].barSizeLow
+ 1;
854 pPciAgent
->pciBar
[detectedBar
].barSizeHigh
= 0;
863 /* write oxffffffff to the bar to get the size */
864 mvPciIfConfigWrite(pciIf
,
866 PCI_MEMORY_BAR_BASE_ADDR(barIndex
),
870 pPciAgent
->pciBar
[detectedBar
].barSizeLow
=
871 mvPciIfConfigRead(pciIf
,
873 PCI_MEMORY_BAR_BASE_ADDR(barIndex
));
875 if (0 == pPciAgent
->pciBar
[detectedBar
].barSizeLow
)
877 /* this bar is not applicable for this device,
878 ignore all previous settings and check the next bar*/
883 /* restore original value */
884 mvPciIfConfigWrite(pciIf
,
886 PCI_MEMORY_BAR_BASE_ADDR(barIndex
),
889 /* calculate size low */
891 if (PCI_MEMORY_BAR
== pPciAgent
->pciBar
[detectedBar
].barMapping
)
893 pPciAgent
->pciBar
[detectedBar
].barSizeLow
&= PBBLR_MEM_BASE_MASK
;
897 pPciAgent
->pciBar
[detectedBar
].barSizeLow
&= PBBLR_IO_BASE_MASK
;
900 pPciAgent
->pciBar
[detectedBar
].barSizeLow
=
901 ~pPciAgent
->pciBar
[detectedBar
].barSizeLow
+ 1;
903 pPciAgent
->pciBar
[detectedBar
].barSizeHigh
= 0;
904 pPciAgent
->pciBar
[detectedBar
].barSize
=
905 (MV_U64
)pPciAgent
->pciBar
[detectedBar
].barSizeLow
;
910 /* we are here ! this means we have already detected a bar for
911 this device , now move on */
914 pPciAgent
->barsNum
++;
921 /*******************************************************************************
922 * mvPciClassNameGet - get PCI class name
925 * This function returns the PCI class name
928 * baseClassCode - Base Class Code.
931 * pType - the class name
934 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
936 *******************************************************************************/
937 MV_STATUS
mvPciClassNameGet(MV_U32 baseClassCode
, MV_8
*pType
)
940 switch(baseClassCode
)
943 strcpy(pType
,"Old generation device");
946 strcpy(pType
,"Mass storage controller");
949 strcpy(pType
,"Network controller");
952 strcpy(pType
,"Display controller");
955 strcpy(pType
,"Multimedia device");
958 strcpy(pType
,"Memory controller");
961 strcpy(pType
,"Bridge Device");
964 strcpy(pType
,"Simple Communication controllers");
967 strcpy(pType
,"Base system peripherals");
970 strcpy(pType
,"Input Devices");
973 strcpy(pType
,"Docking stations");
976 strcpy(pType
,"Processors");
979 strcpy(pType
,"Serial bus controllers");
982 strcpy(pType
,"Wireless controllers");
985 strcpy(pType
,"Intelligent I/O controllers");
988 strcpy(pType
,"Satellite communication controllers");
991 strcpy(pType
,"Encryption/Decryption controllers");
994 strcpy(pType
,"Data acquisition and signal processing controllers");
997 strcpy(pType
,"Unknown device");