2 * This code gets the card location of the hardware
3 * Copyright (C) 2001 <Allan H Trautman> <IBM Corp>
4 * Copyright (C) 2005 Stephen Rothwel, IBM Corp
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the:
18 * Free Software Foundation, Inc.,
19 * 59 Temple Place, Suite 330,
20 * Boston, MA 02111-1307 USA
23 * Created, Feb 2, 2001
24 * Ported to ppc64, August 20, 2001
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <asm/types.h>
31 #include <asm/resource.h>
33 #include <asm/iSeries/HvCallPci.h>
34 #include <asm/iSeries/HvTypes.h>
35 #include <asm/iSeries/iSeries_pci.h>
38 * Size of Bus VPD data
40 #define BUS_VPDSIZE 1024
45 #define VpdEndOfAreaTag 0x79
46 #define VpdIdStringTag 0x82
47 #define VpdVendorAreaTag 0x84
52 #define VpdFruFrameId 0x4649 // "FI"
53 #define VpdSlotMapFormat 0x4D46 // "MF"
54 #define VpdSlotMap 0x534D // "SM"
57 * Structures of the areas
59 struct MfgVpdAreaStruct
{
65 typedef struct MfgVpdAreaStruct MfgArea
;
66 #define MFG_ENTRY_SIZE 3
68 struct SlotMapStruct
{
76 typedef struct SlotMapStruct SlotMap
;
77 #define SLOT_ENTRY_SIZE 16
82 static void __init
iSeries_Parse_SlotArea(SlotMap
*MapPtr
, int MapLen
,
83 HvAgentId agent
, u8
*PhbId
, char card
[4])
85 int SlotMapLen
= MapLen
;
86 SlotMap
*SlotMapPtr
= MapPtr
;
89 * Parse Slot label until we find the one requested
91 while (SlotMapLen
> 0) {
92 if (SlotMapPtr
->AgentId
== agent
) {
94 * If Phb wasn't found, grab the entry first one found.
97 *PhbId
= SlotMapPtr
->PhbId
;
98 /* Found it, extract the data. */
99 if (SlotMapPtr
->PhbId
== *PhbId
) {
100 memcpy(card
, &SlotMapPtr
->CardLocation
, 3);
105 /* Point to the next Slot */
106 SlotMapPtr
= (SlotMap
*)((char *)SlotMapPtr
+ SLOT_ENTRY_SIZE
);
107 SlotMapLen
-= SLOT_ENTRY_SIZE
;
114 static void __init
iSeries_Parse_MfgArea(u8
*AreaData
, int AreaLen
,
115 HvAgentId agent
, u8
*PhbId
,
116 u8
*frame
, char card
[4])
118 MfgArea
*MfgAreaPtr
= (MfgArea
*)AreaData
;
119 int MfgAreaLen
= AreaLen
;
123 while (MfgAreaLen
> 0) {
124 int MfgTagLen
= MfgAreaPtr
->TagLength
;
125 /* Frame ID (FI 4649020310 ) */
126 if (MfgAreaPtr
->Tag
== VpdFruFrameId
) /* FI */
127 *frame
= MfgAreaPtr
->AreaData1
;
128 /* Slot Map Format (MF 4D46020004 ) */
129 else if (MfgAreaPtr
->Tag
== VpdSlotMapFormat
) /* MF */
130 SlotMapFmt
= (MfgAreaPtr
->AreaData1
* 256)
131 + MfgAreaPtr
->AreaData2
;
132 /* Slot Map (SM 534D90 */
133 else if (MfgAreaPtr
->Tag
== VpdSlotMap
) { /* SM */
136 if (SlotMapFmt
== 0x1004)
137 SlotMapPtr
= (SlotMap
*)((char *)MfgAreaPtr
138 + MFG_ENTRY_SIZE
+ 1);
140 SlotMapPtr
= (SlotMap
*)((char *)MfgAreaPtr
142 iSeries_Parse_SlotArea(SlotMapPtr
, MfgTagLen
,
146 * Point to the next Mfg Area
147 * Use defined size, sizeof give wrong answer
149 MfgAreaPtr
= (MfgArea
*)((char *)MfgAreaPtr
+ MfgTagLen
151 MfgAreaLen
-= (MfgTagLen
+ MFG_ENTRY_SIZE
);
156 * Look for "BUS".. Data is not Null terminated.
157 * PHBID of 0xFF indicates PHB was not found in VPD Data.
159 static int __init
iSeries_Parse_PhbId(u8
*AreaPtr
, int AreaLength
)
161 u8
*PhbPtr
= AreaPtr
;
162 int DataLen
= AreaLength
;
165 while (DataLen
> 0) {
166 if ((*PhbPtr
== 'B') && (*(PhbPtr
+ 1) == 'U')
167 && (*(PhbPtr
+ 2) == 'S')) {
169 while (*PhbPtr
== ' ')
171 PhbId
= (*PhbPtr
& 0x0F);
181 * Parse out the VPD Areas
183 static void __init
iSeries_Parse_Vpd(u8
*VpdData
, int VpdDataLen
,
184 HvAgentId agent
, u8
*frame
, char card
[4])
186 u8
*TagPtr
= VpdData
;
187 int DataLen
= VpdDataLen
- 3;
190 while ((*TagPtr
!= VpdEndOfAreaTag
) && (DataLen
> 0)) {
191 int AreaLen
= *(TagPtr
+ 1) + (*(TagPtr
+ 2) * 256);
192 u8
*AreaData
= TagPtr
+ 3;
194 if (*TagPtr
== VpdIdStringTag
)
195 PhbId
= iSeries_Parse_PhbId(AreaData
, AreaLen
);
196 else if (*TagPtr
== VpdVendorAreaTag
)
197 iSeries_Parse_MfgArea(AreaData
, AreaLen
,
198 agent
, &PhbId
, frame
, card
);
199 /* Point to next Area. */
200 TagPtr
= AreaData
+ AreaLen
;
205 static void __init
iSeries_Get_Location_Code(u16 bus
, HvAgentId agent
,
206 u8
*frame
, char card
[4])
209 u8
*BusVpdPtr
= kmalloc(BUS_VPDSIZE
, GFP_KERNEL
);
211 if (BusVpdPtr
== NULL
) {
212 printk("PCI: Bus VPD Buffer allocation failure.\n");
215 BusVpdLen
= HvCallPci_getBusVpd(bus
, ISERIES_HV_ADDR(BusVpdPtr
),
217 if (BusVpdLen
== 0) {
218 printk("PCI: Bus VPD Buffer zero length.\n");
221 /* printk("PCI: BusVpdPtr: %p, %d\n",BusVpdPtr, BusVpdLen); */
222 /* Make sure this is what I think it is */
223 if (*BusVpdPtr
!= VpdIdStringTag
) { /* 0x82 */
224 printk("PCI: Bus VPD Buffer missing starting tag.\n");
227 iSeries_Parse_Vpd(BusVpdPtr
, BusVpdLen
, agent
, frame
, card
);
233 * Prints the device information.
234 * - Pass in pci_dev* pointer to the device.
235 * - Pass in the device count
238 * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
241 void __init
iSeries_Device_Information(struct pci_dev
*PciDev
, int count
)
243 struct device_node
*DevNode
= PciDev
->sysdata
;
247 HvSubBusNumber subbus
;
250 if (DevNode
== NULL
) {
251 printk("%d. PCI: iSeries_Device_Information DevNode is NULL\n",
256 bus
= ISERIES_BUS(DevNode
);
257 subbus
= ISERIES_SUBBUS(DevNode
);
258 agent
= ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus
),
259 ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus
));
260 iSeries_Get_Location_Code(bus
, agent
, &frame
, card
);
262 printk("%d. PCI: Bus%3d, Device%3d, Vendor %04X Frame%3d, Card %4s ",
263 count
, bus
, PCI_SLOT(PciDev
->devfn
), PciDev
->vendor
,
265 printk("0x%04X\n", (int)(PciDev
->class >> 8));