vpdinfo.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. #include <asm/types.h>
  31. #include <asm/resource.h>
  32. #include <asm/abs_addr.h>
  33. #include <asm/iseries/hv_types.h>
  34. #include "pci.h"
  35. #include "call_pci.h"
  36. /*
  37. * Size of Bus VPD data
  38. */
  39. #define BUS_VPDSIZE 1024
  40. /*
  41. * Bus Vpd Tags
  42. */
  43. #define VPD_END_OF_AREA 0x79
  44. #define VPD_ID_STRING 0x82
  45. #define VPD_VENDOR_AREA 0x84
  46. /*
  47. * Mfg Area Tags
  48. */
  49. #define VPD_FRU_FRAME_ID 0x4649 /* "FI" */
  50. #define VPD_SLOT_MAP_FORMAT 0x4D46 /* "MF" */
  51. #define VPD_SLOT_MAP 0x534D /* "SM" */
  52. /*
  53. * Structures of the areas
  54. */
  55. struct mfg_vpd_area {
  56. u16 tag;
  57. u8 length;
  58. u8 data1;
  59. u8 data2;
  60. };
  61. #define MFG_ENTRY_SIZE 3
  62. struct slot_map {
  63. u8 agent;
  64. u8 secondary_agent;
  65. u8 phb;
  66. char card_location[3];
  67. char parms[8];
  68. char reserved[2];
  69. };
  70. #define SLOT_ENTRY_SIZE 16
  71. /*
  72. * Parse the Slot Area
  73. */
  74. static void __init iseries_parse_slot_area(struct slot_map *map, int len,
  75. HvAgentId agent, u8 *phb, char card[4])
  76. {
  77. /*
  78. * Parse Slot label until we find the one requested
  79. */
  80. while (len > 0) {
  81. if (map->agent == agent) {
  82. /*
  83. * If Phb wasn't found, grab the entry first one found.
  84. */
  85. if (*phb == 0xff)
  86. *phb = map->phb;
  87. /* Found it, extract the data. */
  88. if (map->phb == *phb) {
  89. memcpy(card, &map->card_location, 3);
  90. card[3] = 0;
  91. break;
  92. }
  93. }
  94. /* Point to the next Slot */
  95. map = (struct slot_map *)((char *)map + SLOT_ENTRY_SIZE);
  96. len -= SLOT_ENTRY_SIZE;
  97. }
  98. }
  99. /*
  100. * Parse the Mfg Area
  101. */
  102. static void __init iseries_parse_mfg_area(struct mfg_vpd_area *area, int len,
  103. HvAgentId agent, u8 *phb, u8 *frame, char card[4])
  104. {
  105. u16 slot_map_fmt = 0;
  106. /* Parse Mfg Data */
  107. while (len > 0) {
  108. int mfg_tag_len = area->length;
  109. /* Frame ID (FI 4649020310 ) */
  110. if (area->tag == VPD_FRU_FRAME_ID)
  111. *frame = area->data1;
  112. /* Slot Map Format (MF 4D46020004 ) */
  113. else if (area->tag == VPD_SLOT_MAP_FORMAT)
  114. slot_map_fmt = (area->data1 * 256)
  115. + area->data2;
  116. /* Slot Map (SM 534D90 */
  117. else if (area->tag == VPD_SLOT_MAP) {
  118. struct slot_map *slot_map;
  119. if (slot_map_fmt == 0x1004)
  120. slot_map = (struct slot_map *)((char *)area
  121. + MFG_ENTRY_SIZE + 1);
  122. else
  123. slot_map = (struct slot_map *)((char *)area
  124. + MFG_ENTRY_SIZE);
  125. iseries_parse_slot_area(slot_map, mfg_tag_len,
  126. agent, phb, card);
  127. }
  128. /*
  129. * Point to the next Mfg Area
  130. * Use defined size, sizeof give wrong answer
  131. */
  132. area = (struct mfg_vpd_area *)((char *)area + mfg_tag_len
  133. + MFG_ENTRY_SIZE);
  134. len -= (mfg_tag_len + MFG_ENTRY_SIZE);
  135. }
  136. }
  137. /*
  138. * Look for "BUS".. Data is not Null terminated.
  139. * PHBID of 0xFF indicates PHB was not found in VPD Data.
  140. */
  141. static u8 __init iseries_parse_phbid(u8 *area, int len)
  142. {
  143. while (len > 0) {
  144. if ((*area == 'B') && (*(area + 1) == 'U')
  145. && (*(area + 2) == 'S')) {
  146. area += 3;
  147. while (*area == ' ')
  148. area++;
  149. return *area & 0x0F;
  150. }
  151. area++;
  152. len--;
  153. }
  154. return 0xff;
  155. }
  156. /*
  157. * Parse out the VPD Areas
  158. */
  159. static void __init iseries_parse_vpd(u8 *data, int data_len,
  160. HvAgentId agent, u8 *frame, char card[4])
  161. {
  162. u8 phb = 0xff;
  163. while (data_len > 0) {
  164. int len;
  165. u8 tag = *data;
  166. if (tag == VPD_END_OF_AREA)
  167. break;
  168. len = *(data + 1) + (*(data + 2) * 256);
  169. data += 3;
  170. data_len -= 3;
  171. if (tag == VPD_ID_STRING)
  172. phb = iseries_parse_phbid(data, len);
  173. else if (tag == VPD_VENDOR_AREA)
  174. iseries_parse_mfg_area((struct mfg_vpd_area *)data, len,
  175. agent, &phb, frame, card);
  176. /* Point to next Area. */
  177. data += len;
  178. data_len -= len;
  179. }
  180. }
  181. static int __init iseries_get_location_code(u16 bus, HvAgentId agent,
  182. u8 *frame, char card[4])
  183. {
  184. int status = 0;
  185. int bus_vpd_len = 0;
  186. u8 *bus_vpd = kmalloc(BUS_VPDSIZE, GFP_KERNEL);
  187. if (bus_vpd == NULL) {
  188. printk("PCI: Bus VPD Buffer allocation failure.\n");
  189. return 0;
  190. }
  191. bus_vpd_len = HvCallPci_getBusVpd(bus, iseries_hv_addr(bus_vpd),
  192. BUS_VPDSIZE);
  193. if (bus_vpd_len == 0) {
  194. printk("PCI: Bus VPD Buffer zero length.\n");
  195. goto out_free;
  196. }
  197. /* printk("PCI: bus_vpd: %p, %d\n",bus_vpd, bus_vpd_len); */
  198. /* Make sure this is what I think it is */
  199. if (*bus_vpd != VPD_ID_STRING) {
  200. printk("PCI: Bus VPD Buffer missing starting tag.\n");
  201. goto out_free;
  202. }
  203. iseries_parse_vpd(bus_vpd, bus_vpd_len, agent, frame, card);
  204. status = 1;
  205. out_free:
  206. kfree(bus_vpd);
  207. return status;
  208. }
  209. /*
  210. * Prints the device information.
  211. * - Pass in pci_dev* pointer to the device.
  212. * - Pass in the device count
  213. *
  214. * Format:
  215. * PCI: Bus 0, Device 26, Vendor 0x12AE Frame 1, Card C10 Ethernet
  216. * controller
  217. */
  218. void __init iseries_device_information(struct pci_dev *pdev, int count,
  219. u16 bus, HvSubBusNumber subbus)
  220. {
  221. u8 frame = 0;
  222. char card[4];
  223. HvAgentId agent;
  224. agent = ISERIES_PCI_AGENTID(ISERIES_GET_DEVICE_FROM_SUBBUS(subbus),
  225. ISERIES_GET_FUNCTION_FROM_SUBBUS(subbus));
  226. if (iseries_get_location_code(bus, agent, &frame, card)) {
  227. printk("%d. PCI: Bus%3d, Device%3d, Vendor %04X Frame%3d, "
  228. "Card %4s 0x%04X\n", count, bus,
  229. PCI_SLOT(pdev->devfn), pdev->vendor, frame,
  230. card, (int)(pdev->class >> 8));
  231. }
  232. }