1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Board-specific PCI description		File: bcm94702cpci_pci.c
5    *
6    *  This file describes the board-specific PCI slots/devices
7    *  and wiring thereof.
8    *
9    *********************************************************************
10    *
11    *  Copyright 2003
12    *  Broadcom Corporation. All rights reserved.
13    *
14    *  This software is furnished under license and may be used and
15    *  copied only in accordance with the following terms and
16    *  conditions.  Subject to these conditions, you may download,
17    *  copy, install, use, modify and distribute modified or unmodified
18    *  copies of this software in source and/or binary form.  No title
19    *  or ownership is transferred hereby.
20    *
21    *  1) Any source code used, modified or distributed must reproduce
22    *     and retain this copyright notice and list of conditions
23    *     as they appear in the source file.
24    *
25    *  2) No right is granted to use any trade name, trademark, or
26    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
27    *     name may not be used to endorse or promote products derived
28    *     from this software without the prior written permission of
29    *     Broadcom Corporation.
30    *
31    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
32    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
33    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
34    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
35    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
36    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
37    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
38    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
39    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
40    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
41    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
42    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
43    *     THE POSSIBILITY OF SUCH DAMAGE.
44    ********************************************************************* */
45
46#include "lib_types.h"
47
48#include "pcireg.h"
49#include "pcivar.h"
50#include "pci_internal.h"
51
52/* The BCM95836CPCI card can function as either host or device.  As a
53   host, it plugs into a CompactPCI System Slot.  The mapping from
54   System to Logical Slot for interrupts on the backplane is defined
55   by the CompactPCI spec (see Section 3.2.6 and Figure 8).
56
57   Backplane:
58   Slot    IDSEL   DevID   INT{A,B,C,D}  shift
59    1 (HB)  16       0       {A,B,C,D}     0
60    2       31      15       {B,C,D,A}     1
61    3       30      14       {C,D,A,B}     2
62    4       29      13       {D,A,B,C}     3
63    5       28      12       {A,B,C,D}     0
64    6       27      11       {B,C,D,A}     1
65    7       26      10       {C,D,A,B}     2
66    8       25       9       {D,A,B,C}     3
67
68   However, INTA and INTC signals on the connector are mapped to INTA on
69   the card, and the INTB and INTD signals are mapped to INTB. */
70
71/* Return the base shift of a slot or device on the motherboard.
72   This is board specific, for the BCM95836CPCI only. */
73uint8_t
74pci_int_shift_0(pcitag_t tag)
75{
76    int bus, device;
77
78    pci_break_tag(tag, NULL, &bus, &device, NULL);
79
80    if (bus == 0 && (device >= 9 && device <= 15))
81	return ((16 - device) % 4);
82    else
83	return 0;
84}
85
86/* Return the mapping of a device/function interrupt to an interrupt
87   line.  For the BCM95836CPCI, all interrupt signals from the
88   backplane are mapped to the single interrupt eventually generated
89   by the PCI core. */
90uint8_t
91pci_int_map_0(pcitag_t tag)
92{
93    pcireg_t data;
94    int pin;
95
96    data = pci_conf_read(tag, PCI_BPARAM_INTERRUPT_REG);
97    pin = PCI_INTERRUPT_PIN(data);
98    return (pin == 0) ? 0 : (((pin - 1) + pci_int_shift_0(tag)) % 2) + 1;
99}
100