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>
31 #include <asm/types.h>
32 #include <asm/resource.h>
33 #include <asm/abs_addr.h>
34 #include <asm/iseries/hv_types.h>
40 * Size of Bus VPD data
42 #define BUS_VPDSIZE 1024
47 #define VPD_END_OF_AREA 0x79
48 #define VPD_ID_STRING 0x82
49 #define VPD_VENDOR_AREA 0x84
54 #define VPD_FRU_FRAME_ID 0x4649 /* "FI" */
55 #define VPD_SLOT_MAP_FORMAT 0x4D46 /* "MF" */
56 #define VPD_SLOT_MAP 0x534D /* "SM" */
59 * Structures of the areas
67 #define MFG_ENTRY_SIZE 3
73 char card_location[3];
77 #define SLOT_ENTRY_SIZE 16
82 static void __init iseries_parse_slot_area(struct slot_map *map, int len,
83 HvAgentId agent, u8 *phb, char card[4])
86 * Parse Slot label until we find the one requested
89 if (map->agent == agent) {
91 * If Phb wasn't found, grab the entry first one found.
95 /* Found it, extract the data. */
96 if (map->phb == *phb) {
97 memcpy(card, &map->card_location, 3);
102 /* Point to the next Slot */
103 map = (struct slot_map *)((char *)map + SLOT_ENTRY_SIZE);
104 len -= SLOT_ENTRY_SIZE;
111 static void __init iseries_parse_mfg_area(struct mfg_vpd_area *area, int len,
112 HvAgentId agent, u8 *phb, u8 *frame, char card[4])
114 u16 slot_map_fmt = 0;
118 int mfg_tag_len = area->length;
119 /* Frame ID (FI 4649020310 ) */
120 if (area->tag == VPD_FRU_FRAME_ID)
121 *frame = area->data1;
122 /* Slot Map Format (MF 4D46020004 ) */
123 else if (area->tag == VPD_SLOT_MAP_FORMAT)
124 slot_map_fmt = (area->data1 * 256)
126 /* Slot Map (SM 534D90 */
127 else if (area->tag == VPD_SLOT_MAP) {
128 struct slot_map *slot_map;
130 if (slot_map_fmt == 0x1004)
131 slot_map = (struct slot_map *)((char *)area
132 + MFG_ENTRY_SIZE + 1);
134 slot_map = (struct slot_map *)((char *)area
136 iseries_parse_slot_area(slot_map, mfg_tag_len,
140 * Point to the next Mfg Area
141 * Use defined size, sizeof give wrong answer
143 area = (struct mfg_vpd_area *)((char *)area + mfg_tag_len
145 len -= (mfg_tag_len + MFG_ENTRY_SIZE);
150 * Look for "BUS".. Data is not Null terminated.
151 * PHBID of 0xFF indicates PHB was not found in VPD Data.
153 static u8 __init iseries_parse_phbid(u8 *area, int len)
156 if ((*area == 'B') && (*(area + 1) == 'U')
157 && (*(area + 2) == 'S')) {
170 * Parse out the VPD Areas
172 static void __init iseries_parse_vpd(u8 *data, int data_len,
173 HvAgentId agent, u8 *frame, char card[4])
177 while (data_len > 0) {
181 if (tag == VPD_END_OF_AREA)
183 len = *(data + 1) + (*(data + 2) * 256);
186 if (tag == VPD_ID_STRING)
187 phb = iseries_parse_phbid(data, len);
188 else if (tag == VPD_VENDOR_AREA)
189 iseries_parse_mfg_area((struct mfg_vpd_area *)data, len,
190 agent, &phb, frame, card);
191 /* Point to next Area. */
197 static int __init iseries_get_location_code(u16 bus, HvAgentId agent,
198 u8 *frame, char card[4])
202 u8 *bus_vpd = kmalloc(BUS_VPDSIZE, GFP_KERNEL);
204 if (bus_vpd == NULL) {
205 printk("PCI: Bus VPD Buffer allocation failure.\n");
208 bus_vpd_len = HvCallPci_getBusVpd(bus, iseries_hv_addr(bus_vpd),
210 if (bus_vpd_len == 0) {
211 printk("PCI: Bus VPD Buffer zero length.\n");
214 /* printk("PCI: bus_vpd: %p, %d\n",bus_vpd, bus_vpd_len); */
215 /* Make sure this is what I think it is */
216 if (*bus_vpd != VPD_ID_STRING) {
217 printk("PCI: Bus VPD Buffer missing starting tag.\n");
220 iseries_parse_vpd(bus_vpd, bus_vpd_len, agent, frame, card);
228 * Prints the device information.
229 * - Pass in pci_dev* pointer to the device.
230 * - Pass in the device count
233 * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
236 void __init iseries_device_information(struct pci_dev *pdev, int count,
237 u16 bus, HvSubBusNumber subbus)
243 agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus),
244 ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus));
246 if (iseries_get_location_code(bus, agent, &frame, card)) {
247 printk("%d. PCI: Bus%3d, Device%3d, Vendor %04X Frame%3d, "
248 "Card %4s 0x%04X\n", count, bus,
249 PCI_SLOT(pdev->devfn), pdev->vendor, frame,
250 card, (int)(pdev->class >> 8));