1/*  *********************************************************************
2    *  Broadcom Common Firmware Environment (CFE)
3    *
4    *  Board-specific PCI description		File: bmw_pci.c
5    *
6    *  This file describes the board-specific PCI slots/devices
7    *  and wiring thereof.
8    *
9    *  Author:  Ed Satterthwaite
10    *
11    *********************************************************************
12    *
13    *  Copyright 2004
14    *  Broadcom Corporation. All rights reserved.
15    *
16    *  This software is furnished under license and may be used and
17    *  copied only in accordance with the following terms and
18    *  conditions.  Subject to these conditions, you may download,
19    *  copy, install, use, modify and distribute modified or unmodified
20    *  copies of this software in source and/or binary form.  No title
21    *  or ownership is transferred hereby.
22    *
23    *  1) Any source code used, modified or distributed must reproduce
24    *     and retain this copyright notice and list of conditions
25    *     as they appear in the source file.
26    *
27    *  2) No right is granted to use any trade name, trademark, or
28    *     logo of Broadcom Corporation.  The "Broadcom Corporation"
29    *     name may not be used to endorse or promote products derived
30    *     from this software without the prior written permission of
31    *     Broadcom Corporation.
32    *
33    *  3) THIS SOFTWARE IS PROVIDED "AS-IS" AND ANY EXPRESS OR
34    *     IMPLIED WARRANTIES, INCLUDING BUT NOT LIMITED TO, ANY IMPLIED
35    *     WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
36    *     PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED. IN NO EVENT
37    *     SHALL BROADCOM BE LIABLE FOR ANY DAMAGES WHATSOEVER, AND IN
38    *     PARTICULAR, BROADCOM SHALL NOT BE LIABLE FOR DIRECT, INDIRECT,
39    *     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
40    *     (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
41    *     GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
42    *     BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
43    *     OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
44    *     TORT (INCLUDING NEGLIGENCE OR OTHERWISE), EVEN IF ADVISED OF
45    *     THE POSSIBILITY OF SUCH DAMAGE.
46    ********************************************************************* */
47
48#include "lib_types.h"
49
50#include "pcireg.h"
51#include "pcivar.h"
52#include "pci_internal.h"
53
54/* PCI interrupt mapping on the BMW card.  The only on-board device has
55   id 13 (bcm5703 10/100/1000 NIC).  There is also a CompactPCI connector
56   configured for a cPCI System Slot.
57
58   All interrupts are routed via the Altera EPM7064 CPLD to the mpc8245
59   as IRQ1 .. IRQ4 (?).  The bcm5703 interrupt is connected directly,
60   not via INT[A-D].
61
62     Slot    IDSEL   DevID  IRQ{0,1,2,3,4}  shift
63     (HB)     gnd      0      {-,-,-,-}       -  (NC)
64    (5703)    13      13      {M,-,-,-}       0
65
66   PCI INTA through INTD from the CPCI connector are wired as
67   separate signals.  A standard backplane maps IDSEL 31:25 to CPCI
68   logical slots 2 to 8:
69             IDSEL   DevID  cPCI Logical Slot  shift
70              31      10         2               1
71              25      25         8               3
72              26      26         7               2
73              27      27         6               1
74              28      28         5               0
75              29      29         4               3
76              30      30         3               2
77*/
78
79/* Return the base shift of a slot or device on the motherboard.
80   This is board specific, for the BMW only. */
81uint8_t
82pci_int_shift_0(pcitag_t tag)
83{
84    int bus, device;
85
86    pci_break_tag(tag, NULL, &bus, &device, NULL);
87    if (bus == 0) {
88	switch (device) {
89	    case 13:  return 0;
90
91	    /* CPCI backplane */
92	    case 10:  return 1;
93	    case 25:  return 3;
94	    case 26:  return 2;
95	    case 27:  return 1;
96	    case 28:  return 0;
97	    case 29:  return 3;
98	    case 30:  return 2;
99
100	    default:  return 0;   /* for now */
101	    }
102	}
103    else
104	return 0;
105}
106
107/* Return the mapping of a device/function interrupt to an
108   interrupt line (IRQ number).  XXX CONJECTURED XXX */
109uint8_t
110pci_int_map_0(pcitag_t tag)
111{
112    pcireg_t data;
113    int pin, bus, device;
114
115    data = pci_conf_read(tag, PCI_BPARAM_INTERRUPT_REG);
116    pin = PCI_INTERRUPT_PIN(data);
117    if (pin == 0) {
118	/* No IRQ used. */
119	return 0xFF;
120	}
121
122    pci_break_tag(tag, NULL, &bus, &device, NULL);
123
124    if (bus == 0) {
125	switch (device) {
126	    /* Assume MAC -> IRQ[0] */
127	    case 13:  return 0;
128
129            /* via cPCI connector */
130	    /* Assume INT{A,B,C,D} -> IRQ[{1,2,3,4}] */
131	    case 10:  return 1+1;
132	    case 25:  return 1+3;
133	    case 26:  return 1+2;
134	    case 27:  return 1+1;
135	    case 28:  return 1+0;
136	    case 29:  return 1+3;
137	    case 30:  return 1+2;
138
139	    default: return 0xFF;
140	    }
141	}
142    else
143	return 0xFF;
144}
145