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 *******************************************************************************/
64 #include "pci/mvPci.h"
66 #include "ctrlEnv/mvCtrlEnvLib.h"
77 MV_VOID
mvPciHalInit(MV_U32 pciIf
, MV_PCI_MOD pciIfmod
)
79 if (MV_PCI_MOD_HOST
== pciIfmod
)
82 mvPciLocalBusNumSet(pciIf
, PCI_HOST_BUS_NUM(pciIf
));
83 mvPciLocalDevNumSet(pciIf
, PCI_HOST_DEV_NUM(pciIf
));
85 /* Local device master Enable */
86 mvPciMasterEnable(pciIf
, MV_TRUE
);
88 /* Local device slave Enable */
89 mvPciSlaveEnable(pciIf
, mvPciLocalBusNumGet(pciIf
),
90 mvPciLocalDevNumGet(pciIf
), MV_TRUE
);
92 /* enable CPU-2-PCI ordering */
93 MV_REG_BIT_SET(PCI_CMD_REG(0), PCR_CPU_TO_PCI_ORDER_EN
);
96 /*******************************************************************************
97 * mvPciCommandSet - Set PCI comman register value.
100 * This function sets a given PCI interface with its command register
104 * pciIf - PCI interface number.
105 * command - 32bit value to be written to comamnd register.
111 * MV_BAD_PARAM if pciIf is not in range otherwise MV_OK
113 *******************************************************************************/
114 MV_STATUS
mvPciCommandSet(MV_U32 pciIf
, MV_U32 command
)
116 MV_U32 locBusNum
, locDevNum
, regVal
;
118 locBusNum
= mvPciLocalBusNumGet(pciIf
);
119 locDevNum
= mvPciLocalDevNumGet(pciIf
);
121 /* Parameter checking */
122 if (pciIf
>= mvCtrlPciMaxIfGet())
124 mvOsPrintf("mvPciCommandSet: ERR. Invalid PCI IF num %d\n", pciIf
);
128 /* Set command register */
129 MV_REG_WRITE(PCI_CMD_REG(pciIf
), command
);
131 /* Upodate device max outstanding split tarnsaction */
132 if ((command
& PCR_CPU_TO_PCI_ORDER_EN
) &&
133 (command
& PCR_PCI_TO_CPU_ORDER_EN
))
135 /* Read PCI-X command register */
136 regVal
= mvPciConfigRead (pciIf
, locBusNum
, locDevNum
, 0, PCIX_COMMAND
);
138 /* clear bits 22:20 */
139 regVal
&= 0xff8fffff;
141 /* set reset value */
142 regVal
|= (0x3 << 20);
144 /* Write back the value */
145 mvPciConfigWrite (pciIf
, locBusNum
, locDevNum
, 0, PCIX_COMMAND
, regVal
);
154 /*******************************************************************************
155 * mvPciModeGet - Get PCI interface mode.
158 * This function returns the given PCI interface mode.
161 * pciIf - PCI interface number.
164 * pPciMode - Pointer to PCI mode structure.
167 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
169 *******************************************************************************/
170 MV_STATUS
mvPciModeGet(MV_U32 pciIf
, MV_PCI_MODE
*pPciMode
)
174 /* Parameter checking */
175 if (pciIf
>= mvCtrlPciMaxIfGet())
177 mvOsPrintf("mvPciModeGet: ERR. Invalid PCI interface %d\n", pciIf
);
180 if (NULL
== pPciMode
)
182 mvOsPrintf("mvPciModeGet: ERR. pPciMode = NULL \n");
186 /* Read pci mode register */
187 pciMode
= MV_REG_READ(PCI_MODE_REG(pciIf
));
189 switch (pciMode
& PMR_PCI_MODE_MASK
)
191 case PMR_PCI_MODE_CONV
:
192 pPciMode
->pciType
= MV_PCI_CONV
;
194 if (MV_REG_READ(PCI_DLL_CTRL_REG(pciIf
)) & PDC_DLL_EN
)
196 pPciMode
->pciSpeed
= 66000000; /* 66MHZ */
200 pPciMode
->pciSpeed
= 33000000; /* 33MHZ */
205 case PMR_PCI_MODE_PCIX_66MHZ
:
206 pPciMode
->pciType
= MV_PCIX
;
207 pPciMode
->pciSpeed
= 66000000; /* 66MHZ */
210 case PMR_PCI_MODE_PCIX_100MHZ
:
211 pPciMode
->pciType
= MV_PCIX
;
212 pPciMode
->pciSpeed
= 100000000; /* 100MHZ */
215 case PMR_PCI_MODE_PCIX_133MHZ
:
216 pPciMode
->pciType
= MV_PCIX
;
217 pPciMode
->pciSpeed
= 133000000; /* 133MHZ */
222 mvOsPrintf("mvPciModeGet: ERR. Non existing mode !!\n");
227 switch (pciMode
& PMR_PCI_64_MASK
)
229 case PMR_PCI_64_64BIT
:
230 pPciMode
->pciWidth
= MV_PCI_64
;
233 case PMR_PCI_64_32BIT
:
234 pPciMode
->pciWidth
= MV_PCI_32
;
239 mvOsPrintf("mvPciModeGet: ERR. Non existing mode !!\n");
247 /*******************************************************************************
248 * mvPciRetrySet - Set PCI retry counters
251 * This function specifies the number of times the PCI controller
252 * retries a transaction before it quits.
253 * Applies to the PCI Master when acting as a requester.
254 * Applies to the PCI slave when acting as a completer (PCI-X mode).
255 * A 0x00 value means a "retry forever".
258 * pciIf - PCI interface number.
259 * counter - Number of times PCI controller retry. Use counter value
260 * up to PRR_RETRY_CNTR_MAX.
266 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
268 *******************************************************************************/
269 MV_STATUS
mvPciRetrySet(MV_U32 pciIf
, MV_U32 counter
)
273 /* Parameter checking */
274 if (pciIf
>= mvCtrlPciMaxIfGet())
276 mvOsPrintf("mvPciRetrySet: ERR. Invalid PCI interface %d\n", pciIf
);
280 if (counter
>= PRR_RETRY_CNTR_MAX
)
282 mvOsPrintf("mvPciRetrySet: ERR. Invalid counter: %d\n", counter
);
287 /* Reading PCI retry register */
288 pciRetry
= MV_REG_READ(PCI_RETRY_REG(pciIf
));
290 pciRetry
&= ~PRR_RETRY_CNTR_MASK
;
292 pciRetry
|= (counter
<< PRR_RETRY_CNTR_OFFS
);
294 /* write new value */
295 MV_REG_WRITE(PCI_RETRY_REG(pciIf
), pciRetry
);
301 /*******************************************************************************
302 * mvPciDiscardTimerSet - Set PCI discard timer
305 * This function set PCI discard timer.
306 * In conventional PCI mode:
307 * Specifies the number of PCLK cycles the PCI slave keeps a non-accessed
308 * read buffers (non-completed delayed read) before invalidate the buffer.
309 * Set to '0' to disable the timer. The PCI slave waits for delayed
310 * read completion forever.
312 * Specifies the number of PCLK cycles the PCI master waits for split
313 * completion transaction, before it invalidates the pre-allocated read
315 * Set to '0' to disable the timer. The PCI master waits for split
316 * completion forever.
317 * NOTE: Must be set to a number greater than MV_PCI_MAX_DISCARD_CLK,
318 * unless using the "wait for ever" setting 0x0.
319 * NOTE: Must not be updated while there are pending read requests.
322 * pciIf - PCI interface number.
323 * pClkCycles - Number of PCI clock cycles.
329 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
331 *******************************************************************************/
332 MV_STATUS
mvPciDiscardTimerSet(MV_U32 pciIf
, MV_U32 pClkCycles
)
334 MV_U32 pciDiscardTimer
;
336 /* Parameter checking */
337 if (pciIf
>= mvCtrlPciMaxIfGet())
339 mvOsPrintf("mvPciDiscardTimerSet: ERR. Invalid PCI interface %d\n",
344 if (pClkCycles
>= PDTR_TIMER_MIN
)
346 mvOsPrintf("mvPciDiscardTimerSet: ERR. Invalid Clk value: %d\n",
352 /* Read PCI Discard Timer */
353 pciDiscardTimer
= MV_REG_READ(PCI_DISCARD_TIMER_REG(pciIf
));
355 pciDiscardTimer
&= ~PDTR_TIMER_MASK
;
357 pciDiscardTimer
|= (pClkCycles
<< PDTR_TIMER_OFFS
);
359 /* Write new value */
360 MV_REG_WRITE(PCI_DISCARD_TIMER_REG(pciIf
), pciDiscardTimer
);
366 /* PCI Arbiter routines */
368 /*******************************************************************************
369 * mvPciArbEnable - PCI arbiter enable/disable
372 * This fuction enable/disables a given PCI interface arbiter.
373 * NOTE: Arbiter setting can not be changed while in work. It should only
376 * pciIf - PCI interface number.
377 * enable - Enable/disable parameter. If enable = MV_TRUE then enable.
385 *******************************************************************************/
386 MV_STATUS
mvPciArbEnable(MV_U32 pciIf
, MV_BOOL enable
)
390 /* Parameter checking */
391 if (pciIf
>= mvCtrlPciMaxIfGet())
393 mvOsPrintf("mvPciArbEnable: ERR. Invalid PCI interface %d\n", pciIf
);
397 /* Set PCI Arbiter Control register according to default configuration */
398 regVal
= MV_REG_READ(PCI_ARBITER_CTRL_REG(pciIf
));
400 /* Make sure arbiter disabled before changing its values */
401 MV_REG_BIT_RESET(PCI_ARBITER_CTRL_REG(pciIf
), PACR_ARB_ENABLE
);
403 regVal
&= ~PCI_ARBITER_CTRL_DEFAULT_MASK
;
405 regVal
|= PCI_ARBITER_CTRL_DEFAULT
; /* Set default configuration */
407 if (MV_TRUE
== enable
)
409 regVal
|= PACR_ARB_ENABLE
;
413 regVal
&= ~PACR_ARB_ENABLE
;
416 /* Write to register */
417 MV_REG_WRITE(PCI_ARBITER_CTRL_REG(pciIf
), regVal
);
423 /*******************************************************************************
424 * mvPciArbParkDis - Disable arbiter parking on agent
427 * This function disables the PCI arbiter from parking on the given agent
431 * pciIf - PCI interface number.
432 * pciAgentMask - When a bit in the mask is set to '1', parking on
433 * the associated PCI master is disabled. Mask bit
434 * refers to bit 0 - 6. For example disable parking on PCI
435 * agent 3 set pciAgentMask 0x4 (bit 3 is set).
443 *******************************************************************************/
444 MV_STATUS
mvPciArbParkDis(MV_U32 pciIf
, MV_U32 pciAgentMask
)
446 MV_U32 pciArbiterCtrl
;
448 /* Parameter checking */
449 if (pciIf
>= mvCtrlPciMaxIfGet())
451 mvOsPrintf("mvPciArbParkDis: ERR. Invalid PCI interface %d\n", pciIf
);
455 /* Reading Arbiter Control register */
456 pciArbiterCtrl
= MV_REG_READ(PCI_ARBITER_CTRL_REG(pciIf
));
458 /* Arbiter must be disabled before changing parking */
459 MV_REG_BIT_RESET(PCI_ARBITER_CTRL_REG(pciIf
), PACR_ARB_ENABLE
);
462 pciArbiterCtrl
&= ~PACR_PARK_DIS_MASK
;
463 pciArbiterCtrl
|= (pciAgentMask
<< PACR_PARK_DIS_OFFS
);
465 /* writing new value ( if th earbiter was enabled before the change */
466 /* here it will be reenabled */
467 MV_REG_WRITE(PCI_ARBITER_CTRL_REG(pciIf
), pciArbiterCtrl
);
473 /*******************************************************************************
474 * mvPciArbBrokDetectSet - Set PCI arbiter broken detection
477 * This function sets the maximum number of cycles that the arbiter
478 * waits for a PCI master to respond to its grant assertion. If a
479 * PCI agent fails to respond within this time, the PCI arbiter aborts
480 * the transaction and performs a new arbitration cycle.
481 * NOTE: Value must be greater than '1' for conventional PCI and
482 * greater than '5' for PCI-X.
485 * pciIf - PCI interface number.
486 * pClkCycles - Number of PCI clock cycles. If equal to '0' the broken
487 * master detection is disabled.
493 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
495 *******************************************************************************/
496 MV_STATUS
mvPciArbBrokDetectSet(MV_U32 pciIf
, MV_U32 pClkCycles
)
498 MV_U32 pciArbiterCtrl
;
501 /* Parameter checking */
502 if (pciIf
>= mvCtrlPciMaxIfGet())
504 mvOsPrintf("mvPciArbBrokDetectSet: ERR. Invalid PCI interface %d\n",
509 /* Checking PCI mode and if pClkCycles is legal value */
510 pciMode
= MV_REG_READ(PCI_MODE_REG(pciIf
));
511 pciMode
&= PMR_PCI_MODE_MASK
;
513 if (PMR_PCI_MODE_CONV
== pciMode
)
515 if (pClkCycles
< PACR_BROKEN_VAL_CONV_MIN
)
520 if (pClkCycles
< PACR_BROKEN_VAL_PCIX_MIN
)
524 pClkCycles
<<= PACR_BROKEN_VAL_OFFS
;
526 /* Reading Arbiter Control register */
527 pciArbiterCtrl
= MV_REG_READ(PCI_ARBITER_CTRL_REG(pciIf
));
528 pciArbiterCtrl
&= ~PACR_BROKEN_VAL_MASK
;
529 pciArbiterCtrl
|= pClkCycles
;
531 /* Arbiter must be disabled before changing broken detection */
532 MV_REG_BIT_RESET(PCI_ARBITER_CTRL_REG(pciIf
), PACR_ARB_ENABLE
);
534 /* writing new value ( if th earbiter was enabled before the change */
535 /* here it will be reenabled */
537 MV_REG_WRITE(PCI_ARBITER_CTRL_REG(pciIf
), pciArbiterCtrl
);
542 /* PCI configuration space read write */
544 /*******************************************************************************
545 * mvPciConfigRead - Read from configuration space
548 * This function performs a 32 bit read from PCI configuration space.
549 * It supports both type 0 and type 1 of Configuration Transactions
550 * (local and over bridge). In order to read from local bus segment, use
551 * bus number retrieved from mvPciLocalBusNumGet(). Other bus numbers
552 * will result configuration transaction of type 1 (over bridge).
555 * pciIf - PCI interface number.
556 * bus - PCI segment bus number.
557 * dev - PCI device number.
558 * func - Function number.
559 * regOffs - Register offset.
565 * 32bit register data, 0xffffffff on error
567 *******************************************************************************/
568 MV_U32
mvPciConfigRead (MV_U32 pciIf
, MV_U32 bus
, MV_U32 dev
, MV_U32 func
,
573 /* Parameter checking */
574 if (PCI_DEFAULT_IF
!= pciIf
)
576 if (pciIf
>= mvCtrlPciMaxIfGet())
578 mvOsPrintf("mvPciConfigRead: ERR. Invalid PCI interface %d\n",pciIf
);
583 if (dev
>= MAX_PCI_DEVICES
)
585 DB(mvOsPrintf("mvPciConfigRead: ERR. device number illigal %d\n", dev
));
589 if (func
>= MAX_PCI_FUNCS
)
591 DB(mvOsPrintf("mvPciConfigRead: ERR. function number illigal %d\n", func
));
595 if (bus
>= MAX_PCI_BUSSES
)
597 DB(mvOsPrintf("mvPciConfigRead: ERR. bus number illigal %d\n", bus
));
602 /* Creating PCI address to be passed */
603 pciData
|= (bus
<< PCAR_BUS_NUM_OFFS
);
604 pciData
|= (dev
<< PCAR_DEVICE_NUM_OFFS
);
605 pciData
|= (func
<< PCAR_FUNC_NUM_OFFS
);
606 pciData
|= (regOff
& PCAR_REG_NUM_MASK
);
608 pciData
|= PCAR_CONFIG_EN
;
610 /* Write the address to the PCI configuration address register */
611 MV_REG_WRITE(PCI_CONFIG_ADDR_REG(pciIf
), pciData
);
613 /* In order to let the PCI controller absorbed the address of the read */
614 /* transaction we perform a validity check that the address was written */
615 if(pciData
!= MV_REG_READ(PCI_CONFIG_ADDR_REG(pciIf
)))
619 /* Read the Data returned in the PCI Data register */
620 pciData
= MV_REG_READ(PCI_CONFIG_DATA_REG(pciIf
));
625 /*******************************************************************************
626 * mvPciConfigWrite - Write to configuration space
629 * This function performs a 32 bit write to PCI configuration space.
630 * It supports both type 0 and type 1 of Configuration Transactions
631 * (local and over bridge). In order to write to local bus segment, use
632 * bus number retrieved from mvPciLocalBusNumGet(). Other bus numbers
633 * will result configuration transaction of type 1 (over bridge).
636 * pciIf - PCI interface number.
637 * bus - PCI segment bus number.
638 * dev - PCI device number.
639 * func - Function number.
640 * regOffs - Register offset.
647 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
649 *******************************************************************************/
650 MV_STATUS
mvPciConfigWrite(MV_U32 pciIf
, MV_U32 bus
, MV_U32 dev
,
651 MV_U32 func
, MV_U32 regOff
, MV_U32 data
)
655 /* Parameter checking */
656 if (PCI_DEFAULT_IF
!= pciIf
)
658 if (pciIf
>= mvCtrlPciMaxIfGet())
660 mvOsPrintf("mvPciConfigWrite: ERR. Invalid PCI interface %d\n",
666 if (dev
>= MAX_PCI_DEVICES
)
668 mvOsPrintf("mvPciConfigWrite: ERR. device number illigal %d\n",dev
);
672 if (func
>= MAX_PCI_FUNCS
)
674 mvOsPrintf("mvPciConfigWrite: ERR. function number illigal %d\n", func
);
678 if (bus
>= MAX_PCI_BUSSES
)
680 mvOsPrintf("mvPciConfigWrite: ERR. bus number illigal %d\n", bus
);
684 /* Creating PCI address to be passed */
685 pciData
|= (bus
<< PCAR_BUS_NUM_OFFS
);
686 pciData
|= (dev
<< PCAR_DEVICE_NUM_OFFS
);
687 pciData
|= (func
<< PCAR_FUNC_NUM_OFFS
);
688 pciData
|= (regOff
& PCAR_REG_NUM_MASK
);
690 pciData
|= PCAR_CONFIG_EN
;
692 /* Write the address to the PCI configuration address register */
693 MV_REG_WRITE(PCI_CONFIG_ADDR_REG(pciIf
), pciData
);
695 /* In order to let the PCI controller absorbed the address of the read */
696 /* transaction we perform a validity check that the address was written */
697 if(pciData
!= MV_REG_READ(PCI_CONFIG_ADDR_REG(pciIf
)))
702 /* Write the Data passed to the PCI Data register */
703 MV_REG_WRITE(PCI_CONFIG_DATA_REG(pciIf
), data
);
708 /*******************************************************************************
709 * mvPciMasterEnable - Enable/disale PCI interface master transactions.
712 * This function performs read modified write to PCI command status
713 * (offset 0x4) to set/reset bit 2. After this bit is set, the PCI
714 * master is allowed to gain ownership on the bus, otherwise it is
715 * incapable to do so.
718 * pciIf - PCI interface number.
719 * enable - Enable/disable parameter.
725 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
727 *******************************************************************************/
728 MV_STATUS
mvPciMasterEnable(MV_U32 pciIf
, MV_BOOL enable
)
730 MV_U32 pciCommandStatus
;
735 /* Parameter checking */
736 if (pciIf
>= mvCtrlPciMaxIfGet())
738 mvOsPrintf("mvPciMasterEnable: ERR. Invalid PCI interface %d\n", pciIf
);
742 localBus
= mvPciLocalBusNumGet(pciIf
);
743 localDev
= mvPciLocalDevNumGet(pciIf
);
745 RegOffs
= PCI_STATUS_AND_COMMAND
;
747 pciCommandStatus
= mvPciConfigRead(pciIf
, localBus
, localDev
, 0, RegOffs
);
749 if (MV_TRUE
== enable
)
751 pciCommandStatus
|= PSCR_MASTER_EN
;
755 pciCommandStatus
&= ~PSCR_MASTER_EN
;
758 mvPciConfigWrite(pciIf
, localBus
, localDev
, 0, RegOffs
, pciCommandStatus
);
764 /*******************************************************************************
765 * mvPciSlaveEnable - Enable/disale PCI interface slave transactions.
768 * This function performs read modified write to PCI command status
769 * (offset 0x4) to set/reset bit 0 and 1. After those bits are set,
770 * the PCI slave is allowed to respond to PCI IO space access (bit 0)
771 * and PCI memory space access (bit 1).
774 * pciIf - PCI interface number.
775 * dev - PCI device number.
776 * enable - Enable/disable parameter.
782 * MV_BAD_PARAM for bad parameters ,MV_ERROR on error ! otherwise MV_OK
784 *******************************************************************************/
785 MV_STATUS
mvPciSlaveEnable(MV_U32 pciIf
, MV_U32 bus
, MV_U32 dev
, MV_BOOL enable
)
787 MV_U32 pciCommandStatus
;
790 /* Parameter checking */
791 if (pciIf
>= mvCtrlPciMaxIfGet())
793 mvOsPrintf("mvPciSlaveEnable: ERR. Invalid PCI interface %d\n", pciIf
);
796 if (dev
>= MAX_PCI_DEVICES
)
798 mvOsPrintf("mvPciLocalDevNumSet: ERR. device number illigal %d\n", dev
);
803 RegOffs
= PCI_STATUS_AND_COMMAND
;
805 pciCommandStatus
=mvPciConfigRead(pciIf
, bus
, dev
, 0, RegOffs
);
807 if (MV_TRUE
== enable
)
809 pciCommandStatus
|= (PSCR_IO_EN
| PSCR_MEM_EN
);
813 pciCommandStatus
&= ~(PSCR_IO_EN
| PSCR_MEM_EN
);
816 mvPciConfigWrite(pciIf
, bus
, dev
, 0, RegOffs
, pciCommandStatus
);
821 /*******************************************************************************
822 * mvPciLocalBusNumSet - Set PCI interface local bus number.
825 * This function sets given PCI interface its local bus number.
826 * Note: In case the PCI interface is PCI-X, the information is read-only.
829 * pciIf - PCI interface number.
830 * busNum - Bus number.
836 * MV_NOT_ALLOWED in case PCI interface is PCI-X.
837 * MV_BAD_PARAM on bad parameters ,
840 *******************************************************************************/
841 MV_STATUS
mvPciLocalBusNumSet(MV_U32 pciIf
, MV_U32 busNum
)
849 /* Parameter checking */
850 if (pciIf
>= mvCtrlPciMaxIfGet())
852 mvOsPrintf("mvPciLocalBusNumSet: ERR. Invalid PCI interface %d\n",pciIf
);
855 if (busNum
>= MAX_PCI_BUSSES
)
857 mvOsPrintf("mvPciLocalBusNumSet: ERR. bus number illigal %d\n", busNum
);
862 localBus
= mvPciLocalBusNumGet(pciIf
);
863 localDev
= mvPciLocalDevNumGet(pciIf
);
866 /* PCI interface mode */
867 mvPciModeGet(pciIf
, &pciMode
);
869 /* if PCI type is PCI-X then it is not allowed to change the dev number */
870 if (MV_PCIX
== pciMode
.pciType
)
872 pciP2PConfig
= mvPciConfigRead(pciIf
, localBus
, localDev
, 0, PCIX_STATUS
);
874 pciP2PConfig
&= ~PXS_BN_MASK
;
876 pciP2PConfig
|= (busNum
<< PXS_BN_OFFS
) & PXS_BN_MASK
;
878 mvPciConfigWrite(pciIf
, localBus
, localDev
, 0, PCIX_STATUS
,pciP2PConfig
);
883 pciP2PConfig
= MV_REG_READ(PCI_P2P_CONFIG_REG(pciIf
));
885 pciP2PConfig
&= ~PPCR_BUS_NUM_MASK
;
887 pciP2PConfig
|= (busNum
<< PPCR_BUS_NUM_OFFS
) & PPCR_BUS_NUM_MASK
;
889 MV_REG_WRITE(PCI_P2P_CONFIG_REG(pciIf
), pciP2PConfig
);
898 /*******************************************************************************
899 * mvPciLocalBusNumGet - Get PCI interface local bus number.
902 * This function gets the local bus number of a given PCI interface.
905 * pciIf - PCI interface number.
911 * Local bus number.0xffffffff on Error
913 *******************************************************************************/
914 MV_U32
mvPciLocalBusNumGet(MV_U32 pciIf
)
918 /* Parameter checking */
919 if (PCI_DEFAULT_IF
!= pciIf
)
921 if (pciIf
>= mvCtrlPciMaxIfGet())
923 mvOsPrintf("mvPciLocalBusNumGet: ERR. Invalid PCI interface %d\n",
929 pciP2PConfig
= MV_REG_READ(PCI_P2P_CONFIG_REG(pciIf
));
930 pciP2PConfig
&= PPCR_BUS_NUM_MASK
;
931 return (pciP2PConfig
>> PPCR_BUS_NUM_OFFS
);
935 /*******************************************************************************
936 * mvPciLocalDevNumSet - Set PCI interface local device number.
939 * This function sets given PCI interface its local device number.
940 * Note: In case the PCI interface is PCI-X, the information is read-only.
943 * pciIf - PCI interface number.
944 * devNum - Device number.
950 * MV_NOT_ALLOWED in case PCI interface is PCI-X. MV_BAD_PARAM on bad parameters ,
953 *******************************************************************************/
954 MV_STATUS
mvPciLocalDevNumSet(MV_U32 pciIf
, MV_U32 devNum
)
961 /* Parameter checking */
962 if (pciIf
>= mvCtrlPciMaxIfGet())
964 mvOsPrintf("mvPciLocalDevNumSet: ERR. Invalid PCI interface %d\n",pciIf
);
967 if (devNum
>= MAX_PCI_DEVICES
)
969 mvOsPrintf("mvPciLocalDevNumSet: ERR. device number illigal %d\n",
975 localBus
= mvPciLocalBusNumGet(pciIf
);
976 localDev
= mvPciLocalDevNumGet(pciIf
);
978 /* PCI interface mode */
979 mvPciModeGet(pciIf
, &pciMode
);
981 /* if PCI type is PCIX then it is not allowed to change the dev number */
982 if (MV_PCIX
== pciMode
.pciType
)
984 pciP2PConfig
= mvPciConfigRead(pciIf
, localBus
, localDev
, 0, PCIX_STATUS
);
986 pciP2PConfig
&= ~PXS_DN_MASK
;
988 pciP2PConfig
|= (devNum
<< PXS_DN_OFFS
) & PXS_DN_MASK
;
990 mvPciConfigWrite(pciIf
,localBus
, localDev
, 0, PCIX_STATUS
,pciP2PConfig
);
994 pciP2PConfig
= MV_REG_READ(PCI_P2P_CONFIG_REG(pciIf
));
996 pciP2PConfig
&= ~PPCR_DEV_NUM_MASK
;
998 pciP2PConfig
|= (devNum
<< PPCR_DEV_NUM_OFFS
) & PPCR_DEV_NUM_MASK
;
1000 MV_REG_WRITE(PCI_P2P_CONFIG_REG(pciIf
), pciP2PConfig
);
1006 /*******************************************************************************
1007 * mvPciLocalDevNumGet - Get PCI interface local device number.
1010 * This function gets the local device number of a given PCI interface.
1013 * pciIf - PCI interface number.
1019 * Local device number. 0xffffffff on Error
1021 *******************************************************************************/
1022 MV_U32
mvPciLocalDevNumGet(MV_U32 pciIf
)
1024 MV_U32 pciP2PConfig
;
1026 /* Parameter checking */
1028 if (PCI_DEFAULT_IF
!= pciIf
)
1030 if (pciIf
>= mvCtrlPciMaxIfGet())
1032 mvOsPrintf("mvPciLocalDevNumGet: ERR. Invalid PCI interface %d\n",
1038 pciP2PConfig
= MV_REG_READ(PCI_P2P_CONFIG_REG(pciIf
));
1040 pciP2PConfig
&= PPCR_DEV_NUM_MASK
;
1042 return (pciP2PConfig
>> PPCR_DEV_NUM_OFFS
);