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])
85 int slot_map_len = len;
86 struct slot_map *slot_map = map;
89 * Parse Slot label until we find the one requested
91 while (slot_map_len > 0) {
92 if (slot_map->agent == agent) {
94 * If Phb wasn't found, grab the entry first one found.
98 /* Found it, extract the data. */
99 if (slot_map->phb == *phb) {
100 memcpy(card, &slot_map->card_location, 3);
105 /* Point to the next Slot */
106 slot_map = (struct slot_map *)((char *)slot_map + SLOT_ENTRY_SIZE);
107 slot_map_len -= SLOT_ENTRY_SIZE;
114 static void __init iseries_parse_mfg_area(u8 *area, int len,
115 HvAgentId agent, u8 *phb,
116 u8 *frame, char card[4])
118 struct mfg_vpd_area *mfg_area = (struct mfg_vpd_area *)area;
119 int mfg_area_len = len;
120 u16 slot_map_fmt = 0;
123 while (mfg_area_len > 0) {
124 int mfg_tag_len = mfg_area->length;
125 /* Frame ID (FI 4649020310 ) */
126 if (mfg_area->tag == VPD_FRU_FRAME_ID)
127 *frame = mfg_area->data1;
128 /* Slot Map Format (MF 4D46020004 ) */
129 else if (mfg_area->tag == VPD_SLOT_MAP_FORMAT)
130 slot_map_fmt = (mfg_area->data1 * 256)
132 /* Slot Map (SM 534D90 */
133 else if (mfg_area->tag == VPD_SLOT_MAP) {
134 struct slot_map *slot_map;
136 if (slot_map_fmt == 0x1004)
137 slot_map = (struct slot_map *)((char *)mfg_area
138 + MFG_ENTRY_SIZE + 1);
140 slot_map = (struct slot_map *)((char *)mfg_area
142 iseries_parse_slot_area(slot_map, mfg_tag_len,
146 * Point to the next Mfg Area
147 * Use defined size, sizeof give wrong answer
149 mfg_area = (struct mfg_vpd_area *)((char *)mfg_area + mfg_tag_len
151 mfg_area_len -= (mfg_tag_len + 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 *area, int len)
165 while (data_len > 0) {
166 if ((*phb_ptr == 'B') && (*(phb_ptr + 1) == 'U')
167 && (*(phb_ptr + 2) == 'S')) {
169 while (*phb_ptr == ' ')
171 phb = (*phb_ptr & 0x0F);
181 * Parse out the VPD Areas
183 static void __init iseries_parse_vpd(u8 *data, int vpd_data_len,
184 HvAgentId agent, u8 *frame, char card[4])
187 int data_len = vpd_data_len - 3;
190 while ((*tag_ptr != VPD_END_OF_AREA) && (data_len > 0)) {
191 int len = *(tag_ptr + 1) + (*(tag_ptr + 2) * 256);
192 u8 *area = tag_ptr + 3;
194 if (*tag_ptr == VPD_ID_STRING)
195 phb = iseries_parse_phbid(area, len);
196 else if (*tag_ptr == VPD_VENDOR_AREA)
197 iseries_parse_mfg_area(area, len,
198 agent, &phb, frame, card);
199 /* Point to next Area. */
200 tag_ptr = area + len;
205 static int __init iseries_get_location_code(u16 bus, HvAgentId agent,
206 u8 *frame, char card[4])
210 u8 *bus_vpd = kmalloc(BUS_VPDSIZE, GFP_KERNEL);
212 if (bus_vpd == NULL) {
213 printk("PCI: Bus VPD Buffer allocation failure.\n");
216 bus_vpd_len = HvCallPci_getBusVpd(bus, iseries_hv_addr(bus_vpd),
218 if (bus_vpd_len == 0) {
219 printk("PCI: Bus VPD Buffer zero length.\n");
222 /* printk("PCI: bus_vpd: %p, %d\n",bus_vpd, bus_vpd_len); */
223 /* Make sure this is what I think it is */
224 if (*bus_vpd != VPD_ID_STRING) {
225 printk("PCI: Bus VPD Buffer missing starting tag.\n");
228 iseries_parse_vpd(bus_vpd, bus_vpd_len, agent, frame, card);
236 * Prints the device information.
237 * - Pass in pci_dev* pointer to the device.
238 * - Pass in the device count
241 * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
244 void __init iseries_device_information(struct pci_dev *pdev, int count,
245 u16 bus, HvSubBusNumber subbus)
251 agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus),
252 ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus));
254 if (iseries_get_location_code(bus, agent, &frame, card)) {
255 printk("%d. PCI: Bus%3d, Device%3d, Vendor %04X Frame%3d, "
256 "Card %4s 0x%04X\n", count, bus,
257 PCI_SLOT(pdev->devfn), pdev->vendor, frame,
258 card, (int)(pdev->class >> 8));