]> git.karo-electronics.de Git - karo-tx-linux.git/blob - arch/powerpc/platforms/iseries/vpdinfo.c
f9415bf01518e7a53211b09a196786084264f252
[karo-tx-linux.git] / arch / powerpc / platforms / iseries / vpdinfo.c
1 /*
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
5  *
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.
10  *
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.
15  *
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
21  *
22  * Change Activity:
23  *   Created, Feb 2, 2001
24  *   Ported to ppc64, August 20, 2001
25  * End Change Activity
26  */
27 #include <linux/init.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30
31 #include <asm/types.h>
32 #include <asm/resource.h>
33 #include <asm/abs_addr.h>
34 #include <asm/iseries/hv_types.h>
35
36 #include "pci.h"
37 #include "call_pci.h"
38
39 /*
40  * Size of Bus VPD data
41  */
42 #define BUS_VPDSIZE      1024
43
44 /*
45  * Bus Vpd Tags
46  */
47 #define VPD_END_OF_AREA         0x79
48 #define VPD_ID_STRING           0x82
49 #define VPD_VENDOR_AREA         0x84
50
51 /*
52  * Mfg Area Tags
53  */
54 #define VPD_FRU_FRAME_ID        0x4649  /* "FI" */
55 #define VPD_SLOT_MAP_FORMAT     0x4D46  /* "MF" */
56 #define VPD_SLOT_MAP            0x534D  /* "SM" */
57
58 /*
59  * Structures of the areas
60  */
61 struct mfg_vpd_area {
62         u16     tag;
63         u8      length;
64         u8      data1;
65         u8      data2;
66 };
67 #define MFG_ENTRY_SIZE   3
68
69 struct slot_map {
70         u8      agent;
71         u8      secondary_agent;
72         u8      phb;
73         char    card_location[3];
74         char    parms[8];
75         char    reserved[2];
76 };
77 #define SLOT_ENTRY_SIZE   16
78
79 /*
80  * Parse the Slot Area
81  */
82 static void __init iseries_parse_slot_area(struct slot_map *map, int len,
83                 HvAgentId agent, u8 *phb, char card[4])
84 {
85         int slot_map_len = len;
86         struct slot_map *slot_map = map;
87
88         /*
89          * Parse Slot label until we find the one requested
90          */
91         while (slot_map_len > 0) {
92                 if (slot_map->agent == agent) {
93                         /*
94                          * If Phb wasn't found, grab the entry first one found.
95                          */
96                         if (*phb == 0xff)
97                                 *phb = slot_map->phb;
98                         /* Found it, extract the data. */
99                         if (slot_map->phb == *phb) {
100                                 memcpy(card, &slot_map->card_location, 3);
101                                 card[3]  = 0;
102                                 break;
103                         }
104                 }
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;
108         }
109 }
110
111 /*
112  * Parse the Mfg Area
113  */
114 static void __init iseries_parse_mfg_area(u8 *area, int len,
115                 HvAgentId agent, u8 *phb,
116                 u8 *frame, char card[4])
117 {
118         struct mfg_vpd_area *mfg_area = (struct mfg_vpd_area *)area;
119         int mfg_area_len = len;
120         u16 slot_map_fmt = 0;
121
122         /* Parse Mfg Data */
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)
131                                 + mfg_area->data2;
132                 /* Slot Map         (SM 534D90 */
133                 else if (mfg_area->tag == VPD_SLOT_MAP) {
134                         struct slot_map *slot_map;
135
136                         if (slot_map_fmt == 0x1004)
137                                 slot_map = (struct slot_map *)((char *)mfg_area
138                                                 + MFG_ENTRY_SIZE + 1);
139                         else
140                                 slot_map = (struct slot_map *)((char *)mfg_area
141                                                 + MFG_ENTRY_SIZE);
142                         iseries_parse_slot_area(slot_map, mfg_tag_len,
143                                         agent, phb, card);
144                 }
145                 /*
146                  * Point to the next Mfg Area
147                  * Use defined size, sizeof give wrong answer
148                  */
149                 mfg_area = (struct mfg_vpd_area *)((char *)mfg_area + mfg_tag_len
150                                 + MFG_ENTRY_SIZE);
151                 mfg_area_len -= (mfg_tag_len + MFG_ENTRY_SIZE);
152         }
153 }
154
155 /*
156  * Look for "BUS".. Data is not Null terminated.
157  * PHBID of 0xFF indicates PHB was not found in VPD Data.
158  */
159 static int __init iseries_parse_phbid(u8 *area, int len)
160 {
161         u8 *phb_ptr = area;
162         int data_len = len;
163         char phb = 0xFF;
164
165         while (data_len > 0) {
166                 if ((*phb_ptr == 'B') && (*(phb_ptr + 1) == 'U')
167                                 && (*(phb_ptr + 2) == 'S')) {
168                         phb_ptr += 3;
169                         while (*phb_ptr == ' ')
170                                 ++phb_ptr;
171                         phb = (*phb_ptr & 0x0F);
172                         break;
173                 }
174                 ++phb_ptr;
175                 --data_len;
176         }
177         return phb;
178 }
179
180 /*
181  * Parse out the VPD Areas
182  */
183 static void __init iseries_parse_vpd(u8 *data, int vpd_data_len,
184                 HvAgentId agent, u8 *frame, char card[4])
185 {
186         u8 *tag_ptr = data;
187         int data_len = vpd_data_len - 3;
188         u8 phb = 0xff;
189
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;
193
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;
201                 data_len -= len;
202         }
203 }
204
205 static int __init iseries_get_location_code(u16 bus, HvAgentId agent,
206                 u8 *frame, char card[4])
207 {
208         int status = 0;
209         int bus_vpd_len = 0;
210         u8 *bus_vpd = kmalloc(BUS_VPDSIZE, GFP_KERNEL);
211
212         if (bus_vpd == NULL) {
213                 printk("PCI: Bus VPD Buffer allocation failure.\n");
214                 return 0;
215         }
216         bus_vpd_len = HvCallPci_getBusVpd(bus, iseries_hv_addr(bus_vpd),
217                                         BUS_VPDSIZE);
218         if (bus_vpd_len == 0) {
219                 printk("PCI: Bus VPD Buffer zero length.\n");
220                 goto out_free;
221         }
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");
226                 goto out_free;
227         }
228         iseries_parse_vpd(bus_vpd, bus_vpd_len, agent, frame, card);
229         status = 1;
230 out_free:
231         kfree(bus_vpd);
232         return status;
233 }
234
235 /*
236  * Prints the device information.
237  * - Pass in pci_dev* pointer to the device.
238  * - Pass in the device count
239  *
240  * Format:
241  * PCI: Bus  0, Device 26, Vendor 0x12AE  Frame  1, Card  C10  Ethernet
242  * controller
243  */
244 void __init iseries_device_information(struct pci_dev *pdev, int count,
245                 u16 bus, HvSubBusNumber subbus)
246 {
247         u8 frame = 0;
248         char card[4];
249         HvAgentId agent;
250
251         agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus),
252                         ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus));
253
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));
259         }
260 }