Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

296 lines
10 KiB

  1. /*++
  2. Copyright (c) 1999 Intel Corporation
  3. Module Name:
  4. pci.c
  5. Abstract:
  6. Revision History
  7. --*/
  8. #include "shelle.h"
  9. #include "pci22.h"
  10. EFI_STATUS
  11. PciDump (
  12. IN EFI_HANDLE ImageHandle,
  13. IN EFI_SYSTEM_TABLE *SystemTable
  14. );
  15. #define HEADER_TYPE_MULTI_FUNCTION 0x80
  16. typedef struct _PCI_CLASS_CODE {
  17. UINT8 Class;
  18. CHAR16 *Str;
  19. struct _PCI_CLASS_CODE *SubClass;
  20. } PCI_CLASS_CODE;
  21. VOID
  22. PciPrintClassCode (
  23. IN PCI_DEVICE_INDEPENDENT_REGION *Pci
  24. );
  25. PCI_CLASS_CODE PciMassStoreSubClass[] = {
  26. 0x00, L"SCSI Bus", NULL,
  27. 0x01, L"IDE", NULL,
  28. 0x02, L"Floppy", NULL,
  29. 0x03, L"IPI", NULL,
  30. 0x04, L"RAID", NULL,
  31. 0x80, L"Other", NULL,
  32. 0xff, L"ERROR", NULL
  33. };
  34. PCI_CLASS_CODE PciNetworkSubClass[] = {
  35. 0x00, L"Ethernet", NULL,
  36. 0x01, L"Token Ring", NULL,
  37. 0x02, L"FDDI", NULL,
  38. 0x03, L"ATM", NULL,
  39. 0x80, L"Other", NULL,
  40. 0xff, L"ERROR", NULL
  41. };
  42. PCI_CLASS_CODE PciDisplayControllerClass[] = {
  43. 0x00, L"VGA", NULL,
  44. 0x01, L"XVGA", NULL,
  45. 0x02, L"3D", NULL,
  46. 0x80, L"Other", NULL,
  47. 0xff, L"ERROR", NULL
  48. };
  49. PCI_CLASS_CODE PciBridgeSubClass[] = {
  50. 0x00, L"Host", NULL,
  51. 0x01, L"ISA", NULL,
  52. 0x02, L"EISA", NULL,
  53. 0x03, L"MC", NULL,
  54. 0x04, L"PCI to PCI", NULL,
  55. 0x05, L"PCMCIA", NULL,
  56. 0x06, L"NuBus", NULL,
  57. 0x07, L"CardBus", NULL,
  58. 0x08, L"RACEway", NULL,
  59. 0xff, L"ERROR", NULL
  60. };
  61. PCI_CLASS_CODE PciSysPeriphSubClass[] = {
  62. 0x00, L"Interrupt Controller", NULL,
  63. 0x01, L"DMA", NULL,
  64. 0x02, L"System Timer", NULL,
  65. 0x03, L"RTC", NULL,
  66. 0x80, L"Other", NULL,
  67. 0xff, L"ERROR", NULL
  68. };
  69. PCI_CLASS_CODE PciSerialBusSubClass[] = {
  70. 0x00, L"1394", NULL,
  71. 0x01, L"ACCESS Bus", NULL,
  72. 0x02, L"SSA", NULL,
  73. 0x03, L"USB", NULL,
  74. 0x04, L"Fibre Channel", NULL,
  75. 0x05, L"SMBus", NULL,
  76. 0x80, L"Other", NULL,
  77. 0xff, L"ERROR", NULL
  78. };
  79. /*
  80. * BugBug: I got tired of typing, so this is only partial PCI info.
  81. */
  82. PCI_CLASS_CODE PciClassCodes[] = {
  83. 0x00, L"Backward Compatible", NULL,
  84. 0x01, L"Mass Storage Controller", PciMassStoreSubClass,
  85. 0x02, L"Network Controller", PciNetworkSubClass,
  86. 0x03, L"Display Controller", PciDisplayControllerClass,
  87. 0x04, L"Multimedia Device", NULL,
  88. 0x05, L"Memory Controller", NULL,
  89. 0x06, L"PCI Bridge Device", PciBridgeSubClass,
  90. 0x07, L"Communications Controller", NULL,
  91. 0x08, L"Generic System Peripheral", PciSysPeriphSubClass,
  92. 0x09, L"Input Devices", NULL,
  93. 0x0a, L"Docking Stations", NULL,
  94. 0x0b, L"Processors", NULL,
  95. 0x0c, L"Serial Bus Controller", PciSerialBusSubClass,
  96. 0x0d, L"Wireless Controller", NULL,
  97. 0x0e, L"I2O", NULL,
  98. 0x0f, L"Satellite Controller", NULL,
  99. 0x10, L"Encryption Controller", NULL,
  100. 0x11, L"Data Acquisition", NULL,
  101. 0xff, L"No Class", NULL
  102. };
  103. VOID
  104. PciPrintClassCode (
  105. IN PCI_DEVICE_INDEPENDENT_REGION *Pci
  106. )
  107. {
  108. UINT16 *BaseClass, *SubClass;
  109. UINTN i,j;
  110. PCI_CLASS_CODE *ClassTable;
  111. BaseClass = SubClass = NULL;
  112. for (i=0; PciClassCodes[i].Class != 0xff; i++) {
  113. if (Pci->ClassCode[2] == PciClassCodes[i].Class) {
  114. BaseClass = PciClassCodes[i].Str;
  115. if (PciClassCodes[i].SubClass) {
  116. ClassTable = PciClassCodes[i].SubClass;
  117. for (j=0; ClassTable->Class != 0xff; j++, ClassTable++) {
  118. if (Pci->ClassCode[1] == ClassTable->Class) {
  119. SubClass = ClassTable->Str;
  120. }
  121. }
  122. }
  123. }
  124. }
  125. Print (L"%s - %s", BaseClass, (SubClass == NULL ? L"" : SubClass));
  126. }
  127. EFI_DRIVER_ENTRY_POINT(PciDump)
  128. EFI_STATUS
  129. PciDump (
  130. IN EFI_HANDLE ImageHandle,
  131. IN EFI_SYSTEM_TABLE *SystemTable
  132. )
  133. /*+++
  134. pci [bus dev] [func]
  135. ---*/
  136. {
  137. EFI_STATUS Status;
  138. UINT32 Buffer[64];
  139. EFI_DEVICE_IO_INTERFACE *IoDev;
  140. UINT64 Address, FuncAddress;
  141. UINT16 Bus, Device, Func;
  142. EFI_HANDLE Handle;
  143. EFI_DEVICE_PATH *DevicePath;
  144. PCI_DEVICE_INDEPENDENT_REGION PciHeader;
  145. PCI_CONFIG_ACCESS_CF8 Pci;
  146. DEFIO_PCI_ADDR Defio;
  147. UINTN ScreenCount;
  148. UINTN TempColumn;
  149. UINTN ScreenSize;
  150. CHAR16 ReturnStr[1];
  151. InstallInternalShellCommand (
  152. ImageHandle, SystemTable, PciDump,
  153. L"pci", /* command */
  154. L"pci [bus dev] [func]", /* command syntax */
  155. L"Display PCI device(s) info", /* 1 line descriptor */
  156. NULL /* command help page */
  157. );
  158. InitializeShellApplication (ImageHandle, SystemTable);
  159. /*
  160. * The End Device Path represents the Root of the tree, thus get the global IoDev
  161. * for the system
  162. */
  163. DevicePath = EndDevicePath;
  164. Status = BS->LocateDevicePath (&DeviceIoProtocol, &DevicePath, &Handle);
  165. if (!EFI_ERROR(Status)) {
  166. Status = BS->HandleProtocol (Handle, &DeviceIoProtocol, (VOID*)&IoDev);
  167. }
  168. if (EFI_ERROR(Status)) {
  169. Print (L"%E - handle protocol error %r%N", Status);
  170. return EFI_SUCCESS;
  171. }
  172. if ( SI->Argc < 3 ) {
  173. ST->ConOut->QueryMode (ST->ConOut, ST->ConOut->Mode->Mode, &TempColumn, &ScreenSize);
  174. ScreenCount = 0;
  175. Print (L"\n Bus Dev Func");
  176. Print (L"\n --- --- ----");
  177. ScreenSize -= 4;
  178. for (Bus = 0; Bus <= PCI_MAX_BUS; Bus++) {
  179. for (Device = 0; Device < 32; Device++) {
  180. Address = (Bus << 24) + (Device << 16);
  181. for (Func = 0; Func < 8; Func++) {
  182. FuncAddress = Address + (Func << 8);
  183. IoDev->Pci.Read (IoDev, IO_UINT16, FuncAddress, 1, &PciHeader.VendorId);
  184. if (PciHeader.VendorId != 0xffff) {
  185. IoDev->Pci.Read (IoDev, IO_UINT32, FuncAddress, sizeof(PciHeader)/sizeof(UINT32), &PciHeader);
  186. Print (L"%E");
  187. Print (L"\n %02x %02x %02x ==> %N", Bus, Device, Func);
  188. PciPrintClassCode (&PciHeader);
  189. Print (L"\n Vendor 0x%04x Device 0x%04x Prog Interface %x", PciHeader.VendorId, PciHeader.DeviceId, PciHeader.ClassCode[0]);
  190. if (Func == 0) {
  191. if ((PciHeader.HeaderType & HEADER_TYPE_MULTI_FUNCTION) == 0x00) {
  192. /*
  193. * If this is not a multifucntion device leave the loop
  194. */
  195. Func = 8;
  196. }
  197. }
  198. ScreenCount += 2;
  199. if (ScreenCount >= ScreenSize && ScreenSize != 0) {
  200. /*
  201. * If ScreenSize == 0 we have the console redirected so don't
  202. * block updates
  203. */
  204. ScreenCount = 0;
  205. Print (L"\nPress Return to contiue :");
  206. Input (L"", ReturnStr, sizeof(ReturnStr)/sizeof(CHAR16));
  207. Print (L"\n Bus Dev Func");
  208. Print (L"\n --- --- ----");
  209. }
  210. } else {
  211. /*
  212. * If Func 0 does not exist there are no sub fucntions
  213. */
  214. Func = 8;
  215. }
  216. }
  217. }
  218. }
  219. Print (L"\n");
  220. return EFI_SUCCESS;
  221. }
  222. Bus = (UINT16) xtoi(SI->Argv[1]);
  223. Device = (UINT16) xtoi(SI->Argv[2]);
  224. if (SI->Argc > 3) {
  225. Func = (UINT16) xtoi(SI->Argv[3]);
  226. } else {
  227. Func = 0;
  228. }
  229. Address = (Bus << 24) + (Device << 16) + (Func << 8);
  230. CopyMem (&Defio, &Address, sizeof(Address));
  231. Pci.Reg = Defio.Register;
  232. Pci.Func = Defio.Function;
  233. Pci.Dev = Defio.Device;
  234. Pci.Bus = Defio.Bus;
  235. Pci.Reserved = 0;
  236. Pci.Enable = 1;
  237. Print (L"%H PCI Bus %02x Device %02x Func %02x%N [0xcf8(0x%08x) EFI 0x00%02x%02x%02x00]\n", Bus, Device, Func, Pci, Bus, Device, Func);
  238. /*
  239. * Dump standard header
  240. */
  241. IoDev->Pci.Read (IoDev, IO_UINT32, Address, 16, Buffer);
  242. DumpHex (2, 0, 16*sizeof(UINT32), Buffer);
  243. Print(L"\n");
  244. /*
  245. * Dump Device Dependent Header
  246. */
  247. IoDev->Pci.Read (IoDev, IO_UINT32, Address + 0x40, 48, Buffer);
  248. DumpHex (2, 0x40, 48*sizeof(UINT32), Buffer);
  249. return EFI_SUCCESS;
  250. }